Handle the situation of a wrapped interval counter, while the hardclock()

interrupt was not yet executed to update the hardclock_ticks variable.
This commit is contained in:
phx 2009-09-11 19:43:08 +00:00
parent 9501383a83
commit a1fee67004
1 changed files with 17 additions and 2 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: clock.c,v 1.49 2009/09/11 13:11:15 phx Exp $ */
/* $NetBSD: clock.c,v 1.50 2009/09/11 19:43:08 phx Exp $ */
/*
* Copyright (c) 1982, 1990 The Regents of the University of California.
@ -77,7 +77,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.49 2009/09/11 13:11:15 phx Exp $");
__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.50 2009/09/11 19:43:08 phx Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@ -326,6 +326,8 @@ clk_gettick(void)
static u_int
clk_getcounter(struct timecounter *tc)
{
static int last_hardclock_ticks;
static u_int last_clock_tick = 0;
int old_hardclock_ticks;
u_int clock_tick;
@ -334,6 +336,19 @@ clk_getcounter(struct timecounter *tc)
clock_tick = clk_gettick();
} while (old_hardclock_ticks != hardclock_ticks);
/*
* Handle the situation of a wrapped interval counter, while
* the hardclock() interrupt was not yet executed to update
* hardclock_ticks.
*/
if (last_hardclock_ticks > old_hardclock_ticks)
old_hardclock_ticks = last_hardclock_ticks;
if (clock_tick < last_clock_tick &&
old_hardclock_ticks == last_hardclock_ticks)
old_hardclock_ticks++;
last_hardclock_ticks = old_hardclock_ticks;
last_clock_tick = clock_tick;
return old_hardclock_ticks * amiga_clk_interval + clock_tick;
}