more cleanup for s_lock.h
Thread notes
1 note#refactor
hackorum-bot#refactor
@global #refactor
While working on recent round of s_lock.h cleanup, I started wondering
whether we really need architecture-specific implementations of anything in
that file besides SPIN_DELAY(). We've been slowly moving away from
spinlocks, and the compiler builtins have been available for ~20 years, so
I doubt all of this hand-rolled code is still buying us much. I'd like to
see how much of it we can get rid of, and the attached patches are a first
step in that direction. This batch just removes some redundancy between
platforms.
0001 removes the parts of the ARM section that are redundant with the
generic __sync code added by commit 1c72d82c25. The TAS_SPIN() and
SPIN_DELAY() definitions for AArch64 stay, and the generated code shouldn't
change.
0002 merges the i386 section into the x86-64 one. The only real difference
is that i386 does an unlocked test before every xchg, whereas x86-64 only
does so in TAS_SPIN(). The comment in the i386 section suggests that i386
should probably follow x86-64's lead, but nobody has tested it. Since
we've disclaimed interest in micro-optimizing for 32-bit builds (see commit
cb7b2e5e8e), IMHO we should just do it.
0003 makes the unlocked test the default for TAS_SPIN() and removes the
platform-specific versions for x86, PPC, and AArch64 (see commits
b03d196be0, bc2a050d40, and 3d0b4b1068). Nothing changes for those three,
but everything else (e.g., s390, SPARC, MIPS, RISC-V, 32-bit ARM, and all
MSVC builds) will now do the unlocked test while waiting for a contended
spinlock.
We've thus far been hesitant to add the unlocked test to platforms without
evidence of improvements, but that means a platform goes without it until
someone happens to notice. AArch64 is the best example. It didn't get the
unlocked test until v18, more than a decade after we added support for it,
despite it being a clear win there. That's one of the main reasons I'd
like to make it the default. AFAICT that reasoning should basically apply
everywhere, and a platform can still override TAS_SPIN() if it turns out to
hurt.
Thoughts?
--
nathan