From patchwork Thu Oct 27 06:59:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binoy Jayan X-Patchwork-Id: 79616 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp467717qge; Thu, 27 Oct 2016 00:00:15 -0700 (PDT) X-Received: by 10.99.233.5 with SMTP id i5mr9608283pgh.143.1477551613279; Thu, 27 Oct 2016 00:00:13 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id wp6si5248442pab.294.2016.10.27.00.00.13; Thu, 27 Oct 2016 00:00:13 -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 S935070AbcJ0G7x (ORCPT + 27 others); Thu, 27 Oct 2016 02:59:53 -0400 Received: from mail-pf0-f179.google.com ([209.85.192.179]:36051 "EHLO mail-pf0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934840AbcJ0G7p (ORCPT ); Thu, 27 Oct 2016 02:59:45 -0400 Received: by mail-pf0-f179.google.com with SMTP id e6so11864778pfk.3 for ; Wed, 26 Oct 2016 23:59:45 -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=kLRJtvhohCC29tOwdB9owSOIpaCfnMMnZRUytYle0gI=; b=GWDa18PecEeWSuPocQ8HCMYsgD6ncUSBQIaOnpOHZTVIWkxNhy+eWQ1LGG9DHLnGBn 3AtXP6c20rFoWTkfWTYrQ2xlimycdEKLRdQN9ixgMmhXdzL6L7XBpP/N0ldkjIksCIuL KyQYLIgRP6meLAb/Jr7XDKOL748k1j0HbsPRw= 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=R25Ox6tM8b2WPtMqA2bCfu7iGOCuC1k0xWZyFCOqYN4wXmXxefN473DljYdFWZ1/3c IPlsyihXOB/O5vo8FoWaNA5XbooBDyW1RzvJwOnk2XWYIjuwS8DT+BfJ77WnJ6VUkYNm /pnQyMbGFh2/0FiHbXo4wTLurYa3P/zGH0lQ6TWGgb4cdQpxAGt6OHsGaR2hzR+44st2 JGQmHQKn1+XFXOce0LCOhNLrWcBAIUokcaZtlhOKQ04nG6W64mLgp+PgCLcRMAdvEoDG roDsLWLeY9VTN98c1B6+tF6jKfmxqN7PJjhWdXueCorm9n+nTy3i53m2wMAl7Glpy1dP E5+Q== X-Gm-Message-State: ABUngvd1Mq5Jq0oUHiemw4ijs7SvrZwzcrIyECKRxWQ9YsVBj97dbU0a92FhF2ww6tF/6aAm X-Received: by 10.98.66.149 with SMTP id h21mr11618903pfd.32.1477551584516; Wed, 26 Oct 2016 23:59:44 -0700 (PDT) Received: from blr-ubuntu-59.ap.qualcomm.com ([202.46.23.61]) by smtp.gmail.com with ESMTPSA id w24sm8795544pfa.12.2016.10.26.23.59.41 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Oct 2016 23:59:44 -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 v4 07/10] IB/mthca: Replace counting semaphore event_sem with wait_event Date: Thu, 27 Oct 2016 12:29:11 +0530 Message-Id: <1477551554-30349-8-git-send-email-binoy.jayan@linaro.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1477551554-30349-1-git-send-email-binoy.jayan@linaro.org> References: <1477551554-30349-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;