From e6e2e084f712d47dee560f6a8ff3ae9c5cdd4714 Mon Sep 17 00:00:00 2001 From: Xunlei Pang Date: Mon, 23 Nov 2020 10:45:55 +0800 Subject: [PATCH 2417/2944] alinux: sysfs/cpu: Add online cpus support for rich container to #31381921 Make /sys/devices/system/cpu/online container aware. E.g. cpuset.cpus is 4-7, then it will show "4-7" in the rich container. Reviewed-by: Alex Shi Reviewed-by: Michael Wang Signed-off-by: Xunlei Pang --- drivers/base/cpu.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index f3ecf74..5cf2ca0 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "base.h" @@ -211,8 +212,31 @@ static ssize_t show_cpus_attr(struct device *dev, char *buf) { struct cpu_attr *ca = container_of(attr, struct cpu_attr, attr); + struct cpumask cpuset_allowed; + struct task_struct *init_tsk; + bool rich_container; + + rcu_read_lock(); + rich_container = in_rich_container(current); + if (rich_container) { + read_lock(&tasklist_lock); + init_tsk = task_active_pid_ns(current)->child_reaper; + get_task_struct(init_tsk); + read_unlock(&tasklist_lock); + } else { + init_tsk = NULL; + } + rcu_read_unlock(); + + if (rich_container && !strcmp(attr->attr.name, "online")) + cpuset_cpus_allowed(init_tsk, &cpuset_allowed); + else + cpumask_copy(&cpuset_allowed, ca->map); + + if (init_tsk) + put_task_struct(init_tsk); - return cpumap_print_to_pagebuf(true, buf, ca->map); + return cpumap_print_to_pagebuf(true, buf, &cpuset_allowed); } #define _CPU_ATTR(name, map) \ -- 1.8.3.1