Re: [PATCH 7/7] perf/x86/intel/uncore: Implement lazy setup for MSR/MMIO PMU

From: Chen, Zide

Date: Wed May 13 2026 - 13:19:34 EST




On 5/13/2026 2:03 AM, Mi, Dapeng wrote:
>
> On 5/13/2026 7:30 AM, Zide Chen wrote:
>> MSR and MMIO uncore PMUs are currently registered at module init time
>> and appear in sysfs even when no PMU boxes are functional.
>>
>> Apply the same lazy registration model used by PCI uncore PMUs: the
>> PMU is registered when the first box is successfully initialized, and
>> unregistered when the last box exits. If a box fails to initialize on
>> a subsequent die, the PMU is marked broken but remains registered to
>> avoid disrupting any in-flight perf events.
>>
>> Box allocation and free remain at module init/exit time to avoid
>> repeated kfree/alloc cycles across CPU offline/online events.
>>
>> Signed-off-by: Zide Chen <zide.chen@xxxxxxxxx>
>> ---
>> arch/x86/events/intel/uncore.c | 72 ++++++----------------------------
>> 1 file changed, 12 insertions(+), 60 deletions(-)
>>
>> diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c
>> index 399f434e1a7d..2aaac0b49bb6 100644
>> --- a/arch/x86/events/intel/uncore.c
>> +++ b/arch/x86/events/intel/uncore.c
>> @@ -1564,8 +1564,11 @@ static void uncore_box_unref(struct intel_uncore_type **types, int die)
>> for (i = 0; i < type->num_boxes; i++, pmu++) {
>> box = pmu->boxes[die];
>> if (box && box->cpu >= 0 &&
>> - atomic_dec_return(&box->cpu_refcnt) == 0)
>> + atomic_dec_return(&box->cpu_refcnt) == 0) {
>> + if (atomic_dec_return(&pmu->die_refcnt) == 0)
>> + uncore_pmu_unregister(pmu);
>> uncore_box_exit(box);
>> + }
>> }
>> }
>> }
>> @@ -1659,7 +1662,7 @@ static int uncore_box_ref(struct intel_uncore_type **types,
>> box = pmu->boxes[die];
>> if (box && box->cpu >= 0 &&
>> atomic_inc_return(&box->cpu_refcnt) == 1)
>> - uncore_box_init(box);
>> + uncore_box_setup(pmu, box);
>> }
>> }
>> return 0;
>> @@ -1690,67 +1693,16 @@ static int uncore_event_cpu_online(unsigned int cpu)
>> return 0;
>> }
>>
>> -static int __init type_pmu_register(struct intel_uncore_type *type)
>> +static int __init uncore_cpu_mmio_init(struct intel_uncore_type **types)
>
> The name seems a little bit weird, could we name it to a more generic name?
> maybe uncore_pmu_types_init() or something similar? Thanks.

Sure, I may pick uncore_pmu_types_init().