selftests: cgroup: enable the cpu controller in test_cpu
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.
---
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
@@ -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
Applied to cgroup/for-7.4 with the Fixes tag dropped and the subject capitalized.
Thanks.
--
tejun