Skip to contentSkip to conversation

Add statistics and document for cfs_b burst

PATCH Applied Huaixin Chang 5 participants 11 messages Aug 30, 2021 – Oct 5, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover Add statistics and document for cfs_b burst

Changelog:
v2:
- Use burst_time in nanoseconds for cgroup1 interface, and burst_usec in microseconds for cgroup2 interface.
- Minor document adjustment.

v1 Link:
https://lore.kernel.org/lkml/[email protected]/

Huaixin Chang (2):
sched/fair: Add cfs bandwidth burst statistics sched/fair: Add document for burstable CFS bandwidth

 Documentation/admin-guide/cgroup-v2.rst |  8 ++++
 Documentation/scheduler/sched-bwc.rst   | 85 +++++++++++++++++++++++++++++----
 kernel/sched/core.c                     | 13 +++--
 kernel/sched/fair.c                     |  9 ++++
 kernel/sched/sched.h                    |  3 ++
 5 files changed, 105 insertions(+), 13 deletions(-)
Signature · 1 line
2.14.4.44.g2045bb6
#1 lore raw

PATCH v2 1/2 sched/fair: Add cfs bandwidth burst statistics

Two new statistics are introduced to show the internal of burst feature and explain why burst helps or not.

nr_bursts:  number of periods bandwidth burst occurs
burst_time: cumulative wall-time (in nanoseconds) that any cpus has

used above quota in respective periods

---
 kernel/sched/core.c  | 13 ++++++++++---
 kernel/sched/fair.c  |  9 +++++++++
 kernel/sched/sched.h |  3 +++
 3 files changed, 22 insertions(+), 3 deletions(-)
kernel/sched/core.c +10 -3
index 20ffcc044134..d00b92712253 100644
@@ -10068,6 +10068,9 @@ static int cpu_cfs_stat_show(struct seq_file *sf, void *v)
 		seq_printf(sf, "wait_sum %llu\n", ws);
 	}
 
+	seq_printf(sf, "nr_bursts %d\n", cfs_b->nr_burst);
+	seq_printf(sf, "burst_time %llu\n", cfs_b->burst_time);
+
 	return 0;
 }
 #endif /* CONFIG_CFS_BANDWIDTH */
@@ -10164,16 +10167,20 @@ static int cpu_extra_stat_show(struct seq_file *sf,
 	{
 		struct task_group *tg = css_tg(css);
 		struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
-		u64 throttled_usec;
+		u64 throttled_usec, burst_usec;
 
 		throttled_usec = cfs_b->throttled_time;
 		do_div(throttled_usec, NSEC_PER_USEC);
+		burst_usec = cfs_b->burst_time;
+		do_div(burst_usec, NSEC_PER_USEC);
 
 		seq_printf(sf, "nr_periods %d\n"
 			   "nr_throttled %d\n"
-			   "throttled_usec %llu\n",
+			   "throttled_usec %llu\n"
+			   "nr_bursts %d\n"
+			   "burst_usec %llu\n",
 			   cfs_b->nr_periods, cfs_b->nr_throttled,
-			   throttled_usec);
+			   throttled_usec, cfs_b->nr_burst, burst_usec);
 	}
 #endif
 	return 0;
kernel/sched/fair.c +9 -0
index 44c452072a1b..464371f364f1 100644
@@ -4655,11 +4655,20 @@ static inline u64 sched_cfs_bandwidth_slice(void)
  */
 void __refill_cfs_bandwidth_runtime(struct cfs_bandwidth *cfs_b)
 {
+	s64 runtime;
+
 	if (unlikely(cfs_b->quota == RUNTIME_INF))
 		return;
 
 	cfs_b->runtime += cfs_b->quota;
+	runtime = cfs_b->runtime_snap - cfs_b->runtime;
+	if (runtime > 0) {
+		cfs_b->burst_time += runtime;
+		cfs_b->nr_burst++;
+	}
+
 	cfs_b->runtime = min(cfs_b->runtime, cfs_b->quota + cfs_b->burst);
+	cfs_b->runtime_snap = cfs_b->runtime;
 }
 
 static inline struct cfs_bandwidth *tg_cfs_bandwidth(struct task_group *tg)
kernel/sched/sched.h +3 -0
index 14a41a243f7b..80e4322727b4 100644
@@ -367,6 +367,7 @@ struct cfs_bandwidth {
 	u64			quota;
 	u64			runtime;
 	u64			burst;
+	u64			runtime_snap;
 	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
 };
 
Signature · 1 line
2.14.4.44.g2045bb6
reviewer Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH 1/2] sched/fair: Add cfs bandwidth burst statistics

