aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2016-03-22 17:23:43 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-03-23 11:03:07 -0400
commit473398a21d28c089555117a8db4ea04e371dd03c (patch)
tree23aedcb836ef40362aa4bee4f625352b708fc492
parenteb9f03231b7a27999abe22d3c5f71700338630c6 (diff)
perf tools: Add cpumode to struct perf_sample
To avoid parsing event->header.misc in many locations. This will also allow setting perf.sample.{ip,cpumode} in a single place, from tracepoint fields, as needed by 'perf kvm' with PPC guests, where the guest hardware counters is not available at the host. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Hemant Kumar <hemant@linux.vnet.ibm.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> Cc: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-qp3yradhyt6q3wl895b1aat0@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/builtin-inject.c5
-rw-r--r--tools/perf/builtin-script.c7
-rw-r--r--tools/perf/builtin-top.c5
-rw-r--r--tools/perf/builtin-trace.c9
-rw-r--r--tools/perf/tests/code-reading.c5
-rw-r--r--tools/perf/tests/hists_common.c6
-rw-r--r--tools/perf/tests/hists_cumulate.c1
-rw-r--r--tools/perf/tests/hists_filter.c1
-rw-r--r--tools/perf/tests/hists_link.c1
-rw-r--r--tools/perf/tests/hists_output.c1
-rw-r--r--tools/perf/util/build-id.c3
-rw-r--r--tools/perf/util/event.c15
-rw-r--r--tools/perf/util/event.h1
-rw-r--r--tools/perf/util/evsel.c1
-rw-r--r--tools/perf/util/machine.c14
-rw-r--r--tools/perf/util/session.c5
16 files changed, 35 insertions, 45 deletions
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index b33b42c009ed..d1a2d104f2bc 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -416,9 +416,6 @@ static int perf_event__inject_buildid(struct perf_tool *tool,
416{ 416{
417 struct addr_location al; 417 struct addr_location al;
418 struct thread *thread; 418 struct thread *thread;
419 u8 cpumode;
420
421 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
422 419
423 thread = machine__findnew_thread(machine, sample->pid, sample->tid); 420 thread = machine__findnew_thread(machine, sample->pid, sample->tid);
424 if (thread == NULL) { 421 if (thread == NULL) {
@@ -427,7 +424,7 @@ static int perf_event__inject_buildid(struct perf_tool *tool,
427 goto repipe; 424 goto repipe;
428 } 425 }
429 426
430 thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->ip, &al); 427 thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, sample->ip, &al);
431 428
432 if (al.map != NULL) { 429 if (al.map != NULL) {
433 if (!al.map->dso->hit) { 430 if (!al.map->dso->hit) {
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index d04c8e7a9507..928a4411e023 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -498,14 +498,13 @@ static void print_sample_brstack(union perf_event *event __maybe_unused,
498 } 498 }
499} 499}
500 500
501static void print_sample_brstacksym(union perf_event *event, 501static void print_sample_brstacksym(union perf_event *event __maybe_unused,
502 struct perf_sample *sample, 502 struct perf_sample *sample,
503 struct thread *thread __maybe_unused, 503 struct thread *thread __maybe_unused,
504 struct perf_event_attr *attr __maybe_unused) 504 struct perf_event_attr *attr __maybe_unused)
505{ 505{
506 struct branch_stack *br = sample->branch_stack; 506 struct branch_stack *br = sample->branch_stack;
507 struct addr_location alf, alt; 507 struct addr_location alf, alt;
508 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
509 u64 i, from, to; 508 u64 i, from, to;
510 509
511 if (!(br && br->nr)) 510 if (!(br && br->nr))
@@ -518,11 +517,11 @@ static void print_sample_brstacksym(union perf_event *event,
518 from = br->entries[i].from; 517 from = br->entries[i].from;
519 to = br->entries[i].to; 518 to = br->entries[i].to;
520 519
521 thread__find_addr_map(thread, cpumode, MAP__FUNCTION, from, &alf); 520 thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, from, &alf);
522 if (alf.map) 521 if (alf.map)
523 alf.sym = map__find_symbol(alf.map, alf.addr, NULL); 522 alf.sym = map__find_symbol(alf.map, alf.addr, NULL);
524 523
525 thread__find_addr_map(thread, cpumode, MAP__FUNCTION, to, &alt); 524 thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, to, &alt);
526 if (alt.map) 525 if (alt.map)
527 alt.sym = map__find_symbol(alt.map, alt.addr, NULL); 526 alt.sym = map__find_symbol(alt.map, alt.addr, NULL);
528 527
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 94af190f6843..a287800bc495 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -809,7 +809,6 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
809 struct perf_session *session = top->session; 809 struct perf_session *session = top->session;
810 union perf_event *event; 810 union perf_event *event;
811 struct machine *machine; 811 struct machine *machine;
812 u8 origin;
813 int ret; 812 int ret;
814 813
815 while ((event = perf_evlist__mmap_read(top->evlist, idx)) != NULL) { 814 while ((event = perf_evlist__mmap_read(top->evlist, idx)) != NULL) {
@@ -822,12 +821,10 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
822 evsel = perf_evlist__id2evsel(session->evlist, sample.id); 821 evsel = perf_evlist__id2evsel(session->evlist, sample.id);
823 assert(evsel != NULL); 822 assert(evsel != NULL);
824 823
825 origin = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
826
827 if (event->header.type == PERF_RECORD_SAMPLE) 824 if (event->header.type == PERF_RECORD_SAMPLE)
828 ++top->samples; 825 ++top->samples;
829 826
830 switch (origin) { 827 switch (sample.cpumode) {
831 case PERF_RECORD_MISC_USER: 828 case PERF_RECORD_MISC_USER:
832 ++top->us_samples; 829 ++top->us_samples;
833 if (top->hide_user_symbols) 830 if (top->hide_user_symbols)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 8dc98c598b1a..93ac724fb635 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -2256,11 +2256,10 @@ static void print_location(FILE *f, struct perf_sample *sample,
2256 2256
2257static int trace__pgfault(struct trace *trace, 2257static int trace__pgfault(struct trace *trace,
2258 struct perf_evsel *evsel, 2258 struct perf_evsel *evsel,
2259 union perf_event *event, 2259 union perf_event *event __maybe_unused,
2260 struct perf_sample *sample) 2260 struct perf_sample *sample)
2261{ 2261{
2262 struct thread *thread; 2262 struct thread *thread;
2263 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
2264 struct addr_location al; 2263 struct addr_location al;
2265 char map_type = 'd'; 2264 char map_type = 'd';
2266 struct thread_trace *ttrace; 2265 struct thread_trace *ttrace;
@@ -2279,7 +2278,7 @@ static int trace__pgfault(struct trace *trace,
2279 if (trace->summary_only) 2278 if (trace->summary_only)
2280 goto out; 2279 goto out;
2281 2280
2282 thread__find_addr_location(thread, cpumode, MAP__FUNCTION, 2281 thread__find_addr_location(thread, sample->cpumode, MAP__FUNCTION,
2283 sample->ip, &al); 2282 sample->ip, &al);
2284 2283
2285 trace__fprintf_entry_head(trace, thread, 0, sample->time, trace->output); 2284 trace__fprintf_entry_head(trace, thread, 0, sample->time, trace->output);
@@ -2292,11 +2291,11 @@ static int trace__pgfault(struct trace *trace,
2292 2291
2293 fprintf(trace->output, "] => "); 2292 fprintf(trace->output, "] => ");
2294 2293
2295 thread__find_addr_location(thread, cpumode, MAP__VARIABLE, 2294 thread__find_addr_location(thread, sample->cpumode, MAP__VARIABLE,
2296 sample->addr, &al); 2295 sample->addr, &al);
2297 2296
2298 if (!al.map) { 2297 if (!al.map) {
2299 thread__find_addr_location(thread, cpumode, 2298 thread__find_addr_location(thread, sample->cpumode,
2300 MAP__FUNCTION, sample->addr, &al); 2299 MAP__FUNCTION, sample->addr, &al);
2301 2300
2302 if (al.map) 2301 if (al.map)
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index afc9ad0a0515..abd3f0ec0c0b 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -293,7 +293,6 @@ static int process_sample_event(struct machine *machine,
293{ 293{
294 struct perf_sample sample; 294 struct perf_sample sample;
295 struct thread *thread; 295 struct thread *thread;
296 u8 cpumode;
297 int ret; 296 int ret;
298 297
299 if (perf_evlist__parse_sample(evlist, event, &sample)) { 298 if (perf_evlist__parse_sample(evlist, event, &sample)) {
@@ -307,9 +306,7 @@ static int process_sample_event(struct machine *machine,
307 return -1; 306 return -1;
308 } 307 }
309 308
310 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; 309 ret = read_object_code(sample.ip, READLEN, sample.cpumode, thread, state);
311
312 ret = read_object_code(sample.ip, READLEN, cpumode, thread, state);
313 thread__put(thread); 310 thread__put(thread);
314 return ret; 311 return ret;
315} 312}
diff --git a/tools/perf/tests/hists_common.c b/tools/perf/tests/hists_common.c
index 071a8b5f5232..f55f4bd47932 100644
--- a/tools/perf/tests/hists_common.c
+++ b/tools/perf/tests/hists_common.c
@@ -100,9 +100,11 @@ struct machine *setup_fake_machine(struct machines *machines)
100 } 100 }
101 101
102 for (i = 0; i < ARRAY_SIZE(fake_mmap_info); i++) { 102 for (i = 0; i < ARRAY_SIZE(fake_mmap_info); i++) {
103 struct perf_sample sample = {
104 .cpumode = PERF_RECORD_MISC_USER,
105 };
103 union perf_event fake_mmap_event = { 106 union perf_event fake_mmap_event = {
104 .mmap = { 107 .mmap = {
105 .header = { .misc = PERF_RECORD_MISC_USER, },
106 .pid = fake_mmap_info[i].pid, 108 .pid = fake_mmap_info[i].pid,
107 .tid = fake_mmap_info[i].pid, 109 .tid = fake_mmap_info[i].pid,
108 .start = fake_mmap_info[i].start, 110 .start = fake_mmap_info[i].start,
@@ -114,7 +116,7 @@ struct machine *setup_fake_machine(struct machines *machines)
114 strcpy(fake_mmap_event.mmap.filename, 116 strcpy(fake_mmap_event.mmap.filename,
115 fake_mmap_info[i].filename); 117 fake_mmap_info[i].filename);
116 118
117 machine__process_mmap_event(machine, &fake_mmap_event, NULL); 119 machine__process_mmap_event(machine, &fake_mmap_event, &sample);
118 } 120 }
119 121
120 for (i = 0; i < ARRAY_SIZE(fake_symbols); i++) { 122 for (i = 0; i < ARRAY_SIZE(fake_symbols); i++) {
diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cumulate.c
index ecf136c385d5..cf7eef73fbe6 100644
--- a/tools/perf/tests/hists_cumulate.c
+++ b/tools/perf/tests/hists_cumulate.c
@@ -97,6 +97,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)
97 else 97 else
98 iter.ops = &hist_iter_normal; 98 iter.ops = &hist_iter_normal;
99 99
100 sample.cpumode = PERF_RECORD_MISC_USER;
100 sample.pid = fake_samples[i].pid; 101 sample.pid = fake_samples[i].pid;
101 sample.tid = fake_samples[i].pid; 102 sample.tid = fake_samples[i].pid;
102 sample.ip = fake_samples[i].ip; 103 sample.ip = fake_samples[i].ip;
diff --git a/tools/perf/tests/hists_filter.c b/tools/perf/tests/hists_filter.c
index 34b945a55d4d..1c9e19352cb6 100644
--- a/tools/perf/tests/hists_filter.c
+++ b/tools/perf/tests/hists_filter.c
@@ -76,6 +76,7 @@ static int add_hist_entries(struct perf_evlist *evlist,
76 hists->dso_filter = NULL; 76 hists->dso_filter = NULL;
77 hists->symbol_filter_str = NULL; 77 hists->symbol_filter_str = NULL;
78 78
79 sample.cpumode = PERF_RECORD_MISC_USER;
79 sample.pid = fake_samples[i].pid; 80 sample.pid = fake_samples[i].pid;
80 sample.tid = fake_samples[i].pid; 81 sample.tid = fake_samples[i].pid;
81 sample.ip = fake_samples[i].ip; 82 sample.ip = fake_samples[i].ip;
diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c
index 64b257d8d557..7885b1d324e4 100644
--- a/tools/perf/tests/hists_link.c
+++ b/tools/perf/tests/hists_link.c
@@ -82,6 +82,7 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine)
82 }, 82 },
83 }; 83 };
84 84
85 sample.cpumode = PERF_RECORD_MISC_USER;
85 sample.pid = fake_common_samples[k].pid; 86 sample.pid = fake_common_samples[k].pid;
86 sample.tid = fake_common_samples[k].pid; 87 sample.tid = fake_common_samples[k].pid;
87 sample.ip = fake_common_samples[k].ip; 88 sample.ip = fake_common_samples[k].ip;
diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_output.c
index 23cce67c7e48..03e4e9c47a55 100644
--- a/tools/perf/tests/hists_output.c
+++ b/tools/perf/tests/hists_output.c
@@ -63,6 +63,7 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)
63 .hide_unresolved = false, 63 .hide_unresolved = false,
64 }; 64 };
65 65
66 sample.cpumode = PERF_RECORD_MISC_USER;
66 sample.cpu = fake_samples[i].cpu; 67 sample.cpu = fake_samples[i].cpu;
67 sample.pid = fake_samples[i].pid; 68 sample.pid = fake_samples[i].pid;
68 sample.tid = fake_samples[i].pid; 69 sample.tid = fake_samples[i].pid;
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index f1479eeef7da..0573c2ec861d 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -28,7 +28,6 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,
28 struct machine *machine) 28 struct machine *machine)
29{ 29{
30 struct addr_location al; 30 struct addr_location al;
31 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
32 struct thread *thread = machine__findnew_thread(machine, sample->pid, 31 struct thread *thread = machine__findnew_thread(machine, sample->pid,
33 sample->tid); 32 sample->tid);
34 33
@@ -38,7 +37,7 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,
38 return -1; 37 return -1;
39 } 38 }
40 39
41 thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->ip, &al); 40 thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, sample->ip, &al);
42 41
43 if (al.map != NULL) 42 if (al.map != NULL)
44 al.map->dso->hit = 1; 43 al.map->dso->hit = 1;
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 7bad5c3fa7b7..f679caac12d0 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -1295,12 +1295,11 @@ void thread__find_addr_location(struct thread *thread,
1295 * Callers need to drop the reference to al->thread, obtained in 1295 * Callers need to drop the reference to al->thread, obtained in
1296 * machine__findnew_thread() 1296 * machine__findnew_thread()
1297 */ 1297 */
1298int perf_event__preprocess_sample(const union perf_event *event, 1298int perf_event__preprocess_sample(const union perf_event *event __maybe_unused,
1299 struct machine *machine, 1299 struct machine *machine,
1300 struct addr_location *al, 1300 struct addr_location *al,
1301 struct perf_sample *sample) 1301 struct perf_sample *sample)
1302{ 1302{
1303 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
1304 struct thread *thread = machine__findnew_thread(machine, sample->pid, 1303 struct thread *thread = machine__findnew_thread(machine, sample->pid,
1305 sample->tid); 1304 sample->tid);
1306 1305
@@ -1315,11 +1314,11 @@ int perf_event__preprocess_sample(const union perf_event *event,
1315 * events, but for older perf.data files there was no such thing, so do 1314 * events, but for older perf.data files there was no such thing, so do
1316 * it now. 1315 * it now.
1317 */ 1316 */
1318 if (cpumode == PERF_RECORD_MISC_KERNEL && 1317 if (sample->cpumode == PERF_RECORD_MISC_KERNEL &&
1319 machine__kernel_map(machine) == NULL) 1318 machine__kernel_map(machine) == NULL)
1320 machine__create_kernel_maps(machine); 1319 machine__create_kernel_maps(machine);
1321 1320
1322 thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->ip, al); 1321 thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, sample->ip, al);
1323 dump_printf(" ...... dso: %s\n", 1322 dump_printf(" ...... dso: %s\n",
1324 al->map ? al->map->dso->long_name : 1323 al->map ? al->map->dso->long_name :
1325 al->level == 'H' ? "[hypervisor]" : "<not found>"); 1324 al->level == 'H' ? "[hypervisor]" : "<not found>");
@@ -1395,16 +1394,14 @@ bool sample_addr_correlates_sym(struct perf_event_attr *attr)
1395 return false; 1394 return false;
1396} 1395}
1397 1396
1398void perf_event__preprocess_sample_addr(union perf_event *event, 1397void perf_event__preprocess_sample_addr(union perf_event *event __maybe_unused,
1399 struct perf_sample *sample, 1398 struct perf_sample *sample,
1400 struct thread *thread, 1399 struct thread *thread,
1401 struct addr_location *al) 1400 struct addr_location *al)
1402{ 1401{
1403 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; 1402 thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, sample->addr, al);
1404
1405 thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->addr, al);
1406 if (!al->map) 1403 if (!al->map)
1407 thread__find_addr_map(thread, cpumode, MAP__VARIABLE, 1404 thread__find_addr_map(thread, sample->cpumode, MAP__VARIABLE,
1408 sample->addr, al); 1405 sample->addr, al);
1409 1406
1410 al->cpu = sample->cpu; 1407 al->cpu = sample->cpu;
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index b7ffb7ee9971..f5a2e67c86aa 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -192,6 +192,7 @@ struct perf_sample {
192 u64 data_src; 192 u64 data_src;
193 u32 flags; 193 u32 flags;
194 u16 insn_len; 194 u16 insn_len;
195 u8 cpumode;
195 void *raw_data; 196 void *raw_data;
196 struct ip_callchain *callchain; 197 struct ip_callchain *callchain;
197 struct branch_stack *branch_stack; 198 struct branch_stack *branch_stack;
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 0902fe418754..738ce226002b 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1643,6 +1643,7 @@ int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event,
1643 data->stream_id = data->id = data->time = -1ULL; 1643 data->stream_id = data->id = data->time = -1ULL;
1644 data->period = evsel->attr.sample_period; 1644 data->period = evsel->attr.sample_period;
1645 data->weight = 0; 1645 data->weight = 0;
1646 data->cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
1646 1647
1647 if (event->header.type != PERF_RECORD_SAMPLE) { 1648 if (event->header.type != PERF_RECORD_SAMPLE) {
1648 if (!evsel->attr.sample_id_all) 1649 if (!evsel->attr.sample_id_all)
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index ad79297c76c8..80b9b6a87990 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1301,9 +1301,8 @@ out_problem:
1301 1301
1302int machine__process_mmap2_event(struct machine *machine, 1302int machine__process_mmap2_event(struct machine *machine,
1303 union perf_event *event, 1303 union perf_event *event,
1304 struct perf_sample *sample __maybe_unused) 1304 struct perf_sample *sample)
1305{ 1305{
1306 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
1307 struct thread *thread; 1306 struct thread *thread;
1308 struct map *map; 1307 struct map *map;
1309 enum map_type type; 1308 enum map_type type;
@@ -1312,8 +1311,8 @@ int machine__process_mmap2_event(struct machine *machine,
1312 if (dump_trace) 1311 if (dump_trace)
1313 perf_event__fprintf_mmap2(event, stdout); 1312 perf_event__fprintf_mmap2(event, stdout);
1314 1313
1315 if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL || 1314 if (sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
1316 cpumode == PERF_RECORD_MISC_KERNEL) { 1315 sample->cpumode == PERF_RECORD_MISC_KERNEL) {
1317 ret = machine__process_kernel_mmap_event(machine, event); 1316 ret = machine__process_kernel_mmap_event(machine, event);
1318 if (ret < 0) 1317 if (ret < 0)
1319 goto out_problem; 1318 goto out_problem;
@@ -1355,9 +1354,8 @@ out_problem:
1355} 1354}
1356 1355
1357int machine__process_mmap_event(struct machine *machine, union perf_event *event, 1356int machine__process_mmap_event(struct machine *machine, union perf_event *event,
1358 struct perf_sample *sample __maybe_unused) 1357 struct perf_sample *sample)
1359{ 1358{
1360 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
1361 struct thread *thread; 1359 struct thread *thread;
1362 struct map *map; 1360 struct map *map;
1363 enum map_type type; 1361 enum map_type type;
@@ -1366,8 +1364,8 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event
1366 if (dump_trace) 1364 if (dump_trace)
1367 perf_event__fprintf_mmap(event, stdout); 1365 perf_event__fprintf_mmap(event, stdout);
1368 1366
1369 if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL || 1367 if (sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
1370 cpumode == PERF_RECORD_MISC_KERNEL) { 1368 sample->cpumode == PERF_RECORD_MISC_KERNEL) {
1371 ret = machine__process_kernel_mmap_event(machine, event); 1369 ret = machine__process_kernel_mmap_event(machine, event);
1372 if (ret < 0) 1370 if (ret < 0)
1373 goto out_problem; 1371 goto out_problem;
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 60b3593d210d..4abd85c6346d 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1107,12 +1107,11 @@ static struct machine *machines__find_for_cpumode(struct machines *machines,
1107 union perf_event *event, 1107 union perf_event *event,
1108 struct perf_sample *sample) 1108 struct perf_sample *sample)
1109{ 1109{
1110 const u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
1111 struct machine *machine; 1110 struct machine *machine;
1112 1111
1113 if (perf_guest && 1112 if (perf_guest &&
1114 ((cpumode == PERF_RECORD_MISC_GUEST_KERNEL) || 1113 ((sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL) ||
1115 (cpumode == PERF_RECORD_MISC_GUEST_USER))) { 1114 (sample->cpumode == PERF_RECORD_MISC_GUEST_USER))) {
1116 u32 pid; 1115 u32 pid;
1117 1116
1118 if (event->header.type == PERF_RECORD_MMAP 1117 if (event->header.type == PERF_RECORD_MMAP