| 1 |
|
| 2 | #ifndef __PERF_SAMPLE_H
|
| 3 | #define __PERF_SAMPLE_H
|
| 4 |
|
| 5 | #include <linux/perf_event.h>
|
| 6 | #include <linux/types.h>
|
| 7 |
|
| 8 | struct evsel;
|
| 9 | struct machine;
|
| 10 | struct thread;
|
| 11 |
|
| 12 |
|
| 13 | #define PERF_SAMPLE_REGS_CACHE_SIZE (8 * sizeof(u64))
|
| 14 |
|
| 15 | struct regs_dump {
|
| 16 | u64 abi;
|
| 17 | u64 mask;
|
| 18 | u64 *regs;
|
| 19 |
|
| 20 |
|
| 21 | u64 cache_regs[PERF_SAMPLE_REGS_CACHE_SIZE];
|
| 22 | u64 cache_mask;
|
| 23 | };
|
| 24 |
|
| 25 | struct stack_dump {
|
| 26 | u16 offset;
|
| 27 | u64 size;
|
| 28 | char *data;
|
| 29 | };
|
| 30 |
|
| 31 | struct sample_read_value {
|
| 32 | u64 value;
|
| 33 | u64 id;
|
| 34 | u64 lost;
|
| 35 | };
|
| 36 |
|
| 37 | struct sample_read {
|
| 38 | u64 time_enabled;
|
| 39 | u64 time_running;
|
| 40 | union {
|
| 41 | struct {
|
| 42 | u64 nr;
|
| 43 | struct sample_read_value *values;
|
| 44 | } group;
|
| 45 | struct sample_read_value one;
|
| 46 | };
|
| 47 | };
|
| 48 |
|
| 49 | static inline size_t sample_read_value_size(u64 read_format)
|
| 50 | {
|
| 51 |
|
| 52 | if (read_format & PERF_FORMAT_LOST)
|
| 53 | return sizeof(struct sample_read_value);
|
| 54 | else
|
| 55 | return offsetof(struct sample_read_value, lost);
|
| 56 | }
|
| 57 |
|
| 58 | static inline struct sample_read_value *next_sample_read_value(struct sample_read_value *v, u64 read_format)
|
| 59 | {
|
| 60 | return (void *)v + sample_read_value_size(read_format);
|
| 61 | }
|
| 62 |
|
| 63 | #define sample_read_group__for_each(v, nr, rf) \
|
| 64 | for (int __i = 0; __i < (int)nr; v = next_sample_read_value(v, rf), __i++)
|
| 65 |
|
| 66 | #define MAX_INSN 16
|
| 67 |
|
| 68 | struct aux_sample {
|
| 69 | u64 size;
|
| 70 | void *data;
|
| 71 | };
|
| 72 |
|
| 73 | struct simd_flags {
|
| 74 | u8 arch: 2,
|
| 75 | pred: 3,
|
| 76 | resv: 3;
|
| 77 | };
|
| 78 |
|
| 79 |
|
| 80 | enum simd_op_flags {
|
| 81 | SIMD_OP_FLAGS_ARCH_NONE = 0x0,
|
| 82 | SIMD_OP_FLAGS_ARCH_SVE,
|
| 83 | SIMD_OP_FLAGS_ARCH_SME,
|
| 84 | SIMD_OP_FLAGS_ARCH_ASE,
|
| 85 | };
|
| 86 |
|
| 87 |
|
| 88 | enum simd_pred_flags {
|
| 89 | SIMD_OP_FLAGS_PRED_NONE = 0x0,
|
| 90 | SIMD_OP_FLAGS_PRED_PARTIAL,
|
| 91 | SIMD_OP_FLAGS_PRED_EMPTY,
|
| 92 | SIMD_OP_FLAGS_PRED_FULL,
|
| 93 | SIMD_OP_FLAGS_PRED_DISABLED,
|
| 94 | };
|
| 95 |
|
| 96 | |
| 97 | * struct perf_sample
|
| 98 | *
|
| 99 | * A sample is generally filled in by evlist__parse_sample/evsel__parse_sample
|
| 100 | * which fills in the variables from a "union perf_event *event" which is data
|
| 101 | * from a perf ring buffer or perf.data file. The "event" sample is variable in
|
| 102 | * length as determined by the perf_event_attr (in the evsel) and details within
|
| 103 | * the sample event itself. A struct perf_sample avoids needing to care about
|
| 104 | * the variable length nature of the original event.
|
| 105 | *
|
| 106 | * To avoid being excessively large parts of the struct perf_sample are pointers
|
| 107 | * into the original sample event. In general the lifetime of a struct
|
| 108 | * perf_sample needs to be less than the "union perf_event *event" it was
|
| 109 | * derived from.
|
| 110 | *
|
| 111 | * The struct regs_dump user_regs and intr_regs are lazily allocated again for
|
| 112 | * size reasons, due to them holding a cache of looked up registers. The
|
| 113 | * function pair of perf_sample__init and perf_sample__exit correctly initialize
|
| 114 | * and clean up these values.
|
| 115 |
|
| 116 | struct perf_sample {
|
| 117 |
|
| 118 | struct evsel *evsel;
|
| 119 |
|
| 120 | u64 ip;
|
| 121 |
|
| 122 | u32 pid;
|
| 123 |
|
| 124 | u32 tid;
|
| 125 |
|
| 126 | u64 time;
|
| 127 |
|
| 128 | u64 addr;
|
| 129 |
|
| 130 | u64 id;
|
| 131 |
|
| 132 | u64 stream_id;
|
| 133 |
|
| 134 | u64 period;
|
| 135 |
|
| 136 | u64 weight;
|
| 137 |
|
| 138 | u64 transaction;
|
| 139 |
|
| 140 | u64 insn_cnt;
|
| 141 |
|
| 142 | u64 cyc_cnt;
|
| 143 |
|
| 144 | u32 cpu;
|
| 145 | |
| 146 | * @raw_size: The size in bytes of raw data from PERF_SAMPLE_RAW. For
|
| 147 | * alignment reasons this should always be sizeof(u32)
|
| 148 | * followed by a multiple of sizeof(u64).
|
| 149 |
|
| 150 | u32 raw_size;
|
| 151 |
|
| 152 | u64 data_src;
|
| 153 |
|
| 154 | u64 phys_addr;
|
| 155 |
|
| 156 | u64 data_page_size;
|
| 157 |
|
| 158 | u64 code_page_size;
|
| 159 |
|
| 160 | u64 cgroup;
|
| 161 |
|
| 162 | u64 file_offset;
|
| 163 |
|
| 164 | u32 flags;
|
| 165 |
|
| 166 | u32 machine_pid;
|
| 167 |
|
| 168 | u32 vcpu;
|
| 169 | |
| 170 | * @insn_len: Instruction length from auxiliary events like
|
| 171 | * intel-pt. The instruction itself is held in insn.
|
| 172 |
|
| 173 | u16 insn_len;
|
| 174 |
|
| 175 | u16 misc;
|
| 176 | |
| 177 | * @ins_lat: Instruction latency information from weight2 in
|
| 178 | * PERF_SAMPLE_WEIGHT_STRUCT or auxiliary events like
|
| 179 | * intel-pt.
|
| 180 |
|
| 181 | u16 ins_lat;
|
| 182 | |
| 183 | * @weight3: From PERF_SAMPLE_WEIGHT_STRUCT. On x86 holds retire_lat, on
|
| 184 | * powerpc holds p_stage_cyc.
|
| 185 |
|
| 186 | u16 weight3;
|
| 187 | |
| 188 | * @cpumode: The cpumode from struct perf_event_header misc variable
|
| 189 | * masked with CPUMODE_MASK. Gives user, kernel and hypervisor
|
| 190 | * information.
|
| 191 |
|
| 192 | u8 cpumode;
|
| 193 | |
| 194 | * @no_hw_idx: For PERF_SAMPLE_BRANCH_STACK, true when
|
| 195 | * PERF_SAMPLE_BRANCH_HW_INDEX isn't set.
|
| 196 |
|
| 197 | bool no_hw_idx;
|
| 198 | |
| 199 | * @deferred_callchain: When processing PERF_SAMPLE_CALLCHAIN a deferred
|
| 200 | * user callchain marker was encountered.
|
| 201 |
|
| 202 | bool deferred_callchain;
|
| 203 | |
| 204 | * @merged_callchain: A synthesized merged callchain that is allocated
|
| 205 | * and needs freeing.
|
| 206 |
|
| 207 | bool merged_callchain;
|
| 208 | |
| 209 | * @deferred_cookie: Identifier of the deferred callchain in the later
|
| 210 | * PERF_RECORD_CALLCHAIN_DEFERRED event.
|
| 211 |
|
| 212 | u64 deferred_cookie;
|
| 213 |
|
| 214 | char insn[MAX_INSN];
|
| 215 |
|
| 216 | void *raw_data;
|
| 217 | |
| 218 | * @callchain: Pointer into the original event for PERF_SAMPLE_CALLCHAIN
|
| 219 | * data. For deferred callchains this may be a copy that
|
| 220 | * needs freeing, see sample__merge_deferred_callchain.
|
| 221 |
|
| 222 | struct ip_callchain *callchain;
|
| 223 |
|
| 224 | struct branch_stack *branch_stack;
|
| 225 | |
| 226 | * @branch_stack_cntr: Pointer into the original event for
|
| 227 | * PERF_SAMPLE_BRANCH_COUNTERS data.
|
| 228 |
|
| 229 | u64 *branch_stack_cntr;
|
| 230 |
|
| 231 | struct regs_dump *user_regs;
|
| 232 |
|
| 233 | struct regs_dump *intr_regs;
|
| 234 |
|
| 235 | struct stack_dump user_stack;
|
| 236 | |
| 237 | * @read: The sample event PERF_SAMPLE_READ counter values. The valid
|
| 238 | * values depend on the attr.read_format PERF_FORMAT_ values.
|
| 239 |
|
| 240 | struct sample_read read;
|
| 241 | |
| 242 | * @aux_sample: Similar to raw data but with a 64-bit size and
|
| 243 | * alignment, PERF_SAMPLE_AUX data.
|
| 244 |
|
| 245 | struct aux_sample aux_sample;
|
| 246 |
|
| 247 | struct simd_flags simd_flags;
|
| 248 | };
|
| 249 |
|
| 250 | void perf_sample__init(struct perf_sample *sample, bool all);
|
| 251 | void perf_sample__exit(struct perf_sample *sample);
|
| 252 | struct regs_dump *perf_sample__user_regs(struct perf_sample *sample);
|
| 253 | struct regs_dump *perf_sample__intr_regs(struct perf_sample *sample);
|
| 254 |
|
| 255 | void perf_sample__fetch_insn(struct perf_sample *sample,
|
| 256 | struct thread *thread,
|
| 257 | struct machine *machine);
|
| 258 |
|
| 259 | |
| 260 | * raw_data is always 4 bytes from an 8-byte boundary, so subtract 4 to get
|
| 261 | * 8-byte alignment.
|
| 262 |
|
| 263 | static inline void *perf_sample__synth_ptr(struct perf_sample *sample)
|
| 264 | {
|
| 265 | return sample->raw_data - 4;
|
| 266 | }
|
| 267 |
|
| 268 | #endif
|