arch/s390/lib/spinlock.c
Source file repositories/reference/linux-study-clean/arch/s390/lib/spinlock.c
File Facts
- System
- Linux kernel
- Corpus path
arch/s390/lib/spinlock.c- Extension
.c- Size
- 8941 bytes
- Lines
- 364
- Domain
- Architecture Layer
- Bucket
- arch/s390
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration 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.
- 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/types.hlinux/export.hlinux/spinlock.hlinux/jiffies.hlinux/sysctl.hlinux/init.hlinux/smp.hlinux/percpu.hlinux/io.hasm/alternative.hasm/machine.hasm/asm.h
Detected Declarations
struct spin_waitfunction spin_retry_initfunction spin_retry_setupfunction init_s390_spin_sysctlsfunction arch_spin_lock_setupfunction arch_load_niai4function arch_try_cmpxchg_niai8function arch_try_cmpxchg_niai8function arch_spin_yield_targetfunction arch_spin_lock_queuedfunction arch_spin_lock_classicfunction arch_spin_lock_waitfunction arch_spin_trylock_retryfunction arch_read_lock_waitfunction arch_write_lock_waitfunction arch_spin_relaxexport arch_spin_lock_waitexport arch_spin_trylock_retryexport arch_read_lock_waitexport arch_write_lock_waitexport arch_spin_relax
Annotated Snippet
struct spin_wait {
struct spin_wait *next, *prev;
int node_id;
} __aligned(32);
static DEFINE_PER_CPU_ALIGNED(struct spin_wait, spin_wait[4]);
#define _Q_LOCK_CPU_OFFSET 0
#define _Q_LOCK_STEAL_OFFSET 16
#define _Q_TAIL_IDX_OFFSET 18
#define _Q_TAIL_CPU_OFFSET 20
#define _Q_LOCK_CPU_MASK 0x0000ffff
#define _Q_LOCK_STEAL_ADD 0x00010000
#define _Q_LOCK_STEAL_MASK 0x00030000
#define _Q_TAIL_IDX_MASK 0x000c0000
#define _Q_TAIL_CPU_MASK 0xfff00000
#define _Q_LOCK_MASK (_Q_LOCK_CPU_MASK | _Q_LOCK_STEAL_MASK)
#define _Q_TAIL_MASK (_Q_TAIL_IDX_MASK | _Q_TAIL_CPU_MASK)
void arch_spin_lock_setup(int cpu)
{
struct spin_wait *node;
int ix;
node = per_cpu_ptr(&spin_wait[0], cpu);
for (ix = 0; ix < 4; ix++, node++) {
memset(node, 0, sizeof(*node));
node->node_id = ((cpu + 1) << _Q_TAIL_CPU_OFFSET) +
(ix << _Q_TAIL_IDX_OFFSET);
}
}
static inline int arch_load_niai4(int *lock)
{
int owner;
asm_inline volatile(
ALTERNATIVE("nop", ".insn rre,0xb2fa0000,4,0", ALT_FACILITY(49)) /* NIAI 4 */
" l %[owner],%[lock]"
: [owner] "=d" (owner) : [lock] "R" (*lock) : "memory");
return owner;
}
#ifdef __HAVE_ASM_FLAG_OUTPUTS__
static inline int arch_try_cmpxchg_niai8(int *lock, int old, int new)
{
int cc;
asm_inline volatile(
ALTERNATIVE("nop", ".insn rre,0xb2fa0000,8,0", ALT_FACILITY(49)) /* NIAI 8 */
" cs %[old],%[new],%[lock]"
: [old] "+d" (old), [lock] "+Q" (*lock), "=@cc" (cc)
: [new] "d" (new)
: "memory");
return cc == 0;
}
#else /* __HAVE_ASM_FLAG_OUTPUTS__ */
static inline int arch_try_cmpxchg_niai8(int *lock, int old, int new)
{
int expected = old;
asm_inline volatile(
ALTERNATIVE("nop", ".insn rre,0xb2fa0000,8,0", ALT_FACILITY(49)) /* NIAI 8 */
" cs %[old],%[new],%[lock]"
: [old] "+d" (old), [lock] "+Q" (*lock)
: [new] "d" (new)
: "cc", "memory");
return expected == old;
}
#endif /* __HAVE_ASM_FLAG_OUTPUTS__ */
static inline struct spin_wait *arch_spin_decode_tail(int lock)
{
int ix, cpu;
ix = (lock & _Q_TAIL_IDX_MASK) >> _Q_TAIL_IDX_OFFSET;
cpu = (lock & _Q_TAIL_CPU_MASK) >> _Q_TAIL_CPU_OFFSET;
return per_cpu_ptr(&spin_wait[ix], cpu - 1);
}
static inline int arch_spin_yield_target(int lock, struct spin_wait *node)
{
if (lock & _Q_LOCK_CPU_MASK)
return lock & _Q_LOCK_CPU_MASK;
Annotation
- Immediate include surface: `linux/types.h`, `linux/export.h`, `linux/spinlock.h`, `linux/jiffies.h`, `linux/sysctl.h`, `linux/init.h`, `linux/smp.h`, `linux/percpu.h`.
- Detected declarations: `struct spin_wait`, `function spin_retry_init`, `function spin_retry_setup`, `function init_s390_spin_sysctls`, `function arch_spin_lock_setup`, `function arch_load_niai4`, `function arch_try_cmpxchg_niai8`, `function arch_try_cmpxchg_niai8`, `function arch_spin_yield_target`, `function arch_spin_lock_queued`.
- Atlas domain: Architecture Layer / arch/s390.
- 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.