On Tue Sep 9 12:23:41 2025 +0000, Marc-Aurel Zent wrote:
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.
They 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
Hmm okay, I found a different FreeBSD manpage, which more explicitly says that both BOOTTIME and MONOTONIC do include suspend:
https://man.freebsd.org/cgi/man.cgi?query=clock_gettime&apropos=0&se...