Files
tracy/public
Clément Grégoire 1c26daa3ac Detect unreliable TSC on Linux via perf timestamp probe.
Linux exposes time_zero/time_mult/time_shift on the perf_event mmap
page for converting sample timestamps back to TSC cycles, gated by
cap_user_time_zero. That flag only states the conversion math is
valid; on Ryzen the kernel can leave it set while TSC silently drifts
between cores, before the clocksource watchdog catches it. We've had
user reports of this surfacing as garbage timestamps in traces.

CheckLinuxPerfTscConsistency() first looks at the current clocksource
in sysfs, then opens a dummy PERF_COUNT_SW_DUMMY event and verifies
that a PR_SET_NAME-triggered PERF_RECORD_COMM timestamp inverts back
into the rdtsc-sandwiched window with ~1 ms of slack. Modeled on
tools/perf/tests/perf-time-to-tsc.c.

Wired into CheckHardwareSupportsInvariantTSC() so a failing probe
calls InitFailure in non-fallback builds and routes GetTime() to
clock_gettime in TRACY_TIMER_FALLBACK builds. Inconclusive cases
(perf blocked, no COMM record, etc) return true to avoid penalising
sandboxed environments. Gated on TRACY_HAS_SYSTEM_TRACING so we only
probe when Tracy would actually open perf events.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 16:11:39 +02:00
..
2025-01-05 23:21:12 +01:00