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