__run_timers() -- 處理所有超時定時器 run_timer_softirq() --> __run_timers() /usr/src/linux-2.6.19/kernel/timer.c static inline void __run_timers(tvec_base_t *base) { structtimer_list *timer; spin_lock_irq(&base->lock); /*處理全部已經超時的定時器*/ while (time_after_eq(jiffies, base->timer_jiffies)) { structlist_headwork_list; structlist_head *head = &work_list; int index = base->timer_jiffies & TVR_MASK; //(0) /* * Cascade timers: */ if (!index && (!cascade(base, &base->tv2, INDEX(0))) && (!cascade(base, &base->tv3, INDEX(1))) && !cascade(base, &base->tv4, INDEX(2))) cascade(base, &base->tv5, INDEX(3)); ++base->timer_jiffies; list_replace_init(base->tv1.vec + index, &work_list); //(1) /*處理base->tv1.vec[index]鏈表上的全部定時器*/ while (!list_empty(head)) { void (*fn)(unsigned long); unsigned long data; timer = list_entry(head->next, structtimer_list, entry); fn = timer->function; data = timer->data; set_running_timer(base, timer); detach_timer(timer, 1); spin_unlock_irq(&base->lock); { intpreempt_count = preempt_count(); fn(data);//在不帶鎖的狀況下執行定時器函數 if (preempt_count != preempt_count()) { printk(KERN_WARNING "huh, entered %p " "with preempt_count %08x, exited" " with %08x?\n", fn, preempt_count, preempt_count()); BUG(); } } spin_lock_irq(&base->lock); } } set_running_timer(base, NULL); spin_unlock_irq(&base->lock); } (1) TVR_MASK = 255 = 11111111 -------------------------------------- #define TVR_MASK (TVR_SIZE - 1) #define TVR_SIZE (1 << TVR_BITS) #define TVR_BITS (CONFIG_BASE_SMALL ? 6 : 8) CONFIG_BASE_SMALL=0 (2) 根據base->timer_jiffies獲取tv1所管理的數組的一個元素 -- 一個定時器隊列