[PATCH 2/4] clock: Update cs->cycle_last when switching clock
Jules Maselbas
jmaselbas at kalray.eu
Thu Mar 25 13:38:35 GMT 2021
If clocksource is free-running it might have been running for a while
before barebox started, we only care about the time spent in barebox.
We can discard the cycles accumulated before switching clocks by
updating cs->cycle_last with the cycles read for the new clock right
before switching.
Signed-off-by: Jules Maselbas <jmaselbas at kalray.eu>
---
common/clock.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/common/clock.c b/common/clock.c
index 58c2964b1..e30c81a37 100644
--- a/common/clock.c
+++ b/common/clock.c
@@ -222,6 +222,12 @@ int init_clock(struct clocksource *cs)
return ret;
}
+ /*
+ * If clocksource is freerunning it might have been running for a while
+ * before barebox started, we only care about the time spent in barebox
+ * thus we must discard the clocksource cycles up to this exact moment:
+ */
+ cs->cycle_last = cs->read() & cs->mask;
current_clock = cs;
time_beginning = get_time_ns();
--
2.17.1
More information about the barebox
mailing list