From patchwork Wed Oct 26 08:01:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binoy Jayan X-Patchwork-Id: 79345 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp279023qge; Wed, 26 Oct 2016 01:02:01 -0700 (PDT) X-Received: by 10.98.21.197 with SMTP id 188mr1847541pfv.38.1477468921661; Wed, 26 Oct 2016 01:02:01 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a17si1277974pgi.123.2016.10.26.01.02.01; Wed, 26 Oct 2016 01:02:01 -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 S933210AbcJZIBe (ORCPT + 27 others); Wed, 26 Oct 2016 04:01:34 -0400 Received: from mail-pf0-f172.google.com ([209.85.192.172]:35849 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759879AbcJZIB3 (ORCPT ); Wed, 26 Oct 2016 04:01:29 -0400 Received: by mail-pf0-f172.google.com with SMTP id e6so135270048pfk.3 for ; Wed, 26 Oct 2016 01:01: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=hxnQJCePg5Ws7EKduzAw/uMn1KJOKBERMmIT4yxA9U2ykc58W+f8/20xbMAVK/VTRy v+lqrEDzfvFpXLNCWvVDDtlSsvisgy6tlAjqYSdt2ytQbajn+xabmqVSBWKylcrEyT6y 6pALv+IAD1B6px/DzTfg/xeY//Z70YEzmkqC0= 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=jCAabeMaH+km0f93slURjs0awdyD0+zYajOjHkFWAeGVFMKiDGwxd9sh/QuC3gFfbs PJGZBPGYtz1V+ai09RY+E/XZvZObtOsa7YJFAJoi9Rlq3bicGY6JIhguno7pOaMYS7oY qR3Ej9NR7VU3codZy5CUz3bmgdITBEpEPFq3xRuIR9B+OS7+yp4VyPw41Td62Mu2Jgbi EUhsRtSjgcVt+17YhFIOx1G/JR6s6O3Jm9bVZaYXcciFIXba00tTfxtLnEDb5KrFu9/w ybcVWC1WTPbTYDHwjub6/o5wi1lxxeOxVvWLBhzxMPvSN2kuHt0ICcG0KMC4ZjbPn716 gLaA== X-Gm-Message-State: ABUngveCk6vYIZCHb06L02TUZIAcRcqNXLceqGhq6aw0VGJTD71V2jflNXtKb0LPgiLI0pgx X-Received: by 10.98.14.197 with SMTP id 66mr1768561pfo.123.1477468888443; Wed, 26 Oct 2016 01:01:28 -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.25 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Oct 2016 01:01:28 -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 2/9] IB/core: Replace semaphore sm_sem with an atomic wait Date: Wed, 26 Oct 2016 13:31:07 +0530 Message-Id: <1477468874-16328-3-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 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);