These days, CPUs can adjust their frequency to lower energy consumption. However, many ways to do high precision duration measurements rely not directly on measuring time, but on getting ticks count. For example assembly instructions such as RDTSC/RDTSCP seem to access a tick count that is monotonically incremented at each clock cycle. Or the C constant CLOCKS_PER_SEC which is... a constant. For a processor with adjustable frequency, how tick counts and real durations are related? And how one can be deduced from another?
1 Answers
Looking into the documenttion from Intel (Intel® 64 and IA-32 Architectures Software Developer’s Manual / Volume 3 (3A, 3B, 3C & 3D): System Programming Guide) in section 17.17 the documentation reads
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.
So the TSC is running at a constant rate. So the different frequencies do not matter. This is since Pentium 4 the case.
Please read the complete section 17.17 to know what procesors do to give you a constant rate timer.
Also the comments below your questions are right: You have to differentiate between such a short term timer and the wall clock time.