DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] vhost: support rx_queue_count
@ 2017-05-22 20:01 Zhihong Wang
  2017-05-23 11:53 ` Jens Freimann
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Zhihong Wang @ 2017-05-22 20:01 UTC (permalink / raw)
  To: dev; +Cc: yuanhan.liu, Zhihong Wang

This patch implements the ops rx_queue_count for vhost PMD by adding
a helper function rte_vhost_rx_queue_count in vhost lib.

The ops ops rx_queue_count gets vhost RX queue avail count and helps
to understand the queue fill level.

Signed-off-by: Zhihong Wang <zhihong.wang@intel.com>
---
 drivers/net/vhost/rte_eth_vhost.c      | 13 +++++++++++++
 lib/librte_vhost/rte_vhost.h           | 12 ++++++++++++
 lib/librte_vhost/rte_vhost_version.map |  7 +++++++
 lib/librte_vhost/vhost.c               | 23 +++++++++++++++++++++++
 4 files changed, 55 insertions(+)

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 257bf6d..e3a3fe0 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -973,6 +973,18 @@ eth_link_update(struct rte_eth_dev *dev __rte_unused,
 	return 0;
 }
 
+static uint32_t
+eth_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
+{
+	struct vhost_queue *vq;
+
+	vq = dev->data->rx_queues[rx_queue_id];
+	if (!vq)
+		return 0;
+
+	return rte_vhost_rx_queue_count(vq->vid, vq->virtqueue_id);
+}
+
 static const struct eth_dev_ops ops = {
 	.dev_start = eth_dev_start,
 	.dev_stop = eth_dev_stop,
@@ -984,6 +996,7 @@ static const struct eth_dev_ops ops = {
 	.rx_queue_release = eth_queue_release,
 	.tx_queue_release = eth_queue_release,
 	.tx_done_cleanup = eth_tx_done_cleanup,
+	.rx_queue_count = eth_rx_queue_count,
 	.link_update = eth_link_update,
 	.stats_get = eth_stats_get,
 	.stats_reset = eth_stats_reset,
diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h
index 605e47c..f64ed20 100644
--- a/lib/librte_vhost/rte_vhost.h
+++ b/lib/librte_vhost/rte_vhost.h
@@ -432,6 +432,18 @@ int rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem);
 int rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx,
 			      struct rte_vhost_vring *vring);
 
+/**
+ * Get vhost RX queue avail count.
+ *
+ * @param vid
+ *  vhost device ID
+ * @param qid
+ *  virtio queue index in mq case
+ * @return
+ *  num of desc available
+ */
+uint32_t rte_vhost_rx_queue_count(int vid, uint16_t qid);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map
index 0785873..1e70495 100644
--- a/lib/librte_vhost/rte_vhost_version.map
+++ b/lib/librte_vhost/rte_vhost_version.map
@@ -45,3 +45,10 @@ DPDK_17.05 {
 	rte_vhost_log_write;
 
 } DPDK_16.07;
+
+DPDK_17.08 {
+	global:
+
+	rte_vhost_rx_queue_count;
+
+} DPDK_17.05;
diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index 0b19d2e..140d2ae 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -475,3 +475,26 @@ rte_vhost_log_used_vring(int vid, uint16_t vring_idx,
 
 	vhost_log_used_vring(dev, vq, offset, len);
 }
+
+uint32_t
+rte_vhost_rx_queue_count(int vid, uint16_t qid)
+{
+	struct virtio_net *dev;
+	struct vhost_virtqueue *vq;
+
+	dev = get_device(vid);
+	if (!dev)
+		return 0;
+
+	if (unlikely(qid >= dev->nr_vring || (qid & 1) == 0)) {
+		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
+			dev->vid, __func__, qid);
+		return 0;
+	}
+
+	vq = dev->virtqueue[qid];
+	if (unlikely(vq->enabled == 0))
+		return 0;
+
+	return *((volatile uint16_t *)&vq->avail->idx) - vq->last_avail_idx;
+}
-- 
2.7.4

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

* Re: [dpdk-dev] [PATCH] vhost: support rx_queue_count
  2017-05-22 20:01 [dpdk-dev] [PATCH] vhost: support rx_queue_count Zhihong Wang
@ 2017-05-23 11:53 ` Jens Freimann
  2017-05-23 12:51   ` Wang, Zhihong
  2017-05-23 13:10 ` Loftus, Ciara
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Jens Freimann @ 2017-05-23 11:53 UTC (permalink / raw)
  To: Zhihong Wang; +Cc: dev, yuanhan.liu

On Mon, May 22, 2017 at 04:01:08PM -0400, Zhihong Wang wrote:
> This patch implements the ops rx_queue_count for vhost PMD by adding
> a helper function rte_vhost_rx_queue_count in vhost lib.
> 
> The ops ops rx_queue_count gets vhost RX queue avail count and helps

s/ops ops/ops/ ?

