From eb208c746dc7a28237a24ffe50e31d4f829ead90 Mon Sep 17 00:00:00 2001 From: Nishanth Menon Date: Thu, 5 Jun 2008 19:45:08 +0200 Subject: 002-clock-overflow [Patch 02/17] U-Boot-V2: Handle case of clock rollover for get_time_ns get_time_ns does a simplistic delta = cycle_now - cycle_last. It is possible that the h/w counter reached max and reset back to 0. This patch addresses this issue by checking for rollover condition. NOTE 1: This does not guarentee that you cannot confuse get_time_ns. You could possibly wait for two reset cycles and then get a messed up value. To fix that we may need interrupt mode timer tick - something on the lines of jiffies on linux. NOTE 2: the question of cs->mask is not clear. if the mask is for the tick, then it is better done with (cycle_now & cs->mask) - (cs->cycle_last & cs->mask). Signed-off-by: Nishanth Menon --- common/clock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common/clock.c') diff --git a/common/clock.c b/common/clock.c index 4069d4e83b..e22b6a5409 100644 --- a/common/clock.c +++ b/common/clock.c @@ -41,7 +41,7 @@ uint64_t get_time_ns(void) uint64_t ns_offset; /* read clocksource: */ - cycle_now = cs->read(); + cycle_now = cs->read() & cs->mask; /* calculate the delta since the last call: */ cycle_delta = (cycle_now - cs->cycle_last) & cs->mask; -- cgit v1.2.3