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:
Berend Ozceri 2021-09-15 14:12:42 -07:00 committed by Christopher Friedt
parent 123be4f13d
commit 357ec64b36
1 changed files with 1 additions and 1 deletions

View File

@ -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;