[RFCv5 00/19] perf: Add backtrace post dwarf unwind

June 11th, 2012 - 09:30 am ET by Jiri Olsa | Report spam
hi,
besides fixing several issues, going back to the original design
because the last one was considered too generic.. now we have:

sample_regs_user - != 0 triggers the user level regs dump
sample_stack_user - != 0 triggers the user stack dump

We can allway extend this in future with new mask and flags
for IRQ/PEBS regs.

patches available also as tarball in here:
http://people.redhat.com/~jolsa/perf_post_unwind_v5.tar.bz2

v5 changes:
patch 1/19 - having just one enum set of the perf registers
patch 2/19 - using for_each_set_bit for scanning the mask
- single regs enum for both 32 and 64 bits versions
- using regs mask != 0 trigger to trigger the regs dump
patch 5/19 - adding perf_output_skip so we can skip undumped part of the stack in RB
patch 6/19 - using stack size != 0 trigger to trigger the stack dump
- do not zero the memory for non retrieved part of the stack dump
patch 7/19 - adding exclude_callchain_kernel attribute
patch 8/19 - this could be taken without the rest of the series

v4 changes:
- no real change from v3, just rebase
- v3 patch 06/17 got already merged

v3 changes:
patch 01/17
- added HAVE_PERF_REGS config option
patch 02/17, 04/17
- regs and stack perf interface is more general now
patch 06/17
- unrelated online fix for i386 compilation
patch 16/17
- few namespace fixies


Adding the post unwinding user stack backtrace using dwarf unwind
via libunwind. The original work was done by Frederic. I mostly took
his patches and make them compile in current kernel code plus I added
some stuff here and there.

The main idea is to store user registers and portion of user
stack when the sample data during the record phase. Then during
the report, when the data is presented, perform the actual dwarf
dwarf unwind.

attached patches:
01/19 perf: Unified API to record selective sets of arch registers
02/19 perf: Add ability to attach user level registers dump to sample
03/19 perf, x86: Add copy_from_user_nmi_nochk for best effort copy
04/19 perf: Factor __output_copy to be usable with specific copy function
05/19 perf: Add perf_output_skip function to skip bytes in sample
06/19 perf: Add ability to attach user stack dump to sample
07/19 perf: Add attribute to filter out callchains
08/19 perf, tool: Remove unsused evsel parameter from machine__resolve_callchain
09/19 perf, tool: Factor DSO symtab types to generic binary types
10/19 perf, tool: Add interface to read DSO image data
11/19 perf, tool: Add '.note' check into search for NOTE section
12/19 perf, tool: Back [vdso] DSO with real data
13/19 perf, tool: Add interface to arch registers sets
14/19 perf, tool: Add libunwind dependency for dwarf cfi unwinding
15/19 perf, tool: Support user regs and stack in sample parsing
16/19 perf, tool: Support for dwarf cfi unwinding on post processing
17/19 perf, tool: Support for dwarf mode callchain on perf record
18/19 perf, tool: Add dso data caching
19/19 perf, tool: Add dso data caching tests


I tested on Fedora. There was not much gain on i386, because the
binaries are compiled with frame pointers. Thought the dwarf
backtrace is more accurade and unwraps calls in more details
(functions that do not set the frame pointers).

I could see some improvement on x86_64, where I got full backtrace
where current code could got just the first address out of the
instruction pointer.

Example on x86_64:
[dwarf]
perf record -g -e syscalls:sys_enter_write date

100.00% date libc-2.14.90.so [.] __GI___libc_write
|
__GI___libc_write
_IO_file_write@@GLIBC_2.2.5
new_do_write
_IO_do_write@@GLIBC_2.2.5
_IO_file_overflow@@GLIBC_2.2.5
0x4022cd
0x401ee6
__libc_start_main
0x4020b9


[frame pointer]
perf record -g fp -e syscalls:sys_enter_write date

100.00% date libc-2.14.90.so [.] __GI___libc_write
|
__GI___libc_write

Also I tested on coreutils binaries mainly, but I could see
getting wider backtraces with dwarf unwind for more complex
application like firefox.

