From 737429bc962ecabc5c530a8e648a231f66358b70 Mon Sep 17 00:00:00 2001 From: Peter Wemm Date: Tue, 13 Dec 2005 19:08:55 +0000 Subject: [PATCH] MFamd64 rev 1.223: Use the TSC to implement DELAY() if not marked broken and it has been calibrated. --- sys/i386/isa/clock.c | 15 +++++++++++++++ sys/isa/atrtc.c | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/sys/i386/isa/clock.c b/sys/i386/isa/clock.c index 38b238f6dd92..7a75cfb0befc 100644 --- a/sys/i386/isa/clock.c +++ b/sys/i386/isa/clock.c @@ -64,6 +64,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -288,7 +289,21 @@ DELAY(int n) int getit_calls = 1; int n1; static int state = 0; +#endif + if (tsc_freq != 0 && !tsc_is_broken) { + uint64_t start, end, now; + + sched_pin(); + start = rdtsc(); + end = start + (tsc_freq * n) / 1000000; + do { + now = rdtsc(); + } while (now < end || (now > start && end < start)); + sched_unpin(); + return; + } +#ifdef DELAYDEBUG if (state == 0) { state = 1; for (n1 = 1; n1 <= 10000000; n1 *= 10) diff --git a/sys/isa/atrtc.c b/sys/isa/atrtc.c index 38b238f6dd92..7a75cfb0befc 100644 --- a/sys/isa/atrtc.c +++ b/sys/isa/atrtc.c @@ -64,6 +64,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -288,7 +289,21 @@ DELAY(int n) int getit_calls = 1; int n1; static int state = 0; +#endif + if (tsc_freq != 0 && !tsc_is_broken) { + uint64_t start, end, now; + + sched_pin(); + start = rdtsc(); + end = start + (tsc_freq * n) / 1000000; + do { + now = rdtsc(); + } while (now < end || (now > start && end < start)); + sched_unpin(); + return; + } +#ifdef DELAYDEBUG if (state == 0) { state = 1; for (n1 = 1; n1 <= 10000000; n1 *= 10)