Skip to contentSkip to conversation

uptime increases during suspend

DISCUSSION Jonathan Black 7 participants 12 messages Mar 25, 2006 – Mar 29, 2006

lore
Share & tools
lore
#0 lore raw

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,

Signature · 1 line
jonathaN
#1 lore raw

Hi,

Quoted 10 lines · Jonathan Black

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.

Quoted 5 lines

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.

Is your system an i386 or x86_64?

Rafael

#2 lore raw
Quoted 11 lines · Rafael J. Wysocki
Quoted 10 lines · Jonathan Black

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.

Quoted 7 lines
Quoted 5 lines

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.

Is your system an i386 or x86_64?

It is an i386.

Signature · 1 line
jonathaN
#3 lore raw
Quoted 18 lines · Jonathan Black
Quoted 17 lines · Rafael J. Wysocki
Quoted 15 lines · Jonathan Black

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.

Quoted 3 lines
Quoted 1 line

Is your system an i386 or x86_64?

It is an i386.

This seems to happen on my box either, which is an x86_64, so it looks like this doesn't depend on the architecture. Investigating.

Rafael

#4 lore raw
In reply to Jonathan Black
Quoted 9 lines · Jonathan Black

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.

Yes, I don't know exactly when it was changed, but jiffies is now updated when we return from suspend, which causes the uptime to effectively increase while we are suspended.

[snip]

Quoted 5 lines

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.

Well, anyone can hack their kernel to say whatever uptime they want, so I'm not to worried about cheating. Are you seeing an actual bug here?

Quoted 1 line

Would it be possible to get the old behaviour back?

Why exactly do you want this behavior? Maybe a better explanation would help stir this discussion.

The question about the correct behavior is more relevant with virtualization as well. Should the OS's uptime increase even when another OS is running on the cpu? What is the proper interface to export the OS's cpu time?

Right now I'm of the opinion that jiffies should be updated, as real time has past and timer events that are queued should expire.

However with a good enough reason, we might want to add another counter that keeps track of how much time we've been suspended as well.

thanks
-john

#5 lore raw
Quoted 4 lines · In article <1143484821.2168.16.camel@leatherman> you wrote:
Quoted 1 line

Would it be possible to get the old behaviour back?

Why exactly do you want this behavior? Maybe a better explanation would help stir this discussion.

I don't know why he wants it (uptime does not increase during hibernation) but I want it so that I can tell if I should time out or not on an alarm for inactivity in userspace! The alarm should fire if there has been no activity for a while (30s) while activity is possible. If the machine is suspended, no activity is possible, so the alarm should not fire.

This is to counteract sysadamins playing with system time (e.g. syncing with a net time server after bootup) which might cause artificial time outs. Causing a timeout has nasty consequences when, for example, your root fs is mounted over the net via daemons that do the network to-ing and fro-ing from userspace. The only way they have of getting an estimate of REAL time elapsed, without admin playing about messing with them, is by surreptitiously snooping uptime, which more or less represents kernel jiffies.

If you change uptime to not represente kernel jiffies, goodbye the last hope for counting CPU time passed from userspace. False timeouts WILL ensue, and root mounts will fail.

Peter

#6 lore raw
Quoted 22 lines · Peter T. Breuer
Quoted 4 lines · In article <1143484821.2168.16.camel@leatherman> you wrote:
Quoted 1 line

Would it be possible to get the old behaviour back?

Why exactly do you want this behavior? Maybe a better explanation would help stir this discussion.

I don't know why he wants it (uptime does not increase during hibernation) but I want it so that I can tell if I should time out or not on an alarm for inactivity in userspace! The alarm should fire if there has been no activity for a while (30s) while activity is possible. If the machine is suspended, no activity is possible, so the alarm should not fire.

This is to counteract sysadamins playing with system time (e.g. syncing with a net time server after bootup) which might cause artificial time outs. Causing a timeout has nasty consequences when, for example, your root fs is mounted over the net via daemons that do the network to-ing and fro-ing from userspace. The only way they have of getting an estimate of REAL time elapsed, without admin playing about messing with them, is by surreptitiously snooping uptime, which more or less represents kernel jiffies.

Quoted 5 lines

If you change uptime to not represente kernel jiffies, goodbye the last hope for counting CPU time passed from userspace. False timeouts WILL ensue, and root mounts will fail.

Peter

Well uptime code can be modified to subtract the time (if any) in hibernation. Then everybody is happy.

Cheers,
Dick Johnson
Penguin : Linux version 2.6.15.4 on an i686 machine (5589.42 BogoMips). Warning : 98.36% of all statistics are fiction, book release in April. _


****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.

Thank you.

