[RHEL8,COMMIT] ve/proc/stat: Wire virtualized /proc/stat handler

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

Details

Message ID 202011031308.0A3D8cDd2050515@finist-co8.sw.ru
State New
Series "ve/proc/sched/stat: Virtualize /proc/stat in a Container"
Headers show

Commit Message

Konstantin Khorenko Nov. 3, 2020, 1:08 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 c5852f7b4a086208cb39c1f0762041f94a942910
Author: Konstantin Khorenko <khorenko@virtuozzo.com>
Date:   Wed Oct 28 15:43:19 2020 +0300

    ve/proc/stat: Wire virtualized /proc/stat handler
    
    Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
    Reviewed-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 fs/proc/stat.c     | 10 ++++++++++
 include/linux/ve.h |  2 ++
 kernel/ve/ve.c     | 17 +++++++++++++++++
 3 files changed, 29 insertions(+)

Patch hide | download patch | download mbox

diff --git a/fs/proc/stat.c b/fs/proc/stat.c
index dfcd5280a7c6..937790fd02cf 100644
--- a/fs/proc/stat.c
+++ b/fs/proc/stat.c
@@ -13,6 +13,7 @@ 
 #include <linux/irqnr.h>
 #include <linux/sched/cputime.h>
 #include <linux/tick.h>
+#include <linux/ve.h>
 
 #ifndef arch_irq_stat_cpu
 #define arch_irq_stat_cpu(cpu) 0
@@ -113,6 +114,15 @@  static int show_stat(struct seq_file *p, void *v)
 	u64 sum_softirq = 0;
 	unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
 	struct timespec64 boottime;
+	struct ve_struct *ve;
+
+	ve = get_exec_env();
+	if (!ve_is_super(ve)) {
+		int ret;
+		ret = ve_show_cpu_stat(ve, p);
+		if (ret != -ENOSYS)
+			return ret;
+	}
 
 	user = nice = system = idle = iowait =
 		irq = softirq = steal = 0;
diff --git a/include/linux/ve.h b/include/linux/ve.h
index 447a91dbd4d4..d88e4715a222 100644
--- a/include/linux/ve.h
+++ b/include/linux/ve.h
@@ -199,8 +199,10 @@  static inline void monotonic_ve_to_abs(clockid_t which_clock,
 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);
 #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; }
 #endif
 
diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index 2cacb673c0f3..eeb1947a7d53 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -1395,6 +1395,23 @@  int vz_security_protocol_check(struct net *net, int protocol)
 EXPORT_SYMBOL_GPL(vz_security_protocol_check);
 
 #ifdef CONFIG_CGROUP_SCHED
+int cpu_cgroup_proc_stat(struct cgroup_subsys_state *cpu_css,
+			 struct cgroup_subsys_state *cpuacct_css,
+			 struct seq_file *p);
+
+int ve_show_cpu_stat(struct ve_struct *ve, struct seq_file *p)
+{
+	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_proc_stat(cpu_css, cpuacct_css, p);
+	css_put(cpuacct_css);
+	css_put(cpu_css);
+	return err;
+}
+
 int cpu_cgroup_proc_loadavg(struct cgroup_subsys_state *css,
 			    struct seq_file *p);