kernel/trace/trace_functions.c
Source file repositories/reference/linux-study-clean/kernel/trace/trace_functions.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/trace/trace_functions.c- Extension
.c- Size
- 24508 bytes
- Lines
- 1031
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- 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/debugfs.hlinux/uaccess.hlinux/ftrace.hlinux/slab.hlinux/fs.htrace.h
Detected Declarations
function ftrace_allocate_ftrace_opsfunction ftrace_free_ftrace_opsfunction ftrace_create_function_filesfunction ftrace_destroy_function_filesfunction select_trace_functionfunction handle_func_repeatsfunction function_trace_initfunction function_trace_resetfunction function_trace_startfunction function_get_true_parent_ipfunction function_get_true_parent_ipfunction function_trace_callfunction function_args_trace_callfunction function_stack_trace_callfunction is_repeat_checkfunction process_repeatsfunction function_no_repeats_trace_callfunction function_stack_no_repeats_trace_callfunction tracing_start_function_tracefunction tracing_stop_function_tracefunction func_set_flagfunction update_traceon_countfunction ftrace_traceon_countfunction ftrace_traceoff_countfunction ftrace_traceonfunction ftrace_traceofffunction function_trace_probe_callfunction ftrace_stacktracefunction ftrace_stacktrace_countfunction update_countfunction ftrace_dump_probefunction ftrace_cpudump_probefunction ftrace_probe_printfunction ftrace_traceon_printfunction ftrace_traceoff_printfunction ftrace_stacktrace_printfunction ftrace_dump_printfunction ftrace_cpudump_printfunction ftrace_count_initfunction ftrace_count_freefunction ftrace_trace_probe_callbackfunction ftrace_trace_onoff_callbackfunction ftrace_stacktrace_callbackfunction ftrace_dump_callbackfunction ftrace_cpudump_callbackfunction init_func_cmd_traceonfunction init_func_cmd_traceonfunction init_function_trace
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* ring buffer based function tracer
*
* Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
* Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
*
* Based on code from the latency_tracer, that is:
*
* Copyright (C) 2004-2006 Ingo Molnar
* Copyright (C) 2004 Nadia Yvette Chambers
*/
#include <linux/ring_buffer.h>
#include <linux/debugfs.h>
#include <linux/uaccess.h>
#include <linux/ftrace.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include "trace.h"
static void tracing_start_function_trace(struct trace_array *tr);
static void tracing_stop_function_trace(struct trace_array *tr);
static void
function_trace_call(unsigned long ip, unsigned long parent_ip,
struct ftrace_ops *op, struct ftrace_regs *fregs);
static void
function_args_trace_call(unsigned long ip, unsigned long parent_ip,
struct ftrace_ops *op, struct ftrace_regs *fregs);
static void
function_stack_trace_call(unsigned long ip, unsigned long parent_ip,
struct ftrace_ops *op, struct ftrace_regs *fregs);
static void
function_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
struct ftrace_ops *op, struct ftrace_regs *fregs);
static void
function_stack_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
struct ftrace_ops *op,
struct ftrace_regs *fregs);
static struct tracer_flags func_flags;
/* Our option */
enum {
TRACE_FUNC_NO_OPTS = 0x0, /* No flags set. */
TRACE_FUNC_OPT_STACK = 0x1,
TRACE_FUNC_OPT_NO_REPEATS = 0x2,
TRACE_FUNC_OPT_ARGS = 0x4,
/* Update this to next highest bit. */
TRACE_FUNC_OPT_HIGHEST_BIT = 0x8
};
#define TRACE_FUNC_OPT_MASK (TRACE_FUNC_OPT_HIGHEST_BIT - 1)
int ftrace_allocate_ftrace_ops(struct trace_array *tr)
{
struct ftrace_ops *ops;
/* The top level array uses the "global_ops" */
if (tr->flags & TRACE_ARRAY_FL_GLOBAL)
return 0;
ops = kzalloc_obj(*ops);
if (!ops)
return -ENOMEM;
/* Currently only the non stack version is supported */
ops->func = function_trace_call;
ops->flags = FTRACE_OPS_FL_PID;
tr->ops = ops;
ops->private = tr;
return 0;
}
void ftrace_free_ftrace_ops(struct trace_array *tr)
{
kfree(tr->ops);
tr->ops = NULL;
}
int ftrace_create_function_files(struct trace_array *tr,
struct dentry *parent)
{
int ret;
/*
* The top level array uses the "global_ops", and the files are
* created on boot up.
Annotation
- Immediate include surface: `linux/ring_buffer.h`, `linux/debugfs.h`, `linux/uaccess.h`, `linux/ftrace.h`, `linux/slab.h`, `linux/fs.h`, `trace.h`.
- Detected declarations: `function ftrace_allocate_ftrace_ops`, `function ftrace_free_ftrace_ops`, `function ftrace_create_function_files`, `function ftrace_destroy_function_files`, `function select_trace_function`, `function handle_func_repeats`, `function function_trace_init`, `function function_trace_reset`, `function function_trace_start`, `function function_get_true_parent_ip`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source implementation candidate.
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.