> to understand the queue fill level.
> 
> Signed-off-by: Zhihong Wang <zhihong.wang@intel.com>
> ---
>  drivers/net/vhost/rte_eth_vhost.c      | 13 +++++++++++++
>  lib/librte_vhost/rte_vhost.h           | 12 ++++++++++++
>  lib/librte_vhost/rte_vhost_version.map |  7 +++++++
>  lib/librte_vhost/vhost.c               | 23 +++++++++++++++++++++++
>  4 files changed, 55 insertions(+)
> 
> diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
> index 257bf6d..e3a3fe0 100644
> --- a/drivers/net/vhost/rte_eth_vhost.c
> +++ b/drivers/net/vhost/rte_eth_vhost.c
> @@ -973,6 +973,18 @@ eth_link_update(struct rte_eth_dev *dev __rte_unused,
>  	return 0;
>  }
>  
> +static uint32_t
> +eth_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
> +{
> +	struct vhost_queue *vq;
> +
> +	vq = dev->data->rx_queues[rx_queue_id];
> +	if (!vq)

nitpick, but it should be "if (vq == NULL" according to the coding style guide

> +		return 0;
> +
> +	return rte_vhost_rx_queue_count(vq->vid, vq->virtqueue_id);
> +}
> +
>  static const struct eth_dev_ops ops = {
>  	.dev_start = eth_dev_start,
>  	.dev_stop = eth_dev_stop,
> @@ -984,6 +996,7 @@ static const struct eth_dev_ops ops = {
>  	.rx_queue_release = eth_queue_release,
>  	.tx_queue_release = eth_queue_release,
>  	.tx_done_cleanup = eth_tx_done_cleanup,
> +	.rx_queue_count = eth_rx_queue_count,
>  	.link_update = eth_link_update,
>  	.stats_get = eth_stats_get,
>  	.stats_reset = eth_stats_reset,
> diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h
> index 605e47c..f64ed20 100644
> --- a/lib/librte_vhost/rte_vhost.h
> +++ b/lib/librte_vhost/rte_vhost.h
> @@ -432,6 +432,18 @@ int rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem);
>  int rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx,
>  			      struct rte_vhost_vring *vring);
>  
> +/**
> + * Get vhost RX queue avail count.
> + *
> + * @param vid
> + *  vhost device ID
> + * @param qid
> + *  virtio queue index in mq case
> + * @return
> + *  num of desc available
> + */
> +uint32_t rte_vhost_rx_queue_count(int vid, uint16_t qid);
> +
>  #ifdef __cplusplus
>  }
>  #endif
> diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map
> index 0785873..1e70495 100644
> --- a/lib/librte_vhost/rte_vhost_version.map
> +++ b/lib/librte_vhost/rte_vhost_version.map
> @@ -45,3 +45,10 @@ DPDK_17.05 {
>  	rte_vhost_log_write;
>  
>  } DPDK_16.07;
> +
> +DPDK_17.08 {
> +	global:
> +
> +	rte_vhost_rx_queue_count;
> +
> +} DPDK_17.05;
> diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
> index 0b19d2e..140d2ae 100644
> --- a/lib/librte_vhost/vhost.c
> +++ b/lib/librte_vhost/vhost.c
> @@ -475,3 +475,26 @@ rte_vhost_log_used_vring(int vid, uint16_t vring_idx,
>  
>  	vhost_log_used_vring(dev, vq, offset, len);
>  }
> +
> +uint32_t
> +rte_vhost_rx_queue_count(int vid, uint16_t qid)
> +{
> +	struct virtio_net *dev;
> +	struct vhost_virtqueue *vq;
> +
> +	dev = get_device(vid);
> +	if (!dev)

same here

> +		return 0;
> +
> +	if (unlikely(qid >= dev->nr_vring || (qid & 1) == 0)) {
> +		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
> +			dev->vid, __func__, qid);
> +		return 0;
> +	}
> +
> +	vq = dev->virtqueue[qid];

check for vq == NULL?

regards,
Jens 

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

