net/virtio: support NAPI when using vhost_net backend

Message ID 20220302094105.148523-1-baymaxhuang@gmail.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers
Series net/virtio: support NAPI when using vhost_net backend |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

Harold Huang March 2, 2022, 9:41 a.m. UTC
  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 <baymaxhuang@gmail.com>
---
 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(-)
  

Comments

Maxime Coquelin May 5, 2022, 2 p.m. UTC | #1
Hi Harold,

On 3/2/22 10:41, Harold Huang wrote:
> 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 <baymaxhuang@gmail.com>
> ---
>   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(-)
> 

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
  
Maxime Coquelin May 5, 2022, 7:53 p.m. UTC | #2
On 3/2/22 10:41, Harold Huang wrote:
> 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 <baymaxhuang@gmail.com>
> ---
>   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(-)
> 

Applied to dpdk-next-virtio/main.

Thanks,
Maxime
  

Patch

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