From patchwork Thu Oct 27 06:59:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binoy Jayan X-Patchwork-Id: 79612 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp467586qge; Wed, 26 Oct 2016 23:59:51 -0700 (PDT) X-Received: by 10.99.65.133 with SMTP id o127mr9461891pga.73.1477551590931; Wed, 26 Oct 2016 23:59:50 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 123si6338936pgb.296.2016.10.26.23.59.50; Wed, 26 Oct 2016 23:59:50 -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 S934649AbcJ0G7h (ORCPT + 27 others); Thu, 27 Oct 2016 02:59:37 -0400 Received: from mail-pf0-f174.google.com ([209.85.192.174]:33282 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934346AbcJ0G72 (ORCPT ); Thu, 27 Oct 2016 02:59:28 -0400 Received: by mail-pf0-f174.google.com with SMTP id 197so11976008pfu.0 for ; Wed, 26 Oct 2016 23:59:28 -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=tfsZlV6cjTCA2AA5dN1OrgNEG7z+nqgGKTXeDvj0wow=; b=fsIyKC+z4A/AsqY3Eloz5yh73MnZm1tfq/j32EJZT5JTm1CsEfkXruwkbOMc4CRmhn vsUjZBGioD6SRTHEDvifo4/cy24d2S7nt3IKHsFoofpcLYPDWmnQAQYjbTwNxtryTb4k PArwSyYJM0ImBZsVhak/HSrg0UnmrkVJalqVg= 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=MiQBgdmI4ZrJ3sB/QM0+Da+m+x7p2uHCI4afJjs97Js9s8lZ4zb7jiTDAxjrlf41SK ksT0oF+T2+trhpMGxRMCJ8ojrrNfNQCqpM0OFrcqrtV0O22Ok6srzq1SdF71lObNz6zF aBo4XzwXoGEGhiKCMgaHOb7KgiXcf3JCgTM27AV8ijKA/ZuxJjsrJ39MHGmHxnR8w91b iaftR3tJdNnY5VXBQCA6t/5uorY7dDQSkpQSMZn4ILWXjuz96nWxHZcQkmmYzSvZzFkE URSrILjhx+q2f7Sa2u244K+K8omHWyNb4wEJUC732NWMO3Czpuy7tqV1f3ASpUCaTGeg tP8w== X-Gm-Message-State: ABUngveCJyoLieM8J2hBCU0oCbU2EzNlnKUin2cyk5TPWwzedTzWIlNASQV6iM6D1GgxCr36 X-Received: by 10.99.213.21 with SMTP id c21mr9733868pgg.176.1477551568047; Wed, 26 Oct 2016 23:59:28 -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.25 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Oct 2016 23:59:27 -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 02/10] IB/core: Replace semaphore sm_sem with an atomic wait Date: Thu, 27 Oct 2016 12:29:06 +0530 Message-Id: <1477551554-30349-3-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 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);