From dad3b6c6fd41ae85474bda91ea5282c8cca3d8c5 Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Wed, 26 Mar 2008 22:12:00 +0000 Subject: [PATCH] Back in the good old days, PC's had random pieces of rock for frequency generation and what frequency the generated was anyones guess. In general the 32.768kHz RTC clock x-tal was the best, because that was a regular wrist-watch Xtal, whereas the X-tal generating the ISA bus frequency was much lower quality, often costing as much as several cents a piece, so it made good sense to check the ISA bus frequency against the RTC clock. The other relevant property of those machines, is that they typically had no more than 16MB RAM. These days, CPU chips croak if their clocks are not tightly within specs and all necessary frequencies are derived from the master crystal by means if PLL's. Considering that it takes on average 1.5 second to calibrate the frequency of the i8254 counter, that more likely than not, we will not actually use the result of the calibration, and as the final clincher, we seldom use the i8254 for anything besides BEL in syscons anyway, it has become time to drop the calibration code. If you need to tell the system what frequency your i8254 runs, you can do so from the loader using hw.i8254.freq or using the sysctl kern.timecounter.tc.i8254.frequency. --- sys/amd64/conf/NOTES | 13 ----- sys/amd64/isa/clock.c | 112 ------------------------------------- sys/conf/options.amd64 | 2 - sys/conf/options.i386 | 2 - sys/conf/options.pc98 | 2 - sys/i386/conf/NOTES | 13 ----- sys/i386/isa/clock.c | 122 ----------------------------------------- sys/isa/atrtc.c | 122 ----------------------------------------- sys/pc98/cbus/clock.c | 98 --------------------------------- sys/pc98/cbus/pcrtc.c | 98 --------------------------------- sys/pc98/conf/NOTES | 17 ------ 11 files changed, 601 deletions(-) diff --git a/sys/amd64/conf/NOTES b/sys/amd64/conf/NOTES index bfa1c9bce1c..9be763e7bea 100644 --- a/sys/amd64/conf/NOTES +++ b/sys/amd64/conf/NOTES @@ -88,19 +88,6 @@ options BPF_JITTER ##################################################################### # CLOCK OPTIONS -# The following options are used for debugging clock behavior only, and -# should not be used for production systems. - -# CLK_CALIBRATION_LOOP causes clock calibration to be run in a loop at -# startup until the user presses a key. (The i8254 clock is always -# calibrated relative to the RTC (mc146818a) and this option causes the -# calibration to be repeated.) -options CLK_CALIBRATION_LOOP - -# CLK_USE_I8254_CALIBRATION causes the calibrated frequency of the i8254 -# clock to actually be used. -options CLK_USE_I8254_CALIBRATION - # Provide read/write access to the memory in the clock chip. device nvram # Access to rtc cmos via /dev/nvram diff --git a/sys/amd64/isa/clock.c b/sys/amd64/isa/clock.c index 342fe18c5a7..5cc076ee138 100644 --- a/sys/amd64/isa/clock.c +++ b/sys/amd64/isa/clock.c @@ -430,86 +430,6 @@ readrtc(int port) return(bcd2bin(rtcin(port))); } -static u_int -calibrate_clocks(void) -{ - u_int count, prev_count, tot_count; - int sec, start_sec, timeout; - - if (bootverbose) - printf("Calibrating clock(s) ... "); - if (!(rtcin(RTC_STATUSD) & RTCSD_PWR)) - goto fail; - timeout = 100000000; - - /* Read the mc146818A seconds counter. */ - for (;;) { - if (!(rtcin(RTC_STATUSA) & RTCSA_TUP)) { - sec = rtcin(RTC_SEC); - break; - } - if (--timeout == 0) - goto fail; - } - - /* Wait for the mC146818A seconds counter to change. */ - start_sec = sec; - for (;;) { - if (!(rtcin(RTC_STATUSA) & RTCSA_TUP)) { - sec = rtcin(RTC_SEC); - if (sec != start_sec) - break; - } - if (--timeout == 0) - goto fail; - } - - /* Start keeping track of the i8254 counter. */ - prev_count = getit(); - if (prev_count == 0 || prev_count > i8254_max_count) - goto fail; - tot_count = 0; - - /* - * Wait for the mc146818A seconds counter to change. Read the i8254 - * counter for each iteration since this is convenient and only - * costs a few usec of inaccuracy. The timing of the final reads - * of the counters almost matches the timing of the initial reads, - * so the main cause of inaccuracy is the varying latency from - * inside getit() or rtcin(RTC_STATUSA) to the beginning of the - * rtcin(RTC_SEC) that returns a changed seconds count. The - * maximum inaccuracy from this cause is < 10 usec on 486's. - */ - start_sec = sec; - for (;;) { - if (!(rtcin(RTC_STATUSA) & RTCSA_TUP)) - sec = rtcin(RTC_SEC); - count = getit(); - if (count == 0 || count > i8254_max_count) - goto fail; - if (count > prev_count) - tot_count += prev_count - (count - i8254_max_count); - else - tot_count += prev_count - count; - prev_count = count; - if (sec != start_sec) - break; - if (--timeout == 0) - goto fail; - } - - if (bootverbose) { - printf("i8254 clock: %u Hz\n", tot_count); - } - return (tot_count); - -fail: - if (bootverbose) - printf("failed, using default i8254 clock of %u Hz\n", - i8254_freq); - return (i8254_freq); -} - static void set_i8254_freq(u_int freq, int intr_freq) { @@ -547,42 +467,10 @@ i8254_init(void) void startrtclock() { - u_int delta, freq; writertc(RTC_STATUSA, rtc_statusa); writertc(RTC_STATUSB, RTCSB_24HR); - freq = calibrate_clocks(); -#ifdef CLK_CALIBRATION_LOOP - if (bootverbose) { - printf( - "Press a key on the console to abort clock calibration\n"); - while (cncheckc() == -1) - calibrate_clocks(); - } -#endif - - /* - * Use the calibrated i8254 frequency if it seems reasonable. - * Otherwise use the default, and don't use the calibrated i586 - * frequency. - */ - delta = freq > i8254_freq ? freq - i8254_freq : i8254_freq - freq; - if (delta < i8254_freq / 100) { -#ifndef CLK_USE_I8254_CALIBRATION - if (bootverbose) - printf( -"CLK_USE_I8254_CALIBRATION not specified - using default frequency\n"); - freq = i8254_freq; -#endif - i8254_freq = freq; - } else { - if (bootverbose) - printf( - "%d Hz differs from default of %d Hz by more than 1%%\n", - freq, i8254_freq); - } - set_i8254_freq(i8254_freq, hz); tc_init(&i8254_timecounter); diff --git a/sys/conf/options.amd64 b/sys/conf/options.amd64 index 258b0b75de7..b05b770875a 100644 --- a/sys/conf/options.amd64 +++ b/sys/conf/options.amd64 @@ -21,8 +21,6 @@ LINPROCFS opt_dontuse.h LINSYSFS opt_dontuse.h NDISAPI opt_dontuse.h -CLK_CALIBRATION_LOOP opt_clock.h -CLK_USE_I8254_CALIBRATION opt_clock.h TIMER_FREQ opt_clock.h # options for serial support diff --git a/sys/conf/options.i386 b/sys/conf/options.i386 index 3fc3fb17473..8cdaa5efc52 100644 --- a/sys/conf/options.i386 +++ b/sys/conf/options.i386 @@ -36,8 +36,6 @@ KVA_PAGES opt_global.h # Physical address extensions and support for >4G ram. As above. PAE opt_global.h -CLK_CALIBRATION_LOOP opt_clock.h -CLK_USE_I8254_CALIBRATION opt_clock.h TIMER_FREQ opt_clock.h CPU_ATHLON_SSE_HACK opt_cpu.h diff --git a/sys/conf/options.pc98 b/sys/conf/options.pc98 index 605870a07a0..d910ff264e2 100644 --- a/sys/conf/options.pc98 +++ b/sys/conf/options.pc98 @@ -31,8 +31,6 @@ PECOFF_SUPPORT opt_dontuse.h # Change KVM size. Changes things all over the kernel. KVA_PAGES opt_global.h -CLK_CALIBRATION_LOOP opt_clock.h -CLK_USE_I8254_CALIBRATION opt_clock.h TIMER_FREQ opt_clock.h # options for serial support diff --git a/sys/i386/conf/NOTES b/sys/i386/conf/NOTES index 7fac7b8b560..c8401d066d6 100644 --- a/sys/i386/conf/NOTES +++ b/sys/i386/conf/NOTES @@ -259,19 +259,6 @@ options BPF_JITTER ##################################################################### # CLOCK OPTIONS -# The following options are used for debugging clock behavior only, and -# should not be used for production systems. - -# CLK_CALIBRATION_LOOP causes clock calibration to be run in a loop at -# startup until the user presses a key. (The i8254 clock is always -# calibrated relative to the RTC (mc146818a) and this option causes the -# calibration to be repeated.) -options CLK_CALIBRATION_LOOP - -# CLK_USE_I8254_CALIBRATION causes the calibrated frequency of the i8254 -# clock to actually be used. -options CLK_USE_I8254_CALIBRATION - # Provide read/write access to the memory in the clock chip. device nvram # Access to rtc cmos via /dev/nvram diff --git a/sys/i386/isa/clock.c b/sys/i386/isa/clock.c index d5aa1189cce..09a9dc4cb2a 100644 --- a/sys/i386/isa/clock.c +++ b/sys/i386/isa/clock.c @@ -56,34 +56,24 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include -#include #include #include #include #include -#include #include -#include #include -#include #include #include #include -#include -#include #include #include -#include #include #include #include -#include #ifdef DEV_APIC #include #endif -#include #include #include @@ -445,86 +435,6 @@ readrtc(int port) return(bcd2bin(rtcin(port))); } -static u_int -calibrate_clocks(void) -{ - u_int count, prev_count, tot_count; - int sec, start_sec, timeout; - - if (bootverbose) - printf("Calibrating clock(s) ... "); - if (!(rtcin(RTC_STATUSD) & RTCSD_PWR)) - goto fail; - timeout = 100000000; - - /* Read the mc146818A seconds counter. */ - for (;;) { - if (!(rtcin(RTC_STATUSA) & RTCSA_TUP)) { - sec = rtcin(RTC_SEC); - break; - } - if (--timeout == 0) - goto fail; - } - - /* Wait for the mC146818A seconds counter to change. */ - start_sec = sec; - for (;;) { - if (!(rtcin(RTC_STATUSA) & RTCSA_TUP)) { - sec = rtcin(RTC_SEC); - if (sec != start_sec) - break; - } - if (--timeout == 0) - goto fail; - } - - /* Start keeping track of the i8254 counter. */ - prev_count = getit(); - if (prev_count == 0 || prev_count > i8254_max_count) - goto fail; - tot_count = 0; - - /* - * Wait for the mc146818A seconds counter to change. Read the i8254 - * counter for each iteration since this is convenient and only - * costs a few usec of inaccuracy. The timing of the final reads - * of the counters almost matches the timing of the initial reads, - * so the main cause of inaccuracy is the varying latency from - * inside getit() or rtcin(RTC_STATUSA) to the beginning of the - * rtcin(RTC_SEC) that returns a changed seconds count. The - * maximum inaccuracy from this cause is < 10 usec on 486's. - */ - start_sec = sec; - for (;;) { - if (!(rtcin(RTC_STATUSA) & RTCSA_TUP)) - sec = rtcin(RTC_SEC); - count = getit(); - if (count == 0 || count > i8254_max_count) - goto fail; - if (count > prev_count) - tot_count += prev_count - (count - i8254_max_count); - else - tot_count += prev_count - count; - prev_count = count; - if (sec != start_sec) - break; - if (--timeout == 0) - goto fail; - } - - if (bootverbose) { - printf("i8254 clock: %u Hz\n", tot_count); - } - return (tot_count); - -fail: - if (bootverbose) - printf("failed, using default i8254 clock of %u Hz\n", - i8254_freq); - return (i8254_freq); -} - static void set_i8254_freq(u_int freq, int intr_freq) { @@ -601,42 +511,10 @@ i8254_init(void) void startrtclock() { - u_int delta, freq; writertc(RTC_STATUSA, rtc_statusa); writertc(RTC_STATUSB, RTCSB_24HR); - freq = calibrate_clocks(); -#ifdef CLK_CALIBRATION_LOOP - if (bootverbose) { - printf( - "Press a key on the console to abort clock calibration\n"); - while (cncheckc() == -1) - calibrate_clocks(); - } -#endif - - /* - * Use the calibrated i8254 frequency if it seems reasonable. - * Otherwise use the default, and don't use the calibrated i586 - * frequency. - */ - delta = freq > i8254_freq ? freq - i8254_freq : i8254_freq - freq; - if (delta < i8254_freq / 100) { -#ifndef CLK_USE_I8254_CALIBRATION - if (bootverbose) - printf( -"CLK_USE_I8254_CALIBRATION not specified - using default frequency\n"); - freq = i8254_freq; -#endif - i8254_freq = freq; - } else { - if (bootverbose) - printf( - "%d Hz differs from default of %d Hz by more than 1%%\n", - freq, i8254_freq); - } - set_i8254_freq(i8254_freq, hz); tc_init(&i8254_timecounter); diff --git a/sys/isa/atrtc.c b/sys/isa/atrtc.c index d5aa1189cce..09a9dc4cb2a 100644 --- a/sys/isa/atrtc.c +++ b/sys/isa/atrtc.c @@ -56,34 +56,24 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include -#include #include #include #include #include -#include #include -#include #include -#include #include #include #include -#include -#include #include #include -#include #include #include #include -#include #ifdef DEV_APIC #include #endif -#include #include #include @@ -445,86 +435,6 @@ readrtc(int port) return(bcd2bin(rtcin(port))); } -static u_int -calibrate_clocks(void) -{ - u_int count, prev_count, tot_count; - int sec, start_sec, timeout; - - if (bootverbose) - printf("Calibrating clock(s) ... "); - if (!(rtcin(RTC_STATUSD) & RTCSD_PWR)) - goto fail; - timeout = 100000000; - - /* Read the mc146818A seconds counter. */ - for (;;) { - if (!(rtcin(RTC_STATUSA) & RTCSA_TUP)) { - sec = rtcin(RTC_SEC); - break; - } - if (--timeout == 0) - goto fail; - } - - /* Wait for the mC146818A seconds counter to change. */ - start_sec = sec; - for (;;) { - if (!(rtcin(RTC_STATUSA) & RTCSA_TUP)) { - sec = rtcin(RTC_SEC); - if (sec != start_sec) - break; - } - if (--timeout == 0) - goto fail; - } - - /* Start keeping track of the i8254 counter. */ - prev_count = getit(); - if (prev_count == 0 || prev_count > i8254_max_count) - goto fail; - tot_count = 0; - - /* - * Wait for the mc146818A seconds counter to change. Read the i8254 - * counter for each iteration since this is convenient and only - * costs a few usec of inaccuracy. The timing of the final reads - * of the counters almost matches the timing of the initial reads, - * so the main cause of inaccuracy is the varying latency from - * inside getit() or rtcin(RTC_STATUSA) to the beginning of the - * rtcin(RTC_SEC) that returns a changed seconds count. The - * maximum inaccuracy from this cause is < 10 usec on 486's. - */ - start_sec = sec; - for (;;) { - if (!(rtcin(RTC_STATUSA) & RTCSA_TUP)) - sec = rtcin(RTC_SEC); - count = getit(); - if (count == 0 || count > i8254_max_count) - goto fail; - if (count > prev_count) - tot_count += prev_count - (count - i8254_max_count); - else - tot_count += prev_count - count; - prev_count = count; - if (sec != start_sec) - break; - if (--timeout == 0) - goto fail; - } - - if (bootverbose) { - printf("i8254 clock: %u Hz\n", tot_count); - } - return (tot_count); - -fail: - if (bootverbose) - printf("failed, using default i8254 clock of %u Hz\n", - i8254_freq); - return (i8254_freq); -} - static void set_i8254_freq(u_int freq, int intr_freq) { @@ -601,42 +511,10 @@ i8254_init(void) void startrtclock() { - u_int delta, freq; writertc(RTC_STATUSA, rtc_statusa); writertc(RTC_STATUSB, RTCSB_24HR); - freq = calibrate_clocks(); -#ifdef CLK_CALIBRATION_LOOP - if (bootverbose) { - printf( - "Press a key on the console to abort clock calibration\n"); - while (cncheckc() == -1) - calibrate_clocks(); - } -#endif - - /* - * Use the calibrated i8254 frequency if it seems reasonable. - * Otherwise use the default, and don't use the calibrated i586 - * frequency. - */ - delta = freq > i8254_freq ? freq - i8254_freq : i8254_freq - freq; - if (delta < i8254_freq / 100) { -#ifndef CLK_USE_I8254_CALIBRATION - if (bootverbose) - printf( -"CLK_USE_I8254_CALIBRATION not specified - using default frequency\n"); - freq = i8254_freq; -#endif - i8254_freq = freq; - } else { - if (bootverbose) - printf( - "%d Hz differs from default of %d Hz by more than 1%%\n", - freq, i8254_freq); - } - set_i8254_freq(i8254_freq, hz); tc_init(&i8254_timecounter); diff --git a/sys/pc98/cbus/clock.c b/sys/pc98/cbus/clock.c index 38f9854f40f..05d34c5ec80 100644 --- a/sys/pc98/cbus/clock.c +++ b/sys/pc98/cbus/clock.c @@ -69,7 +69,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include @@ -325,71 +324,6 @@ DELAY(int n) #endif } -static u_int -calibrate_clocks(void) -{ - int timeout; - u_int count, prev_count, tot_count; - u_short sec, start_sec; - - if (bootverbose) - printf("Calibrating clock(s) ... "); - /* Check ARTIC. */ - if (!(PC98_SYSTEM_PARAMETER(0x458) & 0x80) && - !(PC98_SYSTEM_PARAMETER(0x45b) & 0x04)) - goto fail; - timeout = 100000000; - - /* Read the ARTIC. */ - sec = inw(0x5e); - - /* Wait for the ARTIC to changes. */ - start_sec = sec; - for (;;) { - sec = inw(0x5e); - if (sec != start_sec) - break; - if (--timeout == 0) - goto fail; - } - - /* Start keeping track of the i8254 counter. */ - prev_count = getit(); - if (prev_count == 0 || prev_count > i8254_max_count) - goto fail; - tot_count = 0; - - start_sec = sec; - for (;;) { - sec = inw(0x5e); - count = getit(); - if (count == 0 || count > i8254_max_count) - goto fail; - if (count > prev_count) - tot_count += prev_count - (count - i8254_max_count); - else - tot_count += prev_count - count; - prev_count = count; - if ((sec == start_sec + 1200) || /* 1200 = 307.2KHz >> 8 */ - (sec < start_sec && - (u_int)sec + 0x10000 == (u_int)start_sec + 1200)) - break; - if (--timeout == 0) - goto fail; - } - - if (bootverbose) { - printf("i8254 clock: %u Hz\n", tot_count); - } - return (tot_count); - -fail: - if (bootverbose) - printf("failed, using default i8254 clock of %u Hz\n", - i8254_freq); - return (i8254_freq); -} - static void set_i8254_freq(u_int freq, int intr_freq) { @@ -459,38 +393,6 @@ i8254_init(void) void startrtclock() { - u_int delta, freq; - - freq = calibrate_clocks(); -#ifdef CLK_CALIBRATION_LOOP - if (bootverbose) { - printf( - "Press a key on the console to abort clock calibration\n"); - while (cncheckc() == -1) - calibrate_clocks(); - } -#endif - - /* - * Use the calibrated i8254 frequency if it seems reasonable. - * Otherwise use the default, and don't use the calibrated i586 - * frequency. - */ - delta = freq > i8254_freq ? freq - i8254_freq : i8254_freq - freq; - if (delta < i8254_freq / 100) { -#ifndef CLK_USE_I8254_CALIBRATION - if (bootverbose) - printf( -"CLK_USE_I8254_CALIBRATION not specified - using default frequency\n"); - freq = i8254_freq; -#endif - i8254_freq = freq; - } else { - if (bootverbose) - printf( - "%d Hz differs from default of %d Hz by more than 1%%\n", - freq, i8254_freq); - } set_i8254_freq(i8254_freq, hz); tc_init(&i8254_timecounter); diff --git a/sys/pc98/cbus/pcrtc.c b/sys/pc98/cbus/pcrtc.c index 38f9854f40f..05d34c5ec80 100644 --- a/sys/pc98/cbus/pcrtc.c +++ b/sys/pc98/cbus/pcrtc.c @@ -69,7 +69,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include @@ -325,71 +324,6 @@ DELAY(int n) #endif } -static u_int -calibrate_clocks(void) -{ - int timeout; - u_int count, prev_count, tot_count; - u_short sec, start_sec; - - if (bootverbose) - printf("Calibrating clock(s) ... "); - /* Check ARTIC. */ - if (!(PC98_SYSTEM_PARAMETER(0x458) & 0x80) && - !(PC98_SYSTEM_PARAMETER(0x45b) & 0x04)) - goto fail; - timeout = 100000000; - - /* Read the ARTIC. */ - sec = inw(0x5e); - - /* Wait for the ARTIC to changes. */ - start_sec = sec; - for (;;) { - sec = inw(0x5e); - if (sec != start_sec) - break; - if (--timeout == 0) - goto fail; - } - - /* Start keeping track of the i8254 counter. */ - prev_count = getit(); - if (prev_count == 0 || prev_count > i8254_max_count) - goto fail; - tot_count = 0; - - start_sec = sec; - for (;;) { - sec = inw(0x5e); - count = getit(); - if (count == 0 || count > i8254_max_count) - goto fail; - if (count > prev_count) - tot_count += prev_count - (count - i8254_max_count); - else - tot_count += prev_count - count; - prev_count = count; - if ((sec == start_sec + 1200) || /* 1200 = 307.2KHz >> 8 */ - (sec < start_sec && - (u_int)sec + 0x10000 == (u_int)start_sec + 1200)) - break; - if (--timeout == 0) - goto fail; - } - - if (bootverbose) { - printf("i8254 clock: %u Hz\n", tot_count); - } - return (tot_count); - -fail: - if (bootverbose) - printf("failed, using default i8254 clock of %u Hz\n", - i8254_freq); - return (i8254_freq); -} - static void set_i8254_freq(u_int freq, int intr_freq) { @@ -459,38 +393,6 @@ i8254_init(void) void startrtclock() { - u_int delta, freq; - - freq = calibrate_clocks(); -#ifdef CLK_CALIBRATION_LOOP - if (bootverbose) { - printf( - "Press a key on the console to abort clock calibration\n"); - while (cncheckc() == -1) - calibrate_clocks(); - } -#endif - - /* - * Use the calibrated i8254 frequency if it seems reasonable. - * Otherwise use the default, and don't use the calibrated i586 - * frequency. - */ - delta = freq > i8254_freq ? freq - i8254_freq : i8254_freq - freq; - if (delta < i8254_freq / 100) { -#ifndef CLK_USE_I8254_CALIBRATION - if (bootverbose) - printf( -"CLK_USE_I8254_CALIBRATION not specified - using default frequency\n"); - freq = i8254_freq; -#endif - i8254_freq = freq; - } else { - if (bootverbose) - printf( - "%d Hz differs from default of %d Hz by more than 1%%\n", - freq, i8254_freq); - } set_i8254_freq(i8254_freq, hz); tc_init(&i8254_timecounter); diff --git a/sys/pc98/conf/NOTES b/sys/pc98/conf/NOTES index b5c3b000cde..6f50f50f55d 100644 --- a/sys/pc98/conf/NOTES +++ b/sys/pc98/conf/NOTES @@ -195,23 +195,6 @@ options DEVICE_POLLING options BPF_JITTER - -##################################################################### -# CLOCK OPTIONS - -# The following options are used for debugging clock behavior only, and -# should not be used for production systems. - -# CLK_CALIBRATION_LOOP causes clock calibration to be run in a loop at -# startup until the user presses a key. (The i8254 clock is always -# calibrated relative to the RTC (mc146818a) and this option causes the -# calibration to be repeated.) -options CLK_CALIBRATION_LOOP - -# CLK_USE_I8254_CALIBRATION causes the calibrated frequency of the i8254 -# clock to actually be used. -options CLK_USE_I8254_CALIBRATION - ##################################################################### # MISCELLANEOUS DEVICES AND OPTIONS