LKML Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] linux/blkdev.h: Use ilog2() directly in blksize_bits()
@ 2020-05-23 15:50 Kaitao Cheng
  2020-05-23 17:07 ` Jens Axboe
  2020-05-23 18:33 ` Bart Van Assche
  0 siblings, 2 replies; 4+ messages in thread
From: Kaitao Cheng @ 2020-05-23 15:50 UTC (permalink / raw)
  To: axboe
  Cc: damien.lemoal, bvanassche, ming.lei, martin.petersen, satyat,
	chaitanya.kulkarni, houtao1, asml.silence, ajay.joshi,
	linux-kernel, songmuchun, Kaitao Cheng

blksize_bits() can be achieved through ilog2(), and ilog2() is
more efficient.

Signed-off-by: Kaitao Cheng <pilgrimtao@gmail.com>
---
 include/linux/blkdev.h | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 2b33166b9daf..cce96abac4d4 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -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)
-- 
2.20.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] linux/blkdev.h: Use ilog2() directly in blksize_bits()
  2020-05-23 15:50 [PATCH] linux/blkdev.h: Use ilog2() directly in blksize_bits() Kaitao Cheng
@ 2020-05-23 17:07 ` Jens Axboe
  2020-05-23 18:33 ` Bart Van Assche
  1 sibling, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2020-05-23 17:07 UTC (permalink / raw)
  To: Kaitao Cheng
  Cc: damien.lemoal, bvanassche, ming.lei, martin.petersen, satyat,
	chaitanya.kulkarni, houtao1, asml.silence, ajay.joshi,
	linux-kernel, songmuchun

On 5/23/20 9:50 AM, Kaitao Cheng wrote:
> blksize_bits() can be achieved through ilog2(), and ilog2() 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?

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] linux/blkdev.h: Use ilog2() directly in blksize_bits()
  2020-05-23 15:50 [PATCH] linux/blkdev.h: Use ilog2() directly in blksize_bits() Kaitao Cheng
  2020-05-23 17:07 ` Jens Axboe
@ 2020-05-23 18:33 ` Bart Van Assche
  2020-05-23 18:50   ` Jens Axboe
  1 sibling, 1 reply; 4+ messages in thread
From: Bart Van Assche @ 2020-05-23 18:33 UTC (permalink / raw)
  To: Kaitao Cheng, axboe
  Cc: damien.lemoal, ming.lei, martin.petersen, satyat,
	chaitanya.kulkarni, houtao1, asml.silence, ajay.joshi,
	linux-kernel, songmuchun

On 2020-05-23 08:50, Kaitao Cheng wrote:
> blksize_bits() can be achieved through ilog2(), and ilog2() 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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] linux/blkdev.h: Use ilog2() directly in blksize_bits()
  2020-05-23 18:33 ` Bart Van Assche
@ 2020-05-23 18:50   ` Jens Axboe
  0 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2020-05-23 18:50 UTC (permalink / raw)
  To: Bart Van Assche, Kaitao Cheng
  Cc: damien.lemoal, ming.lei, martin.petersen, satyat,
	chaitanya.kulkarni, houtao1, asml.silence, ajay.joshi,
	linux-kernel, songmuchun

On 5/23/20 12:33 PM, Bart Van Assche wrote:
> On 2020-05-23 08:50, Kaitao Cheng wrote:
>> blksize_bits() can be achieved through ilog2(), and ilog2() 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()?

Yeah, if we are going this path, then let's just kill the function
completely.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-23 15:50 [PATCH] linux/blkdev.h: Use ilog2() directly in blksize_bits() Kaitao Cheng
2020-05-23 17:07 ` Jens Axboe
2020-05-23 18:33 ` Bart Van Assche
2020-05-23 18:50   ` Jens Axboe

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git