[dpdk-dev] [PATCH v3 5/6] net/mlx5: flow counters query function move and rename

Shahaf Shuler shahafs at mellanox.com
Sun Oct 21 11:20:52 CEST 2018


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 at 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



More information about the dev mailing list