[Devel] [PATCH vz9 09/27] ve/time/stat: idle time virtualization in /proc/loadavg

Nikita Yushchenko nikita.yushchenko at virtuozzo.com
Wed Oct 6 11:57:26 MSK 2021


From: Konstantin Khorenko <khorenko at virtuozzo.com>

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

Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
Reviewed-by: Andrey Ryabinin <aryabinin at virtuozzo.com>

(cherry-picked from vz8 commit 2f58607c7057 ("ve/time/stat: idle time
virtualization in /proc/loadavg"))

Signed-off-by: Nikita Yushchenko <nikita.yushchenko at virtuozzo.com>
---
 fs/proc/uptime.c | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/fs/proc/uptime.c b/fs/proc/uptime.c
index 1e51f5598586..10df5f3a1c21 100644
--- a/fs/proc/uptime.c
+++ b/fs/proc/uptime.c
@@ -7,11 +7,10 @@
 #include <linux/time.h>
 #include <linux/time_namespace.h>
 #include <linux/kernel_stat.h>
+#include <linux/ve.h>
 
-static int uptime_proc_show(struct seq_file *m, void *v)
+static inline void get_ve0_idle(struct timespec64 *idle)
 {
-	struct timespec64 uptime;
-	struct timespec64 idle;
 	u64 nsec;
 	u32 rem;
 	int i;
@@ -20,11 +19,32 @@ static int uptime_proc_show(struct seq_file *m, void *v)
 	for_each_possible_cpu(i)
 		nsec += (__force u64) kcpustat_cpu(i).cpustat[CPUTIME_IDLE];
 
+	idle->tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
+	idle->tv_nsec = rem;
+}
+
+static inline void get_veX_idle(struct ve_struct *ve, struct timespec64 *idle)
+{
+	struct kernel_cpustat kstat;
+
+	ve_get_cpu_stat(ve, &kstat);
+	*idle = ns_to_timespec64(kstat.cpustat[CPUTIME_IDLE]);
+}
+
+static int uptime_proc_show(struct seq_file *m, void *v)
+{
+	struct timespec64 uptime;
+	struct timespec64 idle;
+	struct ve_struct *ve = get_exec_env();
+
+	if (ve_is_super(ve))
+		get_ve0_idle(&idle);
+	else
+		get_veX_idle(ve, &idle);
+
 	ktime_get_boottime_ts64(&uptime);
 	timens_add_boottime(&uptime);
 
-	idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
-	idle.tv_nsec = rem;
 	seq_printf(m, "%lu.%02lu %lu.%02lu\n",
 			(unsigned long) uptime.tv_sec,
 			(uptime.tv_nsec / (NSEC_PER_SEC / 100)),
-- 
2.30.2



More information about the Devel mailing list