Skip to contentSkip to conversation

cgroup, sched: cgroup2 interface for CPU controller (on basic acct)

PATCH Applied Tejun Heo 2 participants 6 messages Sep 25, 2017 – Sep 29, 2017

Subsystems (3)
lore
Share & tools
lore

Tejun Heo

author maintainer
#0 lore raw

PATCH 1/1 cgroup, sched: cgroup2 interface for CPU controller (on basic acct)

Hello,

(Rebased on cgroup/for-4.15, no real changes. Once acked, I think
it'd be easiest to route these through the cgroup branch; alternatively, we can pull cgroup/for-4.15 to a sched branch and apply these there.)

These are two patches to implement the cgroup2 CPU controller interface. Changes from the last revision[L].

* Updated on top of the cgroup2 basic resource accounting patchset[B] and now uses cgroup2's CPU accounting instead of cpuacct as stat source.

* cpuacct is no longer necessary and not converted.

This patchset contains the following two patches.

0001-sched-Misc-preps-for-cgroup-unified-hierarchy-interf.patch 0002-sched-Implement-interface-for-cgroup-unified-hierarc.patch

It's on top of the cgroup2 basic resource accounting patchset, which has been merged to cgroup/for-4.15, and available in the following git branch.

git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git review-cgroup2-cpu-on-basic-acct

diffstat follows. Thanks.

 Documentation/cgroup-v2.txt |   36 ++------
 kernel/sched/core.c         |  179 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 187 insertions(+), 28 deletions(-)

--
tejun

[L] http://lkml.kernel.org/r/20170720184808.1433868-1-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org
[B] http://lkml.kernel.org/r/20170811163754.3939102-1-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org

author maintainer
#1 lore raw

PATCH 1/2 sched: Misc preps for cgroup unified hierarchy interface

Make the following changes in preparation for the cpu controller interface implementation for cgroup2. This patch doesn't cause any functional differences.

* s/cpu_stats_show()/cpu_cfs_stat_show()/

* s/cpu_files/cpu_legacy_files/

v2: Dropped cpuacct changes as it won't be used by cpu controller
interface anymore.

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Li Zefan <[email protected]>
Cc Johannes Weiner <[email protected]>
---
 kernel/sched/core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/sched/core.c +4 -4
index 18a6966..6815fa4 100644
@@ -6599,7 +6599,7 @@ static int __cfs_schedulable(struct task_group *tg, u64 period, u64 quota)
 	return ret;
 }
 
