From patchwork Wed Oct 26 08:01:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binoy Jayan X-Patchwork-Id: 79351 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp279722qge; Wed, 26 Oct 2016 01:03:51 -0700 (PDT) X-Received: by 10.98.204.145 with SMTP id j17mr1793910pfk.83.1477469031156; Wed, 26 Oct 2016 01:03:51 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n67si1303402pga.91.2016.10.26.01.03.50; Wed, 26 Oct 2016 01:03:51 -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 S1754652AbcJZIDr (ORCPT + 27 others); Wed, 26 Oct 2016 04:03:47 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:35933 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934704AbcJZIBo (ORCPT ); Wed, 26 Oct 2016 04:01:44 -0400 Received: by mail-pf0-f177.google.com with SMTP id e6so135274288pfk.3 for ; Wed, 26 Oct 2016 01:01:44 -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=kooXkOQYSd1I5j9iyhDWefNxS6R25e/G8XZw9+bX9FA=; b=b22l6JgDBkW0ojFSaj5r5eK3nOx4smNYQE7tmXcKqPbbioQx/+qERwosRzsAGx8ISI +GmLjlFTy1rRIhayZZHEWQAZm+6bNlLoLA7HtrVOPQlnzA7p4w1R5Tv3z4+VlpxIGqMk WDxjSqyXh2DaR3TL+VOuFxBbc1Nq58S8aT/n4= 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=kooXkOQYSd1I5j9iyhDWefNxS6R25e/G8XZw9+bX9FA=; b=M9d+b8NEl7p3qVoKv5WQoFyc03qJa+ZxHGgz3VyAqCmJF2Ti6tlqa3i7vkUf9RiW7E LkfIgJ4F63RuYvJNcHj29HUMnr565HhqMxRWIqJsWIo9qMrCg9ZepolXrYb8AxhKTS3g 3K9F6ziGjOfDPIO7YtCJNorXQSTazEri/xHNHB/5mhNvz77zT+7l0svBapgdn1/ifTAU 80x9K4kN6K7LtJXqXAb8YBRJultsg7wlIW6HUv3jnrDsO/3DY3p+KhhpgzfbpI2cT7Hv swUcK1nSAI+V7wRJSouLs1xmUIqYJKkJrWNwXlYleiMQXTTJlEiGwkUos1SSTbo2O0zj 9ZLg== X-Gm-Message-State: ABUngvcFfDY5n3Pz9t1WqOVl093/NEHojqvXm/JmxiPVdTuhrfuCJl1eLa9K3elTuObUTG6/ X-Received: by 10.99.104.195 with SMTP id d186mr1560075pgc.26.1477468903944; Wed, 26 Oct 2016 01:01:43 -0700 (PDT) Received: from blr-ubuntu-59.ap.qualcomm.com ([202.46.23.61]) by smtp.gmail.com with ESMTPSA id 74sm2011923pfp.77.2016.10.26.01.01.41 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Oct 2016 01:01:43 -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 v3 7/9] IB/mthca: Replace counting semaphore event_sem with wait_event Date: Wed, 26 Oct 2016 13:31:12 +0530 Message-Id: <1477468874-16328-8-git-send-email-binoy.jayan@linaro.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1477468874-16328-1-git-send-email-binoy.jayan@linaro.org> References: <1477468874-16328-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 | 45 ++++++++++++++++++++++----------- drivers/infiniband/hw/mthca/mthca_dev.h | 3 ++- 2 files changed, 32 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..fab5509 100644 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c @@ -405,6 +405,32 @@ 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 +443,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 +476,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 +589,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 +608,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;