From patchwork Mon Nov 21 06:08:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binoy Jayan X-Patchwork-Id: 83180 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp1325017qge; Sun, 20 Nov 2016 22:10:03 -0800 (PST) X-Received: by 10.13.247.65 with SMTP id h62mr12273119ywf.56.1479708603166; Sun, 20 Nov 2016 22:10:03 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g66si4307337ywd.153.2016.11.20.22.10.01; Sun, 20 Nov 2016 22:10:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753550AbcKUGJu (ORCPT + 26 others); Mon, 21 Nov 2016 01:09:50 -0500 Received: from mail-pf0-f169.google.com ([209.85.192.169]:34927 "EHLO mail-pf0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753521AbcKUGJp (ORCPT ); Mon, 21 Nov 2016 01:09:45 -0500 Received: by mail-pf0-f169.google.com with SMTP id i88so62387499pfk.2 for ; Sun, 20 Nov 2016 22:09:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=A/yzFnL4RnGJFONXv+2bRe3pxbzX2qMzdJto8elzBqE=; b=H932YXKWyOM0HAkDy3kM9HgubP8/UpVJhy+KCaqW3HaebuqhCxQ96fK1x88yM6tLnM MGbTJGAr7zLiNu0ZtHibUMY82kWYkrp+1RvZWk38aAz5EQGZG4dqVVKQb8CZgLstPxbw CzbagCeGDBeQKsfqsz9v5pW4RHS/BecjYG9xc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=A/yzFnL4RnGJFONXv+2bRe3pxbzX2qMzdJto8elzBqE=; b=bWqUSw9lPrbvj0IcpYkQEPzSm++RJh388Cagsby2B5y+FeoK4VEmdtn9Ed3dGDaiE1 34LLCbgOk503O6ZAe0Ip/Xtj5nlIzGzApHZcD/6FzPfHMlfPwrOuKNtLOfoVIEv8xoxO pFcwhEY6VGV3MML3W7H8Q+HMsporVxsGnlo+B1rtEynKhrLGLQewHWC6bxmhk3uSkGi0 Hyui8dilA1bOiPYpheeZVyrHkl6qRX/sHrfmDp0B6LMR/t1ZCBE2wBSHyg5qCVdXAQEY tYs5yVKTYsfstrFW/WsZVBDztzdLtwN2KXBj6yv49cLVv6r2WlR6DlY3HTRujZ8v+5mp K/0w== X-Gm-Message-State: AKaTC031sdBTPjzvx8WOVOhJ92IIGno3Q9nfm+reoiICCoJL7mWAfisi46yDJi+v/bVooR+1 X-Received: by 10.99.126.94 with SMTP id o30mr28496251pgn.66.1479708584308; Sun, 20 Nov 2016 22:09:44 -0800 (PST) Received: from blr-ubuntu-59.ap.qualcomm.com ([202.46.23.61]) by smtp.gmail.com with ESMTPSA id 74sm16068432pge.2.2016.11.20.22.09.37 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 20 Nov 2016 22:09:43 -0800 (PST) From: Binoy Jayan To: Doug Ledford , Sean Hefty , Sagi Grimberg , Hal Rosenstock , Leon Romanovsky , Sagi Grimberg , Bart Van Assche , Nicholas Bellinger , Jenny Derzhavetz , Ira Weiny , Steve Wise , Mark Bloch , Tatyana E Nikolova , Matan Barak , Lijun Ou , "Wei Hu(Xavier)" Cc: Faisal Latif , Mustafa Ismail , Mark Brown , Arnd Bergmann , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, target-devel@vger.kernel.org, Binoy Jayan Subject: [PATCH v5 9/9] IB/mlx5: Replace semaphore umr_common:sem with wait_event Date: Mon, 21 Nov 2016 11:38:16 +0530 Message-Id: <1479708496-9828-10-git-send-email-binoy.jayan@linaro.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1479708496-9828-1-git-send-email-binoy.jayan@linaro.org> References: <1479708496-9828-1-git-send-email-binoy.jayan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Remove semaphore umr_common:sem used to limit concurrent access to umr qp and introduce an atomic value 'users' to keep track of the same. Use a wait_event to block when the limit is reached. Signed-off-by: Binoy Jayan --- drivers/infiniband/hw/mlx5/main.c | 6 +----- drivers/infiniband/hw/mlx5/mlx5_ib.h | 7 ++++++- drivers/infiniband/hw/mlx5/mr.c | 6 ++++-- 3 files changed, 11 insertions(+), 8 deletions(-) -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c index 63036c7..9de716c 100644 --- a/drivers/infiniband/hw/mlx5/main.c +++ b/drivers/infiniband/hw/mlx5/main.c @@ -2437,10 +2437,6 @@ static void destroy_umrc_res(struct mlx5_ib_dev *dev) ib_dealloc_pd(dev->umrc.pd); } -enum { - MAX_UMR_WR = 128, -}; - static int create_umr_res(struct mlx5_ib_dev *dev) { struct ib_qp_init_attr *init_attr = NULL; @@ -2520,7 +2516,7 @@ static int create_umr_res(struct mlx5_ib_dev *dev) dev->umrc.cq = cq; dev->umrc.pd = pd; - sema_init(&dev->umrc.sem, MAX_UMR_WR); + init_waitqueue_head(&dev->umrc.wq); ret = mlx5_mr_cache_init(dev); if (ret) { mlx5_ib_warn(dev, "mr cache init failed %d\n", ret); diff --git a/drivers/infiniband/hw/mlx5/mlx5_ib.h b/drivers/infiniband/hw/mlx5/mlx5_ib.h index dcdcd19..de31b5f 100644 --- a/drivers/infiniband/hw/mlx5/mlx5_ib.h +++ b/drivers/infiniband/hw/mlx5/mlx5_ib.h @@ -533,7 +533,12 @@ struct umr_common { struct ib_qp *qp; /* control access to UMR QP */ - struct semaphore sem; + wait_queue_head_t wq; + atomic_t users; +}; + +enum { + MAX_UMR_WR = 128, }; enum { diff --git a/drivers/infiniband/hw/mlx5/mr.c b/drivers/infiniband/hw/mlx5/mr.c index 1593856..dfaf6f6 100644 --- a/drivers/infiniband/hw/mlx5/mr.c +++ b/drivers/infiniband/hw/mlx5/mr.c @@ -867,7 +867,8 @@ static inline int mlx5_ib_post_send_wait(struct mlx5_ib_dev *dev, mlx5_ib_init_umr_context(&umr_context); umrwr->wr.wr_cqe = &umr_context.cqe; - down(&umrc->sem); + /* limit number of concurrent ib_post_send() on qp */ + wait_event(umrc->wq, atomic_add_unless(&umrc->users, 1, MAX_UMR_WR)); err = ib_post_send(umrc->qp, &umrwr->wr, &bad); if (err) { mlx5_ib_warn(dev, "UMR post send failed, err %d\n", err); @@ -879,7 +880,8 @@ static inline int mlx5_ib_post_send_wait(struct mlx5_ib_dev *dev, err = -EFAULT; } } - up(&umrc->sem); + atomic_dec(&umrc->users); + wake_up(&umrc->wq); return err; }