From patchwork Mon Nov 21 06:08:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binoy Jayan X-Patchwork-Id: 83184 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp1327489qge; Sun, 20 Nov 2016 22:16:36 -0800 (PST) X-Received: by 10.13.251.193 with SMTP id l184mr11360033ywf.17.1479708996883; Sun, 20 Nov 2016 22:16:36 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 124si4313699ybz.239.2016.11.20.22.16.36; Sun, 20 Nov 2016 22:16:36 -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 S1753468AbcKUGQd (ORCPT + 26 others); Mon, 21 Nov 2016 01:16:33 -0500 Received: from mail-pf0-f182.google.com ([209.85.192.182]:33897 "EHLO mail-pf0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750744AbcKUGQc (ORCPT ); Mon, 21 Nov 2016 01:16:32 -0500 Received: by mail-pf0-f182.google.com with SMTP id c4so50671208pfb.1 for ; Sun, 20 Nov 2016 22:16:32 -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=tfsZlV6cjTCA2AA5dN1OrgNEG7z+nqgGKTXeDvj0wow=; b=Kgy5GwajYYC8qdC718Kz4czJ27Wfstb/x5ExlIOtlMDREY2qQ5Ks0BQFUnfg6CUiPn Hi7KUDAG3vsha4IOViEQ382ynNTkvjHpqdN1v6SzgqC2lr/Tla1UEH7jlSTCpcHCMeP1 kKt/0K9xvkNGvTpl0qTfQ0rSTEVAOCpXGr0P4= 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=tfsZlV6cjTCA2AA5dN1OrgNEG7z+nqgGKTXeDvj0wow=; b=K1vMcG57BObRtCZYI7czuwYPmnkjSQFrPKas00WZaOcyVhIk6E34YV02OWj6Z0GO2Q xG0lJR0fwYoPnRxse/kyK03DrsSofEpfu1lw1dNKjZgwNj9Kn2uBRlqyY5a4k6NMnQ7F YJSrtXaVD+a9nq7saI9xDDDf7tZYnlTbVcqd3HMgS2X9u0Xw9pZKr6t62UmBxKO6eqiZ irHctpRLPoN/To8ldIaFdnA5MLRJQyAQAKCzTn3wullNHqQ3+9iSLCOIT0+/ntdefPch kADg+/h4DxsjtCiIn2lGjLKWBhg/TXQ8hzSBYmw8pGShL0pdK691PSFHxI//9bPf2K9c ZDCA== X-Gm-Message-State: AKaTC017lb7XRXw5ZQ4j2eQXFdLLJJSVMijHsA/agVJxWtaQx5dA5i0VTo+OXx8WSG0Qmfom X-Received: by 10.99.111.201 with SMTP id k192mr28509031pgc.176.1479708535485; Sun, 20 Nov 2016 22:08:55 -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.08.48 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 20 Nov 2016 22:08:54 -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 2/9] IB/core: Replace semaphore sm_sem with an atomic wait Date: Mon, 21 Nov 2016 11:38:09 +0530 Message-Id: <1479708496-9828-3-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 The semaphore 'sm_sem' is used for an exclusive ownership of the device so model the same as an atomic variable with an associated wait_event. Semaphores are going away in the future. Signed-off-by: Binoy Jayan --- drivers/infiniband/core/user_mad.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c index 415a318..6101c0a 100644 --- a/drivers/infiniband/core/user_mad.c +++ b/drivers/infiniband/core/user_mad.c @@ -67,6 +67,8 @@ enum { IB_UMAD_MINOR_BASE = 0 }; +#define UMAD_F_CLAIM 0x01 + /* * Our lifetime rules for these structs are the following: * device special file is opened, we take a reference on the @@ -87,7 +89,8 @@ struct ib_umad_port { struct cdev sm_cdev; struct device *sm_dev; - struct semaphore sm_sem; + wait_queue_head_t wq; + unsigned long flags; struct mutex file_mutex; struct list_head file_list; @@ -1030,12 +1033,14 @@ static int ib_umad_sm_open(struct inode *inode, struct file *filp) port = container_of(inode->i_cdev, struct ib_umad_port, sm_cdev); if (filp->f_flags & O_NONBLOCK) { - if (down_trylock(&port->sm_sem)) { + if (test_and_set_bit(UMAD_F_CLAIM, &port->flags)) { ret = -EAGAIN; goto fail; } } else { - if (down_interruptible(&port->sm_sem)) { + if (wait_event_interruptible(port->wq, + !test_and_set_bit(UMAD_F_CLAIM, + &port->flags))) { ret = -ERESTARTSYS; goto fail; } @@ -1060,7 +1065,8 @@ static int ib_umad_sm_open(struct inode *inode, struct file *filp) ib_modify_port(port->ib_dev, port->port_num, 0, &props); err_up_sem: - up(&port->sm_sem); + clear_bit(UMAD_F_CLAIM, &port->flags); + wake_up(&port->wq); fail: return ret; @@ -1079,7 +1085,8 @@ static int ib_umad_sm_close(struct inode *inode, struct file *filp) ret = ib_modify_port(port->ib_dev, port->port_num, 0, &props); mutex_unlock(&port->file_mutex); - up(&port->sm_sem); + clear_bit(UMAD_F_CLAIM, &port->flags); + wake_up(&port->wq); kobject_put(&port->umad_dev->kobj); @@ -1177,7 +1184,8 @@ static int ib_umad_init_port(struct ib_device *device, int port_num, port->ib_dev = device; port->port_num = port_num; - sema_init(&port->sm_sem, 1); + init_waitqueue_head(&port->wq); + __clear_bit(UMAD_F_CLAIM, &port->flags); mutex_init(&port->file_mutex); INIT_LIST_HEAD(&port->file_list);