Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934868AbcJYUQB (ORCPT ); Tue, 25 Oct 2016 16:16:01 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:50947 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932301AbcJYUP7 (ORCPT ); Tue, 25 Oct 2016 16:15:59 -0400 From: Arnd Bergmann To: Jason Gunthorpe Cc: Binoy Jayan , Jack Wang , Doug Ledford , Sean Hefty , Hal Rosenstock , "linux-rdma@vger.kernel.org" , Linux kernel mailing list Subject: Re: [PATCH v2 2/8] IB/core: Replace semaphore sm_sem with completion Date: Tue, 25 Oct 2016 22:15:33 +0200 Message-ID: <3660358.5IXMF8ssab@wuerfel> User-Agent: KMail/5.1.3 (Linux/4.4.0-34-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: <20161025154822.GA27240@obsidianresearch.com> References: <1477396919-27669-1-git-send-email-binoy.jayan@linaro.org> <20161025154822.GA27240@obsidianresearch.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:6MOVDYSoozPCV+UAIMf20lH0f7XMHHNyoTHWHwUDU3GadWPP25Y UA+YZjltRzxQKYFgouxwcYY5APCnkaPvy85RusdxevhxP9XXQlwOaedWd6LgcG+mMFAYXlW RLrP/eEKrkOGJ2DYUqagiT1md6y6vMxpc8E9Hdn7FNbRlk+a+PWY/klPXXuzAp4zgSgdzep sJ+XUEF7/5vmX9cH8Ivxg== X-UI-Out-Filterresults: notjunk:1;V01:K0:P7KFsAwVVsw=:hbz2Sq7fWypr8lexWWQftq fEwEyzdSM5fSxz4pJHP3OsMR/auOXPjjARRjAHGdIbqVztB6nV3ODRESc9DizcBij4GKfTtgV 0//Z9O9+29x8UI+blVgO9k3Dvl2aibFUsyKB9LH54hBSJu6AmQLxildL6Mb4b1yDyUt8lKk+u 2PS0xmg7fCCDkd54KkiiLdUPhu5jKB1jfPc1aUai3lTjKWejY09Czh2r0WAMttOhxVKYdoG/q Uyrd2lJDsL+uyYOsYtOj9n4+AYM6ix6cxkH0BiWU0rZuLEKPX1eYf9f9KjdB50IvNuGSwPQxt ep3wGV3jXHnEQ3OQ0h0L6+ULQd+Co/XYpPyekYFSTA7Kiu9HQwM+fPfvSrkQ+B7zHWUwXK3gc CaF6xiqdkIblMPVlh7u7R30Y40r22uKqOK2C52vP+hkFAG98aVmtDYrGp148UegEfNGY52pmw TP1wQGaRn7IrSpQPrx3KggktB3LD5en6K12JJwY8dH9X7G2Mh2IdxNCqA+DRCARi4FqKP7W4E l8zQVc8Cza9USC8rf7GHcq0SMBtDYhLCUJGJ915DygzT5FS2hZyCGiMRsZXDFvc8UzslGhkYW wt2Ix6wm8Uhg7Ftsly7HLXndfKVMWLJFuoiEEADKjyY/ylhou94rB3GHs4eQ2kMd7NOupCMAM 6hgCIO16sRlMI4GHgsDm238YS3gPy5JfCLZezg9wctlkn858R/xKGRsASGn13eZSGQnPqsOxq sADfC0Hu68HhPij6 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1393 Lines: 37 On Tuesday, October 25, 2016 9:48:22 AM CEST Jason Gunthorpe wrote: > > Using a completion to model exclusive ownership seems convoluted to > me - is that a thing now? What about an atomic? I also totally missed how this is used. I initially mentioned to Binoy that almost all semaphores can either be converted to a mutex or a completion unless they rely on the counting behavior of the semaphore. This driver clearly falls into another category and none of the above apply here. > open: > > while (true) { > wait_event_interruptible(priv->queue,test_bit(CLAIMED_BIT, &priv->flags)); > if (!test_and_set_bit(CLAIMED_BIT, &priv->flags)) > break; > } I'd fold the test_and_set_bit() into the wait_event() and get rid of the loop here, otherwise this looks nice. I'm generally a bit suspicious of open() functions that try to protect you from having multiple file descriptors open, as dup() or fork() will also result in extra file descriptors, but this use here seems harmless, as the device itself only supports open() and close() and the only thing it does is to keep track of whether it is open or not. It's also interesting that the ib_modify_port() function also keeps track of the a flag that is set in open() and cleared in close(), so in principle we should be able to unify this with the semaphore, but the wait_event() approach is certainly much simpler. Arnd