include/linux/seqlock.h
Source file repositories/reference/linux-study-clean/include/linux/seqlock.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/seqlock.h- Extension
.h- Size
- 42691 bytes
- Lines
- 1367
- Domain
- Core OS
- Bucket
- Core Kernel Interface
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- 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/compiler.hlinux/cleanup.hlinux/kcsan-checks.hlinux/lockdep.hlinux/mutex.hlinux/preempt.hlinux/seqlock_types.hlinux/spinlock.hasm/processor.h
Detected Declarations
struct ss_tmpenum ss_statefunction __seqcount_initfunction seqcount_lockdep_reader_accessfunction SEQCNT_ZEROfunction __seqpropfunction __seqprop_sequencefunction __seqprop_preemptiblefunction __seqprop_assertfunction __read_seqcount_retryfunction read_seqcount_retryfunction do_raw_write_seqcount_beginfunction do_raw_write_seqcount_endfunction do_write_seqcount_begin_nestedfunction do_write_seqcount_beginfunction do_write_seqcount_endfunction do_raw_write_seqcount_barrierfunction write_seqcount_invalidatefunction SEQCNT_LATCH_ZEROfunction read_seqcount_latchfunction raw_read_seqcount_latch_retryfunction read_seqcount_latch_retryfunction raw_write_seqcount_latchfunction write_seqcount_latch_beginfunction write_seqcount_latchfunction write_seqcount_latch_endfunction __scoped_seqlock_nextfunction __scoped_seqlock_nextfunction __scoped_seqlock_next
Annotated Snippet
struct ss_tmp {
enum ss_state state;
unsigned long data;
spinlock_t *lock;
spinlock_t *lock_irqsave;
};
static __always_inline void __scoped_seqlock_cleanup(struct ss_tmp *sst)
__no_context_analysis
{
if (sst->lock)
spin_unlock(sst->lock);
if (sst->lock_irqsave)
spin_unlock_irqrestore(sst->lock_irqsave, sst->data);
}
extern void __scoped_seqlock_invalid_target(void);
#if (defined(CONFIG_CC_IS_GCC) && CONFIG_GCC_VERSION < 90000) || \
defined(CONFIG_KASAN) || defined(CONFIG_UBSAN_ALIGNMENT)
/*
* For some reason some GCC-8 architectures (nios2, alpha) have trouble
* determining that the ss_done state is impossible in __scoped_seqlock_next()
* below.
*
* Similarly KASAN and UBSAN_ALIGNMENT are known to confuse compilers enough
* to break this. But we don't care about code quality for such builds anyway.
*/
static inline void __scoped_seqlock_bug(void) { }
#else
/*
* Canary for compiler optimization -- if the compiler doesn't realize this is
* an impossible state, it very likely generates sub-optimal code here.
*/
extern void __scoped_seqlock_bug(void);
#endif
static __always_inline void
__scoped_seqlock_next(struct ss_tmp *sst, seqlock_t *lock, enum ss_state target)
__no_context_analysis
{
switch (sst->state) {
case ss_done:
__scoped_seqlock_bug();
return;
case ss_lock:
case ss_lock_irqsave:
sst->state = ss_done;
return;
case ss_lockless:
if (!read_seqretry(lock, sst->data)) {
sst->state = ss_done;
return;
}
break;
}
switch (target) {
case ss_done:
__scoped_seqlock_invalid_target();
return;
case ss_lock:
sst->lock = &lock->lock;
spin_lock(sst->lock);
sst->state = ss_lock;
return;
case ss_lock_irqsave:
sst->lock_irqsave = &lock->lock;
spin_lock_irqsave(sst->lock_irqsave, sst->data);
sst->state = ss_lock_irqsave;
return;
case ss_lockless:
sst->data = read_seqbegin(lock);
return;
}
}
/*
* Context analysis no-op helper to release seqlock at the end of the for-scope;
* the alias analysis of the compiler will recognize that the pointer @s is an
* alias to @_seqlock passed to read_seqbegin(_seqlock) below.
*/
static __always_inline void __scoped_seqlock_cleanup_ctx(struct ss_tmp **s)
__releases_shared(*((seqlock_t **)s)) __no_context_analysis {}
Annotation
- Immediate include surface: `linux/compiler.h`, `linux/cleanup.h`, `linux/kcsan-checks.h`, `linux/lockdep.h`, `linux/mutex.h`, `linux/preempt.h`, `linux/seqlock_types.h`, `linux/spinlock.h`.
- Detected declarations: `struct ss_tmp`, `enum ss_state`, `function __seqcount_init`, `function seqcount_lockdep_reader_access`, `function SEQCNT_ZERO`, `function __seqprop`, `function __seqprop_sequence`, `function __seqprop_preemptible`, `function __seqprop_assert`, `function __read_seqcount_retry`.
- Atlas domain: Core OS / Core Kernel Interface.
- 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.