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 19 #ifndef __INTEL_PT_H__ 20 #define __INTEL_PT_H__ 21 22 /* 23 * Single-entry ToPA: when this close to region boundary, switch 24 * buffers to avoid losing data. 25 */ 26 #define TOPA_PMI_MARGIN 512 27 28 #define TOPA_SHIFT 12 29 30 static inline unsigned int sizes(unsigned int tsz) 31 { 32 return 1 << (tsz + TOPA_SHIFT); 33 }; 34 35 struct topa_entry { 36 u64 end : 1; 37 u64 rsvd0 : 1; 38 u64 intr : 1; 39 u64 rsvd1 : 1; 40 u64 stop : 1; 41 u64 rsvd2 : 1; 42 u64 size : 4; 43 u64 rsvd3 : 2; 44 u64 base : 36; 45 u64 rsvd4 : 16; 46 }; 47 48 /* TSC to Core Crystal Clock Ratio */ 49 #define CPUID_TSC_LEAF 0x15 50 51 struct pt_pmu { 52 struct pmu pmu; 53 u32 caps[PT_CPUID_REGS_NUM * PT_CPUID_LEAVES]; 54 bool vmx; 55 bool branch_en_always_on; 56 unsigned long max_nonturbo_ratio; 57 unsigned int tsc_art_num; 58 unsigned int tsc_art_den; 59 }; 60 61 /** 62 * struct pt_buffer - buffer configuration; one buffer per task_struct or 63 * cpu, depending on perf event configuration 64 * @cpu: cpu for per-cpu allocation 65 * @tables: list of ToPA tables in this buffer 66 * @first: shorthand for first topa table 67 * @last: shorthand for last topa table 68 * @cur: current topa table 69 * @nr_pages: buffer size in pages 70 * @cur_idx: current output region's index within @cur table 71 * @output_off: offset within the current output region 72 * @data_size: running total of the amount of data in this buffer 73 * @lost: if data was lost/truncated 74 * @head: logical write offset inside the buffer 75 * @snapshot: if this is for a snapshot/overwrite counter 76 * @stop_pos: STOP topa entry in the buffer 77 * @intr_pos: INT topa entry in the buffer 78 * @data_pages: array of pages from perf 79 * @topa_index: table of topa entries indexed by page offset 80 */ 81 struct pt_buffer { 82 int cpu; 83 struct list_head tables; 84 struct topa *first, *last, *cur; 85 unsigned int cur_idx; 86 size_t output_off; 87 unsigned long nr_pages; 88 local_t data_size; 89 local64_t head; 90 bool snapshot; 91 unsigned long stop_pos, intr_pos; 92 void **data_pages; 93 struct topa_entry *topa_index[0]; 94 }; 95 96 #define PT_FILTERS_NUM 4 97 98 /** 99 * struct pt_filter - IP range filter configuration 100 * @msr_a: range start, goes to RTIT_ADDRn_A 101 * @msr_b: range end, goes to RTIT_ADDRn_B 102 * @config: 4-bit field in RTIT_CTL 103 */ 104 struct pt_filter { 105 unsigned long msr_a; 106 unsigned long msr_b; 107 unsigned long config; 108 }; 109 110 /** 111 * struct pt_filters - IP range filtering context 112 * @filter: filters defined for this context 113 * @nr_filters: number of defined filters in the @filter array 114 */ 115 struct pt_filters { 116 struct pt_filter filter[PT_FILTERS_NUM]; 117 unsigned int nr_filters; 118 }; 119 120 /** 121 * struct pt - per-cpu pt context 122 * @handle: perf output handle 123 * @filters: last configured filters 124 * @handle_nmi: do handle PT PMI on this cpu, there's an active event 125 * @vmx_on: 1 if VMX is ON on this cpu 126 */ 127 struct pt { 128 struct perf_output_handle handle; 129 struct pt_filters filters; 130 int handle_nmi; 131 int vmx_on; 132 }; 133 134 #endif /* __INTEL_PT_H__ */ 135