Steven Noonan | fb1b6d8 | 2008-09-19 03:06:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * nop tracer |
| 3 | * |
| 4 | * Copyright (C) 2008 Steven Noonan <steven@uplinklabs.net> |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/fs.h> |
| 10 | #include <linux/debugfs.h> |
| 11 | #include <linux/ftrace.h> |
| 12 | |
| 13 | #include "trace.h" |
| 14 | |
Frederic Weisbecker | 0619faf | 2008-11-17 19:26:30 +0100 | [diff] [blame^] | 15 | /* Our two options */ |
| 16 | enum { |
| 17 | TRACE_NOP_OPT_ACCEPT = 0x1, |
| 18 | TRACE_NOP_OPT_REFUSE = 0x2 |
| 19 | }; |
| 20 | |
| 21 | /* Options for the tracer (see trace_options file) */ |
| 22 | static struct tracer_opt nop_opts[] = { |
| 23 | /* Option that will be accepted by set_flag callback */ |
| 24 | { TRACER_OPT(test_nop_accept, TRACE_NOP_OPT_ACCEPT) }, |
| 25 | /* Option that will be refused by set_flag callback */ |
| 26 | { TRACER_OPT(test_nop_refuse, TRACE_NOP_OPT_REFUSE) }, |
| 27 | { } /* Always set a last empty entry */ |
| 28 | }; |
| 29 | |
| 30 | static struct tracer_flags nop_flags = { |
| 31 | /* You can check your flags value here when you want. */ |
| 32 | .val = 0, /* By default: all flags disabled */ |
| 33 | .opts = nop_opts |
| 34 | }; |
| 35 | |
Steven Noonan | fb1b6d8 | 2008-09-19 03:06:43 -0700 | [diff] [blame] | 36 | static struct trace_array *ctx_trace; |
| 37 | |
| 38 | static void start_nop_trace(struct trace_array *tr) |
| 39 | { |
| 40 | /* Nothing to do! */ |
| 41 | } |
| 42 | |
| 43 | static void stop_nop_trace(struct trace_array *tr) |
| 44 | { |
| 45 | /* Nothing to do! */ |
| 46 | } |
| 47 | |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 48 | static int nop_trace_init(struct trace_array *tr) |
Steven Noonan | fb1b6d8 | 2008-09-19 03:06:43 -0700 | [diff] [blame] | 49 | { |
Frédéric Weisbecker | 35cb5ed | 2008-09-21 20:10:14 +0200 | [diff] [blame] | 50 | int cpu; |
Steven Noonan | fb1b6d8 | 2008-09-19 03:06:43 -0700 | [diff] [blame] | 51 | ctx_trace = tr; |
| 52 | |
Frédéric Weisbecker | 35cb5ed | 2008-09-21 20:10:14 +0200 | [diff] [blame] | 53 | for_each_online_cpu(cpu) |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 54 | tracing_reset(tr, cpu); |
Frédéric Weisbecker | 35cb5ed | 2008-09-21 20:10:14 +0200 | [diff] [blame] | 55 | |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 56 | start_nop_trace(tr); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 57 | return 0; |
Steven Noonan | fb1b6d8 | 2008-09-19 03:06:43 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | static void nop_trace_reset(struct trace_array *tr) |
| 61 | { |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 62 | stop_nop_trace(tr); |
Steven Noonan | fb1b6d8 | 2008-09-19 03:06:43 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Frederic Weisbecker | 0619faf | 2008-11-17 19:26:30 +0100 | [diff] [blame^] | 65 | /* It only serves as a signal handler and a callback to |
| 66 | * accept or refuse tthe setting of a flag. |
| 67 | * If you don't implement it, then the flag setting will be |
| 68 | * automatically accepted. |
| 69 | */ |
| 70 | static int nop_set_flag(u32 old_flags, u32 bit, int set) |
| 71 | { |
| 72 | /* |
| 73 | * Note that you don't need to update nop_flags.val yourself. |
| 74 | * The tracing Api will do it automatically if you return 0 |
| 75 | */ |
| 76 | if (bit == TRACE_NOP_OPT_ACCEPT) { |
| 77 | printk(KERN_DEBUG "nop_test_accept flag set to %d: we accept." |
| 78 | " Now cat trace_options to see the result\n", |
| 79 | set); |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | if (bit == TRACE_NOP_OPT_REFUSE) { |
| 84 | printk(KERN_DEBUG "nop_test_refuse flag set to %d: we refuse." |
| 85 | "Now cat trace_options to see the result\n", |
| 86 | set); |
| 87 | return -EINVAL; |
| 88 | } |
| 89 | |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | |
Frédéric Weisbecker | 43a1538 | 2008-09-21 20:16:30 +0200 | [diff] [blame] | 94 | struct tracer nop_trace __read_mostly = |
Steven Noonan | fb1b6d8 | 2008-09-19 03:06:43 -0700 | [diff] [blame] | 95 | { |
| 96 | .name = "nop", |
| 97 | .init = nop_trace_init, |
| 98 | .reset = nop_trace_reset, |
Steven Noonan | fb1b6d8 | 2008-09-19 03:06:43 -0700 | [diff] [blame] | 99 | #ifdef CONFIG_FTRACE_SELFTEST |
| 100 | .selftest = trace_selftest_startup_nop, |
| 101 | #endif |
Frederic Weisbecker | 0619faf | 2008-11-17 19:26:30 +0100 | [diff] [blame^] | 102 | .flags = &nop_flags, |
| 103 | .set_flag = nop_set_flag |
Steven Noonan | fb1b6d8 | 2008-09-19 03:06:43 -0700 | [diff] [blame] | 104 | }; |
| 105 | |