ANDROID: cgroup: Add android_rvh_cgroup_force_kthread_migration
In Android GKI, CONFIG_FAIR_GROUP_SCHED is enabled [1] to help prioritize important work. Given that CPU shares of root cgroup can't be changed, leaving the tasks inside root cgroup will give them higher share compared to the other tasks inside important cgroups. This is mitigated by moving all tasks inside root cgroup to a different cgroup after Android is booted. However, there are many kernel tasks stuck in the root cgroup after the boot. It is possible to relax kernel threads and kworkers migrations under certain scenarios. However the patch [2] posted at upstream is not accepted. Hence add a restricted vendor hook to notify modules when a kernel thread is requested for cgroup migration. The modules can relax the restrictions forced by the kernel and allow the cgroup migration. [1] https://android.googlesource.com/kernel/common/+/f08f049de11c15a4251cb1db08cf0bee20bd9b59 [2] https://lore.kernel.org/lkml/1617714261-18111-1-git-send-email-pkondeti@codeaurora.org Bug: 184594949 Change-Id: I445a170ba797c8bece3b4b59b7a42cdd85438f1f Signed-off-by: Pavankumar Kondeti <quic_pkondeti@quicinc.com>
This commit is contained in:
parent
7fe4b54bf0
commit
29203f8c8f
5 changed files with 19 additions and 6 deletions
|
|
@ -193,6 +193,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_set_wake_flags);
|
|||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_uclamp_eff_get);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_cpufreq_transition);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cgroup_set_task);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_cgroup_force_kthread_migration);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_syscall_prctl_finished);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_create_worker);
|
||||
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_check_preempt_tick);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@ DECLARE_HOOK(android_vh_cgroup_set_task,
|
|||
DECLARE_RESTRICTED_HOOK(android_rvh_cpuset_fork,
|
||||
TP_PROTO(struct task_struct *p, int *inherit_cpus),
|
||||
TP_ARGS(p, inherit_cpus), 1);
|
||||
DECLARE_RESTRICTED_HOOK(android_rvh_cgroup_force_kthread_migration,
|
||||
TP_PROTO(struct task_struct *tsk, struct cgroup *dst_cgrp, bool *force_migration),
|
||||
TP_ARGS(tsk, dst_cgrp, force_migration), 1);
|
||||
#endif
|
||||
|
||||
#include <trace/define_trace.h>
|
||||
|
|
|
|||
|
|
@ -232,7 +232,8 @@ int cgroup_migrate(struct task_struct *leader, bool threadgroup,
|
|||
int cgroup_attach_task(struct cgroup *dst_cgrp, struct task_struct *leader,
|
||||
bool threadgroup);
|
||||
struct task_struct *cgroup_procs_write_start(char *buf, bool threadgroup,
|
||||
bool *locked)
|
||||
bool *locked,
|
||||
struct cgroup *dst_cgrp);
|
||||
__acquires(&cgroup_threadgroup_rwsem);
|
||||
void cgroup_procs_write_finish(struct task_struct *task, bool locked)
|
||||
__releases(&cgroup_threadgroup_rwsem);
|
||||
|
|
|
|||
|
|
@ -498,7 +498,7 @@ static ssize_t __cgroup1_procs_write(struct kernfs_open_file *of,
|
|||
if (!cgrp)
|
||||
return -ENODEV;
|
||||
|
||||
task = cgroup_procs_write_start(buf, threadgroup, &locked);
|
||||
task = cgroup_procs_write_start(buf, threadgroup, &locked, cgrp);
|
||||
ret = PTR_ERR_OR_ZERO(task);
|
||||
if (ret)
|
||||
goto out_unlock;
|
||||
|
|
|
|||
|
|
@ -61,6 +61,9 @@
|
|||
|
||||
#define CREATE_TRACE_POINTS
|
||||
#include <trace/events/cgroup.h>
|
||||
#undef CREATE_TRACE_POINTS
|
||||
|
||||
#include <trace/hooks/cgroup.h>
|
||||
|
||||
#define CGROUP_FILE_NAME_MAX (MAX_CGROUP_TYPE_NAMELEN + \
|
||||
MAX_CFTYPE_NAME + 2)
|
||||
|
|
@ -2749,11 +2752,13 @@ int cgroup_attach_task(struct cgroup *dst_cgrp, struct task_struct *leader,
|
|||
}
|
||||
|
||||
struct task_struct *cgroup_procs_write_start(char *buf, bool threadgroup,
|
||||
bool *locked)
|
||||
bool *locked,
|
||||
struct cgroup *dst_cgrp)
|
||||
__acquires(&cgroup_threadgroup_rwsem)
|
||||
{
|
||||
struct task_struct *tsk;
|
||||
pid_t pid;
|
||||
bool force_migration = false;
|
||||
|
||||
if (kstrtoint(strstrip(buf), 0, &pid) || pid < 0)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
|
@ -2788,13 +2793,16 @@ struct task_struct *cgroup_procs_write_start(char *buf, bool threadgroup,
|
|||
if (threadgroup)
|
||||
tsk = tsk->group_leader;
|
||||
|
||||
if (tsk->flags & PF_KTHREAD)
|
||||
trace_android_rvh_cgroup_force_kthread_migration(tsk, dst_cgrp, &force_migration);
|
||||
|
||||
/*
|
||||
* kthreads may acquire PF_NO_SETAFFINITY during initialization.
|
||||
* If userland migrates such a kthread to a non-root cgroup, it can
|
||||
* become trapped in a cpuset, or RT kthread may be born in a
|
||||
* cgroup with no rt_runtime allocated. Just say no.
|
||||
*/
|
||||
if (tsk->no_cgroup_migration || (tsk->flags & PF_NO_SETAFFINITY)) {
|
||||
if (!force_migration && (tsk->no_cgroup_migration || (tsk->flags & PF_NO_SETAFFINITY))) {
|
||||
tsk = ERR_PTR(-EINVAL);
|
||||
goto out_unlock_threadgroup;
|
||||
}
|
||||
|
|
@ -4746,7 +4754,7 @@ static ssize_t cgroup_procs_write(struct kernfs_open_file *of,
|
|||
if (!dst_cgrp)
|
||||
return -ENODEV;
|
||||
|
||||
task = cgroup_procs_write_start(buf, true, &locked);
|
||||
task = cgroup_procs_write_start(buf, true, &locked, dst_cgrp);
|
||||
ret = PTR_ERR_OR_ZERO(task);
|
||||
if (ret)
|
||||
goto out_unlock;
|
||||
|
|
@ -4790,7 +4798,7 @@ static ssize_t cgroup_threads_write(struct kernfs_open_file *of,
|
|||
if (!dst_cgrp)
|
||||
return -ENODEV;
|
||||
|
||||
task = cgroup_procs_write_start(buf, false, &locked);
|
||||
task = cgroup_procs_write_start(buf, false, &locked, dst_cgrp);
|
||||
ret = PTR_ERR_OR_ZERO(task);
|
||||
if (ret)
|
||||
goto out_unlock;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue