All of lore.kernel.org
 help / color / mirror / Atom feed
From: Huaixin Chang <changhuaixin@linux.alibaba.com>
To: changhuaixin@linux.alibaba.com
Cc: bsegall@google.com, dietmar.eggemann@arm.com,
	juri.lelli@redhat.com, khlebnikov@yandex-team.ru,
	linux-kernel@vger.kernel.org, mgorman@suse.de, mingo@redhat.com,
	pauld@redhead.com, peterz@infradead.org, pjt@google.com,
	rostedt@goodmis.org, shanpeic@linux.alibaba.com,
	vincent.guittot@linaro.org, xiyou.wangcong@gmail.com
Subject: [PATCH v3 3/4] sched/fair: Add cfs bandwidth burst statistics
Date: Thu, 21 Jan 2021 19:04:52 +0800	[thread overview]
Message-ID: <20210121110453.18899-4-changhuaixin@linux.alibaba.com> (raw)
In-Reply-To: <20210121110453.18899-1-changhuaixin@linux.alibaba.com>

Introduce statistics exports for the burstable cfs bandwidth
controller.

The following exports are included:

current_bw: current runtime in global pool
nr_burst:   number of periods bandwidth burst occurs
burst_time: cumulative wall-time that any cpus has
	    used above quota in respective periods

Signed-off-by: Huaixin Chang <changhuaixin@linux.alibaba.com>
Signed-off-by: Shanpei Chen <shanpeic@linux.alibaba.com>
---
 kernel/sched/core.c  |  6 ++++++
 kernel/sched/fair.c  | 12 +++++++++++-
 kernel/sched/sched.h |  3 +++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index fecf0f05ef0c..80ca763ca492 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7986,6 +7986,8 @@ static int tg_set_cfs_bandwidth(struct task_group *tg, u64 period, u64 quota,
 		cfs_b->runtime = min(max_cfs_runtime, cfs_b->runtime);
 	}
 
+	cfs_b->previous_runtime = cfs_b->runtime;
+
 	/* Restart the period timer (if active) to handle new period expiry: */
 	if (runtime_enabled)
 		start_cfs_bandwidth(cfs_b, 1);
@@ -8234,6 +8236,10 @@ static int cpu_cfs_stat_show(struct seq_file *sf, void *v)
 		seq_printf(sf, "wait_sum %llu\n", ws);
 	}
 
