From f53b32f7290958fe1e4f03a300c8e1f860e8b3f3 Mon Sep 17 00:00:00 2001 From: Tengfei Fan Date: Fri, 1 Aug 2025 17:57:26 +0800 Subject: [PATCH] ANDROID: sched/scx: Add vendor hook to update task's data when switching to scx Vendor might want to change task's data when they are moved from other sched_class to scx sched_class. Add vendor hook to give control to vendor to implement what they need. The vendor may have its own scheduling algorithm that can coexist with SCX and manages all other scheduler sched_class (except the SCX sched_class). When SCX is enabled, some tasks(such as all fair tasks) are migrated from other sched_class (managed by the vendor's algorithm) to the SCX sched_class. During this migration, it's necessary to reset the vendor scheduler's historical data for these tasks. Otherwise, inconsistencies in the data may cause a panic. This is because, depending on the scenario, some tasks may frequently switch between the SCX sched_class and other sched_class (such as the RT sched_class). If a task switches back from the SCX sched_class to another sched_class while still retaining outdated data from the vendor scheduler, the desynchronization may trigger a panic. Bug: 436479714 Change-Id: Ib148c7a3bfc9a8af6ec76d14f3936850033564e1 Signed-off-by: Tengfei Fan Signed-off-by: Srinivasarao Pathipati --- include/trace/hooks/sched.h | 4 ++++ kernel/sched/ext.c | 2 ++ kernel/sched/vendor_hooks.c | 1 + 3 files changed, 7 insertions(+) diff --git a/include/trace/hooks/sched.h b/include/trace/hooks/sched.h index b272a089a1c4..20c400d15cda 100644 --- a/include/trace/hooks/sched.h +++ b/include/trace/hooks/sched.h @@ -431,6 +431,10 @@ DECLARE_HOOK(android_vh_scx_task_switch_finish, TP_PROTO(struct task_struct *p, int enable), TP_ARGS(p, enable)); +DECLARE_HOOK(android_vh_switching_to_scx, + TP_PROTO(struct rq *rq, struct task_struct *p), + TP_ARGS(rq, p)); + struct sugov_policy; DECLARE_RESTRICTED_HOOK(android_rvh_set_sugov_update, TP_PROTO(struct sugov_policy *sg_policy, unsigned int next_freq, bool *should_update), diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 5fec7ed642af..a56fac61ce5b 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -3861,6 +3861,8 @@ static void switching_to_scx(struct rq *rq, struct task_struct *p) if (SCX_HAS_OP(set_cpumask)) SCX_CALL_OP_TASK(SCX_KF_REST, set_cpumask, p, (struct cpumask *)p->cpus_ptr); + + trace_android_vh_switching_to_scx(rq, p); } static void switched_from_scx(struct rq *rq, struct task_struct *p) diff --git a/kernel/sched/vendor_hooks.c b/kernel/sched/vendor_hooks.c index 97155e1a2285..a10a28e089f9 100644 --- a/kernel/sched/vendor_hooks.c +++ b/kernel/sched/vendor_hooks.c @@ -112,6 +112,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_scx_ops_enable_state); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_scx_enabled); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_scx_set_cpus_allowed); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_scx_task_switch_finish); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_switching_to_scx); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_set_sugov_update); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_update_rq_clock_pelt); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_update_load_avg_blocked_se);