aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/builtin-annotate.c2
-rw-r--r--tools/perf/builtin-buildid-list.c2
-rw-r--r--tools/perf/builtin-kmem.c8
-rw-r--r--tools/perf/builtin-record.c36
-rw-r--r--tools/perf/builtin-report.c2
-rw-r--r--tools/perf/builtin-top.c15
-rw-r--r--tools/perf/util/event.c92
-rw-r--r--tools/perf/util/event.h4
-rw-r--r--tools/perf/util/header.c70
-rw-r--r--tools/perf/util/header.h2
-rw-r--r--tools/perf/util/map.c105
-rw-r--r--tools/perf/util/map.h63
-rw-r--r--tools/perf/util/session.c4
-rw-r--r--tools/perf/util/session.h27
-rw-r--r--tools/perf/util/symbol.c132
-rw-r--r--tools/perf/util/symbol.h3
16 files changed, 280 insertions, 287 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index f924b4332be6..986b2efcef2e 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -571,7 +571,7 @@ static int __cmd_annotate(void)
571 perf_session__fprintf(session, stdout); 571 perf_session__fprintf(session, stdout);
572 572
573 if (verbose > 2) 573 if (verbose > 2)
574 dsos__fprintf(&session->kerninfo_root, stdout); 574 dsos__fprintf(&session->machines, stdout);
575 575
576 perf_session__collapse_resort(&session->hists); 576 perf_session__collapse_resort(&session->hists);
577 perf_session__output_resort(&session->hists, session->event_total[0]); 577 perf_session__output_resort(&session->hists, session->event_total[0]);
diff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c
index 623afe3fdcb8..b4a265ae3b98 100644
--- a/tools/perf/builtin-buildid-list.c
+++ b/tools/perf/builtin-buildid-list.c
@@ -46,7 +46,7 @@ static int __cmd_buildid_list(void)
46 if (with_hits) 46 if (with_hits)
47 perf_session__process_events(session, &build_id__mark_dso_hit_ops); 47 perf_session__process_events(session, &build_id__mark_dso_hit_ops);
48 48
49 dsos__fprintf_buildid(&session->kerninfo_root, stdout, with_hits); 49 dsos__fprintf_buildid(&session->machines, stdout, with_hits);
50 50
51 perf_session__delete(session); 51 perf_session__delete(session);
52 return err; 52 return err;
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index ab906cbd5c79..20674759464e 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -352,7 +352,7 @@ static void __print_result(struct rb_root *root, struct perf_session *session,
352 int n_lines, int is_caller) 352 int n_lines, int is_caller)
353{ 353{
354 struct rb_node *next; 354 struct rb_node *next;
355 struct kernel_info *kerninfo; 355 struct machine *machine;
356 356
357 printf("%.102s\n", graph_dotted_line); 357 printf("%.102s\n", graph_dotted_line);
358 printf(" %-34s |", is_caller ? "Callsite": "Alloc Ptr"); 358 printf(" %-34s |", is_caller ? "Callsite": "Alloc Ptr");
@@ -361,8 +361,8 @@ static void __print_result(struct rb_root *root, struct perf_session *session,
361 361
362 next = rb_first(root); 362 next = rb_first(root);
363 363
364 kerninfo = kerninfo__findhost(&session->kerninfo_root); 364 machine = perf_session__find_host_machine(session);
365 if (!kerninfo) { 365 if (!machine) {
366 pr_err("__print_result: couldn't find kernel information\n"); 366 pr_err("__print_result: couldn't find kernel information\n");
367 return; 367 return;
368 } 368 }
@@ -370,7 +370,7 @@ static void __print_result(struct rb_root *root, struct perf_session *session,
370 struct alloc_stat *data = rb_entry(next, struct alloc_stat, 370 struct alloc_stat *data = rb_entry(next, struct alloc_stat,
371 node); 371 node);
372 struct symbol *sym = NULL; 372 struct symbol *sym = NULL;
373 struct map_groups *kmaps = &kerninfo->kmaps; 373 struct map_groups *kmaps = &machine->kmaps;
374 struct map *map; 374 struct map *map;
375 char buf[BUFSIZ]; 375 char buf[BUFSIZ];
376 u64 addr; 376 u64 addr;
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 27f992aca8b5..83b308a035c2 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -456,14 +456,14 @@ static void atexit_header(void)
456 } 456 }
457} 457}
458 458
459static void event__synthesize_guest_os(struct kernel_info *kerninfo, 459static void event__synthesize_guest_os(struct machine *machine, void *data)
460 void *data __attribute__((unused)))
461{ 460{
462 int err; 461 int err;
463 char *guest_kallsyms; 462 char *guest_kallsyms;
464 char path[PATH_MAX]; 463 char path[PATH_MAX];
464 struct perf_session *psession = data;
465 465
466 if (is_host_kernel(kerninfo)) 466 if (machine__is_host(machine))
467 return; 467 return;
468 468
469 /* 469 /*
@@ -475,16 +475,15 @@ static void event__synthesize_guest_os(struct kernel_info *kerninfo,
475 *in module instead of in guest kernel. 475 *in module instead of in guest kernel.
476 */ 476 */
477 err = event__synthesize_modules(process_synthesized_event, 477 err = event__synthesize_modules(process_synthesized_event,
478 session, 478 psession, machine);
479 kerninfo);
480 if (err < 0) 479 if (err < 0)
481 pr_err("Couldn't record guest kernel [%d]'s reference" 480 pr_err("Couldn't record guest kernel [%d]'s reference"
482 " relocation symbol.\n", kerninfo->pid); 481 " relocation symbol.\n", machine->pid);
483 482
484 if (is_default_guest(kerninfo)) 483 if (machine__is_default_guest(machine))
485 guest_kallsyms = (char *) symbol_conf.default_guest_kallsyms; 484 guest_kallsyms = (char *) symbol_conf.default_guest_kallsyms;
486 else { 485 else {
487 sprintf(path, "%s/proc/kallsyms", kerninfo->root_dir); 486 sprintf(path, "%s/proc/kallsyms", machine->root_dir);
488 guest_kallsyms = path; 487 guest_kallsyms = path;
489 } 488 }
490 489
@@ -493,13 +492,13 @@ static void event__synthesize_guest_os(struct kernel_info *kerninfo,
493 * have no _text sometimes. 492 * have no _text sometimes.
494 */ 493 */
495 err = event__synthesize_kernel_mmap(process_synthesized_event, 494 err = event__synthesize_kernel_mmap(process_synthesized_event,
496 session, kerninfo, "_text"); 495 psession, machine, "_text");
497 if (err < 0) 496 if (err < 0)
498 err = event__synthesize_kernel_mmap(process_synthesized_event, 497 err = event__synthesize_kernel_mmap(process_synthesized_event,
499 session, kerninfo, "_stext"); 498 psession, machine, "_stext");
500 if (err < 0) 499 if (err < 0)
501 pr_err("Couldn't record guest kernel [%d]'s reference" 500 pr_err("Couldn't record guest kernel [%d]'s reference"
502 " relocation symbol.\n", kerninfo->pid); 501 " relocation symbol.\n", machine->pid);
503} 502}
504 503
505static int __cmd_record(int argc, const char **argv) 504static int __cmd_record(int argc, const char **argv)
@@ -513,7 +512,7 @@ static int __cmd_record(int argc, const char **argv)
513 int child_ready_pipe[2], go_pipe[2]; 512 int child_ready_pipe[2], go_pipe[2];
514 const bool forks = argc > 0; 513 const bool forks = argc > 0;
515 char buf; 514 char buf;
516 struct kernel_info *kerninfo; 515 struct machine *machine;
517 516
518 page_size = sysconf(_SC_PAGE_SIZE); 517 page_size = sysconf(_SC_PAGE_SIZE);
519 518
@@ -682,31 +681,30 @@ static int __cmd_record(int argc, const char **argv)
682 advance_output(err); 681 advance_output(err);
683 } 682 }
684 683
685 kerninfo = kerninfo__findhost(&session->kerninfo_root); 684 machine = perf_session__find_host_machine(session);
686 if (!kerninfo) { 685 if (!machine) {
687 pr_err("Couldn't find native kernel information.\n"); 686 pr_err("Couldn't find native kernel information.\n");
688 return -1; 687 return -1;
689 } 688 }
690 689
691 err = event__synthesize_kernel_mmap(process_synthesized_event, 690 err = event__synthesize_kernel_mmap(process_synthesized_event,
692 session, kerninfo, "_text"); 691 session, machine, "_text");
693 if (err < 0) 692 if (err < 0)
694 err = event__synthesize_kernel_mmap(process_synthesized_event, 693 err = event__synthesize_kernel_mmap(process_synthesized_event,
695 session, kerninfo, "_stext"); 694 session, machine, "_stext");
696 if (err < 0) { 695 if (err < 0) {
697 pr_err("Couldn't record kernel reference relocation symbol.\n"); 696 pr_err("Couldn't record kernel reference relocation symbol.\n");
698 return err; 697 return err;
699 } 698 }
700 699
701 err = event__synthesize_modules(process_synthesized_event, 700 err = event__synthesize_modules(process_synthesized_event,
702 session, kerninfo); 701 session, machine);
703 if (err < 0) { 702 if (err < 0) {
704 pr_err("Couldn't record kernel reference relocation symbol.\n"); 703 pr_err("Couldn't record kernel reference relocation symbol.\n");
705 return err; 704 return err;
706 } 705 }
707 if (perf_guest) 706 if (perf_guest)
708 kerninfo__process_allkernels(&session->kerninfo_root, 707 perf_session__process_machines(session, event__synthesize_guest_os);
709 event__synthesize_guest_os, session);
710 708
711 if (!system_wide && profile_cpu == -1) 709 if (!system_wide && profile_cpu == -1)
712 event__synthesize_thread(target_tid, process_synthesized_event, 710 event__synthesize_thread(target_tid, process_synthesized_event,
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 816edae7c5b2..49cc367d8c30 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -313,7 +313,7 @@ static int __cmd_report(void)
313 perf_session__fprintf(session, stdout); 313 perf_session__fprintf(session, stdout);
314 314
315 if (verbose > 2) 315 if (verbose > 2)
316 dsos__fprintf(&session->kerninfo_root, stdout); 316 dsos__fprintf(&session->machines, stdout);
317 317
318 next = rb_first(&session->stats_by_id); 318 next = rb_first(&session->stats_by_id);
319 while (next) { 319 while (next) {
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index dfd7ea7dabdd..c390f340b03d 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -854,7 +854,7 @@ static void handle_keypress(struct perf_session *session, int c)
854 case 'Q': 854 case 'Q':
855 printf("exiting.\n"); 855 printf("exiting.\n");
856 if (dump_symtab) 856 if (dump_symtab)
857 dsos__fprintf(&session->kerninfo_root, stderr); 857 dsos__fprintf(&session->machines, stderr);
858 exit(0); 858 exit(0);
859 case 's': 859 case 's':
860 prompt_symbol(&sym_filter_entry, "Enter details symbol"); 860 prompt_symbol(&sym_filter_entry, "Enter details symbol");
@@ -982,7 +982,7 @@ static void event__process_sample(const event_t *self,
982 u64 ip = self->ip.ip; 982 u64 ip = self->ip.ip;
983 struct sym_entry *syme; 983 struct sym_entry *syme;
984 struct addr_location al; 984 struct addr_location al;
985 struct kernel_info *kerninfo; 985 struct machine *machine;
986 u8 origin = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; 986 u8 origin = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
987 987
988 ++samples; 988 ++samples;
@@ -992,18 +992,17 @@ static void event__process_sample(const event_t *self,
992 ++us_samples; 992 ++us_samples;
993 if (hide_user_symbols) 993 if (hide_user_symbols)
994 return; 994 return;
995 kerninfo = kerninfo__findhost(&session->kerninfo_root); 995 machine = perf_session__find_host_machine(session);
996 break; 996 break;
997 case PERF_RECORD_MISC_KERNEL: 997 case PERF_RECORD_MISC_KERNEL:
998 ++kernel_samples; 998 ++kernel_samples;
999 if (hide_kernel_symbols) 999 if (hide_kernel_symbols)
1000 return; 1000 return;
1001 kerninfo = kerninfo__findhost(&session->kerninfo_root); 1001 machine = perf_session__find_host_machine(session);
1002 break; 1002 break;
1003 case PERF_RECORD_MISC_GUEST_KERNEL: 1003 case PERF_RECORD_MISC_GUEST_KERNEL:
1004 ++guest_kernel_samples; 1004 ++guest_kernel_samples;
1005 kerninfo = kerninfo__find(&session->kerninfo_root, 1005 machine = perf_session__find_machine(session, self->ip.pid);
1006 self->ip.pid);
1007 break; 1006 break;
1008 case PERF_RECORD_MISC_GUEST_USER: 1007 case PERF_RECORD_MISC_GUEST_USER:
1009 ++guest_us_samples; 1008 ++guest_us_samples;
@@ -1016,7 +1015,7 @@ static void event__process_sample(const event_t *self,
1016 return; 1015 return;
1017 } 1016 }
1018 1017
1019 if (!kerninfo && perf_guest) { 1018 if (!machine && perf_guest) {
1020 pr_err("Can't find guest [%d]'s kernel information\n", 1019 pr_err("Can't find guest [%d]'s kernel information\n",
1021 self->ip.pid); 1020 self->ip.pid);
1022 return; 1021 return;
@@ -1041,7 +1040,7 @@ static void event__process_sample(const event_t *self,
1041 * --hide-kernel-symbols, even if the user specifies an 1040 * --hide-kernel-symbols, even if the user specifies an
1042 * invalid --vmlinux ;-) 1041 * invalid --vmlinux ;-)
1043 */ 1042 */
1044 if (al.map == kerninfo->vmlinux_maps[MAP__FUNCTION] && 1043 if (al.map == machine->vmlinux_maps[MAP__FUNCTION] &&
1045 RB_EMPTY_ROOT(&al.map->dso->symbols[MAP__FUNCTION])) { 1044 RB_EMPTY_ROOT(&al.map->dso->symbols[MAP__FUNCTION])) {
1046 pr_err("The %s file can't be used\n", 1045 pr_err("The %s file can't be used\n",
1047 symbol_conf.vmlinux_name); 1046 symbol_conf.vmlinux_name);
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index e3fa8d3d11b4..2f33ca9899bd 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -172,17 +172,17 @@ static int event__synthesize_mmap_events(pid_t pid, pid_t tgid,
172 172
173int event__synthesize_modules(event__handler_t process, 173int event__synthesize_modules(event__handler_t process,
174 struct perf_session *session, 174 struct perf_session *session,
175 struct kernel_info *kerninfo) 175 struct machine *machine)
176{ 176{
177 struct rb_node *nd; 177 struct rb_node *nd;
178 struct map_groups *kmaps = &kerninfo->kmaps; 178 struct map_groups *kmaps = &machine->kmaps;
179 u16 misc; 179 u16 misc;
180 180
181 /* 181 /*
182 * kernel uses 0 for user space maps, see kernel/perf_event.c 182 * kernel uses 0 for user space maps, see kernel/perf_event.c
183 * __perf_event_mmap 183 * __perf_event_mmap
184 */ 184 */
185 if (is_host_kernel(kerninfo)) 185 if (machine__is_host(machine))
186 misc = PERF_RECORD_MISC_KERNEL; 186 misc = PERF_RECORD_MISC_KERNEL;
187 else 187 else
188 misc = PERF_RECORD_MISC_GUEST_KERNEL; 188 misc = PERF_RECORD_MISC_GUEST_KERNEL;
@@ -204,7 +204,7 @@ int event__synthesize_modules(event__handler_t process,
204 (sizeof(ev.mmap.filename) - size)); 204 (sizeof(ev.mmap.filename) - size));
205 ev.mmap.start = pos->start; 205 ev.mmap.start = pos->start;
206 ev.mmap.len = pos->end - pos->start; 206 ev.mmap.len = pos->end - pos->start;
207 ev.mmap.pid = kerninfo->pid; 207 ev.mmap.pid = machine->pid;
208 208
209 memcpy(ev.mmap.filename, pos->dso->long_name, 209 memcpy(ev.mmap.filename, pos->dso->long_name,
210 pos->dso->long_name_len + 1); 210 pos->dso->long_name_len + 1);
@@ -267,7 +267,7 @@ static int find_symbol_cb(void *arg, const char *name, char type, u64 start)
267 267
268int event__synthesize_kernel_mmap(event__handler_t process, 268int event__synthesize_kernel_mmap(event__handler_t process,
269 struct perf_session *session, 269 struct perf_session *session,
270 struct kernel_info *kerninfo, 270 struct machine *machine,
271 const char *symbol_name) 271 const char *symbol_name)
272{ 272{
273 size_t size; 273 size_t size;
@@ -288,8 +288,8 @@ int event__synthesize_kernel_mmap(event__handler_t process,
288 */ 288 */
289 struct process_symbol_args args = { .name = symbol_name, }; 289 struct process_symbol_args args = { .name = symbol_name, };
290 290
291 mmap_name = kern_mmap_name(kerninfo, name_buff); 291 mmap_name = machine__mmap_name(machine, name_buff);
292 if (is_host_kernel(kerninfo)) { 292 if (machine__is_host(machine)) {
293 /* 293 /*
294 * kernel uses PERF_RECORD_MISC_USER for user space maps, 294 * kernel uses PERF_RECORD_MISC_USER for user space maps,
295 * see kernel/perf_event.c __perf_event_mmap 295 * see kernel/perf_event.c __perf_event_mmap
@@ -298,10 +298,10 @@ int event__synthesize_kernel_mmap(event__handler_t process,
298 filename = "/proc/kallsyms"; 298 filename = "/proc/kallsyms";
299 } else { 299 } else {
300 ev.header.misc = PERF_RECORD_MISC_GUEST_KERNEL; 300 ev.header.misc = PERF_RECORD_MISC_GUEST_KERNEL;
301 if (is_default_guest(kerninfo)) 301 if (machine__is_default_guest(machine))
302 filename = (char *) symbol_conf.default_guest_kallsyms; 302 filename = (char *) symbol_conf.default_guest_kallsyms;
303 else { 303 else {
304 sprintf(path, "%s/proc/kallsyms", kerninfo->root_dir); 304 sprintf(path, "%s/proc/kallsyms", machine->root_dir);
305 filename = path; 305 filename = path;
306 } 306 }
307 } 307 }
@@ -309,7 +309,7 @@ int event__synthesize_kernel_mmap(event__handler_t process,
309 if (kallsyms__parse(filename, &args, find_symbol_cb) <= 0) 309 if (kallsyms__parse(filename, &args, find_symbol_cb) <= 0)
310 return -ENOENT; 310 return -ENOENT;
311 311
312 map = kerninfo->vmlinux_maps[MAP__FUNCTION]; 312 map = machine->vmlinux_maps[MAP__FUNCTION];
313 size = snprintf(ev.mmap.filename, sizeof(ev.mmap.filename), 313 size = snprintf(ev.mmap.filename, sizeof(ev.mmap.filename),
314 "%s%s", mmap_name, symbol_name) + 1; 314 "%s%s", mmap_name, symbol_name) + 1;
315 size = ALIGN(size, sizeof(u64)); 315 size = ALIGN(size, sizeof(u64));
@@ -318,7 +318,7 @@ int event__synthesize_kernel_mmap(event__handler_t process,
318 ev.mmap.pgoff = args.start; 318 ev.mmap.pgoff = args.start;
319 ev.mmap.start = map->start; 319 ev.mmap.start = map->start;
320 ev.mmap.len = map->end - ev.mmap.start; 320 ev.mmap.len = map->end - ev.mmap.start;
321 ev.mmap.pid = kerninfo->pid; 321 ev.mmap.pid = machine->pid;
322 322
323 return process(&ev, session); 323 return process(&ev, session);
324} 324}
@@ -389,18 +389,18 @@ static int event__process_kernel_mmap(event_t *self,
389{ 389{
390 struct map *map; 390 struct map *map;
391 char kmmap_prefix[PATH_MAX]; 391 char kmmap_prefix[PATH_MAX];
392 struct kernel_info *kerninfo; 392 struct machine *machine;
393 enum dso_kernel_type kernel_type; 393 enum dso_kernel_type kernel_type;
394 bool is_kernel_mmap; 394 bool is_kernel_mmap;
395 395
396 kerninfo = kerninfo__findnew(&session->kerninfo_root, self->mmap.pid); 396 machine = perf_session__findnew_machine(session, self->mmap.pid);
397 if (!kerninfo) { 397 if (!machine) {
398 pr_err("Can't find id %d's kerninfo\n", self->mmap.pid); 398 pr_err("Can't find id %d's machine\n", self->mmap.pid);
399 goto out_problem; 399 goto out_problem;
400 } 400 }
401 401
402 kern_mmap_name(kerninfo, kmmap_prefix); 402 machine__mmap_name(machine, kmmap_prefix);
403 if (is_host_kernel(kerninfo)) 403 if (machine__is_host(machine))
404 kernel_type = DSO_TYPE_KERNEL; 404 kernel_type = DSO_TYPE_KERNEL;
405 else 405 else
406 kernel_type = DSO_TYPE_GUEST_KERNEL; 406 kernel_type = DSO_TYPE_GUEST_KERNEL;
@@ -429,10 +429,9 @@ static int event__process_kernel_mmap(event_t *self,
429 } else 429 } else
430 strcpy(short_module_name, self->mmap.filename); 430 strcpy(short_module_name, self->mmap.filename);
431 431
432 map = map_groups__new_module(&kerninfo->kmaps, 432 map = map_groups__new_module(&machine->kmaps,
433 self->mmap.start, 433 self->mmap.start,
434 self->mmap.filename, 434 self->mmap.filename, machine);
435 kerninfo);
436 if (map == NULL) 435 if (map == NULL)
437 goto out_problem; 436 goto out_problem;
438 437
@@ -449,27 +448,27 @@ static int event__process_kernel_mmap(event_t *self,
449 * Should be there already, from the build-id table in 448 * Should be there already, from the build-id table in
450 * the header. 449 * the header.
451 */ 450 */
452 struct dso *kernel = __dsos__findnew(&kerninfo->dsos__kernel, 451 struct dso *kernel = __dsos__findnew(&machine->kernel_dsos,
453 kmmap_prefix); 452 kmmap_prefix);
454 if (kernel == NULL) 453 if (kernel == NULL)
455 goto out_problem; 454 goto out_problem;
456 455
457 kernel->kernel = kernel_type; 456 kernel->kernel = kernel_type;
458 if (__map_groups__create_kernel_maps(&kerninfo->kmaps, 457 if (__map_groups__create_kernel_maps(&machine->kmaps,
459 kerninfo->vmlinux_maps, kernel) < 0) 458 machine->vmlinux_maps,
459 kernel) < 0)
460 goto out_problem; 460 goto out_problem;
461 461
462 event_set_kernel_mmap_len(kerninfo->vmlinux_maps, self); 462 event_set_kernel_mmap_len(machine->vmlinux_maps, self);
463 perf_session__set_kallsyms_ref_reloc_sym(kerninfo->vmlinux_maps, 463 perf_session__set_kallsyms_ref_reloc_sym(machine->vmlinux_maps,
464 symbol_name, 464 symbol_name,
465 self->mmap.pgoff); 465 self->mmap.pgoff);
466 if (is_default_guest(kerninfo)) { 466 if (machine__is_default_guest(machine)) {
467 /* 467 /*
468 * preload dso of guest kernel and modules 468 * preload dso of guest kernel and modules
469 */ 469 */
470 dso__load(kernel, 470 dso__load(kernel, machine->vmlinux_maps[MAP__FUNCTION],
471 kerninfo->vmlinux_maps[MAP__FUNCTION], 471 NULL);
472 NULL);
473 } 472 }
474 } 473 }
475 return 0; 474 return 0;
@@ -479,7 +478,7 @@ out_problem:
479 478
480int event__process_mmap(event_t *self, struct perf_session *session) 479int event__process_mmap(event_t *self, struct perf_session *session)
481{ 480{
482 struct kernel_info *kerninfo; 481 struct machine *machine;
483 struct thread *thread; 482 struct thread *thread;
484 struct map *map; 483 struct map *map;
485 u8 cpumode = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; 484 u8 cpumode = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
@@ -498,8 +497,8 @@ int event__process_mmap(event_t *self, struct perf_session *session)
498 } 497 }
499 498
500 thread = perf_session__findnew(session, self->mmap.pid); 499 thread = perf_session__findnew(session, self->mmap.pid);
501 kerninfo = kerninfo__findhost(&session->kerninfo_root); 500 machine = perf_session__find_host_machine(session);
502 map = map__new(&kerninfo->dsos__user, self->mmap.start, 501 map = map__new(&machine->user_dsos, self->mmap.start,
503 self->mmap.len, self->mmap.pgoff, 502 self->mmap.len, self->mmap.pgoff,
504 self->mmap.pid, self->mmap.filename, 503 self->mmap.pid, self->mmap.filename,
505 MAP__FUNCTION, session->cwd, session->cwdlen); 504 MAP__FUNCTION, session->cwd, session->cwdlen);
@@ -546,7 +545,7 @@ void thread__find_addr_map(struct thread *self,
546 struct addr_location *al) 545 struct addr_location *al)
547{ 546{
548 struct map_groups *mg = &self->mg; 547 struct map_groups *mg = &self->mg;
549 struct kernel_info *kerninfo = NULL; 548 struct machine *machine = NULL;
550 549
551 al->thread = self; 550 al->thread = self;
552 al->addr = addr; 551 al->addr = addr;
@@ -555,19 +554,19 @@ void thread__find_addr_map(struct thread *self,
555 554
556 if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) { 555 if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) {
557 al->level = 'k'; 556 al->level = 'k';
558 kerninfo = kerninfo__findhost(&session->kerninfo_root); 557 machine = perf_session__find_host_machine(session);
559 mg = &kerninfo->kmaps; 558 mg = &machine->kmaps;
560 } else if (cpumode == PERF_RECORD_MISC_USER && perf_host) { 559 } else if (cpumode == PERF_RECORD_MISC_USER && perf_host) {
561 al->level = '.'; 560 al->level = '.';
562 kerninfo = kerninfo__findhost(&session->kerninfo_root); 561 machine = perf_session__find_host_machine(session);
563 } else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) { 562 } else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) {
564 al->level = 'g'; 563 al->level = 'g';
565 kerninfo = kerninfo__find(&session->kerninfo_root, pid); 564 machine = perf_session__find_machine(session, pid);
566 if (!kerninfo) { 565 if (!machine) {
567 al->map = NULL; 566 al->map = NULL;
568 return; 567 return;
569 } 568 }
570 mg = &kerninfo->kmaps; 569 mg = &machine->kmaps;
571 } else { 570 } else {
572 /* 571 /*
573 * 'u' means guest os user space. 572 * 'u' means guest os user space.
@@ -603,10 +602,9 @@ try_again:
603 * in the whole kernel symbol list. 602 * in the whole kernel symbol list.
604 */ 603 */
605 if ((long long)al->addr < 0 && 604 if ((long long)al->addr < 0 &&
606 cpumode == PERF_RECORD_MISC_KERNEL && 605 cpumode == PERF_RECORD_MISC_KERNEL &&
607 kerninfo && 606 machine && mg != &machine->kmaps) {
608 mg != &kerninfo->kmaps) { 607 mg = &machine->kmaps;
609 mg = &kerninfo->kmaps;
610 goto try_again; 608 goto try_again;
611 } 609 }
612 } else 610 } else
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 4af2ed5d48ad..b364da5b0cbf 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -156,12 +156,12 @@ void event__synthesize_threads(event__handler_t process,
156 struct perf_session *session); 156 struct perf_session *session);
157int event__synthesize_kernel_mmap(event__handler_t process, 157int event__synthesize_kernel_mmap(event__handler_t process,
158 struct perf_session *session, 158 struct perf_session *session,
159 struct kernel_info *kerninfo, 159 struct machine *machine,
160 const char *symbol_name); 160 const char *symbol_name);
161 161
162int event__synthesize_modules(event__handler_t process, 162int event__synthesize_modules(event__handler_t process,
163 struct perf_session *session, 163 struct perf_session *session,
164 struct kernel_info *kerninfo); 164 struct machine *machine);
165 165
166int event__process_comm(event_t *self, struct perf_session *session); 166int event__process_comm(event_t *self, struct perf_session *session);
167int event__process_lost(event_t *self, struct perf_session *session); 167int event__process_lost(event_t *self, struct perf_session *session);
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 75d016768021..6227dc4cb2cf 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -229,10 +229,9 @@ static int dsos__write_buildid_table(struct perf_header *header, int fd)
229 int err = 0; 229 int err = 0;
230 u16 kmisc, umisc; 230 u16 kmisc, umisc;
231 231
232 for (nd = rb_first(&session->kerninfo_root); nd; nd = rb_next(nd)) { 232 for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) {
233 struct kernel_info *pos = rb_entry(nd, struct kernel_info, 233 struct machine *pos = rb_entry(nd, struct machine, rb_node);
234 rb_node); 234 if (machine__is_host(pos)) {
235 if (is_host_kernel(pos)) {
236 kmisc = PERF_RECORD_MISC_KERNEL; 235 kmisc = PERF_RECORD_MISC_KERNEL;
237 umisc = PERF_RECORD_MISC_USER; 236 umisc = PERF_RECORD_MISC_USER;
238 } else { 237 } else {
@@ -240,11 +239,11 @@ static int dsos__write_buildid_table(struct perf_header *header, int fd)
240 umisc = PERF_RECORD_MISC_GUEST_USER; 239 umisc = PERF_RECORD_MISC_GUEST_USER;
241 } 240 }
242 241
243 err = __dsos__write_buildid_table(&pos->dsos__kernel, pos->pid, 242 err = __dsos__write_buildid_table(&pos->kernel_dsos, pos->pid,
244 kmisc, fd); 243 kmisc, fd);
245 if (err == 0) 244 if (err == 0)
246 err = __dsos__write_buildid_table(&pos->dsos__user, 245 err = __dsos__write_buildid_table(&pos->user_dsos,
247 pos->pid, umisc, fd); 246 pos->pid, umisc, fd);
248 if (err) 247 if (err)
249 break; 248 break;
250 } 249 }
@@ -378,11 +377,10 @@ static int dsos__cache_build_ids(struct perf_header *self)
378 if (mkdir(debugdir, 0755) != 0 && errno != EEXIST) 377 if (mkdir(debugdir, 0755) != 0 && errno != EEXIST)
379 return -1; 378 return -1;
380 379
381 for (nd = rb_first(&session->kerninfo_root); nd; nd = rb_next(nd)) { 380 for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) {
382 struct kernel_info *pos = rb_entry(nd, struct kernel_info, 381 struct machine *pos = rb_entry(nd, struct machine, rb_node);
383 rb_node); 382 ret |= __dsos__cache_build_ids(&pos->kernel_dsos, debugdir);
384 ret |= __dsos__cache_build_ids(&pos->dsos__kernel, debugdir); 383 ret |= __dsos__cache_build_ids(&pos->user_dsos, debugdir);
385 ret |= __dsos__cache_build_ids(&pos->dsos__user, debugdir);
386 } 384 }
387 return ret ? -1 : 0; 385 return ret ? -1 : 0;
388} 386}
@@ -394,11 +392,10 @@ static bool dsos__read_build_ids(struct perf_header *self, bool with_hits)
394 struct perf_session, header); 392 struct perf_session, header);
395 struct rb_node *nd; 393 struct rb_node *nd;
396 394
397 for (nd = rb_first(&session->kerninfo_root); nd; nd = rb_next(nd)) { 395 for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) {
398 struct kernel_info *pos = rb_entry(nd, struct kernel_info, 396 struct machine *pos = rb_entry(nd, struct machine, rb_node);
399 rb_node); 397 ret |= __dsos__read_build_ids(&pos->kernel_dsos, with_hits);
400 ret |= __dsos__read_build_ids(&pos->dsos__kernel, with_hits); 398 ret |= __dsos__read_build_ids(&pos->user_dsos, with_hits);
401 ret |= __dsos__read_build_ids(&pos->dsos__user, with_hits);
402 } 399 }
403 400
404 return ret; 401 return ret;
@@ -685,13 +682,13 @@ static int __event_process_build_id(struct build_id_event *bev,
685{ 682{
686 int err = -1; 683 int err = -1;
687 struct list_head *head; 684 struct list_head *head;
688 struct kernel_info *kerninfo; 685 struct machine *machine;
689 u16 misc; 686 u16 misc;
690 struct dso *dso; 687 struct dso *dso;
691 enum dso_kernel_type dso_type; 688 enum dso_kernel_type dso_type;
692 689
693 kerninfo = kerninfo__findnew(&session->kerninfo_root, bev->pid); 690 machine = perf_session__findnew_machine(session, bev->pid);
694 if (!kerninfo) 691 if (!machine)
695 goto out; 692 goto out;
696 693
697 misc = bev->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; 694 misc = bev->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
@@ -699,16 +696,16 @@ static int __event_process_build_id(struct build_id_event *bev,
699 switch (misc) { 696 switch (misc) {
700 case PERF_RECORD_MISC_KERNEL: 697 case PERF_RECORD_MISC_KERNEL:
701 dso_type = DSO_TYPE_KERNEL; 698 dso_type = DSO_TYPE_KERNEL;
702 head = &kerninfo->dsos__kernel; 699 head = &machine->kernel_dsos;
703 break; 700 break;
704 case PERF_RECORD_MISC_GUEST_KERNEL: 701 case PERF_RECORD_MISC_GUEST_KERNEL:
705 dso_type = DSO_TYPE_GUEST_KERNEL; 702 dso_type = DSO_TYPE_GUEST_KERNEL;
706 head = &kerninfo->dsos__kernel; 703 head = &machine->kernel_dsos;
707 break; 704 break;
708 case PERF_RECORD_MISC_USER: 705 case PERF_RECORD_MISC_USER:
709 case PERF_RECORD_MISC_GUEST_USER: 706 case PERF_RECORD_MISC_GUEST_USER:
710 dso_type = DSO_TYPE_USER; 707 dso_type = DSO_TYPE_USER;
711 head = &kerninfo->dsos__user; 708 head = &machine->user_dsos;
712 break; 709 break;
713 default: 710 default:
714 goto out; 711 goto out;
@@ -1113,8 +1110,7 @@ int event__process_tracing_data(event_t *self,
1113} 1110}
1114 1111
1115int event__synthesize_build_id(struct dso *pos, u16 misc, 1112int event__synthesize_build_id(struct dso *pos, u16 misc,
1116 event__handler_t process, 1113 event__handler_t process, struct machine *machine,
1117 struct kernel_info *kerninfo,
1118 struct perf_session *session) 1114 struct perf_session *session)
1119{ 1115{
1120 event_t ev; 1116 event_t ev;
@@ -1131,7 +1127,7 @@ int event__synthesize_build_id(struct dso *pos, u16 misc,
1131 memcpy(&ev.build_id.build_id, pos->build_id, sizeof(pos->build_id)); 1127 memcpy(&ev.build_id.build_id, pos->build_id, sizeof(pos->build_id));
1132 ev.build_id.header.type = PERF_RECORD_HEADER_BUILD_ID; 1128 ev.build_id.header.type = PERF_RECORD_HEADER_BUILD_ID;
1133 ev.build_id.header.misc = misc; 1129 ev.build_id.header.misc = misc;
1134 ev.build_id.pid = kerninfo->pid; 1130 ev.build_id.pid = machine->pid;
1135 ev.build_id.header.size = sizeof(ev.build_id) + len; 1131 ev.build_id.header.size = sizeof(ev.build_id) + len;
1136 memcpy(&ev.build_id.filename, pos->long_name, pos->long_name_len); 1132 memcpy(&ev.build_id.filename, pos->long_name, pos->long_name_len);
1137 1133
@@ -1142,7 +1138,7 @@ int event__synthesize_build_id(struct dso *pos, u16 misc,
1142 1138
1143static int __event_synthesize_build_ids(struct list_head *head, u16 misc, 1139static int __event_synthesize_build_ids(struct list_head *head, u16 misc,
1144 event__handler_t process, 1140 event__handler_t process,
1145 struct kernel_info *kerninfo, 1141 struct machine *machine,
1146 struct perf_session *session) 1142 struct perf_session *session)
1147{ 1143{
1148 struct dso *pos; 1144 struct dso *pos;
@@ -1153,7 +1149,7 @@ static int __event_synthesize_build_ids(struct list_head *head, u16 misc,
1153 continue; 1149 continue;
1154 1150
1155 err = event__synthesize_build_id(pos, misc, process, 1151 err = event__synthesize_build_id(pos, misc, process,
1156 kerninfo, session); 1152 machine, session);
1157 if (err < 0) 1153 if (err < 0)
1158 return err; 1154 return err;
1159 } 1155 }
@@ -1166,15 +1162,15 @@ int event__synthesize_build_ids(event__handler_t process,
1166{ 1162{
1167 int err = 0; 1163 int err = 0;
1168 u16 kmisc, umisc; 1164 u16 kmisc, umisc;
1169 struct kernel_info *pos; 1165 struct machine *pos;
1170 struct rb_node *nd; 1166 struct rb_node *nd;
1171 1167
1172 if (!dsos__read_build_ids(&session->header, true)) 1168 if (!dsos__read_build_ids(&session->header, true))
1173 return 0; 1169 return 0;
1174 1170
1175 for (nd = rb_first(&session->kerninfo_root); nd; nd = rb_next(nd)) { 1171 for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) {
1176 pos = rb_entry(nd, struct kernel_info, rb_node); 1172 pos = rb_entry(nd, struct machine, rb_node);
1177 if (is_host_kernel(pos)) { 1173 if (machine__is_host(pos)) {
1178 kmisc = PERF_RECORD_MISC_KERNEL; 1174 kmisc = PERF_RECORD_MISC_KERNEL;
1179 umisc = PERF_RECORD_MISC_USER; 1175 umisc = PERF_RECORD_MISC_USER;
1180 } else { 1176 } else {
@@ -1182,11 +1178,11 @@ int event__synthesize_build_ids(event__handler_t process,
1182 umisc = PERF_RECORD_MISC_GUEST_USER; 1178 umisc = PERF_RECORD_MISC_GUEST_USER;
1183 } 1179 }
1184 1180
1185 err = __event_synthesize_build_ids(&pos->dsos__kernel, 1181 err = __event_synthesize_build_ids(&pos->kernel_dsos, kmisc,
1186 kmisc, process, pos, session); 1182 process, pos, session);
1187 if (err == 0) 1183 if (err == 0)
1188 err = __event_synthesize_build_ids(&pos->dsos__user, 1184 err = __event_synthesize_build_ids(&pos->user_dsos, umisc,
1189 umisc, process, pos, session); 1185 process, pos, session);
1190 if (err) 1186 if (err)
1191 break; 1187 break;
1192 } 1188 }
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 275915458148..f39443db0706 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -120,7 +120,7 @@ int event__process_tracing_data(event_t *self,
120 120
121int event__synthesize_build_id(struct dso *pos, u16 misc, 121int event__synthesize_build_id(struct dso *pos, u16 misc,
122 event__handler_t process, 122 event__handler_t process,
123 struct kernel_info *kerninfo, 123 struct machine *machine,
124 struct perf_session *session); 124 struct perf_session *session);
125int event__synthesize_build_ids(event__handler_t process, 125int event__synthesize_build_ids(event__handler_t process,
126 struct perf_session *session); 126 struct perf_session *session);
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 7facd016ec97..da3d4e826231 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -245,7 +245,7 @@ void map_groups__init(struct map_groups *self)
245 self->maps[i] = RB_ROOT; 245 self->maps[i] = RB_ROOT;
246 INIT_LIST_HEAD(&self->removed_maps[i]); 246 INIT_LIST_HEAD(&self->removed_maps[i]);
247 } 247 }
248 self->this_kerninfo = NULL; 248 self->machine = NULL;
249} 249}
250 250
251void map_groups__flush(struct map_groups *self) 251void map_groups__flush(struct map_groups *self)
@@ -513,133 +513,130 @@ struct map *maps__find(struct rb_root *maps, u64 ip)
513 return NULL; 513 return NULL;
514} 514}
515 515
516struct kernel_info *add_new_kernel_info(struct rb_root *kerninfo_root, 516struct machine *machines__add(struct rb_root *self, pid_t pid,
517 pid_t pid, const char *root_dir) 517 const char *root_dir)
518{ 518{
519 struct rb_node **p = &kerninfo_root->rb_node; 519 struct rb_node **p = &self->rb_node;
520 struct rb_node *parent = NULL; 520 struct rb_node *parent = NULL;
521 struct kernel_info *kerninfo, *pos; 521 struct machine *pos, *machine = malloc(sizeof(*machine));
522 522
523 kerninfo = malloc(sizeof(struct kernel_info)); 523 if (!machine)
524 if (!kerninfo)
525 return NULL; 524 return NULL;
526 525
527 kerninfo->pid = pid; 526 machine->pid = pid;
528 map_groups__init(&kerninfo->kmaps); 527 map_groups__init(&machine->kmaps);
529 kerninfo->root_dir = strdup(root_dir); 528 machine->root_dir = strdup(root_dir);
530 RB_CLEAR_NODE(&kerninfo->rb_node); 529 RB_CLEAR_NODE(&machine->rb_node);
531 INIT_LIST_HEAD(&kerninfo->dsos__user); 530 INIT_LIST_HEAD(&machine->user_dsos);
532 INIT_LIST_HEAD(&kerninfo->dsos__kernel); 531 INIT_LIST_HEAD(&machine->kernel_dsos);
533 kerninfo->kmaps.this_kerninfo = kerninfo; 532 machine->kmaps.machine = machine;
534 533
535 while (*p != NULL) { 534 while (*p != NULL) {
536 parent = *p; 535 parent = *p;
537 pos = rb_entry(parent, struct kernel_info, rb_node); 536 pos = rb_entry(parent, struct machine, rb_node);
538 if (pid < pos->pid) 537 if (pid < pos->pid)
539 p = &(*p)->rb_left; 538 p = &(*p)->rb_left;
540 else 539 else
541 p = &(*p)->rb_right; 540 p = &(*p)->rb_right;
542 } 541 }
543 542
544 rb_link_node(&kerninfo->rb_node, parent, p); 543 rb_link_node(&machine->rb_node, parent, p);
545 rb_insert_color(&kerninfo->rb_node, kerninfo_root); 544 rb_insert_color(&machine->rb_node, self);
546 545
547 return kerninfo; 546 return machine;
548} 547}
549 548
550struct kernel_info *kerninfo__find(struct rb_root *kerninfo_root, pid_t pid) 549struct machine *machines__find(struct rb_root *self, pid_t pid)
551{ 550{
552 struct rb_node **p = &kerninfo_root->rb_node; 551 struct rb_node **p = &self->rb_node;
553 struct rb_node *parent = NULL; 552 struct rb_node *parent = NULL;
554 struct kernel_info *kerninfo; 553 struct machine *machine;
555 struct kernel_info *default_kerninfo = NULL; 554 struct machine *default_machine = NULL;
556 555
557 while (*p != NULL) { 556 while (*p != NULL) {
558 parent = *p; 557 parent = *p;
559 kerninfo = rb_entry(parent, struct kernel_info, rb_node); 558 machine = rb_entry(parent, struct machine, rb_node);
560 if (pid < kerninfo->pid) 559 if (pid < machine->pid)
561 p = &(*p)->rb_left; 560 p = &(*p)->rb_left;
562 else if (pid > kerninfo->pid) 561 else if (pid > machine->pid)
563 p = &(*p)->rb_right; 562 p = &(*p)->rb_right;
564 else 563 else
565 return kerninfo; 564 return machine;
566 if (!kerninfo->pid) 565 if (!machine->pid)
567 default_kerninfo = kerninfo; 566 default_machine = machine;
568 } 567 }
569 568
570 return default_kerninfo; 569 return default_machine;
571} 570}
572 571
573struct kernel_info *kerninfo__findhost(struct rb_root *kerninfo_root) 572/*
573 * FIXME: Why repeatedly search for this?
574 */
575struct machine *machines__find_host(struct rb_root *self)
574{ 576{
575 struct rb_node **p = &kerninfo_root->rb_node; 577 struct rb_node **p = &self->rb_node;
576 struct rb_node *parent = NULL; 578 struct rb_node *parent = NULL;
577 struct kernel_info *kerninfo; 579 struct machine *machine;
578 pid_t pid = HOST_KERNEL_ID; 580 pid_t pid = HOST_KERNEL_ID;
579 581
580 while (*p != NULL) { 582 while (*p != NULL) {
581 parent = *p; 583 parent = *p;
582 kerninfo = rb_entry(parent, struct kernel_info, rb_node); 584 machine = rb_entry(parent, struct machine, rb_node);
583 if (pid < kerninfo->pid) 585 if (pid < machine->pid)
584 p = &(*p)->rb_left; 586 p = &(*p)->rb_left;
585 else if (pid > kerninfo->pid) 587 else if (pid > machine->pid)
586 p = &(*p)->rb_right; 588 p = &(*p)->rb_right;
587 else 589 else
588 return kerninfo; 590 return machine;
589 } 591 }
590 592
591 return NULL; 593 return NULL;
592} 594}
593 595
594struct kernel_info *kerninfo__findnew(struct rb_root *kerninfo_root, pid_t pid) 596struct machine *machines__findnew(struct rb_root *self, pid_t pid)
595{ 597{
596 char path[PATH_MAX]; 598 char path[PATH_MAX];
597 const char *root_dir; 599 const char *root_dir;
598 int ret; 600 struct machine *machine = machines__find(self, pid);
599 struct kernel_info *kerninfo = kerninfo__find(kerninfo_root, pid);
600 601
601 if (!kerninfo || kerninfo->pid != pid) { 602 if (!machine || machine->pid != pid) {
602 if (pid == HOST_KERNEL_ID || pid == DEFAULT_GUEST_KERNEL_ID) 603 if (pid == HOST_KERNEL_ID || pid == DEFAULT_GUEST_KERNEL_ID)
603 root_dir = ""; 604 root_dir = "";
604 else { 605 else {
605 if (!symbol_conf.guestmount) 606 if (!symbol_conf.guestmount)
606 goto out; 607 goto out;
607 sprintf(path, "%s/%d", symbol_conf.guestmount, pid); 608 sprintf(path, "%s/%d", symbol_conf.guestmount, pid);
608 ret = access(path, R_OK); 609 if (access(path, R_OK)) {
609 if (ret) {
610 pr_err("Can't access file %s\n", path); 610 pr_err("Can't access file %s\n", path);
611 goto out; 611 goto out;
612 } 612 }
613 root_dir = path; 613 root_dir = path;
614 } 614 }
615 kerninfo = add_new_kernel_info(kerninfo_root, pid, root_dir); 615 machine = machines__add(self, pid, root_dir);
616 } 616 }
617 617
618out: 618out:
619 return kerninfo; 619 return machine;
620} 620}
621 621
622void kerninfo__process_allkernels(struct rb_root *kerninfo_root, 622void machines__process(struct rb_root *self, machine__process_t process, void *data)
623 process_kernel_info process,
624 void *data)
625{ 623{
626 struct rb_node *nd; 624 struct rb_node *nd;
627 625
628 for (nd = rb_first(kerninfo_root); nd; nd = rb_next(nd)) { 626 for (nd = rb_first(self); nd; nd = rb_next(nd)) {
629 struct kernel_info *pos = rb_entry(nd, struct kernel_info, 627 struct machine *pos = rb_entry(nd, struct machine, rb_node);
630 rb_node);
631 process(pos, data); 628 process(pos, data);
632 } 629 }
633} 630}
634 631
635char *kern_mmap_name(struct kernel_info *kerninfo, char *buff) 632char *machine__mmap_name(struct machine *self, char *buff)
636{ 633{
637 if (is_host_kernel(kerninfo)) 634 if (machine__is_host(self))
638 sprintf(buff, "[%s]", "kernel.kallsyms"); 635 sprintf(buff, "[%s]", "kernel.kallsyms");
639 else if (is_default_guest(kerninfo)) 636 else if (machine__is_default_guest(self))
640 sprintf(buff, "[%s]", "guest.kernel.kallsyms"); 637 sprintf(buff, "[%s]", "guest.kernel.kallsyms");
641 else 638 else
642 sprintf(buff, "[%s.%d]", "guest.kernel.kallsyms", kerninfo->pid); 639 sprintf(buff, "[%s.%d]", "guest.kernel.kallsyms", self->pid);
643 640
644 return buff; 641 return buff;
645} 642}
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index 30d38d634e09..4c1c2da704b2 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -5,6 +5,7 @@
5#include <linux/list.h> 5#include <linux/list.h>
6#include <linux/rbtree.h> 6#include <linux/rbtree.h>
7#include <stdio.h> 7#include <stdio.h>
8#include <stdbool.h>
8#include "types.h" 9#include "types.h"
9 10
10enum map_type { 11enum map_type {
@@ -19,7 +20,7 @@ extern const char *map_type__name[MAP__NR_TYPES];
19struct dso; 20struct dso;
20struct ref_reloc_sym; 21struct ref_reloc_sym;
21struct map_groups; 22struct map_groups;
22struct kernel_info; 23struct machine;
23 24
24struct map { 25struct map {
25 union { 26 union {
@@ -46,23 +47,23 @@ struct kmap {
46}; 47};
47 48
48struct map_groups { 49struct map_groups {
49 struct rb_root maps[MAP__NR_TYPES]; 50 struct rb_root maps[MAP__NR_TYPES];
50 struct list_head removed_maps[MAP__NR_TYPES]; 51 struct list_head removed_maps[MAP__NR_TYPES];
51 struct kernel_info *this_kerninfo; 52 struct machine *machine;
52}; 53};
53 54
54/* Native host kernel uses -1 as pid index in kernel_info */ 55/* Native host kernel uses -1 as pid index in machine */
55#define HOST_KERNEL_ID (-1) 56#define HOST_KERNEL_ID (-1)
56#define DEFAULT_GUEST_KERNEL_ID (0) 57#define DEFAULT_GUEST_KERNEL_ID (0)
57 58
58struct kernel_info { 59struct machine {
59 struct rb_node rb_node; 60 struct rb_node rb_node;
60 pid_t pid; 61 pid_t pid;
61 char *root_dir; 62 char *root_dir;
62 struct list_head dsos__user; 63 struct list_head user_dsos;
63 struct list_head dsos__kernel; 64 struct list_head kernel_dsos;
64 struct map_groups kmaps; 65 struct map_groups kmaps;
65 struct map *vmlinux_maps[MAP__NR_TYPES]; 66 struct map *vmlinux_maps[MAP__NR_TYPES];
66}; 67};
67 68
68static inline struct kmap *map__kmap(struct map *self) 69static inline struct kmap *map__kmap(struct map *self)
@@ -124,36 +125,30 @@ int map_groups__clone(struct map_groups *self,
124size_t map_groups__fprintf(struct map_groups *self, int verbose, FILE *fp); 125size_t map_groups__fprintf(struct map_groups *self, int verbose, FILE *fp);
125size_t map_groups__fprintf_maps(struct map_groups *self, int verbose, FILE *fp); 126size_t map_groups__fprintf_maps(struct map_groups *self, int verbose, FILE *fp);
126 127
127struct kernel_info *add_new_kernel_info(struct rb_root *kerninfo_root, 128typedef void (*machine__process_t)(struct machine *self, void *data);
128 pid_t pid, const char *root_dir); 129
129struct kernel_info *kerninfo__find(struct rb_root *kerninfo_root, pid_t pid); 130void machines__process(struct rb_root *self, machine__process_t process, void *data);
130struct kernel_info *kerninfo__findnew(struct rb_root *kerninfo_root, pid_t pid); 131struct machine *machines__add(struct rb_root *self, pid_t pid,
131struct kernel_info *kerninfo__findhost(struct rb_root *kerninfo_root); 132 const char *root_dir);
132char *kern_mmap_name(struct kernel_info *kerninfo, char *buff); 133struct machine *machines__find_host(struct rb_root *self);
134struct machine *machines__find(struct rb_root *self, pid_t pid);
135struct machine *machines__findnew(struct rb_root *self, pid_t pid);
136char *machine__mmap_name(struct machine *self, char *buff);
133 137
134/* 138/*
135 * Default guest kernel is defined by parameter --guestkallsyms 139 * Default guest kernel is defined by parameter --guestkallsyms
136 * and --guestmodules 140 * and --guestmodules
137 */ 141 */
138static inline int is_default_guest(struct kernel_info *kerninfo) 142static inline bool machine__is_default_guest(struct machine *self)
139{ 143{
140 if (!kerninfo) 144 return self ? self->pid == DEFAULT_GUEST_KERNEL_ID : false;
141 return 0;
142 return kerninfo->pid == DEFAULT_GUEST_KERNEL_ID;
143} 145}
144 146
145static inline int is_host_kernel(struct kernel_info *kerninfo) 147static inline bool machine__is_host(struct machine *self)
146{ 148{
147 if (!kerninfo) 149 return self ? self->pid == HOST_KERNEL_ID : false;
148 return 0;
149 return kerninfo->pid == HOST_KERNEL_ID;
150} 150}
151 151
152typedef void (*process_kernel_info)(struct kernel_info *kerninfo, void *data);
153void kerninfo__process_allkernels(struct rb_root *kerninfo_root,
154 process_kernel_info process,
155 void *data);
156
157static inline void map_groups__insert(struct map_groups *self, struct map *map) 152static inline void map_groups__insert(struct map_groups *self, struct map *map)
158{ 153{
159 maps__insert(&self->maps[map->type], map); 154 maps__insert(&self->maps[map->type], map);
@@ -197,10 +192,8 @@ int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,
197 192
198struct map *map_groups__find_by_name(struct map_groups *self, 193struct map *map_groups__find_by_name(struct map_groups *self,
199 enum map_type type, const char *name); 194 enum map_type type, const char *name);
200struct map *map_groups__new_module(struct map_groups *self, 195struct map *map_groups__new_module(struct map_groups *self, u64 start,
201 u64 start, 196 const char *filename, struct machine *machine);
202 const char *filename,
203 struct kernel_info *kerninfo);
204 197
205void map_groups__flush(struct map_groups *self); 198void map_groups__flush(struct map_groups *self);
206 199
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index b7aade2184b2..b745c1c0b6c7 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -70,7 +70,7 @@ void perf_session__update_sample_type(struct perf_session *self)
70int perf_session__create_kernel_maps(struct perf_session *self) 70int perf_session__create_kernel_maps(struct perf_session *self)
71{ 71{
72 int ret; 72 int ret;
73 struct rb_root *root = &self->kerninfo_root; 73 struct rb_root *root = &self->machines;
74 74
75 ret = map_groups__create_kernel_maps(root, HOST_KERNEL_ID); 75 ret = map_groups__create_kernel_maps(root, HOST_KERNEL_ID);
76 if (ret >= 0) 76 if (ret >= 0)
@@ -97,7 +97,7 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc
97 self->cwd = NULL; 97 self->cwd = NULL;
98 self->cwdlen = 0; 98 self->cwdlen = 0;
99 self->unknown_events = 0; 99 self->unknown_events = 0;
100 self->kerninfo_root = RB_ROOT; 100 self->machines = RB_ROOT;
101 self->ordered_samples.flush_limit = ULLONG_MAX; 101 self->ordered_samples.flush_limit = ULLONG_MAX;
102 INIT_LIST_HEAD(&self->ordered_samples.samples_head); 102 INIT_LIST_HEAD(&self->ordered_samples.samples_head);
103 103
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 796e2291ebd7..71252723a17d 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -25,7 +25,7 @@ struct perf_session {
25 unsigned long mmap_window; 25 unsigned long mmap_window;
26 struct rb_root threads; 26 struct rb_root threads;
27 struct thread *last_match; 27 struct thread *last_match;
28 struct rb_root kerninfo_root; 28 struct rb_root machines;
29 struct events_stats events_stats; 29 struct events_stats events_stats;
30 struct rb_root stats_by_id; 30 struct rb_root stats_by_id;
31 unsigned long event_total[PERF_RECORD_MAX]; 31 unsigned long event_total[PERF_RECORD_MAX];
@@ -102,4 +102,29 @@ int perf_session__browse_hists(struct rb_root *hists, u64 nr_hists,
102 u64 session_total, const char *helpline, 102 u64 session_total, const char *helpline,
103 const char *input_name); 103 const char *input_name);
104#endif 104#endif
105
106static inline
107struct machine *perf_session__find_host_machine(struct perf_session *self)
108{
109 return machines__find_host(&self->machines);
110}
111
112static inline
113struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid)
114{
115 return machines__find(&self->machines, pid);
116}
117
118static inline
119struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid)
120{
121 return machines__findnew(&self->machines, pid);
122}
123
124static inline
125void perf_session__process_machines(struct perf_session *self,
126 machine__process_t process)
127{
128 return machines__process(&self->machines, process, self);
129}
105#endif /* __PERF_SESSION_H */ 130#endif /* __PERF_SESSION_H */
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index e77c33a11de3..dc046368b5cf 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -485,7 +485,7 @@ static int dso__split_kallsyms(struct dso *self, struct map *map,
485 symbol_filter_t filter) 485 symbol_filter_t filter)
486{ 486{
487 struct map_groups *kmaps = map__kmap(map)->kmaps; 487 struct map_groups *kmaps = map__kmap(map)->kmaps;
488 struct kernel_info *kerninfo = kmaps->this_kerninfo; 488 struct machine *machine = kmaps->machine;
489 struct map *curr_map = map; 489 struct map *curr_map = map;
490 struct symbol *pos; 490 struct symbol *pos;
491 int count = 0; 491 int count = 0;
@@ -508,8 +508,8 @@ static int dso__split_kallsyms(struct dso *self, struct map *map,
508 508
509 if (strcmp(curr_map->dso->short_name, module)) { 509 if (strcmp(curr_map->dso->short_name, module)) {
510 if (curr_map != map && 510 if (curr_map != map &&
511 self->kernel == DSO_TYPE_GUEST_KERNEL && 511 self->kernel == DSO_TYPE_GUEST_KERNEL &&
512 is_default_guest(kerninfo)) { 512 machine__is_default_guest(machine)) {
513 /* 513 /*
514 * We assume all symbols of a module are 514 * We assume all symbols of a module are
515 * continuous in * kallsyms, so curr_map 515 * continuous in * kallsyms, so curr_map
@@ -527,13 +527,13 @@ static int dso__split_kallsyms(struct dso *self, struct map *map,
527 pr_err("%s/proc/{kallsyms,modules} " 527 pr_err("%s/proc/{kallsyms,modules} "
528 "inconsistency while looking " 528 "inconsistency while looking "
529 "for \"%s\" module!\n", 529 "for \"%s\" module!\n",
530 kerninfo->root_dir, module); 530 machine->root_dir, module);
531 curr_map = map; 531 curr_map = map;
532 goto discard_symbol; 532 goto discard_symbol;
533 } 533 }
534 534
535 if (curr_map->dso->loaded && 535 if (curr_map->dso->loaded &&
536 !is_default_guest(kmaps->this_kerninfo)) 536 !machine__is_default_guest(machine))
537 goto discard_symbol; 537 goto discard_symbol;
538 } 538 }
539 /* 539 /*
@@ -586,7 +586,7 @@ discard_symbol: rb_erase(&pos->rb_node, root);
586 586
587 if (curr_map != map && 587 if (curr_map != map &&
588 self->kernel == DSO_TYPE_GUEST_KERNEL && 588 self->kernel == DSO_TYPE_GUEST_KERNEL &&
589 is_default_guest(kmaps->this_kerninfo)) { 589 machine__is_default_guest(kmaps->machine)) {
590 dso__set_loaded(curr_map->dso, curr_map->type); 590 dso__set_loaded(curr_map->dso, curr_map->type);
591 } 591 }
592 592
@@ -1291,7 +1291,7 @@ int dso__load(struct dso *self, struct map *map, symbol_filter_t filter)
1291 char build_id_hex[BUILD_ID_SIZE * 2 + 1]; 1291 char build_id_hex[BUILD_ID_SIZE * 2 + 1];
1292 int ret = -1; 1292 int ret = -1;
1293 int fd; 1293 int fd;
1294 struct kernel_info *kerninfo; 1294 struct machine *machine;
1295 const char *root_dir; 1295 const char *root_dir;
1296 1296
1297 dso__set_loaded(self, map->type); 1297 dso__set_loaded(self, map->type);
@@ -1301,10 +1301,10 @@ int dso__load(struct dso *self, struct map *map, symbol_filter_t filter)
1301 else if (self->kernel == DSO_TYPE_GUEST_KERNEL) 1301 else if (self->kernel == DSO_TYPE_GUEST_KERNEL)
1302 return dso__load_guest_kernel_sym(self, map, filter); 1302 return dso__load_guest_kernel_sym(self, map, filter);
1303 1303
1304 if (map->groups && map->groups->this_kerninfo) 1304 if (map->groups && map->groups->machine)
1305 kerninfo = map->groups->this_kerninfo; 1305 machine = map->groups->machine;
1306 else 1306 else
1307 kerninfo = NULL; 1307 machine = NULL;
1308 1308
1309 name = malloc(size); 1309 name = malloc(size);
1310 if (!name) 1310 if (!name)
@@ -1359,8 +1359,8 @@ more:
1359 snprintf(name, size, "%s", self->long_name); 1359 snprintf(name, size, "%s", self->long_name);
1360 break; 1360 break;
1361 case DSO__ORIG_GUEST_KMODULE: 1361 case DSO__ORIG_GUEST_KMODULE:
1362 if (map->groups && map->groups->this_kerninfo) 1362 if (map->groups && map->groups->machine)
1363 root_dir = map->groups->this_kerninfo->root_dir; 1363 root_dir = map->groups->machine->root_dir;
1364 else 1364 else
1365 root_dir = ""; 1365 root_dir = "";
1366 snprintf(name, size, "%s%s", root_dir, self->long_name); 1366 snprintf(name, size, "%s%s", root_dir, self->long_name);
@@ -1566,12 +1566,12 @@ static struct map *map__new2(u64 start, struct dso *dso, enum map_type type)
1566 1566
1567struct map *map_groups__new_module(struct map_groups *self, u64 start, 1567struct map *map_groups__new_module(struct map_groups *self, u64 start,
1568 const char *filename, 1568 const char *filename,
1569 struct kernel_info *kerninfo) 1569 struct machine *machine)
1570{ 1570{
1571 struct map *map; 1571 struct map *map;
1572 struct dso *dso; 1572 struct dso *dso;
1573 1573
1574 dso = __dsos__findnew(&kerninfo->dsos__kernel, filename); 1574 dso = __dsos__findnew(&machine->kernel_dsos, filename);
1575 if (dso == NULL) 1575 if (dso == NULL)
1576 return NULL; 1576 return NULL;
1577 1577
@@ -1579,7 +1579,7 @@ struct map *map_groups__new_module(struct map_groups *self, u64 start,
1579 if (map == NULL) 1579 if (map == NULL)
1580 return NULL; 1580 return NULL;
1581 1581
1582 if (is_host_kernel(kerninfo)) 1582 if (machine__is_host(machine))
1583 dso->origin = DSO__ORIG_KMODULE; 1583 dso->origin = DSO__ORIG_KMODULE;
1584 else 1584 else
1585 dso->origin = DSO__ORIG_GUEST_KMODULE; 1585 dso->origin = DSO__ORIG_GUEST_KMODULE;
@@ -1587,7 +1587,7 @@ struct map *map_groups__new_module(struct map_groups *self, u64 start,
1587 return map; 1587 return map;
1588} 1588}
1589 1589
1590static int map_groups__create_modules(struct kernel_info *kerninfo) 1590static int map_groups__create_modules(struct machine *machine)
1591{ 1591{
1592 char *line = NULL; 1592 char *line = NULL;
1593 size_t n; 1593 size_t n;
@@ -1597,10 +1597,10 @@ static int map_groups__create_modules(struct kernel_info *kerninfo)
1597 const char *modules; 1597 const char *modules;
1598 char path[PATH_MAX]; 1598 char path[PATH_MAX];
1599 1599
1600 if (is_default_guest(kerninfo)) 1600 if (machine__is_default_guest(machine))
1601 modules = symbol_conf.default_guest_modules; 1601 modules = symbol_conf.default_guest_modules;
1602 else { 1602 else {
1603 sprintf(path, "%s/proc/modules", kerninfo->root_dir); 1603 sprintf(path, "%s/proc/modules", machine->root_dir);
1604 modules = path; 1604 modules = path;
1605 } 1605 }
1606 1606
@@ -1608,7 +1608,7 @@ static int map_groups__create_modules(struct kernel_info *kerninfo)
1608 if (file == NULL) 1608 if (file == NULL)
1609 return -1; 1609 return -1;
1610 1610
1611 root_dir = kerninfo->root_dir; 1611 root_dir = machine->root_dir;
1612 1612
1613 while (!feof(file)) { 1613 while (!feof(file)) {
1614 char name[PATH_MAX]; 1614 char name[PATH_MAX];
@@ -1638,8 +1638,8 @@ static int map_groups__create_modules(struct kernel_info *kerninfo)
1638 *sep = '\0'; 1638 *sep = '\0';
1639 1639
1640 snprintf(name, sizeof(name), "[%s]", line); 1640 snprintf(name, sizeof(name), "[%s]", line);
1641 map = map_groups__new_module(&kerninfo->kmaps, 1641 map = map_groups__new_module(&machine->kmaps, start,
1642 start, name, kerninfo); 1642 name, machine);
1643 if (map == NULL) 1643 if (map == NULL)
1644 goto out_delete_line; 1644 goto out_delete_line;
1645 dso__kernel_module_get_build_id(map->dso, root_dir); 1645 dso__kernel_module_get_build_id(map->dso, root_dir);
@@ -1648,7 +1648,7 @@ static int map_groups__create_modules(struct kernel_info *kerninfo)
1648 free(line); 1648 free(line);
1649 fclose(file); 1649 fclose(file);
1650 1650
1651 return map_groups__set_modules_path(&kerninfo->kmaps, root_dir); 1651 return map_groups__set_modules_path(&machine->kmaps, root_dir);
1652 1652
1653out_delete_line: 1653out_delete_line:
1654 free(line); 1654 free(line);
@@ -1820,16 +1820,16 @@ static int dso__load_guest_kernel_sym(struct dso *self, struct map *map,
1820{ 1820{
1821 int err; 1821 int err;
1822 const char *kallsyms_filename = NULL; 1822 const char *kallsyms_filename = NULL;
1823 struct kernel_info *kerninfo; 1823 struct machine *machine;
1824 char path[PATH_MAX]; 1824 char path[PATH_MAX];
1825 1825
1826 if (!map->groups) { 1826 if (!map->groups) {
1827 pr_debug("Guest kernel map hasn't the point to groups\n"); 1827 pr_debug("Guest kernel map hasn't the point to groups\n");
1828 return -1; 1828 return -1;
1829 } 1829 }
1830 kerninfo = map->groups->this_kerninfo; 1830 machine = map->groups->machine;
1831 1831
1832 if (is_default_guest(kerninfo)) { 1832 if (machine__is_default_guest(machine)) {
1833 /* 1833 /*
1834 * if the user specified a vmlinux filename, use it and only 1834 * if the user specified a vmlinux filename, use it and only
1835 * it, reporting errors to the user if it cannot be used. 1835 * it, reporting errors to the user if it cannot be used.
@@ -1845,7 +1845,7 @@ static int dso__load_guest_kernel_sym(struct dso *self, struct map *map,
1845 if (!kallsyms_filename) 1845 if (!kallsyms_filename)
1846 return -1; 1846 return -1;
1847 } else { 1847 } else {
1848 sprintf(path, "%s/proc/kallsyms", kerninfo->root_dir); 1848 sprintf(path, "%s/proc/kallsyms", machine->root_dir);
1849 kallsyms_filename = path; 1849 kallsyms_filename = path;
1850 } 1850 }
1851 1851
@@ -1856,9 +1856,8 @@ static int dso__load_guest_kernel_sym(struct dso *self, struct map *map,
1856out_try_fixup: 1856out_try_fixup:
1857 if (err > 0) { 1857 if (err > 0) {
1858 if (kallsyms_filename != NULL) { 1858 if (kallsyms_filename != NULL) {
1859 kern_mmap_name(kerninfo, path); 1859 machine__mmap_name(machine, path);
1860 dso__set_long_name(self, 1860 dso__set_long_name(self, strdup(path));
1861 strdup(path));
1862 } 1861 }
1863 map__fixup_start(map); 1862 map__fixup_start(map);
1864 map__fixup_end(map); 1863 map__fixup_end(map);
@@ -1908,15 +1907,14 @@ static void __dsos__fprintf(struct list_head *head, FILE *fp)
1908 } 1907 }
1909} 1908}
1910 1909
1911void dsos__fprintf(struct rb_root *kerninfo_root, FILE *fp) 1910void dsos__fprintf(struct rb_root *machines, FILE *fp)
1912{ 1911{
1913 struct rb_node *nd; 1912 struct rb_node *nd;
1914 1913
1915 for (nd = rb_first(kerninfo_root); nd; nd = rb_next(nd)) { 1914 for (nd = rb_first(machines); nd; nd = rb_next(nd)) {
1916 struct kernel_info *pos = rb_entry(nd, struct kernel_info, 1915 struct machine *pos = rb_entry(nd, struct machine, rb_node);
1917 rb_node); 1916 __dsos__fprintf(&pos->kernel_dsos, fp);
1918 __dsos__fprintf(&pos->dsos__kernel, fp); 1917 __dsos__fprintf(&pos->user_dsos, fp);
1919 __dsos__fprintf(&pos->dsos__user, fp);
1920 } 1918 }
1921} 1919}
1922 1920
@@ -1935,19 +1933,15 @@ static size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp,
1935 return ret; 1933 return ret;
1936} 1934}
1937 1935
1938size_t dsos__fprintf_buildid(struct rb_root *kerninfo_root, 1936size_t dsos__fprintf_buildid(struct rb_root *machines, FILE *fp, bool with_hits)
1939 FILE *fp, bool with_hits)
1940{ 1937{
1941 struct rb_node *nd; 1938 struct rb_node *nd;
1942 size_t ret = 0; 1939 size_t ret = 0;
1943 1940
1944 for (nd = rb_first(kerninfo_root); nd; nd = rb_next(nd)) { 1941 for (nd = rb_first(machines); nd; nd = rb_next(nd)) {
1945 struct kernel_info *pos = rb_entry(nd, struct kernel_info, 1942 struct machine *pos = rb_entry(nd, struct machine, rb_node);
1946 rb_node); 1943 ret += __dsos__fprintf_buildid(&pos->kernel_dsos, fp, with_hits);
1947 ret += __dsos__fprintf_buildid(&pos->dsos__kernel, 1944 ret += __dsos__fprintf_buildid(&pos->user_dsos, fp, with_hits);
1948 fp, with_hits);
1949 ret += __dsos__fprintf_buildid(&pos->dsos__user,
1950 fp, with_hits);
1951 } 1945 }
1952 return ret; 1946 return ret;
1953} 1947}
@@ -1964,14 +1958,12 @@ struct dso *dso__new_kernel(const char *name)
1964 return self; 1958 return self;
1965} 1959}
1966 1960
1967static struct dso *dso__new_guest_kernel(struct kernel_info *kerninfo, 1961static struct dso *dso__new_guest_kernel(struct machine *machine,
1968 const char *name) 1962 const char *name)
1969{ 1963{
1970 char buff[PATH_MAX]; 1964 char buff[PATH_MAX];
1971 struct dso *self; 1965 struct dso *self = dso__new(name ?: machine__mmap_name(machine, buff));
1972 1966
1973 kern_mmap_name(kerninfo, buff);
1974 self = dso__new(name ?: buff);
1975 if (self != NULL) { 1967 if (self != NULL) {
1976 dso__set_short_name(self, "[guest.kernel]"); 1968 dso__set_short_name(self, "[guest.kernel]");
1977 self->kernel = DSO_TYPE_GUEST_KERNEL; 1969 self->kernel = DSO_TYPE_GUEST_KERNEL;
@@ -1980,36 +1972,35 @@ static struct dso *dso__new_guest_kernel(struct kernel_info *kerninfo,
1980 return self; 1972 return self;
1981} 1973}
1982 1974
1983void dso__read_running_kernel_build_id(struct dso *self, 1975void dso__read_running_kernel_build_id(struct dso *self, struct machine *machine)
1984 struct kernel_info *kerninfo)
1985{ 1976{
1986 char path[PATH_MAX]; 1977 char path[PATH_MAX];
1987 1978
1988 if (is_default_guest(kerninfo)) 1979 if (machine__is_default_guest(machine))
1989 return; 1980 return;
1990 sprintf(path, "%s/sys/kernel/notes", kerninfo->root_dir); 1981 sprintf(path, "%s/sys/kernel/notes", machine->root_dir);
1991 if (sysfs__read_build_id(path, self->build_id, 1982 if (sysfs__read_build_id(path, self->build_id,
1992 sizeof(self->build_id)) == 0) 1983 sizeof(self->build_id)) == 0)
1993 self->has_build_id = true; 1984 self->has_build_id = true;
1994} 1985}
1995 1986
1996static struct dso *dsos__create_kernel(struct kernel_info *kerninfo) 1987static struct dso *dsos__create_kernel(struct machine *machine)
1997{ 1988{
1998 const char *vmlinux_name = NULL; 1989 const char *vmlinux_name = NULL;
1999 struct dso *kernel; 1990 struct dso *kernel;
2000 1991
2001 if (is_host_kernel(kerninfo)) { 1992 if (machine__is_host(machine)) {
2002 vmlinux_name = symbol_conf.vmlinux_name; 1993 vmlinux_name = symbol_conf.vmlinux_name;
2003 kernel = dso__new_kernel(vmlinux_name); 1994 kernel = dso__new_kernel(vmlinux_name);
2004 } else { 1995 } else {
2005 if (is_default_guest(kerninfo)) 1996 if (machine__is_default_guest(machine))
2006 vmlinux_name = symbol_conf.default_guest_vmlinux_name; 1997 vmlinux_name = symbol_conf.default_guest_vmlinux_name;
2007 kernel = dso__new_guest_kernel(kerninfo, vmlinux_name); 1998 kernel = dso__new_guest_kernel(machine, vmlinux_name);
2008 } 1999 }
2009 2000
2010 if (kernel != NULL) { 2001 if (kernel != NULL) {
2011 dso__read_running_kernel_build_id(kernel, kerninfo); 2002 dso__read_running_kernel_build_id(kernel, machine);
2012 dsos__add(&kerninfo->dsos__kernel, kernel); 2003 dsos__add(&machine->kernel_dsos, kernel);
2013 } 2004 }
2014 return kernel; 2005 return kernel;
2015} 2006}
@@ -2154,29 +2145,28 @@ out_free_comm_list:
2154 return -1; 2145 return -1;
2155} 2146}
2156 2147
2157int map_groups__create_kernel_maps(struct rb_root *kerninfo_root, pid_t pid) 2148int map_groups__create_kernel_maps(struct rb_root *machines, pid_t pid)
2158{ 2149{
2159 struct kernel_info *kerninfo;
2160 struct dso *kernel; 2150 struct dso *kernel;
2151 struct machine *machine = machines__findnew(machines, pid);
2161 2152
2162 kerninfo = kerninfo__findnew(kerninfo_root, pid); 2153 if (machine == NULL)
2163 if (kerninfo == NULL)
2164 return -1; 2154 return -1;
2165 kernel = dsos__create_kernel(kerninfo); 2155 kernel = dsos__create_kernel(machine);
2166 if (kernel == NULL) 2156 if (kernel == NULL)
2167 return -1; 2157 return -1;
2168 2158
2169 if (__map_groups__create_kernel_maps(&kerninfo->kmaps, 2159 if (__map_groups__create_kernel_maps(&machine->kmaps,
2170 kerninfo->vmlinux_maps, kernel) < 0) 2160 machine->vmlinux_maps, kernel) < 0)
2171 return -1; 2161 return -1;
2172 2162
2173 if (symbol_conf.use_modules && 2163 if (symbol_conf.use_modules &&
2174 map_groups__create_modules(kerninfo) < 0) 2164 map_groups__create_modules(machine) < 0)
2175 pr_debug("Problems creating module maps, continuing anyway...\n"); 2165 pr_debug("Problems creating module maps, continuing anyway...\n");
2176 /* 2166 /*
2177 * Now that we have all the maps created, just set the ->end of them: 2167 * Now that we have all the maps created, just set the ->end of them:
2178 */ 2168 */
2179 map_groups__fixup_end(&kerninfo->kmaps); 2169 map_groups__fixup_end(&machine->kmaps);
2180 return 0; 2170 return 0;
2181} 2171}
2182 2172
@@ -2223,7 +2213,7 @@ char *strxfrchar(char *s, char from, char to)
2223 return s; 2213 return s;
2224} 2214}
2225 2215
2226int map_groups__create_guest_kernel_maps(struct rb_root *kerninfo_root) 2216int map_groups__create_guest_kernel_maps(struct rb_root *machines)
2227{ 2217{
2228 int ret = 0; 2218 int ret = 0;
2229 struct dirent **namelist = NULL; 2219 struct dirent **namelist = NULL;
@@ -2234,8 +2224,7 @@ int map_groups__create_guest_kernel_maps(struct rb_root *kerninfo_root)
2234 if (symbol_conf.default_guest_vmlinux_name || 2224 if (symbol_conf.default_guest_vmlinux_name ||
2235 symbol_conf.default_guest_modules || 2225 symbol_conf.default_guest_modules ||
2236 symbol_conf.default_guest_kallsyms) { 2226 symbol_conf.default_guest_kallsyms) {
2237 map_groups__create_kernel_maps(kerninfo_root, 2227 map_groups__create_kernel_maps(machines, DEFAULT_GUEST_KERNEL_ID);
2238 DEFAULT_GUEST_KERNEL_ID);
2239 } 2228 }
2240 2229
2241 if (symbol_conf.guestmount) { 2230 if (symbol_conf.guestmount) {
@@ -2256,8 +2245,7 @@ int map_groups__create_guest_kernel_maps(struct rb_root *kerninfo_root)
2256 pr_debug("Can't access file %s\n", path); 2245 pr_debug("Can't access file %s\n", path);
2257 goto failure; 2246 goto failure;
2258 } 2247 }
2259 map_groups__create_kernel_maps(kerninfo_root, 2248 map_groups__create_kernel_maps(machines, pid);
2260 pid);
2261 } 2249 }
2262failure: 2250failure:
2263 free(namelist); 2251 free(namelist);
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 478f5ab37787..ed885b06a023 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -186,8 +186,7 @@ enum dso_origin {
186char dso__symtab_origin(const struct dso *self); 186char dso__symtab_origin(const struct dso *self);
187void dso__set_long_name(struct dso *self, char *name); 187void dso__set_long_name(struct dso *self, char *name);
188void dso__set_build_id(struct dso *self, void *build_id); 188void dso__set_build_id(struct dso *self, void *build_id);
189void dso__read_running_kernel_build_id(struct dso *self, 189void dso__read_running_kernel_build_id(struct dso *self, struct machine *machine);
190 struct kernel_info *kerninfo);
191struct symbol *dso__find_symbol(struct dso *self, enum map_type type, u64 addr); 190struct symbol *dso__find_symbol(struct dso *self, enum map_type type, u64 addr);
192struct symbol *dso__find_symbol_by_name(struct dso *self, enum map_type type, 191struct symbol *dso__find_symbol_by_name(struct dso *self, enum map_type type,
193 const char *name); 192 const char *name);