Skip to content

Commit 001ec1b

Browse files
Frederic WeisbeckerKAGA-KOKO
authored andcommitted
timers: Optimize _next_timer_interrupt() level iteration
If a level has a timer that expires before reaching the next level, there is no need to iterate further. The next level is reached when the 3 lower bits of the current level are cleared. If the next event happens before/during that, the next levels won't provide an earlier expiration. 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 4468897 commit 001ec1b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

kernel/time/timer.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1526,13 +1526,21 @@ static unsigned long __next_timer_interrupt(struct timer_base *base)
15261526
clk = base->clk;
15271527
for (lvl = 0; lvl < LVL_DEPTH; lvl++, offset += LVL_SIZE) {
15281528
int pos = next_pending_bucket(base, offset, clk & LVL_MASK);
1529+
unsigned long lvl_clk = clk & LVL_CLK_MASK;
15291530

15301531
if (pos >= 0) {
15311532
unsigned long tmp = clk + (unsigned long) pos;
15321533

15331534
tmp <<= LVL_SHIFT(lvl);
15341535
if (time_before(tmp, next))
15351536
next = tmp;
1537+
1538+
/*
1539+
* If the next expiration happens before we reach
1540+
* the next level, no need to check further.
1541+
*/
1542+
if (pos <= ((LVL_CLK_DIV - lvl_clk) & LVL_CLK_MASK))
1543+
break;
15361544
}
15371545
/*
15381546
* Clock for the next level. If the current level clock lower
@@ -1570,7 +1578,7 @@ static unsigned long __next_timer_interrupt(struct timer_base *base)
15701578
* So the simple check whether the lower bits of the current
15711579
* level are 0 or not is sufficient for all cases.
15721580
*/
1573-
adj = clk & LVL_CLK_MASK ? 1 : 0;
1581+
adj = lvl_clk ? 1 : 0;
15741582
clk >>= LVL_CLK_SHIFT;
15751583
clk += adj;
15761584
}

0 commit comments

Comments
 (0)