From: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
To: netdev@vger.kernel.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowang@redhat.com>,
"David S. Miller" <davem@davemloft.net>,
"Jakub Kicinski" <kuba@kernel.org>,
"Björn Töpel" <bjorn.topel@intel.com>,
"Magnus Karlsson" <magnus.karlsson@intel.com>,
"Jonathan Lemon" <jonathan.lemon@gmail.com>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Jesper Dangaard Brouer" <hawk@kernel.org>,
"John Fastabend" <john.fastabend@gmail.com>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Martin KaFai Lau" <kafai@fb.com>,
"Song Liu" <songliubraving@fb.com>, "Yonghong Song" <yhs@fb.com>,
"KP Singh" <kpsingh@kernel.org>,
virtualization@lists.linux-foundation.org, bpf@vger.kernel.org
Subject: [PATCH net-next v2 7/7] virtio-net, xsk: set xsk completed when packet sent done
Date: Sat, 16 Jan 2021 10:59:28 +0800 [thread overview]
Message-ID: <4949b7afe1420cfdedd890f77335fa9554f774cf.1610765285.git.xuanzhuo@linux.alibaba.com> (raw)
In-Reply-To: <cover.1610765285.git.xuanzhuo@linux.alibaba.com>
In-Reply-To: <cover.1610765285.git.xuanzhuo@linux.alibaba.com>
When recycling packets that have been sent, call xsk_tx_completed to
inform xsk which packets have been sent.
If necessary, start napi to process the packets in the xsk queue.
Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
---
drivers/net/virtio_net.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index e552c2d..d0d620b 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -1442,6 +1442,42 @@ static int virtnet_receive(struct receive_queue *rq, int budget,
return stats.packets;
}
+static void virt_xsk_complete(struct send_queue *sq, u32 num, bool xsk_wakeup)
+{
+ struct xsk_buff_pool *pool;
+ struct virtnet_xsk_hdr *hdr = NULL;
+ int n;
+
+ rcu_read_lock();
+
+ sq->xsk.hdr_pro += num;
+
+ pool = rcu_dereference(sq->xsk.pool);
+ if (!pool) {
+ if (sq->xsk.hdr_pro - sq->xsk.hdr_con == sq->xsk.hdr_n)
+ hdr = rcu_replace_pointer(sq->xsk.hdr, hdr, true);
+
+ rcu_read_unlock();
+
+ kfree(hdr);
+ return;
+ }
+
+ xsk_tx_completed(pool, num);
+
+ rcu_read_unlock();
+
+ if (!xsk_wakeup || !sq->xsk.wait_slot)
+ return;
+
+ n = sq->xsk.hdr_pro - sq->xsk.hdr_con;
+
+ if (n > sq->xsk.hdr_n / 2) {
+ sq->xsk.wait_slot = false;
+ virtqueue_napi_schedule(&sq->napi, sq->vq);
+ }
+}
+
static void __free_old_xmit_ptr(struct send_queue *sq, bool in_napi,
bool xsk_wakeup,
unsigned int *_packets, unsigned int *_bytes)
@@ -1449,6 +1485,7 @@ static void __free_old_xmit_ptr(struct send_queue *sq, bool in_napi,
unsigned int packets = 0;
unsigned int bytes = 0;
unsigned int len;
+ u64 xsknum = 0;
struct virtnet_xdp_type *xtype;
struct xdp_frame *frame;
struct virtnet_xsk_hdr *xskhdr;
@@ -1469,6 +1506,7 @@ static void __free_old_xmit_ptr(struct send_queue *sq, bool in_napi,
if (xtype->type == XDP_TYPE_XSK) {
xskhdr = (struct virtnet_xsk_hdr *)xtype;
bytes += xskhdr->len;
+ xsknum += 1;
} else {
frame = xtype_get_ptr(xtype);
xdp_return_frame(frame);
@@ -1478,6 +1516,9 @@ static void __free_old_xmit_ptr(struct send_queue *sq, bool in_napi,
packets++;
}
+ if (xsknum)
+ virt_xsk_complete(sq, xsknum, xsk_wakeup);
+
*_packets = packets;
*_bytes = bytes;
}
@@ -3044,10 +3085,13 @@ static void free_receive_page_frags(struct virtnet_info *vi)
static void free_unused_bufs(struct virtnet_info *vi)
{
void *buf;
+ u32 n;
int i;
+ struct send_queue *sq;
for (i = 0; i < vi->max_queue_pairs; i++) {
struct virtqueue *vq = vi->sq[i].vq;
+ sq = vi->sq + i;
while ((buf = virtqueue_detach_unused_buf(vq)) != NULL) {
if (!is_xdp_frame(buf)) {
dev_kfree_skb(buf);
@@ -3060,6 +3104,11 @@ static void free_unused_bufs(struct virtnet_info *vi)
xdp_return_frame(xtype_get_ptr(xtype));
}
}
+
+ n = sq->xsk.hdr_con + sq->xsk.hdr_n;
+ n -= sq->xsk.hdr_pro;
+ if (n)
+ virt_xsk_complete(sq, n, false);
}
for (i = 0; i < vi->max_queue_pairs; i++) {
--
1.8.3.1
next prev parent reply other threads:[~2021-01-16 3:01 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-05 9:11 [PATCH netdev 0/5] virtio-net support xdp socket zero copy xmit Xuan Zhuo
2021-01-05 9:11 ` [PATCH netdev 1/5] xsk: support get page for drv Xuan Zhuo
2021-01-05 9:11 ` [PATCH netdev 2/5] virtio-net: support XDP_TX when not more queues Xuan Zhuo
2021-01-05 9:11 ` [PATCH netdev 3/5] virtio-net, xsk: distinguish XDP_TX and XSK XMIT ctx Xuan Zhuo
2021-01-05 9:11 ` [PATCH netdev 4/5] xsk, virtio-net: prepare for support xsk Xuan Zhuo
2021-01-05 9:11 ` [PATCH netdev 5/5] virtio-net, xsk: virtio-net support xsk zero copy tx Xuan Zhuo
2021-01-05 13:21 ` Michael S. Tsirkin
2021-01-05 9:32 ` [PATCH netdev 0/5] virtio-net support xdp socket zero copy xmit Jason Wang
2021-01-05 12:25 ` Michael S. Tsirkin
2021-01-16 2:59 ` [PATCH net-next v2 0/7] " Xuan Zhuo
2021-01-16 2:59 ` [PATCH net-next v2 1/7] xsk: support get page for drv Xuan Zhuo
2021-01-16 2:59 ` [PATCH net-next v2 2/7] virtio-net, xsk: distinguish XDP_TX and XSK XMIT ctx Xuan Zhuo
2021-01-18 6:45 ` Jason Wang
2021-01-16 2:59 ` [PATCH net-next v2 3/7] xsk, virtio-net: prepare for support xsk zerocopy xmit Xuan Zhuo
2021-01-16 2:59 ` [PATCH net-next v2 4/7] virtio-net, xsk: support xsk enable/disable Xuan Zhuo
2021-01-16 2:59 ` [PATCH net-next v2 5/7] virtio-net, xsk: realize the function of xsk packet sending Xuan Zhuo
2021-01-16 4:47 ` Jakub Kicinski
2021-01-18 9:10 ` Jason Wang
2021-01-18 12:27 ` Michael S. Tsirkin
2021-01-16 2:59 ` [PATCH net-next v2 6/7] virtio-net, xsk: implement xsk wakeup callback Xuan Zhuo
2021-01-19 4:50 ` Jason Wang
2021-01-16 2:59 ` Xuan Zhuo [this message]
2021-01-18 6:28 ` [PATCH net-next v2 0/7] virtio-net support xdp socket zero copy xmit Jason Wang
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=4949b7afe1420cfdedd890f77335fa9554f774cf.1610765285.git.xuanzhuo@linux.alibaba.com \
--to=xuanzhuo@linux.alibaba.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bjorn.topel@intel.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=hawk@kernel.org \
--cc=jasowang@redhat.com \
--cc=john.fastabend@gmail.com \
--cc=jonathan.lemon@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=magnus.karlsson@intel.com \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@fb.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=yhs@fb.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).