1 /* SPDX-License-Identifier: GPL-2.0 */ 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 machine; 9 struct thread; 10 11 /* number of register is bound by the number of bits in regs_dump::mask (64) */ 12 #define PERF_SAMPLE_REGS_CACHE_SIZE (8 * sizeof(u64)) 13 14 struct regs_dump { 15 u64 abi; 16 u64 mask; 17 u64 *regs; 18 19 /* Cached values/mask filled by first register access. */ 20 u64 cache_regs[PERF_SAMPLE_REGS_CACHE_SIZE]; 21 u64 cache_mask; 22 }; 23 24 struct stack_dump { 25 u16 offset; 26 u64 size; 27 char *data; 28 }; 29 30 struct sample_read_value { 31 u64 value; 32 u64 id; /* only if PERF_FORMAT_ID */ 33 u64 lost; /* only if PERF_FORMAT_LOST */ 34 }; 35 36 struct sample_read { 37 u64 time_enabled; 38 u64 time_running; 39 union { 40 struct { 41 u64 nr; 42 struct sample_read_value *values; 43 } group; 44 struct sample_read_value one; 45 }; 46 }; 47 48 static inline size_t sample_read_value_size(u64 read_format) 49 { 50 /* PERF_FORMAT_ID is forced for PERF_SAMPLE_READ */ 51 if (read_format & PERF_FORMAT_LOST) 52 return sizeof(struct sample_read_value); 53 else 54 return offsetof(struct sample_read_value, lost); 55 } 56 57 static inline struct sample_read_value *next_sample_read_value(struct sample_read_value *v, u64 read_format) 58 { 59 return (void *)v + sample_read_value_size(read_format); 60 } 61 62 #define sample_read_group__for_each(v, nr, rf) \ 63 for (int __i = 0; __i < (int)nr; v = next_sample_read_value(v, rf), __i++) 64 65 #define MAX_INSN 16 66 67 struct aux_sample { 68 u64 size; 69 void *data; 70 }; 71 72 struct simd_flags { 73 u8 arch:1, /* architecture (isa) */ 74 pred:2; /* predication */ 75 }; 76 77 /* simd architecture flags */ 78 #define SIMD_OP_FLAGS_ARCH_SVE 0x01 /* ARM SVE */ 79 80 /* simd predicate flags */ 81 #define SIMD_OP_FLAGS_PRED_PARTIAL 0x01 /* partial predicate */ 82 #define SIMD_OP_FLAGS_PRED_EMPTY 0x02 /* empty predicate */ 83 84 struct perf_sample { 85 u64 ip; 86 u32 pid, tid; 87 u64 time; 88 u64 addr; 89 u64 id; 90 u64 stream_id; 91 u64 period; 92 u64 weight; 93 u64 transaction; 94 u64 insn_cnt; 95 u64 cyc_cnt; 96 u32 cpu; 97 u32 raw_size; 98 u64 data_src; 99 u64 phys_addr; 100 u64 data_page_size; 101 u64 code_page_size; 102 u64 cgroup; 103 u32 flags; 104 u32 machine_pid; 105 u32 vcpu; 106 u16 insn_len; 107 u8 cpumode; 108 u16 misc; 109 u16 ins_lat; 110 /** @weight3: On x86 holds retire_lat, on powerpc holds p_stage_cyc. */ 111 u16 weight3; 112 bool no_hw_idx; /* No hw_idx collected in branch_stack */ 113 bool deferred_callchain; /* Has deferred user callchains */ 114 u64 deferred_cookie; 115 char insn[MAX_INSN]; 116 void *raw_data; 117 struct ip_callchain *callchain; 118 struct branch_stack *branch_stack; 119 u64 *branch_stack_cntr; 120 struct regs_dump *user_regs; 121 struct regs_dump *intr_regs; 122 struct stack_dump user_stack; 123 struct sample_read read; 124 struct aux_sample aux_sample; 125 struct simd_flags simd_flags; 126 }; 127 128 void perf_sample__init(struct perf_sample *sample, bool all); 129 void perf_sample__exit(struct perf_sample *sample); 130 struct regs_dump *perf_sample__user_regs(struct perf_sample *sample); 131 struct regs_dump *perf_sample__intr_regs(struct perf_sample *sample); 132 133 void perf_sample__fetch_insn(struct perf_sample *sample, 134 struct thread *thread, 135 struct machine *machine); 136 137 /* 138 * raw_data is always 4 bytes from an 8-byte boundary, so subtract 4 to get 139 * 8-byte alignment. 140 */ 141 static inline void *perf_sample__synth_ptr(struct perf_sample *sample) 142 { 143 return sample->raw_data - 4; 144 } 145 146 #endif /* __PERF_SAMPLE_H */ 147