From fcb45d2dd5776211bdf3d5a58ad0f4477cb3fe10 Mon Sep 17 00:00:00 2001 From: Xunlei Pang Date: Mon, 23 Dec 2019 21:09:51 +0800 Subject: [PATCH] alios: psi: Support PSI under cgroup v1 Export "cpu|io|memory.pressure" under cgroup v1 "cpuacct" subsystem. Reviewed-by: Joseph Qi Signed-off-by: Xunlei Pang --- init/Kconfig | 10 ++++++++++ kernel/cgroup/cgroup.c | 28 ++++++++++++++++++++++++++++ kernel/sched/cpuacct.c | 10 ++++++++++ kernel/sched/psi.c | 4 ++++ kernel/sched/sched.h | 4 ++++ 5 files changed, 56 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index d674fd81b171..5eda763822a1 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -532,6 +532,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 c7e066431eb8..474a23b15822 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -3518,6 +3518,34 @@ static void cgroup_pressure_release(struct kernfs_open_file *of) { psi_trigger_replace(&of->priv, NULL); } + +struct cftype cgroup_v1_psi_files[] = { + { + .name = "io.pressure", + .flags = CFTYPE_NO_PREFIX, + .seq_show = cgroup_io_pressure_show, + .write = cgroup_io_pressure_write, + .poll = cgroup_pressure_poll, + .release = cgroup_pressure_release, + }, + { + .name = "memory.pressure", + .flags = CFTYPE_NO_PREFIX, + .seq_show = cgroup_memory_pressure_show, + .write = cgroup_memory_pressure_write, + .poll = cgroup_pressure_poll, + .release = cgroup_pressure_release, + }, + { + .name = "cpu.pressure", + .flags = CFTYPE_NO_PREFIX, + .seq_show = cgroup_cpu_pressure_show, + .write = cgroup_cpu_pressure_write, + .poll = cgroup_pressure_poll, + .release = cgroup_pressure_release, + }, + { } /* terminate */ +}; #endif /* CONFIG_PSI */ static int cgroup_file_open(struct kernfs_open_file *of) diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c index 9fbb10383434..59f515ac11b5 100644 --- a/kernel/sched/cpuacct.c +++ b/kernel/sched/cpuacct.c @@ -373,3 +373,13 @@ struct cgroup_subsys cpuacct_cgrp_subsys = { .legacy_cftypes = files, .early_init = true, }; + +#ifdef CONFIG_PSI +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 517e3719027e..677ed6516066 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -725,7 +725,11 @@ static struct psi_group *iterate_groups(struct task_struct *task, void **iter) struct cgroup *cgroup = NULL; if (!*iter) +#ifdef CONFIG_PSI_CGROUP_V1 + cgroup = task_cgroup(task, cpuacct_cgrp_id); +#else cgroup = task->cgroups->dfl_cgrp; +#endif else if (*iter == &psi_system) return NULL; else diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 9e851e95e98c..88fd87dfca01 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2251,3 +2251,7 @@ unsigned long scale_irq_capacity(unsigned long util, unsigned long irq, unsigned return util; } #endif + +#ifdef CONFIG_PSI +extern struct cftype cgroup_v1_psi_files[]; +#endif -- GitLab