后来通过看代码,终于明白了,通俗的讲,就是:
当前正在处理的定时器的到期时间
说到这里,就有人有疑问了,照你这么说,timer_jiffies不就等于jiffies了么?
非也,大家想想定时器延时执行的情况吧,在那种情况下,jiffies就大于timer_jiffies!
- static void internal_add_timer(struct tvec_base *base, struct timer_list *timer)
- {
- unsigned long expires = timer->expires;
- unsigned long idx = expires - base->timer_jiffies;
- struct list_head *vec;
- if (idx < TVR_SIZE) {
- int i = expires & TVR_MASK;
- vec = base->tv1.vec + i;
- } else if (idx < 1 << (TVR_BITS + TVN_BITS)) {
- int i = (expires >> TVR_BITS) & TVN_MASK;
- vec = base->tv2.vec + i;
- } else if (idx < 1 << (TVR_BITS + 2 * TVN_BITS)) {
- int i = (expires >> (TVR_BITS + TVN_BITS)) & TVN_MASK;
- vec = base->tv3.vec + i;
- } else if (idx < 1 << (TVR_BITS + 3 * TVN_BITS)) {
- int i = (expires >> (TVR_BITS + 2 * TVN_BITS)) & TVN_MASK;
- vec = base->tv4.vec + i;
- } else if ((signed long) idx < 0) {
- /*
- * Can happen if you add a timer with expires == jiffies,
- * or you set a timer to go off in the past
- */
- vec = base->tv1.vec + (base->timer_jiffies & TVR_MASK);
- } else {
- int i;
- /* If the timeout is larger than 0xffffffff on 64-bit
- * architectures then we use the maximum timeout:
- */
- if (idx > 0xffffffffUL) {
- idx = 0xffffffffUL;
- expires = idx + base->timer_jiffies;
- }
- i = (expires >> (TVR_BITS + 3 * TVN_BITS)) & TVN_MASK;
- vec = base->tv5.vec + i;
- }
- /*
- * Timers are FIFO:
- */
- list_add_tail(&timer->entry, vec);
- }
- internal_add_timer计算expires和当前正在处理的定时器的到期时间的差值,把定时器插入到不同的链表中。
- 实例1:
- 假设timer->expires=12,假设此时的jiffies和timer_jiffies都是9
- 那么此timer将会放入base->tv1.vec+2的list后面
- 但是,针对timer_jiffies在__run_timers()中的使用,我还是有些疑问的:
- static inline void __run_timers(struct tvec_base *base)
{
struct timer_list *timer;
spin_lock_irq(&base->lock);
while (time_after_eq(jiffies, base->timer_jiffies)) {
struct list_head work_list;
struct list_head *head = &work_list;
int index = base->timer_jiffies & TVR_MASK;(TVR_MASK=255) - //对这个语句还是有些疑问的,这样就可以得到index么?要知道base->timer_jiffies的起始值可是比较随机的
- //jiffies阿
- //若按照实例1的假设,index为9,直接大于2了
- }
- 权且记下,等待下回分解