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.
This commit is contained in:
Poul-Henning Kamp 2008-03-26 22:12:00 +00:00
parent 1d73a9dc74
commit dad3b6c6fd
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=177651
11 changed files with 0 additions and 601 deletions

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -56,34 +56,24 @@ __FBSDID("$FreeBSD$");
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/clock.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <sys/lock.h>
#include <sys/kdb.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/time.h>
#include <sys/timetc.h>
#include <sys/uio.h>
#include <sys/kernel.h>
#include <sys/limits.h>
#include <sys/module.h>
#include <sys/sched.h>
#include <sys/sysctl.h>
#include <sys/cons.h>
#include <sys/power.h>
#include <machine/clock.h>
#include <machine/cpu.h>
#include <machine/cputypes.h>
#include <machine/frame.h>
#include <machine/intr_machdep.h>
#include <machine/md_var.h>
#include <machine/psl.h>
#ifdef DEV_APIC
#include <machine/apicvar.h>
#endif
#include <machine/specialreg.h>
#include <machine/ppireg.h>
#include <machine/timerreg.h>
@ -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);

View File

@ -56,34 +56,24 @@ __FBSDID("$FreeBSD$");
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/clock.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <sys/lock.h>
#include <sys/kdb.h>
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/time.h>
#include <sys/timetc.h>
#include <sys/uio.h>
#include <sys/kernel.h>
#include <sys/limits.h>
#include <sys/module.h>
#include <sys/sched.h>
#include <sys/sysctl.h>
#include <sys/cons.h>
#include <sys/power.h>
#include <machine/clock.h>
#include <machine/cpu.h>
#include <machine/cputypes.h>
#include <machine/frame.h>
#include <machine/intr_machdep.h>
#include <machine/md_var.h>
#include <machine/psl.h>
#ifdef DEV_APIC
#include <machine/apicvar.h>
#endif
#include <machine/specialreg.h>
#include <machine/ppireg.h>
#include <machine/timerreg.h>
@ -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);

View File

@ -69,7 +69,6 @@ __FBSDID("$FreeBSD$");
#include <sys/limits.h>
#include <sys/module.h>
#include <sys/sysctl.h>
#include <sys/cons.h>
#include <sys/power.h>
#include <machine/clock.h>
@ -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);

View File

@ -69,7 +69,6 @@ __FBSDID("$FreeBSD$");
#include <sys/limits.h>
#include <sys/module.h>
#include <sys/sysctl.h>
#include <sys/cons.h>
#include <sys/power.h>
#include <machine/clock.h>
@ -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);

View File

@ -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