From: Dexuan Cui <decui@microsoft.com>
To: Long Li <longli@microsoft.com>, KY Srinivasan <kys@microsoft.com>,
"Haiyang Zhang" <haiyangz@microsoft.com>
Cc: "devel@linuxdriverproject.org" <devel@linuxdriverproject.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] hv: use substraction to update ring buffer index
Date: Mon, 16 Jan 2017 03:12:03 +0000 [thread overview]
Message-ID: <MWHPR03MB266993A99D6A5A0739723C20BF7D0@MWHPR03MB2669.namprd03.prod.outlook.com> (raw)
In-Reply-To: <1483589302-27177-1-git-send-email-longli@exchange.microsoft.com>
> From: devel [mailto:driverdev-devel-bounces@linuxdriverproject.org] On
> Behalf Of Long Li
> Sent: Thursday, January 5, 2017 12:08
> To: KY Srinivasan <kys@microsoft.com>; Haiyang Zhang
> <haiyangz@microsoft.com>
> Cc: devel@linuxdriverproject.org; linux-kernel@vger.kernel.org
> Subject: [PATCH] hv: use substraction to update ring buffer index
>
> From: Long Li <longli@microsoft.com>
>
> The ring buffer code uses %= to calculate index. For x86/64, %= compiles to
> div, more than 10 times slower than sub.
>
> Replace div with sub for this data heavy code path.
>
> Signed-off-by: Long Li <longli@microsoft.com>
> ---
> drivers/hv/ring_buffer.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
> index cd49cb1..f8eee6e 100644
> --- a/drivers/hv/ring_buffer.c
> +++ b/drivers/hv/ring_buffer.c
> @@ -135,7 +135,8 @@ hv_get_next_readlocation_withoffset(struct
> hv_ring_buffer_info *ring_info,
> u32 next = ring_info->ring_buffer->read_index;
>
> next += offset;
> - next %= ring_info->ring_datasize;
> + if (next >= ring_info->ring_datasize)
> + next -= ring_info->ring_datasize;
>
> return next;
> }
> @@ -179,7 +180,8 @@ static u32 hv_copyfrom_ringbuffer(
> memcpy(dest, ring_buffer + start_read_offset, destlen);
>
> start_read_offset += destlen;
> - start_read_offset %= ring_buffer_size;
> + if (start_read_offset >= ring_buffer_size)
> + start_read_offset -= ring_buffer_size;
>
> return start_read_offset;
> }
> @@ -201,7 +203,8 @@ static u32 hv_copyto_ringbuffer(
> memcpy(ring_buffer + start_write_offset, src, srclen);
>
> start_write_offset += srclen;
> - start_write_offset %= ring_buffer_size;
> + if (start_write_offset >= ring_buffer_size)
> + start_write_offset -= ring_buffer_size;
>
> return start_write_offset;
> }
Hi Long,
I guess you want to fix put_pkt_raw() too. :-)
Thanks,
-- Dexuan
next prev parent reply other threads:[~2017-01-16 3:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-05 4:08 [PATCH] hv: use substraction to update ring buffer index Long Li
2017-01-05 11:39 ` Dan Carpenter
2017-01-05 11:48 ` Dan Carpenter
2017-01-07 7:15 ` Long Li
2017-01-16 3:12 ` Dexuan Cui [this message]
2017-01-20 21:15 ` Long Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=MWHPR03MB266993A99D6A5A0739723C20BF7D0@MWHPR03MB2669.namprd03.prod.outlook.com \
--to=decui@microsoft.com \
--cc=devel@linuxdriverproject.org \
--cc=haiyangz@microsoft.com \
--cc=kys@microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longli@microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).