The unwind should go throught [vdso] object. I haven't studied
the [vsyscall] yet, so not sure there.

Attached patches should work on both x86 and x86_64. I did
some initial testing so far.

The unwind backtrace can be interrupted by following reasons:
- bug in unwind information of processed shared library
- bug in unwind processing code (most likely ;) )
- insufficient dump stack size
- wrong register value - x86_64 does not store whole
set of registers when in exception, but so far
it looks like RIP and RSP should be enough

thanks for comments,
jirka

arch/Kconfig | 6 +
arch/x86/Kconfig | 1 +
arch/x86/include/asm/perf_event.h | 2 +
arch/x86/include/asm/perf_regs.h | 34 ++
arch/x86/include/asm/uaccess.h | 2 +
arch/x86/kernel/Makefile | 2 +
arch/x86/kernel/perf_regs.c | 91 ++++
arch/x86/lib/usercopy.c | 15 +-
include/linux/perf_event.h | 24 +-
include/linux/perf_regs.h | 19 +
kernel/events/callchain.c | 25 +-
kernel/events/core.c | 132 +++++-
kernel/events/internal.h | 69 ++-
kernel/events/ring_buffer.c | 10 +-
tools/perf/Makefile | 45 ++-
tools/perf/arch/x86/Makefile | 3 +
tools/perf/arch/x86/include/perf_regs.h | 80 +++
tools/perf/arch/x86/util/unwind.c | 111 ++++
tools/perf/builtin-record.c | 86 +++-
tools/perf/builtin-report.c | 24 +-
tools/perf/builtin-script.c | 56 ++-
tools/perf/builtin-test.c | 7 +-
tools/perf/builtin-top.c | 7 +-
tools/perf/config/feature-tests.mak | 25 +
tools/perf/perf.h | 9 +-
tools/perf/util/annotate.c | 2 +-
tools/perf/util/dso-test-data.c | 154 ++++++
tools/perf/util/event.h | 15 +-
tools/perf/util/evlist.c | 16 +
tools/perf/util/evlist.h | 2 +
tools/perf/util/evsel.c | 35 ++-
tools/perf/util/include/linux/compiler.h | 1 +
tools/perf/util/map.c | 23 +-
tools/perf/util/map.h | 9 +-
tools/perf/util/perf_regs.h | 14 +
tools/perf/util/python.c | 3 +-
.../perf/util/scripting-engines/trace-event-perl.c | 3 +-
.../util/scripting-engines/trace-event-python.c | 3 +-
tools/perf/util/session.c | 110 ++++-
tools/perf/util/session.h | 17 +-
tools/perf/util/symbol.c | 435 +++++++++++++
tools/perf/util/symbol.h | 52 ++-
tools/perf/util/trace-event-scripting.c | 3 +-
tools/perf/util/trace-event.h | 5 +-
tools/perf/util/unwind.c | 565 ++++++++++++++++++++
tools/perf/util/unwind.h | 34 ++
tools/perf/util/vdso.c | 90 +++
tools/perf/util/vdso.h | 8 +
48 files changed, 2278 insertions(+), 206 deletions(-)
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
email Follow the discussionReplies 16 repliesReplies Make a reply

Replies

#1 Jiri Olsa
June 11th, 2012 - 09:30 am ET | Report spam
Removing unsused evsel parameter from machine__resolve_callchain
function. Plus related header file and callers changes.

The evsel parameter is unused since following commit:
perf callchain: Make callchain cursors TLS
commit 472606458f3e1ced5fe3cc5f04e90a6b5a4732cf
Author: Namhyung Kim
Date: Thu May 31 14:43:26 2012 +0900

Signed-off-by: Jiri Olsa

