mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-12-04 16:40:32 +00:00
GetThreadTimes only advances at the 15.6 ms scheduler tick, so on Windows the thread CPU clock moved in 15.6 ms steps where clock_getres reports 1 us, and could read ahead of the monotonic clock under load. With an invariant TSC, read the calling thread's clock and other guest threads' CPU clocks from QueryThreadCycleTime, converted with the measured host TSC frequency. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
959 B
959 B
libkernel
add Functional
- Thread CPU time on Windows (clock_gettime with the thread CPU clock, and the CPU time of a guest thread) is measured only on one AMD CPU with an invariant TSC:
QueryThreadCycleTime, for which Microsoft documents no time unit, divided by the TSC frequency libkernel measures. On a Ryzen 5 7600X it stayed within 0.25% of wall time without system calls; each read of the clock went about 6.5 ns uncounted, other system calls 1 ns or less. The first read, if the TSC frequency is not measured yet, pins the thread to one CPU and waits 20 ms. Without an invariant TSC these clocks readGetThreadTimes, which moves in 15.6 ms steps, as the process CPU clocks andgetrusagestill do; a thread clock and those can differ by about one step. Closes when: measured on an Intel CPU and on a CPU without an invariant TSC.