Commit dd3e249a authored by Kan Liang's avatar Kan Liang Committed by Arnaldo Carvalho de Melo

perf machine: Factor out lbr_callchain_add_kernel_ip()

Both caller and callee needs to add kernel ip to callchain.  Factor out
lbr_callchain_add_kernel_ip() to improve code readability.
Signed-off-by: default avatarKan Liang <kan.liang@linux.intel.com>
Reviewed-by: default avatarAndi Kleen <ak@linux.intel.com>
Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Pavel Gerasimov <pavel.gerasimov@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Vitaly Slobodskoy <vitaly.slobodskoy@intel.com>
Link: http://lore.kernel.org/lkml/20200319202517.23423-8-kan.liang@linux.intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent e48b8311
...@@ -2190,6 +2190,40 @@ static int remove_loops(struct branch_entry *l, int nr, ...@@ -2190,6 +2190,40 @@ static int remove_loops(struct branch_entry *l, int nr,
return nr; return nr;
} }
static int lbr_callchain_add_kernel_ip(struct thread *thread,
struct callchain_cursor *cursor,
struct perf_sample *sample,
struct symbol **parent,
struct addr_location *root_al,
u64 branch_from,
bool callee, int end)
{
struct ip_callchain *chain = sample->callchain;
u8 cpumode = PERF_RECORD_MISC_USER;
int err, i;
if (callee) {
for (i = 0; i < end + 1; i++) {
err = add_callchain_ip(thread, cursor, parent,
root_al, &cpumode, chain->ips[i],
false, NULL, NULL, branch_from);
if (err)
return err;
}
return 0;
}
for (i = end; i >= 0; i--) {
err = add_callchain_ip(thread, cursor, parent,
root_al, &cpumode, chain->ips[i],
false, NULL, NULL, branch_from);
if (err)
return err;
}
return 0;
}
/* /*
* Recolve LBR callstack chain sample * Recolve LBR callstack chain sample
* Return: * Return:
...@@ -2242,17 +2276,12 @@ static int resolve_lbr_callchain_sample(struct thread *thread, ...@@ -2242,17 +2276,12 @@ static int resolve_lbr_callchain_sample(struct thread *thread,
if (callchain_param.order == ORDER_CALLEE) { if (callchain_param.order == ORDER_CALLEE) {
/* Add kernel ip */ /* Add kernel ip */
for (j = 0; j < i + 1; j++) { err = lbr_callchain_add_kernel_ip(thread, cursor, sample,
ip = chain->ips[j]; parent, root_al, branch_from,
branch = false; true, i);
flags = NULL;
err = add_callchain_ip(thread, cursor, parent,
root_al, &cpumode, ip,
branch, flags, NULL,
branch_from);
if (err) if (err)
goto error; goto error;
}
/* Add LBR ip from first entries.to */ /* Add LBR ip from first entries.to */
ip = entries[0].to; ip = entries[0].to;
branch = true; branch = true;
...@@ -2308,18 +2337,12 @@ static int resolve_lbr_callchain_sample(struct thread *thread, ...@@ -2308,18 +2337,12 @@ static int resolve_lbr_callchain_sample(struct thread *thread,
goto error; goto error;
/* Add kernel ip */ /* Add kernel ip */
for (j = lbr_nr + 1; j < mix_chain_nr; j++) { err = lbr_callchain_add_kernel_ip(thread, cursor, sample,
ip = chain->ips[i + 1 - (j - lbr_nr)]; parent, root_al, branch_from,
branch = false; false, i);
flags = NULL;
err = add_callchain_ip(thread, cursor, parent,
root_al, &cpumode, ip,
branch, flags, NULL,
branch_from);
if (err) if (err)
goto error; goto error;
} }
}
return 1; return 1;
error: error:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment