From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 95120A04A4; Wed, 2 Mar 2022 10:41:30 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5F75D42715; Wed, 2 Mar 2022 10:41:30 +0100 (CET) Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by mails.dpdk.org (Postfix) with ESMTP id 3DDB040141 for ; Wed, 2 Mar 2022 10:41:29 +0100 (CET) Received: by mail-pf1-f179.google.com with SMTP id g1so1444636pfv.1 for ; Wed, 02 Mar 2022 01:41:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=l1lyYlhGUK203LlMh/3c5xnY7SCy0nU+EuYeHF8MVBo=; b=ASUZiwNgC5u9l0lovEwu/Pyn2uZDB8VsA0cxNlYAeUr3Shyeu3jM7HEXbUuGW2ej5/ 2dleVwY2qCIvlNmO7pjiv2oWgjIl2wuMHEGGkOlK0l3SNYjNWQdZ/kwlGSNHPTBP2PFf fu3gLWHMwzRuXGkhKhXjzN2Itzy2WX1CL7K4jkxPaedVjyWvSIfolL1ndTKzk84Bfs2o zxW09qALNz9IZK6fk2OPBJzHW/l1v77OSrB9VcuDNoii8eHZKauVFjPyMClgw+rJqXzR mbW4jT8lQBcuQssDCNHBt+TX6hBrCBy1NLXL8+KXWHcxW+fAiZB6zILDzcetXCsneIsG anjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=l1lyYlhGUK203LlMh/3c5xnY7SCy0nU+EuYeHF8MVBo=; b=DGAnhi7JmDoRpIKcAz0Z0xe/1WULobMW/Tk4e7aV1Kl7QDH9JVnEXUPQ+bOddEss3V wFRexMjfT1lDH5JbOdbsGnzOrSAOF0meirAsclcb3yCWlcTkoxNeuuje8P8u78gSK6Ng GBoh3c32ZaU4ltu07dDooZD1/Ib6ypeVZzavIWtuT/kkhCgvsb20kneIambsP4ntwd9s qr5YSe1k4R8Ag6YN9NuPzcCPdr/KQCavu1UwJQIfCEkh+dp5BH2pAQ0fcY4t6rDg3mqB YEvxcY1tKhhr4R4Yign9YYZVhO+YNGXqIQY6uugrfj/hSOuxeWAkOvNdMGQ+5KGJ24PC t3jQ== X-Gm-Message-State: AOAM531GPNSUGtL7ZnvEWPiT8gtDin1rBtn4JtAhctbWw0mn6BWjzsim WyytF10jyBxQ21CIMDTTS1EBejIVSQ6Vx9Pf X-Google-Smtp-Source: ABdhPJw6drQ9hL2HWK80X/Hd4RFc6fMW6Sbgn5udpdoy+dD9tWwUxpx7itvTjSX3bgUyWaNSGcQfOw== X-Received: by 2002:a63:2204:0:b0:378:9f08:206d with SMTP id i4-20020a632204000000b003789f08206dmr12868308pgi.3.1646214088211; Wed, 02 Mar 2022 01:41:28 -0800 (PST) Received: from localhost.localdomain ([157.255.44.216]) by smtp.gmail.com with ESMTPSA id oo16-20020a17090b1c9000b001b89e05e2b2sm4862606pjb.34.2022.03.02.01.41.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 01:41:27 -0800 (PST) From: Harold Huang To: dev@dpdk.org Cc: Harold Huang , Maxime Coquelin , Chenbo Xia Subject: [PATCH] net/virtio: support NAPI when using vhost_net backend Date: Wed, 2 Mar 2022 17:41:05 +0800 Message-Id: <20220302094105.148523-1-baymaxhuang@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org In patch [1], NAPI has been supported in kernel tun driver to accelerate packet processing received from vhost_net. This will greatly improve the throughput of the tap device in the vhost_net backend. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=fb3f903769e8 Signed-off-by: Harold Huang --- drivers/net/virtio/virtio_user/vhost_kernel.c | 9 +++++++-- drivers/net/virtio/virtio_user/vhost_kernel_tap.c | 4 ++-- drivers/net/virtio/virtio_user/vhost_kernel_tap.h | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/net/virtio/virtio_user/vhost_kernel.c b/drivers/net/virtio/virtio_user/vhost_kernel.c index 202a8cdee1..986b56a7ca 100644 --- a/drivers/net/virtio/virtio_user/vhost_kernel.c +++ b/drivers/net/virtio/virtio_user/vhost_kernel.c @@ -383,6 +383,7 @@ vhost_kernel_setup(struct virtio_user_dev *dev) struct vhost_kernel_data *data; unsigned int tap_features; unsigned int tap_flags; + unsigned int r_flags; const char *ifname; uint32_t q, i; int vhostfd; @@ -394,6 +395,10 @@ vhost_kernel_setup(struct virtio_user_dev *dev) PMD_INIT_LOG(ERR, "TAP does not support IFF_VNET_HDR"); return -1; } + r_flags = IFF_TAP | IFF_NO_PI | IFF_VNET_HDR; + + if (tap_features & IFF_NAPI) + r_flags |= IFF_NAPI; data = malloc(sizeof(*data)); if (!data) { @@ -429,7 +434,7 @@ vhost_kernel_setup(struct virtio_user_dev *dev) } ifname = dev->ifname != NULL ? dev->ifname : "tap%d"; - data->tapfds[0] = tap_open(ifname, (tap_features & IFF_MULTI_QUEUE) != 0); + data->tapfds[0] = tap_open(ifname, r_flags, (tap_features & IFF_MULTI_QUEUE) != 0); if (data->tapfds[0] < 0) goto err_tapfds; if (dev->ifname == NULL && tap_get_name(data->tapfds[0], &dev->ifname) < 0) { @@ -446,7 +451,7 @@ vhost_kernel_setup(struct virtio_user_dev *dev) } for (i = 1; i < dev->max_queue_pairs; i++) { - data->tapfds[i] = tap_open(dev->ifname, true); + data->tapfds[i] = tap_open(dev->ifname, r_flags, true); if (data->tapfds[i] < 0) goto err_tapfds; } diff --git a/drivers/net/virtio/virtio_user/vhost_kernel_tap.c b/drivers/net/virtio/virtio_user/vhost_kernel_tap.c index 2aac4028bb..611e2e25ec 100644 --- a/drivers/net/virtio/virtio_user/vhost_kernel_tap.c +++ b/drivers/net/virtio/virtio_user/vhost_kernel_tap.c @@ -42,7 +42,7 @@ tap_support_features(unsigned int *tap_features) } int -tap_open(const char *ifname, bool multi_queue) +tap_open(const char *ifname, unsigned int r_flags, bool multi_queue) { struct ifreq ifr; int tapfd; @@ -61,7 +61,7 @@ tap_open(const char *ifname, bool multi_queue) retry_mono_q: memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, ifname, IFNAMSIZ - 1); - ifr.ifr_flags = IFF_TAP | IFF_NO_PI | IFF_VNET_HDR; + ifr.ifr_flags = r_flags; if (multi_queue) ifr.ifr_flags |= IFF_MULTI_QUEUE; if (ioctl(tapfd, TUNSETIFF, (void *)&ifr) == -1) { diff --git a/drivers/net/virtio/virtio_user/vhost_kernel_tap.h b/drivers/net/virtio/virtio_user/vhost_kernel_tap.h index 726433c48c..636a0481be 100644 --- a/drivers/net/virtio/virtio_user/vhost_kernel_tap.h +++ b/drivers/net/virtio/virtio_user/vhost_kernel_tap.h @@ -22,6 +22,7 @@ #define IFF_NO_PI 0x1000 #define IFF_VNET_HDR 0x4000 #define IFF_MULTI_QUEUE 0x0100 +#define IFF_NAPI 0x0010 /* Features for GSO (TUNSETOFFLOAD). */ #define TUN_F_CSUM 0x01 /* You can hand me unchecksummed packets. */ @@ -36,7 +37,7 @@ int vhost_kernel_tap_setup(int tapfd, int hdr_size, uint64_t features); int tap_support_features(unsigned int *tap_features); -int tap_open(const char *ifname, bool multi_queue); +int tap_open(const char *ifname, unsigned int r_flags, bool multi_queue); int tap_get_name(int tapfd, char **ifname); int tap_get_flags(int tapfd, unsigned int *tap_flags); int tap_set_mac(int tapfd, uint8_t *mac); -- 2.27.0