From: Phil Yang <phil.yang@arm.com>
To: olivier.matz@6wind.com, dev@dpdk.org
Cc: stephen@networkplumber.org, david.marchand@redhat.com,
drc@linux.vnet.ibm.com, Honnappa.Nagarahalli@arm.com,
Ruifeng.Wang@arm.com, nd@arm.com
Subject: [dpdk-dev] [PATCH v3] mbuf: use C11 atomic built-ins for refcnt operations
Date: Thu, 9 Jul 2020 18:10:42 +0800 [thread overview]
Message-ID: <1594289442-18594-1-git-send-email-phil.yang@arm.com> (raw)
In-Reply-To: <1594116633-14554-1-git-send-email-phil.yang@arm.com>
Use C11 atomic built-ins with explicit ordering instead of rte_atomic
ops which enforce unnecessary barriers on aarch64.
Signed-off-by: Phil Yang <phil.yang@arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
---
v3:
1.Fix ABI breakage.
2.Simplify data type cast.
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 | 2 +-
3 files changed, 11 insertions(+), 11 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 <rte_eal.h>
#include <rte_per_lcore.h>
#include <rte_lcore.h>
-#include <rte_atomic.h>
#include <rte_branch_prediction.h>
#include <rte_mempool.h>
#include <rte_mbuf.h>
diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h
index f8e492e..c1c0956 100644
--- a/lib/librte_mbuf/rte_mbuf.h
+++ b/lib/librte_mbuf/rte_mbuf.h
@@ -37,7 +37,6 @@
#include <rte_config.h>
#include <rte_mempool.h>
#include <rte_memory.h>
-#include <rte_atomic.h>
#include <rte_prefetch.h>
#include <rte_branch_prediction.h>
#include <rte_byteorder.h>
@@ -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 __atomic_add_fetch(&m->refcnt, (uint16_t)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 __atomic_add_fetch(&shinfo->refcnt_atomic, (uint16_t)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(&shinfo->refcnt_atomic, (uint16_t)-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..d65d1c8 100644
--- a/lib/librte_mbuf/rte_mbuf_core.h
+++ b/lib/librte_mbuf/rte_mbuf_core.h
@@ -679,7 +679,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
next prev parent reply other threads:[~2020-07-09 10:11 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-11 10:26 [dpdk-dev] [PATCH] mbuf: use c11 atomics " Phil Yang
2020-07-03 15:38 ` David Marchand
2020-07-06 8:03 ` Phil Yang
2020-07-07 10:10 ` [dpdk-dev] [PATCH v2] mbuf: use C11 " Phil Yang
2020-07-07 17:13 ` Stephen Hemminger
2020-07-08 4:48 ` Phil Yang
2020-07-08 11:43 ` Olivier Matz
2020-07-09 9:52 ` Phil Yang
2020-07-08 5:11 ` Phil Yang
2020-07-08 11:44 ` Olivier Matz
2020-07-09 10:00 ` Phil Yang
2020-07-09 10:10 ` Phil Yang [this message]
2020-07-09 11:03 ` [dpdk-dev] [PATCH v3] mbuf: use C11 atomic built-ins " Olivier Matz
2020-07-09 13:00 ` Phil Yang
2020-07-09 13:31 ` Honnappa Nagarahalli
2020-07-09 14:10 ` Phil Yang
2020-07-09 15:58 ` [dpdk-dev] [PATCH v4 1/2] " Phil Yang
2020-07-09 15:58 ` [dpdk-dev] [PATCH v4 2/2] doc: announce deprecation of refcnt atomic member Phil Yang
2020-07-10 2:55 ` Ruifeng Wang
2020-07-13 15:54 ` Phil Yang
2020-07-14 10:41 ` Ananyev, Konstantin
2020-07-15 12:29 ` [dpdk-dev] [PATCH v4 1/2] mbuf: use C11 atomic built-ins for refcnt operations David Marchand
2020-07-15 12:49 ` Aaron Conole
2020-07-15 16:29 ` Phil Yang
2020-07-16 4:16 ` Phil Yang
2020-07-16 11:30 ` David Marchand
2020-07-16 13:20 ` Dodji Seketeli
2020-07-16 19:11 ` David Marchand
2020-07-17 4:41 ` Phil Yang
2020-07-16 11:32 ` Olivier Matz
2020-07-17 4:36 ` [dpdk-dev] [PATCH v5 1/2] mbuf: use C11 atomic builtins " Phil Yang
2020-07-17 4:36 ` [dpdk-dev] [PATCH v5 2/2] doc: announce deprecation of refcnt atomic member Phil Yang
2020-07-17 11:45 ` Olivier Matz
2020-07-17 14:32 ` David Marchand
2020-07-17 14:35 ` David Marchand
2020-07-17 16:06 ` Ananyev, Konstantin
2020-07-17 16:20 ` Bruce Richardson
2020-07-21 8:35 ` David Marchand
2020-07-21 8:48 ` Ananyev, Konstantin
2020-07-21 8:37 ` [dpdk-dev] [PATCH v5 1/2] mbuf: use C11 atomic builtins for refcnt operations David Marchand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1594289442-18594-1-git-send-email-phil.yang@arm.com \
--to=phil.yang@arm.com \
--cc=Honnappa.Nagarahalli@arm.com \
--cc=Ruifeng.Wang@arm.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=drc@linux.vnet.ibm.com \
--cc=nd@arm.com \
--cc=olivier.matz@6wind.com \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).