From: Xunlei Pang xlpang@linux.alibaba.com
maillist inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8QUNW
Reference: https://github.com/alibaba/cloud-kernel/commit/1f49a73850325bb93601cc2240236...
----------------------------------------------
Export "cpu|io|memory.pressure" under cgroup v1 "cpuacct" subsystem.
Reviewed-by: Joseph Qi joseph.qi@linux.alibaba.com Signed-off-by: Xunlei Pang xlpang@linux.alibaba.com Conflict: kernel/cgroup/cgroup.c kernel/sched/sched.h kernel/sched/psi.c Merge OLK-5.10 fix patch 614135168b0475d54567b3a5d27afe315b09d0a8 Merge OLK-5.10 fix patch 834a1594da34ba6e7b21fdba1b2564240ce4cd05 Signed-off-by: Lu Jialin lujialin4@huawei.com --- init/Kconfig | 10 ++++++++++ kernel/cgroup/cgroup.c | 27 +++++++++++++++++++++++++++ kernel/sched/cpuacct.c | 12 ++++++++++++ kernel/sched/psi.c | 10 +++++++++- 4 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/init/Kconfig b/init/Kconfig index 2ee1384c4f81..3a66ebe72504 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -667,6 +667,16 @@ config PSI_DEFAULT_DISABLED
Say N if unsure.
+config PSI_CGROUP_V1 + bool "Support PSI under cgroup v1" + default Y + depends on PSI + help + If set, pressure stall information tracking will be used + for cgroup v1 other than v2. + + Say N if unsure. + endmenu # "CPU/Task time and stats accounting"
config CPU_ISOLATION diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 41b16ce99f54..ba02b60ad9bd 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -3902,6 +3902,33 @@ bool cgroup_psi_enabled(void) return (cgroup_feature_disable_mask & (1 << OPT_FEATURE_PRESSURE)) == 0; }
+struct cftype cgroup_v1_psi_files[] = { + { + .name = "io.pressure", + .file_offset = offsetof(struct cgroup, psi_files[PSI_IO]), + .seq_show = cgroup_io_pressure_show, + .write = cgroup_io_pressure_write, + .poll = cgroup_pressure_poll, + .release = cgroup_pressure_release, + }, + { + .name = "memory.pressure", + .file_offset = offsetof(struct cgroup, psi_files[PSI_MEM]), + .seq_show = cgroup_memory_pressure_show, + .write = cgroup_memory_pressure_write, + .poll = cgroup_pressure_poll, + .release = cgroup_pressure_release, + }, + { + .name = "cpu.pressure", + .file_offset = offsetof(struct cgroup, psi_files[PSI_CPU]), + .seq_show = cgroup_cpu_pressure_show, + .write = cgroup_cpu_pressure_write, + .poll = cgroup_pressure_poll, + .release = cgroup_pressure_release, + }, + { } /* terminate */ +}; #else /* CONFIG_PSI */ bool cgroup_psi_enabled(void) { diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c index 0de9dda09949..91039b9260a4 100644 --- a/kernel/sched/cpuacct.c +++ b/kernel/sched/cpuacct.c @@ -361,3 +361,15 @@ struct cgroup_subsys cpuacct_cgrp_subsys = { .legacy_cftypes = files, .early_init = true, }; + +#ifdef CONFIG_PSI +extern struct cftype cgroup_v1_psi_files[]; + +static int __init cgroup_v1_psi_init(void) +{ + cgroup_add_legacy_cftypes(&cpuacct_cgrp_subsys, cgroup_v1_psi_files); + return 0; +} + +late_initcall_sync(cgroup_v1_psi_init); +#endif diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index 1d0f634725a6..70c7765766fc 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -884,8 +884,16 @@ static void psi_group_change(struct psi_group *group, int cpu, static inline struct psi_group *task_psi_group(struct task_struct *task) { #ifdef CONFIG_CGROUPS - if (static_branch_likely(&psi_cgroups_enabled)) + if (static_branch_likely(&psi_cgroups_enabled)) { +#ifdef CONFIG_PSI_CGROUP_V1 + if (!cgroup_subsys_on_dfl(cpuacct_cgrp_subsys)) + return cgroup_psi(task_cgroup(task, cpuacct_cgrp_id)); + else + return cgroup_psi(task_dfl_cgroup(task)); +#else return cgroup_psi(task_dfl_cgroup(task)); +#endif + } #endif return &psi_system; }