[PATCH 1/2] alpha: Use rpcc when WTINT is configured but not implemented
From: Matt Turner
Date: Sat Dec 05 2026 - 15:39:00 EST
With CONFIG_ALPHA_WTINT, which most SMP configurations enable, the
rpcc clocksource is compiled out: CALL_PAL WTINT may slow or stop the
cycle counter while the CPU waits for an interrupt. But not every PALcode
implements WTINT. Where it does not, the call raises an OPCDEC fault
and do_entIF() patches it into a no-op, so the counter keeps running
and the kernel is left on the jiffies clocksource for no reason.
The Tru64 PALcode in the Marvel (ES47, GS1280) firmware is one of
these: its WTINT entry is the same stub as its unassigned CALL_PAL
functions, and on an ES47 the call traps.
Always build the rpcc clocksource and record in do_entIF() that WTINT
had to be emulated. Register the clocksource from a device_initcall()
instead of time_init(), which runs with interrupts disabled, and before
that call WTINT once with interrupts enabled: where it is implemented
it returns at the next interrupt, and where it is not, the emulation
says so.
Signed-off-by: Matt Turner <mattst88@xxxxxxxxx>
---
arch/alpha/kernel/proto.h | 1 +
arch/alpha/kernel/time.c | 40 ++++++++++++++++++++++++++++++++--------
arch/alpha/kernel/traps.c | 4 ++++
3 files changed, 37 insertions(+), 8 deletions(-)
diff --git a/arch/alpha/kernel/proto.h b/arch/alpha/kernel/proto.h
index 7ece3b635e27..0226aa8281f0 100644
--- a/arch/alpha/kernel/proto.h
+++ b/arch/alpha/kernel/proto.h
@@ -190,6 +190,7 @@ extern void do_entDbg(struct pt_regs *);
struct allregs;
extern void do_entUna(void *, unsigned long, unsigned long, struct allregs *);
extern void do_entUnaUser(void __user *, unsigned long, unsigned long, struct pt_regs *);
+extern bool alpha_wtint_missing;
/* irq_alpha.c */
extern void notrace lockdep_on_restore(unsigned long ps, unsigned long ip);
diff --git a/arch/alpha/kernel/time.c b/arch/alpha/kernel/time.c
index 4d01c392ab14..7a5aa0ce5ac5 100644
--- a/arch/alpha/kernel/time.c
+++ b/arch/alpha/kernel/time.c
@@ -246,7 +246,6 @@ common_init_rtc(void)
}
-#ifndef CONFIG_ALPHA_WTINT
/*
* The RPCC as a clocksource primitive.
*
@@ -258,7 +257,7 @@ common_init_rtc(void)
*
* When using the WTINT PALcall, the RPCC may shift to a lower frequency,
* or stop altogether, while waiting for the interrupt. Therefore we cannot
- * use this method when WTINT is in use.
+ * use this method when the PALcode implements WTINT.
*/
static u64 read_rpcc(struct clocksource *cs)
@@ -273,7 +272,8 @@ static struct clocksource clocksource_rpcc = {
.mask = CLOCKSOURCE_MASK(32),
.flags = CLOCK_SOURCE_IS_CONTINUOUS
};
-#endif /* ALPHA_WTINT */
+
+static unsigned long rpcc_freq __initdata;
/* Validate a computed cycle counter result against the known bounds for
@@ -434,17 +434,41 @@ time_init(void)
"and unable to estimate a proper value!\n");
}
- /* See above for restrictions on using clocksource_rpcc. */
-#ifndef CONFIG_ALPHA_WTINT
- if (hwrpb->nr_processors == 1)
- clocksource_register_hz(&clocksource_rpcc, cycle_freq);
-#endif
+ /* Registered by init_rpcc_clocksource(). */
+ rpcc_freq = cycle_freq;
/* Startup the timer source. */
alpha_mv.init_rtc();
init_rtc_clockevent();
}
+/*
+ * Registered from an initcall rather than time_init(), which runs with
+ * interrupts disabled, too early to probe for WTINT.
+ */
+static int __init init_rpcc_clocksource(void)
+{
+ /* QEMU uses qemu_cs; time_init() leaves rpcc_freq unset. */
+ if (alpha_using_qemu)
+ return 0;
+
+ /* See above for restrictions on using clocksource_rpcc. */
+ if (hwrpb->nr_processors != 1)
+ return 0;
+
+ if (IS_ENABLED(CONFIG_ALPHA_WTINT)) {
+ /* Returns at the next interrupt, or traps if unimplemented. */
+ wtint(0);
+ if (!alpha_wtint_missing)
+ return 0;
+ }
+
+ clocksource_register_hz(&clocksource_rpcc, rpcc_freq);
+
+ return 0;
+}
+device_initcall(init_rpcc_clocksource);
+
/* Initialize the clock_event_device for secondary cpus. */
#ifdef CONFIG_SMP
void __init
diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
index db6277b3bed0..b335928c8314 100644
--- a/arch/alpha/kernel/traps.c
+++ b/arch/alpha/kernel/traps.c
@@ -196,6 +196,9 @@ do_entArith(unsigned long summary, unsigned long write_mask,
send_sig_fault_trapno(SIGFPE, si_code, (void __user *) regs->pc, 0, current);
}
+/* Set once do_entIF() has had to emulate CALL_PAL WTINT. */
+bool alpha_wtint_missing;
+
asmlinkage void
do_entIF(unsigned long type, struct pt_regs *regs)
{
@@ -234,6 +237,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
*pinsn = 0x47e01400; /* mov 0,$0 */
imb();
regs->r0 = 0;
+ alpha_wtint_missing = true;
return;
}
}
--
2.56.1