* Re: [dpdk-dev] [PATCH] vhost: support rx_queue_count
  2017-05-23 11:53 ` Jens Freimann
@ 2017-05-23 12:51   ` Wang, Zhihong
  2017-05-24  8:14     ` Yuanhan Liu
  0 siblings, 1 reply; 11+ messages in thread
From: Wang, Zhihong @ 2017-05-23 12:51 UTC (permalink / raw)
  To: Jens Freimann; +Cc: dev, yuanhan.liu



> -----Original Message-----
> From: Jens Freimann [mailto:jfreiman@redhat.com]
> Sent: Tuesday, May 23, 2017 7:54 PM
> To: Wang, Zhihong <zhihong.wang@intel.com>
> Cc: dev@dpdk.org; yuanhan.liu@linux.intel.com
> Subject: Re: [dpdk-dev] [PATCH] vhost: support rx_queue_count
> 
> On Mon, May 22, 2017 at 04:01:08PM -0400, Zhihong Wang wrote:
> > This patch implements the ops rx_queue_count for vhost PMD by adding
> > a helper function rte_vhost_rx_queue_count in vhost lib.
> >
> > The ops ops rx_queue_count gets vhost RX queue avail count and helps
> 
> s/ops ops/ops/ ?

Thanks a lot!

> 
> > to understand the queue fill level.
> >
> > Signed-off-by: Zhihong Wang <zhihong.wang@intel.com>
> > ---
> >  drivers/net/vhost/rte_eth_vhost.c      | 13 +++++++++++++
> >  lib/librte_vhost/rte_vhost.h           | 12 ++++++++++++
> >  lib/librte_vhost/rte_vhost_version.map |  7 +++++++
> >  lib/librte_vhost/vhost.c               | 23 +++++++++++++++++++++++
> >  4 files changed, 55 insertions(+)
> >
> > diff --git a/drivers/net/vhost/rte_eth_vhost.c
> b/drivers/net/vhost/rte_eth_vhost.c
> > index 257bf6d..e3a3fe0 100644
> > --- a/drivers/net/vhost/rte_eth_vhost.c
> > +++ b/drivers/net/vhost/rte_eth_vhost.c
> > @@ -973,6 +973,18 @@ eth_link_update(struct rte_eth_dev *dev
> __rte_unused,
> >  	return 0;
> >  }
> >
> > +static uint32_t
> > +eth_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
> > +{
> > +	struct vhost_queue *vq;
> > +
> > +	vq = dev->data->rx_queues[rx_queue_id];
> > +	if (!vq)
> 
> nitpick, but it should be "if (vq == NULL" according to the coding style guide
> 
> > +		return 0;
> > +
> > +	return rte_vhost_rx_queue_count(vq->vid, vq->virtqueue_id);
> > +}
> > +
> >  static const struct eth_dev_ops ops = {
> >  	.dev_start = eth_dev_start,
> >  	.dev_stop = eth_dev_stop,
> > @@ -984,6 +996,7 @@ static const struct eth_dev_ops ops = {
> >  	.rx_queue_release = eth_queue_release,
> >  	.tx_queue_release = eth_queue_release,
> >  	.tx_done_cleanup = eth_tx_done_cleanup,
> > +	.rx_queue_count = eth_rx_queue_count,
> >  	.link_update = eth_link_update,
> >  	.stats_get = eth_stats_get,
> >  	.stats_reset = eth_stats_reset,
> > diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h
> > index 605e47c..f64ed20 100644
> > --- a/lib/librte_vhost/rte_vhost.h
> > +++ b/lib/librte_vhost/rte_vhost.h
> > @@ -432,6 +432,18 @@ int rte_vhost_get_mem_table(int vid, struct
> rte_vhost_memory **mem);
> >  int rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx,
> >  			      struct rte_vhost_vring *vring);
> >
> > +/**
> > + * Get vhost RX queue avail count.
> > + *
> > + * @param vid
> > + *  vhost device ID
> > + * @param qid
> > + *  virtio queue index in mq case
> > + * @return
> > + *  num of desc available
> > + */
> > +uint32_t rte_vhost_rx_queue_count(int vid, uint16_t qid);
> > +
> >  #ifdef __cplusplus
> >  }
> >  #endif
> > diff --git a/lib/librte_vhost/rte_vhost_version.map
> b/lib/librte_vhost/rte_vhost_version.map
> > index 0785873..1e70495 100644
> > --- a/lib/librte_vhost/rte_vhost_version.map
> > +++ b/lib/librte_vhost/rte_vhost_version.map
> > @@ -45,3 +45,10 @@ DPDK_17.05 {
> >  	rte_vhost_log_write;
> >
> >  } DPDK_16.07;
> > +
> > +DPDK_17.08 {
> > +	global:
> > +
> > +	rte_vhost_rx_queue_count;
> > +
> > +} DPDK_17.05;
> > diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
> > index 0b19d2e..140d2ae 100644
> > --- a/lib/librte_vhost/vhost.c
> > +++ b/lib/librte_vhost/vhost.c
> > @@ -475,3 +475,26 @@ rte_vhost_log_used_vring(int vid, uint16_t
> vring_idx,
> >
> >  	vhost_log_used_vring(dev, vq, offset, len);
> >  }
> > +
> > +uint32_t
> > +rte_vhost_rx_queue_count(int vid, uint16_t qid)
> > +{
> > +	struct virtio_net *dev;
> > +	struct vhost_virtqueue *vq;
> > +
> > +	dev = get_device(vid);
> > +	if (!dev)
> 
> same here
> 
> > +		return 0;
> > +
> > +	if (unlikely(qid >= dev->nr_vring || (qid & 1) == 0)) {
> > +		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue
> idx %d.\n",
> > +			dev->vid, __func__, qid);
> > +		return 0;
> > +	}
> > +
> > +	vq = dev->virtqueue[qid];
> 
> check for vq == NULL?
> 
> regards,
> Jens

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

* Re: [dpdk-dev] [PATCH] vhost: support rx_queue_count
  2017-05-22 20:01 [dpdk-dev] [PATCH] vhost: support rx_queue_count Zhihong Wang
  2017-05-23 11:53 ` Jens Freimann
