]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cpu-topo: add a dump of thread-to-CPU mapping to -dc
authorWilly Tarreau <w@1wt.eu>
Mon, 31 Mar 2025 12:36:26 +0000 (14:36 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 31 Mar 2025 14:21:37 +0000 (16:21 +0200)
When emitting the CPU topology info with -dc, also emit a list of
thread-to-CPU mapping. The group/thread and thread ID are emitted
with the list of their CPUs on each line. The count of CPUs is shown
to ease comparisons, and as much as possible, we try to pack identical
lines within a group by showing thread ranges.

src/cpu_topo.c

index 009a11a3f1f3abd380b6abe62e8eb13cc3316c75..8d9b0a7b890f9e6d01a939215744762065a65c4b 100644 (file)
@@ -214,6 +214,7 @@ void cpu_dump_topology(const struct ha_cpu_topo *topo)
 {
        int has_smt = 0;
        int cpu, lvl;
+       int grp, thr;
 
        for (cpu = 0; cpu <= cpu_topo_lastcpu; cpu++)
                if (ha_cpu_topo[cpu].th_cnt > 1)
@@ -263,6 +264,67 @@ void cpu_dump_topology(const struct ha_cpu_topo *topo)
                       ha_cpu_clusters[cpu].nb_cores,
                       ha_cpu_clusters[cpu].capa);
        }
+
+       printf("Thread CPU Bindings:\n  Tgrp/Thr  Tid        CPU set\n");
+       for (grp = 0; grp < global.nbtgroups; grp++) {
+               int first, last;
+               int min, max;
+
+               first = ha_tgroup_info[grp].base;
+               last  = ha_tgroup_info[grp].base + ha_tgroup_info[grp].count - 1;
+
+               min = max = -1;
+               for (thr = first; thr <= last; thr++) {
+                       if (min < 0)
+                               min = thr;
+
+                       if (thr == last ||
+                           !ha_cpuset_isequal(&cpu_map[grp].thread[min - first],
+                                              &cpu_map[grp].thread[thr + 1 - first]))
+                               max = thr;
+
+                       if (min >= 0 && max >= 0) {
+                               /* we have a range */
+                               char str[1024];
+                               int len = 0;
+                               int len2;
+
+                               /* print group/thread-range */
+                               len += snprintf(str + len, sizeof(str) - len, "%d/%d", grp + 1, min - first + 1);
+                               if (min != max)
+                                       len += snprintf(str + len, sizeof(str) - len, "-%d", max - first + 1);
+
+                               /* max len is 8: "64/64-64", plus 2 spaces = 10 */
+                               while (len < 10) {
+                                       str[len++] = ' ';
+                                       str[len] = 0;
+                               }
+
+                               /* append global thread range */
+                               len += snprintf(str + len, sizeof(str) - len, "%d", min + 1);
+                               if (min != max)
+                                       len += snprintf(str + len, sizeof(str) - len, "-%d", max + 1);
+
+                               /* max len is 9: "4096-4096", plus 2 spaces = 11, plus 10 initial chars = 21 */
+                               while (len < 21) {
+                                       str[len++] = ' ';
+                                       str[len] = 0;
+                               }
+
+                               if (ha_cpuset_count(&cpu_map[grp].thread[thr - first]))
+                                       len += snprintf(str + len, sizeof(str) - len, "%d: ", ha_cpuset_count(&cpu_map[grp].thread[thr - first]));
+
+                               len2 = print_cpu_set(str + len, sizeof(str) - len, &cpu_map[grp].thread[thr - first]);
+                               if (len2 > sizeof(str) - len)
+                                       snprintf(str + len, sizeof(str) - len, "<too_large>");
+                               else if (len2 == 0)
+                                       snprintf(str + len, sizeof(str) - len, "<all>");
+
+                               printf("  %s\n", str);
+                               min = max = -1;
+                       }
+               }
+       }
 }
 
 /* function used by qsort to re-arrange CPUs by index only, to restore original