[dpdk-dev,RFC,1/2] ethdev: add function to adjust number of descriptors

Message ID 1488459935-13273-2-git-send-email-arybchenko@solarflare.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Checks

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

Commit Message

Andrew Rybchenko March 2, 2017, 1:05 p.m. UTC
  From: Roman Zhukov <Roman.Zhukov@oktetlabs.ru>

Check that numbers of Rx and Tx descriptors satisfy descriptors limits
from the Ethernet device information, otherwise adjust them to boundaries.

Signed-off-by: Roman Zhukov <Roman.Zhukov@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
---
 lib/librte_ether/rte_ethdev.c          | 37 ++++++++++++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev.h          | 20 ++++++++++++++++++
 lib/librte_ether/rte_ether_version.map |  7 +++++++
 3 files changed, 64 insertions(+)
  

Comments

Thomas Monjalon April 24, 2017, 3:13 p.m. UTC | #1
Hi,

02/03/2017 14:05, Andrew Rybchenko:
> From: Roman Zhukov <Roman.Zhukov@oktetlabs.ru>
> 
> Check that numbers of Rx and Tx descriptors satisfy descriptors limits
> from the Ethernet device information, otherwise adjust them to boundaries.
> 
> Signed-off-by: Roman Zhukov <Roman.Zhukov@oktetlabs.ru>
> Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>

I think this helper is OK.
We could add it in 17.08.

Is there any comment from PMD maintainers?

[...]
> +static void
> +rte_eth_dev_adjust_nb_desc(uint16_t *nb_desc,
> +			   const struct rte_eth_desc_lim *desc_lim)
> +{
> +	if (desc_lim->nb_align != 0)
> +		*nb_desc = RTE_ALIGN_CEIL(*nb_desc, desc_lim->nb_align);
> +
> +	if (desc_lim->nb_max != 0)
> +		*nb_desc = RTE_MIN(*nb_desc, desc_lim->nb_max);
> +
> +	*nb_desc = RTE_MAX(*nb_desc, desc_lim->nb_min);
> +}
> +
> +int
> +rte_eth_dev_adjust_nb_rx_tx_desc(uint8_t port_id,
> +				 uint16_t *nb_rx_desc,
> +				 uint16_t *nb_tx_desc)
> +{
> +	struct rte_eth_dev *dev;
> +	struct rte_eth_dev_info dev_info;
> +
> +	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
> +
> +	dev = &rte_eth_devices[port_id];
> +	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
> +
> +	rte_eth_dev_info_get(port_id, &dev_info);
> +
> +	if (nb_rx_desc != NULL)
> +		rte_eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim);
> +
> +	if (nb_tx_desc != NULL)
> +		rte_eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim);
> +
> +	return 0;
> +}
[...]
> +/**
> + * Check that numbers of Rx and Tx descriptors satisfy descriptors limits from
> + * the ethernet device information, otherwise adjust them to boundaries.
> + *
> + * @param port_id
> + *   The port identifier of the Ethernet device.
> + * @param nb_rx_desc
> + *   A pointer to a uint16_t where the number of receive
> + *   descriptors stored.
> + * @param nb_tx_desc
> + *   A pointer to a uint16_t where the number of transmit
> + *   descriptors stored.
> + * @return
> + *   - (0) if successful.
> + *   - (-ENOTSUP, -ENODEV or -EINVAL) on failure.
> + */
> +int rte_eth_dev_adjust_nb_rx_tx_desc(uint8_t port_id,
> +				     uint16_t *nb_rx_desc,
> +				     uint16_t *nb_tx_desc);
> +
  
Andrew Rybchenko April 25, 2017, 7:39 a.m. UTC | #2
Hi,

On 04/24/2017 06:13 PM, Thomas Monjalon wrote:
> Hi,
>
> 02/03/2017 14:05, Andrew Rybchenko:
>> From: Roman Zhukov <Roman.Zhukov@oktetlabs.ru>
>>
>> Check that numbers of Rx and Tx descriptors satisfy descriptors limits
>> from the Ethernet device information, otherwise adjust them to boundaries.
>>
>> Signed-off-by: Roman Zhukov <Roman.Zhukov@oktetlabs.ru>
>> Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
> I think this helper is OK.
> We could add it in 17.08.

Thanks, we'll prepare patch series which updates alll example 
applications to use the helper.

Andrew.

