This removes the data dependency consumer barrier from the atomic_load_*
functions. I think the intent was to keep these functions relaxed in
terms of CPU memory order.

This makes these functions more agreeable in code that assertions may
use, such as the suggested refcnt_read().

Removing the barrier should be safe at this point. The current callers
of atomic_load_*, that is cond_wait() and refcnt_finalize(), use the
loaded value for a control decision. These functions need to provide
a stronger ordering guarantee (memory acquire) for their callers than
what membar_datadep_consumer() gives.

(The data dependency barrier would be necessary in a setting like the
following where a memory load of non-constant data is dependent on
another load.

        idx = atomic_load_int(&var);
        membar_datadep_consumer();
        val = atomic_load_int(&array[idx]);

Typically, even if the processor did reorder loads, the second load's
dependency on the value of the first load would prevent the load-load
reordering.

However, some DEC Alpha CPUs have their data caches divided into cache
banks to improve bandwidth. These cache banks are relatively
independent. The system maintains coherency, but bus contention can
delay propagation of cache updates. If the loads spanned different cache
banks, the second load could deliver data which is older than the
initial load's value. The data dependency barrier causes an interlock
with cache updating, ensuring causal ordering.)

OK?

Index: sys/sys/atomic.h
===================================================================
RCS file: src/sys/sys/atomic.h,v
retrieving revision 1.8
diff -u -p -r1.8 atomic.h
--- sys/sys/atomic.h    11 Mar 2022 19:02:15 -0000      1.8
+++ sys/sys/atomic.h    15 Mar 2022 07:52:39 -0000
@@ -201,26 +201,16 @@ atomic_sub_long_nv(volatile unsigned lon
  * atomic_load_* - read from memory
  */
 
-static inline void membar_datadep_consumer(void);
-
 static inline unsigned int
 atomic_load_int(volatile unsigned int *p)
 {
-       unsigned int v;
-
-       v = *p;
-       membar_datadep_consumer();
-       return v;
+       return *p;
 }
 
 static inline unsigned long
 atomic_load_long(volatile unsigned long *p)
 {
-       unsigned long v;
-
-       v = *p;
-       membar_datadep_consumer();
-       return v;
+       return *p;
 }
 
 /*

Reply via email to