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.