All of lore.kernel.org
 help / color / mirror / Atom feed
From: Harold Huang <baymaxhuang@gmail.com>
To: dev@dpdk.org
Cc: Harold Huang <baymaxhuang@gmail.com>,
	Maxime Coquelin <maxime.coquelin@redhat.com>,
	Chenbo Xia <chenbo.xia@intel.com>
Subject: [PATCH] net/virtio: support NAPI when using vhost_net backend
Date: Wed,  2 Mar 2022 17:41:05 +0800	[thread overview]
Message-ID: <20220302094105.148523-1-baymaxhuang@gmail.com> (raw)

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

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


             reply	other threads:[~2022-03-02  9:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-02  9:41 Harold Huang [this message]
2022-05-05 14:00 ` [PATCH] net/virtio: support NAPI when using vhost_net backend Maxime Coquelin
2022-05-05 19:53 ` Maxime Coquelin

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=20220302094105.148523-1-baymaxhuang@gmail.com \
    --to=baymaxhuang@gmail.com \
    --cc=chenbo.xia@intel.com \
    --cc=dev@dpdk.org \
    --cc=maxime.coquelin@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.