include/linux/ptr_ring.h
Source file repositories/reference/linux-study-clean/include/linux/ptr_ring.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/ptr_ring.h- Extension
.h- Size
- 17413 bytes
- Lines
- 700
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/spinlock.hlinux/cache.hlinux/types.hlinux/compiler.hlinux/slab.hlinux/mm.hasm/errno.h
Detected Declarations
struct ptr_ringfunction cpu_relaxfunction ptr_ring_fullfunction ptr_ring_full_irqfunction ptr_ring_full_anyfunction ptr_ring_full_bhfunction cpu_relaxfunction cpu_relaxfunction ptr_ring_producefunction ptr_ring_produce_irqfunction ptr_ring_produce_anyfunction ptr_ring_produce_bhfunction cpu_relaxfunction ptr_ring_emptyfunction ptr_ring_empty_irqfunction ptr_ring_empty_anyfunction ptr_ring_empty_bhfunction __ptr_ring_zero_tailfunction __ptr_ring_discard_onefunction __ptr_ring_consume_batchedfunction ptr_ring_consume_batchedfunction ptr_ring_consume_batched_irqfunction ptr_ring_consume_batched_anyfunction ptr_ring_consume_batched_bhfunction __ptr_ring_set_sizefunction ptr_ring_init_noproffunction ptr_ring_unconsumefunction voidfunction ptr_ring_resize_noproffunction ptr_ring_resize_multiple_bh_noproffunction alloc_hooks
Annotated Snippet
struct ptr_ring {
int producer ____cacheline_aligned_in_smp;
spinlock_t producer_lock;
int consumer_head ____cacheline_aligned_in_smp; /* next valid entry */
int consumer_tail; /* next entry to invalidate */
spinlock_t consumer_lock;
/* Shared consumer/producer data */
/* Read-only by both the producer and the consumer */
int size ____cacheline_aligned_in_smp; /* max entries in queue */
int batch; /* number of entries to consume in a batch */
void **queue;
};
/* Note: callers invoking this in a loop must use a compiler barrier,
* for example cpu_relax().
*
* NB: this is unlike __ptr_ring_empty in that callers must hold producer_lock:
* see e.g. ptr_ring_full.
*/
static inline bool __ptr_ring_full(struct ptr_ring *r)
{
return data_race(r->queue[r->producer]);
}
static inline bool ptr_ring_full(struct ptr_ring *r)
{
bool ret;
spin_lock(&r->producer_lock);
ret = __ptr_ring_full(r);
spin_unlock(&r->producer_lock);
return ret;
}
static inline bool ptr_ring_full_irq(struct ptr_ring *r)
{
bool ret;
spin_lock_irq(&r->producer_lock);
ret = __ptr_ring_full(r);
spin_unlock_irq(&r->producer_lock);
return ret;
}
static inline bool ptr_ring_full_any(struct ptr_ring *r)
{
unsigned long flags;
bool ret;
spin_lock_irqsave(&r->producer_lock, flags);
ret = __ptr_ring_full(r);
spin_unlock_irqrestore(&r->producer_lock, flags);
return ret;
}
static inline bool ptr_ring_full_bh(struct ptr_ring *r)
{
bool ret;
spin_lock_bh(&r->producer_lock);
ret = __ptr_ring_full(r);
spin_unlock_bh(&r->producer_lock);
return ret;
}
/* Note: callers invoking this in a loop must use a compiler barrier,
* for example cpu_relax(). Callers must hold producer_lock.
*/
static inline int __ptr_ring_check_produce(struct ptr_ring *r)
{
if (unlikely(!r->size))
return -EINVAL;
if (data_race(r->queue[r->producer]))
return -ENOSPC;
return 0;
}
/* Note: callers invoking this in a loop must use a compiler barrier,
* for example cpu_relax(). Callers must hold producer_lock.
* Callers are responsible for making sure pointer that is being queued
* points to a valid data.
*/
static inline int __ptr_ring_produce(struct ptr_ring *r, void *ptr)
{
Annotation
- Immediate include surface: `linux/spinlock.h`, `linux/cache.h`, `linux/types.h`, `linux/compiler.h`, `linux/slab.h`, `linux/mm.h`, `asm/errno.h`.
- Detected declarations: `struct ptr_ring`, `function cpu_relax`, `function ptr_ring_full`, `function ptr_ring_full_irq`, `function ptr_ring_full_any`, `function ptr_ring_full_bh`, `function cpu_relax`, `function cpu_relax`, `function ptr_ring_produce`, `function ptr_ring_produce_irq`.
- 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.