From patchwork Mon Oct 17 16:31:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binoy Jayan X-Patchwork-Id: 77773 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp476977qge; Mon, 17 Oct 2016 09:32:44 -0700 (PDT) X-Received: by 10.99.4.141 with SMTP id 135mr32434381pge.175.1476721964784; Mon, 17 Oct 2016 09:32:44 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h19si28143238pgn.301.2016.10.17.09.32.42; Mon, 17 Oct 2016 09:32:44 -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 S936005AbcJQQc0 (ORCPT + 27 others); Mon, 17 Oct 2016 12:32:26 -0400 Received: from mail-pf0-f179.google.com ([209.85.192.179]:36086 "EHLO mail-pf0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936072AbcJQQb6 (ORCPT ); Mon, 17 Oct 2016 12:31:58 -0400 Received: by mail-pf0-f179.google.com with SMTP id e6so80836634pfk.3 for ; Mon, 17 Oct 2016 09:31:57 -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=BauJubAcomqseDUqFXnZFebh9+pT4aNTbU5RI9hlC/o=; b=hWuhE32GOqNd42VgecaFQKJbZbpSLIaGv5iWlisuCA19O3u6dEB0tPpodjV80nQwda /cqeq3WT/zEcKpuuVVKxN2smJCreiMSsBj9pcUE3vW+ly8SjdTOAbkL6iOctipgqG5PI BpHaHXPpGDQqOoOiXPeu9q75irkugpu/3cclA= 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=BauJubAcomqseDUqFXnZFebh9+pT4aNTbU5RI9hlC/o=; b=NGhKWZpBmPCWLPqeM94KFAiuTJ6cuo1hnRvhaJfjmFO4TOlBbc2G1ZaAG3WP6PddQJ 6LtFTx4I1e9OiAHvx/5lfqMRrlXJipL1TiXj76WiCawtkMFEDgyc+aWi/WiEAxkYRFQz ifpdc7DFh15JYlxScdDhqCTu7Nb8ACJKsSyx7UoQKObKbydaWWe8zbGvKV/hs4xk56qb cA7RH2elMHWvOxT0ljKzVpgDv/w9n5X0rWof0y15RMVsqeTcA01n+lBZelvyn+ig1fal Tk3IEy9LZQDwVbTpNdRkzuEN9Gfnyxt5s6zu3erpPvdxsEsp17EluSIz8d2TPgNoejzf 4VGQ== X-Gm-Message-State: AA6/9RmEMvzk+X8prTjA83vLbIiJxaVMne1HleIZhjKr+MbcwM2Y32tuKJl8bvSBKW9EQcVT X-Received: by 10.98.13.20 with SMTP id v20mr34558302pfi.80.1476721917126; Mon, 17 Oct 2016 09:31:57 -0700 (PDT) Received: from blr-ubuntu-59.ap.qualcomm.com ([202.46.23.61]) by smtp.gmail.com with ESMTPSA id o9sm43009638pac.27.2016.10.17.09.31.54 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Oct 2016 09:31:56 -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 7/8] IB/mthca: Replace counting semaphore event_sem with wait condition Date: Mon, 17 Oct 2016 22:01:01 +0530 Message-Id: <1476721862-7070-8-git-send-email-binoy.jayan@linaro.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1476721862-7070-1-git-send-email-binoy.jayan@linaro.org> References: <1476721862-7070-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 an open-coded implementation. Signed-off-by: Binoy Jayan --- drivers/infiniband/hw/mthca/mthca_cmd.c | 12 ++++++++---- drivers/infiniband/hw/mthca/mthca_dev.h | 3 ++- 2 files changed, 10 insertions(+), 5 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 0cb58ea..5b8d5ea 100644 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c @@ -417,7 +417,8 @@ static int mthca_cmd_wait(struct mthca_dev *dev, int err = 0; struct mthca_cmd_context *context; - down(&dev->cmd.event_sem); + wait_event(dev->cmd.event_sem.wq, + atomic_add_unless(&dev->cmd.event_sem.count, -1, 0)); spin_lock(&dev->cmd.context_lock); BUG_ON(dev->cmd.free_head < 0); @@ -459,7 +460,8 @@ static int mthca_cmd_wait(struct mthca_dev *dev, dev->cmd.free_head = context - dev->cmd.context; spin_unlock(&dev->cmd.context_lock); - up(&dev->cmd.event_sem); + if (atomic_inc_return(&dev->cmd.event_sem.count) == 1) + wake_up(&dev->cmd.event_sem.wq); return err; } @@ -571,7 +573,8 @@ 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.event_sem.wq); + atomic_set(&dev->cmd.event_sem.count, dev->cmd.max_cmds); spin_lock_init(&dev->cmd.context_lock); for (dev->cmd.token_mask = 1; @@ -597,7 +600,8 @@ void mthca_cmd_use_polling(struct mthca_dev *dev) dev->cmd.flags &= ~MTHCA_CMD_USE_EVENTS; for (i = 0; i < dev->cmd.max_cmds; ++i) - down(&dev->cmd.event_sem); + wait_event(dev->cmd.event_sem.wq, + atomic_add_unless(&dev->cmd.event_sem.count, -1, 0)); kfree(dev->cmd.context); diff --git a/drivers/infiniband/hw/mthca/mthca_dev.h b/drivers/infiniband/hw/mthca/mthca_dev.h index 87ab964..1f88835c 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; + struct ib_semaphore event_sem; int max_cmds; spinlock_t context_lock; int free_head;