1 #ifndef __PERF_MACHINE_H 2 #define __PERF_MACHINE_H 3 4 #include <sys/types.h> 5 #include <linux/rbtree.h> 6 #include "map.h" 7 #include "event.h" 8 9 struct addr_location; 10 struct branch_stack; 11 struct perf_evsel; 12 struct perf_sample; 13 struct symbol; 14 struct thread; 15 union perf_event; 16 17 /* Native host kernel uses -1 as pid index in machine */ 18 #define HOST_KERNEL_ID (-1) 19 #define DEFAULT_GUEST_KERNEL_ID (0) 20 21 extern const char *ref_reloc_sym_names[]; 22 23 struct vdso_info; 24 25 struct machine { 26 struct rb_node rb_node; 27 pid_t pid; 28 u16 id_hdr_size; 29 char *root_dir; 30 struct rb_root threads; 31 struct list_head dead_threads; 32 struct thread *last_match; 33 struct vdso_info *vdso_info; 34 struct list_head user_dsos; 35 struct list_head kernel_dsos; 36 struct map_groups kmaps; 37 struct map *vmlinux_maps[MAP__NR_TYPES]; 38 symbol_filter_t symbol_filter; 39 pid_t *current_tid; 40 }; 41 42 static inline 43 struct map *machine__kernel_map(struct machine *machine, enum map_type type) 44 { 45 return machine->vmlinux_maps[type]; 46 } 47 48 struct thread *machine__find_thread(struct machine *machine, pid_t pid, 49 pid_t tid); 50 51 int machine__process_comm_event(struct machine *machine, union perf_event *event, 52 struct perf_sample *sample); 53 int machine__process_exit_event(struct machine *machine, union perf_event *event, 54 struct perf_sample *sample); 55 int machine__process_fork_event(struct machine *machine, union perf_event *event, 56 struct perf_sample *sample); 57 int machine__process_lost_event(struct machine *machine, union perf_event *event, 58 struct perf_sample *sample); 59 int machine__process_mmap_event(struct machine *machine, union perf_event *event, 60 struct perf_sample *sample); 61 int machine__process_mmap2_event(struct machine *machine, union perf_event *event, 62 struct perf_sample *sample); 63 int machine__process_event(struct machine *machine, union perf_event *event, 64 struct perf_sample *sample); 65 66 typedef void (*machine__process_t)(struct machine *machine, void *data); 67 68 struct machines { 69 struct machine host; 70 struct rb_root guests; 71 symbol_filter_t symbol_filter; 72 }; 73 74 void machines__init(struct machines *machines); 75 void machines__exit(struct machines *machines); 76 77 void machines__process_guests(struct machines *machines, 78 machine__process_t process, void *data); 79 80 struct machine *machines__add(struct machines *machines, pid_t pid, 81 const char *root_dir); 82 struct machine *machines__find_host(struct machines *machines); 83 struct machine *machines__find(struct machines *machines, pid_t pid); 84 struct machine *machines__findnew(struct machines *machines, pid_t pid); 85 86 void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size); 87 char *machine__mmap_name(struct machine *machine, char *bf, size_t size); 88 89 void machines__set_symbol_filter(struct machines *machines, 90 symbol_filter_t symbol_filter); 91 92 struct machine *machine__new_host(void); 93 int machine__init(struct machine *machine, const char *root_dir, pid_t pid); 94 void machine__exit(struct machine *machine); 95 void machine__delete_dead_threads(struct machine *machine); 96 void machine__delete_threads(struct machine *machine); 97 void machine__delete(struct machine *machine); 98 99 struct branch_info *sample__resolve_bstack(struct perf_sample *sample, 100 struct addr_location *al); 101 struct mem_info *sample__resolve_mem(struct perf_sample *sample, 102 struct addr_location *al); 103 int machine__resolve_callchain(struct machine *machine, 104 struct perf_evsel *evsel, 105 struct thread *thread, 106 struct perf_sample *sample, 107 struct symbol **parent, 108 struct addr_location *root_al, 109 int max_stack); 110 111 /* 112 * Default guest kernel is defined by parameter --guestkallsyms 113 * and --guestmodules 114 */ 115 static inline bool machine__is_default_guest(struct machine *machine) 116 { 117 return machine ? machine->pid == DEFAULT_GUEST_KERNEL_ID : false; 118 } 119 120 static inline bool machine__is_host(struct machine *machine) 121 { 122 return machine ? machine->pid == HOST_KERNEL_ID : false; 123 } 124 125 struct thread *machine__findnew_thread(struct machine *machine, pid_t pid, 126 pid_t tid); 127 128 size_t machine__fprintf(struct machine *machine, FILE *fp); 129 130 static inline 131 struct symbol *machine__find_kernel_symbol(struct machine *machine, 132 enum map_type type, u64 addr, 133 struct map **mapp, 134 symbol_filter_t filter) 135 { 136 return map_groups__find_symbol(&machine->kmaps, type, addr, 137 mapp, filter); 138 } 139 140 static inline 141 struct symbol *machine__find_kernel_function(struct machine *machine, u64 addr, 142 struct map **mapp, 143 symbol_filter_t filter) 144 { 145 return machine__find_kernel_symbol(machine, MAP__FUNCTION, addr, 146 mapp, filter); 147 } 148 149 static inline 150 struct symbol *machine__find_kernel_function_by_name(struct machine *machine, 151 const char *name, 152 struct map **mapp, 153 symbol_filter_t filter) 154 { 155 return map_groups__find_function_by_name(&machine->kmaps, name, mapp, 156 filter); 157 } 158 159 struct map *machine__new_module(struct machine *machine, u64 start, 160 const char *filename); 161 162 int machine__load_kallsyms(struct machine *machine, const char *filename, 163 enum map_type type, symbol_filter_t filter); 164 int machine__load_vmlinux_path(struct machine *machine, enum map_type type, 165 symbol_filter_t filter); 166 167 size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp, 168 bool (skip)(struct dso *dso, int parm), int parm); 169 size_t machines__fprintf_dsos(struct machines *machines, FILE *fp); 170 size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp, 171 bool (skip)(struct dso *dso, int parm), int parm); 172 173 void machine__destroy_kernel_maps(struct machine *machine); 174 int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel); 175 int machine__create_kernel_maps(struct machine *machine); 176 177 int machines__create_kernel_maps(struct machines *machines, pid_t pid); 178 int machines__create_guest_kernel_maps(struct machines *machines); 179 void machines__destroy_kernel_maps(struct machines *machines); 180 181 size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp); 182 183 int machine__for_each_thread(struct machine *machine, 184 int (*fn)(struct thread *thread, void *p), 185 void *priv); 186 187 int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool, 188 struct target *target, struct thread_map *threads, 189 perf_event__handler_t process, bool data_mmap); 190 static inline 191 int machine__synthesize_threads(struct machine *machine, struct target *target, 192 struct thread_map *threads, bool data_mmap) 193 { 194 return __machine__synthesize_threads(machine, NULL, target, threads, 195 perf_event__process, data_mmap); 196 } 197 198 pid_t machine__get_current_tid(struct machine *machine, int cpu); 199 int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid, 200 pid_t tid); 201 202 #endif /* __PERF_MACHINE_H */ 203