1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_MACHINE_H
3 #define __PERF_MACHINE_H
6 #include <linux/rbtree.h>
19 /* Native host kernel uses -1 as pid index in machine */
20 #define HOST_KERNEL_ID (-1)
21 #define DEFAULT_GUEST_KERNEL_ID (0)
23 extern const char *ref_reloc_sym_names[];
28 struct rb_node rb_node;
32 bool kptr_restrict_warned;
34 struct rb_root threads;
35 pthread_rwlock_t threads_lock;
36 unsigned int nr_threads;
37 struct list_head dead_threads;
38 struct thread *last_match;
39 struct vdso_info *vdso_info;
42 struct map_groups kmaps;
43 struct map *vmlinux_maps[MAP__NR_TYPES];
46 union { /* Tool specific area */
53 struct map *__machine__kernel_map(struct machine *machine, enum map_type type)
55 return machine->vmlinux_maps[type];
59 struct map *machine__kernel_map(struct machine *machine)
61 return __machine__kernel_map(machine, MAP__FUNCTION);
64 int machine__get_kernel_start(struct machine *machine);
66 static inline u64 machine__kernel_start(struct machine *machine)
68 if (!machine->kernel_start)
69 machine__get_kernel_start(machine);
70 return machine->kernel_start;
73 static inline bool machine__kernel_ip(struct machine *machine, u64 ip)
75 u64 kernel_start = machine__kernel_start(machine);
77 return ip >= kernel_start;
80 struct thread *machine__find_thread(struct machine *machine, pid_t pid,
82 struct comm *machine__thread_exec_comm(struct machine *machine,
83 struct thread *thread);
85 int machine__process_comm_event(struct machine *machine, union perf_event *event,
86 struct perf_sample *sample);
87 int machine__process_exit_event(struct machine *machine, union perf_event *event,
88 struct perf_sample *sample);
89 int machine__process_fork_event(struct machine *machine, union perf_event *event,
90 struct perf_sample *sample);
91 int machine__process_lost_event(struct machine *machine, union perf_event *event,
92 struct perf_sample *sample);
93 int machine__process_lost_samples_event(struct machine *machine, union perf_event *event,
94 struct perf_sample *sample);
95 int machine__process_aux_event(struct machine *machine,
96 union perf_event *event);
97 int machine__process_itrace_start_event(struct machine *machine,
98 union perf_event *event);
99 int machine__process_switch_event(struct machine *machine,
100 union perf_event *event);
101 int machine__process_namespaces_event(struct machine *machine,
102 union perf_event *event,
103 struct perf_sample *sample);
104 int machine__process_mmap_event(struct machine *machine, union perf_event *event,
105 struct perf_sample *sample);
106 int machine__process_mmap2_event(struct machine *machine, union perf_event *event,
107 struct perf_sample *sample);
108 int machine__process_event(struct machine *machine, union perf_event *event,
109 struct perf_sample *sample);
111 typedef void (*machine__process_t)(struct machine *machine, void *data);
115 struct rb_root guests;
118 void machines__init(struct machines *machines);
119 void machines__exit(struct machines *machines);
121 void machines__process_guests(struct machines *machines,
122 machine__process_t process, void *data);
124 struct machine *machines__add(struct machines *machines, pid_t pid,
125 const char *root_dir);
126 struct machine *machines__find_host(struct machines *machines);
127 struct machine *machines__find(struct machines *machines, pid_t pid);
128 struct machine *machines__findnew(struct machines *machines, pid_t pid);
130 void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size);
131 char *machine__mmap_name(struct machine *machine, char *bf, size_t size);
133 void machines__set_comm_exec(struct machines *machines, bool comm_exec);
135 struct machine *machine__new_host(void);
136 struct machine *machine__new_kallsyms(void);
137 int machine__init(struct machine *machine, const char *root_dir, pid_t pid);
138 void machine__exit(struct machine *machine);
139 void machine__delete_threads(struct machine *machine);
140 void machine__delete(struct machine *machine);
141 void machine__remove_thread(struct machine *machine, struct thread *th);
143 struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
144 struct addr_location *al);
145 struct mem_info *sample__resolve_mem(struct perf_sample *sample,
146 struct addr_location *al);
148 struct callchain_cursor;
150 int thread__resolve_callchain(struct thread *thread,
151 struct callchain_cursor *cursor,
152 struct perf_evsel *evsel,
153 struct perf_sample *sample,
154 struct symbol **parent,
155 struct addr_location *root_al,
159 * Default guest kernel is defined by parameter --guestkallsyms
162 static inline bool machine__is_default_guest(struct machine *machine)
164 return machine ? machine->pid == DEFAULT_GUEST_KERNEL_ID : false;
167 static inline bool machine__is_host(struct machine *machine)
169 return machine ? machine->pid == HOST_KERNEL_ID : false;
172 struct thread *__machine__findnew_thread(struct machine *machine, pid_t pid, pid_t tid);
173 struct thread *machine__findnew_thread(struct machine *machine, pid_t pid, pid_t tid);
175 struct dso *machine__findnew_dso(struct machine *machine, const char *filename);
177 size_t machine__fprintf(struct machine *machine, FILE *fp);
180 struct symbol *machine__find_kernel_symbol(struct machine *machine,
181 enum map_type type, u64 addr,
184 return map_groups__find_symbol(&machine->kmaps, type, addr, mapp);
188 struct symbol *machine__find_kernel_symbol_by_name(struct machine *machine,
189 enum map_type type, const char *name,
192 return map_groups__find_symbol_by_name(&machine->kmaps, type, name, mapp);
196 struct symbol *machine__find_kernel_function(struct machine *machine, u64 addr,
199 return machine__find_kernel_symbol(machine, MAP__FUNCTION, addr,
204 struct symbol *machine__find_kernel_function_by_name(struct machine *machine,
208 return map_groups__find_function_by_name(&machine->kmaps, name, mapp);
211 struct map *machine__findnew_module_map(struct machine *machine, u64 start,
212 const char *filename);
213 int arch__fix_module_text_start(u64 *start, const char *name);
215 int __machine__load_kallsyms(struct machine *machine, const char *filename,
216 enum map_type type, bool no_kcore);
217 int machine__load_kallsyms(struct machine *machine, const char *filename,
219 int machine__load_vmlinux_path(struct machine *machine, enum map_type type);
221 size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
222 bool (skip)(struct dso *dso, int parm), int parm);
223 size_t machines__fprintf_dsos(struct machines *machines, FILE *fp);
224 size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
225 bool (skip)(struct dso *dso, int parm), int parm);
227 void machine__destroy_kernel_maps(struct machine *machine);
228 int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel);
229 int machine__create_kernel_maps(struct machine *machine);
231 int machines__create_kernel_maps(struct machines *machines, pid_t pid);
232 int machines__create_guest_kernel_maps(struct machines *machines);
233 void machines__destroy_kernel_maps(struct machines *machines);
235 size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
237 int machine__for_each_thread(struct machine *machine,
238 int (*fn)(struct thread *thread, void *p),
240 int machines__for_each_thread(struct machines *machines,
241 int (*fn)(struct thread *thread, void *p),
244 int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool,
245 struct target *target, struct thread_map *threads,
246 perf_event__handler_t process, bool data_mmap,
247 unsigned int proc_map_timeout);
249 int machine__synthesize_threads(struct machine *machine, struct target *target,
250 struct thread_map *threads, bool data_mmap,
251 unsigned int proc_map_timeout)
253 return __machine__synthesize_threads(machine, NULL, target, threads,
254 perf_event__process, data_mmap,
258 pid_t machine__get_current_tid(struct machine *machine, int cpu);
259 int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid,
262 * For use with libtraceevent's pevent_set_function_resolver()
264 char *machine__resolve_kernel_addr(void *vmachine, unsigned long long *addrp, char **modp);
266 #endif /* __PERF_MACHINE_H */