Skip to content

Commit dd3e249

Browse files
Kan Liangacmel
authored andcommitted
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: Kan Liang <[email protected]> Reviewed-by: Andi Kleen <[email protected]> Acked-by: Jiri Olsa <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexey Budankov <[email protected]> Cc: Mathieu Poirier <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Pavel Gerasimov <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ravi Bangoria <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Vitaly Slobodskoy <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent e48b831 commit dd3e249

File tree

1 file changed

+45
-22
lines changed

1 file changed

+45
-22
lines changed

tools/perf/util/machine.c

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,6 +2190,40 @@ static int remove_loops(struct branch_entry *l, int nr,
21902190
return nr;
21912191
}
21922192

2193+
static int lbr_callchain_add_kernel_ip(struct thread *thread,
2194+
struct callchain_cursor *cursor,
2195+
struct perf_sample *sample,
2196+
struct symbol **parent,
2197+
struct addr_location *root_al,
2198+
u64 branch_from,
2199+
bool callee, int end)
2200+
{
2201+
struct ip_callchain *chain = sample->callchain;
2202+
u8 cpumode = PERF_RECORD_MISC_USER;
2203+
int err, i;
2204+
2205+
if (callee) {
2206+
for (i = 0; i < end + 1; i++) {
2207+
err = add_callchain_ip(thread, cursor, parent,
2208+
root_al, &cpumode, chain->ips[i],
2209+
false, NULL, NULL, branch_from);
2210+
if (err)
2211+
return err;
2212+
}
2213+
return 0;
2214+
}
2215+
2216+
for (i = end; i >= 0; i--) {
2217+
err = add_callchain_ip(thread, cursor, parent,
2218+
root_al, &cpumode, chain->ips[i],
2219+
false, NULL, NULL, branch_from);
2220+
if (err)
2221+
return err;
2222+
}
2223+
2224+
return 0;
2225+
}
2226+
21932227
/*
21942228
* Recolve LBR callstack chain sample
21952229
* Return:
@@ -2242,17 +2276,12 @@ static int resolve_lbr_callchain_sample(struct thread *thread,
22422276

22432277
if (callchain_param.order == ORDER_CALLEE) {
22442278
/* Add kernel ip */
2245-
for (j = 0; j < i + 1; j++) {
2246-
ip = chain->ips[j];
2247-
branch = false;
2248-
flags = NULL;
2249-
err = add_callchain_ip(thread, cursor, parent,
2250-
root_al, &cpumode, ip,
2251-
branch, flags, NULL,
2252-
branch_from);
2253-
if (err)
2254-
goto error;
2255-
}
2279+
err = lbr_callchain_add_kernel_ip(thread, cursor, sample,
2280+
parent, root_al, branch_from,
2281+
true, i);
2282+
if (err)
2283+
goto error;
2284+
22562285
/* Add LBR ip from first entries.to */
22572286
ip = entries[0].to;
22582287
branch = true;
@@ -2308,17 +2337,11 @@ static int resolve_lbr_callchain_sample(struct thread *thread,
23082337
goto error;
23092338

23102339
/* Add kernel ip */
2311-
for (j = lbr_nr + 1; j < mix_chain_nr; j++) {
2312-
ip = chain->ips[i + 1 - (j - lbr_nr)];
2313-
branch = false;
2314-
flags = NULL;
2315-
err = add_callchain_ip(thread, cursor, parent,
2316-
root_al, &cpumode, ip,
2317-
branch, flags, NULL,
2318-
branch_from);
2319-
if (err)
2320-
goto error;
2321-
}
2340+
err = lbr_callchain_add_kernel_ip(thread, cursor, sample,
2341+
parent, root_al, branch_from,
2342+
false, i);
2343+
if (err)
2344+
goto error;
23222345
}
23232346
return 1;
23242347

0 commit comments

Comments
 (0)