[3/8] vmxnet3: add rx queue usage count utility

Message ID 20220503042257.15626-4-pagupta@vmware.com (mailing list archive)
State Changes Requested, archived
Delegated to: Andrew Rybchenko
Headers
Series vmxnet3 version V5 and V6 |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Pankaj Gupta May 3, 2022, 4:22 a.m. UTC
  Count the number of entries in the rx queue for debugging.

Tested, using testpmd, for different hardware version on ESXi 7.0 Update 2

Signed-off-by: Pankaj Gupta <pagupta@vmware.com>
---
 drivers/net/vmxnet3/vmxnet3_ethdev.c |  1 +
 drivers/net/vmxnet3/vmxnet3_ethdev.h |  3 +++
 drivers/net/vmxnet3/vmxnet3_rxtx.c   | 30 ++++++++++++++++++++++++++++
 3 files changed, 34 insertions(+)
  

Comments

Andrew Rybchenko May 4, 2022, 2:27 p.m. UTC | #1
rx -> Rx

in summary in accordance with spelling in DPDK

On 5/3/22 07:22, Pankaj Gupta wrote:
> Count the number of entries in the rx queue for debugging.

rx -> Rx

As I understand debugging is not the only purpose of the API.

> 
> Tested, using testpmd, for different hardware version on ESXi 7.0 Update 2
> 
> Signed-off-by: Pankaj Gupta <pagupta@vmware.com>
> ---
>   drivers/net/vmxnet3/vmxnet3_ethdev.c |  1 +
>   drivers/net/vmxnet3/vmxnet3_ethdev.h |  3 +++
>   drivers/net/vmxnet3/vmxnet3_rxtx.c   | 30 ++++++++++++++++++++++++++++
>   3 files changed, 34 insertions(+)
> 
> diff --git a/drivers/net/vmxnet3/vmxnet3_ethdev.c b/drivers/net/vmxnet3/vmxnet3_ethdev.c
> index eb65499cf2..a76796716b 100644
> --- a/drivers/net/vmxnet3/vmxnet3_ethdev.c
> +++ b/drivers/net/vmxnet3/vmxnet3_ethdev.c
> @@ -294,6 +294,7 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
>   	eth_dev->rx_pkt_burst = &vmxnet3_recv_pkts;
>   	eth_dev->tx_pkt_burst = &vmxnet3_xmit_pkts;
>   	eth_dev->tx_pkt_prepare = vmxnet3_prep_pkts;
> +	eth_dev->rx_queue_count = vmxnet3_dev_rx_queue_count,

Please, put it just after rx_pkt_burst to preserve the same order as in
structure.

>   	pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
>   
>   	/* extra mbuf field is required to guess MSS */

[snip]
  
Morten Brørup May 4, 2022, 2:35 p.m. UTC | #2
> From: Andrew Rybchenko [mailto:andrew.rybchenko@oktetlabs.ru]
> Sent: Wednesday, 4 May 2022 16.28
> 
> rx -> Rx
> 
> in summary in accordance with spelling in DPDK
> 
> On 5/3/22 07:22, Pankaj Gupta wrote:
> > Count the number of entries in the rx queue for debugging.
> 
> rx -> Rx
> 
> As I understand debugging is not the only purpose of the API.

Correct. E.g. our appliance uses it in the production data plane, not just for debugging. We only need the function to return an approximate number, though.

> 
> >
> > Tested, using testpmd, for different hardware version on ESXi 7.0
> Update 2
> >
> > Signed-off-by: Pankaj Gupta <pagupta@vmware.com>
> > ---
> >   drivers/net/vmxnet3/vmxnet3_ethdev.c |  1 +
> >   drivers/net/vmxnet3/vmxnet3_ethdev.h |  3 +++
> >   drivers/net/vmxnet3/vmxnet3_rxtx.c   | 30
> ++++++++++++++++++++++++++++
> >   3 files changed, 34 insertions(+)
> >
> > diff --git a/drivers/net/vmxnet3/vmxnet3_ethdev.c
> b/drivers/net/vmxnet3/vmxnet3_ethdev.c
> > index eb65499cf2..a76796716b 100644
> > --- a/drivers/net/vmxnet3/vmxnet3_ethdev.c
> > +++ b/drivers/net/vmxnet3/vmxnet3_ethdev.c
> > @@ -294,6 +294,7 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
> >   	eth_dev->rx_pkt_burst = &vmxnet3_recv_pkts;
> >   	eth_dev->tx_pkt_burst = &vmxnet3_xmit_pkts;
> >   	eth_dev->tx_pkt_prepare = vmxnet3_prep_pkts;
> > +	eth_dev->rx_queue_count = vmxnet3_dev_rx_queue_count,
> 
> Please, put it just after rx_pkt_burst to preserve the same order as in
> structure.
> 
> >   	pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
> >
> >   	/* extra mbuf field is required to guess MSS */
> 
> [snip]
  
