From patchwork Thu May 17 10:39:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 10406325 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 43BAD60230 for ; Thu, 17 May 2018 10:40:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C0AE28A78 for ; Thu, 17 May 2018 10:40:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2940B28AB7; Thu, 17 May 2018 10:40:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6847F28A7E for ; Thu, 17 May 2018 10:40:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751804AbeEQKkI (ORCPT ); Thu, 17 May 2018 06:40:08 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:45005 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751734AbeEQKkD (ORCPT ); Thu, 17 May 2018 06:40:03 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 17 May 2018 13:41:47 +0300 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [10.7.2.17]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w4HAduJI002342; Thu, 17 May 2018 13:39:56 +0300 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [127.0.0.1]) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8) with ESMTP id w4HAdunL032413; Thu, 17 May 2018 13:39:56 +0300 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id w4HAduj1032412; Thu, 17 May 2018 13:39:56 +0300 From: Yishai Hadas To: linux-rdma@vger.kernel.org Cc: yishaih@mellanox.com, raeds@mellanox.com Subject: [PATCH rdma-core 08/11] mlx5: Add support for counters create/destroy Date: Thu, 17 May 2018 13:39:34 +0300 Message-Id: <1526553577-32273-9-git-send-email-yishaih@mellanox.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1526553577-32273-1-git-send-email-yishaih@mellanox.com> References: <1526553577-32273-1-git-send-email-yishaih@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Raed Salem 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 Signed-off-by: Yishai Hadas --- 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; }