Skip to content

Commit a2026e4

Browse files
committed
timers: Simplify calc_index()
The level granularity round up of calc_index() does: (x + (1 << n)) >> n which is obviously equivalent to (x >> n) + 1 but compilers can't figure that out despite the fact that the input range is known to not cause an overflow. It's neither intuitive to read. Just write out the obvious. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/87h778j46c.ffs@tglx
1 parent 2731aa7 commit a2026e4

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

kernel/time/timer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ static inline unsigned calc_index(unsigned long expires, unsigned lvl,
502502
*
503503
* Round up with level granularity to prevent this.
504504
*/
505-
expires = (expires + LVL_GRAN(lvl)) >> LVL_SHIFT(lvl);
505+
expires = (expires >> LVL_SHIFT(lvl)) + 1;
506506
*bucket_expiry = expires << LVL_SHIFT(lvl);
507507
return LVL_OFFS(lvl) + (expires & LVL_MASK);
508508
}

0 commit comments

Comments
 (0)