From patchwork Tue May 1 23:17:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rohit Zambre X-Patchwork-Id: 10374623 X-Patchwork-Delegate: leon@leon.nu 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 5CC0B601C7 for ; Tue, 1 May 2018 23:17:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4961922A68 for ; Tue, 1 May 2018 23:17:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D6ED24151; Tue, 1 May 2018 23:17:52 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 9ECAE22A68 for ; Tue, 1 May 2018 23:17:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751846AbeEAXRu (ORCPT ); Tue, 1 May 2018 19:17:50 -0400 Received: from mail-io0-f193.google.com ([209.85.223.193]:39508 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751747AbeEAXRu (ORCPT ); Tue, 1 May 2018 19:17:50 -0400 Received: by mail-io0-f193.google.com with SMTP id r9-v6so15371272iod.6 for ; Tue, 01 May 2018 16:17:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uci-edu.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=da3n4ptBNgsn8WrC3jJvr++hmb/iENv108S98mnZ/mw=; b=upi/5+KaiDtBHWC1NygHWh7P1BPm18MUKQBbyMLjAZSgfK3r+Fio+aUHz+4t55JEhZ jqCxwWf9ugCxdNyNh7Zk1eChH1EPdzbrP2aG5wWMCCYk+P240YYw1wfwpTF7A9Nnt1ow Ts9lkKCcr7QdRWdBQsCvBzbdilrgasYr4iLO1ZZvSdA3ss831xFoqB0EbgrDOitRX2ja sYatdIr2lMBtjb/wKJ3/s1xqUjztzd/tHS93KD4KY7YFQj2luGWIxF8e17OJHF59r7ok pDCqUioGdpxjw0otM6Yc4YXZ3vVNXDRsLxEIylMrrBhlO5m/xs7pyQYL/JKsJZBo/RbN swtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=da3n4ptBNgsn8WrC3jJvr++hmb/iENv108S98mnZ/mw=; b=X2awjetCuzspZv1znv/Hk3aFBw8JmzrkhNUcamv8Ln+ZWHrdZElu7Q9GJ9CkGKtAaR esYvFJw8qkHJVYixwdDUy/WDj838FHxUnAP3l8RBXjH/e5Tt7DZkax+kS2wXP8cvhzat BURmjLybVG+r/dDyR4Tnlg5iMkUjY/BLHlZjtMkx6tZx6KihFyKknBuGK/tU4UEHs+hv aiebIkzoinC2KR0NN1yUJIeMrBpWz+FOiWR3I4Y+JHCMpKLqV8KoAhM/EPnoX1UdStWH 9PCcAxRnyBbxc4f9fUIZhQa8IWdjozc0qNrBHfJsNkOOzTz2KHruMcwQygE6WlTs45Qs 6iEw== X-Gm-Message-State: ALQs6tABV9aCTcw7984kjxnsr1tqMDOmq3xKk728OndGNw1CBonnsoNs 14tqaXqh0qjtxRjXjoiw8tba4Q== X-Google-Smtp-Source: AB8JxZqgY812OuySo8YptNobKI3NrQ0F8iMmEHCeJhEbemi3kVjcgIBQzR2+/RPQreBXZXcUbO3uvg== X-Received: by 2002:a6b:c9d8:: with SMTP id z207-v6mr18918995iof.266.1525216669543; Tue, 01 May 2018 16:17:49 -0700 (PDT) Received: from jlselogin2.ftm.alcf.anl.gov (jlselogin2.pub.jlse.anl.gov. [140.221.96.131]) by smtp.gmail.com with ESMTPSA id f63-v6sm5154938itb.2.2018.05.01.16.17.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 May 2018 16:17:48 -0700 (PDT) From: Rohit Zambre To: dledford@redhat.com, jgg@mellanox.com Cc: linux-rdma@vger.kernel.org, balaji@anl.gov, amowli@uci.edu, Rohit Zambre Subject: [PATCH rdma-core v2 1/2] mlx5: Allow individual locking-control for different verbs objects Date: Tue, 1 May 2018 23:17:35 +0000 Message-Id: <1525216656-11549-2-git-send-email-rzambre@uci.edu> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1525216656-11549-1-git-send-email-rzambre@uci.edu> References: <1525216656-11549-1-git-send-email-rzambre@uci.edu> 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 Currently, the locks on the verbs objects can be unset only globally through the MLX5_SINGLE_THREADED environment variable. New verbs, such as ibv_alloc_td, allow the application to guarantee the access to certain verbs objects from only one user thread, eliminating the need for a lock on those objects. This patch allows the driver to toggle locking on individual verbs objects. Signed-off-by: Rohit Zambre --- providers/mlx5/mlx5.c | 4 ++-- providers/mlx5/mlx5.h | 8 +++++--- providers/mlx5/verbs.c | 12 ++++++------ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/providers/mlx5/mlx5.c b/providers/mlx5/mlx5.c index 5590241..3a3fc47 100644 --- a/providers/mlx5/mlx5.c +++ b/providers/mlx5/mlx5.c @@ -1121,7 +1121,7 @@ static struct verbs_context *mlx5_alloc_context(struct ibv_device *ibdev, context->bfs[bfi].reg = context->uar[i].reg + MLX5_ADAPTER_PAGE_SIZE * j + MLX5_BF_OFFSET + k * context->bf_reg_size; context->bfs[bfi].need_lock = need_uuar_lock(context, bfi); - mlx5_spinlock_init(&context->bfs[bfi].lock); + mlx5_spinlock_init(&context->bfs[bfi].lock, context->bfs[bfi].need_lock); context->bfs[bfi].offset = 0; if (bfi) context->bfs[bfi].buf_size = context->bf_reg_size / 2; @@ -1153,7 +1153,7 @@ static struct verbs_context *mlx5_alloc_context(struct ibv_device *ibdev, mlx5_read_env(ibdev, context); - mlx5_spinlock_init(&context->hugetlb_lock); + mlx5_spinlock_init(&context->hugetlb_lock, !mlx5_single_threaded); list_head_init(&context->hugetlb_list); verbs_set_ops(v_ctx, &mlx5_ctx_common_ops); diff --git a/providers/mlx5/mlx5.h b/providers/mlx5/mlx5.h index d3f0829..08ab610 100644 --- a/providers/mlx5/mlx5.h +++ b/providers/mlx5/mlx5.h @@ -207,6 +207,7 @@ struct mlx5_db_page; struct mlx5_spinlock { pthread_spinlock_t lock; int in_use; + int need_lock; }; enum mlx5_uar_type { @@ -844,7 +845,7 @@ static inline void *mlx5_find_uidx(struct mlx5_context *ctx, uint32_t uidx) static inline int mlx5_spin_lock(struct mlx5_spinlock *lock) { - if (!mlx5_single_threaded) + if (lock->need_lock) return pthread_spin_lock(&lock->lock); if (unlikely(lock->in_use)) { @@ -866,7 +867,7 @@ static inline int mlx5_spin_lock(struct mlx5_spinlock *lock) static inline int mlx5_spin_unlock(struct mlx5_spinlock *lock) { - if (!mlx5_single_threaded) + if (lock->need_lock) return pthread_spin_unlock(&lock->lock); lock->in_use = 0; @@ -874,9 +875,10 @@ static inline int mlx5_spin_unlock(struct mlx5_spinlock *lock) return 0; } -static inline int mlx5_spinlock_init(struct mlx5_spinlock *lock) +static inline int mlx5_spinlock_init(struct mlx5_spinlock *lock, int need_lock) { lock->in_use = 0; + lock->need_lock = need_lock; return pthread_spin_init(&lock->lock, PTHREAD_PROCESS_PRIVATE); } diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c index 6ed2c35..f05b2f3 100644 --- a/providers/mlx5/verbs.c +++ b/providers/mlx5/verbs.c @@ -645,7 +645,7 @@ static struct ibv_cq_ex *create_cq(struct ibv_context *context, memset(&cmd, 0, sizeof cmd); cq->cons_index = 0; - if (mlx5_spinlock_init(&cq->lock)) + if (mlx5_spinlock_init(&cq->lock, !mlx5_single_threaded)) goto err; ncqe = align_queue_size(cq_attr->cqe + 1); @@ -907,7 +907,7 @@ struct ibv_srq *mlx5_create_srq(struct ibv_pd *pd, ibsrq = &srq->vsrq.srq; memset(&cmd, 0, sizeof cmd); - if (mlx5_spinlock_init(&srq->lock)) { + if (mlx5_spinlock_init(&srq->lock, !mlx5_single_threaded)) { fprintf(stderr, "%s-%d:\n", __func__, __LINE__); goto err; } @@ -1751,8 +1751,8 @@ static struct ibv_qp *create_qp(struct ibv_context *context, mlx5_init_qp_indices(qp); - if (mlx5_spinlock_init(&qp->sq.lock) || - mlx5_spinlock_init(&qp->rq.lock)) + if (mlx5_spinlock_init(&qp->sq.lock, !mlx5_single_threaded) || + mlx5_spinlock_init(&qp->rq.lock, !mlx5_single_threaded)) goto err_free_qp_buf; qp->db = mlx5_alloc_dbrec(ctx); @@ -2495,7 +2495,7 @@ struct ibv_srq *mlx5_create_srq_ex(struct ibv_context *context, memset(&cmd, 0, sizeof(cmd)); memset(&resp, 0, sizeof(resp)); - if (mlx5_spinlock_init(&msrq->lock)) { + if (mlx5_spinlock_init(&msrq->lock, !mlx5_single_threaded)) { fprintf(stderr, "%s-%d:\n", __func__, __LINE__); goto err; } @@ -2799,7 +2799,7 @@ static struct ibv_wq *create_wq(struct ibv_context *context, mlx5_init_rwq_indices(rwq); - if (mlx5_spinlock_init(&rwq->rq.lock)) + if (mlx5_spinlock_init(&rwq->rq.lock, !mlx5_single_threaded)) goto err_free_rwq_buf; rwq->db = mlx5_alloc_dbrec(ctx);