Re: [PATCH v3 7/8] clocksource/drivers/arm_arch_timer: Expose a direct accessor for the virtual counter
From: Will Deacon
Date: Tue Sep 29 2026 - 09:01:13 EST
On Sun, Aug 02, 2026 at 05:53:26PM +0100, Marc Zyngier wrote:
> We allow access to the architected counter via arch_timer_read_counter().
> However, this accessor can either be the virtual or the physical
> view of the counter, depending on how the kernel has been booted.
>
> At the same time, we have some architectural features (such as WFIT,
> WFET) that rely on the virtual counter, and nothing else.
>
> If implementations were perfect, we'd rely on reading CNTVCT_EL0,
> and be done with it. However, we have a bunch of broken implementations
> in the wild, which rely on preemption being disabled and other
> costly workarounds.
>
> In order to provide decent performance on non-broken HW while still
> supporting the legacy horrors, expose arch_timer_read_vcounter() as
> a new helper that hides this complexity. Obviously, this is simply
> a global alias of arch_counter_get_cntvct().
>
> Signed-off-by: Marc Zyngier <maz@xxxxxxxxxx>
> ---
> drivers/clocksource/arm_arch_timer.c | 2 ++
> include/clocksource/arm_arch_timer.h | 1 +
> 2 files changed, 3 insertions(+)
>
> diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
> index b3b31d4f4815f..9c7501ce57073 100644
> --- a/drivers/clocksource/arm_arch_timer.c
> +++ b/drivers/clocksource/arm_arch_timer.c
> @@ -128,6 +128,8 @@ static notrace u64 arch_counter_get_cntvct(void)
> return __arch_counter_get_cntvct();
> }
>
> +u64 arch_timer_read_vcounter(void) __attribute__((alias("arch_counter_get_cntvct")));
nit: compiler-attributes.h provides __alias to make this a tiny bit cleaner.
That said, why did you decide on the alias rather than just having this
as a wrapper function?
Will