[Devel] [PATCH vz9 08/27] ve/sched/stat: Introduce handler for getting CT cpu statistics
Nikita Yushchenko
nikita.yushchenko at virtuozzo.com
Wed Oct 6 11:57:25 MSK 2021
From: Konstantin Khorenko <khorenko at virtuozzo.com>
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>
Reviewed-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
(cherry-picked from vz8 commit 27d722418d1a ("ve/sched/stat: Introduce
handler for getting CT cpu statistics"))
Signed-off-by: Nikita Yushchenko <nikita.yushchenko 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 47f690c1b8b9..e7b5be193442 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 a409c441aba3..29105ef2f402 100644
--- a/kernel/sched/cpuacct.c
+++ b/kernel/sched/cpuacct.c
@@ -755,3 +755,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 2e418e72ce62..4caa8a1f27ca 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -1485,4 +1485,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.30.2
More information about the Devel
mailing list