pt.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * Intel(R) Processor Trace PMU driver for perf
  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. * Intel PT is specified in the Intel Architecture Instruction Set Extensions
  15. * Programming Reference:
  16. * http://software.intel.com/en-us/intel-isa-extensions
  17. */
  18. #ifndef __INTEL_PT_H__
  19. #define __INTEL_PT_H__
  20. /*
  21. * PT MSR bit definitions
  22. */
  23. #define RTIT_CTL_TRACEEN BIT(0)
  24. #define RTIT_CTL_CYCLEACC BIT(1)
  25. #define RTIT_CTL_OS BIT(2)
  26. #define RTIT_CTL_USR BIT(3)
  27. #define RTIT_CTL_PWR_EVT_EN BIT(4)
  28. #define RTIT_CTL_FUP_ON_PTW BIT(5)
  29. #define RTIT_CTL_CR3EN BIT(7)
  30. #define RTIT_CTL_TOPA BIT(8)
  31. #define RTIT_CTL_MTC_EN BIT(9)
  32. #define RTIT_CTL_TSC_EN BIT(10)
  33. #define RTIT_CTL_DISRETC BIT(11)
  34. #define RTIT_CTL_PTW_EN BIT(12)
  35. #define RTIT_CTL_BRANCH_EN BIT(13)
  36. #define RTIT_CTL_MTC_RANGE_OFFSET 14
  37. #define RTIT_CTL_MTC_RANGE (0x0full << RTIT_CTL_MTC_RANGE_OFFSET)
  38. #define RTIT_CTL_CYC_THRESH_OFFSET 19
  39. #define RTIT_CTL_CYC_THRESH (0x0full << RTIT_CTL_CYC_THRESH_OFFSET)
  40. #define RTIT_CTL_PSB_FREQ_OFFSET 24
  41. #define RTIT_CTL_PSB_FREQ (0x0full << RTIT_CTL_PSB_FREQ_OFFSET)
  42. #define RTIT_CTL_ADDR0_OFFSET 32
  43. #define RTIT_CTL_ADDR0 (0x0full << RTIT_CTL_ADDR0_OFFSET)
  44. #define RTIT_CTL_ADDR1_OFFSET 36
  45. #define RTIT_CTL_ADDR1 (0x0full << RTIT_CTL_ADDR1_OFFSET)
  46. #define RTIT_CTL_ADDR2_OFFSET 40
  47. #define RTIT_CTL_ADDR2 (0x0full << RTIT_CTL_ADDR2_OFFSET)
  48. #define RTIT_CTL_ADDR3_OFFSET 44
  49. #define RTIT_CTL_ADDR3 (0x0full << RTIT_CTL_ADDR3_OFFSET)
  50. #define RTIT_STATUS_FILTEREN BIT(0)
  51. #define RTIT_STATUS_CONTEXTEN BIT(1)
  52. #define RTIT_STATUS_TRIGGEREN BIT(2)
  53. #define RTIT_STATUS_BUFFOVF BIT(3)
  54. #define RTIT_STATUS_ERROR BIT(4)
  55. #define RTIT_STATUS_STOPPED BIT(5)
  56. /*
  57. * Single-entry ToPA: when this close to region boundary, switch
  58. * buffers to avoid losing data.
  59. */
  60. #define TOPA_PMI_MARGIN 512
  61. #define TOPA_SHIFT 12
  62. static inline unsigned int sizes(unsigned int tsz)
  63. {
  64. return 1 << (tsz + TOPA_SHIFT);
  65. };
  66. struct topa_entry {
  67. u64 end : 1;
  68. u64 rsvd0 : 1;
  69. u64 intr : 1;
  70. u64 rsvd1 : 1;
  71. u64 stop : 1;
  72. u64 rsvd2 : 1;
  73. u64 size : 4;
  74. u64 rsvd3 : 2;
  75. u64 base : 36;
  76. u64 rsvd4 : 16;
  77. };
  78. #define PT_CPUID_LEAVES 2
  79. #define PT_CPUID_REGS_NUM 4 /* number of regsters (eax, ebx, ecx, edx) */
  80. /* TSC to Core Crystal Clock Ratio */
  81. #define CPUID_TSC_LEAF 0x15
  82. enum pt_capabilities {
  83. PT_CAP_max_subleaf = 0,
  84. PT_CAP_cr3_filtering,
  85. PT_CAP_psb_cyc,
  86. PT_CAP_ip_filtering,
  87. PT_CAP_mtc,
  88. PT_CAP_ptwrite,
  89. PT_CAP_power_event_trace,
  90. PT_CAP_topa_output,
  91. PT_CAP_topa_multiple_entries,
  92. PT_CAP_single_range_output,
  93. PT_CAP_payloads_lip,
  94. PT_CAP_num_address_ranges,
  95. PT_CAP_mtc_periods,
  96. PT_CAP_cycle_thresholds,
  97. PT_CAP_psb_periods,
  98. };
  99. struct pt_pmu {
  100. struct pmu pmu;
  101. u32 caps[PT_CPUID_REGS_NUM * PT_CPUID_LEAVES];
  102. bool vmx;
  103. unsigned long max_nonturbo_ratio;
  104. unsigned int tsc_art_num;
  105. unsigned int tsc_art_den;
  106. };
  107. /**
  108. * struct pt_buffer - buffer configuration; one buffer per task_struct or
  109. * cpu, depending on perf event configuration
  110. * @cpu: cpu for per-cpu allocation
  111. * @tables: list of ToPA tables in this buffer
  112. * @first: shorthand for first topa table
  113. * @last: shorthand for last topa table
  114. * @cur: current topa table
  115. * @nr_pages: buffer size in pages
  116. * @cur_idx: current output region's index within @cur table
  117. * @output_off: offset within the current output region
  118. * @data_size: running total of the amount of data in this buffer
  119. * @lost: if data was lost/truncated
  120. * @head: logical write offset inside the buffer
  121. * @snapshot: if this is for a snapshot/overwrite counter
  122. * @stop_pos: STOP topa entry in the buffer
  123. * @intr_pos: INT topa entry in the buffer
  124. * @data_pages: array of pages from perf
  125. * @topa_index: table of topa entries indexed by page offset
  126. */
  127. struct pt_buffer {
  128. int cpu;
  129. struct list_head tables;
  130. struct topa *first, *last, *cur;
  131. unsigned int cur_idx;
  132. size_t output_off;
  133. unsigned long nr_pages;
  134. local_t data_size;
  135. local_t lost;
  136. local64_t head;
  137. bool snapshot;
  138. unsigned long stop_pos, intr_pos;
  139. void **data_pages;
  140. struct topa_entry *topa_index[0];
  141. };
  142. #define PT_FILTERS_NUM 4
  143. /**
  144. * struct pt_filter - IP range filter configuration
  145. * @msr_a: range start, goes to RTIT_ADDRn_A
  146. * @msr_b: range end, goes to RTIT_ADDRn_B
  147. * @config: 4-bit field in RTIT_CTL
  148. */
  149. struct pt_filter {
  150. unsigned long msr_a;
  151. unsigned long msr_b;
  152. unsigned long config;
  153. };
  154. /**
  155. * struct pt_filters - IP range filtering context
  156. * @filter: filters defined for this context
  157. * @nr_filters: number of defined filters in the @filter array
  158. */
  159. struct pt_filters {
  160. struct pt_filter filter[PT_FILTERS_NUM];
  161. unsigned int nr_filters;
  162. };
  163. /**
  164. * struct pt - per-cpu pt context
  165. * @handle: perf output handle
  166. * @filters: last configured filters
  167. * @handle_nmi: do handle PT PMI on this cpu, there's an active event
  168. * @vmx_on: 1 if VMX is ON on this cpu
  169. */
  170. struct pt {
  171. struct perf_output_handle handle;
  172. struct pt_filters filters;
  173. int handle_nmi;
  174. int vmx_on;
  175. };
  176. #endif /* __INTEL_PT_H__ */