Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cpuid + rdtsc and out-of-order execution

Tags:

rdtsc

cpuid is used as a serializing instruction to prevent ooo execution when benchmarking, since the execution of benchmarked instructions might be reordered before rdtsc if it's used alone. My question is whether it is still possible for the instructions below rdtsc to be reordered in between cpuid and rdtsc? Since rdtsc is not a serializing instruction, instructions can be freely reordered around it?

like image 534
ashen Avatar asked Nov 09 '22 04:11

ashen


1 Answers

Since RDTSC does not depend on any input (it takes no arguments) in principle the OOO pipeline will run it as soon as it can. The reason you add a serializing instruction before it is not to let the RDTSC execute earlier.

There is an answer from John McCalpin here, you might find it useful. He explains the OOO reordering for the RDTSCP instruction (which behaves differently from RDTSC) which you may prefer to use instead.

like image 136
Anton Ivanov Avatar answered Dec 21 '22 10:12

Anton Ivanov