@ 2017-05-23 13:10 ` Loftus, Ciara
  2017-05-24  0:54 ` [dpdk-dev] [PATCH v2] " Zhihong Wang
  2017-05-26 17:18 ` [dpdk-dev] [PATCH v3] " Zhihong Wang
  3 siblings, 0 replies; 11+ messages in thread
From: Loftus, Ciara @ 2017-05-23 13:10 UTC (permalink / raw)
  To: Wang, Zhihong, dev; +Cc: yuanhan.liu, Wang, Zhihong

> 
> This patch implements the ops rx_queue_count for vhost PMD by adding
> a helper function rte_vhost_rx_queue_count in vhost lib.
> 
> The ops ops rx_queue_count gets vhost RX queue avail count and helps
> to understand the queue fill level.
> 
> Signed-off-by: Zhihong Wang <zhihong.wang@intel.com>
> ---
>  drivers/net/vhost/rte_eth_vhost.c      | 13 +++++++++++++
>  lib/librte_vhost/rte_vhost.h           | 12 ++++++++++++
>  lib/librte_vhost/rte_vhost_version.map |  7 +++++++
>  lib/librte_vhost/vhost.c               | 23 +++++++++++++++++++++++
>  4 files changed, 55 insertions(+)
> 
> diff --git a/drivers/net/vhost/rte_eth_vhost.c
> b/drivers/net/vhost/rte_eth_vhost.c
> index 257bf6d..e3a3fe0 100644
> --- a/drivers/net/vhost/rte_eth_vhost.c
> +++ b/drivers/net/vhost/rte_eth_vhost.c
> @@ -973,6 +973,18 @@ eth_link_update(struct rte_eth_dev *dev
> __rte_unused,
>  	return 0;
>  }
> 
> +static uint32_t
> +eth_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
> +{
> +	struct vhost_queue *vq;
> +
> +	vq = dev->data->rx_queues[rx_queue_id];
> +	if (!vq)
> +		return 0;
> +
> +	return rte_vhost_rx_queue_count(vq->vid, vq->virtqueue_id);
> +}
> +
>  static const struct eth_dev_ops ops = {
>  	.dev_start = eth_dev_start,
>  	.dev_stop = eth_dev_stop,
> @@ -984,6 +996,7 @@ static const struct eth_dev_ops ops = {
>  	.rx_queue_release = eth_queue_release,
>  	.tx_queue_release = eth_queue_release,
>  	.tx_done_cleanup = eth_tx_done_cleanup,
> +	.rx_queue_count = eth_rx_queue_count,
>  	.link_update = eth_link_update,
>  	.stats_get = eth_stats_get,
>  	.stats_reset = eth_stats_reset,
> diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h
> index 605e47c..f64ed20 100644
> --- a/lib/librte_vhost/rte_vhost.h
> +++ b/lib/librte_vhost/rte_vhost.h
> @@ -432,6 +432,18 @@ int rte_vhost_get_mem_table(int vid, struct
> rte_vhost_memory **mem);
>  int rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx,
>  			      struct rte_vhost_vring *vring);
> 
> +/**
> + * Get vhost RX queue avail count.
> + *
> + * @param vid
> + *  vhost device ID
> + * @param qid
> + *  virtio queue index in mq case
> + * @return
> + *  num of desc available
> + */
> +uint32_t rte_vhost_rx_queue_count(int vid, uint16_t qid);
> +
>  #ifdef __cplusplus
>  }
>  #endif
> diff --git a/lib/librte_vhost/rte_vhost_version.map
> b/lib/librte_vhost/rte_vhost_version.map
> index 0785873..1e70495 100644
> --- a/lib/librte_vhost/rte_vhost_version.map
> +++ b/lib/librte_vhost/rte_vhost_version.map
> @@ -45,3 +45,10 @@ DPDK_17.05 {
>  	rte_vhost_log_write;
> 
>  } DPDK_16.07;
> +
> +DPDK_17.08 {
> +	global:
> +
> +	rte_vhost_rx_queue_count;
> +
> +} DPDK_17.05;
> diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
> index 0b19d2e..140d2ae 100644
> --- a/lib/librte_vhost/vhost.c
> +++ b/lib/librte_vhost/vhost.c
> @@ -475,3 +475,26 @@ rte_vhost_log_used_vring(int vid, uint16_t
> vring_idx,
> 
>  	vhost_log_used_vring(dev, vq, offset, len);
>  }
> +
> +uint32_t
> +rte_vhost_rx_queue_count(int vid, uint16_t qid)
> +{
> +	struct virtio_net *dev;
> +	struct vhost_virtqueue *vq;
> +
> +	dev = get_device(vid);
> +	if (!dev)
> +		return 0;
> +
> +	if (unlikely(qid >= dev->nr_vring || (qid & 1) == 0)) {

I assume the '& 1' is to ensure it's a virtio txq? It might be clearer to use the VIRTIO_TXQ var or similar to make this clearer.

> +		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx
> %d.\n",
> +			dev->vid, __func__, qid);
> +		return 0;
> +	}
> +
> +	vq = dev->virtqueue[qid];
> +	if (unlikely(vq->enabled == 0))
> +		return 0;
> +
> +	return *((volatile uint16_t *)&vq->avail->idx) - vq->last_avail_idx;
> +}
> --
> 2.7.4


Acked-by: Ciara Loftus <ciara.loftus@intel.com>

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

* [dpdk-dev] [PATCH v2] vhost: support rx_queue_count
  2017-05-22 20:01 [dpdk-dev] [PATCH] vhost: support rx_queue_count Zhihong Wang
  2017-05-23 11:53 ` Jens Freimann
  2017-05-23 13:10 ` Loftus, Ciara
@ 2017-05-24  0:54 ` Zhihong Wang
  2017-05-26 17:18 ` [dpdk-dev] [PATCH v3] " Zhihong Wang
  3 siblings, 0 replies; 11+ messages in thread
From: Zhihong Wang @ 2017-05-24  0:54 UTC (permalink / raw)
  To: dev; +Cc: yuanhan.liu, jfreiman, Zhihong Wang

This patch implements the ops rx_queue_count for vhost PMD by adding
a helper function rte_vhost_rx_queue_count in vhost lib.

The ops rx_queue_count gets vhost RX queue avail count and helps to
understand the queue fill level.

Signed-off-by: Zhihong Wang <zhihong.wang@intel.com>
---
Changes in v2:

 1. Fixed a typo in commit log.

 drivers/net/vhost/rte_eth_vhost.c      | 13 +++++++++++++
 lib/librte_vhost/rte_vhost.h           | 12 ++++++++++++
 lib/librte_vhost/rte_vhost_version.map |  7 +++++++
 lib/librte_vhost/vhost.c               | 23 +++++++++++++++++++++++
 4 files changed, 55 insertions(+)

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 257bf6d..e3a3fe0 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -973,6 +973,18 @@ eth_link_update(struct rte_eth_dev *dev __rte_unused,
 	return 0;
 }
 
+static uint32_t
+eth_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
+{
+	struct vhost_queue *vq;
+
+	vq = dev->data->rx_queues[rx_queue_id];
+	if (!vq)
+		return 0;
+
+	return rte_vhost_rx_queue_count(vq->vid, vq->virtqueue_id);
+}
+
 static const struct eth_dev_ops ops = {
 	.dev_start = eth_dev_start,
 	.dev_stop = eth_dev_stop,
@@ -984,6 +996,7 @@ static const struct eth_dev_ops ops = {
 	.rx_queue_release = eth_queue_release,
 	.tx_queue_release = eth_queue_release,
 	.tx_done_cleanup = eth_tx_done_cleanup,
+	.rx_queue_count = eth_rx_queue_count,
 	.link_update = eth_link_update,
 	.stats_get = eth_stats_get,
 	.stats_reset = eth_stats_reset,
diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h
index 605e47c..f64ed20 100644
--- a/lib/librte_vhost/rte_vhost.h
+++ b/lib/librte_vhost/rte_vhost.h
@@ -432,6 +432,18 @@ int rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem);
 int rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx,
 			      struct rte_vhost_vring *vring);
 
+/**
+ * Get vhost RX queue avail count.
+ *
+ * @param vid
+ *  vhost device ID
+ * @param qid
+ *  virtio queue index in mq case
+ * @return
+ *  num of desc available
+ */
+uint32_t rte_vhost_rx_queue_count(int vid, uint16_t qid);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map
index 0785873..1e70495 100644
--- a/lib/librte_vhost/rte_vhost_version.map
+++ b/lib/librte_vhost/rte_vhost_version.map
@@ -45,3 +45,10 @@ DPDK_17.05 {
 	rte_vhost_log_write;
 
 } DPDK_16.07;
+
+DPDK_17.08 {
+	global:
+
+	rte_vhost_rx_queue_count;
+
+} DPDK_17.05;
diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index 0b19d2e..140d2ae 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -475,3 +475,26 @@ rte_vhost_log_used_vring(int vid, uint16_t vring_idx,
 
 	vhost_log_used_vring(dev, vq, offset, len);
 }
+
+uint32_t
+rte_vhost_rx_queue_count(int vid, uint16_t qid)
+{
+	struct virtio_net *dev;
+	struct vhost_virtqueue *vq;
+
+	dev = get_device(vid);
+	if (!dev)
+		return 0;
+
+	if (unlikely(qid >= dev->nr_vring || (qid & 1) == 0)) {
+		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
+			dev->vid, __func__, qid);
+		return 0;
+	}
+
+	vq = dev->virtqueue[qid];
+	if (unlikely(vq->enabled == 0))
+		return 0;
+
+	return *((volatile uint16_t *)&vq->avail->idx) - vq->last_avail_idx;
+}
-- 
2.7.4

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

* Re: [dpdk-dev] [PATCH] vhost: support rx_queue_count
  2017-05-23 12:51   ` Wang, Zhihong
