Linux内核定时器

1、内核定时器定义:函数

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
};

2、使用方法:ui

  ①struct timer_list timer;spa

   void fun (unsigned long arg);code

   unsigned long = 0;blog

  ②init_timer (&timer);it

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

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

  ⑤add_timer (&timer);class

  ⑥若是是但愿周期运行,则每次在注册的函数执行完毕后须要从新设置、激活定时器,能够使用mod_timer()。内核注释:map

    * 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:我的快速笔记,若有错误期待指出。

相关文章
相关标签/搜索