]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cpu-topo: renumber cores to avoid holes and make them contiguous
authorWilly Tarreau <w@1wt.eu>
Thu, 27 Feb 2025 10:11:08 +0000 (11:11 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 14 Mar 2025 17:30:31 +0000 (18:30 +0100)
Due to the way core numbers are assigned and the presence of SMT on
some of them, some holes may remain in the array. Let's renumber them
to plug holes once they're known, following pkg/node/die/llc etc, so
that they're local to a (pkg,node) set. Now an i7-14700 shows cores
0 to 19, not 0 to 27.

src/cpu_topo.c

index ffca19ea2bc9046618e414ec3e74530bd83805fb..1510a61f4aaebca265a665cb1094ed7b30aaeff9 100644 (file)
@@ -547,6 +547,36 @@ void cpu_fixup_topology(void)
                }
        }
 
+       /* let's make core numbers contiguous and per (pkg,node) as well, as
+        * holes may exist due to SMT.
+        */
+       prev_id = -2; // make sure it cannot match even unassigned ones
+       curr_id = -1;
+       for (cpu = 0; cpu <= cpu_topo_lastcpu; cpu++) {
+               /* renumber clusters and assign unassigne ones at the same
+                * time. For this, we'll compare pkg/die/llc with the last
+                * CPU's and verify if we need to create a new cluster ID.
+                * Note that some platforms don't report cache. The value is
+                * local to the pkg+node combination so that we reset it when
+                * changing.
+                */
+               if (!cpu ||
+                   (ha_cpu_topo[cpu].pk_id != ha_cpu_topo[cpu-1].pk_id) ||
+                   (ha_cpu_topo[cpu].no_id != ha_cpu_topo[cpu-1].no_id)) {
+                       curr_id = 0;
+               }
+               else if (ha_cpu_topo[cpu].ts_id != prev_id ||
+                        ha_cpu_topo[cpu].ca_id[4] != ha_cpu_topo[cpu-1].ca_id[4] ||
+                        (ha_cpu_topo[cpu].ca_id[4] < 0 && // no l4 ? check L3
+                         ((ha_cpu_topo[cpu].ca_id[3] != ha_cpu_topo[cpu-1].ca_id[3]) ||
+                          (ha_cpu_topo[cpu].ca_id[3] < 0 && // no l3 ? check L2
+                           (ha_cpu_topo[cpu].ca_id[2] != ha_cpu_topo[cpu-1].ca_id[2]))))) {
+                       curr_id++;
+               }
+               prev_id = ha_cpu_topo[cpu].ts_id;
+               ha_cpu_topo[cpu].ts_id = curr_id;
+       }
+
        cpu_reorder_by_index(ha_cpu_topo, cpu_topo_maxcpus);
 }