From 8ecd88d9d38f849d5aac59596ebc7a8679405f5b Mon Sep 17 00:00:00 2001 From: Sai Harshini Nimmala Date: Thu, 27 Oct 2022 12:52:45 -0700 Subject: [PATCH] ANDROID: sched/cpuset: Add vendor hook to change tasks affinity Vendors might want to change tasks affinity settings when they are moving from one cpuset into the other. Add vendor hook to give control to vendor to implement what they need. This feature is necessary to control hotplug behaviour within Qualcomm's proprietary load tracking scheme, WALT. This reverts commit 034ddf86f70f ("Revert "ANDROID: sched/cpuset: Add vendor hook to change tasks affinity"") to effectively bring back the original change. Bug: 174125747 Signed-off-by: Satya Durga Srinivasu Prabhala Signed-off-by: Sai Harshini Nimmala Change-Id: Id4e9c3e47e3b4e041804bdf10cbd9e36179bc172 --- include/trace/hooks/sched.h | 5 +++++ kernel/cgroup/cpuset.c | 18 ++++++++++++++++-- kernel/sched/vendor_hooks.c | 1 + 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/trace/hooks/sched.h b/include/trace/hooks/sched.h index c6fa88f03013..0773eae433a6 100644 --- a/include/trace/hooks/sched.h +++ b/include/trace/hooks/sched.h @@ -193,6 +193,11 @@ DECLARE_RESTRICTED_HOOK(android_rvh_update_misfit_status, TP_PROTO(struct task_struct *p, struct rq *rq, bool *need_update), TP_ARGS(p, rq, need_update), 1); +DECLARE_RESTRICTED_HOOK(android_rvh_update_cpus_allowed, + TP_PROTO(struct task_struct *p, cpumask_var_t cpus_requested, + const struct cpumask *new_mask, int *ret), + TP_ARGS(p, cpus_requested, new_mask, ret), 1); + DECLARE_RESTRICTED_HOOK(android_rvh_sched_fork_init, TP_PROTO(struct task_struct *p), TP_ARGS(p), 1); diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index de18cb9e4f9e..24a75f5c2920 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -67,6 +67,8 @@ #include #include +#include + DEFINE_STATIC_KEY_FALSE(cpusets_pre_enable_key); DEFINE_STATIC_KEY_FALSE(cpusets_enabled_key); @@ -1196,6 +1198,18 @@ void rebuild_sched_domains(void) } EXPORT_SYMBOL_GPL(rebuild_sched_domains); +static int update_cpus_allowed(struct cpuset *cs, struct task_struct *p, + const struct cpumask *new_mask) +{ + int ret = -EINVAL; + + trace_android_rvh_update_cpus_allowed(p, cs->cpus_requested, new_mask, &ret); + if (!ret) + return ret; + + return set_cpus_allowed_ptr(p, new_mask); +} + /** * update_tasks_cpumask - Update the cpumasks of tasks in the cpuset. * @cs: the cpuset in which each task's cpus_allowed mask needs to be changed @@ -1218,7 +1232,7 @@ static void update_tasks_cpumask(struct cpuset *cs) if (top_cs && (task->flags & PF_KTHREAD) && kthread_is_per_cpu(task)) continue; - set_cpus_allowed_ptr(task, cs->effective_cpus); + update_cpus_allowed(cs, task, cs->effective_cpus); } css_task_iter_end(&it); } @@ -2527,7 +2541,7 @@ static void cpuset_attach(struct cgroup_taskset *tset) * can_attach beforehand should guarantee that this doesn't * fail. TODO: have a better way to handle failure here */ - WARN_ON_ONCE(set_cpus_allowed_ptr(task, cpus_attach)); + WARN_ON_ONCE(update_cpus_allowed(cs, task, cpus_attach)); cpuset_change_task_nodemask(task, &cpuset_attach_nodemask_to); cpuset_update_task_spread_flag(cs, task); diff --git a/kernel/sched/vendor_hooks.c b/kernel/sched/vendor_hooks.c index 9fc169565287..a5a581cf888c 100644 --- a/kernel/sched/vendor_hooks.c +++ b/kernel/sched/vendor_hooks.c @@ -35,6 +35,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_find_busiest_queue); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_migrate_queued_task); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_cpu_overutilized); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_sched_setaffinity); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_update_cpus_allowed); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_build_sched_domains); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_check_preempt_tick); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_check_preempt_wakeup_ignore);