Reapply c84bb8cd771c. markj's original commit log:
rmlock: Micro-optimize read locking Use get_pcpu() instead of an open-coded pcpu_find(td->td_oncpu). This eliminates some memory accesses and results in a shorter instruction sequence. Note that get_pcpu() didn't exist when rmlocks were added. Reviewed by: jah, mjg MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D34377
That optimization was subsequently reverted by
afb44cb01018 ("rmlock: Temporarily revert commit c84bb8cd771c")due to triggering panics on arm64. The issue was diagnosed as arm64's
get_pcpu() using a register asm variable, allowing the compiler to
reorder accesses that were intended to be constrained by the pseudo
critical section. The arm64 behavior was subsequently fixed in
ed3066342660 ("Make the arm64 get_pcpu a function again")but the original rmlock optimization was not reapplied at that time.
I checked disassembly of _rm_lock from clang and gcc on arm64 that the
pcpu pointer load occurred within the pseudo critical section.
For more background, see mailing list archive for the thread that began with "panic: Unknown kernel exception 0 esr_el1 2000000 (on 14-CURRENT/aarch64 Feb 28)"
https://lists.freebsd.org/archives/freebsd-current/2022-March/subject.html