Skip to content

Commit dc2a0f1

Browse files
Frederic WeisbeckerKAGA-KOKO
authored andcommitted
timers: Always keep track of next expiry
So far next expiry was only tracked while the CPU was in nohz_idle mode in order to cope with missing ticks that can't increment the base->clk periodically anymore. This logic is going to be expanded beyond nohz in order to spare timer softirqs so do it unconditionally. Signed-off-by: Frederic Weisbecker <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Juri Lelli <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 001ec1b commit dc2a0f1

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

kernel/time/timer.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,7 @@ static int calc_wheel_index(unsigned long expires, unsigned long clk,
544544
}
545545

546546
static void
547-
trigger_dyntick_cpu(struct timer_base *base, struct timer_list *timer,
548-
unsigned long bucket_expiry)
547+
trigger_dyntick_cpu(struct timer_base *base, struct timer_list *timer)
549548
{
550549
if (!is_timers_nohz_active())
551550
return;
@@ -565,23 +564,8 @@ trigger_dyntick_cpu(struct timer_base *base, struct timer_list *timer,
565564
* timer is not deferrable. If the other CPU is on the way to idle
566565
* then it can't set base->is_idle as we hold the base lock:
567566
*/
568-
if (!base->is_idle)
569-
return;
570-
571-
/*
572-
* Check whether this is the new first expiring timer. The
573-
* effective expiry time of the timer is required here
574-
* (bucket_expiry) instead of timer->expires.
575-
*/
576-
if (time_after_eq(bucket_expiry, base->next_expiry))
577-
return;
578-
579-
/*
580-
* Set the next expiry time and kick the CPU so it can reevaluate the
581-
* wheel:
582-
*/
583-
base->next_expiry = bucket_expiry;
584-
wake_up_nohz_cpu(base->cpu);
567+
if (base->is_idle)
568+
wake_up_nohz_cpu(base->cpu);
585569
}
586570

587571
/*
@@ -592,12 +576,26 @@ trigger_dyntick_cpu(struct timer_base *base, struct timer_list *timer,
592576
static void enqueue_timer(struct timer_base *base, struct timer_list *timer,
593577
unsigned int idx, unsigned long bucket_expiry)
594578
{
579+
595580
hlist_add_head(&timer->entry, base->vectors + idx);
596581
__set_bit(idx, base->pending_map);
597582
timer_set_idx(timer, idx);
598583

599584
trace_timer_start(timer, timer->expires, timer->flags);
600-
trigger_dyntick_cpu(base, timer, bucket_expiry);
585+
586+
/*
587+
* Check whether this is the new first expiring timer. The
588+
* effective expiry time of the timer is required here
589+
* (bucket_expiry) instead of timer->expires.
590+
*/
591+
if (time_before(bucket_expiry, base->next_expiry)) {
592+
/*
593+
* Set the next expiry time and kick the CPU so it
594+
* can reevaluate the wheel:
595+
*/
596+
base->next_expiry = bucket_expiry;
597+
trigger_dyntick_cpu(base, timer);
598+
}
601599
}
602600

603601
static void internal_add_timer(struct timer_base *base, struct timer_list *timer)
@@ -1493,7 +1491,6 @@ static int __collect_expired_timers(struct timer_base *base,
14931491
return levels;
14941492
}
14951493

1496-
#ifdef CONFIG_NO_HZ_COMMON
14971494
/*
14981495
* Find the next pending bucket of a level. Search from level start (@offset)
14991496
* + @clk upwards and if nothing there, search from start of the level
@@ -1585,6 +1582,7 @@ static unsigned long __next_timer_interrupt(struct timer_base *base)
15851582
return next;
15861583
}
15871584

1585+
#ifdef CONFIG_NO_HZ_COMMON
15881586
/*
15891587
* Check, if the next hrtimer event is before the next timer wheel
15901588
* event:
@@ -1790,6 +1788,7 @@ static inline void __run_timers(struct timer_base *base)
17901788

17911789
levels = collect_expired_timers(base, heads);
17921790
base->clk++;
1791+
base->next_expiry = __next_timer_interrupt(base);
17931792

17941793
while (levels--)
17951794
expire_timers(base, heads + levels);
@@ -2042,6 +2041,7 @@ static void __init init_timer_cpu(int cpu)
20422041
base->cpu = cpu;
20432042
raw_spin_lock_init(&base->lock);
20442043
base->clk = jiffies;
2044+
base->next_expiry = base->clk + NEXT_TIMER_MAX_DELTA;
20452045
timer_base_init_expiry_lock(base);
20462046
}
20472047
}

0 commit comments

Comments
 (0)