From: Willy Tarreau Date: Tue, 11 Mar 2025 13:04:54 +0000 (+0100) Subject: MEDIUM: cpu-topo: make sure to properly assign CPUs to threads as a fallback X-Git-Tag: v3.2-dev8~71 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4a525e8d27dc61c91f8cf191c1775dfb6f664796;p=thirdparty%2Fhaproxy.git MEDIUM: cpu-topo: make sure to properly assign CPUs to threads as a fallback If no cpu-map is done and no cpu-policy could be enforced, we still need to count the number of usable CPUs, assign them to all threads and set the nbthread value accordingly. This already handles the part that was done in check_config_validity() via thread_cpus_enabled_at_boot. --- diff --git a/src/thread.c b/src/thread.c index deb4bc22d..9d347553f 100644 --- a/src/thread.c +++ b/src/thread.c @@ -1613,6 +1613,36 @@ void thread_detect_count(void) * capacity order until we reach at least thr_min, then continue * on the same cluster _capacity_ up to thr_max. */ + + if (!ha_cpuset_count(&cpu_map[0].thread[0])) { + /* thread 1 is not mapped, no policy was applied, so we have to + * count the threads ourselves. + */ + struct hap_cpuset node_cpu_set; + int thr, cpu, grp, cpu_count; + + ha_cpuset_zero(&node_cpu_set); + + for (cpu = cpu_count = 0; cpu <= cpu_topo_lastcpu; cpu++) { + if (ha_cpu_topo[cpu].st & HA_CPU_F_EXCL_MASK) + continue; + + ha_cpuset_set(&node_cpu_set, ha_cpu_topo[cpu].idx); + cpu_count++; + } + + /* assign all threads of all thread groups to this node */ + for (grp = 0; grp < MAX_TGROUPS; grp++) + for (thr = 0; thr < MAX_THREADS_PER_GROUP; thr++) + ha_cpuset_assign(&cpu_map[grp].thread[thr], &node_cpu_set); + + /* if the number of CPUs is within the allowed thread range, + * automatically set the max thread count to the number of CPUs + * as this will be used as the final number of threads. + */ + if (thr_min <= cpu_count && cpu_count <= thr_max) + thr_max = cpu_count; + } #endif // USE_THREAD && USE_CPU_AFFINITY if (!global.nbthread)