kernel/trace/ring_buffer.c
Source file repositories/reference/linux-study-clean/kernel/trace/ring_buffer.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/trace/ring_buffer.c- Extension
.c- Size
- 228411 bytes
- Lines
- 8314
- 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.
- 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/ring_buffer_types.hlinux/sched/isolation.hlinux/trace_recursion.hlinux/panic_notifier.hlinux/trace_events.hlinux/ring_buffer.hlinux/trace_clock.hlinux/sched/clock.hlinux/cacheflush.hlinux/trace_seq.hlinux/spinlock.hlinux/irq_work.hlinux/security.hlinux/uaccess.hlinux/hardirq.hlinux/kthread.hlinux/module.hlinux/percpu.hlinux/mutex.hlinux/delay.hlinux/slab.hlinux/init.hlinux/hash.hlinux/list.hlinux/cpu.hlinux/oom.hlinux/mm.hasm/ring_buffer.hasm/local64.hasm/local.hasm/setup.htrace.h
Detected Declarations
struct ring_buffer_metastruct ring_buffer_cpu_metastruct buffer_data_read_pagestruct buffer_pagestruct rb_irq_workstruct rb_event_infostruct rb_time_structstruct ring_buffer_per_cpustruct trace_bufferstruct ring_buffer_iterstruct rb_wait_datastruct rb_validation_statestruct rb_test_datastruct rb_itemfunction ring_buffer_print_entry_headerfunction rb_null_eventfunction rb_event_set_paddingfunction rb_event_data_lengthfunction rb_event_lengthfunction rb_event_ts_lengthfunction ring_buffer_event_lengthfunction rb_event_datafunction rb_event_time_stampfunction rb_init_data_pagefunction rb_data_page_commitfunction rb_data_page_sizefunction rb_page_commitfunction rb_page_sizefunction free_buffer_pagefunction ring_buffer_print_page_headerfunction rb_time_readfunction rb_time_setfunction verify_eventfunction verify_eventfunction reservedfunction ring_buffer_nr_dirty_pagesfunction full_hitfunction rb_wake_up_waitersfunction ring_buffer_wake_waitersfunction rb_watermark_hitfunction rb_wait_condfunction ring_buffer_waitfunction ring_buffer_waitfunction ring_buffer_poll_waitfunction rb_time_stampfunction ring_buffer_time_stampfunction ring_buffer_normalize_time_stampfunction head
Annotated Snippet
struct ring_buffer_meta {
int magic;
int struct_sizes;
unsigned long total_size;
unsigned long buffers_offset;
};
struct ring_buffer_cpu_meta {
unsigned long first_buffer;
unsigned long head_buffer;
unsigned long commit_buffer;
__u32 subbuf_size;
__u32 nr_subbufs;
#ifdef CONFIG_RING_BUFFER_PERSISTENT_INJECT
__u32 nr_invalid;
__u32 entry_bytes;
#endif
int buffers[];
};
/*
* The ring buffer header is special. We must manually up keep it.
*/
int ring_buffer_print_entry_header(struct trace_seq *s)
{
trace_seq_puts(s, "# compressed entry header\n");
trace_seq_puts(s, "\ttype_len : 5 bits\n");
trace_seq_puts(s, "\ttime_delta : 27 bits\n");
trace_seq_puts(s, "\tarray : 32 bits\n");
trace_seq_putc(s, '\n');
trace_seq_printf(s, "\tpadding : type == %d\n",
RINGBUF_TYPE_PADDING);
trace_seq_printf(s, "\ttime_extend : type == %d\n",
RINGBUF_TYPE_TIME_EXTEND);
trace_seq_printf(s, "\ttime_stamp : type == %d\n",
RINGBUF_TYPE_TIME_STAMP);
trace_seq_printf(s, "\tdata max type_len == %d\n",
RINGBUF_TYPE_DATA_TYPE_LEN_MAX);
return !trace_seq_has_overflowed(s);
}
/*
* The ring buffer is made up of a list of pages. A separate list of pages is
* allocated for each CPU. A writer may only write to a buffer that is
* associated with the CPU it is currently executing on. A reader may read
* from any per cpu buffer.
*
* The reader is special. For each per cpu buffer, the reader has its own
* reader page. When a reader has read the entire reader page, this reader
* page is swapped with another page in the ring buffer.
*
* Now, as long as the writer is off the reader page, the reader can do what
* ever it wants with that page. The writer will never write to that page
* again (as long as it is out of the ring buffer).
*
* Here's some silly ASCII art.
*
* +------+
* |reader| RING BUFFER
* |page |
* +------+ +---+ +---+ +---+
* | |-->| |-->| |
* +---+ +---+ +---+
* ^ |
* | |
* +---------------+
*
*
* +------+
* |reader| RING BUFFER
* |page |------------------v
* +------+ +---+ +---+ +---+
* | |-->| |-->| |
* +---+ +---+ +---+
* ^ |
* | |
* +---------------+
*
*
* +------+
* |reader| RING BUFFER
* |page |------------------v
* +------+ +---+ +---+ +---+
* ^ | |-->| |-->| |
* | +---+ +---+ +---+
* | |
* | |
* +------------------------------+
*
Annotation
- Immediate include surface: `linux/ring_buffer_types.h`, `linux/sched/isolation.h`, `linux/trace_recursion.h`, `linux/panic_notifier.h`, `linux/trace_events.h`, `linux/ring_buffer.h`, `linux/trace_clock.h`, `linux/sched/clock.h`.
- Detected declarations: `struct ring_buffer_meta`, `struct ring_buffer_cpu_meta`, `struct buffer_data_read_page`, `struct buffer_page`, `struct rb_irq_work`, `struct rb_event_info`, `struct rb_time_struct`, `struct ring_buffer_per_cpu`, `struct trace_buffer`, `struct ring_buffer_iter`.
- 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.