mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] selftests: cgroup: enable the cpu controller in test_cpu
@ 2026-09-30  6:03 Ren Tamura
  0 siblings, 0 replies; only message in thread
From: Ren Tamura @ 2026-09-30  6:03 UTC (permalink / raw)
  To: tj; +Cc: hannes, mkoutny, shuah, void, cgroups, linux-kselftest, linux-kernel

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
Signed-off-by: Ren Tamura <ren.tamura.oss@gmail.com>
---
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(-)

diff --git a/tools/testing/selftests/cgroup/test_cpu.c b/tools/testing/selftests/cgroup/test_cpu.c
index 735a53bb222ba98812d5c6ace221c3154362d859..3456e3e988c68aa6105a0d862fdc51fa0cb10d6a 100644
--- a/tools/testing/selftests/cgroup/test_cpu.c
+++ b/tools/testing/selftests/cgroup/test_cpu.c
@@ -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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-30  6:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-30  6:03 [PATCH] selftests: cgroup: enable the cpu controller in test_cpu Ren Tamura

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®