Module Name: src
Committed By: riastradh
Date: Sat Apr 9 23:38:57 UTC 2022
Modified Files:
src/common/lib/libc/atomic: atomic_load.c atomic_store.c
Log Message:
libc/atomic: Fix membars in __atomic_load/store_* stubs.
- membar_enter/exit ordering was backwards.
- membar_enter doesn't make any sense for load anyway.
- Switch to membar_release for store and membar_acquire for load.
The only sensible orderings for a simple load or store are acquire or
release, respectively, or sequential consistency. This never
provided correct sequential consistency before -- we should really
make it conditional on memmodel but I don't know offhand what the
values of memmodel might be and this is at least better than before.
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/common/lib/libc/atomic/atomic_load.c \
src/common/lib/libc/atomic/atomic_store.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/common/lib/libc/atomic/atomic_load.c
diff -u src/common/lib/libc/atomic/atomic_load.c:1.3 src/common/lib/libc/atomic/atomic_load.c:1.4
--- src/common/lib/libc/atomic/atomic_load.c:1.3 Mon Sep 7 00:52:19 2020
+++ src/common/lib/libc/atomic/atomic_load.c Sat Apr 9 23:38:57 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: atomic_load.c,v 1.3 2020/09/07 00:52:19 mrg Exp $ */
+/* $NetBSD: atomic_load.c,v 1.4 2022/04/09 23:38:57 riastradh Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: atomic_load.c,v 1.3 2020/09/07 00:52:19 mrg Exp $");
+__RCSID("$NetBSD: atomic_load.c,v 1.4 2022/04/09 23:38:57 riastradh Exp $");
#include "atomic_op_namespace.h"
@@ -40,9 +40,8 @@ uint ## b ## _t \
__atomic_load_ ## n(const volatile void *ptr, int memmodel) \
{ \
uint## b ##_t val; \
- membar_enter(); \
val = *(const volatile uint ## b ## _t *)ptr; \
- membar_exit(); \
+ membar_acquire(); \
return val; \
}
Index: src/common/lib/libc/atomic/atomic_store.c
diff -u src/common/lib/libc/atomic/atomic_store.c:1.3 src/common/lib/libc/atomic/atomic_store.c:1.4
--- src/common/lib/libc/atomic/atomic_store.c:1.3 Mon Sep 7 00:52:19 2020
+++ src/common/lib/libc/atomic/atomic_store.c Sat Apr 9 23:38:57 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: atomic_store.c,v 1.3 2020/09/07 00:52:19 mrg Exp $ */
+/* $NetBSD: atomic_store.c,v 1.4 2022/04/09 23:38:57 riastradh Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: atomic_store.c,v 1.3 2020/09/07 00:52:19 mrg Exp $");
+__RCSID("$NetBSD: atomic_store.c,v 1.4 2022/04/09 23:38:57 riastradh Exp $");
#include "atomic_op_namespace.h"
@@ -40,9 +40,8 @@ void \
__atomic_store_ ## n(volatile void *ptr, uint ## b ## _t val, \
int memmodel) \
{ \
- membar_enter(); \
+ membar_release(); \
*(volatile uint ## b ## _t *)ptr = val; \
- membar_exit(); \
}
atomic_store_n(1, 8)