linux 时间戳计数器,linux – 用于基准测试和时间戳计数器频率的rdtsc的准确性

根据英特尔的说法,不变的TSC意味着

The invariant TSC will run at a constant rate in all ACPI P-,C-. and T-states.

但那是多少?好,

That rate may be set by the

maximum core-clock to bus-clock ratio of the processor or may be set by the maximum resolved frequency at

which the processor is booted. The maximum resolved frequency may differ from the maximum qualified

frequency of the processor,see Section 18.14.5 for more detail. On certain processors,the TSC frequency may

not be the same as the frequency in the brand string.

看起来好像他们希望它是品牌字符串的频率,但不知何故并不总是正确的..

那个频率是多少?

The TSC,IA32_MPERF,and IA32_FIXED_CTR2 operate at the same,maximum-resolved frequency of the platform,which is equal to the product of scalable bus frequency and maximum resolved bus ratio.

For processors based on Intel Core microarchitecture,the scalable bus frequency is encoded in the bit field MSR_FSB_FREQ[2:0] at (0CDH),see Appendix B,“Model-Specific Registers (MSRs)”. The maximum resolved bus ratio can be read from the following bit field:

If XE operation is disabled,the maximum resolved bus ratio can be read in MSR_PLATFORM_ID[12:8]. It corresponds to the maximum qualified frequency.

If XE operation is enabled,the maximum resolved bus ratio is given in MSR_PERF_STAT[44:40],it corresponds to the maximum XE operation frequency configured by BIOS.

但这可能不是很有帮助. TL; DR,以编程方式找到TSC速率是太费力了.您当然可以在自己的系统上轻松找到它,只是根据定时循环得到一个不准确的猜测,并采用“最接近的数字”.无论如何,它可能是品牌字符串中的数字.它已经在我测试过的所有系统上,但我没有测试过那么多.如果不是,那么它将是一些显着不同的速率,所以你肯定会知道.

In addition,does this mean the time obtained by using the TSC ticks and cpu frequency isn’t the actual time used by the code piece?

是的,然而并非所有希望都失去了,使用TSC滴答和TSC费率(如果你以某种方式知道它)获得的时间将给出实际时间……几乎?这里通常会发出大量关于不可靠性的FUD.是的,RDTSC没有序列化(但您可以添加序列化指令). RDTSCP正在序列化,但在某些方面还不够(它不能太早执行,但它执行得太晚).但它不是你不能使用它们,你可以接受一个小错误,或阅读我下面链接的论文.

But can it be assumed to be synchronized among cores on newer cpus?

是的,不,也许 – 它将被同步,除非写入TSC.谁知道,有人可能会这样做.你无法控制.它也不会在不同的套接字之间同步.

最后,我并没有真正在基准测试的背景下购买关于RDTSC(P)的FUD.您可以根据需要对其进行序列化,TSC是不变的,您知道速率,因为它是您的系统.也没有任何替代方案,它基本上是高分辨率时间测量的来源,最终其他一切最终都会被使用.即使没有特殊的预防措施(但过滤了你的数据),大多数基准测试的准确性和精确度都很好,如果你需要更多,那么阅读How to Benchmark Code Execution Times on Intel® IA-32 and IA-64 Instruction Set Architectures,他们编写一个内核模块,这样他们就可以摆脱其他两个基准测试错误源.受到大量FUD,抢占和中断的影响.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值