]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cpu-topo: provide a function to sort clusters by average capacity
authorWilly Tarreau <w@1wt.eu>
Tue, 13 May 2025 14:00:23 +0000 (16:00 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 13 May 2025 14:48:30 +0000 (16:48 +0200)
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.

src/cpu_topo.c

index f80a01f9b9ee16b12cc67623fa46caec5541e920..8145309f51c67813433014d7a3eacf97b240644b 100644 (file)
@@ -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.