了解clock_gettime的问题 [英] Problem of understanding clock_gettime

查看:448
本文介绍了了解clock_gettime的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用clock_gettime可以访问的不同时钟有困难.我特别感兴趣:

I am having difficulties with the different clocks which can be accessed by clock_gettime. Especially I am interested in:

  • CLOCK_REALTIME
  • CLOCK_PROCESS_CPUTIME_ID
  • CLOCK_THREAD_COUTIME_ID
  • CLOCK_REALTIME
  • CLOCK_PROCESS_CPUTIME_ID
  • CLOCK_THREAD_COUTIME_ID

我阅读了联机帮助页,但对我没有太大帮助.我使用clock_gettime以便为我的探查器通过套接字发送收集的数据时生成时间戳.我注意到以下差异:

I read the manpage, but it didn't help me very much. I use clock_gettime in order to generate timestamps for my profiler when it sends the gathered data via socket. I have noticed the following differences:

  • CLOCK_REALTIME

有时我从探查器收到的与此时钟相关的事件的顺序是错误的.时间戳以较高的值开始,尽管不是很高.通常,最后一条消息(时间戳较高的消息)首先显示,然后是值较低的时间戳.

The events I receive from my profiler with this clocks are sometimes, in a wrong order. The timestamps start with a higher value, though not very much higher. Often the last messages (those with a higher timestamp) appear first and later the timestamps with a lower value.

  • CLOCK_PROCESS_CPUTIME_ID
  • CLOCK_THREAD_COUTIME_ID
  • CLOCK_PROCESS_CPUTIME_ID
  • CLOCK_THREAD_COUTIME_ID

我发现两个时钟都没有区别,尽管它们以较小的值开头并且始终正确排序.

I found no difference on both clocks, though they start with a lesser value and are always correctly ordered.

我无法解释这种行为.

推荐答案

您的系统时钟源可能设置为TSC而不是HPET.

Your system clock source is probably set to TSC instead of HPET.

通常,在现代多核系统上,HPET是较新的系统,它更加准确和一致,而TSC是一个较旧的系统,性能更高.

On modern multi-core systems in general, HPET is a newer system that is more accurate and consistent, and TSC is an older system that is more performant.

在openSUSE上,您可以找到当前时钟源是什么

On openSUSE, you can find out what your current clocksource is by

cat /sys/devices/system/clocksource/clocksource0/current_clocksource

要在openSUSE上将时钟源设置为HPET,请执行

To set your clock source to HPET on openSUSE, do

echo 'hpet' > /sys/devices/system/clocksource/clocksource0/current_clocksource

进一步阅读:

http://en.wikipedia.org/wiki/HPET

http://en.wikipedia.org/wiki/Time_Stamp_Counter

这篇关于了解clock_gettime的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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