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

Submitted by Konstantin Khorenko on Oct. 30, 2020, 1:08 p.m.

Details

Message ID 20201030130852.2046899-1-khorenko@virtuozzo.com
State New
Series "Series without cover letter"
Headers show

Commit Message

Konstantin Khorenko Oct. 30, 2020, 1:08 p.m.
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@virtuozzo.com>
---
 include/linux/ve.h     |  2 ++
 kernel/sched/cpuacct.c | 24 ++++++++++++++++++++++++
 kernel/ve/ve.c         | 18 ++++++++++++++++++
 3 files changed, 44 insertions(+)

Patch hide | download patch | download mbox

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 */

Comments

Andrey Ryabinin Oct. 30, 2020, 4:41 p.m.
On 10/30/20 4:08 PM, Konstantin Khorenko wrote:
> 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@virtuozzo.com>

Reviewed-by: Andrey Ryabinin <aryabinin@virtuozzo.com>