Re: [PATCH] sched/topology: Optimized copy default topology in sched_init_numa()

From: Valentin Schneider
Date: Mon Jul 04 2022 - 10:40:30 EST


On 27/06/22 18:53, Hao Jia wrote:
> The size of struct sched_domain_topology_level is 64 bytes.
> For NUMA platforms, almost all are multi-core (enable CONFIG_SCHED_MC),
> That is to say, the default_topology array has at least 128 bytes that
> need to be copied in sched_init_numa(). For most x86 platforms,
> CONFIG_SCHED_SMT will be enabled, so more copies will be required.
>
> And memcpy() will be optimized under different architectures.
> Fortunately, for platforms with CONFIG_NUMA enabled,
> these optimizations are likely to be used.
> So, let's use memcpy to copy default topology in sched_init_numa().
>
> Tests are done in an Intel Xeon(R) Platinum 8260 CPU@2.40GHz machine
> with 2 NUMA nodes each of which has 24 cores with SMT2 enabled, so 96
> CPUs in total.
>
> Use RDTSC to count time-consuming, and based on 5.19-rc4.
>
> Enable CONFIG_SCHED_SMT && CONFIG_SCHED_CLUSTER && CONFIG_SCHED_MC,
> So the default_topology array has 256 bytes that need to be copied
> in sched_init_numa().
> 5.19-rc4 5.19-rc4 with patch
> average tsc ticks 516.57 85.33 (-83.48%*)
>
> Enable CONFIG_SCHED_MC, So the default_topology array has
> 128 bytes that need to be copied in sched_init_numa().
> 5.19-rc4 5.19-rc4 with patch
> average tsc ticks 65.71 55.00 (-16.30%*)
>
> Signed-off-by: Hao Jia <jiahao.os@xxxxxxxxxxxxx>

It's not a very hot path but I guess this lets you shave off a bit of boot
time... While you're at it, you could add an early

if (nr_node_ids == 1)
return;

since !NUMA systems still go through sched_init_numa() if they have a
kernel with CONFIG_NUMA (which should be most of them nowdays) and IIRC
they end up with an unused NODE topology level.

Regardless:

Reviewed-by: Valentin Schneider <vschneid@xxxxxxxxxx>