public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] block: slightly optimize blkdev_ioctl BLKRA{SET,GET}
@ 2009-07-14 11:59 Xiaotian Feng
  2009-07-14 13:48 ` Américo Wang
  2009-07-14 14:08 ` Johannes Weiner
  0 siblings, 2 replies; 5+ messages in thread
From: Xiaotian Feng @ 2009-07-14 11:59 UTC (permalink / raw)
  To: axboe; +Cc: linux-kernel, Xiaotian Feng

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

Signed-off-by: Xiaotian Feng <dfeng@redhat.com>
---
 block/ioctl.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/ioctl.c b/block/ioctl.c
index 500e4c7..f8c7362 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -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 */
-- 
1.6.2.5


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

* Re: [RFC PATCH] block: slightly optimize blkdev_ioctl BLKRA{SET,GET}
  2009-07-14 11:59 Xiaotian Feng
@ 2009-07-14 13:48 ` Américo Wang
  2009-07-14 14:08 ` Johannes Weiner
  1 sibling, 0 replies; 5+ messages in thread
From: Américo Wang @ 2009-07-14 13:48 UTC (permalink / raw)
  To: Xiaotian Feng; +Cc: axboe, linux-kernel

On Tue, Jul 14, 2009 at 7:59 PM, Xiaotian Feng<dfeng@redhat.com> wrote:
> 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?

>
> Signed-off-by: Xiaotian Feng <dfeng@redhat.com>
> ---
>  block/ioctl.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/block/ioctl.c b/block/ioctl.c
> index 500e4c7..f8c7362 100644
> --- a/block/ioctl.c
> +++ b/block/ioctl.c
> @@ -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 */
> --
> 1.6.2.5
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>

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

* Re: [RFC PATCH] block: slightly optimize blkdev_ioctl BLKRA{SET,GET}
  2009-07-14 11:59 Xiaotian Feng
  2009-07-14 13:48 ` Américo Wang
@ 2009-07-14 14:08 ` Johannes Weiner
  1 sibling, 0 replies; 5+ messages in thread
From: Johannes Weiner @ 2009-07-14 14:08 UTC (permalink / raw)
  To: Xiaotian Feng; +Cc: axboe, linux-kernel

On Tue, Jul 14, 2009 at 07:59:54PM +0800, Xiaotian Feng wrote:
> 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

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

* [RFC PATCH] block: slightly optimize blkdev_ioctl BLKRA{SET,GET}
       [not found] <1247572395-24021-1-git-send-email-dfeng@redhat.com>
@ 2009-07-14 14:12 ` Xiaotian Feng
  2009-07-17  5:03   ` Tejun Heo
  0 siblings, 1 reply; 5+ messages in thread
From: Xiaotian Feng @ 2009-07-14 14:12 UTC (permalink / raw)
  To: axboe; +Cc: linux-kernel, Xiaotian Feng

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

Signed-off-by: Xiaotian Feng <dfeng@redhat.com>
---
 block/ioctl.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/ioctl.c b/block/ioctl.c
index 500e4c7..f8c7362 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -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 */
-- 
1.6.2.5


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

* Re: [RFC PATCH] block: slightly optimize blkdev_ioctl BLKRA{SET,GET}
  2009-07-14 14:12 ` [RFC PATCH] block: slightly optimize blkdev_ioctl BLKRA{SET,GET} Xiaotian Feng
@ 2009-07-17  5:03   ` Tejun Heo
  0 siblings, 0 replies; 5+ messages in thread
From: Tejun Heo @ 2009-07-17  5:03 UTC (permalink / raw)
  To: Xiaotian Feng; +Cc: axboe, linux-kernel

Xiaotian Feng wrote:
> Slightly optimize blkdev_ioctl by using shift instead of multiply
> and divide.
> 
> Signed-off-by: Xiaotian Feng <dfeng@redhat.com>

As other people have commented, this is unnecessary.  Let's leave it
to the compiler.

Thanks.

-- 
tejun

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

end of thread, other threads:[~2009-07-17  5:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1247572395-24021-1-git-send-email-dfeng@redhat.com>
2009-07-14 14:12 ` [RFC PATCH] block: slightly optimize blkdev_ioctl BLKRA{SET,GET} Xiaotian Feng
2009-07-17  5:03   ` Tejun Heo
2009-07-14 11:59 Xiaotian Feng
2009-07-14 13:48 ` Américo Wang
2009-07-14 14:08 ` Johannes Weiner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox