DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jianfeng Tan <jianfeng.tan@intel.com>
To: dev@dpdk.org
Cc: yuanhan.liu@linux.intel.com, david.marchand@6wind.com,
	Jianfeng Tan <jianfeng.tan@intel.com>
Subject: [dpdk-dev] [PATCH 5/5] net/virtio-user: add lsc support with vhost-kernel adapter
Date: Fri,  3 Mar 2017 17:56:43 +0000	[thread overview]
Message-ID: <1488563803-87754-6-git-send-email-jianfeng.tan@intel.com> (raw)
In-Reply-To: <1488563803-87754-1-git-send-email-jianfeng.tan@intel.com>

To check the link status, we use inotify to check if the file
/sys/class/net/tapX/flags is modified.

Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
---
 drivers/net/virtio/virtio_ethdev.c               | 27 ++++++++++++++++--------
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 24 +++++++++++++++++++++
 drivers/net/virtio/virtio_user/virtio_user_dev.h |  2 ++
 drivers/net/virtio/virtio_user_ethdev.c          | 16 ++++++++++++++
 4 files changed, 60 insertions(+), 9 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 58b20eb..1069219 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1292,10 +1292,9 @@ virtio_configure_intr(struct rte_eth_dev *dev)
 		}
 	}
 
-	/* Re-register callback to update max_intr */
-	rte_intr_callback_unregister(dev->intr_handle,
-				     virtio_interrupt_handler,
-				     dev);
+	/* Temporarily register callback as rte_intr_enable will use max_intr of
+	 * intr_handle on intr_sources.
+	 */
 	rte_intr_callback_register(dev->intr_handle,
 				   virtio_interrupt_handler,
 				   dev);
@@ -1322,6 +1321,9 @@ virtio_configure_intr(struct rte_eth_dev *dev)
 		return -1;
 	}
 
+	rte_intr_callback_unregister(dev->intr_handle,
+				     virtio_interrupt_handler,
+				     dev);
 	return 0;
 }
 
@@ -1335,6 +1337,13 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 	struct rte_pci_device *pci_dev = NULL;
 	int ret;
 
+	/* Callback could have been registered by last initialization,
+	 * unregister it.
+	 */
+	rte_intr_callback_unregister(eth_dev->intr_handle,
+				     virtio_interrupt_handler,
+				     eth_dev);
+
 	/* Reset the device although not necessary at startup */
 	vtpci_reset(hw);
 
@@ -1436,6 +1445,11 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 			eth_dev->data->port_id, pci_dev->id.vendor_id,
 			pci_dev->id.device_id);
 
+	/* Setup interrupt callback */
+	if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
+		rte_intr_callback_register(eth_dev->intr_handle,
+			virtio_interrupt_handler, eth_dev);
+
 	return 0;
 }
 
@@ -1546,11 +1560,6 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 	if (ret < 0)
 		return ret;
 
-	/* Setup interrupt callback  */
-	if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
-		rte_intr_callback_register(eth_dev->intr_handle,
-			virtio_interrupt_handler, eth_dev);
-
 	return 0;
 }
 
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index 2d79818..a331c37 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -42,6 +42,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <sys/inotify.h>
 
 #include "vhost.h"
 #include "virtio_user_dev.h"
@@ -160,6 +161,24 @@ virtio_user_fill_intr_handle(struct virtio_user_dev *dev, uint8_t portid)
 	eth_dev->intr_handle->type = RTE_INTR_HANDLE_VDEV;
 	if (dev->vhostfd >= 0)
 		eth_dev->intr_handle->fd = dev->vhostfd;
+	else {
+		char path[PATH_MAX];
+
+		snprintf(path, PATH_MAX, "/sys/class/net/%s/flags", dev->ifname);
+
+		dev->fd_inotify = inotify_init1(IN_NONBLOCK);
+		if (dev->fd_inotify == -1)
+			return;
+
+		if (inotify_add_watch(dev->fd_inotify, path, IN_MODIFY) == -1) {
+			close(dev->fd_inotify);
+			dev->fd_inotify = -1;
+			return;
+		}
+
+		dev->fd_tap_flags = open(path, O_RDONLY);
+		eth_dev->intr_handle->fd = dev->fd_inotify;
+	}
 }
 
 int
@@ -219,6 +238,11 @@ int virtio_user_stop_device(struct virtio_user_dev *dev)
 	for (i = 0; i < dev->max_queue_pairs; ++i)
 		dev->ops->enable_qp(dev, i, 0);
 
