我是靠谱客的博主 壮观汉堡,这篇文章主要介绍Linux 内核时钟之经典timer处理,现在分享给大家,希望可以做个参考。

 

/*  * 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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部