On Tue Sep 9 12:12:14 2025 +0000, Elizabeth Figura wrote:
On BSDs (and other POSIX compliant operating systems)
`CLOCK_MONOTONIC` likewise includes suspend time. However they also provide a `CLOCK_BOOTTIME`, which does _not_ include suspend time, hence the added `__linux__` check there. Which BSDs? As far as I can see, FreeBSD seems to include suspend time, and NetBSD doesn't have this clock.
I was looking at FreeBSD indeed (and others, but can't remember the details).
My original assumption was that it does have `CLOCK_BOOTTIME`, and that it does not include suspend time, but `CLOCK_MONOTONIC` does given the following man page:
``` CLOCK_MONOTONIC Increments in SI seconds.
CLOCK_BOOTTIME Starts at zero when the kernel boots and increments monotoni- cally in SI seconds while the machine is running. ```
The also state
Finally, `CLOCK_BOOTTIME` is an alias for `CLOCK_UPTIME` for compatibility with other systems.
Now this makes it sound like `CLOCK_BOOTTIME` should be without suspend (which it is) and that `CLOCK_MONOTONIC` is different, but in reality it is a bit more messy, at least for [FreeBSD](https://reviews.freebsd.org/D39270?id=).
On OpenBSD and macOS `CLOCK_MONOTONIC` does include suspend time, but on FreeBSD there still isn't a suspend-aware clock AFAICT, but they are working on it and it will also be `CLOCK_MONOTONIC` and not `CLOCK_BOOTTIME`.
Which probably means that technically that `__linux__` check there might not be needed right now, but in the future. Even so Linux was the only platform I found that works in this way with `CLOCK_MONOTONIC` not including suspend and a `CLOCK_BOOTTIME` (or equivalent) including suspend. There was even a try to change this, but it got reverted due to application breakage: https://lkml.indiana.edu/1804.3/02844.html