Skip to content

Commit

Permalink
powerpc/64s/perf: add power_pmu_wants_prompt_pmi to say whether perf …
Browse files Browse the repository at this point in the history
…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 <npiggin@gmail.com>
  • Loading branch information
npiggin authored and intel-lab-lkp committed Aug 25, 2021
1 parent 9ce5c60 commit 2394634
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions arch/powerpc/include/asm/hw_irq.h
Expand Up @@ -306,6 +306,8 @@ static inline bool lazy_irq_pending_nocheck(void)
return __lazy_irq_pending(local_paca->irq_happened);
}

bool power_pmu_wants_prompt_pmi(void);

/*
* This is called by asynchronous interrupts to conditionally
* re-enable hard interrupts after having cleared the source
Expand Down
28 changes: 28 additions & 0 deletions arch/powerpc/perf/core-book3s.c
Expand Up @@ -17,6 +17,7 @@
#include <asm/firmware.h>
#include <asm/ptrace.h>
#include <asm/code-patching.h>
#include <asm/hw_irq.h>
#include <asm/interrupt.h>

#ifdef CONFIG_PPC64
Expand Down Expand Up @@ -2389,6 +2390,33 @@ static void perf_event_interrupt(struct pt_regs *regs)
perf_sample_event_took(sched_clock() - start_clock);
}

/*
* If the perf subsystem wants performance monitor interrupts as soon as
* possible (e.g., to sample the instruction address and stack chain),
* this should return true. The IRQ masking code can then enable MSR[EE]
* in some places (e.g., interrupt handlers) that allows PMI interrupts
* though to improve accuracy of profiles, at the cost of some performance.
*
* The PMU counters can be enabled by other means (e.g., sysfs raw SPR
* access), but in that case there is no need for prompt PMI handling.
*
* This currently returns true if any perf counter is being used. It
* could possibly return false if only events are being counted rather than
* samples being taken, but for now this is good enough.
*/
bool power_pmu_wants_prompt_pmi(void)
{
struct cpu_hw_events *cpuhw;

/* Could this simply test local_paca->pmcregs_in_use? */

if (!ppmu)
return false;

cpuhw = this_cpu_ptr(&cpu_hw_events);
return cpuhw->n_events;
}

static int power_pmu_prepare_cpu(unsigned int cpu)
{
struct cpu_hw_events *cpuhw = &per_cpu(cpu_hw_events, cpu);
Expand Down

0 comments on commit 2394634

Please sign in to comment.