Quoted 5 lines · Huaixin Chang

Two new statistics are introduced to show the internal of burst feature and explain why burst helps or not.

nr_bursts:  number of periods bandwidth burst occurs
burst_time: cumulative wall-time (in nanoseconds) that any cpus has
Quoted 7 lines

used above quota in respective periods

I know there's some worry about the overhead of a constantly increasing amount of statistics, but as far as the implementation of this goes, it looks good to me.

Quoted 90 lines
---
 kernel/sched/core.c  | 13 ++++++++++---
 kernel/sched/fair.c  |  9 +++++++++
 kernel/sched/sched.h |  3 +++
 3 files changed, 22 insertions(+), 3 deletions(-)
kernel/sched/core.c +10 -3
index 20ffcc044134..d00b92712253 100644
@@ -10068,6 +10068,9 @@ static int cpu_cfs_stat_show(struct seq_file *sf, void *v)
 		seq_printf(sf, "wait_sum %llu\n", ws);
 	}
 
+	seq_printf(sf, "nr_bursts %d\n", cfs_b->nr_burst);
+	seq_printf(sf, "burst_time %llu\n", cfs_b->burst_time);
+
 	return 0;
 }
 #endif /* CONFIG_CFS_BANDWIDTH */
@@ -10164,16 +10167,20 @@ static int cpu_extra_stat_show(struct seq_file *sf,
 	{
 		struct task_group *tg = css_tg(css);
 		struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
-		u64 throttled_usec;
+		u64 throttled_usec, burst_usec;
 
 		throttled_usec = cfs_b->throttled_time;
 		do_div(throttled_usec, NSEC_PER_USEC);
+		burst_usec = cfs_b->burst_time;
+		do_div(burst_usec, NSEC_PER_USEC);
 
 		seq_printf(sf, "nr_periods %d\n"
 			   "nr_throttled %d\n"
-			   "throttled_usec %llu\n",
+			   "throttled_usec %llu\n"
+			   "nr_bursts %d\n"
+			   "burst_usec %llu\n",
 			   cfs_b->nr_periods, cfs_b->nr_throttled,
-			   throttled_usec);
+			   throttled_usec, cfs_b->nr_burst, burst_usec);
 	}
 #endif
 	return 0;
kernel/sched/fair.c +9 -0
index 44c452072a1b..464371f364f1 100644
@@ -4655,11 +4655,20 @@ static inline u64 sched_cfs_bandwidth_slice(void)
  */
 void __refill_cfs_bandwidth_runtime(struct cfs_bandwidth *cfs_b)
 {
+	s64 runtime;
+
 	if (unlikely(cfs_b->quota == RUNTIME_INF))
 		return;
 
 	cfs_b->runtime += cfs_b->quota;
+	runtime = cfs_b->runtime_snap - cfs_b->runtime;
+	if (runtime > 0) {
+		cfs_b->burst_time += runtime;
+		cfs_b->nr_burst++;
+	}
+
 	cfs_b->runtime = min(cfs_b->runtime, cfs_b->quota + cfs_b->burst);
+	cfs_b->runtime_snap = cfs_b->runtime;
 }
 
 static inline struct cfs_bandwidth *tg_cfs_bandwidth(struct task_group *tg)
kernel/sched/sched.h +3 -0
index 14a41a243f7b..80e4322727b4 100644
@@ -367,6 +367,7 @@ struct cfs_bandwidth {
 	u64			quota;
 	u64			runtime;
 	u64			burst;
+	u64			runtime_snap;
 	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
 };
merge bot Applied
#3 lore raw

[tip: sched/core] sched/fair: Add cfs bandwidth burst statistics

In reply to Huaixin Chang
The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     9525616d056e29f7900796cb0c19b38ad274b0eb
Gitweb:        https://git.kernel.org/tip/9525616d056e29f7900796cb0c19b38ad274b0eb
Author:        Huaixin Chang <[email protected]>
AuthorDate:    Mon, 30 Aug 2021 11:22:14 +08:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Thu, 09 Sep 2021 11:27:32 +02:00

sched/fair: Add cfs bandwidth burst statistics

Two new statistics are introduced to show the internal of burst feature and explain why burst helps or not.

nr_bursts:  number of periods bandwidth burst occurs
burst_time: cumulative wall-time (in nanoseconds) that any cpus has

used above quota in respective periods

---
 kernel/sched/core.c  | 13 ++++++++++---
 kernel/sched/fair.c  |  9 +++++++++
 kernel/sched/sched.h |  3 +++
 3 files changed, 22 insertions(+), 3 deletions(-)
