Bug 236702 - KERN_UPTIME not updated after resume
Summary: KERN_UPTIME not updated after resume
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-21 12:01 UTC by Edward Tomasz Napierala
Modified: 2021-05-08 02:30 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Edward Tomasz Napierala freebsd_committer freebsd_triage 2019-03-21 12:01:32 UTC
It seems the time returned by clock_gettime(CLOCK_UPTIME) doesn't get updated on resume - in other words, when you reboot, then suspend to ram, then wait an hour and resume, the uptime, as shown by uptime(1), won't account for that hour.  This is different from eg OSX.
Comment 1 Andriy Gapon freebsd_committer freebsd_triage 2019-03-21 14:17:50 UTC
(In reply to Edward Tomasz Napierala from comment #0)
But not from e.g. Linux? :)
Comment 2 Ed Maste freebsd_committer freebsd_triage 2019-04-01 13:12:41 UTC
I can see arguments for and against including the period during suspend-to-RAM in uptime, so agree with avg that we'd want to survey other OSes and give careful consideration to this change before making it.
Comment 3 Edward Tomasz Napierala freebsd_committer freebsd_triage 2019-04-01 15:32:23 UTC
I've asked around (thanks, Ar!), and it seems the time spent while suspended is accounted for under Linux too (NixOS, 4.19.30).
Comment 4 Edward Tomasz Napierala freebsd_committer freebsd_triage 2020-12-16 22:14:21 UTC
I've tried to track it down, but went nowhere - I don't quite understand how the timers work.  One thing I've noticed is that CLOCK_UPTIME seems to be computed from current time and the boot time; what happens is that after resuming, the boottime (eg 'sysctl kern.boottime') moves forward.
Comment 5 Alexey Dokuchaev freebsd_committer freebsd_triage 2021-05-08 02:30:17 UTC
(In reply to Andriy Gapon from comment #1)
> But not from e.g. Linux? :)
FWIW, if you install `sysutils/coreutils' port/package, you can observe the difference as demonstrated below (quoted from my laptop which I put to sleep, albeit irregularly):

> $ guptime
>  10:26:42  up 5 days  8:10,  7 users,  load average: 0.24, 0.28, 0.63
> $ uptime
> 10:26  up 4 days, 22:25, 16 users, load averages: 0,30 0,29 0,63