All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vhost: add support for interrupt mode
@ 2018-02-22  9:59 Junjie Chen
  2018-03-29 14:37 ` [PATCH v2] " Junjie Chen
  0 siblings, 1 reply; 16+ messages in thread
From: Junjie Chen @ 2018-02-22  9:59 UTC (permalink / raw)
  To: mtetsuyah, yliu, maxime.coquelin, jianfeng.tan.intel.com; +Cc: dev, Junjie Chen

In some cases we want vhost dequeue work in interrupt mode to
release cpus to others when no data to transmit. So we install
interrupt handler of vhost device and interrupt vectors for each
rx queue when creating new backend according to vhost intrerupt
configuration. Thus, applications could register a epoll event fd
to associate rx queues with interrupt vectors.

Signed-off-by: Junjie Chen <junjie.j.chen@intel.com>
---
 drivers/net/vhost/rte_eth_vhost.c | 116 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 116 insertions(+)

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 4e541e3..f474235 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -552,12 +552,115 @@ update_queuing_status(struct rte_eth_dev *dev)
 }
 
 static int
+eth_rxq_intr_enable(struct rte_eth_dev *dev, uint16_t qid)
+{
+	struct rte_vhost_vring vring;
+	struct vhost_queue *vq;
+
+	vq = dev->data->rx_queues[qid];
+	if (!vq) {
+		RTE_LOG(ERR, PMD, "rxq%d is not setup", qid);
+		return -1;
+	}
+
+	rte_vhost_get_vhost_vring(vq->vid, qid << 1, &vring);
+	vring.avail->flags &= (~VRING_AVAIL_F_NO_INTERRUPT);
+	rte_wmb();
+
+	return 0;
+}
+
+static int
+eth_rxq_intr_disable(struct rte_eth_dev *dev, uint16_t qid)
+{
+	struct rte_vhost_vring vring;
+	struct vhost_queue *vq;
+
+	vq = dev->data->rx_queues[qid];
+	if (!vq) {
+		RTE_LOG(ERR, PMD, "rxq%d is not setup", qid);
+		return -1;
+	}
+
+	rte_vhost_get_vhost_vring(vq->vid, qid << 1, &vring);
+	vring.avail->flags |= VRING_AVAIL_F_NO_INTERRUPT;
+	rte_wmb();
+
+	return 0;
+}
+
+static void
+eth_vhost_uninstall_intr(struct rte_eth_dev *dev)
+{
+	struct rte_intr_handle *intr_handle = dev->intr_handle;
+
+	if (intr_handle) {
+		if (intr_handle->intr_vec)
+			free(intr_handle->intr_vec);
+		free(intr_handle);
+	}
+
+	dev->intr_handle = NULL;
+}
+
+static int
+eth_vhost_install_intr(struct rte_eth_dev *dev)
+{
+	struct rte_vhost_vring vring;
+	struct vhost_queue *vq;
+	int count = 0;
+	int nb_rxq = dev->data->nb_rx_queues;
+	int i;
+	int ret;
+
+	/* uninstall firstly if we are reconnecting */
+	if (dev->intr_handle)
+		eth_vhost_uninstall_intr(dev);
+
+	dev->intr_handle = malloc(sizeof(*dev->intr_handle));
+	if (!dev->intr_handle) {
+		RTE_LOG(ERR, PMD, "fail to allocate intr_handle");
+		return -ENOMEM;
+	}
+	memset(dev->intr_handle, 0, sizeof(*dev->intr_handle));
+
+	dev->intr_handle->intr_vec =
+		malloc(nb_rxq * sizeof(dev->intr_handle->intr_vec[0]));
+
+	if (!dev->intr_handle->intr_vec) {
+		RTE_LOG(ERR, PMD,
+			"failed to allocate memory for interrupt vector");
+		return -ENOMEM;
+	}
+
+	for (i = 0; i < nb_rxq; i++) {
+		vq = dev->data->rx_queues[i];
+		if (!vq)
+			continue;
+		ret = rte_vhost_get_vhost_vring(vq->vid, i << 1, &vring);
+		if (ret < 0)
+			continue;
+		RTE_LOG(INFO, PMD, "install intr vec for rxq%d", i);
+		dev->intr_handle->intr_vec[i] = RTE_INTR_VEC_RXTX_OFFSET + i;
+		dev->intr_handle->efds[i] = vring.callfd;
+		count++;
+	}
+
+	dev->intr_handle->nb_efd = count;
+	dev->intr_handle->max_intr = count + 1;
+	dev->intr_handle->type = RTE_INTR_HANDLE_VDEV;
+
+	return 0;
+}
+
+static int
 new_device(int vid)
 {
 	struct rte_eth_dev *eth_dev;
 	struct internal_list *list;
 	struct pmd_internal *internal;
 	struct vhost_queue *vq;
+	struct rte_eth_conf *dev_conf;
 	unsigned i;
 	char ifname[PATH_MAX];
 #ifdef RTE_LIBRTE_VHOST_NUMA
@@ -609,6 +712,15 @@ new_device(int vid)
 
 	RTE_LOG(INFO, PMD, "New connection established\n");
 
+	dev_conf = &eth_dev->data->dev_conf;
+
+	if (dev_conf->intr_conf.rxq) {
+		if (eth_vhost_install_intr(eth_dev) < 0) {
+			RTE_LOG(INFO, PMD, "Failed to prepare intr handler.");
+			return -1;
+		}
+	}
+
 	_rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_INTR_LSC, NULL);
 
 	return 0;
@@ -663,6 +775,8 @@ destroy_device(int vid)
 
 	RTE_LOG(INFO, PMD, "Connection closed\n");
 
+	eth_vhost_uninstall_intr(eth_dev);
+
 	_rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_INTR_LSC, NULL);
 }
 
@@ -1007,6 +1121,8 @@ static const struct eth_dev_ops ops = {
 	.xstats_reset = vhost_dev_xstats_reset,
 	.xstats_get = vhost_dev_xstats_get,
 	.xstats_get_names = vhost_dev_xstats_get_names,
+	.rx_queue_intr_enable = eth_rxq_intr_enable,
+	.rx_queue_intr_disable = eth_rxq_intr_disable,
 };
 
 static struct rte_vdev_driver pmd_vhost_drv;
-- 
2.0.1

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2018-04-19 14:55 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-22  9:59 [PATCH] vhost: add support for interrupt mode Junjie Chen
2018-03-29 14:37 ` [PATCH v2] " Junjie Chen
2018-03-31  4:00   ` Tan, Jianfeng
2018-04-02  8:51     ` Chen, Junjie J
2018-04-03 16:33   ` [PATCH v3] " Junjie Chen
2018-04-04  9:43     ` [PATCH v4] " Junjie Chen
2018-04-08 16:50       ` [PATCH v5] " Junjie Chen
2018-04-12 16:28         ` [PATCH v6 1/2] " Junjie Chen
2018-04-12 12:18           ` Tan, Jianfeng
2018-04-13  9:15           ` Maxime Coquelin
2018-04-13 10:07             ` Chen, Junjie J
2018-04-12 16:29         ` [PATCH v6 2/2] net/vhost: update license to SPDX format Junjie Chen
2018-04-12 16:43         ` Junjie Chen
2018-04-12 12:21           ` Maxime Coquelin
2018-04-19  1:07           ` Takanari Hayama
2018-04-19 14:55             ` Maxime Coquelin

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.