+	if (dev->fd_inotify >= 0)
+		close(dev->fd_inotify);
+	if (dev->fd_tap_flags >= 0)
+		close(dev->fd_tap_flags);
+
 	free(dev->ifname);
 	dev->ifname = NULL;
 
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h
index 3b529f0..dba8254 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.h
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h
@@ -47,6 +47,8 @@ struct virtio_user_dev {
 	char		*ifname;
 	int		*vhostfds;
 	int		*tapfds;
+	int		fd_inotify;
+	int		fd_tap_flags;
 
 	/* for both vhost_user and vhost_kernel */
 	int		callfds[VIRTIO_MAX_VIRTQUEUES * 2 + 1];
diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
index 14f4a5c..f2dd505 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -95,6 +95,22 @@ virtio_user_read_dev_config(struct virtio_hw *hw, size_t offset,
 				dev->status |= VIRTIO_NET_S_LINK_UP;
 			}
 			fcntl(dev->vhostfd, F_SETFL, flags & (~O_NONBLOCK));
+		} else {
+			uint64_t flags = 0;
+
+			while (read(dev->fd_inotify, buf, sizeof buf) > 0) {};
+
+			lseek(dev->fd_tap_flags, 0, SEEK_SET);
+			if (read(dev->fd_tap_flags, buf, 128) > 0) {
+				char *end;
+
+				flags = strtoll(buf, &end, 16);
+			}
+
+			if (flags & 1)
+				dev->status |= VIRTIO_NET_S_LINK_UP;
+			else
+				dev->status &= (~VIRTIO_NET_S_LINK_UP);
 		}
 		*(uint16_t *)dst = dev->status;
 	}
-- 
2.7.4

  parent reply	other threads:[~2017-03-03 17:56 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-03 17:56 [dpdk-dev] [PATCH 0/5] add LSC and Rxq interrupt for virtio-user Jianfeng Tan
2017-03-03 17:56 ` [dpdk-dev] [PATCH 1/5] eal/linux: add interrupt type for vdev Jianfeng Tan
2017-03-03 17:56 ` [dpdk-dev] [PATCH 2/5] net/virtio-user: add rxq interrupt mode support Jianfeng Tan
2017-03-17  6:47   ` Yuanhan Liu
2017-03-28  1:33     ` Tan, Jianfeng
2017-03-03 17:56 ` [dpdk-dev] [PATCH 3/5] net/virtio-user: support to report net status Jianfeng Tan
2017-03-17  6:54   ` Yuanhan Liu
2017-03-27  7:46     ` Tan, Jianfeng
2017-03-29  6:33       ` Yuanhan Liu
2017-03-29  7:07         ` Tan, Jianfeng
2017-03-29  7:14           ` Yuanhan Liu
2017-03-29  7:48             ` Tan, Jianfeng
2017-03-29  8:00               ` Yuanhan Liu
2017-03-29  8:33                 ` Tan, Jianfeng
2017-03-29  8:36                   ` Yuanhan Liu
2017-03-30  3:14                     ` Tan, Jianfeng
2017-03-03 17:56 ` [dpdk-dev] [PATCH 4/5] net/virtio-user: add lsc support with vhost-user adapter Jianfeng Tan
2017-03-17  8:29   ` Yuanhan Liu
2017-03-27  1:51     ` Tan, Jianfeng
2017-03-03 17:56 ` Jianfeng Tan [this message]
2017-03-28  8:21 ` [dpdk-dev] [PATCH v2 0/5] add LSC and Rxq interrupt for virtio-user Jianfeng Tan
2017-03-28  8:21   ` [dpdk-dev] [PATCH v2 1/5] eal/linux: add interrupt type for vdev Jianfeng Tan
2017-03-28  8:21   ` [dpdk-dev] [PATCH v2 2/5] net/virtio: add interrupt configure " Jianfeng Tan
2017-03-29  6:27     ` Yuanhan Liu
2017-03-29  7:03       ` Tan, Jianfeng
2017-03-29  7:09         ` Yuanhan Liu
2017-03-29  7:27           ` Tan, Jianfeng
2017-03-29  7:30             ` Yuanhan Liu
2017-03-28  8:21   ` [dpdk-dev] [PATCH v2 3/5] net/virtio-user: add rxq interrupt mode support Jianfeng Tan
2017-03-28  8:21   ` [dpdk-dev] [PATCH v2 4/5] net/virtio-user: support to report net status Jianfeng Tan
2017-03-28  8:21   ` [dpdk-dev] [PATCH v2 5/5] net/virtio-user: add lsc support Jianfeng Tan
2017-03-31 19:44 ` [dpdk-dev] [PATCH v3 0/5] add LSC and Rxq interrupt for virtio-user Jianfeng Tan
2017-03-31 19:44   ` [dpdk-dev] [PATCH v3 1/5] eal/linux: add interrupt type for vdev Jianfeng Tan
2017-03-31 19:44   ` [dpdk-dev] [PATCH v3 2/5] net/virtio-user: move eventfd open/close into init/uninit Jianfeng Tan
2017-03-31 19:44   ` [dpdk-dev] [PATCH v3 3/5] net/virtio-user: add rxq interrupt mode support Jianfeng Tan
2017-03-31 19:44   ` [dpdk-dev] [PATCH v3 4/5] net/virtio-user: support to report net status Jianfeng Tan
2017-03-31 19:44   ` [dpdk-dev] [PATCH v3 5/5] net/virtio-user: add lsc support Jianfeng Tan
2017-04-01  5:13     ` Yuanhan Liu

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=1488563803-87754-6-git-send-email-jianfeng.tan@intel.com \
    --to=jianfeng.tan@intel.com \
    --cc=david.marchand@6wind.com \
    --cc=dev@dpdk.org \
    --cc=yuanhan.liu@linux.intel.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).