From: Konstantin Khorenko <khore...@virtuozzo.com>

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 <khore...@virtuozzo.com>
Reviewed-by: Andrey Ryabinin <aryabi...@virtuozzo.com>

(cherry-picked from vz8 commit 0d3940d7e3ee ("ve/sched/stat: Add basic
infrastructure for vcpu statistics"))

Signed-off-by: Nikita Yushchenko <nikita.yushche...@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 99eee9cc2324..79a6f6808a7c 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -9541,6 +9541,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);
 }
 
@@ -9559,6 +9561,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);
+
        alloc_uclamp_sched_group(tg, parent);
 
        return tg;
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index cc8f45d72d8c..13c1941d0593 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -436,6 +436,11 @@ struct task_group {
 
        unsigned long avenrun[3];       /* loadavg data */
 
+       struct kernel_cpustat   *cpustat_last;
+       struct kernel_cpustat   *vcpustat;
+       u64                     vcpustat_last_update;
+       spinlock_t              vcpustat_lock;
+
        struct cfs_bandwidth    cfs_bandwidth;
 
 #ifdef CONFIG_UCLAMP_TASK_GROUP
-- 
2.30.2

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to