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 <quic_tengfan@quicinc.com>
Signed-off-by: Srinivasarao Pathipati <quic_c_spathi@quicinc.com>
This commit is contained in:
Tengfei Fan
2025-08-01 17:57:26 +08:00
committed by Todd Kjos
parent 1871faf419
commit f53b32f729
3 changed files with 7 additions and 0 deletions
+4
View File
@@ -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),
+2
View File
@@ -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)
+1
View File
@@ -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);