@ 2017-05-24  8:14     ` Yuanhan Liu
  2017-05-24  8:36       ` Jens Freimann
  0 siblings, 1 reply; 11+ messages in thread
From: Yuanhan Liu @ 2017-05-24  8:14 UTC (permalink / raw)
  To: Wang, Zhihong; +Cc: Jens Freimann, dev

On Tue, May 23, 2017 at 12:51:56PM +0000, Wang, Zhihong wrote:
> 
> 
> > -----Original Message-----
> > From: Jens Freimann [mailto:jfreiman@redhat.com]
> > Sent: Tuesday, May 23, 2017 7:54 PM
> > To: Wang, Zhihong <zhihong.wang@intel.com>
> > Cc: dev@dpdk.org; yuanhan.liu@linux.intel.com
> > Subject: Re: [dpdk-dev] [PATCH] vhost: support rx_queue_count
> > 
> > On Mon, May 22, 2017 at 04:01:08PM -0400, Zhihong Wang wrote:
> > > This patch implements the ops rx_queue_count for vhost PMD by adding
> > > a helper function rte_vhost_rx_queue_count in vhost lib.
> > >
> > > The ops ops rx_queue_count gets vhost RX queue avail count and helps
> > 
> > s/ops ops/ops/ ?
> 
> Thanks a lot!

