fix a kmap leak in virtio_console
[linux/fpc-iii.git] / tools / perf / util / machine.h
blob477133015440483f16ee6c2aca4758f7dfba85e6
1 #ifndef __PERF_MACHINE_H
2 #define __PERF_MACHINE_H
4 #include <sys/types.h>
5 #include <linux/rbtree.h>
6 #include "map.h"
7 #include "event.h"
9 struct addr_location;
10 struct branch_stack;
11 struct perf_evsel;
12 struct perf_sample;
13 struct symbol;
14 struct thread;
15 union perf_event;
17 /* Native host kernel uses -1 as pid index in machine */
18 #define HOST_KERNEL_ID (-1)
19 #define DEFAULT_GUEST_KERNEL_ID (0)
21 struct machine {
22 struct rb_node rb_node;
23 pid_t pid;
24 u16 id_hdr_size;
25 char *root_dir;
26 struct rb_root threads;
27 struct list_head dead_threads;
28 struct thread *last_match;
29 struct list_head user_dsos;
30 struct list_head kernel_dsos;
31 struct map_groups kmaps;
32 struct map *vmlinux_maps[MAP__NR_TYPES];
33 symbol_filter_t symbol_filter;
36 static inline
37 struct map *machine__kernel_map(struct machine *machine, enum map_type type)
39 return machine->vmlinux_maps[type];
42 struct thread *machine__find_thread(struct machine *machine, pid_t tid);
44 int machine__process_comm_event(struct machine *machine, union perf_event *event,
45 struct perf_sample *sample);
46 int machine__process_exit_event(struct machine *machine, union perf_event *event,
47 struct perf_sample *sample);
48 int machine__process_fork_event(struct machine *machine, union perf_event *event,
49 struct perf_sample *sample);
50 int machine__process_lost_event(struct machine *machine, union perf_event *event,
51 struct perf_sample *sample);
52 int machine__process_mmap_event(struct machine *machine, union perf_event *event,
53 struct perf_sample *sample);
54 int machine__process_mmap2_event(struct machine *machine, union perf_event *event,
55 struct perf_sample *sample);
56 int machine__process_event(struct machine *machine, union perf_event *event,
57 struct perf_sample *sample);
59 typedef void (*machine__process_t)(struct machine *machine, void *data);
61 struct machines {
62 struct machine host;
63 struct rb_root guests;
64 symbol_filter_t symbol_filter;
67 void machines__init(struct machines *machines);
68 void machines__exit(struct machines *machines);
70 void machines__process_guests(struct machines *machines,
71 machine__process_t process, void *data);
73 struct machine *machines__add(struct machines *machines, pid_t pid,
74 const char *root_dir);
75 struct machine *machines__find_host(struct machines *machines);
76 struct machine *machines__find(struct machines *machines, pid_t pid);
77 struct machine *machines__findnew(struct machines *machines, pid_t pid);
79 void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size);
80 char *machine__mmap_name(struct machine *machine, char *bf, size_t size);
82 void machines__set_symbol_filter(struct machines *machines,
83 symbol_filter_t symbol_filter);
85 struct machine *machine__new_host(void);
86 int machine__init(struct machine *machine, const char *root_dir, pid_t pid);
87 void machine__exit(struct machine *machine);
88 void machine__delete_dead_threads(struct machine *machine);
89 void machine__delete_threads(struct machine *machine);
90 void machine__delete(struct machine *machine);
92 struct branch_info *machine__resolve_bstack(struct machine *machine,
93 struct thread *thread,
94 struct branch_stack *bs);
95 struct mem_info *machine__resolve_mem(struct machine *machine,
96 struct thread *thread,
97 struct perf_sample *sample, u8 cpumode);
98 int machine__resolve_callchain(struct machine *machine,
99 struct perf_evsel *evsel,
100 struct thread *thread,
101 struct perf_sample *sample,
102 struct symbol **parent,
103 struct addr_location *root_al,
104 int max_stack);
107 * Default guest kernel is defined by parameter --guestkallsyms
108 * and --guestmodules
110 static inline bool machine__is_default_guest(struct machine *machine)
112 return machine ? machine->pid == DEFAULT_GUEST_KERNEL_ID : false;
115 static inline bool machine__is_host(struct machine *machine)
117 return machine ? machine->pid == HOST_KERNEL_ID : false;
120 struct thread *machine__findnew_thread(struct machine *machine, pid_t pid,
121 pid_t tid);
123 size_t machine__fprintf(struct machine *machine, FILE *fp);
125 static inline
126 struct symbol *machine__find_kernel_symbol(struct machine *machine,
127 enum map_type type, u64 addr,
128 struct map **mapp,
129 symbol_filter_t filter)
131 return map_groups__find_symbol(&machine->kmaps, type, addr,
132 mapp, filter);
135 static inline
136 struct symbol *machine__find_kernel_function(struct machine *machine, u64 addr,
137 struct map **mapp,
138 symbol_filter_t filter)
140 return machine__find_kernel_symbol(machine, MAP__FUNCTION, addr,
141 mapp, filter);
144 static inline
145 struct symbol *machine__find_kernel_function_by_name(struct machine *machine,
146 const char *name,
147 struct map **mapp,
148 symbol_filter_t filter)
150 return map_groups__find_function_by_name(&machine->kmaps, name, mapp,
151 filter);
154 struct map *machine__new_module(struct machine *machine, u64 start,
155 const char *filename);
157 int machine__load_kallsyms(struct machine *machine, const char *filename,
158 enum map_type type, symbol_filter_t filter);
159 int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
160 symbol_filter_t filter);
162 size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
163 bool (skip)(struct dso *dso, int parm), int parm);
164 size_t machines__fprintf_dsos(struct machines *machines, FILE *fp);
165 size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
166 bool (skip)(struct dso *dso, int parm), int parm);
168 void machine__destroy_kernel_maps(struct machine *machine);
169 int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel);
170 int machine__create_kernel_maps(struct machine *machine);
172 int machines__create_kernel_maps(struct machines *machines, pid_t pid);
173 int machines__create_guest_kernel_maps(struct machines *machines);
174 void machines__destroy_kernel_maps(struct machines *machines);
176 size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
178 int machine__for_each_thread(struct machine *machine,
179 int (*fn)(struct thread *thread, void *p),
180 void *priv);
182 int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool,
183 struct target *target, struct thread_map *threads,
184 perf_event__handler_t process, bool data_mmap);
185 static inline
186 int machine__synthesize_threads(struct machine *machine, struct target *target,
187 struct thread_map *threads, bool data_mmap)
189 return __machine__synthesize_threads(machine, NULL, target, threads,
190 perf_event__process, data_mmap);
193 #endif /* __PERF_MACHINE_H */