prepare deprecation of rte_atomicNN_*() family
Subsystems (7)
PATCH v4 23/27 net/txgbe: replace rte_atomic32 with stdatomic
In reply to Stephen HemmingerThe swfw_busy flag guarding the AML SW-FW mailbox is a one-bit lock, so convert it to RTE_ATOMIC(bool) and replace the legacy test-and-set / clear pair with explicit acquire-release:
rte_atomic32_test_and_set ->
rte_atomic_exchange_explicit(.., true, acquire)
rte_atomic32_clear ->
rte_atomic_store_explicit(.., false, release)
Acquire on the take pairs with release on the drop, so accesses inside the critical section are synchronized between successive holders. Default zero-initialization of struct txgbe_hw still gives swfw_busy = false, so no init site needs updating.
Note:
The previous rte_atomic32_test_and_set return value was inverted relative to what this code expected; this patch incidentally corrects that. A standalone Fixes: patch is queued in net-next.
--- drivers/net/txgbe/base/txgbe_mng.c | 4 ++-- drivers/net/txgbe/base/txgbe_type.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/txgbe/base/txgbe_mng.c +2 -2
@@ -185,7 +185,7 @@ txgbe_host_interface_command_aml(struct txgbe_hw *hw, u32 *buffer, }/* try to get lock */ -while (rte_atomic32_test_and_set (&hw->swfw_busy)) { +while (rte_atomic_exchange_explicit (&hw->swfw_busy, true, rte_memory_order_acquire)) { timeout--;if (!timeout)return TXGBE_ERR_TIMEOUT ;
@@ -266,7 +266,7 @@ txgbe_host_interface_command_aml(struct txgbe_hw *hw, u32 *buffer,/* index++, index replace txgbe_hic_hdr.checksum */ hw->swfw_index = resp->index ==TXGBE_HIC_HDR_INDEX_MAX ?0 : resp->index +1 ; -rte_atomic32_clear (&hw->swfw_busy); +rte_atomic_store_explicit (&hw->swfw_busy, false, rte_memory_order_release);return err; }
drivers/net/txgbe/base/txgbe_type.h +1 -1
@@ -880,7 +880,7 @@ struct txgbe_hw {rte_spinlock_t phy_lock;/*amlite: new SW-FW mbox */ u8 swfw_index; -rte_atomic32_t swfw_busy; +RTE_ATOMIC (bool ) swfw_busy;u32 fec_mode;u32 cur_fec_link; };
Signature · 1 line
2.53.0
PATCH v4 24/27 net/vhost: use stdatomic instead of rte_atomic32
In reply to Stephen HemmingerConvert allow_queuing, while_queuing, started, and dev_attached from rte_atomic32_t to RTE_ATOMIC(uint32_t) and replace rte_atomic32_*() with rte_atomic_*_explicit().
The data-path / control-thread handshake on allow_queuing and while_queuing is a Dekker-style mutual-visibility pattern: each side stores its own flag and then loads the peer's. Both legs must be seq_cst to forbid store-load reordering; anything weaker permits both sides to miss each other. The previous rte_atomic32_set/read compiled to plain volatile stores/loads and provided no such ordering, so this also closes a latent ordering hole on weakly-ordered ISAs.
The data-path exit store of while_queuing=0 is release, ordering preceding slot accesses before the control thread observes the data path as idle.
The flags started and dev_attached are consulted only inside update_queuing_status, where the per-queue handshake provides the real synchronization; their loads and stores are relaxed.
Factor the per-queue allow_queuing store and while_queuing wait into a small update_queue() helper used by both rx and tx loops.
--- drivers/net/vhost/rte_eth_vhost.c | 103 +++++++++++++++++++----------- 1 file changed, 65 insertions(+), 38 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +65 -38
@@ -73,8 +73,8 @@ struct vhost_stats {struct vhost_queue {int vid; -rte_atomic32_t allow_queuing; -rte_atomic32_t while_queuing; +RTE_ATOMIC (uint32_t ) allow_queuing; +RTE_ATOMIC (uint32_t ) while_queuing;struct pmd_internal *internal;struct rte_mempool *mb_pool;uint16_t port;
@@ -86,14 +86,14 @@ struct vhost_queue { };struct pmd_internal { -rte_atomic32_t dev_attached; +RTE_ATOMIC (uint32_t ) dev_attached;char *iface_name;uint64_t flags;uint64_t disable_flags;uint64_t features;uint16_t max_queues;int vid; -rte_atomic32_t started; +RTE_ATOMIC (uint32_t ) started;bool vlan_strip;bool rx_sw_csum;bool tx_sw_csum;
@@ -406,12 +406,19 @@ eth_vhost_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)uint16_t i, nb_rx =0 ;uint16_t nb_receive = nb_bufs; -if (unlikely (rte_atomic32_read (&r->allow_queuing) ==0 )) +/* Fast-path early exit; racy load is fine here -- if we miss a +* transition we get caught by the seq_cst check below. +*/ +if (unlikely (rte_atomic_load_explicit (&r->allow_queuing, rte_memory_order_relaxed) ==0 ))return 0 ; -rte_atomic32_set (&r->while_queuing,1 ); - -if (unlikely (rte_atomic32_read (&r->allow_queuing) ==0 )) +/* Announce presence, then re-check. The store and the following +* load MUST both be seq_cst so they are totally ordered with the +* control thread's store-to-allow_queuing / load-of-while_queuing +* pair. Anything weaker permits both sides to miss each other. +*/ +rte_atomic_store_explicit (&r->while_queuing,1 , rte_memory_order_seq_cst); +if (unlikely (rte_atomic_load_explicit (&r->allow_queuing, rte_memory_order_seq_cst) ==0 )) goto out;/* Dequeue packets from guest TX queue */
@@ -446,7 +453,7 @@ eth_vhost_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) } out: -rte_atomic32_set (&r->while_queuing,0 ); +rte_atomic_store_explicit (&r->while_queuing,0 , rte_memory_order_release);return nb_rx; }
@@ -460,12 +467,19 @@ eth_vhost_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)uint64_t nb_bytes =0 ;uint64_t nb_missed =0 ; -if (unlikely (rte_atomic32_read (&r->allow_queuing) ==0 )) +/* Fast-path early exit; racy load is fine here -- if we miss a +* transition we get caught by the seq_cst check below. +*/ +if (unlikely (rte_atomic_load_explicit (&r->allow_queuing, rte_memory_order_relaxed) ==0 ))return 0 ; -rte_atomic32_set (&r->while_queuing,1 ); - -if (unlikely (rte_atomic32_read (&r->allow_queuing) ==0 )) +/* Announce presence, then re-check. The store and the following +* load MUST both be seq_cst so they are totally ordered with the +* control thread's store-to-allow_queuing / load-of-while_queuing +* pair. Anything weaker permits both sides to miss each other. +*/ +rte_atomic_store_explicit (&r->while_queuing,1 , rte_memory_order_seq_cst); +if (unlikely (rte_atomic_load_explicit (&r->allow_queuing, rte_memory_order_seq_cst) ==0 )) goto out;for (i =0 ; i < nb_bufs; i++) {
@@ -515,7 +529,7 @@ eth_vhost_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)for (i =0 ;likely (i < nb_tx); i++)rte_pktmbuf_free (bufs[i]); out: -rte_atomic32_set (&r->while_queuing,0 ); +rte_atomic_store_explicit (&r->while_queuing,0 , rte_memory_order_release);return nb_tx; }
@@ -744,6 +758,19 @@ eth_vhost_unconfigure_intr(struct rte_eth_dev *eth_dev) } } +static inline void +update_queue (struct vhost_queue *vq,uint32_t allow,bool wait_queuing) +{ +/* seq_cst: pairs with the data-path's seq_cst store of +* while_queuing and seq_cst load of allow_queuing. See +* eth_vhost_rx(). +*/ +rte_atomic_store_explicit (&vq->allow_queuing, allow, rte_memory_order_seq_cst); +if (wait_queuing) +rte_wait_until_equal_32 ((volatile uint32_t *)(uintptr_t )&vq->while_queuing, +0 , rte_memory_order_seq_cst); +} +static void update_queuing_status (struct rte_eth_dev *dev,bool wait_queuing) {
@@ -751,14 +778,18 @@ update_queuing_status(struct rte_eth_dev *dev, bool wait_queuing)struct vhost_queue *vq;struct rte_vhost_vring_state *state;unsigned int i; -int allow_queuing =1 ; +bool allow_queuing = true;if (!dev->data->rx_queues || !dev->data->tx_queues)return ; -if (rte_atomic32_read (&internal->started) ==0 || -rte_atomic32_read (&internal->dev_attached) ==0 ) - allow_queuing =0 ; +/* These are control-plane flags consulted only here; +* the real data-path handshake is on vq->allow_queuing below. +* Relaxed is sufficient. +*/ +if (rte_atomic_load_explicit (&internal->started, rte_memory_order_relaxed) ==0 || +rte_atomic_load_explicit (&internal->dev_attached, rte_memory_order_relaxed) ==0 ) + allow_queuing = false; state = vring_states[dev->data->port_id];
@@ -767,24 +798,18 @@ update_queuing_status(struct rte_eth_dev *dev, bool wait_queuing) vq = dev->data->rx_queues[i];if (vq ==NULL )continue ; -if (allow_queuing && state->cur[vq->virtqueue_id]) -rte_atomic32_set (&vq->allow_queuing,1 ); -else -rte_atomic32_set (&vq->allow_queuing,0 ); -while (wait_queuing &&rte_atomic32_read (&vq->while_queuing)) -rte_pause (); + +update_queue (vq, !!(allow_queuing && state->cur[vq->virtqueue_id]), + wait_queuing); }for (i =0 ; i < dev->data->nb_tx_queues; i++) { vq = dev->data->tx_queues[i];if (vq ==NULL )continue ; -if (allow_queuing && state->cur[vq->virtqueue_id]) -rte_atomic32_set (&vq->allow_queuing,1 ); -else -rte_atomic32_set (&vq->allow_queuing,0 ); -while (wait_queuing &&rte_atomic32_read (&vq->while_queuing)) -rte_pause (); + +update_queue (vq, !!(allow_queuing && state->cur[vq->virtqueue_id]), + wait_queuing); } }
@@ -848,7 +873,7 @@ new_device(int vid) } internal->vid = vid; -if (rte_atomic32_read (&internal->started) ==1 ) { +if (rte_atomic_load_explicit (&internal->started, rte_memory_order_relaxed) ==1 ) {queue_setup (eth_dev, internal);if (dev_conf->intr_conf.rxq)eth_vhost_configure_intr (eth_dev);
@@ -863,7 +888,7 @@ new_device(int vid)vhost_dev_csum_configure (eth_dev); -rte_atomic32_set (&internal->dev_attached,1 ); +rte_atomic_store_explicit (&internal->dev_attached,1 , rte_memory_order_relaxed);update_queuing_status (eth_dev, false);VHOST_LOG_LINE (INFO ,"Vhost device %d created" , vid);
@@ -893,7 +918,7 @@ destroy_device(int vid) eth_dev = list->eth_dev; internal = eth_dev->data->dev_private; -rte_atomic32_set (&internal->dev_attached,0 ); +rte_atomic_store_explicit (&internal->dev_attached,0 , rte_memory_order_relaxed);update_queuing_status (eth_dev, true);eth_vhost_unconfigure_intr (eth_dev);
@@ -1148,11 +1173,11 @@ eth_dev_start(struct rte_eth_dev *eth_dev) }queue_setup (eth_dev, internal); -if (rte_atomic32_read (&internal->dev_attached) ==1 && +if (rte_atomic_load_explicit (&internal->dev_attached, rte_memory_order_relaxed) ==1 && dev_conf->intr_conf.rxq)eth_vhost_configure_intr (eth_dev); -rte_atomic32_set (&internal->started,1 ); +rte_atomic_store_explicit (&internal->started,1 , rte_memory_order_relaxed);update_queuing_status (eth_dev, false);for (i =0 ; i < eth_dev->data->nb_rx_queues; i++)
@@ -1170,7 +1195,7 @@ eth_dev_stop(struct rte_eth_dev *dev)uint16_t i; dev->data->dev_started =0 ; -rte_atomic32_set (&internal->started,0 ); +rte_atomic_store_explicit (&internal->started,0 , rte_memory_order_relaxed);update_queuing_status (dev, true);for (i =0 ; i < dev->data->nb_rx_queues; i++)
@@ -1471,8 +1496,10 @@ vhost_dev_priv_dump(struct rte_eth_dev *dev, FILE *f)fprintf (f,"features: 0x%" PRIx64"\n" , internal->features);fprintf (f,"max_queues: %u\n" , internal->max_queues);fprintf (f,"vid: %d\n" , internal->vid); -fprintf (f,"started: %d\n" ,rte_atomic32_read (&internal->started)); -fprintf (f,"dev_attached: %d\n" ,rte_atomic32_read (&internal->dev_attached)); +fprintf (f,"started: %u\n" , +rte_atomic_load_explicit (&internal->started, rte_memory_order_relaxed)); +fprintf (f,"dev_attached: %u\n" , +rte_atomic_load_explicit (&internal->dev_attached, rte_memory_order_relaxed));fprintf (f,"vlan_strip: %d\n" , internal->vlan_strip);fprintf (f,"rx_sw_csum: %d\n" , internal->rx_sw_csum);fprintf (f,"tx_sw_csum: %d\n" , internal->tx_sw_csum);
Signature · 1 line
2.53.0
PATCH v4 25/27 vdpa/ifc: replace rte_atomic32 with stdatomic
In reply to Stephen HemmingerLast in-tree caller of rte_atomic32_*(), blocking deprecation of the rte_atomicNN_*() family.
Replace rte_atomic32_read/set() with rte_atomic_load_explicit() and rte_atomic_store_explicit() on the started, dev_attached, and running flags. Narrow them to bool (only ever hold 0/1) and group with the existing bools to reduce padding in struct ifcvf_internal.
--- drivers/vdpa/ifc/ifcvf_vdpa.c | 37 ++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 18 deletions(-)
drivers/vdpa/ifc/ifcvf_vdpa.c +19 -18
@@ -25,6 +25,7 @@#include <rte_log.h> #include <rte_kvargs.h> #include <rte_devargs.h> +#include <rte_stdatomic.h> #include "base/ifcvf.h"
@@ -68,10 +69,10 @@ struct ifcvf_internal {struct rte_vdpa_device *vdev;uint16_t max_queues;uint64_t features; -rte_atomic32_t started; -rte_atomic32_t dev_attached; -rte_atomic32_t running;rte_spinlock_t lock; +RTE_ATOMIC (bool ) started; +RTE_ATOMIC (bool ) dev_attached; +RTE_ATOMIC (bool ) running;bool sw_lm;bool sw_fallback_running;/* mediated vring for sw fallback */
@@ -712,9 +713,9 @@ update_datapath(struct ifcvf_internal *internal)rte_spinlock_lock (&internal->lock); -if (!rte_atomic32_read (&internal->running) && - (rte_atomic32_read (&internal->started) && -rte_atomic32_read (&internal->dev_attached))) { +if (!rte_atomic_load_explicit (&internal->running, rte_memory_order_seq_cst) && + (rte_atomic_load_explicit (&internal->started, rte_memory_order_seq_cst) && +rte_atomic_load_explicit (&internal->dev_attached, rte_memory_order_seq_cst))) { ret =ifcvf_dma_map (internal, true);if (ret) goto err;
@@ -735,10 +736,10 @@ update_datapath(struct ifcvf_internal *internal)if (ret) goto err; -rte_atomic32_set (&internal->running,1 ); - }else if (rte_atomic32_read (&internal->running) && - (!rte_atomic32_read (&internal->started) || - !rte_atomic32_read (&internal->dev_attached))) { +rte_atomic_store_explicit (&internal->running, true, rte_memory_order_seq_cst); + }else if (rte_atomic_load_explicit (&internal->running, rte_memory_order_seq_cst) && + (!rte_atomic_load_explicit (&internal->started, rte_memory_order_seq_cst) || + !rte_atomic_load_explicit (&internal->dev_attached, rte_memory_order_seq_cst))) {unset_intr_relay (internal); ret =unset_notify_relay (internal);
@@ -755,7 +756,7 @@ update_datapath(struct ifcvf_internal *internal)if (ret) goto err; -rte_atomic32_set (&internal->running,0 ); +rte_atomic_store_explicit (&internal->running, false, rte_memory_order_seq_cst); }rte_spinlock_unlock (&internal->lock);
@@ -1058,7 +1059,7 @@ ifcvf_sw_fallback_switchover(struct ifcvf_internal *internal)vdpa_disable_vfio_intr (internal); -rte_atomic32_set (&internal->running,0 ); +rte_atomic_store_explicit (&internal->running, false, rte_memory_order_seq_cst); ret =rte_vhost_host_notifier_ctrl (vid,RTE_VHOST_QUEUE_ALL , false);if (ret && ret != -ENOTSUP )
@@ -1113,11 +1114,11 @@ ifcvf_dev_config(int vid) internal = list->internal; internal->vid = vid; -rte_atomic32_set (&internal->dev_attached,1 ); +rte_atomic_store_explicit (&internal->dev_attached, true, rte_memory_order_seq_cst);if (update_datapath (internal) <0 ) {DRV_LOG (ERR ,"failed to update datapath for vDPA device %s" , vdev->device->name); -rte_atomic32_set (&internal->dev_attached,0 ); +rte_atomic_store_explicit (&internal->dev_attached, false, rte_memory_order_seq_cst);return -1 ; }
@@ -1166,7 +1167,7 @@ ifcvf_dev_close(int vid) internal->sw_fallback_running = false; }else { -rte_atomic32_set (&internal->dev_attached,0 ); +rte_atomic_store_explicit (&internal->dev_attached, false, rte_memory_order_seq_cst);if (update_datapath (internal) <0 ) {DRV_LOG (ERR ,"failed to update datapath for vDPA device %s" , vdev->device->name);
@@ -1782,10 +1783,10 @@ ifcvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, goto error; } -rte_atomic32_set (&internal->started,1 ); +rte_atomic_store_explicit (&internal->started, true, rte_memory_order_seq_cst);if (update_datapath (internal) <0 ) {DRV_LOG (ERR ,"failed to update datapath %s" , pci_dev->name); -rte_atomic32_set (&internal->started,0 ); +rte_atomic_store_explicit (&internal->started, false, rte_memory_order_seq_cst);rte_vdpa_unregister_device (internal->vdev);pthread_mutex_lock (&internal_list_lock);TAILQ_REMOVE (&internal_list, list, next);
@@ -1819,7 +1820,7 @@ ifcvf_pci_remove(struct rte_pci_device *pci_dev) } internal = list->internal; -rte_atomic32_set (&internal->started,0 ); +rte_atomic_store_explicit (&internal->started, false, rte_memory_order_seq_cst);if (update_datapath (internal) <0 )DRV_LOG (ERR ,"failed to update datapath %s" , pci_dev->name);
Signature · 1 line
2.53.0
PATCH v4 26/27 test/atomic: suppress deprecation warnings for legacy APIs
In reply to Stephen HemmingerThe rte_atomicNN_* APIs are now marked __rte_deprecated. Wrap the whole file with __rte_diagnostic_push / pop and a GCC pragma -Wdeprecated-declarations.
In future, when the APIs are removed this test collapses to just the 128-bit compare-and-swap case and the suppression goes with it.
--- app/test/test_atomic.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
app/test/test_atomic.c +12 -0
@@ -100,6 +100,15 @@* - At the end of the test, the number of corrupted tokens must be 0. */ +/* +* The rte_atomicNN_* APIs exercised below are deprecated in favour of C11 atomics. +* Suppress the deprecation warnings for the whole file; +* when the APIs are removed this test collapses to the 128-bit +* compare-and-swap case and the suppression goes with it. +*/ +__rte_diagnostic_push +_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#define NUM_ATOMIC_TYPES 3#define N_BASE 1000000u
@@ -645,4 +654,7 @@ test_atomic(void)return 0 ; }REGISTER_FAST_TEST (atomic_autotest,NOHUGE_SKIP ,ASAN_OK , test_atomic); + +__rte_diagnostic_pop +#endif /* RTE_TOOLCHAIN_MSVC */
Signature · 1 line
2.53.0
PATCH v4 27/27 eal: mark rte_atomicNN as deprecated
In reply to Stephen HemmingerThe decision to deprecate the rte_atomicNN functions was made back in 2021, but in-tree code continued to use them. Now thatall in-tree callers have been converted to C11 stdatomic, markthe functions with __rte_deprecated so any remaining user code will see the deprecation warning.
Since any new use of rte_atomicNN will be caught by the compiler, there is no longer any need to check for it in checkpatches.
--- devtools/checkpatches.sh | 8 -- doc/guides/rel_notes/deprecation.rst | 4 +- doc/guides/rel_notes/release_26_07.rst | 4 + lib/eal/include/generic/rte_atomic.h | 100 ++++++++++++++----------- lib/eal/include/rte_common.h | 2 + 5 files changed, 62 insertions(+), 56 deletions(-)
devtools/checkpatches.sh +0 -8
@@ -113,14 +113,6 @@ check_forbidden_additions() { # <patch> -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ "$1" || res=1 - # refrain from new additions of 16/32/64 bits rte_atomicNN_xxx() - awk -v FOLDERS="lib drivers app examples" \ - -v EXPRESSIONS="rte_atomic[0-9][0-9]_.*\\\(" \ - -v RET_ON_FAIL=1 \ - -v MESSAGE='Using rte_atomicNN_xxx' \ - -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ - "$1" || res=1 - # refrain from using compiler __sync_xxx builtins awk -v FOLDERS="lib drivers app examples" \ -v EXPRESSIONS="__sync_.*\\\(" \
doc/guides/rel_notes/deprecation.rst +1 -3
@@ -43,9 +43,7 @@ Deprecation Notices * rte_atomicNN_xxx: These APIs do not take memory order parameter. This does not allow for writing optimized code for all the CPU architectures supported in DPDK. DPDK has adopted the atomic operations from - https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html. These - operations must be used for patches that need to be merged in 20.08 onwards. - This change will not introduce any performance degradation. + https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html. * lib: will fix extending some enum/define breaking the ABI. There are multiple samples in DPDK that enum/define terminated with a ``.*MAX.*`` value which is
doc/guides/rel_notes/release_26_07.rst +4 -0
@@ -106,6 +106,10 @@ API Changes Also, make sure to start the actual text at the margin. ======================================================= +* atomic: Marked the ``rte_atomicNN`` functions as deprecated. + As previously announced these functions were intended to be deprecated + but was not being enforced. + ABI Changes -----------
lib/eal/include/generic/rte_atomic.h +55 -45
382 lines not on this page · raw message
lib/eal/include/rte_common.h +2 -0
@@ -172,9 +172,11 @@ typedef uint16_t unaligned_uint16_t;#ifdef RTE_TOOLCHAIN_MSVC #define __rte_deprecated#define __rte_deprecated_msg (msg) +#define __rte_allow_deprecated#else #define __rte_deprecated __attribute__((__deprecated__))#define __rte_deprecated_msg (msg) __attribute__((__deprecated__(msg))) +#define __rte_allow_deprecated _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")#endif /**
Signature · 1 line
2.53.0
v6 cover replace use of rte_atomicNN
In reply to Stephen HemmingerThe rte_atomicNN_* family was flagged for deprecation in 2021 by commit 3ec965b6de12 ("doc: update atomic operation deprecation") but enforcement never landed and in-tree usage continued to grow.
This series finishes converting every remaining in-tree caller to the C11-style rte_atomic_*_explicit() / RTE_ATOMIC() API, then marks the legacy functions __rte_deprecated so future in-tree and out-of-tree uses are caught at compile time.
The goal of this series is to get driver writers to review and test each change.
v6 - rebase for 26.11
- address some more AI review comments
Stephen Hemminger (24):
bpf: use C11 atomics in BPF_ST_ATOMIC_REG net/bonding: use stdatomic
net/nbl: remove unused rte_atomic16 field net/ena: replace use of rte_atomicNN net/failsafe: convert to stdatomic
net/enic: do not use deprecated rte_atomic64 net/pfe: use ethdev linkstatus helpers
net/sfc: replace rte_atomic with stdatomic crypto/ccp: replace use of rte_atomic64 with stdatomic bus/dpaa: replace rte_atomic16 with stdatomic bus/fslmc: replace rte_atomic16 with stdatomic net/netvsc: replace rte_atomic32 with stdatomic event/sw: convert from rte_atomic32 to stdatomic bus/vmbus: convert from rte_atomic to stdatomic common/dpaax: use stdatomic instead of rte_atomic net/bnx2x: convert from rte_atomic32 to stdatomic bus/fslmc: replace rte_atomic32 with stdatomic drivers/event: replace rte_atomic32 in selftests net/hinic: replace rte_atomic32 with stdatomic net/txgbe: replace rte_atomic32 with stdatomic net/vhost: use stdatomic instead of rte_atomic32 vdpa/ifc: replace rte_atomic32 with stdatomic test/atomic: suppress deprecation warnings for legacy APIs
eal: deprecate rte_atomicNN functions
app/test/test_atomic.c | 12 + devtools/checkpatches.sh | 8 - doc/guides/rel_notes/deprecation.rst | 4 +- doc/guides/rel_notes/release_26_11.rst | 5 + drivers/bus/dpaa/base/qbman/qman.c | 9 +- drivers/bus/fslmc/portal/dpaa2_hw_dpbp.c | 11 +- drivers/bus/fslmc/portal/dpaa2_hw_dpci.c | 11 +- drivers/bus/fslmc/portal/dpaa2_hw_dpcon.c | 11 +- drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 14 +- drivers/bus/fslmc/portal/dpaa2_hw_pvt.h | 9 +- drivers/bus/fslmc/qbman/include/compat.h | 21 +- drivers/bus/vmbus/private.h | 2 +- drivers/bus/vmbus/vmbus_bufring.c | 39 +-- drivers/common/dpaax/compat.h | 25 +- drivers/crypto/ccp/ccp_crypto.c | 11 +- drivers/crypto/ccp/ccp_crypto.h | 2 +- drivers/crypto/ccp/ccp_dev.c | 10 +- drivers/crypto/ccp/ccp_dev.h | 4 +- drivers/event/dpaa2/dpaa2_eventdev_selftest.c | 26 +- drivers/event/octeontx/ssovf_evdev_selftest.c | 61 +++-- drivers/event/sw/sw_evdev.c | 8 +- drivers/event/sw/sw_evdev.h | 4 +- drivers/event/sw/sw_evdev_worker.c | 16 +- drivers/net/bnx2x/bnx2x.c | 6 +- drivers/net/bnx2x/bnx2x.h | 2 +- drivers/net/bnx2x/ecore_sp.c | 6 +- drivers/net/bonding/eth_bond_8023ad_private.h | 6 +- drivers/net/bonding/rte_eth_bond_8023ad.c | 35 +-- drivers/net/ena/base/ena_plat_dpdk.h | 14 +- drivers/net/ena/ena_ethdev.c | 21 +- drivers/net/ena/ena_ethdev.h | 7 +- drivers/net/enic/enic.h | 6 +- drivers/net/enic/enic_compat.h | 1 - drivers/net/enic/enic_main.c | 17 +- drivers/net/enic/enic_rxtx.c | 14 +- drivers/net/enic/enic_rxtx_vec_avx2.c | 4 +- drivers/net/failsafe/failsafe_ops.c | 12 +- drivers/net/failsafe/failsafe_private.h | 29 ++- drivers/net/failsafe/failsafe_rxtx.c | 2 +- drivers/net/hinic/base/hinic_compat.h | 2 +- drivers/net/hinic/base/hinic_pmd_hwdev.c | 24 +- drivers/net/hinic/base/hinic_pmd_hwdev.h | 4 +- drivers/net/nbl/nbl_hw/nbl_resource.h | 1 - drivers/net/netvsc/hn_rndis.c | 28 +- drivers/net/netvsc/hn_rxtx.c | 12 +- drivers/net/netvsc/hn_var.h | 6 +- drivers/net/pfe/pfe_ethdev.c | 32 +-- drivers/net/sfc/sfc.c | 9 +- drivers/net/sfc/sfc.h | 4 +- drivers/net/sfc/sfc_port.c | 7 +- drivers/net/sfc/sfc_stats.h | 2 +- drivers/net/txgbe/base/txgbe_mng.c | 4 +- drivers/net/txgbe/base/txgbe_type.h | 2 +- drivers/net/vhost/rte_eth_vhost.c | 103 +++++--- drivers/vdpa/ifc/ifcvf_vdpa.c | 37 +-- lib/bpf/bpf_exec.c | 13 +- lib/eal/arm/include/rte_atomic_32.h | 4 - lib/eal/arm/include/rte_atomic_64.h | 4 - lib/eal/include/generic/rte_atomic.h | 243 +++++------------- lib/eal/include/rte_common.h | 2 + lib/eal/loongarch/include/rte_atomic.h | 4 - lib/eal/ppc/include/rte_atomic.h | 173 ------------- lib/eal/riscv/include/rte_atomic.h | 4 - lib/eal/x86/include/rte_atomic.h | 172 ------------- lib/eal/x86/include/rte_atomic_32.h | 188 -------------- lib/eal/x86/include/rte_atomic_64.h | 157 ----------- 66 files changed, 482 insertions(+), 1264 deletions(-)
Signature · 1 line
2.53.0
PATCH v6 1/24 bpf: use C11 atomics in BPF_ST_ATOMIC_REG
The BPF_ST_ATOMIC_REG macro generated code with deprecated rte_atomicNN_add and rte_atomicNN_exchange.
Replace this with the equivalent rte_stdatomic definitions. Use memory order seq_cst to preserve the previous behavior of rte_atomicNN_add() / rte_atomicNN_exchange() and matches the Linux kernel BPF interpreter for these opcodes.
--- lib/bpf/bpf_exec.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
lib/bpf/bpf_exec.c +7 -6
@@ -11,6 +11,7 @@#include <rte_debug.h> #include <rte_byteorder.h> #include <rte_errno.h> +#include <rte_stdatomic.h> #include "bpf_impl.h"
@@ -66,16 +67,16 @@ (type)(reg)[(ins)->src_reg])#define BPF_ST_ATOMIC_REG (reg, ins, tp) do { \ + RTE_ATOMIC(uint##tp##_t) *dst = (RTE_ATOMIC(uint##tp##_t) *) \ + (uintptr_t)((reg)[(ins)->dst_reg] + (ins)->off); \ switch (ins->imm) { \ case BPF_ATOMIC_ADD: \ - rte_atomic##tp##_add((rte_atomic##tp##_t *) \ - (uintptr_t)((reg)[(ins)->dst_reg] + (ins)->off), \ - (reg)[(ins)->src_reg]); \ + rte_atomic_fetch_add_explicit(dst, \ + (reg)[(ins)->src_reg], rte_memory_order_seq_cst); \ break; \ case BPF_ATOMIC_XCHG: \ - (reg)[(ins)->src_reg] = rte_atomic##tp##_exchange((uint##tp##_t *) \ - (uintptr_t)((reg)[(ins)->dst_reg] + (ins)->off), \ - (reg)[(ins)->src_reg]); \ + (reg)[(ins)->src_reg] = rte_atomic_exchange_explicit(dst, \ + (reg)[(ins)->src_reg], rte_memory_order_seq_cst); \ break; \ default: \/* this should be caught by validator and never reach here */ \
Signature · 1 line
2.53.0
PATCH v6 2/24 net/bonding: use stdatomic
In reply to Stephen HemmingerThe old rte_atomic16 and rte_atomic64 functions are deprecated. Replace with rte_stdatomic for managing warning and timer flags.
--- drivers/net/bonding/eth_bond_8023ad_private.h | 6 ++-- drivers/net/bonding/rte_eth_bond_8023ad.c | 35 ++++++++----------- 2 files changed, 17 insertions(+), 24 deletions(-)
drivers/net/bonding/eth_bond_8023ad_private.h +3 -3
@@ -9,7 +9,7 @@#include <rte_ether.h> #include <rte_byteorder.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_flow.h> #include "rte_eth_bond_8023ad.h"
@@ -140,10 +140,10 @@ struct port {/** Timer which is also used as mutex. If is 0 (not running) RX marker * packet might be responded. Otherwise shall be dropped. It is zeroed in * mode 4 callback function after expire. */ -volatile uint64_t rx_marker_timer; +RTE_ATOMIC (uint64_t ) rx_marker_timer;uint64_t warning_timer; -volatile uint16_t warnings_to_show; +RTE_ATOMIC (uint16_t ) warnings_to_show;/** Memory pool used to allocate slow queues */ struct rte_mempool *slow_pool;
drivers/net/bonding/rte_eth_bond_8023ad.c +14 -21
@@ -171,27 +171,17 @@ timer_is_running(uint64_t *timer)static void set_warning_flags (struct port *port,uint16_t flags) { -int retval; -uint16_t old; -uint16_t new_flag =0 ; - -do { - old = port->warnings_to_show; - new_flag = old | flags; - retval =rte_atomic16_cmpset (&port->warnings_to_show, old, new_flag); - }while (unlikely (retval ==0 )); +rte_atomic_fetch_or_explicit (&port->warnings_to_show, flags, rte_memory_order_relaxed); }static void show_warnings (uint16_t member_id) {struct port *port = &bond_mode_8023ad_ports[member_id]; -uint8_t warnings; - -do { - warnings = port->warnings_to_show; - }while (rte_atomic16_cmpset (&port->warnings_to_show, warnings,0 ) ==0 ); +uint16_t warnings; + warnings =rte_atomic_exchange_explicit (&port->warnings_to_show,0 , + rte_memory_order_relaxed);if (!warnings)return ;
@@ -1335,7 +1325,6 @@ bond_mode_8023ad_handle_slow_pkt(struct bond_dev_private *internals,struct port *port = &bond_mode_8023ad_ports[member_id];struct marker_header *m_hdr;uint64_t marker_timer, old_marker_timer; -int retval;uint8_t wrn, subtype;/* If packet is a marker, we send response now by reusing given packet * and update only source MAC, destination MAC is multicast so don't
@@ -1352,17 +1341,19 @@ bond_mode_8023ad_handle_slow_pkt(struct bond_dev_private *internals, }/* Setup marker timer. Do it in loop in case concurrent access. */ + old_marker_timer =rte_atomic_load_explicit (&port->rx_marker_timer, + rte_memory_order_acquire);do { - old_marker_timer = port->rx_marker_timer;if (!timer_is_expired (&old_marker_timer)) { wrn =WRN_RX_MARKER_TO_FAST ; goto free_out; }timer_set (&marker_timer, mode4->rx_marker_timeout); - retval =rte_atomic64_cmpset (&port->rx_marker_timer, - old_marker_timer, marker_timer); - }while (unlikely (retval ==0 )); + + }while (!rte_atomic_compare_exchange_weak_explicit (&port->rx_marker_timer, + &old_marker_timer, marker_timer, + rte_memory_order_release, rte_memory_order_acquire)); m_hdr->marker.tlv_type_marker =MARKER_TLV_TYPE_RESP ;rte_eth_macaddr_get (member_id, &m_hdr->eth_hdr.src_addr);
@@ -1370,7 +1361,8 @@ bond_mode_8023ad_handle_slow_pkt(struct bond_dev_private *internals,if (internals->mode4.dedicated_queues.enabled ==0 ) {if (rte_ring_enqueue (port->tx_ring, pkt) !=0 ) {/* reset timer */ - port->rx_marker_timer =0 ; +rte_atomic_store_explicit (&port->rx_marker_timer,0 , + rte_memory_order_release); wrn =WRN_TX_QUEUE_FULL ; goto free_out; }
@@ -1384,7 +1376,8 @@ bond_mode_8023ad_handle_slow_pkt(struct bond_dev_private *internals, &pkt, tx_count);if (tx_count !=1 ) {/* reset timer */ - port->rx_marker_timer =0 ; +rte_atomic_store_explicit (&port->rx_marker_timer,0 , + rte_memory_order_release); wrn =WRN_TX_QUEUE_FULL ; goto free_out; }
Signature · 1 line
2.53.0
PATCH v6 3/24 net/nbl: remove unused rte_atomic16 field
In reply to Stephen HemmingerThe tx_current_queue was defined as rte_atomic16_t which is deprecated. Remove it since it was never used.
--- drivers/net/nbl/nbl_hw/nbl_resource.h | 1 - 1 file changed, 1 deletion(-)
drivers/net/nbl/nbl_hw/nbl_resource.h +0 -1
@@ -225,7 +225,6 @@ struct nbl_res_info {u16 base_qid;u16 lcore_max;u16 *pf_qid_to_lcore_id; -rte_atomic16_t tx_current_queue; };struct nbl_resource_mgt {
Signature · 1 line
2.53.0
PATCH v6 4/24 net/ena: replace use of rte_atomicNN
In reply to Stephen HemmingerConvert the legacy rte_atomicNN operations to stdatomic.
* Remove variable ena_alloc_cnt is defined by not used. It is a leftover from previous memzone naming scheme.
* Convert the legacy rte_atomic32_t and rte_atomic32_{inc,dec,set,read} macros to C11 stdatomic equivalents.
Memory ordering is kept at seq_cst,
matching the implicit ordering of the legacy API.
* Do not use rte_atomic for statistics
The DPDK PMD model is that statistics do not have to be exact in face of contention.
--- drivers/net/ena/base/ena_plat_dpdk.h | 14 +++++++++----- drivers/net/ena/ena_ethdev.c | 21 ++++++--------------- drivers/net/ena/ena_ethdev.h | 7 +++---- 3 files changed, 18 insertions(+), 24 deletions(-)
drivers/net/ena/base/ena_plat_dpdk.h +9 -5
@@ -40,7 +40,7 @@ typedef uint64_t dma_addr_t;#endif #define ENA_PRIu64 PRIu64 -#define ena_atomic32_t rte_atomic32_t +typedef RTE_ATOMIC (int32_t )ena_atomic32_t ;#define ena_mem_handle_t const struct rte_memzone *#define SZ_256 (256U)
@@ -267,10 +267,14 @@ ena_mem_alloc_coherent(struct rte_eth_dev_data *data, size_t size,#define ENA_REG_READ32 (bus, reg) \ __extension__ ({ (void)(bus); rte_read32_relaxed((reg)); }) -#define ATOMIC32_INC (i32_ptr) rte_atomic32_inc(i32_ptr) -#define ATOMIC32_DEC (i32_ptr) rte_atomic32_dec(i32_ptr) -#define ATOMIC32_SET (i32_ptr, val) rte_atomic32_set(i32_ptr, val) -#define ATOMIC32_READ (i32_ptr) rte_atomic32_read(i32_ptr) +#define ATOMIC32_INC (i32_ptr) \ + rte_atomic_fetch_add_explicit((i32_ptr), 1, rte_memory_order_seq_cst) +#define ATOMIC32_DEC (i32_ptr) \ + rte_atomic_fetch_sub_explicit((i32_ptr), 1, rte_memory_order_seq_cst) +#define ATOMIC32_SET (i32_ptr, val) \ + rte_atomic_store_explicit((i32_ptr), (val), rte_memory_order_seq_cst) +#define ATOMIC32_READ (i32_ptr) \ + rte_atomic_load_explicit((i32_ptr), rte_memory_order_seq_cst)#define msleep (x) rte_delay_us(x * 1000)#define udelay (x) rte_delay_us(x)
drivers/net/ena/ena_ethdev.c +6 -15
@@ -121,12 +121,6 @@ struct ena_stats {*/ #define ENA_DEVARG_ENABLE_FRAG_BYPASS "enable_frag_bypass" -/* -* Each rte_memzone should have unique name. -* To satisfy it, count number of allocation and add it to name. -*/ -rte_atomic64_t ena_alloc_cnt; -static const struct ena_stats ena_stats_global_strings[] = {ENA_STAT_GLOBAL_ENTRY (wd_expired),ENA_STAT_GLOBAL_ENTRY (dev_start),
@@ -1249,10 +1243,7 @@ static void ena_stats_restart(struct rte_eth_dev *dev) {struct ena_adapter *adapter = dev->data->dev_private; -rte_atomic64_init (&adapter->drv_stats->ierrors); -rte_atomic64_init (&adapter->drv_stats->oerrors); -rte_atomic64_init (&adapter->drv_stats->rx_nombuf); - adapter->drv_stats->rx_drops =0 ; +memset (adapter->drv_stats,0 ,sizeof (struct ena_driver_stats )); } static int ena_stats_get(struct rte_eth_dev *dev,
@@ -1289,9 +1280,9 @@ static int ena_stats_get(struct rte_eth_dev *dev,/* Driver related stats */ stats->imissed = adapter->drv_stats->rx_drops; - stats->ierrors =rte_atomic64_read (&adapter->drv_stats->ierrors); - stats->oerrors =rte_atomic64_read (&adapter->drv_stats->oerrors); - stats->rx_nombuf =rte_atomic64_read (&adapter->drv_stats->rx_nombuf); + stats->ierrors = adapter->drv_stats->ierrors; + stats->oerrors = adapter->drv_stats->oerrors; + stats->rx_nombuf = adapter->drv_stats->rx_nombuf;/* Queue statistics */ if (qstats) {
@@ -1887,7 +1878,7 @@ static int ena_populate_rx_queue(struct ena_ring *rxq, unsigned int count)/* get resources for incoming packets */ rc =rte_pktmbuf_alloc_bulk (rxq->mb_pool, mbufs, count);if (unlikely (rc <0 )) { -rte_atomic64_inc (&rxq->adapter->drv_stats->rx_nombuf); + ++rxq->adapter->drv_stats->rx_nombuf; ++rxq->rx_stats.mbuf_alloc_fail;PMD_RX_LOG_LINE (DEBUG ,"There are not enough free buffers" );return 0 ;
@@ -3014,7 +3005,7 @@ static uint16_t eth_ena_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,if (unlikely (mbuf->ol_flags & (RTE_MBUF_F_RX_IP_CKSUM_BAD |RTE_MBUF_F_RX_L4_CKSUM_BAD ))) -rte_atomic64_inc (&rx_ring->adapter->drv_stats->ierrors); + ++rx_ring->adapter->drv_stats->ierrors; rx_pkts[completed] = mbuf; rx_ring->rx_stats.bytes += mbuf->pkt_len;
drivers/net/ena/ena_ethdev.h +3 -4
@@ -6,7 +6,6 @@#ifndef _ENA_ETHDEV_H_#define _ENA_ETHDEV_H_ -#include <rte_atomic.h> #include <rte_ether.h> #include <ethdev_driver.h> #include <ethdev_pci.h>
@@ -225,9 +224,9 @@ enum ena_adapter_state { };struct ena_driver_stats { -rte_atomic64_t ierrors; -rte_atomic64_t oerrors; -rte_atomic64_t rx_nombuf; +u64 ierrors; +u64 oerrors; +u64 rx_nombuf;u64 rx_drops; };
Signature · 1 line
2.53.0
PATCH v6 5/24 net/failsafe: convert to stdatomic
In reply to Stephen HemmingerThe functions rte_atomic64 are deprecated, convert this code to use stdatomic for reference count. Use the memory order implied by naming P/V.
No need for initialization since refcnt is in space allocated with rte_zmalloc().
--- drivers/net/failsafe/failsafe_ops.c | 12 +++++----- drivers/net/failsafe/failsafe_private.h | 29 ++++++++++++++----------- drivers/net/failsafe/failsafe_rxtx.c | 2 +- 3 files changed, 22 insertions(+), 21 deletions(-)
drivers/net/failsafe/failsafe_ops.c +5 -7
@@ -11,7 +11,7 @@#endif #include <rte_debug.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <ethdev_driver.h> #include <rte_malloc.h> #include <rte_flow.h>
@@ -440,14 +440,13 @@ fs_rx_queue_setup(struct rte_eth_dev *dev, } rxq =rte_zmalloc (NULL ,sizeof (*rxq) + -sizeof (rte_atomic64_t) *PRIV (dev)->subs_tail, +sizeof (uint64_t ) *PRIV (dev)->subs_tail,RTE_CACHE_LINE_SIZE );if (rxq ==NULL ) {fs_unlock (dev,0 );return -ENOMEM ; } - FOREACH_SUBDEV(sdev, i, dev) -rte_atomic64_init (&rxq->refcnt[i]); + rxq->qid = rx_queue_id; rxq->socket_id = socket_id; rxq->info.mp = mb_pool;
@@ -617,14 +616,13 @@ fs_tx_queue_setup(struct rte_eth_dev *dev, } txq =rte_zmalloc ("ethdev TX queue" ,sizeof (*txq) + -sizeof (rte_atomic64_t) *PRIV (dev)->subs_tail, +sizeof (uint64_t ) *PRIV (dev)->subs_tail,RTE_CACHE_LINE_SIZE );if (txq ==NULL ) {fs_unlock (dev,0 );return -ENOMEM ; } - FOREACH_SUBDEV(sdev, i, dev) -rte_atomic64_init (&txq->refcnt[i]); + txq->qid = tx_queue_id; txq->socket_id = socket_id; txq->info.conf = *tx_conf;
drivers/net/failsafe/failsafe_private.h +16 -13
@@ -10,7 +10,7 @@#include <sys/queue.h> #include <pthread.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <dev_driver.h> #include <ethdev_driver.h> #include <rte_devargs.h>
@@ -75,7 +75,7 @@ struct rxq {int event_fd; unsigned int enable_events:1;struct rte_eth_rxq_info info; -rte_atomic64_t refcnt[]; +RTE_ATOMIC (uint64_t ) refcnt[]; };struct txq {
@@ -83,7 +83,7 @@ struct txq {uint16_t qid;unsigned int socket_id;struct rte_eth_txq_info info; -rte_atomic64_t refcnt[]; +RTE_ATOMIC (uint64_t ) refcnt[]; };struct rte_flow {
@@ -320,33 +320,36 @@ extern int failsafe_mac_from_arg;*/ /** -* a: (rte_atomic64_t) +* a: _Atomic uint64_t */ #define FS_ATOMIC_P (a) \ - rte_atomic64_set(&(a), 1) + rte_atomic_exchange_explicit(&(a), 1, rte_memory_order_acquire)/** -* a: (rte_atomic64_t) +* a: _Atomic uint64_t */ #define FS_ATOMIC_V (a) \ - rte_atomic64_set(&(a), 0) + rte_atomic_store_explicit(&(a), 0, rte_memory_order_release)/** * s: (struct sub_device *) * i: uint16_t qid */ #define FS_ATOMIC_RX (s, i) \ - rte_atomic64_read( \ - &((struct rxq *) \ - (fs_dev(s)->data->rx_queues[i]))->refcnt[(s)->sid]) + rte_atomic_load_explicit( \ + &((struct rxq *) \ + (fs_dev(s)->data->rx_queues[i]))->refcnt[(s)->sid], \ + rte_memory_order_seq_cst) +/** * s: (struct sub_device *) * i: uint16_t qid */ #define FS_ATOMIC_TX (s, i) \ - rte_atomic64_read( \ - &((struct txq *) \ - (fs_dev(s)->data->tx_queues[i]))->refcnt[(s)->sid]) + rte_atomic_load_explicit( \ + &((struct txq *) \ + (fs_dev(s)->data->tx_queues[i]))->refcnt[(s)->sid], \ + rte_memory_order_seq_cst)#ifdef RTE_EXEC_ENV_FREEBSD #define FS_THREADID_TYPE void*
drivers/net/failsafe/failsafe_rxtx.c +1 -1
@@ -3,7 +3,7 @@* Copyright 2017 Mellanox Technologies, Ltd */ -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_debug.h> #include <rte_mbuf.h> #include <ethdev_driver.h>
Signature · 1 line
2.53.0
PATCH v6 6/24 net/enic: do not use deprecated rte_atomic64
In reply to Stephen HemmingerThe rte_atomic64 datatype and functions are deprecated. This driver was only using it for error statistics where atomic is not necessary. The DPDK PMD model is that statistics do not have to be exact in face of contention.
--- drivers/net/enic/enic.h | 6 +++--- drivers/net/enic/enic_compat.h | 1 - drivers/net/enic/enic_main.c | 17 +++++++---------- drivers/net/enic/enic_rxtx.c | 14 ++++++-------- drivers/net/enic/enic_rxtx_vec_avx2.c | 4 ++-- 5 files changed, 18 insertions(+), 24 deletions(-)
drivers/net/enic/enic.h +3 -3
@@ -59,9 +59,9 @@#define ENICPMD_RXQ_INTR_OFFSET 1struct enic_soft_stats { -rte_atomic64_t rx_nombuf; -rte_atomic64_t rx_packet_errors; -rte_atomic64_t tx_oversized; +uint64_t rx_nombuf; +uint64_t rx_packet_errors; +uint64_t tx_oversized; };struct enic_memzone_entry {
drivers/net/enic/enic_compat.h +0 -1
@@ -9,7 +9,6 @@#include <stdio.h> #include <unistd.h> -#include <rte_atomic.h> #include <rte_malloc.h> #include <rte_log.h> #include <rte_io.h>
drivers/net/enic/enic_main.c +7 -10
@@ -83,17 +83,15 @@ static void enic_log_q_error(struct enic *enic)static void enic_clear_soft_stats (struct enic *enic) {struct enic_soft_stats *soft_stats = &enic->soft_stats; -rte_atomic64_clear (&soft_stats->rx_nombuf); -rte_atomic64_clear (&soft_stats->rx_packet_errors); -rte_atomic64_clear (&soft_stats->tx_oversized); + +memset (soft_stats,0 ,sizeof (*soft_stats)); }static void enic_init_soft_stats (struct enic *enic) {struct enic_soft_stats *soft_stats = &enic->soft_stats; -rte_atomic64_init (&soft_stats->rx_nombuf); -rte_atomic64_init (&soft_stats->rx_packet_errors); -rte_atomic64_init (&soft_stats->tx_oversized); + +memset (soft_stats,0 ,sizeof (*soft_stats));enic_clear_soft_stats (enic); }
@@ -132,7 +130,7 @@ int enic_dev_stats_get(struct enic *enic, struct rte_eth_stats *r_stats,* counted in ibytes even though truncated packets are dropped * which can make ibytes be slightly higher than it should be. */ - rx_packet_errors =rte_atomic64_read (&soft_stats->rx_packet_errors); + rx_packet_errors = soft_stats->rx_packet_errors; rx_truncated = rx_packet_errors - stats->rx.rx_errors; r_stats->ipackets = stats->rx.rx_frames_ok - rx_truncated;
@@ -142,12 +140,11 @@ int enic_dev_stats_get(struct enic *enic, struct rte_eth_stats *r_stats, r_stats->obytes = stats->tx.tx_bytes_ok; r_stats->ierrors = stats->rx.rx_errors + stats->rx.rx_drop; - r_stats->oerrors = stats->tx.tx_errors - +rte_atomic64_read (&soft_stats->tx_oversized); + r_stats->oerrors = stats->tx.tx_errors + soft_stats->tx_oversized; r_stats->imissed = stats->rx.rx_no_bufs + rx_truncated; - r_stats->rx_nombuf =rte_atomic64_read (&soft_stats->rx_nombuf); + r_stats->rx_nombuf = soft_stats->rx_nombuf;return 0 ; }
drivers/net/enic/enic_rxtx.c +6 -8
@@ -112,7 +112,7 @@ enic_recv_pkts_common(void *rx_queue, struct rte_mbuf **rx_pkts,/* allocate a new mbuf */ nmb =rte_mbuf_raw_alloc (rq->mp);if (nmb ==NULL ) { -rte_atomic64_inc (&enic->soft_stats.rx_nombuf); + ++enic->soft_stats.rx_nombuf;break ; }
@@ -185,7 +185,7 @@ enic_recv_pkts_common(void *rx_queue, struct rte_mbuf **rx_pkts, }if (unlikely (packet_error)) {rte_pktmbuf_free (first_seg); -rte_atomic64_inc (&enic->soft_stats.rx_packet_errors); + ++enic->soft_stats.rx_packet_errors;continue ; }
@@ -303,7 +303,7 @@ enic_noscatter_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,if (unlikely (cqd->bytes_written_flags &CQ_ENET_RQ_DESC_FLAGS_TRUNCATED )) {rte_pktmbuf_free (*rxmb++); -rte_atomic64_inc (&enic->soft_stats.rx_packet_errors); + ++enic->soft_stats.rx_packet_errors; cqd++;continue ; }
@@ -505,14 +505,12 @@ uint16_t enic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,uint8_t offload_mode;uint16_t header_len;uint64_t tso; -rte_atomic64_t *tx_oversized;enic_cleanup_wq (enic, wq); wq_desc_avail =vnic_wq_desc_avail (wq); head_idx = wq->head_idx; desc_count = wq->ring.desc_count; ol_flags_mask =RTE_MBUF_F_TX_VLAN |RTE_MBUF_F_TX_IP_CKSUM |RTE_MBUF_F_TX_L4_MASK ; - tx_oversized = &enic->soft_stats.tx_oversized; nb_pkts =RTE_MIN (nb_pkts,ENIC_TX_XMIT_MAX );
@@ -527,7 +525,7 @@ uint16_t enic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,/* drop packet if it's too big to send */ if (unlikely (!tso && pkt_len >ENIC_TX_MAX_PKT_SIZE )) {rte_pktmbuf_free (tx_pkt); -rte_atomic64_inc (tx_oversized); + ++enic->soft_stats.tx_oversized;continue ; }
@@ -558,7 +556,7 @@ uint16_t enic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,if (unlikely (header_len ==0 || ((tx_pkt->tso_segsz + header_len) >ENIC_TX_MAX_PKT_SIZE ))) {rte_pktmbuf_free (tx_pkt); -rte_atomic64_inc (tx_oversized); + ++enic->soft_stats.tx_oversized;continue ; }
@@ -681,7 +679,7 @@ static void enqueue_simple_pkts(struct rte_mbuf **pkts,*/ if (unlikely (p->pkt_len >ENIC_TX_MAX_PKT_SIZE )) { desc->length =ENIC_TX_MAX_PKT_SIZE ; -rte_atomic64_inc (&enic->soft_stats.tx_oversized); + ++enic->soft_stats.tx_oversized; } desc++; }
drivers/net/enic/enic_rxtx_vec_avx2.c +2 -2
@@ -81,7 +81,7 @@ enic_noscatter_vec_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,if (unlikely (cqd->bytes_written_flags &CQ_ENET_RQ_DESC_FLAGS_TRUNCATED )) {rte_pktmbuf_free (*rxmb++); -rte_atomic64_inc (&enic->soft_stats.rx_packet_errors); + ++enic->soft_stats.rx_packet_errors; }else { *rx++ =rx_one (cqd, *rxmb++, enic); }
@@ -761,7 +761,7 @@ enic_noscatter_vec_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,if (unlikely (cqd->bytes_written_flags &CQ_ENET_RQ_DESC_FLAGS_TRUNCATED )) {rte_pktmbuf_free (*rxmb++); -rte_atomic64_inc (&enic->soft_stats.rx_packet_errors); + ++enic->soft_stats.rx_packet_errors; }else { *rx++ =rx_one (cqd, *rxmb++, enic); }
Signature · 1 line
2.53.0
RE: [PATCH v6 06/24] net/enic: do not use deprecated rte_atomic64
Quoted 212 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Friday, July 31, 2026 1:58 PM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; John Daley (johndale) <[email protected]>; Hyong Youb Kim (hyonkim) <[email protected]>; Bruce Richardson <[email protected]>; Konstantin Ananyev <[email protected]>
Subject: [PATCH v6 06/24] net/enic: do not use deprecatedrte_atomic64The
rte_atomic64datatype and functions are deprecated. This driver was only using it for error statistics where atomic is not necessary. The DPDK PMD model is that statistics do not have to be exact in face of contention.Signed-off-by Stephen Hemminger <[email protected]>--- drivers/net/enic/enic.h | 6 +++--- drivers/net/enic/enic_compat.h | 1 - drivers/net/enic/enic_main.c | 17 +++++++---------- drivers/net/enic/enic_rxtx.c | 14 ++++++-------- drivers/net/enic/enic_rxtx_vec_avx2.c | 4 ++-- 5 files changed, 18 insertions(+), 24 deletions(-)drivers/net/enic/enic.h +3
-3@@ -59,9 +59,9 @@#define ENICPMD_RXQ_INTR_OFFSET 1struct enic_soft_stats { -rte_atomic64_t rx_nombuf; -rte_atomic64_t rx_packet_errors; -rte_atomic64_t tx_oversized; +uint64_t rx_nombuf; +uint64_t rx_packet_errors; +uint64_t tx_oversized; };struct enic_memzone_entry {drivers/net/enic/enic_compat.h +0
-1@@ -9,7 +9,6 @@#include <stdio.h> #include <unistd.h> -#include <rte_atomic.h> #include <rte_malloc.h> #include <rte_log.h> #include <rte_io.h> drivers/net/enic/enic_main.c +5
-7@@ -83,17 +83,15 @@ static void enic_log_q_error(struct enic *enic)static void enic_clear_soft_stats (struct enic *enic) {struct enic_soft_stats *soft_stats = &enic->soft_stats; -rte_atomic64_clear (&soft_stats->rx_nombuf); -rte_atomic64_clear (&soft_stats->rx_packet_errors); -rte_atomic64_clear (&soft_stats->tx_oversized); + +memset (soft_stats,0 ,sizeof (*soft_stats)); }static void enic_init_soft_stats (struct enic *enic) {struct enic_soft_stats *soft_stats = &enic->soft_stats; -rte_atomic64_init (&soft_stats->rx_nombuf); -rte_atomic64_init (&soft_stats->rx_packet_errors); -rte_atomic64_init (&soft_stats->tx_oversized); + +memset (soft_stats,0 ,sizeof (*soft_stats));enic_clear_soft_stats (enic); }@@ -132,7 +130,7 @@ int enic_dev_stats_get(struct enic *enic, structrte_eth_stats *r_stats, * counted in ibytes even though truncated packets are dropped * which can make ibytes be slightly higher than it should be. */ - rx_packet_errors =rte_atomic64_read (&soft_stats->rx_packet_errors); + rx_packet_errors = soft_stats->rx_packet_errors; rx_truncated = rx_packet_errors - stats->rx.rx_errors;drivers/net/enic/enic_main.c +2
-3r_stats->ipackets = stats->rx.rx_frames_ok - rx_truncated;@@ -142,12 +140,11 @@ int enic_dev_stats_get(struct enic *enic, struct rte_eth_stats *r_stats, r_stats->obytes = stats->tx.tx_bytes_ok; r_stats->ierrors = stats->rx.rx_errors + stats->rx.rx_drop; - r_stats->oerrors = stats->tx.tx_errors - +rte_atomic64_read (&soft_stats->tx_oversized); + r_stats->oerrors = stats->tx.tx_errors + soft_stats->tx_oversized; r_stats->imissed = stats->rx.rx_no_bufs + rx_truncated; - r_stats->rx_nombuf =rte_atomic64_read (&soft_stats->rx_nombuf); + r_stats->rx_nombuf = soft_stats->rx_nombuf;return 0 ; }drivers/net/enic/enic_rxtx.c +3
-3@@ -112,7 +112,7 @@ enic_recv_pkts_common(void *rx_queue, structrte_mbuf **rx_pkts,/* allocate a new mbuf */ nmb =rte_mbuf_raw_alloc (rq->mp);if (nmb ==NULL ) { -rte_atomic64_inc (&enic->soft_stats.rx_nombuf); + ++enic->soft_stats.rx_nombuf;break ; }@@ -185,7 +185,7 @@ enic_recv_pkts_common(void *rx_queue, struct rte_mbuf **rx_pkts, }if (unlikely (packet_error)) {rte_pktmbuf_free (first_seg); -rte_atomic64_inc (&enic->soft_stats.rx_packet_errors); + ++enic->soft_stats.rx_packet_errors;continue ; }@@ -303,7 +303,7 @@ enic_noscatter_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, if (unlikely(cqd->bytes_written_flags & CQ_ENET_RQ_DESC_FLAGS_TRUNCATED)) {rte_pktmbuf_free (*rxmb++); -rte_atomic64_inc (&enic->soft_stats.rx_packet_errors); + ++enic->soft_stats.rx_packet_errors; cqd++;continue ;drivers/net/enic/enic_rxtx.c +0
-2}@@ -505,14 +505,12 @@ uint16_t enic_xmit_pkts(void *tx_queue, structrte_mbuf **tx_pkts, uint8_t offload_mode;uint16_t header_len;uint64_t tso; -rte_atomic64_t *tx_oversized;enic_cleanup_wq (enic, wq); wq_desc_avail =vnic_wq_desc_avail (wq); head_idx = wq->head_idx; desc_count = wq->ring.desc_count; ol_flags_mask =RTE_MBUF_F_TX_VLAN |RTE_MBUF_F_TX_IP_CKSUM |RTE_MBUF_F_TX_L4_MASK ; - tx_oversized = &enic->soft_stats.tx_oversized;drivers/net/enic/enic_rxtx.c +3
-3nb_pkts =RTE_MIN (nb_pkts,ENIC_TX_XMIT_MAX );@@ -527,7 +525,7 @@ uint16_t enic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,/* drop packet if it's too big to send */ if (unlikely(!tso && pkt_len > ENIC_TX_MAX_PKT_SIZE)) {rte_pktmbuf_free (tx_pkt); -rte_atomic64_inc (tx_oversized); + ++enic->soft_stats.tx_oversized;continue ; }@@ -558,7 +556,7 @@ uint16_t enic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, if (unlikely(header_len == 0 || ((tx_pkt->tso_segsz + header_len) > ENIC_TX_MAX_PKT_SIZE))) {rte_pktmbuf_free (tx_pkt); -rte_atomic64_inc (tx_oversized); + ++enic->soft_stats.tx_oversized;continue ; }@@ -681,7 +679,7 @@ static void enqueue_simple_pkts(struct rte_mbuf**pkts, */ if (unlikely (p->pkt_len >ENIC_TX_MAX_PKT_SIZE )) { desc->length =ENIC_TX_MAX_PKT_SIZE ; -rte_atomic64_inc (&enic->soft_stats.tx_oversized); + ++enic->soft_stats.tx_oversized; } desc++;drivers/net/enic/enic_rxtx.c +0
-0}drivers/net/enic/enic_rxtx_vec_avx2.c +1
-1@@ -81,7 +81,7 @@ enic_noscatter_vec_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, if (unlikely(cqd->bytes_written_flags & CQ_ENET_RQ_DESC_FLAGS_TRUNCATED)) {rte_pktmbuf_free (*rxmb++); -rte_atomic64_inc (&enic->soft_stats.rx_packet_errors); + ++enic->soft_stats.rx_packet_errors; } else { *rx++ =rx_one (cqd, *rxmb++, enic);drivers/net/enic/enic_rxtx_vec_avx2.c +1
-1}@@ -761,7 +761,7 @@ enic_noscatter_vec_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, if (unlikely(cqd->bytes_written_flags & CQ_ENET_RQ_DESC_FLAGS_TRUNCATED)) {rte_pktmbuf_free (*rxmb++); -rte_atomic64_inc (&enic->soft_stats.rx_packet_errors); + ++enic->soft_stats.rx_packet_errors; } else { *rx++ =rx_one (cqd, *rxmb++, enic);
Quoted 3 lines
}
--
2.53.0
Thanks.
-Hyong
PATCH v6 7/24 net/pfe: use ethdev linkstatus helpers
In reply to Stephen HemmingerRather than open coding with deprecated rte_atomic64, use the existing ethdev helpers to get and set link status.
--- drivers/net/pfe/pfe_ethdev.c | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-)
drivers/net/pfe/pfe_ethdev.c +2 -30
@@ -531,34 +531,6 @@ pfe_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)return NULL ; } -static inline int -pfe_eth_atomic_read_link_status (struct rte_eth_dev *dev, -struct rte_eth_link *link) -{ -struct rte_eth_link *dst = link; -struct rte_eth_link *src = &dev->data->dev_link; - -if (rte_atomic64_cmpset ((uint64_t *)dst, *(uint64_t *)dst, - *(uint64_t *)src) ==0 ) -return -1 ; - -return 0 ; -} - -static inline int -pfe_eth_atomic_write_link_status (struct rte_eth_dev *dev, -struct rte_eth_link *link) -{ -struct rte_eth_link *dst = &dev->data->dev_link; -struct rte_eth_link *src = link; - -if (rte_atomic64_cmpset ((uint64_t *)dst, *(uint64_t *)dst, - *(uint64_t *)src) ==0 ) -return -1 ; - -return 0 ; -} -static int pfe_eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused) {
@@ -570,7 +542,7 @@ pfe_eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused)memset (&old,0 ,sizeof (old));memset (&link,0 ,sizeof (struct rte_eth_link )); -pfe_eth_atomic_read_link_status (dev, &old); +rte_eth_linkstatus_get (dev, &old);/* Read from PFE CDEV, status of link, if file was successfully * opened.
@@ -601,7 +573,7 @@ pfe_eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused) link.link_duplex =RTE_ETH_LINK_FULL_DUPLEX ; link.link_autoneg =RTE_ETH_LINK_AUTONEG ; -pfe_eth_atomic_write_link_status (dev, &link); +rte_eth_linkstatus_set (dev, &link);PFE_PMD_INFO ("Port (%d) link is %s" , dev->data->port_id, link.link_status ?"up" :"down" );
Signature · 1 line
2.53.0
PATCH v6 8/24 net/sfc: replace rte_atomic with stdatomic
In reply to Stephen HemmingerThe rte_atomicNN functions are deprecated and need to be replaced. Use stdatomic for the restart required flag.
Use existing ethdev helper to set link status.
--- drivers/net/sfc/sfc.c | 9 +++++---- drivers/net/sfc/sfc.h | 4 ++-- drivers/net/sfc/sfc_port.c | 7 +------ drivers/net/sfc/sfc_stats.h | 2 +- 4 files changed, 9 insertions(+), 13 deletions(-)
drivers/net/sfc/sfc.c +5 -4
@@ -670,8 +670,8 @@ sfc_restart_if_required(void *arg)struct sfc_adapter *sa = arg;/* If restart is scheduled, clear the flag and do it */ -if (rte_atomic32_cmpset ((volatile uint32_t *)&sa->restart_required, -1 ,0 )) { +if (rte_atomic_exchange_explicit (&sa->restart_required, false, + rte_memory_order_seq_cst)) {sfc_adapter_lock (sa);if (sa->state ==SFC_ETHDEV_STARTED ) (void )sfc_restart (sa);
@@ -685,7 +685,8 @@ sfc_schedule_restart(struct sfc_adapter *sa)int rc;/* Schedule restart alarm if it is not scheduled yet */ -if (!rte_atomic32_test_and_set (&sa->restart_required)) +if (rte_atomic_exchange_explicit (&sa->restart_required, true, + rte_memory_order_seq_cst))return ; rc =rte_eal_alarm_set (1 , sfc_restart_if_required, sa);
@@ -1292,7 +1293,7 @@ sfc_probe(struct sfc_adapter *sa)SFC_ASSERT (sfc_adapter_is_locked (sa)); sa->socket_id =rte_socket_id (); -rte_atomic32_init (&sa->restart_required); + sa->restart_required = false;sfc_log_init (sa,"get family" ); rc =sfc_efx_family (pci_dev, &mem_ebrp, &sa->family);
drivers/net/sfc/sfc.h +2 -2
@@ -17,7 +17,7 @@#include <ethdev_driver.h> #include <rte_kvargs.h> #include <rte_spinlock.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include "efx.h"
@@ -239,7 +239,7 @@ struct sfc_adapter {efx_family_t family;efx_nic_t *nic;rte_spinlock_t nic_lock; -rte_atomic32_t restart_required; +RTE_ATOMIC (bool ) restart_required;struct sfc_efx_mcdi mcdi;struct sfc_sriov sriov;
drivers/net/sfc/sfc_port.c +1 -6
@@ -121,7 +121,6 @@ sfc_port_reset_mac_stats(struct sfc_adapter *sa)static int sfc_port_init_dev_link (struct sfc_adapter *sa) { -struct rte_eth_link *dev_link = &sa->eth_dev->data->dev_link;int rc;efx_link_mode_t link_mode;struct rte_eth_link current_link;
@@ -132,11 +131,7 @@ sfc_port_init_dev_link(struct sfc_adapter *sa)sfc_port_link_mode_to_info (link_mode, sa->port.phy_adv_cap, ¤t_link); - -EFX_STATIC_ASSERT (sizeof (*dev_link) ==sizeof (rte_atomic64_t)); -rte_atomic64_set ((rte_atomic64_t *)dev_link, - *(uint64_t *)¤t_link); - +rte_eth_linkstatus_set (sa->eth_dev, ¤t_link);return 0 ; }
drivers/net/sfc/sfc_stats.h +1 -1
@@ -12,7 +12,7 @@#include <stdint.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include "sfc_tweak.h"
Signature · 1 line
2.53.0
PATCH v6 9/24 crypto/ccp: replace use of rte_atomic64 with stdatomic
In reply to Stephen HemmingerThe rte_atomicNN functions are deprecated. Replace the free count with stdatomic.
--- drivers/crypto/ccp/ccp_crypto.c | 11 +++++++---- drivers/crypto/ccp/ccp_crypto.h | 2 +- drivers/crypto/ccp/ccp_dev.c | 10 ++++++---- drivers/crypto/ccp/ccp_dev.h | 4 ++-- 4 files changed, 16 insertions(+), 11 deletions(-)
drivers/crypto/ccp/ccp_crypto.c +7 -4
@@ -2683,7 +2683,8 @@ process_ops_to_enqueue(struct ccp_qp *qp, b_info->cmd_q = cmd_q; b_info->lsb_buf_phys = (phys_addr_t )rte_mem_virt2iova ((void *)b_info->lsb_buf); -rte_atomic64_sub (&b_info->cmd_q->free_slots, slots_req); +rte_atomic_fetch_sub_explicit (&b_info->cmd_q->free_slots, slots_req, + rte_memory_order_seq_cst); b_info->head_offset = (uint32_t )(cmd_q->qbase_phys_addr + cmd_q->qidx *Q_DESC_SIZE );
@@ -2729,8 +2730,9 @@ process_ops_to_enqueue(struct ccp_qp *qp, result =-1 ; }if (unlikely (result <0 )) { -rte_atomic64_add (&b_info->cmd_q->free_slots, - (slots_req - b_info->desccnt)); +rte_atomic_fetch_add_explicit (&b_info->cmd_q->free_slots, + slots_req - b_info->desccnt, + rte_memory_order_seq_cst);break ; } b_info->op[i] = op[i];
@@ -2914,7 +2916,8 @@ process_ops_to_dequeue(struct ccp_qp *qp, success: *total_nb_ops = b_info->total_nb_ops; nb_ops =ccp_prepare_ops (qp, op, b_info, nb_ops); -rte_atomic64_add (&b_info->cmd_q->free_slots, b_info->desccnt); +rte_atomic_fetch_add_explicit (&b_info->cmd_q->free_slots, b_info->desccnt, + rte_memory_order_seq_cst); b_info->desccnt =0 ;if (b_info->opcnt >0 ) { qp->b_info = b_info;
drivers/crypto/ccp/ccp_crypto.h +1 -1
@@ -10,7 +10,7 @@#include <stdint.h> #include <string.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_byteorder.h> #include <rte_io.h> #include <rte_pci.h>
drivers/crypto/ccp/ccp_dev.c +6 -4
@@ -47,14 +47,15 @@ ccp_allot_queue(struct rte_cryptodev *cdev, int slot_req) priv->last_dev = dev;if (dev->qidx >= dev->cmd_q_count) dev->qidx =0 ; - ret =rte_atomic64_read (&dev->cmd_q[dev->qidx].free_slots); + ret =rte_atomic_load_explicit (&dev->cmd_q[dev->qidx].free_slots, rte_memory_order_relaxed);if (ret >= slot_req)return &dev->cmd_q[dev->qidx];for (i =0 ; i < dev->cmd_q_count; i++) { dev->qidx++;if (dev->qidx >= dev->cmd_q_count) dev->qidx =0 ; - ret =rte_atomic64_read (&dev->cmd_q[dev->qidx].free_slots); + ret =rte_atomic_load_explicit (&dev->cmd_q[dev->qidx].free_slots, + rte_memory_order_relaxed);if (ret >= slot_req)return &dev->cmd_q[dev->qidx]; }
@@ -583,8 +584,9 @@ ccp_add_device(struct ccp_device *dev)CCP_LOG_ERR ("queue doesn't have lsb regions" ); cmd_q->lsb =-1 ; -rte_atomic64_init (&cmd_q->free_slots); -rte_atomic64_set (&cmd_q->free_slots, (COMMANDS_PER_QUEUE -1 )); +rte_atomic_store_explicit (&cmd_q->free_slots, +COMMANDS_PER_QUEUE -1 , + rte_memory_order_seq_cst);/* unused slot barrier b/w H&T */ }
drivers/crypto/ccp/ccp_dev.h +2 -2
@@ -11,7 +11,7 @@#include <string.h> #include <bus_pci_driver.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_byteorder.h> #include <rte_io.h> #include <rte_pci.h>
@@ -182,7 +182,7 @@ struct __rte_cache_aligned ccp_queue {struct ccp_device *dev;char memz_name[RTE_MEMZONE_NAMESIZE ]; -rte_atomic64_t free_slots; +RTE_ATOMIC (int64_t ) free_slots;/**< available free slots updated from enq/deq calls */ /* Queue identifier */
Signature · 1 line
2.53.0
PATCH v6 10/24 bus/dpaa: replace rte_atomic16 with stdatomic
In reply to Stephen HemmingerThis is simple inuse flag which can be done with stdatomic exchange logic.
--- drivers/bus/dpaa/base/qbman/qman.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/bus/dpaa/base/qbman/qman.c +6 -3
@@ -11,6 +11,7 @@#include <rte_eventdev.h> #include <rte_byteorder.h> #include <rte_dpaa_logs.h> +#include <rte_stdatomic.h> #include <eal_export.h> #include <dpaa_bits.h>
@@ -683,7 +684,7 @@ qman_init_portal(struct qman_portal *portal,#define MAX_GLOBAL_PORTALS 8static struct qman_portal global_portals[MAX_GLOBAL_PORTALS ]; -static rte_atomic16_t global_portals_used[MAX_GLOBAL_PORTALS ]; +static RTE_ATOMIC (bool ) global_portals_used[MAX_GLOBAL_PORTALS ];struct qman_portal *qman_alloc_global_portal (struct qm_portal_config *q_pcfg)
@@ -691,7 +692,8 @@ qman_alloc_global_portal(struct qm_portal_config *q_pcfg)unsigned int i;for (i =0 ; i <MAX_GLOBAL_PORTALS ; i++) { -if (rte_atomic16_test_and_set (&global_portals_used[i])) { +if (!rte_atomic_exchange_explicit (&global_portals_used[i], true, + rte_memory_order_acquire)) { global_portals[i].config = q_pcfg;return &global_portals[i]; }
@@ -708,7 +710,8 @@ qman_free_global_portal(struct qman_portal *portal)for (i =0 ; i <MAX_GLOBAL_PORTALS ; i++) {if (&global_portals[i] == portal) { -rte_atomic16_clear (&global_portals_used[i]); +rte_atomic_store_explicit (&global_portals_used[i], false, + rte_memory_order_release);return 0 ; } }
Signature · 1 line
2.53.0
PATCH v6 11/24 bus/fslmc: replace rte_atomic16 with stdatomic
In reply to Stephen HemmingerThe rte_atomicNN functions and types are deprecated. The in_use and ref_count flags can be converted to stdatomic.
Note that rte_atomic16_init() and rte_atomic16_clear() were plain stores with no ordering; only test_and_set() and dec() implied a full barrier. Initialization happens before the device is put on the list, so a relaxed store is used there. It is spelled out explicitly because a plain assignment to an RTE_ATOMIC() object is a sequentially consistent store when built with enable_stdatomic=true.
Claiming a device now pairs an acquire compare exchange with a release store on the free path, which is what the test_and_set()/dec() pair was providing.
Also drop the unneeded NULL check in the loop body: TAILQ_FOREACH terminates when the iterator becomes NULL, so var is guaranteed non-NULL inside the loop.
--- drivers/bus/fslmc/portal/dpaa2_hw_dpbp.c | 11 ++++++++--- drivers/bus/fslmc/portal/dpaa2_hw_dpci.c | 11 ++++++++--- drivers/bus/fslmc/portal/dpaa2_hw_dpcon.c | 11 ++++++++--- drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 14 ++++++++++---- drivers/bus/fslmc/portal/dpaa2_hw_pvt.h | 9 +++++---- 5 files changed, 39 insertions(+), 17 deletions(-)
drivers/bus/fslmc/portal/dpaa2_hw_dpbp.c +8 -3
@@ -84,7 +84,7 @@ dpaa2_create_dpbp_device(int vdev_fd __rte_unused, } dpbp_node->dpbp_id = dpbp_id; -rte_atomic16_init (&dpbp_node->in_use); +rte_atomic_store_explicit (&dpbp_node->in_use,0 , rte_memory_order_relaxed);TAILQ_INSERT_TAIL (&dpbp_dev_list, dpbp_node, next);
@@ -103,7 +103,11 @@ struct dpaa2_dpbp_dev *dpaa2_alloc_dpbp_dev(void)/* Get DPBP dev handle from list using index */ TAILQ_FOREACH(dpbp_dev, &dpbp_dev_list, next) { -if (dpbp_dev &&rte_atomic16_test_and_set (&dpbp_dev->in_use)) +uint16_t expected =0 ; + +if (rte_atomic_compare_exchange_strong_explicit (&dpbp_dev->in_use, + &expected,1 , rte_memory_order_acquire, + rte_memory_order_relaxed))break ; }
@@ -118,7 +122,8 @@ void dpaa2_free_dpbp_dev(struct dpaa2_dpbp_dev *dpbp)/* Match DPBP handle and mark it free */ TAILQ_FOREACH(dpbp_dev, &dpbp_dev_list, next) {if (dpbp_dev == dpbp) { -rte_atomic16_dec (&dpbp_dev->in_use); +rte_atomic_store_explicit (&dpbp_dev->in_use,0 , + rte_memory_order_release);return ; } }
drivers/bus/fslmc/portal/dpaa2_hw_dpci.c +8 -3
@@ -135,7 +135,7 @@ rte_dpaa2_create_dpci_device(int vdev_fd __rte_unused, } dpci_node->dpci_id = dpci_id; -rte_atomic16_init (&dpci_node->in_use); +rte_atomic_store_explicit (&dpci_node->in_use,0 , rte_memory_order_relaxed);TAILQ_INSERT_TAIL (&dpci_dev_list, dpci_node, next);
@@ -159,7 +159,11 @@ struct dpaa2_dpci_dev *rte_dpaa2_alloc_dpci_dev(void)/* Get DPCI dev handle from list using index */ TAILQ_FOREACH(dpci_dev, &dpci_dev_list, next) { -if (dpci_dev &&rte_atomic16_test_and_set (&dpci_dev->in_use)) +uint16_t expected =0 ; + +if (rte_atomic_compare_exchange_strong_explicit (&dpci_dev->in_use, + &expected,1 , rte_memory_order_acquire, + rte_memory_order_relaxed))break ; }
@@ -174,7 +178,8 @@ void rte_dpaa2_free_dpci_dev(struct dpaa2_dpci_dev *dpci)/* Match DPCI handle and mark it free */ TAILQ_FOREACH(dpci_dev, &dpci_dev_list, next) {if (dpci_dev == dpci) { -rte_atomic16_dec (&dpci_dev->in_use); +rte_atomic_store_explicit (&dpci_dev->in_use,0 , + rte_memory_order_release);return ; } }
drivers/bus/fslmc/portal/dpaa2_hw_dpcon.c +8 -3
@@ -81,7 +81,7 @@ rte_dpaa2_create_dpcon_device(int dev_fd __rte_unused, dpcon_node->qbman_ch_id = attr.qbman_ch_id; dpcon_node->num_priorities = attr.num_priorities; dpcon_node->dpcon_id = dpcon_id; -rte_atomic16_init (&dpcon_node->in_use); +rte_atomic_store_explicit (&dpcon_node->in_use,0 , rte_memory_order_relaxed);TAILQ_INSERT_TAIL (&dpcon_dev_list, dpcon_node, next);
@@ -95,7 +95,11 @@ struct dpaa2_dpcon_dev *rte_dpaa2_alloc_dpcon_dev(void)/* Get DPCON dev handle from list using index */ TAILQ_FOREACH(dpcon_dev, &dpcon_dev_list, next) { -if (dpcon_dev &&rte_atomic16_test_and_set (&dpcon_dev->in_use)) +uint16_t expected =0 ; + +if (rte_atomic_compare_exchange_strong_explicit (&dpcon_dev->in_use, + &expected,1 , rte_memory_order_acquire, + rte_memory_order_relaxed))break ; }
@@ -110,7 +114,8 @@ void rte_dpaa2_free_dpcon_dev(struct dpaa2_dpcon_dev *dpcon)/* Match DPCON handle and mark it free */ TAILQ_FOREACH(dpcon_dev, &dpcon_dev_list, next) {if (dpcon_dev == dpcon) { -rte_atomic16_dec (&dpcon_dev->in_use); +rte_atomic_store_explicit (&dpcon_dev->in_use,0 , + rte_memory_order_release);return ; } }
drivers/bus/fslmc/portal/dpaa2_hw_dpio.c +10 -4
@@ -352,7 +352,8 @@ static void dpaa2_put_qbman_swp(struct dpaa2_dpio_dev *dpio_dev)* armed: intr_deinit returns early if intr is not enabled. */ dpaa2_dpio_intr_deinit (dpio_dev); -rte_atomic16_clear (&dpio_dev->ref_count); +rte_atomic_store_explicit (&dpio_dev->ref_count,0 , + rte_memory_order_release); } }
@@ -364,7 +365,11 @@ static struct dpaa2_dpio_dev *dpaa2_get_qbman_swp(bool ethrx)/* Get DPIO dev handle from list using index */ TAILQ_FOREACH(dpio_dev, &dpio_dev_list, next) { -if (dpio_dev &&rte_atomic16_test_and_set (&dpio_dev->ref_count)) +uint16_t expected =0 ; + +if (rte_atomic_compare_exchange_strong_explicit (&dpio_dev->ref_count, + &expected,1 , rte_memory_order_acquire, + rte_memory_order_relaxed))break ; }if (!dpio_dev) {
@@ -385,7 +390,8 @@ static struct dpaa2_dpio_dev *dpaa2_get_qbman_swp(bool ethrx) ret =dpaa2_configure_stashing (dpio_dev, cpu_id, ethrx);if (ret) {DPAA2_BUS_ERR ("dpaa2_configure_stashing failed" ); -rte_atomic16_clear (&dpio_dev->ref_count); +rte_atomic_store_explicit (&dpio_dev->ref_count,0 , + rte_memory_order_release);return NULL ; } }
@@ -500,7 +506,7 @@ dpaa2_create_dpio_device(int vdev_fd, dpio_dev->dpio =NULL ; dpio_dev->hw_id = object_id; -rte_atomic16_init (&dpio_dev->ref_count); +rte_atomic_store_explicit (&dpio_dev->ref_count,0 , rte_memory_order_relaxed);/* Using single portal for all devices */ dpio_dev->mc_portal =dpaa2_get_mcp_ptr (MC_PORTAL_INDEX );
drivers/bus/fslmc/portal/dpaa2_hw_pvt.h +5 -4
@@ -9,6 +9,7 @@#define _DPAA2_HW_PVT_H_#include <rte_compat.h> +#include <rte_stdatomic.h> #include <rte_eventdev.h> #include <dpaax_iova_table.h>
@@ -112,7 +113,7 @@ struct dpaa2_dpio_dev {TAILQ_ENTRY (dpaa2_dpio_dev) next;/**< Pointer to Next device instance */ uint16_t index;/**< Index of a instance in the list */ -rte_atomic16_t ref_count; +RTE_ATOMIC (uint16_t ) ref_count;/**< How many thread contexts are sharing this.*/ uint16_t eqresp_ci;uint16_t eqresp_pi;
@@ -143,7 +144,7 @@ struct dpaa2_dpbp_dev {/**< Pointer to Next device instance */ struct fsl_mc_io dpbp;/** handle to DPBP portal object */ uint16_t token; -rte_atomic16_t in_use; +RTE_ATOMIC (uint16_t ) in_use;uint32_t dpbp_id;/*HW ID for DPBP object */ };
@@ -266,7 +267,7 @@ struct dpaa2_dpci_dev {/**< Pointer to Next device instance */ struct fsl_mc_io dpci;/** handle to DPCI portal object */ uint16_t token; -rte_atomic16_t in_use; +RTE_ATOMIC (uint16_t ) in_use;uint32_t dpci_id;/*HW ID for DPCI object */ struct dpaa2_queue rx_queue[DPAA2_DPCI_MAX_QUEUES ];struct dpaa2_queue tx_queue[DPAA2_DPCI_MAX_QUEUES ];
@@ -276,7 +277,7 @@ struct dpaa2_dpcon_dev {TAILQ_ENTRY (dpaa2_dpcon_dev) next;struct fsl_mc_io dpcon;uint16_t token; -rte_atomic16_t in_use; +RTE_ATOMIC (uint16_t ) in_use;uint32_t dpcon_id;uint16_t qbman_ch_id;uint8_t num_priorities;
Signature · 1 line
2.53.0
PATCH v6 12/24 net/netvsc: replace rte_atomic32 with stdatomic
In reply to Stephen HemmingerChange the rndis transaction id and buffer usage to use stdatomic functions.
--- drivers/net/netvsc/hn_rndis.c | 28 +++++++++++++++++++--------- drivers/net/netvsc/hn_rxtx.c | 12 +++++++----- drivers/net/netvsc/hn_var.h | 6 +++--- 3 files changed, 29 insertions(+), 17 deletions(-)
drivers/net/netvsc/hn_rndis.c +19 -9
@@ -17,7 +17,7 @@#include <rte_string_fns.h> #include <rte_memzone.h> #include <rte_malloc.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_alarm.h> #include <rte_branch_prediction.h> #include <rte_ether.h>
@@ -59,7 +59,8 @@ hn_rndis_rid(struct hn_data *hv)uint32_t rid;do { - rid =rte_atomic32_add_return (&hv->rndis_req_id,1 ); + rid =rte_atomic_fetch_add_explicit (&hv->rndis_req_id,1 , + rte_memory_order_seq_cst); }while (rid ==0 );return rid;
@@ -357,12 +358,14 @@ void hn_rndis_receive_response(struct hn_data *hv,memcpy (hv->rndis_resp, data, len);/* make sure response copied before update */ -rte_smp_wmb (); - -if (rte_atomic32_cmpset (&hv->rndis_pending, hdr->rid,0 ) ==0 ) { +uint32_t expected = hdr->rid; +if (!rte_atomic_compare_exchange_strong_explicit (&hv->rndis_pending, + &expected,0 , + rte_memory_order_release, + rte_memory_order_relaxed)) {PMD_DRV_LOG (NOTICE ,"received id %#x pending id %#x" , - hdr->rid, (uint32_t )hv->rndis_pending); + hdr->rid, expected); } }
@@ -388,8 +391,11 @@ static int hn_rndis_exec1(struct hn_data *hv,return -EINVAL ; } +uint32_t expected =0 ;if (comp !=NULL && -rte_atomic32_cmpset (&hv->rndis_pending,0 , rid) ==0 ) { + !rte_atomic_compare_exchange_strong_explicit ( + &hv->rndis_pending, &expected, rid, + rte_memory_order_acquire, rte_memory_order_relaxed)) {PMD_DRV_LOG (ERR ,"Request already pending" );return -EBUSY ;
@@ -405,7 +411,8 @@ static int hn_rndis_exec1(struct hn_data *hv,time_t start =time (NULL );/* Poll primary channel until response received */ -while (hv->rndis_pending == rid) { +while (rte_atomic_load_explicit (&hv->rndis_pending, + rte_memory_order_acquire) == rid) {if (hv->closed)return -ENETDOWN ;
@@ -413,7 +420,10 @@ static int hn_rndis_exec1(struct hn_data *hv,PMD_DRV_LOG (ERR ,"RNDIS response timed out" ); -rte_atomic32_cmpset (&hv->rndis_pending, rid,0 ); + expected = rid; +rte_atomic_compare_exchange_strong_explicit ( + &hv->rndis_pending, &expected,0 , + rte_memory_order_release, rte_memory_order_relaxed);return -ETIMEDOUT ; }
drivers/net/netvsc/hn_rxtx.c +7 -5
@@ -17,7 +17,7 @@#include <rte_string_fns.h> #include <rte_memzone.h> #include <rte_malloc.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_bitmap.h> #include <rte_branch_prediction.h> #include <rte_ether.h>
@@ -558,7 +558,8 @@ static void hn_rx_buf_free_cb(void *buf __rte_unused, void *opaque)struct hn_rx_queue *rxq = rxb->rxq;struct hn_data *hv = rxq->hv; -rte_atomic32_dec (&rxq->rxbuf_outstanding); +rte_atomic_fetch_sub_explicit (&rxq->rxbuf_outstanding,1 , + rte_memory_order_release);hn_nvs_ack_rxbuf (hv, rxb->chan, rxb->xactid); }
@@ -602,8 +603,8 @@ static void hn_rxpkt(struct hn_rx_queue *rxq, struct hn_rx_bufinfo *rxb,* some space available in receive area for later packets. */ if (hv->rx_extmbuf_enable && dlen > hv->rx_copybreak && - (uint32_t )rte_atomic32_read (&rxq->rxbuf_outstanding) < - hv->rxbuf_section_cnt /2 ) { +rte_atomic_load_explicit (&rxq->rxbuf_outstanding, + rte_memory_order_relaxed) < hv->rxbuf_section_cnt /2 ) {struct rte_mbuf_ext_shared_info *shinfo;const void *rxbuf;rte_iova_t iova;
@@ -619,7 +620,8 @@ static void hn_rxpkt(struct hn_rx_queue *rxq, struct hn_rx_bufinfo *rxb,/* shinfo is already set to 1 by the caller */ if (rte_mbuf_ext_refcnt_update (shinfo,1 ) ==2 ) -rte_atomic32_inc (&rxq->rxbuf_outstanding); +rte_atomic_fetch_add_explicit (&rxq->rxbuf_outstanding,1 , + rte_memory_order_acquire);rte_pktmbuf_attach_extbuf (m, data, iova, dlen + headroom, shinfo);
drivers/net/netvsc/hn_var.h +3 -3
@@ -85,7 +85,7 @@ struct hn_rx_queue {void *event_buf;struct hn_rx_bufinfo *rxbuf_info; -rte_atomic32_t rxbuf_outstanding; +RTE_ATOMIC (uint32_t ) rxbuf_outstanding; };
@@ -167,8 +167,8 @@ struct hn_data {uint32_t rndis_agg_pkts;uint32_t rndis_agg_align; -volatile uint32_t rndis_pending; -rte_atomic32_t rndis_req_id; +RTE_ATOMIC (uint32_t ) rndis_pending; +RTE_ATOMIC (uint32_t ) rndis_req_id;uint8_t rndis_resp[256 ];uint32_t rss_hash;
Signature · 1 line
2.53.0
PATCH v6 13/24 event/sw: convert from rte_atomic32 to stdatomic
In reply to Stephen HemmingerUse stdatomic to keep track of inflights.
--- drivers/event/sw/sw_evdev.c | 8 +++++--- drivers/event/sw/sw_evdev.h | 4 ++-- drivers/event/sw/sw_evdev_worker.c | 16 +++++++++++----- 3 files changed, 18 insertions(+), 10 deletions(-)
drivers/event/sw/sw_evdev.c +5 -3
@@ -153,7 +153,9 @@ sw_port_setup(struct rte_eventdev *dev, uint8_t port_id,* the sum to no leak credits */ int possible_inflights = p->inflight_credits + p->inflights; -rte_atomic32_sub (&sw->inflights, possible_inflights); +rte_atomic_fetch_sub_explicit (&sw->inflights, + possible_inflights, + rte_memory_order_release); } *p = (struct sw_port ){0 };/* zero entire structure */
@@ -512,7 +514,7 @@ sw_dev_configure(const struct rte_eventdev *dev) sw->qid_count = conf->nb_event_queues; sw->port_count = conf->nb_event_ports; sw->nb_events_limit = conf->nb_events_limit; -rte_atomic32_set (&sw->inflights,0 ); + sw->inflights =0 ;/* Number of chunks sized for worst-case spread of events across IQs */ num_chunks = ((SW_INFLIGHT_EVENTS_TOTAL/SW_EVS_PER_Q_CHUNK)+1) +
@@ -633,7 +635,7 @@ sw_dump(struct rte_eventdev *dev, FILE *f)fprintf (f,"\tsched cq/qid call: %" PRIu64"\n" , sw->sched_cq_qid_called);fprintf (f,"\tsched no IQ enq: %" PRIu64"\n" , sw->sched_no_iq_enqueues);fprintf (f,"\tsched no CQ enq: %" PRIu64"\n" , sw->sched_no_cq_enqueues); -uint32_t inflights =rte_atomic32_read (&sw->inflights); +uint32_t inflights =rte_atomic_load_explicit (&sw->inflights, rte_memory_order_relaxed);uint32_t credits = sw->nb_events_limit - inflights;fprintf (f,"\tinflight %d, credits: %d\n" , inflights, credits);
drivers/event/sw/sw_evdev.h +2 -2
@@ -8,7 +8,7 @@#include "sw_evdev_log.h" #include <rte_eventdev.h> #include <eventdev_pmd_vdev.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #define SW_DEFAULT_CREDIT_QUANTA 32#define SW_DEFAULT_SCHED_QUANTA 128
@@ -233,7 +233,7 @@ struct sw_evdev {/* Contains all ports - load balanced and directed */ alignas(RTE_CACHE_LINE_SIZE )struct sw_port ports[SW_PORTS_MAX ]; - alignas(RTE_CACHE_LINE_SIZE )rte_atomic32_t inflights; + alignas(RTE_CACHE_LINE_SIZE )RTE_ATOMIC (uint32_t ) inflights;/* * max events in this instance. Cached here for performance.
drivers/event/sw/sw_evdev_worker.c +11 -5
@@ -56,7 +56,7 @@ sw_event_enqueue_burst(void *port, const struct rte_event ev[], uint16_t num)uint8_t new_ops[PORT_ENQUEUE_MAX_BURST_SIZE ];struct sw_port *p = port;struct sw_evdev *sw = (void *)p->sw; -uint32_t sw_inflights =rte_atomic32_read (&sw->inflights); +uint32_t sw_inflights =rte_atomic_load_explicit (&sw->inflights, rte_memory_order_relaxed);uint32_t credit_update_quanta = sw->credit_update_quanta;int new =0 ;
@@ -74,8 +74,10 @@ sw_event_enqueue_burst(void *port, const struct rte_event ev[], uint16_t num)if (sw_inflights + credit_update_quanta > sw->nb_events_limit)return 0 ; -rte_atomic32_add (&sw->inflights, credit_update_quanta); - p->inflight_credits += (credit_update_quanta); +rte_atomic_fetch_add_explicit (&sw->inflights, + credit_update_quanta, + rte_memory_order_acquire); + p->inflight_credits += credit_update_quanta;/* If there are fewer inflight credits than new events, limit * the number of enqueued events.
@@ -124,7 +126,9 @@ sw_event_enqueue_burst(void *port, const struct rte_event ev[], uint16_t num)/* Replenish credits if enough releases are performed */ if (p->inflight_credits >= credit_update_quanta *2 ) { -rte_atomic32_sub (&sw->inflights, credit_update_quanta); +rte_atomic_fetch_sub_explicit (&sw->inflights, + credit_update_quanta, + rte_memory_order_release); p->inflight_credits -= credit_update_quanta; }
@@ -150,7 +154,9 @@ sw_event_dequeue_burst(void *port, struct rte_event *ev, uint16_t num,/* Replenish credits if enough releases are performed */ if (p->inflight_credits >= credit_update_quanta *2 ) { -rte_atomic32_sub (&sw->inflights, credit_update_quanta); +rte_atomic_fetch_sub_explicit (&sw->inflights, + credit_update_quanta, + rte_memory_order_release); p->inflight_credits -= credit_update_quanta; } }
Signature · 1 line
2.53.0
PATCH v6 14/24 bus/vmbus: convert from rte_atomic to stdatomic
In reply to Stephen HemmingerReplace deprecated rte_atomic32 operations in the vmbus ring buffer producer with stdatomic equivalents, and replace the smp_wmb + CAS-spin publish with rte_wait_until_equal_32 + release-store.
The two-cursor design is preserved: tbr->windex is the driver-private reservation cursor that lets producers reserve slots concurrently without a lock; vbr->windex is the host-visible commit cursor, updated in reservation order so the host never observes windex pointing past unwritten data. This is the lockless analogue of the spinlock-around- single-cursor pattern used by the Linux (drivers/hv/ring_buffer.c hv_ringbuffer_write) and FreeBSD (sys/dev/hyperv/vmbus/vmbus_br.c vmbus_txbr_write) implementations of the same host contract.
The memory ordering mirrors __rte_ring_headtail_move_head and __rte_ring_update_tail in lib/ring/rte_ring_c11_pvt.h: relaxed wait for the previous producer's commit, release-store to publish. The rte_smp_wmb before the publish is folded into the release ordering on the store itself.
The host-shared vbr->windex remains volatile uint32_t in the packed bufring struct; the atomic qualifier is added via cast at the access site. The (uintptr_t) launder on the store-side cast suppresses a spurious misaligned-atomic warning from the packed-struct attribute (windex is 4-byte aligned in practice, at offset 0 of a page-aligned struct).
--- drivers/bus/vmbus/private.h | 2 +- drivers/bus/vmbus/vmbus_bufring.c | 39 +++++++++++++++++-------------- 2 files changed, 23 insertions(+), 18 deletions(-)
drivers/bus/vmbus/private.h +1 -1
@@ -25,7 +25,7 @@ extern int vmbus_logtype_bus;struct vmbus_br {struct vmbus_bufring *vbr;uint32_t dsize; -uint32_t windex;/* next available location */ +RTE_ATOMIC (uint32_t ) windex;/* next available location */ };#define UIO_NAME_MAX 64
drivers/bus/vmbus/vmbus_bufring.c +22 -17
@@ -15,7 +15,7 @@#include <rte_tailq.h> #include <rte_log.h> #include <rte_malloc.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_memory.h> #include <rte_pause.h> #include <rte_bus_vmbus.h>
@@ -114,6 +114,7 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen,uint32_t ring_size = tbr->dsize;uint32_t old_windex, next_windex, windex, total;uint64_t save_windex; +bool success;int i; total =0 ;
@@ -121,17 +122,13 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen, total += iov[i].iov_len; total +=sizeof (save_windex); +/* Get current free location */ + old_windex =rte_atomic_load_explicit (&tbr->windex, + rte_memory_order_relaxed); +/* Reserve space in ring */ do { - uint32_t avail; - - /* Get current free location */ - old_windex = tbr->windex; - - /* Prevent compiler reordering this with calculation */ - rte_compiler_barrier(); - - avail = vmbus_br_availwrite(tbr, old_windex); + uint32_t avail = vmbus_br_availwrite(tbr, old_windex); /* If not enough space in ring, then tell caller. */ if (avail <= total)
@@ -139,8 +136,13 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen, next_windex =vmbus_br_idxinc (old_windex, total, ring_size); -/* Atomic update of next write_index for other threads */ - }while (!rte_atomic32_cmpset (&tbr->windex, old_windex, next_windex)); +/* Atomic update of next write_index for other threads +* Can use weak since easy to recompute and retry. +*/ + success =rte_atomic_compare_exchange_weak_explicit ( + &tbr->windex, &old_windex, next_windex, + rte_memory_order_acquire, rte_memory_order_relaxed); + }while (unlikely (!success));/* Space from old..new is now reserved */ windex = old_windex;
@@ -157,12 +159,15 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen,/* The region reserved should match region used */ RTE_ASSERT (windex == next_windex); -/* Ensure that data is available before updating host index */ -rte_smp_wmb (); +/* Wait for previous producer to publish their windex update */ +rte_wait_until_equal_32 (&vbr->windex, old_windex, rte_memory_order_relaxed); -/* Checkin for our reservation. wait for our turn to update host */ -while (!rte_atomic32_cmpset (&vbr->windex, old_windex, next_windex)) -rte_pause (); +/* Publish our windex update; prior data writes ordered via release. +* windex is 4-byte aligned in practice (struct is page-aligned, windex +* at offset 0); cast launders the packed-struct alignment-1 attribute. +*/ + rte_atomic_store_explicit((volatile __rte_atomic uint32_t *)(uintptr_t)&vbr->windex, + next_windex, rte_memory_order_release);/* If host had read all data before this, then need to signal */ *need_sig |=vmbus_txbr_need_signal (vbr, old_windex);
Signature · 1 line
2.53.0
PATCH v6 15/24 common/dpaax: use stdatomic instead of rte_atomic
In reply to Stephen HemmingerThe driver debug code uses local atomic wrappers; convert them to DPDK rte_atomic wrappers for C11 stdatomic.
--- drivers/common/dpaax/compat.h | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/common/dpaax/compat.h +12 -13
@@ -365,19 +365,18 @@ static inline unsigned long get_zeroed_page(gfp_t __foo __rte_unused)#define spin_lock_irqsave (x, f) spin_lock_irq(x)#define spin_unlock_irqrestore (x, f) spin_unlock_irq(x) -#define atomic_t rte_atomic32_t -#define atomic_read (v) rte_atomic32_read(v) -#define atomic_set (v, i) rte_atomic32_set(v, i) - -#define atomic_inc (v) rte_atomic32_add(v, 1) -#define atomic_dec (v) rte_atomic32_sub(v, 1) - -#define atomic_inc_and_test (v) rte_atomic32_inc_and_test(v) -#define atomic_dec_and_test (v) rte_atomic32_dec_and_test(v) - -#define atomic_inc_return (v) rte_atomic32_add_return(v, 1) -#define atomic_dec_return (v) rte_atomic32_sub_return(v, 1) -#define atomic_sub_and_test (i, v) (rte_atomic32_sub_return(v, i) == 0) +typedef RTE_ATOMIC (uint32_t )atomic_t ; + +#define atomic_read (v) rte_atomic_load_explicit((v), rte_memory_order_relaxed) +#define atomic_set (v, i) rte_atomic_store_explicit((v), (i), rte_memory_order_relaxed) +#define atomic_inc (v) ((void)rte_atomic_fetch_add_explicit((v), 1, \ + rte_memory_order_seq_cst)) +#define atomic_dec (v) ((void)rte_atomic_fetch_sub_explicit((v), 1, \ + rte_memory_order_seq_cst)) +#define atomic_inc_and_test (v) (rte_atomic_fetch_add_explicit((v), 1, \ + rte_memory_order_seq_cst) == 0) +#define atomic_dec_and_test (v) (rte_atomic_fetch_sub_explicit((v), 1, \ + rte_memory_order_seq_cst) == 0)/* Interface name len*/ #define IF_NAME_MAX_LEN 16
Signature · 1 line
2.53.0
PATCH v6 16/24 net/bnx2x: convert from rte_atomic32 to stdatomic
In reply to Stephen HemmingerReplace the legacy rte_atomic32_* API on sc->scan_fp with the equivalent rte_atomic_*_explicit C11 helpers, ahead of the deprecation of rte_atomicNN_t and its associated wrappers.
All accesses use rte_memory_order_seq_cst, matching the semantics of the legacy API. No functional change.
The scan_fp field is a notification flag between the slow-path command poster (bnx2x_sp_post) and the fastpath task that reaps ramrod completions (bnx2x_handle_fp_tq), also cleared from ecore_state_wait on success, panic, and timeout.
--- drivers/net/bnx2x/bnx2x.c | 6 +++--- drivers/net/bnx2x/bnx2x.h | 2 +- drivers/net/bnx2x/ecore_sp.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-)
drivers/net/bnx2x/bnx2x.c +3 -3
@@ -1098,7 +1098,7 @@ bnx2x_sp_post(struct bnx2x_softc *sc, int command, int cid, uint32_t data_hi,* Ask bnx2x_intr_intr() to process RAMROD * completion whenever it gets scheduled. */ -rte_atomic32_set (&sc->scan_fp,1 ); +rte_atomic_store_explicit (&sc->scan_fp,1 , rte_memory_order_seq_cst);bnx2x_sp_prod_update (sc);return 0 ;
@@ -4575,7 +4575,7 @@ static void bnx2x_handle_fp_tq(struct bnx2x_fastpath *fp)/* update the fastpath index */ bnx2x_update_fp_sb_idx (fp); -if (rte_atomic32_read (&sc->scan_fp) ==1 ) { +if (rte_atomic_load_explicit (&sc->scan_fp, rte_memory_order_seq_cst)) {if (bnx2x_has_rx_work (fp)) { more_rx =bnx2x_rxeof (sc, fp); }
@@ -4586,7 +4586,7 @@ static void bnx2x_handle_fp_tq(struct bnx2x_fastpath *fp)return ; }/* We have completed slow path completion, clear the flag */ -rte_atomic32_set (&sc->scan_fp,0 ); +rte_atomic_store_explicit (&sc->scan_fp,0 , rte_memory_order_seq_cst); } bnx2x_ack_sb(sc, fp->igu_sb_id, USTORM_ID,
drivers/net/bnx2x/bnx2x.h +1 -1
@@ -1043,7 +1043,7 @@ struct bnx2x_softc {#define PERIODIC_STOP 0#define PERIODIC_GO 1volatile unsigned long periodic_flags; -rte_atomic32_t scan_fp; +RTE_ATOMIC (uint32_t ) scan_fp;struct bnx2x_fastpath fp[MAX_RSS_CHAINS ];struct bnx2x_sp_objs sp_objs[MAX_RSS_CHAINS ];
drivers/net/bnx2x/ecore_sp.c +3 -3
@@ -299,21 +299,21 @@ static int ecore_state_wait(struct bnx2x_softc *sc, int state,#ifdef ECORE_STOP_ON_ERROR ECORE_MSG (sc,"exit (cnt %d)" ,5000 - cnt);#endif -rte_atomic32_set (&sc->scan_fp,0 ); +rte_atomic_store_explicit (&sc->scan_fp,0 , rte_memory_order_seq_cst);return ECORE_SUCCESS ; }ECORE_WAIT (sc, delay_us);if (sc->panic) { -rte_atomic32_set (&sc->scan_fp,0 ); +rte_atomic_store_explicit (&sc->scan_fp,0 , rte_memory_order_seq_cst);return ECORE_IO ; } }/* timeout! */ PMD_DRV_LOG (ERR , sc,"timeout waiting for state %d" , state); -rte_atomic32_set (&sc->scan_fp,0 ); +rte_atomic_store_explicit (&sc->scan_fp,0 , rte_memory_order_seq_cst);#ifdef ECORE_STOP_ON_ERROR ecore_panic ();#endif
Signature · 1 line
2.53.0
PATCH v6 17/24 bus/fslmc: replace rte_atomic32 with stdatomic
In reply to Stephen HemmingerThe atomic wrappers here are easily converted to stdatomic. Drop any unused macros.
--- drivers/bus/fslmc/qbman/include/compat.h | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)
drivers/bus/fslmc/qbman/include/compat.h +8 -13
@@ -81,18 +81,13 @@ do { \#define dma_wmb () rte_io_wmb() -#define atomic_t rte_atomic32_t -#define atomic_read (v) rte_atomic32_read(v) -#define atomic_set (v, i) rte_atomic32_set(v, i) - -#define atomic_inc (v) rte_atomic32_add(v, 1) -#define atomic_dec (v) rte_atomic32_sub(v, 1) - -#define atomic_inc_and_test (v) rte_atomic32_inc_and_test(v) -#define atomic_dec_and_test (v) rte_atomic32_dec_and_test(v) - -#define atomic_inc_return (v) rte_atomic32_add_return(v, 1) -#define atomic_dec_return (v) rte_atomic32_sub_return(v, 1) -#define atomic_sub_and_test (i, v) (rte_atomic32_sub_return(v, i) == 0) +typedef RTE_ATOMIC (uint32_t )atomic_t ; + +#define atomic_read (v) rte_atomic_load_explicit((v), rte_memory_order_relaxed) +#define atomic_set (v, i) rte_atomic_store_explicit((v), (i), rte_memory_order_relaxed) +#define atomic_inc (v) ((void)rte_atomic_fetch_add_explicit((v), 1, rte_memory_order_seq_cst)) +#define atomic_dec (v) ((void)rte_atomic_fetch_sub_explicit((v), 1, rte_memory_order_seq_cst)) +#define atomic_inc_and_test (v) (rte_atomic_fetch_add_explicit((v), 1, rte_memory_order_seq_cst) == -1) +#define atomic_dec_and_test (v) (rte_atomic_fetch_sub_explicit((v), 1, rte_memory_order_seq_cst) == 1)#endif /* HEADER_COMPAT_H */
Signature · 1 line
2.53.0
PATCH v6 18/24 drivers/event: replace rte_atomic32 in selftests
In reply to Stephen HemmingerLast callers in these selftests of the rte_atomicNN_*() family, which is being deprecated.
Convert total_events from rte_atomic32_t to RTE_ATOMIC(uint32_t) for the stack-local instance and __rte_atomic uint32_t * for the pointer in test_core_param. Switch reads and updates to rte_atomic_*_explicit().
Reads in the busy-loop checks and progress logs use relaxed: the counter is purely a "drained yet?" signal and no data is published through it. The fetch_sub on the dequeue path uses release in octeontx (preserving the publish-after-mbuf-free ordering already implied by the seq_cst sub it replaces) and relaxed in dpaa2.
The stack-local atomic_total_events is initialized by direct assignment instead of rte_atomic32_set(), since it is written before any worker is launched.
--- drivers/event/dpaa2/dpaa2_eventdev_selftest.c | 26 ++++---- drivers/event/octeontx/ssovf_evdev_selftest.c | 61 ++++++++++--------- 2 files changed, 47 insertions(+), 40 deletions(-)
drivers/event/dpaa2/dpaa2_eventdev_selftest.c +14 -12
@@ -2,7 +2,7 @@* Copyright 2018-2019 NXP */ -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_common.h> #include <rte_cycles.h> #include <rte_debug.h>
@@ -49,7 +49,7 @@ struct event_attr { };struct test_core_param { -rte_atomic32_t *total_events; + __rte_atomic uint32_t *total_events;uint64_t dequeue_tmo_ticks;uint8_t port;uint8_t sched_type;
@@ -444,10 +444,10 @@ worker_multi_port_fn(void *arg)struct rte_event ev;uint16_t valid_event;uint8_t port = param->port; -rte_atomic32_t *total_events = param->total_events; + __rte_atomic uint32_t *total_events = param->total_events;int ret; -while (rte_atomic32_read (total_events) >0 ) { +while (rte_atomic_load_explicit (total_events, rte_memory_order_relaxed) >0 ) { valid_event =rte_event_dequeue_burst (evdev, port, &ev,1 ,0 );if (!valid_event)continue ;
@@ -455,13 +455,15 @@ worker_multi_port_fn(void *arg) ret =validate_event (&ev);RTE_TEST_ASSERT_SUCCESS (ret,"Failed to validate event" );rte_pktmbuf_free (ev.mbuf); -rte_atomic32_sub (total_events,1 ); + +rte_atomic_fetch_sub_explicit (total_events,1 , + rte_memory_order_relaxed); }return 0 ; }static int -wait_workers_to_join (int lcore,const rte_atomic32_t *count) +wait_workers_to_join(int lcore, const __rte_atomic uint32_t *count) {uint64_t cycles, print_cycles;
@@ -472,15 +474,15 @@ wait_workers_to_join(int lcore, const rte_atomic32_t *count)uint64_t new_cycles =rte_get_timer_cycles ();if (new_cycles - print_cycles >rte_get_timer_hz ()) { -dpaa2_evdev_dbg ("\r%s: events %d" , __func__, -rte_atomic32_read (count)); +dpaa2_evdev_dbg ("\r%s: events %u" , __func__, +rte_atomic_load_explicit (count, rte_memory_order_relaxed)); print_cycles = new_cycles; }if (new_cycles - cycles >rte_get_timer_hz () *10 ) {dpaa2_evdev_info ( -"%s: No schedules for seconds, deadlock (%d)" , +"%s: No schedules for seconds, deadlock (%u)" , __func__, -rte_atomic32_read (count)); +rte_atomic_load_explicit (count, rte_memory_order_relaxed));rte_event_dev_dump (evdev, stdout); cycles = new_cycles;return -1 ;
@@ -500,13 +502,13 @@ launch_workers_and_wait(int (*main_worker)(void *),int w_lcore;int ret;struct test_core_param *param; -rte_atomic32_t atomic_total_events; +RTE_ATOMIC (uint32_t ) atomic_total_events;uint64_t dequeue_tmo_ticks;if (!nb_workers)return 0 ; -rte_atomic32_set (&atomic_total_events, total_events); + atomic_total_events = total_events;RTE_BUILD_BUG_ON (NUM_PACKETS <MAX_EVENTS ); param =malloc (sizeof (struct test_core_param ) * nb_workers);
drivers/event/octeontx/ssovf_evdev_selftest.c +33 -28
182 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v6 19/24 net/hinic: replace rte_atomic32 with stdatomic
In reply to Stephen HemmingerConvert dma_pool::inuse and hinic_os_dep::dma_alloc_cnt to RTE_ATOMIC(uint32_t) and replace rte_atomic32_*() with the rte_atomic_*_explicit() equivalents. The matching local variable and log format change from int/%d to uint32_t/%u.
--- drivers/net/hinic/base/hinic_compat.h | 2 +- drivers/net/hinic/base/hinic_pmd_hwdev.c | 24 ++++++++++++++---------- drivers/net/hinic/base/hinic_pmd_hwdev.h | 4 ++-- 3 files changed, 17 insertions(+), 13 deletions(-)
drivers/net/hinic/base/hinic_compat.h +1 -1
@@ -15,7 +15,7 @@#include <rte_memzone.h> #include <rte_memcpy.h> #include <rte_malloc.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_spinlock.h> #include <rte_cycles.h> #include <rte_log.h>
drivers/net/hinic/base/hinic_pmd_hwdev.c +14 -10
@@ -116,7 +116,8 @@ static void *hinic_dma_mem_zalloc(struct hinic_hwdev *hwdev, size_t size, dma_addr_t *dma_handle, unsigned int align, unsigned int socket_id) { - int rc, alloc_cnt; + int rc; +uint32_t alloc_cnt;const struct rte_memzone *mz;char z_name[RTE_MEMZONE_NAMESIZE ];hash_sig_t sig;
@@ -125,8 +126,9 @@ static void *hinic_dma_mem_zalloc(struct hinic_hwdev *hwdev, size_t size,if (dma_handle ==NULL ||0 == size)return NULL ; - alloc_cnt =rte_atomic32_add_return (&hwdev->os_dep.dma_alloc_cnt,1 ); -snprintf (z_name,sizeof (z_name),"%s_%d" , + alloc_cnt =rte_atomic_fetch_add_explicit (&hwdev->os_dep.dma_alloc_cnt, +1 , rte_memory_order_relaxed); +snprintf (z_name,sizeof (z_name),"%s_%u" , hwdev->pcidev_hdl->name, alloc_cnt); mz = rte_memzone_reserve_aligned(z_name, size, socket_id,
@@ -282,7 +284,6 @@ struct dma_pool *dma_pool_create(const char *name, void *dev,if (!pool)return NULL ; -rte_atomic32_set (&pool->inuse,0 ); pool->elem_size = size; pool->align = align; pool->boundary = boundary;
@@ -294,12 +295,15 @@ struct dma_pool *dma_pool_create(const char *name, void *dev,void dma_pool_destroy (struct dma_pool *pool) { +uint32_t inuse; +if (!pool)return ; -if (rte_atomic32_read (&pool->inuse) !=0 ) { -PMD_DRV_LOG (ERR ,"Leak memory, dma_pool: %s, inuse_count: %d" , - pool->name,rte_atomic32_read (&pool->inuse)); + inuse =rte_atomic_load_explicit (&pool->inuse, rte_memory_order_relaxed); +if (inuse !=0 ) { +PMD_DRV_LOG (ERR ,"Leak memory, dma_pool: %s, inuse_count: %u" , + pool->name, inuse); }rte_free (pool);
@@ -312,14 +316,14 @@ void *dma_pool_alloc(struct pci_pool *pool, dma_addr_t *dma_addr) buf =hinic_dma_mem_zalloc (pool->hwdev, pool->elem_size, dma_addr, (u32 )pool->align,SOCKET_ID_ANY );if (buf) -rte_atomic32_inc (&pool->inuse); +rte_atomic_fetch_add_explicit (&pool->inuse,1 , rte_memory_order_relaxed);return buf; }void dma_pool_free (struct pci_pool *pool,void *vaddr,dma_addr_t dma) { -rte_atomic32_dec (&pool->inuse); +rte_atomic_fetch_sub_explicit (&pool->inuse,1 , rte_memory_order_relaxed);hinic_dma_mem_free (pool->hwdev, pool->elem_size, vaddr, dma); }
@@ -329,7 +333,7 @@ int hinic_osdep_init(struct hinic_hwdev *hwdev)struct rte_hash_parameters dh_params = {0 };struct rte_hash *paddr_hash =NULL ; -rte_atomic32_set (&hwdev->os_dep.dma_alloc_cnt,0 ); + hwdev->os_dep.dma_alloc_cnt =0 ;rte_spinlock_init (&hwdev->os_dep.dma_hash_lock); dh_params.name = hwdev->pcidev_hdl->name;
drivers/net/hinic/base/hinic_pmd_hwdev.h +2 -2
@@ -18,7 +18,7 @@/* dma pool */ struct dma_pool { -rte_atomic32_t inuse; +RTE_ATOMIC (uint32_t ) inuse;size_t elem_size;size_t align;size_t boundary;
@@ -402,7 +402,7 @@ struct hinic_hilink_link_info {/* dma os dependency implementation */ struct hinic_os_dep {/* kernel dma alloc api */ -rte_atomic32_t dma_alloc_cnt; +RTE_ATOMIC (uint32_t ) dma_alloc_cnt;rte_spinlock_t dma_hash_lock;struct rte_hash *dma_addr_hash; };
Signature · 1 line
2.53.0
PATCH v6 20/24 net/txgbe: replace rte_atomic32 with stdatomic
In reply to Stephen HemmingerThe swfw_busy flag guarding the AML SW-FW mailbox is a one-bit lock, so convert it to RTE_ATOMIC(bool) and replace the legacy test-and-set / clear pair with explicit acquire-release:
rte_atomic32_test_and_set ->
rte_atomic_exchange_explicit(.., true, acquire)
rte_atomic32_clear ->
rte_atomic_store_explicit(.., false, release)
Acquire on the take pairs with release on the drop, so accesses inside the critical section are synchronized between successive holders. Default zero-initialization of struct txgbe_hw still gives swfw_busy = false, so no init site needs updating.
Note:
The previous rte_atomic32_test_and_set return value was inverted relative to what this code expected; this patch incidentally corrects that. A standalone Fixes: patch is queued in net-next.
--- drivers/net/txgbe/base/txgbe_mng.c | 4 ++-- drivers/net/txgbe/base/txgbe_type.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/txgbe/base/txgbe_mng.c +2 -2
@@ -185,7 +185,7 @@ txgbe_host_interface_command_aml(struct txgbe_hw *hw, u32 *buffer, }/* try to get lock */ -while (rte_atomic32_test_and_set (&hw->swfw_busy)) { +while (rte_atomic_exchange_explicit (&hw->swfw_busy, true, rte_memory_order_acquire)) { timeout--;if (!timeout)return TXGBE_ERR_TIMEOUT ;
@@ -266,7 +266,7 @@ txgbe_host_interface_command_aml(struct txgbe_hw *hw, u32 *buffer,/* index++, index replace txgbe_hic_hdr.checksum */ hw->swfw_index = resp->index ==TXGBE_HIC_HDR_INDEX_MAX ?0 : resp->index +1 ; -rte_atomic32_clear (&hw->swfw_busy); +rte_atomic_store_explicit (&hw->swfw_busy, false, rte_memory_order_release);return err; }
drivers/net/txgbe/base/txgbe_type.h +1 -1
@@ -897,7 +897,7 @@ struct txgbe_hw {rte_spinlock_t phy_lock;/*amlite: new SW-FW mbox */ u8 swfw_index; -rte_atomic32_t swfw_busy; +RTE_ATOMIC (bool ) swfw_busy;bool link_valid;bool reconfig_rx;RTE_ATOMIC (bool ) pf_running;
Signature · 1 line
2.53.0
PATCH v6 21/24 net/vhost: use stdatomic instead of rte_atomic32
In reply to Stephen HemmingerConvert allow_queuing, while_queuing, started, and dev_attached from rte_atomic32_t to RTE_ATOMIC(uint32_t) and replace rte_atomic32_*() with rte_atomic_*_explicit().
The data-path / control-thread handshake on allow_queuing and while_queuing is a Dekker-style mutual-visibility pattern: each side stores its own flag and then loads the peer's. Both legs must be seq_cst to forbid store-load reordering; anything weaker permits both sides to miss each other. The previous rte_atomic32_set/read compiled to plain volatile stores/loads and provided no such ordering, so this also closes a latent ordering hole on weakly-ordered ISAs.
The data-path exit store of while_queuing=0 is release, ordering preceding slot accesses before the control thread observes the data path as idle.
The flags started and dev_attached are consulted only inside update_queuing_status, where the per-queue handshake provides the real synchronization; their loads and stores are relaxed.
Factor the per-queue allow_queuing store and while_queuing wait into a small update_queue() helper used by both rx and tx loops.
--- drivers/net/vhost/rte_eth_vhost.c | 103 +++++++++++++++++++----------- 1 file changed, 65 insertions(+), 38 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +65 -38
@@ -73,8 +73,8 @@ struct vhost_stats {struct vhost_queue {int vid; -rte_atomic32_t allow_queuing; -rte_atomic32_t while_queuing; +RTE_ATOMIC (uint32_t ) allow_queuing; +RTE_ATOMIC (uint32_t ) while_queuing;struct pmd_internal *internal;struct rte_mempool *mb_pool;uint16_t port;
@@ -86,14 +86,14 @@ struct vhost_queue { };struct pmd_internal { -rte_atomic32_t dev_attached; +RTE_ATOMIC (uint32_t ) dev_attached;char *iface_name;uint64_t flags;uint64_t disable_flags;uint64_t features;uint16_t max_queues;int vid; -rte_atomic32_t started; +RTE_ATOMIC (uint32_t ) started;bool vlan_strip;bool rx_sw_csum;bool tx_sw_csum;
@@ -406,12 +406,19 @@ eth_vhost_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)uint16_t i, nb_rx =0 ;uint16_t nb_receive = nb_bufs; -if (unlikely (rte_atomic32_read (&r->allow_queuing) ==0 )) +/* Fast-path early exit; racy load is fine here -- if we miss a +* transition we get caught by the seq_cst check below. +*/ +if (unlikely (rte_atomic_load_explicit (&r->allow_queuing, rte_memory_order_relaxed) ==0 ))return 0 ; -rte_atomic32_set (&r->while_queuing,1 ); - -if (unlikely (rte_atomic32_read (&r->allow_queuing) ==0 )) +/* Announce presence, then re-check. The store and the following +* load MUST both be seq_cst so they are totally ordered with the +* control thread's store-to-allow_queuing / load-of-while_queuing +* pair. Anything weaker permits both sides to miss each other. +*/ +rte_atomic_store_explicit (&r->while_queuing,1 , rte_memory_order_seq_cst); +if (unlikely (rte_atomic_load_explicit (&r->allow_queuing, rte_memory_order_seq_cst) ==0 )) goto out;/* Dequeue packets from guest TX queue */
@@ -446,7 +453,7 @@ eth_vhost_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) } out: -rte_atomic32_set (&r->while_queuing,0 ); +rte_atomic_store_explicit (&r->while_queuing,0 , rte_memory_order_release);return nb_rx; }
@@ -460,12 +467,19 @@ eth_vhost_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)uint64_t nb_bytes =0 ;uint64_t nb_missed =0 ; -if (unlikely (rte_atomic32_read (&r->allow_queuing) ==0 )) +/* Fast-path early exit; racy load is fine here -- if we miss a +* transition we get caught by the seq_cst check below. +*/ +if (unlikely (rte_atomic_load_explicit (&r->allow_queuing, rte_memory_order_relaxed) ==0 ))return 0 ; -rte_atomic32_set (&r->while_queuing,1 ); - -if (unlikely (rte_atomic32_read (&r->allow_queuing) ==0 )) +/* Announce presence, then re-check. The store and the following +* load MUST both be seq_cst so they are totally ordered with the +* control thread's store-to-allow_queuing / load-of-while_queuing +* pair. Anything weaker permits both sides to miss each other. +*/ +rte_atomic_store_explicit (&r->while_queuing,1 , rte_memory_order_seq_cst); +if (unlikely (rte_atomic_load_explicit (&r->allow_queuing, rte_memory_order_seq_cst) ==0 )) goto out;for (i =0 ; i < nb_bufs; i++) {
@@ -515,7 +529,7 @@ eth_vhost_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)for (i =0 ;likely (i < nb_tx); i++)rte_pktmbuf_free (bufs[i]); out: -rte_atomic32_set (&r->while_queuing,0 ); +rte_atomic_store_explicit (&r->while_queuing,0 , rte_memory_order_release);return nb_tx; }
@@ -744,6 +758,19 @@ eth_vhost_unconfigure_intr(struct rte_eth_dev *eth_dev) } } +static inline void +update_queue (struct vhost_queue *vq,uint32_t allow,bool wait_queuing) +{ +/* seq_cst: pairs with the data-path's seq_cst store of +* while_queuing and seq_cst load of allow_queuing. See +* eth_vhost_rx(). +*/ +rte_atomic_store_explicit (&vq->allow_queuing, allow, rte_memory_order_seq_cst); +if (wait_queuing) +rte_wait_until_equal_32 ((volatile uint32_t *)(uintptr_t )&vq->while_queuing, +0 , rte_memory_order_seq_cst); +} +static void update_queuing_status (struct rte_eth_dev *dev,bool wait_queuing) {
@@ -751,14 +778,18 @@ update_queuing_status(struct rte_eth_dev *dev, bool wait_queuing)struct vhost_queue *vq;struct rte_vhost_vring_state *state;unsigned int i; -int allow_queuing =1 ; +bool allow_queuing = true;if (!dev->data->rx_queues || !dev->data->tx_queues)return ; -if (rte_atomic32_read (&internal->started) ==0 || -rte_atomic32_read (&internal->dev_attached) ==0 ) - allow_queuing =0 ; +/* These are control-plane flags consulted only here; +* the real data-path handshake is on vq->allow_queuing below. +* Relaxed is sufficient. +*/ +if (rte_atomic_load_explicit (&internal->started, rte_memory_order_relaxed) ==0 || +rte_atomic_load_explicit (&internal->dev_attached, rte_memory_order_relaxed) ==0 ) + allow_queuing = false; state = vring_states[dev->data->port_id];
@@ -767,24 +798,18 @@ update_queuing_status(struct rte_eth_dev *dev, bool wait_queuing) vq = dev->data->rx_queues[i];if (vq ==NULL )continue ; -if (allow_queuing && state->cur[vq->virtqueue_id]) -rte_atomic32_set (&vq->allow_queuing,1 ); -else -rte_atomic32_set (&vq->allow_queuing,0 ); -while (wait_queuing &&rte_atomic32_read (&vq->while_queuing)) -rte_pause (); + +update_queue (vq, !!(allow_queuing && state->cur[vq->virtqueue_id]), + wait_queuing); }for (i =0 ; i < dev->data->nb_tx_queues; i++) { vq = dev->data->tx_queues[i];if (vq ==NULL )continue ; -if (allow_queuing && state->cur[vq->virtqueue_id]) -rte_atomic32_set (&vq->allow_queuing,1 ); -else -rte_atomic32_set (&vq->allow_queuing,0 ); -while (wait_queuing &&rte_atomic32_read (&vq->while_queuing)) -rte_pause (); + +update_queue (vq, !!(allow_queuing && state->cur[vq->virtqueue_id]), + wait_queuing); } }
@@ -848,7 +873,7 @@ new_device(int vid) } internal->vid = vid; -if (rte_atomic32_read (&internal->started) ==1 ) { +if (rte_atomic_load_explicit (&internal->started, rte_memory_order_relaxed) ==1 ) {queue_setup (eth_dev, internal);if (dev_conf->intr_conf.rxq)eth_vhost_configure_intr (eth_dev);
@@ -863,7 +888,7 @@ new_device(int vid)vhost_dev_csum_configure (eth_dev); -rte_atomic32_set (&internal->dev_attached,1 ); +rte_atomic_store_explicit (&internal->dev_attached,1 , rte_memory_order_relaxed);update_queuing_status (eth_dev, false);VHOST_LOG_LINE (INFO ,"Vhost device %d created" , vid);
@@ -893,7 +918,7 @@ destroy_device(int vid) eth_dev = list->eth_dev; internal = eth_dev->data->dev_private; -rte_atomic32_set (&internal->dev_attached,0 ); +rte_atomic_store_explicit (&internal->dev_attached,0 , rte_memory_order_relaxed);update_queuing_status (eth_dev, true);eth_vhost_unconfigure_intr (eth_dev);
@@ -1148,11 +1173,11 @@ eth_dev_start(struct rte_eth_dev *eth_dev) }queue_setup (eth_dev, internal); -if (rte_atomic32_read (&internal->dev_attached) ==1 && +if (rte_atomic_load_explicit (&internal->dev_attached, rte_memory_order_relaxed) ==1 && dev_conf->intr_conf.rxq)eth_vhost_configure_intr (eth_dev); -rte_atomic32_set (&internal->started,1 ); +rte_atomic_store_explicit (&internal->started,1 , rte_memory_order_relaxed);update_queuing_status (eth_dev, false);for (i =0 ; i < eth_dev->data->nb_rx_queues; i++)
@@ -1170,7 +1195,7 @@ eth_dev_stop(struct rte_eth_dev *dev)uint16_t i; dev->data->dev_started =0 ; -rte_atomic32_set (&internal->started,0 ); +rte_atomic_store_explicit (&internal->started,0 , rte_memory_order_relaxed);update_queuing_status (dev, true);for (i =0 ; i < dev->data->nb_rx_queues; i++)
@@ -1471,8 +1496,10 @@ vhost_dev_priv_dump(struct rte_eth_dev *dev, FILE *f)fprintf (f,"features: 0x%" PRIx64"\n" , internal->features);fprintf (f,"max_queues: %u\n" , internal->max_queues);fprintf (f,"vid: %d\n" , internal->vid); -fprintf (f,"started: %d\n" ,rte_atomic32_read (&internal->started)); -fprintf (f,"dev_attached: %d\n" ,rte_atomic32_read (&internal->dev_attached)); +fprintf (f,"started: %u\n" , +rte_atomic_load_explicit (&internal->started, rte_memory_order_relaxed)); +fprintf (f,"dev_attached: %u\n" , +rte_atomic_load_explicit (&internal->dev_attached, rte_memory_order_relaxed));fprintf (f,"vlan_strip: %d\n" , internal->vlan_strip);fprintf (f,"rx_sw_csum: %d\n" , internal->rx_sw_csum);fprintf (f,"tx_sw_csum: %d\n" , internal->tx_sw_csum);
Signature · 1 line
2.53.0
PATCH v6 22/24 vdpa/ifc: replace rte_atomic32 with stdatomic
In reply to Stephen HemmingerLast in-tree caller of rte_atomic32_*(), blocking deprecation of the rte_atomicNN_*() family.
Replace rte_atomic32_read/set() with rte_atomic_load_explicit() and rte_atomic_store_explicit() on the started, dev_attached, and running flags. Narrow them to bool (only ever hold 0/1) and group with the existing bools to reduce padding in struct ifcvf_internal.
--- drivers/vdpa/ifc/ifcvf_vdpa.c | 37 ++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 18 deletions(-)
drivers/vdpa/ifc/ifcvf_vdpa.c +19 -18
@@ -25,6 +25,7 @@#include <rte_log.h> #include <rte_kvargs.h> #include <rte_devargs.h> +#include <rte_stdatomic.h> #include "base/ifcvf.h"
@@ -68,10 +69,10 @@ struct ifcvf_internal {struct rte_vdpa_device *vdev;uint16_t max_queues;uint64_t features; -rte_atomic32_t started; -rte_atomic32_t dev_attached; -rte_atomic32_t running;rte_spinlock_t lock; +RTE_ATOMIC (bool ) started; +RTE_ATOMIC (bool ) dev_attached; +RTE_ATOMIC (bool ) running;bool sw_lm;bool sw_fallback_running;/* mediated vring for sw fallback */
@@ -712,9 +713,9 @@ update_datapath(struct ifcvf_internal *internal)rte_spinlock_lock (&internal->lock); -if (!rte_atomic32_read (&internal->running) && - (rte_atomic32_read (&internal->started) && -rte_atomic32_read (&internal->dev_attached))) { +if (!rte_atomic_load_explicit (&internal->running, rte_memory_order_seq_cst) && + (rte_atomic_load_explicit (&internal->started, rte_memory_order_seq_cst) && +rte_atomic_load_explicit (&internal->dev_attached, rte_memory_order_seq_cst))) { ret =ifcvf_dma_map (internal, true);if (ret) goto err;
@@ -735,10 +736,10 @@ update_datapath(struct ifcvf_internal *internal)if (ret) goto err; -rte_atomic32_set (&internal->running,1 ); - }else if (rte_atomic32_read (&internal->running) && - (!rte_atomic32_read (&internal->started) || - !rte_atomic32_read (&internal->dev_attached))) { +rte_atomic_store_explicit (&internal->running, true, rte_memory_order_seq_cst); + }else if (rte_atomic_load_explicit (&internal->running, rte_memory_order_seq_cst) && + (!rte_atomic_load_explicit (&internal->started, rte_memory_order_seq_cst) || + !rte_atomic_load_explicit (&internal->dev_attached, rte_memory_order_seq_cst))) {unset_intr_relay (internal); ret =unset_notify_relay (internal);
@@ -755,7 +756,7 @@ update_datapath(struct ifcvf_internal *internal)if (ret) goto err; -rte_atomic32_set (&internal->running,0 ); +rte_atomic_store_explicit (&internal->running, false, rte_memory_order_seq_cst); }rte_spinlock_unlock (&internal->lock);
@@ -1058,7 +1059,7 @@ ifcvf_sw_fallback_switchover(struct ifcvf_internal *internal)vdpa_disable_vfio_intr (internal); -rte_atomic32_set (&internal->running,0 ); +rte_atomic_store_explicit (&internal->running, false, rte_memory_order_seq_cst); ret =rte_vhost_host_notifier_ctrl (vid,RTE_VHOST_QUEUE_ALL , false);if (ret && ret != -ENOTSUP )
@@ -1113,11 +1114,11 @@ ifcvf_dev_config(int vid) internal = list->internal; internal->vid = vid; -rte_atomic32_set (&internal->dev_attached,1 ); +rte_atomic_store_explicit (&internal->dev_attached, true, rte_memory_order_seq_cst);if (update_datapath (internal) <0 ) {DRV_LOG (ERR ,"failed to update datapath for vDPA device %s" , vdev->device->name); -rte_atomic32_set (&internal->dev_attached,0 ); +rte_atomic_store_explicit (&internal->dev_attached, false, rte_memory_order_seq_cst);return -1 ; }
@@ -1166,7 +1167,7 @@ ifcvf_dev_close(int vid) internal->sw_fallback_running = false; }else { -rte_atomic32_set (&internal->dev_attached,0 ); +rte_atomic_store_explicit (&internal->dev_attached, false, rte_memory_order_seq_cst);if (update_datapath (internal) <0 ) {DRV_LOG (ERR ,"failed to update datapath for vDPA device %s" , vdev->device->name);
@@ -1782,10 +1783,10 @@ ifcvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, goto error; } -rte_atomic32_set (&internal->started,1 ); +rte_atomic_store_explicit (&internal->started, true, rte_memory_order_seq_cst);if (update_datapath (internal) <0 ) {DRV_LOG (ERR ,"failed to update datapath %s" , pci_dev->name); -rte_atomic32_set (&internal->started,0 ); +rte_atomic_store_explicit (&internal->started, false, rte_memory_order_seq_cst);rte_vdpa_unregister_device (internal->vdev);pthread_mutex_lock (&internal_list_lock);TAILQ_REMOVE (&internal_list, list, next);
@@ -1819,7 +1820,7 @@ ifcvf_pci_remove(struct rte_pci_device *pci_dev) } internal = list->internal; -rte_atomic32_set (&internal->started,0 ); +rte_atomic_store_explicit (&internal->started, false, rte_memory_order_seq_cst);if (update_datapath (internal) <0 )DRV_LOG (ERR ,"failed to update datapath %s" , pci_dev->name);
Signature · 1 line
2.53.0
PATCH v6 23/24 test/atomic: suppress deprecation warnings for legacy APIs
In reply to Stephen HemmingerThe rte_atomicNN_* APIs are now marked __rte_deprecated. Wrap the whole file with __rte_diagnostic_push / pop and a GCC pragma -Wdeprecated-declarations.
In future, when the APIs are removed this test collapses to just the 128-bit compare-and-swap case and the suppression goes with it.
--- app/test/test_atomic.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
app/test/test_atomic.c +12 -0
@@ -100,6 +100,15 @@* - At the end of the test, the number of corrupted tokens must be 0. */ +/* +* The rte_atomicNN_* APIs exercised below are deprecated in favour of C11 atomics. +* Suppress the deprecation warnings for the whole file; +* when the APIs are removed this test collapses to the 128-bit +* compare-and-swap case and the suppression goes with it. +*/ +__rte_diagnostic_push +_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#define NUM_ATOMIC_TYPES 3#define N_BASE 1000000u
@@ -645,4 +654,7 @@ test_atomic(void)return 0 ; }REGISTER_FAST_TEST (atomic_autotest,NOHUGE_SKIP ,ASAN_OK , test_atomic); + +__rte_diagnostic_pop +#endif /* RTE_TOOLCHAIN_MSVC */
Signature · 1 line
2.53.0
PATCH v6 24/24 eal: deprecate rte_atomicNN functions
In reply to Stephen HemmingerThis deprecates existing rte_atomic functions that are not used anywhere after this patch series. Rather than keeping platform specific versions; just use the interinsic versions.
Now the compiler checks for these functions, no longer need the check in checkpatches.
--- devtools/checkpatches.sh | 8 - doc/guides/rel_notes/deprecation.rst | 4 +- doc/guides/rel_notes/release_26_11.rst | 5 + lib/eal/arm/include/rte_atomic_32.h | 4 - lib/eal/arm/include/rte_atomic_64.h | 4 - lib/eal/include/generic/rte_atomic.h | 243 ++++++------------------- lib/eal/include/rte_common.h | 2 + lib/eal/loongarch/include/rte_atomic.h | 4 - lib/eal/ppc/include/rte_atomic.h | 173 ------------------ lib/eal/riscv/include/rte_atomic.h | 4 - lib/eal/x86/include/rte_atomic.h | 172 ----------------- lib/eal/x86/include/rte_atomic_32.h | 188 ------------------- lib/eal/x86/include/rte_atomic_64.h | 157 ---------------- 13 files changed, 68 insertions(+), 900 deletions(-)
devtools/checkpatches.sh +0 -8
@@ -121,14 +121,6 @@ check_forbidden_additions() { # <patch> -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ "$1" || res=1 - # refrain from new additions of 16/32/64 bits rte_atomicNN_xxx() - awk -v FOLDERS="lib drivers app examples" \ - -v EXPRESSIONS="rte_atomic[0-9][0-9]_.*\\\(" \ - -v RET_ON_FAIL=1 \ - -v MESSAGE='Using rte_atomicNN_xxx' \ - -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ - "$1" || res=1 - # refrain from new additions of rte_smp_[r/w]mb() awk -v FOLDERS="lib drivers app examples" \ -v EXPRESSIONS="rte_smp_(r|w)?mb\\\(" \
doc/guides/rel_notes/deprecation.rst +1 -3
@@ -42,9 +42,7 @@ Deprecation Notices * rte_atomicNN_xxx: These APIs do not take memory order parameter. This does not allow for writing optimized code for all the CPU architectures supported in DPDK. DPDK has adopted the atomic operations from - https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html. These - operations must be used for patches that need to be merged in 20.08 onwards. - This change will not introduce any performance degradation. + https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html. * rte_smp_*mb: These APIs provide full barrier functionality. However, many use cases do not require full barriers. To support such use cases, DPDK has
doc/guides/rel_notes/release_26_11.rst +5 -0
@@ -109,6 +109,11 @@ ABI Changes Also, make sure to start the actual text at the margin. ======================================================= +* **atomic: Marked the ``rte_atomicNN`` functions as deprecated.** + + As previously announced these functions were intended to be deprecated + but was not being enforced. + Known Issues ------------
lib/eal/arm/include/rte_atomic_32.h +0 -4
@@ -5,10 +5,6 @@#ifndef _RTE_ATOMIC_ARM32_H_#define _RTE_ATOMIC_ARM32_H_ -#ifndef RTE_FORCE_INTRINSICS -# error Platform must be built with RTE_FORCE_INTRINSICS -#endif -#include "generic/rte_atomic.h" #ifdef __cplusplus
lib/eal/arm/include/rte_atomic_64.h +0 -4
@@ -6,10 +6,6 @@#ifndef _RTE_ATOMIC_ARM64_H_#define _RTE_ATOMIC_ARM64_H_ -#ifndef RTE_FORCE_INTRINSICS -# error Platform must be built with RTE_FORCE_INTRINSICS -#endif -#include "generic/rte_atomic.h" #include <rte_branch_prediction.h> #include <rte_debug.h>
lib/eal/include/generic/rte_atomic.h +60 -183
639 lines not on this page · raw message
lib/eal/include/rte_common.h +2 -0
@@ -172,9 +172,11 @@ typedef uint16_t unaligned_uint16_t;#ifdef RTE_TOOLCHAIN_MSVC #define __rte_deprecated#define __rte_deprecated_msg (msg) +#define __rte_allow_deprecated#else #define __rte_deprecated __attribute__((__deprecated__))#define __rte_deprecated_msg (msg) __attribute__((__deprecated__(msg))) +#define __rte_allow_deprecated _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")#endif /**
lib/eal/loongarch/include/rte_atomic.h +0 -4
@@ -5,10 +5,6 @@#ifndef RTE_ATOMIC_LOONGARCH_H #define RTE_ATOMIC_LOONGARCH_H -#ifndef RTE_FORCE_INTRINSICS -# error Platform must be built with RTE_FORCE_INTRINSICS -#endif -#include <rte_common.h> #include "generic/rte_atomic.h"
lib/eal/ppc/include/rte_atomic.h +0 -173
179 lines not on this page · raw message
lib/eal/riscv/include/rte_atomic.h +0 -4
@@ -8,10 +8,6 @@#ifndef RTE_ATOMIC_RISCV_H #define RTE_ATOMIC_RISCV_H -#ifndef RTE_FORCE_INTRINSICS -# error Platform must be built with RTE_FORCE_INTRINSICS -#endif -#include <stdint.h> #include <rte_common.h> #include <rte_config.h>
lib/eal/x86/include/rte_atomic.h +0 -172
178 lines not on this page · raw message
lib/eal/x86/include/rte_atomic_32.h +0 -188
193 lines not on this page · raw message
lib/eal/x86/include/rte_atomic_64.h +0 -157
163 lines not on this page · raw message
Signature · 1 line
2.53.0
v7 cover remove legacy atomic functions
In reply to Stephen HemmingerThe rte_atomicNN_* family was flagged for deprecation in 2021 by commit 3ec965b6de12 ("doc: update atomic operation deprecation") but removal had stalled and usage contined to grow.
This series finishes converting every remaining in-tree caller to the C11-style rte_atomic_*_explicit() / RTE_ATOMIC() API, then removes the legacy functions. The deprecation has been out there long enough so not a big surprise to users.
v7 - fix some review comments
- remove unused macros
- remove ret_atomicNN functions (rather than deprecating them).
v6 - rebase for 26.11
- address some more AI review comments
Stephen Hemminger (24):
bpf: use C11 atomics in BPF_ST_ATOMIC_REG net/bonding: use stdatomic
net/nbl: remove unused rte_atomic16 field net/ena: replace use of rte_atomicNN net/failsafe: convert to stdatomic
net/enic: do not use deprecated rte_atomic64 net/pfe: use ethdev linkstatus helpers net/sfc: replace rte_atomic with stdatomic crypto/ccp: replace use of rte_atomic64 with stdatomic bus/dpaa: replace rte_atomic16 with stdatomic bus/fslmc: replace rte_atomic16 with stdatomic net/netvsc: replace rte_atomic32 with stdatomic event/sw: convert from rte_atomic32 to stdatomic bus/vmbus: convert from rte_atomic to stdatomic common/dpaax: remove unused atomic wrappers net/bnx2x: convert from rte_atomic32 to stdatomic bus/fslmc: replace rte_atomic32 with stdatomic drivers/event: replace rte_atomic32 in selftests net/hinic: replace rte_atomic32 with stdatomic net/txgbe: replace rte_atomic32 with stdatomic net/vhost: use stdatomic instead of rte_atomic32 vdpa/ifc: replace rte_atomic32 with stdatomic test/atomic: drop old rte_atomicNN tests
eal: remove rte_atomicNN functions
app/test/test_atomic.c | 523 +--------- devtools/checkpatches.sh | 8 - doc/guides/rel_notes/deprecation.rst | 7 - doc/guides/rel_notes/release_26_11.rst | 7 + drivers/bus/dpaa/base/qbman/qman.c | 9 +- drivers/bus/fslmc/portal/dpaa2_hw_dpbp.c | 11 +- drivers/bus/fslmc/portal/dpaa2_hw_dpci.c | 11 +- drivers/bus/fslmc/portal/dpaa2_hw_dpcon.c | 11 +- drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 14 +- drivers/bus/fslmc/portal/dpaa2_hw_pvt.h | 9 +- drivers/bus/fslmc/qbman/include/compat.h | 16 +- drivers/bus/vmbus/private.h | 2 +- drivers/bus/vmbus/vmbus_bufring.c | 39 +- drivers/common/dpaax/compat.h | 14 - drivers/crypto/ccp/ccp_crypto.c | 11 +- drivers/crypto/ccp/ccp_crypto.h | 2 +- drivers/crypto/ccp/ccp_dev.c | 10 +- drivers/crypto/ccp/ccp_dev.h | 4 +- drivers/event/dpaa2/dpaa2_eventdev_selftest.c | 26 +- drivers/event/octeontx/ssovf_evdev_selftest.c | 61 +- drivers/event/sw/sw_evdev.c | 8 +- drivers/event/sw/sw_evdev.h | 4 +- drivers/event/sw/sw_evdev_worker.c | 16 +- drivers/net/bnx2x/bnx2x.c | 6 +- drivers/net/bnx2x/bnx2x.h | 2 +- drivers/net/bnx2x/ecore_sp.c | 6 +- drivers/net/bonding/eth_bond_8023ad_private.h | 6 +- drivers/net/bonding/rte_eth_bond_8023ad.c | 35 +- drivers/net/ena/base/ena_plat_dpdk.h | 14 +- drivers/net/ena/ena_ethdev.c | 21 +- drivers/net/ena/ena_ethdev.h | 7 +- drivers/net/enic/enic.h | 6 +- drivers/net/enic/enic_compat.h | 1 - drivers/net/enic/enic_main.c | 17 +- drivers/net/enic/enic_rxtx.c | 14 +- drivers/net/enic/enic_rxtx_vec_avx2.c | 4 +- drivers/net/failsafe/failsafe_ops.c | 12 +- drivers/net/failsafe/failsafe_private.h | 29 +- drivers/net/failsafe/failsafe_rxtx.c | 2 +- drivers/net/hinic/base/hinic_compat.h | 2 +- drivers/net/hinic/base/hinic_pmd_hwdev.c | 24 +- drivers/net/hinic/base/hinic_pmd_hwdev.h | 4 +- drivers/net/nbl/nbl_hw/nbl_resource.h | 1 - drivers/net/netvsc/hn_rndis.c | 28 +- drivers/net/netvsc/hn_rxtx.c | 12 +- drivers/net/netvsc/hn_var.h | 6 +- drivers/net/pfe/pfe_ethdev.c | 32 +- drivers/net/sfc/sfc.c | 9 +- drivers/net/sfc/sfc.h | 4 +- drivers/net/sfc/sfc_port.c | 7 +- drivers/net/sfc/sfc_stats.h | 2 +- drivers/net/txgbe/base/txgbe_mng.c | 4 +- drivers/net/txgbe/base/txgbe_type.h | 2 +- drivers/net/vhost/rte_eth_vhost.c | 92 +- drivers/vdpa/ifc/ifcvf_vdpa.c | 37 +- lib/bpf/bpf_exec.c | 13 +- lib/eal/arm/include/rte_atomic_32.h | 4 - lib/eal/arm/include/rte_atomic_64.h | 4 - lib/eal/include/generic/rte_atomic.h | 928 ------------------ lib/eal/loongarch/include/rte_atomic.h | 4 - lib/eal/ppc/include/rte_atomic.h | 175 ---- lib/eal/riscv/include/rte_atomic.h | 4 - lib/eal/x86/include/meson.build | 1 - lib/eal/x86/include/rte_atomic.h | 187 +--- lib/eal/x86/include/rte_atomic_32.h | 212 ---- lib/eal/x86/include/rte_atomic_64.h | 157 --- 66 files changed, 416 insertions(+), 2544 deletions(-) delete mode 100644 lib/eal/x86/include/rte_atomic_32.h
Signature · 1 line
2.53.0
PATCH v7 1/24 bpf: use C11 atomics in BPF_ST_ATOMIC_REG
The BPF_ST_ATOMIC_REG macro generated code with deprecated rte_atomicNN_add and rte_atomicNN_exchange.
Replace this with the equivalent rte_stdatomic definitions. Use memory order seq_cst to preserve the previous behavior of rte_atomicNN_add() / rte_atomicNN_exchange() and matches the Linux kernel BPF interpreter for these opcodes.
--- lib/bpf/bpf_exec.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
lib/bpf/bpf_exec.c +7 -6
@@ -11,6 +11,7 @@#include <rte_debug.h> #include <rte_byteorder.h> #include <rte_errno.h> +#include <rte_stdatomic.h> #include "bpf_impl.h"
@@ -66,16 +67,16 @@ (type)(reg)[(ins)->src_reg])#define BPF_ST_ATOMIC_REG (reg, ins, tp) do { \ + RTE_ATOMIC(uint##tp##_t) *dst = (RTE_ATOMIC(uint##tp##_t) *) \ + (uintptr_t)((reg)[(ins)->dst_reg] + (ins)->off); \ switch (ins->imm) { \ case BPF_ATOMIC_ADD: \ - rte_atomic##tp##_add((rte_atomic##tp##_t *) \ - (uintptr_t)((reg)[(ins)->dst_reg] + (ins)->off), \ - (reg)[(ins)->src_reg]); \ + rte_atomic_fetch_add_explicit(dst, \ + (reg)[(ins)->src_reg], rte_memory_order_seq_cst); \ break; \ case BPF_ATOMIC_XCHG: \ - (reg)[(ins)->src_reg] = rte_atomic##tp##_exchange((uint##tp##_t *) \ - (uintptr_t)((reg)[(ins)->dst_reg] + (ins)->off), \ - (reg)[(ins)->src_reg]); \ + (reg)[(ins)->src_reg] = rte_atomic_exchange_explicit(dst, \ + (reg)[(ins)->src_reg], rte_memory_order_seq_cst); \ break; \ default: \/* this should be caught by validator and never reach here */ \
Signature · 1 line
2.53.0
PATCH v7 2/24 net/bonding: use stdatomic
In reply to Stephen HemmingerThe old rte_atomic16 and rte_atomic64 functions are deprecated. Replace with rte_stdatomic for managing warning and timer flags.
--- drivers/net/bonding/eth_bond_8023ad_private.h | 6 ++-- drivers/net/bonding/rte_eth_bond_8023ad.c | 35 ++++++++----------- 2 files changed, 17 insertions(+), 24 deletions(-)
drivers/net/bonding/eth_bond_8023ad_private.h +3 -3
@@ -9,7 +9,7 @@#include <rte_ether.h> #include <rte_byteorder.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_flow.h> #include "rte_eth_bond_8023ad.h"
@@ -140,10 +140,10 @@ struct port {/** Timer which is also used as mutex. If is 0 (not running) RX marker * packet might be responded. Otherwise shall be dropped. It is zeroed in * mode 4 callback function after expire. */ -volatile uint64_t rx_marker_timer; +RTE_ATOMIC (uint64_t ) rx_marker_timer;uint64_t warning_timer; -volatile uint16_t warnings_to_show; +RTE_ATOMIC (uint16_t ) warnings_to_show;/** Memory pool used to allocate slow queues */ struct rte_mempool *slow_pool;
drivers/net/bonding/rte_eth_bond_8023ad.c +14 -21
@@ -171,27 +171,17 @@ timer_is_running(uint64_t *timer)static void set_warning_flags (struct port *port,uint16_t flags) { -int retval; -uint16_t old; -uint16_t new_flag =0 ; - -do { - old = port->warnings_to_show; - new_flag = old | flags; - retval =rte_atomic16_cmpset (&port->warnings_to_show, old, new_flag); - }while (unlikely (retval ==0 )); +rte_atomic_fetch_or_explicit (&port->warnings_to_show, flags, rte_memory_order_relaxed); }static void show_warnings (uint16_t member_id) {struct port *port = &bond_mode_8023ad_ports[member_id]; -uint8_t warnings; - -do { - warnings = port->warnings_to_show; - }while (rte_atomic16_cmpset (&port->warnings_to_show, warnings,0 ) ==0 ); +uint16_t warnings; + warnings =rte_atomic_exchange_explicit (&port->warnings_to_show,0 , + rte_memory_order_relaxed);if (!warnings)return ;
@@ -1335,7 +1325,6 @@ bond_mode_8023ad_handle_slow_pkt(struct bond_dev_private *internals,struct port *port = &bond_mode_8023ad_ports[member_id];struct marker_header *m_hdr;uint64_t marker_timer, old_marker_timer; -int retval;uint8_t wrn, subtype;/* If packet is a marker, we send response now by reusing given packet * and update only source MAC, destination MAC is multicast so don't
@@ -1352,17 +1341,19 @@ bond_mode_8023ad_handle_slow_pkt(struct bond_dev_private *internals, }/* Setup marker timer. Do it in loop in case concurrent access. */ + old_marker_timer =rte_atomic_load_explicit (&port->rx_marker_timer, + rte_memory_order_acquire);do { - old_marker_timer = port->rx_marker_timer;if (!timer_is_expired (&old_marker_timer)) { wrn =WRN_RX_MARKER_TO_FAST ; goto free_out; }timer_set (&marker_timer, mode4->rx_marker_timeout); - retval =rte_atomic64_cmpset (&port->rx_marker_timer, - old_marker_timer, marker_timer); - }while (unlikely (retval ==0 )); + + }while (!rte_atomic_compare_exchange_weak_explicit (&port->rx_marker_timer, + &old_marker_timer, marker_timer, + rte_memory_order_release, rte_memory_order_acquire)); m_hdr->marker.tlv_type_marker =MARKER_TLV_TYPE_RESP ;rte_eth_macaddr_get (member_id, &m_hdr->eth_hdr.src_addr);
@@ -1370,7 +1361,8 @@ bond_mode_8023ad_handle_slow_pkt(struct bond_dev_private *internals,if (internals->mode4.dedicated_queues.enabled ==0 ) {if (rte_ring_enqueue (port->tx_ring, pkt) !=0 ) {/* reset timer */ - port->rx_marker_timer =0 ; +rte_atomic_store_explicit (&port->rx_marker_timer,0 , + rte_memory_order_release); wrn =WRN_TX_QUEUE_FULL ; goto free_out; }
@@ -1384,7 +1376,8 @@ bond_mode_8023ad_handle_slow_pkt(struct bond_dev_private *internals, &pkt, tx_count);if (tx_count !=1 ) {/* reset timer */ - port->rx_marker_timer =0 ; +rte_atomic_store_explicit (&port->rx_marker_timer,0 , + rte_memory_order_release); wrn =WRN_TX_QUEUE_FULL ; goto free_out; }
Signature · 1 line
2.53.0
PATCH v7 3/24 net/nbl: remove unused rte_atomic16 field
In reply to Stephen HemmingerThe tx_current_queue was defined as rte_atomic16_t which is deprecated. Remove it since it was never used.
--- drivers/net/nbl/nbl_hw/nbl_resource.h | 1 - 1 file changed, 1 deletion(-)
drivers/net/nbl/nbl_hw/nbl_resource.h +0 -1
@@ -225,7 +225,6 @@ struct nbl_res_info {u16 base_qid;u16 lcore_max;u16 *pf_qid_to_lcore_id; -rte_atomic16_t tx_current_queue; };struct nbl_resource_mgt {
Signature · 1 line
2.53.0
PATCH v7 4/24 net/ena: replace use of rte_atomicNN
In reply to Stephen HemmingerConvert the legacy rte_atomicNN operations to stdatomic.
* Remove variable ena_alloc_cnt is defined by not used. It is a leftover from previous memzone naming scheme.
* Convert the legacy rte_atomic32_t and rte_atomic32_{inc,dec,set,read} macros to C11 stdatomic equivalents.
Memory ordering is kept at seq_cst,
matching the implicit ordering of the legacy API.
* Do not use rte_atomic for statistics
The DPDK PMD model is that statistics do not have to be exact in face of contention.
--- drivers/net/ena/base/ena_plat_dpdk.h | 14 +++++++++----- drivers/net/ena/ena_ethdev.c | 21 ++++++--------------- drivers/net/ena/ena_ethdev.h | 7 +++---- 3 files changed, 18 insertions(+), 24 deletions(-)
drivers/net/ena/base/ena_plat_dpdk.h +9 -5
@@ -40,7 +40,7 @@ typedef uint64_t dma_addr_t;#endif #define ENA_PRIu64 PRIu64 -#define ena_atomic32_t rte_atomic32_t +typedef RTE_ATOMIC (int32_t )ena_atomic32_t ;#define ena_mem_handle_t const struct rte_memzone *#define SZ_256 (256U)
@@ -267,10 +267,14 @@ ena_mem_alloc_coherent(struct rte_eth_dev_data *data, size_t size,#define ENA_REG_READ32 (bus, reg) \ __extension__ ({ (void)(bus); rte_read32_relaxed((reg)); }) -#define ATOMIC32_INC (i32_ptr) rte_atomic32_inc(i32_ptr) -#define ATOMIC32_DEC (i32_ptr) rte_atomic32_dec(i32_ptr) -#define ATOMIC32_SET (i32_ptr, val) rte_atomic32_set(i32_ptr, val) -#define ATOMIC32_READ (i32_ptr) rte_atomic32_read(i32_ptr) +#define ATOMIC32_INC (i32_ptr) \ + rte_atomic_fetch_add_explicit((i32_ptr), 1, rte_memory_order_seq_cst) +#define ATOMIC32_DEC (i32_ptr) \ + rte_atomic_fetch_sub_explicit((i32_ptr), 1, rte_memory_order_seq_cst) +#define ATOMIC32_SET (i32_ptr, val) \ + rte_atomic_store_explicit((i32_ptr), (val), rte_memory_order_seq_cst) +#define ATOMIC32_READ (i32_ptr) \ + rte_atomic_load_explicit((i32_ptr), rte_memory_order_seq_cst)#define msleep (x) rte_delay_us(x * 1000)#define udelay (x) rte_delay_us(x)
drivers/net/ena/ena_ethdev.c +6 -15
@@ -121,12 +121,6 @@ struct ena_stats {*/ #define ENA_DEVARG_ENABLE_FRAG_BYPASS "enable_frag_bypass" -/* -* Each rte_memzone should have unique name. -* To satisfy it, count number of allocation and add it to name. -*/ -rte_atomic64_t ena_alloc_cnt; -static const struct ena_stats ena_stats_global_strings[] = {ENA_STAT_GLOBAL_ENTRY (wd_expired),ENA_STAT_GLOBAL_ENTRY (dev_start),
@@ -1249,10 +1243,7 @@ static void ena_stats_restart(struct rte_eth_dev *dev) {struct ena_adapter *adapter = dev->data->dev_private; -rte_atomic64_init (&adapter->drv_stats->ierrors); -rte_atomic64_init (&adapter->drv_stats->oerrors); -rte_atomic64_init (&adapter->drv_stats->rx_nombuf); - adapter->drv_stats->rx_drops =0 ; +memset (adapter->drv_stats,0 ,sizeof (struct ena_driver_stats )); } static int ena_stats_get(struct rte_eth_dev *dev,
@@ -1289,9 +1280,9 @@ static int ena_stats_get(struct rte_eth_dev *dev,/* Driver related stats */ stats->imissed = adapter->drv_stats->rx_drops; - stats->ierrors =rte_atomic64_read (&adapter->drv_stats->ierrors); - stats->oerrors =rte_atomic64_read (&adapter->drv_stats->oerrors); - stats->rx_nombuf =rte_atomic64_read (&adapter->drv_stats->rx_nombuf); + stats->ierrors = adapter->drv_stats->ierrors; + stats->oerrors = adapter->drv_stats->oerrors; + stats->rx_nombuf = adapter->drv_stats->rx_nombuf;/* Queue statistics */ if (qstats) {
@@ -1887,7 +1878,7 @@ static int ena_populate_rx_queue(struct ena_ring *rxq, unsigned int count)/* get resources for incoming packets */ rc =rte_pktmbuf_alloc_bulk (rxq->mb_pool, mbufs, count);if (unlikely (rc <0 )) { -rte_atomic64_inc (&rxq->adapter->drv_stats->rx_nombuf); + ++rxq->adapter->drv_stats->rx_nombuf; ++rxq->rx_stats.mbuf_alloc_fail;PMD_RX_LOG_LINE (DEBUG ,"There are not enough free buffers" );return 0 ;
@@ -3014,7 +3005,7 @@ static uint16_t eth_ena_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,if (unlikely (mbuf->ol_flags & (RTE_MBUF_F_RX_IP_CKSUM_BAD |RTE_MBUF_F_RX_L4_CKSUM_BAD ))) -rte_atomic64_inc (&rx_ring->adapter->drv_stats->ierrors); + ++rx_ring->adapter->drv_stats->ierrors; rx_pkts[completed] = mbuf; rx_ring->rx_stats.bytes += mbuf->pkt_len;
drivers/net/ena/ena_ethdev.h +3 -4
@@ -6,7 +6,6 @@#ifndef _ENA_ETHDEV_H_#define _ENA_ETHDEV_H_ -#include <rte_atomic.h> #include <rte_ether.h> #include <ethdev_driver.h> #include <ethdev_pci.h>
@@ -225,9 +224,9 @@ enum ena_adapter_state { };struct ena_driver_stats { -rte_atomic64_t ierrors; -rte_atomic64_t oerrors; -rte_atomic64_t rx_nombuf; +u64 ierrors; +u64 oerrors; +u64 rx_nombuf;u64 rx_drops; };
Signature · 1 line
2.53.0
PATCH v7 5/24 net/failsafe: convert to stdatomic
In reply to Stephen HemmingerThe functions rte_atomic64 are deprecated, convert this code to use stdatomic for reference count. Use the memory order implied by naming P/V.
No need for initialization since refcnt is in space allocated with rte_zmalloc().
--- drivers/net/failsafe/failsafe_ops.c | 12 +++++----- drivers/net/failsafe/failsafe_private.h | 29 ++++++++++++++----------- drivers/net/failsafe/failsafe_rxtx.c | 2 +- 3 files changed, 22 insertions(+), 21 deletions(-)
drivers/net/failsafe/failsafe_ops.c +5 -7
@@ -11,7 +11,7 @@#endif #include <rte_debug.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <ethdev_driver.h> #include <rte_malloc.h> #include <rte_flow.h>
@@ -440,14 +440,13 @@ fs_rx_queue_setup(struct rte_eth_dev *dev, } rxq =rte_zmalloc (NULL ,sizeof (*rxq) + -sizeof (rte_atomic64_t) *PRIV (dev)->subs_tail, +sizeof (uint64_t ) *PRIV (dev)->subs_tail,RTE_CACHE_LINE_SIZE );if (rxq ==NULL ) {fs_unlock (dev,0 );return -ENOMEM ; } - FOREACH_SUBDEV(sdev, i, dev) -rte_atomic64_init (&rxq->refcnt[i]); + rxq->qid = rx_queue_id; rxq->socket_id = socket_id; rxq->info.mp = mb_pool;
@@ -617,14 +616,13 @@ fs_tx_queue_setup(struct rte_eth_dev *dev, } txq =rte_zmalloc ("ethdev TX queue" ,sizeof (*txq) + -sizeof (rte_atomic64_t) *PRIV (dev)->subs_tail, +sizeof (uint64_t ) *PRIV (dev)->subs_tail,RTE_CACHE_LINE_SIZE );if (txq ==NULL ) {fs_unlock (dev,0 );return -ENOMEM ; } - FOREACH_SUBDEV(sdev, i, dev) -rte_atomic64_init (&txq->refcnt[i]); + txq->qid = tx_queue_id; txq->socket_id = socket_id; txq->info.conf = *tx_conf;
drivers/net/failsafe/failsafe_private.h +16 -13
@@ -10,7 +10,7 @@#include <sys/queue.h> #include <pthread.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <dev_driver.h> #include <ethdev_driver.h> #include <rte_devargs.h>
@@ -75,7 +75,7 @@ struct rxq {int event_fd; unsigned int enable_events:1;struct rte_eth_rxq_info info; -rte_atomic64_t refcnt[]; +RTE_ATOMIC (uint64_t ) refcnt[]; };struct txq {
@@ -83,7 +83,7 @@ struct txq {uint16_t qid;unsigned int socket_id;struct rte_eth_txq_info info; -rte_atomic64_t refcnt[]; +RTE_ATOMIC (uint64_t ) refcnt[]; };struct rte_flow {
@@ -320,33 +320,36 @@ extern int failsafe_mac_from_arg;*/ /** -* a: (rte_atomic64_t) +* a: _Atomic uint64_t */ #define FS_ATOMIC_P (a) \ - rte_atomic64_set(&(a), 1) + rte_atomic_exchange_explicit(&(a), 1, rte_memory_order_acquire)/** -* a: (rte_atomic64_t) +* a: _Atomic uint64_t */ #define FS_ATOMIC_V (a) \ - rte_atomic64_set(&(a), 0) + rte_atomic_store_explicit(&(a), 0, rte_memory_order_release)/** * s: (struct sub_device *) * i: uint16_t qid */ #define FS_ATOMIC_RX (s, i) \ - rte_atomic64_read( \ - &((struct rxq *) \ - (fs_dev(s)->data->rx_queues[i]))->refcnt[(s)->sid]) + rte_atomic_load_explicit( \ + &((struct rxq *) \ + (fs_dev(s)->data->rx_queues[i]))->refcnt[(s)->sid], \ + rte_memory_order_seq_cst) +/** * s: (struct sub_device *) * i: uint16_t qid */ #define FS_ATOMIC_TX (s, i) \ - rte_atomic64_read( \ - &((struct txq *) \ - (fs_dev(s)->data->tx_queues[i]))->refcnt[(s)->sid]) + rte_atomic_load_explicit( \ + &((struct txq *) \ + (fs_dev(s)->data->tx_queues[i]))->refcnt[(s)->sid], \ + rte_memory_order_seq_cst)#ifdef RTE_EXEC_ENV_FREEBSD #define FS_THREADID_TYPE void*
drivers/net/failsafe/failsafe_rxtx.c +1 -1
@@ -3,7 +3,7 @@* Copyright 2017 Mellanox Technologies, Ltd */ -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_debug.h> #include <rte_mbuf.h> #include <ethdev_driver.h>
Signature · 1 line
2.53.0
PATCH v7 6/24 net/enic: do not use deprecated rte_atomic64
In reply to Stephen HemmingerThe rte_atomic64 datatype and functions are deprecated. This driver was only using it for error statistics where atomic is not necessary. The DPDK PMD model is that statistics do not have to be exact in face of contention.
--- drivers/net/enic/enic.h | 6 +++--- drivers/net/enic/enic_compat.h | 1 - drivers/net/enic/enic_main.c | 17 +++++++---------- drivers/net/enic/enic_rxtx.c | 14 ++++++-------- drivers/net/enic/enic_rxtx_vec_avx2.c | 4 ++-- 5 files changed, 18 insertions(+), 24 deletions(-)
drivers/net/enic/enic.h +3 -3
@@ -59,9 +59,9 @@#define ENICPMD_RXQ_INTR_OFFSET 1struct enic_soft_stats { -rte_atomic64_t rx_nombuf; -rte_atomic64_t rx_packet_errors; -rte_atomic64_t tx_oversized; +uint64_t rx_nombuf; +uint64_t rx_packet_errors; +uint64_t tx_oversized; };struct enic_memzone_entry {
drivers/net/enic/enic_compat.h +0 -1
@@ -9,7 +9,6 @@#include <stdio.h> #include <unistd.h> -#include <rte_atomic.h> #include <rte_malloc.h> #include <rte_log.h> #include <rte_io.h>
drivers/net/enic/enic_main.c +7 -10
@@ -83,17 +83,15 @@ static void enic_log_q_error(struct enic *enic)static void enic_clear_soft_stats (struct enic *enic) {struct enic_soft_stats *soft_stats = &enic->soft_stats; -rte_atomic64_clear (&soft_stats->rx_nombuf); -rte_atomic64_clear (&soft_stats->rx_packet_errors); -rte_atomic64_clear (&soft_stats->tx_oversized); + +memset (soft_stats,0 ,sizeof (*soft_stats)); }static void enic_init_soft_stats (struct enic *enic) {struct enic_soft_stats *soft_stats = &enic->soft_stats; -rte_atomic64_init (&soft_stats->rx_nombuf); -rte_atomic64_init (&soft_stats->rx_packet_errors); -rte_atomic64_init (&soft_stats->tx_oversized); + +memset (soft_stats,0 ,sizeof (*soft_stats));enic_clear_soft_stats (enic); }
@@ -132,7 +130,7 @@ int enic_dev_stats_get(struct enic *enic, struct rte_eth_stats *r_stats,* counted in ibytes even though truncated packets are dropped * which can make ibytes be slightly higher than it should be. */ - rx_packet_errors =rte_atomic64_read (&soft_stats->rx_packet_errors); + rx_packet_errors = soft_stats->rx_packet_errors; rx_truncated = rx_packet_errors - stats->rx.rx_errors; r_stats->ipackets = stats->rx.rx_frames_ok - rx_truncated;
@@ -142,12 +140,11 @@ int enic_dev_stats_get(struct enic *enic, struct rte_eth_stats *r_stats, r_stats->obytes = stats->tx.tx_bytes_ok; r_stats->ierrors = stats->rx.rx_errors + stats->rx.rx_drop; - r_stats->oerrors = stats->tx.tx_errors - +rte_atomic64_read (&soft_stats->tx_oversized); + r_stats->oerrors = stats->tx.tx_errors + soft_stats->tx_oversized; r_stats->imissed = stats->rx.rx_no_bufs + rx_truncated; - r_stats->rx_nombuf =rte_atomic64_read (&soft_stats->rx_nombuf); + r_stats->rx_nombuf = soft_stats->rx_nombuf;return 0 ; }
drivers/net/enic/enic_rxtx.c +6 -8
@@ -112,7 +112,7 @@ enic_recv_pkts_common(void *rx_queue, struct rte_mbuf **rx_pkts,/* allocate a new mbuf */ nmb =rte_mbuf_raw_alloc (rq->mp);if (nmb ==NULL ) { -rte_atomic64_inc (&enic->soft_stats.rx_nombuf); + ++enic->soft_stats.rx_nombuf;break ; }
@@ -185,7 +185,7 @@ enic_recv_pkts_common(void *rx_queue, struct rte_mbuf **rx_pkts, }if (unlikely (packet_error)) {rte_pktmbuf_free (first_seg); -rte_atomic64_inc (&enic->soft_stats.rx_packet_errors); + ++enic->soft_stats.rx_packet_errors;continue ; }
@@ -303,7 +303,7 @@ enic_noscatter_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,if (unlikely (cqd->bytes_written_flags &CQ_ENET_RQ_DESC_FLAGS_TRUNCATED )) {rte_pktmbuf_free (*rxmb++); -rte_atomic64_inc (&enic->soft_stats.rx_packet_errors); + ++enic->soft_stats.rx_packet_errors; cqd++;continue ; }
@@ -505,14 +505,12 @@ uint16_t enic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,uint8_t offload_mode;uint16_t header_len;uint64_t tso; -rte_atomic64_t *tx_oversized;enic_cleanup_wq (enic, wq); wq_desc_avail =vnic_wq_desc_avail (wq); head_idx = wq->head_idx; desc_count = wq->ring.desc_count; ol_flags_mask =RTE_MBUF_F_TX_VLAN |RTE_MBUF_F_TX_IP_CKSUM |RTE_MBUF_F_TX_L4_MASK ; - tx_oversized = &enic->soft_stats.tx_oversized; nb_pkts =RTE_MIN (nb_pkts,ENIC_TX_XMIT_MAX );
@@ -527,7 +525,7 @@ uint16_t enic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,/* drop packet if it's too big to send */ if (unlikely (!tso && pkt_len >ENIC_TX_MAX_PKT_SIZE )) {rte_pktmbuf_free (tx_pkt); -rte_atomic64_inc (tx_oversized); + ++enic->soft_stats.tx_oversized;continue ; }
@@ -558,7 +556,7 @@ uint16_t enic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,if (unlikely (header_len ==0 || ((tx_pkt->tso_segsz + header_len) >ENIC_TX_MAX_PKT_SIZE ))) {rte_pktmbuf_free (tx_pkt); -rte_atomic64_inc (tx_oversized); + ++enic->soft_stats.tx_oversized;continue ; }
@@ -681,7 +679,7 @@ static void enqueue_simple_pkts(struct rte_mbuf **pkts,*/ if (unlikely (p->pkt_len >ENIC_TX_MAX_PKT_SIZE )) { desc->length =ENIC_TX_MAX_PKT_SIZE ; -rte_atomic64_inc (&enic->soft_stats.tx_oversized); + ++enic->soft_stats.tx_oversized; } desc++; }
drivers/net/enic/enic_rxtx_vec_avx2.c +2 -2
@@ -81,7 +81,7 @@ enic_noscatter_vec_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,if (unlikely (cqd->bytes_written_flags &CQ_ENET_RQ_DESC_FLAGS_TRUNCATED )) {rte_pktmbuf_free (*rxmb++); -rte_atomic64_inc (&enic->soft_stats.rx_packet_errors); + ++enic->soft_stats.rx_packet_errors; }else { *rx++ =rx_one (cqd, *rxmb++, enic); }
@@ -761,7 +761,7 @@ enic_noscatter_vec_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,if (unlikely (cqd->bytes_written_flags &CQ_ENET_RQ_DESC_FLAGS_TRUNCATED )) {rte_pktmbuf_free (*rxmb++); -rte_atomic64_inc (&enic->soft_stats.rx_packet_errors); + ++enic->soft_stats.rx_packet_errors; }else { *rx++ =rx_one (cqd, *rxmb++, enic); }
Signature · 1 line
2.53.0
PATCH v7 7/24 net/pfe: use ethdev linkstatus helpers
In reply to Stephen HemmingerRather than open coding with deprecated rte_atomic64, use the existing ethdev helpers to get and set link status.
--- drivers/net/pfe/pfe_ethdev.c | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-)
drivers/net/pfe/pfe_ethdev.c +2 -30
@@ -531,34 +531,6 @@ pfe_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)return NULL ; } -static inline int -pfe_eth_atomic_read_link_status (struct rte_eth_dev *dev, -struct rte_eth_link *link) -{ -struct rte_eth_link *dst = link; -struct rte_eth_link *src = &dev->data->dev_link; - -if (rte_atomic64_cmpset ((uint64_t *)dst, *(uint64_t *)dst, - *(uint64_t *)src) ==0 ) -return -1 ; - -return 0 ; -} - -static inline int -pfe_eth_atomic_write_link_status (struct rte_eth_dev *dev, -struct rte_eth_link *link) -{ -struct rte_eth_link *dst = &dev->data->dev_link; -struct rte_eth_link *src = link; - -if (rte_atomic64_cmpset ((uint64_t *)dst, *(uint64_t *)dst, - *(uint64_t *)src) ==0 ) -return -1 ; - -return 0 ; -} -static int pfe_eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused) {
@@ -570,7 +542,7 @@ pfe_eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused)memset (&old,0 ,sizeof (old));memset (&link,0 ,sizeof (struct rte_eth_link )); -pfe_eth_atomic_read_link_status (dev, &old); +rte_eth_linkstatus_get (dev, &old);/* Read from PFE CDEV, status of link, if file was successfully * opened.
@@ -601,7 +573,7 @@ pfe_eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused) link.link_duplex =RTE_ETH_LINK_FULL_DUPLEX ; link.link_autoneg =RTE_ETH_LINK_AUTONEG ; -pfe_eth_atomic_write_link_status (dev, &link); +rte_eth_linkstatus_set (dev, &link);PFE_PMD_INFO ("Port (%d) link is %s" , dev->data->port_id, link.link_status ?"up" :"down" );
Signature · 1 line
2.53.0
PATCH v7 8/24 net/sfc: replace rte_atomic with stdatomic
In reply to Stephen HemmingerThe rte_atomicNN functions are deprecated and need to be replaced. Use stdatomic for the restart required flag.
Use existing ethdev helper to set link status.
--- drivers/net/sfc/sfc.c | 9 +++++---- drivers/net/sfc/sfc.h | 4 ++-- drivers/net/sfc/sfc_port.c | 7 +------ drivers/net/sfc/sfc_stats.h | 2 +- 4 files changed, 9 insertions(+), 13 deletions(-)
drivers/net/sfc/sfc.c +5 -4
@@ -670,8 +670,8 @@ sfc_restart_if_required(void *arg)struct sfc_adapter *sa = arg;/* If restart is scheduled, clear the flag and do it */ -if (rte_atomic32_cmpset ((volatile uint32_t *)&sa->restart_required, -1 ,0 )) { +if (rte_atomic_exchange_explicit (&sa->restart_required, false, + rte_memory_order_seq_cst)) {sfc_adapter_lock (sa);if (sa->state ==SFC_ETHDEV_STARTED ) (void )sfc_restart (sa);
@@ -685,7 +685,8 @@ sfc_schedule_restart(struct sfc_adapter *sa)int rc;/* Schedule restart alarm if it is not scheduled yet */ -if (!rte_atomic32_test_and_set (&sa->restart_required)) +if (rte_atomic_exchange_explicit (&sa->restart_required, true, + rte_memory_order_seq_cst))return ; rc =rte_eal_alarm_set (1 , sfc_restart_if_required, sa);
@@ -1292,7 +1293,7 @@ sfc_probe(struct sfc_adapter *sa)SFC_ASSERT (sfc_adapter_is_locked (sa)); sa->socket_id =rte_socket_id (); -rte_atomic32_init (&sa->restart_required); + sa->restart_required = false;sfc_log_init (sa,"get family" ); rc =sfc_efx_family (pci_dev, &mem_ebrp, &sa->family);
drivers/net/sfc/sfc.h +2 -2
@@ -17,7 +17,7 @@#include <ethdev_driver.h> #include <rte_kvargs.h> #include <rte_spinlock.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include "efx.h"
@@ -239,7 +239,7 @@ struct sfc_adapter {efx_family_t family;efx_nic_t *nic;rte_spinlock_t nic_lock; -rte_atomic32_t restart_required; +RTE_ATOMIC (bool ) restart_required;struct sfc_efx_mcdi mcdi;struct sfc_sriov sriov;
drivers/net/sfc/sfc_port.c +1 -6
@@ -121,7 +121,6 @@ sfc_port_reset_mac_stats(struct sfc_adapter *sa)static int sfc_port_init_dev_link (struct sfc_adapter *sa) { -struct rte_eth_link *dev_link = &sa->eth_dev->data->dev_link;int rc;efx_link_mode_t link_mode;struct rte_eth_link current_link;
@@ -132,11 +131,7 @@ sfc_port_init_dev_link(struct sfc_adapter *sa)sfc_port_link_mode_to_info (link_mode, sa->port.phy_adv_cap, ¤t_link); - -EFX_STATIC_ASSERT (sizeof (*dev_link) ==sizeof (rte_atomic64_t)); -rte_atomic64_set ((rte_atomic64_t *)dev_link, - *(uint64_t *)¤t_link); - +rte_eth_linkstatus_set (sa->eth_dev, ¤t_link);return 0 ; }
drivers/net/sfc/sfc_stats.h +1 -1
@@ -12,7 +12,7 @@#include <stdint.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include "sfc_tweak.h"
Signature · 1 line
2.53.0
PATCH v7 9/24 crypto/ccp: replace use of rte_atomic64 with stdatomic
In reply to Stephen HemmingerThe rte_atomicNN functions are deprecated. Replace the free count with stdatomic.
--- drivers/crypto/ccp/ccp_crypto.c | 11 +++++++---- drivers/crypto/ccp/ccp_crypto.h | 2 +- drivers/crypto/ccp/ccp_dev.c | 10 ++++++---- drivers/crypto/ccp/ccp_dev.h | 4 ++-- 4 files changed, 16 insertions(+), 11 deletions(-)
drivers/crypto/ccp/ccp_crypto.c +7 -4
@@ -2683,7 +2683,8 @@ process_ops_to_enqueue(struct ccp_qp *qp, b_info->cmd_q = cmd_q; b_info->lsb_buf_phys = (phys_addr_t )rte_mem_virt2iova ((void *)b_info->lsb_buf); -rte_atomic64_sub (&b_info->cmd_q->free_slots, slots_req); +rte_atomic_fetch_sub_explicit (&b_info->cmd_q->free_slots, slots_req, + rte_memory_order_seq_cst); b_info->head_offset = (uint32_t )(cmd_q->qbase_phys_addr + cmd_q->qidx *Q_DESC_SIZE );
@@ -2729,8 +2730,9 @@ process_ops_to_enqueue(struct ccp_qp *qp, result =-1 ; }if (unlikely (result <0 )) { -rte_atomic64_add (&b_info->cmd_q->free_slots, - (slots_req - b_info->desccnt)); +rte_atomic_fetch_add_explicit (&b_info->cmd_q->free_slots, + slots_req - b_info->desccnt, + rte_memory_order_seq_cst);break ; } b_info->op[i] = op[i];
@@ -2914,7 +2916,8 @@ process_ops_to_dequeue(struct ccp_qp *qp, success: *total_nb_ops = b_info->total_nb_ops; nb_ops =ccp_prepare_ops (qp, op, b_info, nb_ops); -rte_atomic64_add (&b_info->cmd_q->free_slots, b_info->desccnt); +rte_atomic_fetch_add_explicit (&b_info->cmd_q->free_slots, b_info->desccnt, + rte_memory_order_seq_cst); b_info->desccnt =0 ;if (b_info->opcnt >0 ) { qp->b_info = b_info;
drivers/crypto/ccp/ccp_crypto.h +1 -1
@@ -10,7 +10,7 @@#include <stdint.h> #include <string.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_byteorder.h> #include <rte_io.h> #include <rte_pci.h>
drivers/crypto/ccp/ccp_dev.c +6 -4
@@ -47,14 +47,15 @@ ccp_allot_queue(struct rte_cryptodev *cdev, int slot_req) priv->last_dev = dev;if (dev->qidx >= dev->cmd_q_count) dev->qidx =0 ; - ret =rte_atomic64_read (&dev->cmd_q[dev->qidx].free_slots); + ret =rte_atomic_load_explicit (&dev->cmd_q[dev->qidx].free_slots, rte_memory_order_relaxed);if (ret >= slot_req)return &dev->cmd_q[dev->qidx];for (i =0 ; i < dev->cmd_q_count; i++) { dev->qidx++;if (dev->qidx >= dev->cmd_q_count) dev->qidx =0 ; - ret =rte_atomic64_read (&dev->cmd_q[dev->qidx].free_slots); + ret =rte_atomic_load_explicit (&dev->cmd_q[dev->qidx].free_slots, + rte_memory_order_relaxed);if (ret >= slot_req)return &dev->cmd_q[dev->qidx]; }
@@ -583,8 +584,9 @@ ccp_add_device(struct ccp_device *dev)CCP_LOG_ERR ("queue doesn't have lsb regions" ); cmd_q->lsb =-1 ; -rte_atomic64_init (&cmd_q->free_slots); -rte_atomic64_set (&cmd_q->free_slots, (COMMANDS_PER_QUEUE -1 )); +rte_atomic_store_explicit (&cmd_q->free_slots, +COMMANDS_PER_QUEUE -1 , + rte_memory_order_seq_cst);/* unused slot barrier b/w H&T */ }
drivers/crypto/ccp/ccp_dev.h +2 -2
@@ -11,7 +11,7 @@#include <string.h> #include <bus_pci_driver.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_byteorder.h> #include <rte_io.h> #include <rte_pci.h>
@@ -182,7 +182,7 @@ struct __rte_cache_aligned ccp_queue {struct ccp_device *dev;char memz_name[RTE_MEMZONE_NAMESIZE ]; -rte_atomic64_t free_slots; +RTE_ATOMIC (int64_t ) free_slots;/**< available free slots updated from enq/deq calls */ /* Queue identifier */
Signature · 1 line
2.53.0
PATCH v7 10/24 bus/dpaa: replace rte_atomic16 with stdatomic
In reply to Stephen HemmingerThis is simple inuse flag which can be done with stdatomic exchange logic.
--- drivers/bus/dpaa/base/qbman/qman.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/bus/dpaa/base/qbman/qman.c +6 -3
@@ -11,6 +11,7 @@#include <rte_eventdev.h> #include <rte_byteorder.h> #include <rte_dpaa_logs.h> +#include <rte_stdatomic.h> #include <eal_export.h> #include <dpaa_bits.h>
@@ -683,7 +684,7 @@ qman_init_portal(struct qman_portal *portal,#define MAX_GLOBAL_PORTALS 8static struct qman_portal global_portals[MAX_GLOBAL_PORTALS ]; -static rte_atomic16_t global_portals_used[MAX_GLOBAL_PORTALS ]; +static RTE_ATOMIC (bool ) global_portals_used[MAX_GLOBAL_PORTALS ];struct qman_portal *qman_alloc_global_portal (struct qm_portal_config *q_pcfg)
@@ -691,7 +692,8 @@ qman_alloc_global_portal(struct qm_portal_config *q_pcfg)unsigned int i;for (i =0 ; i <MAX_GLOBAL_PORTALS ; i++) { -if (rte_atomic16_test_and_set (&global_portals_used[i])) { +if (!rte_atomic_exchange_explicit (&global_portals_used[i], true, + rte_memory_order_acquire)) { global_portals[i].config = q_pcfg;return &global_portals[i]; }
@@ -708,7 +710,8 @@ qman_free_global_portal(struct qman_portal *portal)for (i =0 ; i <MAX_GLOBAL_PORTALS ; i++) {if (&global_portals[i] == portal) { -rte_atomic16_clear (&global_portals_used[i]); +rte_atomic_store_explicit (&global_portals_used[i], false, + rte_memory_order_release);return 0 ; } }
Signature · 1 line
2.53.0
PATCH v7 11/24 bus/fslmc: replace rte_atomic16 with stdatomic
In reply to Stephen HemmingerThe rte_atomicNN functions and types are deprecated. The in_use and ref_count flags can be converted to stdatomic.
Note that rte_atomic16_init() and rte_atomic16_clear() were plain stores with no ordering; only test_and_set() and dec() implied a full barrier. Initialization happens before the device is put on the list, so a relaxed store is used there. It is spelled out explicitly because a plain assignment to an RTE_ATOMIC() object is a sequentially consistent store when built with enable_stdatomic=true.
Claiming a device now pairs an acquire compare exchange with a release store on the free path, which is what the test_and_set()/dec() pair was providing.
Also drop the unneeded NULL check in the loop body: TAILQ_FOREACH terminates when the iterator becomes NULL, so var is guaranteed non-NULL inside the loop.
--- drivers/bus/fslmc/portal/dpaa2_hw_dpbp.c | 11 ++++++++--- drivers/bus/fslmc/portal/dpaa2_hw_dpci.c | 11 ++++++++--- drivers/bus/fslmc/portal/dpaa2_hw_dpcon.c | 11 ++++++++--- drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 14 ++++++++++---- drivers/bus/fslmc/portal/dpaa2_hw_pvt.h | 9 +++++---- 5 files changed, 39 insertions(+), 17 deletions(-)
drivers/bus/fslmc/portal/dpaa2_hw_dpbp.c +8 -3
@@ -84,7 +84,7 @@ dpaa2_create_dpbp_device(int vdev_fd __rte_unused, } dpbp_node->dpbp_id = dpbp_id; -rte_atomic16_init (&dpbp_node->in_use); +rte_atomic_store_explicit (&dpbp_node->in_use,0 , rte_memory_order_relaxed);TAILQ_INSERT_TAIL (&dpbp_dev_list, dpbp_node, next);
@@ -103,7 +103,11 @@ struct dpaa2_dpbp_dev *dpaa2_alloc_dpbp_dev(void)/* Get DPBP dev handle from list using index */ TAILQ_FOREACH(dpbp_dev, &dpbp_dev_list, next) { -if (dpbp_dev &&rte_atomic16_test_and_set (&dpbp_dev->in_use)) +uint16_t expected =0 ; + +if (rte_atomic_compare_exchange_strong_explicit (&dpbp_dev->in_use, + &expected,1 , rte_memory_order_acquire, + rte_memory_order_relaxed))break ; }
@@ -118,7 +122,8 @@ void dpaa2_free_dpbp_dev(struct dpaa2_dpbp_dev *dpbp)/* Match DPBP handle and mark it free */ TAILQ_FOREACH(dpbp_dev, &dpbp_dev_list, next) {if (dpbp_dev == dpbp) { -rte_atomic16_dec (&dpbp_dev->in_use); +rte_atomic_store_explicit (&dpbp_dev->in_use,0 , + rte_memory_order_release);return ; } }
drivers/bus/fslmc/portal/dpaa2_hw_dpci.c +8 -3
@@ -135,7 +135,7 @@ rte_dpaa2_create_dpci_device(int vdev_fd __rte_unused, } dpci_node->dpci_id = dpci_id; -rte_atomic16_init (&dpci_node->in_use); +rte_atomic_store_explicit (&dpci_node->in_use,0 , rte_memory_order_relaxed);TAILQ_INSERT_TAIL (&dpci_dev_list, dpci_node, next);
@@ -159,7 +159,11 @@ struct dpaa2_dpci_dev *rte_dpaa2_alloc_dpci_dev(void)/* Get DPCI dev handle from list using index */ TAILQ_FOREACH(dpci_dev, &dpci_dev_list, next) { -if (dpci_dev &&rte_atomic16_test_and_set (&dpci_dev->in_use)) +uint16_t expected =0 ; + +if (rte_atomic_compare_exchange_strong_explicit (&dpci_dev->in_use, + &expected,1 , rte_memory_order_acquire, + rte_memory_order_relaxed))break ; }
@@ -174,7 +178,8 @@ void rte_dpaa2_free_dpci_dev(struct dpaa2_dpci_dev *dpci)/* Match DPCI handle and mark it free */ TAILQ_FOREACH(dpci_dev, &dpci_dev_list, next) {if (dpci_dev == dpci) { -rte_atomic16_dec (&dpci_dev->in_use); +rte_atomic_store_explicit (&dpci_dev->in_use,0 , + rte_memory_order_release);return ; } }
drivers/bus/fslmc/portal/dpaa2_hw_dpcon.c +8 -3
@@ -81,7 +81,7 @@ rte_dpaa2_create_dpcon_device(int dev_fd __rte_unused, dpcon_node->qbman_ch_id = attr.qbman_ch_id; dpcon_node->num_priorities = attr.num_priorities; dpcon_node->dpcon_id = dpcon_id; -rte_atomic16_init (&dpcon_node->in_use); +rte_atomic_store_explicit (&dpcon_node->in_use,0 , rte_memory_order_relaxed);TAILQ_INSERT_TAIL (&dpcon_dev_list, dpcon_node, next);
@@ -95,7 +95,11 @@ struct dpaa2_dpcon_dev *rte_dpaa2_alloc_dpcon_dev(void)/* Get DPCON dev handle from list using index */ TAILQ_FOREACH(dpcon_dev, &dpcon_dev_list, next) { -if (dpcon_dev &&rte_atomic16_test_and_set (&dpcon_dev->in_use)) +uint16_t expected =0 ; + +if (rte_atomic_compare_exchange_strong_explicit (&dpcon_dev->in_use, + &expected,1 , rte_memory_order_acquire, + rte_memory_order_relaxed))break ; }
@@ -110,7 +114,8 @@ void rte_dpaa2_free_dpcon_dev(struct dpaa2_dpcon_dev *dpcon)/* Match DPCON handle and mark it free */ TAILQ_FOREACH(dpcon_dev, &dpcon_dev_list, next) {if (dpcon_dev == dpcon) { -rte_atomic16_dec (&dpcon_dev->in_use); +rte_atomic_store_explicit (&dpcon_dev->in_use,0 , + rte_memory_order_release);return ; } }
drivers/bus/fslmc/portal/dpaa2_hw_dpio.c +10 -4
@@ -352,7 +352,8 @@ static void dpaa2_put_qbman_swp(struct dpaa2_dpio_dev *dpio_dev)* armed: intr_deinit returns early if intr is not enabled. */ dpaa2_dpio_intr_deinit (dpio_dev); -rte_atomic16_clear (&dpio_dev->ref_count); +rte_atomic_store_explicit (&dpio_dev->ref_count,0 , + rte_memory_order_release); } }
@@ -364,7 +365,11 @@ static struct dpaa2_dpio_dev *dpaa2_get_qbman_swp(bool ethrx)/* Get DPIO dev handle from list using index */ TAILQ_FOREACH(dpio_dev, &dpio_dev_list, next) { -if (dpio_dev &&rte_atomic16_test_and_set (&dpio_dev->ref_count)) +uint16_t expected =0 ; + +if (rte_atomic_compare_exchange_strong_explicit (&dpio_dev->ref_count, + &expected,1 , rte_memory_order_acquire, + rte_memory_order_relaxed))break ; }if (!dpio_dev) {
@@ -385,7 +390,8 @@ static struct dpaa2_dpio_dev *dpaa2_get_qbman_swp(bool ethrx) ret =dpaa2_configure_stashing (dpio_dev, cpu_id, ethrx);if (ret) {DPAA2_BUS_ERR ("dpaa2_configure_stashing failed" ); -rte_atomic16_clear (&dpio_dev->ref_count); +rte_atomic_store_explicit (&dpio_dev->ref_count,0 , + rte_memory_order_release);return NULL ; } }
@@ -500,7 +506,7 @@ dpaa2_create_dpio_device(int vdev_fd, dpio_dev->dpio =NULL ; dpio_dev->hw_id = object_id; -rte_atomic16_init (&dpio_dev->ref_count); +rte_atomic_store_explicit (&dpio_dev->ref_count,0 , rte_memory_order_relaxed);/* Using single portal for all devices */ dpio_dev->mc_portal =dpaa2_get_mcp_ptr (MC_PORTAL_INDEX );
drivers/bus/fslmc/portal/dpaa2_hw_pvt.h +5 -4
@@ -9,6 +9,7 @@#define _DPAA2_HW_PVT_H_#include <rte_compat.h> +#include <rte_stdatomic.h> #include <rte_eventdev.h> #include <dpaax_iova_table.h>
@@ -112,7 +113,7 @@ struct dpaa2_dpio_dev {TAILQ_ENTRY (dpaa2_dpio_dev) next;/**< Pointer to Next device instance */ uint16_t index;/**< Index of a instance in the list */ -rte_atomic16_t ref_count; +RTE_ATOMIC (uint16_t ) ref_count;/**< How many thread contexts are sharing this.*/ uint16_t eqresp_ci;uint16_t eqresp_pi;
@@ -143,7 +144,7 @@ struct dpaa2_dpbp_dev {/**< Pointer to Next device instance */ struct fsl_mc_io dpbp;/** handle to DPBP portal object */ uint16_t token; -rte_atomic16_t in_use; +RTE_ATOMIC (uint16_t ) in_use;uint32_t dpbp_id;/*HW ID for DPBP object */ };
@@ -266,7 +267,7 @@ struct dpaa2_dpci_dev {/**< Pointer to Next device instance */ struct fsl_mc_io dpci;/** handle to DPCI portal object */ uint16_t token; -rte_atomic16_t in_use; +RTE_ATOMIC (uint16_t ) in_use;uint32_t dpci_id;/*HW ID for DPCI object */ struct dpaa2_queue rx_queue[DPAA2_DPCI_MAX_QUEUES ];struct dpaa2_queue tx_queue[DPAA2_DPCI_MAX_QUEUES ];
@@ -276,7 +277,7 @@ struct dpaa2_dpcon_dev {TAILQ_ENTRY (dpaa2_dpcon_dev) next;struct fsl_mc_io dpcon;uint16_t token; -rte_atomic16_t in_use; +RTE_ATOMIC (uint16_t ) in_use;uint32_t dpcon_id;uint16_t qbman_ch_id;uint8_t num_priorities;
Signature · 1 line
2.53.0
PATCH v7 12/24 net/netvsc: replace rte_atomic32 with stdatomic
In reply to Stephen HemmingerChange the rndis transaction id and buffer usage to use stdatomic functions.
--- drivers/net/netvsc/hn_rndis.c | 28 +++++++++++++++++++--------- drivers/net/netvsc/hn_rxtx.c | 12 +++++++----- drivers/net/netvsc/hn_var.h | 6 +++--- 3 files changed, 29 insertions(+), 17 deletions(-)
drivers/net/netvsc/hn_rndis.c +19 -9
@@ -17,7 +17,7 @@#include <rte_string_fns.h> #include <rte_memzone.h> #include <rte_malloc.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_alarm.h> #include <rte_branch_prediction.h> #include <rte_ether.h>
@@ -59,7 +59,8 @@ hn_rndis_rid(struct hn_data *hv)uint32_t rid;do { - rid =rte_atomic32_add_return (&hv->rndis_req_id,1 ); + rid =rte_atomic_fetch_add_explicit (&hv->rndis_req_id,1 , + rte_memory_order_seq_cst); }while (rid ==0 );return rid;
@@ -357,12 +358,14 @@ void hn_rndis_receive_response(struct hn_data *hv,memcpy (hv->rndis_resp, data, len);/* make sure response copied before update */ -rte_smp_wmb (); - -if (rte_atomic32_cmpset (&hv->rndis_pending, hdr->rid,0 ) ==0 ) { +uint32_t expected = hdr->rid; +if (!rte_atomic_compare_exchange_strong_explicit (&hv->rndis_pending, + &expected,0 , + rte_memory_order_release, + rte_memory_order_relaxed)) {PMD_DRV_LOG (NOTICE ,"received id %#x pending id %#x" , - hdr->rid, (uint32_t )hv->rndis_pending); + hdr->rid, expected); } }
@@ -388,8 +391,11 @@ static int hn_rndis_exec1(struct hn_data *hv,return -EINVAL ; } +uint32_t expected =0 ;if (comp !=NULL && -rte_atomic32_cmpset (&hv->rndis_pending,0 , rid) ==0 ) { + !rte_atomic_compare_exchange_strong_explicit ( + &hv->rndis_pending, &expected, rid, + rte_memory_order_acquire, rte_memory_order_relaxed)) {PMD_DRV_LOG (ERR ,"Request already pending" );return -EBUSY ;
@@ -405,7 +411,8 @@ static int hn_rndis_exec1(struct hn_data *hv,time_t start =time (NULL );/* Poll primary channel until response received */ -while (hv->rndis_pending == rid) { +while (rte_atomic_load_explicit (&hv->rndis_pending, + rte_memory_order_acquire) == rid) {if (hv->closed)return -ENETDOWN ;
@@ -413,7 +420,10 @@ static int hn_rndis_exec1(struct hn_data *hv,PMD_DRV_LOG (ERR ,"RNDIS response timed out" ); -rte_atomic32_cmpset (&hv->rndis_pending, rid,0 ); + expected = rid; +rte_atomic_compare_exchange_strong_explicit ( + &hv->rndis_pending, &expected,0 , + rte_memory_order_release, rte_memory_order_relaxed);return -ETIMEDOUT ; }
drivers/net/netvsc/hn_rxtx.c +7 -5
@@ -17,7 +17,7 @@#include <rte_string_fns.h> #include <rte_memzone.h> #include <rte_malloc.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_bitmap.h> #include <rte_branch_prediction.h> #include <rte_ether.h>
@@ -558,7 +558,8 @@ static void hn_rx_buf_free_cb(void *buf __rte_unused, void *opaque)struct hn_rx_queue *rxq = rxb->rxq;struct hn_data *hv = rxq->hv; -rte_atomic32_dec (&rxq->rxbuf_outstanding); +rte_atomic_fetch_sub_explicit (&rxq->rxbuf_outstanding,1 , + rte_memory_order_release);hn_nvs_ack_rxbuf (hv, rxb->chan, rxb->xactid); }
@@ -602,8 +603,8 @@ static void hn_rxpkt(struct hn_rx_queue *rxq, struct hn_rx_bufinfo *rxb,* some space available in receive area for later packets. */ if (hv->rx_extmbuf_enable && dlen > hv->rx_copybreak && - (uint32_t )rte_atomic32_read (&rxq->rxbuf_outstanding) < - hv->rxbuf_section_cnt /2 ) { +rte_atomic_load_explicit (&rxq->rxbuf_outstanding, + rte_memory_order_relaxed) < hv->rxbuf_section_cnt /2 ) {struct rte_mbuf_ext_shared_info *shinfo;const void *rxbuf;rte_iova_t iova;
@@ -619,7 +620,8 @@ static void hn_rxpkt(struct hn_rx_queue *rxq, struct hn_rx_bufinfo *rxb,/* shinfo is already set to 1 by the caller */ if (rte_mbuf_ext_refcnt_update (shinfo,1 ) ==2 ) -rte_atomic32_inc (&rxq->rxbuf_outstanding); +rte_atomic_fetch_add_explicit (&rxq->rxbuf_outstanding,1 , + rte_memory_order_acquire);rte_pktmbuf_attach_extbuf (m, data, iova, dlen + headroom, shinfo);
drivers/net/netvsc/hn_var.h +3 -3
@@ -85,7 +85,7 @@ struct hn_rx_queue {void *event_buf;struct hn_rx_bufinfo *rxbuf_info; -rte_atomic32_t rxbuf_outstanding; +RTE_ATOMIC (uint32_t ) rxbuf_outstanding; };
@@ -167,8 +167,8 @@ struct hn_data {uint32_t rndis_agg_pkts;uint32_t rndis_agg_align; -volatile uint32_t rndis_pending; -rte_atomic32_t rndis_req_id; +RTE_ATOMIC (uint32_t ) rndis_pending; +RTE_ATOMIC (uint32_t ) rndis_req_id;uint8_t rndis_resp[256 ];uint32_t rss_hash;
Signature · 1 line
2.53.0
RE: [EXTERNAL] [PATCH v7 12/24] net/netvsc: replace rte_atomic32 with stdatomic
Quoted 4 lines
Change the rndis transaction id and buffer usage to use stdatomic functions.
Signed-off-by Stephen Hemminger <[email protected]>
Quoted 167 lines
--- drivers/net/netvsc/hn_rndis.c | 28 +++++++++++++++++++--------- drivers/net/netvsc/hn_rxtx.c | 12 +++++++----- drivers/net/netvsc/hn_var.h | 6 +++--- 3 files changed, 29 insertions(+), 17 deletions(-)drivers/net/netvsc/hn_rndis.c +3
-2@@ -17,7 +17,7 @@#include <rte_string_fns.h> #include <rte_memzone.h> #include <rte_malloc.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_alarm.h> #include <rte_branch_prediction.h> #include <rte_ether.h> @@ -59,7 +59,8 @@ hn_rndis_rid(struct hn_data *hv)uint32_t rid;do { - rid =rte_atomic32_add_return (&hv->rndis_req_id,1 ); + rid =rte_atomic_fetch_add_explicit (&hv->rndis_req_id,1 , + rte_memory_order_seq_cst); }while (rid ==0 );drivers/net/netvsc/hn_rndis.c +16
-7return rid;@@ -357,12 +358,14 @@ void hn_rndis_receive_response(struct hn_data *hv,memcpy (hv->rndis_resp, data, len);/* make sure response copied before update */ -rte_smp_wmb (); - -if (rte_atomic32_cmpset (&hv->rndis_pending, hdr->rid,0 ) ==0 ) { +uint32_t expected = hdr->rid; +if (!rte_atomic_compare_exchange_strong_explicit (&hv- >rndis_pending, + &expected,0 , + rte_memory_order_release, + rte_memory_order_relaxed)) {PMD_DRV_LOG (NOTICE ,"received id %#x pending id %#x" , - hdr->rid, (uint32_t )hv->rndis_pending); + hdr->rid, expected); } }@@ -388,8 +391,11 @@ static int hn_rndis_exec1(struct hn_data *hv,return -EINVAL ; } +uint32_t expected =0 ;if (comp !=NULL && -rte_atomic32_cmpset (&hv->rndis_pending,0 , rid) ==0 ) { + !rte_atomic_compare_exchange_strong_explicit ( + &hv->rndis_pending, &expected, rid, + rte_memory_order_acquire, rte_memory_order_relaxed)) {PMD_DRV_LOG (ERR ,"Request already pending" );return -EBUSY ;@@ -405,7 +411,8 @@ static int hn_rndis_exec1(struct hn_data *hv,time_t start =time (NULL );/* Poll primary channel until response received */ -while (hv->rndis_pending == rid) { +while (rte_atomic_load_explicit (&hv->rndis_pending, + rte_memory_order_acquire) == rid) {if (hv->closed)return -ENETDOWN ;@@ -413,7 +420,10 @@ static int hn_rndis_exec1(struct hn_data *hv,PMD_DRV_LOG (ERR ,"RNDIS response timed out" ); -rte_atomic32_cmpset (&hv->rndis_pending, rid, 0); + expected = rid; +rte_atomic_compare_exchange_strong_explicit ( + &hv->rndis_pending, &expected,0 , + rte_memory_order_release, rte_memory_order_relaxed);drivers/net/netvsc/hn_rndis.c +0
-0return -ETIMEDOUT ; }drivers/net/netvsc/hn_rxtx.c index renamed from drivers/net/netvsc/hn_rxtx.c +0
-0
0d770d1b25..6f536610f2100644drivers/net/netvsc/hn_rxtx.c +5
-4@@ -17,7 +17,7 @@#include <rte_string_fns.h> #include <rte_memzone.h> #include <rte_malloc.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_bitmap.h> #include <rte_branch_prediction.h> #include <rte_ether.h> @@ -558,7 +558,8 @@ static void hn_rx_buf_free_cb(void *buf __rte_unused, void *opaque)struct hn_rx_queue *rxq = rxb->rxq;struct hn_data *hv = rxq->hv; -rte_atomic32_dec (&rxq->rxbuf_outstanding); +rte_atomic_fetch_sub_explicit (&rxq->rxbuf_outstanding,1 , + rte_memory_order_release);hn_nvs_ack_rxbuf (hv, rxb->chan, rxb->xactid); }@@ -602,8 +603,8 @@ static void hn_rxpkt(struct hn_rx_queue *rxq, structhn_rx_bufinfo *rxb, * some space available in receive area for later packets. */ if (hv->rx_extmbuf_enable && dlen > hv->rx_copybreak && - (uint32_t )rte_atomic32_read (&rxq->rxbuf_outstanding) < - hv->rxbuf_section_cnt /2 ) { +rte_atomic_load_explicit (&rxq->rxbuf_outstanding, + rte_memory_order_relaxed) < hv- >rxbuf_section_cnt /2 ) {struct rte_mbuf_ext_shared_info *shinfo;drivers/net/netvsc/hn_rxtx.c +2
-1const void *rxbuf;rte_iova_t iova;@@ -619,7 +620,8 @@ static void hn_rxpkt(struct hn_rx_queue *rxq, struct hn_rx_bufinfo *rxb,/* shinfo is already set to 1 by the caller */ if (rte_mbuf_ext_refcnt_update(shinfo, 1) == 2) -rte_atomic32_inc (&rxq->rxbuf_outstanding); +rte_atomic_fetch_add_explicit (&rxq- >rxbuf_outstanding, 1, + rte_memory_order_acquire);drivers/net/netvsc/hn_rxtx.c +0
-0rte_pktmbuf_attach_extbuf (m, data, iova, dlen + headroom, shinfo);drivers/net/netvsc/hn_var.h index renamed from drivers/net/netvsc/hn_var.h +0
-0
574b909c82..d7124a7df9100644drivers/net/netvsc/hn_var.h +3
-4@@ -85,7 +85,7 @@ struct hn_rx_queue {void *event_buf;struct hn_rx_bufinfo *rxbuf_info; -rte_atomic32_t rxbuf_outstanding; +RTE_ATOMIC (uint32_t ) rxbuf_outstanding; };@@ -167,8 +167,8 @@ struct hn_data {uint32_t rndis_agg_pkts;uint32_t rndis_agg_align; -volatile uint32_t rndis_pending; -rte_atomic32_t rndis_req_id; +RTE_ATOMIC (uint32_t ) rndis_pending; +RTE_ATOMIC (uint32_t ) rndis_req_id;uint8_t rndis_resp[256 ];uint32_t rss_hash; --2.53.0
PATCH v7 13/24 event/sw: convert from rte_atomic32 to stdatomic
In reply to Stephen HemmingerUse stdatomic to keep track of inflights.
--- drivers/event/sw/sw_evdev.c | 8 +++++--- drivers/event/sw/sw_evdev.h | 4 ++-- drivers/event/sw/sw_evdev_worker.c | 16 +++++++++++----- 3 files changed, 18 insertions(+), 10 deletions(-)
drivers/event/sw/sw_evdev.c +5 -3
@@ -153,7 +153,9 @@ sw_port_setup(struct rte_eventdev *dev, uint8_t port_id,* the sum to no leak credits */ int possible_inflights = p->inflight_credits + p->inflights; -rte_atomic32_sub (&sw->inflights, possible_inflights); +rte_atomic_fetch_sub_explicit (&sw->inflights, + possible_inflights, + rte_memory_order_release); } *p = (struct sw_port ){0 };/* zero entire structure */
@@ -512,7 +514,7 @@ sw_dev_configure(const struct rte_eventdev *dev) sw->qid_count = conf->nb_event_queues; sw->port_count = conf->nb_event_ports; sw->nb_events_limit = conf->nb_events_limit; -rte_atomic32_set (&sw->inflights,0 ); + sw->inflights =0 ;/* Number of chunks sized for worst-case spread of events across IQs */ num_chunks = ((SW_INFLIGHT_EVENTS_TOTAL/SW_EVS_PER_Q_CHUNK)+1) +
@@ -633,7 +635,7 @@ sw_dump(struct rte_eventdev *dev, FILE *f)fprintf (f,"\tsched cq/qid call: %" PRIu64"\n" , sw->sched_cq_qid_called);fprintf (f,"\tsched no IQ enq: %" PRIu64"\n" , sw->sched_no_iq_enqueues);fprintf (f,"\tsched no CQ enq: %" PRIu64"\n" , sw->sched_no_cq_enqueues); -uint32_t inflights =rte_atomic32_read (&sw->inflights); +uint32_t inflights =rte_atomic_load_explicit (&sw->inflights, rte_memory_order_relaxed);uint32_t credits = sw->nb_events_limit - inflights;fprintf (f,"\tinflight %d, credits: %d\n" , inflights, credits);
drivers/event/sw/sw_evdev.h +2 -2
@@ -8,7 +8,7 @@#include "sw_evdev_log.h" #include <rte_eventdev.h> #include <eventdev_pmd_vdev.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #define SW_DEFAULT_CREDIT_QUANTA 32#define SW_DEFAULT_SCHED_QUANTA 128
@@ -233,7 +233,7 @@ struct sw_evdev {/* Contains all ports - load balanced and directed */ alignas(RTE_CACHE_LINE_SIZE )struct sw_port ports[SW_PORTS_MAX ]; - alignas(RTE_CACHE_LINE_SIZE )rte_atomic32_t inflights; + alignas(RTE_CACHE_LINE_SIZE )RTE_ATOMIC (uint32_t ) inflights;/* * max events in this instance. Cached here for performance.
drivers/event/sw/sw_evdev_worker.c +11 -5
@@ -56,7 +56,7 @@ sw_event_enqueue_burst(void *port, const struct rte_event ev[], uint16_t num)uint8_t new_ops[PORT_ENQUEUE_MAX_BURST_SIZE ];struct sw_port *p = port;struct sw_evdev *sw = (void *)p->sw; -uint32_t sw_inflights =rte_atomic32_read (&sw->inflights); +uint32_t sw_inflights =rte_atomic_load_explicit (&sw->inflights, rte_memory_order_relaxed);uint32_t credit_update_quanta = sw->credit_update_quanta;int new =0 ;
@@ -74,8 +74,10 @@ sw_event_enqueue_burst(void *port, const struct rte_event ev[], uint16_t num)if (sw_inflights + credit_update_quanta > sw->nb_events_limit)return 0 ; -rte_atomic32_add (&sw->inflights, credit_update_quanta); - p->inflight_credits += (credit_update_quanta); +rte_atomic_fetch_add_explicit (&sw->inflights, + credit_update_quanta, + rte_memory_order_acquire); + p->inflight_credits += credit_update_quanta;/* If there are fewer inflight credits than new events, limit * the number of enqueued events.
@@ -124,7 +126,9 @@ sw_event_enqueue_burst(void *port, const struct rte_event ev[], uint16_t num)/* Replenish credits if enough releases are performed */ if (p->inflight_credits >= credit_update_quanta *2 ) { -rte_atomic32_sub (&sw->inflights, credit_update_quanta); +rte_atomic_fetch_sub_explicit (&sw->inflights, + credit_update_quanta, + rte_memory_order_release); p->inflight_credits -= credit_update_quanta; }
@@ -150,7 +154,9 @@ sw_event_dequeue_burst(void *port, struct rte_event *ev, uint16_t num,/* Replenish credits if enough releases are performed */ if (p->inflight_credits >= credit_update_quanta *2 ) { -rte_atomic32_sub (&sw->inflights, credit_update_quanta); +rte_atomic_fetch_sub_explicit (&sw->inflights, + credit_update_quanta, + rte_memory_order_release); p->inflight_credits -= credit_update_quanta; } }
Signature · 1 line
2.53.0
PATCH v7 14/24 bus/vmbus: convert from rte_atomic to stdatomic
In reply to Stephen HemmingerReplace deprecated rte_atomic32 operations in the vmbus ring buffer producer with stdatomic equivalents, and replace the smp_wmb + CAS-spin publish with rte_wait_until_equal_32 + release-store.
The two-cursor design is preserved: tbr->windex is the driver-private reservation cursor that lets producers reserve slots concurrently without a lock; vbr->windex is the host-visible commit cursor, updated in reservation order so the host never observes windex pointing past unwritten data. This is the lockless analogue of the spinlock-around- single-cursor pattern used by the Linux (drivers/hv/ring_buffer.c hv_ringbuffer_write) and FreeBSD (sys/dev/hyperv/vmbus/vmbus_br.c vmbus_txbr_write) implementations of the same host contract.
The memory ordering mirrors __rte_ring_headtail_move_head and __rte_ring_update_tail in lib/ring/rte_ring_c11_pvt.h: relaxed wait for the previous producer's commit, release-store to publish. The rte_smp_wmb before the publish is folded into the release ordering on the store itself.
The host-shared vbr->windex remains volatile uint32_t in the packed bufring struct; the atomic qualifier is added via cast at the access site. The (uintptr_t) launder on the store-side cast suppresses a spurious misaligned-atomic warning from the packed-struct attribute (windex is 4-byte aligned in practice, at offset 0 of a page-aligned struct).
--- drivers/bus/vmbus/private.h | 2 +- drivers/bus/vmbus/vmbus_bufring.c | 39 +++++++++++++++++-------------- 2 files changed, 23 insertions(+), 18 deletions(-)
drivers/bus/vmbus/private.h +1 -1
@@ -25,7 +25,7 @@ extern int vmbus_logtype_bus;struct vmbus_br {struct vmbus_bufring *vbr;uint32_t dsize; -uint32_t windex;/* next available location */ +RTE_ATOMIC (uint32_t ) windex;/* next available location */ };#define UIO_NAME_MAX 64
drivers/bus/vmbus/vmbus_bufring.c +22 -17
@@ -15,7 +15,7 @@#include <rte_tailq.h> #include <rte_log.h> #include <rte_malloc.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_memory.h> #include <rte_pause.h> #include <rte_bus_vmbus.h>
@@ -114,6 +114,7 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen,uint32_t ring_size = tbr->dsize;uint32_t old_windex, next_windex, windex, total;uint64_t save_windex; +bool success;int i; total =0 ;
@@ -121,17 +122,13 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen, total += iov[i].iov_len; total +=sizeof (save_windex); +/* Get current free location */ + old_windex =rte_atomic_load_explicit (&tbr->windex, + rte_memory_order_relaxed); +/* Reserve space in ring */ do { - uint32_t avail; - - /* Get current free location */ - old_windex = tbr->windex; - - /* Prevent compiler reordering this with calculation */ - rte_compiler_barrier(); - - avail = vmbus_br_availwrite(tbr, old_windex); + uint32_t avail = vmbus_br_availwrite(tbr, old_windex); /* If not enough space in ring, then tell caller. */ if (avail <= total)
@@ -139,8 +136,13 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen, next_windex =vmbus_br_idxinc (old_windex, total, ring_size); -/* Atomic update of next write_index for other threads */ - }while (!rte_atomic32_cmpset (&tbr->windex, old_windex, next_windex)); +/* Atomic update of next write_index for other threads +* Can use weak since easy to recompute and retry. +*/ + success =rte_atomic_compare_exchange_weak_explicit ( + &tbr->windex, &old_windex, next_windex, + rte_memory_order_acquire, rte_memory_order_relaxed); + }while (unlikely (!success));/* Space from old..new is now reserved */ windex = old_windex;
@@ -157,12 +159,15 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen,/* The region reserved should match region used */ RTE_ASSERT (windex == next_windex); -/* Ensure that data is available before updating host index */ -rte_smp_wmb (); +/* Wait for previous producer to publish their windex update */ +rte_wait_until_equal_32 (&vbr->windex, old_windex, rte_memory_order_relaxed); -/* Checkin for our reservation. wait for our turn to update host */ -while (!rte_atomic32_cmpset (&vbr->windex, old_windex, next_windex)) -rte_pause (); +/* Publish our windex update; prior data writes ordered via release. +* windex is 4-byte aligned in practice (struct is page-aligned, windex +* at offset 0); cast launders the packed-struct alignment-1 attribute. +*/ + rte_atomic_store_explicit((volatile __rte_atomic uint32_t *)(uintptr_t)&vbr->windex, + next_windex, rte_memory_order_release);/* If host had read all data before this, then need to signal */ *need_sig |=vmbus_txbr_need_signal (vbr, old_windex);
Signature · 1 line
2.53.0
RE: [EXTERNAL] [PATCH v7 14/24] bus/vmbus: convert from rte_atomic to stdatomic
Quoted 110 lines
Replace deprecated
rte_atomic32operations in the vmbus ring buffer producer with stdatomic equivalents, and replace thesmp_wmb+ CAS-spin publish withrte_wait_until_equal_32+ release-store.The two-cursor design is preserved:
tbr->windexis the driver-private reservation cursor that lets producers reserve slots concurrently without a lock;vbr->windexis the host-visible commit cursor, updated in reservation order so the host never observes windex pointing past unwritten data. This is the lockless analogue of the spinlock-around- single-cursor pattern used by the Linux (drivers/hv/ring_buffer.chv_ringbuffer_write) and FreeBSD (sys/dev/hyperv/vmbus/vmbus_br.cvmbus_txbr_write) implementations of the same host contract.The memory ordering mirrors
__rte_ring_headtail_move_headand__rte_ring_update_tailinlib/ring/rte_ring_c11_pvt.h: relaxed wait for the previous producer's commit, release-store to publish. Therte_smp_wmbbefore the publish is folded into the release ordering on the store itself.The host-shared
vbr->windexremains volatileuint32_tin the packed bufring struct; the atomic qualifier is added via cast at the access site. The (uintptr_t) launder on the store-side cast suppresses a spurious misaligned-atomic warning from the packed-struct attribute (windex is 4-byte aligned in practice, at offset 0 of a page-aligned struct).Signed-off-by Stephen Hemminger <[email protected]>--- drivers/bus/vmbus/private.h | 2 +- drivers/bus/vmbus/vmbus_bufring.c | 39 +++++++++++++++++-------------- 2 files changed, 23 insertions(+), 18 deletions(-)drivers/bus/vmbus/private.h index renamed from drivers/bus/vmbus/private.h +0
-0
6efac86b77..6b7782724f100644drivers/bus/vmbus/private.h +1
-1@@ -25,7 +25,7 @@ extern int vmbus_logtype_bus; struct vmbus_br {struct vmbus_bufring *vbr;uint32_t dsize; -uint32_t windex;/* next available location */ +RTE_ATOMIC (uint32_t ) windex;/* next available location */ };#define UIO_NAME_MAX 64drivers/bus/vmbus/vmbus_bufring.c +2
-1@@ -15,7 +15,7 @@#include <rte_tailq.h> #include <rte_log.h> #include <rte_malloc.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_memory.h> #include <rte_pause.h> #include <rte_bus_vmbus.h> @@ -114,6 +114,7 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen, uint32_t ring_size = tbr->dsize;uint32_t old_windex, next_windex, windex, total;uint64_t save_windex; +bool success;int i;drivers/bus/vmbus/vmbus_bufring.c +5
-9total =0 ;@@ -121,17 +122,13 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen, total += iov[i].iov_len; total +=sizeof (save_windex); +/* Get current free location */ + old_windex =rte_atomic_load_explicit (&tbr->windex, + rte_memory_order_relaxed); +/* Reserve space in ring */ do { - uint32_t avail; - - /* Get current free location */ - old_windex = tbr->windex; - - /* Prevent compiler reordering this with calculation */ - rte_compiler_barrier(); - - avail = vmbus_br_availwrite(tbr, old_windex); + uint32_t avail = vmbus_br_availwrite(tbr, old_windex); /* If not enough space in ring, then tell caller. */drivers/bus/vmbus/vmbus_bufring.c +7
-2if (avail <= total)@@ -139,8 +136,13 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen, next_windex =vmbus_br_idxinc (old_windex, total, ring_size); -/* Atomic update of next write_index for other threads */ - }while (!rte_atomic32_cmpset (&tbr->windex, old_windex, next_windex)); +/* Atomic update of next write_index for other threads +* Can use weak since easy to recompute and retry. +*/ + success =rte_atomic_compare_exchange_weak_explicit ( + &tbr->windex, &old_windex, next_windex, + rte_memory_order_acquire, rte_memory_order_relaxed); + }while (unlikely (!success));drivers/bus/vmbus/vmbus_bufring.c +0
-0/* Space from old..new is now reserved */ windex = old_windex;
drivers/bus/vmbus/vmbus_bufring.c vmbus_txbr_write(struct vmbus_br *tbr, const · line 165
Quoted 9 lines
drivers/bus/vmbus/vmbus_bufring.c +3
-2@@ -157,12 +159,15 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen,/* The region reserved should match region used */ RTE_ASSERT(windex == next_windex); -/* Ensure that data is available before updating host index */ -rte_smp_wmb (); +/* Wait for previous producer to publish their windex update */ +rte_wait_until_equal_32 (&vbr->windex, old_windex, +rte_memory_order_relaxed);
I'm not sure about this one, should it be rte_memory_order_acquire?
Thanks,
Long
Quoted 17 lines
drivers/bus/vmbus/vmbus_bufring.c +6
-4-/* Checkin for our reservation. wait for our turn to update host */ -while (!rte_atomic32_cmpset (&vbr->windex, old_windex, next_windex)) -rte_pause (); +/* Publish our windex update; prior data writes ordered via release. +* windex is 4-byte aligned in practice (struct is page-aligned, windex +* at offset 0); cast launders the packed-struct alignment-1 attribute. +*/ + rte_atomic_store_explicit((volatile __rte_atomic uint32_t *)(uintptr_t)&vbr->windex, + next_windex, rte_memory_order_release);/* If host had read all data before this, then need to signal */ *need_sig |=vmbus_txbr_need_signal (vbr, old_windex); --2.53.0
PATCH v7 15/24 common/dpaax: remove unused atomic wrappers
In reply to Stephen HemmingerThis driver defined Linux compatability wrappers but never used them in current code base; remove them.
--- drivers/common/dpaax/compat.h | 14 -------------- 1 file changed, 14 deletions(-)
drivers/common/dpaax/compat.h +0 -14
@@ -365,20 +365,6 @@ static inline unsigned long get_zeroed_page(gfp_t __foo __rte_unused)#define spin_lock_irqsave (x, f) spin_lock_irq(x)#define spin_unlock_irqrestore (x, f) spin_unlock_irq(x) -#define atomic_t rte_atomic32_t -#define atomic_read (v) rte_atomic32_read(v) -#define atomic_set (v, i) rte_atomic32_set(v, i) - -#define atomic_inc (v) rte_atomic32_add(v, 1) -#define atomic_dec (v) rte_atomic32_sub(v, 1) - -#define atomic_inc_and_test (v) rte_atomic32_inc_and_test(v) -#define atomic_dec_and_test (v) rte_atomic32_dec_and_test(v) - -#define atomic_inc_return (v) rte_atomic32_add_return(v, 1) -#define atomic_dec_return (v) rte_atomic32_sub_return(v, 1) -#define atomic_sub_and_test (i, v) (rte_atomic32_sub_return(v, i) == 0) -/* Interface name len*/ #define IF_NAME_MAX_LEN 16
Signature · 1 line
2.53.0
PATCH v7 16/24 net/bnx2x: convert from rte_atomic32 to stdatomic
In reply to Stephen HemmingerReplace the legacy rte_atomic32_* API on sc->scan_fp with the equivalent rte_atomic_*_explicit C11 helpers, ahead of the deprecation of rte_atomicNN_t and its associated wrappers.
All accesses use rte_memory_order_seq_cst, matching the semantics of the legacy API. No functional change.
The scan_fp field is a notification flag between the slow-path command poster (bnx2x_sp_post) and the fastpath task that reaps ramrod completions (bnx2x_handle_fp_tq), also cleared from ecore_state_wait on success, panic, and timeout.
--- drivers/net/bnx2x/bnx2x.c | 6 +++--- drivers/net/bnx2x/bnx2x.h | 2 +- drivers/net/bnx2x/ecore_sp.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-)
drivers/net/bnx2x/bnx2x.c +3 -3
@@ -1098,7 +1098,7 @@ bnx2x_sp_post(struct bnx2x_softc *sc, int command, int cid, uint32_t data_hi,* Ask bnx2x_intr_intr() to process RAMROD * completion whenever it gets scheduled. */ -rte_atomic32_set (&sc->scan_fp,1 ); +rte_atomic_store_explicit (&sc->scan_fp,1 , rte_memory_order_seq_cst);bnx2x_sp_prod_update (sc);return 0 ;
@@ -4575,7 +4575,7 @@ static void bnx2x_handle_fp_tq(struct bnx2x_fastpath *fp)/* update the fastpath index */ bnx2x_update_fp_sb_idx (fp); -if (rte_atomic32_read (&sc->scan_fp) ==1 ) { +if (rte_atomic_load_explicit (&sc->scan_fp, rte_memory_order_seq_cst)) {if (bnx2x_has_rx_work (fp)) { more_rx =bnx2x_rxeof (sc, fp); }
@@ -4586,7 +4586,7 @@ static void bnx2x_handle_fp_tq(struct bnx2x_fastpath *fp)return ; }/* We have completed slow path completion, clear the flag */ -rte_atomic32_set (&sc->scan_fp,0 ); +rte_atomic_store_explicit (&sc->scan_fp,0 , rte_memory_order_seq_cst); } bnx2x_ack_sb(sc, fp->igu_sb_id, USTORM_ID,
drivers/net/bnx2x/bnx2x.h +1 -1
@@ -1043,7 +1043,7 @@ struct bnx2x_softc {#define PERIODIC_STOP 0#define PERIODIC_GO 1volatile unsigned long periodic_flags; -rte_atomic32_t scan_fp; +RTE_ATOMIC (uint32_t ) scan_fp;struct bnx2x_fastpath fp[MAX_RSS_CHAINS ];struct bnx2x_sp_objs sp_objs[MAX_RSS_CHAINS ];
drivers/net/bnx2x/ecore_sp.c +3 -3
@@ -299,21 +299,21 @@ static int ecore_state_wait(struct bnx2x_softc *sc, int state,#ifdef ECORE_STOP_ON_ERROR ECORE_MSG (sc,"exit (cnt %d)" ,5000 - cnt);#endif -rte_atomic32_set (&sc->scan_fp,0 ); +rte_atomic_store_explicit (&sc->scan_fp,0 , rte_memory_order_seq_cst);return ECORE_SUCCESS ; }ECORE_WAIT (sc, delay_us);if (sc->panic) { -rte_atomic32_set (&sc->scan_fp,0 ); +rte_atomic_store_explicit (&sc->scan_fp,0 , rte_memory_order_seq_cst);return ECORE_IO ; } }/* timeout! */ PMD_DRV_LOG (ERR , sc,"timeout waiting for state %d" , state); -rte_atomic32_set (&sc->scan_fp,0 ); +rte_atomic_store_explicit (&sc->scan_fp,0 , rte_memory_order_seq_cst);#ifdef ECORE_STOP_ON_ERROR ecore_panic ();#endif
Signature · 1 line
2.53.0
PATCH v7 17/24 bus/fslmc: replace rte_atomic32 with stdatomic
In reply to Stephen HemmingerThe atomic wrappers here are easily converted to stdatomic. Drop any unused macros.
--- drivers/bus/fslmc/qbman/include/compat.h | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
drivers/bus/fslmc/qbman/include/compat.h +4 -12
@@ -81,18 +81,10 @@ do { \#define dma_wmb () rte_io_wmb() -#define atomic_t rte_atomic32_t -#define atomic_read (v) rte_atomic32_read(v) -#define atomic_set (v, i) rte_atomic32_set(v, i) +typedef RTE_ATOMIC (uint32_t )atomic_t ; -#define atomic_inc (v) rte_atomic32_add(v, 1) -#define atomic_dec (v) rte_atomic32_sub(v, 1) - -#define atomic_inc_and_test (v) rte_atomic32_inc_and_test(v) -#define atomic_dec_and_test (v) rte_atomic32_dec_and_test(v) - -#define atomic_inc_return (v) rte_atomic32_add_return(v, 1) -#define atomic_dec_return (v) rte_atomic32_sub_return(v, 1) -#define atomic_sub_and_test (i, v) (rte_atomic32_sub_return(v, i) == 0) +#define atomic_set (v, i) rte_atomic_store_explicit((v), (i), rte_memory_order_relaxed) +#define atomic_inc (v) ((void)rte_atomic_fetch_add_explicit((v), 1, rte_memory_order_seq_cst)) +#define atomic_dec_and_test (v) (rte_atomic_fetch_sub_explicit((v), 1, rte_memory_order_seq_cst) == 1)#endif /* HEADER_COMPAT_H */
Signature · 1 line
2.53.0
Re: [PATCH v7 17/24] bus/fslmc: replace rte_atomic32 with stdatomic
Quoted 5 lines · Stephen Hemminger
The atomic wrappers here are easily converted to stdatomic. Drop any unused macros.
Signed-off-by Stephen Hemminger <[email protected]>---
PATCH v7 18/24 drivers/event: replace rte_atomic32 in selftests
In reply to Stephen HemmingerLast callers in these selftests of the rte_atomicNN_*() family, which is being deprecated.
Convert total_events from rte_atomic32_t to RTE_ATOMIC(uint32_t) for the stack-local instance and __rte_atomic uint32_t * for the pointer in test_core_param. Switch reads and updates to rte_atomic_*_explicit().
Reads in the busy-loop checks and progress logs use relaxed: the counter is purely a "drained yet?" signal and no data is published through it. The fetch_sub on the dequeue path uses release in octeontx (preserving the publish-after-mbuf-free ordering already implied by the seq_cst sub it replaces) and relaxed in dpaa2.
The stack-local atomic_total_events is initialized by direct assignment instead of rte_atomic32_set(), since it is written before any worker is launched.
--- drivers/event/dpaa2/dpaa2_eventdev_selftest.c | 26 ++++---- drivers/event/octeontx/ssovf_evdev_selftest.c | 61 ++++++++++--------- 2 files changed, 47 insertions(+), 40 deletions(-)
drivers/event/dpaa2/dpaa2_eventdev_selftest.c +14 -12
@@ -2,7 +2,7 @@* Copyright 2018-2019 NXP */ -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_common.h> #include <rte_cycles.h> #include <rte_debug.h>
@@ -49,7 +49,7 @@ struct event_attr { };struct test_core_param { -rte_atomic32_t *total_events; + __rte_atomic uint32_t *total_events;uint64_t dequeue_tmo_ticks;uint8_t port;uint8_t sched_type;
@@ -444,10 +444,10 @@ worker_multi_port_fn(void *arg)struct rte_event ev;uint16_t valid_event;uint8_t port = param->port; -rte_atomic32_t *total_events = param->total_events; + __rte_atomic uint32_t *total_events = param->total_events;int ret; -while (rte_atomic32_read (total_events) >0 ) { +while (rte_atomic_load_explicit (total_events, rte_memory_order_relaxed) >0 ) { valid_event =rte_event_dequeue_burst (evdev, port, &ev,1 ,0 );if (!valid_event)continue ;
@@ -455,13 +455,15 @@ worker_multi_port_fn(void *arg) ret =validate_event (&ev);RTE_TEST_ASSERT_SUCCESS (ret,"Failed to validate event" );rte_pktmbuf_free (ev.mbuf); -rte_atomic32_sub (total_events,1 ); + +rte_atomic_fetch_sub_explicit (total_events,1 , + rte_memory_order_relaxed); }return 0 ; }static int -wait_workers_to_join (int lcore,const rte_atomic32_t *count) +wait_workers_to_join(int lcore, const __rte_atomic uint32_t *count) {uint64_t cycles, print_cycles;
@@ -472,15 +474,15 @@ wait_workers_to_join(int lcore, const rte_atomic32_t *count)uint64_t new_cycles =rte_get_timer_cycles ();if (new_cycles - print_cycles >rte_get_timer_hz ()) { -dpaa2_evdev_dbg ("\r%s: events %d" , __func__, -rte_atomic32_read (count)); +dpaa2_evdev_dbg ("\r%s: events %u" , __func__, +rte_atomic_load_explicit (count, rte_memory_order_relaxed)); print_cycles = new_cycles; }if (new_cycles - cycles >rte_get_timer_hz () *10 ) {dpaa2_evdev_info ( -"%s: No schedules for seconds, deadlock (%d)" , +"%s: No schedules for seconds, deadlock (%u)" , __func__, -rte_atomic32_read (count)); +rte_atomic_load_explicit (count, rte_memory_order_relaxed));rte_event_dev_dump (evdev, stdout); cycles = new_cycles;return -1 ;
@@ -500,13 +502,13 @@ launch_workers_and_wait(int (*main_worker)(void *),int w_lcore;int ret;struct test_core_param *param; -rte_atomic32_t atomic_total_events; +RTE_ATOMIC (uint32_t ) atomic_total_events;uint64_t dequeue_tmo_ticks;if (!nb_workers)return 0 ; -rte_atomic32_set (&atomic_total_events, total_events); + atomic_total_events = total_events;RTE_BUILD_BUG_ON (NUM_PACKETS <MAX_EVENTS ); param =malloc (sizeof (struct test_core_param ) * nb_workers);
drivers/event/octeontx/ssovf_evdev_selftest.c +33 -28
182 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v7 19/24 net/hinic: replace rte_atomic32 with stdatomic
In reply to Stephen HemmingerConvert dma_pool::inuse and hinic_os_dep::dma_alloc_cnt to RTE_ATOMIC(uint32_t) and replace rte_atomic32_*() with the rte_atomic_*_explicit() equivalents. The matching local variable and log format change from int/%d to uint32_t/%u.
--- drivers/net/hinic/base/hinic_compat.h | 2 +- drivers/net/hinic/base/hinic_pmd_hwdev.c | 24 ++++++++++++++---------- drivers/net/hinic/base/hinic_pmd_hwdev.h | 4 ++-- 3 files changed, 17 insertions(+), 13 deletions(-)
drivers/net/hinic/base/hinic_compat.h +1 -1
@@ -15,7 +15,7 @@#include <rte_memzone.h> #include <rte_memcpy.h> #include <rte_malloc.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_spinlock.h> #include <rte_cycles.h> #include <rte_log.h>
drivers/net/hinic/base/hinic_pmd_hwdev.c +14 -10
@@ -116,7 +116,8 @@ static void *hinic_dma_mem_zalloc(struct hinic_hwdev *hwdev, size_t size, dma_addr_t *dma_handle, unsigned int align, unsigned int socket_id) { - int rc, alloc_cnt; + int rc; +uint32_t alloc_cnt;const struct rte_memzone *mz;char z_name[RTE_MEMZONE_NAMESIZE ];hash_sig_t sig;
@@ -125,8 +126,9 @@ static void *hinic_dma_mem_zalloc(struct hinic_hwdev *hwdev, size_t size,if (dma_handle ==NULL ||0 == size)return NULL ; - alloc_cnt =rte_atomic32_add_return (&hwdev->os_dep.dma_alloc_cnt,1 ); -snprintf (z_name,sizeof (z_name),"%s_%d" , + alloc_cnt =rte_atomic_fetch_add_explicit (&hwdev->os_dep.dma_alloc_cnt, +1 , rte_memory_order_relaxed); +snprintf (z_name,sizeof (z_name),"%s_%u" , hwdev->pcidev_hdl->name, alloc_cnt); mz = rte_memzone_reserve_aligned(z_name, size, socket_id,
@@ -282,7 +284,6 @@ struct dma_pool *dma_pool_create(const char *name, void *dev,if (!pool)return NULL ; -rte_atomic32_set (&pool->inuse,0 ); pool->elem_size = size; pool->align = align; pool->boundary = boundary;
@@ -294,12 +295,15 @@ struct dma_pool *dma_pool_create(const char *name, void *dev,void dma_pool_destroy (struct dma_pool *pool) { +uint32_t inuse; +if (!pool)return ; -if (rte_atomic32_read (&pool->inuse) !=0 ) { -PMD_DRV_LOG (ERR ,"Leak memory, dma_pool: %s, inuse_count: %d" , - pool->name,rte_atomic32_read (&pool->inuse)); + inuse =rte_atomic_load_explicit (&pool->inuse, rte_memory_order_relaxed); +if (inuse !=0 ) { +PMD_DRV_LOG (ERR ,"Leak memory, dma_pool: %s, inuse_count: %u" , + pool->name, inuse); }rte_free (pool);
@@ -312,14 +316,14 @@ void *dma_pool_alloc(struct pci_pool *pool, dma_addr_t *dma_addr) buf =hinic_dma_mem_zalloc (pool->hwdev, pool->elem_size, dma_addr, (u32 )pool->align,SOCKET_ID_ANY );if (buf) -rte_atomic32_inc (&pool->inuse); +rte_atomic_fetch_add_explicit (&pool->inuse,1 , rte_memory_order_relaxed);return buf; }void dma_pool_free (struct pci_pool *pool,void *vaddr,dma_addr_t dma) { -rte_atomic32_dec (&pool->inuse); +rte_atomic_fetch_sub_explicit (&pool->inuse,1 , rte_memory_order_relaxed);hinic_dma_mem_free (pool->hwdev, pool->elem_size, vaddr, dma); }
@@ -329,7 +333,7 @@ int hinic_osdep_init(struct hinic_hwdev *hwdev)struct rte_hash_parameters dh_params = {0 };struct rte_hash *paddr_hash =NULL ; -rte_atomic32_set (&hwdev->os_dep.dma_alloc_cnt,0 ); + hwdev->os_dep.dma_alloc_cnt =0 ;rte_spinlock_init (&hwdev->os_dep.dma_hash_lock); dh_params.name = hwdev->pcidev_hdl->name;
drivers/net/hinic/base/hinic_pmd_hwdev.h +2 -2
@@ -18,7 +18,7 @@/* dma pool */ struct dma_pool { -rte_atomic32_t inuse; +RTE_ATOMIC (uint32_t ) inuse;size_t elem_size;size_t align;size_t boundary;
@@ -402,7 +402,7 @@ struct hinic_hilink_link_info {/* dma os dependency implementation */ struct hinic_os_dep {/* kernel dma alloc api */ -rte_atomic32_t dma_alloc_cnt; +RTE_ATOMIC (uint32_t ) dma_alloc_cnt;rte_spinlock_t dma_hash_lock;struct rte_hash *dma_addr_hash; };
Signature · 1 line
2.53.0
PATCH v7 20/24 net/txgbe: replace rte_atomic32 with stdatomic
In reply to Stephen HemmingerThe swfw_busy flag guarding the AML SW-FW mailbox is a one-bit lock, so convert it to RTE_ATOMIC(bool) and replace the legacy test-and-set / clear pair with explicit acquire-release:
rte_atomic32_test_and_set ->
rte_atomic_exchange_explicit(.., true, acquire)
rte_atomic32_clear ->
rte_atomic_store_explicit(.., false, release)
Acquire on the take pairs with release on the drop, so accesses inside the critical section are synchronized between successive holders. Default zero-initialization of struct txgbe_hw still gives swfw_busy = false, so no init site needs updating.
Note:
The previous rte_atomic32_test_and_set return value was inverted relative to what this code expected; this patch incidentally corrects that. A standalone Fixes: patch is queued in net-next.
--- drivers/net/txgbe/base/txgbe_mng.c | 4 ++-- drivers/net/txgbe/base/txgbe_type.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/txgbe/base/txgbe_mng.c +2 -2
@@ -185,7 +185,7 @@ txgbe_host_interface_command_aml(struct txgbe_hw *hw, u32 *buffer, }/* try to get lock */ -while (rte_atomic32_test_and_set (&hw->swfw_busy)) { +while (rte_atomic_exchange_explicit (&hw->swfw_busy, true, rte_memory_order_acquire)) { timeout--;if (!timeout)return TXGBE_ERR_TIMEOUT ;
@@ -266,7 +266,7 @@ txgbe_host_interface_command_aml(struct txgbe_hw *hw, u32 *buffer,/* index++, index replace txgbe_hic_hdr.checksum */ hw->swfw_index = resp->index ==TXGBE_HIC_HDR_INDEX_MAX ?0 : resp->index +1 ; -rte_atomic32_clear (&hw->swfw_busy); +rte_atomic_store_explicit (&hw->swfw_busy, false, rte_memory_order_release);return err; }
drivers/net/txgbe/base/txgbe_type.h +1 -1
@@ -897,7 +897,7 @@ struct txgbe_hw {rte_spinlock_t phy_lock;/*amlite: new SW-FW mbox */ u8 swfw_index; -rte_atomic32_t swfw_busy; +RTE_ATOMIC (bool ) swfw_busy;bool link_valid;bool reconfig_rx;RTE_ATOMIC (bool ) pf_running;
Signature · 1 line
2.53.0
PATCH v7 21/24 net/vhost: use stdatomic instead of rte_atomic32
In reply to Stephen HemmingerConvert allow_queuing, while_queuing, started, and dev_attached from rte_atomic32_t to RTE_ATOMIC(uint32_t) and replace rte_atomic32_*() with rte_atomic_*_explicit().
The data-path / control-thread handshake on allow_queuing and while_queuing is a Dekker-style mutual-visibility pattern: each side stores its own flag and then loads the peer's. Both legs must be seq_cst to forbid store-load reordering; anything weaker permits both sides to miss each other. The previous rte_atomic32_set/read compiled to plain volatile stores/loads and provided no such ordering, so this also closes a latent ordering hole on weakly-ordered ISAs.
The data-path exit store of while_queuing=0 is release, ordering preceding slot accesses before the control thread observes the data path as idle.
The flags started and dev_attached are consulted only inside update_queuing_status, where the per-queue handshake provides the real synchronization; their loads and stores are relaxed.
--- drivers/net/vhost/rte_eth_vhost.c | 92 +++++++++++++++++++------------ 1 file changed, 58 insertions(+), 34 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +58 -34
@@ -73,8 +73,8 @@ struct vhost_stats {struct vhost_queue {int vid; -rte_atomic32_t allow_queuing; -rte_atomic32_t while_queuing; +RTE_ATOMIC (uint32_t ) allow_queuing; +RTE_ATOMIC (uint32_t ) while_queuing;struct pmd_internal *internal;struct rte_mempool *mb_pool;uint16_t port;
@@ -86,14 +86,14 @@ struct vhost_queue { };struct pmd_internal { -rte_atomic32_t dev_attached; +RTE_ATOMIC (uint32_t ) dev_attached;char *iface_name;uint64_t flags;uint64_t disable_flags;uint64_t features;uint16_t max_queues;int vid; -rte_atomic32_t started; +RTE_ATOMIC (uint32_t ) started;bool vlan_strip;bool rx_sw_csum;bool tx_sw_csum;
@@ -406,12 +406,19 @@ eth_vhost_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)uint16_t i, nb_rx =0 ;uint16_t nb_receive = nb_bufs; -if (unlikely (rte_atomic32_read (&r->allow_queuing) ==0 )) +/* Fast-path early exit; racy load is fine here -- if we miss a +* transition we get caught by the seq_cst check below. +*/ +if (unlikely (rte_atomic_load_explicit (&r->allow_queuing, rte_memory_order_relaxed) ==0 ))return 0 ; -rte_atomic32_set (&r->while_queuing,1 ); - -if (unlikely (rte_atomic32_read (&r->allow_queuing) ==0 )) +/* Announce presence, then re-check. The store and the following +* load MUST both be seq_cst so they are totally ordered with the +* control thread's store-to-allow_queuing / load-of-while_queuing +* pair. Anything weaker permits both sides to miss each other. +*/ +rte_atomic_store_explicit (&r->while_queuing,1 , rte_memory_order_seq_cst); +if (unlikely (rte_atomic_load_explicit (&r->allow_queuing, rte_memory_order_seq_cst) ==0 )) goto out;/* Dequeue packets from guest TX queue */
@@ -446,7 +453,7 @@ eth_vhost_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) } out: -rte_atomic32_set (&r->while_queuing,0 ); +rte_atomic_store_explicit (&r->while_queuing,0 , rte_memory_order_release);return nb_rx; }
@@ -460,12 +467,19 @@ eth_vhost_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)uint64_t nb_bytes =0 ;uint64_t nb_missed =0 ; -if (unlikely (rte_atomic32_read (&r->allow_queuing) ==0 )) +/* Fast-path early exit; racy load is fine here -- if we miss a +* transition we get caught by the seq_cst check below. +*/ +if (unlikely (rte_atomic_load_explicit (&r->allow_queuing, rte_memory_order_relaxed) ==0 ))return 0 ; -rte_atomic32_set (&r->while_queuing,1 ); - -if (unlikely (rte_atomic32_read (&r->allow_queuing) ==0 )) +/* Announce presence, then re-check. The store and the following +* load MUST both be seq_cst so they are totally ordered with the +* control thread's store-to-allow_queuing / load-of-while_queuing +* pair. Anything weaker permits both sides to miss each other. +*/ +rte_atomic_store_explicit (&r->while_queuing,1 , rte_memory_order_seq_cst); +if (unlikely (rte_atomic_load_explicit (&r->allow_queuing, rte_memory_order_seq_cst) ==0 )) goto out;for (i =0 ; i < nb_bufs; i++) {
@@ -515,7 +529,7 @@ eth_vhost_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)for (i =0 ;likely (i < nb_tx); i++)rte_pktmbuf_free (bufs[i]); out: -rte_atomic32_set (&r->while_queuing,0 ); +rte_atomic_store_explicit (&r->while_queuing,0 , rte_memory_order_release);return nb_tx; }
@@ -756,8 +770,12 @@ update_queuing_status(struct rte_eth_dev *dev, bool wait_queuing)if (!dev->data->rx_queues || !dev->data->tx_queues)return ; -if (rte_atomic32_read (&internal->started) ==0 || -rte_atomic32_read (&internal->dev_attached) ==0 ) +/* These are control-plane flags consulted only here; +* the real data-path handshake is on vq->allow_queuing below. +* Relaxed is sufficient. +*/ +if (rte_atomic_load_explicit (&internal->started, rte_memory_order_relaxed) ==0 || +rte_atomic_load_explicit (&internal->dev_attached, rte_memory_order_relaxed) ==0 ) allow_queuing =0 ; state = vring_states[dev->data->port_id];
@@ -767,11 +785,13 @@ update_queuing_status(struct rte_eth_dev *dev, bool wait_queuing) vq = dev->data->rx_queues[i];if (vq ==NULL )continue ; -if (allow_queuing && state->cur[vq->virtqueue_id]) -rte_atomic32_set (&vq->allow_queuing,1 ); -else -rte_atomic32_set (&vq->allow_queuing,0 ); -while (wait_queuing &&rte_atomic32_read (&vq->while_queuing)) + +rte_atomic_store_explicit (&vq->allow_queuing, + (allow_queuing && state->cur[vq->virtqueue_id]), + rte_memory_order_seq_cst); + +while (wait_queuing && +rte_atomic_load_explicit (&vq->while_queuing, rte_memory_order_seq_cst))rte_pause (); }
@@ -779,11 +799,13 @@ update_queuing_status(struct rte_eth_dev *dev, bool wait_queuing) vq = dev->data->tx_queues[i];if (vq ==NULL )continue ; -if (allow_queuing && state->cur[vq->virtqueue_id]) -rte_atomic32_set (&vq->allow_queuing,1 ); -else -rte_atomic32_set (&vq->allow_queuing,0 ); -while (wait_queuing &&rte_atomic32_read (&vq->while_queuing)) + +rte_atomic_store_explicit (&vq->allow_queuing, + (allow_queuing && state->cur[vq->virtqueue_id]), + rte_memory_order_seq_cst); + +while (wait_queuing && +rte_atomic_load_explicit (&vq->while_queuing, rte_memory_order_seq_cst))rte_pause (); } }
@@ -848,7 +870,7 @@ new_device(int vid) } internal->vid = vid; -if (rte_atomic32_read (&internal->started) ==1 ) { +if (rte_atomic_load_explicit (&internal->started, rte_memory_order_relaxed) ==1 ) {queue_setup (eth_dev, internal);if (dev_conf->intr_conf.rxq)eth_vhost_configure_intr (eth_dev);
@@ -863,7 +885,7 @@ new_device(int vid)vhost_dev_csum_configure (eth_dev); -rte_atomic32_set (&internal->dev_attached,1 ); +rte_atomic_store_explicit (&internal->dev_attached,1 , rte_memory_order_relaxed);update_queuing_status (eth_dev, false);VHOST_LOG_LINE (INFO ,"Vhost device %d created" , vid);
@@ -893,7 +915,7 @@ destroy_device(int vid) eth_dev = list->eth_dev; internal = eth_dev->data->dev_private; -rte_atomic32_set (&internal->dev_attached,0 ); +rte_atomic_store_explicit (&internal->dev_attached,0 , rte_memory_order_relaxed);update_queuing_status (eth_dev, true);eth_vhost_unconfigure_intr (eth_dev);
@@ -1148,11 +1170,11 @@ eth_dev_start(struct rte_eth_dev *eth_dev) }queue_setup (eth_dev, internal); -if (rte_atomic32_read (&internal->dev_attached) ==1 && +if (rte_atomic_load_explicit (&internal->dev_attached, rte_memory_order_relaxed) ==1 && dev_conf->intr_conf.rxq)eth_vhost_configure_intr (eth_dev); -rte_atomic32_set (&internal->started,1 ); +rte_atomic_store_explicit (&internal->started,1 , rte_memory_order_relaxed);update_queuing_status (eth_dev, false);for (i =0 ; i < eth_dev->data->nb_rx_queues; i++)
@@ -1170,7 +1192,7 @@ eth_dev_stop(struct rte_eth_dev *dev)uint16_t i; dev->data->dev_started =0 ; -rte_atomic32_set (&internal->started,0 ); +rte_atomic_store_explicit (&internal->started,0 , rte_memory_order_relaxed);update_queuing_status (dev, true);for (i =0 ; i < dev->data->nb_rx_queues; i++)
@@ -1471,8 +1493,10 @@ vhost_dev_priv_dump(struct rte_eth_dev *dev, FILE *f)fprintf (f,"features: 0x%" PRIx64"\n" , internal->features);fprintf (f,"max_queues: %u\n" , internal->max_queues);fprintf (f,"vid: %d\n" , internal->vid); -fprintf (f,"started: %d\n" ,rte_atomic32_read (&internal->started)); -fprintf (f,"dev_attached: %d\n" ,rte_atomic32_read (&internal->dev_attached)); +fprintf (f,"started: %u\n" , +rte_atomic_load_explicit (&internal->started, rte_memory_order_relaxed)); +fprintf (f,"dev_attached: %u\n" , +rte_atomic_load_explicit (&internal->dev_attached, rte_memory_order_relaxed));fprintf (f,"vlan_strip: %d\n" , internal->vlan_strip);fprintf (f,"rx_sw_csum: %d\n" , internal->rx_sw_csum);fprintf (f,"tx_sw_csum: %d\n" , internal->tx_sw_csum);
Signature · 1 line
2.53.0
PATCH v7 22/24 vdpa/ifc: replace rte_atomic32 with stdatomic
In reply to Stephen HemmingerLast in-tree caller of rte_atomic32_*(), blocking deprecation of the rte_atomicNN_*() family.
Replace rte_atomic32_read/set() with rte_atomic_load_explicit() and rte_atomic_store_explicit() on the started, dev_attached, and running flags. Narrow them to bool (only ever hold 0/1) and group with the existing bools to reduce padding in struct ifcvf_internal.
--- drivers/vdpa/ifc/ifcvf_vdpa.c | 37 ++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 18 deletions(-)
drivers/vdpa/ifc/ifcvf_vdpa.c +19 -18
@@ -25,6 +25,7 @@#include <rte_log.h> #include <rte_kvargs.h> #include <rte_devargs.h> +#include <rte_stdatomic.h> #include "base/ifcvf.h"
@@ -68,10 +69,10 @@ struct ifcvf_internal {struct rte_vdpa_device *vdev;uint16_t max_queues;uint64_t features; -rte_atomic32_t started; -rte_atomic32_t dev_attached; -rte_atomic32_t running;rte_spinlock_t lock; +RTE_ATOMIC (bool ) started; +RTE_ATOMIC (bool ) dev_attached; +RTE_ATOMIC (bool ) running;bool sw_lm;bool sw_fallback_running;/* mediated vring for sw fallback */
@@ -712,9 +713,9 @@ update_datapath(struct ifcvf_internal *internal)rte_spinlock_lock (&internal->lock); -if (!rte_atomic32_read (&internal->running) && - (rte_atomic32_read (&internal->started) && -rte_atomic32_read (&internal->dev_attached))) { +if (!rte_atomic_load_explicit (&internal->running, rte_memory_order_seq_cst) && + (rte_atomic_load_explicit (&internal->started, rte_memory_order_seq_cst) && +rte_atomic_load_explicit (&internal->dev_attached, rte_memory_order_seq_cst))) { ret =ifcvf_dma_map (internal, true);if (ret) goto err;
@@ -735,10 +736,10 @@ update_datapath(struct ifcvf_internal *internal)if (ret) goto err; -rte_atomic32_set (&internal->running,1 ); - }else if (rte_atomic32_read (&internal->running) && - (!rte_atomic32_read (&internal->started) || - !rte_atomic32_read (&internal->dev_attached))) { +rte_atomic_store_explicit (&internal->running, true, rte_memory_order_seq_cst); + }else if (rte_atomic_load_explicit (&internal->running, rte_memory_order_seq_cst) && + (!rte_atomic_load_explicit (&internal->started, rte_memory_order_seq_cst) || + !rte_atomic_load_explicit (&internal->dev_attached, rte_memory_order_seq_cst))) {unset_intr_relay (internal); ret =unset_notify_relay (internal);
@@ -755,7 +756,7 @@ update_datapath(struct ifcvf_internal *internal)if (ret) goto err; -rte_atomic32_set (&internal->running,0 ); +rte_atomic_store_explicit (&internal->running, false, rte_memory_order_seq_cst); }rte_spinlock_unlock (&internal->lock);
@@ -1058,7 +1059,7 @@ ifcvf_sw_fallback_switchover(struct ifcvf_internal *internal)vdpa_disable_vfio_intr (internal); -rte_atomic32_set (&internal->running,0 ); +rte_atomic_store_explicit (&internal->running, false, rte_memory_order_seq_cst); ret =rte_vhost_host_notifier_ctrl (vid,RTE_VHOST_QUEUE_ALL , false);if (ret && ret != -ENOTSUP )
@@ -1113,11 +1114,11 @@ ifcvf_dev_config(int vid) internal = list->internal; internal->vid = vid; -rte_atomic32_set (&internal->dev_attached,1 ); +rte_atomic_store_explicit (&internal->dev_attached, true, rte_memory_order_seq_cst);if (update_datapath (internal) <0 ) {DRV_LOG (ERR ,"failed to update datapath for vDPA device %s" , vdev->device->name); -rte_atomic32_set (&internal->dev_attached,0 ); +rte_atomic_store_explicit (&internal->dev_attached, false, rte_memory_order_seq_cst);return -1 ; }
@@ -1166,7 +1167,7 @@ ifcvf_dev_close(int vid) internal->sw_fallback_running = false; }else { -rte_atomic32_set (&internal->dev_attached,0 ); +rte_atomic_store_explicit (&internal->dev_attached, false, rte_memory_order_seq_cst);if (update_datapath (internal) <0 ) {DRV_LOG (ERR ,"failed to update datapath for vDPA device %s" , vdev->device->name);
@@ -1782,10 +1783,10 @@ ifcvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, goto error; } -rte_atomic32_set (&internal->started,1 ); +rte_atomic_store_explicit (&internal->started, true, rte_memory_order_seq_cst);if (update_datapath (internal) <0 ) {DRV_LOG (ERR ,"failed to update datapath %s" , pci_dev->name); -rte_atomic32_set (&internal->started,0 ); +rte_atomic_store_explicit (&internal->started, false, rte_memory_order_seq_cst);rte_vdpa_unregister_device (internal->vdev);pthread_mutex_lock (&internal_list_lock);TAILQ_REMOVE (&internal_list, list, next);
@@ -1819,7 +1820,7 @@ ifcvf_pci_remove(struct rte_pci_device *pci_dev) } internal = list->internal; -rte_atomic32_set (&internal->started,0 ); +rte_atomic_store_explicit (&internal->started, false, rte_memory_order_seq_cst);if (update_datapath (internal) <0 )DRV_LOG (ERR ,"failed to update datapath %s" , pci_dev->name);
Signature · 1 line
2.53.0
PATCH v7 23/24 test/atomic: drop old rte_atomicNN tests
In reply to Stephen HemmingerThe rte_atomicNN_* APIs will be removed. Only the 128 bit compare-and-swap case test remains.
--- app/test/test_atomic.c | 523 +++-------------------------------------- 1 file changed, 29 insertions(+), 494 deletions(-)
app/test/test_atomic.c +29 -494
@@ -14,61 +14,23 @@#include <rte_per_lcore.h> #include <rte_launch.h> #include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_eal.h> #include <rte_lcore.h> #include <rte_pause.h> -#include <rte_random.h> -#include <rte_hash_crc.h> #include "test.h" #ifndef RTE_TOOLCHAIN_MSVC +/* +* The 128-bit compare and exchange is only implemented for +* x86_64 and aarch64 with GCC/Clang +*/ +#if defined(RTE_ARCH_X86_64 ) || defined(RTE_ARCH_ARM64 )/* * Atomic Variables * ================ * -* - The main test function performs several subtests. The first -* checks that the usual inc/dec/add/sub functions are working -* correctly: -* -* - Initialize 16-bit, 32-bit and 64-bit atomic variables to specific -* values. -* -* - These variables are incremented and decremented on each core at -* the same time in ``test_atomic_usual()``. -* -* - The function checks that once all lcores finish their function, -* the value of the atomic variables are still the same. -* -* - Test "test and set" functions. -* -* - Initialize 16-bit, 32-bit and 64-bit atomic variables to zero. -* -* - Invoke ``test_atomic_tas()`` on each lcore: before doing anything -* else. The cores are waiting a synchro using ``while -* (rte_atomic32_read(&val) == 0)`` which is triggered by the main test -* function. Then all cores do a -* ``rte_atomicXX_test_and_set()`` at the same time. If it is successful, -* it increments another atomic counter. -* -* - The main function checks that the atomic counter was incremented -* twice only (one for 16-bit, one for 32-bit and one for 64-bit values). -* -* - Test "add/sub and return" functions -* -* - Initialize 16-bit, 32-bit and 64-bit atomic variables to zero. -* -* - Invoke ``test_atomic_addsub_return()`` on each lcore. Before doing -* anything else, the cores are waiting a synchro. Each lcore does -* this operation several times:: -* -* tmp = rte_atomicXX_add_return(&a, 1); -* atomic_add(&count, tmp); -* tmp = rte_atomicXX_sub_return(&a, 1); -* atomic_sub(&count, tmp+1); -* -* - At the end of the test, the *count* value must be 0. -* * - Test "128-bit compare and swap" (aarch64 and x86_64 only) * * - Initialize 128-bit atomic variables to zero.
@@ -84,24 +46,8 @@* * - At the end of the test, the *count128* first 64-bit value and * second 64-bit value differ by the total iterations. -* -* - Test "atomic exchange" functions -* -* - Create a 64 bit token that can be tested for data integrity -* -* - Invoke ``test_atomic_exchange`` on each lcore. Before doing -* anything else, the cores wait for a synchronization event. -* Each core then does the following for N iterations: -* -* Generate a new token with a data integrity check -* Exchange the new token for previously generated token -* Increment a counter if a corrupt token was received -* -* - At the end of the test, the number of corrupted tokens must be 0. */ -#define NUM_ATOMIC_TYPES 3 -#define N_BASE 1000000u#define N_MIN 10000u
@@ -112,156 +58,8 @@*/ static unsigned int num_iterations; -static rte_atomic16_t a16; -static rte_atomic32_t a32; -static rte_atomic64_t a64; -static rte_atomic64_t count; -static rte_atomic32_t synchro; - -static int -test_atomic_usual(__rte_unused void *arg) -{ -unsigned int i; - -while (rte_atomic32_read (&synchro) ==0 ) -rte_pause (); - -for (i =0 ; i < num_iterations; i++) -rte_atomic16_inc (&a16); -for (i =0 ; i < num_iterations; i++) -rte_atomic16_dec (&a16); -for (i =0 ; i < (num_iterations /5 ); i++) -rte_atomic16_add (&a16,5 ); -for (i =0 ; i < (num_iterations /5 ); i++) -rte_atomic16_sub (&a16,5 ); - -for (i =0 ; i < num_iterations; i++) -rte_atomic32_inc (&a32); -for (i =0 ; i < num_iterations; i++) -rte_atomic32_dec (&a32); -for (i =0 ; i < (num_iterations /5 ); i++) -rte_atomic32_add (&a32,5 ); -for (i =0 ; i < (num_iterations /5 ); i++) -rte_atomic32_sub (&a32,5 ); - -for (i =0 ; i < num_iterations; i++) -rte_atomic64_inc (&a64); -for (i =0 ; i < num_iterations; i++) -rte_atomic64_dec (&a64); -for (i =0 ; i < (num_iterations /5 ); i++) -rte_atomic64_add (&a64,5 ); -for (i =0 ; i < (num_iterations /5 ); i++) -rte_atomic64_sub (&a64,5 ); - -return 0 ; -} - -static int -test_atomic_tas(__rte_unused void *arg) -{ -while (rte_atomic32_read (&synchro) ==0 ) -rte_pause (); - -if (rte_atomic16_test_and_set (&a16)) -rte_atomic64_inc (&count); -if (rte_atomic32_test_and_set (&a32)) -rte_atomic64_inc (&count); -if (rte_atomic64_test_and_set (&a64)) -rte_atomic64_inc (&count); - -return 0 ; -} - -static int -test_atomic_addsub_and_return(__rte_unused void *arg) -{ -uint32_t tmp16; -uint32_t tmp32; -uint64_t tmp64; -unsigned int i; - -while (rte_atomic32_read (&synchro) ==0 ) -rte_pause (); - -for (i =0 ; i < num_iterations; i++) { - tmp16 =rte_atomic16_add_return (&a16,1 ); -rte_atomic64_add (&count, tmp16); - - tmp16 =rte_atomic16_sub_return (&a16,1 ); -rte_atomic64_sub (&count, tmp16+1 ); - - tmp32 =rte_atomic32_add_return (&a32,1 ); -rte_atomic64_add (&count, tmp32); - - tmp32 =rte_atomic32_sub_return (&a32,1 ); -rte_atomic64_sub (&count, tmp32+1 ); - - tmp64 =rte_atomic64_add_return (&a64,1 ); -rte_atomic64_add (&count, tmp64); - - tmp64 =rte_atomic64_sub_return (&a64,1 ); -rte_atomic64_sub (&count, tmp64+1 ); - } - -return 0 ; -} - -/* -* rte_atomic32_inc_and_test() would increase a 32 bits counter by one and then -* test if that counter is equal to 0. It would return true if the counter is 0 -* and false if the counter is not 0. rte_atomic64_inc_and_test() could do the -* same thing but for a 64 bits counter. -* Here checks that if the 32/64 bits counter is equal to 0 after being atomically -* increased by one. If it is, increase the variable of "count" by one which would -* be checked as the result later. -* -*/ -static int -test_atomic_inc_and_test(__rte_unused void *arg) -{ -while (rte_atomic32_read (&synchro) ==0 ) -rte_pause (); - -if (rte_atomic16_inc_and_test (&a16)) { -rte_atomic64_inc (&count); - } -if (rte_atomic32_inc_and_test (&a32)) { -rte_atomic64_inc (&count); - } -if (rte_atomic64_inc_and_test (&a64)) { -rte_atomic64_inc (&count); - } - -return 0 ; -} - -/* -* rte_atomicXX_dec_and_test() should decrease a 32 bits counter by one and then -* test if that counter is equal to 0. It should return true if the counter is 0 -* and false if the counter is not 0. -* This test checks if the counter is equal to 0 after being atomically -* decreased by one. If it is, increase the value of "count" by one which is to -* be checked as the result later. -*/ -static int -test_atomic_dec_and_test(__rte_unused void *arg) -{ -while (rte_atomic32_read (&synchro) ==0 ) -rte_pause (); - -if (rte_atomic16_dec_and_test (&a16)) -rte_atomic64_inc (&count); - -if (rte_atomic32_dec_and_test (&a32)) -rte_atomic64_inc (&count); +static RTE_ATOMIC (uint32_t ) synchro; -if (rte_atomic64_dec_and_test (&a64)) -rte_atomic64_inc (&count); - -return 0 ; -} - -#if defined(RTE_ARCH_X86_64 ) || defined(RTE_ARCH_ARM64 )static rte_int128_t count128;/*
@@ -278,7 +76,7 @@ test_atomic128_cmp_exchange(__rte_unused void *arg)int success;unsigned int i; -while (rte_atomic32_read (&synchro) ==0 ) +while (rte_atomic_load_explicit (&synchro, rte_memory_order_relaxed) ==0 )rte_pause (); expected = count128;
@@ -292,7 +90,7 @@ test_atomic128_cmp_exchange(__rte_unused void *arg) success =rte_atomic128_cmp_exchange (&count128, &expected, &desired,1 , - __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); + rte_memory_order_acquire, rte_memory_order_relaxed); }while (success ==0 ); do {
@@ -303,7 +101,7 @@ test_atomic128_cmp_exchange(__rte_unused void *arg) success =rte_atomic128_cmp_exchange (&count128, &expected, &desired,1 , - __ATOMIC_RELEASE, __ATOMIC_RELAXED); + rte_memory_order_release, rte_memory_order_relaxed); }while (success ==0 ); do {
@@ -314,7 +112,7 @@ test_atomic128_cmp_exchange(__rte_unused void *arg) success =rte_atomic128_cmp_exchange (&count128, &expected, &desired,1 , - __ATOMIC_ACQ_REL, __ATOMIC_RELAXED); + rte_memory_order_acq_rel, rte_memory_order_relaxed); }while (success ==0 ); do {
@@ -325,260 +123,20 @@ test_atomic128_cmp_exchange(__rte_unused void *arg) success =rte_atomic128_cmp_exchange (&count128, &expected, &desired,1 , - __ATOMIC_RELAXED, __ATOMIC_RELAXED); + rte_memory_order_relaxed, rte_memory_order_relaxed); }while (success ==0 ); }return 0 ; } -#endif - -/* -* Helper definitions/variables/functions for -* atomic exchange tests -*/ -typedef union { -uint16_t u16; -uint8_t u8[2 ]; -}test16_t ; - -typedef union { -uint32_t u32; -uint16_t u16[2 ]; -uint8_t u8[4 ]; -}test32_t ; - -typedef union { -uint64_t u64; -uint32_t u32[2 ]; -uint16_t u16[4 ]; -uint8_t u8[8 ]; -}test64_t ; - -const uint8_t CRC8_POLY =0x91 ; -uint8_t crc8_table[256 ]; - -volatile uint16_t token16; -volatile uint32_t token32; -volatile uint64_t token64; - -static void -build_crc8_table (void ) -{ -uint8_t val; -int i, j; - -for (i =0 ; i <256 ; i++) { - val = i; -for (j =0 ; j <8 ; j++) { -if (val &1 ) - val ^=CRC8_POLY ; - val >>=1 ; - } - crc8_table[i] = val; - } -} - -static uint8_t -get_crc8 (uint8_t *message,int length) -{ -uint8_t crc =0 ; -int i; - -for (i =0 ; i < length; i++) - crc = crc8_table[crc ^ message[i]]; -return crc; -} - -/* -* The atomic exchange test sets up a token in memory and -* then spins up multiple lcores whose job is to generate -* new tokens, exchange that new token for the old one held -* in memory, and then verify that the old token is still -* valid (i.e. the exchange did not corrupt the token). -* -* A token is made up of random data and 8 bits of crc -* covering that random data. The following is an example -* of a 64bit token. -* -* +------------+------------+ -* | 63 56 | 55 0 | -* +------------+------------+ -* | CRC8 | Data | -* +------------+------------+ -*/ -static int -test_atomic_exchange(__rte_unused void *arg) -{ -unsigned int i; -test16_t nt16, ot16;/* new token, old token */ -test32_t nt32, ot32; -test64_t nt64, ot64; - -/* Wait until all of the other threads have been dispatched */ -while (rte_atomic32_read (&synchro) ==0 ) -rte_pause (); - -/* -* Let the battle begin! Every thread attempts to steal the current -* token with an atomic exchange operation and install its own newly -* generated token. If the old token is valid (i.e. it has the -* appropriate crc32 hash for the data) then the test iteration has -* passed. If the token is invalid, increment the counter. -*/ -for (i =0 ; i < num_iterations; i++) { -/* Test 64bit Atomic Exchange */ - nt64.u64 =rte_rand (); - nt64.u8[7 ] =get_crc8 (&nt64.u8[0 ],sizeof (nt64) -1 ); - ot64.u64 =rte_atomic64_exchange (&token64, nt64.u64); -if (ot64.u8[7 ] !=get_crc8 (&ot64.u8[0 ],sizeof (ot64) -1 )) -rte_atomic64_inc (&count); - -/* Test 32bit Atomic Exchange */ - nt32.u32 = (uint32_t )rte_rand (); - nt32.u8[3 ] =get_crc8 (&nt32.u8[0 ],sizeof (nt32) -1 ); - ot32.u32 =rte_atomic32_exchange (&token32, nt32.u32); -if (ot32.u8[3 ] !=get_crc8 (&ot32.u8[0 ],sizeof (ot32) -1 )) -rte_atomic64_inc (&count); - -/* Test 16bit Atomic Exchange */ - nt16.u16 = (uint16_t )rte_rand (); - nt16.u8[1 ] =get_crc8 (&nt16.u8[0 ],sizeof (nt16) -1 ); - ot16.u16 =rte_atomic16_exchange (&token16, nt16.u16); -if (ot16.u8[1 ] !=get_crc8 (&ot16.u8[0 ],sizeof (ot16) -1 )) -rte_atomic64_inc (&count); - } - -return 0 ; -}static int test_atomic (void ) { - num_iterations =test_scale_iterations (N_BASE ,N_MIN ); - -rte_atomic16_init (&a16); -rte_atomic32_init (&a32); -rte_atomic64_init (&a64); -rte_atomic64_init (&count); -rte_atomic32_init (&synchro); - -rte_atomic16_set (&a16,1UL <<10 ); -rte_atomic32_set (&a32,1UL <<10 ); -rte_atomic64_set (&a64,1ULL <<33 ); - -printf ("usual inc/dec/add/sub functions\n" ); - -rte_eal_mp_remote_launch (test_atomic_usual,NULL ,SKIP_MAIN ); -rte_atomic32_set (&synchro,1 ); -rte_eal_mp_wait_lcore (); -rte_atomic32_set (&synchro,0 ); - -if (rte_atomic16_read (&a16) !=1UL <<10 ) { -printf ("Atomic16 usual functions failed\n" ); -return -1 ; - } - -if (rte_atomic32_read (&a32) !=1UL <<10 ) { -printf ("Atomic32 usual functions failed\n" ); -return -1 ; - } - -if (rte_atomic64_read (&a64) !=1ULL <<33 ) { -printf ("Atomic64 usual functions failed\n" ); -return -1 ; - } - -printf ("test and set\n" ); - -rte_atomic64_set (&a64,0 ); -rte_atomic32_set (&a32,0 ); -rte_atomic16_set (&a16,0 ); -rte_atomic64_set (&count,0 ); -rte_eal_mp_remote_launch (test_atomic_tas,NULL ,SKIP_MAIN ); -rte_atomic32_set (&synchro,1 ); -rte_eal_mp_wait_lcore (); -rte_atomic32_set (&synchro,0 ); +uint64_t iterations; -if (rte_atomic64_read (&count) !=NUM_ATOMIC_TYPES ) { -printf ("Atomic test and set failed\n" ); -return -1 ; - } - -printf ("add/sub and return\n" ); - -rte_atomic64_set (&a64,0 ); -rte_atomic32_set (&a32,0 ); -rte_atomic16_set (&a16,0 ); -rte_atomic64_set (&count,0 ); -rte_eal_mp_remote_launch (test_atomic_addsub_and_return,NULL , -SKIP_MAIN ); -rte_atomic32_set (&synchro,1 ); -rte_eal_mp_wait_lcore (); -rte_atomic32_set (&synchro,0 ); - -if (rte_atomic64_read (&count) !=0 ) { -printf ("Atomic add/sub+return failed\n" ); -return -1 ; - } - -/* -* Set a64, a32 and a16 with the same value of minus "number of worker -* lcores", launch all worker lcores to atomically increase by one and -* test them respectively. -* Each lcore should have only one chance to increase a64 by one and -* then check if it is equal to 0, but there should be only one lcore -* that finds that it is 0. It is similar for a32 and a16. -* Then a variable of "count", initialized to zero, is increased by -* one if a64, a32 or a16 is 0 after being increased and tested -* atomically. -* We can check if "count" is finally equal to 3 to see if all worker -* lcores performed "atomic inc and test" right. -*/ -printf ("inc and test\n" ); - -rte_atomic64_clear (&a64); -rte_atomic32_clear (&a32); -rte_atomic16_clear (&a16); -rte_atomic32_clear (&synchro); -rte_atomic64_clear (&count); - -rte_atomic64_set (&a64, (int64_t )(1 - (int64_t )rte_lcore_count ())); -rte_atomic32_set (&a32, (int32_t )(1 - (int32_t )rte_lcore_count ())); -rte_atomic16_set (&a16, (int16_t )(1 - (int16_t )rte_lcore_count ())); -rte_eal_mp_remote_launch (test_atomic_inc_and_test,NULL ,SKIP_MAIN ); -rte_atomic32_set (&synchro,1 ); -rte_eal_mp_wait_lcore (); -rte_atomic32_clear (&synchro); - -if (rte_atomic64_read (&count) !=NUM_ATOMIC_TYPES ) { -printf ("Atomic inc and test failed %d\n" , (int )count.cnt); -return -1 ; - } - -/* -* Same as above, but this time we set the values to "number of worker -* lcores", and decrement instead of increment. -*/ -printf ("dec and test\n" ); - -rte_atomic32_clear (&synchro); -rte_atomic64_clear (&count); - -rte_atomic64_set (&a64, (int64_t )(rte_lcore_count () -1 )); -rte_atomic32_set (&a32, (int32_t )(rte_lcore_count () -1 )); -rte_atomic16_set (&a16, (int16_t )(rte_lcore_count () -1 )); -rte_eal_mp_remote_launch (test_atomic_dec_and_test,NULL ,SKIP_MAIN ); -rte_atomic32_set (&synchro,1 ); -rte_eal_mp_wait_lcore (); -rte_atomic32_clear (&synchro); - -if (rte_atomic64_read (&count) !=NUM_ATOMIC_TYPES ) { -printf ("Atomic dec and test failed\n" ); -return -1 ; - } + num_iterations =test_scale_iterations (N_BASE ,N_MIN ); -#if defined(RTE_ARCH_X86_64 ) || defined(RTE_ARCH_ARM64 )/* * This case tests the functionality of rte_atomic128_cmp_exchange * API. It calls rte_atomic128_cmp_exchange with four kinds of memory
@@ -591,58 +149,35 @@ test_atomic(void)* it is, the test passes. */ printf ("128-bit compare and swap test\n" ); -uint64_t iterations =0 ; -rte_atomic32_clear (&synchro); +rte_atomic_store_explicit (&synchro,0 , rte_memory_order_relaxed); count128.val[0 ] =0 ; count128.val[1 ] =0 ; -rte_eal_mp_remote_launch (test_atomic128_cmp_exchange,NULL , -SKIP_MAIN ); -rte_atomic32_set (&synchro,1 ); +rte_eal_mp_remote_launch (test_atomic128_cmp_exchange,NULL ,SKIP_MAIN ); +rte_atomic_store_explicit (&synchro,1 , rte_memory_order_relaxed);rte_eal_mp_wait_lcore (); -rte_atomic32_clear (&synchro); +rte_atomic_store_explicit (&synchro,0 , rte_memory_order_relaxed); iterations = count128.val[0 ] - count128.val[1 ]; -if (iterations != (uint64_t )4 *num_iterations*(rte_lcore_count ()-1 )) { +if (iterations != (uint64_t )4 * num_iterations * (rte_lcore_count () -1 )) {printf ("128-bit compare and swap failed\n" );return -1 ; } -#endif -/* -* Test 16/32/64bit atomic exchange. -*/ -test64_t t; - -printf ("exchange test\n" ); - -rte_atomic32_clear (&synchro); -rte_atomic64_clear (&count); - -/* Generate the CRC8 lookup table */ -build_crc8_table (); +return 0 ; +} -/* Create the initial tokens used by the test */ - t.u64 =rte_rand (); - token16 = (get_crc8 (&t.u8[0 ],sizeof (token16) -1 ) <<8 ) - | (t.u16[0 ] &0x00ff ); - token32 = ((uint32_t )get_crc8 (&t.u8[0 ],sizeof (token32) -1 ) <<24 ) - | (t.u32[0 ] &0x00ffffff ); - token64 = ((uint64_t )get_crc8 (&t.u8[0 ],sizeof (token64) -1 ) <<56 ) - | (t.u64 &0x00ffffffffffffff ); +#else -rte_eal_mp_remote_launch (test_atomic_exchange,NULL ,SKIP_MAIN ); -rte_atomic32_set (&synchro,1 ); -rte_eal_mp_wait_lcore (); -rte_atomic32_clear (&synchro); +static int +test_atomic (void ) +{ +printf ("128 bit exchange not implemented\n" ); +return TEST_SKIPPED ; +} -if (rte_atomic64_read (&count) >0 ) { -printf ("Atomic exchange test failed\n" ); -return -1 ; - } +#endif - return 0; -}REGISTER_FAST_TEST (atomic_autotest,NOHUGE_SKIP ,ASAN_OK , test_atomic);#endif /* RTE_TOOLCHAIN_MSVC */
Signature · 1 line
2.53.0
PATCH v7 24/24 eal: remove rte_atomicNN functions
In reply to Stephen HemmingerNow that all the drivers and other code have been converted to use stdatomic, the functions for rte_atomic16, rte_atomic32, and rte_atomic64 can be removed.
--- devtools/checkpatches.sh | 8 - doc/guides/rel_notes/deprecation.rst | 7 - doc/guides/rel_notes/release_26_11.rst | 7 + lib/eal/arm/include/rte_atomic_32.h | 4 - lib/eal/arm/include/rte_atomic_64.h | 4 - lib/eal/include/generic/rte_atomic.h | 928 ------------------------- lib/eal/loongarch/include/rte_atomic.h | 4 - lib/eal/ppc/include/rte_atomic.h | 175 ----- lib/eal/riscv/include/rte_atomic.h | 4 - lib/eal/x86/include/meson.build | 1 - lib/eal/x86/include/rte_atomic.h | 187 +---- lib/eal/x86/include/rte_atomic_32.h | 212 ------ lib/eal/x86/include/rte_atomic_64.h | 157 ----- 13 files changed, 8 insertions(+), 1690 deletions(-) delete mode 100644 lib/eal/x86/include/rte_atomic_32.h
devtools/checkpatches.sh +0 -8
@@ -121,14 +121,6 @@ check_forbidden_additions() { # <patch> -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ "$1" || res=1 - # refrain from new additions of 16/32/64 bits rte_atomicNN_xxx() - awk -v FOLDERS="lib drivers app examples" \ - -v EXPRESSIONS="rte_atomic[0-9][0-9]_.*\\\(" \ - -v RET_ON_FAIL=1 \ - -v MESSAGE='Using rte_atomicNN_xxx' \ - -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ - "$1" || res=1 - # refrain from new additions of rte_smp_[r/w]mb() awk -v FOLDERS="lib drivers app examples" \ -v EXPRESSIONS="rte_smp_(r|w)?mb\\\(" \
doc/guides/rel_notes/deprecation.rst +0 -7
@@ -39,13 +39,6 @@ Deprecation Notices as part of its internal API. All drivers will be adjusted to use the new unified VFIO container device assignment API. -* rte_atomicNN_xxx: These APIs do not take memory order parameter. This does - not allow for writing optimized code for all the CPU architectures supported - in DPDK. DPDK has adopted the atomic operations from - https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html. These - operations must be used for patches that need to be merged in 20.08 onwards. - This change will not introduce any performance degradation. - * rte_smp_*mb: These APIs provide full barrier functionality. However, many use cases do not require full barriers. To support such use cases, DPDK has adopted atomic operations from
doc/guides/rel_notes/release_26_11.rst +7 -0
@@ -77,6 +77,13 @@ Removed Items ``rte_rib6_is_equal`` * table: ``RTE_LPM_IPV6_ADDR_SIZE`` +* Removed the ``rte_atomicNN_t`` types and the ``rte_atomicNN_*`` functions + (16, 32 and 64 bit variants of ``init``, ``read``, ``set``, ``add``, + ``sub``, ``inc``, ``dec``, ``add_return``, ``sub_return``, + ``inc_and_test``, ``dec_and_test``, ``test_and_set``, ``clear``, + ``cmpset`` and ``exchange``). Use the C11 ``rte_atomic_*_explicit`` + operations instead. + API Changes -----------
lib/eal/arm/include/rte_atomic_32.h +0 -4
@@ -5,10 +5,6 @@#ifndef _RTE_ATOMIC_ARM32_H_#define _RTE_ATOMIC_ARM32_H_ -#ifndef RTE_FORCE_INTRINSICS -# error Platform must be built with RTE_FORCE_INTRINSICS -#endif -#include "generic/rte_atomic.h" #ifdef __cplusplus
lib/eal/arm/include/rte_atomic_64.h +0 -4
@@ -6,10 +6,6 @@#ifndef _RTE_ATOMIC_ARM64_H_#define _RTE_ATOMIC_ARM64_H_ -#ifndef RTE_FORCE_INTRINSICS -# error Platform must be built with RTE_FORCE_INTRINSICS -#endif -#include "generic/rte_atomic.h" #include <rte_branch_prediction.h> #include <rte_debug.h>
lib/eal/include/generic/rte_atomic.h +0 -928
934 lines not on this page · raw message
lib/eal/loongarch/include/rte_atomic.h +0 -4
@@ -5,10 +5,6 @@#ifndef RTE_ATOMIC_LOONGARCH_H #define RTE_ATOMIC_LOONGARCH_H -#ifndef RTE_FORCE_INTRINSICS -# error Platform must be built with RTE_FORCE_INTRINSICS -#endif -#include <rte_common.h> #include "generic/rte_atomic.h"
lib/eal/ppc/include/rte_atomic.h +0 -175
181 lines not on this page · raw message
lib/eal/riscv/include/rte_atomic.h +0 -4
@@ -8,10 +8,6 @@#ifndef RTE_ATOMIC_RISCV_H #define RTE_ATOMIC_RISCV_H -#ifndef RTE_FORCE_INTRINSICS -# error Platform must be built with RTE_FORCE_INTRINSICS -#endif -#include <stdint.h> #include <rte_common.h> #include <rte_config.h>
lib/eal/x86/include/meson.build +0 -1
@@ -17,7 +17,6 @@ dpdk_arch_headers += files( 'rte_vect.h', ) dpdk_arch_indirect_headers += files( - 'rte_atomic_32.h', 'rte_atomic_64.h', 'rte_byteorder_32.h', 'rte_byteorder_64.h',
lib/eal/x86/include/rte_atomic.h +1 -186
193 lines not on this page · raw message
lib/eal/x86/include/rte_atomic_32.h deleted +0 -212
212 lines not on this page · raw message
lib/eal/x86/include/rte_atomic_64.h +0 -157
163 lines not on this page · raw message
Signature · 1 line
2.53.0
RE: [PATCH v7 00/24] remove legacy atomic functions
In reply to Stephen HemmingerQuoted 12 lines
From: Stephen Hemminger [mailto:[email protected]]
Sent: Thursday, 6 August 2026 05.23The rte_atomicNN_* family was flagged for deprecation in 2021 by commit
3ec965b6de12("doc: update atomic operation deprecation") but removal had stalled and usage contined to grow.This series finishes converting every remaining in-tree caller to the C11-style rte_atomic_*_explicit() /
RTE_ATOMIC()API, then removes the legacy functions. The deprecation has been out there long enough so not a big surprise to users.
v8 cover remove legacy atomic functions
In reply to Stephen HemmingerThe rte_atomicNN_* family was flagged for deprecation in 2021 by commit 3ec965b6de12 ("doc: update atomic operation deprecation") but removal had stalled and usage continued to grow.
This series finishes converting every remaining in-tree caller to the C11-style rte_atomic_*_explicit() / RTE_ATOMIC() API, then removes the legacy functions. The deprecation has been out there long enough so not a big surprise to users.
v8 - drop unused in_use flag in dpaa
- consolidate fslmc changes
- vmbus: use acquire ordering on the wait for the previous producer so an earlier producer's data writes are carried by this thread's release store (Long Li)
- collect review tags
- more AI review comments
v7 - fix some review comments
- remove unused macros
- remove ret_atomicNN functions (rather than deprecating them).
v6 - rebase for 26.11
- address some more AI review comments
Stephen Hemminger (25):
bpf: use C11 atomics in BPF_ST_ATOMIC_REG net/bonding: use stdatomic
net/nbl: remove unused rte_atomic16 field net/ena: replace use of rte_atomicNN net/failsafe: convert to stdatomic
net/enic: do not use deprecated rte_atomic64 net/pfe: use ethdev linkstatus helpers net/sfc: replace rte_atomic with stdatomic crypto/ccp: replace use of rte_atomic64 with stdatomic bus/dpaa: remove unused in_use field bus/dpaa: replace rte_atomic16 with stdatomic bus/fslmc: replace rte_atomic with stdatomic common/dpaax: remove unused atomic wrappers net/netvsc: replace rte_atomic32 with stdatomic event/sw: convert from rte_atomic32 to stdatomic bus/vmbus: convert from rte_atomic to stdatomic net/bnx2x: convert from rte_atomic32 to stdatomic drivers/event: replace rte_atomic32 in selftests net/hinic: replace rte_atomic32 with stdatomic net/txgbe: replace rte_atomic32 with stdatomic net/vhost: use stdatomic for state flags net/vhost: use stdatomic instead of rte_atomic32 vdpa/ifc: replace rte_atomic32 with stdatomic test/atomic: drop old rte_atomicNN tests
eal: remove rte_atomicNN functions
app/test/test_atomic.c | 523 +--------- devtools/checkpatches.sh | 8 - .../prog_guide/writing_efficient_code.rst | 9 +- doc/guides/rel_notes/deprecation.rst | 7 - doc/guides/rel_notes/release_26_11.rst | 7 + drivers/bus/dpaa/base/qbman/bman.c | 7 +- drivers/bus/dpaa/base/qbman/qman.c | 9 +- drivers/bus/fslmc/portal/dpaa2_hw_dpbp.c | 11 +- drivers/bus/fslmc/portal/dpaa2_hw_dpci.c | 11 +- drivers/bus/fslmc/portal/dpaa2_hw_dpcon.c | 11 +- drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 14 +- drivers/bus/fslmc/portal/dpaa2_hw_pvt.h | 9 +- drivers/bus/fslmc/qbman/include/compat.h | 18 +- drivers/bus/vmbus/private.h | 2 +- drivers/bus/vmbus/vmbus_bufring.c | 40 +- drivers/common/dpaax/compat.h | 14 - drivers/crypto/ccp/ccp_crypto.c | 11 +- drivers/crypto/ccp/ccp_crypto.h | 2 +- drivers/crypto/ccp/ccp_dev.c | 10 +- drivers/crypto/ccp/ccp_dev.h | 4 +- drivers/event/dpaa2/dpaa2_eventdev_selftest.c | 26 +- drivers/event/octeontx/ssovf_evdev_selftest.c | 57 +- drivers/event/sw/sw_evdev.c | 8 +- drivers/event/sw/sw_evdev.h | 4 +- drivers/event/sw/sw_evdev_worker.c | 16 +- drivers/net/bnx2x/bnx2x.c | 6 +- drivers/net/bnx2x/bnx2x.h | 2 +- drivers/net/bnx2x/ecore_sp.c | 6 +- drivers/net/bonding/eth_bond_8023ad_private.h | 6 +- drivers/net/bonding/rte_eth_bond_8023ad.c | 35 +- drivers/net/ena/base/ena_plat_dpdk.h | 14 +- drivers/net/ena/ena_ethdev.c | 21 +- drivers/net/ena/ena_ethdev.h | 7 +- drivers/net/enic/enic.h | 6 +- drivers/net/enic/enic_compat.h | 1 - drivers/net/enic/enic_main.c | 17 +- drivers/net/enic/enic_rxtx.c | 14 +- drivers/net/enic/enic_rxtx_vec_avx2.c | 4 +- drivers/net/failsafe/failsafe_ops.c | 12 +- drivers/net/failsafe/failsafe_private.h | 29 +- drivers/net/failsafe/failsafe_rxtx.c | 2 +- drivers/net/hinic/base/hinic_compat.h | 2 +- drivers/net/hinic/base/hinic_pmd_hwdev.c | 24 +- drivers/net/hinic/base/hinic_pmd_hwdev.h | 4 +- drivers/net/nbl/nbl_hw/nbl_resource.h | 1 - drivers/net/netvsc/hn_rndis.c | 28 +- drivers/net/netvsc/hn_rxtx.c | 12 +- drivers/net/netvsc/hn_var.h | 6 +- drivers/net/pfe/pfe_ethdev.c | 32 +- drivers/net/sfc/sfc.c | 9 +- drivers/net/sfc/sfc.h | 4 +- drivers/net/sfc/sfc_port.c | 7 +- drivers/net/sfc/sfc_stats.h | 2 +- drivers/net/txgbe/base/txgbe_mng.c | 4 +- drivers/net/txgbe/base/txgbe_type.h | 2 +- drivers/net/vhost/rte_eth_vhost.c | 92 +- drivers/vdpa/ifc/ifcvf_vdpa.c | 37 +- lib/bpf/bpf_exec.c | 13 +- lib/eal/arm/include/rte_atomic_32.h | 4 - lib/eal/arm/include/rte_atomic_64.h | 4 - lib/eal/include/generic/rte_atomic.h | 928 ------------------ lib/eal/loongarch/include/rte_atomic.h | 4 - lib/eal/ppc/include/rte_atomic.h | 175 ---- lib/eal/riscv/include/rte_atomic.h | 4 - lib/eal/x86/include/meson.build | 1 - lib/eal/x86/include/rte_atomic.h | 187 +--- lib/eal/x86/include/rte_atomic_32.h | 212 ---- lib/eal/x86/include/rte_atomic_64.h | 157 --- 68 files changed, 416 insertions(+), 2559 deletions(-) delete mode 100644 lib/eal/x86/include/rte_atomic_32.h
Signature · 1 line
2.53.0
PATCH v8 1/25 bpf: use C11 atomics in BPF_ST_ATOMIC_REG
The BPF_ST_ATOMIC_REG macro generated code with deprecated rte_atomicNN_add and rte_atomicNN_exchange.
Replace this with the equivalent rte_stdatomic definitions. Use memory order seq_cst to preserve the previous behavior of rte_atomicNN_add() / rte_atomicNN_exchange() and match the behavior of the Linux kernel BPF interpreter for these opcodes.
--- lib/bpf/bpf_exec.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
lib/bpf/bpf_exec.c +7 -6
@@ -11,6 +11,7 @@#include <rte_debug.h> #include <rte_byteorder.h> #include <rte_errno.h> +#include <rte_stdatomic.h> #include "bpf_impl.h"
@@ -66,16 +67,16 @@ (type)(reg)[(ins)->src_reg])#define BPF_ST_ATOMIC_REG (reg, ins, tp) do { \ + RTE_ATOMIC(uint##tp##_t) *dst = (RTE_ATOMIC(uint##tp##_t) *) \ + (uintptr_t)((reg)[(ins)->dst_reg] + (ins)->off); \ switch (ins->imm) { \ case BPF_ATOMIC_ADD: \ - rte_atomic##tp##_add((rte_atomic##tp##_t *) \ - (uintptr_t)((reg)[(ins)->dst_reg] + (ins)->off), \ - (reg)[(ins)->src_reg]); \ + rte_atomic_fetch_add_explicit(dst, \ + (reg)[(ins)->src_reg], rte_memory_order_seq_cst); \ break; \ case BPF_ATOMIC_XCHG: \ - (reg)[(ins)->src_reg] = rte_atomic##tp##_exchange((uint##tp##_t *) \ - (uintptr_t)((reg)[(ins)->dst_reg] + (ins)->off), \ - (reg)[(ins)->src_reg]); \ + (reg)[(ins)->src_reg] = rte_atomic_exchange_explicit(dst, \ + (reg)[(ins)->src_reg], rte_memory_order_seq_cst); \ break; \ default: \/* this should be caught by validator and never reach here */ \
Signature · 1 line
2.53.0
PATCH v8 2/25 net/bonding: use stdatomic
In reply to Stephen HemmingerThe old rte_atomic16 and rte_atomic64 functions are deprecated. Replace with rte_stdatomic for managing warning and timer flags.
--- drivers/net/bonding/eth_bond_8023ad_private.h | 6 ++-- drivers/net/bonding/rte_eth_bond_8023ad.c | 35 ++++++++----------- 2 files changed, 17 insertions(+), 24 deletions(-)
drivers/net/bonding/eth_bond_8023ad_private.h +3 -3
@@ -9,7 +9,7 @@#include <rte_ether.h> #include <rte_byteorder.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_flow.h> #include "rte_eth_bond_8023ad.h"
@@ -140,10 +140,10 @@ struct port {/** Timer which is also used as mutex. If is 0 (not running) RX marker * packet might be responded. Otherwise shall be dropped. It is zeroed in * mode 4 callback function after expire. */ -volatile uint64_t rx_marker_timer; +RTE_ATOMIC (uint64_t ) rx_marker_timer;uint64_t warning_timer; -volatile uint16_t warnings_to_show; +RTE_ATOMIC (uint16_t ) warnings_to_show;/** Memory pool used to allocate slow queues */ struct rte_mempool *slow_pool;
drivers/net/bonding/rte_eth_bond_8023ad.c +14 -21
@@ -171,27 +171,17 @@ timer_is_running(uint64_t *timer)static void set_warning_flags (struct port *port,uint16_t flags) { -int retval; -uint16_t old; -uint16_t new_flag =0 ; - -do { - old = port->warnings_to_show; - new_flag = old | flags; - retval =rte_atomic16_cmpset (&port->warnings_to_show, old, new_flag); - }while (unlikely (retval ==0 )); +rte_atomic_fetch_or_explicit (&port->warnings_to_show, flags, rte_memory_order_relaxed); }static void show_warnings (uint16_t member_id) {struct port *port = &bond_mode_8023ad_ports[member_id]; -uint8_t warnings; - -do { - warnings = port->warnings_to_show; - }while (rte_atomic16_cmpset (&port->warnings_to_show, warnings,0 ) ==0 ); +uint16_t warnings; + warnings =rte_atomic_exchange_explicit (&port->warnings_to_show,0 , + rte_memory_order_relaxed);if (!warnings)return ;
@@ -1335,7 +1325,6 @@ bond_mode_8023ad_handle_slow_pkt(struct bond_dev_private *internals,struct port *port = &bond_mode_8023ad_ports[member_id];struct marker_header *m_hdr;uint64_t marker_timer, old_marker_timer; -int retval;uint8_t wrn, subtype;/* If packet is a marker, we send response now by reusing given packet * and update only source MAC, destination MAC is multicast so don't
@@ -1352,17 +1341,19 @@ bond_mode_8023ad_handle_slow_pkt(struct bond_dev_private *internals, }/* Setup marker timer. Do it in loop in case concurrent access. */ + old_marker_timer =rte_atomic_load_explicit (&port->rx_marker_timer, + rte_memory_order_acquire);do { - old_marker_timer = port->rx_marker_timer;if (!timer_is_expired (&old_marker_timer)) { wrn =WRN_RX_MARKER_TO_FAST ; goto free_out; }timer_set (&marker_timer, mode4->rx_marker_timeout); - retval =rte_atomic64_cmpset (&port->rx_marker_timer, - old_marker_timer, marker_timer); - }while (unlikely (retval ==0 )); + + }while (!rte_atomic_compare_exchange_weak_explicit (&port->rx_marker_timer, + &old_marker_timer, marker_timer, + rte_memory_order_release, rte_memory_order_acquire)); m_hdr->marker.tlv_type_marker =MARKER_TLV_TYPE_RESP ;rte_eth_macaddr_get (member_id, &m_hdr->eth_hdr.src_addr);
@@ -1370,7 +1361,8 @@ bond_mode_8023ad_handle_slow_pkt(struct bond_dev_private *internals,if (internals->mode4.dedicated_queues.enabled ==0 ) {if (rte_ring_enqueue (port->tx_ring, pkt) !=0 ) {/* reset timer */ - port->rx_marker_timer =0 ; +rte_atomic_store_explicit (&port->rx_marker_timer,0 , + rte_memory_order_release); wrn =WRN_TX_QUEUE_FULL ; goto free_out; }
@@ -1384,7 +1376,8 @@ bond_mode_8023ad_handle_slow_pkt(struct bond_dev_private *internals, &pkt, tx_count);if (tx_count !=1 ) {/* reset timer */ - port->rx_marker_timer =0 ; +rte_atomic_store_explicit (&port->rx_marker_timer,0 , + rte_memory_order_release); wrn =WRN_TX_QUEUE_FULL ; goto free_out; }
Signature · 1 line
2.53.0
PATCH v8 3/25 net/nbl: remove unused rte_atomic16 field
In reply to Stephen HemmingerThe tx_current_queue was defined as rte_atomic16_t which is deprecated. Remove it since it was never used.
--- drivers/net/nbl/nbl_hw/nbl_resource.h | 1 - 1 file changed, 1 deletion(-)
drivers/net/nbl/nbl_hw/nbl_resource.h +0 -1
@@ -225,7 +225,6 @@ struct nbl_res_info {u16 base_qid;u16 lcore_max;u16 *pf_qid_to_lcore_id; -rte_atomic16_t tx_current_queue; };struct nbl_resource_mgt {
Signature · 1 line
2.53.0
PATCH v8 4/25 net/ena: replace use of rte_atomicNN
In reply to Stephen HemmingerConvert the legacy rte_atomicNN operations to stdatomic.
* Remove variable ena_alloc_cnt is defined by not used. It is a leftover from previous memzone naming scheme.
* Convert the legacy rte_atomic32_t and rte_atomic32_{inc,dec,set,read} macros to C11 stdatomic equivalents.
Memory ordering is kept at seq_cst,
matching the implicit ordering of the legacy API.
* Do not use rte_atomic for statistics
The DPDK PMD model is that statistics do not have to be exact in face of contention.
--- drivers/net/ena/base/ena_plat_dpdk.h | 14 +++++++++----- drivers/net/ena/ena_ethdev.c | 21 ++++++--------------- drivers/net/ena/ena_ethdev.h | 7 +++---- 3 files changed, 18 insertions(+), 24 deletions(-)
drivers/net/ena/base/ena_plat_dpdk.h +9 -5
@@ -40,7 +40,7 @@ typedef uint64_t dma_addr_t;#endif #define ENA_PRIu64 PRIu64 -#define ena_atomic32_t rte_atomic32_t +typedef RTE_ATOMIC (int32_t )ena_atomic32_t ;#define ena_mem_handle_t const struct rte_memzone *#define SZ_256 (256U)
@@ -267,10 +267,14 @@ ena_mem_alloc_coherent(struct rte_eth_dev_data *data, size_t size,#define ENA_REG_READ32 (bus, reg) \ __extension__ ({ (void)(bus); rte_read32_relaxed((reg)); }) -#define ATOMIC32_INC (i32_ptr) rte_atomic32_inc(i32_ptr) -#define ATOMIC32_DEC (i32_ptr) rte_atomic32_dec(i32_ptr) -#define ATOMIC32_SET (i32_ptr, val) rte_atomic32_set(i32_ptr, val) -#define ATOMIC32_READ (i32_ptr) rte_atomic32_read(i32_ptr) +#define ATOMIC32_INC (i32_ptr) \ + rte_atomic_fetch_add_explicit((i32_ptr), 1, rte_memory_order_seq_cst) +#define ATOMIC32_DEC (i32_ptr) \ + rte_atomic_fetch_sub_explicit((i32_ptr), 1, rte_memory_order_seq_cst) +#define ATOMIC32_SET (i32_ptr, val) \ + rte_atomic_store_explicit((i32_ptr), (val), rte_memory_order_seq_cst) +#define ATOMIC32_READ (i32_ptr) \ + rte_atomic_load_explicit((i32_ptr), rte_memory_order_seq_cst)#define msleep (x) rte_delay_us(x * 1000)#define udelay (x) rte_delay_us(x)
drivers/net/ena/ena_ethdev.c +6 -15
@@ -121,12 +121,6 @@ struct ena_stats {*/ #define ENA_DEVARG_ENABLE_FRAG_BYPASS "enable_frag_bypass" -/* -* Each rte_memzone should have unique name. -* To satisfy it, count number of allocation and add it to name. -*/ -rte_atomic64_t ena_alloc_cnt; -static const struct ena_stats ena_stats_global_strings[] = {ENA_STAT_GLOBAL_ENTRY (wd_expired),ENA_STAT_GLOBAL_ENTRY (dev_start),
@@ -1249,10 +1243,7 @@ static void ena_stats_restart(struct rte_eth_dev *dev) {struct ena_adapter *adapter = dev->data->dev_private; -rte_atomic64_init (&adapter->drv_stats->ierrors); -rte_atomic64_init (&adapter->drv_stats->oerrors); -rte_atomic64_init (&adapter->drv_stats->rx_nombuf); - adapter->drv_stats->rx_drops =0 ; +memset (adapter->drv_stats,0 ,sizeof (struct ena_driver_stats )); } static int ena_stats_get(struct rte_eth_dev *dev,
@@ -1289,9 +1280,9 @@ static int ena_stats_get(struct rte_eth_dev *dev,/* Driver related stats */ stats->imissed = adapter->drv_stats->rx_drops; - stats->ierrors =rte_atomic64_read (&adapter->drv_stats->ierrors); - stats->oerrors =rte_atomic64_read (&adapter->drv_stats->oerrors); - stats->rx_nombuf =rte_atomic64_read (&adapter->drv_stats->rx_nombuf); + stats->ierrors = adapter->drv_stats->ierrors; + stats->oerrors = adapter->drv_stats->oerrors; + stats->rx_nombuf = adapter->drv_stats->rx_nombuf;/* Queue statistics */ if (qstats) {
@@ -1887,7 +1878,7 @@ static int ena_populate_rx_queue(struct ena_ring *rxq, unsigned int count)/* get resources for incoming packets */ rc =rte_pktmbuf_alloc_bulk (rxq->mb_pool, mbufs, count);if (unlikely (rc <0 )) { -rte_atomic64_inc (&rxq->adapter->drv_stats->rx_nombuf); + ++rxq->adapter->drv_stats->rx_nombuf; ++rxq->rx_stats.mbuf_alloc_fail;PMD_RX_LOG_LINE (DEBUG ,"There are not enough free buffers" );return 0 ;
@@ -3014,7 +3005,7 @@ static uint16_t eth_ena_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,if (unlikely (mbuf->ol_flags & (RTE_MBUF_F_RX_IP_CKSUM_BAD |RTE_MBUF_F_RX_L4_CKSUM_BAD ))) -rte_atomic64_inc (&rx_ring->adapter->drv_stats->ierrors); + ++rx_ring->adapter->drv_stats->ierrors; rx_pkts[completed] = mbuf; rx_ring->rx_stats.bytes += mbuf->pkt_len;
drivers/net/ena/ena_ethdev.h +3 -4
@@ -6,7 +6,6 @@#ifndef _ENA_ETHDEV_H_#define _ENA_ETHDEV_H_ -#include <rte_atomic.h> #include <rte_ether.h> #include <ethdev_driver.h> #include <ethdev_pci.h>
@@ -225,9 +224,9 @@ enum ena_adapter_state { };struct ena_driver_stats { -rte_atomic64_t ierrors; -rte_atomic64_t oerrors; -rte_atomic64_t rx_nombuf; +u64 ierrors; +u64 oerrors; +u64 rx_nombuf;u64 rx_drops; };
Signature · 1 line
2.53.0
Re: [PATCH v8 04/25] net/ena: replace use of rte_atomicNN
Quoted 5 lines · Stephen Hemminger
Convert the legacy
rte_atomicNNoperations to stdatomic.
* Remove variableena_alloc_cntis defined by not used. It is a leftover from previous memzone naming scheme.
Quoted 8 lines
* Convert the legacy
rte_atomic32_tand rte_atomic32_{inc,dec,set,read} macros to C11 stdatomic equivalents.
Memory ordering is kept atseq_cst,
matching the implicit ordering of the legacy API.* Do not use
rte_atomicfor statistics
The DPDK PMD model is that statistics do not have to be exact in face of contention.
AI complains about the change:
"""
While the DPDK guidelines do accept that statistics may be approximate under contention, the problem here is that **concurrent non-atomic increments are undefined behavior in C**. Multiple Rx queues (each potentially on different lcores) can increment ierrors simultaneously. A non-atomic ++ involves a read-modify-write sequence that is not atomic, leading to:
- Lost updates (the classic lost-update problem)
- Potential torn reads/writes on some architectures
The correct approach would be to use rte_atomic_fetch_add_explicit() with rte_memory_order_relaxed. Relaxed ordering is appropriate for statistics counters where approximate values are acceptable, but the operation must still be atomic to avoid undefined behavior. """
Signature · 1 line
David Marchand
Re: [PATCH v8 04/25] net/ena: replace use of rte_atomicNN
Quoted 27 lines · On Tue, 29 Sep 2026 10:07:09 +0200 David Marchand <[email protected]>…
Quoted 5 lines · Stephen Hemminger
Convert the legacy
rte_atomicNNoperations to stdatomic.
* Remove variableena_alloc_cntis defined by not used. It is a leftover from previous memzone naming scheme.Quoted 8 lines
* Convert the legacy
rte_atomic32_tand rte_atomic32_{inc,dec,set,read} macros to C11 stdatomic equivalents.
Memory ordering is kept atseq_cst,
matching the implicit ordering of the legacy API.* Do not use
rte_atomicfor statistics
The DPDK PMD model is that statistics do not have to be exact in face of contention.AI complains about the change:
"""
While the DPDK guidelines do accept that statistics may be approximate under contention, the problem here is that **concurrent non-atomic increments are undefined behavior in C**. Multiple Rx queues (each potentially on different lcores) can incrementierrorssimultaneously. A non-atomic++involves a read-modify-write sequence that is not atomic, leading to:
- Lost updates (the classic lost-update problem)
- Potential torn reads/writes on some architectures
Quoted 6 lines
The correct approach would be to use
rte_atomic_fetch_add_explicit()withrte_memory_order_relaxed. Relaxed ordering is appropriate for statistics counters where approximate values are acceptable, but the operation must still be atomic to avoid undefined behavior. """
AI wants all DPDK statistics to use atomic, but that is not the model we use in DPDK. DPDK trades off performance for the potential for inexact statistics. The commit message says that.
This is a false positive.
PATCH v8 5/25 net/failsafe: convert to stdatomic
In reply to Stephen HemmingerThe functions rte_atomic64 are deprecated, convert this code to use stdatomic for reference count. Use the memory order implied by naming P/V.
No need for initialization since refcnt is in space allocated with rte_zmalloc().
--- drivers/net/failsafe/failsafe_ops.c | 12 +++++----- drivers/net/failsafe/failsafe_private.h | 29 ++++++++++++++----------- drivers/net/failsafe/failsafe_rxtx.c | 2 +- 3 files changed, 22 insertions(+), 21 deletions(-)
drivers/net/failsafe/failsafe_ops.c +5 -7
@@ -11,7 +11,7 @@#endif #include <rte_debug.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <ethdev_driver.h> #include <rte_malloc.h> #include <rte_flow.h>
@@ -440,14 +440,13 @@ fs_rx_queue_setup(struct rte_eth_dev *dev, } rxq =rte_zmalloc (NULL ,sizeof (*rxq) + -sizeof (rte_atomic64_t) *PRIV (dev)->subs_tail, +sizeof (*rxq->refcnt) *PRIV (dev)->subs_tail,RTE_CACHE_LINE_SIZE );if (rxq ==NULL ) {fs_unlock (dev,0 );return -ENOMEM ; } - FOREACH_SUBDEV(sdev, i, dev) -rte_atomic64_init (&rxq->refcnt[i]); + rxq->qid = rx_queue_id; rxq->socket_id = socket_id; rxq->info.mp = mb_pool;
@@ -617,14 +616,13 @@ fs_tx_queue_setup(struct rte_eth_dev *dev, } txq =rte_zmalloc ("ethdev TX queue" ,sizeof (*txq) + -sizeof (rte_atomic64_t) *PRIV (dev)->subs_tail, +sizeof (uint64_t ) *PRIV (dev)->subs_tail,RTE_CACHE_LINE_SIZE );if (txq ==NULL ) {fs_unlock (dev,0 );return -ENOMEM ; } - FOREACH_SUBDEV(sdev, i, dev) -rte_atomic64_init (&txq->refcnt[i]); + txq->qid = tx_queue_id; txq->socket_id = socket_id; txq->info.conf = *tx_conf;
drivers/net/failsafe/failsafe_private.h +16 -13
@@ -10,7 +10,7 @@#include <sys/queue.h> #include <pthread.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <dev_driver.h> #include <ethdev_driver.h> #include <rte_devargs.h>
@@ -75,7 +75,7 @@ struct rxq {int event_fd; unsigned int enable_events:1;struct rte_eth_rxq_info info; -rte_atomic64_t refcnt[]; +RTE_ATOMIC (uint64_t ) refcnt[]; };struct txq {
@@ -83,7 +83,7 @@ struct txq {uint16_t qid;unsigned int socket_id;struct rte_eth_txq_info info; -rte_atomic64_t refcnt[]; +RTE_ATOMIC (uint64_t ) refcnt[]; };struct rte_flow {
@@ -320,33 +320,36 @@ extern int failsafe_mac_from_arg;*/ /** -* a: (rte_atomic64_t) +* a: RTE_ATOMIC(uint64_t) */ #define FS_ATOMIC_P (a) \ - rte_atomic64_set(&(a), 1) + rte_atomic_exchange_explicit(&(a), 1, rte_memory_order_acquire)/** -* a: (rte_atomic64_t) +* a: RTE_ATOMIC(uint64_t) */ #define FS_ATOMIC_V (a) \ - rte_atomic64_set(&(a), 0) + rte_atomic_store_explicit(&(a), 0, rte_memory_order_release)/** * s: (struct sub_device *) * i: uint16_t qid */ #define FS_ATOMIC_RX (s, i) \ - rte_atomic64_read( \ - &((struct rxq *) \ - (fs_dev(s)->data->rx_queues[i]))->refcnt[(s)->sid]) + rte_atomic_load_explicit( \ + &((struct rxq *) \ + (fs_dev(s)->data->rx_queues[i]))->refcnt[(s)->sid], \ + rte_memory_order_seq_cst) +/** * s: (struct sub_device *) * i: uint16_t qid */ #define FS_ATOMIC_TX (s, i) \ - rte_atomic64_read( \ - &((struct txq *) \ - (fs_dev(s)->data->tx_queues[i]))->refcnt[(s)->sid]) + rte_atomic_load_explicit( \ + &((struct txq *) \ + (fs_dev(s)->data->tx_queues[i]))->refcnt[(s)->sid], \ + rte_memory_order_seq_cst)#ifdef RTE_EXEC_ENV_FREEBSD #define FS_THREADID_TYPE void*
drivers/net/failsafe/failsafe_rxtx.c +1 -1
@@ -3,7 +3,7 @@* Copyright 2017 Mellanox Technologies, Ltd */ -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_debug.h> #include <rte_mbuf.h> #include <ethdev_driver.h>
Signature · 1 line
2.53.0
Re: [PATCH v8 05/25] net/failsafe: convert to stdatomic
Quoted 18 lines · Stephen Hemminger
drivers/net/failsafe/failsafe_ops.c +2
-3@@ -440,14 +440,13 @@ fs_rx_queue_setup(struct rte_eth_dev *dev, } rxq =rte_zmalloc (NULL ,sizeof (*rxq) + -sizeof (rte_atomic64_t) *PRIV (dev)->subs_tail, +sizeof (*rxq->refcnt) *PRIV (dev)->subs_tail,RTE_CACHE_LINE_SIZE );if (rxq ==NULL ) {fs_unlock (dev,0 );return -ENOMEM ; } - FOREACH_SUBDEV(sdev, i, dev) -rte_atomic64_init (&rxq->refcnt[i]); + rxq->qid = rx_queue_id; rxq->socket_id = socket_id; rxq->info.mp = mb_pool;
drivers/net/failsafe/failsafe_ops.c fs_tx_queue_setup(struct rte_eth_dev *dev, · line 619
Quoted 5 lines
drivers/net/failsafe/failsafe_ops.c +1
-1@@ -617,14 +616,13 @@ fs_tx_queue_setup(struct rte_eth_dev *dev, } txq = rte_zmalloc("ethdev TX queue", sizeof(*txq) + - sizeof(rte_atomic64_t) * PRIV(dev)->subs_tail, + sizeof(uint64_t) * PRIV(dev)->subs_tail,
sizeof(*txq->refcnt) for consistency.
Quoted 11 lines
drivers/net/failsafe/failsafe_ops.c +1
-2RTE_CACHE_LINE_SIZE);if (txq ==NULL ) {fs_unlock (dev,0 );return -ENOMEM ; } - FOREACH_SUBDEV(sdev, i, dev) -rte_atomic64_init (&txq->refcnt[i]); + txq->qid = tx_queue_id; txq->socket_id = socket_id; txq->info.conf = *tx_conf;
Signature · 1 line
David Marchand
PATCH v8 6/25 net/enic: do not use deprecated rte_atomic64
In reply to Stephen HemmingerThe rte_atomic64 datatype and functions are deprecated. This driver was only using it for error statistics where atomic is not necessary. The DPDK PMD model is that statistics do not have to be exact in face of contention.
--- drivers/net/enic/enic.h | 6 +++--- drivers/net/enic/enic_compat.h | 1 - drivers/net/enic/enic_main.c | 17 +++++++---------- drivers/net/enic/enic_rxtx.c | 14 ++++++-------- drivers/net/enic/enic_rxtx_vec_avx2.c | 4 ++-- 5 files changed, 18 insertions(+), 24 deletions(-)
drivers/net/enic/enic.h +3 -3
@@ -59,9 +59,9 @@#define ENICPMD_RXQ_INTR_OFFSET 1struct enic_soft_stats { -rte_atomic64_t rx_nombuf; -rte_atomic64_t rx_packet_errors; -rte_atomic64_t tx_oversized; +uint64_t rx_nombuf; +uint64_t rx_packet_errors; +uint64_t tx_oversized; };struct enic_memzone_entry {
drivers/net/enic/enic_compat.h +0 -1
@@ -9,7 +9,6 @@#include <stdio.h> #include <unistd.h> -#include <rte_atomic.h> #include <rte_malloc.h> #include <rte_log.h> #include <rte_io.h>
drivers/net/enic/enic_main.c +7 -10
@@ -83,17 +83,15 @@ static void enic_log_q_error(struct enic *enic)static void enic_clear_soft_stats (struct enic *enic) {struct enic_soft_stats *soft_stats = &enic->soft_stats; -rte_atomic64_clear (&soft_stats->rx_nombuf); -rte_atomic64_clear (&soft_stats->rx_packet_errors); -rte_atomic64_clear (&soft_stats->tx_oversized); + +memset (soft_stats,0 ,sizeof (*soft_stats)); }static void enic_init_soft_stats (struct enic *enic) {struct enic_soft_stats *soft_stats = &enic->soft_stats; -rte_atomic64_init (&soft_stats->rx_nombuf); -rte_atomic64_init (&soft_stats->rx_packet_errors); -rte_atomic64_init (&soft_stats->tx_oversized); + +memset (soft_stats,0 ,sizeof (*soft_stats));enic_clear_soft_stats (enic); }
@@ -132,7 +130,7 @@ int enic_dev_stats_get(struct enic *enic, struct rte_eth_stats *r_stats,* counted in ibytes even though truncated packets are dropped * which can make ibytes be slightly higher than it should be. */ - rx_packet_errors =rte_atomic64_read (&soft_stats->rx_packet_errors); + rx_packet_errors = soft_stats->rx_packet_errors; rx_truncated = rx_packet_errors - stats->rx.rx_errors; r_stats->ipackets = stats->rx.rx_frames_ok - rx_truncated;
@@ -142,12 +140,11 @@ int enic_dev_stats_get(struct enic *enic, struct rte_eth_stats *r_stats, r_stats->obytes = stats->tx.tx_bytes_ok; r_stats->ierrors = stats->rx.rx_errors + stats->rx.rx_drop; - r_stats->oerrors = stats->tx.tx_errors - +rte_atomic64_read (&soft_stats->tx_oversized); + r_stats->oerrors = stats->tx.tx_errors + soft_stats->tx_oversized; r_stats->imissed = stats->rx.rx_no_bufs + rx_truncated; - r_stats->rx_nombuf =rte_atomic64_read (&soft_stats->rx_nombuf); + r_stats->rx_nombuf = soft_stats->rx_nombuf;return 0 ; }
drivers/net/enic/enic_rxtx.c +6 -8
@@ -112,7 +112,7 @@ enic_recv_pkts_common(void *rx_queue, struct rte_mbuf **rx_pkts,/* allocate a new mbuf */ nmb =rte_mbuf_raw_alloc (rq->mp);if (nmb ==NULL ) { -rte_atomic64_inc (&enic->soft_stats.rx_nombuf); + ++enic->soft_stats.rx_nombuf;break ; }
@@ -185,7 +185,7 @@ enic_recv_pkts_common(void *rx_queue, struct rte_mbuf **rx_pkts, }if (unlikely (packet_error)) {rte_pktmbuf_free (first_seg); -rte_atomic64_inc (&enic->soft_stats.rx_packet_errors); + ++enic->soft_stats.rx_packet_errors;continue ; }
@@ -303,7 +303,7 @@ enic_noscatter_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,if (unlikely (cqd->bytes_written_flags &CQ_ENET_RQ_DESC_FLAGS_TRUNCATED )) {rte_pktmbuf_free (*rxmb++); -rte_atomic64_inc (&enic->soft_stats.rx_packet_errors); + ++enic->soft_stats.rx_packet_errors; cqd++;continue ; }
@@ -505,14 +505,12 @@ uint16_t enic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,uint8_t offload_mode;uint16_t header_len;uint64_t tso; -rte_atomic64_t *tx_oversized;enic_cleanup_wq (enic, wq); wq_desc_avail =vnic_wq_desc_avail (wq); head_idx = wq->head_idx; desc_count = wq->ring.desc_count; ol_flags_mask =RTE_MBUF_F_TX_VLAN |RTE_MBUF_F_TX_IP_CKSUM |RTE_MBUF_F_TX_L4_MASK ; - tx_oversized = &enic->soft_stats.tx_oversized; nb_pkts =RTE_MIN (nb_pkts,ENIC_TX_XMIT_MAX );
@@ -527,7 +525,7 @@ uint16_t enic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,/* drop packet if it's too big to send */ if (unlikely (!tso && pkt_len >ENIC_TX_MAX_PKT_SIZE )) {rte_pktmbuf_free (tx_pkt); -rte_atomic64_inc (tx_oversized); + ++enic->soft_stats.tx_oversized;continue ; }
@@ -558,7 +556,7 @@ uint16_t enic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,if (unlikely (header_len ==0 || ((tx_pkt->tso_segsz + header_len) >ENIC_TX_MAX_PKT_SIZE ))) {rte_pktmbuf_free (tx_pkt); -rte_atomic64_inc (tx_oversized); + ++enic->soft_stats.tx_oversized;continue ; }
@@ -681,7 +679,7 @@ static void enqueue_simple_pkts(struct rte_mbuf **pkts,*/ if (unlikely (p->pkt_len >ENIC_TX_MAX_PKT_SIZE )) { desc->length =ENIC_TX_MAX_PKT_SIZE ; -rte_atomic64_inc (&enic->soft_stats.tx_oversized); + ++enic->soft_stats.tx_oversized; } desc++; }
drivers/net/enic/enic_rxtx_vec_avx2.c +2 -2
@@ -81,7 +81,7 @@ enic_noscatter_vec_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,if (unlikely (cqd->bytes_written_flags &CQ_ENET_RQ_DESC_FLAGS_TRUNCATED )) {rte_pktmbuf_free (*rxmb++); -rte_atomic64_inc (&enic->soft_stats.rx_packet_errors); + ++enic->soft_stats.rx_packet_errors; }else { *rx++ =rx_one (cqd, *rxmb++, enic); }
@@ -761,7 +761,7 @@ enic_noscatter_vec_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,if (unlikely (cqd->bytes_written_flags &CQ_ENET_RQ_DESC_FLAGS_TRUNCATED )) {rte_pktmbuf_free (*rxmb++); -rte_atomic64_inc (&enic->soft_stats.rx_packet_errors); + ++enic->soft_stats.rx_packet_errors; }else { *rx++ =rx_one (cqd, *rxmb++, enic); }
Signature · 1 line
2.53.0
Re: [PATCH v8 06/25] net/enic: do not use deprecated rte_atomic64
Quoted 16 lines · Stephen Hemminger
drivers/net/enic/enic_main.c +2
-3@@ -83,17 +83,15 @@ static void enic_log_q_error(struct enic *enic)static void enic_clear_soft_stats (struct enic *enic) {struct enic_soft_stats *soft_stats = &enic->soft_stats; -rte_atomic64_clear (&soft_stats->rx_nombuf); -rte_atomic64_clear (&soft_stats->rx_packet_errors); -rte_atomic64_clear (&soft_stats->tx_oversized); + +memset (soft_stats,0 ,sizeof (*soft_stats)); }static void enic_init_soft_stats (struct enic *enic)
drivers/net/enic/enic_main.c static void enic_log_q_error(struct enic *enic) · line 97
Quoted 10 lines
drivers/net/enic/enic_main.c +2
-3{struct enic_soft_stats *soft_stats = &enic->soft_stats; -rte_atomic64_init (&soft_stats->rx_nombuf); -rte_atomic64_init (&soft_stats->rx_packet_errors); -rte_atomic64_init (&soft_stats->tx_oversized); + +memset (soft_stats,0 ,sizeof (*soft_stats));enic_clear_soft_stats (enic); }
enic_init_soft_stats calls enic_clear_soft_stats, so a memset here is unncessary.
Signature · 1 line
David Marchand
PATCH v8 7/25 net/pfe: use ethdev linkstatus helpers
In reply to Stephen HemmingerRather than open coding with deprecated rte_atomic64, use the existing ethdev helpers to get and set link status.
--- drivers/net/pfe/pfe_ethdev.c | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-)
drivers/net/pfe/pfe_ethdev.c +2 -30
@@ -531,34 +531,6 @@ pfe_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)return NULL ; } -static inline int -pfe_eth_atomic_read_link_status (struct rte_eth_dev *dev, -struct rte_eth_link *link) -{ -struct rte_eth_link *dst = link; -struct rte_eth_link *src = &dev->data->dev_link; - -if (rte_atomic64_cmpset ((uint64_t *)dst, *(uint64_t *)dst, - *(uint64_t *)src) ==0 ) -return -1 ; - -return 0 ; -} - -static inline int -pfe_eth_atomic_write_link_status (struct rte_eth_dev *dev, -struct rte_eth_link *link) -{ -struct rte_eth_link *dst = &dev->data->dev_link; -struct rte_eth_link *src = link; - -if (rte_atomic64_cmpset ((uint64_t *)dst, *(uint64_t *)dst, - *(uint64_t *)src) ==0 ) -return -1 ; - -return 0 ; -} -static int pfe_eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused) {
@@ -570,7 +542,7 @@ pfe_eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused)memset (&old,0 ,sizeof (old));memset (&link,0 ,sizeof (struct rte_eth_link )); -pfe_eth_atomic_read_link_status (dev, &old); +rte_eth_linkstatus_get (dev, &old);/* Read from PFE CDEV, status of link, if file was successfully * opened.
@@ -601,7 +573,7 @@ pfe_eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused) link.link_duplex =RTE_ETH_LINK_FULL_DUPLEX ; link.link_autoneg =RTE_ETH_LINK_AUTONEG ; -pfe_eth_atomic_write_link_status (dev, &link); +rte_eth_linkstatus_set (dev, &link);PFE_PMD_INFO ("Port (%d) link is %s" , dev->data->port_id, link.link_status ?"up" :"down" );
Signature · 1 line
2.53.0
PATCH v8 8/25 net/sfc: replace rte_atomic with stdatomic
In reply to Stephen HemmingerThe rte_atomicNN functions are deprecated and need to be replaced. Use stdatomic for the restart required flag.
Use existing ethdev helper to set link status.
--- drivers/net/sfc/sfc.c | 9 +++++---- drivers/net/sfc/sfc.h | 4 ++-- drivers/net/sfc/sfc_port.c | 7 +------ drivers/net/sfc/sfc_stats.h | 2 +- 4 files changed, 9 insertions(+), 13 deletions(-)
drivers/net/sfc/sfc.c +5 -4
@@ -670,8 +670,8 @@ sfc_restart_if_required(void *arg)struct sfc_adapter *sa = arg;/* If restart is scheduled, clear the flag and do it */ -if (rte_atomic32_cmpset ((volatile uint32_t *)&sa->restart_required, -1 ,0 )) { +if (rte_atomic_exchange_explicit (&sa->restart_required, false, + rte_memory_order_seq_cst)) {sfc_adapter_lock (sa);if (sa->state ==SFC_ETHDEV_STARTED ) (void )sfc_restart (sa);
@@ -685,7 +685,8 @@ sfc_schedule_restart(struct sfc_adapter *sa)int rc;/* Schedule restart alarm if it is not scheduled yet */ -if (!rte_atomic32_test_and_set (&sa->restart_required)) +if (rte_atomic_exchange_explicit (&sa->restart_required, true, + rte_memory_order_seq_cst))return ; rc =rte_eal_alarm_set (1 , sfc_restart_if_required, sa);
@@ -1292,7 +1293,7 @@ sfc_probe(struct sfc_adapter *sa)SFC_ASSERT (sfc_adapter_is_locked (sa)); sa->socket_id =rte_socket_id (); -rte_atomic32_init (&sa->restart_required); + sa->restart_required = false;sfc_log_init (sa,"get family" ); rc =sfc_efx_family (pci_dev, &mem_ebrp, &sa->family);
drivers/net/sfc/sfc.h +2 -2
@@ -17,7 +17,7 @@#include <ethdev_driver.h> #include <rte_kvargs.h> #include <rte_spinlock.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include "efx.h"
@@ -239,7 +239,7 @@ struct sfc_adapter {efx_family_t family;efx_nic_t *nic;rte_spinlock_t nic_lock; -rte_atomic32_t restart_required; +RTE_ATOMIC (bool ) restart_required;struct sfc_efx_mcdi mcdi;struct sfc_sriov sriov;
drivers/net/sfc/sfc_port.c +1 -6
@@ -121,7 +121,6 @@ sfc_port_reset_mac_stats(struct sfc_adapter *sa)static int sfc_port_init_dev_link (struct sfc_adapter *sa) { -struct rte_eth_link *dev_link = &sa->eth_dev->data->dev_link;int rc;efx_link_mode_t link_mode;struct rte_eth_link current_link;
@@ -132,11 +131,7 @@ sfc_port_init_dev_link(struct sfc_adapter *sa)sfc_port_link_mode_to_info (link_mode, sa->port.phy_adv_cap, ¤t_link); - -EFX_STATIC_ASSERT (sizeof (*dev_link) ==sizeof (rte_atomic64_t)); -rte_atomic64_set ((rte_atomic64_t *)dev_link, - *(uint64_t *)¤t_link); - +rte_eth_linkstatus_set (sa->eth_dev, ¤t_link);return 0 ; }
drivers/net/sfc/sfc_stats.h +1 -1
@@ -12,7 +12,7 @@#include <stdint.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include "sfc_tweak.h"
Signature · 1 line
2.53.0
PATCH v8 9/25 crypto/ccp: replace use of rte_atomic64 with stdatomic
In reply to Stephen HemmingerThe rte_atomicNN functions are deprecated. Replace the free count with stdatomic.
--- drivers/crypto/ccp/ccp_crypto.c | 11 +++++++---- drivers/crypto/ccp/ccp_crypto.h | 2 +- drivers/crypto/ccp/ccp_dev.c | 10 ++++++---- drivers/crypto/ccp/ccp_dev.h | 4 ++-- 4 files changed, 16 insertions(+), 11 deletions(-)
drivers/crypto/ccp/ccp_crypto.c +7 -4
@@ -2683,7 +2683,8 @@ process_ops_to_enqueue(struct ccp_qp *qp, b_info->cmd_q = cmd_q; b_info->lsb_buf_phys = (phys_addr_t )rte_mem_virt2iova ((void *)b_info->lsb_buf); -rte_atomic64_sub (&b_info->cmd_q->free_slots, slots_req); +rte_atomic_fetch_sub_explicit (&b_info->cmd_q->free_slots, slots_req, + rte_memory_order_seq_cst); b_info->head_offset = (uint32_t )(cmd_q->qbase_phys_addr + cmd_q->qidx *Q_DESC_SIZE );
@@ -2729,8 +2730,9 @@ process_ops_to_enqueue(struct ccp_qp *qp, result =-1 ; }if (unlikely (result <0 )) { -rte_atomic64_add (&b_info->cmd_q->free_slots, - (slots_req - b_info->desccnt)); +rte_atomic_fetch_add_explicit (&b_info->cmd_q->free_slots, + slots_req - b_info->desccnt, + rte_memory_order_seq_cst);break ; } b_info->op[i] = op[i];
@@ -2914,7 +2916,8 @@ process_ops_to_dequeue(struct ccp_qp *qp, success: *total_nb_ops = b_info->total_nb_ops; nb_ops =ccp_prepare_ops (qp, op, b_info, nb_ops); -rte_atomic64_add (&b_info->cmd_q->free_slots, b_info->desccnt); +rte_atomic_fetch_add_explicit (&b_info->cmd_q->free_slots, b_info->desccnt, + rte_memory_order_seq_cst); b_info->desccnt =0 ;if (b_info->opcnt >0 ) { qp->b_info = b_info;
drivers/crypto/ccp/ccp_crypto.h +1 -1
@@ -10,7 +10,7 @@#include <stdint.h> #include <string.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_byteorder.h> #include <rte_io.h> #include <rte_pci.h>
drivers/crypto/ccp/ccp_dev.c +6 -4
@@ -47,14 +47,15 @@ ccp_allot_queue(struct rte_cryptodev *cdev, int slot_req) priv->last_dev = dev;if (dev->qidx >= dev->cmd_q_count) dev->qidx =0 ; - ret =rte_atomic64_read (&dev->cmd_q[dev->qidx].free_slots); + ret =rte_atomic_load_explicit (&dev->cmd_q[dev->qidx].free_slots, rte_memory_order_relaxed);if (ret >= slot_req)return &dev->cmd_q[dev->qidx];for (i =0 ; i < dev->cmd_q_count; i++) { dev->qidx++;if (dev->qidx >= dev->cmd_q_count) dev->qidx =0 ; - ret =rte_atomic64_read (&dev->cmd_q[dev->qidx].free_slots); + ret =rte_atomic_load_explicit (&dev->cmd_q[dev->qidx].free_slots, + rte_memory_order_relaxed);if (ret >= slot_req)return &dev->cmd_q[dev->qidx]; }
@@ -583,8 +584,9 @@ ccp_add_device(struct ccp_device *dev)CCP_LOG_ERR ("queue doesn't have lsb regions" ); cmd_q->lsb =-1 ; -rte_atomic64_init (&cmd_q->free_slots); -rte_atomic64_set (&cmd_q->free_slots, (COMMANDS_PER_QUEUE -1 )); +rte_atomic_store_explicit (&cmd_q->free_slots, +COMMANDS_PER_QUEUE -1 , + rte_memory_order_seq_cst);/* unused slot barrier b/w H&T */ }
drivers/crypto/ccp/ccp_dev.h +2 -2
@@ -11,7 +11,7 @@#include <string.h> #include <bus_pci_driver.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_byteorder.h> #include <rte_io.h> #include <rte_pci.h>
@@ -182,7 +182,7 @@ struct __rte_cache_aligned ccp_queue {struct ccp_device *dev;char memz_name[RTE_MEMZONE_NAMESIZE ]; -rte_atomic64_t free_slots; +RTE_ATOMIC (int64_t ) free_slots;/**< available free slots updated from enq/deq calls */ /* Queue identifier */
Signature · 1 line
2.53.0
PATCH v8 10/25 bus/dpaa: remove unused in_use field
In reply to Stephen HemmingerThe in_use field of struct bman_pool is set once in bman_new_pool() and never read. It has been that way since the driver was added.
--- drivers/bus/dpaa/base/qbman/bman.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/bus/dpaa/base/qbman/bman.c +1 -6
@@ -62,9 +62,6 @@ struct bman_pool {/* Used for hash-table admin when using depletion notifications. */ struct bman_portal *portal;struct bman_pool *next; -#ifdef RTE_LIBRTE_DPAA_HWDEBUG -atomic_t in_use; -#endif }; static inline
@@ -224,9 +221,7 @@ struct bman_pool *bman_new_pool(const struct bman_pool_params *params)if (!pool) goto err; pool->params = *params; -#ifdef RTE_LIBRTE_DPAA_HWDEBUG -atomic_set (&pool->in_use,1 ); -#endif +if (params->flags &BMAN_POOL_FLAG_DYNAMIC_BPID ) pool->params.bpid = bpid;
Signature · 1 line
2.53.0
PATCH v8 11/25 bus/dpaa: replace rte_atomic16 with stdatomic
In reply to Stephen HemmingerThis is simple inuse flag which can be done with stdatomic exchange logic.
--- drivers/bus/dpaa/base/qbman/qman.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/bus/dpaa/base/qbman/qman.c +6 -3
@@ -11,6 +11,7 @@#include <rte_eventdev.h> #include <rte_byteorder.h> #include <rte_dpaa_logs.h> +#include <rte_stdatomic.h> #include <eal_export.h> #include <dpaa_bits.h>
@@ -683,7 +684,7 @@ qman_init_portal(struct qman_portal *portal,#define MAX_GLOBAL_PORTALS 8static struct qman_portal global_portals[MAX_GLOBAL_PORTALS ]; -static rte_atomic16_t global_portals_used[MAX_GLOBAL_PORTALS ]; +static RTE_ATOMIC (bool ) global_portals_used[MAX_GLOBAL_PORTALS ];struct qman_portal *qman_alloc_global_portal (struct qm_portal_config *q_pcfg)
@@ -691,7 +692,8 @@ qman_alloc_global_portal(struct qm_portal_config *q_pcfg)unsigned int i;for (i =0 ; i <MAX_GLOBAL_PORTALS ; i++) { -if (rte_atomic16_test_and_set (&global_portals_used[i])) { +if (!rte_atomic_exchange_explicit (&global_portals_used[i], true, + rte_memory_order_acquire)) { global_portals[i].config = q_pcfg;return &global_portals[i]; }
@@ -708,7 +710,8 @@ qman_free_global_portal(struct qman_portal *portal)for (i =0 ; i <MAX_GLOBAL_PORTALS ; i++) {if (&global_portals[i] == portal) { -rte_atomic16_clear (&global_portals_used[i]); +rte_atomic_store_explicit (&global_portals_used[i], false, + rte_memory_order_release);return 0 ; } }
Signature · 1 line
2.53.0
PATCH v8 12/25 bus/fslmc: replace rte_atomic with stdatomic
In reply to Stephen HemmingerThe rte_atomicNN functions and types are deprecated. The in_use and ref_count flags can be converted to stdatomic.
Note that rte_atomic16_init() and rte_atomic16_clear() were plain stores with no ordering; only test_and_set() and dec() implied a full barrier. Initialization happens before the device is put on the list, so a relaxed store is used there. It is spelled out explicitly because a plain assignment to an RTE_ATOMIC() object is a sequentially consistent store when built with enable_stdatomic=true.
Claiming a device now pairs an acquire compare exchange with a release store on the free path, which is what the test_and_set()/dec() pair was providing.
Also drop the unneeded NULL check in the loop body: TAILQ_FOREACH terminates when the iterator becomes NULL, so var is guaranteed non-NULL inside the loop.
--- drivers/bus/fslmc/portal/dpaa2_hw_dpbp.c | 11 ++++++++--- drivers/bus/fslmc/portal/dpaa2_hw_dpci.c | 11 ++++++++--- drivers/bus/fslmc/portal/dpaa2_hw_dpcon.c | 11 ++++++++--- drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 14 ++++++++++---- drivers/bus/fslmc/portal/dpaa2_hw_pvt.h | 9 +++++---- drivers/bus/fslmc/qbman/include/compat.h | 18 ++++++------------ 6 files changed, 45 insertions(+), 29 deletions(-)
drivers/bus/fslmc/portal/dpaa2_hw_dpbp.c +8 -3
@@ -84,7 +84,7 @@ dpaa2_create_dpbp_device(int vdev_fd __rte_unused, } dpbp_node->dpbp_id = dpbp_id; -rte_atomic16_init (&dpbp_node->in_use); +rte_atomic_store_explicit (&dpbp_node->in_use,0 , rte_memory_order_relaxed);TAILQ_INSERT_TAIL (&dpbp_dev_list, dpbp_node, next);
@@ -103,7 +103,11 @@ struct dpaa2_dpbp_dev *dpaa2_alloc_dpbp_dev(void)/* Get DPBP dev handle from list using index */ TAILQ_FOREACH(dpbp_dev, &dpbp_dev_list, next) { -if (dpbp_dev &&rte_atomic16_test_and_set (&dpbp_dev->in_use)) +uint16_t expected =0 ; + +if (rte_atomic_compare_exchange_strong_explicit (&dpbp_dev->in_use, + &expected,1 , rte_memory_order_acquire, + rte_memory_order_relaxed))break ; }
@@ -118,7 +122,8 @@ void dpaa2_free_dpbp_dev(struct dpaa2_dpbp_dev *dpbp)/* Match DPBP handle and mark it free */ TAILQ_FOREACH(dpbp_dev, &dpbp_dev_list, next) {if (dpbp_dev == dpbp) { -rte_atomic16_dec (&dpbp_dev->in_use); +rte_atomic_store_explicit (&dpbp_dev->in_use,0 , + rte_memory_order_release);return ; } }
drivers/bus/fslmc/portal/dpaa2_hw_dpci.c +8 -3
@@ -135,7 +135,7 @@ rte_dpaa2_create_dpci_device(int vdev_fd __rte_unused, } dpci_node->dpci_id = dpci_id; -rte_atomic16_init (&dpci_node->in_use); +rte_atomic_store_explicit (&dpci_node->in_use,0 , rte_memory_order_relaxed);TAILQ_INSERT_TAIL (&dpci_dev_list, dpci_node, next);
@@ -159,7 +159,11 @@ struct dpaa2_dpci_dev *rte_dpaa2_alloc_dpci_dev(void)/* Get DPCI dev handle from list using index */ TAILQ_FOREACH(dpci_dev, &dpci_dev_list, next) { -if (dpci_dev &&rte_atomic16_test_and_set (&dpci_dev->in_use)) +uint16_t expected =0 ; + +if (rte_atomic_compare_exchange_strong_explicit (&dpci_dev->in_use, + &expected,1 , rte_memory_order_acquire, + rte_memory_order_relaxed))break ; }
@@ -174,7 +178,8 @@ void rte_dpaa2_free_dpci_dev(struct dpaa2_dpci_dev *dpci)/* Match DPCI handle and mark it free */ TAILQ_FOREACH(dpci_dev, &dpci_dev_list, next) {if (dpci_dev == dpci) { -rte_atomic16_dec (&dpci_dev->in_use); +rte_atomic_store_explicit (&dpci_dev->in_use,0 , + rte_memory_order_release);return ; } }
drivers/bus/fslmc/portal/dpaa2_hw_dpcon.c +8 -3
@@ -81,7 +81,7 @@ rte_dpaa2_create_dpcon_device(int dev_fd __rte_unused, dpcon_node->qbman_ch_id = attr.qbman_ch_id; dpcon_node->num_priorities = attr.num_priorities; dpcon_node->dpcon_id = dpcon_id; -rte_atomic16_init (&dpcon_node->in_use); +rte_atomic_store_explicit (&dpcon_node->in_use,0 , rte_memory_order_relaxed);TAILQ_INSERT_TAIL (&dpcon_dev_list, dpcon_node, next);
@@ -95,7 +95,11 @@ struct dpaa2_dpcon_dev *rte_dpaa2_alloc_dpcon_dev(void)/* Get DPCON dev handle from list using index */ TAILQ_FOREACH(dpcon_dev, &dpcon_dev_list, next) { -if (dpcon_dev &&rte_atomic16_test_and_set (&dpcon_dev->in_use)) +uint16_t expected =0 ; + +if (rte_atomic_compare_exchange_strong_explicit (&dpcon_dev->in_use, + &expected,1 , rte_memory_order_acquire, + rte_memory_order_relaxed))break ; }
@@ -110,7 +114,8 @@ void rte_dpaa2_free_dpcon_dev(struct dpaa2_dpcon_dev *dpcon)/* Match DPCON handle and mark it free */ TAILQ_FOREACH(dpcon_dev, &dpcon_dev_list, next) {if (dpcon_dev == dpcon) { -rte_atomic16_dec (&dpcon_dev->in_use); +rte_atomic_store_explicit (&dpcon_dev->in_use,0 , + rte_memory_order_release);return ; } }
drivers/bus/fslmc/portal/dpaa2_hw_dpio.c +10 -4
@@ -352,7 +352,8 @@ static void dpaa2_put_qbman_swp(struct dpaa2_dpio_dev *dpio_dev)* armed: intr_deinit returns early if intr is not enabled. */ dpaa2_dpio_intr_deinit (dpio_dev); -rte_atomic16_clear (&dpio_dev->ref_count); +rte_atomic_store_explicit (&dpio_dev->ref_count,0 , + rte_memory_order_release); } }
@@ -364,7 +365,11 @@ static struct dpaa2_dpio_dev *dpaa2_get_qbman_swp(bool ethrx)/* Get DPIO dev handle from list using index */ TAILQ_FOREACH(dpio_dev, &dpio_dev_list, next) { -if (dpio_dev &&rte_atomic16_test_and_set (&dpio_dev->ref_count)) +uint16_t expected =0 ; + +if (rte_atomic_compare_exchange_strong_explicit (&dpio_dev->ref_count, + &expected,1 , rte_memory_order_acquire, + rte_memory_order_relaxed))break ; }if (!dpio_dev) {
@@ -385,7 +390,8 @@ static struct dpaa2_dpio_dev *dpaa2_get_qbman_swp(bool ethrx) ret =dpaa2_configure_stashing (dpio_dev, cpu_id, ethrx);if (ret) {DPAA2_BUS_ERR ("dpaa2_configure_stashing failed" ); -rte_atomic16_clear (&dpio_dev->ref_count); +rte_atomic_store_explicit (&dpio_dev->ref_count,0 , + rte_memory_order_release);return NULL ; } }
@@ -500,7 +506,7 @@ dpaa2_create_dpio_device(int vdev_fd, dpio_dev->dpio =NULL ; dpio_dev->hw_id = object_id; -rte_atomic16_init (&dpio_dev->ref_count); +rte_atomic_store_explicit (&dpio_dev->ref_count,0 , rte_memory_order_relaxed);/* Using single portal for all devices */ dpio_dev->mc_portal =dpaa2_get_mcp_ptr (MC_PORTAL_INDEX );
drivers/bus/fslmc/portal/dpaa2_hw_pvt.h +5 -4
@@ -9,6 +9,7 @@#define _DPAA2_HW_PVT_H_#include <rte_compat.h> +#include <rte_stdatomic.h> #include <rte_eventdev.h> #include <dpaax_iova_table.h>
@@ -112,7 +113,7 @@ struct dpaa2_dpio_dev {TAILQ_ENTRY (dpaa2_dpio_dev) next;/**< Pointer to Next device instance */ uint16_t index;/**< Index of a instance in the list */ -rte_atomic16_t ref_count; +RTE_ATOMIC (uint16_t ) ref_count;/**< How many thread contexts are sharing this.*/ uint16_t eqresp_ci;uint16_t eqresp_pi;
@@ -143,7 +144,7 @@ struct dpaa2_dpbp_dev {/**< Pointer to Next device instance */ struct fsl_mc_io dpbp;/** handle to DPBP portal object */ uint16_t token; -rte_atomic16_t in_use; +RTE_ATOMIC (uint16_t ) in_use;uint32_t dpbp_id;/*HW ID for DPBP object */ };
@@ -266,7 +267,7 @@ struct dpaa2_dpci_dev {/**< Pointer to Next device instance */ struct fsl_mc_io dpci;/** handle to DPCI portal object */ uint16_t token; -rte_atomic16_t in_use; +RTE_ATOMIC (uint16_t ) in_use;uint32_t dpci_id;/*HW ID for DPCI object */ struct dpaa2_queue rx_queue[DPAA2_DPCI_MAX_QUEUES ];struct dpaa2_queue tx_queue[DPAA2_DPCI_MAX_QUEUES ];
@@ -276,7 +277,7 @@ struct dpaa2_dpcon_dev {TAILQ_ENTRY (dpaa2_dpcon_dev) next;struct fsl_mc_io dpcon;uint16_t token; -rte_atomic16_t in_use; +RTE_ATOMIC (uint16_t ) in_use;uint32_t dpcon_id;uint16_t qbman_ch_id;uint8_t num_priorities;
drivers/bus/fslmc/qbman/include/compat.h +6 -12
@@ -81,18 +81,12 @@ do { \#define dma_wmb () rte_io_wmb() -#define atomic_t rte_atomic32_t -#define atomic_read (v) rte_atomic32_read(v) -#define atomic_set (v, i) rte_atomic32_set(v, i) +typedef RTE_ATOMIC (uint32_t )atomic_t ; -#define atomic_inc (v) rte_atomic32_add(v, 1) -#define atomic_dec (v) rte_atomic32_sub(v, 1) - -#define atomic_inc_and_test (v) rte_atomic32_inc_and_test(v) -#define atomic_dec_and_test (v) rte_atomic32_dec_and_test(v) - -#define atomic_inc_return (v) rte_atomic32_add_return(v, 1) -#define atomic_dec_return (v) rte_atomic32_sub_return(v, 1) -#define atomic_sub_and_test (i, v) (rte_atomic32_sub_return(v, i) == 0) +#define atomic_set (v, i) rte_atomic_store_explicit((v), (i), rte_memory_order_relaxed) +#define atomic_inc (v) ((void)rte_atomic_fetch_add_explicit((v), 1, \ + rte_memory_order_seq_cst)) +#define atomic_dec_and_test (v) (rte_atomic_fetch_sub_explicit((v), 1, \ + rte_memory_order_seq_cst) == 1)#endif /* HEADER_COMPAT_H */
Signature · 1 line
2.53.0
PATCH v8 13/25 common/dpaax: remove unused atomic wrappers
In reply to Stephen HemmingerThis driver defined Linux compatibility wrappers but never used them in current code base; remove them.
--- drivers/common/dpaax/compat.h | 14 -------------- 1 file changed, 14 deletions(-)
drivers/common/dpaax/compat.h +0 -14
@@ -365,20 +365,6 @@ static inline unsigned long get_zeroed_page(gfp_t __foo __rte_unused)#define spin_lock_irqsave (x, f) spin_lock_irq(x)#define spin_unlock_irqrestore (x, f) spin_unlock_irq(x) -#define atomic_t rte_atomic32_t -#define atomic_read (v) rte_atomic32_read(v) -#define atomic_set (v, i) rte_atomic32_set(v, i) - -#define atomic_inc (v) rte_atomic32_add(v, 1) -#define atomic_dec (v) rte_atomic32_sub(v, 1) - -#define atomic_inc_and_test (v) rte_atomic32_inc_and_test(v) -#define atomic_dec_and_test (v) rte_atomic32_dec_and_test(v) - -#define atomic_inc_return (v) rte_atomic32_add_return(v, 1) -#define atomic_dec_return (v) rte_atomic32_sub_return(v, 1) -#define atomic_sub_and_test (i, v) (rte_atomic32_sub_return(v, i) == 0) -/* Interface name len*/ #define IF_NAME_MAX_LEN 16
Signature · 1 line
2.53.0
PATCH v8 14/25 net/netvsc: replace rte_atomic32 with stdatomic
In reply to Stephen HemmingerChange the rndis transaction id and buffer usage to use stdatomic functions.
It also removes rte_smp_wmb() and relies on the release ordering of compare-exchange.
--- drivers/net/netvsc/hn_rndis.c | 28 +++++++++++++++++++--------- drivers/net/netvsc/hn_rxtx.c | 12 +++++++----- drivers/net/netvsc/hn_var.h | 6 +++--- 3 files changed, 29 insertions(+), 17 deletions(-)
drivers/net/netvsc/hn_rndis.c +19 -9
@@ -17,7 +17,7 @@#include <rte_string_fns.h> #include <rte_memzone.h> #include <rte_malloc.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_alarm.h> #include <rte_branch_prediction.h> #include <rte_ether.h>
@@ -59,7 +59,8 @@ hn_rndis_rid(struct hn_data *hv)uint32_t rid;do { - rid =rte_atomic32_add_return (&hv->rndis_req_id,1 ); + rid =rte_atomic_fetch_add_explicit (&hv->rndis_req_id,1 , + rte_memory_order_seq_cst) +1 ; }while (rid ==0 );return rid;
@@ -357,12 +358,14 @@ void hn_rndis_receive_response(struct hn_data *hv,memcpy (hv->rndis_resp, data, len);/* make sure response copied before update */ -rte_smp_wmb (); - -if (rte_atomic32_cmpset (&hv->rndis_pending, hdr->rid,0 ) ==0 ) { +uint32_t expected = hdr->rid; +if (!rte_atomic_compare_exchange_strong_explicit (&hv->rndis_pending, + &expected,0 , + rte_memory_order_release, + rte_memory_order_relaxed)) {PMD_DRV_LOG (NOTICE ,"received id %#x pending id %#x" , - hdr->rid, (uint32_t )hv->rndis_pending); + hdr->rid, expected); } }
@@ -388,8 +391,11 @@ static int hn_rndis_exec1(struct hn_data *hv,return -EINVAL ; } +uint32_t expected =0 ;if (comp !=NULL && -rte_atomic32_cmpset (&hv->rndis_pending,0 , rid) ==0 ) { + !rte_atomic_compare_exchange_strong_explicit ( + &hv->rndis_pending, &expected, rid, + rte_memory_order_acquire, rte_memory_order_relaxed)) {PMD_DRV_LOG (ERR ,"Request already pending" );return -EBUSY ;
@@ -405,7 +411,8 @@ static int hn_rndis_exec1(struct hn_data *hv,time_t start =time (NULL );/* Poll primary channel until response received */ -while (hv->rndis_pending == rid) { +while (rte_atomic_load_explicit (&hv->rndis_pending, + rte_memory_order_acquire) == rid) {if (hv->closed)return -ENETDOWN ;
@@ -413,7 +420,10 @@ static int hn_rndis_exec1(struct hn_data *hv,PMD_DRV_LOG (ERR ,"RNDIS response timed out" ); -rte_atomic32_cmpset (&hv->rndis_pending, rid,0 ); + expected = rid; +rte_atomic_compare_exchange_strong_explicit ( + &hv->rndis_pending, &expected,0 , + rte_memory_order_release, rte_memory_order_relaxed);return -ETIMEDOUT ; }
drivers/net/netvsc/hn_rxtx.c +7 -5
@@ -17,7 +17,7 @@#include <rte_string_fns.h> #include <rte_memzone.h> #include <rte_malloc.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_bitmap.h> #include <rte_branch_prediction.h> #include <rte_ether.h>
@@ -558,7 +558,8 @@ static void hn_rx_buf_free_cb(void *buf __rte_unused, void *opaque)struct hn_rx_queue *rxq = rxb->rxq;struct hn_data *hv = rxq->hv; -rte_atomic32_dec (&rxq->rxbuf_outstanding); +rte_atomic_fetch_sub_explicit (&rxq->rxbuf_outstanding,1 , + rte_memory_order_release);hn_nvs_ack_rxbuf (hv, rxb->chan, rxb->xactid); }
@@ -602,8 +603,8 @@ static void hn_rxpkt(struct hn_rx_queue *rxq, struct hn_rx_bufinfo *rxb,* some space available in receive area for later packets. */ if (hv->rx_extmbuf_enable && dlen > hv->rx_copybreak && - (uint32_t )rte_atomic32_read (&rxq->rxbuf_outstanding) < - hv->rxbuf_section_cnt /2 ) { +rte_atomic_load_explicit (&rxq->rxbuf_outstanding, + rte_memory_order_relaxed) < hv->rxbuf_section_cnt /2 ) {struct rte_mbuf_ext_shared_info *shinfo;const void *rxbuf;rte_iova_t iova;
@@ -619,7 +620,8 @@ static void hn_rxpkt(struct hn_rx_queue *rxq, struct hn_rx_bufinfo *rxb,/* shinfo is already set to 1 by the caller */ if (rte_mbuf_ext_refcnt_update (shinfo,1 ) ==2 ) -rte_atomic32_inc (&rxq->rxbuf_outstanding); +rte_atomic_fetch_add_explicit (&rxq->rxbuf_outstanding,1 , + rte_memory_order_acquire);rte_pktmbuf_attach_extbuf (m, data, iova, dlen + headroom, shinfo);
drivers/net/netvsc/hn_var.h +3 -3
@@ -85,7 +85,7 @@ struct hn_rx_queue {void *event_buf;struct hn_rx_bufinfo *rxbuf_info; -rte_atomic32_t rxbuf_outstanding; +RTE_ATOMIC (uint32_t ) rxbuf_outstanding; };
@@ -167,8 +167,8 @@ struct hn_data {uint32_t rndis_agg_pkts;uint32_t rndis_agg_align; -volatile uint32_t rndis_pending; -rte_atomic32_t rndis_req_id; +RTE_ATOMIC (uint32_t ) rndis_pending; +RTE_ATOMIC (uint32_t ) rndis_req_id;uint8_t rndis_resp[256 ];uint32_t rss_hash;
Signature · 1 line
2.53.0
RE: [EXTERNAL] [PATCH v8 14/25] net/netvsc: replace rte_atomic32 with stdatomic
Quoted 11 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Friday, September 18, 2026 4:10 AM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; Long Li <[email protected]>; Wei Hu <[email protected]>
Subject: [EXTERNAL] [PATCH v8 14/25] net/netvsc: replacerte_atomic32with stdatomic
Quoted 7 lines
Change the rndis transaction id and buffer usage to use stdatomic functions.
It also removes
rte_smp_wmb()and relies on the release ordering of compare- exchange.Signed-off-by Stephen Hemminger <[email protected]>Reviewed-by Long Li <[email protected]>
Quoted 167 lines
--- drivers/net/netvsc/hn_rndis.c | 28 +++++++++++++++++++--------- drivers/net/netvsc/hn_rxtx.c | 12 +++++++----- drivers/net/netvsc/hn_var.h | 6 +++--- 3 files changed, 29 insertions(+), 17 deletions(-)drivers/net/netvsc/hn_rndis.c +3
-2@@ -17,7 +17,7 @@#include <rte_string_fns.h> #include <rte_memzone.h> #include <rte_malloc.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_alarm.h> #include <rte_branch_prediction.h> #include <rte_ether.h> @@ -59,7 +59,8 @@ hn_rndis_rid(struct hn_data *hv)uint32_t rid;do { - rid =rte_atomic32_add_return (&hv->rndis_req_id,1 ); + rid =rte_atomic_fetch_add_explicit (&hv->rndis_req_id,1 , + rte_memory_order_seq_cst) +1 ; }while (rid ==0 );drivers/net/netvsc/hn_rndis.c +16
-7return rid;@@ -357,12 +358,14 @@ void hn_rndis_receive_response(struct hn_data *hv,memcpy (hv->rndis_resp, data, len);/* make sure response copied before update */ -rte_smp_wmb (); - -if (rte_atomic32_cmpset (&hv->rndis_pending, hdr->rid,0 ) ==0 ) { +uint32_t expected = hdr->rid; +if (!rte_atomic_compare_exchange_strong_explicit (&hv- >rndis_pending, + &expected,0 , + rte_memory_order_release, + rte_memory_order_relaxed)) {PMD_DRV_LOG (NOTICE ,"received id %#x pending id %#x" , - hdr->rid, (uint32_t )hv->rndis_pending); + hdr->rid, expected); } }@@ -388,8 +391,11 @@ static int hn_rndis_exec1(struct hn_data *hv,return -EINVAL ; } +uint32_t expected =0 ;if (comp !=NULL && -rte_atomic32_cmpset (&hv->rndis_pending,0 , rid) ==0 ) { + !rte_atomic_compare_exchange_strong_explicit ( + &hv->rndis_pending, &expected, rid, + rte_memory_order_acquire, rte_memory_order_relaxed)) {PMD_DRV_LOG (ERR ,"Request already pending" );return -EBUSY ;@@ -405,7 +411,8 @@ static int hn_rndis_exec1(struct hn_data *hv,time_t start =time (NULL );/* Poll primary channel until response received */ -while (hv->rndis_pending == rid) { +while (rte_atomic_load_explicit (&hv->rndis_pending, + rte_memory_order_acquire) == rid) {if (hv->closed)return -ENETDOWN ;@@ -413,7 +420,10 @@ static int hn_rndis_exec1(struct hn_data *hv,PMD_DRV_LOG (ERR ,"RNDIS response timed out" ); -rte_atomic32_cmpset (&hv->rndis_pending, rid, 0); + expected = rid; +rte_atomic_compare_exchange_strong_explicit ( + &hv->rndis_pending, &expected,0 , + rte_memory_order_release, rte_memory_order_relaxed);drivers/net/netvsc/hn_rndis.c +0
-0return -ETIMEDOUT ; }drivers/net/netvsc/hn_rxtx.c index renamed from drivers/net/netvsc/hn_rxtx.c +0
-0
0d770d1b25..6f536610f2100644drivers/net/netvsc/hn_rxtx.c +5
-4@@ -17,7 +17,7 @@#include <rte_string_fns.h> #include <rte_memzone.h> #include <rte_malloc.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_bitmap.h> #include <rte_branch_prediction.h> #include <rte_ether.h> @@ -558,7 +558,8 @@ static void hn_rx_buf_free_cb(void *buf __rte_unused, void *opaque)struct hn_rx_queue *rxq = rxb->rxq;struct hn_data *hv = rxq->hv; -rte_atomic32_dec (&rxq->rxbuf_outstanding); +rte_atomic_fetch_sub_explicit (&rxq->rxbuf_outstanding,1 , + rte_memory_order_release);hn_nvs_ack_rxbuf (hv, rxb->chan, rxb->xactid); }@@ -602,8 +603,8 @@ static void hn_rxpkt(struct hn_rx_queue *rxq, structhn_rx_bufinfo *rxb, * some space available in receive area for later packets. */ if (hv->rx_extmbuf_enable && dlen > hv->rx_copybreak && - (uint32_t )rte_atomic32_read (&rxq->rxbuf_outstanding) < - hv->rxbuf_section_cnt /2 ) { +rte_atomic_load_explicit (&rxq->rxbuf_outstanding, + rte_memory_order_relaxed) < hv- >rxbuf_section_cnt /2 ) {struct rte_mbuf_ext_shared_info *shinfo;drivers/net/netvsc/hn_rxtx.c +2
-1const void *rxbuf;rte_iova_t iova;@@ -619,7 +620,8 @@ static void hn_rxpkt(struct hn_rx_queue *rxq, struct hn_rx_bufinfo *rxb,/* shinfo is already set to 1 by the caller */ if (rte_mbuf_ext_refcnt_update(shinfo, 1) == 2) -rte_atomic32_inc (&rxq->rxbuf_outstanding); +rte_atomic_fetch_add_explicit (&rxq- >rxbuf_outstanding, 1, + rte_memory_order_acquire);drivers/net/netvsc/hn_rxtx.c +0
-0rte_pktmbuf_attach_extbuf (m, data, iova, dlen + headroom, shinfo);drivers/net/netvsc/hn_var.h index renamed from drivers/net/netvsc/hn_var.h +0
-0
574b909c82..d7124a7df9100644drivers/net/netvsc/hn_var.h +3
-4@@ -85,7 +85,7 @@ struct hn_rx_queue {void *event_buf;struct hn_rx_bufinfo *rxbuf_info; -rte_atomic32_t rxbuf_outstanding; +RTE_ATOMIC (uint32_t ) rxbuf_outstanding; };@@ -167,8 +167,8 @@ struct hn_data {uint32_t rndis_agg_pkts;uint32_t rndis_agg_align; -volatile uint32_t rndis_pending; -rte_atomic32_t rndis_req_id; +RTE_ATOMIC (uint32_t ) rndis_pending; +RTE_ATOMIC (uint32_t ) rndis_req_id;uint8_t rndis_resp[256 ];uint32_t rss_hash; --2.53.0
PATCH v8 15/25 event/sw: convert from rte_atomic32 to stdatomic
In reply to Stephen HemmingerUse stdatomic to keep track of inflights.
--- drivers/event/sw/sw_evdev.c | 8 +++++--- drivers/event/sw/sw_evdev.h | 4 ++-- drivers/event/sw/sw_evdev_worker.c | 16 +++++++++++----- 3 files changed, 18 insertions(+), 10 deletions(-)
drivers/event/sw/sw_evdev.c +5 -3
@@ -153,7 +153,9 @@ sw_port_setup(struct rte_eventdev *dev, uint8_t port_id,* the sum to no leak credits */ int possible_inflights = p->inflight_credits + p->inflights; -rte_atomic32_sub (&sw->inflights, possible_inflights); +rte_atomic_fetch_sub_explicit (&sw->inflights, + possible_inflights, + rte_memory_order_release); } *p = (struct sw_port ){0 };/* zero entire structure */
@@ -512,7 +514,7 @@ sw_dev_configure(const struct rte_eventdev *dev) sw->qid_count = conf->nb_event_queues; sw->port_count = conf->nb_event_ports; sw->nb_events_limit = conf->nb_events_limit; -rte_atomic32_set (&sw->inflights,0 ); + sw->inflights =0 ;/* Number of chunks sized for worst-case spread of events across IQs */ num_chunks = ((SW_INFLIGHT_EVENTS_TOTAL/SW_EVS_PER_Q_CHUNK)+1) +
@@ -633,7 +635,7 @@ sw_dump(struct rte_eventdev *dev, FILE *f)fprintf (f,"\tsched cq/qid call: %" PRIu64"\n" , sw->sched_cq_qid_called);fprintf (f,"\tsched no IQ enq: %" PRIu64"\n" , sw->sched_no_iq_enqueues);fprintf (f,"\tsched no CQ enq: %" PRIu64"\n" , sw->sched_no_cq_enqueues); -uint32_t inflights =rte_atomic32_read (&sw->inflights); +uint32_t inflights =rte_atomic_load_explicit (&sw->inflights, rte_memory_order_relaxed);uint32_t credits = sw->nb_events_limit - inflights;fprintf (f,"\tinflight %d, credits: %d\n" , inflights, credits);
drivers/event/sw/sw_evdev.h +2 -2
@@ -8,7 +8,7 @@#include "sw_evdev_log.h" #include <rte_eventdev.h> #include <eventdev_pmd_vdev.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #define SW_DEFAULT_CREDIT_QUANTA 32#define SW_DEFAULT_SCHED_QUANTA 128
@@ -233,7 +233,7 @@ struct sw_evdev {/* Contains all ports - load balanced and directed */ alignas(RTE_CACHE_LINE_SIZE )struct sw_port ports[SW_PORTS_MAX ]; - alignas(RTE_CACHE_LINE_SIZE )rte_atomic32_t inflights; + alignas(RTE_CACHE_LINE_SIZE )RTE_ATOMIC (uint32_t ) inflights;/* * max events in this instance. Cached here for performance.
drivers/event/sw/sw_evdev_worker.c +11 -5
@@ -56,7 +56,7 @@ sw_event_enqueue_burst(void *port, const struct rte_event ev[], uint16_t num)uint8_t new_ops[PORT_ENQUEUE_MAX_BURST_SIZE ];struct sw_port *p = port;struct sw_evdev *sw = (void *)p->sw; -uint32_t sw_inflights =rte_atomic32_read (&sw->inflights); +uint32_t sw_inflights =rte_atomic_load_explicit (&sw->inflights, rte_memory_order_relaxed);uint32_t credit_update_quanta = sw->credit_update_quanta;int new =0 ;
@@ -74,8 +74,10 @@ sw_event_enqueue_burst(void *port, const struct rte_event ev[], uint16_t num)if (sw_inflights + credit_update_quanta > sw->nb_events_limit)return 0 ; -rte_atomic32_add (&sw->inflights, credit_update_quanta); - p->inflight_credits += (credit_update_quanta); +rte_atomic_fetch_add_explicit (&sw->inflights, + credit_update_quanta, + rte_memory_order_acquire); + p->inflight_credits += credit_update_quanta;/* If there are fewer inflight credits than new events, limit * the number of enqueued events.
@@ -124,7 +126,9 @@ sw_event_enqueue_burst(void *port, const struct rte_event ev[], uint16_t num)/* Replenish credits if enough releases are performed */ if (p->inflight_credits >= credit_update_quanta *2 ) { -rte_atomic32_sub (&sw->inflights, credit_update_quanta); +rte_atomic_fetch_sub_explicit (&sw->inflights, + credit_update_quanta, + rte_memory_order_release); p->inflight_credits -= credit_update_quanta; }
@@ -150,7 +154,9 @@ sw_event_dequeue_burst(void *port, struct rte_event *ev, uint16_t num,/* Replenish credits if enough releases are performed */ if (p->inflight_credits >= credit_update_quanta *2 ) { -rte_atomic32_sub (&sw->inflights, credit_update_quanta); +rte_atomic_fetch_sub_explicit (&sw->inflights, + credit_update_quanta, + rte_memory_order_release); p->inflight_credits -= credit_update_quanta; } }
Signature · 1 line
2.53.0
PATCH v8 16/25 bus/vmbus: convert from rte_atomic to stdatomic
In reply to Stephen HemmingerThe tx ring producer uses two cursors:
- tbr->windex which is driver private. It lets producers reserve space concurrently without a lock
- vbr->windex is the host visible commit cursor and has to advance in reservation order so the host never sees it point past unwritten data.
Convert the reservation CAS on tbr->windex to a weak compare exchange, and replace the smp_wmb plus CAS spin that published the commit with rte_wait_until_equal_32 on the previous producer followed by a release store. The release ordering on that store covers what the barrier did.
The wait on the previous producer uses acquire ordering, not relaxed. A release store only carries the writes of the storing thread and anything it has a happens-before edge to. Producers publish in reservation order, so when this thread stores its own windex the host may then consume the data of every earlier producer as well. The acquire on the wait pairs with the earlier producer's release store, putting that producer's data writes into this thread's happens-before set so they are carried by this store too.
vbr->windex stays volatile uint32_t in the packed bufring struct. The host is not a C11 thread.
The atomic qualifier is applied by cast at the single publishing store; the (uintptr_t) launder there avoids a bogus misaligned atomic warning from the packed attribute, since windex sits at offset 0 of a page aligned struct.
--- drivers/bus/vmbus/private.h | 2 +- drivers/bus/vmbus/vmbus_bufring.c | 40 +++++++++++++++++-------------- 2 files changed, 23 insertions(+), 19 deletions(-)
drivers/bus/vmbus/private.h +1 -1
@@ -25,7 +25,7 @@ extern int vmbus_logtype_bus;struct vmbus_br {struct vmbus_bufring *vbr;uint32_t dsize; -uint32_t windex;/* next available location */ +RTE_ATOMIC (uint32_t ) windex;/* next available location */ };#define UIO_NAME_MAX 64
drivers/bus/vmbus/vmbus_bufring.c +22 -18
@@ -15,7 +15,7 @@#include <rte_tailq.h> #include <rte_log.h> #include <rte_malloc.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_memory.h> #include <rte_pause.h> #include <rte_bus_vmbus.h>
@@ -121,17 +121,13 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen, total += iov[i].iov_len; total +=sizeof (save_windex); +/* Get current free location */ + old_windex =rte_atomic_load_explicit (&tbr->windex, + rte_memory_order_relaxed); +/* Reserve space in ring */ do { - uint32_t avail; - - /* Get current free location */ - old_windex = tbr->windex; - - /* Prevent compiler reordering this with calculation */ - rte_compiler_barrier(); - - avail = vmbus_br_availwrite(tbr, old_windex); + uint32_t avail = vmbus_br_availwrite(tbr, old_windex); /* If not enough space in ring, then tell caller. */ if (avail <= total)
@@ -139,8 +135,12 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen, next_windex =vmbus_br_idxinc (old_windex, total, ring_size); -/* Atomic update of next write_index for other threads */ - }while (!rte_atomic32_cmpset (&tbr->windex, old_windex, next_windex)); +/* Atomic update of next write_index for other threads +* Can use weak since easy to recompute and retry. +*/ + }while (!rte_atomic_compare_exchange_weak_explicit ( + &tbr->windex, &old_windex, next_windex, + rte_memory_order_acquire, rte_memory_order_relaxed));/* Space from old..new is now reserved */ windex = old_windex;
@@ -157,12 +157,15 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen,/* The region reserved should match region used */ RTE_ASSERT (windex == next_windex); -/* Ensure that data is available before updating host index */ -rte_smp_wmb (); +/* Wait for previous producer to publish their windex update */ +rte_wait_until_equal_32 (&vbr->windex, old_windex, rte_memory_order_acquire); -/* Checkin for our reservation. wait for our turn to update host */ -while (!rte_atomic32_cmpset (&vbr->windex, old_windex, next_windex)) -rte_pause (); +/* Publish our windex update; prior data writes ordered via release. +* windex is 4-byte aligned in practice (struct is page-aligned, windex +* at offset 0); cast launders the packed-struct alignment-1 attribute. +*/ + rte_atomic_store_explicit((volatile __rte_atomic uint32_t *)(uintptr_t)&vbr->windex, + next_windex, rte_memory_order_release);/* If host had read all data before this, then need to signal */ *need_sig |=vmbus_txbr_need_signal (vbr, old_windex);
@@ -224,7 +227,8 @@ vmbus_rxbr_read(struct vmbus_br *rbr, void *data, size_t dlen, size_t skip)return -EAGAIN ;/* Record where host was when we started read (for debug) */ - rbr->windex = rbr->vbr->windex; +rte_atomic_store_explicit (&rbr->windex, rbr->vbr->windex, + rte_memory_order_relaxed);/* * Copy channel packet from RX bufring.
Signature · 1 line
2.53.0
RE: [EXTERNAL] [PATCH v8 16/25] bus/vmbus: convert from rte_atomic to stdatomic
Quoted 30 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Friday, September 18, 2026 4:10 AM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; Wei Hu <[email protected]>
Subject: [EXTERNAL] [PATCH v8 16/25] bus/vmbus: convert fromrte_atomicto stdatomicThe tx ring producer uses two cursors:
-tbr->windexwhich is driver private. It lets producers reserve space concurrently without a lock
-vbr->windexis the host visible commit cursor and has to advance in reservation order so the host never sees it point past unwritten data.Convert the reservation CAS on
tbr->windexto a weak compare exchange, and replace thesmp_wmbplus CAS spin that published the commit withrte_wait_until_equal_32on the previous producer followed by a release store. The release ordering on that store covers what the barrier did.The wait on the previous producer uses acquire ordering, not relaxed. A release store only carries the writes of the storing thread and anything it has a happens-before edge to. Producers publish in reservation order, so when this thread stores its own windex the host may then consume the data of every earlier producer as well. The acquire on the wait pairs with the earlier producer's release store, putting that producer's data writes into this thread's happens-before set so they are carried by this store too.
Quoted 8 lines
vbr->windexstays volatileuint32_tin the packed bufring struct. The host is not a C11 thread.The atomic qualifier is applied by cast at the single publishing store; the (
uintptr_t) launder there avoids a bogus misaligned atomic warning from the packed attribute, since windex sits at offset 0 of a page aligned struct.Signed-off-by Stephen Hemminger <[email protected]>
Quoted 111 lines
--- drivers/bus/vmbus/private.h | 2 +- drivers/bus/vmbus/vmbus_bufring.c | 40 +++++++++++++++++-------------- 2 files changed, 23 insertions(+), 19 deletions(-)drivers/bus/vmbus/private.h index renamed from drivers/bus/vmbus/private.h +0
-0
6efac86b77..6b7782724f100644drivers/bus/vmbus/private.h +1
-1@@ -25,7 +25,7 @@ extern int vmbus_logtype_bus; struct vmbus_br {struct vmbus_bufring *vbr;uint32_t dsize; -uint32_t windex;/* next available location */ +RTE_ATOMIC (uint32_t ) windex;/* next available location */ };#define UIO_NAME_MAX 64drivers/bus/vmbus/vmbus_bufring.c +6
-10@@ -15,7 +15,7 @@#include <rte_tailq.h> #include <rte_log.h> #include <rte_malloc.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_memory.h> #include <rte_pause.h> #include <rte_bus_vmbus.h> @@ -121,17 +121,13 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen, total += iov[i].iov_len; total +=sizeof (save_windex); +/* Get current free location */ + old_windex =rte_atomic_load_explicit (&tbr->windex, + rte_memory_order_relaxed); +/* Reserve space in ring */ do { - uint32_t avail; - - /* Get current free location */ - old_windex = tbr->windex; - - /* Prevent compiler reordering this with calculation */ - rte_compiler_barrier(); - - avail = vmbus_br_availwrite(tbr, old_windex); + uint32_t avail = vmbus_br_availwrite(tbr, old_windex); /* If not enough space in ring, then tell caller. */drivers/bus/vmbus/vmbus_bufring.c +6
-2if (avail <= total)@@ -139,8 +135,12 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen, next_windex =vmbus_br_idxinc (old_windex, total, ring_size); -/* Atomic update of next write_index for other threads */ - }while (!rte_atomic32_cmpset (&tbr->windex, old_windex, next_windex)); +/* Atomic update of next write_index for other threads +* Can use weak since easy to recompute and retry. +*/ + }while (!rte_atomic_compare_exchange_weak_explicit ( + &tbr->windex, &old_windex, next_windex, + rte_memory_order_acquire, rte_memory_order_relaxed));drivers/bus/vmbus/vmbus_bufring.c +10
-5/* Space from old..new is now reserved */ windex = old_windex;@@ -157,12 +157,15 @@ vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen,/* The region reserved should match region used */ RTE_ASSERT(windex == next_windex); -/* Ensure that data is available before updating host index */ -rte_smp_wmb (); +/* Wait for previous producer to publish their windex update */ +rte_wait_until_equal_32 (&vbr->windex, old_windex, +rte_memory_order_acquire); -/* Checkin for our reservation. wait for our turn to update host */ -while (!rte_atomic32_cmpset (&vbr->windex, old_windex, next_windex)) -rte_pause (); +/* Publish our windex update; prior data writes ordered via release. +* windex is 4-byte aligned in practice (struct is page-aligned, windex +* at offset 0); cast launders the packed-struct alignment-1 attribute. +*/ + rte_atomic_store_explicit((volatile __rte_atomic uint32_t *)(uintptr_t)&vbr->windex, + next_windex, rte_memory_order_release);/* If host had read all data before this, then need to signal */ *need_sig |= vmbus_txbr_need_signal(vbr, old_windex); @@ -224,7 +227,8 @@ vmbus_rxbr_read(struct vmbus_br *rbr, void *data, size_t dlen,
size_tskip)drivers/bus/vmbus/vmbus_bufring.c +2
-2return -EAGAIN ;/* Record where host was when we started read (for debug) */ - rbr->windex = rbr->vbr->windex; +rte_atomic_store_explicit (&rbr->windex, rbr->vbr->windex, + rte_memory_order_relaxed);/* * Copy channel packet from RX bufring. -- 2.53.0
PATCH v8 17/25 net/bnx2x: convert from rte_atomic32 to stdatomic
In reply to Stephen HemmingerReplace the legacy rte_atomic32_* API on sc->scan_fp with the equivalent rte_atomic_*_explicit C11 helpers, ahead of the deprecation of rte_atomicNN_t and its associated wrappers.
All accesses use rte_memory_order_seq_cst, matching the semantics of the legacy API. No functional change.
The scan_fp field is a notification flag between the slow-path command poster (bnx2x_sp_post) and the fastpath task that reaps ramrod completions (bnx2x_handle_fp_tq), also cleared from ecore_state_wait on success, panic, and timeout.
--- drivers/net/bnx2x/bnx2x.c | 6 +++--- drivers/net/bnx2x/bnx2x.h | 2 +- drivers/net/bnx2x/ecore_sp.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-)
drivers/net/bnx2x/bnx2x.c +3 -3
@@ -1098,7 +1098,7 @@ bnx2x_sp_post(struct bnx2x_softc *sc, int command, int cid, uint32_t data_hi,* Ask bnx2x_intr_intr() to process RAMROD * completion whenever it gets scheduled. */ -rte_atomic32_set (&sc->scan_fp,1 ); +rte_atomic_store_explicit (&sc->scan_fp,1 , rte_memory_order_seq_cst);bnx2x_sp_prod_update (sc);return 0 ;
@@ -4575,7 +4575,7 @@ static void bnx2x_handle_fp_tq(struct bnx2x_fastpath *fp)/* update the fastpath index */ bnx2x_update_fp_sb_idx (fp); -if (rte_atomic32_read (&sc->scan_fp) ==1 ) { +if (rte_atomic_load_explicit (&sc->scan_fp, rte_memory_order_seq_cst)) {if (bnx2x_has_rx_work (fp)) { more_rx =bnx2x_rxeof (sc, fp); }
@@ -4586,7 +4586,7 @@ static void bnx2x_handle_fp_tq(struct bnx2x_fastpath *fp)return ; }/* We have completed slow path completion, clear the flag */ -rte_atomic32_set (&sc->scan_fp,0 ); +rte_atomic_store_explicit (&sc->scan_fp,0 , rte_memory_order_seq_cst); } bnx2x_ack_sb(sc, fp->igu_sb_id, USTORM_ID,
drivers/net/bnx2x/bnx2x.h +1 -1
@@ -1043,7 +1043,7 @@ struct bnx2x_softc {#define PERIODIC_STOP 0#define PERIODIC_GO 1volatile unsigned long periodic_flags; -rte_atomic32_t scan_fp; +RTE_ATOMIC (uint32_t ) scan_fp;struct bnx2x_fastpath fp[MAX_RSS_CHAINS ];struct bnx2x_sp_objs sp_objs[MAX_RSS_CHAINS ];
drivers/net/bnx2x/ecore_sp.c +3 -3
@@ -299,21 +299,21 @@ static int ecore_state_wait(struct bnx2x_softc *sc, int state,#ifdef ECORE_STOP_ON_ERROR ECORE_MSG (sc,"exit (cnt %d)" ,5000 - cnt);#endif -rte_atomic32_set (&sc->scan_fp,0 ); +rte_atomic_store_explicit (&sc->scan_fp,0 , rte_memory_order_seq_cst);return ECORE_SUCCESS ; }ECORE_WAIT (sc, delay_us);if (sc->panic) { -rte_atomic32_set (&sc->scan_fp,0 ); +rte_atomic_store_explicit (&sc->scan_fp,0 , rte_memory_order_seq_cst);return ECORE_IO ; } }/* timeout! */ PMD_DRV_LOG (ERR , sc,"timeout waiting for state %d" , state); -rte_atomic32_set (&sc->scan_fp,0 ); +rte_atomic_store_explicit (&sc->scan_fp,0 , rte_memory_order_seq_cst);#ifdef ECORE_STOP_ON_ERROR ecore_panic ();#endif
Signature · 1 line
2.53.0
PATCH v8 18/25 drivers/event: replace rte_atomic32 in selftests
In reply to Stephen HemmingerLast callers in these selftests of the rte_atomicNN_*() family, which is being deprecated.
Convert total_events from rte_atomic32_t to RTE_ATOMIC(uint32_t) for the stack-local instance and __rte_atomic uint32_t * for the pointer in test_core_param. Switch reads and updates to rte_atomic_*_explicit().
Reads in the busy-loop checks and progress logs use relaxed: the counter is purely a "drained yet?" signal and no data is published through it. The fetch_sub on the dequeue path uses release in octeontx (preserving the publish-after-mbuf-free ordering already implied by the seq_cst sub it replaces) and relaxed in dpaa2.
The stack-local atomic_total_events is initialized by direct assignment instead of rte_atomic32_set(), since it is written before any worker is launched.
--- drivers/event/dpaa2/dpaa2_eventdev_selftest.c | 26 +++++---- drivers/event/octeontx/ssovf_evdev_selftest.c | 57 ++++++++++--------- 2 files changed, 43 insertions(+), 40 deletions(-)
drivers/event/dpaa2/dpaa2_eventdev_selftest.c +14 -12
@@ -2,7 +2,7 @@* Copyright 2018-2019 NXP */ -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_common.h> #include <rte_cycles.h> #include <rte_debug.h>
@@ -49,7 +49,7 @@ struct event_attr { };struct test_core_param { -rte_atomic32_t *total_events; + __rte_atomic uint32_t *total_events;uint64_t dequeue_tmo_ticks;uint8_t port;uint8_t sched_type;
@@ -444,10 +444,10 @@ worker_multi_port_fn(void *arg)struct rte_event ev;uint16_t valid_event;uint8_t port = param->port; -rte_atomic32_t *total_events = param->total_events; + __rte_atomic uint32_t *total_events = param->total_events;int ret; -while (rte_atomic32_read (total_events) >0 ) { +while (rte_atomic_load_explicit (total_events, rte_memory_order_relaxed) >0 ) { valid_event =rte_event_dequeue_burst (evdev, port, &ev,1 ,0 );if (!valid_event)continue ;
@@ -455,13 +455,15 @@ worker_multi_port_fn(void *arg) ret =validate_event (&ev);RTE_TEST_ASSERT_SUCCESS (ret,"Failed to validate event" );rte_pktmbuf_free (ev.mbuf); -rte_atomic32_sub (total_events,1 ); + +rte_atomic_fetch_sub_explicit (total_events,1 , + rte_memory_order_relaxed); }return 0 ; }static int -wait_workers_to_join (int lcore,const rte_atomic32_t *count) +wait_workers_to_join(int lcore, const __rte_atomic uint32_t *count) {uint64_t cycles, print_cycles;
@@ -472,15 +474,15 @@ wait_workers_to_join(int lcore, const rte_atomic32_t *count)uint64_t new_cycles =rte_get_timer_cycles ();if (new_cycles - print_cycles >rte_get_timer_hz ()) { -dpaa2_evdev_dbg ("\r%s: events %d" , __func__, -rte_atomic32_read (count)); +dpaa2_evdev_dbg ("\r%s: events %u" , __func__, +rte_atomic_load_explicit (count, rte_memory_order_relaxed)); print_cycles = new_cycles; }if (new_cycles - cycles >rte_get_timer_hz () *10 ) {dpaa2_evdev_info ( -"%s: No schedules for seconds, deadlock (%d)" , +"%s: No schedules for seconds, deadlock (%u)" , __func__, -rte_atomic32_read (count)); +rte_atomic_load_explicit (count, rte_memory_order_relaxed));rte_event_dev_dump (evdev, stdout); cycles = new_cycles;return -1 ;
@@ -500,13 +502,13 @@ launch_workers_and_wait(int (*main_worker)(void *),int w_lcore;int ret;struct test_core_param *param; -rte_atomic32_t atomic_total_events; +RTE_ATOMIC (uint32_t ) atomic_total_events;uint64_t dequeue_tmo_ticks;if (!nb_workers)return 0 ; -rte_atomic32_set (&atomic_total_events, total_events); + atomic_total_events = total_events;RTE_BUILD_BUG_ON (NUM_PACKETS <MAX_EVENTS ); param =malloc (sizeof (struct test_core_param ) * nb_workers);
drivers/event/octeontx/ssovf_evdev_selftest.c +29 -28
178 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v8 19/25 net/hinic: replace rte_atomic32 with stdatomic
In reply to Stephen HemmingerConvert dma_pool::inuse and hinic_os_dep::dma_alloc_cnt to RTE_ATOMIC(uint32_t) and replace rte_atomic32_*() with the rte_atomic_*_explicit() equivalents. The matching local variable and log format change from int/%d to uint32_t/%u.
Note: the memzone names now start with zero; i.e "0000:03:00.0_0" which is harmless side effect.
--- drivers/net/hinic/base/hinic_compat.h | 2 +- drivers/net/hinic/base/hinic_pmd_hwdev.c | 24 ++++++++++++++---------- drivers/net/hinic/base/hinic_pmd_hwdev.h | 4 ++-- 3 files changed, 17 insertions(+), 13 deletions(-)
drivers/net/hinic/base/hinic_compat.h +1 -1
@@ -15,7 +15,7 @@#include <rte_memzone.h> #include <rte_memcpy.h> #include <rte_malloc.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_spinlock.h> #include <rte_cycles.h> #include <rte_log.h>
drivers/net/hinic/base/hinic_pmd_hwdev.c +14 -10
@@ -116,7 +116,8 @@ static void *hinic_dma_mem_zalloc(struct hinic_hwdev *hwdev, size_t size, dma_addr_t *dma_handle, unsigned int align, unsigned int socket_id) { - int rc, alloc_cnt; + int rc; +uint32_t alloc_cnt;const struct rte_memzone *mz;char z_name[RTE_MEMZONE_NAMESIZE ];hash_sig_t sig;
@@ -125,8 +126,9 @@ static void *hinic_dma_mem_zalloc(struct hinic_hwdev *hwdev, size_t size,if (dma_handle ==NULL ||0 == size)return NULL ; - alloc_cnt =rte_atomic32_add_return (&hwdev->os_dep.dma_alloc_cnt,1 ); -snprintf (z_name,sizeof (z_name),"%s_%d" , + alloc_cnt =rte_atomic_fetch_add_explicit (&hwdev->os_dep.dma_alloc_cnt, +1 , rte_memory_order_relaxed); +snprintf (z_name,sizeof (z_name),"%s_%u" , hwdev->pcidev_hdl->name, alloc_cnt); mz = rte_memzone_reserve_aligned(z_name, size, socket_id,
@@ -282,7 +284,6 @@ struct dma_pool *dma_pool_create(const char *name, void *dev,if (!pool)return NULL ; -rte_atomic32_set (&pool->inuse,0 ); pool->elem_size = size; pool->align = align; pool->boundary = boundary;
@@ -294,12 +295,15 @@ struct dma_pool *dma_pool_create(const char *name, void *dev,void dma_pool_destroy (struct dma_pool *pool) { +uint32_t inuse; +if (!pool)return ; -if (rte_atomic32_read (&pool->inuse) !=0 ) { -PMD_DRV_LOG (ERR ,"Leak memory, dma_pool: %s, inuse_count: %d" , - pool->name,rte_atomic32_read (&pool->inuse)); + inuse =rte_atomic_load_explicit (&pool->inuse, rte_memory_order_relaxed); +if (inuse !=0 ) { +PMD_DRV_LOG (ERR ,"Leak memory, dma_pool: %s, inuse_count: %u" , + pool->name, inuse); }rte_free (pool);
@@ -312,14 +316,14 @@ void *dma_pool_alloc(struct pci_pool *pool, dma_addr_t *dma_addr) buf =hinic_dma_mem_zalloc (pool->hwdev, pool->elem_size, dma_addr, (u32 )pool->align,SOCKET_ID_ANY );if (buf) -rte_atomic32_inc (&pool->inuse); +rte_atomic_fetch_add_explicit (&pool->inuse,1 , rte_memory_order_relaxed);return buf; }void dma_pool_free (struct pci_pool *pool,void *vaddr,dma_addr_t dma) { -rte_atomic32_dec (&pool->inuse); +rte_atomic_fetch_sub_explicit (&pool->inuse,1 , rte_memory_order_relaxed);hinic_dma_mem_free (pool->hwdev, pool->elem_size, vaddr, dma); }
@@ -329,7 +333,7 @@ int hinic_osdep_init(struct hinic_hwdev *hwdev)struct rte_hash_parameters dh_params = {0 };struct rte_hash *paddr_hash =NULL ; -rte_atomic32_set (&hwdev->os_dep.dma_alloc_cnt,0 ); + hwdev->os_dep.dma_alloc_cnt =0 ;rte_spinlock_init (&hwdev->os_dep.dma_hash_lock); dh_params.name = hwdev->pcidev_hdl->name;
drivers/net/hinic/base/hinic_pmd_hwdev.h +2 -2
@@ -18,7 +18,7 @@/* dma pool */ struct dma_pool { -rte_atomic32_t inuse; +RTE_ATOMIC (uint32_t ) inuse;size_t elem_size;size_t align;size_t boundary;
@@ -402,7 +402,7 @@ struct hinic_hilink_link_info {/* dma os dependency implementation */ struct hinic_os_dep {/* kernel dma alloc api */ -rte_atomic32_t dma_alloc_cnt; +RTE_ATOMIC (uint32_t ) dma_alloc_cnt;rte_spinlock_t dma_hash_lock;struct rte_hash *dma_addr_hash; };
Signature · 1 line
2.53.0
PATCH v8 20/25 net/txgbe: replace rte_atomic32 with stdatomic
In reply to Stephen HemmingerThe swfw_busy flag guarding the AML SW-FW mailbox is a one-bit lock, so convert it to RTE_ATOMIC(bool) and replace the legacy test-and-set / clear pair with explicit acquire-release:
rte_atomic32_test_and_set ->
rte_atomic_exchange_explicit(.., true, acquire)
rte_atomic32_clear ->
rte_atomic_store_explicit(.., false, release)
Acquire on the take pairs with release on the drop, so accesses inside the critical section are synchronized between successive holders. Default zero-initialization of struct txgbe_hw still gives swfw_busy = false, so no init site needs updating.
Note:
The previous rte_atomic32_test_and_set return value was inverted relative to what this code expected; this patch fixes that. A standalone Fixes: patch is queued in next-net.
--- drivers/net/txgbe/base/txgbe_mng.c | 4 ++-- drivers/net/txgbe/base/txgbe_type.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/txgbe/base/txgbe_mng.c +2 -2
@@ -185,7 +185,7 @@ txgbe_host_interface_command_aml(struct txgbe_hw *hw, u32 *buffer, }/* try to get lock */ -while (rte_atomic32_test_and_set (&hw->swfw_busy)) { +while (rte_atomic_exchange_explicit (&hw->swfw_busy, true, rte_memory_order_acquire)) { timeout--;if (!timeout)return TXGBE_ERR_TIMEOUT ;
@@ -266,7 +266,7 @@ txgbe_host_interface_command_aml(struct txgbe_hw *hw, u32 *buffer,/* index++, index replace txgbe_hic_hdr.checksum */ hw->swfw_index = resp->index ==TXGBE_HIC_HDR_INDEX_MAX ?0 : resp->index +1 ; -rte_atomic32_clear (&hw->swfw_busy); +rte_atomic_store_explicit (&hw->swfw_busy, false, rte_memory_order_release);return err; }
drivers/net/txgbe/base/txgbe_type.h +1 -1
@@ -897,7 +897,7 @@ struct txgbe_hw {rte_spinlock_t phy_lock;/*amlite: new SW-FW mbox */ u8 swfw_index; -rte_atomic32_t swfw_busy; +RTE_ATOMIC (bool ) swfw_busy;bool link_valid;bool reconfig_rx;RTE_ATOMIC (bool ) pf_running;
Signature · 1 line
2.53.0
PATCH v8 21/25 net/vhost: use stdatomic for state flags
In reply to Stephen HemmingerThe flags started and dev_attached are consulted only inside update_queuing_status, where the per-queue handshake provides the real synchronization; their loads and stores are relaxed.
--- drivers/net/vhost/rte_eth_vhost.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +18 -12
@@ -86,14 +86,14 @@ struct vhost_queue { };struct pmd_internal { -rte_atomic32_t dev_attached; +RTE_ATOMIC (uint32_t ) dev_attached;char *iface_name;uint64_t flags;uint64_t disable_flags;uint64_t features;uint16_t max_queues;int vid; -rte_atomic32_t started; +RTE_ATOMIC (uint32_t ) started;bool vlan_strip;bool rx_sw_csum;bool tx_sw_csum;
@@ -756,8 +756,12 @@ update_queuing_status(struct rte_eth_dev *dev, bool wait_queuing)if (!dev->data->rx_queues || !dev->data->tx_queues)return ; -if (rte_atomic32_read (&internal->started) ==0 || -rte_atomic32_read (&internal->dev_attached) ==0 ) +/* These are control-plane flags consulted only here; +* the real data-path handshake is on vq->allow_queuing below. +* Relaxed is sufficient. +*/ +if (rte_atomic_load_explicit (&internal->started, rte_memory_order_relaxed) ==0 || +rte_atomic_load_explicit (&internal->dev_attached, rte_memory_order_relaxed) ==0 ) allow_queuing =0 ; state = vring_states[dev->data->port_id];
@@ -848,7 +852,7 @@ new_device(int vid) } internal->vid = vid; -if (rte_atomic32_read (&internal->started) ==1 ) { +if (rte_atomic_load_explicit (&internal->started, rte_memory_order_relaxed) ==1 ) {queue_setup (eth_dev, internal);if (dev_conf->intr_conf.rxq)eth_vhost_configure_intr (eth_dev);
@@ -863,7 +867,7 @@ new_device(int vid)vhost_dev_csum_configure (eth_dev); -rte_atomic32_set (&internal->dev_attached,1 ); +rte_atomic_store_explicit (&internal->dev_attached,1 , rte_memory_order_relaxed);update_queuing_status (eth_dev, false);VHOST_LOG_LINE (INFO ,"Vhost device %d created" , vid);
@@ -893,7 +897,7 @@ destroy_device(int vid) eth_dev = list->eth_dev; internal = eth_dev->data->dev_private; -rte_atomic32_set (&internal->dev_attached,0 ); +rte_atomic_store_explicit (&internal->dev_attached,0 , rte_memory_order_relaxed);update_queuing_status (eth_dev, true);eth_vhost_unconfigure_intr (eth_dev);
@@ -1148,11 +1152,11 @@ eth_dev_start(struct rte_eth_dev *eth_dev) }queue_setup (eth_dev, internal); -if (rte_atomic32_read (&internal->dev_attached) ==1 && +if (rte_atomic_load_explicit (&internal->dev_attached, rte_memory_order_relaxed) ==1 && dev_conf->intr_conf.rxq)eth_vhost_configure_intr (eth_dev); -rte_atomic32_set (&internal->started,1 ); +rte_atomic_store_explicit (&internal->started,1 , rte_memory_order_relaxed);update_queuing_status (eth_dev, false);for (i =0 ; i < eth_dev->data->nb_rx_queues; i++)
@@ -1170,7 +1174,7 @@ eth_dev_stop(struct rte_eth_dev *dev)uint16_t i; dev->data->dev_started =0 ; -rte_atomic32_set (&internal->started,0 ); +rte_atomic_store_explicit (&internal->started,0 , rte_memory_order_relaxed);update_queuing_status (dev, true);for (i =0 ; i < dev->data->nb_rx_queues; i++)
@@ -1471,8 +1475,10 @@ vhost_dev_priv_dump(struct rte_eth_dev *dev, FILE *f)fprintf (f,"features: 0x%" PRIx64"\n" , internal->features);fprintf (f,"max_queues: %u\n" , internal->max_queues);fprintf (f,"vid: %d\n" , internal->vid); -fprintf (f,"started: %d\n" ,rte_atomic32_read (&internal->started)); -fprintf (f,"dev_attached: %d\n" ,rte_atomic32_read (&internal->dev_attached)); +fprintf (f,"started: %u\n" , +rte_atomic_load_explicit (&internal->started, rte_memory_order_relaxed)); +fprintf (f,"dev_attached: %u\n" , +rte_atomic_load_explicit (&internal->dev_attached, rte_memory_order_relaxed));fprintf (f,"vlan_strip: %d\n" , internal->vlan_strip);fprintf (f,"rx_sw_csum: %d\n" , internal->rx_sw_csum);fprintf (f,"tx_sw_csum: %d\n" , internal->tx_sw_csum);
Signature · 1 line
2.53.0
PATCH v8 22/25 net/vhost: use stdatomic instead of rte_atomic32
In reply to Stephen HemmingerConvert allow_queuing, while_queuing, started, and dev_attached from rte_atomic32_t to RTE_ATOMIC(uint32_t) and replace rte_atomic32_*() with rte_atomic_*_explicit().
The data-path / control-thread handshake on allow_queuing and while_queuing is a Dekker-style mutual-visibility pattern: each side stores its own flag and then loads the peer's. Both legs must be seq_cst to forbid store-load reordering; anything weaker permits both sides to miss each other. The previous rte_atomic32_set/read compiled to plain volatile stores/loads and provided no such ordering, so this also closes a latent ordering hole on weakly-ordered ISAs.
The data-path exit store of while_queuing=0 is release, ordering preceding slot accesses before the control thread observes the data path as idle.
--- drivers/net/vhost/rte_eth_vhost.c | 62 ++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 22 deletions(-)
drivers/net/vhost/rte_eth_vhost.c +40 -22
@@ -73,8 +73,8 @@ struct vhost_stats {struct vhost_queue {int vid; -rte_atomic32_t allow_queuing; -rte_atomic32_t while_queuing; +RTE_ATOMIC (uint32_t ) allow_queuing; +RTE_ATOMIC (uint32_t ) while_queuing;struct pmd_internal *internal;struct rte_mempool *mb_pool;uint16_t port;
@@ -406,12 +406,19 @@ eth_vhost_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)uint16_t i, nb_rx =0 ;uint16_t nb_receive = nb_bufs; -if (unlikely (rte_atomic32_read (&r->allow_queuing) ==0 )) +/* Fast-path early exit; racy load is fine here -- if we miss a +* transition we get caught by the seq_cst check below. +*/ +if (unlikely (rte_atomic_load_explicit (&r->allow_queuing, rte_memory_order_relaxed) ==0 ))return 0 ; -rte_atomic32_set (&r->while_queuing,1 ); - -if (unlikely (rte_atomic32_read (&r->allow_queuing) ==0 )) +/* Announce presence, then re-check. The store and the following +* load MUST both be seq_cst so they are totally ordered with the +* control thread's store-to-allow_queuing / load-of-while_queuing +* pair. Anything weaker permits both sides to miss each other. +*/ +rte_atomic_store_explicit (&r->while_queuing,1 , rte_memory_order_seq_cst); +if (unlikely (rte_atomic_load_explicit (&r->allow_queuing, rte_memory_order_seq_cst) ==0 )) goto out;/* Dequeue packets from guest TX queue */
@@ -446,7 +453,7 @@ eth_vhost_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) } out: -rte_atomic32_set (&r->while_queuing,0 ); +rte_atomic_store_explicit (&r->while_queuing,0 , rte_memory_order_release);return nb_rx; }
@@ -460,12 +467,19 @@ eth_vhost_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)uint64_t nb_bytes =0 ;uint64_t nb_missed =0 ; -if (unlikely (rte_atomic32_read (&r->allow_queuing) ==0 )) +/* Fast-path early exit; racy load is fine here -- if we miss a +* transition we get caught by the seq_cst check below. +*/ +if (unlikely (rte_atomic_load_explicit (&r->allow_queuing, rte_memory_order_relaxed) ==0 ))return 0 ; -rte_atomic32_set (&r->while_queuing,1 ); - -if (unlikely (rte_atomic32_read (&r->allow_queuing) ==0 )) +/* Announce presence, then re-check. The store and the following +* load MUST both be seq_cst so they are totally ordered with the +* control thread's store-to-allow_queuing / load-of-while_queuing +* pair. Anything weaker permits both sides to miss each other. +*/ +rte_atomic_store_explicit (&r->while_queuing,1 , rte_memory_order_seq_cst); +if (unlikely (rte_atomic_load_explicit (&r->allow_queuing, rte_memory_order_seq_cst) ==0 )) goto out;for (i =0 ; i < nb_bufs; i++) {
@@ -515,7 +529,7 @@ eth_vhost_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)for (i =0 ;likely (i < nb_tx); i++)rte_pktmbuf_free (bufs[i]); out: -rte_atomic32_set (&r->while_queuing,0 ); +rte_atomic_store_explicit (&r->while_queuing,0 , rte_memory_order_release);return nb_tx; }
@@ -771,11 +785,13 @@ update_queuing_status(struct rte_eth_dev *dev, bool wait_queuing) vq = dev->data->rx_queues[i];if (vq ==NULL )continue ; -if (allow_queuing && state->cur[vq->virtqueue_id]) -rte_atomic32_set (&vq->allow_queuing,1 ); -else -rte_atomic32_set (&vq->allow_queuing,0 ); -while (wait_queuing &&rte_atomic32_read (&vq->while_queuing)) + +rte_atomic_store_explicit (&vq->allow_queuing, + (allow_queuing && state->cur[vq->virtqueue_id]), + rte_memory_order_seq_cst); + +while (wait_queuing && +rte_atomic_load_explicit (&vq->while_queuing, rte_memory_order_seq_cst))rte_pause (); }
@@ -783,11 +799,13 @@ update_queuing_status(struct rte_eth_dev *dev, bool wait_queuing) vq = dev->data->tx_queues[i];if (vq ==NULL )continue ; -if (allow_queuing && state->cur[vq->virtqueue_id]) -rte_atomic32_set (&vq->allow_queuing,1 ); -else -rte_atomic32_set (&vq->allow_queuing,0 ); -while (wait_queuing &&rte_atomic32_read (&vq->while_queuing)) + +rte_atomic_store_explicit (&vq->allow_queuing, + (allow_queuing && state->cur[vq->virtqueue_id]), + rte_memory_order_seq_cst); + +while (wait_queuing && +rte_atomic_load_explicit (&vq->while_queuing, rte_memory_order_seq_cst))rte_pause (); } }
Signature · 1 line
2.53.0
PATCH v8 23/25 vdpa/ifc: replace rte_atomic32 with stdatomic
In reply to Stephen HemmingerLast in-tree caller of rte_atomic32_*(), blocking deprecation of the rte_atomicNN_*() family.
Replace rte_atomic32_read/set() with rte_atomic_load_explicit() and rte_atomic_store_explicit() on the started, dev_attached, and running flags. Narrow them to bool (only ever hold 0/1) and group with the existing bools to reduce padding in struct ifcvf_internal.
--- drivers/vdpa/ifc/ifcvf_vdpa.c | 37 ++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 18 deletions(-)
drivers/vdpa/ifc/ifcvf_vdpa.c +19 -18
@@ -25,6 +25,7 @@#include <rte_log.h> #include <rte_kvargs.h> #include <rte_devargs.h> +#include <rte_stdatomic.h> #include "base/ifcvf.h"
@@ -68,10 +69,10 @@ struct ifcvf_internal {struct rte_vdpa_device *vdev;uint16_t max_queues;uint64_t features; -rte_atomic32_t started; -rte_atomic32_t dev_attached; -rte_atomic32_t running;rte_spinlock_t lock; +RTE_ATOMIC (bool ) started; +RTE_ATOMIC (bool ) dev_attached; +RTE_ATOMIC (bool ) running;bool sw_lm;bool sw_fallback_running;/* mediated vring for sw fallback */
@@ -712,9 +713,9 @@ update_datapath(struct ifcvf_internal *internal)rte_spinlock_lock (&internal->lock); -if (!rte_atomic32_read (&internal->running) && - (rte_atomic32_read (&internal->started) && -rte_atomic32_read (&internal->dev_attached))) { +if (!rte_atomic_load_explicit (&internal->running, rte_memory_order_seq_cst) && + (rte_atomic_load_explicit (&internal->started, rte_memory_order_seq_cst) && +rte_atomic_load_explicit (&internal->dev_attached, rte_memory_order_seq_cst))) { ret =ifcvf_dma_map (internal, true);if (ret) goto err;
@@ -735,10 +736,10 @@ update_datapath(struct ifcvf_internal *internal)if (ret) goto err; -rte_atomic32_set (&internal->running,1 ); - }else if (rte_atomic32_read (&internal->running) && - (!rte_atomic32_read (&internal->started) || - !rte_atomic32_read (&internal->dev_attached))) { +rte_atomic_store_explicit (&internal->running, true, rte_memory_order_seq_cst); + }else if (rte_atomic_load_explicit (&internal->running, rte_memory_order_seq_cst) && + (!rte_atomic_load_explicit (&internal->started, rte_memory_order_seq_cst) || + !rte_atomic_load_explicit (&internal->dev_attached, rte_memory_order_seq_cst))) {unset_intr_relay (internal); ret =unset_notify_relay (internal);
@@ -755,7 +756,7 @@ update_datapath(struct ifcvf_internal *internal)if (ret) goto err; -rte_atomic32_set (&internal->running,0 ); +rte_atomic_store_explicit (&internal->running, false, rte_memory_order_seq_cst); }rte_spinlock_unlock (&internal->lock);
@@ -1058,7 +1059,7 @@ ifcvf_sw_fallback_switchover(struct ifcvf_internal *internal)vdpa_disable_vfio_intr (internal); -rte_atomic32_set (&internal->running,0 ); +rte_atomic_store_explicit (&internal->running, false, rte_memory_order_seq_cst); ret =rte_vhost_host_notifier_ctrl (vid,RTE_VHOST_QUEUE_ALL , false);if (ret && ret != -ENOTSUP )
@@ -1113,11 +1114,11 @@ ifcvf_dev_config(int vid) internal = list->internal; internal->vid = vid; -rte_atomic32_set (&internal->dev_attached,1 ); +rte_atomic_store_explicit (&internal->dev_attached, true, rte_memory_order_seq_cst);if (update_datapath (internal) <0 ) {DRV_LOG (ERR ,"failed to update datapath for vDPA device %s" , vdev->device->name); -rte_atomic32_set (&internal->dev_attached,0 ); +rte_atomic_store_explicit (&internal->dev_attached, false, rte_memory_order_seq_cst);return -1 ; }
@@ -1166,7 +1167,7 @@ ifcvf_dev_close(int vid) internal->sw_fallback_running = false; }else { -rte_atomic32_set (&internal->dev_attached,0 ); +rte_atomic_store_explicit (&internal->dev_attached, false, rte_memory_order_seq_cst);if (update_datapath (internal) <0 ) {DRV_LOG (ERR ,"failed to update datapath for vDPA device %s" , vdev->device->name);
@@ -1782,10 +1783,10 @@ ifcvf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, goto error; } -rte_atomic32_set (&internal->started,1 ); +rte_atomic_store_explicit (&internal->started, true, rte_memory_order_seq_cst);if (update_datapath (internal) <0 ) {DRV_LOG (ERR ,"failed to update datapath %s" , pci_dev->name); -rte_atomic32_set (&internal->started,0 ); +rte_atomic_store_explicit (&internal->started, false, rte_memory_order_seq_cst);rte_vdpa_unregister_device (internal->vdev);pthread_mutex_lock (&internal_list_lock);TAILQ_REMOVE (&internal_list, list, next);
@@ -1819,7 +1820,7 @@ ifcvf_pci_remove(struct rte_pci_device *pci_dev) } internal = list->internal; -rte_atomic32_set (&internal->started,0 ); +rte_atomic_store_explicit (&internal->started, false, rte_memory_order_seq_cst);if (update_datapath (internal) <0 )DRV_LOG (ERR ,"failed to update datapath %s" , pci_dev->name);
Signature · 1 line
2.53.0
PATCH v8 24/25 test/atomic: drop old rte_atomicNN tests
In reply to Stephen HemmingerThe rte_atomicNN_* APIs will be removed. Only the 128 bit compare-and-swap case test remains.
--- app/test/test_atomic.c | 523 +++-------------------------------------- 1 file changed, 29 insertions(+), 494 deletions(-)
app/test/test_atomic.c +29 -494
@@ -14,61 +14,23 @@#include <rte_per_lcore.h> #include <rte_launch.h> #include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_eal.h> #include <rte_lcore.h> #include <rte_pause.h> -#include <rte_random.h> -#include <rte_hash_crc.h> #include "test.h" #ifndef RTE_TOOLCHAIN_MSVC +/* +* The 128-bit compare and exchange is only implemented for +* x86_64 and aarch64 with GCC/Clang +*/ +#if defined(RTE_ARCH_X86_64 ) || defined(RTE_ARCH_ARM64 )/* * Atomic Variables * ================ * -* - The main test function performs several subtests. The first -* checks that the usual inc/dec/add/sub functions are working -* correctly: -* -* - Initialize 16-bit, 32-bit and 64-bit atomic variables to specific -* values. -* -* - These variables are incremented and decremented on each core at -* the same time in ``test_atomic_usual()``. -* -* - The function checks that once all lcores finish their function, -* the value of the atomic variables are still the same. -* -* - Test "test and set" functions. -* -* - Initialize 16-bit, 32-bit and 64-bit atomic variables to zero. -* -* - Invoke ``test_atomic_tas()`` on each lcore: before doing anything -* else. The cores are waiting a synchro using ``while -* (rte_atomic32_read(&val) == 0)`` which is triggered by the main test -* function. Then all cores do a -* ``rte_atomicXX_test_and_set()`` at the same time. If it is successful, -* it increments another atomic counter. -* -* - The main function checks that the atomic counter was incremented -* twice only (one for 16-bit, one for 32-bit and one for 64-bit values). -* -* - Test "add/sub and return" functions -* -* - Initialize 16-bit, 32-bit and 64-bit atomic variables to zero. -* -* - Invoke ``test_atomic_addsub_return()`` on each lcore. Before doing -* anything else, the cores are waiting a synchro. Each lcore does -* this operation several times:: -* -* tmp = rte_atomicXX_add_return(&a, 1); -* atomic_add(&count, tmp); -* tmp = rte_atomicXX_sub_return(&a, 1); -* atomic_sub(&count, tmp+1); -* -* - At the end of the test, the *count* value must be 0. -* * - Test "128-bit compare and swap" (aarch64 and x86_64 only) * * - Initialize 128-bit atomic variables to zero.
@@ -84,24 +46,8 @@* * - At the end of the test, the *count128* first 64-bit value and * second 64-bit value differ by the total iterations. -* -* - Test "atomic exchange" functions -* -* - Create a 64 bit token that can be tested for data integrity -* -* - Invoke ``test_atomic_exchange`` on each lcore. Before doing -* anything else, the cores wait for a synchronization event. -* Each core then does the following for N iterations: -* -* Generate a new token with a data integrity check -* Exchange the new token for previously generated token -* Increment a counter if a corrupt token was received -* -* - At the end of the test, the number of corrupted tokens must be 0. */ -#define NUM_ATOMIC_TYPES 3 -#define N_BASE 1000000u#define N_MIN 10000u
@@ -112,156 +58,8 @@*/ static unsigned int num_iterations; -static rte_atomic16_t a16; -static rte_atomic32_t a32; -static rte_atomic64_t a64; -static rte_atomic64_t count; -static rte_atomic32_t synchro; - -static int -test_atomic_usual(__rte_unused void *arg) -{ -unsigned int i; - -while (rte_atomic32_read (&synchro) ==0 ) -rte_pause (); - -for (i =0 ; i < num_iterations; i++) -rte_atomic16_inc (&a16); -for (i =0 ; i < num_iterations; i++) -rte_atomic16_dec (&a16); -for (i =0 ; i < (num_iterations /5 ); i++) -rte_atomic16_add (&a16,5 ); -for (i =0 ; i < (num_iterations /5 ); i++) -rte_atomic16_sub (&a16,5 ); - -for (i =0 ; i < num_iterations; i++) -rte_atomic32_inc (&a32); -for (i =0 ; i < num_iterations; i++) -rte_atomic32_dec (&a32); -for (i =0 ; i < (num_iterations /5 ); i++) -rte_atomic32_add (&a32,5 ); -for (i =0 ; i < (num_iterations /5 ); i++) -rte_atomic32_sub (&a32,5 ); - -for (i =0 ; i < num_iterations; i++) -rte_atomic64_inc (&a64); -for (i =0 ; i < num_iterations; i++) -rte_atomic64_dec (&a64); -for (i =0 ; i < (num_iterations /5 ); i++) -rte_atomic64_add (&a64,5 ); -for (i =0 ; i < (num_iterations /5 ); i++) -rte_atomic64_sub (&a64,5 ); - -return 0 ; -} - -static int -test_atomic_tas(__rte_unused void *arg) -{ -while (rte_atomic32_read (&synchro) ==0 ) -rte_pause (); - -if (rte_atomic16_test_and_set (&a16)) -rte_atomic64_inc (&count); -if (rte_atomic32_test_and_set (&a32)) -rte_atomic64_inc (&count); -if (rte_atomic64_test_and_set (&a64)) -rte_atomic64_inc (&count); - -return 0 ; -} - -static int -test_atomic_addsub_and_return(__rte_unused void *arg) -{ -uint32_t tmp16; -uint32_t tmp32; -uint64_t tmp64; -unsigned int i; - -while (rte_atomic32_read (&synchro) ==0 ) -rte_pause (); - -for (i =0 ; i < num_iterations; i++) { - tmp16 =rte_atomic16_add_return (&a16,1 ); -rte_atomic64_add (&count, tmp16); - - tmp16 =rte_atomic16_sub_return (&a16,1 ); -rte_atomic64_sub (&count, tmp16+1 ); - - tmp32 =rte_atomic32_add_return (&a32,1 ); -rte_atomic64_add (&count, tmp32); - - tmp32 =rte_atomic32_sub_return (&a32,1 ); -rte_atomic64_sub (&count, tmp32+1 ); - - tmp64 =rte_atomic64_add_return (&a64,1 ); -rte_atomic64_add (&count, tmp64); - - tmp64 =rte_atomic64_sub_return (&a64,1 ); -rte_atomic64_sub (&count, tmp64+1 ); - } - -return 0 ; -} - -/* -* rte_atomic32_inc_and_test() would increase a 32 bits counter by one and then -* test if that counter is equal to 0. It would return true if the counter is 0 -* and false if the counter is not 0. rte_atomic64_inc_and_test() could do the -* same thing but for a 64 bits counter. -* Here checks that if the 32/64 bits counter is equal to 0 after being atomically -* increased by one. If it is, increase the variable of "count" by one which would -* be checked as the result later. -* -*/ -static int -test_atomic_inc_and_test(__rte_unused void *arg) -{ -while (rte_atomic32_read (&synchro) ==0 ) -rte_pause (); - -if (rte_atomic16_inc_and_test (&a16)) { -rte_atomic64_inc (&count); - } -if (rte_atomic32_inc_and_test (&a32)) { -rte_atomic64_inc (&count); - } -if (rte_atomic64_inc_and_test (&a64)) { -rte_atomic64_inc (&count); - } - -return 0 ; -} - -/* -* rte_atomicXX_dec_and_test() should decrease a 32 bits counter by one and then -* test if that counter is equal to 0. It should return true if the counter is 0 -* and false if the counter is not 0. -* This test checks if the counter is equal to 0 after being atomically -* decreased by one. If it is, increase the value of "count" by one which is to -* be checked as the result later. -*/ -static int -test_atomic_dec_and_test(__rte_unused void *arg) -{ -while (rte_atomic32_read (&synchro) ==0 ) -rte_pause (); - -if (rte_atomic16_dec_and_test (&a16)) -rte_atomic64_inc (&count); - -if (rte_atomic32_dec_and_test (&a32)) -rte_atomic64_inc (&count); +static RTE_ATOMIC (uint32_t ) synchro; -if (rte_atomic64_dec_and_test (&a64)) -rte_atomic64_inc (&count); - -return 0 ; -} - -#if defined(RTE_ARCH_X86_64 ) || defined(RTE_ARCH_ARM64 )static rte_int128_t count128;/*
@@ -278,7 +76,7 @@ test_atomic128_cmp_exchange(__rte_unused void *arg)int success;unsigned int i; -while (rte_atomic32_read (&synchro) ==0 ) +while (rte_atomic_load_explicit (&synchro, rte_memory_order_relaxed) ==0 )rte_pause (); expected = count128;
@@ -292,7 +90,7 @@ test_atomic128_cmp_exchange(__rte_unused void *arg) success =rte_atomic128_cmp_exchange (&count128, &expected, &desired,1 , - __ATOMIC_ACQUIRE, __ATOMIC_RELAXED); + rte_memory_order_acquire, rte_memory_order_relaxed); }while (success ==0 ); do {
@@ -303,7 +101,7 @@ test_atomic128_cmp_exchange(__rte_unused void *arg) success =rte_atomic128_cmp_exchange (&count128, &expected, &desired,1 , - __ATOMIC_RELEASE, __ATOMIC_RELAXED); + rte_memory_order_release, rte_memory_order_relaxed); }while (success ==0 ); do {
@@ -314,7 +112,7 @@ test_atomic128_cmp_exchange(__rte_unused void *arg) success =rte_atomic128_cmp_exchange (&count128, &expected, &desired,1 , - __ATOMIC_ACQ_REL, __ATOMIC_RELAXED); + rte_memory_order_acq_rel, rte_memory_order_relaxed); }while (success ==0 ); do {
@@ -325,260 +123,20 @@ test_atomic128_cmp_exchange(__rte_unused void *arg) success =rte_atomic128_cmp_exchange (&count128, &expected, &desired,1 , - __ATOMIC_RELAXED, __ATOMIC_RELAXED); + rte_memory_order_relaxed, rte_memory_order_relaxed); }while (success ==0 ); }return 0 ; } -#endif - -/* -* Helper definitions/variables/functions for -* atomic exchange tests -*/ -typedef union { -uint16_t u16; -uint8_t u8[2 ]; -}test16_t ; - -typedef union { -uint32_t u32; -uint16_t u16[2 ]; -uint8_t u8[4 ]; -}test32_t ; - -typedef union { -uint64_t u64; -uint32_t u32[2 ]; -uint16_t u16[4 ]; -uint8_t u8[8 ]; -}test64_t ; - -const uint8_t CRC8_POLY =0x91 ; -uint8_t crc8_table[256 ]; - -volatile uint16_t token16; -volatile uint32_t token32; -volatile uint64_t token64; - -static void -build_crc8_table (void ) -{ -uint8_t val; -int i, j; - -for (i =0 ; i <256 ; i++) { - val = i; -for (j =0 ; j <8 ; j++) { -if (val &1 ) - val ^=CRC8_POLY ; - val >>=1 ; - } - crc8_table[i] = val; - } -} - -static uint8_t -get_crc8 (uint8_t *message,int length) -{ -uint8_t crc =0 ; -int i; - -for (i =0 ; i < length; i++) - crc = crc8_table[crc ^ message[i]]; -return crc; -} - -/* -* The atomic exchange test sets up a token in memory and -* then spins up multiple lcores whose job is to generate -* new tokens, exchange that new token for the old one held -* in memory, and then verify that the old token is still -* valid (i.e. the exchange did not corrupt the token). -* -* A token is made up of random data and 8 bits of crc -* covering that random data. The following is an example -* of a 64bit token. -* -* +------------+------------+ -* | 63 56 | 55 0 | -* +------------+------------+ -* | CRC8 | Data | -* +------------+------------+ -*/ -static int -test_atomic_exchange(__rte_unused void *arg) -{ -unsigned int i; -test16_t nt16, ot16;/* new token, old token */ -test32_t nt32, ot32; -test64_t nt64, ot64; - -/* Wait until all of the other threads have been dispatched */ -while (rte_atomic32_read (&synchro) ==0 ) -rte_pause (); - -/* -* Let the battle begin! Every thread attempts to steal the current -* token with an atomic exchange operation and install its own newly -* generated token. If the old token is valid (i.e. it has the -* appropriate crc32 hash for the data) then the test iteration has -* passed. If the token is invalid, increment the counter. -*/ -for (i =0 ; i < num_iterations; i++) { -/* Test 64bit Atomic Exchange */ - nt64.u64 =rte_rand (); - nt64.u8[7 ] =get_crc8 (&nt64.u8[0 ],sizeof (nt64) -1 ); - ot64.u64 =rte_atomic64_exchange (&token64, nt64.u64); -if (ot64.u8[7 ] !=get_crc8 (&ot64.u8[0 ],sizeof (ot64) -1 )) -rte_atomic64_inc (&count); - -/* Test 32bit Atomic Exchange */ - nt32.u32 = (uint32_t )rte_rand (); - nt32.u8[3 ] =get_crc8 (&nt32.u8[0 ],sizeof (nt32) -1 ); - ot32.u32 =rte_atomic32_exchange (&token32, nt32.u32); -if (ot32.u8[3 ] !=get_crc8 (&ot32.u8[0 ],sizeof (ot32) -1 )) -rte_atomic64_inc (&count); - -/* Test 16bit Atomic Exchange */ - nt16.u16 = (uint16_t )rte_rand (); - nt16.u8[1 ] =get_crc8 (&nt16.u8[0 ],sizeof (nt16) -1 ); - ot16.u16 =rte_atomic16_exchange (&token16, nt16.u16); -if (ot16.u8[1 ] !=get_crc8 (&ot16.u8[0 ],sizeof (ot16) -1 )) -rte_atomic64_inc (&count); - } - -return 0 ; -}static int test_atomic (void ) { - num_iterations =test_scale_iterations (N_BASE ,N_MIN ); - -rte_atomic16_init (&a16); -rte_atomic32_init (&a32); -rte_atomic64_init (&a64); -rte_atomic64_init (&count); -rte_atomic32_init (&synchro); - -rte_atomic16_set (&a16,1UL <<10 ); -rte_atomic32_set (&a32,1UL <<10 ); -rte_atomic64_set (&a64,1ULL <<33 ); - -printf ("usual inc/dec/add/sub functions\n" ); - -rte_eal_mp_remote_launch (test_atomic_usual,NULL ,SKIP_MAIN ); -rte_atomic32_set (&synchro,1 ); -rte_eal_mp_wait_lcore (); -rte_atomic32_set (&synchro,0 ); - -if (rte_atomic16_read (&a16) !=1UL <<10 ) { -printf ("Atomic16 usual functions failed\n" ); -return -1 ; - } - -if (rte_atomic32_read (&a32) !=1UL <<10 ) { -printf ("Atomic32 usual functions failed\n" ); -return -1 ; - } - -if (rte_atomic64_read (&a64) !=1ULL <<33 ) { -printf ("Atomic64 usual functions failed\n" ); -return -1 ; - } - -printf ("test and set\n" ); - -rte_atomic64_set (&a64,0 ); -rte_atomic32_set (&a32,0 ); -rte_atomic16_set (&a16,0 ); -rte_atomic64_set (&count,0 ); -rte_eal_mp_remote_launch (test_atomic_tas,NULL ,SKIP_MAIN ); -rte_atomic32_set (&synchro,1 ); -rte_eal_mp_wait_lcore (); -rte_atomic32_set (&synchro,0 ); +uint64_t iterations; -if (rte_atomic64_read (&count) !=NUM_ATOMIC_TYPES ) { -printf ("Atomic test and set failed\n" ); -return -1 ; - } - -printf ("add/sub and return\n" ); - -rte_atomic64_set (&a64,0 ); -rte_atomic32_set (&a32,0 ); -rte_atomic16_set (&a16,0 ); -rte_atomic64_set (&count,0 ); -rte_eal_mp_remote_launch (test_atomic_addsub_and_return,NULL , -SKIP_MAIN ); -rte_atomic32_set (&synchro,1 ); -rte_eal_mp_wait_lcore (); -rte_atomic32_set (&synchro,0 ); - -if (rte_atomic64_read (&count) !=0 ) { -printf ("Atomic add/sub+return failed\n" ); -return -1 ; - } - -/* -* Set a64, a32 and a16 with the same value of minus "number of worker -* lcores", launch all worker lcores to atomically increase by one and -* test them respectively. -* Each lcore should have only one chance to increase a64 by one and -* then check if it is equal to 0, but there should be only one lcore -* that finds that it is 0. It is similar for a32 and a16. -* Then a variable of "count", initialized to zero, is increased by -* one if a64, a32 or a16 is 0 after being increased and tested -* atomically. -* We can check if "count" is finally equal to 3 to see if all worker -* lcores performed "atomic inc and test" right. -*/ -printf ("inc and test\n" ); - -rte_atomic64_clear (&a64); -rte_atomic32_clear (&a32); -rte_atomic16_clear (&a16); -rte_atomic32_clear (&synchro); -rte_atomic64_clear (&count); - -rte_atomic64_set (&a64, (int64_t )(1 - (int64_t )rte_lcore_count ())); -rte_atomic32_set (&a32, (int32_t )(1 - (int32_t )rte_lcore_count ())); -rte_atomic16_set (&a16, (int16_t )(1 - (int16_t )rte_lcore_count ())); -rte_eal_mp_remote_launch (test_atomic_inc_and_test,NULL ,SKIP_MAIN ); -rte_atomic32_set (&synchro,1 ); -rte_eal_mp_wait_lcore (); -rte_atomic32_clear (&synchro); - -if (rte_atomic64_read (&count) !=NUM_ATOMIC_TYPES ) { -printf ("Atomic inc and test failed %d\n" , (int )count.cnt); -return -1 ; - } - -/* -* Same as above, but this time we set the values to "number of worker -* lcores", and decrement instead of increment. -*/ -printf ("dec and test\n" ); - -rte_atomic32_clear (&synchro); -rte_atomic64_clear (&count); - -rte_atomic64_set (&a64, (int64_t )(rte_lcore_count () -1 )); -rte_atomic32_set (&a32, (int32_t )(rte_lcore_count () -1 )); -rte_atomic16_set (&a16, (int16_t )(rte_lcore_count () -1 )); -rte_eal_mp_remote_launch (test_atomic_dec_and_test,NULL ,SKIP_MAIN ); -rte_atomic32_set (&synchro,1 ); -rte_eal_mp_wait_lcore (); -rte_atomic32_clear (&synchro); - -if (rte_atomic64_read (&count) !=NUM_ATOMIC_TYPES ) { -printf ("Atomic dec and test failed\n" ); -return -1 ; - } + num_iterations =test_scale_iterations (N_BASE ,N_MIN ); -#if defined(RTE_ARCH_X86_64 ) || defined(RTE_ARCH_ARM64 )/* * This case tests the functionality of rte_atomic128_cmp_exchange * API. It calls rte_atomic128_cmp_exchange with four kinds of memory
@@ -591,58 +149,35 @@ test_atomic(void)* it is, the test passes. */ printf ("128-bit compare and swap test\n" ); -uint64_t iterations =0 ; -rte_atomic32_clear (&synchro); +rte_atomic_store_explicit (&synchro,0 , rte_memory_order_relaxed); count128.val[0 ] =0 ; count128.val[1 ] =0 ; -rte_eal_mp_remote_launch (test_atomic128_cmp_exchange,NULL , -SKIP_MAIN ); -rte_atomic32_set (&synchro,1 ); +rte_eal_mp_remote_launch (test_atomic128_cmp_exchange,NULL ,SKIP_MAIN ); +rte_atomic_store_explicit (&synchro,1 , rte_memory_order_relaxed);rte_eal_mp_wait_lcore (); -rte_atomic32_clear (&synchro); +rte_atomic_store_explicit (&synchro,0 , rte_memory_order_relaxed); iterations = count128.val[0 ] - count128.val[1 ]; -if (iterations != (uint64_t )4 *num_iterations*(rte_lcore_count ()-1 )) { +if (iterations != (uint64_t )4 * num_iterations * (rte_lcore_count () -1 )) {printf ("128-bit compare and swap failed\n" );return -1 ; } -#endif -/* -* Test 16/32/64bit atomic exchange. -*/ -test64_t t; - -printf ("exchange test\n" ); - -rte_atomic32_clear (&synchro); -rte_atomic64_clear (&count); - -/* Generate the CRC8 lookup table */ -build_crc8_table (); +return 0 ; +} -/* Create the initial tokens used by the test */ - t.u64 =rte_rand (); - token16 = (get_crc8 (&t.u8[0 ],sizeof (token16) -1 ) <<8 ) - | (t.u16[0 ] &0x00ff ); - token32 = ((uint32_t )get_crc8 (&t.u8[0 ],sizeof (token32) -1 ) <<24 ) - | (t.u32[0 ] &0x00ffffff ); - token64 = ((uint64_t )get_crc8 (&t.u8[0 ],sizeof (token64) -1 ) <<56 ) - | (t.u64 &0x00ffffffffffffff ); +#else -rte_eal_mp_remote_launch (test_atomic_exchange,NULL ,SKIP_MAIN ); -rte_atomic32_set (&synchro,1 ); -rte_eal_mp_wait_lcore (); -rte_atomic32_clear (&synchro); +static int +test_atomic (void ) +{ +printf ("128 bit exchange not implemented\n" ); +return TEST_SKIPPED ; +} -if (rte_atomic64_read (&count) >0 ) { -printf ("Atomic exchange test failed\n" ); -return -1 ; - } +#endif - return 0; -}REGISTER_FAST_TEST (atomic_autotest,NOHUGE_SKIP ,ASAN_OK , test_atomic);#endif /* RTE_TOOLCHAIN_MSVC */
Signature · 1 line
2.53.0
PATCH v8 25/25 eal: remove rte_atomicNN functions
In reply to Stephen HemmingerNow that all the drivers and other code have been converted to use stdatomic, the functions for rte_atomic16, rte_atomic32, and rte_atomic64 can be removed.
--- devtools/checkpatches.sh | 8 - .../prog_guide/writing_efficient_code.rst | 9 +- doc/guides/rel_notes/deprecation.rst | 7 - doc/guides/rel_notes/release_26_11.rst | 7 + lib/eal/arm/include/rte_atomic_32.h | 4 - lib/eal/arm/include/rte_atomic_64.h | 4 - lib/eal/include/generic/rte_atomic.h | 928 ------------------ lib/eal/loongarch/include/rte_atomic.h | 4 - lib/eal/ppc/include/rte_atomic.h | 175 ---- lib/eal/riscv/include/rte_atomic.h | 4 - lib/eal/x86/include/meson.build | 1 - lib/eal/x86/include/rte_atomic.h | 187 +--- lib/eal/x86/include/rte_atomic_32.h | 212 ---- lib/eal/x86/include/rte_atomic_64.h | 157 --- 14 files changed, 9 insertions(+), 1698 deletions(-) delete mode 100644 lib/eal/x86/include/rte_atomic_32.h
devtools/checkpatches.sh +0 -8
@@ -121,14 +121,6 @@ check_forbidden_additions() { # <patch> -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ "$1" || res=1 - # refrain from new additions of 16/32/64 bits rte_atomicNN_xxx() - awk -v FOLDERS="lib drivers app examples" \ - -v EXPRESSIONS="rte_atomic[0-9][0-9]_.*\\\(" \ - -v RET_ON_FAIL=1 \ - -v MESSAGE='Using rte_atomicNN_xxx' \ - -f $(dirname $(readlink -f $0))/check-forbidden-tokens.awk \ - "$1" || res=1 - # refrain from new additions of rte_smp_[r/w]mb() awk -v FOLDERS="lib drivers app examples" \ -v EXPRESSIONS="rte_smp_(r|w)?mb\\\(" \
doc/guides/prog_guide/writing_efficient_code.rst +1 -8
@@ -186,15 +186,8 @@ For instance, the Read-Copy-Update (RCU) algorithm can frequently replace simple Atomic Operations: Use C11 Atomic Builtins ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -DPDK generic rte_atomic operations are implemented by __sync builtins. These -__sync builtins result in full barriers on aarch64, which are unnecessary -in many use cases. They can be replaced by __atomic builtins that conform to -the C11 memory model and provide finer memory order control. +DPDK has been converted to C11 memory model atomics. -So replacing the rte_atomic operations with __atomic builtins might improve -performance for aarch64 machines. - -Some typical optimization cases are listed below: Atomicity ^^^^^^^^^
doc/guides/rel_notes/deprecation.rst +0 -7
@@ -39,13 +39,6 @@ Deprecation Notices as part of its internal API. All drivers will be adjusted to use the new unified VFIO container device assignment API. -* rte_atomicNN_xxx: These APIs do not take memory order parameter. This does - not allow for writing optimized code for all the CPU architectures supported - in DPDK. DPDK has adopted the atomic operations from - https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html. These - operations must be used for patches that need to be merged in 20.08 onwards. - This change will not introduce any performance degradation. - * rte_smp_*mb: These APIs provide full barrier functionality. However, many use cases do not require full barriers. To support such use cases, DPDK has adopted atomic operations from
doc/guides/rel_notes/release_26_11.rst +7 -0
@@ -79,6 +79,13 @@ Removed Items ``rte_rib6_is_equal`` * table: ``RTE_LPM_IPV6_ADDR_SIZE`` +* Removed the ``rte_atomicNN_t`` types and the ``rte_atomicNN_*`` functions + (16, 32 and 64 bit variants of ``init``, ``read``, ``set``, ``add``, + ``sub``, ``inc``, ``dec``, ``add_return``, ``sub_return``, + ``inc_and_test``, ``dec_and_test``, ``test_and_set``, ``clear``, + ``cmpset`` and ``exchange``). Use the C11 ``rte_atomic_*_explicit`` + operations instead. + API Changes -----------
lib/eal/arm/include/rte_atomic_32.h +0 -4
@@ -5,10 +5,6 @@#ifndef _RTE_ATOMIC_ARM32_H_#define _RTE_ATOMIC_ARM32_H_ -#ifndef RTE_FORCE_INTRINSICS -# error Platform must be built with RTE_FORCE_INTRINSICS -#endif -#include "generic/rte_atomic.h" #ifdef __cplusplus
lib/eal/arm/include/rte_atomic_64.h +0 -4
@@ -6,10 +6,6 @@#ifndef _RTE_ATOMIC_ARM64_H_#define _RTE_ATOMIC_ARM64_H_ -#ifndef RTE_FORCE_INTRINSICS -# error Platform must be built with RTE_FORCE_INTRINSICS -#endif -#include "generic/rte_atomic.h" #include <rte_branch_prediction.h> #include <rte_debug.h>
lib/eal/include/generic/rte_atomic.h +0 -928
934 lines not on this page · raw message
lib/eal/loongarch/include/rte_atomic.h +0 -4
@@ -5,10 +5,6 @@#ifndef RTE_ATOMIC_LOONGARCH_H #define RTE_ATOMIC_LOONGARCH_H -#ifndef RTE_FORCE_INTRINSICS -# error Platform must be built with RTE_FORCE_INTRINSICS -#endif -#include <rte_common.h> #include "generic/rte_atomic.h"
lib/eal/ppc/include/rte_atomic.h +0 -175
181 lines not on this page · raw message
lib/eal/riscv/include/rte_atomic.h +0 -4
@@ -8,10 +8,6 @@#ifndef RTE_ATOMIC_RISCV_H #define RTE_ATOMIC_RISCV_H -#ifndef RTE_FORCE_INTRINSICS -# error Platform must be built with RTE_FORCE_INTRINSICS -#endif -#include <stdint.h> #include <rte_common.h> #include <rte_config.h>
lib/eal/x86/include/meson.build +0 -1
@@ -17,7 +17,6 @@ dpdk_arch_headers += files( 'rte_vect.h', ) dpdk_arch_indirect_headers += files( - 'rte_atomic_32.h', 'rte_atomic_64.h', 'rte_byteorder_32.h', 'rte_byteorder_64.h',
lib/eal/x86/include/rte_atomic.h +1 -186
193 lines not on this page · raw message
lib/eal/x86/include/rte_atomic_32.h deleted +0 -212
212 lines not on this page · raw message
lib/eal/x86/include/rte_atomic_64.h +0 -157
163 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH v8 00/25] remove legacy atomic functions
In reply to Stephen HemmingerQuoted 116 lines · Stephen Hemminger
The rte_atomicNN_* family was flagged for deprecation in 2021 by commit
3ec965b6de12("doc: update atomic operation deprecation") but removal had stalled and usage continued to grow.This series finishes converting every remaining in-tree caller to the C11-style rte_atomic_*_explicit() /
RTE_ATOMIC()API, then removes the legacy functions. The deprecation has been out there long enough so not a big surprise to users.Series-acked-by Morten Brørup <[email protected]>v8 - drop unused
in_useflag in dpaa
- consolidate fslmc changes
- vmbus: use acquire ordering on the wait for the previous producer so an earlier producer's data writes are carried by this thread's release store (Long Li)
- collect review tags
- more AI review commentsv7 - fix some review comments
- remove unused macros
- removeret_atomicNNfunctions (rather than deprecating them).v6 - rebase for 26.11
- address some more AI review commentsStephen Hemminger (25):
bpf: use C11 atomics inBPF_ST_ATOMIC_REGnet/bonding: use stdatomic
net/nbl: remove unusedrte_atomic16field net/ena: replace use ofrte_atomicNNnet/failsafe: convert to stdatomic
net/enic: do not use deprecatedrte_atomic64net/pfe: use ethdev linkstatus helpers net/sfc: replacerte_atomicwith stdatomiccrypto/ccp: replace use ofrte_atomic64with stdatomic bus/dpaa: remove unusedin_usefield bus/dpaa: replacerte_atomic16with stdatomic bus/fslmc: replacerte_atomicwith stdatomic common/dpaax: remove unused atomic wrappers net/netvsc: replacerte_atomic32with stdatomic event/sw: convert fromrte_atomic32to stdatomic bus/vmbus: convert fromrte_atomicto stdatomic net/bnx2x: convert fromrte_atomic32to stdatomicdrivers/event: replacerte_atomic32in selftests net/hinic: replacerte_atomic32with stdatomic net/txgbe: replacerte_atomic32with stdatomic net/vhost: use stdatomic for state flags net/vhost: use stdatomic instead ofrte_atomic32vdpa/ifc: replacerte_atomic32with stdatomic test/atomic: drop oldrte_atomicNNtests
eal: removerte_atomicNNfunctionsapp/test/test_atomic.c | 523 +--------- devtools/checkpatches.sh | 8 - .../prog_guide/writing_efficient_code.rst | 9 +- doc/guides/rel_notes/deprecation.rst | 7 - doc/guides/rel_notes/release_26_11.rst | 7 + drivers/bus/dpaa/base/qbman/bman.c | 7 +- drivers/bus/dpaa/base/qbman/qman.c | 9 +- drivers/bus/fslmc/portal/dpaa2_hw_dpbp.c | 11 +- drivers/bus/fslmc/portal/dpaa2_hw_dpci.c | 11 +- drivers/bus/fslmc/portal/dpaa2_hw_dpcon.c | 11 +- drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 14 +- drivers/bus/fslmc/portal/dpaa2_hw_pvt.h | 9 +- drivers/bus/fslmc/qbman/include/compat.h | 18 +- drivers/bus/vmbus/private.h | 2 +- drivers/bus/vmbus/vmbus_bufring.c | 40 +- drivers/common/dpaax/compat.h | 14 - drivers/crypto/ccp/ccp_crypto.c | 11 +- drivers/crypto/ccp/ccp_crypto.h | 2 +- drivers/crypto/ccp/ccp_dev.c | 10 +- drivers/crypto/ccp/ccp_dev.h | 4 +- drivers/event/dpaa2/dpaa2_eventdev_selftest.c | 26 +- drivers/event/octeontx/ssovf_evdev_selftest.c | 57 +- drivers/event/sw/sw_evdev.c | 8 +- drivers/event/sw/sw_evdev.h | 4 +- drivers/event/sw/sw_evdev_worker.c | 16 +- drivers/net/bnx2x/bnx2x.c | 6 +- drivers/net/bnx2x/bnx2x.h | 2 +- drivers/net/bnx2x/ecore_sp.c | 6 +- drivers/net/bonding/eth_bond_8023ad_private.h | 6 +- drivers/net/bonding/rte_eth_bond_8023ad.c | 35 +- drivers/net/ena/base/ena_plat_dpdk.h | 14 +- drivers/net/ena/ena_ethdev.c | 21 +- drivers/net/ena/ena_ethdev.h | 7 +- drivers/net/enic/enic.h | 6 +- drivers/net/enic/enic_compat.h | 1 - drivers/net/enic/enic_main.c | 17 +- drivers/net/enic/enic_rxtx.c | 14 +- drivers/net/enic/enic_rxtx_vec_avx2.c | 4 +- drivers/net/failsafe/failsafe_ops.c | 12 +- drivers/net/failsafe/failsafe_private.h | 29 +- drivers/net/failsafe/failsafe_rxtx.c | 2 +- drivers/net/hinic/base/hinic_compat.h | 2 +- drivers/net/hinic/base/hinic_pmd_hwdev.c | 24 +- drivers/net/hinic/base/hinic_pmd_hwdev.h | 4 +- drivers/net/nbl/nbl_hw/nbl_resource.h | 1 - drivers/net/netvsc/hn_rndis.c | 28 +- drivers/net/netvsc/hn_rxtx.c | 12 +- drivers/net/netvsc/hn_var.h | 6 +- drivers/net/pfe/pfe_ethdev.c | 32 +- drivers/net/sfc/sfc.c | 9 +- drivers/net/sfc/sfc.h | 4 +- drivers/net/sfc/sfc_port.c | 7 +- drivers/net/sfc/sfc_stats.h | 2 +- drivers/net/txgbe/base/txgbe_mng.c | 4 +- drivers/net/txgbe/base/txgbe_type.h | 2 +- drivers/net/vhost/rte_eth_vhost.c | 92 +- drivers/vdpa/ifc/ifcvf_vdpa.c | 37 +- lib/bpf/bpf_exec.c | 13 +- lib/eal/arm/include/rte_atomic_32.h | 4 - lib/eal/arm/include/rte_atomic_64.h | 4 - lib/eal/include/generic/rte_atomic.h | 928 ------------------ lib/eal/loongarch/include/rte_atomic.h | 4 -
Quoted 8 lines
lib/eal/ppc/include/rte_atomic.h | 175 ---- lib/eal/riscv/include/rte_atomic.h | 4 - lib/eal/x86/include/meson.build | 1 - lib/eal/x86/include/rte_atomic.h | 187 +--- lib/eal/x86/include/rte_atomic_32.h | 212 ---- lib/eal/x86/include/rte_atomic_64.h | 157 --- 68 files changed, 416 insertions(+), 2559 deletions(-) delete mode 100644 lib/eal/x86/include/rte_atomic_32.h
AI review spots that concurrent non atomic increments is undefined behavior (in at least net/ena).
There is also one nit in net/enic.
There may be some leftover, but I spotted nothing more for now. The series lgtm on the principle.
Signature · 1 line
David Marchand
v9 cover remove legacy atomic functions
In reply to Stephen HemmingerThe rte_atomicNN_* family was flagged for deprecation in 2021 by commit 3ec965b6de12 ("doc: update atomic operation deprecation") but removal had stalled and usage continued to grow.
This series finishes converting every remaining in-tree caller to the C11-style rte_atomic_*_explicit() / RTE_ATOMIC() API, then removes the legacy functions. The deprecation has been out there long enough so not a big surprise to users.
The eal/ring/smp_mb changes that were part of the earlier RFC and v1-v5 postings are not in this series; they are being handled separately since the ring memory model discussion is independent of removing the legacy API.
v9 - rebase to main
- enic: remove extra memset
- failsafe: zmalloc of txq and rxq consistency
v8 - drop unused in_use flag in dpaa
- consolidate fslmc changes
- vmbus: use acquire ordering on the wait for the previous producer so an earlier producer's data writes are carried by this thread's release store (Long Li)
- collect review tags
- more AI review comments
v7 - fix some review comments
- remove unused macros
- remove ret_atomicNN functions (rather than deprecating them).
v6 - rebase for 26.11
- address some more AI review comments
Stephen Hemminger (25):
bpf: use C11 atomics in BPF_ST_ATOMIC_REG net/bonding: use stdatomic
net/nbl: remove unused rte_atomic16 field net/ena: replace use of rte_atomicNN net/failsafe: convert to stdatomic
net/enic: do not use deprecated rte_atomic64 net/pfe: use ethdev linkstatus helpers net/sfc: replace rte_atomic with stdatomic crypto/ccp: replace use of rte_atomic64 with stdatomic bus/dpaa: remove unused in_use field bus/dpaa: replace rte_atomic16 with stdatomic bus/fslmc: replace rte_atomic with stdatomic common/dpaax: remove unused atomic wrappers net/netvsc: replace rte_atomic32 with stdatomic event/sw: convert from rte_atomic32 to stdatomic bus/vmbus: convert from rte_atomic to stdatomic net/bnx2x: convert from rte_atomic32 to stdatomic drivers/event: replace rte_atomic32 in selftests net/hinic: replace rte_atomic32 with stdatomic net/txgbe: replace rte_atomic32 with stdatomic net/vhost: use stdatomic for state flags net/vhost: use stdatomic instead of rte_atomic32 vdpa/ifc: replace rte_atomic32 with stdatomic test/atomic: drop old rte_atomicNN tests
eal: remove rte_atomicNN functions
app/test/test_atomic.c | 523 +--------- devtools/checkpatches.sh | 8 - .../prog_guide/writing_efficient_code.rst | 9 +- doc/guides/rel_notes/deprecation.rst | 7 - doc/guides/rel_notes/release_26_11.rst | 7 + drivers/bus/dpaa/base/qbman/bman.c | 7 +- drivers/bus/dpaa/base/qbman/qman.c | 9 +- drivers/bus/fslmc/portal/dpaa2_hw_dpbp.c | 11 +- drivers/bus/fslmc/portal/dpaa2_hw_dpci.c | 11 +- drivers/bus/fslmc/portal/dpaa2_hw_dpcon.c | 11 +- drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 14 +- drivers/bus/fslmc/portal/dpaa2_hw_pvt.h | 9 +- drivers/bus/fslmc/qbman/include/compat.h | 18 +- drivers/bus/vmbus/private.h | 2 +- drivers/bus/vmbus/vmbus_bufring.c | 40 +- drivers/common/dpaax/compat.h | 14 - drivers/crypto/ccp/ccp_crypto.c | 11 +- drivers/crypto/ccp/ccp_crypto.h | 2 +- drivers/crypto/ccp/ccp_dev.c | 10 +- drivers/crypto/ccp/ccp_dev.h | 4 +- drivers/event/dpaa2/dpaa2_eventdev_selftest.c | 26 +- drivers/event/octeontx/ssovf_evdev_selftest.c | 57 +- drivers/event/sw/sw_evdev.c | 8 +- drivers/event/sw/sw_evdev.h | 4 +- drivers/event/sw/sw_evdev_worker.c | 16 +- drivers/net/bnx2x/bnx2x.c | 6 +- drivers/net/bnx2x/bnx2x.h | 2 +- drivers/net/bnx2x/ecore_sp.c | 6 +- drivers/net/bonding/eth_bond_8023ad_private.h | 6 +- drivers/net/bonding/rte_eth_bond_8023ad.c | 35 +- drivers/net/ena/base/ena_plat_dpdk.h | 14 +- drivers/net/ena/ena_ethdev.c | 21 +- drivers/net/ena/ena_ethdev.h | 7 +- drivers/net/enic/enic.h | 6 +- drivers/net/enic/enic_compat.h | 1 - drivers/net/enic/enic_main.c | 21 +- drivers/net/enic/enic_rxtx.c | 14 +- drivers/net/enic/enic_rxtx_vec_avx2.c | 4 +- drivers/net/failsafe/failsafe_ops.c | 16 +- drivers/net/failsafe/failsafe_private.h | 29 +- drivers/net/failsafe/failsafe_rxtx.c | 2 +- drivers/net/hinic/base/hinic_compat.h | 2 +- drivers/net/hinic/base/hinic_pmd_hwdev.c | 24 +- drivers/net/hinic/base/hinic_pmd_hwdev.h | 4 +- drivers/net/nbl/nbl_hw/nbl_resource.h | 1 - drivers/net/netvsc/hn_rndis.c | 28 +- drivers/net/netvsc/hn_rxtx.c | 12 +- drivers/net/netvsc/hn_var.h | 6 +- drivers/net/pfe/pfe_ethdev.c | 32 +- drivers/net/sfc/sfc.c | 9 +- drivers/net/sfc/sfc.h | 4 +- drivers/net/sfc/sfc_port.c | 7 +- drivers/net/sfc/sfc_stats.h | 2 +- drivers/net/txgbe/base/txgbe_mng.c | 4 +- drivers/net/txgbe/base/txgbe_type.h | 2 +- drivers/net/vhost/rte_eth_vhost.c | 92 +- drivers/vdpa/ifc/ifcvf_vdpa.c | 37 +- lib/bpf/bpf_exec.c | 13 +- lib/eal/arm/include/rte_atomic_32.h | 4 - lib/eal/arm/include/rte_atomic_64.h | 4 - lib/eal/include/generic/rte_atomic.h | 928 ------------------ lib/eal/loongarch/include/rte_atomic.h | 4 - lib/eal/ppc/include/rte_atomic.h | 175 ---- lib/eal/riscv/include/rte_atomic.h | 4 - lib/eal/x86/include/meson.build | 1 - lib/eal/x86/include/rte_atomic.h | 187 +--- lib/eal/x86/include/rte_atomic_32.h | 212 ---- lib/eal/x86/include/rte_atomic_64.h | 157 --- 68 files changed, 415 insertions(+), 2568 deletions(-) delete mode 100644 lib/eal/x86/include/rte_atomic_32.h
Signature · 1 line
2.53.0
PATCH v9 1/25 bpf: use C11 atomics in BPF_ST_ATOMIC_REG
The BPF_ST_ATOMIC_REG macro generated code with deprecated rte_atomicNN_add and rte_atomicNN_exchange.
Replace this with the equivalent rte_stdatomic definitions. Use memory order seq_cst to preserve the previous behavior of rte_atomicNN_add() / rte_atomicNN_exchange() and match the behavior of the Linux kernel BPF interpreter for these opcodes.
--- lib/bpf/bpf_exec.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
lib/bpf/bpf_exec.c +7 -6
@@ -11,6 +11,7 @@#include <rte_debug.h> #include <rte_byteorder.h> #include <rte_errno.h> +#include <rte_stdatomic.h> #include "bpf_impl.h"
@@ -66,16 +67,16 @@ (type)(reg)[(ins)->src_reg])#define BPF_ST_ATOMIC_REG (reg, ins, tp) do { \ + RTE_ATOMIC(uint##tp##_t) *dst = (RTE_ATOMIC(uint##tp##_t) *) \ + (uintptr_t)((reg)[(ins)->dst_reg] + (ins)->off); \ switch (ins->imm) { \ case BPF_ATOMIC_ADD: \ - rte_atomic##tp##_add((rte_atomic##tp##_t *) \ - (uintptr_t)((reg)[(ins)->dst_reg] + (ins)->off), \ - (reg)[(ins)->src_reg]); \ + rte_atomic_fetch_add_explicit(dst, \ + (reg)[(ins)->src_reg], rte_memory_order_seq_cst); \ break; \ case BPF_ATOMIC_XCHG: \ - (reg)[(ins)->src_reg] = rte_atomic##tp##_exchange((uint##tp##_t *) \ - (uintptr_t)((reg)[(ins)->dst_reg] + (ins)->off), \ - (reg)[(ins)->src_reg]); \ + (reg)[(ins)->src_reg] = rte_atomic_exchange_explicit(dst, \ + (reg)[(ins)->src_reg], rte_memory_order_seq_cst); \ break; \ default: \/* this should be caught by validator and never reach here */ \
Signature · 1 line
2.53.0
PATCH v9 2/25 net/bonding: use stdatomic
In reply to Stephen HemmingerThe old rte_atomic16 and rte_atomic64 functions are deprecated. Replace with rte_stdatomic for managing warning and timer flags.
--- drivers/net/bonding/eth_bond_8023ad_private.h | 6 ++-- drivers/net/bonding/rte_eth_bond_8023ad.c | 35 ++++++++----------- 2 files changed, 17 insertions(+), 24 deletions(-)
drivers/net/bonding/eth_bond_8023ad_private.h +3 -3
@@ -9,7 +9,7 @@#include <rte_ether.h> #include <rte_byteorder.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_flow.h> #include "rte_eth_bond_8023ad.h"
@@ -140,10 +140,10 @@ struct port {/** Timer which is also used as mutex. If is 0 (not running) RX marker * packet might be responded. Otherwise shall be dropped. It is zeroed in * mode 4 callback function after expire. */ -volatile uint64_t rx_marker_timer; +RTE_ATOMIC (uint64_t ) rx_marker_timer;uint64_t warning_timer; -volatile uint16_t warnings_to_show; +RTE_ATOMIC (uint16_t ) warnings_to_show;/** Memory pool used to allocate slow queues */ struct rte_mempool *slow_pool;
drivers/net/bonding/rte_eth_bond_8023ad.c +14 -21
@@ -171,27 +171,17 @@ timer_is_running(uint64_t *timer)static void set_warning_flags (struct port *port,uint16_t flags) { -int retval; -uint16_t old; -uint16_t new_flag =0 ; - -do { - old = port->warnings_to_show; - new_flag = old | flags; - retval =rte_atomic16_cmpset (&port->warnings_to_show, old, new_flag); - }while (unlikely (retval ==0 )); +rte_atomic_fetch_or_explicit (&port->warnings_to_show, flags, rte_memory_order_relaxed); }static void show_warnings (uint16_t member_id) {struct port *port = &bond_mode_8023ad_ports[member_id]; -uint8_t warnings; - -do { - warnings = port->warnings_to_show; - }while (rte_atomic16_cmpset (&port->warnings_to_show, warnings,0 ) ==0 ); +uint16_t warnings; + warnings =rte_atomic_exchange_explicit (&port->warnings_to_show,0 , + rte_memory_order_relaxed);if (!warnings)return ;
@@ -1335,7 +1325,6 @@ bond_mode_8023ad_handle_slow_pkt(struct bond_dev_private *internals,struct port *port = &bond_mode_8023ad_ports[member_id];struct marker_header *m_hdr;uint64_t marker_timer, old_marker_timer; -int retval;uint8_t wrn, subtype;/* If packet is a marker, we send response now by reusing given packet * and update only source MAC, destination MAC is multicast so don't
@@ -1352,17 +1341,19 @@ bond_mode_8023ad_handle_slow_pkt(struct bond_dev_private *internals, }/* Setup marker timer. Do it in loop in case concurrent access. */ + old_marker_timer =rte_atomic_load_explicit (&port->rx_marker_timer, + rte_memory_order_acquire);do { - old_marker_timer = port->rx_marker_timer;if (!timer_is_expired (&old_marker_timer)) { wrn =WRN_RX_MARKER_TO_FAST ; goto free_out; }timer_set (&marker_timer, mode4->rx_marker_timeout); - retval =rte_atomic64_cmpset (&port->rx_marker_timer, - old_marker_timer, marker_timer); - }while (unlikely (retval ==0 )); + + }while (!rte_atomic_compare_exchange_weak_explicit (&port->rx_marker_timer, + &old_marker_timer, marker_timer, + rte_memory_order_release, rte_memory_order_acquire)); m_hdr->marker.tlv_type_marker =MARKER_TLV_TYPE_RESP ;rte_eth_macaddr_get (member_id, &m_hdr->eth_hdr.src_addr);
@@ -1370,7 +1361,8 @@ bond_mode_8023ad_handle_slow_pkt(struct bond_dev_private *internals,if (internals->mode4.dedicated_queues.enabled ==0 ) {if (rte_ring_enqueue (port->tx_ring, pkt) !=0 ) {/* reset timer */ - port->rx_marker_timer =0 ; +rte_atomic_store_explicit (&port->rx_marker_timer,0 , + rte_memory_order_release); wrn =WRN_TX_QUEUE_FULL ; goto free_out; }
@@ -1384,7 +1376,8 @@ bond_mode_8023ad_handle_slow_pkt(struct bond_dev_private *internals, &pkt, tx_count);if (tx_count !=1 ) {/* reset timer */ - port->rx_marker_timer =0 ; +rte_atomic_store_explicit (&port->rx_marker_timer,0 , + rte_memory_order_release); wrn =WRN_TX_QUEUE_FULL ; goto free_out; }
Signature · 1 line
2.53.0
PATCH v9 3/25 net/nbl: remove unused rte_atomic16 field
In reply to Stephen HemmingerThe tx_current_queue was defined as rte_atomic16_t which is deprecated. Remove it since it was never used.
--- drivers/net/nbl/nbl_hw/nbl_resource.h | 1 - 1 file changed, 1 deletion(-)
drivers/net/nbl/nbl_hw/nbl_resource.h +0 -1
@@ -225,7 +225,6 @@ struct nbl_res_info {u16 base_qid;u16 lcore_max;u16 *pf_qid_to_lcore_id; -rte_atomic16_t tx_current_queue; };struct nbl_resource_mgt {
Signature · 1 line
2.53.0
PATCH v9 4/25 net/ena: replace use of rte_atomicNN
In reply to Stephen HemmingerConvert the legacy rte_atomicNN operations to stdatomic.
* Remove variable ena_alloc_cnt is defined by not used. It is a leftover from previous memzone naming scheme.
* Convert the legacy rte_atomic32_t and rte_atomic32_{inc,dec,set,read} macros to C11 stdatomic equivalents.
Memory ordering is kept at seq_cst,
matching the implicit ordering of the legacy API.
* Do not use rte_atomic for statistics
The DPDK PMD model is that statistics do not have to be exact in face of contention.
--- drivers/net/ena/base/ena_plat_dpdk.h | 14 +++++++++----- drivers/net/ena/ena_ethdev.c | 21 ++++++--------------- drivers/net/ena/ena_ethdev.h | 7 +++---- 3 files changed, 18 insertions(+), 24 deletions(-)
drivers/net/ena/base/ena_plat_dpdk.h +9 -5
@@ -40,7 +40,7 @@ typedef uint64_t dma_addr_t;#endif #define ENA_PRIu64 PRIu64 -#define ena_atomic32_t rte_atomic32_t +typedef RTE_ATOMIC (int32_t )ena_atomic32_t ;#define ena_mem_handle_t const struct rte_memzone *#define SZ_256 (256U)
@@ -267,10 +267,14 @@ ena_mem_alloc_coherent(struct rte_eth_dev_data *data, size_t size,#define ENA_REG_READ32 (bus, reg) \ __extension__ ({ (void)(bus); rte_read32_relaxed((reg)); }) -#define ATOMIC32_INC (i32_ptr) rte_atomic32_inc(i32_ptr) -#define ATOMIC32_DEC (i32_ptr) rte_atomic32_dec(i32_ptr) -#define ATOMIC32_SET (i32_ptr, val) rte_atomic32_set(i32_ptr, val) -#define ATOMIC32_READ (i32_ptr) rte_atomic32_read(i32_ptr) +#define ATOMIC32_INC (i32_ptr) \ + rte_atomic_fetch_add_explicit((i32_ptr), 1, rte_memory_order_seq_cst) +#define ATOMIC32_DEC (i32_ptr) \ + rte_atomic_fetch_sub_explicit((i32_ptr), 1, rte_memory_order_seq_cst) +#define ATOMIC32_SET (i32_ptr, val) \ + rte_atomic_store_explicit((i32_ptr), (val), rte_memory_order_seq_cst) +#define ATOMIC32_READ (i32_ptr) \ + rte_atomic_load_explicit((i32_ptr), rte_memory_order_seq_cst)#define msleep (x) rte_delay_us(x * 1000)#define udelay (x) rte_delay_us(x)
drivers/net/ena/ena_ethdev.c +6 -15
@@ -121,12 +121,6 @@ struct ena_stats {*/ #define ENA_DEVARG_ENABLE_FRAG_BYPASS "enable_frag_bypass" -/* -* Each rte_memzone should have unique name. -* To satisfy it, count number of allocation and add it to name. -*/ -rte_atomic64_t ena_alloc_cnt; -static const struct ena_stats ena_stats_global_strings[] = {ENA_STAT_GLOBAL_ENTRY (wd_expired),ENA_STAT_GLOBAL_ENTRY (dev_start),
@@ -1249,10 +1243,7 @@ static void ena_stats_restart(struct rte_eth_dev *dev) {struct ena_adapter *adapter = dev->data->dev_private; -rte_atomic64_init (&adapter->drv_stats->ierrors); -rte_atomic64_init (&adapter->drv_stats->oerrors); -rte_atomic64_init (&adapter->drv_stats->rx_nombuf); - adapter->drv_stats->rx_drops =0 ; +memset (adapter->drv_stats,0 ,sizeof (struct ena_driver_stats )); } static int ena_stats_get(struct rte_eth_dev *dev,
@@ -1288,9 +1279,9 @@ static int ena_stats_get(struct rte_eth_dev *dev,/* Driver related stats */ stats->imissed = adapter->drv_stats->rx_drops; - stats->ierrors =rte_atomic64_read (&adapter->drv_stats->ierrors); - stats->oerrors =rte_atomic64_read (&adapter->drv_stats->oerrors); - stats->rx_nombuf =rte_atomic64_read (&adapter->drv_stats->rx_nombuf); + stats->ierrors = adapter->drv_stats->ierrors; + stats->oerrors = adapter->drv_stats->oerrors; + stats->rx_nombuf = adapter->drv_stats->rx_nombuf;/* Queue statistics */ if (qstats) {
@@ -1878,7 +1869,7 @@ static int ena_populate_rx_queue(struct ena_ring *rxq, unsigned int count)/* get resources for incoming packets */ rc =rte_pktmbuf_alloc_bulk (rxq->mb_pool, mbufs, count);if (unlikely (rc <0 )) { -rte_atomic64_inc (&rxq->adapter->drv_stats->rx_nombuf); + ++rxq->adapter->drv_stats->rx_nombuf; ++rxq->rx_stats.mbuf_alloc_fail;PMD_RX_LOG_LINE (DEBUG ,"There are not enough free buffers" );return 0 ;
@@ -3005,7 +2996,7 @@ static uint16_t eth_ena_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,if (unlikely (mbuf->ol_flags & (RTE_MBUF_F_RX_IP_CKSUM_BAD |RTE_MBUF_F_RX_L4_CKSUM_BAD ))) -rte_atomic64_inc (&rx_ring->adapter->drv_stats->ierrors); + ++rx_ring->adapter->drv_stats->ierrors; rx_pkts[completed] = mbuf; rx_ring->rx_stats.bytes += mbuf->pkt_len;
drivers/net/ena/ena_ethdev.h +3 -4
@@ -6,7 +6,6 @@#ifndef _ENA_ETHDEV_H_#define _ENA_ETHDEV_H_ -#include <rte_atomic.h> #include <rte_ether.h> #include <ethdev_driver.h> #include <ethdev_pci.h>
@@ -225,9 +224,9 @@ enum ena_adapter_state { };struct ena_driver_stats { -rte_atomic64_t ierrors; -rte_atomic64_t oerrors; -rte_atomic64_t rx_nombuf; +u64 ierrors; +u64 oerrors; +u64 rx_nombuf;u64 rx_drops; };
Signature · 1 line
2.53.0
PATCH v9 5/25 net/failsafe: convert to stdatomic
In reply to Stephen HemmingerThe functions rte_atomic64 are deprecated, convert this code to use stdatomic for reference count. Use the memory order implied by naming P/V.
No need for initialization since refcnt is in space allocated with rte_zmalloc().
--- drivers/net/failsafe/failsafe_ops.c | 16 +++++--------- drivers/net/failsafe/failsafe_private.h | 29 ++++++++++++++----------- drivers/net/failsafe/failsafe_rxtx.c | 2 +- 3 files changed, 23 insertions(+), 24 deletions(-)
drivers/net/failsafe/failsafe_ops.c +6 -10
@@ -11,7 +11,7 @@#endif #include <rte_debug.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <ethdev_driver.h> #include <rte_malloc.h> #include <rte_flow.h>
@@ -438,16 +438,14 @@ fs_rx_queue_setup(struct rte_eth_dev *dev,fs_rx_queue_release (dev, rx_queue_id); dev->data->rx_queues[rx_queue_id] =NULL ; } - rxq =rte_zmalloc (NULL , -sizeof (*rxq) + -sizeof (rte_atomic64_t) *PRIV (dev)->subs_tail, + rxq =rte_zmalloc ("ethdev RX queue" , +sizeof (*rxq) +sizeof (*rxq->refcnt) *PRIV (dev)->subs_tail,RTE_CACHE_LINE_SIZE );if (rxq ==NULL ) {fs_unlock (dev,0 );return -ENOMEM ; } - FOREACH_SUBDEV(sdev, i, dev) -rte_atomic64_init (&rxq->refcnt[i]); + rxq->qid = rx_queue_id; rxq->socket_id = socket_id; rxq->info.mp = mb_pool;
@@ -616,15 +614,13 @@ fs_tx_queue_setup(struct rte_eth_dev *dev, dev->data->tx_queues[tx_queue_id] =NULL ; } txq =rte_zmalloc ("ethdev TX queue" , -sizeof (*txq) + -sizeof (rte_atomic64_t) *PRIV (dev)->subs_tail, +sizeof (*txq) +sizeof (*txq->refcnt) *PRIV (dev)->subs_tail,RTE_CACHE_LINE_SIZE );if (txq ==NULL ) {fs_unlock (dev,0 );return -ENOMEM ; } - FOREACH_SUBDEV(sdev, i, dev) -rte_atomic64_init (&txq->refcnt[i]); + txq->qid = tx_queue_id; txq->socket_id = socket_id; txq->info.conf = *tx_conf;
drivers/net/failsafe/failsafe_private.h +16 -13
@@ -10,7 +10,7 @@#include <sys/queue.h> #include <pthread.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <dev_driver.h> #include <ethdev_driver.h> #include <rte_devargs.h>
@@ -75,7 +75,7 @@ struct rxq {int event_fd; unsigned int enable_events:1;struct rte_eth_rxq_info info; -rte_atomic64_t refcnt[]; +RTE_ATOMIC (uint64_t ) refcnt[]; };struct txq {
@@ -83,7 +83,7 @@ struct txq {uint16_t qid;unsigned int socket_id;struct rte_eth_txq_info info; -rte_atomic64_t refcnt[]; +RTE_ATOMIC (uint64_t ) refcnt[]; };struct rte_flow {
@@ -320,33 +320,36 @@ extern int failsafe_mac_from_arg;*/ /** -* a: (rte_atomic64_t) +* a: RTE_ATOMIC(uint64_t) */ #define FS_ATOMIC_P (a) \ - rte_atomic64_set(&(a), 1) + rte_atomic_exchange_explicit(&(a), 1, rte_memory_order_acquire)/** -* a: (rte_atomic64_t) +* a: RTE_ATOMIC(uint64_t) */ #define FS_ATOMIC_V (a) \ - rte_atomic64_set(&(a), 0) + rte_atomic_store_explicit(&(a), 0, rte_memory_order_release)/** * s: (struct sub_device *) * i: uint16_t qid */ #define FS_ATOMIC_RX (s, i) \ - rte_atomic64_read( \ - &((struct rxq *) \ - (fs_dev(s)->data->rx_queues[i]))->refcnt[(s)->sid]) + rte_atomic_load_explicit( \ + &((struct rxq *) \ + (fs_dev(s)->data->rx_queues[i]))->refcnt[(s)->sid], \ + rte_memory_order_seq_cst) +/** * s: (struct sub_device *) * i: uint16_t qid */ #define FS_ATOMIC_TX (s, i) \ - rte_atomic64_read( \ - &((struct txq *) \ - (fs_dev(s)->data->tx_queues[i]))->refcnt[(s)->sid]) + rte_atomic_load_explicit( \ + &((struct txq *) \ + (fs_dev(s)->data->tx_queues[i]))->refcnt[(s)->sid], \ + rte_memory_order_seq_cst)#ifdef RTE_EXEC_ENV_FREEBSD #define FS_THREADID_TYPE void*
drivers/net/failsafe/failsafe_rxtx.c +1 -1
@@ -3,7 +3,7 @@* Copyright 2017 Mellanox Technologies, Ltd */ -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include <rte_debug.h> #include <rte_mbuf.h> #include <ethdev_driver.h>
Signature · 1 line
2.53.0
PATCH v9 6/25 net/enic: do not use deprecated rte_atomic64
In reply to Stephen HemmingerThe rte_atomic64 datatype and functions are deprecated. This driver was only using it for error statistics where atomic is not necessary. The DPDK PMD model is that statistics do not have to be exact in face of contention.
--- drivers/net/enic/enic.h | 6 +++--- drivers/net/enic/enic_compat.h | 1 - drivers/net/enic/enic_main.c | 21 +++++---------------- drivers/net/enic/enic_rxtx.c | 14 ++++++-------- drivers/net/enic/enic_rxtx_vec_avx2.c | 4 ++-- 5 files changed, 16 insertions(+), 30 deletions(-)
drivers/net/enic/enic.h +3 -3
@@ -59,9 +59,9 @@#define ENICPMD_RXQ_INTR_OFFSET 1struct enic_soft_stats { -rte_atomic64_t rx_nombuf; -rte_atomic64_t rx_packet_errors; -rte_atomic64_t tx_oversized; +uint64_t rx_nombuf; +uint64_t rx_packet_errors; +uint64_t tx_oversized; };struct enic_memzone_entry {
drivers/net/enic/enic_compat.h +0 -1
@@ -9,7 +9,6 @@#include <stdio.h> #include <unistd.h> -#include <rte_atomic.h> #include <rte_malloc.h> #include <rte_log.h> #include <rte_io.h>
drivers/net/enic/enic_main.c +5 -16
@@ -83,18 +83,8 @@ static void enic_log_q_error(struct enic *enic)static void enic_clear_soft_stats (struct enic *enic) {struct enic_soft_stats *soft_stats = &enic->soft_stats; -rte_atomic64_clear (&soft_stats->rx_nombuf); -rte_atomic64_clear (&soft_stats->rx_packet_errors); -rte_atomic64_clear (&soft_stats->tx_oversized); -} -static void enic_init_soft_stats (struct enic *enic) -{ -struct enic_soft_stats *soft_stats = &enic->soft_stats; -rte_atomic64_init (&soft_stats->rx_nombuf); -rte_atomic64_init (&soft_stats->rx_packet_errors); -rte_atomic64_init (&soft_stats->tx_oversized); -enic_clear_soft_stats (enic); +memset (soft_stats,0 ,sizeof (*soft_stats)); }int enic_dev_stats_clear (struct enic *enic)
@@ -132,7 +122,7 @@ int enic_dev_stats_get(struct enic *enic, struct rte_eth_stats *r_stats,* counted in ibytes even though truncated packets are dropped * which can make ibytes be slightly higher than it should be. */ - rx_packet_errors =rte_atomic64_read (&soft_stats->rx_packet_errors); + rx_packet_errors = soft_stats->rx_packet_errors; rx_truncated = rx_packet_errors - stats->rx.rx_errors; r_stats->ipackets = stats->rx.rx_frames_ok - rx_truncated;
@@ -142,12 +132,11 @@ int enic_dev_stats_get(struct enic *enic, struct rte_eth_stats *r_stats, r_stats->obytes = stats->tx.tx_bytes_ok; r_stats->ierrors = stats->rx.rx_errors + stats->rx.rx_drop; - r_stats->oerrors = stats->tx.tx_errors - +rte_atomic64_read (&soft_stats->tx_oversized); + r_stats->oerrors = stats->tx.tx_errors + soft_stats->tx_oversized; r_stats->imissed = stats->rx.rx_no_bufs + rx_truncated; - r_stats->rx_nombuf =rte_atomic64_read (&soft_stats->rx_nombuf); + r_stats->rx_nombuf = soft_stats->rx_nombuf;return 0 ; }
@@ -1313,7 +1302,7 @@ int enic_setup_finish(struct enic *enic)int err;ENICPMD_FUNC_TRACE (); -enic_init_soft_stats (enic); +enic_clear_soft_stats (enic);/* * Enable admin channel so we can perform certain devcmds
drivers/net/enic/enic_rxtx.c +6 -8
@@ -112,7 +112,7 @@ enic_recv_pkts_common(void *rx_queue, struct rte_mbuf **rx_pkts,/* allocate a new mbuf */ nmb =rte_mbuf_raw_alloc (rq->mp);if (nmb ==NULL ) { -rte_atomic64_inc (&enic->soft_stats.rx_nombuf); + ++enic->soft_stats.rx_nombuf;break ; }
@@ -185,7 +185,7 @@ enic_recv_pkts_common(void *rx_queue, struct rte_mbuf **rx_pkts, }if (unlikely (packet_error)) {rte_pktmbuf_free (first_seg); -rte_atomic64_inc (&enic->soft_stats.rx_packet_errors); + ++enic->soft_stats.rx_packet_errors;continue ; }
@@ -303,7 +303,7 @@ enic_noscatter_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,if (unlikely (cqd->bytes_written_flags &CQ_ENET_RQ_DESC_FLAGS_TRUNCATED )) {rte_pktmbuf_free (*rxmb++); -rte_atomic64_inc (&enic->soft_stats.rx_packet_errors); + ++enic->soft_stats.rx_packet_errors; cqd++;continue ; }
@@ -505,14 +505,12 @@ uint16_t enic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,uint8_t offload_mode;uint16_t header_len;uint64_t tso; -rte_atomic64_t *tx_oversized;enic_cleanup_wq (enic, wq); wq_desc_avail =vnic_wq_desc_avail (wq); head_idx = wq->head_idx; desc_count = wq->ring.desc_count; ol_flags_mask =RTE_MBUF_F_TX_VLAN |RTE_MBUF_F_TX_IP_CKSUM |RTE_MBUF_F_TX_L4_MASK ; - tx_oversized = &enic->soft_stats.tx_oversized; nb_pkts =RTE_MIN (nb_pkts,ENIC_TX_XMIT_MAX );
@@ -527,7 +525,7 @@ uint16_t enic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,/* drop packet if it's too big to send */ if (unlikely (!tso && pkt_len >ENIC_TX_MAX_PKT_SIZE )) {rte_pktmbuf_free (tx_pkt); -rte_atomic64_inc (tx_oversized); + ++enic->soft_stats.tx_oversized;continue ; }
@@ -558,7 +556,7 @@ uint16_t enic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,if (unlikely (header_len ==0 || ((tx_pkt->tso_segsz + header_len) >ENIC_TX_MAX_PKT_SIZE ))) {rte_pktmbuf_free (tx_pkt); -rte_atomic64_inc (tx_oversized); + ++enic->soft_stats.tx_oversized;continue ; }
@@ -681,7 +679,7 @@ static void enqueue_simple_pkts(struct rte_mbuf **pkts,*/ if (unlikely (p->pkt_len >ENIC_TX_MAX_PKT_SIZE )) { desc->length =ENIC_TX_MAX_PKT_SIZE ; -rte_atomic64_inc (&enic->soft_stats.tx_oversized); + ++enic->soft_stats.tx_oversized; } desc++; }
drivers/net/enic/enic_rxtx_vec_avx2.c +2 -2
@@ -81,7 +81,7 @@ enic_noscatter_vec_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,if (unlikely (cqd->bytes_written_flags &CQ_ENET_RQ_DESC_FLAGS_TRUNCATED )) {rte_pktmbuf_free (*rxmb++); -rte_atomic64_inc (&enic->soft_stats.rx_packet_errors); + ++enic->soft_stats.rx_packet_errors; }else { *rx++ =rx_one (cqd, *rxmb++, enic); }
@@ -761,7 +761,7 @@ enic_noscatter_vec_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,if (unlikely (cqd->bytes_written_flags &CQ_ENET_RQ_DESC_FLAGS_TRUNCATED )) {rte_pktmbuf_free (*rxmb++); -rte_atomic64_inc (&enic->soft_stats.rx_packet_errors); + ++enic->soft_stats.rx_packet_errors; }else { *rx++ =rx_one (cqd, *rxmb++, enic); }
Signature · 1 line
2.53.0
PATCH v9 7/25 net/pfe: use ethdev linkstatus helpers
In reply to Stephen HemmingerRather than open coding with deprecated rte_atomic64, use the existing ethdev helpers to get and set link status.
--- drivers/net/pfe/pfe_ethdev.c | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-)
drivers/net/pfe/pfe_ethdev.c +2 -30
@@ -531,34 +531,6 @@ pfe_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)return NULL ; } -static inline int -pfe_eth_atomic_read_link_status (struct rte_eth_dev *dev, -struct rte_eth_link *link) -{ -struct rte_eth_link *dst = link; -struct rte_eth_link *src = &dev->data->dev_link; - -if (rte_atomic64_cmpset ((uint64_t *)dst, *(uint64_t *)dst, - *(uint64_t *)src) ==0 ) -return -1 ; - -return 0 ; -} - -static inline int -pfe_eth_atomic_write_link_status (struct rte_eth_dev *dev, -struct rte_eth_link *link) -{ -struct rte_eth_link *dst = &dev->data->dev_link; -struct rte_eth_link *src = link; - -if (rte_atomic64_cmpset ((uint64_t *)dst, *(uint64_t *)dst, - *(uint64_t *)src) ==0 ) -return -1 ; - -return 0 ; -} -static int pfe_eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused) {
@@ -570,7 +542,7 @@ pfe_eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused)memset (&old,0 ,sizeof (old));memset (&link,0 ,sizeof (struct rte_eth_link )); -pfe_eth_atomic_read_link_status (dev, &old); +rte_eth_linkstatus_get (dev, &old);/* Read from PFE CDEV, status of link, if file was successfully * opened.
@@ -601,7 +573,7 @@ pfe_eth_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused) link.link_duplex =RTE_ETH_LINK_FULL_DUPLEX ; link.link_autoneg =RTE_ETH_LINK_AUTONEG ; -pfe_eth_atomic_write_link_status (dev, &link); +rte_eth_linkstatus_set (dev, &link);PFE_PMD_INFO ("Port (%d) link is %s" , dev->data->port_id, link.link_status ?"up" :"down" );
Signature · 1 line
2.53.0
PATCH v9 8/25 net/sfc: replace rte_atomic with stdatomic
In reply to Stephen HemmingerThe rte_atomicNN functions are deprecated and need to be replaced. Use stdatomic for the restart required flag.
Use existing ethdev helper to set link status.
--- drivers/net/sfc/sfc.c | 9 +++++---- drivers/net/sfc/sfc.h | 4 ++-- drivers/net/sfc/sfc_port.c | 7 +------ drivers/net/sfc/sfc_stats.h | 2 +- 4 files changed, 9 insertions(+), 13 deletions(-)
drivers/net/sfc/sfc.c +5 -4
@@ -670,8 +670,8 @@ sfc_restart_if_required(void *arg)struct sfc_adapter *sa = arg;/* If restart is scheduled, clear the flag and do it */ -if (rte_atomic32_cmpset ((volatile uint32_t *)&sa->restart_required, -1 ,0 )) { +if (rte_atomic_exchange_explicit (&sa->restart_required, false, + rte_memory_order_seq_cst)) {sfc_adapter_lock (sa);if (sa->state ==SFC_ETHDEV_STARTED ) (void )sfc_restart (sa);
@@ -685,7 +685,8 @@ sfc_schedule_restart(struct sfc_adapter *sa)int rc;/* Schedule restart alarm if it is not scheduled yet */ -if (!rte_atomic32_test_and_set (&sa->restart_required)) +if (rte_atomic_exchange_explicit (&sa->restart_required, true, + rte_memory_order_seq_cst))return ; rc =rte_eal_alarm_set (1 , sfc_restart_if_required, sa);
@@ -1292,7 +1293,7 @@ sfc_probe(struct sfc_adapter *sa)SFC_ASSERT (sfc_adapter_is_locked (sa)); sa->socket_id =rte_socket_id (); -rte_atomic32_init (&sa->restart_required); + sa->restart_required = false;sfc_log_init (sa,"get family" ); rc =sfc_efx_family (pci_dev, &mem_ebrp, &sa->family);
drivers/net/sfc/sfc.h +2 -2
@@ -17,7 +17,7 @@#include <ethdev_driver.h> #include <rte_kvargs.h> #include <rte_spinlock.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include "efx.h"
@@ -258,7 +258,7 @@ struct sfc_adapter {efx_family_t family;efx_nic_t *nic;rte_spinlock_t nic_lock; -rte_atomic32_t restart_required; +RTE_ATOMIC (bool ) restart_required;struct sfc_efx_mcdi mcdi;struct sfc_sriov sriov;
drivers/net/sfc/sfc_port.c +1 -6
@@ -121,7 +121,6 @@ sfc_port_reset_mac_stats(struct sfc_adapter *sa)static int sfc_port_init_dev_link (struct sfc_adapter *sa) { -struct rte_eth_link *dev_link = &sa->eth_dev->data->dev_link;int rc;efx_link_mode_t link_mode;struct rte_eth_link current_link;
@@ -132,11 +131,7 @@ sfc_port_init_dev_link(struct sfc_adapter *sa)sfc_port_link_mode_to_info (link_mode, sa->port.phy_adv_cap, ¤t_link); - -EFX_STATIC_ASSERT (sizeof (*dev_link) ==sizeof (rte_atomic64_t)); -rte_atomic64_set ((rte_atomic64_t *)dev_link, - *(uint64_t *)¤t_link); - +rte_eth_linkstatus_set (sa->eth_dev, ¤t_link);return 0 ; }
drivers/net/sfc/sfc_stats.h +1 -1
@@ -12,7 +12,7 @@#include <stdint.h> -#include <rte_atomic.h> +#include <rte_stdatomic.h> #include "sfc_tweak.h"
Signature · 1 line
2.53.0