Ubuntu – What counts towards uptime

kernelpower-managementuptime

The question is simple: do time periods when computer is in any of the states below count towards total uptime of a system ?

  • hibernation
  • suspending the system
  • changing runlevel

NOTE:

  • I am not interested in the uptime command itself. Quick look at source code link that Terrance provided reveals nothing about hibernation or suspending
  • I am interested in how does kernel compute the time system has been running, how does suspending/hibernating affect that value.
  • If possible, please provide a reference to documentation

Best Answer

The uptime command gets its data from /proc/uptime, which is exposed entirely by the kernel. So, we'll check out the kernel documentation to see what this actually represents.

In Documentation/filesystems/proc.txt, we see:

uptime      Wall clock since boot, combined idle time of all cpus

(there are two values in this file, hence the two descriptions)

The reference to "wall clock" is important here - it means all elapsed time, regardless of whether or not the machine's clocks are running. So, this time will keep increasing in suspended or hibernated state.

Putting it another way, the uptime value is effectively the time elapsed since the last boot.

Related Question