何时使用Linux内核add_timer与queue_delayed_work [英] When to use linux kernel add_timer vs queue_delayed_work

查看:618
本文介绍了何时使用Linux内核add_timer与queue_delayed_work的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要安排稍后在Linux内核驱动程序中执行的操作,我有2个选项:

To schedule an action to happen later in a linux kernel driver I have 2 options:

  • add_timer
  • queue_delayed_work
  • add_timer
  • queue_delayed_work

我知道的一个区别是:对于计时器,您需要指定expires,这是计时器到期时的吉菲斯值;对于延迟的工作,您需要指定吉菲斯的延迟.

One difference I know about: for timers you need to specify expires which is the jiffies value when the timer will expire, for delayed work you need to specify the delay of jiffies.

我一直在阅读其他有关计时器和work_queue的问题,其中提到了计时器在流程上下文之外运行.这和延迟工作有什么不同吗?

I've been reading other questions about timers and work_queue's, and it mentions timers run outside process context. Is this different from delayed work?

我也知道计时器存在问题,在计算expires时,可能会发生值溢出,因此计算出的值小于当前的抖动值,并且计时器立即过期(如果我输入错了,请纠正我这里).延迟工作是否会遇到同样的问题?如果可以,怎么办

Also I know there is an issue with timers, when calculating the expires, it might happen the value overflows, so the calculated value is smaller than the current jiffies and the timer expired immediately (correct me if I'm wrong here). Does delayed work suffer from the same issue? If it does, how do

在我看来,使用延迟的工作似乎更容易(因为该工作不是定期进行的).但是使用计时器有什么缺点呢?

To me it seems easier to use delayed work (because the work is not periodically). But what disadvantages over using timers?

编辑 我做了一些进一步的研究.似乎queue_delayed_work仅在内部使用add_timer.

EDIT I did some further research. It seems queue_delayed_work just uses add_timer internally.

因此,我的新问题是,如何正确处理计时器的延迟溢出?例如,如何将timer/delayed_work设置为10分钟的延迟?

So my new question is, how do I take properly care of the jiffies overflow for timers? For example how can I set a timer/delayed_work to a 10min delay?

推荐答案

正如我在问题中所述,queue_delayed_work仅在内部使用add_timer.所以用途是一样的.

As I stated in my question, queue_delayed_work just uses add_timer internally. So the use is equally.

这篇关于何时使用Linux内核add_timer与queue_delayed_work的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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