| #
f183eaee |
| 16-Jul-2024 |
riastradh <riastradh@NetBSD.org> |
xen: Don't hotpatch away LOCK prefix in xen_mb, even on UP boots.
Both xen_mb and membar_sync are designed to provide store-before-load ordering, but xen_mb has to provide it in synchronizing guest
xen: Don't hotpatch away LOCK prefix in xen_mb, even on UP boots.
Both xen_mb and membar_sync are designed to provide store-before-load ordering, but xen_mb has to provide it in synchronizing guest with hypervisor, while membar_sync only has to provide it in synchronizing one (guest) CPU with another (guest) CPU.
It is safe to hotpatch away the LOCK prefix in membar_sync on a uniprocessor boot because membar_sync is only designed to coordinate between normal memory on multiple CPUs, and is never necessary when there's only one CPU involved.
But xen_mb is used to coordinate between the guest and the `device' implemented by a hypervisor, which might be running on another _physical_ CPU even if the NetBSD guest only sees one `CPU', i.e., one _virtual_ CPU. So even on `uniprocessor' boots, xen_mb must still issue an instruction with store-before-load ordering on multiprocessor systems, such as a LOCK ADD (or MFENCE, but MFENCE is costlier for no benefit here).
No need to change xen_wmb (release ordering, load/store-before-store) or xen_rmb (acquire ordering, load-before-load/store) because every x86 store is a store-release and every x86 load is a load-acquire, even on multiprocessor systems, so there's no hotpatching involved anyway.
PR kern/57199
show more ...
|
| #
376bcb54 |
| 30-Jul-2022 |
riastradh <riastradh@NetBSD.org> |
x86: Eliminate mfence hotpatch for membar_sync.
The more-compatible LOCK ADD $0,-N(%rsp) turns out to be cheaper than MFENCE anyway. Let's save some space and maintenance and rip out the hotpatch
x86: Eliminate mfence hotpatch for membar_sync.
The more-compatible LOCK ADD $0,-N(%rsp) turns out to be cheaper than MFENCE anyway. Let's save some space and maintenance and rip out the hotpatching for it.
show more ...
|
| #
4f8ce3b3 |
| 09-Apr-2022 |
riastradh <riastradh@NetBSD.org> |
Introduce membar_acquire/release. Deprecate membar_enter/exit.
The names membar_enter/exit were unclear, and the documentation of membar_enter has disagreed with the implementations on sparc, power
Introduce membar_acquire/release. Deprecate membar_enter/exit.
The names membar_enter/exit were unclear, and the documentation of membar_enter has disagreed with the implementations on sparc, powerpc, and even x86(!) for the entire time it has been in NetBSD.
The terms `acquire' and `release' are ubiquitous in the literature today, and have been adopted in the C and C++ standards to mean load-before-load/store and load/store-before-store, respectively, which are exactly the orderings required by acquiring and releasing a mutex, as well as other useful applications like decrementing a reference count and then freeing the underlying object if it went to zero.
Originally I proposed changing one word in the documentation for membar_enter to make it load-before-load/store instead of store-before-load/store, i.e., to make it an acquire barrier. I proposed this on the grounds that
(a) all implementations guarantee load-before-load/store, (b) some implementations fail to guarantee store-before-load/store, and (c) all uses in-tree assume load-before-load/store.
I verified parts (a) and (b) (except, for (a), powerpc didn't even guarantee load-before-load/store -- isync isn't necessarily enough; need lwsync in general -- but it _almost_ did, and it certainly didn't guarantee store-before-load/store).
Part (c) might not be correct, however: under the mistaken assumption that atomic-r/m/w then membar-w/rw is equivalent to atomic-r/m/w then membar-r/rw, I only audited the cases of membar_enter that _aren't_ immediately after an atomic-r/m/w. All of those cases assume load-before-load/store. But my assumption was wrong -- there are cases of atomic-r/m/w then membar-w/rw that would be broken by changing to atomic-r/m/w then membar-r/rw:
https://mail-index.netbsd.org/tech-kern/2022/03/29/msg028044.html
Furthermore, the name membar_enter has been adopted in other places like OpenBSD where it actually does follow the documentation and guarantee store-before-load/store, even if that order is not useful. So the name membar_enter currently lives in a bad place where it means either of two things -- r/rw or w/rw.
With this change, we deprecate membar_enter/exit, introduce membar_acquire/release as better names for the useful pair (r/rw and rw/w), and make sure the implementation of membar_enter guarantees both what was documented _and_ what was implemented, making it an alias for membar_sync.
While here, rework all of the membar_* definitions and aliases. The new logic follows a rule to make it easier to audit:
membar_X is defined as an alias for membar_Y iff membar_X is guaranteed by membar_Y.
The `no stronger than' relation is (the transitive closure of):
- membar_consumer (r/r) is guaranteed by membar_acquire (r/rw) - membar_producer (w/w) is guaranteed by membar_release (rw/w) - membar_acquire (r/rw) is guaranteed by membar_sync (rw/rw) - membar_release (rw/w) is guaranteed by membar_sync (rw/rw)
And, for the deprecated membars:
- membar_enter (whether r/rw, w/rw, or rw/rw) is guaranteed by membar_sync (rw/rw) - membar_exit (rw/w) is guaranteed by membar_release (rw/w)
(membar_exit is identical to membar_release, but the name is deprecated.)
Finally, while here, annotate some of the instructions with their semantics. For powerpc, leave an essay with citations on the unfortunate but -- as far as I can tell -- necessary decision to use lwsync, not isync, for membar_acquire and membar_consumer.
Also add membar(3) and atomic(3) man page links.
show more ...
|
| #
a1f4bcbf |
| 09-Apr-2022 |
riastradh <riastradh@NetBSD.org> |
i386/membar_ops: Upgrade membar_enter from R/RW to RW/RW.
This will be deprecated soon but let's avoid leaving rakes to trip on with it arising from disagreement over the documentation (W/RW) and im
i386/membar_ops: Upgrade membar_enter from R/RW to RW/RW.
This will be deprecated soon but let's avoid leaving rakes to trip on with it arising from disagreement over the documentation (W/RW) and implementation and usage (R/RW).
show more ...
|
| #
d767c973 |
| 09-Apr-2022 |
riastradh <riastradh@NetBSD.org> |
x86: Add a note on membar_sync and mfence.
|
| #
3066bbbb |
| 09-Apr-2022 |
riastradh <riastradh@NetBSD.org> |
x86: Omit needless store in membar_producer/exit.
On x86, every store is a store-release, so there is no need for any barrier. But this wasn't a barrier anyway; it was just a store, which was redun
x86: Omit needless store in membar_producer/exit.
On x86, every store is a store-release, so there is no need for any barrier. But this wasn't a barrier anyway; it was just a store, which was redundant with the store of the return address to the stack implied by CALL even if issuing a store made a difference.
show more ...
|
| #
e0c914a7 |
| 09-Apr-2022 |
riastradh <riastradh@NetBSD.org> |
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 lik
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.)
show more ...
|
| #
09ff5f3b |
| 06-Apr-2022 |
riastradh <riastradh@NetBSD.org> |
Nix trailing whitespace in files of membars, atomics, and lock stubs.
Will be touching many of these files soon for functional changes.
No functional change intended.
|
| #
712bef21 |
| 01-May-2020 |
maxv <maxv@NetBSD.org> |
Use the hotpatch framework when patching _atomic_cas_64.
|
| #
129e4c2b |
| 26-Apr-2020 |
maxv <maxv@NetBSD.org> |
Use the hotpatch framework for LFENCE/MFENCE.
|
| #
f012eec2 |
| 26-Apr-2020 |
maxv <maxv@NetBSD.org> |
Remove unused argument in macro.
|
| #
e18b0a46 |
| 26-Apr-2020 |
maxv <maxv@NetBSD.org> |
Remove unused.
|
| #
88b0d179 |
| 26-Apr-2020 |
maxv <maxv@NetBSD.org> |
Drop the hardcoded array, use the hotpatch section.
|
| #
c24c993f |
| 25-Apr-2020 |
bouyer <bouyer@NetBSD.org> |
Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM guests in GENERIC. Xen support can be disabled at runtime with boot -c disable hypervisor
|
| #
efd0e73e |
| 18-Jul-2018 |
bouyer <bouyer@NetBSD.org> |
On Xen, always alias _atomic_cas_64 to _atomic_cas_cx8. AFAIK Xen doesn't support CPUs that don't support cx8. i386 XENPAE_DOMU boots again.
|
| #
19ef5b5b |
| 23-May-2014 |
uebayasi <uebayasi@NetBSD.org> |
Put missing END() markers to set ELF symbol size.
|
| #
57561cf1 |
| 22-Apr-2014 |
christos <christos@NetBSD.org> |
The kernel uses 64 bit atomic ops.
|
| #
7c94bf08 |
| 18-Feb-2014 |
martin <martin@NetBSD.org> |
Provide most missing __sync_*64 primitives for i386
|
| #
d3a052c4 |
| 12-Jan-2011 |
joerg <joerg@NetBSD.org> |
Allow use of traditional CPP to be set on a per platform base in sys.mk. Honour this for dependency processing in bsd.dep.mk. Switch i386 and amd64 assembly to use ISO C90 preprocessor concat and dr
Allow use of traditional CPP to be set on a per platform base in sys.mk. Honour this for dependency processing in bsd.dep.mk. Switch i386 and amd64 assembly to use ISO C90 preprocessor concat and drop the -traditional-cpp on this platform.
show more ...
|
| #
043ef3bc |
| 26-Nov-2009 |
pooka <pooka@NetBSD.org> |
Use strong alias within the kernel namespace regardless of if we're dealing with a hard or soft kernel (kernel linker doesn't support weak symbols).
|
| #
09fcc8b3 |
| 02-Apr-2009 |
enami <enami@NetBSD.org> |
So that profile kernel runs again, - Adjust the size of functions used to patch. - Fix the jump offset of mcount call when patching functions.
Approved by Andrew Doran.
|
| #
654753c2 |
| 12-Jan-2009 |
pooka <pooka@NetBSD.org> |
include sys/param.h for _HARDKERNEL instead of homegrown def.
|
| #
58302d67 |
| 04-Jan-2009 |
pooka <pooka@NetBSD.org> |
Opt for libc versions in case of _KERNEL && !_RUMPKERNEL. (kernel version uses sti/cli and is not PIC)
|
| #
30fd42e8 |
| 19-Dec-2008 |
ad <ad@NetBSD.org> |
PR kern/40213 my i386 machine can't boot because of tsc
- Patch in atomic_cas_64() twice. The first patch is early and makes it the MP-atomic version available if we have cmpxchg8b. The second pat
PR kern/40213 my i386 machine can't boot because of tsc
- Patch in atomic_cas_64() twice. The first patch is early and makes it the MP-atomic version available if we have cmpxchg8b. The second patch strips the lock prefix if ncpu==1.
- Fix the i486 atomic_cas_64() to not unconditionally enable interrupts.
show more ...
|
| #
6740bb54 |
| 25-May-2008 |
chs <chs@NetBSD.org> |
enable profiling of assembly functions.
|