[Devel] [PATCH vz10] cpuacct: expose interface file in cgroup v2

Aleksei Oladko aleksey.oladko at virtuozzo.com
Mon Nov 10 19:03:07 MSK 2025


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 <aleksey.oladko at virtuozzo.com>
---
 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,
 	.early_init	= true,
 
 	.implicit_on_dfl = true,
-- 
2.43.0



More information about the Devel mailing list