[v3,5/6] net/mlx5: flow counters query function move and rename

Message ID 1539962470-10950-6-git-send-email-viacheslavo@mellanox.com (mailing list archive)
State Changes Requested, archived
Delegated to: Shahaf Shuler
Headers
Series net/mlx5: flow counters support for Linux-rdma v19 |

Checks

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

Commit Message

Slava Ovsiienko Oct. 19, 2018, 3:21 p.m. UTC
  The flow_verbs_query_count() is moved into the the group of counter
managing functions and renamed to flow_verbs_counter_query() in order
to be in unified fashion with others.

Also minor function modification is made to avoid unreachable code
warnings if there is no counter support at compile time.

Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
---
 drivers/net/mlx5/mlx5_flow_verbs.c | 111 +++++++++++++++++++------------------
 1 file changed, 56 insertions(+), 55 deletions(-)
  

Comments

Shahaf Shuler Oct. 21, 2018, 9:20 a.m. UTC | #1
Friday, October 19, 2018 6:21 PM, Slava Ovsiienko:
> Subject: [PATCH v3 5/6] net/mlx5: flow counters query function move and
> rename

How about: "net/mlx5: relocate flow counter query function" 

This patch should come before the glue library update

> 
> The flow_verbs_query_count() is moved into the the group of counter
> managing functions and renamed to flow_verbs_counter_query() in order to
> be in unified fashion with others.

The tcf engine has the same naming. However since you add new ones on the next commit it is OK. 
Will think if we want to rename tcf one later. 

