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.
This commit is contained in:
parent
01df98adad
commit
5ab2c815f1
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user