1 #ifndef __PERF_MACHINE_H
2 #define __PERF_MACHINE_H
5 #include <linux/rbtree.h>
18 /* Native host kernel uses -1 as pid index in machine */
19 #define HOST_KERNEL_ID (-1)
20 #define DEFAULT_GUEST_KERNEL_ID (0)
22 extern const char *ref_reloc_sym_names
[];
27 struct rb_node rb_node
;
32 struct rb_root threads
;
33 struct list_head dead_threads
;
34 struct thread
*last_match
;
35 struct vdso_info
*vdso_info
;
36 struct dsos user_dsos
;
37 struct dsos kernel_dsos
;
38 struct map_groups kmaps
;
39 struct map
*vmlinux_maps
[MAP__NR_TYPES
];
41 symbol_filter_t symbol_filter
;
46 struct map
*machine__kernel_map(struct machine
*machine
, enum map_type type
)
48 return machine
->vmlinux_maps
[type
];
51 int machine__get_kernel_start(struct machine
*machine
);
53 static inline u64
machine__kernel_start(struct machine
*machine
)
55 if (!machine
->kernel_start
)
56 machine__get_kernel_start(machine
);
57 return machine
->kernel_start
;
60 static inline bool machine__kernel_ip(struct machine
*machine
, u64 ip
)
62 u64 kernel_start
= machine__kernel_start(machine
);
64 return ip
>= kernel_start
;
67 struct thread
*machine__find_thread(struct machine
*machine
, pid_t pid
,
69 struct comm
*machine__thread_exec_comm(struct machine
*machine
,
70 struct thread
*thread
);
72 int machine__process_comm_event(struct machine
*machine
, union perf_event
*event
,
73 struct perf_sample
*sample
);
74 int machine__process_exit_event(struct machine
*machine
, union perf_event
*event
,
75 struct perf_sample
*sample
);
76 int machine__process_fork_event(struct machine
*machine
, union perf_event
*event
,
77 struct perf_sample
*sample
);
78 int machine__process_lost_event(struct machine
*machine
, union perf_event
*event
,
79 struct perf_sample
*sample
);
80 int machine__process_mmap_event(struct machine
*machine
, union perf_event
*event
,
81 struct perf_sample
*sample
);
82 int machine__process_mmap2_event(struct machine
*machine
, union perf_event
*event
,
83 struct perf_sample
*sample
);
84 int machine__process_event(struct machine
*machine
, union perf_event
*event
,
85 struct perf_sample
*sample
);
87 typedef void (*machine__process_t
)(struct machine
*machine
, void *data
);
91 struct rb_root guests
;
92 symbol_filter_t symbol_filter
;
95 void machines__init(struct machines
*machines
);
96 void machines__exit(struct machines
*machines
);
98 void machines__process_guests(struct machines
*machines
,
99 machine__process_t process
, void *data
);
101 struct machine
*machines__add(struct machines
*machines
, pid_t pid
,
102 const char *root_dir
);
103 struct machine
*machines__find_host(struct machines
*machines
);
104 struct machine
*machines__find(struct machines
*machines
, pid_t pid
);
105 struct machine
*machines__findnew(struct machines
*machines
, pid_t pid
);
107 void machines__set_id_hdr_size(struct machines
*machines
, u16 id_hdr_size
);
108 char *machine__mmap_name(struct machine
*machine
, char *bf
, size_t size
);
110 void machines__set_symbol_filter(struct machines
*machines
,
111 symbol_filter_t symbol_filter
);
112 void machines__set_comm_exec(struct machines
*machines
, bool comm_exec
);
114 struct machine
*machine__new_host(void);
115 int machine__init(struct machine
*machine
, const char *root_dir
, pid_t pid
);
116 void machine__exit(struct machine
*machine
);
117 void machine__delete_dead_threads(struct machine
*machine
);
118 void machine__delete_threads(struct machine
*machine
);
119 void machine__delete(struct machine
*machine
);
121 struct branch_info
*sample__resolve_bstack(struct perf_sample
*sample
,
122 struct addr_location
*al
);
123 struct mem_info
*sample__resolve_mem(struct perf_sample
*sample
,
124 struct addr_location
*al
);
125 int machine__resolve_callchain(struct machine
*machine
,
126 struct perf_evsel
*evsel
,
127 struct thread
*thread
,
128 struct perf_sample
*sample
,
129 struct symbol
**parent
,
130 struct addr_location
*root_al
,
134 * Default guest kernel is defined by parameter --guestkallsyms
137 static inline bool machine__is_default_guest(struct machine
*machine
)
139 return machine
? machine
->pid
== DEFAULT_GUEST_KERNEL_ID
: false;
142 static inline bool machine__is_host(struct machine
*machine
)
144 return machine
? machine
->pid
== HOST_KERNEL_ID
: false;
147 struct thread
*machine__findnew_thread(struct machine
*machine
, pid_t pid
,
150 size_t machine__fprintf(struct machine
*machine
, FILE *fp
);
153 struct symbol
*machine__find_kernel_symbol(struct machine
*machine
,
154 enum map_type type
, u64 addr
,
156 symbol_filter_t filter
)
158 return map_groups__find_symbol(&machine
->kmaps
, type
, addr
,
163 struct symbol
*machine__find_kernel_function(struct machine
*machine
, u64 addr
,
165 symbol_filter_t filter
)
167 return machine__find_kernel_symbol(machine
, MAP__FUNCTION
, addr
,
172 struct symbol
*machine__find_kernel_function_by_name(struct machine
*machine
,
175 symbol_filter_t filter
)
177 return map_groups__find_function_by_name(&machine
->kmaps
, name
, mapp
,
181 struct map
*machine__new_module(struct machine
*machine
, u64 start
,
182 const char *filename
);
184 int machine__load_kallsyms(struct machine
*machine
, const char *filename
,
185 enum map_type type
, symbol_filter_t filter
);
186 int machine__load_vmlinux_path(struct machine
*machine
, enum map_type type
,
187 symbol_filter_t filter
);
189 size_t machine__fprintf_dsos_buildid(struct machine
*machine
, FILE *fp
,
190 bool (skip
)(struct dso
*dso
, int parm
), int parm
);
191 size_t machines__fprintf_dsos(struct machines
*machines
, FILE *fp
);
192 size_t machines__fprintf_dsos_buildid(struct machines
*machines
, FILE *fp
,
193 bool (skip
)(struct dso
*dso
, int parm
), int parm
);
195 void machine__destroy_kernel_maps(struct machine
*machine
);
196 int __machine__create_kernel_maps(struct machine
*machine
, struct dso
*kernel
);
197 int machine__create_kernel_maps(struct machine
*machine
);
199 int machines__create_kernel_maps(struct machines
*machines
, pid_t pid
);
200 int machines__create_guest_kernel_maps(struct machines
*machines
);
201 void machines__destroy_kernel_maps(struct machines
*machines
);
203 size_t machine__fprintf_vmlinux_path(struct machine
*machine
, FILE *fp
);
205 int machine__for_each_thread(struct machine
*machine
,
206 int (*fn
)(struct thread
*thread
, void *p
),
209 int __machine__synthesize_threads(struct machine
*machine
, struct perf_tool
*tool
,
210 struct target
*target
, struct thread_map
*threads
,
211 perf_event__handler_t process
, bool data_mmap
);
213 int machine__synthesize_threads(struct machine
*machine
, struct target
*target
,
214 struct thread_map
*threads
, bool data_mmap
)
216 return __machine__synthesize_threads(machine
, NULL
, target
, threads
,
217 perf_event__process
, data_mmap
);
220 pid_t
machine__get_current_tid(struct machine
*machine
, int cpu
);
221 int machine__set_current_tid(struct machine
*machine
, int cpu
, pid_t pid
,
224 #endif /* __PERF_MACHINE_H */