Skip to content

Commit

Permalink
Merge branch 'timers.2014.02.25a' of git://git.kernel.org/pub/scm/lin…
Browse files Browse the repository at this point in the history
…ux/kernel/git/paulmck/linux-rcu into timers/core

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
  • Loading branch information
Thomas Gleixner committed Feb 28, 2014
2 parents f96a34e + aea369b commit bce1936
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions kernel/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ struct tvec_base {
unsigned long timer_jiffies;
unsigned long next_timer;
unsigned long active_timers;
unsigned long all_timers;
struct tvec_root tv1;
struct tvec tv2;
struct tvec tv3;
Expand Down Expand Up @@ -337,6 +338,20 @@ void set_timer_slack(struct timer_list *timer, int slack_hz)
}
EXPORT_SYMBOL_GPL(set_timer_slack);

/*
* If the list is empty, catch up ->timer_jiffies to the current time.
* The caller must hold the tvec_base lock. Returns true if the list
* was empty and therefore ->timer_jiffies was updated.
*/
static bool catchup_timer_jiffies(struct tvec_base *base)
{
if (!base->all_timers) {
base->timer_jiffies = jiffies;
return true;
}
return false;
}

static void
__internal_add_timer(struct tvec_base *base, struct timer_list *timer)
{
Expand Down Expand Up @@ -383,15 +398,17 @@ __internal_add_timer(struct tvec_base *base, struct timer_list *timer)

static void internal_add_timer(struct tvec_base *base, struct timer_list *timer)
{
(void)catchup_timer_jiffies(base);
__internal_add_timer(base, timer);
/*
* Update base->active_timers and base->next_timer
*/
if (!tbase_get_deferrable(timer->base)) {
if (time_before(timer->expires, base->next_timer))
if (!base->active_timers++ ||
time_before(timer->expires, base->next_timer))
base->next_timer = timer->expires;
base->active_timers++;
}
base->all_timers++;
}

#ifdef CONFIG_TIMER_STATS
Expand Down Expand Up @@ -671,6 +688,8 @@ detach_expired_timer(struct timer_list *timer, struct tvec_base *base)
detach_timer(timer, true);
if (!tbase_get_deferrable(timer->base))
base->active_timers--;
base->all_timers--;
(void)catchup_timer_jiffies(base);
}

static int detach_if_pending(struct timer_list *timer, struct tvec_base *base,
Expand All @@ -685,6 +704,8 @@ static int detach_if_pending(struct timer_list *timer, struct tvec_base *base,
if (timer->expires == base->next_timer)
base->next_timer = base->timer_jiffies;
}
base->all_timers--;
(void)catchup_timer_jiffies(base);
return 1;
}

Expand Down Expand Up @@ -1153,6 +1174,10 @@ static inline void __run_timers(struct tvec_base *base)
struct timer_list *timer;

spin_lock_irq(&base->lock);
if (catchup_timer_jiffies(base)) {
spin_unlock_irq(&base->lock);
return;
}
while (time_after_eq(jiffies, base->timer_jiffies)) {
struct list_head work_list;
struct list_head *head = &work_list;
Expand Down Expand Up @@ -1566,6 +1591,7 @@ static int init_timers_cpu(int cpu)
base->timer_jiffies = jiffies;
base->next_timer = base->timer_jiffies;
base->active_timers = 0;
base->all_timers = 0;
return 0;
}

Expand Down

0 comments on commit bce1936

Please sign in to comment.