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.

Dependency Surface

Detected Declarations

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

Implementation Notes