2010-07-20 15:13:35 +08:00
|
|
|
/*
|
|
|
|
* Ftrace header. For implementation details beyond the random comments
|
|
|
|
* scattered below, see: Documentation/trace/ftrace-design.txt
|
|
|
|
*/
|
|
|
|
|
2008-05-13 03:20:42 +08:00
|
|
|
#ifndef _LINUX_FTRACE_H
|
|
|
|
#define _LINUX_FTRACE_H
|
|
|
|
|
2009-03-05 08:49:22 +08:00
|
|
|
#include <linux/trace_clock.h>
|
2008-10-02 19:26:05 +08:00
|
|
|
#include <linux/kallsyms.h>
|
2009-03-05 08:49:22 +08:00
|
|
|
#include <linux/linkage.h>
|
2008-12-04 04:36:57 +08:00
|
|
|
#include <linux/bitops.h>
|
2011-08-10 00:50:46 +08:00
|
|
|
#include <linux/ptrace.h>
|
2009-03-05 08:49:22 +08:00
|
|
|
#include <linux/ktime.h>
|
2008-12-05 06:51:23 +08:00
|
|
|
#include <linux/sched.h>
|
2009-03-05 08:49:22 +08:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/fs.h>
|
2008-05-13 03:20:42 +08:00
|
|
|
|
2009-02-28 04:30:03 +08:00
|
|
|
#include <asm/ftrace.h>
|
|
|
|
|
2011-08-09 04:57:47 +08:00
|
|
|
/*
|
|
|
|
* If the arch supports passing the variable contents of
|
|
|
|
* function_trace_op as the third parameter back from the
|
|
|
|
* mcount call, then the arch should define this as 1.
|
|
|
|
*/
|
|
|
|
#ifndef ARCH_SUPPORTS_FTRACE_OPS
|
|
|
|
#define ARCH_SUPPORTS_FTRACE_OPS 0
|
|
|
|
#endif
|
|
|
|
|
2012-06-05 21:44:25 +08:00
|
|
|
/*
|
|
|
|
* If the arch's mcount caller does not support all of ftrace's
|
|
|
|
* features, then it must call an indirect function that
|
|
|
|
* does. Or at least does enough to prevent any unwelcomed side effects.
|
|
|
|
*/
|
2014-06-26 01:26:59 +08:00
|
|
|
#if !ARCH_SUPPORTS_FTRACE_OPS
|
2012-06-05 21:44:25 +08:00
|
|
|
# define FTRACE_FORCE_LIST_FUNC 1
|
|
|
|
#else
|
|
|
|
# define FTRACE_FORCE_LIST_FUNC 0
|
|
|
|
#endif
|
|
|
|
|
2014-12-13 09:05:10 +08:00
|
|
|
/* Main tracing buffer and events set up */
|
|
|
|
#ifdef CONFIG_TRACING
|
|
|
|
void trace_init(void);
|
2017-03-04 02:37:33 +08:00
|
|
|
void early_trace_init(void);
|
2014-12-13 09:05:10 +08:00
|
|
|
#else
|
|
|
|
static inline void trace_init(void) { }
|
2017-03-04 02:37:33 +08:00
|
|
|
static inline void early_trace_init(void) { }
|
2014-12-13 09:05:10 +08:00
|
|
|
#endif
|
2012-06-05 21:44:25 +08:00
|
|
|
|
2011-05-27 01:46:22 +08:00
|
|
|
struct module;
|
2011-07-11 22:12:59 +08:00
|
|
|
struct ftrace_hash;
|
|
|
|
|
2008-10-07 07:06:12 +08:00
|
|
|
#ifdef CONFIG_FUNCTION_TRACER
|
2008-10-02 23:45:47 +08:00
|
|
|
|
2008-05-13 03:20:43 +08:00
|
|
|
extern int ftrace_enabled;
|
|
|
|
extern int
|
|
|
|
ftrace_enable_sysctl(struct ctl_table *table, int write,
|
2009-09-24 06:57:19 +08:00
|
|
|
void __user *buffer, size_t *lenp,
|
2008-05-13 03:20:43 +08:00
|
|
|
loff_t *ppos);
|
|
|
|
|
2011-08-09 04:57:47 +08:00
|
|
|
struct ftrace_ops;
|
|
|
|
|
|
|
|
typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip,
|
2011-08-10 00:50:46 +08:00
|
|
|
struct ftrace_ops *op, struct pt_regs *regs);
|
2008-05-13 03:20:42 +08:00
|
|
|
|
2014-07-23 08:41:42 +08:00
|
|
|
ftrace_func_t ftrace_ops_get_func(struct ftrace_ops *ops);
|
|
|
|
|
2012-02-15 22:51:48 +08:00
|
|
|
/*
|
|
|
|
* FTRACE_OPS_FL_* bits denote the state of ftrace_ops struct and are
|
|
|
|
* set in the flags member.
|
2014-11-21 18:25:16 +08:00
|
|
|
* CONTROL, SAVE_REGS, SAVE_REGS_IF_SUPPORTED, RECURSION_SAFE, STUB and
|
|
|
|
* IPMODIFY are a kind of attribute flags which can be set only before
|
|
|
|
* registering the ftrace_ops, and can not be modified while registered.
|
|
|
|
* Changing those attribute flags after regsitering ftrace_ops will
|
|
|
|
* cause unexpected results.
|
2012-02-15 22:51:48 +08:00
|
|
|
*
|
|
|
|
* ENABLED - set/unset when ftrace_ops is registered/unregistered
|
|
|
|
* DYNAMIC - set when ftrace_ops is registered to denote dynamically
|
|
|
|
* allocated ftrace_ops which need special care
|
2015-12-01 06:23:39 +08:00
|
|
|
* PER_CPU - set manualy by ftrace_ops user to denote the ftrace_ops
|
|
|
|
* could be controlled by following calls:
|
2012-02-15 22:51:48 +08:00
|
|
|
* ftrace_function_local_enable
|
|
|
|
* ftrace_function_local_disable
|
2012-05-01 04:20:23 +08:00
|
|
|
* SAVE_REGS - The ftrace_ops wants regs saved at each function called
|
|
|
|
* and passed to the callback. If this flag is set, but the
|
|
|
|
* architecture does not support passing regs
|
2012-09-28 16:15:17 +08:00
|
|
|
* (CONFIG_DYNAMIC_FTRACE_WITH_REGS is not defined), then the
|
2012-05-01 04:20:23 +08:00
|
|
|
* ftrace_ops will fail to register, unless the next flag
|
|
|
|
* is set.
|
|
|
|
* SAVE_REGS_IF_SUPPORTED - This is the same as SAVE_REGS, but if the
|
|
|
|
* handler can handle an arch that does not save regs
|
|
|
|
* (the handler tests if regs == NULL), then it can set
|
|
|
|
* this flag instead. It will not fail registering the ftrace_ops
|
|
|
|
* but, the regs field will be NULL if the arch does not support
|
|
|
|
* passing regs to the handler.
|
|
|
|
* Note, if this flag is set, the SAVE_REGS flag will automatically
|
|
|
|
* get set upon registering the ftrace_ops, if the arch supports it.
|
2012-07-20 23:04:44 +08:00
|
|
|
* RECURSION_SAFE - The ftrace_ops can set this to tell the ftrace infrastructure
|
|
|
|
* that the call back has its own recursion protection. If it does
|
|
|
|
* not set this, then the ftrace infrastructure will add recursion
|
|
|
|
* protection for the caller.
|
2013-03-27 21:31:28 +08:00
|
|
|
* STUB - The ftrace_ops is just a place holder.
|
2013-05-09 13:44:17 +08:00
|
|
|
* INITIALIZED - The ftrace_ops has already been initialized (first use time
|
|
|
|
* register_ftrace_function() is called, it will initialized the ops)
|
2014-01-11 05:17:45 +08:00
|
|
|
* DELETED - The ops are being deleted, do not let them be registered again.
|
2014-08-06 05:19:38 +08:00
|
|
|
* ADDING - The ops is in the process of being added.
|
|
|
|
* REMOVING - The ops is in the process of being removed.
|
|
|
|
* MODIFYING - The ops is in the process of changing its filter functions.
|
ftrace/x86: Add dynamic allocated trampoline for ftrace_ops
The current method of handling multiple function callbacks is to register
a list function callback that calls all the other callbacks based on
their hash tables and compare it to the function that the callback was
called on. But this is very inefficient.
For example, if you are tracing all functions in the kernel and then
add a kprobe to a function such that the kprobe uses ftrace, the
mcount trampoline will switch from calling the function trace callback
to calling the list callback that will iterate over all registered
ftrace_ops (in this case, the function tracer and the kprobes callback).
That means for every function being traced it checks the hash of the
ftrace_ops for function tracing and kprobes, even though the kprobes
is only set at a single function. The kprobes ftrace_ops is checked
for every function being traced!
Instead of calling the list function for functions that are only being
traced by a single callback, we can call a dynamically allocated
trampoline that calls the callback directly. The function graph tracer
already uses a direct call trampoline when it is being traced by itself
but it is not dynamically allocated. It's trampoline is static in the
kernel core. The infrastructure that called the function graph trampoline
can also be used to call a dynamically allocated one.
For now, only ftrace_ops that are not dynamically allocated can have
a trampoline. That is, users such as function tracer or stack tracer.
kprobes and perf allocate their ftrace_ops, and until there's a safe
way to free the trampoline, it can not be used. The dynamically allocated
ftrace_ops may, although, use the trampoline if the kernel is not
compiled with CONFIG_PREEMPT. But that will come later.
Tested-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Tested-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2014-07-03 11:23:31 +08:00
|
|
|
* ALLOC_TRAMP - A dynamic trampoline was allocated by the core code.
|
|
|
|
* The arch specific code sets this flag when it allocated a
|
|
|
|
* trampoline. This lets the arch know that it can update the
|
|
|
|
* trampoline in case the callback function changes.
|
|
|
|
* The ftrace_ops trampoline can be set by the ftrace users, and
|
|
|
|
* in such cases the arch must not modify it. Only the arch ftrace
|
|
|
|
* core code should set this flag.
|
2014-11-21 18:25:16 +08:00
|
|
|
* IPMODIFY - The ops can modify the IP register. This can only be set with
|
|
|
|
* SAVE_REGS. If another ops with this flag set is already registered
|
|
|
|
* for any of the functions that this ops will be registered for, then
|
|
|
|
* this ops will fail to register or set_filter_ip.
|
2015-07-24 22:38:12 +08:00
|
|
|
* PID - Is affected by set_ftrace_pid (allows filtering on those pids)
|
2012-02-15 22:51:48 +08:00
|
|
|
*/
|
2011-05-04 21:27:52 +08:00
|
|
|
enum {
|
2012-05-01 04:20:23 +08:00
|
|
|
FTRACE_OPS_FL_ENABLED = 1 << 0,
|
2014-01-11 06:01:58 +08:00
|
|
|
FTRACE_OPS_FL_DYNAMIC = 1 << 1,
|
2015-12-01 06:23:39 +08:00
|
|
|
FTRACE_OPS_FL_PER_CPU = 1 << 2,
|
2014-01-11 06:01:58 +08:00
|
|
|
FTRACE_OPS_FL_SAVE_REGS = 1 << 3,
|
|
|
|
FTRACE_OPS_FL_SAVE_REGS_IF_SUPPORTED = 1 << 4,
|
|
|
|
FTRACE_OPS_FL_RECURSION_SAFE = 1 << 5,
|
|
|
|
FTRACE_OPS_FL_STUB = 1 << 6,
|
|
|
|
FTRACE_OPS_FL_INITIALIZED = 1 << 7,
|
|
|
|
FTRACE_OPS_FL_DELETED = 1 << 8,
|
2014-08-06 05:19:38 +08:00
|
|
|
FTRACE_OPS_FL_ADDING = 1 << 9,
|
|
|
|
FTRACE_OPS_FL_REMOVING = 1 << 10,
|
|
|
|
FTRACE_OPS_FL_MODIFYING = 1 << 11,
|
ftrace/x86: Add dynamic allocated trampoline for ftrace_ops
The current method of handling multiple function callbacks is to register
a list function callback that calls all the other callbacks based on
their hash tables and compare it to the function that the callback was
called on. But this is very inefficient.
For example, if you are tracing all functions in the kernel and then
add a kprobe to a function such that the kprobe uses ftrace, the
mcount trampoline will switch from calling the function trace callback
to calling the list callback that will iterate over all registered
ftrace_ops (in this case, the function tracer and the kprobes callback).
That means for every function being traced it checks the hash of the
ftrace_ops for function tracing and kprobes, even though the kprobes
is only set at a single function. The kprobes ftrace_ops is checked
for every function being traced!
Instead of calling the list function for functions that are only being
traced by a single callback, we can call a dynamically allocated
trampoline that calls the callback directly. The function graph tracer
already uses a direct call trampoline when it is being traced by itself
but it is not dynamically allocated. It's trampoline is static in the
kernel core. The infrastructure that called the function graph trampoline
can also be used to call a dynamically allocated one.
For now, only ftrace_ops that are not dynamically allocated can have
a trampoline. That is, users such as function tracer or stack tracer.
kprobes and perf allocate their ftrace_ops, and until there's a safe
way to free the trampoline, it can not be used. The dynamically allocated
ftrace_ops may, although, use the trampoline if the kernel is not
compiled with CONFIG_PREEMPT. But that will come later.
Tested-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Tested-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2014-07-03 11:23:31 +08:00
|
|
|
FTRACE_OPS_FL_ALLOC_TRAMP = 1 << 12,
|
2014-11-21 18:25:16 +08:00
|
|
|
FTRACE_OPS_FL_IPMODIFY = 1 << 13,
|
2015-07-24 22:38:12 +08:00
|
|
|
FTRACE_OPS_FL_PID = 1 << 14,
|
2015-12-01 06:23:39 +08:00
|
|
|
FTRACE_OPS_FL_RCU = 1 << 15,
|
2011-05-04 21:27:52 +08:00
|
|
|
};
|
|
|
|
|
2014-08-16 05:23:02 +08:00
|
|
|
#ifdef CONFIG_DYNAMIC_FTRACE
|
|
|
|
/* The hash used to know what functions callbacks trace */
|
|
|
|
struct ftrace_ops_hash {
|
|
|
|
struct ftrace_hash *notrace_hash;
|
|
|
|
struct ftrace_hash *filter_hash;
|
|
|
|
struct mutex regex_lock;
|
|
|
|
};
|
2017-03-04 05:15:39 +08:00
|
|
|
|
2017-04-04 00:57:35 +08:00
|
|
|
void ftrace_free_init_mem(void);
|
2017-03-04 05:15:39 +08:00
|
|
|
#else
|
2017-04-04 00:57:35 +08:00
|
|
|
static inline void ftrace_free_init_mem(void) { }
|
2014-08-16 05:23:02 +08:00
|
|
|
#endif
|
|
|
|
|
2013-11-07 22:36:25 +08:00
|
|
|
/*
|
2015-12-01 06:23:39 +08:00
|
|
|
* Note, ftrace_ops can be referenced outside of RCU protection, unless
|
|
|
|
* the RCU flag is set. If ftrace_ops is allocated and not part of kernel
|
|
|
|
* core data, the unregistering of it will perform a scheduling on all CPUs
|
|
|
|
* to make sure that there are no more users. Depending on the load of the
|
|
|
|
* system that may take a bit of time.
|
2013-11-07 22:36:25 +08:00
|
|
|
*
|
|
|
|
* Any private data added must also take care not to be freed and if private
|
|
|
|
* data is added to a ftrace_ops that is in core code, the user of the
|
|
|
|
* ftrace_ops must perform a schedule_on_each_cpu() before freeing it.
|
|
|
|
*/
|
2008-05-13 03:20:42 +08:00
|
|
|
struct ftrace_ops {
|
2011-05-03 00:29:25 +08:00
|
|
|
ftrace_func_t func;
|
|
|
|
struct ftrace_ops *next;
|
2011-05-04 21:27:52 +08:00
|
|
|
unsigned long flags;
|
2013-11-07 22:36:25 +08:00
|
|
|
void *private;
|
2015-07-24 22:38:12 +08:00
|
|
|
ftrace_func_t saved_func;
|
ftrace: Optimize function graph to be called directly
Function graph tracing is a bit different than the function tracers, as
it is processed after either the ftrace_caller or ftrace_regs_caller
and we only have one place to modify the jump to ftrace_graph_caller,
the jump needs to happen after the restore of registeres.
The function graph tracer is dependent on the function tracer, where
even if the function graph tracing is going on by itself, the save and
restore of registers is still done for function tracing regardless of
if function tracing is happening, before it calls the function graph
code.
If there's no function tracing happening, it is possible to just call
the function graph tracer directly, and avoid the wasted effort to save
and restore regs for function tracing.
This requires adding new flags to the dyn_ftrace records:
FTRACE_FL_TRAMP
FTRACE_FL_TRAMP_EN
The first is set if the count for the record is one, and the ftrace_ops
associated to that record has its own trampoline. That way the mcount code
can call that trampoline directly.
In the future, trampolines can be added to arbitrary ftrace_ops, where you
can have two or more ftrace_ops registered to ftrace (like kprobes and perf)
and if they are not tracing the same functions, then instead of doing a
loop to check all registered ftrace_ops against their hashes, just call the
ftrace_ops trampoline directly, which would call the registered ftrace_ops
function directly.
Without this patch perf showed:
0.05% hackbench [kernel.kallsyms] [k] ftrace_caller
0.05% hackbench [kernel.kallsyms] [k] arch_local_irq_save
0.05% hackbench [kernel.kallsyms] [k] native_sched_clock
0.04% hackbench [kernel.kallsyms] [k] __buffer_unlock_commit
0.04% hackbench [kernel.kallsyms] [k] preempt_trace
0.04% hackbench [kernel.kallsyms] [k] prepare_ftrace_return
0.04% hackbench [kernel.kallsyms] [k] __this_cpu_preempt_check
0.04% hackbench [kernel.kallsyms] [k] ftrace_graph_caller
See that the ftrace_caller took up more time than the ftrace_graph_caller
did.
With this patch:
0.05% hackbench [kernel.kallsyms] [k] __buffer_unlock_commit
0.04% hackbench [kernel.kallsyms] [k] call_filter_check_discard
0.04% hackbench [kernel.kallsyms] [k] ftrace_graph_caller
0.04% hackbench [kernel.kallsyms] [k] sched_clock
The ftrace_caller is no where to be found and ftrace_graph_caller still
takes up the same percentage.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2014-05-07 09:56:17 +08:00
|
|
|
int __percpu *disabled;
|
2011-05-03 00:29:25 +08:00
|
|
|
#ifdef CONFIG_DYNAMIC_FTRACE
|
2014-08-16 05:23:02 +08:00
|
|
|
struct ftrace_ops_hash local_hash;
|
|
|
|
struct ftrace_ops_hash *func_hash;
|
2014-07-25 00:25:47 +08:00
|
|
|
struct ftrace_ops_hash old_hash;
|
ftrace: Optimize function graph to be called directly
Function graph tracing is a bit different than the function tracers, as
it is processed after either the ftrace_caller or ftrace_regs_caller
and we only have one place to modify the jump to ftrace_graph_caller,
the jump needs to happen after the restore of registeres.
The function graph tracer is dependent on the function tracer, where
even if the function graph tracing is going on by itself, the save and
restore of registers is still done for function tracing regardless of
if function tracing is happening, before it calls the function graph
code.
If there's no function tracing happening, it is possible to just call
the function graph tracer directly, and avoid the wasted effort to save
and restore regs for function tracing.
This requires adding new flags to the dyn_ftrace records:
FTRACE_FL_TRAMP
FTRACE_FL_TRAMP_EN
The first is set if the count for the record is one, and the ftrace_ops
associated to that record has its own trampoline. That way the mcount code
can call that trampoline directly.
In the future, trampolines can be added to arbitrary ftrace_ops, where you
can have two or more ftrace_ops registered to ftrace (like kprobes and perf)
and if they are not tracing the same functions, then instead of doing a
loop to check all registered ftrace_ops against their hashes, just call the
ftrace_ops trampoline directly, which would call the registered ftrace_ops
function directly.
Without this patch perf showed:
0.05% hackbench [kernel.kallsyms] [k] ftrace_caller
0.05% hackbench [kernel.kallsyms] [k] arch_local_irq_save
0.05% hackbench [kernel.kallsyms] [k] native_sched_clock
0.04% hackbench [kernel.kallsyms] [k] __buffer_unlock_commit
0.04% hackbench [kernel.kallsyms] [k] preempt_trace
0.04% hackbench [kernel.kallsyms] [k] prepare_ftrace_return
0.04% hackbench [kernel.kallsyms] [k] __this_cpu_preempt_check
0.04% hackbench [kernel.kallsyms] [k] ftrace_graph_caller
See that the ftrace_caller took up more time than the ftrace_graph_caller
did.
With this patch:
0.05% hackbench [kernel.kallsyms] [k] __buffer_unlock_commit
0.04% hackbench [kernel.kallsyms] [k] call_filter_check_discard
0.04% hackbench [kernel.kallsyms] [k] ftrace_graph_caller
0.04% hackbench [kernel.kallsyms] [k] sched_clock
The ftrace_caller is no where to be found and ftrace_graph_caller still
takes up the same percentage.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2014-05-07 09:56:17 +08:00
|
|
|
unsigned long trampoline;
|
2014-11-19 10:14:11 +08:00
|
|
|
unsigned long trampoline_size;
|
2011-05-03 00:29:25 +08:00
|
|
|
#endif
|
2008-05-13 03:20:42 +08:00
|
|
|
};
|
|
|
|
|
2008-11-16 13:02:06 +08:00
|
|
|
/*
|
|
|
|
* Type of the current tracing.
|
|
|
|
*/
|
|
|
|
enum ftrace_tracing_type_t {
|
|
|
|
FTRACE_TYPE_ENTER = 0, /* Hook the call of the function */
|
|
|
|
FTRACE_TYPE_RETURN, /* Hook the return of the function */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Current tracing type, default is FTRACE_TYPE_ENTER */
|
|
|
|
extern enum ftrace_tracing_type_t ftrace_tracing_type;
|
|
|
|
|
2008-05-13 03:20:42 +08:00
|
|
|
/*
|
|
|
|
* The ftrace_ops must be a static and should also
|
|
|
|
* be read_mostly. These functions do modify read_mostly variables
|
|
|
|
* so use them sparely. Never free an ftrace_op or modify the
|
|
|
|
* next pointer after it has been registered. Even after unregistering
|
|
|
|
* it, the next pointer may still be used internally.
|
|
|
|
*/
|
|
|
|
int register_ftrace_function(struct ftrace_ops *ops);
|
|
|
|
int unregister_ftrace_function(struct ftrace_ops *ops);
|
|
|
|
void clear_ftrace_function(void);
|
|
|
|
|
2012-02-15 22:51:48 +08:00
|
|
|
/**
|
2015-12-01 06:23:39 +08:00
|
|
|
* ftrace_function_local_enable - enable ftrace_ops on current cpu
|
2012-02-15 22:51:48 +08:00
|
|
|
*
|
|
|
|
* This function enables tracing on current cpu by decreasing
|
|
|
|
* the per cpu control variable.
|
|
|
|
* It must be called with preemption disabled and only on ftrace_ops
|
2015-12-01 06:23:39 +08:00
|
|
|
* registered with FTRACE_OPS_FL_PER_CPU. If called without preemption
|
2012-02-15 22:51:48 +08:00
|
|
|
* disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
|
|
|
|
*/
|
|
|
|
static inline void ftrace_function_local_enable(struct ftrace_ops *ops)
|
|
|
|
{
|
2015-12-01 06:23:39 +08:00
|
|
|
if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_PER_CPU)))
|
2012-02-15 22:51:48 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
(*this_cpu_ptr(ops->disabled))--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-12-01 06:23:39 +08:00
|
|
|
* ftrace_function_local_disable - disable ftrace_ops on current cpu
|
2012-02-15 22:51:48 +08:00
|
|
|
*
|
2015-12-01 06:23:39 +08:00
|
|
|
* This function disables tracing on current cpu by increasing
|
2012-02-15 22:51:48 +08:00
|
|
|
* the per cpu control variable.
|
|
|
|
* It must be called with preemption disabled and only on ftrace_ops
|
2015-12-01 06:23:39 +08:00
|
|
|
* registered with FTRACE_OPS_FL_PER_CPU. If called without preemption
|
2012-02-15 22:51:48 +08:00
|
|
|
* disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
|
|
|
|
*/
|
|
|
|
static inline void ftrace_function_local_disable(struct ftrace_ops *ops)
|
|
|
|
{
|
2015-12-01 06:23:39 +08:00
|
|
|
if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_PER_CPU)))
|
2012-02-15 22:51:48 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
(*this_cpu_ptr(ops->disabled))++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ftrace_function_local_disabled - returns ftrace_ops disabled value
|
|
|
|
* on current cpu
|
|
|
|
*
|
|
|
|
* This function returns value of ftrace_ops::disabled on current cpu.
|
|
|
|
* It must be called with preemption disabled and only on ftrace_ops
|
2015-12-01 06:23:39 +08:00
|
|
|
* registered with FTRACE_OPS_FL_PER_CPU. If called without preemption
|
2012-02-15 22:51:48 +08:00
|
|
|
* disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
|
|
|
|
*/
|
|
|
|
static inline int ftrace_function_local_disabled(struct ftrace_ops *ops)
|
|
|
|
{
|
2015-12-01 06:23:39 +08:00
|
|
|
WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_PER_CPU));
|
2012-02-15 22:51:48 +08:00
|
|
|
return *this_cpu_ptr(ops->disabled);
|
|
|
|
}
|
|
|
|
|
2011-08-10 00:50:46 +08:00
|
|
|
extern void ftrace_stub(unsigned long a0, unsigned long a1,
|
|
|
|
struct ftrace_ops *op, struct pt_regs *regs);
|
2008-05-13 03:20:42 +08:00
|
|
|
|
2008-10-07 07:06:12 +08:00
|
|
|
#else /* !CONFIG_FUNCTION_TRACER */
|
2010-05-04 23:24:01 +08:00
|
|
|
/*
|
|
|
|
* (un)register_ftrace_function must be a macro since the ops parameter
|
|
|
|
* must not be evaluated.
|
|
|
|
*/
|
|
|
|
#define register_ftrace_function(ops) ({ 0; })
|
|
|
|
#define unregister_ftrace_function(ops) ({ 0; })
|
2012-07-21 01:08:05 +08:00
|
|
|
static inline int ftrace_nr_registered_ops(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2010-05-04 23:24:01 +08:00
|
|
|
static inline void clear_ftrace_function(void) { }
|
2008-10-23 21:33:02 +08:00
|
|
|
static inline void ftrace_kill(void) { }
|
2017-04-04 00:57:35 +08:00
|
|
|
static inline void ftrace_free_init_mem(void) { }
|
2008-10-07 07:06:12 +08:00
|
|
|
#endif /* CONFIG_FUNCTION_TRACER */
|
2008-05-13 03:20:42 +08:00
|
|
|
|
2008-12-17 12:06:40 +08:00
|
|
|
#ifdef CONFIG_STACK_TRACER
|
2015-10-30 13:25:39 +08:00
|
|
|
|
|
|
|
#define STACK_TRACE_ENTRIES 500
|
|
|
|
|
|
|
|
struct stack_trace;
|
|
|
|
|
|
|
|
extern unsigned stack_trace_index[];
|
|
|
|
extern struct stack_trace stack_trace_max;
|
|
|
|
extern unsigned long stack_trace_max_size;
|
2015-11-04 03:50:15 +08:00
|
|
|
extern arch_spinlock_t stack_trace_max_lock;
|
2015-10-30 13:25:39 +08:00
|
|
|
|
2008-12-17 12:06:40 +08:00
|
|
|
extern int stack_tracer_enabled;
|
2015-10-30 13:25:39 +08:00
|
|
|
void stack_trace_print(void);
|
2008-12-17 12:06:40 +08:00
|
|
|
int
|
|
|
|
stack_trace_sysctl(struct ctl_table *table, int write,
|
2009-09-24 06:57:19 +08:00
|
|
|
void __user *buffer, size_t *lenp,
|
2008-12-17 12:06:40 +08:00
|
|
|
loff_t *ppos);
|
2017-04-07 00:26:20 +08:00
|
|
|
|
|
|
|
void stack_tracer_disable(void);
|
|
|
|
void stack_tracer_enable(void);
|
|
|
|
#else
|
|
|
|
static inline void stack_tracer_disable(void) { }
|
|
|
|
static inline void stack_tracer_enable(void) { }
|
2008-12-17 12:06:40 +08:00
|
|
|
#endif
|
|
|
|
|
2009-02-14 13:40:25 +08:00
|
|
|
struct ftrace_func_command {
|
|
|
|
struct list_head list;
|
|
|
|
char *name;
|
2011-07-07 23:09:22 +08:00
|
|
|
int (*func)(struct ftrace_hash *hash,
|
|
|
|
char *func, char *cmd,
|
2009-02-14 13:40:25 +08:00
|
|
|
char *params, int enable);
|
|
|
|
};
|
|
|
|
|
ftrace: dynamic enabling/disabling of function calls
This patch adds a feature to dynamically replace the ftrace code
with the jmps to allow a kernel with ftrace configured to run
as fast as it can without it configured.
The way this works, is on bootup (if ftrace is enabled), a ftrace
function is registered to record the instruction pointer of all
places that call the function.
Later, if there's still any code to patch, a kthread is awoken
(rate limited to at most once a second) that performs a stop_machine,
and replaces all the code that was called with a jmp over the call
to ftrace. It only replaces what was found the previous time. Typically
the system reaches equilibrium quickly after bootup and there's no code
patching needed at all.
e.g.
call ftrace /* 5 bytes */
is replaced with
jmp 3f /* jmp is 2 bytes and we jump 3 forward */
3:
When we want to enable ftrace for function tracing, the IP recording
is removed, and stop_machine is called again to replace all the locations
of that were recorded back to the call of ftrace. When it is disabled,
we replace the code back to the jmp.
Allocation is done by the kthread. If the ftrace recording function is
called, and we don't have any record slots available, then we simply
skip that call. Once a second a new page (if needed) is allocated for
recording new ftrace function calls. A large batch is allocated at
boot up to get most of the calls there.
Because we do this via stop_machine, we don't have to worry about another
CPU executing a ftrace call as we modify it. But we do need to worry
about NMI's so all functions that might be called via nmi must be
annotated with notrace_nmi. When this code is configured in, the NMI code
will not call notrace.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2008-05-13 03:20:42 +08:00
|
|
|
#ifdef CONFIG_DYNAMIC_FTRACE
|
2008-11-15 08:21:19 +08:00
|
|
|
|
2009-02-18 02:35:06 +08:00
|
|
|
int ftrace_arch_code_modify_prepare(void);
|
|
|
|
int ftrace_arch_code_modify_post_process(void);
|
|
|
|
|
2014-10-25 05:56:04 +08:00
|
|
|
struct dyn_ftrace;
|
|
|
|
|
2015-11-26 01:50:47 +08:00
|
|
|
enum ftrace_bug_type {
|
|
|
|
FTRACE_BUG_UNKNOWN,
|
|
|
|
FTRACE_BUG_INIT,
|
|
|
|
FTRACE_BUG_NOP,
|
|
|
|
FTRACE_BUG_CALL,
|
|
|
|
FTRACE_BUG_UPDATE,
|
|
|
|
};
|
|
|
|
extern enum ftrace_bug_type ftrace_bug_type;
|
|
|
|
|
2015-11-26 03:13:11 +08:00
|
|
|
/*
|
|
|
|
* Archs can set this to point to a variable that holds the value that was
|
|
|
|
* expected at the call site before calling ftrace_bug().
|
|
|
|
*/
|
|
|
|
extern const void *ftrace_expected;
|
|
|
|
|
2014-10-25 05:56:04 +08:00
|
|
|
void ftrace_bug(int err, struct dyn_ftrace *rec);
|
2011-08-16 21:53:39 +08:00
|
|
|
|
2009-02-17 12:06:01 +08:00
|
|
|
struct seq_file;
|
|
|
|
|
2009-02-18 01:32:04 +08:00
|
|
|
struct ftrace_probe_ops {
|
ftrace: trace different functions with a different tracer
Impact: new feature
Currently, the function tracer only gives you an ability to hook
a tracer to all functions being traced. The dynamic function trace
allows you to pick and choose which of those functions will be
traced, but all functions being traced will call all tracers that
registered with the function tracer.
This patch adds a new feature that allows a tracer to hook to specific
functions, even when all functions are being traced. It allows for
different functions to call different tracer hooks.
The way this is accomplished is by a special function that will hook
to the function tracer and will set up a hash table knowing which
tracer hook to call with which function. This is the most general
and easiest method to accomplish this. Later, an arch may choose
to supply their own method in changing the mcount call of a function
to call a different tracer. But that will be an exercise for the
future.
To register a function:
struct ftrace_hook_ops {
void (*func)(unsigned long ip,
unsigned long parent_ip,
void **data);
int (*callback)(unsigned long ip, void **data);
void (*free)(void **data);
};
int register_ftrace_function_hook(char *glob, struct ftrace_hook_ops *ops,
void *data);
glob is a simple glob to search for the functions to hook.
ops is a pointer to the operations (listed below)
data is the default data to be passed to the hook functions when traced
ops:
func is the hook function to call when the functions are traced
callback is a callback function that is called when setting up the hash.
That is, if the tracer needs to do something special for each
function, that is being traced, and wants to give each function
its own data. The address of the entry data is passed to this
callback, so that the callback may wish to update the entry to
whatever it would like.
free is a callback for when the entry is freed. In case the tracer
allocated any data, it is give the chance to free it.
To unregister we have three functions:
void
unregister_ftrace_function_hook(char *glob, struct ftrace_hook_ops *ops,
void *data)
This will unregister all hooks that match glob, point to ops, and
have its data matching data. (note, if glob is NULL, blank or '*',
all functions will be tested).
void
unregister_ftrace_function_hook_func(char *glob,
struct ftrace_hook_ops *ops)
This will unregister all functions matching glob that has an entry
pointing to ops.
void unregister_ftrace_function_hook_all(char *glob)
This simply unregisters all funcs.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
2009-02-15 04:29:06 +08:00
|
|
|
void (*func)(unsigned long ip,
|
|
|
|
unsigned long parent_ip,
|
|
|
|
void **data);
|
2013-03-13 03:07:59 +08:00
|
|
|
int (*init)(struct ftrace_probe_ops *ops,
|
|
|
|
unsigned long ip, void **data);
|
|
|
|
void (*free)(struct ftrace_probe_ops *ops,
|
|
|
|
unsigned long ip, void **data);
|
2009-02-17 12:06:01 +08:00
|
|
|
int (*print)(struct seq_file *m,
|
|
|
|
unsigned long ip,
|
2009-02-18 01:32:04 +08:00
|
|
|
struct ftrace_probe_ops *ops,
|
2009-02-17 12:06:01 +08:00
|
|
|
void *data);
|
ftrace: trace different functions with a different tracer
Impact: new feature
Currently, the function tracer only gives you an ability to hook
a tracer to all functions being traced. The dynamic function trace
allows you to pick and choose which of those functions will be
traced, but all functions being traced will call all tracers that
registered with the function tracer.
This patch adds a new feature that allows a tracer to hook to specific
functions, even when all functions are being traced. It allows for
different functions to call different tracer hooks.
The way this is accomplished is by a special function that will hook
to the function tracer and will set up a hash table knowing which
tracer hook to call with which function. This is the most general
and easiest method to accomplish this. Later, an arch may choose
to supply their own method in changing the mcount call of a function
to call a different tracer. But that will be an exercise for the
future.
To register a function:
struct ftrace_hook_ops {
void (*func)(unsigned long ip,
unsigned long parent_ip,
void **data);
int (*callback)(unsigned long ip, void **data);
void (*free)(void **data);
};
int register_ftrace_function_hook(char *glob, struct ftrace_hook_ops *ops,
void *data);
glob is a simple glob to search for the functions to hook.
ops is a pointer to the operations (listed below)
data is the default data to be passed to the hook functions when traced
ops:
func is the hook function to call when the functions are traced
callback is a callback function that is called when setting up the hash.
That is, if the tracer needs to do something special for each
function, that is being traced, and wants to give each function
its own data. The address of the entry data is passed to this
callback, so that the callback may wish to update the entry to
whatever it would like.
free is a callback for when the entry is freed. In case the tracer
allocated any data, it is give the chance to free it.
To unregister we have three functions:
void
unregister_ftrace_function_hook(char *glob, struct ftrace_hook_ops *ops,
void *data)
This will unregister all hooks that match glob, point to ops, and
have its data matching data. (note, if glob is NULL, blank or '*',
all functions will be tested).
void
unregister_ftrace_function_hook_func(char *glob,
struct ftrace_hook_ops *ops)
This will unregister all functions matching glob that has an entry
pointing to ops.
void unregister_ftrace_function_hook_all(char *glob)
This simply unregisters all funcs.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
2009-02-15 04:29:06 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
extern int
|
2009-02-18 01:32:04 +08:00
|
|
|
register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
|
ftrace: trace different functions with a different tracer
Impact: new feature
Currently, the function tracer only gives you an ability to hook
a tracer to all functions being traced. The dynamic function trace
allows you to pick and choose which of those functions will be
traced, but all functions being traced will call all tracers that
registered with the function tracer.
This patch adds a new feature that allows a tracer to hook to specific
functions, even when all functions are being traced. It allows for
different functions to call different tracer hooks.
The way this is accomplished is by a special function that will hook
to the function tracer and will set up a hash table knowing which
tracer hook to call with which function. This is the most general
and easiest method to accomplish this. Later, an arch may choose
to supply their own method in changing the mcount call of a function
to call a different tracer. But that will be an exercise for the
future.
To register a function:
struct ftrace_hook_ops {
void (*func)(unsigned long ip,
unsigned long parent_ip,
void **data);
int (*callback)(unsigned long ip, void **data);
void (*free)(void **data);
};
int register_ftrace_function_hook(char *glob, struct ftrace_hook_ops *ops,
void *data);
glob is a simple glob to search for the functions to hook.
ops is a pointer to the operations (listed below)
data is the default data to be passed to the hook functions when traced
ops:
func is the hook function to call when the functions are traced
callback is a callback function that is called when setting up the hash.
That is, if the tracer needs to do something special for each
function, that is being traced, and wants to give each function
its own data. The address of the entry data is passed to this
callback, so that the callback may wish to update the entry to
whatever it would like.
free is a callback for when the entry is freed. In case the tracer
allocated any data, it is give the chance to free it.
To unregister we have three functions:
void
unregister_ftrace_function_hook(char *glob, struct ftrace_hook_ops *ops,
void *data)
This will unregister all hooks that match glob, point to ops, and
have its data matching data. (note, if glob is NULL, blank or '*',
all functions will be tested).
void
unregister_ftrace_function_hook_func(char *glob,
struct ftrace_hook_ops *ops)
This will unregister all functions matching glob that has an entry
pointing to ops.
void unregister_ftrace_function_hook_all(char *glob)
This simply unregisters all funcs.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
2009-02-15 04:29:06 +08:00
|
|
|
void *data);
|
|
|
|
extern void
|
2009-02-18 01:32:04 +08:00
|
|
|
unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
|
ftrace: trace different functions with a different tracer
Impact: new feature
Currently, the function tracer only gives you an ability to hook
a tracer to all functions being traced. The dynamic function trace
allows you to pick and choose which of those functions will be
traced, but all functions being traced will call all tracers that
registered with the function tracer.
This patch adds a new feature that allows a tracer to hook to specific
functions, even when all functions are being traced. It allows for
different functions to call different tracer hooks.
The way this is accomplished is by a special function that will hook
to the function tracer and will set up a hash table knowing which
tracer hook to call with which function. This is the most general
and easiest method to accomplish this. Later, an arch may choose
to supply their own method in changing the mcount call of a function
to call a different tracer. But that will be an exercise for the
future.
To register a function:
struct ftrace_hook_ops {
void (*func)(unsigned long ip,
unsigned long parent_ip,
void **data);
int (*callback)(unsigned long ip, void **data);
void (*free)(void **data);
};
int register_ftrace_function_hook(char *glob, struct ftrace_hook_ops *ops,
void *data);
glob is a simple glob to search for the functions to hook.
ops is a pointer to the operations (listed below)
data is the default data to be passed to the hook functions when traced
ops:
func is the hook function to call when the functions are traced
callback is a callback function that is called when setting up the hash.
That is, if the tracer needs to do something special for each
function, that is being traced, and wants to give each function
its own data. The address of the entry data is passed to this
callback, so that the callback may wish to update the entry to
whatever it would like.
free is a callback for when the entry is freed. In case the tracer
allocated any data, it is give the chance to free it.
To unregister we have three functions:
void
unregister_ftrace_function_hook(char *glob, struct ftrace_hook_ops *ops,
void *data)
This will unregister all hooks that match glob, point to ops, and
have its data matching data. (note, if glob is NULL, blank or '*',
all functions will be tested).
void
unregister_ftrace_function_hook_func(char *glob,
struct ftrace_hook_ops *ops)
This will unregister all functions matching glob that has an entry
pointing to ops.
void unregister_ftrace_function_hook_all(char *glob)
This simply unregisters all funcs.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
2009-02-15 04:29:06 +08:00
|
|
|
void *data);
|
|
|
|
extern void
|
2009-02-18 01:32:04 +08:00
|
|
|
unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
|
|
|
|
extern void unregister_ftrace_function_probe_all(char *glob);
|
ftrace: trace different functions with a different tracer
Impact: new feature
Currently, the function tracer only gives you an ability to hook
a tracer to all functions being traced. The dynamic function trace
allows you to pick and choose which of those functions will be
traced, but all functions being traced will call all tracers that
registered with the function tracer.
This patch adds a new feature that allows a tracer to hook to specific
functions, even when all functions are being traced. It allows for
different functions to call different tracer hooks.
The way this is accomplished is by a special function that will hook
to the function tracer and will set up a hash table knowing which
tracer hook to call with which function. This is the most general
and easiest method to accomplish this. Later, an arch may choose
to supply their own method in changing the mcount call of a function
to call a different tracer. But that will be an exercise for the
future.
To register a function:
struct ftrace_hook_ops {
void (*func)(unsigned long ip,
unsigned long parent_ip,
void **data);
int (*callback)(unsigned long ip, void **data);
void (*free)(void **data);
};
int register_ftrace_function_hook(char *glob, struct ftrace_hook_ops *ops,
void *data);
glob is a simple glob to search for the functions to hook.
ops is a pointer to the operations (listed below)
data is the default data to be passed to the hook functions when traced
ops:
func is the hook function to call when the functions are traced
callback is a callback function that is called when setting up the hash.
That is, if the tracer needs to do something special for each
function, that is being traced, and wants to give each function
its own data. The address of the entry data is passed to this
callback, so that the callback may wish to update the entry to
whatever it would like.
free is a callback for when the entry is freed. In case the tracer
allocated any data, it is give the chance to free it.
To unregister we have three functions:
void
unregister_ftrace_function_hook(char *glob, struct ftrace_hook_ops *ops,
void *data)
This will unregister all hooks that match glob, point to ops, and
have its data matching data. (note, if glob is NULL, blank or '*',
all functions will be tested).
void
unregister_ftrace_function_hook_func(char *glob,
struct ftrace_hook_ops *ops)
This will unregister all functions matching glob that has an entry
pointing to ops.
void unregister_ftrace_function_hook_all(char *glob)
This simply unregisters all funcs.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
2009-02-15 04:29:06 +08:00
|
|
|
|
2013-01-10 07:09:20 +08:00
|
|
|
extern int ftrace_text_reserved(const void *start, const void *end);
|
2010-02-03 05:49:11 +08:00
|
|
|
|
2012-07-21 01:08:05 +08:00
|
|
|
extern int ftrace_nr_registered_ops(void);
|
|
|
|
|
2014-11-19 10:14:11 +08:00
|
|
|
bool is_ftrace_trampoline(unsigned long addr);
|
|
|
|
|
2012-05-01 04:20:23 +08:00
|
|
|
/*
|
|
|
|
* The dyn_ftrace record's flags field is split into two parts.
|
|
|
|
* the first part which is '0-FTRACE_REF_MAX' is a counter of
|
|
|
|
* the number of callbacks that have registered the function that
|
|
|
|
* the dyn_ftrace descriptor represents.
|
|
|
|
*
|
|
|
|
* The second part is a mask:
|
|
|
|
* ENABLED - the function is being traced
|
|
|
|
* REGS - the record wants the function to save regs
|
|
|
|
* REGS_EN - the function is set up to save regs.
|
2014-11-21 18:25:16 +08:00
|
|
|
* IPMODIFY - the record allows for the IP address to be changed.
|
ftrace: Add infrastructure for delayed enabling of module functions
Qiu Peiyang pointed out that there's a race when enabling function tracing
and loading a module. In order to make the modifications of converting nops
in the prologue of functions into callbacks, the text needs to be converted
from read-only to read-write. When enabling function tracing, the text
permission is updated, the functions are modified, and then they are put
back.
When loading a module, the updates to convert function calls to mcount is
done before the module text is set to read-only. But after it is done, the
module text is visible by the function tracer. Thus we have the following
race:
CPU 0 CPU 1
----- -----
start function tracing
set text to read-write
load_module
add functions to ftrace
set module text read-only
update all functions to callbacks
modify module functions too
< Can't it's read-only >
When this happens, ftrace detects the issue and disables itself till the
next reboot.
To fix this, a new DISABLED flag is added for ftrace records, which all
module functions get when they are added. Then later, after the module code
is all set, the records will have the DISABLED flag cleared, and they will
be enabled if any callback wants all functions to be traced.
Note, this doesn't add the delay to later. It simply changes the
ftrace_module_init() to do both the setting of DISABLED records, and then
immediately calls the enable code. This helps with testing this new code as
it has the same behavior as previously. Another change will come after this
to have the ftrace_module_enable() called after the text is set to
read-only.
Cc: Qiu Peiyang <peiyangx.qiu@intel.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2016-01-08 04:40:01 +08:00
|
|
|
* DISABLED - the record is not ready to be touched yet
|
2012-05-01 04:20:23 +08:00
|
|
|
*
|
|
|
|
* When a new ftrace_ops is registered and wants a function to save
|
|
|
|
* pt_regs, the rec->flag REGS is set. When the function has been
|
|
|
|
* set up to save regs, the REG_EN flag is set. Once a function
|
|
|
|
* starts saving regs it will do so until all ftrace_ops are removed
|
|
|
|
* from tracing that function.
|
|
|
|
*/
|
2008-05-13 03:20:43 +08:00
|
|
|
enum {
|
ftrace: Optimize function graph to be called directly
Function graph tracing is a bit different than the function tracers, as
it is processed after either the ftrace_caller or ftrace_regs_caller
and we only have one place to modify the jump to ftrace_graph_caller,
the jump needs to happen after the restore of registeres.
The function graph tracer is dependent on the function tracer, where
even if the function graph tracing is going on by itself, the save and
restore of registers is still done for function tracing regardless of
if function tracing is happening, before it calls the function graph
code.
If there's no function tracing happening, it is possible to just call
the function graph tracer directly, and avoid the wasted effort to save
and restore regs for function tracing.
This requires adding new flags to the dyn_ftrace records:
FTRACE_FL_TRAMP
FTRACE_FL_TRAMP_EN
The first is set if the count for the record is one, and the ftrace_ops
associated to that record has its own trampoline. That way the mcount code
can call that trampoline directly.
In the future, trampolines can be added to arbitrary ftrace_ops, where you
can have two or more ftrace_ops registered to ftrace (like kprobes and perf)
and if they are not tracing the same functions, then instead of doing a
loop to check all registered ftrace_ops against their hashes, just call the
ftrace_ops trampoline directly, which would call the registered ftrace_ops
function directly.
Without this patch perf showed:
0.05% hackbench [kernel.kallsyms] [k] ftrace_caller
0.05% hackbench [kernel.kallsyms] [k] arch_local_irq_save
0.05% hackbench [kernel.kallsyms] [k] native_sched_clock
0.04% hackbench [kernel.kallsyms] [k] __buffer_unlock_commit
0.04% hackbench [kernel.kallsyms] [k] preempt_trace
0.04% hackbench [kernel.kallsyms] [k] prepare_ftrace_return
0.04% hackbench [kernel.kallsyms] [k] __this_cpu_preempt_check
0.04% hackbench [kernel.kallsyms] [k] ftrace_graph_caller
See that the ftrace_caller took up more time than the ftrace_graph_caller
did.
With this patch:
0.05% hackbench [kernel.kallsyms] [k] __buffer_unlock_commit
0.04% hackbench [kernel.kallsyms] [k] call_filter_check_discard
0.04% hackbench [kernel.kallsyms] [k] ftrace_graph_caller
0.04% hackbench [kernel.kallsyms] [k] sched_clock
The ftrace_caller is no where to be found and ftrace_graph_caller still
takes up the same percentage.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2014-05-07 09:56:17 +08:00
|
|
|
FTRACE_FL_ENABLED = (1UL << 31),
|
2012-05-01 04:20:23 +08:00
|
|
|
FTRACE_FL_REGS = (1UL << 30),
|
ftrace: Optimize function graph to be called directly
Function graph tracing is a bit different than the function tracers, as
it is processed after either the ftrace_caller or ftrace_regs_caller
and we only have one place to modify the jump to ftrace_graph_caller,
the jump needs to happen after the restore of registeres.
The function graph tracer is dependent on the function tracer, where
even if the function graph tracing is going on by itself, the save and
restore of registers is still done for function tracing regardless of
if function tracing is happening, before it calls the function graph
code.
If there's no function tracing happening, it is possible to just call
the function graph tracer directly, and avoid the wasted effort to save
and restore regs for function tracing.
This requires adding new flags to the dyn_ftrace records:
FTRACE_FL_TRAMP
FTRACE_FL_TRAMP_EN
The first is set if the count for the record is one, and the ftrace_ops
associated to that record has its own trampoline. That way the mcount code
can call that trampoline directly.
In the future, trampolines can be added to arbitrary ftrace_ops, where you
can have two or more ftrace_ops registered to ftrace (like kprobes and perf)
and if they are not tracing the same functions, then instead of doing a
loop to check all registered ftrace_ops against their hashes, just call the
ftrace_ops trampoline directly, which would call the registered ftrace_ops
function directly.
Without this patch perf showed:
0.05% hackbench [kernel.kallsyms] [k] ftrace_caller
0.05% hackbench [kernel.kallsyms] [k] arch_local_irq_save
0.05% hackbench [kernel.kallsyms] [k] native_sched_clock
0.04% hackbench [kernel.kallsyms] [k] __buffer_unlock_commit
0.04% hackbench [kernel.kallsyms] [k] preempt_trace
0.04% hackbench [kernel.kallsyms] [k] prepare_ftrace_return
0.04% hackbench [kernel.kallsyms] [k] __this_cpu_preempt_check
0.04% hackbench [kernel.kallsyms] [k] ftrace_graph_caller
See that the ftrace_caller took up more time than the ftrace_graph_caller
did.
With this patch:
0.05% hackbench [kernel.kallsyms] [k] __buffer_unlock_commit
0.04% hackbench [kernel.kallsyms] [k] call_filter_check_discard
0.04% hackbench [kernel.kallsyms] [k] ftrace_graph_caller
0.04% hackbench [kernel.kallsyms] [k] sched_clock
The ftrace_caller is no where to be found and ftrace_graph_caller still
takes up the same percentage.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2014-05-07 09:56:17 +08:00
|
|
|
FTRACE_FL_REGS_EN = (1UL << 29),
|
|
|
|
FTRACE_FL_TRAMP = (1UL << 28),
|
|
|
|
FTRACE_FL_TRAMP_EN = (1UL << 27),
|
2014-11-21 18:25:16 +08:00
|
|
|
FTRACE_FL_IPMODIFY = (1UL << 26),
|
ftrace: Add infrastructure for delayed enabling of module functions
Qiu Peiyang pointed out that there's a race when enabling function tracing
and loading a module. In order to make the modifications of converting nops
in the prologue of functions into callbacks, the text needs to be converted
from read-only to read-write. When enabling function tracing, the text
permission is updated, the functions are modified, and then they are put
back.
When loading a module, the updates to convert function calls to mcount is
done before the module text is set to read-only. But after it is done, the
module text is visible by the function tracer. Thus we have the following
race:
CPU 0 CPU 1
----- -----
start function tracing
set text to read-write
load_module
add functions to ftrace
set module text read-only
update all functions to callbacks
modify module functions too
< Can't it's read-only >
When this happens, ftrace detects the issue and disables itself till the
next reboot.
To fix this, a new DISABLED flag is added for ftrace records, which all
module functions get when they are added. Then later, after the module code
is all set, the records will have the DISABLED flag cleared, and they will
be enabled if any callback wants all functions to be traced.
Note, this doesn't add the delay to later. It simply changes the
ftrace_module_init() to do both the setting of DISABLED records, and then
immediately calls the enable code. This helps with testing this new code as
it has the same behavior as previously. Another change will come after this
to have the ftrace_module_enable() called after the text is set to
read-only.
Cc: Qiu Peiyang <peiyangx.qiu@intel.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2016-01-08 04:40:01 +08:00
|
|
|
FTRACE_FL_DISABLED = (1UL << 25),
|
2008-05-13 03:20:43 +08:00
|
|
|
};
|
|
|
|
|
ftrace: Add infrastructure for delayed enabling of module functions
Qiu Peiyang pointed out that there's a race when enabling function tracing
and loading a module. In order to make the modifications of converting nops
in the prologue of functions into callbacks, the text needs to be converted
from read-only to read-write. When enabling function tracing, the text
permission is updated, the functions are modified, and then they are put
back.
When loading a module, the updates to convert function calls to mcount is
done before the module text is set to read-only. But after it is done, the
module text is visible by the function tracer. Thus we have the following
race:
CPU 0 CPU 1
----- -----
start function tracing
set text to read-write
load_module
add functions to ftrace
set module text read-only
update all functions to callbacks
modify module functions too
< Can't it's read-only >
When this happens, ftrace detects the issue and disables itself till the
next reboot.
To fix this, a new DISABLED flag is added for ftrace records, which all
module functions get when they are added. Then later, after the module code
is all set, the records will have the DISABLED flag cleared, and they will
be enabled if any callback wants all functions to be traced.
Note, this doesn't add the delay to later. It simply changes the
ftrace_module_init() to do both the setting of DISABLED records, and then
immediately calls the enable code. This helps with testing this new code as
it has the same behavior as previously. Another change will come after this
to have the ftrace_module_enable() called after the text is set to
read-only.
Cc: Qiu Peiyang <peiyangx.qiu@intel.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2016-01-08 04:40:01 +08:00
|
|
|
#define FTRACE_REF_MAX_SHIFT 25
|
|
|
|
#define FTRACE_FL_BITS 7
|
2014-05-08 00:42:28 +08:00
|
|
|
#define FTRACE_FL_MASKED_BITS ((1UL << FTRACE_FL_BITS) - 1)
|
|
|
|
#define FTRACE_FL_MASK (FTRACE_FL_MASKED_BITS << FTRACE_REF_MAX_SHIFT)
|
|
|
|
#define FTRACE_REF_MAX ((1UL << FTRACE_REF_MAX_SHIFT) - 1)
|
2011-05-04 01:25:24 +08:00
|
|
|
|
2014-05-08 01:46:45 +08:00
|
|
|
#define ftrace_rec_count(rec) ((rec)->flags & ~FTRACE_FL_MASK)
|
|
|
|
|
ftrace: dynamic enabling/disabling of function calls
This patch adds a feature to dynamically replace the ftrace code
with the jmps to allow a kernel with ftrace configured to run
as fast as it can without it configured.
The way this works, is on bootup (if ftrace is enabled), a ftrace
function is registered to record the instruction pointer of all
places that call the function.
Later, if there's still any code to patch, a kthread is awoken
(rate limited to at most once a second) that performs a stop_machine,
and replaces all the code that was called with a jmp over the call
to ftrace. It only replaces what was found the previous time. Typically
the system reaches equilibrium quickly after bootup and there's no code
patching needed at all.
e.g.
call ftrace /* 5 bytes */
is replaced with
jmp 3f /* jmp is 2 bytes and we jump 3 forward */
3:
When we want to enable ftrace for function tracing, the IP recording
is removed, and stop_machine is called again to replace all the locations
of that were recorded back to the call of ftrace. When it is disabled,
we replace the code back to the jmp.
Allocation is done by the kthread. If the ftrace recording function is
called, and we don't have any record slots available, then we simply
skip that call. Once a second a new page (if needed) is allocated for
recording new ftrace function calls. A large batch is allocated at
boot up to get most of the calls there.
Because we do this via stop_machine, we don't have to worry about another
CPU executing a ftrace call as we modify it. But we do need to worry
about NMI's so all functions that might be called via nmi must be
annotated with notrace_nmi. When this code is configured in, the NMI code
will not call notrace.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2008-05-13 03:20:42 +08:00
|
|
|
struct dyn_ftrace {
|
2014-02-25 03:00:00 +08:00
|
|
|
unsigned long ip; /* address of mcount call-site */
|
2011-12-17 05:30:31 +08:00
|
|
|
unsigned long flags;
|
2014-02-25 03:00:00 +08:00
|
|
|
struct dyn_arch_ftrace arch;
|
ftrace: dynamic enabling/disabling of function calls
This patch adds a feature to dynamically replace the ftrace code
with the jmps to allow a kernel with ftrace configured to run
as fast as it can without it configured.
The way this works, is on bootup (if ftrace is enabled), a ftrace
function is registered to record the instruction pointer of all
places that call the function.
Later, if there's still any code to patch, a kthread is awoken
(rate limited to at most once a second) that performs a stop_machine,
and replaces all the code that was called with a jmp over the call
to ftrace. It only replaces what was found the previous time. Typically
the system reaches equilibrium quickly after bootup and there's no code
patching needed at all.
e.g.
call ftrace /* 5 bytes */
is replaced with
jmp 3f /* jmp is 2 bytes and we jump 3 forward */
3:
When we want to enable ftrace for function tracing, the IP recording
is removed, and stop_machine is called again to replace all the locations
of that were recorded back to the call of ftrace. When it is disabled,
we replace the code back to the jmp.
Allocation is done by the kthread. If the ftrace recording function is
called, and we don't have any record slots available, then we simply
skip that call. Once a second a new page (if needed) is allocated for
recording new ftrace function calls. A large batch is allocated at
boot up to get most of the calls there.
Because we do this via stop_machine, we don't have to worry about another
CPU executing a ftrace call as we modify it. But we do need to worry
about NMI's so all functions that might be called via nmi must be
annotated with notrace_nmi. When this code is configured in, the NMI code
will not call notrace.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2008-05-13 03:20:42 +08:00
|
|
|
};
|
|
|
|
|
2008-05-13 03:20:44 +08:00
|
|
|
int ftrace_force_update(void);
|
2012-06-05 18:28:08 +08:00
|
|
|
int ftrace_set_filter_ip(struct ftrace_ops *ops, unsigned long ip,
|
|
|
|
int remove, int reset);
|
2012-01-02 17:04:14 +08:00
|
|
|
int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
|
2011-05-06 10:54:01 +08:00
|
|
|
int len, int reset);
|
2012-01-02 17:04:14 +08:00
|
|
|
int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
|
2011-05-06 10:54:01 +08:00
|
|
|
int len, int reset);
|
|
|
|
void ftrace_set_global_filter(unsigned char *buf, int len, int reset);
|
|
|
|
void ftrace_set_global_notrace(unsigned char *buf, int len, int reset);
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 22:51:54 +08:00
|
|
|
void ftrace_free_filter(struct ftrace_ops *ops);
|
2016-11-16 04:31:20 +08:00
|
|
|
void ftrace_ops_set_global_filter(struct ftrace_ops *ops);
|
2008-05-13 03:20:44 +08:00
|
|
|
|
2009-02-14 13:40:25 +08:00
|
|
|
int register_ftrace_command(struct ftrace_func_command *cmd);
|
|
|
|
int unregister_ftrace_command(struct ftrace_func_command *cmd);
|
|
|
|
|
2011-08-16 21:53:39 +08:00
|
|
|
enum {
|
|
|
|
FTRACE_UPDATE_CALLS = (1 << 0),
|
|
|
|
FTRACE_DISABLE_CALLS = (1 << 1),
|
|
|
|
FTRACE_UPDATE_TRACE_FUNC = (1 << 2),
|
|
|
|
FTRACE_START_FUNC_RET = (1 << 3),
|
|
|
|
FTRACE_STOP_FUNC_RET = (1 << 4),
|
|
|
|
};
|
|
|
|
|
2012-05-01 04:20:23 +08:00
|
|
|
/*
|
|
|
|
* The FTRACE_UPDATE_* enum is used to pass information back
|
|
|
|
* from the ftrace_update_record() and ftrace_test_record()
|
|
|
|
* functions. These are called by the code update routines
|
|
|
|
* to find out what is to be done for a given function.
|
|
|
|
*
|
|
|
|
* IGNORE - The function is already what we want it to be
|
|
|
|
* MAKE_CALL - Start tracing the function
|
|
|
|
* MODIFY_CALL - Stop saving regs for the function
|
|
|
|
* MAKE_NOP - Stop tracing the function
|
|
|
|
*/
|
2011-08-16 21:53:39 +08:00
|
|
|
enum {
|
|
|
|
FTRACE_UPDATE_IGNORE,
|
|
|
|
FTRACE_UPDATE_MAKE_CALL,
|
2012-05-01 04:20:23 +08:00
|
|
|
FTRACE_UPDATE_MODIFY_CALL,
|
2011-08-16 21:53:39 +08:00
|
|
|
FTRACE_UPDATE_MAKE_NOP,
|
|
|
|
};
|
|
|
|
|
2011-12-20 03:41:25 +08:00
|
|
|
enum {
|
|
|
|
FTRACE_ITER_FILTER = (1 << 0),
|
|
|
|
FTRACE_ITER_NOTRACE = (1 << 1),
|
|
|
|
FTRACE_ITER_PRINTALL = (1 << 2),
|
2011-12-20 04:21:16 +08:00
|
|
|
FTRACE_ITER_DO_HASH = (1 << 3),
|
|
|
|
FTRACE_ITER_HASH = (1 << 4),
|
|
|
|
FTRACE_ITER_ENABLED = (1 << 5),
|
2011-12-20 03:41:25 +08:00
|
|
|
};
|
|
|
|
|
2011-08-16 21:53:39 +08:00
|
|
|
void arch_ftrace_update_code(int command);
|
|
|
|
|
|
|
|
struct ftrace_rec_iter;
|
|
|
|
|
|
|
|
struct ftrace_rec_iter *ftrace_rec_iter_start(void);
|
|
|
|
struct ftrace_rec_iter *ftrace_rec_iter_next(struct ftrace_rec_iter *iter);
|
|
|
|
struct dyn_ftrace *ftrace_rec_iter_record(struct ftrace_rec_iter *iter);
|
|
|
|
|
2011-08-16 21:57:10 +08:00
|
|
|
#define for_ftrace_rec_iter(iter) \
|
|
|
|
for (iter = ftrace_rec_iter_start(); \
|
|
|
|
iter; \
|
|
|
|
iter = ftrace_rec_iter_next(iter))
|
|
|
|
|
|
|
|
|
2011-08-16 21:53:39 +08:00
|
|
|
int ftrace_update_record(struct dyn_ftrace *rec, int enable);
|
|
|
|
int ftrace_test_record(struct dyn_ftrace *rec, int enable);
|
|
|
|
void ftrace_run_stop_machine(int command);
|
2012-04-26 02:39:54 +08:00
|
|
|
unsigned long ftrace_location(unsigned long ip);
|
2016-03-24 19:04:01 +08:00
|
|
|
unsigned long ftrace_location_range(unsigned long start, unsigned long end);
|
2014-05-07 09:34:14 +08:00
|
|
|
unsigned long ftrace_get_addr_new(struct dyn_ftrace *rec);
|
|
|
|
unsigned long ftrace_get_addr_curr(struct dyn_ftrace *rec);
|
2011-08-16 21:53:39 +08:00
|
|
|
|
|
|
|
extern ftrace_func_t ftrace_trace_function;
|
|
|
|
|
2011-12-20 03:41:25 +08:00
|
|
|
int ftrace_regex_open(struct ftrace_ops *ops, int flag,
|
|
|
|
struct inode *inode, struct file *file);
|
|
|
|
ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
|
|
|
|
size_t cnt, loff_t *ppos);
|
|
|
|
ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
|
|
|
|
size_t cnt, loff_t *ppos);
|
|
|
|
int ftrace_regex_release(struct inode *inode, struct file *file);
|
|
|
|
|
2011-12-20 10:57:44 +08:00
|
|
|
void __init
|
|
|
|
ftrace_set_early_filter(struct ftrace_ops *ops, char *buf, int enable);
|
|
|
|
|
ftrace: dynamic enabling/disabling of function calls
This patch adds a feature to dynamically replace the ftrace code
with the jmps to allow a kernel with ftrace configured to run
as fast as it can without it configured.
The way this works, is on bootup (if ftrace is enabled), a ftrace
function is registered to record the instruction pointer of all
places that call the function.
Later, if there's still any code to patch, a kthread is awoken
(rate limited to at most once a second) that performs a stop_machine,
and replaces all the code that was called with a jmp over the call
to ftrace. It only replaces what was found the previous time. Typically
the system reaches equilibrium quickly after bootup and there's no code
patching needed at all.
e.g.
call ftrace /* 5 bytes */
is replaced with
jmp 3f /* jmp is 2 bytes and we jump 3 forward */
3:
When we want to enable ftrace for function tracing, the IP recording
is removed, and stop_machine is called again to replace all the locations
of that were recorded back to the call of ftrace. When it is disabled,
we replace the code back to the jmp.
Allocation is done by the kthread. If the ftrace recording function is
called, and we don't have any record slots available, then we simply
skip that call. Once a second a new page (if needed) is allocated for
recording new ftrace function calls. A large batch is allocated at
boot up to get most of the calls there.
Because we do this via stop_machine, we don't have to worry about another
CPU executing a ftrace call as we modify it. But we do need to worry
about NMI's so all functions that might be called via nmi must be
annotated with notrace_nmi. When this code is configured in, the NMI code
will not call notrace.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2008-05-13 03:20:42 +08:00
|
|
|
/* defined in arch */
|
2008-05-13 03:20:43 +08:00
|
|
|
extern int ftrace_ip_converted(unsigned long ip);
|
2014-02-25 02:59:59 +08:00
|
|
|
extern int ftrace_dyn_arch_init(void);
|
2012-04-27 21:13:18 +08:00
|
|
|
extern void ftrace_replace_code(int enable);
|
2008-05-13 03:20:43 +08:00
|
|
|
extern int ftrace_update_ftrace_func(ftrace_func_t func);
|
|
|
|
extern void ftrace_caller(void);
|
2012-05-01 04:20:23 +08:00
|
|
|
extern void ftrace_regs_caller(void);
|
2008-05-13 03:20:43 +08:00
|
|
|
extern void ftrace_call(void);
|
2012-05-01 04:20:23 +08:00
|
|
|
extern void ftrace_regs_call(void);
|
2008-05-13 03:20:43 +08:00
|
|
|
extern void mcount_call(void);
|
2009-01-09 11:29:42 +08:00
|
|
|
|
2012-04-27 02:59:43 +08:00
|
|
|
void ftrace_modify_all_code(int command);
|
|
|
|
|
2009-01-09 11:29:42 +08:00
|
|
|
#ifndef FTRACE_ADDR
|
|
|
|
#define FTRACE_ADDR ((unsigned long)ftrace_caller)
|
|
|
|
#endif
|
2012-05-01 04:20:23 +08:00
|
|
|
|
ftrace: Optimize function graph to be called directly
Function graph tracing is a bit different than the function tracers, as
it is processed after either the ftrace_caller or ftrace_regs_caller
and we only have one place to modify the jump to ftrace_graph_caller,
the jump needs to happen after the restore of registeres.
The function graph tracer is dependent on the function tracer, where
even if the function graph tracing is going on by itself, the save and
restore of registers is still done for function tracing regardless of
if function tracing is happening, before it calls the function graph
code.
If there's no function tracing happening, it is possible to just call
the function graph tracer directly, and avoid the wasted effort to save
and restore regs for function tracing.
This requires adding new flags to the dyn_ftrace records:
FTRACE_FL_TRAMP
FTRACE_FL_TRAMP_EN
The first is set if the count for the record is one, and the ftrace_ops
associated to that record has its own trampoline. That way the mcount code
can call that trampoline directly.
In the future, trampolines can be added to arbitrary ftrace_ops, where you
can have two or more ftrace_ops registered to ftrace (like kprobes and perf)
and if they are not tracing the same functions, then instead of doing a
loop to check all registered ftrace_ops against their hashes, just call the
ftrace_ops trampoline directly, which would call the registered ftrace_ops
function directly.
Without this patch perf showed:
0.05% hackbench [kernel.kallsyms] [k] ftrace_caller
0.05% hackbench [kernel.kallsyms] [k] arch_local_irq_save
0.05% hackbench [kernel.kallsyms] [k] native_sched_clock
0.04% hackbench [kernel.kallsyms] [k] __buffer_unlock_commit
0.04% hackbench [kernel.kallsyms] [k] preempt_trace
0.04% hackbench [kernel.kallsyms] [k] prepare_ftrace_return
0.04% hackbench [kernel.kallsyms] [k] __this_cpu_preempt_check
0.04% hackbench [kernel.kallsyms] [k] ftrace_graph_caller
See that the ftrace_caller took up more time than the ftrace_graph_caller
did.
With this patch:
0.05% hackbench [kernel.kallsyms] [k] __buffer_unlock_commit
0.04% hackbench [kernel.kallsyms] [k] call_filter_check_discard
0.04% hackbench [kernel.kallsyms] [k] ftrace_graph_caller
0.04% hackbench [kernel.kallsyms] [k] sched_clock
The ftrace_caller is no where to be found and ftrace_graph_caller still
takes up the same percentage.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2014-05-07 09:56:17 +08:00
|
|
|
#ifndef FTRACE_GRAPH_ADDR
|
|
|
|
#define FTRACE_GRAPH_ADDR ((unsigned long)ftrace_graph_caller)
|
|
|
|
#endif
|
|
|
|
|
2012-05-01 04:20:23 +08:00
|
|
|
#ifndef FTRACE_REGS_ADDR
|
2012-09-28 16:15:17 +08:00
|
|
|
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
|
2012-05-01 04:20:23 +08:00
|
|
|
# define FTRACE_REGS_ADDR ((unsigned long)ftrace_regs_caller)
|
|
|
|
#else
|
|
|
|
# define FTRACE_REGS_ADDR FTRACE_ADDR
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2014-07-12 02:39:10 +08:00
|
|
|
/*
|
|
|
|
* If an arch would like functions that are only traced
|
|
|
|
* by the function graph tracer to jump directly to its own
|
|
|
|
* trampoline, then they can define FTRACE_GRAPH_TRAMP_ADDR
|
|
|
|
* to be that address to jump to.
|
|
|
|
*/
|
|
|
|
#ifndef FTRACE_GRAPH_TRAMP_ADDR
|
|
|
|
#define FTRACE_GRAPH_TRAMP_ADDR ((unsigned long) 0)
|
|
|
|
#endif
|
|
|
|
|
2008-11-26 04:07:04 +08:00
|
|
|
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
|
|
|
|
extern void ftrace_graph_caller(void);
|
2008-11-26 13:16:24 +08:00
|
|
|
extern int ftrace_enable_ftrace_graph_caller(void);
|
|
|
|
extern int ftrace_disable_ftrace_graph_caller(void);
|
|
|
|
#else
|
|
|
|
static inline int ftrace_enable_ftrace_graph_caller(void) { return 0; }
|
|
|
|
static inline int ftrace_disable_ftrace_graph_caller(void) { return 0; }
|
2008-11-16 13:02:06 +08:00
|
|
|
#endif
|
ftrace: user update and disable dynamic ftrace daemon
In dynamic ftrace, the mcount function starts off pointing to a stub
function that just returns.
On start up, the call to the stub is modified to point to a "record_ip"
function. The job of the record_ip function is to add the function to
a pre-allocated hash list. If the function is already there, it simply is
ignored, otherwise it is added to the list.
Later, a ftraced daemon wakes up and calls kstop_machine if any functions
have been recorded, and changes the calls to the recorded functions to
a simple nop. If no functions were recorded, the daemon goes back to sleep.
The daemon wakes up once a second to see if it needs to update any newly
recorded functions into nops. Usually it does not, but if a lot of code
has been executed for the first time in the kernel, the ftraced daemon
will call kstop_machine to update those into nops.
The problem currently is that there's no way to stop the daemon from doing
this, and it can cause unneeded latencies (800us which for some is bothersome).
This patch adds a new file /debugfs/tracing/ftraced_enabled. If the daemon
is active, reading this will return "enabled\n" and "disabled\n" when the
daemon is not running. To disable the daemon, the user can echo "0" or
"disable" into this file, and "1" or "enable" to re-enable the daemon.
Since the daemon is used to convert the functions into nops to increase
the performance of the system, I also added that anytime something is
written into the ftraced_enabled file, kstop_machine will run if there
are new functions that have been detected that need to be converted.
This way the user can disable the daemon but still be able to control the
conversion of the mcount calls to nops by simply,
"echo 0 > /debugfs/tracing/ftraced_enabled"
when they need to do more conversions.
To see the number of converted functions:
"cat /debugfs/tracing/dyn_ftrace_total_info"
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2008-05-28 08:48:37 +08:00
|
|
|
|
2008-11-15 08:21:19 +08:00
|
|
|
/**
|
2009-02-06 17:33:27 +08:00
|
|
|
* ftrace_make_nop - convert code into nop
|
2008-11-15 08:21:19 +08:00
|
|
|
* @mod: module structure if called by module load initialization
|
|
|
|
* @rec: the mcount call site record
|
|
|
|
* @addr: the address that the call site should be calling
|
|
|
|
*
|
|
|
|
* This is a very sensitive operation and great care needs
|
|
|
|
* to be taken by the arch. The operation should carefully
|
|
|
|
* read the location, check to see if what is read is indeed
|
|
|
|
* what we expect it to be, and then on success of the compare,
|
|
|
|
* it should write to the location.
|
|
|
|
*
|
|
|
|
* The code segment at @rec->ip should be a caller to @addr
|
|
|
|
*
|
|
|
|
* Return must be:
|
|
|
|
* 0 on success
|
|
|
|
* -EFAULT on error reading the location
|
|
|
|
* -EINVAL on a failed compare of the contents
|
|
|
|
* -EPERM on error writing to the location
|
|
|
|
* Any other value will be considered a failure.
|
|
|
|
*/
|
|
|
|
extern int ftrace_make_nop(struct module *mod,
|
|
|
|
struct dyn_ftrace *rec, unsigned long addr);
|
2008-10-31 12:03:22 +08:00
|
|
|
|
2008-10-23 21:32:59 +08:00
|
|
|
/**
|
2008-11-15 08:21:19 +08:00
|
|
|
* ftrace_make_call - convert a nop call site into a call to addr
|
|
|
|
* @rec: the mcount call site record
|
|
|
|
* @addr: the address that the call site should call
|
2008-10-23 21:32:59 +08:00
|
|
|
*
|
|
|
|
* This is a very sensitive operation and great care needs
|
|
|
|
* to be taken by the arch. The operation should carefully
|
|
|
|
* read the location, check to see if what is read is indeed
|
|
|
|
* what we expect it to be, and then on success of the compare,
|
|
|
|
* it should write to the location.
|
|
|
|
*
|
2008-11-15 08:21:19 +08:00
|
|
|
* The code segment at @rec->ip should be a nop
|
|
|
|
*
|
2008-10-23 21:32:59 +08:00
|
|
|
* Return must be:
|
|
|
|
* 0 on success
|
|
|
|
* -EFAULT on error reading the location
|
|
|
|
* -EINVAL on a failed compare of the contents
|
|
|
|
* -EPERM on error writing to the location
|
|
|
|
* Any other value will be considered a failure.
|
|
|
|
*/
|
2008-11-15 08:21:19 +08:00
|
|
|
extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);
|
|
|
|
|
2012-09-28 16:15:17 +08:00
|
|
|
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
|
2012-05-01 04:20:23 +08:00
|
|
|
/**
|
|
|
|
* ftrace_modify_call - convert from one addr to another (no nop)
|
|
|
|
* @rec: the mcount call site record
|
|
|
|
* @old_addr: the address expected to be currently called to
|
|
|
|
* @addr: the address to change to
|
|
|
|
*
|
|
|
|
* This is a very sensitive operation and great care needs
|
|
|
|
* to be taken by the arch. The operation should carefully
|
|
|
|
* read the location, check to see if what is read is indeed
|
|
|
|
* what we expect it to be, and then on success of the compare,
|
|
|
|
* it should write to the location.
|
|
|
|
*
|
|
|
|
* The code segment at @rec->ip should be a caller to @old_addr
|
|
|
|
*
|
|
|
|
* Return must be:
|
|
|
|
* 0 on success
|
|
|
|
* -EFAULT on error reading the location
|
|
|
|
* -EINVAL on a failed compare of the contents
|
|
|
|
* -EPERM on error writing to the location
|
|
|
|
* Any other value will be considered a failure.
|
|
|
|
*/
|
|
|
|
extern int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
|
|
|
|
unsigned long addr);
|
|
|
|
#else
|
|
|
|
/* Should never be called */
|
|
|
|
static inline int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
|
|
|
|
unsigned long addr)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-11-15 08:21:19 +08:00
|
|
|
/* May be defined in arch */
|
|
|
|
extern int ftrace_arch_read_dyn_info(char *buf, int size);
|
2008-10-23 21:32:59 +08:00
|
|
|
|
2008-06-22 02:17:53 +08:00
|
|
|
extern int skip_trace(unsigned long ip);
|
2014-04-24 22:40:12 +08:00
|
|
|
extern void ftrace_module_init(struct module *mod);
|
2016-02-17 06:32:33 +08:00
|
|
|
extern void ftrace_module_enable(struct module *mod);
|
2016-01-06 09:32:47 +08:00
|
|
|
extern void ftrace_release_mod(struct module *mod);
|
2008-06-22 02:17:53 +08:00
|
|
|
|
2008-09-06 13:06:03 +08:00
|
|
|
extern void ftrace_disable_daemon(void);
|
|
|
|
extern void ftrace_enable_daemon(void);
|
2012-06-07 01:45:31 +08:00
|
|
|
#else /* CONFIG_DYNAMIC_FTRACE */
|
2010-05-04 23:24:01 +08:00
|
|
|
static inline int skip_trace(unsigned long ip) { return 0; }
|
|
|
|
static inline int ftrace_force_update(void) { return 0; }
|
|
|
|
static inline void ftrace_disable_daemon(void) { }
|
|
|
|
static inline void ftrace_enable_daemon(void) { }
|
2016-02-17 06:32:33 +08:00
|
|
|
static inline void ftrace_module_init(struct module *mod) { }
|
|
|
|
static inline void ftrace_module_enable(struct module *mod) { }
|
|
|
|
static inline void ftrace_release_mod(struct module *mod) { }
|
2013-10-24 21:34:18 +08:00
|
|
|
static inline __init int register_ftrace_command(struct ftrace_func_command *cmd)
|
2009-02-14 13:40:25 +08:00
|
|
|
{
|
2009-02-17 18:47:39 +08:00
|
|
|
return -EINVAL;
|
2009-02-14 13:40:25 +08:00
|
|
|
}
|
2013-10-24 21:34:18 +08:00
|
|
|
static inline __init int unregister_ftrace_command(char *cmd_name)
|
2009-02-14 13:40:25 +08:00
|
|
|
{
|
2009-02-17 18:47:39 +08:00
|
|
|
return -EINVAL;
|
2009-02-14 13:40:25 +08:00
|
|
|
}
|
2013-01-10 07:09:20 +08:00
|
|
|
static inline int ftrace_text_reserved(const void *start, const void *end)
|
2010-02-03 05:49:11 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2012-06-07 01:45:31 +08:00
|
|
|
static inline unsigned long ftrace_location(unsigned long ip)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2011-12-20 03:41:25 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Again users of functions that have ftrace_ops may not
|
|
|
|
* have them defined when ftrace is not enabled, but these
|
|
|
|
* functions may still be called. Use a macro instead of inline.
|
|
|
|
*/
|
|
|
|
#define ftrace_regex_open(ops, flag, inod, file) ({ -ENODEV; })
|
2012-01-08 06:26:49 +08:00
|
|
|
#define ftrace_set_early_filter(ops, buf, enable) do { } while (0)
|
2012-06-05 18:28:08 +08:00
|
|
|
#define ftrace_set_filter_ip(ops, ip, remove, reset) ({ -ENODEV; })
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 22:51:54 +08:00
|
|
|
#define ftrace_set_filter(ops, buf, len, reset) ({ -ENODEV; })
|
|
|
|
#define ftrace_set_notrace(ops, buf, len, reset) ({ -ENODEV; })
|
|
|
|
#define ftrace_free_filter(ops) do { } while (0)
|
2016-11-16 04:31:20 +08:00
|
|
|
#define ftrace_ops_set_global_filter(ops) do { } while (0)
|
2011-12-20 03:41:25 +08:00
|
|
|
|
|
|
|
static inline ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
|
|
|
|
size_t cnt, loff_t *ppos) { return -ENODEV; }
|
|
|
|
static inline ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
|
|
|
|
size_t cnt, loff_t *ppos) { return -ENODEV; }
|
|
|
|
static inline int
|
|
|
|
ftrace_regex_release(struct inode *inode, struct file *file) { return -ENODEV; }
|
2014-11-19 10:14:11 +08:00
|
|
|
|
|
|
|
static inline bool is_ftrace_trampoline(unsigned long addr)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2008-06-22 02:17:53 +08:00
|
|
|
#endif /* CONFIG_DYNAMIC_FTRACE */
|
2008-05-13 03:20:42 +08:00
|
|
|
|
2008-05-13 03:20:49 +08:00
|
|
|
/* totally disable ftrace - can not re-enable after this */
|
|
|
|
void ftrace_kill(void);
|
|
|
|
|
2008-05-13 03:20:43 +08:00
|
|
|
static inline void tracer_disable(void)
|
|
|
|
{
|
2008-10-07 07:06:12 +08:00
|
|
|
#ifdef CONFIG_FUNCTION_TRACER
|
2008-05-13 03:20:43 +08:00
|
|
|
ftrace_enabled = 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-08-18 16:24:56 +08:00
|
|
|
/*
|
|
|
|
* Ftrace disable/restore without lock. Some synchronization mechanism
|
2008-08-15 15:40:25 +08:00
|
|
|
* must be used to prevent ftrace_enabled to be changed between
|
2008-08-18 16:24:56 +08:00
|
|
|
* disable/restore.
|
|
|
|
*/
|
2008-08-15 15:40:25 +08:00
|
|
|
static inline int __ftrace_enabled_save(void)
|
|
|
|
{
|
2008-10-07 07:06:12 +08:00
|
|
|
#ifdef CONFIG_FUNCTION_TRACER
|
2008-08-15 15:40:25 +08:00
|
|
|
int saved_ftrace_enabled = ftrace_enabled;
|
|
|
|
ftrace_enabled = 0;
|
|
|
|
return saved_ftrace_enabled;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void __ftrace_enabled_restore(int enabled)
|
|
|
|
{
|
2008-10-07 07:06:12 +08:00
|
|
|
#ifdef CONFIG_FUNCTION_TRACER
|
2008-08-15 15:40:25 +08:00
|
|
|
ftrace_enabled = enabled;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-05-20 19:31:04 +08:00
|
|
|
/* All archs should have this, but we define it for consistency */
|
|
|
|
#ifndef ftrace_return_address0
|
|
|
|
# define ftrace_return_address0 __builtin_return_address(0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Archs may use other ways for ADDR1 and beyond */
|
|
|
|
#ifndef ftrace_return_address
|
2009-02-28 04:30:03 +08:00
|
|
|
# ifdef CONFIG_FRAME_POINTER
|
2014-05-20 19:31:04 +08:00
|
|
|
# define ftrace_return_address(n) __builtin_return_address(n)
|
2009-02-28 04:30:03 +08:00
|
|
|
# else
|
2014-05-20 19:31:04 +08:00
|
|
|
# define ftrace_return_address(n) 0UL
|
2009-02-28 04:30:03 +08:00
|
|
|
# endif
|
2014-05-20 19:31:04 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define CALLER_ADDR0 ((unsigned long)ftrace_return_address0)
|
|
|
|
#define CALLER_ADDR1 ((unsigned long)ftrace_return_address(1))
|
|
|
|
#define CALLER_ADDR2 ((unsigned long)ftrace_return_address(2))
|
|
|
|
#define CALLER_ADDR3 ((unsigned long)ftrace_return_address(3))
|
|
|
|
#define CALLER_ADDR4 ((unsigned long)ftrace_return_address(4))
|
|
|
|
#define CALLER_ADDR5 ((unsigned long)ftrace_return_address(5))
|
|
|
|
#define CALLER_ADDR6 ((unsigned long)ftrace_return_address(6))
|
2008-05-13 03:20:42 +08:00
|
|
|
|
2016-02-26 21:54:56 +08:00
|
|
|
static inline unsigned long get_lock_parent_ip(void)
|
|
|
|
{
|
|
|
|
unsigned long addr = CALLER_ADDR0;
|
|
|
|
|
|
|
|
if (!in_lock_functions(addr))
|
|
|
|
return addr;
|
|
|
|
addr = CALLER_ADDR1;
|
|
|
|
if (!in_lock_functions(addr))
|
|
|
|
return addr;
|
|
|
|
return CALLER_ADDR2;
|
|
|
|
}
|
|
|
|
|
2008-05-13 03:20:42 +08:00
|
|
|
#ifdef CONFIG_IRQSOFF_TRACER
|
2008-02-25 20:38:05 +08:00
|
|
|
extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
|
|
|
|
extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
|
2008-05-13 03:20:42 +08:00
|
|
|
#else
|
2010-05-04 23:24:01 +08:00
|
|
|
static inline void time_hardirqs_on(unsigned long a0, unsigned long a1) { }
|
|
|
|
static inline void time_hardirqs_off(unsigned long a0, unsigned long a1) { }
|
2008-05-13 03:20:42 +08:00
|
|
|
#endif
|
|
|
|
|
2008-05-13 03:20:42 +08:00
|
|
|
#ifdef CONFIG_PREEMPT_TRACER
|
2008-02-25 20:38:05 +08:00
|
|
|
extern void trace_preempt_on(unsigned long a0, unsigned long a1);
|
|
|
|
extern void trace_preempt_off(unsigned long a0, unsigned long a1);
|
2008-05-13 03:20:42 +08:00
|
|
|
#else
|
2012-05-07 10:36:00 +08:00
|
|
|
/*
|
|
|
|
* Use defines instead of static inlines because some arches will make code out
|
|
|
|
* of the CALLER_ADDR, when we really want these to be a real nop.
|
|
|
|
*/
|
|
|
|
# define trace_preempt_on(a0, a1) do { } while (0)
|
|
|
|
# define trace_preempt_off(a0, a1) do { } while (0)
|
2008-05-13 03:20:42 +08:00
|
|
|
#endif
|
|
|
|
|
2008-08-15 03:45:08 +08:00
|
|
|
#ifdef CONFIG_FTRACE_MCOUNT_RECORD
|
|
|
|
extern void ftrace_init(void);
|
|
|
|
#else
|
|
|
|
static inline void ftrace_init(void) { }
|
|
|
|
#endif
|
|
|
|
|
2008-11-26 07:57:25 +08:00
|
|
|
/*
|
|
|
|
* Structure that defines an entry function trace.
|
2016-06-29 18:56:48 +08:00
|
|
|
* It's already packed but the attribute "packed" is needed
|
|
|
|
* to remove extra padding at the end.
|
2008-11-26 07:57:25 +08:00
|
|
|
*/
|
|
|
|
struct ftrace_graph_ent {
|
|
|
|
unsigned long func; /* Current function */
|
|
|
|
int depth;
|
2016-06-29 18:56:48 +08:00
|
|
|
} __packed;
|
2008-08-02 00:26:41 +08:00
|
|
|
|
2008-11-11 14:03:45 +08:00
|
|
|
/*
|
|
|
|
* Structure that defines a return function trace.
|
2016-06-29 18:56:48 +08:00
|
|
|
* It's already packed but the attribute "packed" is needed
|
|
|
|
* to remove extra padding at the end.
|
2008-11-11 14:03:45 +08:00
|
|
|
*/
|
2008-11-26 04:07:04 +08:00
|
|
|
struct ftrace_graph_ret {
|
2008-11-11 14:03:45 +08:00
|
|
|
unsigned long func; /* Current function */
|
2008-11-17 10:22:41 +08:00
|
|
|
/* Number of functions that overran the depth limit for current task */
|
|
|
|
unsigned long overrun;
|
2016-06-29 18:56:48 +08:00
|
|
|
unsigned long long calltime;
|
|
|
|
unsigned long long rettime;
|
2008-11-26 07:57:25 +08:00
|
|
|
int depth;
|
2016-06-29 18:56:48 +08:00
|
|
|
} __packed;
|
2008-11-11 14:03:45 +08:00
|
|
|
|
2010-04-03 01:01:22 +08:00
|
|
|
/* Type of the callback handlers for tracing function graph*/
|
|
|
|
typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */
|
|
|
|
typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */
|
|
|
|
|
2008-11-26 04:07:04 +08:00
|
|
|
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
|
2008-12-06 10:40:00 +08:00
|
|
|
|
2009-03-26 08:55:00 +08:00
|
|
|
/* for init task */
|
2009-04-08 13:05:43 +08:00
|
|
|
#define INIT_FTRACE_GRAPH .ret_stack = NULL,
|
2009-03-26 08:55:00 +08:00
|
|
|
|
2009-02-10 02:54:03 +08:00
|
|
|
/*
|
|
|
|
* Stack of return addresses for functions
|
|
|
|
* of a thread.
|
|
|
|
* Used in struct thread_info
|
|
|
|
*/
|
|
|
|
struct ftrace_ret_stack {
|
|
|
|
unsigned long ret;
|
|
|
|
unsigned long func;
|
|
|
|
unsigned long long calltime;
|
2016-08-31 10:55:29 +08:00
|
|
|
#ifdef CONFIG_FUNCTION_PROFILER
|
2009-03-25 11:17:58 +08:00
|
|
|
unsigned long long subtime;
|
2016-08-31 10:55:29 +08:00
|
|
|
#endif
|
2016-08-19 19:52:56 +08:00
|
|
|
#ifdef HAVE_FUNCTION_GRAPH_FP_TEST
|
function-graph: add stack frame test
In case gcc does something funny with the stack frames, or the return
from function code, we would like to detect that.
An arch may implement passing of a variable that is unique to the
function and can be saved on entering a function and can be tested
when exiting the function. Usually the frame pointer can be used for
this purpose.
This patch also implements this for x86. Where it passes in the stack
frame of the parent function, and will test that frame on exit.
There was a case in x86_32 with optimize for size (-Os) where, for a
few functions, gcc would align the stack frame and place a copy of the
return address into it. The function graph tracer modified the copy and
not the actual return address. On return from the funtion, it did not go
to the tracer hook, but returned to the parent. This broke the function
graph tracer, because the return of the parent (where gcc did not do
this funky manipulation) returned to the location that the child function
was suppose to. This caused strange kernel crashes.
This test detected the problem and pointed out where the issue was.
This modifies the parameters of one of the functions that the arch
specific code calls, so it includes changes to arch code to accommodate
the new prototype.
Note, I notice that the parsic arch implements its own push_return_trace.
This is now a generic function and the ftrace_push_return_trace should be
used instead. This patch does not touch that code.
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-19 00:45:08 +08:00
|
|
|
unsigned long fp;
|
2016-08-19 19:52:56 +08:00
|
|
|
#endif
|
2016-08-19 19:52:57 +08:00
|
|
|
#ifdef HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
|
|
|
|
unsigned long *retp;
|
|
|
|
#endif
|
2009-02-10 02:54:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Primary handler of a function return.
|
|
|
|
* It relays on ftrace_return_to_handler.
|
|
|
|
* Defined in entry_32/64.S
|
|
|
|
*/
|
|
|
|
extern void return_to_handler(void);
|
|
|
|
|
|
|
|
extern int
|
function-graph: add stack frame test
In case gcc does something funny with the stack frames, or the return
from function code, we would like to detect that.
An arch may implement passing of a variable that is unique to the
function and can be saved on entering a function and can be tested
when exiting the function. Usually the frame pointer can be used for
this purpose.
This patch also implements this for x86. Where it passes in the stack
frame of the parent function, and will test that frame on exit.
There was a case in x86_32 with optimize for size (-Os) where, for a
few functions, gcc would align the stack frame and place a copy of the
return address into it. The function graph tracer modified the copy and
not the actual return address. On return from the funtion, it did not go
to the tracer hook, but returned to the parent. This broke the function
graph tracer, because the return of the parent (where gcc did not do
this funky manipulation) returned to the location that the child function
was suppose to. This caused strange kernel crashes.
This test detected the problem and pointed out where the issue was.
This modifies the parameters of one of the functions that the arch
specific code calls, so it includes changes to arch code to accommodate
the new prototype.
Note, I notice that the parsic arch implements its own push_return_trace.
This is now a generic function and the ftrace_push_return_trace should be
used instead. This patch does not touch that code.
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-19 00:45:08 +08:00
|
|
|
ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
|
2016-08-19 19:52:57 +08:00
|
|
|
unsigned long frame_pointer, unsigned long *retp);
|
2009-02-10 02:54:03 +08:00
|
|
|
|
2016-08-19 19:52:58 +08:00
|
|
|
unsigned long ftrace_graph_ret_addr(struct task_struct *task, int *idx,
|
|
|
|
unsigned long ret, unsigned long *retp);
|
|
|
|
|
2008-12-06 10:40:00 +08:00
|
|
|
/*
|
|
|
|
* Sometimes we don't want to trace a function with the function
|
|
|
|
* graph tracer but we want them to keep traced by the usual function
|
|
|
|
* tracer if the function graph tracer is not configured.
|
|
|
|
*/
|
|
|
|
#define __notrace_funcgraph notrace
|
|
|
|
|
2013-10-14 16:24:26 +08:00
|
|
|
#define FTRACE_NOTRACE_DEPTH 65536
|
2008-11-23 13:22:56 +08:00
|
|
|
#define FTRACE_RETFUNC_DEPTH 50
|
|
|
|
#define FTRACE_RETSTACK_ALLOC_SIZE 32
|
2008-11-26 07:57:25 +08:00
|
|
|
extern int register_ftrace_graph(trace_func_graph_ret_t retfunc,
|
|
|
|
trace_func_graph_ent_t entryfunc);
|
|
|
|
|
2014-06-25 22:39:46 +08:00
|
|
|
extern bool ftrace_graph_is_dead(void);
|
2008-12-03 12:50:02 +08:00
|
|
|
extern void ftrace_graph_stop(void);
|
|
|
|
|
2008-11-26 07:57:25 +08:00
|
|
|
/* The current handlers in use */
|
|
|
|
extern trace_func_graph_ret_t ftrace_graph_return;
|
|
|
|
extern trace_func_graph_ent_t ftrace_graph_entry;
|
2008-11-11 14:03:45 +08:00
|
|
|
|
2008-11-26 04:07:04 +08:00
|
|
|
extern void unregister_ftrace_graph(void);
|
2008-11-23 13:22:56 +08:00
|
|
|
|
2008-11-26 04:07:04 +08:00
|
|
|
extern void ftrace_graph_init_task(struct task_struct *t);
|
|
|
|
extern void ftrace_graph_exit_task(struct task_struct *t);
|
ftrace: Fix memory leak with function graph and cpu hotplug
When the fuction graph tracer starts, it needs to make a special
stack for each task to save the real return values of the tasks.
All running tasks have this stack created, as well as any new
tasks.
On CPU hot plug, the new idle task will allocate a stack as well
when init_idle() is called. The problem is that cpu hotplug does
not create a new idle_task. Instead it uses the idle task that
existed when the cpu went down.
ftrace_graph_init_task() will add a new ret_stack to the task
that is given to it. Because a clone will make the task
have a stack of its parent it does not check if the task's
ret_stack is already NULL or not. When the CPU hotplug code
starts a CPU up again, it will allocate a new stack even
though one already existed for it.
The solution is to treat the idle_task specially. In fact, the
function_graph code already does, just not at init_idle().
Instead of using the ftrace_graph_init_task() for the idle task,
which that function expects the task to be a clone, have a
separate ftrace_graph_init_idle_task(). Also, we will create a
per_cpu ret_stack that is used by the idle task. When we call
ftrace_graph_init_idle_task() it will check if the idle task's
ret_stack is NULL, if it is, then it will assign it the per_cpu
ret_stack.
Reported-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Suggested-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stable Tree <stable@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2011-02-11 10:26:13 +08:00
|
|
|
extern void ftrace_graph_init_idle_task(struct task_struct *t, int cpu);
|
2008-12-05 06:51:23 +08:00
|
|
|
|
|
|
|
static inline int task_curr_ret_stack(struct task_struct *t)
|
|
|
|
{
|
|
|
|
return t->curr_ret_stack;
|
|
|
|
}
|
2008-12-06 10:43:41 +08:00
|
|
|
|
|
|
|
static inline void pause_graph_tracing(void)
|
|
|
|
{
|
|
|
|
atomic_inc(¤t->tracing_graph_pause);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void unpause_graph_tracing(void)
|
|
|
|
{
|
|
|
|
atomic_dec(¤t->tracing_graph_pause);
|
|
|
|
}
|
2009-03-26 08:55:00 +08:00
|
|
|
#else /* !CONFIG_FUNCTION_GRAPH_TRACER */
|
2008-12-06 10:40:00 +08:00
|
|
|
|
|
|
|
#define __notrace_funcgraph
|
2009-03-26 08:55:00 +08:00
|
|
|
#define INIT_FTRACE_GRAPH
|
2008-12-06 10:40:00 +08:00
|
|
|
|
2008-11-26 04:07:04 +08:00
|
|
|
static inline void ftrace_graph_init_task(struct task_struct *t) { }
|
|
|
|
static inline void ftrace_graph_exit_task(struct task_struct *t) { }
|
ftrace: Fix memory leak with function graph and cpu hotplug
When the fuction graph tracer starts, it needs to make a special
stack for each task to save the real return values of the tasks.
All running tasks have this stack created, as well as any new
tasks.
On CPU hot plug, the new idle task will allocate a stack as well
when init_idle() is called. The problem is that cpu hotplug does
not create a new idle_task. Instead it uses the idle task that
existed when the cpu went down.
ftrace_graph_init_task() will add a new ret_stack to the task
that is given to it. Because a clone will make the task
have a stack of its parent it does not check if the task's
ret_stack is already NULL or not. When the CPU hotplug code
starts a CPU up again, it will allocate a new stack even
though one already existed for it.
The solution is to treat the idle_task specially. In fact, the
function_graph code already does, just not at init_idle().
Instead of using the ftrace_graph_init_task() for the idle task,
which that function expects the task to be a clone, have a
separate ftrace_graph_init_idle_task(). Also, we will create a
per_cpu ret_stack that is used by the idle task. When we call
ftrace_graph_init_idle_task() it will check if the idle task's
ret_stack is NULL, if it is, then it will assign it the per_cpu
ret_stack.
Reported-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Suggested-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stable Tree <stable@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2011-02-11 10:26:13 +08:00
|
|
|
static inline void ftrace_graph_init_idle_task(struct task_struct *t, int cpu) { }
|
2008-12-05 06:51:23 +08:00
|
|
|
|
2010-04-03 01:01:22 +08:00
|
|
|
static inline int register_ftrace_graph(trace_func_graph_ret_t retfunc,
|
|
|
|
trace_func_graph_ent_t entryfunc)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
static inline void unregister_ftrace_graph(void) { }
|
|
|
|
|
2008-12-05 06:51:23 +08:00
|
|
|
static inline int task_curr_ret_stack(struct task_struct *tsk)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2008-12-06 10:43:41 +08:00
|
|
|
|
2016-08-19 19:52:58 +08:00
|
|
|
static inline unsigned long
|
|
|
|
ftrace_graph_ret_addr(struct task_struct *task, int *idx, unsigned long ret,
|
|
|
|
unsigned long *retp)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-12-06 10:43:41 +08:00
|
|
|
static inline void pause_graph_tracing(void) { }
|
|
|
|
static inline void unpause_graph_tracing(void) { }
|
2009-03-26 08:55:00 +08:00
|
|
|
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
|
2008-11-11 14:03:45 +08:00
|
|
|
|
2008-12-04 04:36:57 +08:00
|
|
|
#ifdef CONFIG_TRACING
|
|
|
|
|
|
|
|
/* flags for current->trace */
|
|
|
|
enum {
|
|
|
|
TSK_TRACE_FL_TRACE_BIT = 0,
|
|
|
|
TSK_TRACE_FL_GRAPH_BIT = 1,
|
|
|
|
};
|
|
|
|
enum {
|
|
|
|
TSK_TRACE_FL_TRACE = 1 << TSK_TRACE_FL_TRACE_BIT,
|
|
|
|
TSK_TRACE_FL_GRAPH = 1 << TSK_TRACE_FL_GRAPH_BIT,
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void set_tsk_trace_trace(struct task_struct *tsk)
|
|
|
|
{
|
|
|
|
set_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void clear_tsk_trace_trace(struct task_struct *tsk)
|
|
|
|
{
|
|
|
|
clear_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int test_tsk_trace_trace(struct task_struct *tsk)
|
|
|
|
{
|
|
|
|
return tsk->trace & TSK_TRACE_FL_TRACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void set_tsk_trace_graph(struct task_struct *tsk)
|
|
|
|
{
|
|
|
|
set_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void clear_tsk_trace_graph(struct task_struct *tsk)
|
|
|
|
{
|
|
|
|
clear_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int test_tsk_trace_graph(struct task_struct *tsk)
|
|
|
|
{
|
|
|
|
return tsk->trace & TSK_TRACE_FL_GRAPH;
|
|
|
|
}
|
|
|
|
|
2010-04-19 01:08:41 +08:00
|
|
|
enum ftrace_dump_mode;
|
|
|
|
|
|
|
|
extern enum ftrace_dump_mode ftrace_dump_on_oops;
|
2014-12-13 11:27:10 +08:00
|
|
|
extern int tracepoint_printk;
|
2009-03-05 17:28:45 +08:00
|
|
|
|
2013-06-15 04:21:43 +08:00
|
|
|
extern void disable_trace_on_warning(void);
|
|
|
|
extern int __disable_trace_on_warning;
|
|
|
|
|
tracing: add same level recursion detection
The tracing infrastructure allows for recursion. That is, an interrupt
may interrupt the act of tracing an event, and that interrupt may very well
perform its own trace. This is a recursive trace, and is fine to do.
The problem arises when there is a bug, and the utility doing the trace
calls something that recurses back into the tracer. This recursion is not
caused by an external event like an interrupt, but by code that is not
expected to recurse. The result could be a lockup.
This patch adds a bitmask to the task structure that keeps track
of the trace recursion. To find the interrupt depth, the following
algorithm is used:
level = hardirq_count() + softirq_count() + in_nmi;
Here, level will be the depth of interrutps and softirqs, and even handles
the nmi. Then the corresponding bit is set in the recursion bitmask.
If the bit was already set, we know we had a recursion at the same level
and we warn about it and fail the writing to the buffer.
After the data has been committed to the buffer, we clear the bit.
No atomics are needed. The only races are with interrupts and they reset
the bitmask before returning anywy.
[ Impact: detect same irq level trace recursion ]
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-04-17 09:41:52 +08:00
|
|
|
#ifdef CONFIG_PREEMPT
|
|
|
|
#define INIT_TRACE_RECURSION .trace_recursion = 0,
|
|
|
|
#endif
|
|
|
|
|
2016-11-24 04:52:45 +08:00
|
|
|
int tracepoint_printk_sysctl(struct ctl_table *table, int write,
|
|
|
|
void __user *buffer, size_t *lenp,
|
|
|
|
loff_t *ppos);
|
|
|
|
|
2013-06-15 04:21:43 +08:00
|
|
|
#else /* CONFIG_TRACING */
|
|
|
|
static inline void disable_trace_on_warning(void) { }
|
2008-12-04 04:36:57 +08:00
|
|
|
#endif /* CONFIG_TRACING */
|
|
|
|
|
tracing: add same level recursion detection
The tracing infrastructure allows for recursion. That is, an interrupt
may interrupt the act of tracing an event, and that interrupt may very well
perform its own trace. This is a recursive trace, and is fine to do.
The problem arises when there is a bug, and the utility doing the trace
calls something that recurses back into the tracer. This recursion is not
caused by an external event like an interrupt, but by code that is not
expected to recurse. The result could be a lockup.
This patch adds a bitmask to the task structure that keeps track
of the trace recursion. To find the interrupt depth, the following
algorithm is used:
level = hardirq_count() + softirq_count() + in_nmi;
Here, level will be the depth of interrutps and softirqs, and even handles
the nmi. Then the corresponding bit is set in the recursion bitmask.
If the bit was already set, we know we had a recursion at the same level
and we warn about it and fail the writing to the buffer.
After the data has been committed to the buffer, we clear the bit.
No atomics are needed. The only races are with interrupts and they reset
the bitmask before returning anywy.
[ Impact: detect same irq level trace recursion ]
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-04-17 09:41:52 +08:00
|
|
|
#ifndef INIT_TRACE_RECURSION
|
|
|
|
#define INIT_TRACE_RECURSION
|
|
|
|
#endif
|
2009-01-19 17:31:01 +08:00
|
|
|
|
2010-01-26 17:40:03 +08:00
|
|
|
#ifdef CONFIG_FTRACE_SYSCALLS
|
|
|
|
|
|
|
|
unsigned long arch_syscall_addr(int nr);
|
|
|
|
|
|
|
|
#endif /* CONFIG_FTRACE_SYSCALLS */
|
|
|
|
|
2008-05-13 03:20:42 +08:00
|
|
|
#endif /* _LINUX_FTRACE_H */
|