* [Devel] [PATCH hci-8.1] selftests/cgroup: Pin the hogs of test_cpucg_weight_overprovisioned
@ 2026-11-12 4:23 Eva Kurchatova
2026-11-12 4:27 ` no-reply
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Eva Kurchatova @ 2026-11-12 4:23 UTC (permalink / raw)
To: khorenko; +Cc: devel
The test runs one hog thread per CPU in each of three cgroups weighted
1:2:3 and expects their CPU time in the same ratio. That holds when
each CPU runs one hog of every cgroup. On a NUMA machine the load
balancer leaves them less evenly spread, and the heaviest cgroup can
fall short of the tolerance.
Pin the hogs of each cgroup one per CPU: the test checks the weights,
not the load balancer.
Fixes: 6376b22cd0a3 ("cgroup: Add test_cpucg_weight_overprovisioned() testcase")
https://virtuozzo.atlassian.net/browse/VSTOR-152674
Feature: fix selftests
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/testing/selftests/cgroup/test_cpu.c | 31 +++++++++++++++++++----
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/cgroup/test_cpu.c b/tools/testing/selftests/cgroup/test_cpu.c
index a2b50af8e9ee..3385e75eed81 100644
--- a/tools/testing/selftests/cgroup/test_cpu.c
+++ b/tools/testing/selftests/cgroup/test_cpu.c
@@ -6,6 +6,7 @@
#include <sys/wait.h>
#include <errno.h>
#include <pthread.h>
+#include <sched.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
@@ -30,6 +31,7 @@ struct cpu_hog_func_param {
int nprocs;
struct timespec ts;
enum hog_clock_type clock_type;
+ bool pin;
};
/*
@@ -136,7 +138,13 @@ static int hog_cpus_timed(const char *cgroup, void *arg)
struct timespec ts_run = param->ts;
struct timespec ts_remaining = ts_run;
struct timespec ts_start;
- int i, ret;
+ pthread_attr_t attr;
+ cpu_set_t cpus, one;
+ int i, ret, cpu = -1;
+ /* Unpinned, as before, where the mask does not fit in a cpu_set_t */
+ bool pin = param->pin && !sched_getaffinity(0, sizeof(cpus), &cpus);
+
+ pthread_attr_init(&attr);
ret = clock_gettime(CLOCK_MONOTONIC, &ts_start);
if (ret != 0)
@@ -145,7 +153,18 @@ static int hog_cpus_timed(const char *cgroup, void *arg)
for (i = 0; i < param->nprocs; i++) {
pthread_t tid;
- ret = pthread_create(&tid, NULL, &hog_cpu_thread_func, NULL);
+ /* One hog per allowed CPU, in turn */
+ if (pin) {
+ do {
+ cpu = (cpu + 1) % CPU_SETSIZE;
+ } while (!CPU_ISSET(cpu, &cpus));
+ CPU_ZERO(&one);
+ CPU_SET(cpu, &one);
+ ret = pthread_attr_setaffinity_np(&attr, sizeof(one), &one);
+ if (ret != 0)
+ return ret;
+ }
+ ret = pthread_create(&tid, &attr, &hog_cpu_thread_func, NULL);
if (ret != 0)
return ret;
}
@@ -372,7 +391,8 @@ run_cpucg_weight_test(
return ret;
}
-static pid_t weight_hog_ncpus(const struct cpu_hogger *child, int ncpus)
+static pid_t weight_hog_ncpus(const struct cpu_hogger *child, int ncpus,
+ bool pin)
{
long usage_seconds = 10;
struct cpu_hog_func_param param = {
@@ -382,13 +402,14 @@ static pid_t weight_hog_ncpus(const struct cpu_hogger *child, int ncpus)
.tv_nsec = 0,
},
.clock_type = CPU_HOG_CLOCK_WALL,
+ .pin = pin,
};
return cg_run_nowait(child->cgroup, hog_cpus_timed, (void *)¶m);
}
static pid_t weight_hog_all_cpus(const struct cpu_hogger *child)
{
- return weight_hog_ncpus(child, get_nprocs());
+ return weight_hog_ncpus(child, get_nprocs(), true);
}
static int
@@ -434,7 +455,7 @@ static int test_cpucg_weight_overprovisioned(const char *root)
static pid_t weight_hog_one_cpu(const struct cpu_hogger *child)
{
- return weight_hog_ncpus(child, 1);
+ return weight_hog_ncpus(child, 1, false);
}
static int
--
2.56.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [Devel] [PATCH hci-8.1] selftests/cgroup: Pin the hogs of test_cpucg_weight_overprovisioned
2026-11-12 4:23 [Devel] [PATCH hci-8.1] selftests/cgroup: Pin the hogs of test_cpucg_weight_overprovisioned Eva Kurchatova
@ 2026-11-12 4:27 ` no-reply
2026-11-12 11:49 ` Konstantin Khorenko
2026-11-12 11:49 ` Konstantin Khorenko
2 siblings, 0 replies; 4+ messages in thread
From: no-reply @ 2026-11-12 4:27 UTC (permalink / raw)
To: Eva Kurchatova, khorenko; +Cc: devel
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] selftests/cgroup: hog_cpus_timed() never calls pthread_attr_destroy()
--
commit 3e0ad2c93c22b3e844f853e154c385c491c1c5ca
Author: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
selftests/cgroup: Pin the hogs of test_cpucg_weight_overprovisioned
This patch pins each hog thread in test_cpucg_weight_overprovisioned() to
one CPU. The threads of each cgroup are spread one per allowed CPU, so the
test checks the cgroup weights and not the load balancer's placement.
> diff --git a/tools/testing/selftests/cgroup/test_cpu.c b/tools/testing/selftests/cgroup/test_cpu.c
> --- a/tools/testing/selftests/cgroup/test_cpu.c
> +++ b/tools/testing/selftests/cgroup/test_cpu.c
[ ... ]
> @@ -136,7 +138,13 @@ static int hog_cpus_timed(const char *cgroup, void *arg)
> struct timespec ts_run = param->ts;
> struct timespec ts_remaining = ts_run;
> struct timespec ts_start;
> - int i, ret;
> + pthread_attr_t attr;
> + cpu_set_t cpus, one;
> + int i, ret, cpu = -1;
> + /* Unpinned, as before, where the mask does not fit in a cpu_set_t */
> + bool pin = param->pin && !sched_getaffinity(0, sizeof(cpus), &cpus);
> +
> + pthread_attr_init(&attr);
[Severity: Low]
Is the pthread_attr_t initialized here ever released? hog_cpus_timed()
calls pthread_attr_init(&attr) unconditionally, but none of its exit paths
call pthread_attr_destroy(&attr).
This covers the final "return 0", the early return after a failed
pthread_attr_setaffinity_np(), the return after a failed pthread_create(),
and the clock_gettime()/nanosleep() failure returns.
With pin set, glibc's pthread_attr_setaffinity_np() allocates a copy of the
cpuset inside attr, and pthread_attr_destroy() is what frees it.
The return value of pthread_attr_init() is also not checked.
The impact is small, since hog_cpus_timed() runs in a short-lived child
forked by cg_run_nowait() and the memory is reclaimed on exit. Would it be
worth adding a pthread_attr_destroy(&attr) on the exit paths?
> @@ -145,7 +153,18 @@ static int hog_cpus_timed(const char *cgroup, void *arg)
> for (i = 0; i < param->nprocs; i++) {
> pthread_t tid;
>
> - ret = pthread_create(&tid, NULL, &hog_cpu_thread_func, NULL);
> + /* One hog per allowed CPU, in turn */
> + if (pin) {
> + do {
> + cpu = (cpu + 1) % CPU_SETSIZE;
> + } while (!CPU_ISSET(cpu, &cpus));
> + CPU_ZERO(&one);
> + CPU_SET(cpu, &one);
> + ret = pthread_attr_setaffinity_np(&attr, sizeof(one), &one);
> + if (ret != 0)
> + return ret;
> + }
> + ret = pthread_create(&tid, &attr, &hog_cpu_thread_func, NULL);
> if (ret != 0)
> return ret;
> }
[ ... ]
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261112042325.399633-1-eva.kurchatova@virtuozzo.com?part=1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [Devel] [PATCH hci-8.1] selftests/cgroup: Pin the hogs of test_cpucg_weight_overprovisioned
2026-11-12 4:23 [Devel] [PATCH hci-8.1] selftests/cgroup: Pin the hogs of test_cpucg_weight_overprovisioned Eva Kurchatova
2026-11-12 4:27 ` no-reply
@ 2026-11-12 11:49 ` Konstantin Khorenko
2026-11-12 11:49 ` Konstantin Khorenko
2 siblings, 0 replies; 4+ messages in thread
From: Konstantin Khorenko @ 2026-11-12 11:49 UTC (permalink / raw)
To: Eva Kurchatova; +Cc: devel
Applying with these fixes on my side:
- subject: "Pin the hogs" -> "pin the hogs", lowercase after the
prefix.
Asks, not needed for this patch:
- Send it to mainline too, see the task below.
- Say whether test_cpucg_nested_weight_overprovisioned passes on the
same NUMA host; if it does not, pin its hogs in a separate patch.
On Thu, 12 Nov 2026 06:23:20 +0200, Eva Kurchatova wrote:
> Pin the hogs of each cgroup one per CPU: the test checks the weights,
> not the load balancer.
This needs to go to mainline too, I created a task for that:
https://virtuozzo.atlassian.net/browse/VSTOR-154829
Mainline v7.4-rc1 has the same unpinned hog_cpus_timed(), so the test
fails there on the same hosts. For the mainline version, take Sashiko's
pthread_attr_destroy() remark: init the attr only when pinning, pass
NULL otherwise and destroy it after the loop. Upstream reviewers will
ask for it.
> - return weight_hog_ncpus(child, get_nprocs());
> + return weight_hog_ncpus(child, get_nprocs(), true);
run_cpucg_nested_weight_test() with overprovisioned set starts
get_nprocs() unpinned hogs in each of its three leaves through the same
hog_cpus_timed(), so the reasoning of this patch applies to it as well.
Its tolerance is wider in practice, which may be why it has not failed
yet. ".pin = overprovisioned" in its param would cover it; the
underprovisioned cases must stay unpinned, or all hogs land on the
first CPUs of the mask.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Devel] [PATCH hci-8.1] selftests/cgroup: Pin the hogs of test_cpucg_weight_overprovisioned
2026-11-12 4:23 [Devel] [PATCH hci-8.1] selftests/cgroup: Pin the hogs of test_cpucg_weight_overprovisioned Eva Kurchatova
2026-11-12 4:27 ` no-reply
2026-11-12 11:49 ` Konstantin Khorenko
@ 2026-11-12 11:49 ` Konstantin Khorenko
2 siblings, 0 replies; 4+ messages in thread
From: Konstantin Khorenko @ 2026-11-12 11:49 UTC (permalink / raw)
To: Eva Kurchatova; +Cc: devel
On Thu, 12 Nov 2026 06:23:20 +0200, Eva Kurchatova wrote:
> selftests/cgroup: Pin the hogs of test_cpucg_weight_overprovisioned
Applied to branch-rh10-6.12.0-211.52.1.22.x.vz10-ovz, will be released in rh10-6.12.0-211.52.1.22.21.vz10, thanks!
[1/1] selftests/cgroup: Pin the hogs of test_cpucg_weight_overprovisioned
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/a56b30724f24
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-12 11:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-12 4:23 [Devel] [PATCH hci-8.1] selftests/cgroup: Pin the hogs of test_cpucg_weight_overprovisioned Eva Kurchatova
2026-11-12 4:27 ` no-reply
2026-11-12 11:49 ` Konstantin Khorenko
2026-11-12 11:49 ` Konstantin Khorenko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.