timers: Simplify calc_index()
authorThomas Gleixner <tglx@linutronix.de>
Mon, 4 Apr 2022 14:47:55 +0000 (16:47 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Sat, 9 Apr 2022 20:19:39 +0000 (22:19 +0200)
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
kernel/time/timer.c

index 204d6cd83d0e2d458e8ec02d7dea4dc2fe98f36f..60aebf2b7f0ac4c912304a3f26893240bab0e537 100644 (file)
@@ -502,7 +502,7 @@ static inline unsigned calc_index(unsigned long expires, unsigned lvl,
         *
         * Round up with level granularity to prevent this.
         */
-       expires = (expires + LVL_GRAN(lvl)) >> LVL_SHIFT(lvl);
+       expires = (expires >> LVL_SHIFT(lvl)) + 1;
        *bucket_expiry = expires << LVL_SHIFT(lvl);
        return LVL_OFFS(lvl) + (expires & LVL_MASK);
 }