Re: Question about /proc/uptime

From: Martin Schwidefsky
Date: Mon Dec 30 2013 - 03:57:42 EST

On Fri, 27 Dec 2013 15:45:04 +0100
Oleg Nesterov <oleg@xxxxxxxxxx> wrote:

> Add Frederic, I am not sure I understand this correctly.
> On 12/25, Rob Landley wrote:
> >
> > There are two values here, the first is seconds since boot time (which
> > is just elapsed time; at one point it was ajusted for suspend and that
> > was revered as confusing).
> Hmm, uptime_proc_show() still uses get_monotonic_boottime(), this should
> include suspend time?

The first value of /proc/uptime is the amount of time the system has been
running, the sum of the suspend time is not included. timekeeping_resume()
is supposed to take care of that.

> > The second value isn't documented but looking at fs/proc/uptime.c I
> > think it's idle time?
> And this cpustat[CPUTIME_IDLE] doesn't match get_idle_time(), I guess
> it only counts ticks.

The second value of /proc/uptime is the sum of the idle time of all cpus.
The value should roughly match the sum over get_idle_time() for all cpus.
The difference is that get_idle_time() uses arch_idle_time to add the
time for the currently running idle period as well (at least for s390).
That does make a difference if the cpus stay idle for long periods of

> > Except, if yo uadd up the idle time from all
> > processors wouldn't you get 4x the uptime on a 4-way SMP system that's
> > been idle since boot?
> Yes, looks strange.

Minus some cpu time for the boot and an occasional timer interrupt. And
if cpus are offline for any period of time this is not added to the idle
time as well. For a system that never disables cpus and stays idle for
99.9% of the time the idle time from /proc/uptime should be close to
#cpus * uptime.

> > Also, is this actual "cpu was on but not doing anything" time, so
> > doesn't count suspend as idle?
> I think suspend is not counted as idle.

For suspend all cpus but one are set offline. These cpus will not generate
any cputime while offline, so no idle time nor steal time nor system time.
The suspend cpu will store the TOD clock before switching off, on resume
a new TOD time stamp is created and things are restarted from this new
time. The time spent while in idle is ignored, it is not included in any
cputime bucket.

blue skies,

"Reality continues to ruin my life." - Calvin.

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at