kernel/locking/spinlock_rt.c
Source file repositories/reference/linux-study-clean/kernel/locking/spinlock_rt.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/locking/spinlock_rt.c- Extension
.c- Size
- 7311 bytes
- Lines
- 288
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/spinlock.hlinux/export.hrtmutex.crwbase_rt.c
Detected Declarations
function rcu_read_lockfunction __rt_spin_lockfunction rt_spin_lockfunction rt_spin_lock_nestedfunction rt_spin_lock_nest_lockfunction rt_spin_unlockfunction rt_spin_lock_unlockfunction __rt_spin_trylockfunction rt_spin_trylockfunction rt_spin_trylock_bhfunction __rt_spin_lock_initfunction rwbase_rtmutex_lock_statefunction rwbase_rtmutex_slowlock_lockedfunction rwbase_rtmutex_unlockfunction rwbase_rtmutex_trylockfunction rt_read_trylockfunction rt_write_trylockfunction rt_read_lockfunction rt_write_lockfunction rt_write_lock_nestedfunction rt_read_unlockfunction rt_write_unlockfunction __rt_rwlock_initexport rt_spin_lockexport rt_spin_lock_nestedexport rt_spin_lock_nest_lockexport rt_spin_unlockexport rt_spin_lock_unlockexport rt_spin_trylockexport rt_spin_trylock_bhexport __rt_spin_lock_initexport rt_read_trylockexport rt_write_trylockexport rt_read_lockexport rt_write_lockexport rt_write_lock_nestedexport rt_read_unlockexport rt_write_unlockexport __rt_rwlock_init
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* PREEMPT_RT substitution for spin/rw_locks
*
* spinlocks and rwlocks on RT are based on rtmutexes, with a few twists to
* resemble the non RT semantics:
*
* - Contrary to plain rtmutexes, spinlocks and rwlocks are state
* preserving. The task state is saved before blocking on the underlying
* rtmutex, and restored when the lock has been acquired. Regular wakeups
* during that time are redirected to the saved state so no wake up is
* missed.
*
* - Non RT spin/rwlocks disable preemption and eventually interrupts.
* Disabling preemption has the side effect of disabling migration and
* preventing RCU grace periods.
*
* The RT substitutions explicitly disable migration and take
* rcu_read_lock() across the lock held section.
*/
#include <linux/spinlock.h>
#include <linux/export.h>
#define RT_MUTEX_BUILD_SPINLOCKS
#include "rtmutex.c"
/*
* __might_resched() skips the state check as rtlocks are state
* preserving. Take RCU nesting into account as spin/read/write_lock() can
* legitimately nest into an RCU read side critical section.
*/
#define RTLOCK_RESCHED_OFFSETS \
(rcu_preempt_depth() << MIGHT_RESCHED_RCU_SHIFT)
#define rtlock_might_resched() \
__might_resched(__FILE__, __LINE__, RTLOCK_RESCHED_OFFSETS)
static __always_inline void rtlock_lock(struct rt_mutex_base *rtm)
{
lockdep_assert(!current->pi_blocked_on);
if (unlikely(!rt_mutex_cmpxchg_acquire(rtm, NULL, current)))
rtlock_slowlock(rtm);
}
static __always_inline void __rt_spin_lock(spinlock_t *lock)
{
rtlock_might_resched();
rtlock_lock(&lock->lock);
rcu_read_lock();
migrate_disable();
}
void __sched rt_spin_lock(spinlock_t *lock) __acquires(RCU)
{
spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
__rt_spin_lock(lock);
}
EXPORT_SYMBOL(rt_spin_lock);
#ifdef CONFIG_DEBUG_LOCK_ALLOC
void __sched rt_spin_lock_nested(spinlock_t *lock, int subclass)
{
spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
__rt_spin_lock(lock);
}
EXPORT_SYMBOL(rt_spin_lock_nested);
void __sched rt_spin_lock_nest_lock(spinlock_t *lock,
struct lockdep_map *nest_lock)
{
spin_acquire_nest(&lock->dep_map, 0, 0, nest_lock, _RET_IP_);
__rt_spin_lock(lock);
}
EXPORT_SYMBOL(rt_spin_lock_nest_lock);
#endif
void __sched rt_spin_unlock(spinlock_t *lock) __releases(RCU)
{
spin_release(&lock->dep_map, _RET_IP_);
migrate_enable();
rcu_read_unlock();
if (unlikely(!rt_mutex_cmpxchg_release(&lock->lock, current, NULL)))
rt_mutex_slowunlock(&lock->lock);
}
EXPORT_SYMBOL(rt_spin_unlock);
/*
* Wait for the lock to get unlocked: instead of polling for an unlock
Annotation
- Immediate include surface: `linux/spinlock.h`, `linux/export.h`, `rtmutex.c`, `rwbase_rt.c`.
- Detected declarations: `function rcu_read_lock`, `function __rt_spin_lock`, `function rt_spin_lock`, `function rt_spin_lock_nested`, `function rt_spin_lock_nest_lock`, `function rt_spin_unlock`, `function rt_spin_lock_unlock`, `function __rt_spin_trylock`, `function rt_spin_trylock`, `function rt_spin_trylock_bh`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.