* [PATCH] net/mlx5: functions refactor for getting counter's action
@ 2022-02-21 8:27 Haifei Luo
2022-02-23 8:51 ` Raslan Darawsheh
0 siblings, 1 reply; 2+ messages in thread
From: Haifei Luo @ 2022-02-21 8:27 UTC (permalink / raw)
To: matan, orika, viacheslavo, Shahaf Shuler; +Cc: dev, thomas, rasland
Previously API flow_dv_query_count_ptr is defined to get counter's
action pointer. This dv function is directly called and the better
way is by the callback.
Add one arg in API mlx5_counter_query and the related callback
counter_query. The added arg is for counter's action pointer.
Signed-off-by: Haifei Luo <haifeil@nvidia.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
---
drivers/net/mlx5/mlx5.h | 2 +-
drivers/net/mlx5/mlx5_flow.c | 41 ++++++++++++++++---------------
drivers/net/mlx5/mlx5_flow.h | 7 +-----
drivers/net/mlx5/mlx5_flow_dv.c | 49 ++++----------------------------------
drivers/net/mlx5/mlx5_flow_meter.c | 2 +-
5 files changed, 28 insertions(+), 73 deletions(-)
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 737ad68..c217a7d 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -1734,7 +1734,7 @@ void mlx5_flow_async_pool_query_handle(struct mlx5_dev_ctx_shared *sh,
uint32_t mlx5_counter_alloc(struct rte_eth_dev *dev);
void mlx5_counter_free(struct rte_eth_dev *dev, uint32_t cnt);
int mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
- bool clear, uint64_t *pkts, uint64_t *bytes);
+ bool clear, uint64_t *pkts, uint64_t *bytes, void **action);
int mlx5_flow_dev_dump(struct rte_eth_dev *dev, struct rte_flow *flow,
FILE *file, struct rte_flow_error *error);
int save_dump_file(const unsigned char *data, uint32_t size,
diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index 179cc3b..f12ec58 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -7797,14 +7797,15 @@ struct mlx5_flow_workspace*
*/
int
mlx5_counter_query(struct rte_eth_dev *dev, uint32_t cnt,
- bool clear, uint64_t *pkts, uint64_t *bytes)
+ bool clear, uint64_t *pkts, uint64_t *bytes, void **action)
{
const struct mlx5_flow_driver_ops *fops;
struct rte_flow_attr attr = { .transfer = 0 };
if (flow_get_drv_type(dev, &attr) == MLX5_FLOW_TYPE_DV) {
fops = flow_get_drv_ops(MLX5_FLOW_TYPE_DV);
- return fops->counter_query(dev, cnt, clear, pkts, bytes);
+ return fops->counter_query(dev, cnt, clear, pkts,
+ bytes, action);
}
DRV_LOG(ERR,
"port %u counter query is not supported.",
@@ -8376,6 +8377,16 @@ struct mlx5_flow_workspace*
"invalid flow handle");
}
handle_idx = flow->dev_handles;
+ /* query counter */
+ if (flow->counter &&
+ (!mlx5_counter_query(dev, flow->counter, false,
+ &count.hits, &count.bytes, &action)) && action) {
+ id = (uint64_t)(uintptr_t)action;
+ type = DR_DUMP_REC_TYPE_PMD_COUNTER;
+ save_dump_file(NULL, 0, type,
+ id, (void *)&count, file);
+ }
+
while (handle_idx) {
dh = mlx5_ipool_get(priv->sh->ipool
[MLX5_IPOOL_MLX5_FLOW], handle_idx);
@@ -8383,16 +8394,6 @@ struct mlx5_flow_workspace*
continue;
handle_idx = dh->next.next;
- /* query counter */
- type = DR_DUMP_REC_TYPE_PMD_COUNTER;
- flow_dv_query_count_ptr(dev, flow->counter,
- &action, error);
- if (action) {
- id = (uint64_t)(uintptr_t)action;
- if (!mlx5_flow_query_counter(dev, flow, &count, error))
- save_dump_file(NULL, 0, type,
- id, (void *)&count, file);
- }
/* Get modify_hdr and encap_decap buf from ipools. */
encap_decap = NULL;
modify_hdr = dh->dvh.modify_hdr;
@@ -8438,7 +8439,7 @@ struct mlx5_flow_workspace*
*/
static int
mlx5_flow_dev_dump_sh_all(struct rte_eth_dev *dev,
- FILE *file, struct rte_flow_error *error)
+ FILE *file, struct rte_flow_error *error __rte_unused)
{
struct mlx5_priv *priv = dev->data->dev_private;
struct mlx5_dev_ctx_shared *sh = priv->sh;
@@ -8523,14 +8524,12 @@ struct mlx5_flow_workspace*
max = MLX5_COUNTERS_PER_POOL * cmng->n_valid;
for (j = 1; j <= max; j++) {
action = NULL;
- flow_dv_query_count_ptr(dev, j, &action, error);
- if (action) {
- if (!flow_dv_query_count(dev, j, &count, error)) {
- type = DR_DUMP_REC_TYPE_PMD_COUNTER;
- id = (uint64_t)(uintptr_t)action;
- save_dump_file(NULL, 0, type,
- id, (void *)&count, file);
- }
+ if ((!mlx5_counter_query(dev, j, false, &count.hits,
+ &count.bytes, &action)) && action) {
+ id = (uint64_t)(uintptr_t)action;
+ type = DR_DUMP_REC_TYPE_PMD_COUNTER;
+ save_dump_file(NULL, 0, type,
+ id, (void *)&count, file);
}
}
return 0;
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index 7fec79a..2b53961 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -1180,7 +1180,7 @@ typedef void (*mlx5_flow_counter_free_t)(struct rte_eth_dev *dev,
typedef int (*mlx5_flow_counter_query_t)(struct rte_eth_dev *dev,
uint32_t cnt,
bool clear, uint64_t *pkts,
- uint64_t *bytes);
+ uint64_t *bytes, void **action);
typedef int (*mlx5_flow_get_aged_flows_t)
(struct rte_eth_dev *dev,
void **context,
@@ -1723,11 +1723,6 @@ struct mlx5_list_entry *flow_dv_dest_array_clone_cb(void *tool_ctx,
struct mlx5_list_entry *entry, void *cb_ctx);
void flow_dv_dest_array_clone_free_cb(void *tool_ctx,
struct mlx5_list_entry *entry);
-int flow_dv_query_count_ptr(struct rte_eth_dev *dev, uint32_t cnt_idx,
- void **action, struct rte_flow_error *error);
-int
-flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
- struct rte_flow_error *error);
struct mlx5_aso_age_action *flow_aso_age_get_by_idx(struct rte_eth_dev *dev,
uint32_t age_idx);
diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c
index ef9c66e..204b045 100644
--- a/drivers/net/mlx5/mlx5_flow_dv.c
+++ b/drivers/net/mlx5/mlx5_flow_dv.c
@@ -15826,7 +15826,7 @@ struct mlx5_list_entry *
* @return
* 0 on success, a negative errno value otherwise and rte_errno is set.
*/
-int
+static int
flow_dv_query_count(struct rte_eth_dev *dev, uint32_t cnt_idx, void *data,
struct rte_flow_error *error)
{
@@ -15864,48 +15864,6 @@ struct mlx5_list_entry *
"counters are not available");
}
-
-/**
- * Query counter's action pointer for a DV flow rule via DevX.
- *
- * @param[in] dev
- * Pointer to Ethernet device.
- * @param[in] cnt_idx
- * Index to the flow counter.
- * @param[out] action_ptr
- * Action pointer for counter.
- * @param[out] error
- * Perform verbose error reporting if not NULL.
- *
- * @return
- * 0 on success, a negative errno value otherwise and rte_errno is set.
- */
-int
-flow_dv_query_count_ptr(struct rte_eth_dev *dev, uint32_t cnt_idx,
- void **action_ptr, struct rte_flow_error *error)
-{
- struct mlx5_priv *priv = dev->data->dev_private;
-
- if (!priv->sh->devx || !action_ptr)
- return rte_flow_error_set(error, ENOTSUP,
- RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
- NULL,
- "counters are not supported");
-
- if (cnt_idx) {
- struct mlx5_flow_counter *cnt = NULL;
- cnt = flow_dv_counter_get_by_idx(dev, cnt_idx, NULL);
- if (cnt) {
- *action_ptr = cnt->action;
- return 0;
- }
- }
- return rte_flow_error_set(error, EINVAL,
- RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
- NULL,
- "counters are not available");
-}
-
static int
flow_dv_action_query(struct rte_eth_dev *dev,
const struct rte_flow_action_handle *handle, void *data,
@@ -17483,7 +17441,7 @@ struct mlx5_list_entry *
*/
static int
flow_dv_counter_query(struct rte_eth_dev *dev, uint32_t counter, bool clear,
- uint64_t *pkts, uint64_t *bytes)
+ uint64_t *pkts, uint64_t *bytes, void **action)
{
struct mlx5_priv *priv = dev->data->dev_private;
struct mlx5_flow_counter *cnt;
@@ -17497,6 +17455,9 @@ struct mlx5_list_entry *
if (ret)
return -1;
cnt = flow_dv_counter_get_by_idx(dev, counter, NULL);
+ if (cnt && action)
+ *action = cnt->action;
+
*pkts = inn_pkts - cnt->hits;
*bytes = inn_bytes - cnt->bytes;
if (clear) {
diff --git a/drivers/net/mlx5/mlx5_flow_meter.c b/drivers/net/mlx5/mlx5_flow_meter.c
index 4f5de5e..b2725db 100644
--- a/drivers/net/mlx5/mlx5_flow_meter.c
+++ b/drivers/net/mlx5/mlx5_flow_meter.c
@@ -1726,7 +1726,7 @@ struct mlx5_flow_meter_policy *
memset(stats, 0, sizeof(*stats));
if (fm->drop_cnt) {
ret = mlx5_counter_query(dev, fm->drop_cnt, clear, &pkts,
- &bytes);
+ &bytes, NULL);
if (ret)
goto error;
/* If need to read the packets, set it. */
--
1.8.3.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* RE: [PATCH] net/mlx5: functions refactor for getting counter's action
2022-02-21 8:27 [PATCH] net/mlx5: functions refactor for getting counter's action Haifei Luo
@ 2022-02-23 8:51 ` Raslan Darawsheh
0 siblings, 0 replies; 2+ messages in thread
From: Raslan Darawsheh @ 2022-02-23 8:51 UTC (permalink / raw)
To: Haifei Luo, Matan Azrad, Ori Kam, Slava Ovsiienko, Shahaf Shuler
Cc: dev, NBU-Contact-Thomas Monjalon (EXTERNAL)
Hi,
> -----Original Message-----
> From: Haifei Luo <haifeil@nvidia.com>
> Sent: Monday, February 21, 2022 10:27 AM
> To: Matan Azrad <matan@nvidia.com>; Ori Kam <orika@nvidia.com>; Slava
> Ovsiienko <viacheslavo@nvidia.com>; Shahaf Shuler <shahafs@nvidia.com>
> Cc: dev@dpdk.org; NBU-Contact-Thomas Monjalon (EXTERNAL)
> <thomas@monjalon.net>; Raslan Darawsheh <rasland@nvidia.com>
> Subject: [PATCH] net/mlx5: functions refactor for getting counter's action
>
> Previously API flow_dv_query_count_ptr is defined to get counter's
> action pointer. This dv function is directly called and the better
> way is by the callback.
>
> Add one arg in API mlx5_counter_query and the related callback
> counter_query. The added arg is for counter's action pointer.
>
> Signed-off-by: Haifei Luo <haifeil@nvidia.com>
> Acked-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
Patch rebased and applied to next-net-mlx,
Kindest regards,
Raslan Darawsheh
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-02-23 8:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-21 8:27 [PATCH] net/mlx5: functions refactor for getting counter's action Haifei Luo
2022-02-23 8:51 ` Raslan Darawsheh
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).