All of lore.kernel.org
 help / color / mirror / Atom feed
* /proc/stat btime accuracy problem
@ 2011-06-01 20:50 Bjorn Helgaas
  2011-06-01 22:35 ` john stultz
  0 siblings, 1 reply; 13+ messages in thread
From: Bjorn Helgaas @ 2011-06-01 20:50 UTC (permalink / raw)
  To: John Stultz, Thomas Gleixner; +Cc: linux-kernel

timekeeping_init() basically does the following:

    xtime = RTC
    if (arch implements read_boot_clock())
        wall_to_monotonic = -read_boot_clock()
    else
      wall_to_monotonic = -xtime

So wall_to_monotonic records some approximation of the system boot
time, which is then used to derive the "btime" reported in /proc/stat.

The problem I'm seeing is that xtime is updated on timer ticks, so
uninterruptible code, like kernel serial printk, makes us miss ticks,
so xtime falls behind the RTC.  Then, when userland fixes xtime, in my
case with "hwclock --hctosys", the delta is applied to both xtime and
wall_to_monotonic.  The result is that "btime" is no longer accurate.

Here's an example where I artificially exaggerated the problem by
adding 30 seconds of wait time with interrupts disabled.  Assume the
RTC is perfectly correct at boot, and note that xtime has fallen
behind the RTC by 31 seconds by the time userland resets the clock:

  rtc 1306957603 xtime 1306957603 wall_to_monotonic -1306957603  in
timekeeping_init()
  rtc 1306957638 xtime 1306957607 wall_to_monotonic -1306957603
before do_settimeofday()
  rtc 1306957638 xtime 1306957638 wall_to_monotonic -1306957634  after
do_settimeofday()

Now /proc/stat btime reports 1306957634 instead of the correct 1306957603.

Bjorn

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2011-06-08  4:17 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-01 20:50 /proc/stat btime accuracy problem Bjorn Helgaas
2011-06-01 22:35 ` john stultz
2011-06-01 23:35   ` Bjorn Helgaas
2011-06-01 23:58     ` john stultz
2011-06-02  0:31       ` Bjorn Helgaas
2011-06-02  0:49         ` john stultz
2011-06-02  6:34           ` Bjorn Helgaas
2011-06-07  5:20             ` Bjorn Helgaas
2011-06-07 17:50               ` john stultz
2011-06-08  1:03                 ` john stultz
2011-06-08  4:16                   ` Bjorn Helgaas
2011-06-08  4:16                     ` Bjorn Helgaas
2011-06-02 10:00           ` Alan Cox

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.