summaryrefslogtreecommitdiff
path: root/common/lib/libc/arch/powerpc/atomic
AgeCommit message (Collapse)Author
2022-04-09Introduce membar_acquire/release. Deprecate membar_enter/exit.riastradh
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.
2022-04-06Nix trailing whitespace in files of membars, atomics, and lock stubs.riastradh
Will be touching many of these files soon for functional changes. No functional change intended.
2020-03-01Implement workaround for IBM405 Errata 77 (aka CPU_210), whererin
interrupted stwcx. may errantly write data to memory: https://elinux.org/images/1/1d/Ppc405gp-errata.pdf This is because stwcx. is split into two pieces in the pipeline. We need to (1) insert dcbt before every stwcx. instruction, as well as (2) insert sync before every rfi/rfci instruction. It is unclear which processors are affected, but according to Linux, all 405-based cores up until 405GPR and 405EP are affected: https://github.com/torvalds/linux/blob/master/arch/powerpc/platforms/40x/Kconfig#L140 For kernel, this workaround can be restricted to affected processors. However, for kernel modules and userland, we have to enable it for all 32bit powerpc archs in order to share common binaries as before. Proposed on port-powerpc: http://mail-index.netbsd.org/port-powerpc/2020/02/21/msg003583.html
2014-03-07Reduce duplication.matt
Use beqlr to quicken returns
2011-01-15Use END(foo) everywhere.matt
Make __cerror hidden. Use non-PLT calls to __cerror. Use assym.h when appropriate. Use addi to adjust stack instead of loading it. Add __RCSIDs Force -D_NOREGNAMES for all .S files. [this is all in preperation for secure plt support]
2009-01-04allow inclusion of atomic ops in librumppooka
2008-09-29Allow atomic ops to be built as part of libpthread.ad
2008-05-25enable profiling of assembly functions.chs
2008-04-28Remove clause 3 and 4 from TNF licensesmartin
2008-02-13add missing %. (hi matt!)dogcow
2008-02-12Use %rN as all new code is supposed to.matt
2008-02-11Only build atomic ops for libkern/libc.ad
2008-02-10Enable the atomic ops in userspace.ad
2008-02-10Add atomic_cas_foo_ni().ad
2007-11-28Atomic ops for powerpc. Please review.ad