more cleanup for s_lock.h

Started by Nathan Bossart8 days ago1 messageshackers

Thread notes

1 note#refactor
hackorum-bot#refactor
hackorum-bot
2 days ago

@global #refactor

#refactor
Jump to latest
#1Nathan Bossart
nathandbossart@gmail.com

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

Attachments:

t259601_1
v1-0001-Remove-redundant-spinlock-code-for-ARM-ARM64.patchtext/plain; charset=us-asciiDownload+3-23
v1-0002-Merge-i386-and-x86-64-code-in-s_lock.h.patchtext/plain; charset=us-asciiDownload+10-74
v1-0003-Use-unlocked-test-before-test-and-set-in-TAS_SPIN.patchtext/plain; charset=us-asciiDownload+6-27