1 // SPDX-License-Identifier: GPL-2.0 << 2 /* 1 /* 3 * nop tracer 2 * nop tracer 4 * 3 * 5 * Copyright (C) 2008 Steven Noonan <steven@up 4 * Copyright (C) 2008 Steven Noonan <steven@uplinklabs.net> 6 * 5 * 7 */ 6 */ 8 7 9 #include <linux/module.h> 8 #include <linux/module.h> 10 #include <linux/ftrace.h> 9 #include <linux/ftrace.h> 11 10 12 #include "trace.h" 11 #include "trace.h" 13 12 14 /* Our two options */ 13 /* Our two options */ 15 enum { 14 enum { 16 TRACE_NOP_OPT_ACCEPT = 0x1, 15 TRACE_NOP_OPT_ACCEPT = 0x1, 17 TRACE_NOP_OPT_REFUSE = 0x2 16 TRACE_NOP_OPT_REFUSE = 0x2 18 }; 17 }; 19 18 20 /* Options for the tracer (see trace_options f 19 /* Options for the tracer (see trace_options file) */ 21 static struct tracer_opt nop_opts[] = { 20 static struct tracer_opt nop_opts[] = { 22 /* Option that will be accepted by set 21 /* Option that will be accepted by set_flag callback */ 23 { TRACER_OPT(test_nop_accept, TRACE_NO 22 { TRACER_OPT(test_nop_accept, TRACE_NOP_OPT_ACCEPT) }, 24 /* Option that will be refused by set_ 23 /* Option that will be refused by set_flag callback */ 25 { TRACER_OPT(test_nop_refuse, TRACE_NO 24 { TRACER_OPT(test_nop_refuse, TRACE_NOP_OPT_REFUSE) }, 26 { } /* Always set a last empty entry * 25 { } /* Always set a last empty entry */ 27 }; 26 }; 28 27 29 static struct tracer_flags nop_flags = { 28 static struct tracer_flags nop_flags = { 30 /* You can check your flags value here 29 /* You can check your flags value here when you want. */ 31 .val = 0, /* By default: all flags dis 30 .val = 0, /* By default: all flags disabled */ 32 .opts = nop_opts 31 .opts = nop_opts 33 }; 32 }; 34 33 35 static struct trace_array *ctx_trace; 34 static struct trace_array *ctx_trace; 36 35 37 static void start_nop_trace(struct trace_array 36 static void start_nop_trace(struct trace_array *tr) 38 { 37 { 39 /* Nothing to do! */ 38 /* Nothing to do! */ 40 } 39 } 41 40 42 static void stop_nop_trace(struct trace_array 41 static void stop_nop_trace(struct trace_array *tr) 43 { 42 { 44 /* Nothing to do! */ 43 /* Nothing to do! */ 45 } 44 } 46 45 47 static int nop_trace_init(struct trace_array * 46 static int nop_trace_init(struct trace_array *tr) 48 { 47 { 49 ctx_trace = tr; 48 ctx_trace = tr; 50 start_nop_trace(tr); 49 start_nop_trace(tr); 51 return 0; 50 return 0; 52 } 51 } 53 52 54 static void nop_trace_reset(struct trace_array 53 static void nop_trace_reset(struct trace_array *tr) 55 { 54 { 56 stop_nop_trace(tr); 55 stop_nop_trace(tr); 57 } 56 } 58 57 59 /* It only serves as a signal handler and a ca 58 /* It only serves as a signal handler and a callback to 60 * accept or refuse the setting of a flag. !! 59 * accept or refuse tthe setting of a flag. 61 * If you don't implement it, then the flag se 60 * If you don't implement it, then the flag setting will be 62 * automatically accepted. 61 * automatically accepted. 63 */ 62 */ 64 static int nop_set_flag(struct trace_array *tr 63 static int nop_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set) 65 { 64 { 66 /* 65 /* 67 * Note that you don't need to update 66 * Note that you don't need to update nop_flags.val yourself. 68 * The tracing Api will do it automati 67 * The tracing Api will do it automatically if you return 0 69 */ 68 */ 70 if (bit == TRACE_NOP_OPT_ACCEPT) { 69 if (bit == TRACE_NOP_OPT_ACCEPT) { 71 printk(KERN_DEBUG "nop_test_ac 70 printk(KERN_DEBUG "nop_test_accept flag set to %d: we accept." 72 " Now cat trace_option 71 " Now cat trace_options to see the result\n", 73 set); 72 set); 74 return 0; 73 return 0; 75 } 74 } 76 75 77 if (bit == TRACE_NOP_OPT_REFUSE) { 76 if (bit == TRACE_NOP_OPT_REFUSE) { 78 printk(KERN_DEBUG "nop_test_re 77 printk(KERN_DEBUG "nop_test_refuse flag set to %d: we refuse." 79 " Now cat trace_option !! 78 "Now cat trace_options to see the result\n", 80 set); 79 set); 81 return -EINVAL; 80 return -EINVAL; 82 } 81 } 83 82 84 return 0; 83 return 0; 85 } 84 } 86 85 87 86 88 struct tracer nop_trace __read_mostly = 87 struct tracer nop_trace __read_mostly = 89 { 88 { 90 .name = "nop", 89 .name = "nop", 91 .init = nop_trace_init, 90 .init = nop_trace_init, 92 .reset = nop_trace_reset, 91 .reset = nop_trace_reset, 93 #ifdef CONFIG_FTRACE_SELFTEST 92 #ifdef CONFIG_FTRACE_SELFTEST 94 .selftest = trace_selftest_start 93 .selftest = trace_selftest_startup_nop, 95 #endif 94 #endif 96 .flags = &nop_flags, 95 .flags = &nop_flags, 97 .set_flag = nop_set_flag, 96 .set_flag = nop_set_flag, 98 .allow_instances = true, 97 .allow_instances = true, 99 }; 98 }; 100 99 101 100
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.