内核定时机制API之add_timer_on
2018-02-24 08:14
681 查看
add_timer_on 用于在形参指定的cpu上开始一个定时器. 其源码分析如下: 从这个函数可以知道每个cpu上都有timer的list.如果调用add_timer的时候没有指定cpu 其实就是运行在当前的cpu上。 void add_timer_on(struct timer_list *timer, int cpu) { struct timer_base *new_base, *base; unsigned long flags; #如果这个timer已经pending或者timer到期后的回调函数为null,则通过BUG_ON 打印当前的callstack BUG_ON(timer_pending(timer) || !timer->function); #得到在形参指定cpu上的timer_base 指针 new_base = get_timer_cpu_base(timer->flags, cpu); /* * If @timer was on a different CPU, it should be migrated with the * old base locked to prevent other operations proceeding with the * wrong base locked. See lock_timer_base(). */ #在对timer_base 操作期间需要锁定 base = lock_timer_base(timer, &flags); if (base != new_base) { timer->flags |= TIMER_MIGRATING; raw_spin_unlock(&base->lock); base = new_base; raw_spin_lock(&base->lock); WRITE_ONCE(timer->flags, (timer->flags & ~TIMER_BASEMASK) | cpu); } #由于NOHZ的影响如果cpu处于idle,或者刚从idle 出来,base的时间可能不准,因此这里会检查是否需要调整 forward_timer_base(base); debug_activate(timer, timer->expires); #在形参指定cpu的timer_base上添加这个time internal_add_timer(base, timer); #解锁对形参cpu的base->lock的解锁 raw_spin_unlock_irqrestore(&base->lock, flags); }
相关文章推荐
- 内核定时机制API之add_timer
- 内核定时机制API之timer_setup
- 内核定时机制API之timespec64_add
- 内核定时机制API之del_timer
- 内核定时机制API之del_timer_sync
- 内核定时机制API之do_gettimeofday
- 内核定时机制API之timespec64_compare
- 内核定时机制API之do_settimeofday64
- 内核定时机制API之get_seconds
- 内核定时机制API之getnstimeofday
- 内核定时机制API之set_normalized_timespec64
- 内核定时机制API之msleep 和 msleep_interruptible
- 内核定时机制API之__round_jiffies
- 内核定时机制API之usleep_range
- 内核定时机制API之__round_jiffies_relative
- 内核定时机制API之mktime
- 内核定时机制API之ns_to_timespec64 和 ns_to_timeval
- 内核定时机制API之current_kernel_time
- 内核设备驱动API之device_add
- 内核同步机制API之up