> 
> Also minor function modification is made to avoid unreachable code warnings
> if there is no counter support at compile time.
> 
> Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
> ---
>  drivers/net/mlx5/mlx5_flow_verbs.c | 111 +++++++++++++++++++----------
> --------
>  1 file changed, 56 insertions(+), 55 deletions(-)
> 
> diff --git a/drivers/net/mlx5/mlx5_flow_verbs.c
> b/drivers/net/mlx5/mlx5_flow_verbs.c
> index 3d6fedb..f720c35 100644
> --- a/drivers/net/mlx5/mlx5_flow_verbs.c
> +++ b/drivers/net/mlx5/mlx5_flow_verbs.c
> @@ -110,6 +110,61 @@
>  }
> 
>  /**
> + * Query a flow counter via Verbs library call.
> + *
> + * @see rte_flow_query()
> + * @see rte_flow_ops
> + */
> +static int
> +flow_verbs_counter_query(struct rte_eth_dev *dev __rte_unused,
> +			 struct rte_flow *flow __rte_unused,
> +			 void *data __rte_unused,
> +			 struct rte_flow_error *error)
> +{
> +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V42
> +	if (flow->actions & MLX5_FLOW_ACTION_COUNT) {
> +		struct rte_flow_query_count *qc = data;
> +		uint64_t counters[2] = {0, 0};
> +		struct ibv_query_counter_set_attr query_cs_attr = {
> +			.cs = flow->counter->cs,
> +			.query_flags = IBV_COUNTER_SET_FORCE_UPDATE,
> +		};
> +		struct ibv_counter_set_data query_out = {
> +			.out = counters,
> +			.outlen = 2 * sizeof(uint64_t),
> +		};
> +		int err = mlx5_glue->query_counter_set(&query_cs_attr,
> +						       &query_out);
> +
> +		if (err)
> +			return rte_flow_error_set
> +				(error, err,
> +				 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
> +				 NULL,
> +				 "cannot read counter");
> +		qc->hits_set = 1;
> +		qc->bytes_set = 1;
> +		qc->hits = counters[0] - flow->counter->hits;
> +		qc->bytes = counters[1] - flow->counter->bytes;
> +		if (qc->reset) {
> +			flow->counter->hits = counters[0];
> +			flow->counter->bytes = counters[1];
> +		}
> +		return 0;
> +	}
> +	return rte_flow_error_set(error, EINVAL,
> +				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
> +				  NULL,
> +				  "flow does not have counter");
> +#else
> +	return rte_flow_error_set(error, ENOTSUP,
> +				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
> +				  NULL,
> +				  "counters are not available");
> +#endif
> +}
> +
> +/**
>   * Add a verbs item specification into @p flow.
>   *
>   * @param[in, out] flow
> @@ -1654,60 +1709,6 @@
>  }
> 
>  /**
> - * Query a flows.
> - *
> - * @see rte_flow_query()
> - * @see rte_flow_ops
> - */
> -static int
> -flow_verbs_query_count(struct rte_eth_dev *dev __rte_unused,
> -		       struct rte_flow *flow __rte_unused,
> -		       void *data __rte_unused,
> -		       struct rte_flow_error *error)
> -{
> -#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V42
> -	if (flow->actions & MLX5_FLOW_ACTION_COUNT) {
> -		struct rte_flow_query_count *qc = data;
> -		uint64_t counters[2] = {0, 0};
> -		struct ibv_query_counter_set_attr query_cs_attr = {
> -			.cs = flow->counter->cs,
> -			.query_flags = IBV_COUNTER_SET_FORCE_UPDATE,
> -		};
> -		struct ibv_counter_set_data query_out = {
> -			.out = counters,
> -			.outlen = 2 * sizeof(uint64_t),
> -		};
> -		int err = mlx5_glue->query_counter_set(&query_cs_attr,
> -						       &query_out);
> -
> -		if (err)
> -			return rte_flow_error_set
> -				(error, err,
> -				 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
> -				 NULL,
> -				 "cannot read counter");
> -		qc->hits_set = 1;
> -		qc->bytes_set = 1;
> -		qc->hits = counters[0] - flow->counter->hits;
> -		qc->bytes = counters[1] - flow->counter->bytes;
> -		if (qc->reset) {
> -			flow->counter->hits = counters[0];
> -			flow->counter->bytes = counters[1];
> -		}
> -		return 0;
> -	}
> -	return rte_flow_error_set(error, EINVAL,
> -				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
> -				  NULL,
> -				  "flow does not have counter");
> -#endif
> -	return rte_flow_error_set(error, ENOTSUP,
> -				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
> -				  NULL,
> -				  "counters are not available");
> -}
> -
> -/**
>   * Query a flow.
>   *
>   * @see rte_flow_query()
> @@ -1727,7 +1728,7 @@
>  		case RTE_FLOW_ACTION_TYPE_VOID:
>  			break;
>  		case RTE_FLOW_ACTION_TYPE_COUNT:
> -			ret = flow_verbs_query_count(dev, flow, data,
> error);
> +			ret = flow_verbs_counter_query(dev, flow, data,
> error);
>  			break;
>  		default:
>  			return rte_flow_error_set(error, ENOTSUP,
> --
> 1.8.3.1
  

Patch

diff --git a/drivers/net/mlx5/mlx5_flow_verbs.c b/drivers/net/mlx5/mlx5_flow_verbs.c
index 3d6fedb..f720c35 100644
--- a/drivers/net/mlx5/mlx5_flow_verbs.c
+++ b/drivers/net/mlx5/mlx5_flow_verbs.c
@@ -110,6 +110,61 @@ 
 }
 
 /**
+ * Query a flow counter via Verbs library call.
+ *
+ * @see rte_flow_query()
+ * @see rte_flow_ops
+ */
+static int
+flow_verbs_counter_query(struct rte_eth_dev *dev __rte_unused,
+			 struct rte_flow *flow __rte_unused,
+			 void *data __rte_unused,
+			 struct rte_flow_error *error)
+{
+#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V42
+	if (flow->actions & MLX5_FLOW_ACTION_COUNT) {
+		struct rte_flow_query_count *qc = data;
+		uint64_t counters[2] = {0, 0};
+		struct ibv_query_counter_set_attr query_cs_attr = {
+			.cs = flow->counter->cs,
+			.query_flags = IBV_COUNTER_SET_FORCE_UPDATE,
+		};
+		struct ibv_counter_set_data query_out = {
+			.out = counters,
+			.outlen = 2 * sizeof(uint64_t),
+		};
+		int err = mlx5_glue->query_counter_set(&query_cs_attr,
+						       &query_out);
+
+		if (err)
+			return rte_flow_error_set
+				(error, err,
+				 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				 NULL,
+				 "cannot read counter");
+		qc->hits_set = 1;
+		qc->bytes_set = 1;
+		qc->hits = counters[0] - flow->counter->hits;
+		qc->bytes = counters[1] - flow->counter->bytes;
+		if (qc->reset) {
+			flow->counter->hits = counters[0];
+			flow->counter->bytes = counters[1];
+		}
+		return 0;
+	}
+	return rte_flow_error_set(error, EINVAL,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL,
+				  "flow does not have counter");
+#else
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL,
+				  "counters are not available");
+#endif
+}
+
+/**
  * Add a verbs item specification into @p flow.
  *
  * @param[in, out] flow
@@ -1654,60 +1709,6 @@ 
 }
 
 /**
- * Query a flows.
- *
- * @see rte_flow_query()
- * @see rte_flow_ops
- */
-static int
-flow_verbs_query_count(struct rte_eth_dev *dev __rte_unused,
-		       struct rte_flow *flow __rte_unused,
-		       void *data __rte_unused,
-		       struct rte_flow_error *error)
-{
-#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V42
-	if (flow->actions & MLX5_FLOW_ACTION_COUNT) {
-		struct rte_flow_query_count *qc = data;
-		uint64_t counters[2] = {0, 0};
-		struct ibv_query_counter_set_attr query_cs_attr = {
-			.cs = flow->counter->cs,
-			.query_flags = IBV_COUNTER_SET_FORCE_UPDATE,
-		};
-		struct ibv_counter_set_data query_out = {
-			.out = counters,
-			.outlen = 2 * sizeof(uint64_t),
-		};
-		int err = mlx5_glue->query_counter_set(&query_cs_attr,
-						       &query_out);
-
-		if (err)
-			return rte_flow_error_set
-				(error, err,
-				 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
-				 NULL,
-				 "cannot read counter");
-		qc->hits_set = 1;
-		qc->bytes_set = 1;
-		qc->hits = counters[0] - flow->counter->hits;
-		qc->bytes = counters[1] - flow->counter->bytes;
-		if (qc->reset) {
-			flow->counter->hits = counters[0];
-			flow->counter->bytes = counters[1];
-		}
-		return 0;
-	}
-	return rte_flow_error_set(error, EINVAL,
-				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
-				  NULL,
-				  "flow does not have counter");
-#endif
-	return rte_flow_error_set(error, ENOTSUP,
-				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
-				  NULL,
-				  "counters are not available");
-}
-
-/**
  * Query a flow.
  *
  * @see rte_flow_query()
@@ -1727,7 +1728,7 @@ 
 		case RTE_FLOW_ACTION_TYPE_VOID:
 			break;
 		case RTE_FLOW_ACTION_TYPE_COUNT:
-			ret = flow_verbs_query_count(dev, flow, data, error);
+			ret = flow_verbs_counter_query(dev, flow, data, error);
 			break;
 		default:
 			return rte_flow_error_set(error, ENOTSUP,