3 ms·
I'm not sure if AMD properly supports invariant TSC. See this post from Agner Fog with regards to the Zen cores: http://www.agner.org/optimize/blog/read.php?i=
by dragontamer 9y ago
I'm not sure if AMD properly supports invariant TSC. See this post from Agner Fog with regards to the Zen cores:
http://www.agner.org/optimize/blog/read.php?i=838 http://www.agner.org/optimize/blog/read.php?i=838
> The varying clock frequency was a big problem for my performance tests because it was impossible to get precise and reproducible measurements of computation times. It helps to warm up the processor with a long sequence of dummy calculations, but the clock counts were still somewhat inaccurate. The Time Stamp Counter (TSC), which is used for measuring the execution time of small pieces of code, is counting at the nominal frequency. The Ryzen processor has another counter called Actual Performance Frequency Clock Counter (APERF) which is similar to the Core Clock Counter in Intel processors. Unfortunately, the APERF counter can only be read in kernel mode, unlike the TSC which is accessible to the test program running in user mode. I had to calculate the actual clock counts in the following way: The TSC and APERF counters are both read in a device driver immediately before and after a run of the test sequence. The ratio between the TSC count and the APERF count obtained in this way is then used as a correction factor which is applied to all TSC counts obtained during the running of the test sequence. This method is awkward, but the results appear to be quite precise, except in the cases where the frequency is varying considerably during the test sequence. My test program is available at www.agner.org/optimize/#testp
---------------
EDIT: Odd. AMD Documentation of 17h (aka Zen) suggests that the TSC is invariant: https://support.amd.com/TechDocs/54945_PPR_Family_17h_Models_00h-0Fh.pdf https://support.amd.com/TechDocs/54945_PPR_Family_17h_Models...
See bottom of page 82.
I can't say I've run tests as thoroughly as Agner Fog has done however, or even have access to Zen cores.
- notaplumber 9y agoAMD certainly proclaims to support it on the pre-Ryzen hardware I have, if the bit is set than software no reason not to trust it. But it should really be no surprise that CPU errata sheets are not small.
- wtallis 9y agoI think that's saying that TSC is invariant with respect to wall time, but what Agner Fog wants is a counter that's invariant with respect to actual CPU clock cycles, so that he can count how many cycles an instruction takes even if the clock speed of the CPU changes during a test run.
- dragontamer 9y agoThat makes sense actually. I never thought of it that way.