[PATCH v1 2/4] powerpc/64s/perf: add power_pmu_running to query whether perf is being used

Nicholas Piggin npiggin at gmail.com
Wed Aug 18 21:41:55 AEST 2021


Excerpts from Madhavan Srinivasan's message of August 17, 2021 11:06 pm:
> 
> On 8/16/21 12:59 PM, Nicholas Piggin wrote:
>> Interrupt handling code would like to know whether perf is enabled, to
>> know whether it should enable MSR[EE] to improve PMI coverage.
>>
>> Cc: Madhavan Srinivasan <maddy at linux.ibm.com>
>> Cc: Athira Rajeev <atrajeev at linux.vnet.ibm.com>
>> Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
>> ---
>>   arch/powerpc/include/asm/hw_irq.h |  2 ++
>>   arch/powerpc/perf/core-book3s.c   | 13 +++++++++++++
>>   2 files changed, 15 insertions(+)
>>
>> diff --git a/arch/powerpc/include/asm/hw_irq.h b/arch/powerpc/include/asm/hw_irq.h
>> index 21cc571ea9c2..2d5c0d3ccbb6 100644
>> --- a/arch/powerpc/include/asm/hw_irq.h
>> +++ b/arch/powerpc/include/asm/hw_irq.h
>> @@ -306,6 +306,8 @@ static inline bool lazy_irq_pending_nocheck(void)
>>   	return __lazy_irq_pending(local_paca->irq_happened);
>>   }
>>   
>> +bool power_pmu_running(void);
>> +
>>   /*
>>    * This is called by asynchronous interrupts to conditionally
>>    * re-enable hard interrupts after having cleared the source
>> diff --git a/arch/powerpc/perf/core-book3s.c b/arch/powerpc/perf/core-book3s.c
>> index bb0ee716de91..76114a9afb2b 100644
>> --- a/arch/powerpc/perf/core-book3s.c
>> +++ b/arch/powerpc/perf/core-book3s.c
>> @@ -2380,6 +2380,19 @@ static void perf_event_interrupt(struct pt_regs *regs)
>>   	perf_sample_event_took(sched_clock() - start_clock);
>>   }
>>   
>> +bool power_pmu_running(void)
>> +{
>> +	struct cpu_hw_events *cpuhw;
>> +
>> +	/* Could this simply test local_paca->pmcregs_in_use? */
>> +
>> +	if (!ppmu)
>> +		return false;
> 
> 
> This covers only when perf platform driver is not registered,
> but we should also check for MMCR0[32], since pmu sprs can be
> accessed via sysfs.

In that case do they actually do anything with the PMI? I don't think it 
should matter hopefully.

But I do think a lot of this stuff could be cleaned up. We have 
pmcs_enabled and ppc_enable_pmcs() in sysfs.c, ppc_set_pmu_inuse(), 
ppc_md.enable_pmcs(), reserve_pmc_hardware(), etc and different users 
call different things. We don't consistently disable either, e.g., we 
never disable the H_PERFMON facility after we stop using perf even 
though it says that slows down partition switch.

I started to have a look at sorting it out but it looks like a big
job so would take a bit of time if we want to do it.

Thanks,
Nick


More information about the Linuxppc-dev mailing list