[PATCH v2 1/1] alpha/perf: Account for time spent handling PMU interrupts
From: Magnus Lindholm
Date: Tue Nov 10 2026 - 14:32:08 EST
Alpha does not report PMU interrupt duration to perf, preventing its
adaptive throttling from reducing an excessively costly sampling rate.
Short sampling periods can leave the machine unresponsive with RCU
grace-period kthread starvation reports.
Measure handler time with RPCC and report it to perf_sample_event_took().
Precompute a multiplier and shift using the frequency selected by
time_init(), avoiding division in the interrupt handler. Alpha's
tick-based sched_clock() is too coarse for this measurement.
Wrap the existing handler so all return paths are accounted for, without
changing counter programming or event handling.
Signed-off-by: Magnus Lindholm <linmag7@xxxxxxxxx>
Reviewed-by: Matt Turner <mattst88@xxxxxxxxx>
---
arch/alpha/kernel/perf_event.c | 35 ++++++++++++++++++++++++++++++++--
1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/arch/alpha/kernel/perf_event.c b/arch/alpha/kernel/perf_event.c
index a3eaab094ece..09033c2d1f66 100644
--- a/arch/alpha/kernel/perf_event.c
+++ b/arch/alpha/kernel/perf_event.c
@@ -16,8 +16,11 @@
#include <linux/kdebug.h>
#include <linux/mutex.h>
#include <linux/init.h>
+#include <linux/math64.h>
+#include <linux/clocksource.h>
#include <asm/hwrpb.h>
+#include <asm/timex.h>
#include <linux/atomic.h>
#include <asm/irq.h>
#include <asm/irq_regs.h>
@@ -25,6 +28,10 @@
#include <asm/wrperfmon.h>
#include <asm/hw_irq.h>
+#include "proto.h"
+
+static u32 pmu_cycle_mult __ro_after_init;
+static u32 pmu_cycle_shift __ro_after_init;
/* The maximum number of PMCs on any Alpha CPU whatsoever. */
#define MAX_HWEVENTS 3
@@ -797,8 +804,8 @@ void perf_event_print_debug(void)
* Performance Monitoring Interrupt Service Routine called when a PMC
* overflows. The PMC that overflowed is passed in la_ptr.
*/
-static void alpha_perf_event_irq_handler(unsigned long la_ptr,
- struct pt_regs *regs)
+static void alpha_perf_event_irq_inner(unsigned long la_ptr,
+ struct pt_regs *regs)
{
struct cpu_hw_events *cpuc;
struct perf_sample_data data;
@@ -862,11 +869,28 @@ static void alpha_perf_event_irq_handler(unsigned long la_ptr,
+/* sched_clock() is tick-based on Alpha; measure a short same-CPU interval. */
+static void alpha_perf_event_irq_handler(unsigned long la_ptr,
+ struct pt_regs *regs)
+{
+ cycles_t start = get_cycles();
+ cycles_t cycles;
+
+ alpha_perf_event_irq_inner(la_ptr, regs);
+ /* Unsigned subtraction handles a wrap of the low 32-bit counter. */
+ cycles = get_cycles() - start;
+ if (likely(pmu_cycle_mult))
+ perf_sample_event_took(mul_u64_u32_shr(cycles, pmu_cycle_mult,
+ pmu_cycle_shift));
+}
+
/*
* Init call to initialise performance events at kernel startup.
*/
static int __init init_hw_perf_events(void)
{
+ unsigned long cycle_freq;
+
pr_info("Performance events: ");
if (!supported_cpu()) {
@@ -878,6 +902,13 @@ static int __init init_hw_perf_events(void)
/* Override performance counter IRQ vector */
+ /* Match the calibrated frequency selected by time_init(). */
+ cycle_freq = est_cycle_freq ? est_cycle_freq : hwrpb->cycle_freq;
+ if (cycle_freq && cycle_freq <= U32_MAX)
+ clocks_calc_mult_shift(&pmu_cycle_mult, &pmu_cycle_shift,
+ cycle_freq, NSEC_PER_SEC, 1);
+ else
+ pr_warn("PMU interrupt duration accounting disabled: invalid cycle frequency\n");
perf_irq = alpha_perf_event_irq_handler;
/* And set up PMU specification */
--
2.43.0