[PATCH 2/5] clocksource/drivers/arm_arch_timer: Convert counter accessors to a static key alternative

From: Marc Zyngier

Date: Mon Mar 02 2026 - 05:41:43 EST


Now that we have a reliable static key to control whether our
counter accessors need to be worked around, use it in these
accessors and simplify the logic that picks which accessor to use.

Signed-off-by: Marc Zyngier <maz@xxxxxxxxxx>
---
drivers/clocksource/arm_arch_timer.c | 38 +++++++++++++++-------------
1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index c5b42001c9282..723ba698b8c46 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -92,9 +92,12 @@ static int arch_counter_get_width(void)
*/
static inline bool arch_counter_broken_accessors(void);

-static noinstr u64 raw_counter_get_cntpct_stable(void)
+static noinstr u64 raw_counter_get_cntpct(void)
{
- return __arch_counter_get_cntpct_stable();
+ if (arch_counter_broken_accessors())
+ return __arch_counter_get_cntpct_stable();
+
+ return __arch_counter_get_cntpct();
}

static notrace u64 arch_counter_get_cntpct_stable(void)
@@ -108,12 +111,18 @@ static notrace u64 arch_counter_get_cntpct_stable(void)

static noinstr u64 arch_counter_get_cntpct(void)
{
+ if (arch_counter_broken_accessors())
+ return arch_counter_get_cntpct_stable();
+
return __arch_counter_get_cntpct();
}

-static noinstr u64 raw_counter_get_cntvct_stable(void)
+static noinstr u64 raw_counter_get_cntvct(void)
{
- return __arch_counter_get_cntvct_stable();
+ if (arch_counter_broken_accessors())
+ return __arch_counter_get_cntvct_stable();
+
+ return __arch_counter_get_cntvct();
}

static notrace u64 arch_counter_get_cntvct_stable(void)
@@ -127,6 +136,9 @@ static notrace u64 arch_counter_get_cntvct_stable(void)

static noinstr u64 arch_counter_get_cntvct(void)
{
+ if (arch_counter_broken_accessors())
+ return arch_counter_get_cntvct_stable();
+
return __arch_counter_get_cntvct();
}

@@ -946,21 +958,11 @@ static void __init arch_counter_register(void)

if ((IS_ENABLED(CONFIG_ARM64) && !is_hyp_mode_available()) ||
arch_timer_uses_ppi == ARCH_TIMER_VIRT_PPI) {
- if (arch_timer_counter_has_wa()) {
- rd = arch_counter_get_cntvct_stable;
- scr = raw_counter_get_cntvct_stable;
- } else {
- rd = arch_counter_get_cntvct;
- scr = arch_counter_get_cntvct;
- }
+ rd = arch_counter_get_cntvct;
+ scr = raw_counter_get_cntvct;
} else {
- if (arch_timer_counter_has_wa()) {
- rd = arch_counter_get_cntpct_stable;
- scr = raw_counter_get_cntpct_stable;
- } else {
- rd = arch_counter_get_cntpct;
- scr = arch_counter_get_cntpct;
- }
+ rd = arch_counter_get_cntpct;
+ scr = raw_counter_get_cntpct;
}

arch_timer_read_counter = rd;
--
2.47.3