include/asm-generic/rqspinlock.h
Source file repositories/reference/linux-study-clean/include/asm-generic/rqspinlock.h
File Facts
- System
- Linux kernel
- Corpus path
include/asm-generic/rqspinlock.h- Extension
.h- Size
- 8151 bytes
- Lines
- 263
- Domain
- Repository Root And Misc
- Bucket
- include
- Inferred role
- Repository Root And Misc: implementation source
- Status
- source implementation candidate
Why This File Exists
Top-level or miscellaneous repository surface. Use this as map coverage unless a later manual pass promotes the file into a deeper subsystem dossier.
- Top-level or miscellaneous repository surface. Use this as map coverage unless a later manual pass promotes the file into a deeper subsystem dossier.
- 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.hvdso/time64.hlinux/percpu.hasm/qspinlock.h
Detected Declarations
struct rqspinlockstruct bpf_res_spin_lockstruct qspinlockstruct rqspinlock_heldfunction resilient_virt_spin_lock_enabledfunction resilient_virt_spin_lockfunction grab_held_lock_entryfunction orderfunction res_spin_lockfunction res_spin_unlock
Annotated Snippet
struct rqspinlock {
union {
atomic_t val;
u32 locked;
};
};
/* Even though this is same as struct rqspinlock, we need to emit a distinct
* type in BTF for BPF programs.
*/
struct bpf_res_spin_lock {
u32 val;
} __aligned(__alignof__(struct rqspinlock));
struct qspinlock;
#ifdef CONFIG_QUEUED_SPINLOCKS
typedef struct qspinlock rqspinlock_t;
#else
typedef struct rqspinlock rqspinlock_t;
#endif
extern int resilient_tas_spin_lock(rqspinlock_t *lock);
#ifdef CONFIG_QUEUED_SPINLOCKS
extern int resilient_queued_spin_lock_slowpath(rqspinlock_t *lock, u32 val);
#endif
#ifndef resilient_virt_spin_lock_enabled
static __always_inline bool resilient_virt_spin_lock_enabled(void)
{
return false;
}
#endif
#ifndef resilient_virt_spin_lock
static __always_inline int resilient_virt_spin_lock(rqspinlock_t *lock)
{
return 0;
}
#endif
/*
* Default timeout for waiting loops is 0.25 seconds
*/
#define RES_DEF_TIMEOUT (NSEC_PER_SEC / 4)
/*
* Choose 31 as it makes rqspinlock_held cacheline-aligned.
*/
#define RES_NR_HELD 31
struct rqspinlock_held {
int cnt;
void *locks[RES_NR_HELD];
};
DECLARE_PER_CPU_ALIGNED(struct rqspinlock_held, rqspinlock_held_locks);
static __always_inline void grab_held_lock_entry(void *lock)
{
int cnt = this_cpu_inc_return(rqspinlock_held_locks.cnt);
if (unlikely(cnt > RES_NR_HELD)) {
/* Still keep the inc so we decrement later. */
return;
}
/*
* Implied compiler barrier in per-CPU operations; otherwise we can have
* the compiler reorder inc with write to table, allowing interrupts to
* overwrite and erase our write to the table (as on interrupt exit it
* will be reset to NULL).
*
* It is fine for cnt inc to be reordered wrt remote readers though,
* they won't observe our entry until the cnt update is visible, that's
* all.
*/
this_cpu_write(rqspinlock_held_locks.locks[cnt - 1], lock);
}
/*
* We simply don't support out-of-order unlocks, and keep the logic simple here.
* The verifier prevents BPF programs from unlocking out-of-order, and the same
* holds for in-kernel users.
*
* It is possible to run into misdetection scenarios of AA deadlocks on the same
* CPU, and missed ABBA deadlocks on remote CPUs if this function pops entries
* out of order (due to lock A, lock B, unlock A, unlock B) pattern. The correct
* logic to preserve right entries in the table would be to walk the array of
* held locks and swap and clear out-of-order entries, but that's too
* complicated and we don't have a compelling use case for out of order unlocking.
Annotation
- Immediate include surface: `linux/types.h`, `vdso/time64.h`, `linux/percpu.h`, `asm/qspinlock.h`.
- Detected declarations: `struct rqspinlock`, `struct bpf_res_spin_lock`, `struct qspinlock`, `struct rqspinlock_held`, `function resilient_virt_spin_lock_enabled`, `function resilient_virt_spin_lock`, `function grab_held_lock_entry`, `function order`, `function res_spin_lock`, `function res_spin_unlock`.
- Atlas domain: Repository Root And Misc / include.
- 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.