Skip to content

Commit

Permalink
crush: don't normalize input of crush_ln iteratively
Browse files Browse the repository at this point in the history
Use __builtin_clz() supported by GCC and Clang to figure out
how many bits we should shift instead of shifting by a bit
in a loop until the value gets normalized. Improves performance
of this function by up to 3x in worst-case scenario and overall
straw2 performance by ~10%.

Reflects ceph.git commit 110de33ca497d94fc4737e5154d3fe781fa84a0a.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
  • Loading branch information
Ilya Dryomov committed Oct 5, 2016
1 parent 464691b commit 74a5293
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions net/ceph/crush/mapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,15 @@ static __u64 crush_ln(unsigned int xin)

/* normalize input */
iexpon = 15;
while (!(x & 0x18000)) {
x <<= 1;
iexpon--;

/*
* figure out number of bits we need to shift and
* do it in one step instead of iteratively
*/
if (!(x & 0x18000)) {
int bits = __builtin_clz(x & 0x1FFFF) - 16;
x <<= bits;
iexpon = 15 - bits;
}

index1 = (x >> 8) << 1;
Expand Down

0 comments on commit 74a5293

Please sign in to comment.