[dpdk-dev,2/5] net/virtio-user: add rxq interrupt mode support

Message ID 1488563803-87754-3-git-send-email-jianfeng.tan@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Yuanhan Liu
Headers

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK

Commit Message

Jianfeng Tan March 3, 2017, 5:56 p.m. UTC
  Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
---
 drivers/net/virtio/virtio_ethdev.c               | 17 ++++++++++++++--
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 25 +++++++++++++++++++++++-
 drivers/net/virtio/virtio_user/virtio_user_dev.h |  2 +-
 drivers/net/virtio/virtio_user_ethdev.c          | 12 +++++++++++-
 4 files changed, 51 insertions(+), 5 deletions(-)
  

Comments

Yuanhan Liu March 17, 2017, 6:47 a.m. UTC | #1
On Fri, Mar 03, 2017 at 05:56:40PM +0000, Jianfeng Tan wrote:
> Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>

I don't see a single word to explain how this patch works :/

> ---
>  drivers/net/virtio/virtio_ethdev.c               | 17 ++++++++++++++--
>  drivers/net/virtio/virtio_user/virtio_user_dev.c | 25 +++++++++++++++++++++++-
>  drivers/net/virtio/virtio_user/virtio_user_dev.h |  2 +-
>  drivers/net/virtio/virtio_user_ethdev.c          | 12 +++++++++++-
>  4 files changed, 51 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
> index 4dc03b9..5d80d1a 100644
> --- a/drivers/net/virtio/virtio_ethdev.c
> +++ b/drivers/net/virtio/virtio_ethdev.c
> @@ -1264,6 +1264,10 @@ virtio_configure_intr(struct rte_eth_dev *dev)
>  {
>  	struct virtio_hw *hw = dev->data->dev_private;
>  
> +
> +#ifdef RTE_VIRTIO_USER
> +        if (!hw->virtio_user_dev) {
> +#endif

No need to put the #ifdef block here. virtio_user_dev is defined even
when RTE_VIRTIO_USER is not configured.

...

> +	vtpci_reinit_complete(hw);
> +
>  	if (eth_dev->data->dev_conf.intr_conf.rxq) {
>  		if (virtio_configure_intr(eth_dev) < 0) {
>  			PMD_INIT_LOG(ERR, "failed to configure interrupt");
> @@ -1416,8 +1431,6 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
>  		}
>  	}
>  
> -	vtpci_reinit_complete(hw);


Hmm, why ...? Such stealthy change definitely need an explanation.
And it's more likely it needs a single patch.

	--yliu
  
Jianfeng Tan March 28, 2017, 1:33 a.m. UTC | #2
> -----Original Message-----
> From: Yuanhan Liu [mailto:yuanhan.liu@linux.intel.com]
> Sent: Friday, March 17, 2017 2:48 PM
> To: Tan, Jianfeng
> Cc: dev@dpdk.org; david.marchand@6wind.com
> Subject: Re: [PATCH 2/5] net/virtio-user: add rxq interrupt mode support
> 
> On Fri, Mar 03, 2017 at 05:56:40PM +0000, Jianfeng Tan wrote:
> > Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
> 
> I don't see a single word to explain how this patch works :/

Sorry, will add that in next version.

> 
> > ---
> >  drivers/net/virtio/virtio_ethdev.c               | 17 ++++++++++++++--
> >  drivers/net/virtio/virtio_user/virtio_user_dev.c | 25
> +++++++++++++++++++++++-
> >  drivers/net/virtio/virtio_user/virtio_user_dev.h |  2 +-
> >  drivers/net/virtio/virtio_user_ethdev.c          | 12 +++++++++++-
> >  4 files changed, 51 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/net/virtio/virtio_ethdev.c
> b/drivers/net/virtio/virtio_ethdev.c
> > index 4dc03b9..5d80d1a 100644
> > --- a/drivers/net/virtio/virtio_ethdev.c
> > +++ b/drivers/net/virtio/virtio_ethdev.c
> > @@ -1264,6 +1264,10 @@ virtio_configure_intr(struct rte_eth_dev *dev)
> >  {
> >  	struct virtio_hw *hw = dev->data->dev_private;
> >
> > +
> > +#ifdef RTE_VIRTIO_USER
> > +        if (!hw->virtio_user_dev) {
> > +#endif
> 
> No need to put the #ifdef block here. virtio_user_dev is defined even
> when RTE_VIRTIO_USER is not configured.

Correct. I'll remove that.

> 
> ...
> 
> > +	vtpci_reinit_complete(hw);
> > +
> >  	if (eth_dev->data->dev_conf.intr_conf.rxq) {
> >  		if (virtio_configure_intr(eth_dev) < 0) {
> >  			PMD_INIT_LOG(ERR, "failed to configure interrupt");
> > @@ -1416,8 +1431,6 @@ virtio_init_device(struct rte_eth_dev *eth_dev,
> uint64_t req_features)
> >  		}
> >  	}
> >
> > -	vtpci_reinit_complete(hw);
> 
> 
> Hmm, why ...? Such stealthy change definitely need an explanation.
> And it's more likely it needs a single patch.

I should have described it more. The reason of above change is to make sure intr_handle is filled in virtio_user_start_device(). But reconsidering this, this could have effect on virtio pci device as it requires interrupts are set up before setting DRIVER_OK. So how about:

1. configure intr for PCI devices;
2. vtpci_reinit_complete();
3. configure intr for vdev;

Thanks,
Jianfeng
  

Patch

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 4dc03b9..5d80d1a 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1264,6 +1264,10 @@  virtio_configure_intr(struct rte_eth_dev *dev)
 {
 	struct virtio_hw *hw = dev->data->dev_private;
 
+
+#ifdef RTE_VIRTIO_USER
+        if (!hw->virtio_user_dev) {
+#endif
 	if (!rte_intr_cap_multiple(dev->intr_handle)) {
 		PMD_INIT_LOG(ERR, "Multiple intr vector not supported");
 		return -ENOTSUP;
@@ -1273,6 +1277,9 @@  virtio_configure_intr(struct rte_eth_dev *dev)
 		PMD_INIT_LOG(ERR, "Fail to create eventfd");
 		return -1;
 	}
+#ifdef RTE_VIRTIO_USER
+	}
+#endif
 
 	if (!dev->intr_handle->intr_vec) {
 		dev->intr_handle->intr_vec =
@@ -1293,6 +1300,9 @@  virtio_configure_intr(struct rte_eth_dev *dev)
 				   virtio_interrupt_handler,
 				   dev);
 
+#ifdef RTE_VIRTIO_USER
+        if (!hw->virtio_user_dev) {
+#endif
 	/* DO NOT try to remove this! This function will enable msix, or QEMU
 	 * will encounter SIGSEGV when DRIVER_OK is sent.
 	 * And for legacy devices, this should be done before queue/vec binding
@@ -1303,6 +1313,9 @@  virtio_configure_intr(struct rte_eth_dev *dev)
 		PMD_DRV_LOG(ERR, "interrupt enable failed");
 		return -1;
 	}
+#ifdef RTE_VIRTIO_USER
+	}
+#endif
 
 	if (virtio_queues_bind_intr(dev) < 0) {
 		PMD_INIT_LOG(ERR, "Failed to bind queue/interrupt");
@@ -1409,6 +1422,8 @@  virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 	if (ret < 0)
 		return ret;
 
+	vtpci_reinit_complete(hw);
+
 	if (eth_dev->data->dev_conf.intr_conf.rxq) {
 		if (virtio_configure_intr(eth_dev) < 0) {
 			PMD_INIT_LOG(ERR, "failed to configure interrupt");
@@ -1416,8 +1431,6 @@  virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 		}
 	}
 
-	vtpci_reinit_complete(hw);
-
 	if (pci_dev)
 		PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x",
 			eth_dev->data->port_id, pci_dev->id.vendor_id,
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index 21ed00d..9777d6b 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -140,8 +140,28 @@  virtio_user_queue_setup(struct virtio_user_dev *dev,
 	return 0;
 }
 
+static void
+virtio_user_fill_intr_handle(struct virtio_user_dev *dev, uint8_t portid)
+{
+	uint32_t i;
+	struct rte_eth_dev *eth_dev = &rte_eth_devices[portid];
+
+	if (!eth_dev->intr_handle) {
+		eth_dev->intr_handle = malloc(sizeof(*eth_dev->intr_handle));
+		if (!eth_dev->intr_handle)
+			return;
+		memset(eth_dev->intr_handle, 0, sizeof(*eth_dev->intr_handle));
+	}
+
+	for (i = 0; i < dev->max_queue_pairs; ++i)
+		eth_dev->intr_handle->efds[i] = dev->callfds[i];
+	eth_dev->intr_handle->nb_efd = dev->max_queue_pairs;
+	eth_dev->intr_handle->max_intr = dev->max_queue_pairs + 1;
+	eth_dev->intr_handle->type = RTE_INTR_HANDLE_VDEV;
+}
+
 int
-virtio_user_start_device(struct virtio_user_dev *dev)
+virtio_user_start_device(struct virtio_user_dev *dev, uint8_t portid)
 {
 	uint64_t features;
 	int ret;
@@ -175,6 +195,9 @@  virtio_user_start_device(struct virtio_user_dev *dev)
 	 */
 	dev->ops->enable_qp(dev, 0, 1);
 
+	/* Step 5: prepare for interrupt mode */
+	virtio_user_fill_intr_handle(dev, portid);
+
 	return 0;
 error:
 	/* TODO: free resource here or caller to check */
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h
index 0d39f40..3b529f0 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.h
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h
@@ -66,7 +66,7 @@  struct virtio_user_dev {
 	struct virtio_user_backend_ops *ops;
 };
 
-int virtio_user_start_device(struct virtio_user_dev *dev);
+int virtio_user_start_device(struct virtio_user_dev *dev, uint8_t portid);
 int virtio_user_stop_device(struct virtio_user_dev *dev);
 int virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
 			 int cq, int queue_size, const char *mac);
diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
index 0b226ac..fa79419 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -101,7 +101,7 @@  virtio_user_set_status(struct virtio_hw *hw, uint8_t status)
 	struct virtio_user_dev *dev = virtio_user_get_dev(hw);
 
 	if (status & VIRTIO_CONFIG_STATUS_DRIVER_OK)
-		virtio_user_start_device(dev);
+		virtio_user_start_device(dev, hw->port_id);
 	else if (status == VIRTIO_CONFIG_STATUS_RESET)
 		virtio_user_reset(hw);
 	dev->status = status;
@@ -148,6 +148,15 @@  virtio_user_set_config_irq(struct virtio_hw *hw __rte_unused,
 	return VIRTIO_MSI_NO_VECTOR;
 }
 
+static uint16_t
+virtio_user_set_queue_irq(struct virtio_hw *hw __rte_unused,
+			  struct virtqueue *vq __rte_unused,
+			  uint16_t vec)
+{
+	/* pretend we have done that */
+	return vec;
+}
+
 /* This function is to get the queue size, aka, number of descs, of a specified
  * queue. Different with the VHOST_USER_GET_QUEUE_NUM, which is used to get the
  * max supported queues.
@@ -226,6 +235,7 @@  const struct virtio_pci_ops virtio_user_ops = {
 	.set_features	= virtio_user_set_features,
 	.get_isr	= virtio_user_get_isr,
 	.set_config_irq	= virtio_user_set_config_irq,
+	.set_queue_irq	= virtio_user_set_queue_irq,
 	.get_queue_num	= virtio_user_get_queue_num,
 	.setup_queue	= virtio_user_setup_queue,
 	.del_queue	= virtio_user_del_queue,