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);   }  } }

 

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值