Subject: Re: apic timing/clock problem in 4.0_RC3, MacBook 2x2.0
To: None <port-i386@netbsd.org>
From: Marco Trillo <marcotrillo@gmail.com>
List: port-i386
Date: 11/03/2007 19:04:03
Hi,

On 11/3/07, Bernd Ernesti <netbsd@lists.veego.de> wrote:
> On Sat, Nov 03, 2007 at 02:19:37PM +0100, Marco Trillo wrote:
> > Hi all,
> >
> > I installed NetBSD 4.0_RC3/i386 on a 2x2.0 MacBook (the original model
> > with a 32-bit Core Duo, not the one with 64-bit Core 2 Duo) -- dmesg
> > attached.
> >
> > I'm running the GENERIC.MP and everything works fine (SMP, devices,
> > etc.) except one timing problem.
>
> Can you open a PR by using send-pr so this doesn't get lost?

OK, I'll send a PR.

I have collected more information about the issue: I found a Linux
bugreport of a similar problem (APIC timing calibration problem) which
contained a possible cause: some feature of the Intel ICH7 called
"LEGACY_USB" which "causes legacy USB circuit to cause SMI";
apparently such SMIs in the middle of the calibration process botch
it.

Based on such report, I have added a quirk at the start of the
initrtclock() function in src/sys/arch/x86/isa/clock.c to disable the
LEGACY_USB SMI bit:

outl(0x430, inl(0x430) & ~8);

Indeed, the quirk appears to be working:

cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel Pentium M (Yonah) (686-class), 1997.51 MHz
[snip]
cpu0: calibrating local timer
cpu0: apic clock running at 166 MHz
[snip]
cpu1: Intel Pentium M (Yonah) (686-class), 1997.33 MHz
[snip]

The apic clock is reported always at 166 MHz in each of the reboots,
no more different values in each reboot. Also the processor speed is
guessed correctly. The timing appears to work now:

# sleep 2
(sleeps 2 seconds)

There were also other issues which are perhaps related to this:
sometimes the cpu1 processor would fail to start. Pressing random keys
in the USB keyboard before the cpu1 is started made it to always start
reliably.
I have found some FreeBSD MacBook documents that report the same kind
of problem.

I'll see if this issue still happens with the new USB quirk.

Apart from these quirks, the system works great, including the
Centrino speed scaling which allows chaning the CPU frequency to one
of {2000, 1667, 1000}. I'm using 1000 now.


     -Marco