[RHEL8,COMMIT] ve/sched/stat: Introduce handler for getting CT cpu statistics

Submitted by Konstantin Khorenko on Nov. 3, 2020, 1:10 p.m.

Details

Message ID 202011031310.0A3DAuH22050603@finist-co8.sw.ru
State New
Series "Series without cover letter"
Headers show

Commit Message

Konstantin Khorenko Nov. 3, 2020, 1:10 p.m.
The commit is pushed to "branch-rh8-4.18.0-193.6.3.vz8.4.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-193.6.3.vz8.4.15
------>
commit a890bf5d21b8e99fef319ce72cfdfb1416e5138b
Author: Konstantin Khorenko <khorenko@virtuozzo.com>
Date:   Fri Oct 30 12:26:34 2020 +0300

    ve/sched/stat: Introduce handler for getting CT cpu statistics
    
    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>
---
 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 8756560d0b4f..ed59607f2157 100644
--- a/kernel/sched/cpuacct.c
+++ b/kernel/sched/cpuacct.c
@@ -748,3 +748,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 */