]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cpu-topo: write thread-cpu bindings into trash buffer
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Thu, 17 Jul 2025 16:18:20 +0000 (18:18 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 17 Jul 2025 17:07:58 +0000 (19:07 +0200)
Write thread-cpu bindings and cluster summary into provided trash buffer.
Like this we can call this function in any place, when this info is needed.

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

index 20dabe02c823292f48c6a9e419af4b55f7427ea2..767d01c38053d5dfeb2538132415802a0f6f67b9 100644 (file)
@@ -61,7 +61,7 @@ void cpu_topo_debug(const struct ha_cpu_topo *topo);
 /* Dump the summary of CPU topology <topo>, i.e. clusters info and thread-cpu
  * bindings.
  */
-void cpu_topo_dump_summary(const struct ha_cpu_topo *topo);
+void cpu_topo_dump_summary(const struct ha_cpu_topo *topo, struct buffer *trash);
 
 /* re-order a CPU topology array by locality to help form groups. */
 void cpu_reorder_by_locality(struct ha_cpu_topo *topo, int entries);
index 6ffb6e54fb82ac1cc4fce4a907e1d49f6ef7226c..b5840e5078a323cab1189b0bae9e54e753e94f80 100644 (file)
@@ -269,21 +269,21 @@ void cpu_topo_debug(const struct ha_cpu_topo *topo)
 /* Dump the summary of CPU topology <topo>: clusters info and thread-cpu
  * bindings.
  */
-void cpu_topo_dump_summary(const struct ha_cpu_topo *topo)
+void cpu_topo_dump_summary(const struct ha_cpu_topo *topo, struct buffer *trash)
 {
        int cpu, grp, thr;
 
-       printf("CPU clusters:\n");
+       chunk_appendf(trash, "CPU clusters:\n");
        for (cpu = 0; cpu < cpu_topo_maxcpus; cpu++) {
                if (!ha_cpu_clusters[cpu].nb_cpu)
                        continue;
-               printf("  %3u  cpus=%3u cores=%3u capa=%u\n",
-                      cpu, ha_cpu_clusters[cpu].nb_cpu,
-                      ha_cpu_clusters[cpu].nb_cores,
-                      ha_cpu_clusters[cpu].capa);
+               chunk_appendf(trash, "  %3u  cpus=%3u cores=%3u capa=%u\n",
+                             cpu, ha_cpu_clusters[cpu].nb_cpu,
+                             ha_cpu_clusters[cpu].nb_cores,
+                             ha_cpu_clusters[cpu].capa);
        }
 
-       printf("Thread CPU Bindings:\n  Tgrp/Thr  Tid        CPU set\n");
+       chunk_appendf(trash, "Thread CPU Bindings:\n  Tgrp/Thr  Tid        CPU set\n");
        for (grp = 0; grp < global.nbtgroups; grp++) {
                int first, last;
                int min, max;
@@ -338,7 +338,7 @@ void cpu_topo_dump_summary(const struct ha_cpu_topo *topo)
                                else if (len2 == 0)
                                        snprintf(str + len, sizeof(str) - len, "<all>");
 
-                               printf("  %s\n", str);
+                               chunk_appendf(trash, "  %s\n", str);
                                min = max = -1;
                        }
                }
index 0feee87e496e8218c9f641f9181d00ce81298739..16d087b839c184bafe2e41f67f27fc3b0b4cf401 100644 (file)
@@ -1481,7 +1481,7 @@ int thread_map_to_groups()
                cpu_reorder_by_index(ha_cpu_topo, cpu_topo_maxcpus);
                cpu_topo_debug(ha_cpu_topo);
                chunk_reset(&trash);
-               cpu_topo_dump_summary(ha_cpu_topo);
+               cpu_topo_dump_summary(ha_cpu_topo, &trash);
                printf("%s\n", trash.area);
        }
 #endif