netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: davem@davemloft.net, kys@microsoft.com
Cc: netdev@vger.kernel.org, Stephen Hemminger <sthemmin@microsoft.com>
Subject: [PATCH 15/18] netvsc: account for packets/bytes transmitted after completion
Date: Tue, 24 Jan 2017 13:06:12 -0800	[thread overview]
Message-ID: <20170124210615.18628-16-sthemmin@microsoft.com> (raw)
In-Reply-To: <20170124210615.18628-1-sthemmin@microsoft.com>

Most drivers do not increment transmit statistics until after the
transmit is completed. This will also be necessary for BQL support.

Slight additional complexity because the netvsc driver aggregates
multiple packets into one transmit.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
---
 drivers/net/hyperv/hyperv_net.h |  4 +++-
 drivers/net/hyperv/netvsc.c     | 19 ++++++++++++++++---
 drivers/net/hyperv/netvsc_drv.c | 13 +++----------
 3 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index fec365241f37..340f64233e2a 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -137,8 +137,10 @@ struct hv_netvsc_packet {
 	u8 page_buf_cnt;
 
 	u16 q_idx;
-	u32 send_buf_index;
+	u16 total_packets;
 
+	u32 total_bytes;
+	u32 send_buf_index;
 	u32 total_data_buflen;
 };
 
diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index bd055146f098..397aa1d88a6f 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -611,15 +611,23 @@ static void netvsc_send_tx_complete(struct netvsc_device *net_device,
 
 	/* Notify the layer above us */
 	if (likely(skb)) {
-		struct hv_netvsc_packet *nvsc_packet
+		const struct hv_netvsc_packet *packet
 			= (struct hv_netvsc_packet *)skb->cb;
-		u32 send_index = nvsc_packet->send_buf_index;
+		u32 send_index = packet->send_buf_index;
+		struct netvsc_stats *tx_stats;
 
 		if (send_index != NETVSC_INVALID_INDEX)
 			netvsc_free_send_slot(net_device, send_index);
-		q_idx = nvsc_packet->q_idx;
+		q_idx = packet->q_idx;
 		channel = incoming_channel;
 
+		tx_stats = this_cpu_ptr(net_device_ctx->tx_stats);
+
+		u64_stats_update_begin(&tx_stats->syncp);
+		tx_stats->packets += packet->total_packets;
+		tx_stats->bytes += packet->total_bytes;
+		u64_stats_update_end(&tx_stats->syncp);
+
 		dev_consume_skb_any(skb);
 	}
 
@@ -924,6 +932,11 @@ int netvsc_send(struct hv_device *device,
 			packet->total_data_buflen += msd_len;
 		}
 
+		if (msdp->pkt) {
+			packet->total_packets += msdp->pkt->total_packets;
+			packet->total_bytes += msdp->pkt->total_bytes;
+		}
+
 		if (msdp->skb)
 			dev_consume_skb_any(msdp->skb);
 
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 11755783c2f6..1dd13da79f02 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -364,7 +364,6 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
 	u32 rndis_msg_size;
 	struct rndis_per_packet_info *ppi;
 	u32 hash;
-	u32 skb_length;
 	struct hv_page_buffer page_buf[MAX_PAGE_BUFFER_COUNT];
 	struct hv_page_buffer *pb = page_buf;
 
@@ -374,7 +373,6 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
 	 * more pages we try linearizing it.
 	 */
 
-	skb_length = skb->len;
 	num_data_pgs = netvsc_get_slots(skb) + 2;
 
 	if (unlikely(num_data_pgs > MAX_PAGE_BUFFER_COUNT)) {
@@ -407,6 +405,8 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
 	packet->q_idx = skb_get_queue_mapping(skb);
 
 	packet->total_data_buflen = skb->len;
+	packet->total_bytes = skb->len;
+	packet->total_packets = 1;
 
 	rndis_msg = (struct rndis_message *)skb->head;
 
@@ -517,15 +517,8 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
 	skb_tx_timestamp(skb);
 	ret = netvsc_send(net_device_ctx->device_ctx, packet,
 			  rndis_msg, &pb, skb);
-	if (likely(ret == 0)) {
-		struct netvsc_stats *tx_stats = this_cpu_ptr(net_device_ctx->tx_stats);
-
-		u64_stats_update_begin(&tx_stats->syncp);
-		tx_stats->packets++;
-		tx_stats->bytes += skb_length;
-		u64_stats_update_end(&tx_stats->syncp);
+	if (likely(ret == 0))
 		return NETDEV_TX_OK;
-	}
 
 	if (ret == -EAGAIN) {
 		++net_device_ctx->eth_stats.tx_busy;
-- 
2.11.0

  parent reply	other threads:[~2017-01-24 21:06 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-24 21:05 [PATCH net-next 00/18] netvsc driver enhancements for net-next Stephen Hemminger
2017-01-24 21:05 ` [PATCH 01/18] netvsc: remove no longer needed receive staging buffers Stephen Hemminger
2017-01-24 21:05 ` [PATCH 02/18] netvsc: negotiate checksum and segmentation parameters Stephen Hemminger
2017-01-24 21:06 ` [PATCH 03/18] netvsc: report number of rx queues in ethtool Stephen Hemminger
2017-01-24 21:06 ` [PATCH 04/18] netvsc: report rss field values Stephen Hemminger
2017-01-24 21:06 ` [PATCH 05/18] netvsc: add ethtool ops to get/set RSS key Stephen Hemminger
2017-01-24 21:06 ` [PATCH 06/18] netvsc: allow more flexible setting of number of channels Stephen Hemminger
2017-01-24 21:06 ` [PATCH 07/18] netvsc: allow get/set of RSS indirection table Stephen Hemminger
2017-01-24 21:06 ` [PATCH 08/18] netvsc: enhance transmit select_queue Stephen Hemminger
2017-01-24 21:06 ` [PATCH 09/18] netvsc: remove unused variables Stephen Hemminger
2017-01-24 21:06 ` [PATCH 10/18] netvsc: group all per-channel state together Stephen Hemminger
2017-01-24 21:06 ` [PATCH 11/18] netvsc: optimize receive path Stephen Hemminger
2017-01-24 21:06 ` [PATCH 12/18] netvsc: don't pass void * to internal device_add Stephen Hemminger
2017-01-24 21:06 ` [PATCH 13/18] netvsc: simplify rndis_filter_remove Stephen Hemminger
2017-01-24 21:06 ` [PATCH 14/18] netvsc: eliminate per-device outstanding send counter Stephen Hemminger
2017-01-24 21:06 ` Stephen Hemminger [this message]
2017-01-24 21:06 ` [PATCH 16/18] netvsc: report per-channel stats in ethtool statistics Stephen Hemminger
2017-01-24 21:06 ` [PATCH 17/18] netvsc: simplify get next send section Stephen Hemminger
2017-01-24 21:06 ` [PATCH 18/18] netvsc: call netif_receive_skb Stephen Hemminger
2017-01-24 22:39   ` Eric Dumazet
2017-01-24 23:00     ` Stephen Hemminger
2017-01-24 23:07       ` Eric Dumazet
2017-01-24 21:30 ` [PATCH net-next 00/18] netvsc driver enhancements for net-next David Miller
2017-01-24 22:00   ` Stephen Hemminger
2017-01-24 22:50   ` Stephen Hemminger

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=20170124210615.18628-16-sthemmin@microsoft.com \
    --to=stephen@networkplumber.org \
    --cc=davem@davemloft.net \
    --cc=kys@microsoft.com \
    --cc=netdev@vger.kernel.org \
    --cc=sthemmin@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).