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: Berend Ozceri <berend@recogni.com>
This commit is contained in:
parent
123be4f13d
commit
357ec64b36
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue