kernel/printk/printk_ringbuffer.c
Source file repositories/reference/linux-study-clean/kernel/printk/printk_ringbuffer.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/printk/printk_ringbuffer.c- Extension
.c- Size
- 79067 bytes
- Lines
- 2419
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- 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
kunit/visibility.hlinux/kernel.hlinux/irqflags.hlinux/string.hlinux/errno.hlinux/bug.hprintk_ringbuffer.hinternal.h
Detected Declarations
struct prb_data_blockfunction prb_for_each_recordfunction to_blk_sizefunction data_check_sizefunction CPUfunction get_desc_statefunction statefunction desc_make_reusablefunction data_make_reusablefunction data_push_tailfunction desc_push_tailfunction desc_reservefunction get_desc_statefunction DESC_SVfunction is_blk_wrappedfunction get_next_lposfunction data_check_sizefunction need_more_spacefunction data_check_sizefunction space_usedfunction functionfunction WARN_ON_ONCEfunction DESC_SVfunction prb_reserve_in_lastfunction datafunction printkfunction desc_update_last_finalizedfunction CPUfunction desc_make_finalfunction prb_reservefunction _prb_commitfunction cmpxchgfunction prb_commitfunction prb_final_commitfunction count_linesfunction functionfunction desc_readfunction desc_read_finalized_seqfunction prb_first_seqfunction prb_next_reserve_seqfunction _prb_read_validfunction prb_read_validfunction prb_read_valid_infofunction prb_first_valid_seqfunction prb_next_seqfunction prb_initfunction prb_record_text_space
Annotated Snippet
struct prb_data_block {
unsigned long id;
char data[];
};
/*
* Return the descriptor associated with @n. @n can be either a
* descriptor ID or a sequence number.
*/
static struct prb_desc *to_desc(struct prb_desc_ring *desc_ring, u64 n)
{
return &desc_ring->descs[DESC_INDEX(desc_ring, n)];
}
/*
* Return the printk_info associated with @n. @n can be either a
* descriptor ID or a sequence number.
*/
static struct printk_info *to_info(struct prb_desc_ring *desc_ring, u64 n)
{
return &desc_ring->infos[DESC_INDEX(desc_ring, n)];
}
static struct prb_data_block *to_block(struct prb_data_ring *data_ring,
unsigned long begin_lpos)
{
return (void *)&data_ring->data[DATA_INDEX(data_ring, begin_lpos)];
}
/*
* Increase the data size to account for data block meta data plus any
* padding so that the adjacent data block is aligned on the ID size.
*/
static unsigned int to_blk_size(unsigned int size)
{
struct prb_data_block *db = NULL;
size += sizeof(*db);
size = ALIGN(size, sizeof(db->id));
return size;
}
/*
* Sanity checker for reserve size. The ringbuffer code assumes that a data
* block does not exceed the maximum possible size that could fit within the
* ringbuffer. This function provides that basic size check so that the
* assumption is safe. In particular, it guarantees that data_push_tail() will
* never attempt to push the tail beyond the head.
*/
static bool data_check_size(struct prb_data_ring *data_ring, unsigned int size)
{
/* Data-less blocks take no space. */
if (size == 0)
return true;
/*
* If data blocks were allowed to be larger than half the data ring
* size, a wrapping data block could require more space than the full
* ringbuffer.
*/
return to_blk_size(size) <= DATA_SIZE(data_ring) / 2;
}
/*
* Compare the current and requested logical position and decide
* whether more space is needed.
*
* Return false when @lpos_current is already at or beyond @lpos_target.
*
* Also return false when the difference between the positions is bigger
* than the size of the data buffer. It might happen only when the caller
* raced with another CPU(s) which already made and used the space.
*/
static bool need_more_space(struct prb_data_ring *data_ring,
unsigned long lpos_current,
unsigned long lpos_target)
{
return lpos_target - lpos_current - 1 < DATA_SIZE(data_ring);
}
/* Query the state of a descriptor. */
static enum desc_state get_desc_state(unsigned long id,
unsigned long state_val)
{
if (id != DESC_ID(state_val))
return desc_miss;
return DESC_STATE(state_val);
}
Annotation
- Immediate include surface: `kunit/visibility.h`, `linux/kernel.h`, `linux/irqflags.h`, `linux/string.h`, `linux/errno.h`, `linux/bug.h`, `printk_ringbuffer.h`, `internal.h`.
- Detected declarations: `struct prb_data_block`, `function prb_for_each_record`, `function to_blk_size`, `function data_check_size`, `function CPU`, `function get_desc_state`, `function state`, `function desc_make_reusable`, `function data_make_reusable`, `function data_push_tail`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- 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.