* [PATCH 1/2] selftests/cgroup: remove unused user_usec read in test_cpucg_nice
2026-07-29 10:04 [PATCH 0/2] selftests/cgroup: misc cleanups for test_cpu.c Shaojie Sun
@ 2026-07-29 10:04 ` Shaojie Sun
2026-07-29 11:58 ` Michal Koutný
2026-07-29 10:04 ` [PATCH 2/2] selftests/cgroup: write explicit period to cpu.max in max tests Shaojie Sun
1 sibling, 1 reply; 5+ messages in thread
From: Shaojie Sun @ 2026-07-29 10:04 UTC (permalink / raw)
To: tj, hannes, mkoutny, shuah
Cc: cgroups, linux-kselftest, linux-kernel, Shaojie Sun
In test_cpucg_nice, after the child process exits, user_usec is read
from cpu.stat but never used. Only nice_usec is validated against the
expected value. Remove this redundant read.
Signed-off-by: Shaojie Sun <sunshaojie@kylinos.cn>
---
tools/testing/selftests/cgroup/test_cpu.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/tools/testing/selftests/cgroup/test_cpu.c b/tools/testing/selftests/cgroup/test_cpu.c
index 7a40d76b9548..fe637e1d2fcd 100644
--- a/tools/testing/selftests/cgroup/test_cpu.c
+++ b/tools/testing/selftests/cgroup/test_cpu.c
@@ -289,7 +289,6 @@ static int test_cpucg_nice(const char *root)
if (!WIFEXITED(status))
goto cleanup;
- user_usec = cg_read_key_long(cpucg, "cpu.stat", "user_usec");
nice_usec = cg_read_key_long(cpucg, "cpu.stat", "nice_usec");
if (!values_close_report(nice_usec, expected_nice_usec, 1))
goto cleanup;
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] selftests/cgroup: write explicit period to cpu.max in max tests
2026-07-29 10:04 [PATCH 0/2] selftests/cgroup: misc cleanups for test_cpu.c Shaojie Sun
2026-07-29 10:04 ` [PATCH 1/2] selftests/cgroup: remove unused user_usec read in test_cpucg_nice Shaojie Sun
@ 2026-07-29 10:04 ` Shaojie Sun
2026-07-29 11:53 ` Michal Koutný
1 sibling, 1 reply; 5+ messages in thread
From: Shaojie Sun @ 2026-07-29 10:04 UTC (permalink / raw)
To: tj, hannes, mkoutny, shuah
Cc: cgroups, linux-kselftest, linux-kernel, Shaojie Sun
The cpu.max interface accepts "quota period" as two values, but
test_cpucg_max and test_cpucg_max_nested only wrote the quota,
relying on the kernel default period of 100ms. Since the test
duration is exactly divisible by the default period (1s / 100ms
= 10, no remainder), the remainder calculation was effectively
dead code.
Write both values explicitly so that the period can be easily
adjusted for testing purposes and the remainder logic becomes
genuinely useful.
While at it, rename misleading variable names:
- default_period_usec -> period_usec (no longer relying on a
kernel default, as it is now explicitly written to cpu.max)
- quota_buf -> max_param_buf (since the buffer holds both quota
and period)
Signed-off-by: Shaojie Sun <sunshaojie@kylinos.cn>
---
tools/testing/selftests/cgroup/test_cpu.c | 26 ++++++++++++-----------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/tools/testing/selftests/cgroup/test_cpu.c b/tools/testing/selftests/cgroup/test_cpu.c
index fe637e1d2fcd..10f9254cd08e 100644
--- a/tools/testing/selftests/cgroup/test_cpu.c
+++ b/tools/testing/selftests/cgroup/test_cpu.c
@@ -646,15 +646,16 @@ static int test_cpucg_max(const char *root)
{
int ret = KSFT_FAIL;
long quota_usec = 1000;
- long default_period_usec = 100000; /* cpu.max's default period */
+ long period_usec = 100000;
long duration_seconds = 1;
long duration_usec = duration_seconds * USEC_PER_SEC;
long usage_usec, n_periods, remainder_usec, expected_usage_usec;
char *cpucg;
- char quota_buf[32];
+ char max_param_buf[32];
- snprintf(quota_buf, sizeof(quota_buf), "%ld", quota_usec);
+ snprintf(max_param_buf, sizeof(max_param_buf), "%ld %ld", quota_usec,
+ period_usec);
cpucg = cg_name(root, "cpucg_test");
if (!cpucg)
@@ -663,7 +664,7 @@ static int test_cpucg_max(const char *root)
if (cg_create(cpucg))
goto cleanup;
- if (cg_write(cpucg, "cpu.max", quota_buf))
+ if (cg_write(cpucg, "cpu.max", max_param_buf))
goto cleanup;
struct cpu_hog_func_param param = {
@@ -685,8 +686,8 @@ static int test_cpucg_max(const char *root)
* The following calculation applies only since
* the cpu hog is set to run as per wall-clock time
*/
- n_periods = duration_usec / default_period_usec;
- remainder_usec = duration_usec - n_periods * default_period_usec;
+ n_periods = duration_usec / period_usec;
+ remainder_usec = duration_usec - n_periods * period_usec;
expected_usage_usec
= n_periods * quota_usec + MIN(remainder_usec, quota_usec);
@@ -710,15 +711,16 @@ static int test_cpucg_max_nested(const char *root)
{
int ret = KSFT_FAIL;
long quota_usec = 1000;
- long default_period_usec = 100000; /* cpu.max's default period */
+ long period_usec = 100000;
long duration_seconds = 1;
long duration_usec = duration_seconds * USEC_PER_SEC;
long usage_usec, n_periods, remainder_usec, expected_usage_usec;
char *parent, *child;
- char quota_buf[32];
+ char max_param_buf[32];
- snprintf(quota_buf, sizeof(quota_buf), "%ld", quota_usec);
+ snprintf(max_param_buf, sizeof(max_param_buf), "%ld %ld", quota_usec,
+ period_usec);
parent = cg_name(root, "cpucg_parent");
child = cg_name(parent, "cpucg_child");
@@ -734,7 +736,7 @@ static int test_cpucg_max_nested(const char *root)
if (cg_create(child))
goto cleanup;
- if (cg_write(parent, "cpu.max", quota_buf))
+ if (cg_write(parent, "cpu.max", max_param_buf))
goto cleanup;
struct cpu_hog_func_param param = {
@@ -756,8 +758,8 @@ static int test_cpucg_max_nested(const char *root)
* The following calculation applies only since
* the cpu hog is set to run as per wall-clock time
*/
- n_periods = duration_usec / default_period_usec;
- remainder_usec = duration_usec - n_periods * default_period_usec;
+ n_periods = duration_usec / period_usec;
+ remainder_usec = duration_usec - n_periods * period_usec;
expected_usage_usec
= n_periods * quota_usec + MIN(remainder_usec, quota_usec);
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread