trace_nop.c 2.2 KB

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