]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: cpu-topo: Enforce thread-hard-limit on policy
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 27 May 2026 09:13:52 +0000 (11:13 +0200)
committerOlivier Houchard <cognet@ci0.org>
Wed, 27 May 2026 10:28:14 +0000 (12:28 +0200)
When a policy is set, and the number of threads is calculated
dynamically, make sure we enforce thread-hard-limit, and do not create
thread groups based on how many thread we would have created without
the limit.
This should be backported to 3.3 and 3.2. The patch won't apply cleanly
there, because the code has changed since then, but it should be very
similar, only we'll have to check "cpu_count" there, where in 3.4 we
check "thr_count".

src/cpu_topo.c

index bfb7177cd217952405c52cad530cabe912b3fa02..a9ba92fb5619d0c6cf77c99bdcdc5b27b122206d 100644 (file)
@@ -1520,7 +1520,8 @@ static int cpu_policy_group_by_cluster(int policy, int tmin, int tmax, int gmin,
        div = ha_cpu_policy[policy].arg;
        div = div ? div : 1;
 
-       while (global.nbtgroups < MAX_TGROUPS && global.nbthread < MAX_THREADS) {
+       while (global.nbtgroups < MAX_TGROUPS && (global.nbthread < MAX_THREADS) &&
+              (global.thread_limit == 0 || global.nbthread < global.thread_limit)) {
                ha_cpuset_zero(&node_cpu_set);
                ha_cpuset_zero(&touse_tsid);
                ha_cpuset_zero(&touse_ccx);
@@ -1550,6 +1551,10 @@ static int cpu_policy_group_by_cluster(int policy, int tmin, int tmax, int gmin,
                                ha_cpuset_set(&touse_tsid, ha_cpu_topo[cpu].ts_id);
                        } else if (!(cpu_policy_conf.flags & CPU_POLICY_ONE_THREAD_PER_CORE))
                                thr_count++;
+
+                       if (global.thread_limit != 0 &&
+                           thr_count + global.nbthread >= global.thread_limit)
+                               break;
                }
 
                /* now cid = next cluster_id or -1 if none; cpu_count is the
@@ -1608,7 +1613,8 @@ static int cpu_policy_group_by_ccx(int policy, int tmin, int tmax, int gmin, int
        div = ha_cpu_policy[policy].arg;
        div = div ? div : 1;
 
-       while (global.nbtgroups < MAX_TGROUPS && global.nbthread < MAX_THREADS) {
+       while (global.nbtgroups < MAX_TGROUPS && global.nbthread < MAX_THREADS &&
+              (global.thread_limit == 0 || global.nbthread < global.thread_limit)) {
                ha_cpuset_zero(&node_cpu_set);
                ha_cpuset_zero(&touse_tsid);
                ha_cpuset_zero(&touse_ccx);
@@ -1638,6 +1644,9 @@ static int cpu_policy_group_by_ccx(int policy, int tmin, int tmax, int gmin, int
                                ha_cpuset_set(&touse_tsid, ha_cpu_topo[cpu].ts_id);
                        } else if (!(cpu_policy_conf.flags & CPU_POLICY_ONE_THREAD_PER_CORE))
                                thr_count++;
+                       if (global.thread_limit != 0 &&
+                           global.nbthread + thr_count >= global.thread_limit)
+                               break;
                }
 
                /* now l3id = next L3 ID or -1 if none; cpu_count is the