[3/4] ethdev: add meter profile config calculation

Message ID 20220518043459.1281590-4-akozyrev@nvidia.com (mailing list archive)
State Superseded, archived
Delegated to: Andrew Rybchenko
Headers
Series ethdev: separate metering and marking from policing |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Alexander Kozyrev May 18, 2022, 4:34 a.m. UTC
  Introduce a new Meter API to calculate PMD-specific profile
configuration values based on user-provided CIR, CBS and EBS.
That will allow fast Meter configuration in hardware without
the need to convert these values every time we use a profile.

Signed-off-by: Alexander Kozyrev <akozyrev@nvidia.com>
---
 .../traffic_metering_and_policing.rst         |  2 ++
 doc/guides/rel_notes/release_22_07.rst        |  1 +
 lib/ethdev/rte_mtr.c                          | 12 ++++++++++
 lib/ethdev/rte_mtr.h                          | 24 +++++++++++++++++++
 lib/ethdev/rte_mtr_driver.h                   |  9 +++++++
 lib/ethdev/version.map                        |  3 +++
 6 files changed, 51 insertions(+)
  

Comments

Cristian Dumitrescu May 19, 2022, 2:55 p.m. UTC | #1
> diff --git a/lib/ethdev/rte_mtr.h b/lib/ethdev/rte_mtr.h
> index 40df0888c8..d7b916b168 100644
> --- a/lib/ethdev/rte_mtr.h
> +++ b/lib/ethdev/rte_mtr.h
> @@ -524,6 +524,30 @@ rte_mtr_meter_profile_delete(uint16_t port_id,
>  	uint32_t meter_profile_id,
>  	struct rte_mtr_error *error);
> 
> +/**
> + * Meter profile calculate
> + *
> + * Calculate CIR, CBS and EBS values for a given meter profile ID.
> + * Convert user-provided values to PMD-specific configuration.
> + *
> + * @param[in] port_id
> + *   The port identifier of the Ethernet device.
> + * @param[in] meter_profile_id
> + *   Meter profile ID. Needs to be the valid.
> + * @param[out] meter_profile_cfg
> + *   Meter profile configuration filled by PMD.
> + * @param[out] error
> + *   Error details. Filled in only on error, when not NULL.
> + * @return
> + *   0 on success, non-zero error code otherwise.
> + */
> +__rte_experimental
> +int
> +rte_mtr_meter_profile_calculate(uint16_t port_id,
> +	uint32_t meter_profile_id,
> +	void *meter_profile_cfg,
> +	struct rte_mtr_error *error);
> +
>  /**
>   * Check whether a meter policy can be created on a given port.
>   *

I don't understand the purpose of this proposed API function, can you please explain?

It looks to me that you want to have an alternative way to create a meter profile, so why not use the existing API function rte_mtr_meter_profile_add() ? It does the same thing.

Also, who allocates this opaque array meter_profile_cfg? Assuming it is the user that needs to allocate it, how does the user know its size?
  
Alexander Kozyrev May 24, 2022, 12:36 p.m. UTC | #2
On  Thur, May 19, 2022 10:55 Dumitrescu, Cristian <cristian.dumitrescu@intel.com>:
> I don't understand the purpose of this proposed API function, can you please
> explain?
> 
> It looks to me that you want to have an alternative way to create a meter
> profile, so why not use the existing API function rte_mtr_meter_profile_add() ?
> It does the same thing.
> 
> Also, who allocates this opaque array meter_profile_cfg? Assuming it is the user
> that needs to allocate it, how does the user know its size?

The creation of a meter is still done thru the rte_mtr_meter_profile_add() API.
It is responsible for memory allocation and parameters calculation.
The rte_mtr_meter_profile_get() API just returns the pointer to the object
allocated earlier, based on the Meter ID, saving the lookup time.
User still have to manage the lifecycle with add/destroy functions.
PMD allocates this opaque pointer and knows its size, user doesn't need to worry.
I hope that my examples in the meeting minutes explain this concept clear enough.
  

Patch

diff --git a/doc/guides/prog_guide/traffic_metering_and_policing.rst b/doc/guides/prog_guide/traffic_metering_and_policing.rst
index ceb5a96488..99c25f8937 100644
--- a/doc/guides/prog_guide/traffic_metering_and_policing.rst
+++ b/doc/guides/prog_guide/traffic_metering_and_policing.rst
@@ -105,3 +105,5 @@  traffic meter and policing library.
    * Adding one (or multiple) actions of the type ``RTE_FLOW_ACTION_TYPE_METER``
      to the list of meter actions (``struct rte_mtr_meter_policy_params::actions``)
      specified per color as show in :numref:`figure_rte_mtr_chaining`.
+#.  Traffic metering algorithm configuration may be converted to the PDM-specific
+   values using ``rte_mtr_meter_profile_calculate()`` API function for reuse.
diff --git a/doc/guides/rel_notes/release_22_07.rst b/doc/guides/rel_notes/release_22_07.rst
index ec83178d98..5f19223663 100644
--- a/doc/guides/rel_notes/release_22_07.rst
+++ b/doc/guides/rel_notes/release_22_07.rst
@@ -64,6 +64,7 @@  New Features
 
   * Added METER_COLOR item to match Color Marker set by a Meter.
   * Added ability to set Color Marker via modify_field Flow API.
+  * Added Meter API to calculate a profile configuration values.
 
 * **Updated Intel iavf driver.**
 
diff --git a/lib/ethdev/rte_mtr.c b/lib/ethdev/rte_mtr.c
index e49fcf271c..e236cac09b 100644
--- a/lib/ethdev/rte_mtr.c
+++ b/lib/ethdev/rte_mtr.c
@@ -91,6 +91,18 @@  rte_mtr_meter_profile_delete(uint16_t port_id,
 		meter_profile_id, error);
 }
 
+/** MTR meter profile calculate */
+int
+rte_mtr_meter_profile_calculate(uint16_t port_id,
+	uint32_t meter_profile_id,
+	void *meter_profile_cfg,
+	struct rte_mtr_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	return RTE_MTR_FUNC(port_id, meter_profile_calculate)(dev,
+		meter_profile_id, meter_profile_cfg, error);
+}
+
 /* MTR meter policy validate */
 int
 rte_mtr_meter_policy_validate(uint16_t port_id,
diff --git a/lib/ethdev/rte_mtr.h b/lib/ethdev/rte_mtr.h
index 40df0888c8..d7b916b168 100644
--- a/lib/ethdev/rte_mtr.h
+++ b/lib/ethdev/rte_mtr.h
@@ -524,6 +524,30 @@  rte_mtr_meter_profile_delete(uint16_t port_id,
 	uint32_t meter_profile_id,
 	struct rte_mtr_error *error);
 
+/**
+ * Meter profile calculate
+ *
+ * Calculate CIR, CBS and EBS values for a given meter profile ID.
+ * Convert user-provided values to PMD-specific configuration.
+ *
+ * @param[in] port_id
+ *   The port identifier of the Ethernet device.
+ * @param[in] meter_profile_id
+ *   Meter profile ID. Needs to be the valid.
+ * @param[out] meter_profile_cfg
+ *   Meter profile configuration filled by PMD.
+ * @param[out] error
+ *   Error details. Filled in only on error, when not NULL.
+ * @return
+ *   0 on success, non-zero error code otherwise.
+ */
+__rte_experimental
+int
+rte_mtr_meter_profile_calculate(uint16_t port_id,
+	uint32_t meter_profile_id,
+	void *meter_profile_cfg,
+	struct rte_mtr_error *error);
+
 /**
  * Check whether a meter policy can be created on a given port.
  *
diff --git a/lib/ethdev/rte_mtr_driver.h b/lib/ethdev/rte_mtr_driver.h
index ee8c6ef7ad..f1982ff220 100644
--- a/lib/ethdev/rte_mtr_driver.h
+++ b/lib/ethdev/rte_mtr_driver.h
@@ -41,6 +41,12 @@  typedef int (*rte_mtr_meter_profile_delete_t)(struct rte_eth_dev *dev,
 	uint32_t meter_profile_id,
 	struct rte_mtr_error *error);
 
+/** @internal MTR meter profile calculate. */
+typedef int (*rte_mtr_meter_profile_calculate_t)(struct rte_eth_dev *dev,
+	uint32_t meter_profile_id,
+	void *meter_profile_cfg,
+	struct rte_mtr_error *error);
+
 /** @internal MTR meter policy validate. */
 typedef int (*rte_mtr_meter_policy_validate_t)(struct rte_eth_dev *dev,
 	struct rte_mtr_meter_policy_params *policy,
@@ -156,6 +162,9 @@  struct rte_mtr_ops {
 
 	/** MTR object meter policy update */
 	rte_mtr_meter_policy_update_t meter_policy_update;
+
+	/** MTR meter profile calculate */
+	rte_mtr_meter_profile_calculate_t meter_profile_calculate;
 };
 
 /**
diff --git a/lib/ethdev/version.map b/lib/ethdev/version.map
index 20391ab29e..76024331cb 100644
--- a/lib/ethdev/version.map
+++ b/lib/ethdev/version.map
@@ -279,6 +279,9 @@  EXPERIMENTAL {
 	rte_flow_async_action_handle_create;
 	rte_flow_async_action_handle_destroy;
 	rte_flow_async_action_handle_update;
+
+	# added in 22.07
+	rte_mtr_meter_profile_calculate;
 };
 
 INTERNAL {