Re: [PATCH 1/2] perf/x86/rapl: Move the pmu allocation out of CPU hotplug

From: Thomas Gleixner
Date: Tue Oct 08 2024 - 18:46:52 EST


On Tue, Oct 08 2024 at 17:05, Kan Liang wrote:
> On 2024-10-08 4:36 p.m., Thomas Gleixner wrote:
>>>
>>> 1) Start your kernel with maxcpus=2 (not recommended, but ...)
>>> 2) Load the module
>>> 3) Online the rest of the CPUs from userspace
>>>
>>> If your machine has more than one die you might be surprised...
>
> Thanks. I will find a 2 sockets machine and give it a try.
>
>>
>> You can make this work because the new topology code allows you to
>> retrieve the possible number of cores/dies/packages even when they have
>> not been onlined yet.
>>
>
> Actually, I think the possible CPU mask should be good enough here. The
> init_rapl_pmu() just intends to allocate the space for a pmu in each die.
>
> The worst case of using a possible mask is that some space may be
> wasted, when there is no online CPUs on a die. But it should be an
> unusual case. It should be harmless.

Right, but you can't use the regular topology functions which are used
by cpu to rapl ID for that because they depend on the CPU being
online. The x86 specific ones which parse the APIC ID topology
information can provide that information.

I.e. you only need

topology_max_packages()
topology_max_dies_per_package()
topology_num_cores_per_package()

which provide you the required information to allocate upfront. Later
when the CPUs are actually online the existing mapping functions work.

Thanks,

tglx