strange system clock issues

Ben Scott dragonhawk at gmail.com
Wed Aug 26 20:43:43 EDT 2009


On Wed, Aug 26, 2009 at 6:33 PM, Thomas Charron<twaffle at gmail.com> wrote:
> At startup, the RTC is
> interogated to set the system clock, and then is only used again if..
> Actually, I can't think of much that would requery it unless it is
> specifically opening it to do something outside of the kernel.

  It's not a query, but many Linux distros invoke "hwclock --systohc"
during shutdown.  Otherwise, time corrections made with the "date"
command or by ntpd wouldn't survive a reboot.  Unlike MS-DOS and MS
Windows, changing the system clock in Linux does *not* implicitly
update the battery clock as well.

> However, the RTC itself will generate a system time interupt every
> second.

  I do not believe the IBM-PC/AT RTC (what I call "battery clock",
since "real-time clock" is non-obvious) normally generates an
interrupt once per second.

  The RTC certainly doesn't advance the system clock.  That's done by
IRQ0, which fires 18 times per second.  The original IBM-PC and PC/XT
did not *have* an RTC.  You had to set the system clock at boot, and
then IRQ0 drove the show.

  The RTC can can be programmed to generate periodic interrupts, or
interrupts at a particular time.  Those come in on IRQ8.  (I had
forgotten this, but Google just reminded me).  That was useful in the
days of MS-DOS, when there was no OS and everything was single task
and interrupt driven.  It's not for the system clock.

  Disclaimer: It may be that Linux does something different to advance
the system clock.  The above is how the BIOS does things.  But since
the latest and greatest from Intel and AMD are still backwards
compatible with the original IBM-PC (1981), that's still how things
work unless the OS does different.

http://www.pcguide.com/ref/mbsys/res/irq/numIRQ0-c.html

http://www.pcguide.com/ref/mbsys/res/irq/numIRQ8-c.html

> The counts that Ben refers to below are the interrupt
> count of that once a second bang of the RTC interupt.

$ grep -e rtc -e timer /proc/interrupts
  0: 2321478409  local-APIC-edge  timer
  8:          3    IO-APIC-edge  rtc
$ uptime
 20:43:02 up 26 days, 20:46,  1 user,  load average: 0.00, 0.00, 0.00
$

  According to that, the RTC interrupt (IRQ8) has fired 3 times since
boot, while the system timer (IRQ0) has fired roughly 2.3 billion
times.  Which do you think is advancing the system clock?  :)

-- Ben


More information about the gnhlug-discuss mailing list