Seems you overlooked other comments, such as:

> > > +	vq = dev->virtqueue[qid];
> > 
> > check for vq == NULL?
> > 
> > regards,
> > Jens

Besides, Jens, I'm not a big fan of "dev == NULL" over "!dev". I accept
both :)

	--yliu

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

* Re: [dpdk-dev] [PATCH] vhost: support rx_queue_count
  2017-05-24  8:14     ` Yuanhan Liu
@ 2017-05-24  8:36       ` Jens Freimann
  2017-05-24  8:42         ` Yuanhan Liu
  0 siblings, 1 reply; 11+ messages in thread
From: Jens Freimann @ 2017-05-24  8:36 UTC (permalink / raw)
  To: Yuanhan Liu; +Cc: Wang, Zhihong, dev

On Wed, May 24, 2017 at 04:14:19PM +0800, Yuanhan Liu wrote:
> On Tue, May 23, 2017 at 12:51:56PM +0000, Wang, Zhihong wrote:
> > 
> > 
> > > -----Original Message-----
> > > From: Jens Freimann [mailto:jfreiman@redhat.com]
> > > Sent: Tuesday, May 23, 2017 7:54 PM
> > > To: Wang, Zhihong <zhihong.wang@intel.com>
> > > Cc: dev@dpdk.org; yuanhan.liu@linux.intel.com
> > > Subject: Re: [dpdk-dev] [PATCH] vhost: support rx_queue_count
> > > 
> > > On Mon, May 22, 2017 at 04:01:08PM -0400, Zhihong Wang wrote:
> > > > This patch implements the ops rx_queue_count for vhost PMD by adding
> > > > a helper function rte_vhost_rx_queue_count in vhost lib.
> > > >
> > > > The ops ops rx_queue_count gets vhost RX queue avail count and helps
> > > 
> > > s/ops ops/ops/ ?
> > 
> > Thanks a lot!
> 
> Seems you overlooked other comments, such as:
> 
> > > > +	vq = dev->virtqueue[qid];
> > > 
> > > check for vq == NULL?
> > > 
> > > regards,
> > > Jens
> 
> Besides, Jens, I'm not a big fan of "dev == NULL" over "!dev". I accept
> both :)

Personally I'm with you on this, but it says different in http://dpdk.org/doc/guides/contributing/coding_style.html
Anyway, up to you :)

regards,
Jens

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

* Re: [dpdk-dev] [PATCH] vhost: support rx_queue_count
  2017-05-24  8:36       ` Jens Freimann
@ 2017-05-24  8:42         ` Yuanhan Liu
  2017-05-26  4:35           ` Wang, Zhihong
  0 siblings, 1 reply; 11+ messages in thread
From: Yuanhan Liu @ 2017-05-24  8:42 UTC (permalink / raw)
  To: Jens Freimann; +Cc: Wang, Zhihong, dev

On Wed, May 24, 2017 at 10:36:01AM +0200, Jens Freimann wrote:
> On Wed, May 24, 2017 at 04:14:19PM +0800, Yuanhan Liu wrote:
> > On Tue, May 23, 2017 at 12:51:56PM +0000, Wang, Zhihong wrote:
> > > 
> > > 
> > > > -----Original Message-----
> > > > From: Jens Freimann [mailto:jfreiman@redhat.com]
> > > > Sent: Tuesday, May 23, 2017 7:54 PM
> > > > To: Wang, Zhihong <zhihong.wang@intel.com>
> > > > Cc: dev@dpdk.org; yuanhan.liu@linux.intel.com
> > > > Subject: Re: [dpdk-dev] [PATCH] vhost: support rx_queue_count
> > > > 
> > > > On Mon, May 22, 2017 at 04:01:08PM -0400, Zhihong Wang wrote:
> > > > > This patch implements the ops rx_queue_count for vhost PMD by adding
> > > > > a helper function rte_vhost_rx_queue_count in vhost lib.
> > > > >
> > > > > The ops ops rx_queue_count gets vhost RX queue avail count and helps
> > > > 
> > > > s/ops ops/ops/ ?
> > > 
> > > Thanks a lot!
> > 
> > Seems you overlooked other comments, such as:
> > 
> > > > > +	vq = dev->virtqueue[qid];
> > > > 
> > > > check for vq == NULL?
> > > > 
> > > > regards,
> > > > Jens
> > 
> > Besides, Jens, I'm not a big fan of "dev == NULL" over "!dev". I accept
> > both :)
> 
> Personally I'm with you on this, but it says different in http://dpdk.org/doc/guides/contributing/coding_style.html
> Anyway, up to you :)

