Re: [PATCH v2] sched/topology: Check average distances to remote packages
From: Peter Zijlstra
Date: Wed Feb 25 2026 - 08:37:06 EST
On Wed, Feb 25, 2026 at 01:30:52PM +0100, Peter Zijlstra wrote:
> diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
> index 5cd6950ab672..cba3e4b14250 100644
> --- a/arch/x86/kernel/smpboot.c
> +++ b/arch/x86/kernel/smpboot.c
> @@ -513,33 +513,55 @@ static void __init build_sched_topology(void)
> }
>
> #ifdef CONFIG_NUMA
> +
> +/*
> + * Find the largest symmetric cluster in an attempt to identify the unit size.
> + *
> + * XXX doesn't respect N_CPU node classes and such.
> + */
> +static int slit_cluster_size(void)
> {
> + int i, j, n, m = num_possible_nodes();
>
> + for (n = 2; n < m; n++) {
> + for (i = 0; i < n; i++) {
> + for (j = i; j < n; j++) {
> + if (node_distance(i, j) != node_distance(j, i))
> + return n - 1;
> }
> }
> }
>
> + return m;
> +}
If we make x86_has_numa_in_package a counter of how many nodes in the
package, we could use that number, rather than trying to guesstimate it.
Similarly, if the system would enumerate the SNC mode anywhere, that too
could be used.
> +static int slit_cluster_distance(int i, int j)
> +{
> + static int u = 0;
> + long d = 0;
> + int x, y;
> +
> + if (!u)
> + u = slit_cluster_size();
> +
> + /*
> + * Is this a unit cluster on the trace?
> + */
> + if ((i / u) == (j / u))
> + return node_distance(i, j);
> +
> + /*
> + * Off-trace cluster, return average of the cluster to force symmetry.
> + */
> + x = i - (i % u);
> + y = j - (j % u);
> +
> + for (i = x; i < x + u; i++) {
> + for (j = y; j < y + u; j++)
> + d += node_distance(i, j);
> + }
> +
> + return d / (u*u);
> }