Rdtsc accuracy for control and time frequency

As part of the benchmarking task, I studied various mechanisms that can be used to measure elapsed time. I ended up using it clock_gettime, but I did enough research and testing with the team RDTSC. I have a few questions regarding the same (depending on what I read in several online streams):

  • On new processors (> Pentium 4), TSC ticks at the maximum CPU frequency in the system. It's right? In this case, is it correct to use the number of ticks and frequencies to determine the time?

  • If the above is true, this means that the processor frequency is not affected by the TSC due to power saving and other functions. Knowing this, would it mean that the common ticks obtained with the help RDTSCare NOT the actual ticks used by the selective part of the code, since the code will work on the CPU frequency, and not on the TSC? In addition, does this mean that the time obtained using TSC ticks and processor frequency is not the actual time used by the code fragment?

  • I find many different statements about the synchronization of TSC values ​​across cores (see this thread ). I am not sure which is correct, and I assume that it depends on the processor model. But can we assume that they are synchronized between the cores on newer processors? (This is not used sched_set_affinity)?

Note that I do not use RDTSCbecause of various problems associated with it (portability, reliability, etc.). These questions are just to improve my understanding of how TSC and benchmarking in general work.

+4
source share
1 answer

Invariant TSC means, according to Intel,

Invariant TSC will operate at a constant speed in all ACPI P-, C-. and T-states.

But what is the speed? Well,

. , . 18.14.5 . TSC , .

, , , - . ?

TSC, IA32_MPERF IA32_FIXED_CTR2 , .
    Intel Core MSR_FSB_FREQ [2: 0] (0CDH), . B ", (MSR)". :
    XE , MSR_PLATFORM_ID [12: 8]. .
    XE , MSR_PERF_STAT [44:40], XE, BIOS.

, , . TL; DR, TSC - . , , , , -, " , ". , . , , . , , .

, , TSC , , ?

, , , , TSC TSC ( - ) ... ? , , FUD . , RDTSC ( ). RDTSCP , ( , ). , , , .

, ?

, , - , TSC . , - . - . .

, FUD RDTSC (P) . , , TSC , , . , , . ( ) , , Intel® IA-32 IA-64 Architects Architects, , , FUD, .

+4

Source: https://habr.com/ru/post/1607309/


All Articles