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