]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
9d2f8e22 ACM |
2 | #ifndef __PERF_MACHINE_H |
3 | #define __PERF_MACHINE_H | |
4 | ||
5 | #include <sys/types.h> | |
69d2591a ACM |
6 | #include <linux/rbtree.h> |
7 | #include "map.h" | |
8fa7d87f | 8 | #include "dso.h" |
58d925dc | 9 | #include "event.h" |
0a7c74ea | 10 | #include "rwsem.h" |
9d2f8e22 | 11 | |
b21484f1 | 12 | struct addr_location; |
69d2591a ACM |
13 | struct branch_stack; |
14 | struct perf_evsel; | |
15 | struct perf_sample; | |
16 | struct symbol; | |
9d2f8e22 | 17 | struct thread; |
b0a7d1a0 | 18 | union perf_event; |
9d2f8e22 | 19 | |
69d2591a ACM |
20 | /* Native host kernel uses -1 as pid index in machine */ |
21 | #define HOST_KERNEL_ID (-1) | |
22 | #define DEFAULT_GUEST_KERNEL_ID (0) | |
23 | ||
5512cf24 AH |
24 | extern const char *ref_reloc_sym_names[]; |
25 | ||
d027b640 AH |
26 | struct vdso_info; |
27 | ||
91e467bc KL |
28 | #define THREADS__TABLE_BITS 8 |
29 | #define THREADS__TABLE_SIZE (1 << THREADS__TABLE_BITS) | |
30 | ||
31 | struct threads { | |
32 | struct rb_root entries; | |
0a7c74ea | 33 | struct rw_semaphore lock; |
91e467bc KL |
34 | unsigned int nr; |
35 | struct list_head dead; | |
36 | struct thread *last_match; | |
37 | }; | |
38 | ||
69d2591a ACM |
39 | struct machine { |
40 | struct rb_node rb_node; | |
41 | pid_t pid; | |
42 | u16 id_hdr_size; | |
cfe1c414 | 43 | bool comm_exec; |
caf8a0d0 | 44 | bool kptr_restrict_warned; |
69d2591a | 45 | char *root_dir; |
8c7f1bb3 | 46 | char *mmap_name; |
91e467bc | 47 | struct threads threads[THREADS__TABLE_SIZE]; |
d027b640 | 48 | struct vdso_info *vdso_info; |
4cde998d | 49 | struct perf_env *env; |
3d39ac53 | 50 | struct dsos dsos; |
69d2591a | 51 | struct map_groups kmaps; |
3183f8ca | 52 | struct map *vmlinux_map; |
fbe2af45 | 53 | u64 kernel_start; |
b9d266ba | 54 | pid_t *current_tid; |
0db15b1e AH |
55 | union { /* Tool specific area */ |
56 | void *priv; | |
57 | u64 db_id; | |
58 | }; | |
69d2591a ACM |
59 | }; |
60 | ||
91e467bc KL |
61 | static inline struct threads *machine__threads(struct machine *machine, pid_t tid) |
62 | { | |
63 | /* Cast it to handle tid == -1 */ | |
64 | return &machine->threads[(unsigned int)tid % THREADS__TABLE_SIZE]; | |
65 | } | |
66 | ||
68a74186 ACM |
67 | /* |
68 | * The main kernel (vmlinux) map | |
69 | */ | |
a5e813c6 ACM |
70 | static inline |
71 | struct map *machine__kernel_map(struct machine *machine) | |
72 | { | |
3183f8ca | 73 | return machine->vmlinux_map; |
a5e813c6 ACM |
74 | } |
75 | ||
68a74186 ACM |
76 | /* |
77 | * kernel (the one returned by machine__kernel_map()) plus kernel modules maps | |
78 | */ | |
79 | static inline | |
80 | struct maps *machine__kernel_maps(struct machine *machine) | |
81 | { | |
3183f8ca | 82 | return &machine->kmaps.maps; |
68a74186 ACM |
83 | } |
84 | ||
fbe2af45 AH |
85 | int machine__get_kernel_start(struct machine *machine); |
86 | ||
87 | static inline u64 machine__kernel_start(struct machine *machine) | |
88 | { | |
89 | if (!machine->kernel_start) | |
90 | machine__get_kernel_start(machine); | |
91 | return machine->kernel_start; | |
92 | } | |
93 | ||
94 | static inline bool machine__kernel_ip(struct machine *machine, u64 ip) | |
95 | { | |
96 | u64 kernel_start = machine__kernel_start(machine); | |
97 | ||
98 | return ip >= kernel_start; | |
99 | } | |
100 | ||
d75e6097 JO |
101 | struct thread *machine__find_thread(struct machine *machine, pid_t pid, |
102 | pid_t tid); | |
cfe1c414 AH |
103 | struct comm *machine__thread_exec_comm(struct machine *machine, |
104 | struct thread *thread); | |
9d2f8e22 | 105 | |
162f0bef FW |
106 | int machine__process_comm_event(struct machine *machine, union perf_event *event, |
107 | struct perf_sample *sample); | |
108 | int machine__process_exit_event(struct machine *machine, union perf_event *event, | |
109 | struct perf_sample *sample); | |
110 | int machine__process_fork_event(struct machine *machine, union perf_event *event, | |
111 | struct perf_sample *sample); | |
112 | int machine__process_lost_event(struct machine *machine, union perf_event *event, | |
113 | struct perf_sample *sample); | |
c4937a91 KL |
114 | int machine__process_lost_samples_event(struct machine *machine, union perf_event *event, |
115 | struct perf_sample *sample); | |
4a96f7a0 AH |
116 | int machine__process_aux_event(struct machine *machine, |
117 | union perf_event *event); | |
0ad21f68 AH |
118 | int machine__process_itrace_start_event(struct machine *machine, |
119 | union perf_event *event); | |
b8f8eb84 | 120 | int machine__process_switch_event(struct machine *machine, |
0286039f | 121 | union perf_event *event); |
f3b3614a HB |
122 | int machine__process_namespaces_event(struct machine *machine, |
123 | union perf_event *event, | |
124 | struct perf_sample *sample); | |
162f0bef FW |
125 | int machine__process_mmap_event(struct machine *machine, union perf_event *event, |
126 | struct perf_sample *sample); | |
127 | int machine__process_mmap2_event(struct machine *machine, union perf_event *event, | |
128 | struct perf_sample *sample); | |
129 | int machine__process_event(struct machine *machine, union perf_event *event, | |
130 | struct perf_sample *sample); | |
b0a7d1a0 | 131 | |
69d2591a ACM |
132 | typedef void (*machine__process_t)(struct machine *machine, void *data); |
133 | ||
876650e6 ACM |
134 | struct machines { |
135 | struct machine host; | |
136 | struct rb_root guests; | |
137 | }; | |
138 | ||
139 | void machines__init(struct machines *machines); | |
140 | void machines__exit(struct machines *machines); | |
141 | ||
142 | void machines__process_guests(struct machines *machines, | |
143 | machine__process_t process, void *data); | |
69d2591a | 144 | |
876650e6 | 145 | struct machine *machines__add(struct machines *machines, pid_t pid, |
69d2591a | 146 | const char *root_dir); |
876650e6 ACM |
147 | struct machine *machines__find_host(struct machines *machines); |
148 | struct machine *machines__find(struct machines *machines, pid_t pid); | |
149 | struct machine *machines__findnew(struct machines *machines, pid_t pid); | |
69d2591a | 150 | |
876650e6 | 151 | void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size); |
cfe1c414 | 152 | void machines__set_comm_exec(struct machines *machines, bool comm_exec); |
611a5ce8 | 153 | |
8fb598e5 | 154 | struct machine *machine__new_host(void); |
7d132caa | 155 | struct machine *machine__new_kallsyms(void); |
69d2591a ACM |
156 | int machine__init(struct machine *machine, const char *root_dir, pid_t pid); |
157 | void machine__exit(struct machine *machine); | |
3f067dca | 158 | void machine__delete_threads(struct machine *machine); |
69d2591a | 159 | void machine__delete(struct machine *machine); |
5e78c69b | 160 | void machine__remove_thread(struct machine *machine, struct thread *th); |
69d2591a | 161 | |
644f2df2 ACM |
162 | struct branch_info *sample__resolve_bstack(struct perf_sample *sample, |
163 | struct addr_location *al); | |
e80faac0 ACM |
164 | struct mem_info *sample__resolve_mem(struct perf_sample *sample, |
165 | struct addr_location *al); | |
91d7b2de ACM |
166 | |
167 | struct callchain_cursor; | |
168 | ||
cc8b7c2b | 169 | int thread__resolve_callchain(struct thread *thread, |
91d7b2de | 170 | struct callchain_cursor *cursor, |
cc8b7c2b ACM |
171 | struct perf_evsel *evsel, |
172 | struct perf_sample *sample, | |
173 | struct symbol **parent, | |
174 | struct addr_location *root_al, | |
175 | int max_stack); | |
69d2591a ACM |
176 | |
177 | /* | |
178 | * Default guest kernel is defined by parameter --guestkallsyms | |
179 | * and --guestmodules | |
180 | */ | |
181 | static inline bool machine__is_default_guest(struct machine *machine) | |
182 | { | |
183 | return machine ? machine->pid == DEFAULT_GUEST_KERNEL_ID : false; | |
184 | } | |
185 | ||
186 | static inline bool machine__is_host(struct machine *machine) | |
187 | { | |
188 | return machine ? machine->pid == HOST_KERNEL_ID : false; | |
189 | } | |
190 | ||
b91fc39f ACM |
191 | struct thread *__machine__findnew_thread(struct machine *machine, pid_t pid, pid_t tid); |
192 | struct thread *machine__findnew_thread(struct machine *machine, pid_t pid, pid_t tid); | |
69d2591a | 193 | |
aa7cc2ae ACM |
194 | struct dso *machine__findnew_dso(struct machine *machine, const char *filename); |
195 | ||
69d2591a ACM |
196 | size_t machine__fprintf(struct machine *machine, FILE *fp); |
197 | ||
198 | static inline | |
3183f8ca | 199 | struct symbol *machine__find_kernel_symbol(struct machine *machine, u64 addr, |
be39db9f | 200 | struct map **mapp) |
69d2591a | 201 | { |
3183f8ca | 202 | return map_groups__find_symbol(&machine->kmaps, addr, mapp); |
69d2591a ACM |
203 | } |
204 | ||
8acd3da0 ACM |
205 | static inline |
206 | struct symbol *machine__find_kernel_symbol_by_name(struct machine *machine, | |
3183f8ca | 207 | const char *name, |
be39db9f | 208 | struct map **mapp) |
8acd3da0 | 209 | { |
3183f8ca | 210 | return map_groups__find_symbol_by_name(&machine->kmaps, name, mapp); |
8acd3da0 ACM |
211 | } |
212 | ||
69d2591a ACM |
213 | static inline |
214 | struct symbol *machine__find_kernel_function(struct machine *machine, u64 addr, | |
be39db9f | 215 | struct map **mapp) |
69d2591a | 216 | { |
3183f8ca | 217 | return machine__find_kernel_symbol(machine, addr, mapp); |
69d2591a ACM |
218 | } |
219 | ||
220 | static inline | |
221 | struct symbol *machine__find_kernel_function_by_name(struct machine *machine, | |
222 | const char *name, | |
be39db9f | 223 | struct map **mapp) |
69d2591a | 224 | { |
be39db9f | 225 | return map_groups__find_function_by_name(&machine->kmaps, name, mapp); |
69d2591a ACM |
226 | } |
227 | ||
9f2de315 ACM |
228 | struct map *machine__findnew_module_map(struct machine *machine, u64 start, |
229 | const char *filename); | |
203d8a4a | 230 | int arch__fix_module_text_start(u64 *start, const char *name); |
69d2591a | 231 | |
3183f8ca | 232 | int machine__load_kallsyms(struct machine *machine, const char *filename); |
329f0ade | 233 | |
1d1a2654 | 234 | int machine__load_vmlinux_path(struct machine *machine); |
69d2591a | 235 | |
417c2ff6 ACM |
236 | size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp, |
237 | bool (skip)(struct dso *dso, int parm), int parm); | |
876650e6 ACM |
238 | size_t machines__fprintf_dsos(struct machines *machines, FILE *fp); |
239 | size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp, | |
417c2ff6 | 240 | bool (skip)(struct dso *dso, int parm), int parm); |
69d2591a ACM |
241 | |
242 | void machine__destroy_kernel_maps(struct machine *machine); | |
69d2591a ACM |
243 | int machine__create_kernel_maps(struct machine *machine); |
244 | ||
876650e6 ACM |
245 | int machines__create_kernel_maps(struct machines *machines, pid_t pid); |
246 | int machines__create_guest_kernel_maps(struct machines *machines); | |
247 | void machines__destroy_kernel_maps(struct machines *machines); | |
69d2591a ACM |
248 | |
249 | size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp); | |
250 | ||
35feee19 DA |
251 | int machine__for_each_thread(struct machine *machine, |
252 | int (*fn)(struct thread *thread, void *p), | |
253 | void *priv); | |
a5499b37 AH |
254 | int machines__for_each_thread(struct machines *machines, |
255 | int (*fn)(struct thread *thread, void *p), | |
256 | void *priv); | |
35feee19 | 257 | |
a33fbd56 | 258 | int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool, |
602ad878 | 259 | struct target *target, struct thread_map *threads, |
9d9cad76 | 260 | perf_event__handler_t process, bool data_mmap, |
340b47f5 KL |
261 | unsigned int proc_map_timeout, |
262 | unsigned int nr_threads_synthesize); | |
a33fbd56 | 263 | static inline |
602ad878 | 264 | int machine__synthesize_threads(struct machine *machine, struct target *target, |
9d9cad76 | 265 | struct thread_map *threads, bool data_mmap, |
340b47f5 KL |
266 | unsigned int proc_map_timeout, |
267 | unsigned int nr_threads_synthesize) | |
a33fbd56 ACM |
268 | { |
269 | return __machine__synthesize_threads(machine, NULL, target, threads, | |
9d9cad76 | 270 | perf_event__process, data_mmap, |
340b47f5 KL |
271 | proc_map_timeout, |
272 | nr_threads_synthesize); | |
a33fbd56 ACM |
273 | } |
274 | ||
b9d266ba AH |
275 | pid_t machine__get_current_tid(struct machine *machine, int cpu); |
276 | int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid, | |
277 | pid_t tid); | |
c3168b0d ACM |
278 | /* |
279 | * For use with libtraceevent's pevent_set_function_resolver() | |
280 | */ | |
281 | char *machine__resolve_kernel_addr(void *vmachine, unsigned long long *addrp, char **modp); | |
b9d266ba | 282 | |
9d2f8e22 | 283 | #endif /* __PERF_MACHINE_H */ |