Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/sys Adapt to use the new atomic_* operations. As discus...



details:   https://anonhg.NetBSD.org/src/rev/daf791e31641
branches:  trunk
changeset: 846885:daf791e31641
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Tue Dec 03 13:48:25 2019 +0000

description:
Adapt to use the new atomic_* operations.  As discussed with
riastradh@ in private Email.

diffstat:

 sys/sys/module_hook.h |  25 +++++++++++++++++--------
 1 files changed, 17 insertions(+), 8 deletions(-)

diffs (71 lines):

diff -r 1a26cee697ff -r daf791e31641 sys/sys/module_hook.h
--- a/sys/sys/module_hook.h     Tue Dec 03 13:42:55 2019 +0000
+++ b/sys/sys/module_hook.h     Tue Dec 03 13:48:25 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: module_hook.h,v 1.3 2019/03/01 11:06:57 pgoyette Exp $     */
+/* $NetBSD: module_hook.h,v 1.4 2019/12/03 13:48:25 pgoyette Exp $     */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -55,6 +55,17 @@
        type                    (*f)args;                       \
 } hook __cacheline_aligned;
 
+/*
+ * We use pserialize_perform() to issue a memory barrier on the current
+ * CPU and on all other CPUs so that all prior memory operations on the
+ * current CPU globally happen before all subsequent memory operations
+ * on the current CPU, as perceived by any other CPU.
+ *
+ * pserialize_perform() might be rather heavy-weight here, but it only
+ * happens during module loading, and it allows MODULE_HOOK_CALL() to
+ * work without any other memory barriers.
+ */
+
 #define MODULE_HOOK_SET(hook, waitchan, func)                  \
 do {                                                           \
                                                                \
@@ -67,10 +78,10 @@
        hook.f = func;                                          \
                                                                \
        /* Make sure it's initialized before anyone uses it */  \
-       membar_producer();                                      \
+       pserialize_perform(hook.psz);                           \
                                                                \
        /* Let them use it */                                   \
-       hook.hooked = true;                                     \
+       atomic_store_relaxed(&hook.hooked, true);               \
 } while /* CONSTCOND */ (0)
 
 #define MODULE_HOOK_UNSET(hook)                                        \
@@ -84,7 +95,7 @@
        mutex_enter(&hook.mtx);                                 \
                                                                \
        /* Prevent new localcount_acquire calls.  */            \
-       hook.hooked = false;                                    \
+       atomic_store_relaxed(&hook.hooked, false);              \
                                                                \
        /*                                                      \
         * Wait for localcount_acquire calls already under way  \
@@ -109,9 +120,8 @@
        int __hook_s;                                           \
                                                                \
        __hook_s = pserialize_read_enter();                     \
-       __hooked = hook.hooked;                                 \
+       __hooked = atomic_load_relaxed(&hook.hooked);           \
        if (__hooked) {                                         \
-               membar_consumer();                              \
                localcount_acquire(&hook.lc);                   \
        }                                                       \
        pserialize_read_exit(__hook_s);                         \
@@ -131,9 +141,8 @@
        int __hook_s;                                           \
                                                                \
        __hook_s = pserialize_read_enter();                     \
-       __hooked = hook.hooked;                                 \
+       __hooked = atomic_load_relaxed(&hook.hooked);           \
        if (__hooked) {                                         \
-               membar_consumer();                              \
                localcount_acquire(&hook.lc);                   \
        }                                                       \
        pserialize_read_exit(__hook_s);                         \



Home | Main Index | Thread Index | Old Index