Pankaj Gupta May 4, 2022, 5:58 p.m. UTC | #3
Hi Andrew,
Please refer struct rte_eth_dev. Following assignment already preserve the order in struct rte_eth_dev

> diff --git a/drivers/net/vmxnet3/vmxnet3_ethdev.c b/drivers/net/vmxnet3/vmxnet3_ethdev.c
> index eb65499cf2..a76796716b 100644
> --- a/drivers/net/vmxnet3/vmxnet3_ethdev.c
> +++ b/drivers/net/vmxnet3/vmxnet3_ethdev.c
> @@ -294,6 +294,7 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
>       eth_dev->rx_pkt_burst = &vmxnet3_recv_pkts;
>       eth_dev->tx_pkt_burst = &vmxnet3_xmit_pkts;
>       eth_dev->tx_pkt_prepare = vmxnet3_prep_pkts;
> +     eth_dev->rx_queue_count = vmxnet3_dev_rx_queue_count,

Please, put it just after rx_pkt_burst to preserve the same order as in
structure.


/**
* @internal
* The generic data structure associated with each Ethernet device.
*
* Pointers to burst-oriented packet receive and transmit functions are
* located at the beginning of the structure, along with the pointer to
* where all the data elements for the particular device are stored in shared
* memory. This split allows the function pointer and driver data to be per-
* process, while the actual configuration data for the device is shared.
*/
struct rte_eth_dev {
    eth_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive function */
    eth_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit function */

    /** Pointer to PMD transmit prepare function */
    eth_tx_prep_t tx_pkt_prepare;
    /** Get the number of used Rx descriptors */
    eth_rx_queue_count_t rx_queue_count;
    /** Check the status of a Rx descriptor */
    eth_rx_descriptor_status_t rx_descriptor_status;
    /** Check the status of a Tx descriptor */
    eth_tx_descriptor_status_t tx_descriptor_status;

    /**
     * Device data that is shared between primary and secondary processes
     */
    struct rte_eth_dev_data *data;
    void *process_private; /**< Pointer to per-process device data */
    const struct eth_dev_ops *dev_ops; /**< Functions exported by PMD */
    struct rte_device *device; /**< Backing device */
   struct rte_intr_handle *intr_handle; /**< Device interrupt handle */

    /** User application callbacks for NIC interrupts */
    struct rte_eth_dev_cb_list link_intr_cbs;
    /**
     * User-supplied functions called from rx_burst to post-process
     * received packets before passing them to the user
     */
    struct rte_eth_rxtx_callback *post_rx_burst_cbs[RTE_MAX_QUEUES_PER_PORT];
    /**
     * User-supplied functions called from tx_burst to pre-process
     * received packets before passing them to the driver for transmission
     */
    struct rte_eth_rxtx_callback *pre_tx_burst_cbs[RTE_MAX_QUEUES_PER_PORT];

    enum rte_eth_dev_state state; /**< Flag indicating the port state */
    void *security_ctx; /**< Context for security ops */
} __rte_cache_aligned;

Thanks,
Pankaj

From: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Date: Wednesday, May 4, 2022 at 7:27 AM
To: Pankaj Gupta <pagupta@vmware.com>, Jochen Behrens <jbehrens@vmware.com>, Yong Wang <yongwang@vmware.com>
Cc: dev@dpdk.org <dev@dpdk.org>
Subject: Re: [PATCH 3/8] vmxnet3: add rx queue usage count utility
⚠ External Email

rx -> Rx

in summary in accordance with spelling in DPDK

On 5/3/22 07:22, Pankaj Gupta wrote:
> Count the number of entries in the rx queue for debugging.

rx -> Rx

As I understand debugging is not the only purpose of the API.

