zoukankan      html  css  js  c++  java
  • Linux内核定时器

    一、内核定时器定义:

    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:个人快速笔记,如有错误期待指出。

  • 相关阅读:
    十三周课程总结
    第十二周课程总结
    第十一周课程总结
    第十周java总结
    第九周课程总结&实验报告(七)
    第八周课程报告&&实验报告六
    第七次学习总结&&第五次实验报告
    第六次学习总结&&第四次实验总结
    同余&逆元简单总结
    原根&离散对数简单总结
  • 原文地址:https://www.cnblogs.com/svking/p/3932570.html
Copyright © 2011-2022 走看看