Skip to content

Commit 2424830

Browse files
ahunter6acmel
authored andcommitted
perf intel-pt: Insert callchain context into synthesized callchains
In the absence of a fallback, callchains must encode also the callchain context. 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/100ea2ec-ed14-b56d-d810-e0a6d2f4b069@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 4f8f382 commit 2424830

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

tools/perf/util/intel-pt.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,8 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt,
759759
if (pt->synth_opts.callchain) {
760760
size_t sz = sizeof(struct ip_callchain);
761761

762-
sz += pt->synth_opts.callchain_sz * sizeof(u64);
762+
/* Add 1 to callchain_sz for callchain context */
763+
sz += (pt->synth_opts.callchain_sz + 1) * sizeof(u64);
763764
ptq->chain = zalloc(sz);
764765
if (!ptq->chain)
765766
goto out_free;
@@ -1160,7 +1161,8 @@ static void intel_pt_prep_sample(struct intel_pt *pt,
11601161

11611162
if (pt->synth_opts.callchain) {
11621163
thread_stack__sample(ptq->thread, ptq->chain,
1163-
pt->synth_opts.callchain_sz, sample->ip);
1164+
pt->synth_opts.callchain_sz + 1,
1165+
sample->ip, pt->kernel_start);
11641166
sample->callchain = ptq->chain;
11651167
}
11661168

tools/perf/util/thread-stack.c

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,20 +310,46 @@ void thread_stack__free(struct thread *thread)
310310
}
311311
}
312312

313+
static inline u64 callchain_context(u64 ip, u64 kernel_start)
314+
{
315+
return ip < kernel_start ? PERF_CONTEXT_USER : PERF_CONTEXT_KERNEL;
316+
}
317+
313318
void thread_stack__sample(struct thread *thread, struct ip_callchain *chain,
314-
size_t sz, u64 ip)
319+
size_t sz, u64 ip, u64 kernel_start)
315320
{
316-
size_t i;
321+
u64 context = callchain_context(ip, kernel_start);
322+
u64 last_context;
323+
size_t i, j;
317324

318-
if (!thread || !thread->ts)
319-
chain->nr = 1;
320-
else
321-
chain->nr = min(sz, thread->ts->cnt + 1);
325+
if (sz < 2) {
326+
chain->nr = 0;
327+
return;
328+
}
322329

323-
chain->ips[0] = ip;
330+
chain->ips[0] = context;
331+
chain->ips[1] = ip;
332+
333+
if (!thread || !thread->ts) {
334+
chain->nr = 2;
335+
return;
336+
}
337+
338+
last_context = context;
339+
340+
for (i = 2, j = 1; i < sz && j <= thread->ts->cnt; i++, j++) {
341+
ip = thread->ts->stack[thread->ts->cnt - j].ret_addr;
342+
context = callchain_context(ip, kernel_start);
343+
if (context != last_context) {
344+
if (i >= sz - 1)
345+
break;
346+
chain->ips[i++] = context;
347+
last_context = context;
348+
}
349+
chain->ips[i] = ip;
350+
}
324351

325-
for (i = 1; i < chain->nr; i++)
326-
chain->ips[i] = thread->ts->stack[thread->ts->cnt - i].ret_addr;
352+
chain->nr = i;
327353
}
328354

329355
struct call_return_processor *

tools/perf/util/thread-stack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ int thread_stack__event(struct thread *thread, u32 flags, u64 from_ip,
8484
u64 to_ip, u16 insn_len, u64 trace_nr);
8585
void thread_stack__set_trace_nr(struct thread *thread, u64 trace_nr);
8686
void thread_stack__sample(struct thread *thread, struct ip_callchain *chain,
87-
size_t sz, u64 ip);
87+
size_t sz, u64 ip, u64 kernel_start);
8888
int thread_stack__flush(struct thread *thread);
8989
void thread_stack__free(struct thread *thread);
9090
size_t thread_stack__depth(struct thread *thread);

0 commit comments

Comments
 (0)