This extends the cgroup v2 testing framework in selftests to validate the newly added Dynamic Housekeeping Management (DHM) cpuset interface: `cpuset.housekeeping.cpus` and `cpuset.housekeeping.smt_aware`.
The `test_cpuset_housekeeping` functional test verifies: - Validation of DHM's SMT safety guard (`cpuset.housekeeping.smt_aware`) by ensuring writing to it behaves as expected. - Basic read and write capabilities of `cpuset.housekeeping.cpus` using the base CPU mask. If the DHM functionality is not present in the kernel, the selftest skips gracefully. Signed-off-by: Qiliang Yuan <[email protected]> --- tools/testing/selftests/cgroup/test_cpuset.c | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tools/testing/selftests/cgroup/test_cpuset.c b/tools/testing/selftests/cgroup/test_cpuset.c index c5cf8b56ceb8f..b2a032be4407a 100644 --- a/tools/testing/selftests/cgroup/test_cpuset.c +++ b/tools/testing/selftests/cgroup/test_cpuset.c @@ -232,6 +232,41 @@ static int test_cpuset_perms_subtree(const char *root) return ret; } +static int test_cpuset_housekeeping(const char *root) +{ + char buf[PAGE_SIZE]; + int ret = KSFT_FAIL; + + /* If the kernel doesn't have DHM patch, skip */ + if (cg_read(root, "cpuset.housekeeping.cpus", buf, sizeof(buf))) + return KSFT_SKIP; + + /* Test writing 1 and 0 to smt_aware */ + if (cg_write(root, "cpuset.housekeeping.smt_aware", "1")) + goto cleanup; + + if (cg_read_strstr(root, "cpuset.housekeeping.smt_aware", "1")) + goto cleanup; + + if (cg_write(root, "cpuset.housekeeping.smt_aware", "0")) + goto cleanup; + + if (cg_read_strstr(root, "cpuset.housekeeping.smt_aware", "0")) + goto cleanup; + + /* Read root cpuset.cpus.effective */ + if (cg_read(root, "cpuset.cpus.effective", buf, sizeof(buf))) + goto cleanup; + + /* Write it back to housekeeping.cpus */ + if (cg_write(root, "cpuset.housekeeping.cpus", buf)) + goto cleanup; + + ret = KSFT_PASS; + +cleanup: + return ret; +} #define T(x) { x, #x } struct cpuset_test { @@ -241,6 +276,7 @@ struct cpuset_test { T(test_cpuset_perms_object_allow), T(test_cpuset_perms_object_deny), T(test_cpuset_perms_subtree), + T(test_cpuset_housekeeping), }; #undef T -- 2.43.0

