kernel/trace/ftrace.c
Source file repositories/reference/linux-study-clean/kernel/trace/ftrace.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/trace/ftrace.c- Extension
.c- Size
- 235049 bytes
- Lines
- 9450
- 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/stop_machine.hlinux/clocksource.hlinux/sched/task.hlinux/kallsyms.hlinux/security.hlinux/seq_file.hlinux/tracefs.hlinux/hardirq.hlinux/kthread.hlinux/uaccess.hlinux/bsearch.hlinux/module.hlinux/ftrace.hlinux/sysctl.hlinux/slab.hlinux/ctype.hlinux/sort.hlinux/list.hlinux/hash.hlinux/rcupdate.hlinux/kprobes.htrace/events/sched.hasm/sections.hasm/setup.hftrace_internal.htrace_output.htrace_stat.h
Detected Declarations
struct ftrace_profilestruct ftrace_profile_pagestruct ftrace_profile_statstruct profile_fgraph_datastruct ftrace_func_probestruct ftrace_pagestruct ftrace_rec_iterstruct ftrace_iteratorstruct ftrace_globstruct ftrace_func_mapstruct ftrace_func_mapperstruct ftrace_graph_datastruct ftrace_mod_funcstruct ftrace_mod_mapstruct ftrace_init_funcstruct kallsyms_dataenum graph_filter_typefunction ftrace_pids_enabledfunction ftrace_ops_nop_funcfunction ftrace_ops_initfunction ftrace_pid_funcfunction ftrace_sync_ipifunction ftrace_ops_get_list_funcfunction update_ftrace_functionfunction lockdep_is_heldfunction add_ftrace_opsfunction remove_ftrace_opsfunction lockdep_is_heldfunction __register_ftrace_functionfunction __unregister_ftrace_functionfunction ftrace_update_pid_funcfunction do_for_each_ftrace_opfunction function_stat_nextfunction function_stat_cmpfunction function_stat_cmpfunction function_stat_headersfunction function_stat_showfunction ftrace_profile_resetfunction ftrace_profile_pages_initfunction ftrace_profile_init_cpufunction ftrace_profile_initfunction for_each_possible_cpufunction ftrace_find_profiled_funcfunction hlist_for_each_entry_rcu_notracefunction ftrace_add_profilefunction ftrace_profile_allocfunction function_profile_callfunction ftrace_graph_graph_time_control
Annotated Snippet
static const struct file_operations ftrace_profile_fops = {
.open = tracing_open_generic,
.read = ftrace_profile_read,
.write = ftrace_profile_write,
.llseek = default_llseek,
};
/* used to initialize the real stat files */
static struct tracer_stat function_stats __initdata = {
.name = "functions",
.stat_start = function_stat_start,
.stat_next = function_stat_next,
.stat_cmp = function_stat_cmp,
.stat_headers = function_stat_headers,
.stat_show = function_stat_show
};
static __init void ftrace_profile_tracefs(struct dentry *d_tracer)
{
struct ftrace_profile_stat *stat;
char *name;
int ret;
int cpu;
for_each_possible_cpu(cpu) {
stat = &per_cpu(ftrace_profile_stats, cpu);
name = kasprintf(GFP_KERNEL, "function%d", cpu);
if (!name) {
/*
* The files created are permanent, if something happens
* we still do not free memory.
*/
WARN(1,
"Could not allocate stat file for cpu %d\n",
cpu);
return;
}
stat->stat = function_stats;
stat->stat.name = name;
ret = register_stat_tracer(&stat->stat);
if (ret) {
WARN(1,
"Could not register function stat for cpu %d\n",
cpu);
kfree(name);
return;
}
}
trace_create_file("function_profile_enabled",
TRACE_MODE_WRITE, d_tracer, NULL,
&ftrace_profile_fops);
}
#else /* CONFIG_FUNCTION_PROFILER */
static __init void ftrace_profile_tracefs(struct dentry *d_tracer)
{
}
#endif /* CONFIG_FUNCTION_PROFILER */
#ifdef CONFIG_DYNAMIC_FTRACE
static struct ftrace_ops *removed_ops;
/*
* Set when doing a global update, like enabling all recs or disabling them.
* It is not set when just updating a single ftrace_ops.
*/
static bool update_all_ops;
struct ftrace_func_probe {
struct ftrace_probe_ops *probe_ops;
struct ftrace_ops ops;
struct trace_array *tr;
struct list_head list;
void *data;
int ref;
};
/*
* We make these constant because no one should touch them,
* but they are used as the default "empty hash", to avoid allocating
* it all the time. These are in a read only section such that if
* anyone does try to modify it, it will cause an exception.
*/
static const struct hlist_head empty_buckets[1];
static const struct ftrace_hash empty_hash = {
.buckets = (struct hlist_head *)empty_buckets,
};
Annotation
- Immediate include surface: `linux/stop_machine.h`, `linux/clocksource.h`, `linux/sched/task.h`, `linux/kallsyms.h`, `linux/security.h`, `linux/seq_file.h`, `linux/tracefs.h`, `linux/hardirq.h`.
- Detected declarations: `struct ftrace_profile`, `struct ftrace_profile_page`, `struct ftrace_profile_stat`, `struct profile_fgraph_data`, `struct ftrace_func_probe`, `struct ftrace_page`, `struct ftrace_rec_iter`, `struct ftrace_iterator`, `struct ftrace_glob`, `struct ftrace_func_map`.
- 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.