From 240528323002fad1901a2dd3dec5a9739f6a6960 Mon Sep 17 00:00:00 2001 From: Valentine Krasnobaeva Date: Thu, 17 Jul 2025 12:05:33 +0200 Subject: [PATCH] MINOR: cpu-topo: split cpu_dump_topology() to show its summary in show dev cpu_dump_topology() prints details about each enabled CPU and a summary with clusters info and thread-cpu bindings. The latter is often usefull for debugging and we want to add it in the 'show dev' output. So, let's split cpu_dump_topology() in two parts: cpu_topo_debug() to print the details about each enabled CPU; and cpu_topo_dump_summary() to print only the summary. In the next commit we will modify cpu_topo_dump_summary() to write into local trash buffer and it could be easily called from debug_parse_cli_show_dev(). --- include/haproxy/cpu_topo.h | 8 +++++++- src/cpu_topo.c | 11 +++++++++-- src/thread.c | 5 ++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/include/haproxy/cpu_topo.h b/include/haproxy/cpu_topo.h index 959d89b99..20dabe02c 100644 --- a/include/haproxy/cpu_topo.h +++ b/include/haproxy/cpu_topo.h @@ -2,6 +2,7 @@ #define _HAPROXY_CPU_TOPO_H #include +#include #include #include @@ -55,7 +56,12 @@ int cpu_map_configured(void); /* Dump the CPU topology for up to cpu_topo_maxcpus CPUs for * debugging purposes. Offline CPUs are skipped. */ -void cpu_dump_topology(const struct ha_cpu_topo *topo); +void cpu_topo_debug(const struct ha_cpu_topo *topo); + +/* Dump the summary of CPU topology , i.e. clusters info and thread-cpu + * bindings. + */ +void cpu_topo_dump_summary(const struct ha_cpu_topo *topo); /* re-order a CPU topology array by locality to help form groups. */ void cpu_reorder_by_locality(struct ha_cpu_topo *topo, int entries); diff --git a/src/cpu_topo.c b/src/cpu_topo.c index 7422046c3..6ffb6e54f 100644 --- a/src/cpu_topo.c +++ b/src/cpu_topo.c @@ -218,11 +218,10 @@ int cpu_map_configured(void) /* Dump the CPU topology for up to cpu_topo_maxcpus CPUs for * debugging purposes. Offline CPUs are skipped. */ -void cpu_dump_topology(const struct ha_cpu_topo *topo) +void cpu_topo_debug(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) { @@ -265,6 +264,14 @@ void cpu_dump_topology(const struct ha_cpu_topo *topo) } putchar('\n'); } +} + +/* Dump the summary of CPU topology : clusters info and thread-cpu + * bindings. + */ +void cpu_topo_dump_summary(const struct ha_cpu_topo *topo) +{ + int cpu, grp, thr; printf("CPU clusters:\n"); for (cpu = 0; cpu < cpu_topo_maxcpus; cpu++) { diff --git a/src/thread.c b/src/thread.c index 266c1562b..0feee87e4 100644 --- a/src/thread.c +++ b/src/thread.c @@ -1479,7 +1479,10 @@ int thread_map_to_groups() #if defined(USE_THREAD) && defined(USE_CPU_AFFINITY) if (global.tune.debug & GDBG_CPU_AFFINITY) { cpu_reorder_by_index(ha_cpu_topo, cpu_topo_maxcpus); - cpu_dump_topology(ha_cpu_topo); + cpu_topo_debug(ha_cpu_topo); + chunk_reset(&trash); + cpu_topo_dump_summary(ha_cpu_topo); + printf("%s\n", trash.area); } #endif return 0; -- 2.47.3