diff options
author | bde <bde@FreeBSD.org> | 1999-05-28 14:08:59 +0000 |
---|---|---|
committer | bde <bde@FreeBSD.org> | 1999-05-28 14:08:59 +0000 |
commit | 639d45925192cc9e90ee6a2d2a1d207f2be07e71 (patch) | |
tree | 5a485bd9bf242adc519c2591f634416db18a5c8e /sys/isa | |
parent | 2c39f0fd7d079a2cea7dcf8425e931366294a5fe (diff) | |
download | FreeBSD-src-639d45925192cc9e90ee6a2d2a1d207f2be07e71.zip FreeBSD-src-639d45925192cc9e90ee6a2d2a1d207f2be07e71.tar.gz |
Fixed glitches (jumps) of about 1/HZ seconds for the i8254 timecounter.
The old version only worked right when the time was read strictly
more often than every 1/HZ seconds, but we only guarantee reading
it every (1/HZ + epsilon) seconds. Part of rev.1.126-1.127 attempted
to fix this but didn't succeed. Detect counter rollover using the
heuristic from the old version of microtime() with additional
complications for supporting calls from fast interrupt handlers.
This works provided i8254 interrupts are not delayed by more than
1/(2*HZ) seconds.
This needs more comments, and cleanups for the SMP case, and more
testing of the SMP case before it is merged into RELENG_3.
Tested by: jhay
Diffstat (limited to 'sys/isa')
-rw-r--r-- | sys/isa/atrtc.c | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/sys/isa/atrtc.c b/sys/isa/atrtc.c index d9ee00e..75511f4 100644 --- a/sys/isa/atrtc.c +++ b/sys/isa/atrtc.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)clock.c 7.2 (Berkeley) 5/12/91 - * $Id: clock.c,v 1.132 1999/04/25 09:00:00 phk Exp $ + * $Id: clock.c,v 1.133 1999/05/09 23:32:29 peter Exp $ */ /* @@ -69,6 +69,7 @@ #include <machine/ipl.h> #include <machine/limits.h> #include <machine/md_var.h> +#include <machine/psl.h> #if NAPM > 0 #include <machine/apm_bios.h> #include <i386/apm/apm_setup.h> @@ -127,6 +128,7 @@ static void setup_8254_mixed_mode __P((void)); #define TIMER0_MAX_FREQ 20000 int adjkerntz; /* local offset from GMT in seconds */ +int clkintr_pending; int disable_rtc_set; /* disable resettodr() if != 0 */ volatile u_int idelayed; int statclock_disable; @@ -199,24 +201,15 @@ static void clkintr(struct clockframe frame) { if (timecounter->tc_get_timecount == i8254_get_timecount) { - /* - * Maintain i8254_offset and related variables. Optimize - * the usual case where i8254 counter rollover has not been - * detected in i8254_get_timecount() by pretending that we - * read the counter when it rolled over. Otherwise, call - * i8254_get_timecount() to do most of the work. The - * hardware counter must be read to ensure monotonicity - * despite multiple rollovers and misbehaving hardware. - */ - (disable_intr)(); /* XXX avoid clock locking */ - if (i8254_ticked) { - i8254_get_timecount(NULL); + disable_intr(); + if (i8254_ticked) i8254_ticked = 0; - } else { + else { i8254_offset += timer0_max_count; i8254_lastcount = 0; } - (enable_intr)(); /* XXX avoid clock locking */ + clkintr_pending = 0; + enable_intr(); } timer_func(&frame); switch (timer0_state) { @@ -1159,13 +1152,21 @@ i8254_get_timecount(struct timecounter *tc) low = inb(TIMER_CNTR0); high = inb(TIMER_CNTR0); - - count = hardclock_max_count - ((high << 8) | low); - if (count < i8254_lastcount) { + count = timer0_max_count - ((high << 8) | low); + if (count < i8254_lastcount || + (!i8254_ticked && (clkintr_pending || + ((count < 20 || (!(ef & PSL_I) && count < timer0_max_count / 2u)) && +#ifdef APIC_IO +#define lapic_irr1 ((volatile u_int *)&lapic)[0x210 / 4] /* XXX XXX */ + /* XXX this assumes that apic_8254_intr is < 24. */ + (lapic_irr1 & (1 << apic_8254_intr)))) +#else + (inb(IO_ICU1) & 1))) +#endif + )) { i8254_ticked = 1; - i8254_offset += hardclock_max_count; + i8254_offset += timer0_max_count; } - i8254_lastcount = count; count += i8254_offset; CLOCK_UNLOCK(); |