Skip to content

Commit

Permalink
[SPARC]: Make gettimeofday() monotonic again.
Browse files Browse the repository at this point in the history
When we switched away from the optimized C version
things stopped being monotonic.

The problem is that if we run this with interrupts disabled, we can
see the interrupt pending because the counter reached the limit value.
When this happens the counter has bit 31 set, and the low bits start
counting again from zero.

Reported by Martin Habets.

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Jan 13, 2008
1 parent d0c4c9d commit 000775c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion arch/sparc/kernel/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,14 @@ void __init time_init(void)

static inline unsigned long do_gettimeoffset(void)
{
return (*master_l10_counter >> 10) & 0x1fffff;
unsigned long val = *master_l10_counter;
unsigned long usec = (val >> 10) & 0x1fffff;

/* Limit hit? */
if (val & 0x80000000)
usec += 1000000 / HZ;

return usec;
}

/* Ok, my cute asm atomicity trick doesn't work anymore.
Expand Down

0 comments on commit 000775c

Please sign in to comment.