linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Question about /proc/uptime
@ 2013-12-26  2:30 Rob Landley
  2013-12-27 14:45 ` Oleg Nesterov
  0 siblings, 1 reply; 9+ messages in thread
From: Rob Landley @ 2013-12-26  2:30 UTC (permalink / raw)
  To: linux-kernel; +Cc: Oleg Nesterov, Martin Schwidefsky

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

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

* Re: Question about /proc/uptime
  2013-12-26  2:30 Question about /proc/uptime Rob Landley
@ 2013-12-27 14:45 ` Oleg Nesterov
  2013-12-30  8:56   ` Martin Schwidefsky
  0 siblings, 1 reply; 9+ messages in thread
From: Oleg Nesterov @ 2013-12-27 14:45 UTC (permalink / raw)
  To: Rob Landley; +Cc: linux-kernel, Martin Schwidefsky, Frederic Weisbecker

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 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.

> 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.

> 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.

> Confused,

I guess the 2nd value is historical, probably you should use /proc/stat.

Oleg.


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

* Re: Question about /proc/uptime
  2013-12-27 14:45 ` Oleg Nesterov
@ 2013-12-30  8:56   ` Martin Schwidefsky
  2013-12-30 15:11     ` Oleg Nesterov
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Schwidefsky @ 2013-12-30  8:56 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: Rob Landley, linux-kernel, Frederic Weisbecker

On Fri, 27 Dec 2013 15:45:04 +0100
Oleg Nesterov <oleg@redhat.com> 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
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?
> 
> 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,
   Martin.

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


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

* Re: Question about /proc/uptime
  2013-12-30  8:56   ` Martin Schwidefsky
@ 2013-12-30 15:11     ` Oleg Nesterov
  2013-12-30 15:26       ` Martin Schwidefsky
  0 siblings, 1 reply; 9+ messages in thread
From: Oleg Nesterov @ 2013-12-30 15:11 UTC (permalink / raw)
  To: Martin Schwidefsky; +Cc: Rob Landley, linux-kernel, Frederic Weisbecker

On 12/30, Martin Schwidefsky wrote:
<
> On Fri, 27 Dec 2013 15:45:04 +0100
> Oleg Nesterov <oleg@redhat.com> 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.

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.

> timekeeping_resume()
> is supposed to take care of that.

Not sure I understand... except that timekeeping_resume() does
__timekeeping_inject_sleeptime().

> > > 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).

Only if defined(arch_idle_time) ?

Otherwise get_idle_time() uses get_cpu_idle_time_us() and
CONFIG_NO_HZ_COMMON makes a difference.

> That does make a difference if the cpus stay idle for long periods of
> time.

Yes.

Oleg.


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

* Re: Question about /proc/uptime
  2013-12-30 15:11     ` Oleg Nesterov
@ 2013-12-30 15:26       ` Martin Schwidefsky
  2014-01-01  4:17         ` Rob Landley
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Schwidefsky @ 2013-12-30 15:26 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: Rob Landley, linux-kernel, Frederic Weisbecker

On Mon, 30 Dec 2013 16:11:10 +0100
Oleg Nesterov <oleg@redhat.com> wrote:

> On 12/30, Martin Schwidefsky wrote:
> <
> > On Fri, 27 Dec 2013 15:45:04 +0100
> > Oleg Nesterov <oleg@redhat.com> 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.
> 
> 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.
> 
> > 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.

-- 
blue skies,
   Martin.

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


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

* Re: Question about /proc/uptime
  2013-12-30 15:26       ` Martin Schwidefsky
@ 2014-01-01  4:17         ` Rob Landley
  2014-01-01 12:41           ` Martin Schwidefsky
  0 siblings, 1 reply; 9+ messages in thread
From: Rob Landley @ 2014-01-01  4:17 UTC (permalink / raw)
  To: Martin Schwidefsky, Oleg Nesterov; +Cc: linux-kernel, Frederic Weisbecker

On 12/30/13 09:26, Martin Schwidefsky wrote:
> On Mon, 30 Dec 2013 16:11:10 +0100
> Oleg Nesterov <oleg@redhat.com> 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/uptime is 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

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

* Re: Question about /proc/uptime
  2014-01-01  4:17         ` Rob Landley
@ 2014-01-01 12:41           ` Martin Schwidefsky
  2014-01-01 21:21             ` Rob Landley
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Schwidefsky @ 2014-01-01 12:41 UTC (permalink / raw)
  To: Rob Landley; +Cc: Oleg Nesterov, linux-kernel, Frederic Weisbecker

On Tue, 31 Dec 2013 22:17:39 -0600
Rob Landley <rob@landley.net> wrote:

> On 12/30/13 09:26, Martin Schwidefsky wrote:
> > On Mon, 30 Dec 2013 16:11:10 +0100
> > Oleg Nesterov <oleg@redhat.com> 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/uptime is 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.

-- 
blue skies,
   Martin.

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


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

* Re: Question about /proc/uptime
  2014-01-01 12:41           ` Martin Schwidefsky
@ 2014-01-01 21:21             ` Rob Landley
  2014-01-02  8:28               ` Martin Schwidefsky
  0 siblings, 1 reply; 9+ messages in thread
From: Rob Landley @ 2014-01-01 21:21 UTC (permalink / raw)
  To: Martin Schwidefsky
  Cc: Oleg Nesterov, mtk.manpages, linux-kernel, Frederic Weisbecker

On 01/01/14 06:41, Martin Schwidefsky wrote:
> On Tue, 31 Dec 2013 22:17:39 -0600
> Rob Landley <rob@landley.net> wrote:
>
>> On 12/30/13 09:26, Martin Schwidefsky wrote:
>>> On Mon, 30 Dec 2013 16:11:10 +0100
>>> Oleg Nesterov <oleg@redhat.com> 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/uptime is 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.

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

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

* Re: Question about /proc/uptime
  2014-01-01 21:21             ` Rob Landley
@ 2014-01-02  8:28               ` Martin Schwidefsky
  0 siblings, 0 replies; 9+ messages in thread
From: Martin Schwidefsky @ 2014-01-02  8:28 UTC (permalink / raw)
  To: Rob Landley
  Cc: Oleg Nesterov, mtk.manpages, linux-kernel, Frederic Weisbecker

On Wed, 01 Jan 2014 15:21:00 -0600
Rob Landley <rob@landley.net> wrote:

> On 01/01/14 06:41, Martin Schwidefsky wrote:
> > On Tue, 31 Dec 2013 22:17:39 -0600
> > Rob Landley <rob@landley.net> wrote:
> >
> >> On 12/30/13 09:26, Martin Schwidefsky wrote:
> >>> On Mon, 30 Dec 2013 16:11:10 +0100
> >>> Oleg Nesterov <oleg@redhat.com> 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/uptime is 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.
> 
> 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?

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.

-- 
blue skies,
   Martin.

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


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

end of thread, other threads:[~2014-01-02  8:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-26  2:30 Question about /proc/uptime Rob Landley
2013-12-27 14:45 ` Oleg Nesterov
2013-12-30  8:56   ` Martin Schwidefsky
2013-12-30 15:11     ` Oleg Nesterov
2013-12-30 15:26       ` Martin Schwidefsky
2014-01-01  4:17         ` Rob Landley
2014-01-01 12:41           ` Martin Schwidefsky
2014-01-01 21:21             ` Rob Landley
2014-01-02  8:28               ` Martin Schwidefsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).