rdtscl函数的指令周期为什么不一样

朽木可雕 2015-10-14 08:52:48

驱动中的代码
preempt_disable();
rdtscl(start);
rdtscl(end);
preempt_enable();

printk("big end - start %lu\n",end - start);

输入命令:echo "123" > /dev/scull_char0

没有加入非抢占的preempt_disable的代码
[53611.182403] big end - start 48
[53611.548697] big end - start 120
[53611.842520] big end - start 140
[53612.226049] big end - start 120
[53612.552272] big end - start 120
[53612.888664] big end - start 140
[53613.247085] big end - start 120


加入非抢占的preempt_disable的代码
[53688.269852] big end - start 120
[53689.148889] big end - start 120
[53710.049073] big end - start 96
[53710.359387] big end - start 120
[53710.670128] big end - start 120
[53710.981119] big end - start 140


为什么open指定的两个rdtscl指定的时间会有不一致的情况呢?
理论上rdtscl的时钟周期应该是固定的啊
...全文
241 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
nswcfd 2015-10-21
  • 打赏
  • 举报
回复
The RDTSC instruction is not a serializing instruction. It does not necessarily wait until all previous instructions have been executed before reading the counter. Similarly, subsequent instructions may begin execution before the read operation is performed. If software requires RDTSC to be executed only after all previous instructions have completed locally, it can either use RDTSCP (if the processor supports that instruction) or execute the sequence LFENCE;RDTSC. 从intel手册上抄的,不知道not serializing是不是关键
朽木可雕 2015-10-21
  • 打赏
  • 举报
回复
引用 5 楼 nswcfd 的回复:
http://blog.csdn.net/solstice/article/details/5196544 3. 测不准
太感谢了正是我想找的资料。
nswcfd 2015-10-21
  • 打赏
  • 举报
回复
http://blog.csdn.net/solstice/article/details/5196544 3. 测不准
朽木可雕 2015-10-20
  • 打赏
  • 举报
回复
引用 2 楼 nswcfd 的回复:
可能跟cpu流水线的工作方式有关吧。 为了让结果更可靠,建议多次循环取平均值。
流水线为什么什么会对时间影响这么大呢 ,应该只有几个指令周期的才对啊。为什么最小的才48最大的都140了这个不符合逻辑啊。
nswcfd 2015-10-19
  • 打赏
  • 举报
回复
可能跟cpu流水线的工作方式有关吧。 为了让结果更可靠,建议多次循环取平均值。
朽木可雕 2015-10-15
  • 打赏
  • 举报
回复
各位大神求解答,小菜在此感激不尽。

4,465

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