Skip to contentSkip to conversation

cfs_bandwidth01 and CGroup API

PATCH New Richard Palethorpe 3 participants 9 messages Jun 1, 2021 – Jun 2, 2021 Library code

lore
Share & tools
lore
#0 lore raw

v3 cover cfs_bandwidth01 and CGroup API

Hello,

This adds a test scheduler test which uses the cpu controller.

Also included are some additions and fixes to the CGroup API related to the test.

V3:
* Reverse order of writing cpu.cfs_period_us and cpu.cfs_quota_us to fix V1.
* Add may_have_waiters to indicate we should try waking and cleaning up children during cleanup. At worst this can result in timeout warnings if there are less than 9 children waiting.
Which is probably better than failing to cleanup the CGroups.

V2:
* Simpler check for unrecognised controller name
* Dropped whitespace patch which was already merged
* Moved subgroup creation to setup. Otherwise it leaks memory between iterations. Although the test still worked because it doesn't error if the group already exists.

Richard Palethorpe (6):
API/cgroups: Allow fetching of CGroup name
API/cgroups: Remove obsolete function in API
API/cgroups: Add cpu controller
API/cgroups: Auto add controllers to subtree_control in new subgroup API/cgroups: tst_require fail gracefully with unknown controller sched/cgroup: Add cfs_bandwidth01

 include/tst_cgroup.h                          |   4 +
 lib/tst_cgroup.c                              |  58 ++++--
 runtest/sched                                 |   1 +
 .../kernel/sched/cfs-scheduler/.gitignore     |   1 +
 testcases/kernel/sched/cfs-scheduler/Makefile |   4 +-
 .../sched/cfs-scheduler/cfs_bandwidth01.c     | 184 ++++++++++++++++++
 6 files changed, 236 insertions(+), 16 deletions(-)
 create mode 100644 testcases/kernel/sched/cfs-scheduler/cfs_bandwidth01.c
Signature · 1 line
2.31.1
#1 lore raw

PATCH v3 1/6 API/cgroups: Allow fetching of CGroup name

Lets the test author get the name of a CGroup.

---
 include/tst_cgroup.h | 4 ++++
 lib/tst_cgroup.c     | 5 +++++
 2 files changed, 9 insertions(+)
include/tst_cgroup.h +4 -0
index d4c93db79..de72645bc 100644
@@ -133,6 +133,10 @@ struct tst_cgroup_group *
 tst_cgroup_group_mk(const struct tst_cgroup_group *const parent,
 		    const char *const group_name)
 		    __attribute__ ((nonnull, warn_unused_result));
+const char *
+tst_cgroup_group_name(const struct tst_cgroup_group *const cg)
+		      __attribute__ ((nonnull, warn_unused_result));
+
 /* Remove a descendant CGroup */
 struct tst_cgroup_group *
 tst_cgroup_group_rm(struct tst_cgroup_group *const cg)
lib/tst_cgroup.c +5 -0
index 1e036d3c3..793a712e1 100644
@@ -855,6 +855,11 @@ tst_cgroup_group_mk(const struct tst_cgroup_group *const parent,
 	return cg;
 }
 