+	seq_printf(sf, "current_bw %llu\n", cfs_b->runtime);
+	seq_printf(sf, "nr_burst %d\n", cfs_b->nr_burst);
+	seq_printf(sf, "burst_time %llu\n", cfs_b->burst_time);
+
 	return 0;
 }
 #endif /* CONFIG_CFS_BANDWIDTH */
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index abe6eb05fe09..e3536301df7b 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4601,7 +4601,7 @@ static inline u64 sched_cfs_bandwidth_slice(void)
 static void __refill_cfs_bandwidth_runtime(struct cfs_bandwidth *cfs_b,
 		u64 overrun)
 {
-	u64 refill;
+	u64 refill, runtime;
 
 	if (cfs_b->quota != RUNTIME_INF) {
 
@@ -4610,10 +4610,20 @@ static void __refill_cfs_bandwidth_runtime(struct cfs_bandwidth *cfs_b,
 			return;
 		}
 
+		if (cfs_b->previous_runtime > cfs_b->runtime) {
+			runtime = cfs_b->previous_runtime - cfs_b->runtime;
+			if (runtime > cfs_b->quota) {
+				cfs_b->burst_time += runtime - cfs_b->quota;
+				cfs_b->nr_burst++;
+			}
+		}
+
 		overrun = min(overrun, cfs_b->max_overrun);
 		refill = cfs_b->quota * overrun;
 		cfs_b->runtime += refill;
 		cfs_b->runtime = min(cfs_b->runtime, cfs_b->buffer);
+
+		cfs_b->previous_runtime = cfs_b->runtime;
 	}
 }
 
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index ff8b5382485d..4adb984e5197 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -367,6 +367,7 @@ struct cfs_bandwidth {
 	u64			burst;
 	u64			buffer;
 	u64			max_overrun;
+	u64			previous_runtime;
 	s64			hierarchical_quota;
 
 	u8			idle;
@@ -379,7 +380,9 @@ struct cfs_bandwidth {
 	/* Statistics: */
 	int			nr_periods;
 	int			nr_throttled;
+	int			nr_burst;
 	u64			throttled_time;
+	u64			burst_time;
 #endif
 };
 
-- 
2.14.4.44.g2045bb6


  parent reply	other threads:[~2021-01-21 11:07 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-17  7:46 [PATCH 0/4] sched/fair: Burstable CFS bandwidth controller Huaixin Chang
2020-12-17  7:46 ` [PATCH 1/4] sched/fair: Introduce primitives for CFS bandwidth burst Huaixin Chang
2020-12-17 13:36   ` Peter Zijlstra
2020-12-21 13:53     ` changhuaixin
2021-01-12  9:21       ` changhuaixin
2020-12-17  7:46 ` [PATCH 2/4] sched/fair: Make CFS bandwidth controller burstable Huaixin Chang
2020-12-18  9:53   ` kernel test robot
2020-12-18  9:53     ` kernel test robot
2020-12-17  7:46 ` [PATCH 3/4] sched/fair: Add cfs bandwidth burst statistics Huaixin Chang
2020-12-17  7:46 ` [PATCH 4/4] sched/fair: Add document for burstable CFS bandwidth control Huaixin Chang
2020-12-17 21:25 ` [PATCH 0/4] sched/fair: Burstable CFS bandwidth controller Benjamin Segall
2021-01-20 12:27 ` [PATCH v2 " Huaixin Chang
2021-01-20 12:27   ` [PATCH 1/4] sched/fair: Introduce primitives for CFS bandwidth burst Huaixin Chang
2021-01-20 12:27   ` [PATCH 2/4] sched/fair: Make CFS bandwidth controller burstable Huaixin Chang
2021-01-20 17:06     ` kernel test robot
2021-01-20 17:06       ` kernel test robot
2021-01-20 18:33     ` kernel test robot
2021-01-20 18:33       ` kernel test robot
2021-01-20 22:01     ` kernel test robot
2021-01-20 22:01       ` kernel test robot
2021-01-20 22:01     ` [RFC PATCH] sched/fair: __refill_cfs_bandwidth_runtime() can be static kernel test robot
2021-01-20 22:01       ` kernel test robot
2021-01-20 12:27   ` [PATCH 3/4] sched/fair: Add cfs bandwidth burst statistics Huaixin Chang
2021-01-20 12:27   ` [PATCH 4/4] sched/fair: Add document for burstable CFS bandwidth control Huaixin Chang
2021-01-20 19:48     ` Randy Dunlap
2021-01-21 11:04 ` [PATCH v3 0/4] sched/fair: Burstable CFS bandwidth controller Huaixin Chang
2021-01-21 11:04   ` [PATCH v3 1/4] sched/fair: Introduce primitives for CFS bandwidth burst Huaixin Chang
2021-03-10 12:39     ` Peter Zijlstra
2021-01-21 11:04   ` [PATCH v3 2/4] sched/fair: Make CFS bandwidth controller burstable Huaixin Chang
2021-03-10 13:04     ` Peter Zijlstra
2021-03-12 13:54       ` changhuaixin
2021-03-16 10:55         ` Peter Zijlstra
2021-01-21 11:04   ` Huaixin Chang [this message]
2021-03-10 13:10     ` [PATCH v3 3/4] sched/fair: Add cfs bandwidth burst statistics Peter Zijlstra
2021-01-21 11:04   ` [PATCH v3 4/4] sched/fair: Add document for burstable CFS bandwidth control Huaixin Chang
2021-03-10 13:17     ` Peter Zijlstra
2021-01-26 10:18   ` [PATCH v3 0/4] sched/fair: Burstable CFS bandwidth controller changhuaixin
2021-03-10 12:26     ` Peter Zijlstra
2021-02-09 13:17   ` Odin Ugedal
2021-02-09 10:28     ` Tejun Heo
2021-02-27 13:48     ` changhuaixin
2021-03-10 11:11       ` Odin Ugedal
2021-03-12 13:26         ` changhuaixin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210121110453.18899-4-changhuaixin@linux.alibaba.com \
    --to=changhuaixin@linux.alibaba.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=khlebnikov@yandex-team.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=pauld@redhead.com \
    --cc=peterz@infradead.org \
    --cc=pjt@google.com \
    --cc=rostedt@goodmis.org \
    --cc=shanpeic@linux.alibaba.com \
    --cc=vincent.guittot@linaro.org \
    --cc=xiyou.wangcong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.