diff options
| -rw-r--r-- | kernel/trace/Kconfig | 13 | ||||
| -rw-r--r-- | kernel/trace/Makefile | 1 | ||||
| -rw-r--r-- | kernel/trace/trace_functions.c | 73 |
3 files changed, 87 insertions, 0 deletions
diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig index ce70677afbf9..1399f372b5dc 100644 --- a/kernel/trace/Kconfig +++ b/kernel/trace/Kconfig | |||
| @@ -8,3 +8,16 @@ config TRACING | |||
| 8 | bool | 8 | bool |
| 9 | select DEBUG_FS | 9 | select DEBUG_FS |
| 10 | 10 | ||
| 11 | config FTRACE | ||
| 12 | bool "Kernel Function Tracer" | ||
| 13 | depends on DEBUG_KERNEL && HAVE_FTRACE | ||
| 14 | select FRAME_POINTER | ||
| 15 | select TRACING | ||
| 16 | help | ||
| 17 | Enable the kernel to trace every kernel function. This is done | ||
| 18 | by using a compiler feature to insert a small, 5-byte No-Operation | ||
| 19 | instruction to the beginning of every kernel function, which NOP | ||
| 20 | sequence is then dynamically patched into a tracer call when | ||
| 21 | tracing is enabled by the administrator. If it's runtime disabled | ||
| 22 | (the bootup default), then the overhead of the instructions is very | ||
| 23 | small and not measurable even in micro-benchmarks. | ||
diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile index 7af403175255..6bb5e50b4a40 100644 --- a/kernel/trace/Makefile +++ b/kernel/trace/Makefile | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | obj-$(CONFIG_FTRACE) += libftrace.o | 1 | obj-$(CONFIG_FTRACE) += libftrace.o |
| 2 | 2 | ||
| 3 | obj-$(CONFIG_TRACING) += trace.o | 3 | obj-$(CONFIG_TRACING) += trace.o |
| 4 | obj-$(CONFIG_FTRACE) += trace_functions.o | ||
| 4 | 5 | ||
| 5 | libftrace-y := ftrace.o | 6 | libftrace-y := ftrace.o |
diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c new file mode 100644 index 000000000000..82988c5336e0 --- /dev/null +++ b/kernel/trace/trace_functions.c | |||
| @@ -0,0 +1,73 @@ | |||
| 1 | /* | ||
| 2 | * ring buffer based function tracer | ||
| 3 | * | ||
| 4 | * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com> | ||
| 5 | * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com> | ||
| 6 | * | ||
| 7 | * Based on code from the latency_tracer, that is: | ||
| 8 | * | ||
| 9 | * Copyright (C) 2004-2006 Ingo Molnar | ||
| 10 | * Copyright (C) 2004 William Lee Irwin III | ||
| 11 | */ | ||
| 12 | #include <linux/fs.h> | ||
| 13 | #include <linux/debugfs.h> | ||
| 14 | #include <linux/uaccess.h> | ||
| 15 | #include <linux/ftrace.h> | ||
| 16 | |||
| 17 | #include "trace.h" | ||
| 18 | |||
| 19 | static notrace void function_reset(struct trace_array *tr) | ||
| 20 | { | ||
| 21 | int cpu; | ||
| 22 | |||
| 23 | tr->time_start = now(tr->cpu); | ||
| 24 | |||
| 25 | for_each_online_cpu(cpu) | ||
| 26 | tracing_reset(tr->data[cpu]); | ||
| 27 | } | ||
| 28 | |||
| 29 | static notrace void start_function_trace(struct trace_array *tr) | ||
| 30 | { | ||
| 31 | function_reset(tr); | ||
| 32 | tracing_start_function_trace(); | ||
| 33 | } | ||
| 34 | |||
| 35 | static notrace void stop_function_trace(struct trace_array *tr) | ||
| 36 | { | ||
| 37 | tracing_stop_function_trace(); | ||
| 38 | } | ||
| 39 | |||
| 40 | static notrace void function_trace_init(struct trace_array *tr) | ||
| 41 | { | ||
| 42 | if (tr->ctrl) | ||
| 43 | start_function_trace(tr); | ||
| 44 | } | ||
| 45 | |||
| 46 | static notrace void function_trace_reset(struct trace_array *tr) | ||
| 47 | { | ||
| 48 | if (tr->ctrl) | ||
| 49 | stop_function_trace(tr); | ||
| 50 | } | ||
| 51 | |||
| 52 | static notrace void function_trace_ctrl_update(struct trace_array *tr) | ||
| 53 | { | ||
| 54 | if (tr->ctrl) | ||
| 55 | start_function_trace(tr); | ||
| 56 | else | ||
| 57 | stop_function_trace(tr); | ||
| 58 | } | ||
| 59 | |||
| 60 | static struct tracer function_trace __read_mostly = | ||
| 61 | { | ||
| 62 | .name = "ftrace", | ||
| 63 | .init = function_trace_init, | ||
| 64 | .reset = function_trace_reset, | ||
| 65 | .ctrl_update = function_trace_ctrl_update, | ||
| 66 | }; | ||
| 67 | |||
| 68 | static __init int init_function_trace(void) | ||
| 69 | { | ||
| 70 | return register_tracer(&function_trace); | ||
| 71 | } | ||
| 72 | |||
| 73 | device_initcall(init_function_trace); | ||
