kernel/trace/trace_stack.c
Source file repositories/reference/linux-study-clean/kernel/trace/trace_stack.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/trace/trace_stack.c- Extension
.c- Size
- 15344 bytes
- Lines
- 601
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/sched/task_stack.hlinux/stacktrace.hlinux/security.hlinux/kallsyms.hlinux/seq_file.hlinux/spinlock.hlinux/uaccess.hlinux/ftrace.hlinux/module.hlinux/sysctl.hlinux/init.hasm/setup.htrace.h
Detected Declarations
function print_max_stackfunction variablesfunction stack_trace_callfunction stack_max_size_readfunction stack_max_size_writefunction __nextfunction t_nextfunction t_stopfunction trace_lookup_stackfunction print_disabledfunction t_showfunction stack_trace_openfunction stack_trace_filter_openfunction stack_trace_sysctlfunction enable_stacktracefunction stack_trace_initfunction init_trace_stack_sysctlsmodule init stack_trace_initmodule init init_trace_stack_sysctls
Annotated Snippet
static const struct file_operations stack_max_size_fops = {
.open = tracing_open_generic,
.read = stack_max_size_read,
.write = stack_max_size_write,
.llseek = default_llseek,
};
static void *
__next(struct seq_file *m, loff_t *pos)
{
long n = *pos - 1;
if (n >= stack_trace_nr_entries)
return NULL;
m->private = (void *)n;
return &m->private;
}
static void *
t_next(struct seq_file *m, void *v, loff_t *pos)
{
(*pos)++;
return __next(m, pos);
}
static void *t_start(struct seq_file *m, loff_t *pos)
{
local_irq_disable();
__this_cpu_inc(disable_stack_tracer);
arch_spin_lock(&stack_trace_max_lock);
if (*pos == 0)
return SEQ_START_TOKEN;
return __next(m, pos);
}
static void t_stop(struct seq_file *m, void *p)
{
arch_spin_unlock(&stack_trace_max_lock);
__this_cpu_dec(disable_stack_tracer);
local_irq_enable();
}
static void trace_lookup_stack(struct seq_file *m, long i)
{
unsigned long addr = stack_dump_trace[i];
seq_printf(m, "%pS\n", (void *)addr);
}
static void print_disabled(struct seq_file *m)
{
seq_puts(m, "#\n"
"# Stack tracer disabled\n"
"#\n"
"# To enable the stack tracer, either add 'stacktrace' to the\n"
"# kernel command line\n"
"# or 'echo 1 > /proc/sys/kernel/stack_tracer_enabled'\n"
"#\n");
}
static int t_show(struct seq_file *m, void *v)
{
long i;
int size;
if (v == SEQ_START_TOKEN) {
seq_printf(m, " Depth Size Location"
" (%d entries)\n"
" ----- ---- --------\n",
stack_trace_nr_entries);
if (!stack_tracer_enabled && !stack_trace_max_size)
print_disabled(m);
return 0;
}
i = *(long *)v;
if (i >= stack_trace_nr_entries)
return 0;
if (i + 1 == stack_trace_nr_entries)
Annotation
- Immediate include surface: `linux/sched/task_stack.h`, `linux/stacktrace.h`, `linux/security.h`, `linux/kallsyms.h`, `linux/seq_file.h`, `linux/spinlock.h`, `linux/uaccess.h`, `linux/ftrace.h`.
- Detected declarations: `function print_max_stack`, `function variables`, `function stack_trace_call`, `function stack_max_size_read`, `function stack_max_size_write`, `function __next`, `function t_next`, `function t_stop`, `function trace_lookup_stack`, `function print_disabled`.
- 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.