Subject: Re: interrupts (was Clockticks lost)
To: Erik E. Fair <fair@clock.org>
From: Bill Studenmund <wrstuden@loki.stanford.edu>
List: port-mac68k
Date: 01/24/1997 16:30:56
> At 2:52 -0800 1/24/97, Christoph Ewering wrote:
> >Hello guys!
> >
> >Could someone explain to me why it is so difficult for a Unix-system to
> >hold the time.
> 
> Short answer: because the vendors don't care. They produce systems with
> cheap crystal oscillators, and then (as noted) set them to lower than the
> highest priority interrupt, and they write hacks to the UNIX kernel (device
> drivers, other "critical" sections) which disable interrupts far too long.

Part of the blame here goes to Apple for making the clock interrupt
low priority. :-)

> The way to fix it is two fold:
> 
> 1. Eliminate as much of the p =3D spl7(); /* critical code */; splx(p); out
> of the kernel as possible; write device drivers to defer serious processing
> until after the device interrupt is dismissed.

Since the clock is at the lowest interrupt level, ANYTHING blocking
interrupts (even things allowing HD or serial port interrupts) will
block the clock. I just checked, and indeed, the RTC is on via1, which
is a level 1 interrupt. A WHOLE lot of the kernel blocks level one
interrupts, even things which don't need to.

Right now, things like spltty, splsoftnet, and splsoftclock all block
via1. They don't really need to as they are really software semaphores.
spltty, for example, locks others out of feeding characters to the
tty subsystem. splsoftnet single-threads the networking code. splsoftclock
single-threads changes to the internal time (I don't fully understand
this one).

I've heard tell of ports that impliment spltty and splsoftnet at
spl0 - i.e. they really just block task switches. If we migrated
to such a thing, I think we'd keep the date beter. The two sticking
points are that the ADB system must use a two-level interrupt
structure (I don't know if it does now, but it's blocked by
spltty now, so it might not), and that spl0 becomes interesting. W/o
this change, spl0 means enable all interrupts, and possably get a clock
tick which will let the scheduler run a different process. But the main
emphasis of spltty and splsoftnet are to prevent switches, so the
swithc has to be defered to the spl0, which now must look for lingering
switches.

Thoughts?

Take care,

Bill