Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1553589 > unrolled thread
| Started by | Masami Hiramatsu <mhiramat@kernel.org> |
|---|---|
| First post | 2017-01-07 06:30 +0100 |
| Last post | 2017-01-10 17:00 +0100 |
| Articles | 4 — 1 participant |
Back to article view | Back to linux.kernel
[PATCH perf/core 0/4] perf-probe: Fix and improve module probe events Masami Hiramatsu <mhiramat@kernel.org> - 2017-01-07 06:30 +0100
[PATCH perf/core 3/4] perf-probe: Fix to probe on gcc generated functions in modules Masami Hiramatsu <mhiramat@kernel.org> - 2017-01-07 06:30 +0100
[PATCH perf/core 4/4] perf-probe: Find probe events without target module Masami Hiramatsu <mhiramat@kernel.org> - 2017-01-07 06:30 +0100
Re: [PATCH perf/core 4/4] perf-probe: Find probe events without target module Masami Hiramatsu <mhiramat@kernel.org> - 2017-01-10 17:00 +0100
| From | Masami Hiramatsu <mhiramat@kernel.org> |
|---|---|
| Date | 2017-01-07 06:30 +0100 |
| Subject | [PATCH perf/core 0/4] perf-probe: Fix and improve module probe events |
| Message-ID | <sWRJL-4oE-3@gated-at.bofh.it> |
Hello,
This series fixes some issues on offline/online module
probe support and improve perf-probe to probe module
without -m option (Thanks Arnaldo!).
This includes below patches.
- [1/4] Fix perf-probe --list to show correct probe location
in module.
- [2/4] Improve error checking for the probes for offline
kernel.
- [3/4] (V2) Fix perf-probe to probe correctly on gcc generated
functions in module.
- [4/4] Improve perf-probe to find probe events in module
without -m option.
Thank you,
---
Masami Hiramatsu (4):
perf-probe: Fix to show correct locations for events on modules
perf-probe: Add error checks to offline probe post-processing
perf-probe: Fix to probe on gcc generated functions in modules
perf-probe: Find probe events without target module
tools/perf/util/probe-event.c | 165 ++++++++++++++++++++++++++++------------
tools/perf/util/probe-finder.c | 15 ++--
tools/perf/util/probe-finder.h | 3 +
3 files changed, 125 insertions(+), 58 deletions(-)
--
Masami Hiramatsu (Linaro)
[toc] | [next] | [standalone]
| From | Masami Hiramatsu <mhiramat@kernel.org> |
|---|---|
| Date | 2017-01-07 06:30 +0100 |
| Subject | [PATCH perf/core 3/4] perf-probe: Fix to probe on gcc generated functions in modules |
| Message-ID | <sWRJM-4oE-7@gated-at.bofh.it> |
| In reply to | #1553589 |
Fix to probe on gcc generated functions on modules. Since
probing on a module is based on its symbol name, it should
be adjusted on actual symbols.
E.g. without this fix, perf probe shows probe definition
on non-exist symbol as below.
$ perf probe -m build-x86_64/net/netfilter/nf_nat.ko -F in_range*
in_range.isra.12
$ perf probe -m build-x86_64/net/netfilter/nf_nat.ko -D in_range
p:probe/in_range nf_nat:in_range+0
With this fix, perf probe correctly shows a probe on
gcc-generated symbol.
$ perf probe -m build-x86_64/net/netfilter/nf_nat.ko -D in_range
p:probe/in_range nf_nat:in_range.isra.12+0
This also fixes same problem on online module as below.
$ perf probe -m i915 -D assert_plane
p:probe/assert_plane i915:assert_plane.constprop.134+0
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
tools/perf/util/probe-event.c | 45 ++++++++++++++++++++++++++--------------
tools/perf/util/probe-finder.c | 7 ++++--
tools/perf/util/probe-finder.h | 3 +++
3 files changed, 37 insertions(+), 18 deletions(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index aa8a922..6a6f44d 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -698,18 +698,31 @@ static int add_exec_to_probe_trace_events(struct probe_trace_event *tevs,
return ret;
}
-static int add_module_to_probe_trace_events(struct probe_trace_event *tevs,
- int ntevs, const char *module)
+static int
+post_process_module_probe_trace_events(struct probe_trace_event *tevs,
+ int ntevs, const char *module,
+ struct debuginfo *dinfo)
{
+ Dwarf_Addr text_offs = 0;
int i, ret = 0;
char *mod_name = NULL;
+ struct map *map;
if (!module)
return 0;
- mod_name = find_module_name(module);
+ map = get_target_map(module, false);
+ if (!map || debuginfo__get_text_offset(dinfo, &text_offs, true) < 0) {
+ pr_warning("Failed to get ELF symbols for %s\n", module);
+ return -EINVAL;
+ }
+ mod_name = find_module_name(module);
for (i = 0; i < ntevs; i++) {
+ ret = post_process_probe_trace_point(&tevs[i].point,
+ map, (unsigned long)text_offs);
+ if (ret < 0)
+ break;
tevs[i].point.module =
strdup(mod_name ? mod_name : module);
if (!tevs[i].point.module) {
@@ -719,6 +732,8 @@ static int add_module_to_probe_trace_events(struct probe_trace_event *tevs,
}
free(mod_name);
+ map__put(map);
+
return ret;
}
@@ -776,7 +791,7 @@ arch__post_process_probe_trace_events(struct perf_probe_event *pev __maybe_unuse
static int post_process_probe_trace_events(struct perf_probe_event *pev,
struct probe_trace_event *tevs,
int ntevs, const char *module,
- bool uprobe)
+ bool uprobe, struct debuginfo *dinfo)
{
int ret;
@@ -784,7 +799,8 @@ static int post_process_probe_trace_events(struct perf_probe_event *pev,
ret = add_exec_to_probe_trace_events(tevs, ntevs, module);
else if (module)
/* Currently ref_reloc_sym based probe is not for drivers */
- ret = add_module_to_probe_trace_events(tevs, ntevs, module);
+ ret = post_process_module_probe_trace_events(tevs, ntevs,
+ module, dinfo);
else
ret = post_process_kernel_probe_trace_events(tevs, ntevs);
@@ -828,30 +844,27 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
}
}
- debuginfo__delete(dinfo);
-
if (ntevs > 0) { /* Succeeded to find trace events */
pr_debug("Found %d probe_trace_events.\n", ntevs);
ret = post_process_probe_trace_events(pev, *tevs, ntevs,
- pev->target, pev->uprobes);
+ pev->target, pev->uprobes, dinfo);
if (ret < 0 || ret == ntevs) {
+ pr_debug("Post processing failed or all events are skipped. (%d)\n", ret);
clear_probe_trace_events(*tevs, ntevs);
zfree(tevs);
+ ntevs = 0;
}
- if (ret != ntevs)
- return ret < 0 ? ret : ntevs;
- ntevs = 0;
- /* Fall through */
}
+ debuginfo__delete(dinfo);
+
if (ntevs == 0) { /* No error but failed to find probe point. */
pr_warning("Probe point '%s' not found.\n",
synthesize_perf_probe_point(&pev->point));
return -ENOENT;
- }
- /* Error path : ntevs < 0 */
- pr_debug("An error occurred in debuginfo analysis (%d).\n", ntevs);
- if (ntevs < 0) {
+ } else if (ntevs < 0) {
+ /* Error path : ntevs < 0 */
+ pr_debug("An error occurred in debuginfo analysis (%d).\n", ntevs);
if (ntevs == -EBADF)
pr_warning("Warning: No dwarf info found in the vmlinux - "
"please rebuild kernel with CONFIG_DEBUG_INFO=y.\n");
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 0278fe1..0d9d6e0 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -1501,7 +1501,8 @@ int debuginfo__find_available_vars_at(struct debuginfo *dbg,
}
/* For the kernel module, we need a special code to get a DIE */
-static int debuginfo__get_text_offset(struct debuginfo *dbg, Dwarf_Addr *offs)
+int debuginfo__get_text_offset(struct debuginfo *dbg, Dwarf_Addr *offs,
+ bool adjust_offset)
{
int n, i;
Elf32_Word shndx;
@@ -1530,6 +1531,8 @@ static int debuginfo__get_text_offset(struct debuginfo *dbg, Dwarf_Addr *offs)
if (!shdr)
return -ENOENT;
*offs = shdr->sh_addr;
+ if (adjust_offset)
+ *offs -= shdr->sh_offset;
}
}
return 0;
@@ -1545,7 +1548,7 @@ int debuginfo__find_probe_point(struct debuginfo *dbg, unsigned long addr,
int baseline = 0, lineno = 0, ret = 0;
/* We always need to relocate the address for aranges */
- if (debuginfo__get_text_offset(dbg, &baseaddr) == 0)
+ if (debuginfo__get_text_offset(dbg, &baseaddr, false) == 0)
addr += baseaddr;
/* Find cu die */
if (!dwarf_addrdie(dbg->dbg, (Dwarf_Addr)addr, &cudie)) {
diff --git a/tools/perf/util/probe-finder.h b/tools/perf/util/probe-finder.h
index f1d8558..2956c51 100644
--- a/tools/perf/util/probe-finder.h
+++ b/tools/perf/util/probe-finder.h
@@ -46,6 +46,9 @@ int debuginfo__find_trace_events(struct debuginfo *dbg,
int debuginfo__find_probe_point(struct debuginfo *dbg, unsigned long addr,
struct perf_probe_point *ppt);
+int debuginfo__get_text_offset(struct debuginfo *dbg, Dwarf_Addr *offs,
+ bool adjust_offset);
+
/* Find a line range */
int debuginfo__find_line_range(struct debuginfo *dbg, struct line_range *lr);
[toc] | [prev] | [next] | [standalone]
| From | Masami Hiramatsu <mhiramat@kernel.org> |
|---|---|
| Date | 2017-01-07 06:30 +0100 |
| Subject | [PATCH perf/core 4/4] perf-probe: Find probe events without target module |
| Message-ID | <sWRJM-4oE-11@gated-at.bofh.it> |
| In reply to | #1553589 |
Find probe events without -m "module" option. If perf-probe
failed to find given function in kernel image, it tries to
find same symbol and module in kallsyms, and retry search
in the found module. E.g.
# perf probe -D i915_capabilities
p:probe/i915_capabilities i915:i915_capabilities+0
Note: without -m option, perf probe can not find inlined
function since there is no symbol information in kallsyms.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Suggested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/probe-event.c | 74 ++++++++++++++++++++++++++++++-----------
1 file changed, 55 insertions(+), 19 deletions(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 6a6f44d..09bd093 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -858,11 +858,7 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
debuginfo__delete(dinfo);
- if (ntevs == 0) { /* No error but failed to find probe point. */
- pr_warning("Probe point '%s' not found.\n",
- synthesize_perf_probe_point(&pev->point));
- return -ENOENT;
- } else if (ntevs < 0) {
+ if (ntevs < 0) {
/* Error path : ntevs < 0 */
pr_debug("An error occurred in debuginfo analysis (%d).\n", ntevs);
if (ntevs == -EBADF)
@@ -2073,8 +2069,10 @@ static int find_perf_probe_point_from_map(struct probe_trace_point *tp,
} else {
if (tp->symbol && !addr) {
if (kernel_get_symbol_address_by_name(tp->symbol,
- &addr, true, false) < 0)
+ &addr, true, false) < 0) {
+ ret = 0;
goto out;
+ }
}
if (addr) {
addr += tp->offset;
@@ -2829,9 +2827,7 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev,
*/
num_matched_functions = find_probe_functions(map, pp->function, syms);
if (num_matched_functions == 0) {
- pr_err("Failed to find symbol %s in %s\n", pp->function,
- pev->target ? : "kernel");
- ret = -ENOENT;
+ ret = 0;
goto out;
} else if (num_matched_functions > probe_conf.max_probes) {
pr_err("Too many functions matched in %s\n",
@@ -3233,6 +3229,43 @@ static int find_probe_trace_events_from_cache(struct perf_probe_event *pev,
return ret;
}
+static int __convert_to_probe_trace_events(struct perf_probe_event *pev,
+ struct probe_trace_event **tevs)
+{
+ int ret;
+
+ /* At first, we need to lookup cache entry */
+ ret = find_probe_trace_events_from_cache(pev, tevs);
+ if (ret > 0 || pev->sdt) /* SDT can be found only in the cache */
+ return ret == 0 ? -ENOENT : ret; /* Found in probe cache */
+
+ /* Convert perf_probe_event with debuginfo */
+ ret = try_to_find_probe_trace_events(pev, tevs);
+ if (ret != 0)
+ return ret; /* Found in debuginfo or got an error */
+
+ return find_probe_trace_events_from_map(pev, tevs);
+}
+
+static char *find_module_from_kallsyms(const char *symbol_name)
+{
+ struct machine *machine = machine__new_kallsyms();
+ struct symbol *sym;
+ struct map *map;
+ char *module;
+
+ pr_debug("Try to find module for %s\n", symbol_name);
+ sym = machine__find_kernel_function_by_name(machine, symbol_name, &map);
+ if (!sym || map->dso->short_name[0] != '[')
+ return NULL;
+ pr_debug("Found: %s in %s\n", sym->name, map->dso->short_name);
+ module = strdup(map->dso->short_name + 1);
+ if (module)
+ module[strlen(module) - 1] = '\0';
+
+ return module;
+}
+
static int convert_to_probe_trace_events(struct perf_probe_event *pev,
struct probe_trace_event **tevs)
{
@@ -3255,17 +3288,20 @@ static int convert_to_probe_trace_events(struct perf_probe_event *pev,
if (ret > 0)
return ret;
- /* At first, we need to lookup cache entry */
- ret = find_probe_trace_events_from_cache(pev, tevs);
- if (ret > 0 || pev->sdt) /* SDT can be found only in the cache */
- return ret == 0 ? -ENOENT : ret; /* Found in probe cache */
-
- /* Convert perf_probe_event with debuginfo */
- ret = try_to_find_probe_trace_events(pev, tevs);
- if (ret != 0)
- return ret; /* Found in debuginfo or got an error */
+ ret = __convert_to_probe_trace_events(pev, tevs);
+ /* Not found. will retry to check kmodule if possible */
+ if (ret == 0 && !pev->uprobes && !pev->target) {
+ pev->target = find_module_from_kallsyms(pev->point.function);
+ if (pev->target)
+ ret = __convert_to_probe_trace_events(pev, tevs);
+ }
- return find_probe_trace_events_from_map(pev, tevs);
+ if (ret == 0) {
+ pr_warning("Probe point '%s' not found.\n",
+ synthesize_perf_probe_point(&pev->point));
+ ret = -ENOENT;
+ }
+ return ret;
}
int convert_perf_probe_events(struct perf_probe_event *pevs, int npevs)
[toc] | [prev] | [next] | [standalone]
| From | Masami Hiramatsu <mhiramat@kernel.org> |
|---|---|
| Date | 2017-01-10 17:00 +0100 |
| Subject | Re: [PATCH perf/core 4/4] perf-probe: Find probe events without target module |
| Message-ID | <sY70b-3cI-27@gated-at.bofh.it> |
| In reply to | #1553591 |
On Sat, 7 Jan 2017 14:28:42 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:
> Find probe events without -m "module" option. If perf-probe
> failed to find given function in kernel image, it tries to
> find same symbol and module in kallsyms, and retry search
> in the found module. E.g.
>
> # perf probe -D i915_capabilities
> p:probe/i915_capabilities i915:i915_capabilities+0
>
> Note: without -m option, perf probe can not find inlined
> function since there is no symbol information in kallsyms.
>
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> Suggested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
> tools/perf/util/probe-event.c | 74 ++++++++++++++++++++++++++++++-----------
> 1 file changed, 55 insertions(+), 19 deletions(-)
>
> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> index 6a6f44d..09bd093 100644
> --- a/tools/perf/util/probe-event.c
> +++ b/tools/perf/util/probe-event.c
> @@ -858,11 +858,7 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
>
> debuginfo__delete(dinfo);
>
> - if (ntevs == 0) { /* No error but failed to find probe point. */
> - pr_warning("Probe point '%s' not found.\n",
> - synthesize_perf_probe_point(&pev->point));
> - return -ENOENT;
> - } else if (ntevs < 0) {
> + if (ntevs < 0) {
> /* Error path : ntevs < 0 */
> pr_debug("An error occurred in debuginfo analysis (%d).\n", ntevs);
> if (ntevs == -EBADF)
> @@ -2073,8 +2069,10 @@ static int find_perf_probe_point_from_map(struct probe_trace_point *tp,
> } else {
> if (tp->symbol && !addr) {
> if (kernel_get_symbol_address_by_name(tp->symbol,
> - &addr, true, false) < 0)
> + &addr, true, false) < 0) {
> + ret = 0;
> goto out;
Oops, I've found that this is not needed and breaks --list result.
I'll update it.
Thanks.
--
Masami Hiramatsu <mhiramat@kernel.org>
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web