1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _PERF_ANNOTATE_DATA_H 3 #define _PERF_ANNOTATE_DATA_H 4 5 #include <errno.h> 6 #include <linux/compiler.h> 7 #include <linux/rbtree.h> 8 #include <linux/types.h> 9 10 struct annotated_op_loc; 11 struct debuginfo; 12 struct evsel; 13 struct map_symbol; 14 struct thread; 15 16 /** 17 * struct annotated_member - Type of member field 18 * @node: List entry in the parent list 19 * @children: List head for child nodes 20 * @type_name: Name of the member type 21 * @var_name: Name of the member variable 22 * @offset: Offset from the outer data type 23 * @size: Size of the member field 24 * 25 * This represents a member type in a data type. 26 */ 27 struct annotated_member { 28 struct list_head node; 29 struct list_head children; 30 char *type_name; 31 char *var_name; 32 int offset; 33 int size; 34 }; 35 36 /** 37 * struct type_hist_entry - Histogram entry per offset 38 * @nr_samples: Number of samples 39 * @period: Count of event 40 */ 41 struct type_hist_entry { 42 int nr_samples; 43 u64 period; 44 }; 45 46 /** 47 * struct type_hist - Type histogram for each event 48 * @nr_samples: Total number of samples in this data type 49 * @period: Total count of the event in this data type 50 * @offset: Array of histogram entry 51 */ 52 struct type_hist { 53 u64 nr_samples; 54 u64 period; 55 struct type_hist_entry addr[]; 56 }; 57 58 /** 59 * struct annotated_data_type - Data type to profile 60 * @node: RB-tree node for dso->type_tree 61 * @self: Actual type information 62 * @nr_histogram: Number of histogram entries 63 * @histograms: An array of pointers to histograms 64 * 65 * This represents a data type accessed by samples in the profile data. 66 */ 67 struct annotated_data_type { 68 struct rb_node node; 69 struct annotated_member self; 70 int nr_histograms; 71 struct type_hist **histograms; 72 }; 73 74 extern struct annotated_data_type unknown_type; 75 extern struct annotated_data_type stackop_type; 76 extern struct annotated_data_type canary_type; 77 78 /** 79 * struct data_loc_info - Data location information 80 * @arch: CPU architecture info 81 * @thread: Thread info 82 * @ms: Map and Symbol info 83 * @ip: Instruction address 84 * @var_addr: Data address (for global variables) 85 * @cpumode: CPU execution mode 86 * @op: Instruction operand location (regs and offset) 87 * @di: Debug info 88 * @fbreg: Frame base register 89 * @fb_cfa: Whether the frame needs to check CFA 90 * @type_offset: Final offset in the type 91 */ 92 struct data_loc_info { 93 /* These are input field, should be filled by caller */ 94 struct arch *arch; 95 struct thread *thread; 96 struct map_symbol *ms; 97 u64 ip; 98 u64 var_addr; 99 u8 cpumode; 100 struct annotated_op_loc *op; 101 102 /* These are used internally */ 103 struct debuginfo *di; 104 int fbreg; 105 bool fb_cfa; 106 107 /* This is for the result */ 108 int type_offset; 109 }; 110 111 /** 112 * struct annotated_data_stat - Debug statistics 113 * @total: Total number of entry 114 * @no_sym: No symbol or map found 115 * @no_insn: Failed to get disasm line 116 * @no_insn_ops: The instruction has no operands 117 * @no_mem_ops: The instruction has no memory operands 118 * @no_reg: Failed to extract a register from the operand 119 * @no_dbginfo: The binary has no debug information 120 * @no_cuinfo: Failed to find a compile_unit 121 * @no_var: Failed to find a matching variable 122 * @no_typeinfo: Failed to get a type info for the variable 123 * @invalid_size: Failed to get a size info of the type 124 * @bad_offset: The access offset is out of the type 125 */ 126 struct annotated_data_stat { 127 int total; 128 int no_sym; 129 int no_insn; 130 int no_insn_ops; 131 int no_mem_ops; 132 int no_reg; 133 int no_dbginfo; 134 int no_cuinfo; 135 int no_var; 136 int no_typeinfo; 137 int invalid_size; 138 int bad_offset; 139 int insn_track; 140 }; 141 extern struct annotated_data_stat ann_data_stat; 142 143 #ifdef HAVE_DWARF_SUPPORT 144 145 /* Returns data type at the location (ip, reg, offset) */ 146 struct annotated_data_type *find_data_type(struct data_loc_info *dloc); 147 148 /* Update type access histogram at the given offset */ 149 int annotated_data_type__update_samples(struct annotated_data_type *adt, 150 struct evsel *evsel, int offset, 151 int nr_samples, u64 period); 152 153 /* Release all data type information in the tree */ 154 void annotated_data_type__tree_delete(struct rb_root *root); 155 156 /* Release all global variable information in the tree */ 157 void global_var_type__tree_delete(struct rb_root *root); 158 159 #else /* HAVE_DWARF_SUPPORT */ 160 161 static inline struct annotated_data_type * 162 find_data_type(struct data_loc_info *dloc __maybe_unused) 163 { 164 return NULL; 165 } 166 167 static inline int 168 annotated_data_type__update_samples(struct annotated_data_type *adt __maybe_unused, 169 struct evsel *evsel __maybe_unused, 170 int offset __maybe_unused, 171 int nr_samples __maybe_unused, 172 u64 period __maybe_unused) 173 { 174 return -1; 175 } 176 177 static inline void annotated_data_type__tree_delete(struct rb_root *root __maybe_unused) 178 { 179 } 180 181 static inline void global_var_type__tree_delete(struct rb_root *root __maybe_unused) 182 { 183 } 184 185 #endif /* HAVE_DWARF_SUPPORT */ 186 187 #endif /* _PERF_ANNOTATE_DATA_H */ 188