Module Name: src
Committed By: pgoyette
Date: Tue Dec 3 13:48:25 UTC 2019
Modified Files:
src/sys/sys: module_hook.h
Log Message:
Adapt to use the new atomic_* operations. As discussed with
riastradh@ in private Email.
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/sys/module_hook.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/sys/module_hook.h
diff -u src/sys/sys/module_hook.h:1.3 src/sys/sys/module_hook.h:1.4
--- src/sys/sys/module_hook.h:1.3 Fri Mar 1 11:06:57 2019
+++ src/sys/sys/module_hook.h Tue Dec 3 13:48:25 2019
@@ -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 @@ extern struct hook ## _t { \
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 @@ do { \
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 @@ do { \
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 @@ do { \
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 @@ do { \
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); \