How to detect if RDTSC returns a constant rate counter value?

后端 未结 4 1068
时光说笑
时光说笑 2021-01-19 15:17

It seems most newer CPUs from both AMD and Intel implement rdtsc as a constant rate counter, avoiding the issues caused by frequency changing as a result of things like Turb

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-19 15:24

    I know it's a long time since the original question was asked, but can I just point out that checking the generation/model of the processor is absolutely the WRONG thing to do. First of all, it's very easy to get the code wrong so that it doesn't work on future generation processors (because the family/model numbers aren't always "linear"), and secondly, just because a processor is "a later family/model" than the ones you knew this works on, it's not a guarantee that the feature is there. It's LIKELY, but I've seen plenty of code that does this badly, and thus "new processor comes out, and the code gets things wrong".

    Use the CPUID bit to check if the processor has the correct bit or not.

提交回复
热议问题