From b278b98232504971d575eb5a10eddfa7e5f49880 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Fri, 23 Aug 2024 06:58:33 +0000 Subject: [PATCH] arm64: Disable timer when not in use. * ARM documentation indicates this may save power. * Notably, the timer keeps ticking even when "disabled", but cannot be read by the core without temporarily "enabling" the timer. Change-Id: Iccff84915c611b43ee7a3c53ed2f8a3e426eda06 Reviewed-on: https://review.haiku-os.org/c/haiku/+/8093 Haiku-Format: Haiku-format Bot Tested-by: Commit checker robot Reviewed-by: Adrien Destugues --- src/system/kernel/arch/arm64/arch_timer.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/system/kernel/arch/arm64/arch_timer.cpp b/src/system/kernel/arch/arm64/arch_timer.cpp index a2cd77f6fd..d2c0ac631b 100644 --- a/src/system/kernel/arch/arm64/arch_timer.cpp +++ b/src/system/kernel/arch/arm64/arch_timer.cpp @@ -16,8 +16,11 @@ static uint64 sTimerTicksUS; static bigtime_t sTimerMaxInterval; static uint64 sBootTime; -#define TIMER_ARMED (1) -#define TIMER_MASKED (2 | 1) +#define TIMER_DISABLED (0) +#define TIMER_ENABLE (1) +#define TIMER_IMASK (2) +#define TIMER_ISTATUS (4) + #define TIMER_IRQ 27 @@ -28,21 +31,21 @@ arch_timer_set_hardware_timer(bigtime_t timeout) timeout = sTimerMaxInterval; WRITE_SPECIALREG(CNTV_TVAL_EL0, timeout * sTimerTicksUS); - WRITE_SPECIALREG(CNTV_CTL_EL0, TIMER_ARMED); + WRITE_SPECIALREG(CNTV_CTL_EL0, TIMER_ENABLE); } void arch_timer_clear_hardware_timer() { - WRITE_SPECIALREG(CNTV_CTL_EL0, TIMER_MASKED); + WRITE_SPECIALREG(CNTV_CTL_EL0, TIMER_DISABLED); } int32 arch_timer_interrupt(void *data) { - WRITE_SPECIALREG(CNTV_CTL_EL0, TIMER_MASKED); + WRITE_SPECIALREG(CNTV_CTL_EL0, TIMER_DISABLED); return timer_interrupt(); } @@ -53,7 +56,7 @@ arch_init_timer(kernel_args *args) sTimerTicksUS = READ_SPECIALREG(CNTFRQ_EL0) / 1000000; sTimerMaxInterval = INT32_MAX / sTimerTicksUS; - WRITE_SPECIALREG(CNTV_CTL_EL0, TIMER_MASKED); + WRITE_SPECIALREG(CNTV_CTL_EL0, TIMER_DISABLED); install_io_interrupt_handler(TIMER_IRQ, &arch_timer_interrupt, NULL, 0); sBootTime = READ_SPECIALREG(CNTPCT_EL0);