Skip to content

Commit

Permalink
Merge branch 'timers-urgent-for-linus' of git://git.kernel.org/pub/sc…
Browse files Browse the repository at this point in the history
…m/linux/kernel/git/tip/tip

Pull timer fix from Ingo Molnar:
 "Fix a timer expiry bug that would cause spurious delay of timers"

* 'timers-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  timer: Read jiffies once when forwarding base clk
  • Loading branch information
torvalds committed Sep 26, 2019
2 parents a7b7b77 + e430d80 commit da05b5e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions kernel/time/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1678,24 +1678,26 @@ void timer_clear_idle(void)
static int collect_expired_timers(struct timer_base *base,
struct hlist_head *heads)
{
unsigned long now = READ_ONCE(jiffies);

/*
* NOHZ optimization. After a long idle sleep we need to forward the
* base to current jiffies. Avoid a loop by searching the bitfield for
* the next expiring timer.
*/
if ((long)(jiffies - base->clk) > 2) {
if ((long)(now - base->clk) > 2) {
unsigned long next = __next_timer_interrupt(base);

/*
* If the next timer is ahead of time forward to current
* jiffies, otherwise forward to the next expiry time:
*/
if (time_after(next, jiffies)) {
if (time_after(next, now)) {
/*
* The call site will increment base->clk and then
* terminate the expiry loop immediately.
*/
base->clk = jiffies;
base->clk = now;
return 0;
}
base->clk = next;
Expand Down

0 comments on commit da05b5e

Please sign in to comment.