From patchwork Fri Apr 27 04:36:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rohit Zambre X-Patchwork-Id: 10367417 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 CF880602DC for ; Fri, 27 Apr 2018 04:36:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BFF4728797 for ; Fri, 27 Apr 2018 04:36:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B462D292E4; Fri, 27 Apr 2018 04:36:31 +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 0BF4E292E3 for ; Fri, 27 Apr 2018 04:36:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751140AbeD0Eg3 (ORCPT ); Fri, 27 Apr 2018 00:36:29 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:36607 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750892AbeD0Eg3 (ORCPT ); Fri, 27 Apr 2018 00:36:29 -0400 Received: by mail-io0-f196.google.com with SMTP id d73-v6so1074888iog.3 for ; Thu, 26 Apr 2018 21:36:28 -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=11+ZIN6BX3EZ1QoRCJXsYy283uC5ozsjppTasRXvUDw=; b=IuDQK1irp1KomUDa8+UJdHaQdpuvS6EO37T8A+kYvwMcGxziUz0Qh15ErWPiiWMV5v zmKs+3Kpk1kkufSgeDlkwVf08s1mzb7LgvwChuHUnWV75EnTN0i8O9yVqSWdHktmJTYo kSd+uVEfXFyAehGKTWa4G6BwhGn0Cr33xTnsIkKi2CqcxItBMuT0p03J0B/0YGko3AIP ZtjCH7R2G2khwy8ONSFCxIx2S0g21tDymirq9f2lCKA4EfUJknatNw2Ga4W3SxYYRKrH qM/gPMDL1dWY61N/xBZHUFdtcgVqDsb/UREn/ntUFp4+Tq5XJ8WYn4NOmWdF11YNzlAH H2vA== 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=11+ZIN6BX3EZ1QoRCJXsYy283uC5ozsjppTasRXvUDw=; b=i6e5knEuYH9QVVlT8z9iGjdC6iESKACBxv5rs+HMmXrfNzBqdM70o6t6HqLpJctf4S 3+W3Hkw04wI5KQvXbPj0PvzatAmPsACNF8sWkOrzf4dUQFy6Dyyd3kyb8l6GhTlbXjMX ak7HplxH3JkQWJ68cI9QY3pKyfb7jQQEH4skSRRGSel4/nYcAxSxzzb+qZRVD0CIqk9o cREFoV1gqiTAtIemwsDH2C65AZG7QvpDZ2ZMkStdN/VQW1qLUEtqcIB6oR+3X/QsZkTT GETm/llNP9qkZ1+1rMxIJCD1ZvowkIzYr5bwe9xcIPv70ukslyTrknbvS3JxLnRPMCLu ok1Q== X-Gm-Message-State: ALQs6tAedxuD3bMopj/t8uXRL1Nzzn6Nx0iz8JCh4ca/dPS53FMo+BeP FoXABF1Fy9pnxZM3p5rn32FpHA== X-Google-Smtp-Source: AB8JxZppReh5VmoFOio3D9ASnRYxMNCD3pSyIFv0eBLX2aKKkGBKUUoDSHzoiXzJ3wYfo5fWXcs8Qw== X-Received: by 2002:a6b:268b:: with SMTP id m133-v6mr716361iom.107.1524803788311; Thu, 26 Apr 2018 21:36:28 -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 32-v6sm247321ios.26.2018.04.26.21.36.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Apr 2018 21:36:27 -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 1/2] mlx5: Allow individual locking-control for different verbs objects Date: Fri, 27 Apr 2018 04:36:14 +0000 Message-Id: <1524803775-24118-2-git-send-email-rzambre@uci.edu> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1524803775-24118-1-git-send-email-rzambre@uci.edu> References: <1524803775-24118-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..9fd765e 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);