[patch 00/50] locking, sched: The PREEMPT-RT locking infrastructure

From: Thomas Gleixner
Date: Tue Jul 13 2021 - 12:13:12 EST


Folks,

the following series contains the bulk of the PREEMPT-RT locking
infrastructure. In PREEMPT-RT enabled kernels the following locking
primitives are substituted by RT-Mutex based variants:

mutex, rw_semaphore, spinlock, rwlock

semaphores are not substituted because they do not provide strict owner
semantics.

ww_mutexes are also not substituted because the usage sites are not really
RT relevant and it would require a full reimplementation to make them work
correctly based on rtmutex. That might change in the future, but for now
utilizing the existing variant is considered a safe and sane choice.

Of course raw_spinlocks are not touched either as they protect low level
operations in the scheduler, timers and hardware access.

The most interesting parts of the series which need a lot of eyeballs
are:

- the scheduler bits which provide the infrastructure for spinlock and
rwlock substitution to ensure that the task state is preserved when
blocking on such a lock and a regular wakeup is handled correctly and
not lost

- the rtmutex core implementation to handle lock contention on spinlocks
and rwlocks correctly vs. the task state

- the rw_semaphore/rwlock substitutions which utilize the same
implementation vs. the reader/writer handling

- the isolation of the ww_mutex code which allows to build it stand alone.
The typedef based solution might look a bit odd on the first glance,
but that turned out to be the least intrusive variant.

- the PI futex related bits to handle the interaction between blocking
on the underlying rtmutex and contention on the hash bucket lock which
is converted to a 'sleeping spinlock'.

The rest surely needs a thorough review as well, but those parts are pretty
straight forward. Quite some code restructuring and the actual wrapper
functions to replace the existing !RT implementations.

The series survived quite some internal testing in RT kernels and is part
of the recent 5.13-rt1 release.

For !RT kernels there is no functional change.

The series is also available from git:

git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git rtmutex

Thanks,

tglx
---
a/kernel/locking/mutex-debug.h | 29 -
b/include/linux/mutex.h | 165 ++++--
b/include/linux/rbtree_types.h | 34 +
b/include/linux/rwbase_rt.h | 37 +
b/include/linux/rwlock_rt.h | 140 +++++
b/include/linux/spinlock_rt.h | 151 +++++
b/include/linux/spinlock_types_raw.h | 65 ++
b/kernel/locking/rtmutex_api.c | 647 ++++++++++++++++++++++++
b/kernel/locking/rwbase_rt.c | 263 +++++++++
b/kernel/locking/spinlock_rt.c | 257 +++++++++
include/linux/debug_locks.h | 3
include/linux/preempt.h | 4
include/linux/rbtree.h | 30 -
include/linux/rtmutex.h | 4
include/linux/rwlock_types.h | 39 +
include/linux/rwsem.h | 58 ++
include/linux/sched.h | 77 ++
include/linux/sched/wake_q.h | 7
include/linux/spinlock.h | 15
include/linux/spinlock_api_smp.h | 3
include/linux/spinlock_types.h | 45 +
include/linux/ww_mutex.h | 16
kernel/Kconfig.locks | 2
kernel/futex.c | 466 ++++++++++++-----
kernel/locking/Makefile | 3
kernel/locking/mutex-debug.c | 25
kernel/locking/mutex.c | 139 ++---
kernel/locking/mutex.h | 35 +
kernel/locking/rtmutex.c | 930 ++++++++++++-----------------------
kernel/locking/rtmutex_common.h | 110 ++--
kernel/locking/rwsem.c | 108 ++++
kernel/locking/spinlock.c | 7
kernel/locking/spinlock_debug.c | 5
kernel/sched/core.c | 111 +++-
lib/test_lockup.c | 8
35 files changed, 3031 insertions(+), 1007 deletions(-)