Linux clock_gettime(CLOCK_MONOTONIC) 奇怪的非单调行为 [英] Linux clock_gettime(CLOCK_MONOTONIC) strange non-monotonic behavior

查看:40
本文介绍了Linux clock_gettime(CLOCK_MONOTONIC) 奇怪的非单调行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,在我的应用程序中,我使用 clock_gettime(CLOCK_MONOTONIC) 来测量帧之间的时间差(gamedev 中的典型方法),有时我会遇到一个奇怪的问题clock_gettime(..) 的行为 - 有时返回的值不是单调的(即上一个时间比当前时间大).

Folks, in my application I'm using clock_gettime(CLOCK_MONOTONIC) in order to measure the delta time between frames (a typical approach in gamedev) and from time to time I'm facing a strange behavior of clock_gettime(..) - returned values occasionally are not monotonic (i.e prev. time is bigger than current time).

目前,如果发生这样的悖论,我只需跳过当前帧并开始处理下一帧.

Currently, if such a paradox happens I simply skip the current frame and start processing the next one.

问题是这怎么可能?它是 clock_gettime 的 Linux POSIX 实现中的错误吗?我使用的是 Ubuntu Server Edition 10.04(内核 2.6.32-24,x86_64),gcc-4.4.3.

The question is how can this be possible at all? Is it a bug in Linux POSIX implementation of clock_gettime? I'm using Ubuntu Server Edition 10.04 (kernel 2.6.32-24, x86_64), gcc-4.4.3.

推荐答案

man clock_gettime 说:

CLOCK_MONOTONIC_RAW(自 Linux 2.6.28 起;Linux 专用)

CLOCK_MONOTONIC_RAW (since Linux 2.6.28; Linux-specific)

类似于 CLOCK_MONOTONIC,但提供对不受 NTP 调整影响的基于硬件的原始时间的访问.

Similar to CLOCK_MONOTONIC, but provides access to a raw hardware-based time that is not subject to NTP adjustments.

由于 CLOCK_MONOTONIC_RAW 不是 NTP 调整的主题,我猜 CLOCK_MONOTONIC 可能是.

Since CLOCK_MONOTONIC_RAW is not subject of NTP adjustments, I guess CLOCK_MONOTONIC could be.

我们在使用 2.6.18 内核和某些特定 Itanium 处理器的 Redhat Enterprise 5.0 上遇到了类似的问题.我们无法在同一操作系统上用其他处理器重现它.它在 RHEL 5.3 中得到了修复,并带有稍微更新的内核和一些 Redhat 补丁.

We had similar problems with Redhat Enterprise 5.0 with 2.6.18 kernel and some specific Itanium processor. We couldn't reproduce it with other processor on the same OS. It was fixed in RHEL 5.3 with slightly newer kernel and some Redhat patches.

这篇关于Linux clock_gettime(CLOCK_MONOTONIC) 奇怪的非单调行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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