linux系统计时,关于linux:计算机系统中的计时机制

我已经阅读了关于Linux中测量时间的这个链接 - getrusage vs clock_gettime vs clock vs gettimeofday? 它提供了C中可用的定时功能的大量细分

然而,我很困惑OS /硬件如何维护"时间"的不同概念。

这是Linux手册页的引用,

RTCs should not be confused with the system clock, which is a

software clock maintained by the kernel and used to implement

gettimeofday(2) and time(2), as well as setting timestamps on files,

and so on. The system clock reports seconds and microseconds since a

start point, defined to be the POSIX Epoch: 1970-01-01 00:00:00 +0000

(UTC). (One common implementation counts timer interrupts, once per

"jiffy", at a frequency of 100, 250, or 1000 Hz.) That is, it is

supposed to report wall clock time, which RTCs also do.

A key difference between an RTC and the system clock is that RTCs run

even when the system is in a low power state (including"off"), and

the system clock can't. Until it is initialized, the system clock

can only report time since system boot ... not since the POSIX Epoch.

So at boot time, and after resuming from a system low power state,

the system clock will often be set to the current wall clock time

using an RTC. Systems without an RTC need to set the system clock

using another clock, maybe across the network or by entering that

data manually.

Arch Linux文档表明RTC和系统时钟在启动后是独立的。 我的问题是:

是什么导致中断增加系统时钟???

如果壁时间=使用系统时钟的时间间隔,则处理时间取决于什么?

这些都与CPU频率有关吗? 或者这是一个完全正交的计时业务

它因CPU平台而异。 内核树的体系结构特定部分每个都有特定的处理程序。 也许你可以缩小这个问题?

@wallyk我已经改写了整个事情大声笑

在Linux上,从应用程序的角度来看,time(7)手册页给出了很好的解释。

Linux还提供(linux特定的)timerfd_create(2)和相关的系统调用。

您不应该关心中断(它们是内核的业务,并且是动态配置的,例如通过应用程序定时器-timer_create(2),poll(2)和许多其他系统调用 - 以及调度程序),但仅涉及应用程序可见时间相关系统调用。

也许,如果某个过程正在制作一个具有很短周期的定时器,例如10ms,内核会将定时器中断的频率增加到100Hz

在最近的内核上,你可能想要

CONFIG_HIGH_RES_TIMERS=y

CONFIG_TIMERFD=y

CONFIG_HPET_TIMER=y

CONFIG_PREEMPT=y

内核的.config文件中的选项。

顺便说一下,你可以用10秒间隔做cat /proc/interrupts两次。在我的笔记本电脑上有一个自制的3.16内核 - 主要是空闲进程,但是firefox浏览器和emacs,我每秒钟有25个中断。同时尝试cat /proc/timer_list和cat /proc/timer_stats

另请参见最近(例如3.16)Linux内核树的Documentation / timers /目录。

内核可能使用硬件设备,如PC笔记本电脑和台式机片上HPET(或TSC),它们比旧电池节省的RTC定时器要好得多。当然,细节是特定于硬件的。因此,在基于ARM的Linux系统(例如您的Android智能手机)上,它是不同的。

我在尝试学习更多关于操作系统的同时问这个问题..所以我真的关心中断

不,内核将根据要求配置中断。

最后一点我不太明白。我真的只想了解系统时钟是如何主要维护的。它是中断驱动的,所以必须引起中断..但是什么?我没看到内核如何配置这个?

进程调度程序为内核执行此操作!

@shekharsuman我不明白那是怎么回事

@shekharsuman进程调度依赖于一个可编程的间隔定时器,而这又取决于系统时钟没有?

@BasileStarynkevitch我已经阅读了它们,但仍然没有得到它。软件/系统时钟(或定时器/调度器等)是软件。必须有......某些......最终负责"标记时间"并递增这些时钟的硬件。显然它不是RTC ..所以它是什么?

我编辑了我提到HPET的答案。

@BasileStarynkevitch谢谢! HPET和TSC的链接非常有用..正是我所寻找的!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值