From patchwork Thu May 17 10:39:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 10406319 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 1CBDC602C2 for ; Thu, 17 May 2018 10:40:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A23028A9D for ; Thu, 17 May 2018 10:40:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04BB628A7D; Thu, 17 May 2018 10:40:14 +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 5CFBC28A7D for ; Thu, 17 May 2018 10:40:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751595AbeEQKkI (ORCPT ); Thu, 17 May 2018 06:40:08 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:45006 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751698AbeEQKkD (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 w4HAdu2I002345; 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 w4HAdunh032422; 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 w4HAduLS032421; 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 09/11] mlx5: Add support for counters attach point flow Date: Thu, 17 May 2018 13:39:35 +0300 Message-Id: <1526553577-32273-10-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 Attach individual counter description definition to a flow object at specific index location. Downstream patches will add support for read counters. Signed-off-by: Raed Salem Signed-off-by: Yishai Hadas --- providers/mlx5/mlx5.c | 1 + providers/mlx5/mlx5.h | 12 ++++++++++++ providers/mlx5/verbs.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/providers/mlx5/mlx5.c b/providers/mlx5/mlx5.c index 23855ac..24a69f3 100644 --- a/providers/mlx5/mlx5.c +++ b/providers/mlx5/mlx5.c @@ -118,6 +118,7 @@ static const struct verbs_context_ops mlx5_ctx_common_ops = { .alloc_dm = mlx5_alloc_dm, .alloc_parent_domain = mlx5_alloc_parent_domain, .alloc_td = mlx5_alloc_td, + .attach_counters_point_flow = mlx5_attach_counters_point_flow, .close_xrcd = mlx5_close_xrcd, .create_counters = mlx5_create_counters, .create_cq_ex = mlx5_create_cq_ex, diff --git a/providers/mlx5/mlx5.h b/providers/mlx5/mlx5.h index 5f789f4..c975dff 100644 --- a/providers/mlx5/mlx5.h +++ b/providers/mlx5/mlx5.h @@ -535,8 +535,17 @@ struct mlx5_rwq { int wq_sig; }; +struct mlx5_counter_node { + uint32_t index; + struct list_node entry; + enum ibv_counter_description desc; +}; + struct mlx5_counters { struct verbs_counters vcounters; + struct list_head counters_list; + pthread_mutex_t lock; + uint32_t ncounters; }; static inline int mlx5_ilog2(int n) @@ -846,6 +855,9 @@ void *mlx5_mmap(struct mlx5_uar_info *uar, int index, 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); +int mlx5_attach_counters_point_flow(struct ibv_counters *counters, + struct ibv_counter_attach_attr *attr, + struct ibv_flow *flow); static inline void *mlx5_find_uidx(struct mlx5_context *ctx, uint32_t uidx) { diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c index d1f350a..780f093 100644 --- a/providers/mlx5/verbs.c +++ b/providers/mlx5/verbs.c @@ -3255,6 +3255,7 @@ struct ibv_counters *mlx5_create_counters(struct ibv_context *context, return NULL; } + pthread_mutex_init(&mcntrs->lock, NULL); ret = ibv_cmd_create_counters(context, init_attr, &mcntrs->vcounters, @@ -3262,6 +3263,8 @@ struct ibv_counters *mlx5_create_counters(struct ibv_context *context, if (ret) goto err_create; + list_head_init(&mcntrs->counters_list); + return &mcntrs->vcounters.counters; err_create: @@ -3272,12 +3275,51 @@ err_create: int mlx5_destroy_counters(struct ibv_counters *counters) { struct mlx5_counters *mcntrs = to_mcounters(counters); + struct mlx5_counter_node *tmp, *cntrs_node; int ret; ret = ibv_cmd_destroy_counters(&mcntrs->vcounters); if (ret) return ret; + list_for_each_safe(&mcntrs->counters_list, cntrs_node, tmp, entry) { + list_del(&cntrs_node->entry); + free(cntrs_node); + } + free(mcntrs); return 0; } + +int mlx5_attach_counters_point_flow(struct ibv_counters *counters, + struct ibv_counter_attach_attr *attr, + struct ibv_flow *flow) +{ + struct mlx5_counters *mcntrs = to_mcounters(counters); + struct mlx5_counter_node *cntrs_node; + + /* The driver supports only the static binding mode as part of ibv_create_flow */ + if (flow) + return ENOTSUP; + + if (!check_comp_mask(attr->comp_mask, 0)) + return EOPNOTSUPP; + + /* Check whether the attached counter is supported */ + if (attr->counter_desc < IBV_COUNTER_PACKETS || + attr->counter_desc > IBV_COUNTER_BYTES) + return ENOTSUP; + + cntrs_node = calloc(1, sizeof(*cntrs_node)); + if (!cntrs_node) + return ENOMEM; + + cntrs_node->index = attr->index; + cntrs_node->desc = attr->counter_desc; + pthread_mutex_lock(&mcntrs->lock); + list_add(&mcntrs->counters_list, &cntrs_node->entry); + mcntrs->ncounters++; + pthread_mutex_unlock(&mcntrs->lock); + + return 0; +}