trace_dbg.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause */
  2. /*
  3. * Copyright(c) 2015 - 2018 Intel Corporation.
  4. */
  5. #if !defined(__HFI1_TRACE_EXTRA_H) || defined(TRACE_HEADER_MULTI_READ)
  6. #define __HFI1_TRACE_EXTRA_H
  7. #include <linux/tracepoint.h>
  8. #include <linux/trace_seq.h>
  9. #include "hfi.h"
  10. /*
  11. * Note:
  12. * This produces a REALLY ugly trace in the console output when the string is
  13. * too long.
  14. */
  15. #undef TRACE_SYSTEM
  16. #define TRACE_SYSTEM hfi1_dbg
  17. #define MAX_MSG_LEN 512
  18. DECLARE_EVENT_CLASS(hfi1_trace_template,
  19. TP_PROTO(const char *function, struct va_format *vaf),
  20. TP_ARGS(function, vaf),
  21. TP_STRUCT__entry(__string(function, function)
  22. __vstring(msg, vaf->fmt, vaf->va)
  23. ),
  24. TP_fast_assign(__assign_str(function, function);
  25. __assign_vstr(msg, vaf->fmt, vaf->va);
  26. ),
  27. TP_printk("(%s) %s",
  28. __get_str(function),
  29. __get_str(msg))
  30. );
  31. /*
  32. * It may be nice to macroize the __hfi1_trace but the va_* stuff requires an
  33. * actual function to work and can not be in a macro.
  34. */
  35. #define __hfi1_trace_def(lvl) \
  36. void __printf(2, 3) __hfi1_trace_##lvl(const char *funct, char *fmt, ...); \
  37. \
  38. DEFINE_EVENT(hfi1_trace_template, hfi1_ ##lvl, \
  39. TP_PROTO(const char *function, struct va_format *vaf), \
  40. TP_ARGS(function, vaf))
  41. #define __hfi1_trace_fn(lvl) \
  42. void __printf(2, 3) __hfi1_trace_##lvl(const char *func, char *fmt, ...)\
  43. { \
  44. struct va_format vaf = { \
  45. .fmt = fmt, \
  46. }; \
  47. va_list args; \
  48. \
  49. va_start(args, fmt); \
  50. vaf.va = &args; \
  51. trace_hfi1_ ##lvl(func, &vaf); \
  52. va_end(args); \
  53. return; \
  54. }
  55. /*
  56. * To create a new trace level simply define it below and as a __hfi1_trace_fn
  57. * in trace.c. This will create all the hooks for calling
  58. * hfi1_cdbg(LVL, fmt, ...); as well as take care of all
  59. * the debugfs stuff.
  60. */
  61. __hfi1_trace_def(AFFINITY);
  62. __hfi1_trace_def(PKT);
  63. __hfi1_trace_def(PROC);
  64. __hfi1_trace_def(SDMA);
  65. __hfi1_trace_def(LINKVERB);
  66. __hfi1_trace_def(DEBUG);
  67. __hfi1_trace_def(SNOOP);
  68. __hfi1_trace_def(CNTR);
  69. __hfi1_trace_def(PIO);
  70. __hfi1_trace_def(DC8051);
  71. __hfi1_trace_def(FIRMWARE);
  72. __hfi1_trace_def(RCVCTRL);
  73. __hfi1_trace_def(TID);
  74. __hfi1_trace_def(MMU);
  75. __hfi1_trace_def(IOCTL);
  76. #define hfi1_cdbg(which, fmt, ...) \
  77. __hfi1_trace_##which(__func__, fmt, ##__VA_ARGS__)
  78. #define hfi1_dbg(fmt, ...) \
  79. hfi1_cdbg(DEBUG, fmt, ##__VA_ARGS__)
  80. /*
  81. * Define HFI1_EARLY_DBG at compile time or here to enable early trace
  82. * messages. Do not check in an enablement for this.
  83. */
  84. #ifdef HFI1_EARLY_DBG
  85. #define hfi1_dbg_early(fmt, ...) \
  86. trace_printk(fmt, ##__VA_ARGS__)
  87. #else
  88. #define hfi1_dbg_early(fmt, ...)
  89. #endif
  90. #endif /* __HFI1_TRACE_EXTRA_H */
  91. #undef TRACE_INCLUDE_PATH
  92. #undef TRACE_INCLUDE_FILE
  93. #define TRACE_INCLUDE_PATH .
  94. #define TRACE_INCLUDE_FILE trace_dbg
  95. #include <trace/define_trace.h>