Skip to content

Commit 5a7745b

Browse files
npigginmpe
authored andcommitted
powerpc/64s/perf: add power_pmu_wants_prompt_pmi to say whether perf wants PMIs to be soft-NMI
Interrupt code enables MSR[EE] in some irq handlers while keeping local irqs disabled via soft-mask, allowing PMI interrupts to be taken as soft-NMI to improve profiling of irq handlers. When perf is not enabled, there is no point to doing this, it's additional overhead. So provide a function that can say if PMIs should be taken promptly if possible. Signed-off-by: Nicholas Piggin <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ff0b0d6 commit 5a7745b

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

arch/powerpc/include/asm/hw_irq.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ static inline bool lazy_irq_pending_nocheck(void)
342342
return __lazy_irq_pending(local_paca->irq_happened);
343343
}
344344

345+
bool power_pmu_wants_prompt_pmi(void);
346+
345347
/*
346348
* This is called by asynchronous interrupts to conditionally
347349
* re-enable hard interrupts after having cleared the source

arch/powerpc/perf/core-book3s.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <asm/firmware.h>
1818
#include <asm/ptrace.h>
1919
#include <asm/code-patching.h>
20+
#include <asm/hw_irq.h>
2021
#include <asm/interrupt.h>
2122

2223
#ifdef CONFIG_PPC64
@@ -2437,6 +2438,36 @@ static void perf_event_interrupt(struct pt_regs *regs)
24372438
perf_sample_event_took(sched_clock() - start_clock);
24382439
}
24392440

2441+
/*
2442+
* If the perf subsystem wants performance monitor interrupts as soon as
2443+
* possible (e.g., to sample the instruction address and stack chain),
2444+
* this should return true. The IRQ masking code can then enable MSR[EE]
2445+
* in some places (e.g., interrupt handlers) that allows PMI interrupts
2446+
* though to improve accuracy of profiles, at the cost of some performance.
2447+
*
2448+
* The PMU counters can be enabled by other means (e.g., sysfs raw SPR
2449+
* access), but in that case there is no need for prompt PMI handling.
2450+
*
2451+
* This currently returns true if any perf counter is being used. It
2452+
* could possibly return false if only events are being counted rather than
2453+
* samples being taken, but for now this is good enough.
2454+
*/
2455+
bool power_pmu_wants_prompt_pmi(void)
2456+
{
2457+
struct cpu_hw_events *cpuhw;
2458+
2459+
/*
2460+
* This could simply test local_paca->pmcregs_in_use if that were not
2461+
* under ifdef KVM.
2462+
*/
2463+
2464+
if (!ppmu)
2465+
return false;
2466+
2467+
cpuhw = this_cpu_ptr(&cpu_hw_events);
2468+
return cpuhw->n_events;
2469+
}
2470+
24402471
static int power_pmu_prepare_cpu(unsigned int cpu)
24412472
{
24422473
struct cpu_hw_events *cpuhw = &per_cpu(cpu_hw_events, cpu);

0 commit comments

Comments
 (0)