1b9c87f53SNamhyung Kim /* SPDX-License-Identifier: GPL-2.0 */ 2b9c87f53SNamhyung Kim #ifndef _PERF_ANNOTATE_DATA_H 3b9c87f53SNamhyung Kim #define _PERF_ANNOTATE_DATA_H 4b9c87f53SNamhyung Kim 5b9c87f53SNamhyung Kim #include <errno.h> 6b9c87f53SNamhyung Kim #include <linux/compiler.h> 7fc044c53SNamhyung Kim #include <linux/rbtree.h> 8b9c87f53SNamhyung Kim #include <linux/types.h> 9b9c87f53SNamhyung Kim 10d3030191SNamhyung Kim struct annotated_op_loc; 11a3f4d5b5SNamhyung Kim struct debuginfo; 129bd7ddd1SNamhyung Kim struct evsel; 13b9c87f53SNamhyung Kim struct map_symbol; 14b9c87f53SNamhyung Kim 15b9c87f53SNamhyung Kim /** 164a111cadSNamhyung Kim * struct annotated_member - Type of member field 174a111cadSNamhyung Kim * @node: List entry in the parent list 184a111cadSNamhyung Kim * @children: List head for child nodes 194a111cadSNamhyung Kim * @type_name: Name of the member type 204a111cadSNamhyung Kim * @var_name: Name of the member variable 214a111cadSNamhyung Kim * @offset: Offset from the outer data type 224a111cadSNamhyung Kim * @size: Size of the member field 234a111cadSNamhyung Kim * 244a111cadSNamhyung Kim * This represents a member type in a data type. 254a111cadSNamhyung Kim */ 264a111cadSNamhyung Kim struct annotated_member { 274a111cadSNamhyung Kim struct list_head node; 284a111cadSNamhyung Kim struct list_head children; 294a111cadSNamhyung Kim char *type_name; 304a111cadSNamhyung Kim char *var_name; 314a111cadSNamhyung Kim int offset; 324a111cadSNamhyung Kim int size; 334a111cadSNamhyung Kim }; 344a111cadSNamhyung Kim 354a111cadSNamhyung Kim /** 369bd7ddd1SNamhyung Kim * struct type_hist_entry - Histogram entry per offset 379bd7ddd1SNamhyung Kim * @nr_samples: Number of samples 389bd7ddd1SNamhyung Kim * @period: Count of event 399bd7ddd1SNamhyung Kim */ 409bd7ddd1SNamhyung Kim struct type_hist_entry { 419bd7ddd1SNamhyung Kim int nr_samples; 429bd7ddd1SNamhyung Kim u64 period; 439bd7ddd1SNamhyung Kim }; 449bd7ddd1SNamhyung Kim 459bd7ddd1SNamhyung Kim /** 469bd7ddd1SNamhyung Kim * struct type_hist - Type histogram for each event 479bd7ddd1SNamhyung Kim * @nr_samples: Total number of samples in this data type 489bd7ddd1SNamhyung Kim * @period: Total count of the event in this data type 499bd7ddd1SNamhyung Kim * @offset: Array of histogram entry 509bd7ddd1SNamhyung Kim */ 519bd7ddd1SNamhyung Kim struct type_hist { 529bd7ddd1SNamhyung Kim u64 nr_samples; 539bd7ddd1SNamhyung Kim u64 period; 549bd7ddd1SNamhyung Kim struct type_hist_entry addr[]; 559bd7ddd1SNamhyung Kim }; 569bd7ddd1SNamhyung Kim 579bd7ddd1SNamhyung Kim /** 58b9c87f53SNamhyung Kim * struct annotated_data_type - Data type to profile 594a111cadSNamhyung Kim * @node: RB-tree node for dso->type_tree 604a111cadSNamhyung Kim * @self: Actual type information 619bd7ddd1SNamhyung Kim * @nr_histogram: Number of histogram entries 629bd7ddd1SNamhyung Kim * @histograms: An array of pointers to histograms 63b9c87f53SNamhyung Kim * 64b9c87f53SNamhyung Kim * This represents a data type accessed by samples in the profile data. 65b9c87f53SNamhyung Kim */ 66b9c87f53SNamhyung Kim struct annotated_data_type { 67fc044c53SNamhyung Kim struct rb_node node; 684a111cadSNamhyung Kim struct annotated_member self; 699bd7ddd1SNamhyung Kim int nr_histograms; 709bd7ddd1SNamhyung Kim struct type_hist **histograms; 71b9c87f53SNamhyung Kim }; 72b9c87f53SNamhyung Kim 732f2c41bdSNamhyung Kim extern struct annotated_data_type unknown_type; 747a54f1d8SNamhyung Kim extern struct annotated_data_type stackop_type; 752f2c41bdSNamhyung Kim 7661a9741eSNamhyung Kim /** 77a3f4d5b5SNamhyung Kim * struct data_loc_info - Data location information 78*4f903455SNamhyung Kim * @arch: CPU architecture info 79a3f4d5b5SNamhyung Kim * @ms: Map and Symbol info 80a3f4d5b5SNamhyung Kim * @ip: Instruction address 81a3f4d5b5SNamhyung Kim * @var_addr: Data address (for global variables) 82a3f4d5b5SNamhyung Kim * @var_name: Variable name (for global variables) 83a3f4d5b5SNamhyung Kim * @op: Instruction operand location (regs and offset) 84a3f4d5b5SNamhyung Kim * @di: Debug info 85a3f4d5b5SNamhyung Kim * @fbreg: Frame base register 86a3f4d5b5SNamhyung Kim * @fb_cfa: Whether the frame needs to check CFA 87a3f4d5b5SNamhyung Kim * @type_offset: Final offset in the type 88a3f4d5b5SNamhyung Kim */ 89a3f4d5b5SNamhyung Kim struct data_loc_info { 90a3f4d5b5SNamhyung Kim /* These are input field, should be filled by caller */ 91*4f903455SNamhyung Kim struct arch *arch; 92a3f4d5b5SNamhyung Kim struct map_symbol *ms; 93a3f4d5b5SNamhyung Kim u64 ip; 94a3f4d5b5SNamhyung Kim u64 var_addr; 95a3f4d5b5SNamhyung Kim const char *var_name; 96a3f4d5b5SNamhyung Kim struct annotated_op_loc *op; 97a3f4d5b5SNamhyung Kim 98a3f4d5b5SNamhyung Kim /* These are used internally */ 99a3f4d5b5SNamhyung Kim struct debuginfo *di; 100a3f4d5b5SNamhyung Kim int fbreg; 101a3f4d5b5SNamhyung Kim bool fb_cfa; 102a3f4d5b5SNamhyung Kim 103a3f4d5b5SNamhyung Kim /* This is for the result */ 104a3f4d5b5SNamhyung Kim int type_offset; 105a3f4d5b5SNamhyung Kim }; 106a3f4d5b5SNamhyung Kim 107a3f4d5b5SNamhyung Kim /** 10861a9741eSNamhyung Kim * struct annotated_data_stat - Debug statistics 10961a9741eSNamhyung Kim * @total: Total number of entry 11061a9741eSNamhyung Kim * @no_sym: No symbol or map found 11161a9741eSNamhyung Kim * @no_insn: Failed to get disasm line 11261a9741eSNamhyung Kim * @no_insn_ops: The instruction has no operands 11361a9741eSNamhyung Kim * @no_mem_ops: The instruction has no memory operands 11461a9741eSNamhyung Kim * @no_reg: Failed to extract a register from the operand 11561a9741eSNamhyung Kim * @no_dbginfo: The binary has no debug information 11661a9741eSNamhyung Kim * @no_cuinfo: Failed to find a compile_unit 11761a9741eSNamhyung Kim * @no_var: Failed to find a matching variable 11861a9741eSNamhyung Kim * @no_typeinfo: Failed to get a type info for the variable 11961a9741eSNamhyung Kim * @invalid_size: Failed to get a size info of the type 12061a9741eSNamhyung Kim * @bad_offset: The access offset is out of the type 12161a9741eSNamhyung Kim */ 12261a9741eSNamhyung Kim struct annotated_data_stat { 12361a9741eSNamhyung Kim int total; 12461a9741eSNamhyung Kim int no_sym; 12561a9741eSNamhyung Kim int no_insn; 12661a9741eSNamhyung Kim int no_insn_ops; 12761a9741eSNamhyung Kim int no_mem_ops; 12861a9741eSNamhyung Kim int no_reg; 12961a9741eSNamhyung Kim int no_dbginfo; 13061a9741eSNamhyung Kim int no_cuinfo; 13161a9741eSNamhyung Kim int no_var; 13261a9741eSNamhyung Kim int no_typeinfo; 13361a9741eSNamhyung Kim int invalid_size; 13461a9741eSNamhyung Kim int bad_offset; 13561a9741eSNamhyung Kim }; 13661a9741eSNamhyung Kim extern struct annotated_data_stat ann_data_stat; 13761a9741eSNamhyung Kim 138b9c87f53SNamhyung Kim #ifdef HAVE_DWARF_SUPPORT 139b9c87f53SNamhyung Kim 140b9c87f53SNamhyung Kim /* Returns data type at the location (ip, reg, offset) */ 141a3f4d5b5SNamhyung Kim struct annotated_data_type *find_data_type(struct data_loc_info *dloc); 142b9c87f53SNamhyung Kim 1439bd7ddd1SNamhyung Kim /* Update type access histogram at the given offset */ 1449bd7ddd1SNamhyung Kim int annotated_data_type__update_samples(struct annotated_data_type *adt, 1459bd7ddd1SNamhyung Kim struct evsel *evsel, int offset, 1469bd7ddd1SNamhyung Kim int nr_samples, u64 period); 1479bd7ddd1SNamhyung Kim 148fc044c53SNamhyung Kim /* Release all data type information in the tree */ 149fc044c53SNamhyung Kim void annotated_data_type__tree_delete(struct rb_root *root); 150fc044c53SNamhyung Kim 151b9c87f53SNamhyung Kim #else /* HAVE_DWARF_SUPPORT */ 152b9c87f53SNamhyung Kim 153b9c87f53SNamhyung Kim static inline struct annotated_data_type * 154a3f4d5b5SNamhyung Kim find_data_type(struct data_loc_info *dloc __maybe_unused) 155b9c87f53SNamhyung Kim { 156b9c87f53SNamhyung Kim return NULL; 157b9c87f53SNamhyung Kim } 158b9c87f53SNamhyung Kim 1599bd7ddd1SNamhyung Kim static inline int 1609bd7ddd1SNamhyung Kim annotated_data_type__update_samples(struct annotated_data_type *adt __maybe_unused, 1619bd7ddd1SNamhyung Kim struct evsel *evsel __maybe_unused, 1629bd7ddd1SNamhyung Kim int offset __maybe_unused, 1639bd7ddd1SNamhyung Kim int nr_samples __maybe_unused, 1649bd7ddd1SNamhyung Kim u64 period __maybe_unused) 1659bd7ddd1SNamhyung Kim { 1669bd7ddd1SNamhyung Kim return -1; 1679bd7ddd1SNamhyung Kim } 1689bd7ddd1SNamhyung Kim 169fc044c53SNamhyung Kim static inline void annotated_data_type__tree_delete(struct rb_root *root __maybe_unused) 170fc044c53SNamhyung Kim { 171fc044c53SNamhyung Kim } 172fc044c53SNamhyung Kim 173b9c87f53SNamhyung Kim #endif /* HAVE_DWARF_SUPPORT */ 174b9c87f53SNamhyung Kim 175b9c87f53SNamhyung Kim #endif /* _PERF_ANNOTATE_DATA_H */ 176