理解clock_gettime的问题

发布于 2024-11-05 19:27:51 字数 610 浏览 7 评论 0原文

我在使用可通过 clock_gettime 访问的不同时钟时遇到困难。我特别感兴趣的是:

  • CLOCK_REALTIME
  • CLOCK_PROCESS_CPUTIME_ID
  • CLOCK_THREAD_COUTIME_ID

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

  • CLOCK_REALTIME

我使用此时钟从分析器收到的事件有时顺序错误。时间戳以较高的值开始,但不会高很多。通常,最后的消息(具有较高时间戳的消息)首先出现,然后出现具有较低值的时间戳。

  • CLOCK_PROCESS_CPUTIME_ID
  • CLOCK_THREAD_COUTIME_ID

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

我无法解释这种行为。

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

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

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

I cannot explain this behavior.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怪我太投入 2024-11-12 19:27:51

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

一般来说,在现代多核系统中,HPET 是一个更准确和一致的新系统,而 TSC 是一个性能更高的旧系统。

找到当前时钟源。

在 openSUSE 上,您可以通过cat /sys/devices/system/clocksource/clocksource0/current_clocksource

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

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

进一步阅读:

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

http://en.wikipedia.org/wiki/Time_Stamp_Counter< /a>

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

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.

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

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

To set your clock source to HPET on openSUSE, do

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

Further reading:

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

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

南渊 2024-11-12 19:27:51
  • CLOCK_REALTIME 使您可以访问实时时钟,即存储当前日期和时间的时钟。
  • CLOCK_MONOTONIC 使您可以访问一个永远不会倒退的时钟,您可能应该使用这个而不是 CLOCK_REALTIME
  • CLOCK_PROCESS_CPUTIME_ID 使您可以访问特定于当前进程的时钟,从而获得该进程的 CPU 时间(CPU 运行该特定进程所花费的时间)。
  • CLOCK_THREAD_CPUTIME_ID 使您可以访问特定于当前线程的时钟,从而获得进程的 CPU 时间(CPU 运行该特定线程所花费的时间)。
  • CLOCK_REALTIME gives you access to the real time clock, i.e. the one that stores the current date and time.
  • CLOCK_MONOTONIC gives you access to a clock that never goes back in time, you should probably use this one instead of CLOCK_REALTIME.
  • CLOCK_PROCESS_CPUTIME_ID gives you acces to a clock specific to the current process, giving you the CPU time of the process (time spent by the CPU running that specific process).
  • CLOCK_THREAD_CPUTIME_ID gives you acces to a clock specific to the current thread, giving you the CPU time of the process (time spent by the CPU running that specific thread).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文