" CPUID"前" RDTSC" [英] "cpuid" before "rdtsc"
问题描述
有时我遇到code与 RDTSC
读取TSC指令,但电话 CPUID
权利之前。
Sometimes I encounter code that reads TSC with rdtsc
instruction, but calls cpuid
right before.
为什么叫 CPUID
有必要吗?我意识到这可能是与有TSC的值不同的内核,但什么究竟的,当你调用序列中的这两个指令会发生什么?
Why is calling cpuid
necessary? I realize it may have something to do with different cores having TSC values, but what exactly happens when you call those two instructions in sequence?
推荐答案
这是为prevent乱序执行。请参见这里的全部细节,下面的相关位:
It's to prevent out-of-order execution. See here for full details, relevant bit below:
奔腾Pro和奔腾II处理器支持乱序执行指令可以在另一个顺序编程你他们执行。这可能是错误的来源,如果不照顾。
The Pentium Pro and Pentium II processors support out-of-order execution instructions may be executed in another order as you programmed them. This can be a source of errors if not taken care of.
要prevent这个程序员必须序列化指令队列。这可以通过RDTSC指令之前插入像CPUID指令序列化指令来实现。
To prevent this the programmer must serialize the the instruction queue. This can be done by inserting a serializing instruction like CPUID instruction before the RDTSC instruction.
这篇关于" CPUID"前" RDTSC"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!