[Devel] [PATCH rh8 2/3] ve/sched/loadavg: Provide task_group parameter to get_avenrun_ve()

Konstantin Khorenko khorenko at virtuozzo.com
Tue Nov 10 12:44:54 MSK 2020


Rename get_avenrun_ve() to get_avenrun_tg() and provide it
the task_group argument to use it later for any VE, for the the current
one.

Fixes: f52cf2752bca ("ve/sched/loadavg: Calculate avenrun for Containers
root cpu cgroups")

Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
 include/linux/sched/loadavg.h |  2 --
 kernel/sched/loadavg.c        | 12 ++++++++++--
 kernel/sys.c                  |  6 +++++-
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/include/linux/sched/loadavg.h b/include/linux/sched/loadavg.h
index 1da5768389b7..25fb3344cdbf 100644
--- a/include/linux/sched/loadavg.h
+++ b/include/linux/sched/loadavg.h
@@ -16,8 +16,6 @@
  */
 extern unsigned long avenrun[];		/* Load averages */
 extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift);
-extern void get_avenrun_ve(unsigned long *loads,
-			   unsigned long offset, int shift);
 
 #define FSHIFT		11		/* nr of bits of precision */
 #define FIXED_1		(1<<FSHIFT)	/* 1.0 as fixed-point */
diff --git a/kernel/sched/loadavg.c b/kernel/sched/loadavg.c
index c76b1c842ad8..c430132b5d11 100644
--- a/kernel/sched/loadavg.c
+++ b/kernel/sched/loadavg.c
@@ -76,12 +76,20 @@ void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
 	loads[2] = (avenrun[2] + offset) << shift;
 }
 
-void get_avenrun_ve(unsigned long *loads, unsigned long offset, int shift)
+int get_avenrun_tg(struct task_group *tg, unsigned long *loads,
+		   unsigned long offset, int shift)
 {
-	struct task_group *tg = task_group(current);
+	/* Get current tg if not provided. */
+	tg = tg ? tg : task_group(current);
+
+	if (tg == &root_task_group)
+		return -ENOSYS;
+
 	loads[0] = (tg->avenrun[0] + offset) << shift;
 	loads[1] = (tg->avenrun[1] + offset) << shift;
 	loads[2] = (tg->avenrun[2] + offset) << shift;
+
+	return 0;
 }
 
 long calc_load_fold_active(struct rq *this_rq, long adjust)
diff --git a/kernel/sys.c b/kernel/sys.c
index e7e07ea8d7ef..8560e5bcb6c2 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -2543,6 +2543,8 @@ SYSCALL_DEFINE3(getcpu, unsigned __user *, cpup, unsigned __user *, nodep,
 }
 
 extern void si_meminfo_ve(struct sysinfo *si, struct ve_struct *ve);
+extern int get_avenrun_tg(struct task_group *tg, unsigned long *loads,
+			  unsigned long offset, int shift);
 
 /**
  * do_sysinfo - fill in sysinfo struct
@@ -2575,7 +2577,9 @@ static int do_sysinfo(struct sysinfo *info)
 
 		info->procs = nr_threads_ve(ve);
 
-		get_avenrun_ve(info->loads, 0, SI_LOAD_SHIFT - FSHIFT);
+		/* does not fail on non-VE0 task group */
+		(void)get_avenrun_tg(NULL, info->loads,
+				     0, SI_LOAD_SHIFT - FSHIFT);
 	}
 
 	/*
-- 
2.28.0



More information about the Devel mailing list