[Devel] [PATCH rh8 3/8] ve/sched/stat: Add basic infrastructure for vcpu statistics

Konstantin Khorenko khorenko at virtuozzo.com
Wed Oct 28 18:57:32 MSK 2020


Container might have a limit on CPUs in its config.
Previously we had a fair vcpu primitive and fair 2 level
cpu scheduler.

Nowadays we do not have fair vcpus for Containers, but still have
emulate this behavior.
The most important part here is to provide correct statistics:
it should be collected upon all cpus in the system and spread
equally by "vcpus" in the output.

The current patch introduces vcpu related necessary fields in
task_group and their allocation/deallocation.

Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
 kernel/sched/core.c  | 15 +++++++++++++++
 kernel/sched/sched.h |  5 +++++
 2 files changed, 20 insertions(+)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 0116742de578..88bc46d163b3 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6398,6 +6398,8 @@ static void sched_free_group(struct task_group *tg)
 	free_fair_sched_group(tg);
 	free_rt_sched_group(tg);
 	autogroup_free(tg);
+	kvfree(tg->cpustat_last);
+	kvfree(tg->vcpustat);
 	kmem_cache_free(task_group_cache, tg);
 }
 
@@ -6416,6 +6418,19 @@ struct task_group *sched_create_group(struct task_group *parent)
 	if (!alloc_rt_sched_group(tg, parent))
 		goto err;
 
+	tg->cpustat_last = kvzalloc(nr_cpu_ids * sizeof(struct kernel_cpustat),
+				    GFP_KERNEL);
+	if (!tg->cpustat_last)
+		goto err;
+
+	tg->vcpustat = kvzalloc(nr_cpu_ids * sizeof(struct kernel_cpustat),
+				GFP_KERNEL);
+	if (!tg->vcpustat)
+		goto err;
+
+	tg->vcpustat_last_update = 0;
+	spin_lock_init(&tg->vcpustat_lock);
+
 	/* start_timespec is saved CT0 uptime */
 	tg->start_time = ktime_get_boot_ns();
 
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 3f1e5ba43910..d8331e5b4c4f 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -412,6 +412,11 @@ struct task_group {
 	/* Monotonic time in nsecs: */
 	u64			start_time;
 
+	struct kernel_cpustat	*cpustat_last;
+	struct kernel_cpustat	*vcpustat;
+	u64			vcpustat_last_update;
+	spinlock_t		vcpustat_lock;
+
 	struct cfs_bandwidth	cfs_bandwidth;
 #ifdef CONFIG_CFS_CPULIMIT
 #define MAX_CPU_RATE 1024
-- 
2.28.0



More information about the Devel mailing list