From: Stephen Hemminger <stephen@networkplumber•org>
To: kys@microsoft•com, haiyangz@microsoft•com, sthemmin@microsoft•com
Cc: devel@linuxdriverproject•org, netdev@vger•kernel.org
Subject: [PATCH net-next 1/6] netvsc: optimize calculation of number of slots
Date: Thu, 8 Jun 2017 16:21:18 -0700 [thread overview]
Message-ID: <20170608232123.28366-2-sthemmin@microsoft.com> (raw)
In-Reply-To: <20170608232123.28366-1-sthemmin@microsoft.com>
Speed up transmit check for fragmented packets by using existing
macros to compute number of pages, and eliminate loop since
skb fragments each take a page. Number of slots is also unsigned.
Signed-off-by: Stephen Hemminger <sthemmin@microsoft•com>
---
drivers/net/hyperv/netvsc_drv.c | 43 ++++++++++-------------------------------
1 file changed, 10 insertions(+), 33 deletions(-)
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 2564ac83eb64..df6d8e28949e 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -345,34 +345,14 @@ static u32 init_page_array(void *hdr, u32 len, struct sk_buff *skb,
return slots_used;
}
-static int count_skb_frag_slots(struct sk_buff *skb)
-{
- int i, frags = skb_shinfo(skb)->nr_frags;
- int pages = 0;
-
- for (i = 0; i < frags; i++) {
- skb_frag_t *frag = skb_shinfo(skb)->frags + i;
- unsigned long size = skb_frag_size(frag);
- unsigned long offset = frag->page_offset;
-
- /* Skip unused frames from start of page */
- offset &= ~PAGE_MASK;
- pages += PFN_UP(offset + size);
- }
- return pages;
-}
-
-static int netvsc_get_slots(struct sk_buff *skb)
+/* Estimate number of page buffers neede to transmit
+ * Need at most 2 for RNDIS header plus skb body and fragments.
+ */
+static unsigned int netvsc_get_slots(const struct sk_buff *skb)
{
- char *data = skb->data;
- unsigned int offset = offset_in_page(data);
- unsigned int len = skb_headlen(skb);
- int slots;
- int frag_slots;
-
- slots = DIV_ROUND_UP(offset + len, PAGE_SIZE);
- frag_slots = count_skb_frag_slots(skb);
- return slots + frag_slots;
+ return PFN_UP(offset_in_page(skb->data) + skb_headlen(skb))
+ + skb_shinfo(skb)->nr_frags
+ + 2;
}
static u32 net_checksum_info(struct sk_buff *skb)
@@ -410,21 +390,18 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
struct hv_page_buffer page_buf[MAX_PAGE_BUFFER_COUNT];
struct hv_page_buffer *pb = page_buf;
- /* We will atmost need two pages to describe the rndis
- * header. We can only transmit MAX_PAGE_BUFFER_COUNT number
+ /* We can only transmit MAX_PAGE_BUFFER_COUNT number
* of pages in a single packet. If skb is scattered around
* more pages we try linearizing it.
*/
-
- num_data_pgs = netvsc_get_slots(skb) + 2;
-
+ num_data_pgs = netvsc_get_slots(skb);
if (unlikely(num_data_pgs > MAX_PAGE_BUFFER_COUNT)) {
++net_device_ctx->eth_stats.tx_scattered;
if (skb_linearize(skb))
goto no_memory;
- num_data_pgs = netvsc_get_slots(skb) + 2;
+ num_data_pgs = netvsc_get_slots(skb);
if (num_data_pgs > MAX_PAGE_BUFFER_COUNT) {
++net_device_ctx->eth_stats.tx_too_big;
goto drop;
--
2.11.0
next prev parent reply other threads:[~2017-06-08 23:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-08 23:21 [PATCH net-next 0/6] netvsc: small cleanups Stephen Hemminger
2017-06-08 23:21 ` Stephen Hemminger [this message]
2017-06-08 23:21 ` [PATCH net-next 2/6] netvsc: use hv_get_bytes_to_read Stephen Hemminger
2017-06-08 23:21 ` [PATCH net-next 3/6] netvsc: use typed pointer for internal state Stephen Hemminger
2017-06-09 10:24 ` Sergei Shtylyov
2017-06-08 23:21 ` [PATCH net-next 4/6] netvsc: mark error cases as unlikely Stephen Hemminger
2017-06-08 23:21 ` [PATCH net-next 5/6] netvsc: pass net_device to netvsc_init_buf and netvsc_connect_vsp Stephen Hemminger
2017-06-08 23:21 ` [PATCH net-next 6/6] netvsc: fold in get_outbound_net_device Stephen Hemminger
2017-06-09 16:16 ` [PATCH net-next 0/6] netvsc: small cleanups David Miller
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=20170608232123.28366-2-sthemmin@microsoft.com \
--to=stephen@networkplumber$(echo .)org \
--cc=devel@linuxdriverproject$(echo .)org \
--cc=haiyangz@microsoft$(echo .)com \
--cc=kys@microsoft$(echo .)com \
--cc=netdev@vger$(echo .)kernel.org \
--cc=sthemmin@microsoft$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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