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@xxxxxxxxx> --- 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 _______________________________________________ barebox mailing list barebox@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/barebox