]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cpu-topo: add a function to dump CPU topology
authorWilly Tarreau <w@1wt.eu>
Thu, 23 Jan 2025 17:00:51 +0000 (18:00 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 14 Mar 2025 17:30:30 +0000 (18:30 +0100)
The new function cpu_dump_topology() will centralize most debugging
calls, and it can make efforts of not dumping some possibly irrelevant
fields (e.g. non-existing cache levels).

include/haproxy/cpu_topo.h
src/cpu_topo.c

index acc04268cde31fe2d78f2edbca3bbcaf9add5c7a..6a21e220e580439fc11919867ec289b17d8097ee 100644 (file)
@@ -9,4 +9,9 @@ extern int cpu_topo_maxcpus;
 extern int cpu_topo_lastcpu;
 extern struct ha_cpu_topo *ha_cpu_topo;
 
+/* Dump the CPU topology <topo> for up to cpu_topo_maxcpus CPUs for
+ * debugging purposes. Offline CPUs are skipped.
+ */
+void cpu_dump_topology(const struct ha_cpu_topo *topo);
+
 #endif /* _HAPROXY_CPU_TOPO_H */
index 894d8197bd086c12a906b41091179d5236e37315..2622994d93a3f0933a34c93669afb10c6b3bfc90 100644 (file)
@@ -9,6 +9,54 @@ int cpu_topo_maxcpus  = -1;  // max number of CPUs supported by OS/haproxy
 int cpu_topo_lastcpu  = -1;  // last supposed online CPU (no need to look beyond)
 struct ha_cpu_topo *ha_cpu_topo = NULL;
 
+/* Dump the CPU topology <topo> for up to cpu_topo_maxcpus CPUs for
+ * debugging purposes. Offline CPUs are skipped.
+ */
+void cpu_dump_topology(const struct ha_cpu_topo *topo)
+{
+       int has_smt = 0;
+       int cpu, lvl;
+
+       for (cpu = 0; cpu <= cpu_topo_lastcpu; cpu++)
+               if (ha_cpu_topo[cpu].th_cnt > 1)
+                       has_smt = 1;
+
+       for (cpu = 0; cpu <= cpu_topo_lastcpu; cpu++) {
+               if (ha_cpu_topo[cpu].st & HA_CPU_F_OFFLINE)
+                       continue;
+
+               printf("%3d: cpu=%3d excl=%d pk=%02d no=%02d cl=%03d(%03d)",
+                      cpu, ha_cpu_topo[cpu].idx,
+                      (ha_cpu_topo[cpu].st & HA_CPU_F_EXCL_MASK),
+                      ha_cpu_topo[cpu].pk_id,
+                      ha_cpu_topo[cpu].no_id,
+                      ha_cpu_topo[cpu].cl_gid,
+                      ha_cpu_topo[cpu].cl_lid);
+
+               /* list only relevant cache levels */
+               for (lvl = 4; lvl >= 0; lvl--) {
+                       if (ha_cpu_topo[cpu].ca_id[lvl] < 0)
+                               continue;
+                       printf(lvl < 3 ? " l%d=%02d" : " l%d=%03d", lvl, ha_cpu_topo[cpu].ca_id[lvl]);
+               }
+
+               printf(" ts=%03d capa=%d",
+                      ha_cpu_topo[cpu].ts_id,
+                      ha_cpu_topo[cpu].capa);
+
+               if (has_smt) {
+                       if (ha_cpu_topo[cpu].th_cnt > 1)
+                               printf(" smt=%d/%d",
+                                      ha_cpu_topo[cpu].th_id,
+                                      ha_cpu_topo[cpu].th_cnt);
+                       else
+                               printf(" smt=%d",
+                                      ha_cpu_topo[cpu].th_cnt);
+               }
+               putchar('\n');
+       }
+}
+
 /* returns an optimal maxcpus for the current system. It will take into
  * account what is reported by the OS, if any, otherwise will fall back
  * to the cpuset size, which serves as an upper limit in any case.