Commit 357ec64b authored by Berend Ozceri's avatar Berend Ozceri Committed by Christopher Friedt
Browse files

drivers: timer: Fix RISC-V machine timer count drift due integer math

If CYC_PER_TICK does not divide the (now - last_count) quantity exactly with integer math, the subsequent multiplication before incrementing last_count causes a drift. This commit eliminates the redundant division-followed-by-multiplication and fixes https://github.com/zephyrproject-rtos/zephyr/issues/37852



Signed-off-by: default avatarBerend Ozceri <berend@recogni.com>
parent 123be4f1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ static void timer_isr(const void *arg)
	uint64_t now = mtime();
	uint32_t dticks = (uint32_t)((now - last_count) / CYC_PER_TICK);

	last_count += dticks * CYC_PER_TICK;
	last_count = now;

	if (!TICKLESS) {
		uint64_t next = last_count + CYC_PER_TICK;