Lines Matching full:machine
6 #include "machine.h"
14 int machine__init(struct machine *machine, const char *root_dir, pid_t pid) in machine__init() argument
16 map_groups__init(&machine->kmaps); in machine__init()
17 RB_CLEAR_NODE(&machine->rb_node); in machine__init()
18 INIT_LIST_HEAD(&machine->user_dsos); in machine__init()
19 INIT_LIST_HEAD(&machine->kernel_dsos); in machine__init()
21 machine->threads = RB_ROOT; in machine__init()
22 INIT_LIST_HEAD(&machine->dead_threads); in machine__init()
23 machine->last_match = NULL; in machine__init()
25 machine->kmaps.machine = machine; in machine__init()
26 machine->pid = pid; in machine__init()
28 machine->symbol_filter = NULL; in machine__init()
30 machine->root_dir = strdup(root_dir); in machine__init()
31 if (machine->root_dir == NULL) in machine__init()
35 struct thread *thread = machine__findnew_thread(machine, 0, in machine__init()
59 void machine__delete_dead_threads(struct machine *machine) in machine__delete_dead_threads() argument
63 list_for_each_entry_safe(t, n, &machine->dead_threads, node) { in machine__delete_dead_threads()
69 void machine__delete_threads(struct machine *machine) in machine__delete_threads() argument
71 struct rb_node *nd = rb_first(&machine->threads); in machine__delete_threads()
76 rb_erase(&t->rb_node, &machine->threads); in machine__delete_threads()
82 void machine__exit(struct machine *machine) in machine__exit() argument
84 map_groups__exit(&machine->kmaps); in machine__exit()
85 dsos__delete(&machine->user_dsos); in machine__exit()
86 dsos__delete(&machine->kernel_dsos); in machine__exit()
87 free(machine->root_dir); in machine__exit()
88 machine->root_dir = NULL; in machine__exit()
91 void machine__delete(struct machine *machine) in machine__delete() argument
93 machine__exit(machine); in machine__delete()
94 free(machine); in machine__delete()
110 struct machine *machines__add(struct machines *machines, pid_t pid, in machines__add()
115 struct machine *pos, *machine = malloc(sizeof(*machine)); in machines__add() local
117 if (machine == NULL) in machines__add()
120 if (machine__init(machine, root_dir, pid) != 0) { in machines__add()
121 free(machine); in machines__add()
125 machine->symbol_filter = machines->symbol_filter; in machines__add()
129 pos = rb_entry(parent, struct machine, rb_node); in machines__add()
136 rb_link_node(&machine->rb_node, parent, p); in machines__add()
137 rb_insert_color(&machine->rb_node, &machines->guests); in machines__add()
139 return machine; in machines__add()
151 struct machine *machine = rb_entry(nd, struct machine, rb_node); in machines__set_symbol_filter() local
153 machine->symbol_filter = symbol_filter; in machines__set_symbol_filter()
157 struct machine *machines__find(struct machines *machines, pid_t pid) in machines__find()
161 struct machine *machine; in machines__find() local
162 struct machine *default_machine = NULL; in machines__find()
169 machine = rb_entry(parent, struct machine, rb_node); in machines__find()
170 if (pid < machine->pid) in machines__find()
172 else if (pid > machine->pid) in machines__find()
175 return machine; in machines__find()
176 if (!machine->pid) in machines__find()
177 default_machine = machine; in machines__find()
183 struct machine *machines__findnew(struct machines *machines, pid_t pid) in machines__findnew()
187 struct machine *machine = machines__find(machines, pid); in machines__findnew() local
189 if (machine && (machine->pid == pid)) in machines__findnew()
206 machine = NULL; in machines__findnew()
212 machine = machines__add(machines, pid, root_dir); in machines__findnew()
214 return machine; in machines__findnew()
223 struct machine *pos = rb_entry(nd, struct machine, rb_node); in machines__process_guests()
228 char *machine__mmap_name(struct machine *machine, char *bf, size_t size) in machine__mmap_name() argument
230 if (machine__is_host(machine)) in machine__mmap_name()
232 else if (machine__is_default_guest(machine)) in machine__mmap_name()
236 machine->pid); in machine__mmap_name()
245 struct machine *machine; in machines__set_id_hdr_size() local
250 machine = rb_entry(node, struct machine, rb_node); in machines__set_id_hdr_size()
251 machine->id_hdr_size = id_hdr_size; in machines__set_id_hdr_size()
257 static struct thread *__machine__findnew_thread(struct machine *machine, in __machine__findnew_thread() argument
261 struct rb_node **p = &machine->threads.rb_node; in __machine__findnew_thread()
270 if (machine->last_match && machine->last_match->tid == tid) { in __machine__findnew_thread()
271 if (pid && pid != machine->last_match->pid_) in __machine__findnew_thread()
272 machine->last_match->pid_ = pid; in __machine__findnew_thread()
273 return machine->last_match; in __machine__findnew_thread()
281 machine->last_match = th; in __machine__findnew_thread()
299 rb_insert_color(&th->rb_node, &machine->threads); in __machine__findnew_thread()
300 machine->last_match = th; in __machine__findnew_thread()
306 struct thread *machine__findnew_thread(struct machine *machine, pid_t pid, in machine__findnew_thread() argument
309 return __machine__findnew_thread(machine, pid, tid, true); in machine__findnew_thread()
312 struct thread *machine__find_thread(struct machine *machine, pid_t tid) in machine__find_thread() argument
314 return __machine__findnew_thread(machine, 0, tid, false); in machine__find_thread()
317 int machine__process_comm_event(struct machine *machine, union perf_event *event) in machine__process_comm_event() argument
319 struct thread *thread = machine__findnew_thread(machine, in machine__process_comm_event()
334 int machine__process_lost_event(struct machine *machine __maybe_unused, in machine__process_lost_event()
342 struct map *machine__new_module(struct machine *machine, u64 start, in machine__new_module() argument
346 struct dso *dso = __dsos__findnew(&machine->kernel_dsos, filename); in machine__new_module()
355 if (machine__is_host(machine)) in machine__new_module()
359 map_groups__insert(&machine->kmaps, map); in machine__new_module()
370 struct machine *pos = rb_entry(nd, struct machine, rb_node); in machines__fprintf_dsos()
378 size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp, in machine__fprintf_dsos_buildid() argument
381 return __dsos__fprintf_buildid(&machine->kernel_dsos, fp, skip, parm) + in machine__fprintf_dsos_buildid()
382 __dsos__fprintf_buildid(&machine->user_dsos, fp, skip, parm); in machine__fprintf_dsos_buildid()
392 struct machine *pos = rb_entry(nd, struct machine, rb_node); in machines__fprintf_dsos_buildid()
398 size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp) in machine__fprintf_vmlinux_path() argument
402 struct dso *kdso = machine->vmlinux_maps[MAP__FUNCTION]->dso; in machine__fprintf_vmlinux_path()
417 size_t machine__fprintf(struct machine *machine, FILE *fp) in machine__fprintf() argument
422 for (nd = rb_first(&machine->threads); nd; nd = rb_next(nd)) { in machine__fprintf()
431 static struct dso *machine__get_kernel(struct machine *machine) in machine__get_kernel() argument
436 if (machine__is_host(machine)) { in machine__get_kernel()
441 kernel = dso__kernel_findnew(machine, vmlinux_name, in machine__get_kernel()
447 if (machine__is_default_guest(machine)) in machine__get_kernel()
450 vmlinux_name = machine__mmap_name(machine, bf, in machine__get_kernel()
453 kernel = dso__kernel_findnew(machine, vmlinux_name, in machine__get_kernel()
459 dso__read_running_kernel_build_id(kernel, machine); in machine__get_kernel()
481 static u64 machine__get_kernel_start_addr(struct machine *machine) in machine__get_kernel_start_addr() argument
487 if (machine__is_host(machine)) { in machine__get_kernel_start_addr()
490 if (machine__is_default_guest(machine)) in machine__get_kernel_start_addr()
493 sprintf(path, "%s/proc/kallsyms", machine->root_dir); in machine__get_kernel_start_addr()
507 int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel) in __machine__create_kernel_maps() argument
510 u64 start = machine__get_kernel_start_addr(machine); in __machine__create_kernel_maps()
515 machine->vmlinux_maps[type] = map__new2(start, kernel, type); in __machine__create_kernel_maps()
516 if (machine->vmlinux_maps[type] == NULL) in __machine__create_kernel_maps()
519 machine->vmlinux_maps[type]->map_ip = in __machine__create_kernel_maps()
520 machine->vmlinux_maps[type]->unmap_ip = in __machine__create_kernel_maps()
522 kmap = map__kmap(machine->vmlinux_maps[type]); in __machine__create_kernel_maps()
523 kmap->kmaps = &machine->kmaps; in __machine__create_kernel_maps()
524 map_groups__insert(&machine->kmaps, in __machine__create_kernel_maps()
525 machine->vmlinux_maps[type]); in __machine__create_kernel_maps()
531 void machine__destroy_kernel_maps(struct machine *machine) in machine__destroy_kernel_maps() argument
538 if (machine->vmlinux_maps[type] == NULL) in machine__destroy_kernel_maps()
541 kmap = map__kmap(machine->vmlinux_maps[type]); in machine__destroy_kernel_maps()
542 map_groups__remove(&machine->kmaps, in machine__destroy_kernel_maps()
543 machine->vmlinux_maps[type]); in machine__destroy_kernel_maps()
557 map__delete(machine->vmlinux_maps[type]); in machine__destroy_kernel_maps()
558 machine->vmlinux_maps[type] = NULL; in machine__destroy_kernel_maps()
618 struct machine *pos = rb_entry(next, struct machine, rb_node); in machines__destroy_kernel_maps()
628 struct machine *machine = machines__findnew(machines, pid); in machines__create_kernel_maps() local
630 if (machine == NULL) in machines__create_kernel_maps()
633 return machine__create_kernel_maps(machine); in machines__create_kernel_maps()
636 int machine__load_kallsyms(struct machine *machine, const char *filename, in machine__load_kallsyms() argument
639 struct map *map = machine->vmlinux_maps[type]; in machine__load_kallsyms()
649 __map_groups__fixup_end(&machine->kmaps, type); in machine__load_kallsyms()
655 int machine__load_vmlinux_path(struct machine *machine, enum map_type type, in machine__load_vmlinux_path() argument
658 struct map *map = machine->vmlinux_maps[type]; in machine__load_vmlinux_path()
763 static int machine__set_modules_path(struct machine *machine) in machine__set_modules_path() argument
768 version = get_kernel_version(machine->root_dir); in machine__set_modules_path()
773 machine->root_dir, version); in machine__set_modules_path()
776 return map_groups__set_modules_path_dir(&machine->kmaps, modules_path); in machine__set_modules_path()
779 static int machine__create_modules(struct machine *machine) in machine__create_modules() argument
788 if (machine__is_default_guest(machine)) in machine__create_modules()
791 sprintf(path, "%s/proc/modules", machine->root_dir); in machine__create_modules()
830 map = machine__new_module(machine, start, name); in machine__create_modules()
833 dso__kernel_module_get_build_id(map->dso, machine->root_dir); in machine__create_modules()
839 if (machine__set_modules_path(machine) < 0) { in machine__create_modules()
850 int machine__create_kernel_maps(struct machine *machine) in machine__create_kernel_maps() argument
852 struct dso *kernel = machine__get_kernel(machine); in machine__create_kernel_maps()
855 __machine__create_kernel_maps(machine, kernel) < 0) in machine__create_kernel_maps()
858 if (symbol_conf.use_modules && machine__create_modules(machine) < 0) { in machine__create_kernel_maps()
859 if (machine__is_host(machine)) in machine__create_kernel_maps()
864 "continuing anyway...\n", machine->pid); in machine__create_kernel_maps()
870 map_groups__fixup_end(&machine->kmaps); in machine__create_kernel_maps()
874 static void machine__set_kernel_mmap_len(struct machine *machine, in machine__set_kernel_mmap_len() argument
880 machine->vmlinux_maps[i]->start = event->mmap.start; in machine__set_kernel_mmap_len()
881 machine->vmlinux_maps[i]->end = (event->mmap.start + in machine__set_kernel_mmap_len()
887 if (machine->vmlinux_maps[i]->end == 0) in machine__set_kernel_mmap_len()
888 machine->vmlinux_maps[i]->end = ~0ULL; in machine__set_kernel_mmap_len()
892 static bool machine__uses_kcore(struct machine *machine) in machine__uses_kcore() argument
896 list_for_each_entry(dso, &machine->kernel_dsos, node) { in machine__uses_kcore()
904 static int machine__process_kernel_mmap_event(struct machine *machine, in machine__process_kernel_mmap_event() argument
913 if (machine__uses_kcore(machine)) in machine__process_kernel_mmap_event()
916 machine__mmap_name(machine, kmmap_prefix, sizeof(kmmap_prefix)); in machine__process_kernel_mmap_event()
917 if (machine__is_host(machine)) in machine__process_kernel_mmap_event()
946 map = machine__new_module(machine, event->mmap.start, in machine__process_kernel_mmap_event()
965 struct dso *kernel = __dsos__findnew(&machine->kernel_dsos, in machine__process_kernel_mmap_event()
971 if (__machine__create_kernel_maps(machine, kernel) < 0) in machine__process_kernel_mmap_event()
974 machine__set_kernel_mmap_len(machine, event); in machine__process_kernel_mmap_event()
982 maps__set_kallsyms_ref_reloc_sym(machine->vmlinux_maps, in machine__process_kernel_mmap_event()
987 if (machine__is_default_guest(machine)) { in machine__process_kernel_mmap_event()
991 dso__load(kernel, machine->vmlinux_maps[MAP__FUNCTION], in machine__process_kernel_mmap_event()
1000 int machine__process_mmap2_event(struct machine *machine, in machine__process_mmap2_event() argument
1014 ret = machine__process_kernel_mmap_event(machine, event); in machine__process_mmap2_event()
1020 thread = machine__findnew_thread(machine, event->mmap2.pid, in machine__process_mmap2_event()
1030 map = map__new(&machine->user_dsos, event->mmap2.start, in machine__process_mmap2_event()
1048 int machine__process_mmap_event(struct machine *machine, union perf_event *event) in machine__process_mmap_event() argument
1061 ret = machine__process_kernel_mmap_event(machine, event); in machine__process_mmap_event()
1067 thread = machine__findnew_thread(machine, event->mmap.pid, in machine__process_mmap_event()
1077 map = map__new(&machine->user_dsos, event->mmap.start, in machine__process_mmap_event()
1094 static void machine__remove_thread(struct machine *machine, struct thread *th) in machine__remove_thread() argument
1096 machine->last_match = NULL; in machine__remove_thread()
1097 rb_erase(&th->rb_node, &machine->threads); in machine__remove_thread()
1102 list_add_tail(&th->node, &machine->dead_threads); in machine__remove_thread()
1105 int machine__process_fork_event(struct machine *machine, union perf_event *event) in machine__process_fork_event() argument
1107 struct thread *thread = machine__find_thread(machine, event->fork.tid); in machine__process_fork_event()
1108 struct thread *parent = machine__findnew_thread(machine, in machine__process_fork_event()
1114 machine__remove_thread(machine, thread); in machine__process_fork_event()
1116 thread = machine__findnew_thread(machine, event->fork.pid, in machine__process_fork_event()
1130 int machine__process_exit_event(struct machine *machine __maybe_unused, in machine__process_exit_event()
1133 struct thread *thread = machine__find_thread(machine, event->fork.tid); in machine__process_exit_event()
1144 int machine__process_event(struct machine *machine, union perf_event *event) in machine__process_event() argument
1150 ret = machine__process_comm_event(machine, event); break; in machine__process_event()
1152 ret = machine__process_mmap_event(machine, event); break; in machine__process_event()
1154 ret = machine__process_mmap2_event(machine, event); break; in machine__process_event()
1156 ret = machine__process_fork_event(machine, event); break; in machine__process_event()
1158 ret = machine__process_exit_event(machine, event); break; in machine__process_event()
1160 ret = machine__process_lost_event(machine, event); break; in machine__process_event()
1184 static void ip__resolve_ams(struct machine *machine, struct thread *thread, in ip__resolve_ams() argument
1203 thread__find_addr_location(thread, machine, m, MAP__FUNCTION, in ip__resolve_ams()
1215 static void ip__resolve_data(struct machine *machine, struct thread *thread, in ip__resolve_data() argument
1222 thread__find_addr_location(thread, machine, m, MAP__VARIABLE, addr, in ip__resolve_data()
1230 struct mem_info *machine__resolve_mem(struct machine *machine, in machine__resolve_mem() argument
1240 ip__resolve_ams(machine, thr, &mi->iaddr, sample->ip); in machine__resolve_mem()
1241 ip__resolve_data(machine, thr, cpumode, &mi->daddr, sample->addr); in machine__resolve_mem()
1247 struct branch_info *machine__resolve_bstack(struct machine *machine, in machine__resolve_bstack() argument
1259 ip__resolve_ams(machine, thr, &bi[i].to, bs->entries[i].to); in machine__resolve_bstack()
1260 ip__resolve_ams(machine, thr, &bi[i].from, bs->entries[i].from); in machine__resolve_bstack()
1266 static int machine__resolve_callchain_sample(struct machine *machine, in machine__resolve_callchain_sample() argument
1317 thread__find_addr_location(thread, machine, cpumode, in machine__resolve_callchain_sample()
1350 int machine__resolve_callchain(struct machine *machine, in machine__resolve_callchain() argument
1359 ret = machine__resolve_callchain_sample(machine, thread, in machine__resolve_callchain()
1374 return unwind__get_entries(unwind_entry, &callchain_cursor, machine, in machine__resolve_callchain()