2014-01-01 12:41:29

by Martin Schwidefsky

[permalink] [raw]
Subject: Re: Question about /proc/uptime

On Tue, 31 Dec 2013 22:17:39 -0600
Rob Landley <[email protected]> wrote:

> On 12/30/13 09:26, Martin Schwidefsky wrote:
> > 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/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.


2014-01-01 21:21:12

by Rob Landley

[permalink] [raw]
Subject: Re: Question about /proc/uptime

On 01/01/14 06:41, Martin Schwidefsky wrote:
> On Tue, 31 Dec 2013 22:17:39 -0600
> Rob Landley <[email protected]> wrote:
>
>> On 12/30/13 09:26, Martin Schwidefsky wrote:
>>> 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/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

2014-01-02 08:28:32

by Martin Schwidefsky

[permalink] [raw]
Subject: Re: Question about /proc/uptime

On Wed, 01 Jan 2014 15:21:00 -0600
Rob Landley <[email protected]> wrote:

> On 01/01/14 06:41, Martin Schwidefsky wrote:
> > On Tue, 31 Dec 2013 22:17:39 -0600
> > Rob Landley <[email protected]> wrote:
> >
> >> On 12/30/13 09:26, Martin Schwidefsky wrote:
> >>> 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/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.