trace_dbg.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright(c) 2015 - 2018 Intel Corporation.
  3. *
  4. * This file is provided under a dual BSD/GPLv2 license. When using or
  5. * redistributing this file, you may do so under either license.
  6. *
  7. * GPL LICENSE SUMMARY
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * BSD LICENSE
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions
  22. * are met:
  23. *
  24. * - Redistributions of source code must retain the above copyright
  25. * notice, this list of conditions and the following disclaimer.
  26. * - Redistributions in binary form must reproduce the above copyright
  27. * notice, this list of conditions and the following disclaimer in
  28. * the documentation and/or other materials provided with the
  29. * distribution.
  30. * - Neither the name of Intel Corporation nor the names of its
  31. * contributors may be used to endorse or promote products derived
  32. * from this software without specific prior written permission.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  35. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  36. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  37. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  38. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  39. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  41. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  42. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  44. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. *
  46. */
  47. #if !defined(__HFI1_TRACE_EXTRA_H) || defined(TRACE_HEADER_MULTI_READ)
  48. #define __HFI1_TRACE_EXTRA_H
  49. #include <linux/tracepoint.h>
  50. #include <linux/trace_seq.h>
  51. #include "hfi.h"
  52. /*
  53. * Note:
  54. * This produces a REALLY ugly trace in the console output when the string is
  55. * too long.
  56. */
  57. #undef TRACE_SYSTEM
  58. #define TRACE_SYSTEM hfi1_dbg
  59. #define MAX_MSG_LEN 512
  60. DECLARE_EVENT_CLASS(hfi1_trace_template,
  61. TP_PROTO(const char *function, struct va_format *vaf),
  62. TP_ARGS(function, vaf),
  63. TP_STRUCT__entry(__string(function, function)
  64. __dynamic_array(char, msg, MAX_MSG_LEN)
  65. ),
  66. TP_fast_assign(__assign_str(function, function);
  67. WARN_ON_ONCE(vsnprintf
  68. (__get_dynamic_array(msg),
  69. MAX_MSG_LEN, vaf->fmt,
  70. *vaf->va) >=
  71. MAX_MSG_LEN);
  72. ),
  73. TP_printk("(%s) %s",
  74. __get_str(function),
  75. __get_str(msg))
  76. );
  77. /*
  78. * It may be nice to macroize the __hfi1_trace but the va_* stuff requires an
  79. * actual function to work and can not be in a macro.
  80. */
  81. #define __hfi1_trace_def(lvl) \
  82. void __hfi1_trace_##lvl(const char *funct, char *fmt, ...); \
  83. \
  84. DEFINE_EVENT(hfi1_trace_template, hfi1_ ##lvl, \
  85. TP_PROTO(const char *function, struct va_format *vaf), \
  86. TP_ARGS(function, vaf))
  87. #define __hfi1_trace_fn(lvl) \
  88. void __hfi1_trace_##lvl(const char *func, char *fmt, ...) \
  89. { \
  90. struct va_format vaf = { \
  91. .fmt = fmt, \
  92. }; \
  93. va_list args; \
  94. \
  95. va_start(args, fmt); \
  96. vaf.va = &args; \
  97. trace_hfi1_ ##lvl(func, &vaf); \
  98. va_end(args); \
  99. return; \
  100. }
  101. /*
  102. * To create a new trace level simply define it below and as a __hfi1_trace_fn
  103. * in trace.c. This will create all the hooks for calling
  104. * hfi1_cdbg(LVL, fmt, ...); as well as take care of all
  105. * the debugfs stuff.
  106. */
  107. __hfi1_trace_def(AFFINITY);
  108. __hfi1_trace_def(PKT);
  109. __hfi1_trace_def(PROC);
  110. __hfi1_trace_def(SDMA);
  111. __hfi1_trace_def(LINKVERB);
  112. __hfi1_trace_def(DEBUG);
  113. __hfi1_trace_def(SNOOP);
  114. __hfi1_trace_def(CNTR);
  115. __hfi1_trace_def(PIO);
  116. __hfi1_trace_def(DC8051);
  117. __hfi1_trace_def(FIRMWARE);
  118. __hfi1_trace_def(RCVCTRL);
  119. __hfi1_trace_def(TID);
  120. __hfi1_trace_def(MMU);
  121. __hfi1_trace_def(IOCTL);
  122. #define hfi1_cdbg(which, fmt, ...) \
  123. __hfi1_trace_##which(__func__, fmt, ##__VA_ARGS__)
  124. #define hfi1_dbg(fmt, ...) \
  125. hfi1_cdbg(DEBUG, fmt, ##__VA_ARGS__)
  126. /*
  127. * Define HFI1_EARLY_DBG at compile time or here to enable early trace
  128. * messages. Do not check in an enablement for this.
  129. */
  130. #ifdef HFI1_EARLY_DBG
  131. #define hfi1_dbg_early(fmt, ...) \
  132. trace_printk(fmt, ##__VA_ARGS__)
  133. #else
  134. #define hfi1_dbg_early(fmt, ...)
  135. #endif
  136. #endif /* __HFI1_TRACE_EXTRA_H */
  137. #undef TRACE_INCLUDE_PATH
  138. #undef TRACE_INCLUDE_FILE
  139. #define TRACE_INCLUDE_PATH .
  140. #define TRACE_INCLUDE_FILE trace_dbg
  141. #include <trace/define_trace.h>