1 #ifndef __PERF_MACHINE_H
2 #define __PERF_MACHINE_H
3
4 #include <sys/types.h>
5 #include <linux/rbtree.h>
6 #include "map.h"
7
8 struct branch_stack;
9 struct perf_evsel;
10 struct perf_sample;
11 struct symbol;
12 struct thread;
13 union perf_event;
14
15 /* Native host kernel uses -1 as pid index in machine */
16 #define HOST_KERNEL_ID (-1)
17 #define DEFAULT_GUEST_KERNEL_ID (0)
18
19 struct machine {
20 struct rb_node rb_node;
21 pid_t pid;
22 u16 id_hdr_size;
23 char *root_dir;
24 struct rb_root threads;
25 struct list_head dead_threads;
26 struct thread *last_match;
27 struct list_head user_dsos;
28 struct list_head kernel_dsos;
29 struct map_groups kmaps;
30 struct map *vmlinux_maps[MAP__NR_TYPES];
31 };
32
33 static inline
machine__kernel_map(struct machine * machine,enum map_type type)34 struct map *machine__kernel_map(struct machine *machine, enum map_type type)
35 {
36 return machine->vmlinux_maps[type];
37 }
38
39 struct thread *machine__find_thread(struct machine *machine, pid_t pid);
40
41 int machine__process_comm_event(struct machine *machine, union perf_event *event);
42 int machine__process_exit_event(struct machine *machine, union perf_event *event);
43 int machine__process_fork_event(struct machine *machine, union perf_event *event);
44 int machine__process_lost_event(struct machine *machine, union perf_event *event);
45 int machine__process_mmap_event(struct machine *machine, union perf_event *event);
46 int machine__process_event(struct machine *machine, union perf_event *event);
47
48 typedef void (*machine__process_t)(struct machine *machine, void *data);
49
50 struct machines {
51 struct machine host;
52 struct rb_root guests;
53 };
54
55 void machines__init(struct machines *machines);
56 void machines__exit(struct machines *machines);
57
58 void machines__process_guests(struct machines *machines,
59 machine__process_t process, void *data);
60
61 struct machine *machines__add(struct machines *machines, pid_t pid,
62 const char *root_dir);
63 struct machine *machines__find_host(struct machines *machines);
64 struct machine *machines__find(struct machines *machines, pid_t pid);
65 struct machine *machines__findnew(struct machines *machines, pid_t pid);
66
67 void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size);
68 char *machine__mmap_name(struct machine *machine, char *bf, size_t size);
69
70 int machine__init(struct machine *machine, const char *root_dir, pid_t pid);
71 void machine__exit(struct machine *machine);
72 void machine__delete_dead_threads(struct machine *machine);
73 void machine__delete_threads(struct machine *machine);
74 void machine__delete(struct machine *machine);
75
76 struct branch_info *machine__resolve_bstack(struct machine *machine,
77 struct thread *thread,
78 struct branch_stack *bs);
79 struct mem_info *machine__resolve_mem(struct machine *machine,
80 struct thread *thread,
81 struct perf_sample *sample, u8 cpumode);
82 int machine__resolve_callchain(struct machine *machine,
83 struct perf_evsel *evsel,
84 struct thread *thread,
85 struct perf_sample *sample,
86 struct symbol **parent);
87
88 /*
89 * Default guest kernel is defined by parameter --guestkallsyms
90 * and --guestmodules
91 */
machine__is_default_guest(struct machine * machine)92 static inline bool machine__is_default_guest(struct machine *machine)
93 {
94 return machine ? machine->pid == DEFAULT_GUEST_KERNEL_ID : false;
95 }
96
machine__is_host(struct machine * machine)97 static inline bool machine__is_host(struct machine *machine)
98 {
99 return machine ? machine->pid == HOST_KERNEL_ID : false;
100 }
101
102 struct thread *machine__findnew_thread(struct machine *machine, pid_t pid);
103
104 size_t machine__fprintf(struct machine *machine, FILE *fp);
105
106 static inline
machine__find_kernel_symbol(struct machine * machine,enum map_type type,u64 addr,struct map ** mapp,symbol_filter_t filter)107 struct symbol *machine__find_kernel_symbol(struct machine *machine,
108 enum map_type type, u64 addr,
109 struct map **mapp,
110 symbol_filter_t filter)
111 {
112 return map_groups__find_symbol(&machine->kmaps, type, addr,
113 mapp, filter);
114 }
115
116 static inline
machine__find_kernel_function(struct machine * machine,u64 addr,struct map ** mapp,symbol_filter_t filter)117 struct symbol *machine__find_kernel_function(struct machine *machine, u64 addr,
118 struct map **mapp,
119 symbol_filter_t filter)
120 {
121 return machine__find_kernel_symbol(machine, MAP__FUNCTION, addr,
122 mapp, filter);
123 }
124
125 static inline
machine__find_kernel_function_by_name(struct machine * machine,const char * name,struct map ** mapp,symbol_filter_t filter)126 struct symbol *machine__find_kernel_function_by_name(struct machine *machine,
127 const char *name,
128 struct map **mapp,
129 symbol_filter_t filter)
130 {
131 return map_groups__find_function_by_name(&machine->kmaps, name, mapp,
132 filter);
133 }
134
135 struct map *machine__new_module(struct machine *machine, u64 start,
136 const char *filename);
137
138 int machine__load_kallsyms(struct machine *machine, const char *filename,
139 enum map_type type, symbol_filter_t filter);
140 int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
141 symbol_filter_t filter);
142
143 size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
144 bool (skip)(struct dso *dso, int parm), int parm);
145 size_t machines__fprintf_dsos(struct machines *machines, FILE *fp);
146 size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
147 bool (skip)(struct dso *dso, int parm), int parm);
148
149 void machine__destroy_kernel_maps(struct machine *machine);
150 int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel);
151 int machine__create_kernel_maps(struct machine *machine);
152
153 int machines__create_kernel_maps(struct machines *machines, pid_t pid);
154 int machines__create_guest_kernel_maps(struct machines *machines);
155 void machines__destroy_kernel_maps(struct machines *machines);
156
157 size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
158
159 #endif /* __PERF_MACHINE_H */
160