kernel/trace/trace_snapshot.c
Source file repositories/reference/linux-study-clean/kernel/trace/trace_snapshot.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/trace/trace_snapshot.c- Extension
.c- Size
- 26878 bytes
- Lines
- 1067
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/fsnotify.hasm/setup.htrace.h
Detected Declarations
function boot_alloc_snapshotfunction boot_snapshotfunction tracing_snapshot_instance_condfunction tracing_snapshot_instancefunction tracing_snapshotfunction tracing_snapshot_cond_enablefunction resize_buffer_duplicate_sizefunction tracing_alloc_snapshot_instancefunction free_snapshotfunction tracing_arm_snapshot_lockedfunction tracing_arm_snapshotfunction tracing_disarm_snapshotfunction tracing_snapshotfunction tracing_snapshot_cond_enablefunction tracing_snapshot_cond_disablefunction latency_fsnotify_workfnfunction latency_fsnotify_workfn_irqfunction latency_fsnotify_initfunction latency_fsnotifyfunction trace_create_maxlat_filefunction __update_max_trfunction __update_max_trfunction update_max_tr_singlefunction show_snapshot_main_helpfunction show_snapshot_percpu_helpfunction print_snapshot_helpfunction tracing_snapshot_openfunction tracing_swap_cpu_bufferfunction tracing_snapshot_writefunction tracing_snapshot_releasefunction snapshot_raw_openfunction tracing_max_lat_readfunction tracing_max_lat_writefunction get_snapshot_mapfunction put_snapshot_mapfunction ftrace_snapshotfunction ftrace_count_snapshotfunction ftrace_snapshot_printfunction ftrace_snapshot_initfunction ftrace_snapshot_freefunction ftrace_trace_snapshot_callbackfunction register_snapshot_cmdfunction trace_allocate_snapshotfunction tr_needs_alloc_snapshotfunction do_allocate_snapshotfunction ftrace_boot_snapshotfunction list_for_each_entryexport tracing_snapshot_cond
Annotated Snippet
static const struct file_operations tracing_max_lat_fops;
void trace_create_maxlat_file(struct trace_array *tr,
struct dentry *d_tracer)
{
#ifdef LATENCY_FS_NOTIFY
INIT_WORK(&tr->fsnotify_work, latency_fsnotify_workfn);
init_irq_work(&tr->fsnotify_irqwork, latency_fsnotify_workfn_irq);
#endif
tr->d_max_latency = trace_create_file("tracing_max_latency",
TRACE_MODE_WRITE,
d_tracer, tr,
&tracing_max_lat_fops);
}
/*
* Copy the new maximum trace into the separate maximum-trace
* structure. (this way the maximum trace is permanently saved,
* for later retrieval via /sys/kernel/tracing/tracing_max_latency)
*/
static void
__update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
{
struct array_buffer *trace_buf = &tr->array_buffer;
struct trace_array_cpu *data = per_cpu_ptr(trace_buf->data, cpu);
struct array_buffer *max_buf = &tr->snapshot_buffer;
struct trace_array_cpu *max_data = per_cpu_ptr(max_buf->data, cpu);
max_buf->cpu = cpu;
max_buf->time_start = data->preempt_timestamp;
max_data->saved_latency = tr->max_latency;
max_data->critical_start = data->critical_start;
max_data->critical_end = data->critical_end;
strscpy(max_data->comm, tsk->comm);
max_data->pid = tsk->pid;
/*
* If tsk == current, then use current_uid(), as that does not use
* RCU. The irq tracer can be called out of RCU scope.
*/
if (tsk == current)
max_data->uid = current_uid();
else
max_data->uid = task_uid(tsk);
max_data->nice = tsk->static_prio - 20 - MAX_RT_PRIO;
max_data->policy = tsk->policy;
max_data->rt_priority = tsk->rt_priority;
/* record this tasks comm */
tracing_record_cmdline(tsk);
latency_fsnotify(tr);
}
#else
static inline void __update_max_tr(struct trace_array *tr,
struct task_struct *tsk, int cpu) { }
#endif /* CONFIG_TRACER_MAX_TRACE */
/**
* update_max_tr - snapshot all trace buffers from global_trace to max_tr
* @tr: tracer
* @tsk: the task with the latency
* @cpu: The cpu that initiated the trace.
* @cond_data: User data associated with a conditional snapshot
*
* Flip the buffers between the @tr and the max_tr and record information
* about which task was the cause of this latency.
*/
void
update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu,
void *cond_data)
{
if (tr->stop_count)
return;
WARN_ON_ONCE(!irqs_disabled());
if (!tr->allocated_snapshot) {
/* Only the nop tracer should hit this when disabling */
WARN_ON_ONCE(tr->current_trace != &nop_trace);
return;
}
arch_spin_lock(&tr->max_lock);
/* Inherit the recordable setting from array_buffer */
if (ring_buffer_record_is_set_on(tr->array_buffer.buffer))
ring_buffer_record_on(tr->snapshot_buffer.buffer);
else
Annotation
- Immediate include surface: `linux/fsnotify.h`, `asm/setup.h`, `trace.h`.
- Detected declarations: `function boot_alloc_snapshot`, `function boot_snapshot`, `function tracing_snapshot_instance_cond`, `function tracing_snapshot_instance`, `function tracing_snapshot`, `function tracing_snapshot_cond_enable`, `function resize_buffer_duplicate_size`, `function tracing_alloc_snapshot_instance`, `function free_snapshot`, `function tracing_arm_snapshot_locked`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: pattern 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.