On 11/10/25 17:03, Aleksei Oladko wrote:
In commit 0a76d99f5aa, the cpuacct controller was implicitly enabled in
cgroup v2. This patch enables user access to the cpuacct interface files
in cgroup v2, allowing statistics such as cpuacct.usage_percpu to be
retrieved in the same way as in cgroup v1.

https://virtuozzo.atlassian.net/browse/VSTOR-100092

Signed-off-by: Aleksei Oladko <[email protected]>
---
  kernel/sched/cpuacct.c | 38 ++++++++++++++++++++++++++++++++++++++
  1 file changed, 38 insertions(+)

diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c
index 65a331807e5d..4aa845afa9e7 100644
--- a/kernel/sched/cpuacct.c
+++ b/kernel/sched/cpuacct.c
@@ -293,6 +293,43 @@ static int cpuacct_stats_show(struct seq_file *sf, void *v)
        return 0;
  }
+static struct cftype cpuacct_files[] = {
+       {
+               .name = "usage",
+               .read_u64 = cpuusage_read,
+               .write_u64 = cpuusage_write,
+       },
+       {
+               .name = "usage_user",
+               .read_u64 = cpuusage_user_read,
+       },
+       {
+               .name = "usage_sys",
+               .read_u64 = cpuusage_sys_read,
+       },
+       {
+               .name = "usage_percpu",
+               .seq_show = cpuacct_percpu_seq_show,
+       },
+       {
+               .name = "usage_percpu_user",
+               .seq_show = cpuacct_percpu_user_seq_show,
+       },
+       {
+               .name = "usage_percpu_sys",
+               .seq_show = cpuacct_percpu_sys_seq_show,
+       },
+       {
+               .name = "usage_all",
+               .seq_show = cpuacct_all_seq_show,
+       },
+       {
+               .name = "stat",
+               .seq_show = cpuacct_stats_show,
+       },
+       { }     /* terminate */
+};
+
  static struct cftype files[] = {
        {
                .name = "usage",
@@ -363,6 +400,7 @@ struct cgroup_subsys cpuacct_cgrp_subsys = {
        .css_alloc      = cpuacct_css_alloc,
        .css_free       = cpuacct_css_free,
        .legacy_cftypes = files,
+       .dfl_cftypes    = cpuacct_files,

May be just

     1 │ struct cgroup_subsys cpuacct_cgrp_subsys = {
     2 │    .css_alloc  = cpuacct_css_alloc,
     3 │    .css_free   = cpuacct_css_free,
     4 │    .legacy_cftypes = files,
     5 │+   .dfl_cftypes    = files,  /* Same files for v1 and v2 */
     6 │    .early_init = true,
     7 │
     8 │    .implicit_on_dfl = true,
     9 │    .threaded       = true,
    10 │ };

?

int __init cgroup_init(void)
{
...
                if (ss->dfl_cftypes == ss->legacy_cftypes) {
                        WARN_ON(cgroup_add_cftypes(ss, ss->dfl_cftypes));
                } else {
                        WARN_ON(cgroup_add_dfl_cftypes(ss, ss->dfl_cftypes));
                        WARN_ON(cgroup_add_legacy_cftypes(ss, 
ss->legacy_cftypes));
                }


        .early_init     = true,
.implicit_on_dfl = true,

_______________________________________________
Devel mailing list
[email protected]
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to