linux/blkdev.h: Use ilog2() directly in blksize_bits()
PATCH 1/1 linux/blkdev.h: Use ilog2() directly in blksize_bits()
blksize_bits() can be achieved through ilog2(), and ilog2() is more efficient.
--- include/linux/blkdev.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
include/linux/blkdev.h +1 -6
@@ -1505,12 +1505,7 @@ static inline int blk_rq_aligned(struct request_queue *q, unsigned long addr,/* assumes size > 256 */ static inline unsigned int blksize_bits (unsigned int size) { -unsigned int bits =8 ; -do { - bits++; - size >>=1 ; - }while (size >256 ); -return bits; +return ilog2 (size); }static inline unsigned int block_size (struct block_device *bdev)
Signature · 1 line
2.20.1
Jens Axboe
maintainerQuoted 2 lines · Kaitao Cheng
blksize_bits()can be achieved throughilog2(), andilog2()is more efficient.
I like the simplification, but do you have any results to back up that claim? Is the generated code shorter? Runs faster?
Signature · 1 line
Jens Axboe
Quoted 2 lines · Kaitao Cheng
blksize_bits()can be achieved throughilog2(), andilog2()is more efficient.
If Jens agrees, how about removing the blksize_bits() function entirely and to make all callers use ilog2() instead of blksize_bits()?
Thanks,
Bart.
Jens Axboe
maintainerQuoted 6 lines · Bart Van Assche
Quoted 2 lines · Kaitao Cheng
blksize_bits()can be achieved throughilog2(), andilog2()is more efficient.If Jens agrees, how about removing the
blksize_bits()function entirely and to make all callers useilog2()instead ofblksize_bits()?
Yeah, if we are going this path, then let's just kill the function completely.
Signature · 1 line
Jens Axboe