Merge remote-tracking branch 'xen-tip/linux-next'
[deliverable/linux.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);
162f0bef
FW
100int machine__process_mmap_event(struct machine *machine, union perf_event *event,
101 struct perf_sample *sample);
102int machine__process_mmap2_event(struct machine *machine, union perf_event *event,
103 struct perf_sample *sample);
104int machine__process_event(struct machine *machine, union perf_event *event,
105 struct perf_sample *sample);
b0a7d1a0 106
69d2591a
ACM
107typedef void (*machine__process_t)(struct machine *machine, void *data);
108
876650e6
ACM
109struct machines {
110 struct machine host;
111 struct rb_root guests;
112};
113
114void machines__init(struct machines *machines);
115void machines__exit(struct machines *machines);
116
117void machines__process_guests(struct machines *machines,
118 machine__process_t process, void *data);
69d2591a 119
876650e6 120struct machine *machines__add(struct machines *machines, pid_t pid,
69d2591a 121 const char *root_dir);
876650e6
ACM
122struct machine *machines__find_host(struct machines *machines);
123struct machine *machines__find(struct machines *machines, pid_t pid);
124struct machine *machines__findnew(struct machines *machines, pid_t pid);
69d2591a 125
876650e6 126void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size);
69d2591a
ACM
127char *machine__mmap_name(struct machine *machine, char *bf, size_t size);
128
cfe1c414 129void machines__set_comm_exec(struct machines *machines, bool comm_exec);
611a5ce8 130
8fb598e5 131struct machine *machine__new_host(void);
69d2591a
ACM
132int machine__init(struct machine *machine, const char *root_dir, pid_t pid);
133void machine__exit(struct machine *machine);
3f067dca 134void machine__delete_threads(struct machine *machine);
69d2591a 135void machine__delete(struct machine *machine);
5e78c69b 136void machine__remove_thread(struct machine *machine, struct thread *th);
69d2591a 137
644f2df2
ACM
138struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
139 struct addr_location *al);
e80faac0
ACM
140struct mem_info *sample__resolve_mem(struct perf_sample *sample,
141 struct addr_location *al);
91d7b2de
ACM
142
143struct callchain_cursor;
144
cc8b7c2b 145int thread__resolve_callchain(struct thread *thread,
91d7b2de 146 struct callchain_cursor *cursor,
cc8b7c2b
ACM
147 struct perf_evsel *evsel,
148 struct perf_sample *sample,
149 struct symbol **parent,
150 struct addr_location *root_al,
151 int max_stack);
69d2591a
ACM
152
153/*
154 * Default guest kernel is defined by parameter --guestkallsyms
155 * and --guestmodules
156 */
157static inline bool machine__is_default_guest(struct machine *machine)
158{
159 return machine ? machine->pid == DEFAULT_GUEST_KERNEL_ID : false;
160}
161
162static inline bool machine__is_host(struct machine *machine)
163{
164 return machine ? machine->pid == HOST_KERNEL_ID : false;
165}
166
b91fc39f
ACM
167struct thread *__machine__findnew_thread(struct machine *machine, pid_t pid, pid_t tid);
168struct thread *machine__findnew_thread(struct machine *machine, pid_t pid, pid_t tid);
69d2591a 169
aa7cc2ae
ACM
170struct dso *machine__findnew_dso(struct machine *machine, const char *filename);
171
69d2591a
ACM
172size_t machine__fprintf(struct machine *machine, FILE *fp);
173
174static inline
175struct symbol *machine__find_kernel_symbol(struct machine *machine,
176 enum map_type type, u64 addr,
be39db9f 177 struct map **mapp)
69d2591a 178{
be39db9f 179 return map_groups__find_symbol(&machine->kmaps, type, addr, mapp);
69d2591a
ACM
180}
181
8acd3da0
ACM
182static inline
183struct symbol *machine__find_kernel_symbol_by_name(struct machine *machine,
184 enum map_type type, const char *name,
be39db9f 185 struct map **mapp)
8acd3da0 186{
be39db9f 187 return map_groups__find_symbol_by_name(&machine->kmaps, type, name, mapp);
8acd3da0
ACM
188}
189
69d2591a
ACM
190static inline
191struct symbol *machine__find_kernel_function(struct machine *machine, u64 addr,
be39db9f 192 struct map **mapp)
69d2591a
ACM
193{
194 return machine__find_kernel_symbol(machine, MAP__FUNCTION, addr,
be39db9f 195 mapp);
69d2591a
ACM
196}
197
198static inline
199struct symbol *machine__find_kernel_function_by_name(struct machine *machine,
200 const char *name,
be39db9f 201 struct map **mapp)
69d2591a 202{
be39db9f 203 return map_groups__find_function_by_name(&machine->kmaps, name, mapp);
69d2591a
ACM
204}
205
9f2de315
ACM
206struct map *machine__findnew_module_map(struct machine *machine, u64 start,
207 const char *filename);
203d8a4a 208int arch__fix_module_text_start(u64 *start, const char *name);
69d2591a 209
e02092b9 210int __machine__load_kallsyms(struct machine *machine, const char *filename,
be39db9f 211 enum map_type type, bool no_kcore);
69d2591a 212int machine__load_kallsyms(struct machine *machine, const char *filename,
be39db9f
ACM
213 enum map_type type);
214int machine__load_vmlinux_path(struct machine *machine, enum map_type type);
69d2591a 215
417c2ff6
ACM
216size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
217 bool (skip)(struct dso *dso, int parm), int parm);
876650e6
ACM
218size_t machines__fprintf_dsos(struct machines *machines, FILE *fp);
219size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
417c2ff6 220 bool (skip)(struct dso *dso, int parm), int parm);
69d2591a
ACM
221
222void machine__destroy_kernel_maps(struct machine *machine);
223int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel);
224int machine__create_kernel_maps(struct machine *machine);
225
876650e6
ACM
226int machines__create_kernel_maps(struct machines *machines, pid_t pid);
227int machines__create_guest_kernel_maps(struct machines *machines);
228void machines__destroy_kernel_maps(struct machines *machines);
69d2591a
ACM
229
230size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
231
35feee19
DA
232int machine__for_each_thread(struct machine *machine,
233 int (*fn)(struct thread *thread, void *p),
234 void *priv);
a5499b37
AH
235int machines__for_each_thread(struct machines *machines,
236 int (*fn)(struct thread *thread, void *p),
237 void *priv);
35feee19 238
a33fbd56 239int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool,
602ad878 240 struct target *target, struct thread_map *threads,
9d9cad76
KL
241 perf_event__handler_t process, bool data_mmap,
242 unsigned int proc_map_timeout);
a33fbd56 243static inline
602ad878 244int machine__synthesize_threads(struct machine *machine, struct target *target,
9d9cad76
KL
245 struct thread_map *threads, bool data_mmap,
246 unsigned int proc_map_timeout)
a33fbd56
ACM
247{
248 return __machine__synthesize_threads(machine, NULL, target, threads,
9d9cad76
KL
249 perf_event__process, data_mmap,
250 proc_map_timeout);
a33fbd56
ACM
251}
252
b9d266ba
AH
253pid_t machine__get_current_tid(struct machine *machine, int cpu);
254int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid,
255 pid_t tid);
c3168b0d
ACM
256/*
257 * For use with libtraceevent's pevent_set_function_resolver()
258 */
259char *machine__resolve_kernel_addr(void *vmachine, unsigned long long *addrp, char **modp);
b9d266ba 260
9d2f8e22 261#endif /* __PERF_MACHINE_H */
This page took 0.134049 seconds and 5 git commands to generate.