Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/x86/x86 x86: Every load is a load-acquire, so memba...
details: https://anonhg.NetBSD.org/src/rev/1fcb11c0680d
branches: trunk
changeset: 364726:1fcb11c0680d
user: riastradh <riastradh%NetBSD.org@localhost>
date: Sat Apr 09 12:07:00 2022 +0000
description:
x86: Every load is a load-acquire, so membar_consumer is a noop.
lfence is only needed for MD logic, such as operations on I/O memory
rather than normal cacheable memory, or special instructions like
RDTSC -- never for MI synchronization between threads/CPUs. No need
for hot-patching to do lfence here.
(The x86_lfence function might reasonably be patched on i386 to do
lfence for MD logic, but it isn't now and this doesn't change that.)
diffstat:
common/lib/libc/arch/i386/atomic/atomic.S | 19 +++++------------
common/lib/libc/arch/x86_64/atomic/atomic.S | 19 +++++------------
sys/arch/amd64/include/frameasm.h | 5 +--
sys/arch/i386/include/frameasm.h | 11 ++++-----
sys/arch/x86/x86/patch.c | 30 +++++++++-------------------
5 files changed, 29 insertions(+), 55 deletions(-)
diffs (204 lines):
diff -r f18d6c2ad25a -r 1fcb11c0680d common/lib/libc/arch/i386/atomic/atomic.S
--- a/common/lib/libc/arch/i386/atomic/atomic.S Sat Apr 09 12:06:47 2022 +0000
+++ b/common/lib/libc/arch/i386/atomic/atomic.S Sat Apr 09 12:07:00 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: atomic.S,v 1.30 2022/04/06 22:47:56 riastradh Exp $ */
+/* $NetBSD: atomic.S,v 1.31 2022/04/09 12:07:00 riastradh Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -46,12 +46,10 @@
#include "opt_xen.h"
#include <machine/frameasm.h>
#define LOCK HOTPATCH(HP_NAME_NOLOCK, 1); lock
-#define HOTPATCH_SSE2_LFENCE HOTPATCH(HP_NAME_SSE2_LFENCE, 7);
#define HOTPATCH_SSE2_MFENCE HOTPATCH(HP_NAME_SSE2_MFENCE, 7);
#define HOTPATCH_CAS_64 HOTPATCH(HP_NAME_CAS_64, 49);
#else
#define LOCK lock
-#define HOTPATCH_SSE2_LFENCE /* nothing */
#define HOTPATCH_SSE2_MFENCE /* nothing */
#define HOTPATCH_CAS_64 /* nothing */
#endif
@@ -181,10 +179,11 @@
END(_atomic_cas_32_ni)
ENTRY(_membar_consumer)
- HOTPATCH_SSE2_LFENCE
- /* 7 bytes of instructions */
- LOCK
- addl $0, -4(%esp)
+ /*
+ * Every load from normal memory is a load-acquire on x86, so
+ * there is never any need for explicit barriers to order
+ * load-before-anything.
+ */
ret
END(_membar_consumer)
@@ -396,12 +395,6 @@
#ifdef _HARDKERNEL
.section .rodata
-LABEL(sse2_lfence)
- lfence
- ret
- nop; nop; nop;
-LABEL(sse2_lfence_end)
-
LABEL(sse2_mfence)
mfence
ret
diff -r f18d6c2ad25a -r 1fcb11c0680d common/lib/libc/arch/x86_64/atomic/atomic.S
--- a/common/lib/libc/arch/x86_64/atomic/atomic.S Sat Apr 09 12:06:47 2022 +0000
+++ b/common/lib/libc/arch/x86_64/atomic/atomic.S Sat Apr 09 12:07:00 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: atomic.S,v 1.23 2022/04/06 22:47:57 riastradh Exp $ */
+/* $NetBSD: atomic.S,v 1.24 2022/04/09 12:07:00 riastradh Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -41,11 +41,9 @@
#ifdef _HARDKERNEL
#include <machine/frameasm.h>
#define LOCK HOTPATCH(HP_NAME_NOLOCK, 1); lock
-#define HOTPATCH_SSE2_LFENCE HOTPATCH(HP_NAME_SSE2_LFENCE, 8);
#define HOTPATCH_SSE2_MFENCE HOTPATCH(HP_NAME_SSE2_MFENCE, 8);
#else
#define LOCK lock
-#define HOTPATCH_SSE2_LFENCE /* nothing */
#define HOTPATCH_SSE2_MFENCE /* nothing */
#endif
@@ -256,10 +254,11 @@
/* memory barriers */
ENTRY(_membar_consumer)
- HOTPATCH_SSE2_LFENCE
- /* 8 bytes of instructions */
- LOCK
- addq $0, -8(%rsp)
+ /*
+ * Every load from normal memory is a load-acquire on x86, so
+ * there is never any need for explicit barriers to order
+ * load-before-anything.
+ */
ret
END(_membar_consumer)
@@ -419,12 +418,6 @@
#ifdef _HARDKERNEL
.section .rodata
-LABEL(sse2_lfence)
- lfence
- ret
- nop; nop; nop; nop;
-LABEL(sse2_lfence_end)
-
LABEL(sse2_mfence)
mfence
ret
diff -r f18d6c2ad25a -r 1fcb11c0680d sys/arch/amd64/include/frameasm.h
--- a/sys/arch/amd64/include/frameasm.h Sat Apr 09 12:06:47 2022 +0000
+++ b/sys/arch/amd64/include/frameasm.h Sat Apr 09 12:07:00 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: frameasm.h,v 1.53 2021/04/17 20:12:55 rillig Exp $ */
+/* $NetBSD: frameasm.h,v 1.54 2022/04/09 12:07:00 riastradh Exp $ */
#ifndef _AMD64_MACHINE_FRAMEASM_H
#define _AMD64_MACHINE_FRAMEASM_H
@@ -63,8 +63,7 @@
#define HP_NAME_SVS_ENTER_NMI 11
#define HP_NAME_SVS_LEAVE_NMI 12
#define HP_NAME_MDS_LEAVE 13
-#define HP_NAME_SSE2_LFENCE 14
-#define HP_NAME_SSE2_MFENCE 15
+#define HP_NAME_SSE2_MFENCE 14
#define HOTPATCH(name, size) \
123: ; \
diff -r f18d6c2ad25a -r 1fcb11c0680d sys/arch/i386/include/frameasm.h
--- a/sys/arch/i386/include/frameasm.h Sat Apr 09 12:06:47 2022 +0000
+++ b/sys/arch/i386/include/frameasm.h Sat Apr 09 12:07:00 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: frameasm.h,v 1.33 2020/05/01 09:40:47 maxv Exp $ */
+/* $NetBSD: frameasm.h,v 1.34 2022/04/09 12:07:00 riastradh Exp $ */
#ifndef _I386_FRAMEASM_H_
#define _I386_FRAMEASM_H_
@@ -48,11 +48,10 @@
#define HP_NAME_STAC 2
#define HP_NAME_NOLOCK 3
#define HP_NAME_RETFENCE 4
-#define HP_NAME_SSE2_LFENCE 5
-#define HP_NAME_SSE2_MFENCE 6
-#define HP_NAME_CAS_64 7
-#define HP_NAME_SPLLOWER 8
-#define HP_NAME_MUTEX_EXIT 9
+#define HP_NAME_SSE2_MFENCE 5
+#define HP_NAME_CAS_64 6
+#define HP_NAME_SPLLOWER 7
+#define HP_NAME_MUTEX_EXIT 8
#define HOTPATCH(name, size) \
123: ; \
diff -r f18d6c2ad25a -r 1fcb11c0680d sys/arch/x86/x86/patch.c
--- a/sys/arch/x86/x86/patch.c Sat Apr 09 12:06:47 2022 +0000
+++ b/sys/arch/x86/x86/patch.c Sat Apr 09 12:07:00 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: patch.c,v 1.49 2020/05/07 18:13:05 maxv Exp $ */
+/* $NetBSD: patch.c,v 1.50 2022/04/09 12:07:00 riastradh Exp $ */
/*-
* Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: patch.c,v 1.49 2020/05/07 18:13:05 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: patch.c,v 1.50 2022/04/09 12:07:00 riastradh Exp $");
#include "opt_lockdebug.h"
#ifdef i386
@@ -117,19 +117,6 @@
};
__link_set_add_rodata(x86_hotpatch_descriptors, hp_nolock_desc);
-/* Use LFENCE if available, part of SSE2. */
-extern uint8_t sse2_lfence, sse2_lfence_end;
-static const struct x86_hotpatch_source hp_sse2_lfence_source = {
- .saddr = &sse2_lfence,
- .eaddr = &sse2_lfence_end
-};
-static const struct x86_hotpatch_descriptor hp_sse2_lfence_desc = {
- .name = HP_NAME_SSE2_LFENCE,
- .nsrc = 1,
- .srcs = { &hp_sse2_lfence_source }
-};
-__link_set_add_rodata(x86_hotpatch_descriptors, hp_sse2_lfence_desc);
-
/* Use MFENCE if available, part of SSE2. */
extern uint8_t sse2_mfence, sse2_mfence_end;
static const struct x86_hotpatch_source hp_sse2_mfence_source = {
@@ -342,12 +329,15 @@
if (!early && (cpu_feature[0] & CPUID_SSE2) != 0) {
/*
- * Faster memory barriers. We do not need to patch
- * membar_producer to use SFENCE because on x86
- * ordinary non-temporal stores are always issued in
- * program order to main memory and to other CPUs.
+ * Faster memory barriers. The only barrier x86 ever
+ * requires for MI synchronization between CPUs is
+ * MFENCE for store-before-load ordering; all other
+ * ordering is guaranteed already -- every load is a
+ * load-acquire and every store is a store-release.
+ *
+ * LFENCE and SFENCE are relevant only for MD logic
+ * involving I/O devices or non-temporal stores.
*/
- x86_hotpatch(HP_NAME_SSE2_LFENCE, 0);
x86_hotpatch(HP_NAME_SSE2_MFENCE, 0);
}
Home |
Main Index |
Thread Index |
Old Index