* [PATCH 1/2] perf annotate: Treat 'call' instruction as stack operation
@ 2024-09-09 21:42 Namhyung Kim
2024-09-09 21:42 ` [PATCH 2/2] perf annotate-data: Add pr_debug_scope() Namhyung Kim
2024-09-10 14:49 ` [PATCH 1/2] perf annotate: Treat 'call' instruction as stack operation Arnaldo Carvalho de Melo
0 siblings, 2 replies; 3+ messages in thread
From: Namhyung Kim @ 2024-09-09 21:42 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Ian Rogers, Kan Liang
Cc: Jiri Olsa, Adrian Hunter, Peter Zijlstra, Ingo Molnar, LKML,
linux-perf-users
I found some portion of mem-store events sampled on CALL instruction
which has no memory access. But it actually saves a return address
into stack. It should be considered as a stack operation like RET
instruction.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/annotate.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 4990c70b1794d7a9..1a347a711dcf5c62 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2474,6 +2474,7 @@ static bool is_stack_operation(struct arch *arch, struct disasm_line *dl)
if (arch__is(arch, "x86")) {
if (!strncmp(dl->ins.name, "push", 4) ||
!strncmp(dl->ins.name, "pop", 3) ||
+ !strncmp(dl->ins.name, "call", 4) ||
!strncmp(dl->ins.name, "ret", 3))
return true;
}
--
2.46.0.598.g6f2099f65c-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] perf annotate-data: Add pr_debug_scope()
2024-09-09 21:42 [PATCH 1/2] perf annotate: Treat 'call' instruction as stack operation Namhyung Kim
@ 2024-09-09 21:42 ` Namhyung Kim
2024-09-10 14:49 ` [PATCH 1/2] perf annotate: Treat 'call' instruction as stack operation Arnaldo Carvalho de Melo
1 sibling, 0 replies; 3+ messages in thread
From: Namhyung Kim @ 2024-09-09 21:42 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Ian Rogers, Kan Liang
Cc: Jiri Olsa, Adrian Hunter, Peter Zijlstra, Ingo Molnar, LKML,
linux-perf-users
The pr_debug_scope() is to print more information about the scope DIE
during the instruction tracking so that it can help finding relevant
debug info and the source code like inlined functions more easily.
$ perf --debug type-profile annotate --data-type
...
-----------------------------------------------------------
find data type for 0(reg0, reg12) at set_task_cpu+0xdd
CU for kernel/sched/core.c (die:0x1268dae)
frame base: cfa=1 fbreg=7
scope: [3/3] (die:12b6d28) [inlined] set_task_rq <<<--- (here)
bb: [9f - dd]
var [9f] reg3 type='struct task_struct*' size=0x8 (die:0x126aff0)
var [9f] reg6 type='unsigned int' size=0x4 (die:0x1268e0d)
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/annotate-data.c | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-data.c
index a0ea4e07e57031ff..976abedca09ef547 100644
--- a/tools/perf/util/annotate-data.c
+++ b/tools/perf/util/annotate-data.c
@@ -131,6 +131,26 @@ static void pr_debug_location(Dwarf_Die *die, u64 pc, int reg)
}
}
+static void pr_debug_scope(Dwarf_Die *scope_die)
+{
+ int tag;
+
+ if (!debug_type_profile && verbose < 3)
+ return;
+
+ pr_info("(die:%lx) ", (long)dwarf_dieoffset(scope_die));
+
+ tag = dwarf_tag(scope_die);
+ if (tag == DW_TAG_subprogram)
+ pr_info("[function] %s\n", dwarf_diename(scope_die));
+ else if (tag == DW_TAG_inlined_subroutine)
+ pr_info("[inlined] %s\n", dwarf_diename(scope_die));
+ else if (tag == DW_TAG_lexical_block)
+ pr_info("[block]\n");
+ else
+ pr_info("[unknown] tag=%x\n", tag);
+}
+
bool has_reg_type(struct type_state *state, int reg)
{
return (unsigned)reg < ARRAY_SIZE(state->regs);
@@ -1305,8 +1325,9 @@ static enum type_match_result find_data_type_block(struct data_loc_info *dloc,
if (dwarf_ranges(&scopes[i], 0, &base, &start, &end) < 0)
break;
- pr_debug_dtp("scope: [%d/%d] (die:%lx)\n",
- i + 1, nr_scopes, (long)dwarf_dieoffset(&scopes[i]));
+ pr_debug_dtp("scope: [%d/%d] ", i + 1, nr_scopes);
+ pr_debug_scope(&scopes[i]);
+
src_ip = map__objdump_2rip(dloc->ms->map, start);
again:
--
2.46.0.598.g6f2099f65c-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] perf annotate: Treat 'call' instruction as stack operation
2024-09-09 21:42 [PATCH 1/2] perf annotate: Treat 'call' instruction as stack operation Namhyung Kim
2024-09-09 21:42 ` [PATCH 2/2] perf annotate-data: Add pr_debug_scope() Namhyung Kim
@ 2024-09-10 14:49 ` Arnaldo Carvalho de Melo
1 sibling, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-09-10 14:49 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ian Rogers, Kan Liang, Jiri Olsa, Adrian Hunter, Peter Zijlstra,
Ingo Molnar, LKML, linux-perf-users
On Mon, Sep 09, 2024 at 02:42:50PM -0700, Namhyung Kim wrote:
> I found some portion of mem-store events sampled on CALL instruction
> which has no memory access. But it actually saves a return address
> into stack. It should be considered as a stack operation like RET
> instruction.
Thanks, applied to perf-tools-next,
- Arnaldo
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> tools/perf/util/annotate.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
> index 4990c70b1794d7a9..1a347a711dcf5c62 100644
> --- a/tools/perf/util/annotate.c
> +++ b/tools/perf/util/annotate.c
> @@ -2474,6 +2474,7 @@ static bool is_stack_operation(struct arch *arch, struct disasm_line *dl)
> if (arch__is(arch, "x86")) {
> if (!strncmp(dl->ins.name, "push", 4) ||
> !strncmp(dl->ins.name, "pop", 3) ||
> + !strncmp(dl->ins.name, "call", 4) ||
> !strncmp(dl->ins.name, "ret", 3))
> return true;
> }
> --
> 2.46.0.598.g6f2099f65c-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-09-10 14:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-09 21:42 [PATCH 1/2] perf annotate: Treat 'call' instruction as stack operation Namhyung Kim
2024-09-09 21:42 ` [PATCH 2/2] perf annotate-data: Add pr_debug_scope() Namhyung Kim
2024-09-10 14:49 ` [PATCH 1/2] perf annotate: Treat 'call' instruction as stack operation Arnaldo Carvalho de Melo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).