码迷,mamicode.com
首页 > 系统相关 > 详细

Linux内核定时器

时间:2014-08-24 11:30:02      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   使用   io   ar   art   div   cti   

一、内核定时器定义:

struct timer_list {
    struct list_head entry;
    unsigned long expires;

    void (*function)(unsigned long);
    unsigned long data;

    struct tvec_base *base;
#ifdef CONFIG_TIMER_STATS
    void *start_site;
    char start_comm[16];
    int start_pid;
#endif
#ifdef CONFIG_LOCKDEP
    struct lockdep_map lockdep_map;
#endif
};

二、使用方法:

  ①struct timer_list timer;

   void fun (unsigned long arg);

   unsigned long = 0;

  ②init_timer (&timer);

  ③setup_timer (&timer, fun, (unsigned long )arg);  

  ④timer.expires = jiffires + 60 * HZ; //自定义一个超时时间,jiffires是计时器的当前值(单位是中断),HZ是每秒对应的中断次数。

  ⑤add_timer (&timer);

  ⑥如果是希望周期运行,则每次在注册的函数执行完毕后需要重新设置、激活定时器,可以使用mod_timer()。内核注释:

    * mod_timer(timer, expires) is equivalent to:
    *
    * del_timer(timer); timer->expires = expires; add_timer(timer);

 

   mod_timer (&timer, jiffires + 60 * HZ); //写在fun函数的最后

  ⑦del_timer (&timer);

 

ps:个人快速笔记,如有错误期待指出。

Linux内核定时器

标签:style   blog   color   使用   io   ar   art   div   cti   

原文地址:http://www.cnblogs.com/svking/p/3932570.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!