Yes, I know that. To make every body happy, I would suggset you to
follow the coding style. But if you have already choosen another way,
I won't bother to ask you do the change. Unless, it becomes a must
in future.

	--yliu

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

* Re: [dpdk-dev] [PATCH] vhost: support rx_queue_count
  2017-05-24  8:42         ` Yuanhan Liu
@ 2017-05-26  4:35           ` Wang, Zhihong
  0 siblings, 0 replies; 11+ messages in thread
From: Wang, Zhihong @ 2017-05-26  4:35 UTC (permalink / raw)
  To: Yuanhan Liu, Jens Freimann; +Cc: dev



> -----Original Message-----
> From: Yuanhan Liu [mailto:yuanhan.liu@linux.intel.com]
> Sent: Wednesday, May 24, 2017 4:43 PM
> To: Jens Freimann <jfreiman@redhat.com>
> Cc: Wang, Zhihong <zhihong.wang@intel.com>; dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH] vhost: support rx_queue_count
> 
> On Wed, May 24, 2017 at 10:36:01AM +0200, Jens Freimann wrote:
> > On Wed, May 24, 2017 at 04:14:19PM +0800, Yuanhan Liu wrote:
> > > On Tue, May 23, 2017 at 12:51:56PM +0000, Wang, Zhihong wrote:
> > > >
> > > >
> > > > > -----Original Message-----
> > > > > From: Jens Freimann [mailto:jfreiman@redhat.com]
> > > > > Sent: Tuesday, May 23, 2017 7:54 PM
> > > > > To: Wang, Zhihong <zhihong.wang@intel.com>
> > > > > Cc: dev@dpdk.org; yuanhan.liu@linux.intel.com
> > > > > Subject: Re: [dpdk-dev] [PATCH] vhost: support rx_queue_count
> > > > >
> > > > > On Mon, May 22, 2017 at 04:01:08PM -0400, Zhihong Wang wrote:
> > > > > > This patch implements the ops rx_queue_count for vhost PMD by
> adding
> > > > > > a helper function rte_vhost_rx_queue_count in vhost lib.
> > > > > >
> > > > > > The ops ops rx_queue_count gets vhost RX queue avail count and
> helps
> > > > >
> > > > > s/ops ops/ops/ ?
> > > >
> > > > Thanks a lot!
> > >
> > > Seems you overlooked other comments, such as:
> > >
> > > > > > +	vq = dev->virtqueue[qid];
> > > > >
> > > > > check for vq == NULL?
> > > > >
> > > > > regards,
> > > > > Jens
> > >
> > > Besides, Jens, I'm not a big fan of "dev == NULL" over "!dev". I accept
> > > both :)
> >
> > Personally I'm with you on this, but it says different in
> http://dpdk.org/doc/guides/contributing/coding_style.html
> > Anyway, up to you :)
> 
> Yes, I know that. To make every body happy, I would suggset you to
> follow the coding style. But if you have already choosen another way,
> I won't bother to ask you do the change. Unless, it becomes a must
> in future.

Thanks Yuanhan and Jens! Will address these comments in v3.

> 
> 	--yliu

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

* Re: [dpdk-dev] [PATCH v3] vhost: support rx_queue_count
  2017-05-26 17:18 ` [dpdk-dev] [PATCH v3] " Zhihong Wang
@ 2017-05-26  5:54   ` Yuanhan Liu
  0 siblings, 0 replies; 11+ messages in thread
From: Yuanhan Liu @ 2017-05-26  5:54 UTC (permalink / raw)
  To: Zhihong Wang; +Cc: dev, jfreiman, ciara.loftus

On Fri, May 26, 2017 at 01:18:02PM -0400, Zhihong Wang wrote:
> This patch implements the ops rx_queue_count for vhost PMD by adding
> a helper function rte_vhost_rx_queue_count in vhost lib.
> 
> The ops rx_queue_count gets vhost RX queue avail count and helps to
> understand the queue fill level.
> 
> Signed-off-by: Zhihong Wang <zhihong.wang@intel.com>
> Acked-by: Ciara Loftus <ciara.loftus@intel.com>

Applied to dpdk-next-virtio.

Thanks.

	--yliu

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

* [dpdk-dev] [PATCH v3] vhost: support rx_queue_count
  2017-05-22 20:01 [dpdk-dev] [PATCH] vhost: support rx_queue_count Zhihong Wang
                   ` (2 preceding siblings ...)
  2017-05-24  0:54 ` [dpdk-dev] [PATCH v2] " Zhihong Wang
@ 2017-05-26 17:18 ` Zhihong Wang
  2017-05-26  5:54   ` Yuanhan Liu
  3 siblings, 1 reply; 11+ messages in thread