kernel/sched/core.c +10 -3
index 953ff36..2877138 100644
@@ -10244,6 +10244,9 @@ static int cpu_cfs_stat_show(struct seq_file *sf, void *v)
 		seq_printf(sf, "wait_sum %llu\n", ws);
 	}
 
+	seq_printf(sf, "nr_bursts %d\n", cfs_b->nr_burst);
+	seq_printf(sf, "burst_time %llu\n", cfs_b->burst_time);
+
 	return 0;
 }
 #endif /* CONFIG_CFS_BANDWIDTH */
@@ -10359,16 +10362,20 @@ static int cpu_extra_stat_show(struct seq_file *sf,
 	{
 		struct task_group *tg = css_tg(css);
 		struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
-		u64 throttled_usec;
+		u64 throttled_usec, burst_usec;
 
 		throttled_usec = cfs_b->throttled_time;
 		do_div(throttled_usec, NSEC_PER_USEC);
+		burst_usec = cfs_b->burst_time;
+		do_div(burst_usec, NSEC_PER_USEC);
 
 		seq_printf(sf, "nr_periods %d\n"
 			   "nr_throttled %d\n"
-			   "throttled_usec %llu\n",
+			   "throttled_usec %llu\n"
+			   "nr_bursts %d\n"
+			   "burst_usec %llu\n",
 			   cfs_b->nr_periods, cfs_b->nr_throttled,
-			   throttled_usec);
+			   throttled_usec, cfs_b->nr_burst, burst_usec);
 	}
 #endif
 	return 0;
kernel/sched/fair.c +9 -0
index b27ed8b..3594884 100644
@@ -4686,11 +4686,20 @@ static inline u64 sched_cfs_bandwidth_slice(void)
  */
 void __refill_cfs_bandwidth_runtime(struct cfs_bandwidth *cfs_b)
 {
+	s64 runtime;
+
 	if (unlikely(cfs_b->quota == RUNTIME_INF))
 		return;
 
 	cfs_b->runtime += cfs_b->quota;
+	runtime = cfs_b->runtime_snap - cfs_b->runtime;
+	if (runtime > 0) {
+		cfs_b->burst_time += runtime;
+		cfs_b->nr_burst++;
+	}
+
 	cfs_b->runtime = min(cfs_b->runtime, cfs_b->quota + cfs_b->burst);
+	cfs_b->runtime_snap = cfs_b->runtime;
 }
 
 static inline struct cfs_bandwidth *tg_cfs_bandwidth(struct task_group *tg)
kernel/sched/sched.h +3 -0
index 6b2d8b7..094ea86 100644
@@ -369,6 +369,7 @@ struct cfs_bandwidth {
 	u64			quota;
 	u64			runtime;
 	u64			burst;
+	u64			runtime_snap;
 	s64			hierarchical_quota;
 
 	u8			idle;
@@ -381,7 +382,9 @@ struct cfs_bandwidth {
 	/* Statistics: */
 	int			nr_periods;
 	int			nr_throttled;
+	int			nr_burst;
 	u64			throttled_time;
+	u64			burst_time;
 #endif
 };
 
merge bot Applied
#4 lore raw

[tip: sched/core] sched/fair: Add cfs bandwidth burst statistics

In reply to Huaixin Chang
The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     bcb1704a1ed2de580a46f28922e223a65f16e0f5
Gitweb:        https://git.kernel.org/tip/bcb1704a1ed2de580a46f28922e223a65f16e0f5
Author:        Huaixin Chang <[email protected]>
AuthorDate:    Mon, 30 Aug 2021 11:22:14 +08:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Tue, 05 Oct 2021 15:51:40 +02:00

sched/fair: Add cfs bandwidth burst statistics

Two new statistics are introduced to show the internal of burst feature and explain why burst helps or not.

nr_bursts:  number of periods bandwidth burst occurs
burst_time: cumulative wall-time (in nanoseconds) that any cpus has

used above quota in respective periods

---
 kernel/sched/core.c  | 13 ++++++++++---
 kernel/sched/fair.c  |  9 +++++++++
 kernel/sched/sched.h |  3 +++
 3 files changed, 22 insertions(+), 3 deletions(-)
kernel/sched/core.c +10 -3
index f963c81..ccb604a 100644
@@ -10406,6 +10406,9 @@ static int cpu_cfs_stat_show(struct seq_file *sf, void *v)
 		seq_printf(sf, "wait_sum %llu\n", ws);
 	}
 
+	seq_printf(sf, "nr_bursts %d\n", cfs_b->nr_burst);
+	seq_printf(sf, "burst_time %llu\n", cfs_b->burst_time);
+
 	return 0;
 }
 #endif /* CONFIG_CFS_BANDWIDTH */
