public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* uptime increases during suspend
@ 2006-03-25 15:02 Jonathan Black
  2006-03-25 15:10 ` Rafael J. Wysocki
  2006-03-27 18:40 ` john stultz
  0 siblings, 2 replies; 13+ messages in thread
From: Jonathan Black @ 2006-03-25 15:02 UTC (permalink / raw)
  To: linux-kernel; +Cc: john stultz

Hi,

I'd like to enquire about the following behaviour:

$ uptime && sudo hibernate && uptime
 14:18:51 up 1 day, 4:12,  2 users,  load average: 0.58, 3.30, 2.42
 14:23:46 up 1 day, 4:17,  2 users,  load average: 20.34, 7.74, 3.91

I.e. the system was suspended to disk for 5 minutes, but the value
reported by 'uptime' has increased by as much, as if it had actually
continued running during that time.

I'm using Linux 2.6.16 with the latest version of the Suspend 2 patch
(2.2.1), but Nigel its maintainer says that this isn't actually related
to his suspend code, essentially the same would happen using the swsusp
code currently in the kernel, and therefore we need to ask the kernel
time code people about this issue.

I've been using suspend2 for a while now, and until some point in the
past it used to be the case that uptime would stand still during
hibernation, i.e. only counting the time during which the system was
actually up and running. This seems like more meaningful and desirable
behaviour to me.

The way it is now, one can essentially "cheat": suspend a machine, put
it in the cupboard for a couple of weeks, resume it and claim a
respectable uptime, because the uptime value only reflects how long ago
the system was first booted up, with no regard to how much of that time
it has actually been running.

Would it be possible to get the old behaviour back?

Greetings,
-- 
jonathaN

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: uptime increases during suspend
@ 2006-03-28  2:01 Peter T. Breuer
  0 siblings, 0 replies; 13+ messages in thread
From: Peter T. Breuer @ 2006-03-28  2:01 UTC (permalink / raw)
  To: linux-kernel

"Also sprach Eric Piel:"
> It seems that what you are really looking for in your application is a 
> monotonic clock. Linux has such thing since few releases. Using 
> CLOCK_MONOTONIC (cf "man 3 clock_gettime") may look much less hacky than 
> using the uptime ;-)

Likely. But I and others have to support all kernels and all operating
systems, and the code would look less hacky if it could use just one
thing, and continue using it. Uptime has been used this way for years
by many many applications. Read proc/sysinfo.c from procps...

/***********************************************************************
 * Some values in /proc are expressed in units of 1/HZ seconds, where HZ
 * is the kernel clock tick rate. One of these units is called a jiffy.
 * The HZ value used in the kernel may vary according to hacker desire.
 * According to Linus Torvalds, this is not true. He considers the values
 * in /proc as being in architecture-dependant units that have no relation
 * to the kernel clock tick rate. Examination of the kernel source code
 * reveals that opinion as wishful thinking.
 *
 * In any case, we need the HZ constant as used in /proc. (the real HZ value
 * may differ, but we don't care) There are several ways we could get HZ:
 *
 * 1. Include the kernel header file. If it changes, recompile this library.
 * 2. Use the sysconf() function. When HZ changes, recompile the C library!
 * 3. Ask the kernel. This is obviously correct...
 *
 * Linus Torvalds won't let us ask the kernel, because he thinks we should
 * not know the HZ value. Oh well, we don't have to listen to him.
 * Someone smuggled out the HZ value. :-)
 *
 * This code should work fine, even if Linus fixes the kernel to match his
 * stated behavior. The code only fails in case of a partial conversion.
 *
 * Recent update: on some architectures, the 2.4 kernel provides an
 * ELF note to indicate HZ. This may be for ARM or user-mode Linux
 * support. This ought to be investigated. Note that sysconf() is still
 * unreliable, because it doesn't return an error code when it is
 * used with a kernel that doesn't support the ELF note. On some other
 * architectures there may be a system call or sysctl() that will work.
 */

Etc.

How am I supposed to know on which installation what will work and what
will not? What do you propose? Try CLOCK_MONOTONIC and see if it returns
EINVAL, then fall back to uptime?

(and it'll be some years before my manpage documents the flag you give!
- I don't even have a man page for clock_gettime! Aahh ... I see it on a 
more recent debian system ... yes, that looks good).

Sigh, more configure.in-ery.

   On  POSIX  systems  on  which these functions are available, the symbol
       _POSIX_TIMERS is defined in <unistd.h> to a value greater than 0.   The
       symbols  _POSIX_MONOTONIC_CLOCK,  _POSIX_CPUTIME, _POSIX_THREAD_CPUTIME
       indicate      that      CLOCK_MONOTONIC,      CLOCK_PROCESS_CPUTIME_ID,
       CLOCK_THREAD_CPUTIME_ID are available. 

This is getting as bad as bdflush.

> Now... concerning the suspend effect on this clock, I don't know. It's 
> probably the same problem as uptime: no official semantic has ever been 
> stated yet... Does anyone know?

Peter


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

end of thread, other threads:[~2006-03-29 14:52 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-25 15:02 uptime increases during suspend Jonathan Black
2006-03-25 15:10 ` Rafael J. Wysocki
2006-03-25 15:18   ` Jonathan Black
2006-03-26 21:38     ` Rafael J. Wysocki
2006-03-27 18:40 ` john stultz
2006-03-27 19:53   ` Peter T. Breuer
2006-03-27 20:01     ` linux-os (Dick Johnson)
2006-03-27 22:30     ` Eric Piel
2006-03-28  3:57       ` Peter T. Breuer
2006-03-27 21:37   ` Tomasz Torcz
2006-03-27 22:43   ` Rafael J. Wysocki
2006-03-29 14:52   ` Jonathan Black
  -- strict thread matches above, loose matches on Subject: below --
2006-03-28  2:01 Peter T. Breuer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox