netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] virtio_net: Account for tx bytes and packets on sending xdp_frames
@ 2019-01-31 11:40 Toshiaki Makita
  2019-01-31 15:25 ` Michael S. Tsirkin
  2019-02-04  4:18 ` [PATCH net] virtio_net: Account for tx bytes and packets on sending xdp_frames David Miller
  0 siblings, 2 replies; 27+ messages in thread
From: Toshiaki Makita @ 2019-01-31 11:40 UTC (permalink / raw)
  To: David S. Miller, Michael S. Tsirkin, Jason Wang
  Cc: Toshiaki Makita, netdev, virtualization, David Ahern

Previously virtnet_xdp_xmit() did not account for device tx counters,
which caused confusions.
To be consistent with SKBs, account them on freeing xdp_frames.

Reported-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Toshiaki Makita <makita.toshiaki@lab.ntt.co.jp>
---
 drivers/net/virtio_net.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 2594481..4cfceb7 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -503,6 +503,8 @@ static int virtnet_xdp_xmit(struct net_device *dev,
 	struct bpf_prog *xdp_prog;
 	struct send_queue *sq;
 	unsigned int len;
+	int packets = 0;
+	int bytes = 0;
 	int drops = 0;
 	int kicks = 0;
 	int ret, err;
@@ -526,10 +528,18 @@ static int virtnet_xdp_xmit(struct net_device *dev,
 
 	/* Free up any pending old buffers before queueing new ones. */
 	while ((ptr = virtqueue_get_buf(sq->vq, &len)) != NULL) {
-		if (likely(is_xdp_frame(ptr)))
-			xdp_return_frame(ptr_to_xdp(ptr));
-		else
-			napi_consume_skb(ptr, false);
+		if (likely(is_xdp_frame(ptr))) {
+			struct xdp_frame *frame = ptr_to_xdp(ptr);
+
+			bytes += frame->len;
+			xdp_return_frame(frame);
+		} else {
+			struct sk_buff *skb = ptr;
+
+			bytes += skb->len;
+			napi_consume_skb(skb, false);
+		}
+		packets++;
 	}
 
 	for (i = 0; i < n; i++) {
@@ -549,6 +559,8 @@ static int virtnet_xdp_xmit(struct net_device *dev,
 	}
 out:
 	u64_stats_update_begin(&sq->stats.syncp);
+	sq->stats.bytes += bytes;
+	sq->stats.packets += packets;
 	sq->stats.xdp_tx += n;
 	sq->stats.xdp_tx_drops += drops;
 	sq->stats.kicks += kicks;
-- 
1.8.3.1



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

end of thread, other threads:[~2019-06-21 13:57 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-31 11:40 [PATCH net] virtio_net: Account for tx bytes and packets on sending xdp_frames Toshiaki Makita
2019-01-31 15:25 ` Michael S. Tsirkin
2019-01-31 17:45   ` David Miller
2019-01-31 20:15     ` Jesper Dangaard Brouer
2019-02-01  1:53       ` Toshiaki Makita
2019-02-02 21:27       ` David Ahern
2019-02-04 11:53         ` Jesper Dangaard Brouer
2019-02-05  3:13           ` David Ahern
2019-02-06  0:06             ` Saeed Mahameed
2019-02-06 13:48               ` Jesper Dangaard Brouer
2019-02-06 15:52                 ` Jakub Kicinski
2019-02-07  7:48               ` Resource management for ndo_xdp_xmit (Was: [PATCH net] virtio_net: Account for tx bytes and packets on sending xdp_frames) Jesper Dangaard Brouer
2019-02-07 19:08                 ` Saeed Mahameed
2019-02-08 16:55                   ` Toke Høiland-Jørgensen
2019-02-08 22:49                     ` Saeed Mahameed
2019-02-08 23:17                   ` Saeed Mahameed
2019-02-09  0:18                     ` Saeed Mahameed
2019-02-09  2:05                       ` Jakub Kicinski
2019-02-09 16:56                         ` Toke Høiland-Jørgensen
2019-02-09 16:56                       ` Toke Høiland-Jørgensen
2019-02-08 16:02               ` [PATCH net] virtio_net: Account for tx bytes and packets on sending xdp_frames Jesper Dangaard Brouer
2019-04-18 14:24             ` Stats for XDP actions (was: Re: [PATCH net] virtio_net: Account for tx bytes and packets on sending xdp_frames) Toke Høiland-Jørgensen
2019-04-21  0:16               ` Stats for XDP actions David Ahern
2019-06-20 20:42                 ` Toke Høiland-Jørgensen
2019-06-21  0:42                   ` David Ahern
2019-06-21 13:57                     ` Toke Høiland-Jørgensen
2019-02-04  4:18 ` [PATCH net] virtio_net: Account for tx bytes and packets on sending xdp_frames David Miller

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).