@@ -10521,16 +10524,20 @@ static int cpu_extra_stat_show(struct seq_file *sf,
 	{
 		struct task_group *tg = css_tg(css);
 		struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
-		u64 throttled_usec;
+		u64 throttled_usec, burst_usec;
 
 		throttled_usec = cfs_b->throttled_time;
 		do_div(throttled_usec, NSEC_PER_USEC);
+		burst_usec = cfs_b->burst_time;
+		do_div(burst_usec, NSEC_PER_USEC);
 
 		seq_printf(sf, "nr_periods %d\n"
 			   "nr_throttled %d\n"
-			   "throttled_usec %llu\n",
+			   "throttled_usec %llu\n"
+			   "nr_bursts %d\n"
+			   "burst_usec %llu\n",
 			   cfs_b->nr_periods, cfs_b->nr_throttled,
-			   throttled_usec);
+			   throttled_usec, cfs_b->nr_burst, burst_usec);
 	}
 #endif
 	return 0;
kernel/sched/fair.c +9 -0
index 5457c80..fd41abe 100644
@@ -4715,11 +4715,20 @@ static inline u64 sched_cfs_bandwidth_slice(void)
  */
 void __refill_cfs_bandwidth_runtime(struct cfs_bandwidth *cfs_b)
 {
+	s64 runtime;
+
 	if (unlikely(cfs_b->quota == RUNTIME_INF))
 		return;
 
 	cfs_b->runtime += cfs_b->quota;
+	runtime = cfs_b->runtime_snap - cfs_b->runtime;
+	if (runtime > 0) {
+		cfs_b->burst_time += runtime;
+		cfs_b->nr_burst++;
+	}
+
 	cfs_b->runtime = min(cfs_b->runtime, cfs_b->quota + cfs_b->burst);
+	cfs_b->runtime_snap = cfs_b->runtime;
 }
 
 static inline struct cfs_bandwidth *tg_cfs_bandwidth(struct task_group *tg)
