From: Raed Salem <raeds@xxxxxxxxxxxx> Add support for counters create/destroy methods. It uses the ioctl API to call the kernel to accomplish those tasks. Signed-off-by: Raed Salem <raeds@xxxxxxxxxxxx> Signed-off-by: Yishai Hadas <yishaih@xxxxxxxxxxxx> --- providers/mlx5/mlx5.c | 2 ++ providers/mlx5/mlx5.h | 14 ++++++++++++++ providers/mlx5/verbs.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/providers/mlx5/mlx5.c b/providers/mlx5/mlx5.c index 7505540..23855ac 100644 --- a/providers/mlx5/mlx5.c +++ b/providers/mlx5/mlx5.c @@ -119,6 +119,7 @@ static const struct verbs_context_ops mlx5_ctx_common_ops = { .alloc_parent_domain = mlx5_alloc_parent_domain, .alloc_td = mlx5_alloc_td, .close_xrcd = mlx5_close_xrcd, + .create_counters = mlx5_create_counters, .create_cq_ex = mlx5_create_cq_ex, .create_flow = mlx5_create_flow, .create_flow_action_esp = mlx5_create_flow_action_esp, @@ -127,6 +128,7 @@ static const struct verbs_context_ops mlx5_ctx_common_ops = { .create_srq_ex = mlx5_create_srq_ex, .create_wq = mlx5_create_wq, .dealloc_td = mlx5_dealloc_td, + .destroy_counters = mlx5_destroy_counters, .destroy_flow = mlx5_destroy_flow, .destroy_flow_action = mlx5_destroy_flow_action, .destroy_rwq_ind_table = mlx5_destroy_rwq_ind_table, diff --git a/providers/mlx5/mlx5.h b/providers/mlx5/mlx5.h index ca902a6..5f789f4 100644 --- a/providers/mlx5/mlx5.h +++ b/providers/mlx5/mlx5.h @@ -535,6 +535,10 @@ struct mlx5_rwq { int wq_sig; }; +struct mlx5_counters { + struct verbs_counters vcounters; +}; + static inline int mlx5_ilog2(int n) { int t; @@ -665,6 +669,11 @@ static inline struct mlx5_rwq *rsc_to_mrwq(struct mlx5_resource *rsc) return (struct mlx5_rwq *)rsc; } +static inline struct mlx5_counters *to_mcounters(struct ibv_counters *ibcounters) +{ + return container_of(ibcounters, struct mlx5_counters, vcounters.counters); +} + int mlx5_alloc_buf(struct mlx5_buf *buf, size_t size, int page_size); void mlx5_free_buf(struct mlx5_buf *buf); int mlx5_alloc_buf_contig(struct mlx5_context *mctx, struct mlx5_buf *buf, @@ -833,6 +842,11 @@ struct ibv_pd *mlx5_alloc_parent_domain(struct ibv_context *context, void *mlx5_mmap(struct mlx5_uar_info *uar, int index, int cmd_fd, int page_size, int uar_type); + +struct ibv_counters *mlx5_create_counters(struct ibv_context *context, + struct ibv_counters_init_attr *init_attr); +int mlx5_destroy_counters(struct ibv_counters *counters); + static inline void *mlx5_find_uidx(struct mlx5_context *ctx, uint32_t uidx) { int tind = uidx >> MLX5_UIDX_TABLE_SHIFT; diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c index 851493c..d1f350a 100644 --- a/providers/mlx5/verbs.c +++ b/providers/mlx5/verbs.c @@ -3235,6 +3235,49 @@ int mlx5_free_dm(struct ibv_dm *ibdm) munmap(dm->mmap_va, act_size); free(dm); + return 0; +} + +struct ibv_counters *mlx5_create_counters(struct ibv_context *context, + struct ibv_counters_init_attr *init_attr) +{ + struct mlx5_counters *mcntrs; + int ret; + + if (!check_comp_mask(init_attr->comp_mask, 0)) { + errno = EOPNOTSUPP; + return NULL; + } + + mcntrs = calloc(1, sizeof(*mcntrs)); + if (!mcntrs) { + errno = ENOMEM; + return NULL; + } + + ret = ibv_cmd_create_counters(context, + init_attr, + &mcntrs->vcounters, + NULL); + if (ret) + goto err_create; + + return &mcntrs->vcounters.counters; + +err_create: + free(mcntrs); + return NULL; +} + +int mlx5_destroy_counters(struct ibv_counters *counters) +{ + struct mlx5_counters *mcntrs = to_mcounters(counters); + int ret; + + ret = ibv_cmd_destroy_counters(&mcntrs->vcounters); + if (ret) + return ret; + free(mcntrs); return 0; } -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html