CLOCK_MONOTONIC与CLOCK_REALTIME区别

CLOCK_MONOTONIC与CLOCK_REALTIME区别,第1张

1 CLOCK_MONOTONIC(即monotonic time)

CLOCK_MONOTONIC:以绝对时间为准,获取的时间为系统重启到现在的时间,更改系统时间对它没有影响。

字面意义:单调时间,表示系统启动后流逝的时间,由变量jiffies来记录的。

系统每次启动时,jiffies初始化为0。每来一个timer interrupt,jiffies加1,即它代表系统启动后流逝的tick数。

jiffies一定是单调递增的,因为时间不可逆。

2 CLOCK_REALTIME(即wall time)

CLOCK_REALTIME:相对时间,从1970.1.1到目前的时间。更改系统时间会更改获取的值。它以系统时间为坐标。

字面意思: wall time挂钟时间,表示现实的雀空时间,由变量xtime来记录的。

系统每次启动时,将CMOS上的RTC时间读入xtime,这个值是”自1970-01-01起经历的秒数、本秒中经历的纳秒数”。每来一个timer interrupt,也需要去更新xtime。

wall time不一定是单调递增穗岁答的。因为wall time是指现实中的实际时间,如果系统要与网络中某个节点时间同步、或者由系统管理员觉得这个wall time与现实时间不一致,有可能任意的改变这个wall time。

最简单的例子是,用户本身可以去任意修改系统时间,这个被修改的时间应该就是wall time,即xtime,它甚至可以被写入RTC而永久保存。

一些应用软件可能猜慧就是用到了这个wall time。比如以前用vmware workstation,一启动提示试用期已过,但是只要把系统时间调整一下提前一年,再启动就不会有提示了。这很可能就是因为它启动时,用gettimeofday去读wall time,然后判断是否过期,只要将wall time改一下,就可以欺骗过去了。

CLOCK_MONOTONIC 指的是 monotonic time,而 CLOCK_REALTIME 指的是 wall time。

monotonic time 的字面意思是单调时间,实际上,指的是系橡罩咐统启动之后所流逝的时间,这是由变量 jiffies 来记录的,当系统每次启动时,jiffies 被初始化为 0,在每一个 timer interrupt 到来时,变量 jiffies 就加上 1,因此这个变量代表着系统启动后的流逝 tick 数。jiffies 一定是单调增加的,因为时间不可逆。

wall time 的字面意思是挂钟时间,实际上,指的是现实的时间,这是由变量 xtime 来记录的。系统在每次启动时,将 CMOS 上的 RTC 时间读入 xtime,这个值是自从 1970 年 1 月 1 日起经历的秒数,在每一个 timer interrupt 到来时,变量 xtime 也会加上 1。

注意, xtime 不一定是单独梁纯增加的 。因为 wall time 是指现实中的实际时间,如果系统要与网络中某个节闷大点时间同步,或者系统管理员觉得 wall time 与现实的时间不一致,就可能随意地更改这个 wall time。最常见的情况,用户可以去任意修改系统时间,这个被修改的时间就是 wall time。

http://man7.org/linux/man-pages/man2/epoll_wait.2.html

epoll_wait, epoll_pwait - wait for an I/O event on an epoll file

descriptor

以上两个系统调用等待epoll fd上的IO 事件

The epoll_wait() system call waits for events on the epoll(7)

instance referred to by the file descriptor epfd. The memory area pointed to by events will contain the events that will be available

for the caller. Up to maxevents are returned by epoll_wait(). The maxevents argument must be greater than zero.

The timeout argument specifies the number of milliseconds that

epoll_wait() will block. Time is measured against the

CLOCK_MONOTONIC clock. The call will block until either:

timout 参数颤升的时间单位是毫秒,epoll_wait 系统调用将被茄悄老阻塞。时间由 CLOCK_MONOTONIC 测量,直到下列几种情况该调用将一直被运纳阻塞。

Note

that the timeout interval will be rounded up to the system clock

granularity, and kernel scheduling delays mean that the blocking

interval may overrun by a small amount.

When successful, epoll_wait() returns the number of file descriptors

ready for the requested I/O, or zero if no file descriptor became

ready during the requested timeout milliseconds. When an error

occurs, epoll_wait() returns -1 and errno is set appropriately.


欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/tougao/12281591.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存