时间测量,CPU 刻度和可调 CPU 频率?

Time measurements, CPU ticks and adjustable CPU frequency?

如今,CPU 可以调整频率以降低能耗。然而,许多进行高精度持续时间测量的方法并不直接依赖于测量时间,而是依赖于滴答计数。例如 RDTSC/RDTSCP 之类的汇编指令似乎访问了在每个时钟周期单调递增的滴答计数。或者 C 常量 CLOCKS_PER_SEC 这是一个常量。对于频率可调的处理器,滴答计数和实际持续时间有何关系?以及如何从一个推导出另一个?

查看 Intel 的文档(Intel® 64 和 IA-32 架构 软件开发人员手册/第 3 卷(3A、3B、3C 和 3D):系统编程指南)在第 17.17 节中,文档显示

For Pentium 4 processors, Intel Xeon processors (family [0FH], models [03H and higher]); for Intel Core Solo and Intel Core Duo processors (family [06H], model [0EH]); for the Intel Xeon processor 5100 series and Intel Core 2 Duo processors (family [06H], model [0FH]); for Intel Core 2 and Intel Xeon processors (family [06H], DisplayModel [17H]); for Intel Atom processors (family [06H], DisplayModel [1CH]): the time-stamp counter increments at a constant rate. That rate may be set by the maximum core-clock to bus-clock ratio of the processor or may be set by the maximum resolved frequency at which the processor is booted. The maximum resolved frequency may differ from the processor base frequency, see Section 18.7.2 for more detail. On certain processors, the TSC frequency may not be the same as the frequency in the brand string.

所以 TSC 是 运行 以恒定速率。所以不同的频率并不重要。这是Pentium 4以来的情况。

请阅读完整的第 17.17 节以了解处理器如何为您提供恒定速率计时器。

还有你的问题下面的评论是对的:你必须区分这种短期计时器和挂钟时间。