#9 lore raw
In reply to john stultz
Quoted 4 lines · john stultz
Quoted 1 line

Would it be possible to get the old behaviour back?

Why exactly do you want this behavior? Maybe a better explanation would help stir this discussion.

Well, if X session with xscreesaver was active when suspending,
screensacer will be activated just after resume. And if by chance OpenGL hack will be run, X will freeze. Because running apps using OpenGL or xvideo after resume freezes X (for me, at least).

Signature · 2 lines
Tomasz Torcz                 "God, root, what's the difference?"
[email protected]         "God is more forgiving."
#7 lore raw
In reply to Peter T. Breuer
Quoted 13 lines · Peter T. Breuer wrote/
Quoted 4 lines · In article <1143484821.2168.16.camel@leatherman> you wrote:
Quoted 1 line

Would it be possible to get the old behaviour back?

Why exactly do you want this behavior? Maybe a better explanation would help stir this discussion.

I don't know why he wants it (uptime does not increase during hibernation) but I want it so that I can tell if I should time out or not on an alarm for inactivity in userspace! The alarm should fire if there has been no activity for a while (30s) while activity is possible. If the machine is suspended, no activity is possible, so the alarm should not fire.

Quoted 8 lines

This is to counteract sysadamins playing with system time (e.g. syncing with a net time server after bootup) which might cause artificial time outs. Causing a timeout has nasty consequences when, for example, your root fs is mounted over the net via daemons that do the network to-ing and fro-ing from userspace. The only way they have of getting an estimate of REAL time elapsed, without admin playing about messing with them, is by surreptitiously snooping uptime, which more or less represents kernel jiffies.

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

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?

Eric

#10 lore raw
In reply to john stultz

Hi,

Quoted 7 lines · john stultz
Quoted 6 lines · Jonathan Black

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
Quoted 7 lines
Quoted 3 lines

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.

Yes, I don't know exactly when it was changed, but jiffies is now updated when we return from suspend, which causes the uptime to effectively increase while we are suspended.

IIRC on x86_64 jiffies has always been updated in timer_resume(), but this did not cause uptime to behave like that until recently.

There must have been an unrelated change somewhere in the time-handling code that made this behavior appear, but I haven't found it yet.

Quoted 7 lines

[snip]

Quoted 5 lines

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.

Quoted 7 lines

Well, anyone can hack their kernel to say whatever uptime they want, so I'm not to worried about cheating. Are you seeing an actual bug here?

Quoted 1 line

Would it be possible to get the old behaviour back?

Why exactly do you want this behavior? Maybe a better explanation would help stir this discussion.

Apparently it makes some people's setups break.

Greetings,
Rafael

#8 lore raw
In reply to Eric Piel

"Also sprach Eric Piel:"

Quoted 3 lines

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

Actually, the man page does not say anything about the behavior across suspends, and ...

CLOCK_REALTIME
System-wide realtime clock. Setting this clock requires appro- priate privileges.

CLOCK_MONOTONIC
Clock that cannot be set and represents monotonic time since some unspecified starting point.

I'd understand both those wordings the same way! Well, I suppose "cannot be set" means that at least humans can't willingly interfere with it, but maybe something else can.

Quoted 3 lines

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?

"Monotonic" means "always goes in the same direction", not "never skips".

Peter

#11 lore raw
In reply to john stultz
Quoted 10 lines · john stultz
Quoted 5 lines · Jonathan Black

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.

Well, anyone can hack their kernel to say whatever uptime they want, so I'm not to worried about cheating. Are you seeing an actual bug here?

Well, of course the uptime value reported by a hacked kernel cannot be trusted to be accurate or meaningful. My problem is that with the current behaviour, even the value reported by an *unhacked* kernel cannot really be trusted, or at least is a lot less meaningful than it was before, on a machine which uses suspend.

Quoted 10 lines
Quoted 1 line

Would it be possible to get the old behaviour back?

Why exactly do you want this behavior? Maybe a better explanation would help stir this discussion.

The question about the correct behavior is more relevant with virtualization as well. Should the OS's uptime increase even when another OS is running on the cpu? What is the proper interface to export the OS's cpu time?

Quoted 6 lines

Right now I'm of the opinion that jiffies should be updated, as real time has past and timer events that are queued should expire.

However with a good enough reason, we might want to add another counter that keeps track of how much time we've been suspended as well.

Others have given some practical examples. I think there are probably examples to be given of both: things that should behave as if the time spent suspended has actually passed, and things that should behave as if it had not. So maybe is a good idea to have both these notions available somehow.

My initial point was really only that the value reported as the system's "uptime" should be the latter kind of counter, as it seems silly to include time during with the machine is completely powered off.

Greetings,

Signature · 1 line
jonathaN