i386/113540: decrease i8254 calibration precision to make it work with Xbox, remove warnings

Bruce Evans brde at optusnet.com.au
Tue Jun 12 05:59:11 UTC 2007


On Sun, 10 Jun 2007, Ed Schouten wrote:

>> Description:
> For some reason, the timers in the Microsoft Xbox aren't as sane as on
> PC's; it has two issues:
>
> - The frequency of the i8254 timer is 1125000 Hz instead of 1193182 Hz.
>  The Microsoft Xbox port currently solves this by hardcoding TIMER_FREQ
>  in the config file.
> - The diagnostic and status registers of the RTC contain invalid data,
>  which causes FreeBSD to assume the RTC is broken. This causes a lot of
>  spurious messages in the dmesg.
>> How-To-Repeat:
>> Fix:
> I've been using the following patch on my Xbox for a long time now; it
> essentially does the following things:
>
> - It changes the rtcin() routine to return fake values for the diagnose
>  and status registers, which forces FreeBSD to properly use theh RTC.
> - It decreases the precision of the timer (by default disabled) timer
>  calibration code from 1% to 10%; this is needed because the Xbox clock
>  is 6% off.

Is it only 6% off because the default is 6% off?  The error margin is
supposed to be just a sanity check, but if the i8254 clock frequency is
not required to be nearly 1193182 then this frequency can be almost
anything in theory and no sanity check works.

> - It removes the hardcoded Xbox timer value from the Xbox configuration
>  file and enables timer calibration.

I hope to remove the timer calibration.  It was mainly for RTC calibration,
but that most important part of it has been axed.  In practice, the i8254
has always been nearly 1193182 until now, with an error of about the same
as for the RTC, so it doesn't matter which of these is used as a reference.
What I do now is not worry much about initial calibration; then fix up
the frequencies of all timecounters in /etc/rc.local, using the results
of more accurate calibrations previously done in userland.  Unfortunately,
this requires a lot of setup (ntpd might be able to do it automatically
but might take years to stabilize if the initial frequencies are very
inaccurate).

> The reason why we want to do such a thing is because we could then
> compile kernels that run on Xbox'es and PC's without a clock drift on
> one of those systems.

You could make the frequency a tunable.  This would minimize clock drift
before the frequency can be fixed up in /etc/rc, but still requires
pre-calibration and storing the result somewhere.

Does XBOX have any other timers/timecounters that might give a more
suitable reference?

Bruce


More information about the freebsd-i386 mailing list