Skip to content

Commit 5d4f0ed

Browse files
ahunter6acmel
authored andcommitted
perf intel-pt/bts: Calculate cpumode for synthesized samples
In the absence of a fallback, samples must provide a correct cpumode for the 'ip'. Do that now there is no fallback. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Reviewed-by: Jiri Olsa <jolsa@kernel.org> Cc: Andi Kleen <ak@linux.intel.com> Cc: David S. Miller <davem@davemloft.net> Cc: Leo Yan <leo.yan@linaro.org> Cc: Mathieu Poirier <mathieu.poirier@linaro.org> Cc: stable@vger.kernel.org # 4.19 Link: http://lkml.kernel.org/r/20181031091043.23465-6-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 2424830 commit 5d4f0ed

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

tools/perf/util/intel-bts.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,13 @@ static int intel_bts_do_fix_overlap(struct auxtrace_queue *queue,
269269
return 0;
270270
}
271271

272+
static inline u8 intel_bts_cpumode(struct intel_bts *bts, uint64_t ip)
273+
{
274+
return machine__kernel_ip(bts->machine, ip) ?
275+
PERF_RECORD_MISC_KERNEL :
276+
PERF_RECORD_MISC_USER;
277+
}
278+
272279
static int intel_bts_synth_branch_sample(struct intel_bts_queue *btsq,
273280
struct branch *branch)
274281
{
@@ -281,12 +288,8 @@ static int intel_bts_synth_branch_sample(struct intel_bts_queue *btsq,
281288
bts->num_events++ <= bts->synth_opts.initial_skip)
282289
return 0;
283290

284-
event.sample.header.type = PERF_RECORD_SAMPLE;
285-
event.sample.header.misc = PERF_RECORD_MISC_USER;
286-
event.sample.header.size = sizeof(struct perf_event_header);
287-
288-
sample.cpumode = PERF_RECORD_MISC_USER;
289291
sample.ip = le64_to_cpu(branch->from);
292+
sample.cpumode = intel_bts_cpumode(bts, sample.ip);
290293
sample.pid = btsq->pid;
291294
sample.tid = btsq->tid;
292295
sample.addr = le64_to_cpu(branch->to);
@@ -298,6 +301,10 @@ static int intel_bts_synth_branch_sample(struct intel_bts_queue *btsq,
298301
sample.insn_len = btsq->intel_pt_insn.length;
299302
memcpy(sample.insn, btsq->intel_pt_insn.buf, INTEL_PT_INSN_BUF_SZ);
300303

304+
event.sample.header.type = PERF_RECORD_SAMPLE;
305+
event.sample.header.misc = sample.cpumode;
306+
event.sample.header.size = sizeof(struct perf_event_header);
307+
301308
if (bts->synth_opts.inject) {
302309
event.sample.header.size = bts->branches_event_size;
303310
ret = perf_event__synthesize_sample(&event,

tools/perf/util/intel-pt.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,13 @@ intel_pt_cache_lookup(struct dso *dso, struct machine *machine, u64 offset)
407407
return auxtrace_cache__lookup(dso->auxtrace_cache, offset);
408408
}
409409

410+
static inline u8 intel_pt_cpumode(struct intel_pt *pt, uint64_t ip)
411+
{
412+
return ip >= pt->kernel_start ?
413+
PERF_RECORD_MISC_KERNEL :
414+
PERF_RECORD_MISC_USER;
415+
}
416+
410417
static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
411418
uint64_t *insn_cnt_ptr, uint64_t *ip,
412419
uint64_t to_ip, uint64_t max_insn_cnt,
@@ -429,10 +436,7 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
429436
if (to_ip && *ip == to_ip)
430437
goto out_no_cache;
431438

432-
if (*ip >= ptq->pt->kernel_start)
433-
cpumode = PERF_RECORD_MISC_KERNEL;
434-
else
435-
cpumode = PERF_RECORD_MISC_USER;
439+
cpumode = intel_pt_cpumode(ptq->pt, *ip);
436440

437441
thread = ptq->thread;
438442
if (!thread) {
@@ -1059,15 +1063,11 @@ static void intel_pt_prep_b_sample(struct intel_pt *pt,
10591063
union perf_event *event,
10601064
struct perf_sample *sample)
10611065
{
1062-
event->sample.header.type = PERF_RECORD_SAMPLE;
1063-
event->sample.header.misc = PERF_RECORD_MISC_USER;
1064-
event->sample.header.size = sizeof(struct perf_event_header);
1065-
10661066
if (!pt->timeless_decoding)
10671067
sample->time = tsc_to_perf_time(ptq->timestamp, &pt->tc);
10681068

1069-
sample->cpumode = PERF_RECORD_MISC_USER;
10701069
sample->ip = ptq->state->from_ip;
1070+
sample->cpumode = intel_pt_cpumode(pt, sample->ip);
10711071
sample->pid = ptq->pid;
10721072
sample->tid = ptq->tid;
10731073
sample->addr = ptq->state->to_ip;
@@ -1076,6 +1076,10 @@ static void intel_pt_prep_b_sample(struct intel_pt *pt,
10761076
sample->flags = ptq->flags;
10771077
sample->insn_len = ptq->insn_len;
10781078
memcpy(sample->insn, ptq->insn, INTEL_PT_INSN_BUF_SZ);
1079+
1080+
event->sample.header.type = PERF_RECORD_SAMPLE;
1081+
event->sample.header.misc = sample->cpumode;
1082+
event->sample.header.size = sizeof(struct perf_event_header);
10791083
}
10801084

10811085
static int intel_pt_inject_event(union perf_event *event,

0 commit comments

Comments
 (0)