trace.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*
  2. * Copyright © 2011-2016 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Jike Song <jike.song@intel.com>
  25. *
  26. * Contributors:
  27. * Zhi Wang <zhi.a.wang@intel.com>
  28. *
  29. */
  30. #if !defined(_GVT_TRACE_H_) || defined(TRACE_HEADER_MULTI_READ)
  31. #define _GVT_TRACE_H_
  32. #include <linux/types.h>
  33. #include <linux/stringify.h>
  34. #include <linux/tracepoint.h>
  35. #include <asm/tsc.h>
  36. #undef TRACE_SYSTEM
  37. #define TRACE_SYSTEM gvt
  38. TRACE_EVENT(spt_alloc,
  39. TP_PROTO(int id, void *spt, int type, unsigned long mfn,
  40. unsigned long gpt_gfn),
  41. TP_ARGS(id, spt, type, mfn, gpt_gfn),
  42. TP_STRUCT__entry(
  43. __field(int, id)
  44. __field(void *, spt)
  45. __field(int, type)
  46. __field(unsigned long, mfn)
  47. __field(unsigned long, gpt_gfn)
  48. ),
  49. TP_fast_assign(
  50. __entry->id = id;
  51. __entry->spt = spt;
  52. __entry->type = type;
  53. __entry->mfn = mfn;
  54. __entry->gpt_gfn = gpt_gfn;
  55. ),
  56. TP_printk("VM%d [alloc] spt %p type %d mfn 0x%lx gfn 0x%lx\n",
  57. __entry->id,
  58. __entry->spt,
  59. __entry->type,
  60. __entry->mfn,
  61. __entry->gpt_gfn)
  62. );
  63. TRACE_EVENT(spt_free,
  64. TP_PROTO(int id, void *spt, int type),
  65. TP_ARGS(id, spt, type),
  66. TP_STRUCT__entry(
  67. __field(int, id)
  68. __field(void *, spt)
  69. __field(int, type)
  70. ),
  71. TP_fast_assign(
  72. __entry->id = id;
  73. __entry->spt = spt;
  74. __entry->type = type;
  75. ),
  76. TP_printk("VM%u [free] spt %p type %d\n",
  77. __entry->id,
  78. __entry->spt,
  79. __entry->type)
  80. );
  81. #define MAX_BUF_LEN 256
  82. TRACE_EVENT(gma_index,
  83. TP_PROTO(const char *prefix, unsigned long gma,
  84. unsigned long index),
  85. TP_ARGS(prefix, gma, index),
  86. TP_STRUCT__entry(
  87. __array(char, buf, MAX_BUF_LEN)
  88. ),
  89. TP_fast_assign(
  90. snprintf(__entry->buf, MAX_BUF_LEN,
  91. "%s gma 0x%lx index 0x%lx\n", prefix, gma, index);
  92. ),
  93. TP_printk("%s", __entry->buf)
  94. );
  95. TRACE_EVENT(gma_translate,
  96. TP_PROTO(int id, char *type, int ring_id, int pt_level,
  97. unsigned long gma, unsigned long gpa),
  98. TP_ARGS(id, type, ring_id, pt_level, gma, gpa),
  99. TP_STRUCT__entry(
  100. __array(char, buf, MAX_BUF_LEN)
  101. ),
  102. TP_fast_assign(
  103. snprintf(__entry->buf, MAX_BUF_LEN,
  104. "VM%d %s ring %d pt_level %d gma 0x%lx -> gpa 0x%lx\n",
  105. id, type, ring_id, pt_level, gma, gpa);
  106. ),
  107. TP_printk("%s", __entry->buf)
  108. );
  109. TRACE_EVENT(spt_refcount,
  110. TP_PROTO(int id, char *action, void *spt, int before, int after),
  111. TP_ARGS(id, action, spt, before, after),
  112. TP_STRUCT__entry(
  113. __array(char, buf, MAX_BUF_LEN)
  114. ),
  115. TP_fast_assign(
  116. snprintf(__entry->buf, MAX_BUF_LEN,
  117. "VM%d [%s] spt %p before %d -> after %d\n",
  118. id, action, spt, before, after);
  119. ),
  120. TP_printk("%s", __entry->buf)
  121. );
  122. TRACE_EVENT(spt_change,
  123. TP_PROTO(int id, char *action, void *spt, unsigned long gfn,
  124. int type),
  125. TP_ARGS(id, action, spt, gfn, type),
  126. TP_STRUCT__entry(
  127. __array(char, buf, MAX_BUF_LEN)
  128. ),
  129. TP_fast_assign(
  130. snprintf(__entry->buf, MAX_BUF_LEN,
  131. "VM%d [%s] spt %p gfn 0x%lx type %d\n",
  132. id, action, spt, gfn, type);
  133. ),
  134. TP_printk("%s", __entry->buf)
  135. );
  136. TRACE_EVENT(gpt_change,
  137. TP_PROTO(int id, const char *tag, void *spt, int type, u64 v,
  138. unsigned long index),
  139. TP_ARGS(id, tag, spt, type, v, index),
  140. TP_STRUCT__entry(
  141. __array(char, buf, MAX_BUF_LEN)
  142. ),
  143. TP_fast_assign(
  144. snprintf(__entry->buf, MAX_BUF_LEN,
  145. "VM%d [%s] spt %p type %d entry 0x%llx index 0x%lx\n",
  146. id, tag, spt, type, v, index);
  147. ),
  148. TP_printk("%s", __entry->buf)
  149. );
  150. TRACE_EVENT(oos_change,
  151. TP_PROTO(int id, const char *tag, int page_id, void *gpt, int type),
  152. TP_ARGS(id, tag, page_id, gpt, type),
  153. TP_STRUCT__entry(
  154. __array(char, buf, MAX_BUF_LEN)
  155. ),
  156. TP_fast_assign(
  157. snprintf(__entry->buf, MAX_BUF_LEN,
  158. "VM%d [oos %s] page id %d gpt %p type %d\n",
  159. id, tag, page_id, gpt, type);
  160. ),
  161. TP_printk("%s", __entry->buf)
  162. );
  163. TRACE_EVENT(oos_sync,
  164. TP_PROTO(int id, int page_id, void *gpt, int type, u64 v,
  165. unsigned long index),
  166. TP_ARGS(id, page_id, gpt, type, v, index),
  167. TP_STRUCT__entry(
  168. __array(char, buf, MAX_BUF_LEN)
  169. ),
  170. TP_fast_assign(
  171. snprintf(__entry->buf, MAX_BUF_LEN,
  172. "VM%d [oos sync] page id %d gpt %p type %d entry 0x%llx index 0x%lx\n",
  173. id, page_id, gpt, type, v, index);
  174. ),
  175. TP_printk("%s", __entry->buf)
  176. );
  177. #define MAX_CMD_STR_LEN 256
  178. TRACE_EVENT(gvt_command,
  179. TP_PROTO(u8 vm_id, u8 ring_id, u32 ip_gma, u32 *cmd_va, u32 cmd_len, bool ring_buffer_cmd, cycles_t cost_pre_cmd_handler, cycles_t cost_cmd_handler),
  180. TP_ARGS(vm_id, ring_id, ip_gma, cmd_va, cmd_len, ring_buffer_cmd, cost_pre_cmd_handler, cost_cmd_handler),
  181. TP_STRUCT__entry(
  182. __field(u8, vm_id)
  183. __field(u8, ring_id)
  184. __field(int, i)
  185. __array(char, tmp_buf, MAX_CMD_STR_LEN)
  186. __array(char, cmd_str, MAX_CMD_STR_LEN)
  187. ),
  188. TP_fast_assign(
  189. __entry->vm_id = vm_id;
  190. __entry->ring_id = ring_id;
  191. __entry->cmd_str[0] = '\0';
  192. snprintf(__entry->tmp_buf, MAX_CMD_STR_LEN, "VM(%d) Ring(%d): %s ip(%08x) pre handler cost (%llu), handler cost (%llu) ", vm_id, ring_id, ring_buffer_cmd ? "RB":"BB", ip_gma, cost_pre_cmd_handler, cost_cmd_handler);
  193. strcat(__entry->cmd_str, __entry->tmp_buf);
  194. entry->i = 0;
  195. while (cmd_len > 0) {
  196. if (cmd_len >= 8) {
  197. snprintf(__entry->tmp_buf, MAX_CMD_STR_LEN, "%08x %08x %08x %08x %08x %08x %08x %08x ",
  198. cmd_va[__entry->i], cmd_va[__entry->i+1], cmd_va[__entry->i+2], cmd_va[__entry->i+3],
  199. cmd_va[__entry->i+4], cmd_va[__entry->i+5], cmd_va[__entry->i+6], cmd_va[__entry->i+7]);
  200. __entry->i += 8;
  201. cmd_len -= 8;
  202. strcat(__entry->cmd_str, __entry->tmp_buf);
  203. } else if (cmd_len >= 4) {
  204. snprintf(__entry->tmp_buf, MAX_CMD_STR_LEN, "%08x %08x %08x %08x ",
  205. cmd_va[__entry->i], cmd_va[__entry->i+1], cmd_va[__entry->i+2], cmd_va[__entry->i+3]);
  206. __entry->i += 4;
  207. cmd_len -= 4;
  208. strcat(__entry->cmd_str, __entry->tmp_buf);
  209. } else if (cmd_len >= 2) {
  210. snprintf(__entry->tmp_buf, MAX_CMD_STR_LEN, "%08x %08x ", cmd_va[__entry->i], cmd_va[__entry->i+1]);
  211. __entry->i += 2;
  212. cmd_len -= 2;
  213. strcat(__entry->cmd_str, __entry->tmp_buf);
  214. } else if (cmd_len == 1) {
  215. snprintf(__entry->tmp_buf, MAX_CMD_STR_LEN, "%08x ", cmd_va[__entry->i]);
  216. __entry->i += 1;
  217. cmd_len -= 1;
  218. strcat(__entry->cmd_str, __entry->tmp_buf);
  219. }
  220. }
  221. strcat(__entry->cmd_str, "\n");
  222. ),
  223. TP_printk("%s", __entry->cmd_str)
  224. );
  225. #endif /* _GVT_TRACE_H_ */
  226. /* This part must be out of protection */
  227. #undef TRACE_INCLUDE_PATH
  228. #define TRACE_INCLUDE_PATH .
  229. #undef TRACE_INCLUDE_FILE
  230. #define TRACE_INCLUDE_FILE trace
  231. #include <trace/define_trace.h>