Skip to contentSkip to conversation

selftests: cgroup: enable the cpu controller in test_cpu

PATCH Applied Ren Tamura 2 participants 2 messages Sep 30

Subsystems (2)
lore
Share & tools
lore

Ren Tamura

author
#0 lore raw

PATCH 1/1 selftests: cgroup: enable the cpu controller in test_cpu

test_cpu uses cg_read_strstr() to check for "cpu" in the root cgroup's cgroup.subtree_control. The substring also matches "cpuset", so a hierarchy with only cpuset enabled skips writing "+cpu" during setup.

The tests then run without the required controller enabled and report failures. When cpu is unavailable in that hierarchy, the suite also reports failures instead of skipping.

Always write "+cpu" during setup and skip if the write fails. Enabling a controller that is already enabled is a no-op, so a separate presence check is unnecessary. This requires write access to cgroup.subtree_control even when cpu is already enabled.

Fixes 820a4f88ee46 ("cgroup: Add new test_cpu.c test suite in cgroup selftests")
Assisted-by LLM

---
Validation (2026-09-24, mainline 62f4c998b297): ran the full, unfiltered test_cpu binary as root on a freshly built mainline kernel in a four-vCPU KVM guest. With only cpuset enabled, the original reports two passes and seven failures; the modified binary passes all nine tests. With cpu already enabled, both pass all nine tests in the comparison with vCPUs pinned to separate physical cores. With cpu disabled at boot and only cpuset enabled, the original reports test failures while the modified binary skips with exit status 4.

The guest validation used a writable root cgroup.

LLM assistance: finding small cgroup fixes, drafting code and commit messages, and preparing validation.

 tools/testing/selftests/cgroup/test_cpu.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tools/testing/selftests/cgroup/test_cpu.c +2 -3
index 735a53bb222ba98812d5c6ace221c3154362d859..3456e3e988c68aa6105a0d862fdc51fa0cb10d6a 100644
@@ -835,9 +835,8 @@ int main(int argc, char *argv[])
 	if (cg_find_unified_root(root, sizeof(root), NULL))
 		ksft_exit_skip("cgroup v2 isn't mounted\n");
 
-	if (cg_read_strstr(root, "cgroup.subtree_control", "cpu"))
-		if (cg_write(root, "cgroup.subtree_control", "+cpu"))
-			ksft_exit_skip("Failed to set cpu controller\n");
+	if (cg_write(root, "cgroup.subtree_control", "+cpu"))
+		ksft_exit_skip("Failed to set cpu controller\n");
 
 	ksft_set_plan(ARRAY_SIZE(tests));
 	for (i = 0; i < ARRAY_SIZE(tests); i++) {

base-commit: 551c722f40809618230001baccf219193e22fc5a

maintainer Applied
#1 lore raw

Applied to cgroup/for-7.4 with the Fixes tag dropped and the subject capitalized.

Thanks.

--
tejun