From: Willy Tarreau Date: Tue, 13 May 2025 14:00:23 +0000 (+0200) Subject: MINOR: cpu-topo: provide a function to sort clusters by average capacity X-Git-Tag: v3.2-dev16~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5ab2c815f1b109df0554a890127ef7e5d4a421f7;p=thirdparty%2Fhaproxy.git MINOR: cpu-topo: provide a function to sort clusters by average capacity The current per-capacity sorting function acts on a whole cluster, but in some setups having many small cores and few big ones, it becomes easy to observe an inversion of metrics where the many small cores show a globally higher total capacity than the few big ones. This does not necessarily fit all use cases. Let's add new a function to sort clusters by their per-cpu average capacity to cover more use cases. --- diff --git a/src/cpu_topo.c b/src/cpu_topo.c index f80a01f9b..8145309f5 100644 --- a/src/cpu_topo.c +++ b/src/cpu_topo.c @@ -620,7 +620,7 @@ int _cmp_cluster_index(const void *a, const void *b) return l->idx - r->idx; } -/* function used by qsort to order clustes by reverse capacity */ +/* function used by qsort to order clusters by reverse capacity */ int _cmp_cluster_capa(const void *a, const void *b) { const struct ha_cpu_cluster *l = (const struct ha_cpu_cluster *)a; @@ -628,6 +628,14 @@ int _cmp_cluster_capa(const void *a, const void *b) return r->capa - l->capa; } +/* function used by qsort to order clusters by average reverse capacity */ +int _cmp_cluster_avg_capa(const void *a, const void *b) +{ + const struct ha_cpu_cluster *l = (const struct ha_cpu_cluster *)a; + const struct ha_cpu_cluster *r = (const struct ha_cpu_cluster *)b; + return r->capa - l->capa; +} + /* re-order a cluster array by cluster index only */ void cpu_cluster_reorder_by_index(struct ha_cpu_cluster *clusters, int entries) { @@ -640,6 +648,12 @@ void cpu_cluster_reorder_by_capa(struct ha_cpu_cluster *clusters, int entries) qsort(clusters, entries, sizeof(*clusters), _cmp_cluster_capa); } +/* re-order a CPU topology array by locality and avg capacity to detect clusters. */ +void cpu_cluster_reorder_by_avg_capa(struct ha_cpu_cluster *clusters, int entries) +{ + qsort(clusters, entries, sizeof(*clusters), _cmp_cluster_avg_capa); +} + /* 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.