Feature #12663
openexpose boot hrtime for uptime interval calculations
0%
Description
We currently expose a kstat, unix:0:system_misc:boot_time
, which is expressed as the UNIX time in seconds at which the OS booted. This value could be misleading for a number of reasons that affect measurements of wall time: inaccurate or incorrectly set system RTC, NTP adjustments, clock drift, etc.
We provide gethrtime(3C)
for user processes to read the current high-resolution time. This time value is not subject to adjustments or drift that the real time clock experiences, but it is also only meaningful when compared with another hrtime reading: that is, it is useful for calculating an interval, but the absolute value of the reading is generally meaningless.
In order to calculate the interval of "time since boot", we should expose as a kstat the hrtime value when the system booted. This would enable a process to calculate the system uptime as an interval between this kstat and a current hrtime reading.
NOTE: Suspend and resume may affect the progression of gethrtime()
readings; e.g., hrtime may not advance while the system is asleep. As such this value will need to be used with that knowledge in mind, and is probably not generally suitable for tools like uptime
and w
.
Updated by Joshua M. Clulow about 2 years ago
- Subject changed from expose boot time as a hrtime value for uptime interval calculations to expose boot hrtime for uptime interval calculations