From patchwork Wed Mar 15 23:18:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 9626835 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 07D8560424 for ; Wed, 15 Mar 2017 23:19:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC5EB2850E for ; Wed, 15 Mar 2017 23:19:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF26D285FC; Wed, 15 Mar 2017 23:19:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45F722850E for ; Wed, 15 Mar 2017 23:19:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754312AbdCOXTD (ORCPT ); Wed, 15 Mar 2017 19:19:03 -0400 Received: from quartz.orcorp.ca ([184.70.90.242]:45619 "EHLO quartz.orcorp.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752493AbdCOXSk (ORCPT ); Wed, 15 Mar 2017 19:18:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=obsidianresearch.com; s=rsa1; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=zu4l3PBV8aWit7p6rq1/2b6vCGHJnsfTPXvs1iv35n4=; b=Hub9p3FsHiMqhSVAsntnLfW2t9PWSsUyhFWh/qBaWrvZ+rYgOzRURBBx4p6hK+qt2K36oh2pSQ71yxpd/XuuVKOvHU4r7eEIlTUjS/Y2uGr1ilw54M28HLhDG7fTHFsvdq2LfxTKoT/WjemNAvI9vGBysjW944QqzGD8e0K+wXc=; Received: from [10.0.0.156] (helo=jggl.edm.orcorp.ca) by quartz.orcorp.ca with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1coIBh-0005sW-Ad; Wed, 15 Mar 2017 17:18:37 -0600 Received: from jgg by jggl.edm.orcorp.ca with local (Exim 4.86_2) (envelope-from ) id 1coIBh-00061w-7n; Wed, 15 Mar 2017 17:18:37 -0600 Date: Wed, 15 Mar 2017 17:18:37 -0600 From: Jason Gunthorpe To: Bart Van Assche Cc: "linux-rdma@vger.kernel.org" , "sean.hefty@intel.com" Subject: Re: [PATCH rdma-core 4/6] rdmacm: Use C11 stdatomic for all atomics Message-ID: <20170315231837.GA23082@obsidianresearch.com> References: <1489615927-12117-1-git-send-email-jgunthorpe@obsidianresearch.com> <1489615927-12117-5-git-send-email-jgunthorpe@obsidianresearch.com> <1489618538.2660.14.camel@sandisk.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1489618538.2660.14.camel@sandisk.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Broken-Reverse-DNS: no host name found for IP address 10.0.0.156 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Wed, Mar 15, 2017 at 10:55:52PM +0000, Bart Van Assche wrote: > On Wed, 2017-03-15 at 16:12 -0600, Jason Gunthorpe wrote: > > @@ -1013,7 +1012,7 @@ int close(int socket) > > return ret; > > } > > > > - if (atomic_dec(&fdi->refcnt)) > > + if (atomic_fetch_sub(&fdi->refcnt, 1)) > > return 0; > > > > idm_clear(&idm, socket); > > @@ -898,7 +898,7 @@ static int rs_create_ep(struct rsocket *rs) > > > > static void rs_release_iomap_mr(struct rs_iomap_mr *iomr) > > { > > - if (atomic_dec(&iomr->refcnt)) > > + if (atomic_fetch_sub(&iomr->refcnt, 1)) > > return; > > > > dlist_remove(&iomr->entry); > > Hello Jason, > > In the gcc documentation I read that __sync_sub_and_fetch() (used to > implement atomic_dec()) returns the new value. In the C11 standard I read > that atomic_fetch_sub() returns the old value. Do you agree with this? Indeed, you are right, I will sqush in this patch, thanks --- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/librdmacm/cma.h b/librdmacm/cma.h index 645d1e43576279..2f5f86cf498918 100644 --- a/librdmacm/cma.h +++ b/librdmacm/cma.h @@ -69,12 +69,12 @@ static inline void fastlock_destroy(fastlock_t *lock) } static inline void fastlock_acquire(fastlock_t *lock) { - if (atomic_fetch_add(&lock->cnt, 1) > 1) + if (atomic_fetch_add(&lock->cnt, 1) > 0) sem_wait(&lock->sem); } static inline void fastlock_release(fastlock_t *lock) { - if (atomic_fetch_sub(&lock->cnt, 1) > 0) + if (atomic_fetch_sub(&lock->cnt, 1) > 1) sem_post(&lock->sem); } diff --git a/librdmacm/preload.c b/librdmacm/preload.c index bd1bcb1d701015..82cb0c03850b05 100644 --- a/librdmacm/preload.c +++ b/librdmacm/preload.c @@ -1012,7 +1012,7 @@ int close(int socket) return ret; } - if (atomic_fetch_sub(&fdi->refcnt, 1)) + if (atomic_fetch_sub(&fdi->refcnt, 1) != 1) return 0; idm_clear(&idm, socket); diff --git a/librdmacm/rsocket.c b/librdmacm/rsocket.c index 4fbe7aaa938610..9a71035fbeed8b 100644 --- a/librdmacm/rsocket.c +++ b/librdmacm/rsocket.c @@ -898,7 +898,7 @@ static int rs_create_ep(struct rsocket *rs) static void rs_release_iomap_mr(struct rs_iomap_mr *iomr) { - if (atomic_fetch_sub(&iomr->refcnt, 1)) + if (atomic_fetch_sub(&iomr->refcnt, 1) != 1) return; dlist_remove(&iomr->entry);