Skip to content

Commit 2e77784

Browse files
kliang2acmel
authored andcommitted
perf callchain: Move cpumode resolve code to add_callchain_ip
Using flag to distinguish between branch_history and normal callchain. Move the cpumode to add_callchain_ip function. No change in behavior. Signed-off-by: Kan Liang <kan.liang@intel.com> Acked-by: Jiri Olsa <jolsa@redhat.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1417532814-26208-3-git-send-email-kan.liang@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent f70b4e3 commit 2e77784

File tree

1 file changed

+35
-37
lines changed

1 file changed

+35
-37
lines changed

tools/perf/util/machine.c

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,19 +1385,46 @@ struct mem_info *sample__resolve_mem(struct perf_sample *sample,
13851385
static int add_callchain_ip(struct thread *thread,
13861386
struct symbol **parent,
13871387
struct addr_location *root_al,
1388-
int cpumode,
1388+
bool branch_history,
13891389
u64 ip)
13901390
{
13911391
struct addr_location al;
13921392

13931393
al.filtered = 0;
13941394
al.sym = NULL;
1395-
if (cpumode == -1)
1395+
if (branch_history)
13961396
thread__find_cpumode_addr_location(thread, MAP__FUNCTION,
13971397
ip, &al);
1398-
else
1398+
else {
1399+
u8 cpumode = PERF_RECORD_MISC_USER;
1400+
1401+
if (ip >= PERF_CONTEXT_MAX) {
1402+
switch (ip) {
1403+
case PERF_CONTEXT_HV:
1404+
cpumode = PERF_RECORD_MISC_HYPERVISOR;
1405+
break;
1406+
case PERF_CONTEXT_KERNEL:
1407+
cpumode = PERF_RECORD_MISC_KERNEL;
1408+
break;
1409+
case PERF_CONTEXT_USER:
1410+
cpumode = PERF_RECORD_MISC_USER;
1411+
break;
1412+
default:
1413+
pr_debug("invalid callchain context: "
1414+
"%"PRId64"\n", (s64) ip);
1415+
/*
1416+
* It seems the callchain is corrupted.
1417+
* Discard all.
1418+
*/
1419+
callchain_cursor_reset(&callchain_cursor);
1420+
return 1;
1421+
}
1422+
return 0;
1423+
}
13991424
thread__find_addr_location(thread, cpumode, MAP__FUNCTION,
14001425
ip, &al);
1426+
}
1427+
14011428
if (al.sym != NULL) {
14021429
if (sort__has_parent && !*parent &&
14031430
symbol__match_regex(al.sym, &parent_regex))
@@ -1480,11 +1507,8 @@ static int thread__resolve_callchain_sample(struct thread *thread,
14801507
struct addr_location *root_al,
14811508
int max_stack)
14821509
{
1483-
u8 cpumode = PERF_RECORD_MISC_USER;
14841510
int chain_nr = min(max_stack, (int)chain->nr);
1485-
int i;
1486-
int j;
1487-
int err;
1511+
int i, j, err;
14881512
int skip_idx = -1;
14891513
int first_call = 0;
14901514

@@ -1542,10 +1566,10 @@ static int thread__resolve_callchain_sample(struct thread *thread,
15421566

15431567
for (i = 0; i < nr; i++) {
15441568
err = add_callchain_ip(thread, parent, root_al,
1545-
-1, be[i].to);
1569+
true, be[i].to);
15461570
if (!err)
15471571
err = add_callchain_ip(thread, parent, root_al,
1548-
-1, be[i].from);
1572+
true, be[i].from);
15491573
if (err == -EINVAL)
15501574
break;
15511575
if (err)
@@ -1574,36 +1598,10 @@ static int thread__resolve_callchain_sample(struct thread *thread,
15741598
#endif
15751599
ip = chain->ips[j];
15761600

1577-
if (ip >= PERF_CONTEXT_MAX) {
1578-
switch (ip) {
1579-
case PERF_CONTEXT_HV:
1580-
cpumode = PERF_RECORD_MISC_HYPERVISOR;
1581-
break;
1582-
case PERF_CONTEXT_KERNEL:
1583-
cpumode = PERF_RECORD_MISC_KERNEL;
1584-
break;
1585-
case PERF_CONTEXT_USER:
1586-
cpumode = PERF_RECORD_MISC_USER;
1587-
break;
1588-
default:
1589-
pr_debug("invalid callchain context: "
1590-
"%"PRId64"\n", (s64) ip);
1591-
/*
1592-
* It seems the callchain is corrupted.
1593-
* Discard all.
1594-
*/
1595-
callchain_cursor_reset(&callchain_cursor);
1596-
return 0;
1597-
}
1598-
continue;
1599-
}
1601+
err = add_callchain_ip(thread, parent, root_al, false, ip);
16001602

1601-
err = add_callchain_ip(thread, parent, root_al,
1602-
cpumode, ip);
1603-
if (err == -EINVAL)
1604-
break;
16051603
if (err)
1606-
return err;
1604+
return (err < 0) ? err : 0;
16071605
}
16081606

16091607
return 0;

0 commit comments

Comments
 (0)