Re: Clarification of CLOCK_MONOTONIC
x85729201kza <[email protected]> Mon, 8 Jun 2026 16:59:36 +1000
| Newsgroups | gmane.os.netbsd.devel.kernel |
|---|---|
| Message-ID | <TYZPR02MB6044D23AFFD62C5AB5DAA05ED61C2@TYZPR02MB6044.apcprd02.prod.outlook.com> |
On 7/06/2026 10:16 pm, Greg Troxel wrote: > JJ <[email protected]> writes: > >> Hi all, >> >> A "simple" question about CLOCK_MONOTONIC. >> >> How does this behave under sleep states? See clock_gettime(2) or >> clock_getres(2) >> >> For example, in FreeBSD (per the manual page), it states: >> >> "Increments in SI seconds, even while the system is suspended. >> Its epoch is unspecified. The count is not adjusted by leap seconds." >> >> NetBSD makes no such pronouncement. > > FreeBSD is simply (and reasonably) paraphrasing POSIX: > > https://pubs.opengroup.org/onlinepubs/9799919799/functions/clock_getres.html > > The NetBSD man page doesn't say this clearly. It's a fair question > what the behavior is, and either way, the man page should be clarified > (to say it doesn't meet POSIX, or to point out POSIX and say it meets it > even under susspend/resume). Yes, this is the question. > >> In code, for say, Linux kernel I would use CLOCK_BOOTTIME because it >> is aware of suspension yet CLOCK_MONOTONIC is not. > > If Linux's CLOCK_MONOTONIC does not increase across suspension, then I > would say it does not comply with POSIX and should be fixed. I might be > off here, not having passed the POSIX Language Lawyer bar exam. Of course it doesn't, but this is not the issue. However, unlike NetBSD, Linux does document its bizarre behaviour, though, and offers what should be CLOCK_MONOTONIC as CLOCK_BOOTTIME (FreeBSD also offers this as a synonym of CLOCK_MONOTONIC). So, while I can (and will) experiment with CLOCK_MONOTONIC on NetBSD, it would be nice for it to be clarified and documented in the correct places. Cheers.