From: Zhihong Wang @ 2017-05-26 17:18 UTC (permalink / raw)
  To: dev; +Cc: yuanhan.liu, jfreiman, ciara.loftus, Zhihong Wang

This patch implements the ops rx_queue_count for vhost PMD by adding
a helper function rte_vhost_rx_queue_count in vhost lib.

The ops rx_queue_count gets vhost RX queue avail count and helps to
understand the queue fill level.

Signed-off-by: Zhihong Wang <zhihong.wang@intel.com>
Acked-by: Ciara Loftus <ciara.loftus@intel.com>
---
Changes in v3:

 1. Added pointer check for vq and vq->avail.
 
 2. Fixed coding style.

---
Changes in v2:

 1. Fixed a typo in commit log.

 drivers/net/vhost/rte_eth_vhost.c      | 13 +++++++++++++
 lib/librte_vhost/rte_vhost.h           | 12 ++++++++++++
 lib/librte_vhost/rte_vhost_version.map |  7 +++++++
 lib/librte_vhost/vhost.c               | 26 ++++++++++++++++++++++++++
 4 files changed, 58 insertions(+)

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 257bf6d..ebcfb28 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -973,6 +973,18 @@ eth_link_update(struct rte_eth_dev *dev __rte_unused,
 	return 0;
 }
 
+static uint32_t
+eth_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
+{
+	struct vhost_queue *vq;
+
+	vq = dev->data->rx_queues[rx_queue_id];
+	if (vq == NULL)
+		return 0;
+
+	return rte_vhost_rx_queue_count(vq->vid, vq->virtqueue_id);
+}
+
 static const struct eth_dev_ops ops = {
 	.dev_start = eth_dev_start,
 	.dev_stop = eth_dev_stop,
@@ -984,6 +996,7 @@ static const struct eth_dev_ops ops = {
 	.rx_queue_release = eth_queue_release,
 	.tx_queue_release = eth_queue_release,
 	.tx_done_cleanup = eth_tx_done_cleanup,
+	.rx_queue_count = eth_rx_queue_count,
 	.link_update = eth_link_update,
 	.stats_get = eth_stats_get,
 	.stats_reset = eth_stats_reset,
diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h
index 605e47c..f64ed20 100644
--- a/lib/librte_vhost/rte_vhost.h
+++ b/lib/librte_vhost/rte_vhost.h
@@ -432,6 +432,18 @@ int rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem);
 int rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx,
 			      struct rte_vhost_vring *vring);
 
+/**
+ * Get vhost RX queue avail count.
+ *
+ * @param vid
+ *  vhost device ID
+ * @param qid
+ *  virtio queue index in mq case
+ * @return
+ *  num of desc available
+ */
+uint32_t rte_vhost_rx_queue_count(int vid, uint16_t qid);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map
index 0785873..1e70495 100644
--- a/lib/librte_vhost/rte_vhost_version.map
+++ b/lib/librte_vhost/rte_vhost_version.map
@@ -45,3 +45,10 @@ DPDK_17.05 {
 	rte_vhost_log_write;
 
 } DPDK_16.07;
+
+DPDK_17.08 {
+	global:
+
+	rte_vhost_rx_queue_count;
+
+} DPDK_17.05;
diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index 0b19d2e..1b8e6bd 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -475,3 +475,29 @@ rte_vhost_log_used_vring(int vid, uint16_t vring_idx,
 
 	vhost_log_used_vring(dev, vq, offset, len);
 }
+
+uint32_t
+rte_vhost_rx_queue_count(int vid, uint16_t qid)
+{
+	struct virtio_net *dev;
+	struct vhost_virtqueue *vq;
+
+	dev = get_device(vid);
+	if (dev == NULL)
+		return 0;
+
+	if (unlikely(qid >= dev->nr_vring || (qid & 1) == 0)) {
+		RTE_LOG(ERR, VHOST_DATA, "(%d) %s: invalid virtqueue idx %d.\n",
+			dev->vid, __func__, qid);
+		return 0;
+	}
+
+	vq = dev->virtqueue[qid];
+	if (vq == NULL)
+		return 0;
+
+	if (unlikely(vq->enabled == 0 || vq->avail == NULL))
+		return 0;
+
+	return *((volatile uint16_t *)&vq->avail->idx) - vq->last_avail_idx;
+}
-- 
2.7.4

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

end of thread, other threads:[~2017-05-26  5:54 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-22 20:01 [dpdk-dev] [PATCH] vhost: support rx_queue_count Zhihong Wang
2017-05-23 11:53 ` Jens Freimann
2017-05-23 12:51   ` Wang, Zhihong
2017-05-24  8:14     ` Yuanhan Liu
2017-05-24  8:36       ` Jens Freimann
2017-05-24  8:42         ` Yuanhan Liu
2017-05-26  4:35           ` Wang, Zhihong
2017-05-23 13:10 ` Loftus, Ciara
2017-05-24  0:54 ` [dpdk-dev] [PATCH v2] " Zhihong Wang
2017-05-26 17:18 ` [dpdk-dev] [PATCH v3] " Zhihong Wang
2017-05-26  5:54   ` Yuanhan Liu

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