-static int cpu_stats_show(struct seq_file *sf, void *v)
+static int cpu_cfs_stat_show(struct seq_file *sf, void *v)
 {
 	struct task_group *tg = css_tg(seq_css(sf));
 	struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
@@ -6639,7 +6639,7 @@ static u64 cpu_rt_period_read_uint(struct cgroup_subsys_state *css,
 }
 #endif /* CONFIG_RT_GROUP_SCHED */
 
-static struct cftype cpu_files[] = {
+static struct cftype cpu_legacy_files[] = {
 #ifdef CONFIG_FAIR_GROUP_SCHED
 	{
 		.name = "shares",
@@ -6660,7 +6660,7 @@ static struct cftype cpu_files[] = {
 	},
 	{
 		.name = "stat",
-		.seq_show = cpu_stats_show,
+		.seq_show = cpu_cfs_stat_show,
 	},
 #endif
 #ifdef CONFIG_RT_GROUP_SCHED
@@ -6686,7 +6686,7 @@ struct cgroup_subsys cpu_cgrp_subsys = {
 	.fork		= cpu_cgroup_fork,
 	.can_attach	= cpu_cgroup_can_attach,
 	.attach		= cpu_cgroup_attach,
-	.legacy_cftypes	= cpu_files,
+	.legacy_cftypes	= cpu_legacy_files,
 	.early_init	= true,
 };
 
Signature · 1 line
2.9.5
author maintainer
#2 lore raw

PATCH 2/2 sched: Implement interface for cgroup unified hierarchy

In reply to Tejun Heo

There are a couple interface issues which can be addressed in cgroup2 interface.

* Stats from cpuacct being reported separately from the cpu stats.

* Use of different time units. Writable control knobs use microseconds, some stat fields use nanoseconds while other cpuacct stat fields use centiseconds.

* Control knobs which can't be used in the root cgroup still show up in the root.

* Control knob names and semantics aren't consistent with other controllers.

This patchset implements cpu controller's interface on cgroup2 which adheres to the controller file conventions described in Documentation/cgroups/cgroup-v2.txt. Overall, the following changes are made.

* cpuacct is implictly enabled and disabled by cpu and its information is reported through "cpu.stat" which now uses microseconds for all time durations. All time duration fields now have "_usec" appended to them for clarity.

Note that cpuacct.usage_percpu is currently not included in "cpu.stat". If this information is actually called for, it will be added later.

* "cpu.shares" is replaced with "cpu.weight" and operates on the standard scale defined by CGROUP_WEIGHT_MIN/DFL/MAX (1, 100, 10000). The weight is scaled to scheduler weight so that 100 maps to 1024 and the ratio relationship is preserved - if weight is W and its scaled value is S, W / 100 == S / 1024. While the mapped range is a bit smaller than the orignal scheduler weight range, the dead zones on both sides are relatively small and covers wider range than the nice value mappings. This file doesn't make sense in the root cgroup and isn't created on root.

* "cpu.weight.nice" is added. When read, it reads back the nice value which is closest to the current "cpu.weight". When written, it sets "cpu.weight" to the weight value which matches the nice value. This makes it easy to configure cgroups when they're competing against threads in threaded subtrees.

* "cpu.cfs_quota_us" and "cpu.cfs_period_us" are replaced by "cpu.max" which contains both quota and period.

v4: - Use cgroup2 basic usage stat as the information source instead
of cpuacct.

v3: - Added "cpu.weight.nice" to allow using nice values when
configuring the weight. The feature is requested by PeterZ.
- Merge the patch to enable threaded support on cpu and cpuacct.
- Dropped the bits about getting rid of cpuacct from patch description as there is a pretty strong case for making cpuacct an implicit controller so that basic cpu usage stats are always available.
- Documentation updated accordingly. "cpu.rt.max" section is dropped for now.

v2: - cpu_stats_show() was incorrectly using CONFIG_FAIR_GROUP_SCHED
for CFS bandwidth stats and also using raw division for u64. Use CONFIG_CFS_BANDWITH and do_div() instead. "cpu.rt.max" is not included yet.

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Li Zefan <[email protected]>
Cc Johannes Weiner <[email protected]>
---
 Documentation/cgroup-v2.txt |  36 ++++------
 kernel/sched/core.c         | 171 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 183 insertions(+), 24 deletions(-)
Documentation/cgroup-v2.txt +12 -24
index 3f82169..0bbdc72 100644
@@ -902,10 +902,6 @@ Controllers
 CPU
 ---
 
-.. note::
-
-	The interface for the cpu controller hasn't been merged yet
-
 The "cpu" controllers regulates distribution of CPU cycles.  This
 controller implements weight and absolute bandwidth limit models for
 normal scheduling policy and absolute bandwidth allocation model for
@@ -935,6 +931,18 @@ All time durations are in microseconds.
 
 	The weight in the range [1, 10000].
 
+  cpu.weight.nice
+	A read-write single value file which exists on non-root
+	cgroups.  The default is "0".
+
+	The nice value is in the range [-20, 19].
+
+	This interface file is an alternative interface for
+	"cpu.weight" and allows reading and setting weight using the
+	same values used by nice(2).  Because the range is smaller and
+	granularity is coarser for the nice values, the read value is
+	the closest approximation of the current weight.
+
   cpu.max
 	A read-write two value file which exists on non-root cgroups.
 	The default is "max 100000".
@@ -947,26 +955,6 @@ All time durations are in microseconds.
 	$PERIOD duration.  "max" for $MAX indicates no limit.  If only
 	one number is written, $MAX is updated.
 
-  cpu.rt.max
-	.. note::
-
-	   The semantics of this file is still under discussion and the
-	   interface hasn't been merged yet
-
-	A read-write two value file which exists on all cgroups.
-	The default is "0 100000".
-
-	The maximum realtime runtime allocation.  Over-committing
-	configurations are disallowed and process migrations are
-	rejected if not enough bandwidth is available.  It's in the
-	following format::
-
-	  $MAX $PERIOD
-
-	which indicates that the group may consume upto $MAX in each
-	$PERIOD duration.  If only one number is written, $MAX is
-	updated.
-
 
 Memory
 ------
kernel/sched/core.c +171 -0

184 lines not on this page · raw message

Signature · 1 line
2.9.5
author maintainer
#3 lore raw
In reply to Tejun Heo
Quoted 2 lines · Tejun Heo

These are two patches to implement the cgroup2 CPU controller interface. Changes from the last revision[L].

Peter, Ping.

Thanks.

Signature · 1 line
tejun
maintainer Acked-by on v1 1/1
#4 lore raw
In reply to Tejun Heo
Quoted 25 lines · Tejun Heo

Hello,

(Rebased on cgroup/for-4.15, no real changes. Once acked, I think
it'd be easiest to route these through the cgroup branch; alternatively, we can pull cgroup/for-4.15 to a sched branch and apply these there.)

These are two patches to implement the cgroup2 CPU controller interface. Changes from the last revision[L].

* Updated on top of the cgroup2 basic resource accounting patchset[B] and now uses cgroup2's CPU accounting instead of cpuacct as stat source.

* cpuacct is no longer necessary and not converted.

This patchset contains the following two patches.

0001-sched-Misc-preps-for-cgroup-unified-hierarchy-interf.patch 0002-sched-Implement-interface-for-cgroup-unified-hierarc.patch

It's on top of the cgroup2 basic resource accounting patchset, which has been merged to cgroup/for-4.15, and available in the following git branch.

Quoted 7 lines

git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git review-cgroup2-cpu-on-basic-acct

diffstat follows. Thanks.

 Documentation/cgroup-v2.txt |   36 ++------
 kernel/sched/core.c         |  179 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 187 insertions(+), 28 deletions(-)
author maintainer Applied
#5 lore raw
In reply to Tejun Heo
Quoted 9 lines · Tejun Heo

Hello,

(Rebased on cgroup/for-4.15, no real changes. Once acked, I think
it'd be easiest to route these through the cgroup branch; alternatively, we can pull cgroup/for-4.15 to a sched branch and apply these there.)

These are two patches to implement the cgroup2 CPU controller interface. Changes from the last revision[L].

Applied to cgroup/for-4.15.

Thanks.

Signature · 1 line
tejun