riscv_mtimer: modify riscv_mtimer_current to reduce precision lost
Signed-off-by: liaoao <liaoao@xiaomi.com>
This commit is contained in:
parent
339457dda3
commit
512a496467
@ -319,10 +319,11 @@ static int riscv_mtimer_current(struct oneshot_lowerhalf_s *lower,
|
||||
struct riscv_mtimer_lowerhalf_s *priv =
|
||||
(struct riscv_mtimer_lowerhalf_s *)lower;
|
||||
uint64_t mtime = riscv_mtimer_get_mtime(priv);
|
||||
uint64_t nsec = mtime / (priv->freq / USEC_PER_SEC) * NSEC_PER_USEC;
|
||||
uint64_t left;
|
||||
|
||||
ts->tv_sec = nsec / NSEC_PER_SEC;
|
||||
ts->tv_nsec = nsec % NSEC_PER_SEC;
|
||||
ts->tv_sec = mtime / priv->freq;
|
||||
left = mtime - ts->tv_sec * priv->freq;
|
||||
ts->tv_nsec = NSEC_PER_SEC * left / priv->freq;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user