Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759353AbcJYPsk (ORCPT ); Tue, 25 Oct 2016 11:48:40 -0400 Received: from quartz.orcorp.ca ([184.70.90.242]:50750 "EHLO quartz.orcorp.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752677AbcJYPsh (ORCPT ); Tue, 25 Oct 2016 11:48:37 -0400 Date: Tue, 25 Oct 2016 09:48:22 -0600 From: Jason Gunthorpe To: Binoy Jayan Cc: Jack Wang , Doug Ledford , Sean Hefty , Hal Rosenstock , Arnd Bergmann , "linux-rdma@vger.kernel.org" , Linux kernel mailing list Subject: Re: [PATCH v2 2/8] IB/core: Replace semaphore sm_sem with completion Message-ID: <20161025154822.GA27240@obsidianresearch.com> References: <1477396919-27669-1-git-send-email-binoy.jayan@linaro.org> <1477396919-27669-3-git-send-email-binoy.jayan@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Broken-Reverse-DNS: no host name found for IP address 10.0.0.151 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1223 Lines: 48 On Tue, Oct 25, 2016 at 08:38:21PM +0530, Binoy Jayan wrote: > On 25 October 2016 at 18:13, Jack Wang wrote: > > Hi Binoy, > > > > snip > >> > >> port->ib_dev = device; > >> port->port_num = port_num; > >> - sema_init(&port->sm_sem, 1); > >> + init_completion(&port->sm_comp); > >> + complete(&port->sm_comp); > > > > Why complete here? > > > >> mutex_init(&port->file_mutex); > >> INIT_LIST_HEAD(&port->file_list); > >> > > KR, > > Jinpu > > > Hi Jack, > > ib_umad_sm_open() calls wait_for_completion_interruptible() which > comes before ib_umad_sm_close() that calls complete(). In the > initial open() there will not be anybody to signal the completion, > so the complete is called to mark the initial state. I am not sure > if this is the right way to do it, though. Using a completion to model exclusive ownership seems convoluted to me - is that a thing now? What about an atomic? open: while (true) { wait_event_interruptible(priv->queue,test_bit(CLAIMED_BIT, &priv->flags)); if (!test_and_set_bit(CLAIMED_BIT, &priv->flags)) break; } close(): clear_bit(CLAIMED_BIT, &priv->flags) wake_up(&priv->queue); ?? Jason