test/ring: relax memory ordering for stress test
authorHonnappa Nagarahalli <honnappa.nagarahalli@arm.com>
Mon, 25 Oct 2021 04:52:37 +0000 (23:52 -0500)
committerDavid Marchand <david.marchand@redhat.com>
Mon, 25 Oct 2021 16:20:59 +0000 (18:20 +0200)
wrk_cmd variable is used to signal the worker thread to start
or stop the stress test loop. Relaxed barriers are used
to achieve the same.

Signed-off-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
Reviewed-by: Ola Liljedahl <ola.liljedahl@arm.com>
Reviewed-by: Feifei Wang <feifei.wang2@arm.com>
app/test/test_ring_stress_impl.h

index f9ca63b..2825a9d 100644 (file)
@@ -22,7 +22,7 @@ enum {
        WRK_CMD_RUN,
 };
 
-static volatile uint32_t wrk_cmd __rte_cache_aligned;
+static uint32_t wrk_cmd __rte_cache_aligned = WRK_CMD_STOP;
 
 /* test run-time in seconds */
 static const uint32_t run_time = 60;
@@ -197,10 +197,12 @@ test_worker(void *arg, const char *fname, int32_t prcs)
        fill_ring_elm(&def_elm, UINT32_MAX);
        fill_ring_elm(&loc_elm, lc);
 
-       while (wrk_cmd != WRK_CMD_RUN) {
-               rte_smp_rmb();
+       /* Acquire ordering is not required as the main is not
+        * really releasing any data through 'wrk_cmd' to
+        * the worker.
+        */
+       while (__atomic_load_n(&wrk_cmd, __ATOMIC_RELAXED) != WRK_CMD_RUN)
                rte_pause();
-       }
 
        cl = rte_rdtsc_precise();
 
@@ -242,7 +244,7 @@ test_worker(void *arg, const char *fname, int32_t prcs)
 
                lcore_stat_update(&la->stats, 1, num, tm0 + tm1, prcs);
 
-       } while (wrk_cmd == WRK_CMD_RUN);
+       } while (__atomic_load_n(&wrk_cmd, __ATOMIC_RELAXED) == WRK_CMD_RUN);
 
        cl = rte_rdtsc_precise() - cl;
        if (prcs == 0)
@@ -356,14 +358,12 @@ test_mt1(int (*test)(void *))
        }
 
        /* signal worker to start test */
-       wrk_cmd = WRK_CMD_RUN;
-       rte_smp_wmb();
+       __atomic_store_n(&wrk_cmd, WRK_CMD_RUN, __ATOMIC_RELEASE);
 
        usleep(run_time * US_PER_S);
 
        /* signal worker to start test */
-       wrk_cmd = WRK_CMD_STOP;
-       rte_smp_wmb();
+       __atomic_store_n(&wrk_cmd, WRK_CMD_STOP, __ATOMIC_RELEASE);
 
        /* wait for workers and collect stats. */
        mc = rte_lcore_id();