>
> Tested, using testpmd, for different hardware version on ESXi 7.0 Update 2
>
> Signed-off-by: Pankaj Gupta <pagupta@vmware.com>
> ---
>   drivers/net/vmxnet3/vmxnet3_ethdev.c |  1 +
>   drivers/net/vmxnet3/vmxnet3_ethdev.h |  3 +++
>   drivers/net/vmxnet3/vmxnet3_rxtx.c   | 30 ++++++++++++++++++++++++++++
>   3 files changed, 34 insertions(+)
>
> diff --git a/drivers/net/vmxnet3/vmxnet3_ethdev.c b/drivers/net/vmxnet3/vmxnet3_ethdev.c
> index eb65499cf2..a76796716b 100644
> --- a/drivers/net/vmxnet3/vmxnet3_ethdev.c
> +++ b/drivers/net/vmxnet3/vmxnet3_ethdev.c
> @@ -294,6 +294,7 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
>       eth_dev->rx_pkt_burst = &vmxnet3_recv_pkts;
>       eth_dev->tx_pkt_burst = &vmxnet3_xmit_pkts;
>       eth_dev->tx_pkt_prepare = vmxnet3_prep_pkts;
> +     eth_dev->rx_queue_count = vmxnet3_dev_rx_queue_count,

Please, put it just after rx_pkt_burst to preserve the same order as in
structure.

>       pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
>
>       /* extra mbuf field is required to guess MSS */

[snip]
  

Patch

diff --git a/drivers/net/vmxnet3/vmxnet3_ethdev.c b/drivers/net/vmxnet3/vmxnet3_ethdev.c
index eb65499cf2..a76796716b 100644
--- a/drivers/net/vmxnet3/vmxnet3_ethdev.c
+++ b/drivers/net/vmxnet3/vmxnet3_ethdev.c
@@ -294,6 +294,7 @@  eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
 	eth_dev->rx_pkt_burst = &vmxnet3_recv_pkts;
 	eth_dev->tx_pkt_burst = &vmxnet3_xmit_pkts;
 	eth_dev->tx_pkt_prepare = vmxnet3_prep_pkts;
+	eth_dev->rx_queue_count = vmxnet3_dev_rx_queue_count,
 	pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
 
 	/* extra mbuf field is required to guess MSS */
diff --git a/drivers/net/vmxnet3/vmxnet3_ethdev.h b/drivers/net/vmxnet3/vmxnet3_ethdev.h
index 7ec3b2e1f0..ceaeb66392 100644
--- a/drivers/net/vmxnet3/vmxnet3_ethdev.h
+++ b/drivers/net/vmxnet3/vmxnet3_ethdev.h
@@ -193,6 +193,9 @@  int  vmxnet3_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
 				uint16_t nb_rx_desc, unsigned int socket_id,
 				const struct rte_eth_rxconf *rx_conf,
 				struct rte_mempool *mb_pool);
+
+uint32_t vmxnet3_dev_rx_queue_count(void *rx_queue);
+
 int  vmxnet3_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
 				uint16_t nb_tx_desc, unsigned int socket_id,
 				const struct rte_eth_txconf *tx_conf);
diff --git a/drivers/net/vmxnet3/vmxnet3_rxtx.c b/drivers/net/vmxnet3/vmxnet3_rxtx.c
index d745064bc4..e15b377d8c 100644
--- a/drivers/net/vmxnet3/vmxnet3_rxtx.c
+++ b/drivers/net/vmxnet3/vmxnet3_rxtx.c
@@ -1019,6 +1019,36 @@  vmxnet3_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 	return nb_rx;
 }
 
+uint32_t
+vmxnet3_dev_rx_queue_count(void *rx_queue)
+{
+	const vmxnet3_rx_queue_t *rxq;
+	const Vmxnet3_RxCompDesc *rcd;
+	uint32_t idx, nb_rxd = 0;
+	uint8_t gen;
+
+	rxq = rx_queue;
+	if (unlikely(rxq->stopped)) {
+		PMD_RX_LOG(DEBUG, "Rx queue is stopped.");
+		return 0;
+	}
+
+	gen = rxq->comp_ring.gen;
+	idx = rxq->comp_ring.next2proc;
+	rcd = &rxq->comp_ring.base[idx].rcd;
+	while (rcd->gen == gen) {
+		if (rcd->eop)
+			++nb_rxd;
+		if (++idx == rxq->comp_ring.size) {
+			idx = 0;
+			gen ^= 1;
+		}
+		rcd = &rxq->comp_ring.base[idx].rcd;
+	}
+
+	return nb_rxd;
+}
+
 int
 vmxnet3_dev_tx_queue_setup(struct rte_eth_dev *dev,
 			   uint16_t queue_idx,