
TSC Frequency for All: Better Profiling and Benchmarking - tyoma
https://blog.trailofbits.com/2019/10/03/tsc-frequency-for-all-better-profiling-and-benchmarking/
======
tyoma
Hopefully something similar to this can be upstreamed into the mainline Linux
kernel — ideally whatever Google is using internally since it probably works
well and is battle tested.

------
fsfod
Its disappointing that AMD didn't bother to implement the 15H CPUID leaf that
Intel added years ago to get the exact CPU TSC frequency. Yet AMD cared enough
to add there own instruction(RDPRU) to get the values of APERF and MPERF in
user mode.

~~~
vardump
As if that matters much in the current TSC frequency disaster... Very few
Intel processors implement it completely or at all.

------
woodruffw
FD: My employer's blog.

I guess it shouldn't surprise me given the number of Linux and LLVM developers
present at Google, but it always blows my mind a bit to see these kinds of
internal changes form the basis of correct/sound results from tools like
X-Ray.

------
saagarjha
> Additionally, the maximum clock speed, accessible in Linux via
> /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq, is not available in
> cloud-based or other virtualized environments.

Why? To prevent side-channel attacks?

~~~
tyoma
The device is populated by the cpu_freq driver, which is used to control
frequency scaling. Most cloud environments have shared tenancy and disable the
feature to ensure one user can’t scale down the CPU for other tenants.

~~~
saagarjha
Is there no way to disable setting the CPU frequency?

~~~
tyoma
I am not sure, but in my experience the driver is not present and not
loadable.

Regardless, the max cpu frequency is not equal to tsc frequency on newer Intel
CPUs, so the number is meaningless.

