From: Konstantin Ananyev <konstantin.ananyev@huawei.com>
To: Stephen Hemminger <stephen@networkplumber.org>,
"dev@dpdk.org" <dev@dpdk.org>
Subject: RE: [RFC 02/32] test: remove test for rte_smp_mb
Date: Thu, 30 Jul 2026 07:25:28 +0000 [thread overview]
Message-ID: <6cc178b410da423d96e80e98eb444231@huawei.com> (raw)
In-Reply-To: <20260729175715.165120-3-stephen@networkplumber.org>
> The DPDK version of SMP barriers is deprecated and
> being removed. Drop the test as no longer relevant.
Why to remove the whole test?
I believe it is still useful for testing our custom x86 implementation
of rte_atomic_thread_fence(rte_memory_order_seq_cst).
See patch 17 in this series:
[RFC 17/32] eal/x86: move optimized fence out of SMP barrier
Instead of removing it we can replace rte_smp_mb() with
rte_atomic_thread_fence(rte_memory_order_seq_cst)
In one function below, i.e.:
static inline void
store_load_barrier(uint32_t utype)
{
if (utype == USE_MB)
rte_mb();
else if (utype == USE_SMP_MB)
- rte_smp_mb();
+ rte_atomic_thread_fence(rte_memory_order_seq_cst);
else
RTE_VERIFY(0);
}
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> app/test/meson.build | 1 -
> app/test/test_barrier.c | 288 ----------------------------------------
> 2 files changed, 289 deletions(-)
> delete mode 100644 app/test/test_barrier.c
>
> diff --git a/app/test/meson.build b/app/test/meson.build
> index 51abeeb732..6df9dfa222 100644
> --- a/app/test/meson.build
> +++ b/app/test/meson.build
> @@ -28,7 +28,6 @@ source_file_deps = {
> 'test_alarm.c': [],
> 'test_argparse.c': ['argparse'],
> 'test_atomic.c': ['hash'],
> - 'test_barrier.c': [],
> 'test_bitcount.c': [],
> 'test_bitmap.c': [],
> 'test_bitops.c': [],
> diff --git a/app/test/test_barrier.c b/app/test/test_barrier.c
> deleted file mode 100644
> index 925a88b68a..0000000000
> --- a/app/test/test_barrier.c
> +++ /dev/null
> @@ -1,288 +0,0 @@
> -/* SPDX-License-Identifier: BSD-3-Clause
> - * Copyright(c) 2010-2018 Intel Corporation
> - */
> -
> - /*
> - * This is a simple functional test for rte_smp_mb() implementation.
> - * I.E. make sure that LOAD and STORE operations that precede the
> - * rte_smp_mb() call are globally visible across the lcores
> - * before the LOAD and STORE operations that follows it.
> - * The test uses simple implementation of Peterson's lock algorithm
> - * (https://en.wikipedia.org/wiki/Peterson%27s_algorithm)
> - * for two execution units to make sure that rte_smp_mb() prevents
> - * store-load reordering to happen.
> - * Also when executed on a single lcore could be used as a approximate
> - * estimation of number of cycles particular implementation of rte_smp_mb()
> - * will take.
> - */
> -
> -#include <stdio.h>
> -#include <string.h>
> -#include <stdint.h>
> -#include <inttypes.h>
> -
> -#include <rte_memory.h>
> -#include <rte_per_lcore.h>
> -#include <rte_launch.h>
> -#include <rte_eal.h>
> -#include <rte_lcore.h>
> -#include <rte_pause.h>
> -#include <rte_random.h>
> -#include <rte_cycles.h>
> -#include <rte_vect.h>
> -#include <rte_debug.h>
> -
> -#include "test.h"
> -
> -#define ADD_MAX 8
> -#define ITER_MAX 0x1000000
> -
> -enum plock_use_type {
> - USE_MB,
> - USE_SMP_MB,
> - USE_NUM
> -};
> -
> -struct plock {
> - volatile uint32_t flag[2];
> - volatile uint32_t victim;
> - enum plock_use_type utype;
> -};
> -
> -/*
> - * Lock plus protected by it two counters.
> - */
> -struct plock_test {
> - struct plock lock;
> - uint64_t val;
> - uint64_t iter;
> -};
> -
> -/*
> - * Each active lcore shares plock_test struct with it's left and right
> - * neighbours.
> - */
> -struct lcore_plock_test {
> - struct plock_test *pt[2]; /* shared, lock-protected data */
> - uint64_t sum[2]; /* local copy of the shared data */
> - uint64_t iter; /* number of iterations to perform */
> - uint32_t lc; /* given lcore id */
> -};
> -
> -static inline void
> -store_load_barrier(uint32_t utype)
> -{
> - if (utype == USE_MB)
> - rte_mb();
> - else if (utype == USE_SMP_MB)
> - rte_smp_mb();
> - else
> - RTE_VERIFY(0);
> -}
> -
> -/*
> - * Peterson lock implementation.
> - */
> -static void
> -plock_lock(struct plock *l, uint32_t self)
> -{
> - uint32_t other;
> -
> - other = self ^ 1;
> -
> - l->flag[self] = 1;
> - rte_smp_wmb();
> - l->victim = self;
> -
> - store_load_barrier(l->utype);
> -
> - while (l->flag[other] == 1 && l->victim == self)
> - rte_pause();
> - rte_smp_rmb();
> -}
> -
> -static void
> -plock_unlock(struct plock *l, uint32_t self)
> -{
> - rte_smp_wmb();
> - l->flag[self] = 0;
> -}
> -
> -static void
> -plock_reset(struct plock *l, enum plock_use_type utype)
> -{
> - memset(l, 0, sizeof(*l));
> - l->utype = utype;
> -}
> -
> -/*
> - * grab the lock, update both counters, release the lock.
> - */
> -static void
> -plock_add(struct plock_test *pt, uint32_t self, uint32_t n)
> -{
> - plock_lock(&pt->lock, self);
> - pt->iter++;
> - pt->val += n;
> - plock_unlock(&pt->lock, self);
> -}
> -
> -static int
> -plock_test1_lcore(void *data)
> -{
> - uint64_t tm;
> - uint32_t lc, ln;
> - uint64_t i, n;
> - struct lcore_plock_test *lpt;
> -
> - lpt = data;
> - lc = rte_lcore_id();
> -
> - /* find lcore_plock_test struct for given lcore */
> - for (ln = rte_lcore_count(); ln != 0 && lpt->lc != lc; lpt++, ln--)
> - ;
> -
> - if (ln == 0) {
> - printf("%s(%u) error at init\n", __func__, lc);
> - return -1;
> - }
> -
> - n = rte_rand() % ADD_MAX;
> - tm = rte_get_timer_cycles();
> -
> - /*
> - * for each iteration:
> - * - update shared, locked protected data in a safe manner
> - * - update local copy of the shared data
> - */
> - for (i = 0; i != lpt->iter; i++) {
> -
> - plock_add(lpt->pt[0], 0, n);
> - plock_add(lpt->pt[1], 1, n);
> -
> - lpt->sum[0] += n;
> - lpt->sum[1] += n;
> -
> - n = (n + 1) % ADD_MAX;
> - }
> -
> - tm = rte_get_timer_cycles() - tm;
> -
> - printf("%s(%u): %" PRIu64 " iterations finished, in %" PRIu64
> - " cycles, %#Lf cycles/iteration, "
> - "local sum={%" PRIu64 ", %" PRIu64 "}\n",
> - __func__, lc, i, tm, (long double)tm / i,
> - lpt->sum[0], lpt->sum[1]);
> - return 0;
> -}
> -
> -/*
> - * For N active lcores we allocate N+1 lcore_plock_test structures.
> - * Each active lcore shares one lcore_plock_test structure with its
> - * left lcore neighbor and one lcore_plock_test structure with its
> - * right lcore neighbor.
> - * During the test each lcore updates data in both shared structures and
> - * its local copies. Then at validation phase we check that our shared
> - * and local data are the same.
> - */
> -static int
> -plock_test(uint64_t iter, enum plock_use_type utype)
> -{
> - int32_t rc;
> - uint32_t i, lc, n;
> - uint64_t *sum;
> - struct plock_test *pt;
> - struct lcore_plock_test *lpt;
> -
> - /* init phase, allocate and initialize shared data */
> -
> - n = rte_lcore_count();
> - pt = calloc(n + 1, sizeof(*pt));
> - lpt = calloc(n, sizeof(*lpt));
> - sum = calloc(n + 1, sizeof(*sum));
> -
> - printf("%s(iter=%" PRIu64 ", utype=%u) started on %u lcores\n",
> - __func__, iter, utype, n);
> -
> - if (pt == NULL || lpt == NULL || sum == NULL) {
> - printf("%s: failed to allocate memory for %u lcores\n",
> - __func__, n);
> - free(pt);
> - free(lpt);
> - free(sum);
> - return -ENOMEM;
> - }
> -
> - for (i = 0; i != n + 1; i++)
> - plock_reset(&pt[i].lock, utype);
> -
> - i = 0;
> - RTE_LCORE_FOREACH(lc) {
> -
> - lpt[i].lc = lc;
> - lpt[i].iter = iter;
> - lpt[i].pt[0] = pt + i;
> - lpt[i].pt[1] = pt + i + 1;
> - i++;
> - }
> -
> - lpt[i - 1].pt[1] = pt;
> -
> - for (i = 0; i != n; i++)
> - printf("lpt[%u]={lc=%u, pt={%p, %p},};\n",
> - i, lpt[i].lc, lpt[i].pt[0], lpt[i].pt[1]);
> -
> -
> - /* test phase - start and wait for completion on each active lcore */
> -
> - rte_eal_mp_remote_launch(plock_test1_lcore, lpt, CALL_MAIN);
> - rte_eal_mp_wait_lcore();
> -
> - /* validation phase - make sure that shared and local data match */
> -
> - for (i = 0; i != n; i++) {
> - sum[i] += lpt[i].sum[0];
> - sum[i + 1] += lpt[i].sum[1];
> - }
> -
> - sum[0] += sum[i];
> -
> - rc = 0;
> - for (i = 0; i != n; i++) {
> - printf("%s: sum[%u]=%" PRIu64 ", pt[%u].val=%" PRIu64 ",
> pt[%u].iter=%" PRIu64 ";\n",
> - __func__, i, sum[i], i, pt[i].val, i, pt[i].iter);
> -
> - /* race condition occurred, lock doesn't work properly */
> - if (sum[i] != pt[i].val || 2 * iter != pt[i].iter) {
> - printf("error: local and shared sums don't match\n");
> - rc = -1;
> - }
> - }
> -
> - free(pt);
> - free(lpt);
> - free(sum);
> -
> - printf("%s(utype=%u) returns %d\n", __func__, utype, rc);
> - return rc;
> -}
> -
> -static int
> -test_barrier(void)
> -{
> - int32_t i, ret, rc[USE_NUM];
> -
> - for (i = 0; i != RTE_DIM(rc); i++)
> - rc[i] = plock_test(ITER_MAX, i);
> -
> - ret = 0;
> - for (i = 0; i != RTE_DIM(rc); i++) {
> - printf("%s for utype=%d %s\n",
> - __func__, i, rc[i] == 0 ? "passed" : "failed");
> - ret |= rc[i];
> - }
> -
> - return ret;
> -}
> -
> -REGISTER_PERF_TEST(barrier_autotest, test_barrier);
> --
> 2.53.0
next prev parent reply other threads:[~2026-07-30 7:25 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 17:53 [RFC 00/32] remove rte_smp barrier functions Stephen Hemminger
2026-07-29 17:53 ` [RFC 01/32] bpf: replace deprecated SMP barriers with C11 fences Stephen Hemminger
2026-07-29 17:53 ` [RFC 02/32] test: remove test for rte_smp_mb Stephen Hemminger
2026-07-30 7:25 ` Konstantin Ananyev [this message]
2026-07-29 17:53 ` [RFC 03/32] bus/vmbus: fix ring buffer ordering on weakly ordered CPUs Stephen Hemminger
2026-07-29 17:53 ` [RFC 04/32] bus/vmbus: fix missing acquire on receive ring index Stephen Hemminger
2026-07-29 17:53 ` [RFC 05/32] bus/vmbus: replace SMP barriers with C11 memory fences Stephen Hemminger
2026-07-29 17:53 ` [RFC 06/32] baseband: convert rte_smp_rmb to fence Stephen Hemminger
2026-07-29 17:54 ` [RFC 07/32] net/hinic: replace rte_smp_rmb Stephen Hemminger
2026-07-29 17:54 ` [RFC 08/32] net/intel: " Stephen Hemminger
2026-07-29 17:54 ` [RFC 09/32] crypto_caam_jr: " Stephen Hemminger
2026-07-29 17:54 ` [RFC 10/32] net/virtio: replcae rte_smp_rmb Stephen Hemminger
2026-07-29 17:54 ` [RFC 11/32] net/thunderx: replace rte_smp_rmb Stephen Hemminger
2026-07-29 17:54 ` [RFC 12/32] stack: always use C11 memory model implementation Stephen Hemminger
2026-07-29 17:54 ` [RFC 13/32] ring: replace SMP read barrier with C11 acquire fence Stephen Hemminger
2026-07-30 8:16 ` Konstantin Ananyev
2026-07-29 17:54 ` [RFC 14/32] crypto/virtio: update comment reference to rte_smp_rmb Stephen Hemminger
2026-07-29 17:54 ` [RFC 15/32] event/sw: fix unlinks in progress counter races Stephen Hemminger
2026-07-29 17:54 ` [RFC 16/32] event/sw: replace SMP barriers with C11 atomics Stephen Hemminger
2026-07-29 17:54 ` [RFC 17/32] eal/x86: move optimized fence out of SMP barrier Stephen Hemminger
2026-07-30 7:27 ` Konstantin Ananyev
2026-07-29 17:54 ` [RFC 18/32] common/octeontx: remove redundant barrier in mbox Stephen Hemminger
2026-07-29 17:54 ` [RFC 19/32] crypto/caam_jr: use IO barrier before job ring doorbell Stephen Hemminger
2026-07-29 17:54 ` [RFC 20/32] crypto/octeontx: use IO barrier before doorbell Stephen Hemminger
2026-07-29 17:54 ` [RFC 21/32] mempool/octeontx: use IO barrier in pool destroy Stephen Hemminger
2026-07-29 17:54 ` [RFC 22/32] event/octeontx: replace deprecated SMP barriers Stephen Hemminger
2026-07-29 17:54 ` [RFC 23/32] event/dpaa2: replace deprecated barrier in selftest Stephen Hemminger
2026-07-29 17:54 ` [RFC 24/32] event/dsw: replace SMP barriers with release fences Stephen Hemminger
2026-07-29 17:54 ` [RFC 25/32] event/opdl: replace SMP barriers with C11 atomics Stephen Hemminger
2026-07-29 17:54 ` [RFC 26/32] net/netvsc: replace SMP barrier in RNDIS response Stephen Hemminger
2026-07-29 17:54 ` [RFC 27/32] net/thunderx: replace deprecated SMP barriers Stephen Hemminger
2026-07-29 17:54 ` [RFC 28/32] net/virtio: replace deprecated barrier in avail index update Stephen Hemminger
2026-07-29 17:54 ` [RFC 29/32] eal: remove stale SMP barrier in rte_service Stephen Hemminger
2026-07-29 17:54 ` [RFC 30/32] eal: remove rte_smp_XX Stephen Hemminger
2026-07-29 17:54 ` [RFC 31/32] checkpatches: no longer warn about rte_smp_XX Stephen Hemminger
2026-07-29 17:54 ` [RFC 32/32] doc: update release notes about rte_smp_XX removal Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6cc178b410da423d96e80e98eb444231@huawei.com \
--to=konstantin.ananyev@huawei.com \
--cc=dev@dpdk.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox