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