RDTSC为什么不是序列化指令? [英] Why isn't RDTSC a serializing instruction?

查看:132
本文介绍了RDTSC为什么不是序列化指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关RDTSC指令的英特尔手册警告说,乱序执行当实际执行RDTSC时,它可能会改变,因此他们建议在其前面插入一个CPUID指令,因为CPUID将序列化指令流(永远不会无序执行CPUID).我的问题很简单:如果他们能够进行指令序列化,为什么不进行RDTSC序列化呢?它的全部目的似乎是要获得精确的周期计时.是否有一种情况,您要在序列化指令之前添加它?

The Intel manuals for the RDTSC instruction warn that out of order execution can change when RDTSC is actually executed, so they recommend inserting a CPUID instruction in front of it because CPUID will serialize the instruction stream (CPUID is never executed out of order). My question is simple: if they had the ability to make instructions serializing, why didn't they make RDTSC serializing? The entire point of it appears to be to get cycle accurate timings. Is there a situation under which you would not want to precede it with a serializing instruction?

较新的Intel CPU有一个单独的RDTSCP指令正在序列化.英特尔选择引入单独的指令,而不是改变RDTSC的行为,这向我暗示,在某些情况下,您想要的是潜在的乱序时间.什么事?

Newer Intel CPUs have a separate RDTSCP instruction that is serializing. Intel opted to introduce a separate instruction rather than change the behavior of RDTSC, which suggests to me that there has to be some situation where a potentially out of order timing is what you want. What is it?

推荐答案

如果您尝试使用rdtsc来查看分支是否预测错误,则需要非序列化版本.

If you are trying to use rdtsc to see if a branch mispredicts, the non-serializing version is what you want.

//math here
rdtsc
branch if zero to done
//do some work that always takes 1 cycle
done: rdtsc

如果正确预测了分支,则增量将很小(甚至可能是负数).如果分支预测错误,则增量将很大.

If the branch is predicted correctly, the delta will be small (maybe even negative?). If the branch is mispredicted, the delta will be large.

对于序列化版本,分支条件将得到解决,因为第一个rdtsc等待数学完成.

With the serializing version, the branch condition will be resolved because the first rdtsc waits for the math to finish.

这篇关于RDTSC为什么不是序列化指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