概述
/* * This function runs timers and the timer-tq in bottom half context. */ static __latent_entropy void run_timer_softirq(struct softirq_action *h) { struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]);
__run_timers(base); if (IS_ENABLED(CONFIG_NO_HZ_COMMON) && base->nohz_active) __run_timers(this_cpu_ptr(&timer_bases[BASE_DEF])); }
/** * __run_timers - run all expired timers (if any) on this CPU. * @base: the timer vector to be processed. */ static inline void __run_timers(struct timer_base *base) { struct hlist_head heads[LVL_DEPTH]; int levels;
if (!time_after_eq(jiffies, base->clk)) return;
spin_lock_irq(&base->lock);
while (time_after_eq(jiffies, base->clk)) {
levels = collect_expired_timers(base, heads); base->clk++;
while (levels--) expire_timers(base, heads + levels); } base->running_timer = NULL; spin_unlock_irq(&base->lock); }
static void expire_timers(struct timer_base *base, struct hlist_head *head) { while (!hlist_empty(head)) { struct timer_list *timer; void (*fn)(unsigned long); unsigned long data;
timer = hlist_entry(head->first, struct timer_list, entry); timer_stats_account_timer(timer);
base->running_timer = timer; detach_timer(timer, true);
fn = timer->function; data = timer->data;
if (timer->flags & TIMER_IRQSAFE) { spin_unlock(&base->lock); call_timer_fn(timer, fn, data); spin_lock(&base->lock); } else { spin_unlock_irq(&base->lock); call_timer_fn(timer, fn, data); spin_lock_irq(&base->lock); } } }
最后
以上就是壮观汉堡为你收集整理的Linux 内核时钟之经典timer处理的全部内容,希望文章能够帮你解决Linux 内核时钟之经典timer处理所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复