arch/powerpc/include/asm/simple_spinlock.h
Source file repositories/reference/linux-study-clean/arch/powerpc/include/asm/simple_spinlock.h
File Facts
- System
- Linux kernel
- Corpus path
arch/powerpc/include/asm/simple_spinlock.h- Extension
.h- Size
- 6242 bytes
- Lines
- 269
- Domain
- Architecture Layer
- Bucket
- arch/powerpc
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
Dependency Surface
linux/irqflags.hlinux/kcsan-checks.hasm/paravirt.hasm/paca.hasm/synch.hasm/ppc-opcode.h
Detected Declarations
function Copyrightfunction arch_spin_is_lockedfunction __arch_spin_trylockfunction arch_spin_trylockfunction splpar_spin_yieldfunction rw_yieldfunction arch_spin_lockfunction arch_spin_unlockfunction __arch_read_trylockfunction __arch_write_trylockfunction arch_read_lockfunction arch_write_lockfunction arch_read_trylockfunction arch_write_trylockfunction arch_read_unlockfunction arch_write_unlock
Annotated Snippet
static inline void splpar_spin_yield(arch_spinlock_t *lock) {}
static inline void splpar_rw_yield(arch_rwlock_t *lock) {}
#endif
static inline void spin_yield(arch_spinlock_t *lock)
{
if (is_shared_processor())
splpar_spin_yield(lock);
else
barrier();
}
static inline void rw_yield(arch_rwlock_t *lock)
{
if (is_shared_processor())
splpar_rw_yield(lock);
else
barrier();
}
static inline void arch_spin_lock(arch_spinlock_t *lock)
{
while (1) {
if (likely(__arch_spin_trylock(lock) == 0))
break;
do {
HMT_low();
if (is_shared_processor())
splpar_spin_yield(lock);
} while (unlikely(lock->slock != 0));
HMT_medium();
}
}
static inline void arch_spin_unlock(arch_spinlock_t *lock)
{
kcsan_mb();
__asm__ __volatile__("# arch_spin_unlock\n\t"
PPC_RELEASE_BARRIER: : :"memory");
lock->slock = 0;
}
/*
* Read-write spinlocks, allowing multiple readers
* but only one writer.
*
* NOTE! it is quite common to have readers in interrupts
* but no interrupt writers. For those circumstances we
* can "mix" irq-safe locks - any writer needs to get a
* irq-safe write-lock, but readers can get non-irqsafe
* read-locks.
*/
#ifdef CONFIG_PPC64
#define __DO_SIGN_EXTEND "extsw %0,%0\n"
#define WRLOCK_TOKEN LOCK_TOKEN /* it's negative */
#else
#define __DO_SIGN_EXTEND
#define WRLOCK_TOKEN (-1)
#endif
/*
* This returns the old value in the lock + 1,
* so we got a read lock if the return value is > 0.
*/
static inline long __arch_read_trylock(arch_rwlock_t *rw)
{
long tmp;
unsigned int eh = IS_ENABLED(CONFIG_PPC64);
__asm__ __volatile__(
"1: lwarx %0,0,%1,%[eh]\n"
__DO_SIGN_EXTEND
" addic. %0,%0,1\n\
ble- 2f\n"
" stwcx. %0,0,%1\n\
bne- 1b\n"
PPC_ACQUIRE_BARRIER
"2:" : "=&r" (tmp)
: "r" (&rw->lock), [eh] "n" (eh)
: "cr0", "xer", "memory");
return tmp;
}
/*
* This returns the old value in the lock,
* so we got the write lock if the return value is 0.
*/
static inline long __arch_write_trylock(arch_rwlock_t *rw)
Annotation
- Immediate include surface: `linux/irqflags.h`, `linux/kcsan-checks.h`, `asm/paravirt.h`, `asm/paca.h`, `asm/synch.h`, `asm/ppc-opcode.h`.
- Detected declarations: `function Copyright`, `function arch_spin_is_locked`, `function __arch_spin_trylock`, `function arch_spin_trylock`, `function splpar_spin_yield`, `function rw_yield`, `function arch_spin_lock`, `function arch_spin_unlock`, `function __arch_read_trylock`, `function __arch_write_trylock`.
- Atlas domain: Architecture Layer / arch/powerpc.
- Implementation status: source 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.