Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #ifndef __PERF_ANNOTATE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #define __PERF_ANNOTATE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <stdbool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <stdint.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/rbtree.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <pthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <asm/bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "symbol_conf.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "spark.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) struct hist_browser_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) struct hist_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) struct ins_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) struct map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) struct map_symbol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) struct addr_map_symbol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) struct option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) struct perf_sample;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) struct evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) struct symbol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) struct ins {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	const char     *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct ins_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) struct ins_operands {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	char	*raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	char	*raw_comment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	char	*raw_func_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		char	*raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		char	*name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		struct symbol *sym;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		u64	addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		s64	offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		bool	offset_avail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		bool	outside;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	} target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 			char	*raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 			char	*name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			u64	addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		} source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			struct ins	    ins;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			struct ins_operands *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		} locked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) struct arch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) struct ins_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	void (*free)(struct ins_operands *ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	int (*parse)(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	int (*scnprintf)(struct ins *ins, char *bf, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			 struct ins_operands *ops, int max_ins_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) bool ins__is_jump(const struct ins *ins);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) bool ins__is_call(const struct ins *ins);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) bool ins__is_ret(const struct ins *ins);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) bool ins__is_lock(const struct ins *ins);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) #define ANNOTATION__IPC_WIDTH 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) #define ANNOTATION__CYCLES_WIDTH 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) #define ANNOTATION__MINMAX_CYCLES_WIDTH 19
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #define ANNOTATION__AVG_IPC_WIDTH 36
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #define ANNOTATION_DUMMY_LEN	256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) struct annotation_options {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	bool hide_src_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	     use_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	     jump_arrows,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	     print_lines,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	     full_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	     show_linenr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	     show_nr_jumps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	     show_minmax_cycle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	     show_asm_raw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	     annotate_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	u8   offset_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	int  min_pcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	int  max_lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	int  context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	const char *objdump_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	const char *disassembler_style;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	const char *prefix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	const char *prefix_strip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	unsigned int percent_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	ANNOTATION__OFFSET_JUMP_TARGETS = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	ANNOTATION__OFFSET_CALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	ANNOTATION__MAX_OFFSET_LEVEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #define ANNOTATION__MIN_OFFSET_LEVEL ANNOTATION__OFFSET_JUMP_TARGETS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) extern struct annotation_options annotation__default_options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct annotation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct sym_hist_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	u64		nr_samples;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	u64		period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	PERCENT_HITS_LOCAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	PERCENT_HITS_GLOBAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	PERCENT_PERIOD_LOCAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	PERCENT_PERIOD_GLOBAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	PERCENT_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct annotation_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	double			 percent[PERCENT_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	double			 percent_sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	struct sym_hist_entry	 he;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct annotation_line {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	struct list_head	 node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	struct rb_node		 rb_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	s64			 offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	char			*line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	int			 line_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	int			 jump_sources;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	float			 ipc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	u64			 cycles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	u64			 cycles_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	u64			 cycles_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	char			*path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	u32			 idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	int			 idx_asm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	int			 data_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	struct annotation_data	 data[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct disasm_line {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	struct ins		 ins;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	struct ins_operands	 ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	/* This needs to be at the end. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	struct annotation_line	 al;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static inline double annotation_data__percent(struct annotation_data *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 					      unsigned int which)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	return which < PERCENT_MAX ? data->percent[which] : -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static inline const char *percent_type_str(unsigned int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	static const char *str[PERCENT_MAX] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		"local hits",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		"global hits",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		"local period",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		"global period",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	if (WARN_ON(type >= PERCENT_MAX))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		return "N/A";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	return str[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static inline struct disasm_line *disasm_line(struct annotation_line *al)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	return al ? container_of(al, struct disasm_line, al) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  * Is this offset in the same function as the line it is used?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  * asm functions jump to other functions, for instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static inline bool disasm_line__has_local_offset(const struct disasm_line *dl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	return dl->ops.target.offset_avail && !dl->ops.target.outside;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  * Can we draw an arrow from the jump to its target, for instance? I.e.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  * is the jump and its target in the same function?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) bool disasm_line__is_valid_local_jump(struct disasm_line *dl, struct symbol *sym);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) void disasm_line__free(struct disasm_line *dl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct annotation_line *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) annotation_line__next(struct annotation_line *pos, struct list_head *head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) struct annotation_write_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	bool first_line, current_entry, change_color;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	int  width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	void *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	int  (*set_color)(void *obj, int color);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	void (*set_percent_color)(void *obj, double percent, bool current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	int  (*set_jumps_percent_color)(void *obj, int nr, bool current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	void (*printf)(void *obj, const char *fmt, ...);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	void (*write_graph)(void *obj, int graph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) void annotation_line__write(struct annotation_line *al, struct annotation *notes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			    struct annotation_write_ops *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			    struct annotation_options *opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) int __annotation__scnprintf_samples_period(struct annotation *notes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 					   char *bf, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 					   struct evsel *evsel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 					   bool show_freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw, int max_ins_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) size_t disasm__fprintf(struct list_head *head, FILE *fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) void symbol__calc_percent(struct symbol *sym, struct evsel *evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) struct sym_hist {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	u64		      nr_samples;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	u64		      period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	struct sym_hist_entry addr[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct cyc_hist {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	u64	start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	u64	cycles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	u64	cycles_aggr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	u64	cycles_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	u64	cycles_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	s64	cycles_spark[NUM_SPARKS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	u32	num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	u32	num_aggr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	u8	have_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	/* 1 byte padding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	u16	reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /** struct annotated_source - symbols with hits have this attached as in sannotation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  * @histograms: Array of addr hit histograms per event being monitored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  * nr_histograms: This may not be the same as evsel->evlist->core.nr_entries if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  * 		  we have more than a group in a evlist, where we will want
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)  * 		  to see each group separately, that is why symbol__annotate2()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)  * 		  sets src->nr_histograms to evsel->nr_members.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)  * @lines: If 'print_lines' is specified, per source code line percentages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)  * @source: source parsed from a disassembler like objdump -dS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)  * @cyc_hist: Average cycles per basic block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)  * lines is allocated, percentages calculated and all sorted by percentage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)  * when the annotation is about to be presented, so the percentages are for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)  * one of the entries in the histogram array, i.e. for the event/counter being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)  * presented. It is deallocated right after symbol__{tui,tty,etc}_annotate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)  * returns.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct annotated_source {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	struct list_head   source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	int    		   nr_histograms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	size_t		   sizeof_sym_hist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	struct cyc_hist	   *cycles_hist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	struct sym_hist	   *histograms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct annotation {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	pthread_mutex_t		lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	u64			max_coverage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	u64			start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	u64			hit_cycles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	u64			hit_insn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	unsigned int		total_insn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	unsigned int		cover_insn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	struct annotation_options *options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	struct annotation_line	**offsets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	int			nr_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	int			max_jump_sources;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	int			nr_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	int			nr_asm_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	u16			max_line_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		u8		addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		u8		jumps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		u8		target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		u8		min_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		u8		max_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		u8		max_ins_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	} widths;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	bool			have_cycles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	struct annotated_source *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) static inline int annotation__cycles_width(struct annotation *notes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	if (notes->have_cycles && notes->options->show_minmax_cycle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		return ANNOTATION__IPC_WIDTH + ANNOTATION__MINMAX_CYCLES_WIDTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	return notes->have_cycles ? ANNOTATION__IPC_WIDTH + ANNOTATION__CYCLES_WIDTH : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static inline int annotation__pcnt_width(struct annotation *notes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	return (symbol_conf.show_total_period ? 12 : 7) * notes->nr_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static inline bool annotation_line__filter(struct annotation_line *al, struct annotation *notes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	return notes->options->hide_src_code && al->offset == -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) void annotation__set_offsets(struct annotation *notes, s64 size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) void annotation__compute_ipc(struct annotation *notes, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) void annotation__mark_jump_targets(struct annotation *notes, struct symbol *sym);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) void annotation__update_column_widths(struct annotation *notes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) void annotation__init_column_widths(struct annotation *notes, struct symbol *sym);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) static inline struct sym_hist *annotated_source__histogram(struct annotated_source *src, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	return ((void *)src->histograms) + (src->sizeof_sym_hist * idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) static inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	return annotated_source__histogram(notes->src, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) static inline struct annotation *symbol__annotation(struct symbol *sym)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	return (void *)sym - symbol_conf.priv_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, struct perf_sample *sample,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 				 struct evsel *evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) int addr_map_symbol__account_cycles(struct addr_map_symbol *ams,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 				    struct addr_map_symbol *start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 				    unsigned cycles);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) int hist_entry__inc_addr_samples(struct hist_entry *he, struct perf_sample *sample,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 				 struct evsel *evsel, u64 addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) struct annotated_source *symbol__hists(struct symbol *sym, int nr_hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) void symbol__annotate_zero_histograms(struct symbol *sym);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) int symbol__annotate(struct map_symbol *ms,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		     struct evsel *evsel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		     struct annotation_options *options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		     struct arch **parch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) int symbol__annotate2(struct map_symbol *ms,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		      struct evsel *evsel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		      struct annotation_options *options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		      struct arch **parch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) enum symbol_disassemble_errno {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	SYMBOL_ANNOTATE_ERRNO__SUCCESS		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	 * Choose an arbitrary negative big number not to clash with standard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	 * errno since SUS requires the errno has distinct positive values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	 * See 'Issue 6' in the link below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	 * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	__SYMBOL_ANNOTATE_ERRNO__START		= -10000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX	= __SYMBOL_ANNOTATE_ERRNO__START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	SYMBOL_ANNOTATE_ERRNO__NO_LIBOPCODES_FOR_BPF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	SYMBOL_ANNOTATE_ERRNO__BPF_INVALID_FILE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	SYMBOL_ANNOTATE_ERRNO__BPF_MISSING_BTF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	__SYMBOL_ANNOTATE_ERRNO__END,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) int symbol__strerror_disassemble(struct map_symbol *ms, int errnum, char *buf, size_t buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) int symbol__annotate_printf(struct map_symbol *ms, struct evsel *evsel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 			    struct annotation_options *options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) void annotated_source__purge(struct annotated_source *as);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) int map_symbol__annotation_dump(struct map_symbol *ms, struct evsel *evsel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 				struct annotation_options *opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) bool ui__has_annotation(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) int symbol__tty_annotate(struct map_symbol *ms, struct evsel *evsel, struct annotation_options *opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) int symbol__tty_annotate2(struct map_symbol *ms, struct evsel *evsel, struct annotation_options *opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) #ifdef HAVE_SLANG_SUPPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) int symbol__tui_annotate(struct map_symbol *ms, struct evsel *evsel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 			 struct hist_browser_timer *hbt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 			 struct annotation_options *opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) static inline int symbol__tui_annotate(struct map_symbol *ms __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 				struct evsel *evsel  __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 				struct hist_browser_timer *hbt __maybe_unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 				struct annotation_options *opts __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) void annotation_config__init(struct annotation_options *opt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) int annotate_parse_percent_type(const struct option *opt, const char *_str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 				int unset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) int annotate_check_args(struct annotation_options *args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) #endif	/* __PERF_ANNOTATE_H */