理论知识
原理介绍
软件意义上的定时器是依赖硬件定时器实现的,内核在时钟中断发生后检测各个定时器是否到期,如果到期,将到期的定时器的处理函数作为软中断的下半部执行。实质上,时钟中断处理程序会唤醒TIMER_SOFTIRQ软中断,运行当前处理器上到期的所有定时器。
timer定时器的重要数据结构
struct timer_list {
/*
* All fields that change during normal runtime grouped to the
* same cacheline
*/
struct hlist_node entry;
unsigned long expires; //定时器的到期时间(jiffies)
void (*function)(unsigned long); //定时器时间溢出时的触发函数
unsigned long data; //function的传入参数
u32 flags;
int slack;
#ifdef CONFIG_TIMER_STATS
int start_pid;
void *start_site;
char start_comm[16];
#endif
#ifdef CONFIG_LOCKDEP
struct lockdep_map lockdep_map;
#endif
};
expires一般用户毫秒级别的定时器