Cyber Risks · Trail of Bits Blog

TSC Frequency For All: Better Profiling and Benchmarking

Summary: Trail of Bits built a Linux kernel module called tsc_freq_khz that exports the kernel's internal x86 Time Stamp Counter frequency, tsc_khz, to userspace via /sys/devices/system/cpu/cpu0/tsc_freq_khz. The module addresses two profiling failures: LLVM's X-Ray assumes TSC frequency equals maximum clock speed, which is wrong on newer Intel CPUs and causes missing minutes in profiles, and the cpufreq value it relies on is absent in virtualized environments, causing "Unable to determine CPU Frequency" errors.

Bottom line: Profiling and benchmarking tools like X-Ray and Abseil already look for this sysfs file, but it previously existed only on Google's production kernels, so measurements elsewhere could silently undercount a 20-minute run by roughly five minutes. The authors explicitly warn against using the module in a real production system, since it assumes CPU0 exists and performs no sanity checks on the TSC value.

Read the original at Trail of Bits Blog ↗