我想看看 1 纳秒在我的笔记本电脑上需要多少个周期。
笔记本电脑配置:
- 处理器:Intel Centrino Duo 2.0 GHz ( T7200 )
- 内存:2 GB
以下是计数:
- 1 秒耗时:1995198000(接近 20 亿次滴答,没问题)
- 1 毫秒:2,159,460(接近 200 万,没问题)
- 1 微秒:507,408(为什么?)
- 1 纳秒:139,000(为什么?)
直到 1 微秒,刻度与频率一致。但是,在此之下,事实并非如此。此外,我可以可靠地使用周期计数来区分 100 纳秒和 200 纳秒,而不是低于该值。
测量设置:
- 测量过程附加到一个处理器。
- 进程的优先级设置为最高。
- CPU 设置为始终以最高频率运行。
谁能解释一下原因?是因为以这种方式实现 sleep (我正在使用 nanosleep)吗? ?
最佳答案
来自 the specification of nanosleep :
The suspension time may be longer than requested because the argument value is rounded up to an integer multiple of the sleep resolution or because of the scheduling of other activity by the system.
关于使用 RDTSC 的 nanosleep 循环计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26654160/