[Devel] [PATCH RHEL COMMIT] vzstat,sched: Track sched_lat_ve

Konstantin Khorenko khorenko at virtuozzo.com
Fri Sep 24 15:48:42 MSK 2021


The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after ark-5.14
------>
commit 08f92f97f6e8c18c8e94734c94cdab3c5bc98367
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Fri Sep 24 15:48:42 2021 +0300

    vzstat,sched: Track sched_lat_ve
    
    FIXME: This patch must be rewritten via sched_entity::statistics::wait_max.
    
    Signed-off-by: Vladimir Davydov <vdavydov at parallels.com>
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
    
    (cherry picked from vz8 commit c0fb61430afceb6564a1b0792d51835b70eab9e1)
    Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 include/linux/ve.h  |  3 +++
 kernel/sched/fair.c | 11 +++++++++++
 kernel/ve/ve.c      | 10 ++++++++++
 3 files changed, 24 insertions(+)

diff --git a/include/linux/ve.h b/include/linux/ve.h
index d5825ce3b30e..18d52c6c63cf 100644
--- a/include/linux/ve.h
+++ b/include/linux/ve.h
@@ -14,6 +14,7 @@
 #include <linux/ve_proto.h>
 #include <linux/cgroup.h>
 #include <linux/kmapset.h>
+#include <linux/vzstat.h>
 
 struct nsproxy;
 struct veip_struct;
@@ -48,6 +49,8 @@ struct ve_struct {
 	/* see vzcalluser.h for VE_FEATURE_XXX definitions */
 	__u64			features;
 
+	struct kstat_lat_pcpu_struct    sched_lat_ve;
+
 	struct kmapset_key	sysfs_perms_key;
 
 	atomic_t		netns_avail_nr;
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 266862d677d8..e5b9d9d26e78 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -21,6 +21,8 @@
  *  Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra
  */
 #include "sched.h"
+#include <linux/ve.h>
+#include <linux/vzstat.h>
 
 /*
  * Targeted preemption latency for CPU-bound tasks:
@@ -935,6 +937,14 @@ update_stats_wait_start(struct cfs_rq *cfs_rq, struct sched_entity *se)
 	__schedstat_set(se->statistics.wait_start, wait_start);
 }
 
+static inline void update_sched_lat(struct task_struct *t, u64 delta)
+{
+#ifdef CONFIG_VE
+	KSTAT_LAT_PCPU_ADD(&kstat_glob.sched_lat, delta);
+	KSTAT_LAT_PCPU_ADD(&t->task_ve->sched_lat_ve, delta);
+#endif
+}
+
 static inline void
 update_stats_wait_end(struct cfs_rq *cfs_rq, struct sched_entity *se)
 {
@@ -967,6 +977,7 @@ update_stats_wait_end(struct cfs_rq *cfs_rq, struct sched_entity *se)
 			return;
 		}
 		trace_sched_stat_wait(p, delta);
+		update_sched_lat(p, delta);
 	}
 
 	__schedstat_set(se->statistics.wait_max,
diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index ab2a16435ea1..560a63902127 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -29,6 +29,8 @@ extern struct kmapset_set sysfs_ve_perms_set;
 
 static struct kmem_cache *ve_cachep;
 
+static DEFINE_PER_CPU(struct kstat_lat_pcpu_snap_struct, ve0_lat_stats);
+
 struct ve_struct ve0 = {
 	.ve_name		= "0",
 	.start_jiffies		= INITIAL_JIFFIES,
@@ -40,6 +42,7 @@ struct ve_struct ve0 = {
 
 	.init_cred		= &init_cred,
 	.features		= -1,
+	.sched_lat_ve.cur	= &ve0_lat_stats,
 	.netns_avail_nr		= ATOMIC_INIT(INT_MAX),
 	.netns_max_nr		= INT_MAX,
 	._randomize_va_space	=
@@ -398,6 +401,10 @@ static struct cgroup_subsys_state *ve_create(struct cgroup_subsys_state *parent_
 	if (!ve)
 		goto err_ve;
 
+	ve->sched_lat_ve.cur = alloc_percpu(struct kstat_lat_pcpu_snap_struct);
+	if (!ve->sched_lat_ve.cur)
+		goto err_lat;
+
 	ve->features = VE_FEATURES_DEF;
 	ve->_randomize_va_space = ve0._randomize_va_space;
 
@@ -409,6 +416,8 @@ static struct cgroup_subsys_state *ve_create(struct cgroup_subsys_state *parent_
 	kmapset_init_key(&ve->sysfs_perms_key);
 	return &ve->css;
 
+err_lat:
+	kmem_cache_free(ve_cachep, ve);
 err_ve:
 	return ERR_PTR(err);
 }
@@ -448,6 +457,7 @@ static void ve_destroy(struct cgroup_subsys_state *css)
 	struct ve_struct *ve = css_to_ve(css);
 
 	kmapset_unlink(&ve->sysfs_perms_key, &sysfs_ve_perms_set);
+	free_percpu(ve->sched_lat_ve.cur);
 	kmem_cache_free(ve_cachep, ve);
 }
 


More information about the Devel mailing list