Difference in time stamps between /proc/uptime and dmesg

727 views Asked by At

Today I noticed an issue with the timestamps in my Linux box running redhat 7.3. The timestamp as shown in dmesg is behind of the one shown in /proc/uptime

# echo TEST > /dev/kmsg &&  dmesg | tail -1 && cat /proc/uptime
  [661503.956980] TEST
  661301.99 15107232.56

As I understand, they both shows the number of seconds passed since the kernel initialized. Then what could be causing the difference here ?

2

There are 2 answers

5
Nikita Yushchenko On

dmesg timestamps show CLOCK_MONOTONIC, while /proc/uptime shows CLOCK_BOOTTIME.

See 'man timer_create' for details on what CLOCK_* is.

0
Changbin Du On

They are different clocks.

  • The timestamps of kernel dmesg are retrieved by kernel internal local_clock(), which is not exported to userspace. It's not CLOCK_MONOTONIC nor CLOCK_MONOTONIC_RAW.

  • The time shown in /proc/uptime is CLOCK_BOOTTIME. CLOCK_BOOTTIME is identical to CLOCK_MONOTONIC, except that it also includes any time that the system is suspended.

On x86, these two clocks are usually both based on tsc clock. But they are managed independently.