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:我的快速筆記,若有錯誤期待指出。