Development issues regarding the cerowrt test router project
 help / color / mirror / Atom feed
* [Cerowrt-devel] Fwd: [PATCH] tun: support NAPI to accelerate packet processing
       [not found] <20220224103852.311369-1-baymaxhuang@gmail.com>
@ 2022-02-25 12:25 ` Dave Taht
  0 siblings, 0 replies; only message in thread
From: Dave Taht @ 2022-02-25 12:25 UTC (permalink / raw)
  To: cerowrt-devel

really remarkable potential improvement in userspace vpn traffic

---------- Forwarded message ---------
From: Harold Huang <baymaxhuang@gmail.com>
Date: Thu, Feb 24, 2022 at 6:37 AM
Subject: [PATCH] tun: support NAPI to accelerate packet processing
To: <netdev@vger.kernel.org>
Cc: <jasowang@redhat.com>, Harold Huang <baymaxhuang@gmail.com>, David
S. Miller <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>,
open list <linux-kernel@vger.kernel.org>


In tun, NAPI is supported and we can also use NAPI in the path of
batched XDP buffs to accelerate packet processing. What is more, after
we use NPAI, GRO is also supported. The iperf shows that the throughput
could be improved from 4.5Gbsp to 9.2Gbps per stream.

Reported-at: https://lore.kernel.org/netdev/CAHJXk3Y9_Fh04sakMMbcAkef7kOTEc-kf84Ne3DtWD7EAp13cg@mail.gmail.com/T/#t
Signed-off-by: Harold Huang <baymaxhuang@gmail.com>
---
 drivers/net/tun.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index fed85447701a..4e1cea659b42 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -2388,6 +2388,7 @@ static int tun_xdp_one(struct tun_struct *tun,
        struct virtio_net_hdr *gso = &hdr->gso;
        struct bpf_prog *xdp_prog;
        struct sk_buff *skb = NULL;
+       struct sk_buff_head *queue;
        u32 rxhash = 0, act;
        int buflen = hdr->buflen;
        int err = 0;
@@ -2464,7 +2465,14 @@ static int tun_xdp_one(struct tun_struct *tun,
            !tfile->detached)
                rxhash = __skb_get_hash_symmetric(skb);

-       netif_receive_skb(skb);
+       if (tfile->napi_enabled) {
+               queue = &tfile->sk.sk_write_queue;
+               spin_lock(&queue->lock);
+               __skb_queue_tail(queue, skb);
+               spin_unlock(&queue->lock);
+       } else {
+               netif_receive_skb(skb);
+       }

        /* No need to disable preemption here since this function is
         * always called with bh disabled
@@ -2507,6 +2515,9 @@ static int tun_sendmsg(struct socket *sock,
struct msghdr *m, size_t total_len)
                if (flush)
                        xdp_do_flush();

+               if (tfile->napi_enabled)
+                       napi_schedule(&tfile->napi);
+
                rcu_read_unlock();
                local_bh_enable();

--
2.27.0



-- 
I tried to build a better future, a few times:
https://wayforward.archive.org/?site=https%3A%2F%2Fwww.icei.org

Dave Täht CEO, TekLibre, LLC

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-02-25 12:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20220224103852.311369-1-baymaxhuang@gmail.com>
2022-02-25 12:25 ` [Cerowrt-devel] Fwd: [PATCH] tun: support NAPI to accelerate packet processing Dave Taht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox