From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id A2043A0526; Wed, 8 Jul 2020 13:44:32 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 613C91DB73; Wed, 8 Jul 2020 13:44:32 +0200 (CEST) Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by dpdk.org (Postfix) with ESMTP id 4D11D1DAEB for ; Wed, 8 Jul 2020 13:44:30 +0200 (CEST) Received: by mail-wr1-f68.google.com with SMTP id o11so48649925wrv.9 for ; Wed, 08 Jul 2020 04:44:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=fBFiuYeDM26KCeIMaU9FWwOHbpBtA3W+AKpTXBmGwZI=; b=XPD4Av0bvHSJZUlw9VSddhZkygTn/HMNgQgg0gqj0WTv1yQysUZYBr5IG7sCjgiY9N IgqGz+4gDm9pc0B3Eqb2YA2jt3Y370vnwVuupfaVmsQVXGit0Ynnq01gpg9zbA859Onn 5Y1LJX+vfNzS24nB4x+QQSO32NWcOraePgdy9pVu2RE8Yni0Bnv/07z97bijpmf9Pkdx B1Z97CVRcXisRi4i1JOV/RtIDJfpnakY5t2gD2ZbO7OFxaj80DG5rxZcLwfoaK4k1Gvs 9dQTllSnhl0q8H8ZCooLc8jLezs+VQ7+yG9y3/tT3FY4YAar7wXioBgPwQrc0aKpVUtU qs2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=fBFiuYeDM26KCeIMaU9FWwOHbpBtA3W+AKpTXBmGwZI=; b=UEWe80NySgrYXH7soXML9sEi1HzzMbQOLPYOC8EDXlRR2BtzOw0gm0A+rRbx08139v I2P5sUJ0Dl+ChsMl7A91Wr5zaBkTtAWKSD++NzKqJn0SsGFidtsl89lmmCf9Up0hjGiF /803U/XveZCINY2wucxgNhLQkClO6FsLZL51pAbm4WjLBdrulqWTl/qT9mjRIHYEDnjR I2S1EouaDkSzgBJfyea/VSN9fmYaZm6V+tpbXDXLuD26arfDpe7euIddjqt2wLHwLvMc MFe5H2nfu9b71ZCYX+CIf6drdDnCJT+ZxzjUzMQqTWq95AnZDMQxrWXfVhjGk9gGpmrk wG8g== X-Gm-Message-State: AOAM532U97U61Gzj85S608TqdKg/BkY16sYSxER6xzSVBvR4E3sS+zzj CWKvV10MJvSDmmB/qIAqwYdMLQ== X-Google-Smtp-Source: ABdhPJx2jvF5obJ5W3kSxoYR1hO876dBO//cgEh+QGUq6jYJp+0XB4fyqVfEaCabwcQ/y7x0JPRkPA== X-Received: by 2002:a5d:4dc2:: with SMTP id f2mr59378516wru.399.1594208670014; Wed, 08 Jul 2020 04:44:30 -0700 (PDT) Received: from 6wind.com (2a01cb0c0005a600345636f7e65ed1a0.ipv6.abo.wanadoo.fr. [2a01:cb0c:5:a600:3456:36f7:e65e:d1a0]) by smtp.gmail.com with ESMTPSA id a22sm5279512wmb.4.2020.07.08.04.44.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2020 04:44:29 -0700 (PDT) Date: Wed, 8 Jul 2020 13:44:28 +0200 From: Olivier Matz To: Phil Yang Cc: david.marchand@redhat.com, dev@dpdk.org, drc@linux.vnet.ibm.com, Honnappa.Nagarahalli@arm.com, ruifeng.wang@arm.com, nd@arm.com Message-ID: <20200708114428.GO5869@platinum> References: <1591871178-12542-1-git-send-email-phil.yang@arm.com> <1594116633-14554-1-git-send-email-phil.yang@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1594116633-14554-1-git-send-email-phil.yang@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Subject: Re: [dpdk-dev] [PATCH v2] mbuf: use C11 atomics for refcnt operations X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Hi, On Tue, Jul 07, 2020 at 06:10:33PM +0800, Phil Yang wrote: > Use C11 atomics with explicit ordering instead of rte_atomic ops which > enforce unnecessary barriers on aarch64. > > Signed-off-by: Phil Yang > Reviewed-by: Ruifeng Wang > --- > v2: > Fix ABI issue: revert the rte_mbuf_ext_shared_info struct refcnt field > to refcnt_atomic. > > lib/librte_mbuf/rte_mbuf.c | 1 - > lib/librte_mbuf/rte_mbuf.h | 19 ++++++++++--------- > lib/librte_mbuf/rte_mbuf_core.h | 11 +++-------- > 3 files changed, 13 insertions(+), 18 deletions(-) > > diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c > index ae91ae2..8a456e5 100644 > --- a/lib/librte_mbuf/rte_mbuf.c > +++ b/lib/librte_mbuf/rte_mbuf.c > @@ -22,7 +22,6 @@ > #include > #include > #include > -#include > #include > #include > #include > diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h > index f8e492e..4a7a98c 100644 > --- a/lib/librte_mbuf/rte_mbuf.h > +++ b/lib/librte_mbuf/rte_mbuf.h > @@ -37,7 +37,6 @@ > #include > #include > #include > -#include > #include > #include > #include > @@ -365,7 +364,7 @@ rte_pktmbuf_priv_flags(struct rte_mempool *mp) > static inline uint16_t > rte_mbuf_refcnt_read(const struct rte_mbuf *m) > { > - return (uint16_t)(rte_atomic16_read(&m->refcnt_atomic)); > + return __atomic_load_n(&m->refcnt, __ATOMIC_RELAXED); > } > > /** > @@ -378,14 +377,15 @@ rte_mbuf_refcnt_read(const struct rte_mbuf *m) > static inline void > rte_mbuf_refcnt_set(struct rte_mbuf *m, uint16_t new_value) > { > - rte_atomic16_set(&m->refcnt_atomic, (int16_t)new_value); > + __atomic_store_n(&m->refcnt, new_value, __ATOMIC_RELAXED); > } > > /* internal */ > static inline uint16_t > __rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value) > { > - return (uint16_t)(rte_atomic16_add_return(&m->refcnt_atomic, value)); > + return (uint16_t)(__atomic_add_fetch((int16_t *)&m->refcnt, value, > + __ATOMIC_ACQ_REL)); > } > > /** > @@ -466,7 +466,7 @@ rte_mbuf_refcnt_set(struct rte_mbuf *m, uint16_t new_value) > static inline uint16_t > rte_mbuf_ext_refcnt_read(const struct rte_mbuf_ext_shared_info *shinfo) > { > - return (uint16_t)(rte_atomic16_read(&shinfo->refcnt_atomic)); > + return __atomic_load_n(&shinfo->refcnt_atomic, __ATOMIC_RELAXED); > } > > /** > @@ -481,7 +481,7 @@ static inline void > rte_mbuf_ext_refcnt_set(struct rte_mbuf_ext_shared_info *shinfo, > uint16_t new_value) > { > - rte_atomic16_set(&shinfo->refcnt_atomic, (int16_t)new_value); > + __atomic_store_n(&shinfo->refcnt_atomic, new_value, __ATOMIC_RELAXED); > } > > /** > @@ -505,7 +505,8 @@ rte_mbuf_ext_refcnt_update(struct rte_mbuf_ext_shared_info *shinfo, > return (uint16_t)value; > } > > - return (uint16_t)rte_atomic16_add_return(&shinfo->refcnt_atomic, value); > + return (uint16_t)(__atomic_add_fetch((int16_t *)&shinfo->refcnt_atomic, > + value, __ATOMIC_ACQ_REL)); > } > > /** Mbuf prefetch */ > @@ -1304,8 +1305,8 @@ static inline int __rte_pktmbuf_pinned_extbuf_decref(struct rte_mbuf *m) > * Direct usage of add primitive to avoid > * duplication of comparing with one. > */ > - if (likely(rte_atomic16_add_return > - (&shinfo->refcnt_atomic, -1))) > + if (likely(__atomic_add_fetch((int *)&shinfo->refcnt_atomic, -1, > + __ATOMIC_ACQ_REL))) > return 1; > > /* Reinitialize counter before mbuf freeing. */ > diff --git a/lib/librte_mbuf/rte_mbuf_core.h b/lib/librte_mbuf/rte_mbuf_core.h > index 16600f1..806313a 100644 > --- a/lib/librte_mbuf/rte_mbuf_core.h > +++ b/lib/librte_mbuf/rte_mbuf_core.h > @@ -18,7 +18,6 @@ > > #include > #include > -#include > > #ifdef __cplusplus > extern "C" { > @@ -495,12 +494,8 @@ struct rte_mbuf { > * or non-atomic) is controlled by the CONFIG_RTE_MBUF_REFCNT_ATOMIC > * config option. > */ > - RTE_STD_C11 > - union { > - rte_atomic16_t refcnt_atomic; /**< Atomically accessed refcnt */ > - /** Non-atomically accessed refcnt */ > - uint16_t refcnt; > - }; > + uint16_t refcnt; > + It seems this patch does 2 things: - remove refcnt_atomic - use C11 atomics The first change is an API break. I think it should be announced in a deprecation notice. The one about atomic does not talk about it. So I suggest to keep refcnt_atomic until next version. > uint16_t nb_segs; /**< Number of segments. */ > > /** Input port (16 bits to support more than 256 virtual ports). > @@ -679,7 +674,7 @@ typedef void (*rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque); > struct rte_mbuf_ext_shared_info { > rte_mbuf_extbuf_free_callback_t free_cb; /**< Free callback function */ > void *fcb_opaque; /**< Free callback argument */ > - rte_atomic16_t refcnt_atomic; /**< Atomically accessed refcnt */ > + uint16_t refcnt_atomic; /**< Atomically accessed refcnt */ > }; > > /**< Maximum number of nb_segs allowed. */ > -- > 2.7.4 >