ANDROID: kernel: sched: tracehook for is_cpu_allowed

To support the replacement of pause, is_cpu_allowed is the best
place to hook into the code to restrict CPUs for a module based
implementation. This restricts select_fallback_rq, select_task_rq,
and __migate_task, to ensure the cpu is allowed.

Include a hook in is_cpu_allowed to allow the module to control
which cpu is allowed during a migration event.

Bug: 205164003
Change-Id: I665e4d39318079bdb99bd248969ecb9eb528f9df
Signed-off-by: Stephen Dickey <quic_dickey@quicinc.com>
This commit is contained in:
Stephen Dickey
2022-01-10 14:13:51 -08:00
committed by Todd Kjos
parent 50f5345c87
commit a243208877
3 changed files with 15 additions and 2 deletions

View File

@@ -195,6 +195,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_check_file_open);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_check_bpf_syscall);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_set_cpus_allowed_ptr_locked);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_rto_next_cpu);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_is_cpu_allowed);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_em_dev_register_pd);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_logbuf);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_logbuf_pr_cont);

View File

@@ -61,6 +61,10 @@ DECLARE_RESTRICTED_HOOK(android_rvh_rto_next_cpu,
TP_PROTO(int rto_cpu, struct cpumask *rto_mask, int *cpu),
TP_ARGS(rto_cpu, rto_mask, cpu), 1);
DECLARE_RESTRICTED_HOOK(android_rvh_is_cpu_allowed,
TP_PROTO(int cpu, bool *allowed),
TP_ARGS(cpu, allowed), 1);
DECLARE_RESTRICTED_HOOK(android_rvh_set_user_nice,
TP_PROTO(struct task_struct *p, long *nice, bool *allowed),
TP_ARGS(p, nice, allowed), 1);

View File

@@ -2205,6 +2205,8 @@ static inline bool rq_has_pinned_tasks(struct rq *rq)
*/
static inline bool is_cpu_allowed(struct task_struct *p, int cpu)
{
bool allowed = true;
/* When not in the task's cpumask, no point in looking further. */
if (!cpumask_test_cpu(cpu, p->cpus_ptr))
return false;
@@ -2214,8 +2216,14 @@ static inline bool is_cpu_allowed(struct task_struct *p, int cpu)
return cpu_online(cpu);
/* Non kernel threads are not allowed during either online or offline. */
if (!(p->flags & PF_KTHREAD))
return cpu_active(cpu) && task_cpu_possible(cpu, p);
if (!(p->flags & PF_KTHREAD)) {
if (cpu_active(cpu) && task_cpu_possible(cpu, p)) {
trace_android_rvh_is_cpu_allowed(cpu, &allowed);
return allowed;
} else {
return false;
}
}
/* KTHREAD_IS_PER_CPU is always allowed. */
if (kthread_is_per_cpu(p))