From patchwork Tue Oct 25 12:01:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binoy Jayan X-Patchwork-Id: 79160 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp3072368qge; Tue, 25 Oct 2016 05:03:14 -0700 (PDT) X-Received: by 10.99.103.198 with SMTP id b189mr31760744pgc.81.1477396994563; Tue, 25 Oct 2016 05:03:14 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m17si20371477pgj.256.2016.10.25.05.03.14; Tue, 25 Oct 2016 05:03:14 -0700 (PDT) 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 S965656AbcJYMDA (ORCPT + 27 others); Tue, 25 Oct 2016 08:03:00 -0400 Received: from mail-pf0-f172.google.com ([209.85.192.172]:34028 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758762AbcJYMCa (ORCPT ); Tue, 25 Oct 2016 08:02:30 -0400 Received: by mail-pf0-f172.google.com with SMTP id n85so2147511pfi.1 for ; Tue, 25 Oct 2016 05:02:30 -0700 (PDT) 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=Yame2OyQq28sUwEi6+hi1RX549AzAyAMKQkt1GYHQvE=; b=fJNodpODAzFZdO1pRpOU9ofULQxO46BwR3wIeMXS+mExNI/nXooA2oek8lQKcdtWyS xFL5NXbys6Rz6iVCp+unFImAYazp7lKw44VSmUb11hFXjYq93QYuQcBFuFnQeZh6EDKD vkvYFnod87RoHlnIDrcEsPXhBM1VPF4FIrFXE= 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=Yame2OyQq28sUwEi6+hi1RX549AzAyAMKQkt1GYHQvE=; b=b1Vb+52ReJe+UK2aG3EvQPhdZTCvAdOZwoWB4NxUGczW2/zzhG3NJGuQ/viZ8uIocT tP0UlxG23BwT5pGYA9cycog/9a1AqOlGBlNRMA0eP5ghqs2eXpOW1D+INWiziVRz6sfH MyRTmhn5KgXUz0+xTM6qslXbj7IgBWBpy5iwV8dAYz8J1fDZ9id9v5LwaILDX5dqGq1H 8bzjuon2d1s8u0hFrIITiOxVIXhwDbKICwJaWESc459BxdjM0uWOFd0/gQZclNssPJ4U XHp4PGJgvX6rQKZvDjpN4VrpAxDi2SwMWcHeNtk5ljd8y7YO27PxvQ6wZLC4M3dZ9Xt1 VWuA== X-Gm-Message-State: ABUngvcNbV7DEan/1adPBjKhh1dJkB+2N928sv23ORR6qYkQ/+pGuiNTzJ3FBqQz9GCQ1gy8 X-Received: by 10.98.141.19 with SMTP id z19mr38959888pfd.105.1477396949485; Tue, 25 Oct 2016 05:02:29 -0700 (PDT) Received: from blr-ubuntu-59.ap.qualcomm.com ([202.46.23.61]) by smtp.gmail.com with ESMTPSA id ij5sm33051828pab.2.2016.10.25.05.02.26 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Oct 2016 05:02:29 -0700 (PDT) From: Binoy Jayan To: Doug Ledford , Sean Hefty , Hal Rosenstock Cc: Arnd Bergmann , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Binoy Jayan Subject: [PATCH v2 7/8] IB/mthca: Replace counting semaphore event_sem with wait_event Date: Tue, 25 Oct 2016 17:31:58 +0530 Message-Id: <1477396919-27669-8-git-send-email-binoy.jayan@linaro.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1477396919-27669-1-git-send-email-binoy.jayan@linaro.org> References: <1477396919-27669-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 Counting semaphores are going away in the future, so replace the semaphore mthca_cmd::event_sem with a conditional wait_event. Signed-off-by: Binoy Jayan --- drivers/infiniband/hw/mthca/mthca_cmd.c | 37 ++++++++++++++++++++++++--------- drivers/infiniband/hw/mthca/mthca_dev.h | 3 ++- 2 files changed, 29 insertions(+), 11 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/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c index 49c6e19..87c475c 100644 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c @@ -405,6 +405,26 @@ void mthca_cmd_event(struct mthca_dev *dev, complete(&context->done); } +/* Similar to atomic_cmpxchg but with the complimentary condition. Returns + * index to a free node. It also sets cmd->free_head to 'new' so it ensures + * atomicity between a call to 'wait_event' and manipulating the free_head. + */ + +static inline int atomic_free_node(struct mthca_cmd *cmd, int new) +{ + int orig; + + spin_lock(&cmd->context_lock); + + orig = cmd->free_head; + if (likely(cmd->free_head != -1)) + cmd->free_head = new; + + spin_unlock(&cmd->context_lock); + + return orig; +} + static int mthca_cmd_wait(struct mthca_dev *dev, u64 in_param, u64 *out_param, @@ -414,14 +434,14 @@ static int mthca_cmd_wait(struct mthca_dev *dev, u16 op, unsigned long timeout) { - int err = 0; + int orig_free_head, err = 0; struct mthca_cmd_context *context; - down(&dev->cmd.event_sem); + wait_event(dev->cmd.wq, + (orig_free_head = atomic_free_node(&dev->cmd, -1)) != -1); spin_lock(&dev->cmd.context_lock); - BUG_ON(dev->cmd.free_head < 0); - context = &dev->cmd.context[dev->cmd.free_head]; + context = &dev->cmd.context[orig_free_head]; context->token += dev->cmd.token_mask + 1; dev->cmd.free_head = context->next; spin_unlock(&dev->cmd.context_lock); @@ -458,8 +478,8 @@ static int mthca_cmd_wait(struct mthca_dev *dev, context->next = dev->cmd.free_head; dev->cmd.free_head = context - dev->cmd.context; spin_unlock(&dev->cmd.context_lock); + wake_up(&dev->cmd.wq); - up(&dev->cmd.event_sem); return err; } @@ -571,7 +591,7 @@ int mthca_cmd_use_events(struct mthca_dev *dev) dev->cmd.context[dev->cmd.max_cmds - 1].next = -1; dev->cmd.free_head = 0; - sema_init(&dev->cmd.event_sem, dev->cmd.max_cmds); + init_waitqueue_head(&dev->cmd.wq); spin_lock_init(&dev->cmd.context_lock); for (dev->cmd.token_mask = 1; @@ -590,12 +610,9 @@ int mthca_cmd_use_events(struct mthca_dev *dev) */ void mthca_cmd_use_polling(struct mthca_dev *dev) { - int i; - dev->cmd.flags &= ~MTHCA_CMD_USE_EVENTS; - for (i = 0; i < dev->cmd.max_cmds; ++i) - down(&dev->cmd.event_sem); + dev->cmd.free_head = -1; kfree(dev->cmd.context); } diff --git a/drivers/infiniband/hw/mthca/mthca_dev.h b/drivers/infiniband/hw/mthca/mthca_dev.h index 87ab964..2fc86db 100644 --- a/drivers/infiniband/hw/mthca/mthca_dev.h +++ b/drivers/infiniband/hw/mthca/mthca_dev.h @@ -46,6 +46,7 @@ #include #include +#include #include "mthca_provider.h" #include "mthca_doorbell.h" @@ -121,7 +122,7 @@ struct mthca_cmd { struct pci_pool *pool; struct mutex hcr_mutex; struct mutex poll_mutex; - struct semaphore event_sem; + wait_queue_head_t wq; int max_cmds; spinlock_t context_lock; int free_head;