intel-pt-decoder.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * intel_pt_decoder.h: Intel Processor Trace support
  3. * Copyright (c) 2013-2014, Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. */
  15. #ifndef INCLUDE__INTEL_PT_DECODER_H__
  16. #define INCLUDE__INTEL_PT_DECODER_H__
  17. #include <stdint.h>
  18. #include <stddef.h>
  19. #include <stdbool.h>
  20. #include "intel-pt-insn-decoder.h"
  21. #define INTEL_PT_IN_TX (1 << 0)
  22. #define INTEL_PT_ABORT_TX (1 << 1)
  23. #define INTEL_PT_ASYNC (1 << 2)
  24. #define INTEL_PT_FUP_IP (1 << 3)
  25. enum intel_pt_sample_type {
  26. INTEL_PT_BRANCH = 1 << 0,
  27. INTEL_PT_INSTRUCTION = 1 << 1,
  28. INTEL_PT_TRANSACTION = 1 << 2,
  29. INTEL_PT_PTW = 1 << 3,
  30. INTEL_PT_MWAIT_OP = 1 << 4,
  31. INTEL_PT_PWR_ENTRY = 1 << 5,
  32. INTEL_PT_EX_STOP = 1 << 6,
  33. INTEL_PT_PWR_EXIT = 1 << 7,
  34. INTEL_PT_CBR_CHG = 1 << 8,
  35. INTEL_PT_TRACE_BEGIN = 1 << 9,
  36. INTEL_PT_TRACE_END = 1 << 10,
  37. };
  38. enum intel_pt_period_type {
  39. INTEL_PT_PERIOD_NONE,
  40. INTEL_PT_PERIOD_INSTRUCTIONS,
  41. INTEL_PT_PERIOD_TICKS,
  42. INTEL_PT_PERIOD_MTC,
  43. };
  44. enum {
  45. INTEL_PT_ERR_NOMEM = 1,
  46. INTEL_PT_ERR_INTERN,
  47. INTEL_PT_ERR_BADPKT,
  48. INTEL_PT_ERR_NODATA,
  49. INTEL_PT_ERR_NOINSN,
  50. INTEL_PT_ERR_MISMAT,
  51. INTEL_PT_ERR_OVR,
  52. INTEL_PT_ERR_LOST,
  53. INTEL_PT_ERR_UNK,
  54. INTEL_PT_ERR_NELOOP,
  55. INTEL_PT_ERR_MAX,
  56. };
  57. enum intel_pt_param_flags {
  58. /*
  59. * FUP packet can contain next linear instruction pointer instead of
  60. * current linear instruction pointer.
  61. */
  62. INTEL_PT_FUP_WITH_NLIP = 1 << 0,
  63. };
  64. struct intel_pt_state {
  65. enum intel_pt_sample_type type;
  66. int err;
  67. uint64_t from_ip;
  68. uint64_t to_ip;
  69. uint64_t cr3;
  70. uint64_t tot_insn_cnt;
  71. uint64_t timestamp;
  72. uint64_t est_timestamp;
  73. uint64_t trace_nr;
  74. uint64_t ptw_payload;
  75. uint64_t mwait_payload;
  76. uint64_t pwre_payload;
  77. uint64_t pwrx_payload;
  78. uint64_t cbr_payload;
  79. uint32_t flags;
  80. enum intel_pt_insn_op insn_op;
  81. int insn_len;
  82. char insn[INTEL_PT_INSN_BUF_SZ];
  83. };
  84. struct intel_pt_insn;
  85. struct intel_pt_buffer {
  86. const unsigned char *buf;
  87. size_t len;
  88. bool consecutive;
  89. uint64_t ref_timestamp;
  90. uint64_t trace_nr;
  91. };
  92. struct intel_pt_params {
  93. int (*get_trace)(struct intel_pt_buffer *buffer, void *data);
  94. int (*walk_insn)(struct intel_pt_insn *intel_pt_insn,
  95. uint64_t *insn_cnt_ptr, uint64_t *ip, uint64_t to_ip,
  96. uint64_t max_insn_cnt, void *data);
  97. bool (*pgd_ip)(uint64_t ip, void *data);
  98. void *data;
  99. bool return_compression;
  100. bool branch_enable;
  101. uint64_t period;
  102. enum intel_pt_period_type period_type;
  103. unsigned max_non_turbo_ratio;
  104. unsigned int mtc_period;
  105. uint32_t tsc_ctc_ratio_n;
  106. uint32_t tsc_ctc_ratio_d;
  107. enum intel_pt_param_flags flags;
  108. };
  109. struct intel_pt_decoder;
  110. struct intel_pt_decoder *intel_pt_decoder_new(struct intel_pt_params *params);
  111. void intel_pt_decoder_free(struct intel_pt_decoder *decoder);
  112. const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder);
  113. unsigned char *intel_pt_find_overlap(unsigned char *buf_a, size_t len_a,
  114. unsigned char *buf_b, size_t len_b,
  115. bool have_tsc, bool *consecutive);
  116. int intel_pt__strerror(int code, char *buf, size_t buflen);
  117. #endif