Skip to content

Commit

Permalink
timers: Consider slack value in mod_timer()
Browse files Browse the repository at this point in the history
There is an optimization which does not update the timer if the timer
was pending and the expiration time was unchanged.

Since commit 3bbb9ec ("timers: Introduce the concept of timer slack
for legacy timers") this optimization is no longer applied for timers
where the expiration time got extended due to the slack value. So we
need to check again after the expiration time might have been updated.

[ tglx: Made it a single check by applying slack first and sorting
  out the slack = 0 value (all timeouts < 256 jiffies) early ]

Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Link: http://lkml.kernel.org/r/20110521105828.GA29442@Chamillionaire.breakpoint.cc
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
  • Loading branch information
Sebastian Andrzej Siewior authored and Thomas Gleixner committed Jun 3, 2011
1 parent 1b054b6 commit 1c3cc11
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions kernel/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,16 +749,15 @@ unsigned long apply_slack(struct timer_list *timer, unsigned long expires)
unsigned long expires_limit, mask;
int bit;

expires_limit = expires;

if (timer->slack >= 0) {
expires_limit = expires + timer->slack;
} else {
unsigned long now = jiffies;
long delta = expires - jiffies;

if (delta < 256)
return expires;

/* No slack, if already expired else auto slack 0.4% */
if (time_after(expires, now))
expires_limit = expires + (expires - now)/256;
expires_limit = expires + delta / 256;
}
mask = expires ^ expires_limit;
if (mask == 0)
Expand Down Expand Up @@ -795,6 +794,8 @@ unsigned long apply_slack(struct timer_list *timer, unsigned long expires)
*/
int mod_timer(struct timer_list *timer, unsigned long expires)
{
expires = apply_slack(timer, expires);

/*
* This is a common optimization triggered by the
* networking code - if the timer is re-modified
Expand All @@ -803,8 +804,6 @@ int mod_timer(struct timer_list *timer, unsigned long expires)
if (timer_pending(timer) && timer->expires == expires)
return 1;

expires = apply_slack(timer, expires);

return __mod_timer(timer, expires, false, TIMER_NOT_PINNED);
}
EXPORT_SYMBOL(mod_timer);
Expand Down

0 comments on commit 1c3cc11

Please sign in to comment.