include/linux/percpu-rwsem.h
Source file repositories/reference/linux-study-clean/include/linux/percpu-rwsem.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/percpu-rwsem.h- Extension
.h- Size
- 4855 bytes
- Lines
- 172
- 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/atomic.hlinux/percpu.hlinux/rcuwait.hlinux/wait.hlinux/rcu_sync.hlinux/lockdep.hlinux/cleanup.h
Detected Declarations
struct percpu_rw_semaphorefunction percpu_down_read_internalfunction percpu_down_readfunction percpu_down_read_freezablefunction percpu_down_read_trylockfunction percpu_up_readfunction percpu_down_readfunction percpu_down_readfunction percpu_rwsem_releasefunction percpu_rwsem_acquire
Annotated Snippet
struct percpu_rw_semaphore {
struct rcu_sync rss;
unsigned int __percpu *read_count;
struct rcuwait writer;
wait_queue_head_t waiters;
atomic_t block;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lockdep_map dep_map;
#endif
};
#ifdef CONFIG_DEBUG_LOCK_ALLOC
#define __PERCPU_RWSEM_DEP_MAP_INIT(lockname) .dep_map = { .name = #lockname },
#else
#define __PERCPU_RWSEM_DEP_MAP_INIT(lockname)
#endif
#define __DEFINE_PERCPU_RWSEM(name, is_static) \
static DEFINE_PER_CPU(unsigned int, __percpu_rwsem_rc_##name); \
is_static struct percpu_rw_semaphore name = { \
.rss = __RCU_SYNC_INITIALIZER(name.rss), \
.read_count = &__percpu_rwsem_rc_##name, \
.writer = __RCUWAIT_INITIALIZER(name.writer), \
.waiters = __WAIT_QUEUE_HEAD_INITIALIZER(name.waiters), \
.block = ATOMIC_INIT(0), \
__PERCPU_RWSEM_DEP_MAP_INIT(name) \
}
#define DEFINE_PERCPU_RWSEM(name) \
__DEFINE_PERCPU_RWSEM(name, /* not static */)
#define DEFINE_STATIC_PERCPU_RWSEM(name) \
__DEFINE_PERCPU_RWSEM(name, static)
extern bool __percpu_down_read(struct percpu_rw_semaphore *, bool, bool);
static inline void percpu_down_read_internal(struct percpu_rw_semaphore *sem,
bool freezable)
{
might_sleep();
rwsem_acquire_read(&sem->dep_map, 0, 0, _RET_IP_);
preempt_disable();
/*
* We are in an RCU-sched read-side critical section, so the writer
* cannot both change sem->state from readers_fast and start checking
* counters while we are here. So if we see !sem->state, we know that
* the writer won't be checking until we're past the preempt_enable()
* and that once the synchronize_rcu() is done, the writer will see
* anything we did within this RCU-sched read-size critical section.
*/
if (likely(rcu_sync_is_idle(&sem->rss)))
this_cpu_inc(*sem->read_count);
else
__percpu_down_read(sem, false, freezable); /* Unconditional memory barrier */
/*
* The preempt_enable() prevents the compiler from
* bleeding the critical section out.
*/
preempt_enable();
}
static inline void percpu_down_read(struct percpu_rw_semaphore *sem)
{
percpu_down_read_internal(sem, false);
}
static inline void percpu_down_read_freezable(struct percpu_rw_semaphore *sem,
bool freeze)
{
percpu_down_read_internal(sem, freeze);
}
static inline bool percpu_down_read_trylock(struct percpu_rw_semaphore *sem)
{
bool ret = true;
preempt_disable();
/*
* Same as in percpu_down_read().
*/
if (likely(rcu_sync_is_idle(&sem->rss)))
this_cpu_inc(*sem->read_count);
else
ret = __percpu_down_read(sem, true, false); /* Unconditional memory barrier */
preempt_enable();
/*
* The barrier() from preempt_enable() prevents the compiler from
* bleeding the critical section out.
*/
Annotation
- Immediate include surface: `linux/atomic.h`, `linux/percpu.h`, `linux/rcuwait.h`, `linux/wait.h`, `linux/rcu_sync.h`, `linux/lockdep.h`, `linux/cleanup.h`.
- Detected declarations: `struct percpu_rw_semaphore`, `function percpu_down_read_internal`, `function percpu_down_read`, `function percpu_down_read_freezable`, `function percpu_down_read_trylock`, `function percpu_up_read`, `function percpu_down_read`, `function percpu_down_read`, `function percpu_rwsem_release`, `function percpu_rwsem_acquire`.
- 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.