kernel/sched/sched.h +3 -0
index 15a8895..8712fc4 100644
@@ -369,6 +369,7 @@ struct cfs_bandwidth {
 	u64			quota;
 	u64			runtime;
 	u64			burst;
+	u64			runtime_snap;
 	s64			hierarchical_quota;
 
 	u8			idle;
@@ -381,7 +382,9 @@ struct cfs_bandwidth {
 	/* Statistics: */
 	int			nr_periods;
 	int			nr_throttled;
+	int			nr_burst;
 	u64			throttled_time;
+	u64			burst_time;
 #endif
 };
 
#5 lore raw

PATCH v2 2/2 sched/fair: Add document for burstable CFS bandwidth

In reply to Huaixin Chang

Basic description of usage and effect for CFS Bandwidth Control Burst.

---
 Documentation/admin-guide/cgroup-v2.rst |  8 ++++
 Documentation/scheduler/sched-bwc.rst   | 85 +++++++++++++++++++++++++++++----
 2 files changed, 83 insertions(+), 10 deletions(-)
Documentation/admin-guide/cgroup-v2.rst +8 -0
index 5c7377b5bd3e..f9d749d2daf2 100644
@@ -1016,6 +1016,8 @@ All time durations are in microseconds.
 	- nr_periods
 	- nr_throttled
 	- throttled_usec
+	- nr_bursts
+	- burst_usec
 
   cpu.weight
 	A read-write single value file which exists on non-root
@@ -1047,6 +1049,12 @@ All time durations are in microseconds.
 	$PERIOD duration.  "max" for $MAX indicates no limit.  If only
 	one number is written, $MAX is updated.
 
+  cpu.max.burst
+	A read-write single value file which exists on non-root
+	cgroups.  The default is "0".
+
+	The burst in the range [0, $MAX].
+
   cpu.pressure
 	A read-write nested-keyed file.
 
Documentation/scheduler/sched-bwc.rst +75 -10

130 lines not on this page · raw message

Signature · 1 line
2.14.4.44.g2045bb6
merge bot Applied
#6 lore raw

[tip: sched/core] sched/fair: Add document for burstable CFS bandwidth

The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     9de47777ee77c2b9bedf43ba92900b199cf1457e
Gitweb:        https://git.kernel.org/tip/9de47777ee77c2b9bedf43ba92900b199cf1457e
Author:        Huaixin Chang <[email protected]>
AuthorDate:    Mon, 30 Aug 2021 11:22:15 +08:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Thu, 09 Sep 2021 11:27:32 +02:00

sched/fair: Add document for burstable CFS bandwidth

Basic description of usage and effect for CFS Bandwidth Control Burst.

---
 Documentation/admin-guide/cgroup-v2.rst |  8 ++-
 Documentation/scheduler/sched-bwc.rst   | 84 +++++++++++++++++++++---
 2 files changed, 83 insertions(+), 9 deletions(-)
Documentation/admin-guide/cgroup-v2.rst +8 -0
index b1e81aa..4cee0f3 100644
@@ -1000,6 +1000,8 @@ All time durations are in microseconds.
 	- nr_periods
 	- nr_throttled
 	- throttled_usec
+	- nr_bursts
+	- burst_usec
 
   cpu.weight
 	A read-write single value file which exists on non-root
@@ -1031,6 +1033,12 @@ All time durations are in microseconds.
 	$PERIOD duration.  "max" for $MAX indicates no limit.  If only
 	one number is written, $MAX is updated.
 
+  cpu.max.burst
+	A read-write single value file which exists on non-root
+	cgroups.  The default is "0".
+
+	The burst in the range [0, $MAX].
+
   cpu.pressure
 	A read-write nested-keyed file.
 
Documentation/scheduler/sched-bwc.rst +75 -9

129 lines not on this page · raw message

merge bot Applied
#7 lore raw

[tip: sched/core] sched/fair: Add document for burstable CFS bandwidth

In reply to Huaixin Chang
The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     d73df887b6b8174dfbb7f5f878fbd1e0e2eb3f08
Gitweb:        https://git.kernel.org/tip/d73df887b6b8174dfbb7f5f878fbd1e0e2eb3f08
Author:        Huaixin Chang <[email protected]>
AuthorDate:    Mon, 30 Aug 2021 11:22:15 +08:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Tue, 05 Oct 2021 15:51:41 +02:00

sched/fair: Add document for burstable CFS bandwidth

Basic description of usage and effect for CFS Bandwidth Control Burst.

---
 Documentation/admin-guide/cgroup-v2.rst |  8 ++-
 Documentation/scheduler/sched-bwc.rst   | 84 +++++++++++++++++++++---
 2 files changed, 83 insertions(+), 9 deletions(-)
Documentation/admin-guide/cgroup-v2.rst +8 -0
index babbe04..d5b0e8a 100644
@@ -1016,6 +1016,8 @@ All time durations are in microseconds.
 	- nr_periods
 	- nr_throttled
 	- throttled_usec
+	- nr_bursts
+	- burst_usec
 
   cpu.weight
 	A read-write single value file which exists on non-root
@@ -1047,6 +1049,12 @@ All time durations are in microseconds.
 	$PERIOD duration.  "max" for $MAX indicates no limit.  If only
 	one number is written, $MAX is updated.
 
+  cpu.max.burst
+	A read-write single value file which exists on non-root
+	cgroups.  The default is "0".
+
+	The burst in the range [0, $MAX].
+
   cpu.pressure
 	A read-write nested-keyed file.
 
Documentation/scheduler/sched-bwc.rst +75 -9

129 lines not on this page · raw message

Reviewed-by on the v2 series
#9 lore raw
In reply to Huaixin Chang
Quoted 6 lines · Huaixin Chang

Changelog:
v2:
- Use burst_time in nanoseconds for cgroup1 interface, and burst_usec in microseconds for cgroup2 interface.
- Minor document adjustment.

Quoted 6 lines

v1 Link:
https://lore.kernel.org/lkml/[email protected]/

Huaixin Chang (2):
sched/fair: Add cfs bandwidth burst statistics sched/fair: Add document for burstable CFS bandwidth

#10 lore raw
In reply to Huaixin Chang

Hi,

I wonder how do these two patches look this time, from cfs_b's point of view. The statistics is simpler than before. And document is added too.

Quoted 24 lines · Huaixin Chang

Changelog:
v2:
- Use burst_time in nanoseconds for cgroup1 interface, and burst_usec in microseconds for cgroup2 interface.
- Minor document adjustment.

v1 Link:
https://lore.kernel.org/lkml/[email protected]/

Huaixin Chang (2):
sched/fair: Add cfs bandwidth burst statistics sched/fair: Add document for burstable CFS bandwidth

Documentation/admin-guide/cgroup-v2.rst |  8 ++++
Documentation/scheduler/sched-bwc.rst   | 85 +++++++++++++++++++++++++++++----
kernel/sched/core.c                     | 13 +++--
kernel/sched/fair.c                     |  9 ++++
kernel/sched/sched.h                    |  3 ++
5 files changed, 105 insertions(+), 13 deletions(-)
Signature · 1 line
2.14.4.44.g2045bb6