tools/perf/builtin-report.c | 4 ++--
tools/perf/builtin-script.c | 4 ++--
tools/perf/builtin-top.c | 2 +-
tools/perf/util/map.h | 2 +-
tools/perf/util/session.c | 7 +++-
tools/perf/util/session.h | 4 ++--
6 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 25249f7..d20ef95 100644
a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -69,7 +69,7 @@ static int perf_report__add_branch_hist_entry(struct perf_tool *tool,

if ((sort__has_parent || symbol_conf.use_callchain)
&& sample->callchain) {
- err = machine__resolve_callchain(machine, evsel, al->thread,
+ err = machine__resolve_callchain(machine, al->thread,
sample->callchain, &parent);
if (err)
return err;
@@ -140,7 +140,7 @@ static int perf_evsel__add_hist_entry(struct perf_evsel *evsel,
struct hist_entry *he;

if ((sort__has_parent || symbol_conf.use_callchain) && sample->callchain) {
- err = machine__resolve_callchain(machine, evsel, al->thread,
+ err = machine__resolve_callchain(machine, al->thread,
sample->callchain, &parent);
if (err)
return err;
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 8e395a5..05aa2bb 100644
a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -387,7 +387,7 @@ static void print_sample_bts(union perf_event *event,
printf(" ");
else
printf("");
- perf_event__print_ip(event, sample, machine, evsel,
+ perf_event__print_ip(event, sample, machine,
PRINT_FIELD(SYM), PRINT_FIELD(DSO),
PRINT_FIELD(SYMOFFSET));
}
@@ -431,7 +431,7 @@ static void process_event(union perf_event *event __unused,
printf(" ");
else
printf("");
- perf_event__print_ip(event, sample, machine, evsel,
+ perf_event__print_ip(event, sample, machine,
PRINT_FIELD(SYM), PRINT_FIELD(DSO),
PRINT_FIELD(SYMOFFSET));
}
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 6bb0277..79cabe4 100644
a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -774,7 +774,7 @@ static void perf_event__process_sample(struct perf_tool *tool,

if ((sort__has_parent || symbol_conf.use_callchain) &&
sample->callchain) {
- err = machine__resolve_callchain(machine, evsel, al.thread,
+ err = machine__resolve_callchain(machine, al.thread,
sample->callchain, &parent);
if (err)
return;
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index 81371ba..c14c665 100644
a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -157,7 +157,7 @@ void machine__exit(struct machine *self);
void machine__delete(struct machine *self);

int machine__resolve_callchain(struct machine *machine,
- struct perf_evsel *evsel, struct thread *thread,
+ struct thread *thread,
struct ip_callchain *chain,
struct symbol **parent);
int maps__set_kallsyms_ref_reloc_sym(struct map **maps, const char *symbol_name,
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 2600916..2785ce8 100644
a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -289,7 +289,6 @@ struct branch_info *machine__resolve_bstack(struct machine *self,
}

int machine__resolve_callchain(struct machine *self,
- struct perf_evsel *evsel __used,
struct thread *thread,
struct ip_callchain *chain,
struct symbol **parent)
@@ -1480,8 +1479,8 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
}

void perf_event__print_ip(union perf_event *event, struct perf_sample *sample,
- struct machine *machine, struct perf_evsel *evsel,
- int print_sym, int print_dso, int print_symoffset)
+ struct machine *machine, int print_sym,
+ int print_dso, int print_symoffset)
{
struct addr_location al;
struct callchain_cursor_node *node;
@@ -1495,7 +1494,7 @@ void perf_event__print_ip(union perf_event *event, struct perf_sample *sample,

if (symbol_conf.use_callchain && sample->callchain) {

- if (machine__resolve_callchain(machine, evsel, al.thread,
+ if (machine__resolve_callchain(machine, al.thread,
sample->callchain, NULL) != 0) {
if (verbose)
error("Failed to resolve callchain. Skipping");
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 7a5434c..877d781 100644
a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -150,8 +150,8 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
unsigned int type);

void perf_event__print_ip(union perf_event *event, struct perf_sample *sample,
- struct machine *machine, struct perf_evsel *evsel,
- int print_sym, int print_dso, int print_symoffset);
+ struct machine *machine, int print_sym,
+ int print_dso, int print_symoffset);

int perf_session__cpu_bitmap(struct perf_session *session,
const char *cpu_list, unsigned long *cpu_bitmap);
1.7.7.6

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Similar topics