[Devel] [PATCH rh8 1/3] ve/sched/stat: Introduce handler for getting CT cpu statistics

Konstantin Khorenko khorenko at virtuozzo.com
Fri Oct 30 16:08:50 MSK 2020


It will be used later in
  * idle cpu stat virtualization in /proc/loadavg
  * /proc/vz/vestat output
  * VZCTL_GET_CPU_STAT ioctl

The patch is based on following vz7 commits:
  ecdce58b214c ("sched: Export per task_group statistics_work")
  75fc174adc36 ("sched: Port cpustat related patches")
  a58fb58bff1c ("Use ve init task's css instead of opening cgroup via vfs")

Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
 include/linux/ve.h     |  2 ++
 kernel/sched/cpuacct.c | 24 ++++++++++++++++++++++++
 kernel/ve/ve.c         | 18 ++++++++++++++++++
 3 files changed, 44 insertions(+)

diff --git a/include/linux/ve.h b/include/linux/ve.h
index d88e4715a222..656ee43e383e 100644
--- a/include/linux/ve.h
+++ b/include/linux/ve.h
@@ -201,9 +201,11 @@ struct seq_file;
 #if defined(CONFIG_VE) && defined(CONFIG_CGROUP_SCHED)
 int ve_show_cpu_stat(struct ve_struct *ve, struct seq_file *p);
 int ve_show_loadavg(struct ve_struct *ve, struct seq_file *p);
+int ve_get_cpu_stat(struct ve_struct *ve, struct kernel_cpustat *kstat);
 #else
 static inline int ve_show_cpu_stat(struct ve_struct *ve, struct seq_file *p) { return -ENOSYS; }
 static inline int ve_show_loadavg(struct ve_struct *ve, struct seq_file *p) { return -ENOSYS; }
+static inline int ve_get_cpu_stat(struct ve_struct *ve, struct kernel_cpustat *kstat) { return -ENOSYS; }
 #endif
 
 #endif /* _LINUX_VE_H */
diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c
index 0ba19cce9fac..df5fe01c8f24 100644
--- a/kernel/sched/cpuacct.c
+++ b/kernel/sched/cpuacct.c
@@ -754,3 +754,27 @@ int cpu_cgroup_proc_stat(struct cgroup_subsys_state *cpu_css,
 
 	return 0;
 }
+
+int cpu_cgroup_get_stat(struct cgroup_subsys_state *cpu_css,
+			struct cgroup_subsys_state *cpuacct_css,
+			struct kernel_cpustat *kstat)
+{
+	struct task_group *tg = css_tg(cpu_css);
+	int nr_vcpus = tg_nr_cpus(tg);
+	int i;
+
+	kernel_cpustat_zero(kstat);
+
+	if (tg == &root_task_group)
+		return -ENOENT;
+
+	for_each_possible_cpu(i)
+		cpu_cgroup_update_stat(cpu_css, cpuacct_css, i);
+
+	cpu_cgroup_update_vcpustat(cpu_css, cpuacct_css);
+
+	for (i = 0; i < nr_vcpus; i++)
+		kernel_cpustat_add(tg->vcpustat + i, kstat, kstat);
+
+	return 0;
+}
diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index eeb1947a7d53..10cebe10beab 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -1425,4 +1425,22 @@ int ve_show_loadavg(struct ve_struct *ve, struct seq_file *p)
 	css_put(css);
 	return err;
 }
+
+int cpu_cgroup_get_stat(struct cgroup_subsys_state *cpu_css,
+			struct cgroup_subsys_state *cpuacct_css,
+			struct kernel_cpustat *kstat);
+
+int ve_get_cpu_stat(struct ve_struct *ve, struct kernel_cpustat *kstat)
+{
+	struct cgroup_subsys_state *cpu_css, *cpuacct_css;
+	int err;
+
+	cpu_css = ve_get_init_css(ve, cpu_cgrp_id);
+	cpuacct_css = ve_get_init_css(ve, cpuacct_cgrp_id);
+	err = cpu_cgroup_get_stat(cpu_css, cpuacct_css, kstat);
+	css_put(cpuacct_css);
+	css_put(cpu_css);
+	return err;
+}
+EXPORT_SYMBOL(ve_get_cpu_stat);
 #endif /* CONFIG_CGROUP_SCHED */
-- 
2.28.0



More information about the Devel mailing list