> Is there any comment from PMD maintainers?
>
> [...]
>> +static void
>> +rte_eth_dev_adjust_nb_desc(uint16_t *nb_desc,
>> +			   const struct rte_eth_desc_lim *desc_lim)
>> +{
>> +	if (desc_lim->nb_align != 0)
>> +		*nb_desc = RTE_ALIGN_CEIL(*nb_desc, desc_lim->nb_align);
>> +
>> +	if (desc_lim->nb_max != 0)
>> +		*nb_desc = RTE_MIN(*nb_desc, desc_lim->nb_max);
>> +
>> +	*nb_desc = RTE_MAX(*nb_desc, desc_lim->nb_min);
>> +}
>> +
>> +int
>> +rte_eth_dev_adjust_nb_rx_tx_desc(uint8_t port_id,
>> +				 uint16_t *nb_rx_desc,
>> +				 uint16_t *nb_tx_desc)
>> +{
>> +	struct rte_eth_dev *dev;
>> +	struct rte_eth_dev_info dev_info;
>> +
>> +	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
>> +
>> +	dev = &rte_eth_devices[port_id];
>> +	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
>> +
>> +	rte_eth_dev_info_get(port_id, &dev_info);
>> +
>> +	if (nb_rx_desc != NULL)
>> +		rte_eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim);
>> +
>> +	if (nb_tx_desc != NULL)
>> +		rte_eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim);
>> +
>> +	return 0;
>> +}
> [...]
>> +/**
>> + * Check that numbers of Rx and Tx descriptors satisfy descriptors limits from
>> + * the ethernet device information, otherwise adjust them to boundaries.
>> + *
>> + * @param port_id
>> + *   The port identifier of the Ethernet device.
>> + * @param nb_rx_desc
>> + *   A pointer to a uint16_t where the number of receive
>> + *   descriptors stored.
>> + * @param nb_tx_desc
>> + *   A pointer to a uint16_t where the number of transmit
>> + *   descriptors stored.
>> + * @return
>> + *   - (0) if successful.
>> + *   - (-ENOTSUP, -ENODEV or -EINVAL) on failure.
>> + */
>> +int rte_eth_dev_adjust_nb_rx_tx_desc(uint8_t port_id,
>> +				     uint16_t *nb_rx_desc,
>> +				     uint16_t *nb_tx_desc);
>> +
  

Patch

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index eb0a94a..67ae2d7 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -3273,3 +3273,40 @@  rte_eth_dev_l2_tunnel_offload_set(uint8_t port_id,
 				-ENOTSUP);
 	return (*dev->dev_ops->l2_tunnel_offload_set)(dev, l2_tunnel, mask, en);
 }
+
+static void
+rte_eth_dev_adjust_nb_desc(uint16_t *nb_desc,
+			   const struct rte_eth_desc_lim *desc_lim)
+{
+	if (desc_lim->nb_align != 0)
+		*nb_desc = RTE_ALIGN_CEIL(*nb_desc, desc_lim->nb_align);
+
+	if (desc_lim->nb_max != 0)
+		*nb_desc = RTE_MIN(*nb_desc, desc_lim->nb_max);
+
+	*nb_desc = RTE_MAX(*nb_desc, desc_lim->nb_min);
+}
+
+int
+rte_eth_dev_adjust_nb_rx_tx_desc(uint8_t port_id,
+				 uint16_t *nb_rx_desc,
+				 uint16_t *nb_tx_desc)
+{
+	struct rte_eth_dev *dev;
+	struct rte_eth_dev_info dev_info;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+
+	dev = &rte_eth_devices[port_id];
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
+
+	rte_eth_dev_info_get(port_id, &dev_info);
+
+	if (nb_rx_desc != NULL)
+		rte_eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim);
+
+	if (nb_tx_desc != NULL)
+		rte_eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim);
+
+	return 0;
+}
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index 97f3e2d..b8b985c 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -4421,6 +4421,26 @@  int rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
  */
 int rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev);
 
+/**
+ * Check that numbers of Rx and Tx descriptors satisfy descriptors limits from
+ * the ethernet device information, otherwise adjust them to boundaries.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param nb_rx_desc
+ *   A pointer to a uint16_t where the number of receive
+ *   descriptors stored.
+ * @param nb_tx_desc
+ *   A pointer to a uint16_t where the number of transmit
+ *   descriptors stored.
+ * @return
+ *   - (0) if successful.
+ *   - (-ENOTSUP, -ENODEV or -EINVAL) on failure.
+ */
+int rte_eth_dev_adjust_nb_rx_tx_desc(uint8_t port_id,
+				     uint16_t *nb_rx_desc,
+				     uint16_t *nb_tx_desc);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_ether/rte_ether_version.map b/lib/librte_ether/rte_ether_version.map
index c6c9d0d..8a6696a 100644
--- a/lib/librte_ether/rte_ether_version.map
+++ b/lib/librte_ether/rte_ether_version.map
@@ -154,3 +154,10 @@  DPDK_17.02 {
 	rte_flow_validate;
 
 } DPDK_16.11;
+
+DPDK_17.05 {
+	global:
+
+	rte_eth_dev_adjust_nb_rx_tx_desc;
+
+} DPDK_17.02;