blob: 49f61fe96a6b302a2bfc85ffdd83d5073cbca835 [file] [log] [blame]
Steven Noonanfb1b6d82008-09-19 03:06:43 -07001/*
2 * nop tracer
3 *
4 * Copyright (C) 2008 Steven Noonan <steven@uplinklabs.net>
5 *
6 */
7
8#include <linux/module.h>
Steven Noonanfb1b6d82008-09-19 03:06:43 -07009#include <linux/ftrace.h>
10
11#include "trace.h"
12
Frederic Weisbecker0619faf2008-11-17 19:26:30 +010013/* Our two options */
14enum {
15 TRACE_NOP_OPT_ACCEPT = 0x1,
16 TRACE_NOP_OPT_REFUSE = 0x2
17};
18
19/* Options for the tracer (see trace_options file) */
20static struct tracer_opt nop_opts[] = {
21 /* Option that will be accepted by set_flag callback */
22 { TRACER_OPT(test_nop_accept, TRACE_NOP_OPT_ACCEPT) },
23 /* Option that will be refused by set_flag callback */
24 { TRACER_OPT(test_nop_refuse, TRACE_NOP_OPT_REFUSE) },
25 { } /* Always set a last empty entry */
26};
27
28static struct tracer_flags nop_flags = {
29 /* You can check your flags value here when you want. */
30 .val = 0, /* By default: all flags disabled */
31 .opts = nop_opts
32};
33
Steven Noonanfb1b6d82008-09-19 03:06:43 -070034static struct trace_array *ctx_trace;
35
36static void start_nop_trace(struct trace_array *tr)
37{
38 /* Nothing to do! */
39}
40
41static void stop_nop_trace(struct trace_array *tr)
42{
43 /* Nothing to do! */
44}
45
Frederic Weisbecker1c800252008-11-16 05:57:26 +010046static int nop_trace_init(struct trace_array *tr)
Steven Noonanfb1b6d82008-09-19 03:06:43 -070047{
48 ctx_trace = tr;
Steven Rostedtc76f0692008-11-07 22:36:02 -050049 start_nop_trace(tr);
Frederic Weisbecker1c800252008-11-16 05:57:26 +010050 return 0;
Steven Noonanfb1b6d82008-09-19 03:06:43 -070051}
52
53static void nop_trace_reset(struct trace_array *tr)
54{
Steven Rostedtc76f0692008-11-07 22:36:02 -050055 stop_nop_trace(tr);
Steven Noonanfb1b6d82008-09-19 03:06:43 -070056}
57
Frederic Weisbecker0619faf2008-11-17 19:26:30 +010058/* It only serves as a signal handler and a callback to
Chunyu Hu1cf80672016-03-08 21:37:02 +080059 * accept or refuse the setting of a flag.
Frederic Weisbecker0619faf2008-11-17 19:26:30 +010060 * If you don't implement it, then the flag setting will be
61 * automatically accepted.
62 */
Steven Rostedt (Red Hat)8c1a49a2014-01-10 11:13:54 -050063static int nop_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set)
Frederic Weisbecker0619faf2008-11-17 19:26:30 +010064{
65 /*
66 * Note that you don't need to update nop_flags.val yourself.
67 * The tracing Api will do it automatically if you return 0
68 */
69 if (bit == TRACE_NOP_OPT_ACCEPT) {
70 printk(KERN_DEBUG "nop_test_accept flag set to %d: we accept."
71 " Now cat trace_options to see the result\n",
72 set);
73 return 0;
74 }
75
76 if (bit == TRACE_NOP_OPT_REFUSE) {
77 printk(KERN_DEBUG "nop_test_refuse flag set to %d: we refuse."
Chunyu Hu1cf80672016-03-08 21:37:02 +080078 " Now cat trace_options to see the result\n",
Frederic Weisbecker0619faf2008-11-17 19:26:30 +010079 set);
80 return -EINVAL;
81 }
82
83 return 0;
84}
85
86
Frédéric Weisbecker43a15382008-09-21 20:16:30 +020087struct tracer nop_trace __read_mostly =
Steven Noonanfb1b6d82008-09-19 03:06:43 -070088{
89 .name = "nop",
90 .init = nop_trace_init,
91 .reset = nop_trace_reset,
Steven Noonanfb1b6d82008-09-19 03:06:43 -070092#ifdef CONFIG_FTRACE_SELFTEST
93 .selftest = trace_selftest_startup_nop,
94#endif
Frederic Weisbecker0619faf2008-11-17 19:26:30 +010095 .flags = &nop_flags,
Steven Rostedt (Red Hat)607e2ea2013-11-06 22:42:48 -050096 .set_flag = nop_set_flag,
97 .allow_instances = true,
Steven Noonanfb1b6d82008-09-19 03:06:43 -070098};
99