Page MenuHomeFreeBSD

dtrace/arm64: Fix dtrace_gethrtime()
ClosedPublic

Authored by markj on Mar 5 2025, 11:00 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Apr 6, 9:40 PM
Unknown Object (File)
Mar 29 2025, 11:10 AM
Unknown Object (File)
Mar 26 2025, 9:28 PM
Unknown Object (File)
Mar 21 2025, 12:42 PM
Unknown Object (File)
Mar 19 2025, 5:11 PM
Unknown Object (File)
Mar 19 2025, 5:11 PM
Unknown Object (File)
Mar 19 2025, 2:04 PM
Unknown Object (File)
Mar 10 2025, 11:08 PM
Subscribers

Details

Summary

This routine returns a monotonic count of the number of nanoseconds elapsed
since the previous call. On arm64 it uses the generic system timer. The
implementation multiplies the counter value by 10**9 then divides by the counter
frequency, but this multiplication can overflow. This can result in trace
records with non-monotonic timestamps, which breaks libdtrace's temporal
ordering algorithm.

An easy fix is to reverse the order of operations, since the counter frequency
will in general be smaller than 10**9. (In fact, it's mandated to be 1Ghz in
ARMv9, which makes life simple.) However, this can give a fair bit of error.
Adopt the calculation used on amd64, with tweaks to handle frequencies as low as
1MHz: the ARM generic timer documentation suggests that ARMv8 timers are
typically in the 1MHz-50MHz range, which is true on arm64 systems that I have
access to.

Sponsored by: Innovate UK

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable