axmap: optimize ulog64 usage in axmap_handler()
authorJens Axboe <axboe@kernel.dk>
Thu, 12 Jul 2018 14:33:14 +0000 (08:33 -0600)
committerJens Axboe <axboe@kernel.dk>
Thu, 12 Jul 2018 14:33:14 +0000 (08:33 -0600)
We can do this incrementally, no need to compute from scratch
for every iteration.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
lib/axmap.c

index 4047f236bf20e532266d52d67f59dca80364d4e0..454af0b9d0361806bbf515c2e9c5c94776db3891 100644 (file)
@@ -156,10 +156,10 @@ static bool axmap_handler(struct axmap *axmap, uint64_t bit_nr,
                          void *), void *data)
 {
        struct axmap_level *al;
+       uint64_t index = bit_nr;
        int i;
 
        for (i = 0; i < axmap->nr_levels; i++) {
-               unsigned long index = ulog64(bit_nr, i);
                unsigned long offset = index >> UNIT_SHIFT;
                unsigned int bit = index & BLOCKS_PER_UNIT_MASK;
 
@@ -167,6 +167,9 @@ static bool axmap_handler(struct axmap *axmap, uint64_t bit_nr,
 
                if (func(al, offset, bit, data))
                        return true;
+
+               if (index)
+                       index >>= UNIT_SHIFT;
        }
 
        return false;