aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/ftrace.h
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2008-05-12 15:20:42 -0400
committerThomas Gleixner <tglx@linutronix.de>2008-05-23 14:33:09 -0400
commit3d0833953e1b98b79ddf491dd49229eef9baeac1 (patch)
tree3520cda824bdb58e47ce3e9f43d68249d5cc1a12 /include/linux/ftrace.h
parent6cd8a4bb2f97527a9ceb30bc77ea4e959c6a95e3 (diff)
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>
Diffstat (limited to 'include/linux/ftrace.h')
-rw-r--r--include/linux/ftrace.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
index 740c97dcf9cb..90dbc0ee2046 100644
--- a/include/linux/ftrace.h
+++ b/include/linux/ftrace.h
@@ -32,6 +32,24 @@ extern void mcount(void);
32# define clear_ftrace_function(ops) do { } while (0) 32# define clear_ftrace_function(ops) do { } while (0)
33#endif /* CONFIG_FTRACE */ 33#endif /* CONFIG_FTRACE */
34 34
35#ifdef CONFIG_DYNAMIC_FTRACE
36# define FTRACE_HASHBITS 10
37# define FTRACE_HASHSIZE (1<<FTRACE_HASHBITS)
38
39struct dyn_ftrace {
40 struct hlist_node node;
41 unsigned long ip;
42};
43
44/* defined in arch */
45extern struct dyn_ftrace *
46ftrace_alloc_shutdown_node(unsigned long ip);
47extern int ftrace_shutdown_arch_init(void);
48extern void ftrace_code_disable(struct dyn_ftrace *rec);
49extern void ftrace_startup_code(void);
50extern void ftrace_shutdown_code(void);
51extern void ftrace_shutdown_replenish(void);
52#endif
35 53
36#ifdef CONFIG_FRAME_POINTER 54#ifdef CONFIG_FRAME_POINTER
37/* TODO: need to fix this for ARM */ 55/* TODO: need to fix this for ARM */