[RFC v2 3/7] ethdev: introduce Rx queue based limit watermark
Spike Du
spiked at nvidia.com
Sun May 22 07:58:56 CEST 2022
LWM(limit watermark) describes the fullness of a Rx queue. If the Rx
queue fullness is above LWM, the device will trigger the event
RTE_ETH_EVENT_RX_LWM.
LWM is defined as a percentage of Rx queue size with valid value of
[0,99].
Setting LWM to 0 means disable it, which is the default.
When translate the percentage to queue descriptor number, the numbe
should be bigger than 0 and less than queue size.
Add LWM's configuration and query driver callbacks in eth_dev_ops.
Signed-off-by: Spike Du <spiked at nvidia.com>
---
lib/ethdev/ethdev_driver.h | 22 ++++++++++++
lib/ethdev/rte_ethdev.c | 52 +++++++++++++++++++++++++++
lib/ethdev/rte_ethdev.h | 74 +++++++++++++++++++++++++++++++++++++-
lib/ethdev/version.map | 4 +++
4 files changed, 151 insertions(+), 1 deletion(-)
diff --git a/lib/ethdev/ethdev_driver.h b/lib/ethdev/ethdev_driver.h
index 69d9dc21d8..12ec5e7e19 100644
--- a/lib/ethdev/ethdev_driver.h
+++ b/lib/ethdev/ethdev_driver.h
@@ -470,6 +470,23 @@ typedef int (*eth_rx_queue_setup_t)(struct rte_eth_dev *dev,
const struct rte_eth_rxconf *rx_conf,
struct rte_mempool *mb_pool);
+/**
+ * @internal Set Rx queue limit watermark.
+ * see @rte_eth_rx_lwm_set()
+ */
+typedef int (*eth_rx_queue_lwm_set_t)(struct rte_eth_dev *dev,
+ uint16_t rx_queue_id,
+ uint8_t lwm);
+
+/**
+ * @internal Query queue limit watermark.
+ * see @rte_eth_rx_lwm_query()
+ */
+
+typedef int (*eth_rx_queue_lwm_query_t)(struct rte_eth_dev *dev,
+ uint16_t *rx_queue_id,
+ uint8_t *lwm);
+
/** @internal Setup a transmit queue of an Ethernet device. */
typedef int (*eth_tx_queue_setup_t)(struct rte_eth_dev *dev,
uint16_t tx_queue_id,
@@ -1168,6 +1185,11 @@ struct eth_dev_ops {
/** Priority flow control queue configure */
priority_flow_ctrl_queue_config_t priority_flow_ctrl_queue_config;
+ /** Set Rx queue limit watermark */
+ eth_rx_queue_lwm_set_t rx_queue_lwm_set;
+ /** Query Rx queue limit watermark */
+ eth_rx_queue_lwm_query_t rx_queue_lwm_query;
+
/** Set Unicast Table Array */
eth_uc_hash_table_set_t uc_hash_table_set;
/** Set Unicast hash bitmap */
diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index 8520aec561..0a46c71288 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -4429,6 +4429,58 @@ int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx,
queue_idx, tx_rate));
}
+int rte_eth_rx_lwm_set(uint16_t port_id, uint16_t queue_id,
+ uint8_t lwm)
+{
+ struct rte_eth_dev *dev;
+ struct rte_eth_dev_info dev_info;
+ int ret;
+
+ RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+ dev = &rte_eth_devices[port_id];
+
+ ret = rte_eth_dev_info_get(port_id, &dev_info);
+ if (ret != 0)
+ return ret;
+
+ if (queue_id > dev_info.max_rx_queues) {
+ RTE_ETHDEV_LOG(ERR,
+ "Set queue LWM:port %u: invalid queue ID=%u.\n",
+ port_id, queue_id);
+ return -EINVAL;
+ }
+
+ if (lwm > 99)
+ return -EINVAL;
+ RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_lwm_set, -ENOTSUP);
+ return eth_err(port_id, (*dev->dev_ops->rx_queue_lwm_set)(dev,
+ queue_id, lwm));
+}
+
+int rte_eth_rx_lwm_query(uint16_t port_id, uint16_t *queue_id,
+ uint8_t *lwm)
+{
+ struct rte_eth_dev_info dev_info;
+ struct rte_eth_dev *dev;
+ int ret;
+
+ RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+ dev = &rte_eth_devices[port_id];
+
+ ret = rte_eth_dev_info_get(port_id, &dev_info);
+ if (ret != 0)
+ return ret;
+
+ if (queue_id == NULL)
+ return -EINVAL;
+ if (*queue_id >= dev_info.max_rx_queues)
+ *queue_id = 0;
+
+ RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_lwm_query, -ENOTSUP);
+ return eth_err(port_id, (*dev->dev_ops->rx_queue_lwm_query)(dev,
+ queue_id, lwm));
+}
+
RTE_INIT(eth_dev_init_fp_ops)
{
uint32_t i;
diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h
index 04cff8ee10..687ae5ff29 100644
--- a/lib/ethdev/rte_ethdev.h
+++ b/lib/ethdev/rte_ethdev.h
@@ -1249,7 +1249,16 @@ struct rte_eth_rxconf {
*/
union rte_eth_rxseg *rx_seg;
- uint64_t reserved_64s[2]; /**< Reserved for future fields */
+ /**
+ * Per-queue Rx limit watermark defined as percentage of Rx queue
+ * size. If Rx queue receives traffic higher than this percentage,
+ * the event RTE_ETH_EVENT_RX_LWM is triggered.
+ */
+ uint8_t lwm;
+
+ uint8_t reserved_bits[3];
+ uint32_t reserved_32s;
+ uint64_t reserved_64s;
void *reserved_ptrs[2]; /**< Reserved for future fields */
};
@@ -3668,6 +3677,64 @@ int rte_eth_dev_get_vlan_offload(uint16_t port_id);
*/
int rte_eth_dev_set_vlan_pvid(uint16_t port_id, uint16_t pvid, int on);
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Set Rx queue based limit watermark.
+ *
+ * @param port_id
+ * The port identifier of the Ethernet device.
+ * @param queue_id
+ * The index of the receive queue.
+ * @param lwm
+ * The limit watermark percentage of Rx queue size which describes
+ * the fullness of Rx queue. If the Rx queue fullness is above LWM,
+ * the device will trigger the event RTE_ETH_EVENT_RX_LWM.
+ * [1-99] to set a new LWM.
+ * 0 to disable watermark monitoring.
+ *
+ * @return
+ * - 0 if successful.
+ * - negative if failed.
+ */
+__rte_experimental
+int rte_eth_rx_lwm_set(uint16_t port_id, uint16_t queue_id, uint8_t lwm);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Query Rx queue based limit watermark.
+ * The function queries all queues in the port circularly until one
+ * pending LWM event is found or no pending LWM event is found.
+ *
+ * @param port_id
+ * The port identifier of the Ethernet device.
+ * @param queue_id
+ * The API caller sets the starting Rx queue id in the pointer.
+ * If the queue_id is bigger than maximum queue id of the port,
+ * it's rewinded to 0 so that application can keep calling
+ * this function to handle all pending LWM events in the queues
+ * with a simple increment between calls.
+ * If a Rx queue has pending lwm event, the pointer is updated
+ * with this Rx queue id; otherwise this pointer's content is
+ * unchanged.
+ * @param lwm
+ * The pointer to the limit watermark percentage of Rx queue.
+ * If Rx queue with pending lwm event is found, the queue's LWM
+ * percentage is stored in this pointer, otherwise the pointer's
+ * content is unchanged.
+ *
+ * @return
+ * - 1 if a Rx queue with pending lwm event is found.
+ * - 0 if no Rx queue with pending lwm event is found.
+ * - -EINVAL if queue_id is NULL.
+ */
+__rte_experimental
+int rte_eth_rx_lwm_query(uint16_t port_id, uint16_t *queue_id,
+ uint8_t *lwm);
+
typedef void (*buffer_tx_error_fn)(struct rte_mbuf **unsent, uint16_t count,
void *userdata);
@@ -3873,6 +3940,11 @@ enum rte_eth_event_type {
RTE_ETH_EVENT_DESTROY, /**< port is released */
RTE_ETH_EVENT_IPSEC, /**< IPsec offload related event */
RTE_ETH_EVENT_FLOW_AGED,/**< New aged-out flows is detected */
+ /**
+ * watermark value is exceeded in a queue.
+ * see @rte_eth_rx_lwm_set()
+ */
+ RTE_ETH_EVENT_RX_LWM,
RTE_ETH_EVENT_MAX /**< max value of this enum */
};
diff --git a/lib/ethdev/version.map b/lib/ethdev/version.map
index 20391ab29e..5cf44c5d1d 100644
--- a/lib/ethdev/version.map
+++ b/lib/ethdev/version.map
@@ -279,6 +279,10 @@ EXPERIMENTAL {
rte_flow_async_action_handle_create;
rte_flow_async_action_handle_destroy;
rte_flow_async_action_handle_update;
+
+ # added in 22.07
+ rte_eth_rx_lwm_set;
+ rte_eth_rx_lwm_query;
};
INTERNAL {
--
2.27.0
More information about the dev
mailing list