rdtsc under WSL2 lacks nonstop_tsc?

171 Views Asked by At

I'm doing some microbenchmarking of short code snippets using the __rdtsc intrinsic inside WSL2 on Windows 11. I'm noticing that there is a lot more variance in the results than I'm used to from working on machines that are running Linux on bare metal. If I use clock_gettime with CLOCK_MONOTONIC_RAW instead my results across runs are much more consistent. From prior experience this made me suspect that the TSC might not be reliable, so I ran dmesg and found this:

tsc: Marking TSC unstable due to running on Hyper-V

Which is surprising because that directly contradicts the documentation here:

Hyper-V initialization code in Linux reads this MSR to get the frequency, so it skips TSC calibration and sets tsc_reliable.

Any ideas why this is happening? Is there a way for me to use plain __rdtsc? I notice my /proc/cpuinfo does have constant_tsc but not nonstop_tsc, but since my CPU is new enough to be running Windows 11 I assume this is an artifact of running in WSL2.

0

There are 0 best solutions below