perf/probe: Additional fixes for range only functions
v2 cover perf/probe: Additional fixes for range only functions
Hi Arnaldo,
I've updated examples in patch description in this v2. No changes in the code itself. I ran it on Ubuntu 19.04 (linux-5.0.0-32-generic).
Please replace previous one with this.
Thank you,
---
Masami Hiramatsu (6):
perf/probe: Fix wrong address verification
perf/probe: Fix to probe a function which has no entry pc perf/probe: Fix to probe an inline function which has no entry pc perf/probe: Fix to list probe event with correct line number perf/probe: Fix to show inlined function callsite without entry_pc perf/probe: Fix to show ranges of variables in functions without entry_pc
tools/perf/util/dwarf-aux.c | 6 +++--- tools/perf/util/probe-finder.c | 40 ++++++++++++++-------------------------- 2 files changed, 17 insertions(+), 29 deletions(-)
--
Masami Hiramatsu (Linaro) <[email protected]>
PATCH v2 1/6 perf/probe: Fix wrong address verification
Since there are some DIE which has only ranges instead of the combination of entrypc/highpc, address verification must use dwarf_haspc() instead of dwarf_entrypc/dwarf_highpc.
Also, the ranges only DIE will have a partial code in different section (e.g. unlikely code will be in text.unlikely as "FUNC.cold" symbol). In that case, we can not use dwarf_entrypc() or die_entrypc(), because the offset from original DIE can be a minus value.
Instead, this simply gets the symbol and offset from symtab.
Without this patch;
# tools/perf/perf probe -D clear_tasks_mm_cpumask:1
Failed to get entry address of clear_tasks_mm_cpumask
Error: Failed to add events.And with this patch
# perf probe -D clear_tasks_mm_cpumask:1 p:probe/clear_tasks_mm_cpumask _text+632816 p:probe/clear_tasks_mm_cpumask_1 _text+632821 p:probe/clear_tasks_mm_cpumask_2 _text+632830
--- tools/perf/util/probe-finder.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-)
tools/perf/util/probe-finder.c +10 -22
@@ -604,38 +604,26 @@ static int convert_to_trace_point(Dwarf_Die *sp_die, Dwfl_Module *mod,const char *function, struct probe_trace_point *tp) { - Dwarf_Addr eaddr, highaddr; + Dwarf_Addr eaddr;GElf_Sym sym;const char *symbol;/* Verify the address is correct */ -if (dwarf_entrypc (sp_die, &eaddr) !=0 ) { -pr_warning ("Failed to get entry address of %s\n" , -dwarf_diename (sp_die)); -return -ENOENT ; - } -if (dwarf_highpc (sp_die, &highaddr) !=0 ) { -pr_warning ("Failed to get end address of %s\n" , -dwarf_diename (sp_die)); -return -ENOENT ; - } -if (paddr > highaddr) { -pr_warning ("Offset specified is greater than size of %s\n" , +if (!dwarf_haspc (sp_die, paddr)) { +pr_warning ("Specified offset is out of %s\n" ,dwarf_diename (sp_die));return -EINVAL ; } - symbol =dwarf_diename (sp_die); +/* Try to get actual symbol name from symtab */ + symbol =dwfl_module_addrsym (mod, paddr, &sym,NULL );if (!symbol) { -/* Try to get the symbol name from symtab */ - symbol =dwfl_module_addrsym (mod, paddr, &sym,NULL ); -if (!symbol) { -pr_warning ("Failed to find symbol at 0x%lx\n" , - (unsigned long )paddr); -return -ENOENT ; - } - eaddr = sym.st_value; +pr_warning ("Failed to find symbol at 0x%lx\n" , + (unsigned long )paddr); +return -ENOENT ; } + eaddr = sym.st_value; + tp->offset = (unsigned long )(paddr - eaddr); tp->address = (unsigned long )paddr; tp->symbol =strdup (symbol);
PATCH v2 2/6 perf/probe: Fix to probe a function which has no entry pc
In reply to Masami HiramatsuFix perf probe to probe a function which has no entry pc or low pc but only has ranges attribute.
probe_point_search_cb() uses dwarf_entrypc() to get the probe address, but that doesn't work for the function DIE which has only ranges attribute. Use die_entrypc() instead.
Without this fix,
# perf probe -D clear_tasks_mm_cpumask:0
Probe point 'clear_tasks_mm_cpumask' not found.
Error: Failed to add events.With this,
# perf probe -D clear_tasks_mm_cpumask:0 p:probe/clear_tasks_mm_cpumask _text+632816
--- tools/perf/util/probe-finder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/probe-finder.c +1 -1
@@ -982,7 +982,7 @@ static int probe_point_search_cb(Dwarf_Die *sp_die, void *data) param->retval =find_probe_point_by_line (pf); }else if (die_is_func_instance (sp_die)) {/* Instances always have the entry address */ -dwarf_entrypc (sp_die, &pf->addr); +die_entrypc (sp_die, &pf->addr);/* But in some case the entry address is 0 */ if (pf->addr ==0 ) { pr_debug("%s has no entry PC. Skipped\n",
PATCH v2 3/6 perf/probe: Fix to probe an inline function which has no entry pc
In reply to Masami HiramatsuFix perf probe to probe an inlne function which has no entry pc or low pc but only has ranges attribute.
This seems very rare case, but I could find a few examples, as same as probe_point_search_cb(), use die_entrypc() to get the entry address in probe_point_inline_cb() too.
Without this patch,
# perf probe -D __amd_put_nb_event_constraints
Failed to get entry address of __amd_put_nb_event_constraints.
Probe point '__amd_put_nb_event_constraints' not found.
Error: Failed to add events.With this patch,
# perf probe -D __amd_put_nb_event_constraints p:probe/__amd_put_nb_event_constraints _text+34059
--- tools/perf/util/probe-finder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/probe-finder.c +1 -1
@@ -930,7 +930,7 @@ static int probe_point_inline_cb(Dwarf_Die *in_die, void *data) ret =find_probe_point_lazy (in_die, pf); else {/* Get probe address */ -if (dwarf_entrypc (in_die, &addr) !=0 ) { +if (die_entrypc (in_die, &addr) !=0 ) {pr_warning ("Failed to get entry address of %s.\n" ,dwarf_diename (in_die));return -ENOENT ;
PATCH v2 4/6 perf/probe: Fix to list probe event with correct line number
In reply to Masami HiramatsuSince debuginfo__find_probe_point() uses dwarf_entrypc() for finding the entry address of the function on which a probe is, it will fail when the function DIE has only ranges attribute.
To fix this issue, use die_entrypc() instead of dwarf_entrypc().
Without this fix, perf probe -l shows incorrect offset.
# perf probe --force -a clear_tasks_mm_cpumask:0 clear_tasks_mm_cpumask:21
Added new events:
probe:clear_tasks_mm_cpumask (on clear_tasks_mm_cpumask)
probe:clear_tasks_mm_cpumask_1 (on clear_tasks_mm_cpumask:21)You can now use it in all perf tools, such as:
perf record -e probe:clear_tasks_mm_cpumask_1 -aR sleep 1
# perf probe -l
probe:clear_tasks_mm_cpumask (on [email protected]/kernel/cpu.c)
probe:clear_tasks_mm_cpumask_1 (on [email protected]/kernel/cpu.c)With this,
# perf probe -l
probe:clear_tasks_mm_cpumask (on [email protected]/kernel/cpu.c)
probe:clear_tasks_mm_cpumask_1 (on clear_tasks_mm_cpumask:[email protected]/kernel/cpu.c)--- tools/perf/util/probe-finder.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/probe-finder.c +2 -2
@@ -1566,7 +1566,7 @@ int debuginfo__find_probe_point(struct debuginfo *dbg, unsigned long addr,/* Get function entry information */ func = basefunc =dwarf_diename (&spdie);if (!func || -dwarf_entrypc (&spdie, &baseaddr) !=0 || +die_entrypc (&spdie, &baseaddr) !=0 ||dwarf_decl_line (&spdie, &baseline) !=0 ) { lineno =0 ; goto post;
@@ -1583,7 +1583,7 @@ int debuginfo__find_probe_point(struct debuginfo *dbg, unsigned long addr,while (die_find_top_inlinefunc (&spdie, (Dwarf_Addr )addr, &indie)) {/* There is an inline function */ -if (dwarf_entrypc (&indie, &_addr) ==0 && +if (die_entrypc (&indie, &_addr) ==0 && _addr == addr) {/* * addr is at an inline function entry.
PATCH v2 5/6 perf/probe: Fix to show inlined function callsite without entry_pc
In reply to Masami HiramatsuFix perf-probe --line option to show inlined function callsite lines even if the function DIE has only ranges.
Without this,
# perf probe -L amd_put_event_constraints
<amd_put_event_constraints@/build/linux-pvZVvI/linux-5.0.0/arch/x86/events/amd/core.c:0>
0 static void amd_put_event_constraints(struct cpu_hw_events *cpuc,
struct perf_event *event)
2 {
3 if (amd_has_nb(cpuc) && amd_is_nb_event(&event->hw))
__amd_put_nb_event_constraints(cpuc, event);
5 }With this patch,
# perf probe -L amd_put_event_constraints
<amd_put_event_constraints@/build/linux-pvZVvI/linux-5.0.0/arch/x86/events/amd/core.c:0>
0 static void amd_put_event_constraints(struct cpu_hw_events *cpuc,
struct perf_event *event)
2 {
3 if (amd_has_nb(cpuc) && amd_is_nb_event(&event->hw))
4 __amd_put_nb_event_constraints(cpuc, event);
5 }--- tools/perf/util/dwarf-aux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/dwarf-aux.c +1 -1
@@ -695,7 +695,7 @@ static int __die_walk_funclines_cb(Dwarf_Die *in_die, void *data)if (dwarf_tag (in_die) == DW_TAG_inlined_subroutine) { fname =die_get_call_file (in_die); lineno =die_get_call_lineno (in_die); -if (fname && lineno >0 &&dwarf_entrypc (in_die, &addr) ==0 ) { +if (fname && lineno >0 &&die_entrypc (in_die, &addr) ==0 ) { lw->retval = lw->callback (fname, lineno, addr, lw->data);if (lw->retval !=0 )return DIE_FIND_CB_END ;
PATCH v2 6/6 perf/probe: Fix to show ranges of variables in functions without entry_pc
In reply to Masami HiramatsuFix to show ranges of variables (--range and --vars option) in functions which DIE has only ranges but no entry_pc attribute.
Without this fix,
# perf probe --range -V clear_tasks_mm_cpumask Available variables at clear_tasks_mm_cpumask @<clear_tasks_mm_cpumask+0> (No matched variables)
With this fix,
# perf probe --range -V clear_tasks_mm_cpumask
Available variables at clear_tasks_mm_cpumask
@<clear_tasks_mm_cpumask+0>
[VAL] int cpu @<clear_tasks_mm_cpumask+[0-62,104-109,1881-1888]>--- tools/perf/util/dwarf-aux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/dwarf-aux.c +2 -2
@@ -1019,7 +1019,7 @@ static int die_get_var_innermost_scope(Dwarf_Die *sp_die, Dwarf_Die *vr_die,bool first = true;const char *name; - ret =dwarf_entrypc (sp_die, &entry); + ret =die_entrypc (sp_die, &entry);if (ret)return ret;
@@ -1082,7 +1082,7 @@ int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf)bool first = true;const char *name; - ret =dwarf_entrypc (sp_die, &entry); + ret =die_entrypc (sp_die, &entry);if (ret)return ret;
Em Sat, Oct 26, 2019 at 06:00:19PM +0900, Masami Hiramatsu escreveu:
Quoted 7 lines
Hi Arnaldo,
I've updated examples in patch description in this v2. No changes in the code itself. I ran it on Ubuntu 19.04 (linux-5.0.0-32-generic).
Please replace previous one with this.
Can you please take a look at my perf/core branch? I have these already there:
5e72f4349eff perf probe: Fix to show ranges of variables in functions without entry_pc 50fc0fda5f2c perf probe: Fix to show inlined function callsite without entry_pc d7bf48229b85 perf probe: Fix to list probe event with correct line number 39cee497850a perf probe: Fix to probe an inline function which has no entry pc 6150bad27ebd perf probe: Fix to probe a function which has no entry pc fdaea9eea92d perf probe: Fix wrong address verification
And I added committer notes doing the tests.
- Arnaldo
Quoted 19 lines
Thank you,
---
Masami Hiramatsu (6):
perf/probe: Fix wrong address verification
perf/probe: Fix to probe a function which has no entry pc perf/probe: Fix to probe an inline function which has no entry pc perf/probe: Fix to list probe event with correct line number perf/probe: Fix to show inlined function callsite withoutentry_pcperf/probe: Fix to show ranges of variables in functions withoutentry_pctools/perf/util/dwarf-aux.c | 6 +++--- tools/perf/util/probe-finder.c | 40 ++++++++++++++-------------------------- 2 files changed, 17 insertions(+), 29 deletions(-)--
Masami Hiramatsu (Linaro) <[email protected]>
Signature · 1 line
- Arnaldo
Quoted 12 lines · On Mon, 28 Oct 2019 11:16:55 -0300 Arnaldo Carvalho de Melo <[email protected]>…
Em Sat, Oct 26, 2019 at 06:00:19PM +0900, Masami Hiramatsu escreveu:
Quoted 7 lines
Hi Arnaldo,
I've updated examples in patch description in this v2. No changes in the code itself. I ran it on Ubuntu 19.04 (linux-5.0.0-32-generic).
Please replace previous one with this.
Can you please take a look at my perf/core branch? I have these already there:
Quoted 8 lines
5e72f4349effperf probe: Fix to show ranges of variables in functions withoutentry_pc50fc0fda5f2cperf probe: Fix to show inlined function callsite withoutentry_pcd7bf48229b85perf probe: Fix to list probe event with correct line number39cee497850aperf probe: Fix to probe an inline function which has no entry pc6150bad27ebdperf probe: Fix to probe a function which has no entry pcfdaea9eea92dperf probe: Fix wrong address verificationAnd I added committer notes doing the tests.
Yes, I confirmed your comments on the patches. It looks good to me.
Thank you!
Quoted 26 lines
- Arnaldo
Quoted 19 lines
Thank you,
---
Masami Hiramatsu (6):
perf/probe: Fix wrong address verification
perf/probe: Fix to probe a function which has no entry pc perf/probe: Fix to probe an inline function which has no entry pc perf/probe: Fix to list probe event with correct line number perf/probe: Fix to show inlined function callsite withoutentry_pcperf/probe: Fix to show ranges of variables in functions withoutentry_pctools/perf/util/dwarf-aux.c | 6 +++--- tools/perf/util/probe-finder.c | 40 ++++++++++++++-------------------------- 2 files changed, 17 insertions(+), 29 deletions(-)--
Masami Hiramatsu (Linaro) <[email protected]>Signature · 1 line
- Arnaldo
Signature · 1 line
Masami Hiramatsu <[email protected]>