* [PATCH] arm64: arch_timer: reuse arch_timer_read_cnt{p,v}ct_el0() helpers
@ 2026-05-23 16:59 Breno Leitao
2026-06-05 16:43 ` Will Deacon
0 siblings, 1 reply; 2+ messages in thread
From: Breno Leitao @ 2026-05-23 16:59 UTC (permalink / raw)
To: Mark Rutland, Marc Zyngier, Catalin Marinas, Will Deacon
Cc: linux-arm-kernel, linux-kernel, kernel-team, Breno Leitao
__arch_counter_get_cntpct() and __arch_counter_get_cntvct() open-code
the same ECV-aware ALTERNATIVE block that arch_timer_read_cntpct_el0()
and arch_timer_read_cntvct_el0() already provide in the same header.
The two pairs are byte-for-byte identical except for the trailing
arch_counter_enforce_ordering() the __arch_counter_get_* variants add.
Replace the duplicated inline assembly in __arch_counter_get_cntpct()
and __arch_counter_get_cntvct() with calls to the corresponding helpers.
This mirrors commit 00b39d150986 ("arm64: vdso: Use
__arch_counter_get_cntvct()"), which removed similar duplication from
the vDSO, and keeps the system-counter read sequence in a single place,
reducing assembly code in the kernell
No functional change: the resulting inline assembly, alternatives, and
clobbers are unchanged; only the source-level expression of the read
moves into the existing helper.
Verified by rebuilding the consumers of these helpers before and after
the change and comparing the resulting disassembly:
- arch/arm64/kernel/vdso/vdso.so (final linked vDSO):
bit-identical (same sha256 across rebuilds)
- arch/arm64/kernel/vdso/vgettimeofday.o: identical disassembly
- arch/arm64/lib/delay.o: identical disassembly
- drivers/clocksource/arm_arch_timer.o: same 50 functions with
byte-identical instruction streams; only difference is function
ordering inside .text and NOP padding, with no opcodes added or
removed.
Signed-off-by: Breno Leitao <leitao@debian.org>
---
arch/arm64/include/asm/arch_timer.h | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/arch/arm64/include/asm/arch_timer.h b/arch/arm64/include/asm/arch_timer.h
index f5794d50f51d..6717209df05b 100644
--- a/arch/arm64/include/asm/arch_timer.h
+++ b/arch/arm64/include/asm/arch_timer.h
@@ -178,12 +178,8 @@ static __always_inline u64 __arch_counter_get_cntpct_stable(void)
static __always_inline u64 __arch_counter_get_cntpct(void)
{
- u64 cnt;
+ u64 cnt = arch_timer_read_cntpct_el0();
- asm volatile(ALTERNATIVE("isb\n mrs %0, cntpct_el0",
- "nop\n" __mrs_s("%0", SYS_CNTPCTSS_EL0),
- ARM64_HAS_ECV)
- : "=r" (cnt));
arch_counter_enforce_ordering(cnt);
return cnt;
}
@@ -199,12 +195,8 @@ static __always_inline u64 __arch_counter_get_cntvct_stable(void)
static __always_inline u64 __arch_counter_get_cntvct(void)
{
- u64 cnt;
+ u64 cnt = arch_timer_read_cntvct_el0();
- asm volatile(ALTERNATIVE("isb\n mrs %0, cntvct_el0",
- "nop\n" __mrs_s("%0", SYS_CNTVCTSS_EL0),
- ARM64_HAS_ECV)
- : "=r" (cnt));
arch_counter_enforce_ordering(cnt);
return cnt;
}
---
base-commit: 9f84f9898cf191aa251268547ceef03abb8d1edd
change-id: 20260523-arch64_fix-6416179b7173
Best regards,
--
Breno Leitao <leitao@debian.org>
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] arm64: arch_timer: reuse arch_timer_read_cnt{p,v}ct_el0() helpers
2026-05-23 16:59 [PATCH] arm64: arch_timer: reuse arch_timer_read_cnt{p,v}ct_el0() helpers Breno Leitao
@ 2026-06-05 16:43 ` Will Deacon
0 siblings, 0 replies; 2+ messages in thread
From: Will Deacon @ 2026-06-05 16:43 UTC (permalink / raw)
To: Mark Rutland, Marc Zyngier, Catalin Marinas, Breno Leitao
Cc: kernel-team, Will Deacon, linux-arm-kernel, linux-kernel,
kernel-team
On Sat, 23 May 2026 12:59:26 -0400, Breno Leitao wrote:
> __arch_counter_get_cntpct() and __arch_counter_get_cntvct() open-code
> the same ECV-aware ALTERNATIVE block that arch_timer_read_cntpct_el0()
> and arch_timer_read_cntvct_el0() already provide in the same header.
> The two pairs are byte-for-byte identical except for the trailing
> arch_counter_enforce_ordering() the __arch_counter_get_* variants add.
>
> Replace the duplicated inline assembly in __arch_counter_get_cntpct()
> and __arch_counter_get_cntvct() with calls to the corresponding helpers.
> This mirrors commit 00b39d150986 ("arm64: vdso: Use
> __arch_counter_get_cntvct()"), which removed similar duplication from
> the vDSO, and keeps the system-counter read sequence in a single place,
> reducing assembly code in the kernell
>
> [...]
Applied to arm64 (for-next/misc), thanks!
[1/1] arm64: arch_timer: reuse arch_timer_read_cnt{p,v}ct_el0() helpers
https://git.kernel.org/arm64/c/11c33ffb3a4e
Cheers,
--
Will
https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-05 16:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-23 16:59 [PATCH] arm64: arch_timer: reuse arch_timer_read_cnt{p,v}ct_el0() helpers Breno Leitao
2026-06-05 16:43 ` Will Deacon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox