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