Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * nop tracer
0004  *
0005  * Copyright (C) 2008 Steven Noonan <steven@uplinklabs.net>
0006  *
0007  */
0008 
0009 #include <linux/module.h>
0010 #include <linux/ftrace.h>
0011 
0012 #include "trace.h"
0013 
0014 /* Our two options */
0015 enum {
0016     TRACE_NOP_OPT_ACCEPT = 0x1,
0017     TRACE_NOP_OPT_REFUSE = 0x2
0018 };
0019 
0020 /* Options for the tracer (see trace_options file) */
0021 static struct tracer_opt nop_opts[] = {
0022     /* Option that will be accepted by set_flag callback */
0023     { TRACER_OPT(test_nop_accept, TRACE_NOP_OPT_ACCEPT) },
0024     /* Option that will be refused by set_flag callback */
0025     { TRACER_OPT(test_nop_refuse, TRACE_NOP_OPT_REFUSE) },
0026     { } /* Always set a last empty entry */
0027 };
0028 
0029 static struct tracer_flags nop_flags = {
0030     /* You can check your flags value here when you want. */
0031     .val = 0, /* By default: all flags disabled */
0032     .opts = nop_opts
0033 };
0034 
0035 static struct trace_array   *ctx_trace;
0036 
0037 static void start_nop_trace(struct trace_array *tr)
0038 {
0039     /* Nothing to do! */
0040 }
0041 
0042 static void stop_nop_trace(struct trace_array *tr)
0043 {
0044     /* Nothing to do! */
0045 }
0046 
0047 static int nop_trace_init(struct trace_array *tr)
0048 {
0049     ctx_trace = tr;
0050     start_nop_trace(tr);
0051     return 0;
0052 }
0053 
0054 static void nop_trace_reset(struct trace_array *tr)
0055 {
0056     stop_nop_trace(tr);
0057 }
0058 
0059 /* It only serves as a signal handler and a callback to
0060  * accept or refuse the setting of a flag.
0061  * If you don't implement it, then the flag setting will be
0062  * automatically accepted.
0063  */
0064 static int nop_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set)
0065 {
0066     /*
0067      * Note that you don't need to update nop_flags.val yourself.
0068      * The tracing Api will do it automatically if you return 0
0069      */
0070     if (bit == TRACE_NOP_OPT_ACCEPT) {
0071         printk(KERN_DEBUG "nop_test_accept flag set to %d: we accept."
0072             " Now cat trace_options to see the result\n",
0073             set);
0074         return 0;
0075     }
0076 
0077     if (bit == TRACE_NOP_OPT_REFUSE) {
0078         printk(KERN_DEBUG "nop_test_refuse flag set to %d: we refuse."
0079             " Now cat trace_options to see the result\n",
0080             set);
0081         return -EINVAL;
0082     }
0083 
0084     return 0;
0085 }
0086 
0087 
0088 struct tracer nop_trace __read_mostly =
0089 {
0090     .name       = "nop",
0091     .init       = nop_trace_init,
0092     .reset      = nop_trace_reset,
0093 #ifdef CONFIG_FTRACE_SELFTEST
0094     .selftest   = trace_selftest_startup_nop,
0095 #endif
0096     .flags      = &nop_flags,
0097     .set_flag   = nop_set_flag,
0098     .allow_instances = true,
0099 };
0100