aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2012-12-18 17:15:48 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-01-24 14:40:12 -0500
commit876650e6c3209861a8949111140d805b3440951f (patch)
tree92923adf71a21512f20889c49ace7ed42b139f29 /tools
parent28a6b6aa54878a6a239e901698b3fc111bbcc54f (diff)
perf machine: Introduce struct machines
That consolidates the grouping of host + guests, isolating a bit more of functionality now centered on 'perf_session' that can be used independently in tools that don't need a 'perf_session' instance, but needs to have all the thread/map/symbol machinery. Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-c700rsiphpmzv8klogojpfut@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/builtin-record.c4
-rw-r--r--tools/perf/builtin-report.c2
-rw-r--r--tools/perf/builtin-top.c4
-rw-r--r--tools/perf/tests/hists_link.c17
-rw-r--r--tools/perf/util/header.c12
-rw-r--r--tools/perf/util/machine.c64
-rw-r--r--tools/perf/util/machine.h32
-rw-r--r--tools/perf/util/session.c30
-rw-r--r--tools/perf/util/session.h11
9 files changed, 95 insertions, 81 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 69e28950a328..a0b2427b509d 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -571,8 +571,8 @@ static int __cmd_record(struct perf_record *rec, int argc, const char **argv)
571 "Check /proc/modules permission or run as root.\n"); 571 "Check /proc/modules permission or run as root.\n");
572 572
573 if (perf_guest) { 573 if (perf_guest) {
574 machines__process(&session->machines, 574 machines__process_guests(&session->machines,
575 perf_event__synthesize_guest_os, tool); 575 perf_event__synthesize_guest_os, tool);
576 } 576 }
577 577
578 if (!opts->target.system_wide) 578 if (!opts->target.system_wide)
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 5134acf1c39a..13cdf61c4f82 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -372,7 +372,7 @@ static int __cmd_report(struct perf_report *rep)
372 if (ret) 372 if (ret)
373 goto out_delete; 373 goto out_delete;
374 374
375 kernel_map = session->host_machine.vmlinux_maps[MAP__FUNCTION]; 375 kernel_map = session->machines.host.vmlinux_maps[MAP__FUNCTION];
376 kernel_kmap = map__kmap(kernel_map); 376 kernel_kmap = map__kmap(kernel_map);
377 if (kernel_map == NULL || 377 if (kernel_map == NULL ||
378 (kernel_map->dso->hit && 378 (kernel_map->dso->hit &&
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 996b10c702ba..e0ecebdde3fe 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -966,10 +966,10 @@ static int __cmd_top(struct perf_top *top)
966 if (perf_target__has_task(&opts->target)) 966 if (perf_target__has_task(&opts->target))
967 perf_event__synthesize_thread_map(&top->tool, top->evlist->threads, 967 perf_event__synthesize_thread_map(&top->tool, top->evlist->threads,
968 perf_event__process, 968 perf_event__process,
969 &top->session->host_machine); 969 &top->session->machines.host);
970 else 970 else
971 perf_event__synthesize_threads(&top->tool, perf_event__process, 971 perf_event__synthesize_threads(&top->tool, perf_event__process,
972 &top->session->host_machine); 972 &top->session->machines.host);
973 perf_top__start_counters(top); 973 perf_top__start_counters(top);
974 top->session->evlist = top->evlist; 974 top->session->evlist = top->evlist;
975 perf_session__set_id_hdr_size(top->session); 975 perf_session__set_id_hdr_size(top->session);
diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c
index 0f1aae3b8a99..27860a082381 100644
--- a/tools/perf/tests/hists_link.c
+++ b/tools/perf/tests/hists_link.c
@@ -75,13 +75,11 @@ static struct {
75 { "[kernel]", kernel_syms, ARRAY_SIZE(kernel_syms) }, 75 { "[kernel]", kernel_syms, ARRAY_SIZE(kernel_syms) },
76}; 76};
77 77
78static struct machine *setup_fake_machine(void) 78static struct machine *setup_fake_machine(struct machines *machines)
79{ 79{
80 struct rb_root machine_root = RB_ROOT; 80 struct machine *machine = machines__find(machines, HOST_KERNEL_ID);
81 struct machine *machine;
82 size_t i; 81 size_t i;
83 82
84 machine = machines__findnew(&machine_root, HOST_KERNEL_ID);
85 if (machine == NULL) { 83 if (machine == NULL) {
86 pr_debug("Not enough memory for machine setup\n"); 84 pr_debug("Not enough memory for machine setup\n");
87 return NULL; 85 return NULL;
@@ -435,6 +433,7 @@ static void print_hists(struct hists *hists)
435int test__hists_link(void) 433int test__hists_link(void)
436{ 434{
437 int err = -1; 435 int err = -1;
436 struct machines machines;
438 struct machine *machine = NULL; 437 struct machine *machine = NULL;
439 struct perf_evsel *evsel, *first; 438 struct perf_evsel *evsel, *first;
440 struct perf_evlist *evlist = perf_evlist__new(NULL, NULL); 439 struct perf_evlist *evlist = perf_evlist__new(NULL, NULL);
@@ -452,8 +451,10 @@ int test__hists_link(void)
452 /* default sort order (comm,dso,sym) will be used */ 451 /* default sort order (comm,dso,sym) will be used */
453 setup_sorting(NULL, NULL); 452 setup_sorting(NULL, NULL);
454 453
454 machines__init(&machines);
455
455 /* setup threads/dso/map/symbols also */ 456 /* setup threads/dso/map/symbols also */
456 machine = setup_fake_machine(); 457 machine = setup_fake_machine(&machines);
457 if (!machine) 458 if (!machine)
458 goto out; 459 goto out;
459 460
@@ -492,11 +493,7 @@ int test__hists_link(void)
492out: 493out:
493 /* tear down everything */ 494 /* tear down everything */
494 perf_evlist__delete(evlist); 495 perf_evlist__delete(evlist);
495 496 machines__exit(&machines);
496 if (machine) {
497 machine__delete_threads(machine);
498 machine__delete(machine);
499 }
500 497
501 return err; 498 return err;
502} 499}
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index bb578d2d10f9..fccd69dbbbb9 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -287,12 +287,12 @@ static int dsos__write_buildid_table(struct perf_header *header, int fd)
287 struct perf_session *session = container_of(header, 287 struct perf_session *session = container_of(header,
288 struct perf_session, header); 288 struct perf_session, header);
289 struct rb_node *nd; 289 struct rb_node *nd;
290 int err = machine__write_buildid_table(&session->host_machine, fd); 290 int err = machine__write_buildid_table(&session->machines.host, fd);
291 291
292 if (err) 292 if (err)
293 return err; 293 return err;
294 294
295 for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) { 295 for (nd = rb_first(&session->machines.guests); nd; nd = rb_next(nd)) {
296 struct machine *pos = rb_entry(nd, struct machine, rb_node); 296 struct machine *pos = rb_entry(nd, struct machine, rb_node);
297 err = machine__write_buildid_table(pos, fd); 297 err = machine__write_buildid_table(pos, fd);
298 if (err) 298 if (err)
@@ -448,9 +448,9 @@ static int perf_session__cache_build_ids(struct perf_session *session)
448 if (mkdir(debugdir, 0755) != 0 && errno != EEXIST) 448 if (mkdir(debugdir, 0755) != 0 && errno != EEXIST)
449 return -1; 449 return -1;
450 450
451 ret = machine__cache_build_ids(&session->host_machine, debugdir); 451 ret = machine__cache_build_ids(&session->machines.host, debugdir);
452 452
453 for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) { 453 for (nd = rb_first(&session->machines.guests); nd; nd = rb_next(nd)) {
454 struct machine *pos = rb_entry(nd, struct machine, rb_node); 454 struct machine *pos = rb_entry(nd, struct machine, rb_node);
455 ret |= machine__cache_build_ids(pos, debugdir); 455 ret |= machine__cache_build_ids(pos, debugdir);
456 } 456 }
@@ -467,9 +467,9 @@ static bool machine__read_build_ids(struct machine *machine, bool with_hits)
467static bool perf_session__read_build_ids(struct perf_session *session, bool with_hits) 467static bool perf_session__read_build_ids(struct perf_session *session, bool with_hits)
468{ 468{
469 struct rb_node *nd; 469 struct rb_node *nd;
470 bool ret = machine__read_build_ids(&session->host_machine, with_hits); 470 bool ret = machine__read_build_ids(&session->machines.host, with_hits);
471 471
472 for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) { 472 for (nd = rb_first(&session->machines.guests); nd; nd = rb_next(nd)) {
473 struct machine *pos = rb_entry(nd, struct machine, rb_node); 473 struct machine *pos = rb_entry(nd, struct machine, rb_node);
474 ret |= machine__read_build_ids(pos, with_hits); 474 ret |= machine__read_build_ids(pos, with_hits);
475 } 475 }
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 71fa90391fe4..efdb38e65a92 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -91,10 +91,22 @@ void machine__delete(struct machine *machine)
91 free(machine); 91 free(machine);
92} 92}
93 93
94struct machine *machines__add(struct rb_root *machines, pid_t pid, 94void machines__init(struct machines *machines)
95{
96 machine__init(&machines->host, "", HOST_KERNEL_ID);
97 machines->guests = RB_ROOT;
98}
99
100void machines__exit(struct machines *machines)
101{
102 machine__exit(&machines->host);
103 /* XXX exit guest */
104}
105
106struct machine *machines__add(struct machines *machines, pid_t pid,
95 const char *root_dir) 107 const char *root_dir)
96{ 108{
97 struct rb_node **p = &machines->rb_node; 109 struct rb_node **p = &machines->guests.rb_node;
98 struct rb_node *parent = NULL; 110 struct rb_node *parent = NULL;
99 struct machine *pos, *machine = malloc(sizeof(*machine)); 111 struct machine *pos, *machine = malloc(sizeof(*machine));
100 112
@@ -116,18 +128,21 @@ struct machine *machines__add(struct rb_root *machines, pid_t pid,
116 } 128 }
117 129
118 rb_link_node(&machine->rb_node, parent, p); 130 rb_link_node(&machine->rb_node, parent, p);
119 rb_insert_color(&machine->rb_node, machines); 131 rb_insert_color(&machine->rb_node, &machines->guests);
120 132
121 return machine; 133 return machine;
122} 134}
123 135
124struct machine *machines__find(struct rb_root *machines, pid_t pid) 136struct machine *machines__find(struct machines *machines, pid_t pid)
125{ 137{
126 struct rb_node **p = &machines->rb_node; 138 struct rb_node **p = &machines->guests.rb_node;
127 struct rb_node *parent = NULL; 139 struct rb_node *parent = NULL;
128 struct machine *machine; 140 struct machine *machine;
129 struct machine *default_machine = NULL; 141 struct machine *default_machine = NULL;
130 142
143 if (pid == HOST_KERNEL_ID)
144 return &machines->host;
145
131 while (*p != NULL) { 146 while (*p != NULL) {
132 parent = *p; 147 parent = *p;
133 machine = rb_entry(parent, struct machine, rb_node); 148 machine = rb_entry(parent, struct machine, rb_node);
@@ -144,7 +159,7 @@ struct machine *machines__find(struct rb_root *machines, pid_t pid)
144 return default_machine; 159 return default_machine;
145} 160}
146 161
147struct machine *machines__findnew(struct rb_root *machines, pid_t pid) 162struct machine *machines__findnew(struct machines *machines, pid_t pid)
148{ 163{
149 char path[PATH_MAX]; 164 char path[PATH_MAX];
150 const char *root_dir = ""; 165 const char *root_dir = "";
@@ -178,12 +193,12 @@ out:
178 return machine; 193 return machine;
179} 194}
180 195
181void machines__process(struct rb_root *machines, 196void machines__process_guests(struct machines *machines,
182 machine__process_t process, void *data) 197 machine__process_t process, void *data)
183{ 198{
184 struct rb_node *nd; 199 struct rb_node *nd;
185 200
186 for (nd = rb_first(machines); nd; nd = rb_next(nd)) { 201 for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) {
187 struct machine *pos = rb_entry(nd, struct machine, rb_node); 202 struct machine *pos = rb_entry(nd, struct machine, rb_node);
188 process(pos, data); 203 process(pos, data);
189 } 204 }
@@ -203,12 +218,14 @@ char *machine__mmap_name(struct machine *machine, char *bf, size_t size)
203 return bf; 218 return bf;
204} 219}
205 220
206void machines__set_id_hdr_size(struct rb_root *machines, u16 id_hdr_size) 221void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size)
207{ 222{
208 struct rb_node *node; 223 struct rb_node *node;
209 struct machine *machine; 224 struct machine *machine;
210 225
211 for (node = rb_first(machines); node; node = rb_next(node)) { 226 machines->host.id_hdr_size = id_hdr_size;
227
228 for (node = rb_first(&machines->guests); node; node = rb_next(node)) {
212 machine = rb_entry(node, struct machine, rb_node); 229 machine = rb_entry(node, struct machine, rb_node);
213 machine->id_hdr_size = id_hdr_size; 230 machine->id_hdr_size = id_hdr_size;
214 } 231 }
@@ -313,12 +330,13 @@ struct map *machine__new_module(struct machine *machine, u64 start,
313 return map; 330 return map;
314} 331}
315 332
316size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp) 333size_t machines__fprintf_dsos(struct machines *machines, FILE *fp)
317{ 334{
318 struct rb_node *nd; 335 struct rb_node *nd;
319 size_t ret = 0; 336 size_t ret = __dsos__fprintf(&machines->host.kernel_dsos, fp) +
337 __dsos__fprintf(&machines->host.user_dsos, fp);
320 338
321 for (nd = rb_first(machines); nd; nd = rb_next(nd)) { 339 for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) {
322 struct machine *pos = rb_entry(nd, struct machine, rb_node); 340 struct machine *pos = rb_entry(nd, struct machine, rb_node);
323 ret += __dsos__fprintf(&pos->kernel_dsos, fp); 341 ret += __dsos__fprintf(&pos->kernel_dsos, fp);
324 ret += __dsos__fprintf(&pos->user_dsos, fp); 342 ret += __dsos__fprintf(&pos->user_dsos, fp);
@@ -334,13 +352,13 @@ size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
334 __dsos__fprintf_buildid(&machine->user_dsos, fp, skip, parm); 352 __dsos__fprintf_buildid(&machine->user_dsos, fp, skip, parm);
335} 353}
336 354
337size_t machines__fprintf_dsos_buildid(struct rb_root *machines, FILE *fp, 355size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
338 bool (skip)(struct dso *dso, int parm), int parm) 356 bool (skip)(struct dso *dso, int parm), int parm)
339{ 357{
340 struct rb_node *nd; 358 struct rb_node *nd;
341 size_t ret = 0; 359 size_t ret = machine__fprintf_dsos_buildid(&machines->host, fp, skip, parm);
342 360
343 for (nd = rb_first(machines); nd; nd = rb_next(nd)) { 361 for (nd = rb_first(&machines->guests); nd; nd = rb_next(nd)) {
344 struct machine *pos = rb_entry(nd, struct machine, rb_node); 362 struct machine *pos = rb_entry(nd, struct machine, rb_node);
345 ret += machine__fprintf_dsos_buildid(pos, fp, skip, parm); 363 ret += machine__fprintf_dsos_buildid(pos, fp, skip, parm);
346 } 364 }
@@ -511,7 +529,7 @@ void machine__destroy_kernel_maps(struct machine *machine)
511 } 529 }
512} 530}
513 531
514int machines__create_guest_kernel_maps(struct rb_root *machines) 532int machines__create_guest_kernel_maps(struct machines *machines)
515{ 533{
516 int ret = 0; 534 int ret = 0;
517 struct dirent **namelist = NULL; 535 struct dirent **namelist = NULL;
@@ -560,20 +578,22 @@ failure:
560 return ret; 578 return ret;
561} 579}
562 580
563void machines__destroy_guest_kernel_maps(struct rb_root *machines) 581void machines__destroy_kernel_maps(struct machines *machines)
564{ 582{
565 struct rb_node *next = rb_first(machines); 583 struct rb_node *next = rb_first(&machines->guests);
584
585 machine__destroy_kernel_maps(&machines->host);
566 586
567 while (next) { 587 while (next) {
568 struct machine *pos = rb_entry(next, struct machine, rb_node); 588 struct machine *pos = rb_entry(next, struct machine, rb_node);
569 589
570 next = rb_next(&pos->rb_node); 590 next = rb_next(&pos->rb_node);
571 rb_erase(&pos->rb_node, machines); 591 rb_erase(&pos->rb_node, &machines->guests);
572 machine__delete(pos); 592 machine__delete(pos);
573 } 593 }
574} 594}
575 595
576int machines__create_kernel_maps(struct rb_root *machines, pid_t pid) 596int machines__create_kernel_maps(struct machines *machines, pid_t pid)
577{ 597{
578 struct machine *machine = machines__findnew(machines, pid); 598 struct machine *machine = machines__findnew(machines, pid);
579 599
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h
index e11236878ec1..5ac5892f2326 100644
--- a/tools/perf/util/machine.h
+++ b/tools/perf/util/machine.h
@@ -47,16 +47,24 @@ int machine__process_event(struct machine *machine, union perf_event *event);
47 47
48typedef void (*machine__process_t)(struct machine *machine, void *data); 48typedef void (*machine__process_t)(struct machine *machine, void *data);
49 49
50void machines__process(struct rb_root *machines, 50struct machines {
51 machine__process_t process, void *data); 51 struct machine host;
52 struct rb_root guests;
53};
54
55void machines__init(struct machines *machines);
56void machines__exit(struct machines *machines);
57
58void machines__process_guests(struct machines *machines,
59 machine__process_t process, void *data);
52 60
53struct machine *machines__add(struct rb_root *machines, pid_t pid, 61struct machine *machines__add(struct machines *machines, pid_t pid,
54 const char *root_dir); 62 const char *root_dir);
55struct machine *machines__find_host(struct rb_root *machines); 63struct machine *machines__find_host(struct machines *machines);
56struct machine *machines__find(struct rb_root *machines, pid_t pid); 64struct machine *machines__find(struct machines *machines, pid_t pid);
57struct machine *machines__findnew(struct rb_root *machines, pid_t pid); 65struct machine *machines__findnew(struct machines *machines, pid_t pid);
58 66
59void machines__set_id_hdr_size(struct rb_root *machines, u16 id_hdr_size); 67void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size);
60char *machine__mmap_name(struct machine *machine, char *bf, size_t size); 68char *machine__mmap_name(struct machine *machine, char *bf, size_t size);
61 69
62int machine__init(struct machine *machine, const char *root_dir, pid_t pid); 70int machine__init(struct machine *machine, const char *root_dir, pid_t pid);
@@ -132,17 +140,17 @@ int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
132 140
133size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp, 141size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
134 bool (skip)(struct dso *dso, int parm), int parm); 142 bool (skip)(struct dso *dso, int parm), int parm);
135size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp); 143size_t machines__fprintf_dsos(struct machines *machines, FILE *fp);
136size_t machines__fprintf_dsos_buildid(struct rb_root *machines, FILE *fp, 144size_t machines__fprintf_dsos_buildid(struct machines *machines, FILE *fp,
137 bool (skip)(struct dso *dso, int parm), int parm); 145 bool (skip)(struct dso *dso, int parm), int parm);
138 146
139void machine__destroy_kernel_maps(struct machine *machine); 147void machine__destroy_kernel_maps(struct machine *machine);
140int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel); 148int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel);
141int machine__create_kernel_maps(struct machine *machine); 149int machine__create_kernel_maps(struct machine *machine);
142 150
143int machines__create_kernel_maps(struct rb_root *machines, pid_t pid); 151int machines__create_kernel_maps(struct machines *machines, pid_t pid);
144int machines__create_guest_kernel_maps(struct rb_root *machines); 152int machines__create_guest_kernel_maps(struct machines *machines);
145void machines__destroy_guest_kernel_maps(struct rb_root *machines); 153void machines__destroy_kernel_maps(struct machines *machines);
146 154
147size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp); 155size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
148 156
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index b0bcc328d1fb..046b057c8f7f 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -86,13 +86,12 @@ void perf_session__set_id_hdr_size(struct perf_session *session)
86{ 86{
87 u16 id_hdr_size = perf_evlist__id_hdr_size(session->evlist); 87 u16 id_hdr_size = perf_evlist__id_hdr_size(session->evlist);
88 88
89 session->host_machine.id_hdr_size = id_hdr_size;
90 machines__set_id_hdr_size(&session->machines, id_hdr_size); 89 machines__set_id_hdr_size(&session->machines, id_hdr_size);
91} 90}
92 91
93int perf_session__create_kernel_maps(struct perf_session *self) 92int perf_session__create_kernel_maps(struct perf_session *self)
94{ 93{
95 int ret = machine__create_kernel_maps(&self->host_machine); 94 int ret = machine__create_kernel_maps(&self->machines.host);
96 95
97 if (ret >= 0) 96 if (ret >= 0)
98 ret = machines__create_guest_kernel_maps(&self->machines); 97 ret = machines__create_guest_kernel_maps(&self->machines);
@@ -101,8 +100,7 @@ int perf_session__create_kernel_maps(struct perf_session *self)
101 100
102static void perf_session__destroy_kernel_maps(struct perf_session *self) 101static void perf_session__destroy_kernel_maps(struct perf_session *self)
103{ 102{
104 machine__destroy_kernel_maps(&self->host_machine); 103 machines__destroy_kernel_maps(&self->machines);
105 machines__destroy_guest_kernel_maps(&self->machines);
106} 104}
107 105
108struct perf_session *perf_session__new(const char *filename, int mode, 106struct perf_session *perf_session__new(const char *filename, int mode,
@@ -127,12 +125,11 @@ struct perf_session *perf_session__new(const char *filename, int mode,
127 goto out; 125 goto out;
128 126
129 memcpy(self->filename, filename, len); 127 memcpy(self->filename, filename, len);
130 self->machines = RB_ROOT;
131 self->repipe = repipe; 128 self->repipe = repipe;
132 INIT_LIST_HEAD(&self->ordered_samples.samples); 129 INIT_LIST_HEAD(&self->ordered_samples.samples);
133 INIT_LIST_HEAD(&self->ordered_samples.sample_cache); 130 INIT_LIST_HEAD(&self->ordered_samples.sample_cache);
134 INIT_LIST_HEAD(&self->ordered_samples.to_free); 131 INIT_LIST_HEAD(&self->ordered_samples.to_free);
135 machine__init(&self->host_machine, "", HOST_KERNEL_ID); 132 machines__init(&self->machines);
136 133
137 if (mode == O_RDONLY) { 134 if (mode == O_RDONLY) {
138 if (perf_session__open(self, force) < 0) 135 if (perf_session__open(self, force) < 0)
@@ -162,12 +159,12 @@ out_delete:
162 159
163static void perf_session__delete_dead_threads(struct perf_session *session) 160static void perf_session__delete_dead_threads(struct perf_session *session)
164{ 161{
165 machine__delete_dead_threads(&session->host_machine); 162 machine__delete_dead_threads(&session->machines.host);
166} 163}
167 164
168static void perf_session__delete_threads(struct perf_session *session) 165static void perf_session__delete_threads(struct perf_session *session)
169{ 166{
170 machine__delete_threads(&session->host_machine); 167 machine__delete_threads(&session->machines.host);
171} 168}
172 169
173static void perf_session_env__delete(struct perf_session_env *env) 170static void perf_session_env__delete(struct perf_session_env *env)
@@ -192,7 +189,7 @@ void perf_session__delete(struct perf_session *self)
192 perf_session__delete_dead_threads(self); 189 perf_session__delete_dead_threads(self);
193 perf_session__delete_threads(self); 190 perf_session__delete_threads(self);
194 perf_session_env__delete(&self->header.env); 191 perf_session_env__delete(&self->header.env);
195 machine__exit(&self->host_machine); 192 machines__exit(&self->machines);
196 close(self->fd); 193 close(self->fd);
197 free(self); 194 free(self);
198 vdso__exit(); 195 vdso__exit();
@@ -998,7 +995,7 @@ void perf_event_header__bswap(struct perf_event_header *self)
998 995
999struct thread *perf_session__findnew(struct perf_session *session, pid_t pid) 996struct thread *perf_session__findnew(struct perf_session *session, pid_t pid)
1000{ 997{
1001 return machine__findnew_thread(&session->host_machine, pid); 998 return machine__findnew_thread(&session->machines.host, pid);
1002} 999}
1003 1000
1004static struct thread *perf_session__register_idle_thread(struct perf_session *self) 1001static struct thread *perf_session__register_idle_thread(struct perf_session *self)
@@ -1335,16 +1332,13 @@ int maps__set_kallsyms_ref_reloc_sym(struct map **maps,
1335 1332
1336size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp) 1333size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp)
1337{ 1334{
1338 return __dsos__fprintf(&self->host_machine.kernel_dsos, fp) + 1335 return machines__fprintf_dsos(&self->machines, fp);
1339 __dsos__fprintf(&self->host_machine.user_dsos, fp) +
1340 machines__fprintf_dsos(&self->machines, fp);
1341} 1336}
1342 1337
1343size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp, 1338size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp,
1344 bool (skip)(struct dso *dso, int parm), int parm) 1339 bool (skip)(struct dso *dso, int parm), int parm)
1345{ 1340{
1346 size_t ret = machine__fprintf_dsos_buildid(&self->host_machine, fp, skip, parm); 1341 return machines__fprintf_dsos_buildid(&self->machines, fp, skip, parm);
1347 return ret + machines__fprintf_dsos_buildid(&self->machines, fp, skip, parm);
1348} 1342}
1349 1343
1350size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp) 1344size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp)
@@ -1368,7 +1362,7 @@ size_t perf_session__fprintf(struct perf_session *session, FILE *fp)
1368 * FIXME: Here we have to actually print all the machines in this 1362 * FIXME: Here we have to actually print all the machines in this
1369 * session, not just the host... 1363 * session, not just the host...
1370 */ 1364 */
1371 return machine__fprintf(&session->host_machine, fp); 1365 return machine__fprintf(&session->machines.host, fp);
1372} 1366}
1373 1367
1374void perf_session__remove_thread(struct perf_session *session, 1368void perf_session__remove_thread(struct perf_session *session,
@@ -1377,10 +1371,10 @@ void perf_session__remove_thread(struct perf_session *session,
1377 /* 1371 /*
1378 * FIXME: This one makes no sense, we need to remove the thread from 1372 * FIXME: This one makes no sense, we need to remove the thread from
1379 * the machine it belongs to, perf_session can have many machines, so 1373 * the machine it belongs to, perf_session can have many machines, so
1380 * doing it always on ->host_machine is wrong. Fix when auditing all 1374 * doing it always on ->machines.host is wrong. Fix when auditing all
1381 * the 'perf kvm' code. 1375 * the 'perf kvm' code.
1382 */ 1376 */
1383 machine__remove_thread(&session->host_machine, th); 1377 machine__remove_thread(&session->machines.host, th);
1384} 1378}
1385 1379
1386struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session, 1380struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 57066cb867a6..de4e68716626 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -30,8 +30,7 @@ struct ordered_samples {
30struct perf_session { 30struct perf_session {
31 struct perf_header header; 31 struct perf_header header;
32 unsigned long size; 32 unsigned long size;
33 struct machine host_machine; 33 struct machines machines;
34 struct rb_root machines;
35 struct perf_evlist *evlist; 34 struct perf_evlist *evlist;
36 struct pevent *pevent; 35 struct pevent *pevent;
37 struct events_stats stats; 36 struct events_stats stats;
@@ -49,7 +48,7 @@ struct perf_tool;
49struct perf_session *perf_session__new(const char *filename, int mode, 48struct perf_session *perf_session__new(const char *filename, int mode,
50 bool force, bool repipe, 49 bool force, bool repipe,
51 struct perf_tool *tool); 50 struct perf_tool *tool);
52void perf_session__delete(struct perf_session *self); 51void perf_session__delete(struct perf_session *session);
53 52
54void perf_event_header__bswap(struct perf_event_header *self); 53void perf_event_header__bswap(struct perf_event_header *self);
55 54
@@ -78,22 +77,18 @@ void perf_session__remove_thread(struct perf_session *self, struct thread *th);
78static inline 77static inline
79struct machine *perf_session__find_host_machine(struct perf_session *self) 78struct machine *perf_session__find_host_machine(struct perf_session *self)
80{ 79{
81 return &self->host_machine; 80 return &self->machines.host;
82} 81}
83 82
84static inline 83static inline
85struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid) 84struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid)
86{ 85{
87 if (pid == HOST_KERNEL_ID)
88 return &self->host_machine;
89 return machines__find(&self->machines, pid); 86 return machines__find(&self->machines, pid);
90} 87}
91 88
92static inline 89static inline
93struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid) 90struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid)
94{ 91{
95 if (pid == HOST_KERNEL_ID)
96 return &self->host_machine;
97 return machines__findnew(&self->machines, pid); 92 return machines__findnew(&self->machines, pid);
98} 93}
99 94