kernel/trace/trace.c
Source file repositories/reference/linux-study-clean/kernel/trace/trace.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/trace/trace.c- Extension
.c- Size
- 252494 bytes
- Lines
- 10019
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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.hlinux/utsname.hlinux/stacktrace.hlinux/writeback.hlinux/kallsyms.hlinux/security.hlinux/seq_file.hlinux/irqflags.hlinux/syscalls.hlinux/debugfs.hlinux/tracefs.hlinux/pagemap.hlinux/hardirq.hlinux/linkage.hlinux/uaccess.hlinux/cleanup.hlinux/vmalloc.hlinux/ftrace.hlinux/module.hlinux/percpu.hlinux/splice.hlinux/kdebug.hlinux/string.hlinux/mount.hlinux/rwsem.hlinux/slab.hlinux/ctype.hlinux/init.hlinux/panic_notifier.hlinux/poll.hlinux/nmi.hlinux/fs.h
Detected Declarations
struct tracersstruct trace_eval_map_headstruct trace_eval_map_tailstruct pipe_waitstruct trace_selftestsstruct ftrace_stackstruct ftrace_stacksstruct trace_mod_entrystruct trace_scratchstruct trace_user_bufstruct err_infostruct tracing_log_errstruct buffer_reffunction disable_tracing_selftestfunction init_trace_sysctlsfunction trace_append_boot_paramfunction set_cmdline_ftracefunction ftrace_dump_on_oops_enabledfunction set_ftrace_dump_on_oopsfunction stop_trace_on_warningfunction boot_instancefunction set_trace_boot_optionsfunction set_trace_boot_clockfunction set_tracepoint_printkfunction set_tracepoint_printk_stopfunction set_traceoff_after_bootfunction ns2usecsfunction trace_process_exportfunction ftrace_exports_enablefunction ftrace_exports_disablefunction ftrace_exportsfunction add_trace_exportfunction rm_trace_exportfunction add_ftrace_exportfunction rm_ftrace_exportfunction register_ftrace_exportfunction unregister_ftrace_exportfunction update_printk_tracefunction update_marker_tracefunction trace_set_ring_buffer_expandedfunction trace_array_autoremovefunction trace_array_kick_autoremovefunction trace_array_cancel_autoremovefunction trace_array_init_autoremovefunction trace_array_start_autoremovefunction __trace_array_getfunction trace_array_getfunction __trace_array_put
Annotated Snippet
static const struct file_operations tracing_fops = {
.open = tracing_open,
.read = seq_read,
.read_iter = seq_read_iter,
.splice_read = copy_splice_read,
.write = tracing_write_stub,
.llseek = tracing_lseek,
.release = tracing_release,
};
static const struct file_operations show_traces_fops = {
.open = show_traces_open,
.read = seq_read,
.llseek = seq_lseek,
.release = tracing_seq_release,
};
static ssize_t
tracing_cpumask_read(struct file *filp, char __user *ubuf,
size_t count, loff_t *ppos)
{
struct trace_array *tr = file_inode(filp)->i_private;
char *mask_str __free(kfree) = NULL;
int len;
len = snprintf(NULL, 0, "%*pb\n",
cpumask_pr_args(tr->tracing_cpumask)) + 1;
mask_str = kmalloc(len, GFP_KERNEL);
if (!mask_str)
return -ENOMEM;
len = snprintf(mask_str, len, "%*pb\n",
cpumask_pr_args(tr->tracing_cpumask));
if (len >= count)
return -EINVAL;
return simple_read_from_buffer(ubuf, count, ppos, mask_str, len);
}
int tracing_set_cpumask(struct trace_array *tr,
cpumask_var_t tracing_cpumask_new)
{
int cpu;
if (!tr)
return -EINVAL;
local_irq_disable();
arch_spin_lock(&tr->max_lock);
for_each_tracing_cpu(cpu) {
/*
* Increase/decrease the disabled counter if we are
* about to flip a bit in the cpumask:
*/
if (cpumask_test_cpu(cpu, tr->tracing_cpumask) &&
!cpumask_test_cpu(cpu, tracing_cpumask_new)) {
ring_buffer_record_disable_cpu(tr->array_buffer.buffer, cpu);
#ifdef CONFIG_TRACER_SNAPSHOT
ring_buffer_record_disable_cpu(tr->snapshot_buffer.buffer, cpu);
#endif
}
if (!cpumask_test_cpu(cpu, tr->tracing_cpumask) &&
cpumask_test_cpu(cpu, tracing_cpumask_new)) {
ring_buffer_record_enable_cpu(tr->array_buffer.buffer, cpu);
#ifdef CONFIG_TRACER_SNAPSHOT
ring_buffer_record_enable_cpu(tr->snapshot_buffer.buffer, cpu);
#endif
}
}
arch_spin_unlock(&tr->max_lock);
local_irq_enable();
cpumask_copy(tr->tracing_cpumask, tracing_cpumask_new);
return 0;
}
static ssize_t
tracing_cpumask_write(struct file *filp, const char __user *ubuf,
size_t count, loff_t *ppos)
{
struct trace_array *tr = file_inode(filp)->i_private;
cpumask_var_t tracing_cpumask_new;
int err;
if (count == 0 || count > KMALLOC_MAX_SIZE)
return -EINVAL;
if (!zalloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL))
return -ENOMEM;
Annotation
- Immediate include surface: `linux/ring_buffer.h`, `linux/utsname.h`, `linux/stacktrace.h`, `linux/writeback.h`, `linux/kallsyms.h`, `linux/security.h`, `linux/seq_file.h`, `linux/irqflags.h`.
- Detected declarations: `struct tracers`, `struct trace_eval_map_head`, `struct trace_eval_map_tail`, `struct pipe_wait`, `struct trace_selftests`, `struct ftrace_stack`, `struct ftrace_stacks`, `struct trace_mod_entry`, `struct trace_scratch`, `struct trace_user_buf`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.