0001
0002 #ifndef __PERF_MACHINE_H
0003 #define __PERF_MACHINE_H
0004
0005 #include <sys/types.h>
0006 #include <linux/rbtree.h>
0007 #include "maps.h"
0008 #include "dsos.h"
0009 #include "rwsem.h"
0010
0011 struct addr_location;
0012 struct branch_stack;
0013 struct dso;
0014 struct dso_id;
0015 struct evsel;
0016 struct perf_sample;
0017 struct symbol;
0018 struct target;
0019 struct thread;
0020 union perf_event;
0021 struct machines;
0022
0023
0024 #define HOST_KERNEL_ID (-1)
0025 #define DEFAULT_GUEST_KERNEL_ID (0)
0026
0027 extern const char *ref_reloc_sym_names[];
0028
0029 struct vdso_info;
0030
0031 #define THREADS__TABLE_BITS 8
0032 #define THREADS__TABLE_SIZE (1 << THREADS__TABLE_BITS)
0033
0034 struct threads {
0035 struct rb_root_cached entries;
0036 struct rw_semaphore lock;
0037 unsigned int nr;
0038 struct list_head dead;
0039 struct thread *last_match;
0040 };
0041
0042 struct machine {
0043 struct rb_node rb_node;
0044 pid_t pid;
0045 u16 id_hdr_size;
0046 bool comm_exec;
0047 bool kptr_restrict_warned;
0048 bool single_address_space;
0049 char *root_dir;
0050 char *mmap_name;
0051 char *kallsyms_filename;
0052 struct threads threads[THREADS__TABLE_SIZE];
0053 struct vdso_info *vdso_info;
0054 struct perf_env *env;
0055 struct dsos dsos;
0056 struct maps *kmaps;
0057 struct map *vmlinux_map;
0058 u64 kernel_start;
0059 pid_t *current_tid;
0060 size_t current_tid_sz;
0061 union {
0062 void *priv;
0063 u64 db_id;
0064 };
0065 struct machines *machines;
0066 bool trampolines_mapped;
0067 };
0068
0069 static inline struct threads *machine__threads(struct machine *machine, pid_t tid)
0070 {
0071
0072 return &machine->threads[(unsigned int)tid % THREADS__TABLE_SIZE];
0073 }
0074
0075
0076
0077
0078 static inline
0079 struct map *machine__kernel_map(struct machine *machine)
0080 {
0081 return machine->vmlinux_map;
0082 }
0083
0084
0085
0086
0087 static inline
0088 struct maps *machine__kernel_maps(struct machine *machine)
0089 {
0090 return machine->kmaps;
0091 }
0092
0093 int machine__get_kernel_start(struct machine *machine);
0094
0095 static inline u64 machine__kernel_start(struct machine *machine)
0096 {
0097 if (!machine->kernel_start)
0098 machine__get_kernel_start(machine);
0099 return machine->kernel_start;
0100 }
0101
0102 static inline bool machine__kernel_ip(struct machine *machine, u64 ip)
0103 {
0104 u64 kernel_start = machine__kernel_start(machine);
0105
0106 return ip >= kernel_start;
0107 }
0108
0109 u8 machine__addr_cpumode(struct machine *machine, u8 cpumode, u64 addr);
0110
0111 struct thread *machine__find_thread(struct machine *machine, pid_t pid,
0112 pid_t tid);
0113 struct thread *machine__idle_thread(struct machine *machine);
0114 struct comm *machine__thread_exec_comm(struct machine *machine,
0115 struct thread *thread);
0116
0117 int machine__process_comm_event(struct machine *machine, union perf_event *event,
0118 struct perf_sample *sample);
0119 int machine__process_exit_event(struct machine *machine, union perf_event *event,
0120 struct perf_sample *sample);
0121 int machine__process_fork_event(struct machine *machine, union perf_event *event,
0122 struct perf_sample *sample);
0123 int machine__process_lost_event(struct machine *machine, union perf_event *event,
0124 struct perf_sample *sample);
0125 int machine__process_lost_samples_event(struct machine *machine, union perf_event *event,
0126 struct perf_sample *sample);
0127 int machine__process_aux_event(struct machine *machine,
0128 union perf_event *event);
0129 int machine__process_itrace_start_event(struct machine *machine,
0130 union perf_event *event);
0131 int machine__process_aux_output_hw_id_event(struct machine *machine,
0132 union perf_event *event);
0133 int machine__process_switch_event(struct machine *machine,
0134 union perf_event *event);
0135 int machine__process_namespaces_event(struct machine *machine,
0136 union perf_event *event,
0137 struct perf_sample *sample);
0138 int machine__process_cgroup_event(struct machine *machine,
0139 union perf_event *event,
0140 struct perf_sample *sample);
0141 int machine__process_mmap_event(struct machine *machine, union perf_event *event,
0142 struct perf_sample *sample);
0143 int machine__process_mmap2_event(struct machine *machine, union perf_event *event,
0144 struct perf_sample *sample);
0145 int machine__process_ksymbol(struct machine *machine,
0146 union perf_event *event,
0147 struct perf_sample *sample);
0148 int machine__process_text_poke(struct machine *machine,
0149 union perf_event *event,
0150 struct perf_sample *sample);
0151 int machine__process_event(struct machine *machine, union perf_event *event,
0152 struct perf_sample *sample);
0153
0154 typedef void (*machine__process_t)(struct machine *machine, void *data);
0155
0156 struct machines {
0157 struct machine host;
0158 struct rb_root_cached guests;
0159 };
0160
0161 void machines__init(struct machines *machines);
0162 void machines__exit(struct machines *machines);
0163
0164 void machines__process_guests(struct machines *machines,
0165 machine__process_t process, void *data);
0166
0167 struct machine *machines__add(struct machines *machines, pid_t pid,
0168 const char *root_dir);
0169 struct machine *machines__find(struct machines *machines, pid_t pid);
0170 struct machine *machines__findnew(struct machines *machines, pid_t pid);
0171 struct machine *machines__find_guest(struct machines *machines, pid_t pid);
0172 struct thread *machines__findnew_guest_code(struct machines *machines, pid_t pid);
0173 struct thread *machine__findnew_guest_code(struct machine *machine, pid_t pid);
0174
0175 void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size);
0176 void machines__set_comm_exec(struct machines *machines, bool comm_exec);
0177
0178 struct machine *machine__new_host(void);
0179 struct machine *machine__new_kallsyms(void);
0180 int machine__init(struct machine *machine, const char *root_dir, pid_t pid);
0181 void machine__exit(struct machine *machine);
0182 void machine__delete_threads(struct machine *machine);
0183 void machine__delete(struct machine *machine);
0184 void machine__remove_thread(struct machine *machine, struct thread *th);
0185
0186 struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
0187 struct addr_location *al);
0188 struct mem_info *sample__resolve_mem(struct perf_sample *sample,
0189 struct addr_location *al);
0190
0191 struct callchain_cursor;
0192
0193 int thread__resolve_callchain(struct thread *thread,
0194 struct callchain_cursor *cursor,
0195 struct evsel *evsel,
0196 struct perf_sample *sample,
0197 struct symbol **parent,
0198 struct addr_location *root_al,
0199 int max_stack);
0200
0201
0202
0203
0204
0205 static inline bool machine__is_default_guest(struct machine *machine)
0206 {
0207 return machine ? machine->pid == DEFAULT_GUEST_KERNEL_ID : false;
0208 }
0209
0210 static inline bool machine__is_host(struct machine *machine)
0211 {
0212 return machine ? machine->pid == HOST_KERNEL_ID : false;
0213 }
0214
0215 bool machine__is(struct machine *machine, const char *arch);
0216 bool machine__normalized_is(struct machine *machine, const char *arch);
0217 int machine__nr_cpus_avail(struct machine *machine);
0218
0219 struct thread *__machine__findnew_thread(struct machine *machine, pid_t pid, pid_t tid);
0220 struct thread *machine__findnew_thread(struct machine *machine, pid_t pid, pid_t tid);
0221
0222 struct dso *machine__findnew_dso_id(struct machine *machine, const char *filename, struct dso_id *id);
0223 struct dso *machine__findnew_dso(struct machine *machine, const char *filename);
0224
0225 size_t machine__fprintf(struct machine *machine, FILE *fp);
0226
0227 static inline
0228 struct symbol *machine__find_kernel_symbol(struct machine *machine, u64 addr,
0229 struct map **mapp)
0230 {
0231 return maps__find_symbol(machine->kmaps, addr, mapp);
0232 }
0233
0234 static inline
0235 struct symbol *machine__find_kernel_symbol_by_name(struct machine *machine,
0236 const char *name,
0237 struct map **mapp)
0238 {
0239 return maps__find_symbol_by_name(machine->kmaps, name, mapp);
0240 }
0241
0242 int arch__fix_module_text_start(u64 *start, u64 *size, const char *name);
0243
0244 int machine__load_kallsyms(struct machine *machine, const char *filename);
0245
0246 int machine__load_vmlinux_path(struct machine *machine);
0247
0248 size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
0249 bool (skip)(struct dso *dso, int parm), int parm);
0250 size_t machines__fprintf_dsos(struct machines *machines, FILE *fp);
0251 size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
0252 bool (skip)(struct dso *dso, int parm), int parm);
0253
0254 void machine__destroy_kernel_maps(struct machine *machine);
0255 int machine__create_kernel_maps(struct machine *machine);
0256
0257 int machines__create_kernel_maps(struct machines *machines, pid_t pid);
0258 int machines__create_guest_kernel_maps(struct machines *machines);
0259 void machines__destroy_kernel_maps(struct machines *machines);
0260
0261 size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
0262
0263 typedef int (*machine__dso_t)(struct dso *dso, struct machine *machine, void *priv);
0264
0265 int machine__for_each_dso(struct machine *machine, machine__dso_t fn,
0266 void *priv);
0267
0268 typedef int (*machine__map_t)(struct map *map, void *priv);
0269 int machine__for_each_kernel_map(struct machine *machine, machine__map_t fn,
0270 void *priv);
0271
0272 int machine__for_each_thread(struct machine *machine,
0273 int (*fn)(struct thread *thread, void *p),
0274 void *priv);
0275 int machines__for_each_thread(struct machines *machines,
0276 int (*fn)(struct thread *thread, void *p),
0277 void *priv);
0278
0279 pid_t machine__get_current_tid(struct machine *machine, int cpu);
0280 int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid,
0281 pid_t tid);
0282
0283
0284
0285 char *machine__resolve_kernel_addr(void *vmachine, unsigned long long *addrp, char **modp);
0286
0287 void machine__get_kallsyms_filename(struct machine *machine, char *buf,
0288 size_t bufsz);
0289
0290 int machine__create_extra_kernel_maps(struct machine *machine,
0291 struct dso *kernel);
0292
0293
0294 struct extra_kernel_map {
0295 u64 start;
0296 u64 end;
0297 u64 pgoff;
0298 char name[KMAP_NAME_LEN];
0299 };
0300
0301 int machine__create_extra_kernel_map(struct machine *machine,
0302 struct dso *kernel,
0303 struct extra_kernel_map *xm);
0304
0305 int machine__map_x86_64_entry_trampolines(struct machine *machine,
0306 struct dso *kernel);
0307
0308 #endif