]> git.puffer.fish Git - mirror/frr.git/commitdiff
tests: fix TSAN warnings in atomlist test 16258/head
authorDavid Lamparter <equinox@opensourcerouting.org>
Thu, 20 Jun 2024 10:02:25 +0000 (12:02 +0200)
committerDavid Lamparter <equinox@opensourcerouting.org>
Thu, 20 Jun 2024 13:44:46 +0000 (15:44 +0200)
The atomlist test consists of a sequence of (MT) sub-tests, from which
counters are collected and verified.  TSAN doesn't know that these
counters are synchronized by way of the sub-test starting and finishing,
so it complains.  Just use atomics to get rid of the warning.

(This is solely an issue with the test, not the atomlist code.  There
are no warnings from that.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
tests/lib/test_atomlist.c

index b50216cf929224a59e8fbcc9345001df0941c269..afcfa987913860efdcb43451f27b760ca44a0b4c 100644 (file)
@@ -62,7 +62,7 @@ static struct asort_head shead;
 static struct testthread {
        pthread_t pt;
        struct seqlock sqlo;
-       size_t counter, nullops;
+       _Atomic size_t counter, nullops;
 } thr[NTHREADS];
 
 struct testrun {
@@ -97,10 +97,10 @@ static void trfunc_##name(unsigned int offset) \
 { \
        size_t i = 0, n = 0;
 
-#define endtestrun \
-       thr[offset].counter = i; \
-       thr[offset].nullops = n; \
-}
+#define endtestrun                                                             \
+       atomic_store_explicit(&thr[offset].counter, i, memory_order_seq_cst);  \
+       atomic_store_explicit(&thr[offset].nullops, n, memory_order_seq_cst);  \
+       }
 
 deftestrun(add, "add vs. add", 0, false)
        for (; i < NITEM / NTHREADS; i++)
@@ -288,10 +288,10 @@ static void run_tr(struct testrun *tr)
        sv = seqlock_bump(&sqlo) - SEQLOCK_INCR;
        for (size_t i = 0; i < NTHREADS; i++) {
                seqlock_wait(&thr[i].sqlo, seqlock_cur(&sqlo));
-               s += thr[i].counter;
-               n += thr[i].nullops;
-               thr[i].counter = 0;
-               thr[i].nullops = 0;
+               s += atomic_load_explicit(&thr[i].counter, memory_order_seq_cst);
+               n += atomic_load_explicit(&thr[i].nullops, memory_order_seq_cst);
+               atomic_store_explicit(&thr[i].counter, 0, memory_order_seq_cst);
+               atomic_store_explicit(&thr[i].nullops, 0, memory_order_seq_cst);
        }
 
        delta = monotime_since(&tv, NULL);