+const char *tst_cgroup_group_name(const struct tst_cgroup_group *const cg)
+{
+	return cg->group_name;
+}
+
 struct tst_cgroup_group *tst_cgroup_group_rm(struct tst_cgroup_group *const cg)
 {
 	struct cgroup_dir **dir;
Signature · 1 line
2.31.1
#2 lore raw

PATCH v3 2/6 API/cgroups: Remove obsolete function in API

In reply to Richard Palethorpe
---
 lib/tst_cgroup.c | 6 ------
 1 file changed, 6 deletions(-)
lib/tst_cgroup.c +0 -6
index 793a712e1..8fd5ab288 100644
@@ -225,12 +225,6 @@ static void add_ctrl(uint32_t *const ctrl_field,
 	*ctrl_field |= 1 << ctrl->ctrl_indx;
 }
 
-__attribute__ ((warn_unused_result))
-struct cgroup_root *tst_cgroup_root_get(void)
-{
-	return roots[0].ver ? roots : roots + 1;
-}
-
 static int cgroup_v2_mounted(void)
 {
 	return !!roots[0].ver;
Signature · 1 line
2.31.1
#3 lore raw

PATCH v3 3/6 API/cgroups: Add cpu controller

In reply to Richard Palethorpe
---
 lib/tst_cgroup.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
lib/tst_cgroup.c +17 -1
index 8fd5ab288..0b71d4eed 100644
@@ -82,7 +82,8 @@ struct cgroup_root {
 /* Controller sub-systems */
 enum cgroup_ctrl_indx {
 	CTRL_MEMORY = 1,
-	CTRL_CPUSET = 2,
+	CTRL_CPU,
+	CTRL_CPUSET,
 };
 #define CTRLS_MAX CTRL_CPUSET
 
@@ -162,6 +163,18 @@ static const files_t memory_ctrl_files = {
 	{ }
 };
 
+static const files_t cpu_ctrl_files = {
+	/* The V1 quota and period files were combined in the V2 max
+	 * file. The quota is in the first column and if we just print
+	 * a single value to the file, it will be treated as the
+	 * quota. To get or set the period we need to branch on the
+	 * API version.
+	 */
+	{ "cpu.max", "cpu.cfs_quota_us", CTRL_CPU },
+	{ "cpu.cfs_period_us", "cpu.cfs_period_us", CTRL_CPU },
+	{ }
+};
+
 static const files_t cpuset_ctrl_files = {
 	{ "cpuset.cpus", "cpuset.cpus", CTRL_CPUSET },
 	{ "cpuset.mems", "cpuset.mems", CTRL_CPUSET },
@@ -174,6 +187,9 @@ static struct cgroup_ctrl controllers[] = {
 	[CTRL_MEMORY] = {
 		"memory", memory_ctrl_files, CTRL_MEMORY, NULL, 0
 	},
+	[CTRL_CPU] = {
+		"cpu", cpu_ctrl_files, CTRL_CPU, NULL, 0
+	},
 	[CTRL_CPUSET] = {
 		"cpuset", cpuset_ctrl_files, CTRL_CPUSET, NULL, 0
 	},
Signature · 1 line
2.31.1
#4 lore raw

PATCH v3 4/6 API/cgroups: Auto add controllers to subtree_control in new subgroup

In reply to Richard Palethorpe

This is what we have always wanted so far. If we do not want to do it on a new test then a new config option can be added during require.

---
 lib/tst_cgroup.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)
lib/tst_cgroup.c +16 -7
index 0b71d4eed..74746f13e 100644
@@ -826,19 +826,28 @@ static void cgroup_group_init(struct tst_cgroup_group *const cg,
 	strcpy(cg->group_name, group_name);
 }
 
-__attribute__ ((nonnull))
-static void cgroup_group_add_dir(struct tst_cgroup_group *const cg,
+__attribute__((nonnull (2, 3)))
+static void cgroup_group_add_dir(const struct tst_cgroup_group *const parent,
+				 struct tst_cgroup_group *const cg,
 				 struct cgroup_dir *const dir)
 {
 	const struct cgroup_ctrl *ctrl;
 	int i;
 
-	if (dir->dir_root->ver == TST_CGROUP_V2)
+	if (dir->dir_root->ver != TST_CGROUP_V1)
 		cg->dirs_by_ctrl[0] = dir;
 
 	for_each_ctrl(ctrl) {
-		if (has_ctrl(dir->ctrl_field, ctrl))
-			cg->dirs_by_ctrl[ctrl->ctrl_indx] = dir;
+		if (!has_ctrl(dir->ctrl_field, ctrl))
+			continue;
+
+		cg->dirs_by_ctrl[ctrl->ctrl_indx] = dir;
+
+		if (!parent || dir->dir_root->ver == TST_CGROUP_V1)
+			continue;
+
+		SAFE_CGROUP_PRINTF(parent, "cgroup.subtree_control",
+				   "+%s", ctrl->ctrl_name);
 	}
 
 	for (i = 0; cg->dirs[i]; i++);
@@ -859,7 +868,7 @@ tst_cgroup_group_mk(const struct tst_cgroup_group *const parent,
 	for_each_dir(parent, 0, dir) {
 		new_dir = SAFE_MALLOC(sizeof(*new_dir));
 		cgroup_dir_mk(*dir, group_name, new_dir);
-		cgroup_group_add_dir(cg, new_dir);
+		cgroup_group_add_dir(parent, cg, new_dir);
 	}
 
 	return cg;
@@ -1023,7 +1032,7 @@ static struct tst_cgroup_group *cgroup_group_from_roots(const size_t tree_off)
 		dir = (typeof(dir))(((char *)root) + tree_off);
 
 		if (dir->ctrl_field)
-			cgroup_group_add_dir(cg, dir);
+			cgroup_group_add_dir(NULL, cg, dir);
 	}
 
 	if (cg->dirs[0]) {
Signature · 1 line
2.31.1
#5 lore raw

PATCH v3 5/6 API/cgroups: tst_require fail gracefully with unknown controller

In reply to Richard Palethorpe
---
 lib/tst_cgroup.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/tst_cgroup.c +6 -0
index 74746f13e..6d94ea41c 100644
@@ -599,6 +599,12 @@ void tst_cgroup_require(const char *const ctrl_name,
 	struct cgroup_ctrl *const ctrl = cgroup_find_ctrl(ctrl_name);
 	struct cgroup_root *root;
 
+	if (!ctrl) {
+		tst_brk(TBROK, "'%s' controller is unknown to LTP", ctrl_name);
+		tst_brk(TBROK, "Calling %s in cleanup?", __func__);
+		return;
+	}
+
 	if (!options)
 		options = &default_opts;
 
Signature · 1 line
2.31.1
#6 lore raw

PATCH v3 6/6 sched/cgroup: Add cfs_bandwidth01

In reply to Richard Palethorpe
---
 runtest/sched                                 |   1 +
 .../kernel/sched/cfs-scheduler/.gitignore     |   1 +
 testcases/kernel/sched/cfs-scheduler/Makefile |   4 +-
 .../sched/cfs-scheduler/cfs_bandwidth01.c     | 184 ++++++++++++++++++
 4 files changed, 188 insertions(+), 2 deletions(-)
 create mode 100644 testcases/kernel/sched/cfs-scheduler/cfs_bandwidth01.c
runtest/sched +1 -0
index bfc4f2711..592898723 100644
@@ -6,6 +6,7 @@ pth_str03 pth_str03
 time-schedule01		time-schedule
 trace_sched01		trace_sched -c 1
 
+cfs_bandwidth01 cfs_bandwidth01 -i 5
 hackbench01 hackbench 50 process 1000
 hackbench02 hackbench 20 thread 1000
 
testcases/kernel/sched/cfs-scheduler/.gitignore +1 -0
index db2759e4f..c5dacd6ef 100644
@@ -1 +1,2 @@
 /hackbench
+cfs_bandwidth01
testcases/kernel/sched/cfs-scheduler/Makefile +2 -2
index aa3bf8459..2ffe1f7f9 100644
@@ -18,8 +18,8 @@
 
 top_srcdir		?= ../../../..
 
-include $(top_srcdir)/include/mk/env_pre.mk
+include $(top_srcdir)/include/mk/testcases.mk
 
-LDLIBS			+= -lpthread
+hackbench: LDLIBS			+= -lpthread
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/sched/cfs-scheduler/cfs_bandwidth01.c new file +184 -0

184 lines not on this page · raw message

Signature · 1 line
2.31.1
#7 lore raw

v3 cover cfs_bandwidth01 and CGroup API

In reply to Richard Palethorpe
Quoted 11 lines

This adds a test scheduler test which uses the cpu controller.

Also included are some additions and fixes to the CGroup API related to the test.

V3:
* Reverse order of writing cpu.cfs_period_us and cpu.cfs_quota_us to fix V1.
* Add may_have_waiters to indicate we should try waking and cleaning up children during cleanup. At worst this can result in timeout warnings if there are less than 9 children waiting.
Which is probably better than failing to cleanup the CGroups.

I helped to test the patchset and push. Thanks~

Signature · 2 lines
Regards,
Li Wang
#8 lore raw

v3 cover cfs_bandwidth01 and CGroup API

Hello Li,

Quoted 5 lines · Li Wang
Quoted 5 lines

This adds a test scheduler test which uses the cpu controller.

Also included are some additions and fixes to the CGroup API related to the test.

Quoted 8 lines
Quoted 6 lines

V3:
* Reverse order of writing cpu.cfs_period_us and cpu.cfs_quota_us to fix V1.
* Add may_have_waiters to indicate we should try waking and cleaning up children during cleanup. At worst this can result in timeout warnings if there are less than 9 children waiting.
Which is probably better than failing to cleanup the CGroups.

I helped to test the patchset and push. Thanks~

Much thanks!

Signature · 2 lines
Thank you,
Richard.