linux内核中的高精度定时器

146 views
Skip to first unread message

张海鹏

unread,
Oct 23, 2012, 7:29:46 AM10/23/12
to sh...@googlegroups.com
最近在看linux内核中的定时器,有一个疑问始终没有找到答案:
无论是基于jiffies的定时器还是基于High resolution timers,都是在时钟中断中检查有没有超时(不知道理解错了吗),那么High resolution timers是怎么实现低于时钟中断周期的定时任务呢?
如HZ=100,要定时1ms,如何实现啊?


--


**********************************************

        张海鹏(lzu...@gmail.com

**********************************************

Honglei Cong

unread,
Oct 23, 2012, 7:35:31 AM10/23/12
to sh...@googlegroups.com
高精度没有周期性timer,而是根据需要设置下次timer 中断时间

2012/10/23 张海鹏 <lzu...@gmail.com>:

> --
> -- You received this message because you are subscribed to the Google Groups
> Shanghai Linux User Group group. To post to this group, send email to
> sh...@googlegroups.com. To unsubscribe from this group, send email to
> shlug+un...@googlegroups.com. For more options, visit this group at
> https://groups.google.com/d/forum/shlug?hl=zh-CN
>
>

张海鹏

unread,
Oct 23, 2012, 7:43:56 AM10/23/12
to sh...@googlegroups.com
那么若是timer到来的时候,是以中断的方式通知cpu吗?能否具体讲讲是那个中断啊?

Honglei Cong

unread,
Oct 23, 2012, 8:05:05 AM10/23/12
to sh...@googlegroups.com
是以中断形式通知cpu,
要看是哪个中断,不同系统不同,
可以从这个函数开始看 clockevents_register_device,负责注册clock device

2012/10/23 张海鹏 <lzu...@gmail.com>:

张海鹏

unread,
Oct 23, 2012, 8:45:29 AM10/23/12
to sh...@googlegroups.com
好的,多谢指点。

Wizard

unread,
Oct 27, 2012, 10:30:41 PM10/27/12
to sh...@googlegroups.com
在 2012年10月23日 下午8:05,Honglei Cong <congh...@gmail.com> 写道:
> 是以中断形式通知cpu,
> 要看是哪个中断,不同系统不同,
> 可以从这个函数开始看 clockevents_register_device,负责注册clock device

那如果是要得到1ms的时间精度,那么就是每1ms产生一个时钟中断?

--
Wizard

zergmk2

unread,
Oct 29, 2012, 10:12:43 PM10/29/12
to sh...@googlegroups.com
对的。 要看你编译内核的时候有没有选上NO_HZ或者是高精度timer的选项。
不选上的话,默认会建立一个根据HZ为频率的周期性定时器,
选上了NO_HZ会根据你最近的定时器去设置你系统中的定时器寄存器来触发中断。

Wizard

unread,
Oct 31, 2012, 2:29:21 AM10/31/12
to sh...@googlegroups.com
2012/10/30 zergmk2 <zer...@gmail.com>:

> 对的。 要看你编译内核的时候有没有选上NO_HZ或者是高精度timer的选项。
> 不选上的话,默认会建立一个根据HZ为频率的周期性定时器,
> 选上了NO_HZ会根据你最近的定时器去设置你系统中的定时器寄存器来触发中断。
>
多谢,那快得反应不过来了。
Reply all
Reply to author
Forward
0 new messages