Question about /proc/uptime
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).
The second value isn't documented but looking at fs/proc/uptime.c I think it's idle time? 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?
Also, is this actual "cpu was on but not doing anything" time, so doesn't count suspend as idle? So if you subtract idle from uptime (on a uniprocessor system) on a system that spent some of its time suspended, what do you get? Amount of time the system "wasn't idle" means... Is suspend time idle or not idle?
Confused,
Rob
Add Frederic, I am not sure I understand this correctly.
Quoted 4 lines · Rob Landley
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?
Quoted 2 lines
The second value isn't documented but looking at
fs/proc/uptime.cI think it's idle time?
And this cpustat[CPUTIME_IDLE] doesn't match get_idle_time(), I guess it only counts ticks.
Quoted 3 lines
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.
Quoted 2 lines
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.
Quoted 1 line
Confused,
I guess the 2nd value is historical, probably you should use /proc/stat.
Oleg.
Quoted 10 lines · On Fri, 27 Dec 2013 15:45:04 +0100 Oleg Nesterov <[email protected]> wrote:
Add Frederic, I am not sure I understand this correctly.
Quoted 4 lines · Rob Landley
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 usesget_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.
Quoted 5 lines
Quoted 2 lines
The second value isn't documented but looking at
fs/proc/uptime.cI 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 time.
Quoted 5 lines
Quoted 3 lines
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.
Quoted 4 lines
Quoted 2 lines
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.
Signature · 4 lines
blue skies, Martin. "Reality continues to ruin my life." - Calvin.
On 12/30, Martin Schwidefsky wrote:
<
Quoted 11 lines
Quoted 8 lines · On Fri, 27 Dec 2013 15:45:04 +0100 Oleg Nesterov <[email protected]> wrote:
Add Frederic, I am not sure I understand this correctly.
Quoted 4 lines · Rob Landley
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).
Quoted 5 lines
Quoted 2 lines
Hmm,
uptime_proc_show()still usesget_monotonic_boottime(), this should include suspend time?The first value of
/proc/uptimeis the amount of time the system has been running, the sum of the suspend time is not included.
Hmm. It uses get_monotonic_boottime() and this helper adds timekeeper->total_sleep_time to the returned value? Even the comment says
* This is similar to CLOCK_MONTONIC/ktime_get_ts, but also
* includes the time spent in suspend.
Quoted 2 lines
timekeeping_resume()
is supposed to take care of that.
Not sure I understand... except that timekeeping_resume() does __timekeeping_inject_sleeptime().
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines
The second value isn't documented but looking at
fs/proc/uptime.cI 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/uptimeis the sum of the idle time of all cpus. The value should roughly match the sum overget_idle_time()for all cpus. The difference is thatget_idle_time()usesarch_idle_timeto add the time for the currently running idle period as well (at least for s390).
Only if defined(arch_idle_time) ?
Otherwise get_idle_time() uses get_cpu_idle_time_us() and CONFIG_NO_HZ_COMMON makes a difference.
Quoted 2 lines
That does make a difference if the cpus stay idle for long periods of time.
Yes.
Oleg.
Quoted 22 lines · On Mon, 30 Dec 2013 16:11:10 +0100 Oleg Nesterov <[email protected]> wrote:
On 12/30, Martin Schwidefsky wrote:
<Quoted 11 lines
Quoted 8 lines · On Fri, 27 Dec 2013 15:45:04 +0100 Oleg Nesterov <[email protected]> wrote:
Add Frederic, I am not sure I understand this correctly.
Quoted 4 lines · Rob Landley
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).
Quoted 5 lines
Quoted 2 lines
Hmm,
uptime_proc_show()still usesget_monotonic_boottime(), this should include suspend time?The first value of
/proc/uptimeis the amount of time the system has been running, the sum of the suspend time is not included.Hmm. It uses
get_monotonic_boottime()and this helper addstimekeeper->total_sleep_timeto the returned value? Even the comment says
Quoted 8 lines
* This is similar to CLOCK_MONTONIC/ktime_get_ts, but also
* includes the time spent in suspend.Quoted 2 lines
timekeeping_resume()
is supposed to take care of that.Not sure I understand... except that
timekeeping_resume()does__timekeeping_inject_sleeptime().
Hmm, you are right. The sleeptime is added to the monotonic boottime. So the first value of /proc/uptime is the wall-time since boot. And the second value is combined idle time over all cpus.
Signature · 4 lines
blue skies, Martin. "Reality continues to ruin my life." - Calvin.
Quoted 8 lines · Martin Schwidefsky
Quoted 2 lines · On Mon, 30 Dec 2013 16:11:10 +0100 Oleg Nesterov <[email protected]> wrote:
Not sure I understand... except that
timekeeping_resume()does__timekeeping_inject_sleeptime().Hmm, you are right. The sleeptime is added to the monotonic boottime. So the first value of
/proc/uptimeis the wall-time since boot. And the second value is combined idle time over all cpus.
Is there an obvious way to query the non-suspend uptime from userspace?
Rob
Quoted 11 lines · On Tue, 31 Dec 2013 22:17:39 -0600 Rob Landley <[email protected]> wrote:
Quoted 8 lines · Martin Schwidefsky
Quoted 2 lines · On Mon, 30 Dec 2013 16:11:10 +0100 Oleg Nesterov <[email protected]> wrote:
Not sure I understand... except that
timekeeping_resume()does__timekeeping_inject_sleeptime().Hmm, you are right. The sleeptime is added to the monotonic boottime. So the first value of
/proc/uptimeis the wall-time since boot. And the second value is combined idle time over all cpus.Is there an obvious way to query the non-suspend uptime from userspace?
clock_gettime with CLOCK_MONOTONIC gives you the uptime minus without the suspend time.
Signature · 4 lines
blue skies, Martin. "Reality continues to ruin my life." - Calvin.
Quoted 9 lines · Martin Schwidefsky
Quoted 6 lines · On Tue, 31 Dec 2013 22:17:39 -0600 Rob Landley <[email protected]> wrote:
Quoted 5 lines · Martin Schwidefsky
Quoted 2 lines · On Mon, 30 Dec 2013 16:11:10 +0100 Oleg Nesterov <[email protected]> wrote:
Not sure I understand... except that
timekeeping_resume()does__timekeeping_inject_sleeptime().
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Hmm, you are right. The sleeptime is added to the monotonic boottime. So the first value of
/proc/uptimeis the wall-time since boot. And the second value is combined idle time over all cpus.Is there an obvious way to query the non-suspend uptime from userspace?
clock_gettimewithCLOCK_MONOTONICgives you the uptime minus without the suspend time.
Given that the clock_gettime man page says:
CLOCK_MONOTONIC
Clock that cannot be set and represents monotonic time since some unspecified starting point.
Can I rely on it _continuing_ to do so in future, and if so should the man page be clarified?
Rob
Quoted 19 lines · On Wed, 01 Jan 2014 15:21:00 -0600 Rob Landley <[email protected]> wrote:
Quoted 9 lines · Martin Schwidefsky
Quoted 6 lines · On Tue, 31 Dec 2013 22:17:39 -0600 Rob Landley <[email protected]> wrote:
Quoted 5 lines · Martin Schwidefsky
Quoted 2 lines · On Mon, 30 Dec 2013 16:11:10 +0100 Oleg Nesterov <[email protected]> wrote:
Not sure I understand... except that
timekeeping_resume()does__timekeeping_inject_sleeptime().Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Hmm, you are right. The sleeptime is added to the monotonic boottime. So the first value of
/proc/uptimeis the wall-time since boot. And the second value is combined idle time over all cpus.Is there an obvious way to query the non-suspend uptime from userspace?
clock_gettimewithCLOCK_MONOTONICgives you the uptime minus without the suspend time.
Quoted 8 lines
Given that the
clock_gettimeman page says:
CLOCK_MONOTONIC
Clock that cannot be set and represents monotonic time since some unspecified starting point.Can I rely on it _continuing_ to do so in future, and if so should the man page be clarified?
Good point. CLOCK_MONOTONIC is implemented in a specific way now and I doubt that this will change any time soon, but you have no guarantee that it will keep the property 'monotonic-time = uptime - suspend-time'. You can not use the values in /proc/stat either as you can set any CPU offline, which means that no CPU line contains all ticks since boot.
Without the CLOCK_MONOTONIC option I do not see a way how to get the non-suspend uptime from user space.
Signature · 4 lines
blue skies, Martin. "Reality continues to ruin my life." - Calvin.