Skip to contentSkip to conversation

block: slightly optimize blkdev_ioctl BLKRA{SET,GET}

RFC PATCH In review Xiaotian Feng 3 participants 3 messages Jul 14, 2009 Block layer

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 block: slightly optimize blkdev_ioctl BLKRA{SET,GET}

Slightly optimize blkdev_ioctl by using shift instead of multiply and divide.

---
 block/ioctl.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
block/ioctl.c +2 -2
index 500e4c7..f8c7362 100644
@@ -305,7 +305,7 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
 		bdi = blk_get_backing_dev_info(bdev);
 		if (bdi == NULL)
 			return -ENOTTY;
-		return put_long(arg, (bdi->ra_pages * PAGE_CACHE_SIZE) / 512);
+		return put_long(arg, bdi->ra_pages << (PAGE_CACHE_SHIFT - 9));
 	case BLKROGET:
 		return put_int(arg, bdev_read_only(bdev) != 0);
 	case BLKBSZGET: /* get the logical block size (cf. BLKSSZGET) */
@@ -321,7 +321,7 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
 		bdi = blk_get_backing_dev_info(bdev);
 		if (bdi == NULL)
 			return -ENOTTY;
-		bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE;
+		bdi->ra_pages = arg >> (PAGE_CACHE_SHIFT - 9);
 		return 0;
 	case BLKBSZSET:
 		/* set the logical block size */
Signature · 1 line
1.6.2.5
#1 lore raw
Quoted 2 lines · Xiaotian Feng

Slightly optimize blkdev_ioctl by using shift instead of multiply and divide.

Not necessary, I believe gcc can do this by itself.

Have you checked its asm code?

Quoted 37 lines

---
 block/ioctl.c |    4 ++--

 1 files changed, 2 insertions(+), 2 deletions(-)
block/ioctl.c +1 -1
index 500e4c7..f8c7362 100644
@@ -305,7 +305,7 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
                bdi = blk_get_backing_dev_info(bdev);
                if (bdi == NULL)
                        return -ENOTTY;
-               return put_long(arg, (bdi->ra_pages * PAGE_CACHE_SIZE) / 512);
+               return put_long(arg, bdi->ra_pages << (PAGE_CACHE_SHIFT - 9));

       case BLKROGET:
               return put_int(arg, bdev_read_only(bdev) != 0); case BLKBSZGET: /* get the logical block size (cf. BLKSSZGET) */

block/ioctl.c +1 -1
@@ -321,7 +321,7 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
                bdi = blk_get_backing_dev_info(bdev);
                if (bdi == NULL)
                        return -ENOTTY;
-               bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE;
+               bdi->ra_pages = arg >> (PAGE_CACHE_SHIFT - 9);
                return 0;

       case BLKBSZSET:
               /* set the logical block size */
--
1.6.2.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

#2 lore raw
In reply to Xiaotian Feng
Quoted 2 lines · Xiaotian Feng

Slightly optimize blkdev_ioctl by using shift instead of multiply and divide.

Does it make an actual difference in the object code for you? I don't have a single multiplication in that function after compilation.

Hannes