[RHEL8,COMMIT] ve/sched/loadavg: Provide task_group parameter to get_avenrun_ve()

Submitted by Konstantin Khorenko on Nov. 11, 2020, 1 p.m.

Details

Message ID 202011111300.0ABD04kr3319744@finist-co8.sw.ru
State New
Series "vecalls: Implement VZCTL_GET_CPU_STAT ioctl"
Headers show

Commit Message

Konstantin Khorenko Nov. 11, 2020, 1 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.17
------>
commit 2e7bc3486fb7bd25dbc3a6a4530ece030aa8456c
Author: Konstantin Khorenko <khorenko@virtuozzo.com>
Date:   Wed Nov 11 16:00:03 2020 +0300

    ve/sched/loadavg: Provide task_group parameter to get_avenrun_ve()
    
    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@virtuozzo.com>
    Reviewed-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 include/linux/sched/loadavg.h |  2 --
 kernel/sched/loadavg.c        | 12 ++++++++++--
 kernel/sys.c                  |  6 +++++-
 3 files changed, 15 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

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);
 	}
 
 	/*