From patchwork Mon Nov 21 06:08:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binoy Jayan X-Patchwork-Id: 83178 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp1324881qge; Sun, 20 Nov 2016 22:09:40 -0800 (PST) X-Received: by 10.129.31.214 with SMTP id f205mr13347840ywf.267.1479708580434; Sun, 20 Nov 2016 22:09:40 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d60si4308884ybi.179.2016.11.20.22.09.39; Sun, 20 Nov 2016 22:09:40 -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 S1753483AbcKUGJd (ORCPT + 26 others); Mon, 21 Nov 2016 01:09:33 -0500 Received: from mail-pf0-f175.google.com ([209.85.192.175]:34121 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753437AbcKUGJb (ORCPT ); Mon, 21 Nov 2016 01:09:31 -0500 Received: by mail-pf0-f175.google.com with SMTP id c4so50627622pfb.1 for ; Sun, 20 Nov 2016 22:09:30 -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=kLRJtvhohCC29tOwdB9owSOIpaCfnMMnZRUytYle0gI=; b=DyIv5kFbG0UsTa1RzuVJ6QkPUONb6WbX07KK1wlj+jTOAe1VKzys4174IuVjHkz1Sv JgyQHlKRdJuRwHVf/3L1MDeTnQ936UBuWywFbBAEw8umE+BdxuTwEIxqZ9zYPN7DQEJw fHuH4fbzajY3mOVWJDeqhfA1GhZv7EgFGaWtA= 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=kLRJtvhohCC29tOwdB9owSOIpaCfnMMnZRUytYle0gI=; b=FSnctcpg924AUg/oYjklXYttX1iL/6FvLsPgzbxQEk6AzvrZ1g10tXy+eYOx+B9soV a6vkxGaSGkjEWsEcceLarF5Fjws7BR2qv83P2aqMidJ/21T0cfyxTbUHTbNqaO2goDmC CealQO5EThY6rZjZ04XevhSp3iu/hFabOeewLwXhYZrPLZSkB3kx/AkwKZtf5BYB6WCN hEHxyOUAVOR5M8qjwssjTshoqS2q2IbwETVpspcfzp1C8tIDbNvGEofJq9bBnMTEh27u LIWFOneOdhEZRbZeUwxOxML6pWUCYaT2PCGqTWcXR05N9O8iLvLDNeS5Tu2nrId9xodS XJ1w== X-Gm-Message-State: AKaTC02QpIAcWg5KHASbTmLBa8aYcLT8dqfBJjZnsYb+SyQ+urqfCGgMZ/M03nWUbuqsSDp5 X-Received: by 10.99.171.65 with SMTP id k1mr28303117pgp.87.1479708570235; Sun, 20 Nov 2016 22:09:30 -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.23 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 20 Nov 2016 22:09:29 -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 7/9] IB/mthca: Replace counting semaphore event_sem with wait_event Date: Mon, 21 Nov 2016 11:38:14 +0530 Message-Id: <1479708496-9828-8-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 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 | 47 ++++++++++++++++++++++----------- drivers/infiniband/hw/mthca/mthca_dev.h | 3 ++- 2 files changed, 34 insertions(+), 16 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..d6a048a 100644 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c @@ -405,6 +405,34 @@ void mthca_cmd_event(struct mthca_dev *dev, complete(&context->done); } +static inline struct mthca_cmd_context * +mthca_try_get_context(struct mthca_cmd *cmd) +{ + struct mthca_cmd_context *context = NULL; + + spin_lock(&cmd->context_lock); + + if (cmd->free_head < 0) + goto out; + + context = &cmd->context[cmd->free_head]; + context->token += cmd->token_mask + 1; + cmd->free_head = context->next; +out: + spin_unlock(&cmd->context_lock); + return context; +} + +/* wait for and acquire a free context */ +static inline struct mthca_cmd_context * +mthca_get_free_context(struct mthca_cmd *cmd) +{ + struct mthca_cmd_context *context; + + wait_event(cmd->wq, (context = mthca_try_get_context(cmd))); + return context; +} + static int mthca_cmd_wait(struct mthca_dev *dev, u64 in_param, u64 *out_param, @@ -417,15 +445,7 @@ static int mthca_cmd_wait(struct mthca_dev *dev, int err = 0; struct mthca_cmd_context *context; - down(&dev->cmd.event_sem); - - spin_lock(&dev->cmd.context_lock); - BUG_ON(dev->cmd.free_head < 0); - context = &dev->cmd.context[dev->cmd.free_head]; - context->token += dev->cmd.token_mask + 1; - dev->cmd.free_head = context->next; - spin_unlock(&dev->cmd.context_lock); - + context = mthca_get_free_context(&dev->cmd); init_completion(&context->done); err = mthca_cmd_post(dev, in_param, @@ -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;