All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC 00/15] perf: Add backtrace post dwarf unwind
@ 2012-03-28 12:35 Jiri Olsa
  2012-03-28 12:35 ` [PATCH 01/15] perf, tool: Fix the array pointer to follow event data properly Jiri Olsa
                   ` (15 more replies)
  0 siblings, 16 replies; 36+ messages in thread
From: Jiri Olsa @ 2012-03-28 12:35 UTC (permalink / raw)
  To: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec
  Cc: eranian, gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	fche, linux-kernel

hi,
sending RFC version of 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/15 perf, tool: Fix the array pointer to follow event data properly
 02/15 uaccess: Add new copy_from_user_gup API
 03/15 perf: Unified API to record selective sets of arch registers
 04/15 perf: Add ability to dump user regs
 05/15 perf: Add ability to dump part of the user stack
 06/15 perf: Add attribute to filter out user callchains
 07/15 perf, tool: Factor DSO symtab types to generic binary types
 08/15 perf, tool: Add interface to read DSO image data
 09/15 perf, tool: Add '.note' check into search for NOTE section
 10/15 perf, tool: Back [vdso] DSO with real data
 11/15 perf, tool: Add interface to arch registers sets
 12/15 perf, tool: Add libunwind dependency for dwarf cfi unwinding
 13/15 perf, tool: Support user regs and stack in sample parsing
 14/15 perf, tool: Support for dwarf cfi unwinding on post processing
 15/15 perf, tool: Support for dwarf mode callchain on perf record

The unwind processing could considerably prolong the computing
time of the report command, but I believe this could be improved.
   - caching DSO data accesses (as suggested in patch 8/15)
   - maybe separate thread with unwind processing on background,
     so the user does no need to wait for all the data to be
     processed.

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

I'd like to have some automated tests on this, but so far nothing
smart is comming to me.. ;)

thanks for comments,
jirka
---
 arch/Kconfig                                       |    7 +
 arch/x86/Kconfig                                   |    1 +
 arch/x86/include/asm/perf_regs.h                   |   15 +
 arch/x86/include/asm/perf_regs_32.h                |   86 +++
 arch/x86/include/asm/perf_regs_64.h                |  101 ++++
 arch/x86/include/asm/uaccess.h                     |    8 +-
 arch/x86/kernel/cpu/perf_event.c                   |    4 +-
 arch/x86/kernel/cpu/perf_event_intel_ds.c          |    3 +-
 arch/x86/kernel/cpu/perf_event_intel_lbr.c         |    2 +-
 arch/x86/lib/usercopy.c                            |    4 +-
 arch/x86/oprofile/backtrace.c                      |    4 +-
 include/asm-generic/uaccess.h                      |    4 +
 include/linux/perf_event.h                         |   36 ++-
 kernel/events/callchain.c                          |    4 +-
 kernel/events/core.c                               |  127 +++++-
 kernel/events/internal.h                           |   59 ++-
 kernel/events/ring_buffer.c                        |    4 +-
 tools/perf/Makefile                                |   40 ++-
 tools/perf/arch/x86/Makefile                       |    3 +
 tools/perf/arch/x86/include/perf_regs.h            |  101 ++++
 tools/perf/arch/x86/util/unwind.c                  |  111 ++++
 tools/perf/builtin-record.c                        |   89 +++-
 tools/perf/builtin-report.c                        |   24 +-
 tools/perf/builtin-script.c                        |   56 ++-
 tools/perf/builtin-test.c                          |    3 +-
 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/event.h                            |   15 +-
 tools/perf/util/evlist.c                           |   16 +
 tools/perf/util/evlist.h                           |    2 +
 tools/perf/util/evsel.c                            |   36 ++-
 tools/perf/util/include/linux/compiler.h           |    1 +
 tools/perf/util/map.c                              |   16 +-
 tools/perf/util/map.h                              |    7 +-
 tools/perf/util/perf_regs.h                        |   10 +
 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                          |  100 +++-
 tools/perf/util/session.h                          |   10 +-
 tools/perf/util/symbol.c                           |  317 +++++++++---
 tools/perf/util/symbol.h                           |   40 +-
 tools/perf/util/trace-event-scripting.c            |    3 +-
 tools/perf/util/trace-event.h                      |    5 +-
 tools/perf/util/unwind.c                           |  563 ++++++++++++++++++++
 tools/perf/util/unwind.h                           |   34 ++
 tools/perf/util/vdso.c                             |   92 ++++
 tools/perf/util/vdso.h                             |    7 +
 50 files changed, 2023 insertions(+), 199 deletions(-)

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH 01/15] perf, tool: Fix the array pointer to follow event data properly
  2012-03-28 12:35 [RFC 00/15] perf: Add backtrace post dwarf unwind Jiri Olsa
@ 2012-03-28 12:35 ` Jiri Olsa
  2012-03-28 12:35 ` [PATCH 02/15] uaccess: Add new copy_from_user_gup API Jiri Olsa
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 36+ messages in thread
From: Jiri Olsa @ 2012-03-28 12:35 UTC (permalink / raw)
  To: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec
  Cc: eranian, gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	fche, linux-kernel, Jiri Olsa

Currently we dont update the 'array' pointer properly after
processing the RAW data. This way perf might report wrong data
for branch stack if it is used along with tracepoint sample.

I'm not sure tracepoint could be connected with branch stack,
but I think the array pointer should have correct value after
each sample processing.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
---
 tools/perf/util/evsel.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index d9da62a..56a9689 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -580,6 +580,7 @@ int perf_event__parse_sample(const union perf_event *event, u64 type,
 			return -EFAULT;
 
 		data->raw_data = (void *) pdata;
+		array = (u64 *)(((char *)array) + data->raw_size + sizeof(u32));
 	}
 
 	if (type & PERF_SAMPLE_BRANCH_STACK) {
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 02/15] uaccess: Add new copy_from_user_gup API
  2012-03-28 12:35 [RFC 00/15] perf: Add backtrace post dwarf unwind Jiri Olsa
  2012-03-28 12:35 ` [PATCH 01/15] perf, tool: Fix the array pointer to follow event data properly Jiri Olsa
@ 2012-03-28 12:35 ` Jiri Olsa
  2012-03-28 12:35 ` [PATCH 03/15] perf: Unified API to record selective sets of arch registers Jiri Olsa
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 36+ messages in thread
From: Jiri Olsa @ 2012-03-28 12:35 UTC (permalink / raw)
  To: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec
  Cc: eranian, gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	fche, linux-kernel, Jiri Olsa

This brings a get_user_page_fast() based copy_from_user() that can
do a best effort copy from any context.

In order to support user stack dump safely in perf samples from
generic code, rename x86 copy_from_user_nmi to copy_from_user_gup
and make it generally available. If the arch doesn't provide an
implementation it will map to copy_from_user_inatomic.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
---
 arch/x86/include/asm/uaccess.h             |    8 +++++---
 arch/x86/kernel/cpu/perf_event.c           |    4 ++--
 arch/x86/kernel/cpu/perf_event_intel_ds.c  |    3 ++-
 arch/x86/kernel/cpu/perf_event_intel_lbr.c |    2 +-
 arch/x86/lib/usercopy.c                    |    4 ++--
 arch/x86/oprofile/backtrace.c              |    4 ++--
 include/asm-generic/uaccess.h              |    4 ++++
 7 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index 8be5f54..e3f5307 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -228,6 +228,11 @@ extern void __put_user_2(void);
 extern void __put_user_4(void);
 extern void __put_user_8(void);
 
+extern unsigned long
+__copy_from_user_gup(void *to, const void __user *from, unsigned long n);
+
+#define copy_from_user_gup(to, from, n) __copy_from_user_gup(to, from, n)
+
 #ifdef CONFIG_X86_WP_WORKS_OK
 
 /**
@@ -555,9 +560,6 @@ struct __large_struct { unsigned long buf[100]; };
 
 #endif /* CONFIG_X86_WP_WORKS_OK */
 
-extern unsigned long
-copy_from_user_nmi(void *to, const void __user *from, unsigned long n);
-
 /*
  * movsl can be slow when source and dest are not both 8-byte aligned
  */
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index bb8e034..294ad68 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1781,7 +1781,7 @@ perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry *entry)
 		frame.next_frame     = 0;
 		frame.return_address = 0;
 
-		bytes = copy_from_user_nmi(&frame, fp, sizeof(frame));
+		bytes = copy_from_user_gup(&frame, fp, sizeof(frame));
 		if (bytes != sizeof(frame))
 			break;
 
@@ -1827,7 +1827,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
 		frame.next_frame	     = NULL;
 		frame.return_address = 0;
 
-		bytes = copy_from_user_nmi(&frame, fp, sizeof(frame));
+		bytes = copy_from_user_gup(&frame, fp, sizeof(frame));
 		if (bytes != sizeof(frame))
 			break;
 
diff --git a/arch/x86/kernel/cpu/perf_event_intel_ds.c b/arch/x86/kernel/cpu/perf_event_intel_ds.c
index 7f64df1..77053af 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_ds.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_ds.c
@@ -520,7 +520,8 @@ static int intel_pmu_pebs_fixup_ip(struct pt_regs *regs)
 		if (!kernel_ip(ip)) {
 			int bytes, size = MAX_INSN_SIZE;
 
-			bytes = copy_from_user_nmi(buf, (void __user *)to, size);
+			bytes = copy_from_user_gup(buf, (void __user *)to,
+						   size);
 			if (bytes != size)
 				return 0;
 
diff --git a/arch/x86/kernel/cpu/perf_event_intel_lbr.c b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
index 520b426..8f0b9ce 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_lbr.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
@@ -437,7 +437,7 @@ static int branch_type(unsigned long from, unsigned long to)
 			return X86_BR_NONE;
 
 		/* may fail if text not present */
-		bytes = copy_from_user_nmi(buf, (void __user *)from, size);
+		bytes = copy_from_user_gup(buf, (void __user *)from, size);
 		if (bytes != size)
 			return X86_BR_NONE;
 
diff --git a/arch/x86/lib/usercopy.c b/arch/x86/lib/usercopy.c
index 97be9cb..a03e49a 100644
--- a/arch/x86/lib/usercopy.c
+++ b/arch/x86/lib/usercopy.c
@@ -11,7 +11,7 @@
  * best effort, GUP based copy_from_user() that is NMI-safe
  */
 unsigned long
-copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
+__copy_from_user_gup(void *to, const void __user *from, unsigned long n)
 {
 	unsigned long offset, addr = (unsigned long)from;
 	unsigned long size, len = 0;
@@ -40,4 +40,4 @@ copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
 
 	return len;
 }
-EXPORT_SYMBOL_GPL(copy_from_user_nmi);
+EXPORT_SYMBOL_GPL(__copy_from_user_gup);
diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
index d6aa6e8..42511b0 100644
--- a/arch/x86/oprofile/backtrace.c
+++ b/arch/x86/oprofile/backtrace.c
@@ -46,7 +46,7 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
 	struct stack_frame_ia32 *fp;
 	unsigned long bytes;
 
-	bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
+	bytes = copy_from_user_gup(bufhead, head, sizeof(bufhead));
 	if (bytes != sizeof(bufhead))
 		return NULL;
 
@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
 	struct stack_frame bufhead[2];
 	unsigned long bytes;
 
-	bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
+	bytes = copy_from_user_gup(bufhead, head, sizeof(bufhead));
 	if (bytes != sizeof(bufhead))
 		return NULL;
 
diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
index 9788568..759339b 100644
--- a/include/asm-generic/uaccess.h
+++ b/include/asm-generic/uaccess.h
@@ -240,6 +240,10 @@ extern int __get_user_bad(void) __attribute__((noreturn));
 #define __copy_to_user_inatomic __copy_to_user
 #endif
 
+#ifndef copy_from_user_gup
+#define copy_from_user_gup __copy_from_user_inatomic
+#endif
+
 static inline long copy_from_user(void *to,
 		const void __user * from, unsigned long n)
 {
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 03/15] perf: Unified API to record selective sets of arch registers
  2012-03-28 12:35 [RFC 00/15] perf: Add backtrace post dwarf unwind Jiri Olsa
  2012-03-28 12:35 ` [PATCH 01/15] perf, tool: Fix the array pointer to follow event data properly Jiri Olsa
  2012-03-28 12:35 ` [PATCH 02/15] uaccess: Add new copy_from_user_gup API Jiri Olsa
@ 2012-03-28 12:35 ` Jiri Olsa
  2012-03-30 12:51   ` Cyrill Gorcunov
  2012-03-28 12:35 ` [PATCH 04/15] perf: Add ability to dump user regs Jiri Olsa
                   ` (12 subsequent siblings)
  15 siblings, 1 reply; 36+ messages in thread
From: Jiri Olsa @ 2012-03-28 12:35 UTC (permalink / raw)
  To: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec
  Cc: eranian, gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	fche, linux-kernel, Jiri Olsa

This brings a new API to help the selective dump of registers on
event sampling, and its implementation in x86.

- The informations about the desired registers will be passed
  to a single u64 mask. It's up to the architecture to map the
  registers into the mask bits.

- The architecture must provide a non-zero and unique id to
  identify the origin of a register set because interpreting a
  register dump requires to know from which architecture it comes.
  The achitecture is considered different between the 32 and 64 bits
  version. x86-32 has the id 1, x86-64 has the id 2.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
---
 arch/Kconfig                        |    7 +++
 arch/x86/Kconfig                    |    1 +
 arch/x86/include/asm/perf_regs.h    |   15 +++++
 arch/x86/include/asm/perf_regs_32.h |   86 +++++++++++++++++++++++++++++
 arch/x86/include/asm/perf_regs_64.h |  101 +++++++++++++++++++++++++++++++++++
 5 files changed, 210 insertions(+), 0 deletions(-)
 create mode 100644 arch/x86/include/asm/perf_regs.h
 create mode 100644 arch/x86/include/asm/perf_regs_32.h
 create mode 100644 arch/x86/include/asm/perf_regs_64.h

diff --git a/arch/Kconfig b/arch/Kconfig
index cfddeb0..aa83dda 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -204,6 +204,13 @@ config HAVE_PERF_EVENTS_NMI
 	  subsystem.  Also has support for calculating CPU cycle events
 	  to determine how many clock cycles in a given period.
 
+config HAVE_PERF_REGS_DEFS
+	bool
+	help
+	  Support selective register dumps for perf events. This includes
+	  bit-mapping of each registers and a unique architecture version,
+	  also different between 32 and 64 bits.
+
 config HAVE_ARCH_JUMP_LABEL
 	bool
 
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 1b61bd8..556cda9 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -59,6 +59,7 @@ config X86
 	select HAVE_MIXED_BREAKPOINTS_REGS
 	select PERF_EVENTS
 	select HAVE_PERF_EVENTS_NMI
+	select HAVE_PERF_REGS_DEFS
 	select ANON_INODES
 	select HAVE_ALIGNED_STRUCT_PAGE if SLUB && !M386
 	select HAVE_CMPXCHG_LOCAL if !M386
diff --git a/arch/x86/include/asm/perf_regs.h b/arch/x86/include/asm/perf_regs.h
new file mode 100644
index 0000000..df3dec7
--- /dev/null
+++ b/arch/x86/include/asm/perf_regs.h
@@ -0,0 +1,15 @@
+#ifndef _ASM_X86_PERF_REGS_H
+#define _ASM_X86_PERF_REGS_H
+
+enum {
+	PERF_X86_32_REG_VERSION = 1UL,
+	PERF_X86_64_REG_VERSION = 2UL,
+};
+
+#ifdef CONFIG_X86_32
+#include "perf_regs_32.h"
+#else
+#include "perf_regs_64.h"
+#endif
+
+#endif /* _ASM_X86_PERF_REGS_H */
diff --git a/arch/x86/include/asm/perf_regs_32.h b/arch/x86/include/asm/perf_regs_32.h
new file mode 100644
index 0000000..b38d8b4
--- /dev/null
+++ b/arch/x86/include/asm/perf_regs_32.h
@@ -0,0 +1,86 @@
+#ifndef _ASM_X86_PERF_REGS_32_H
+#define _ASM_X86_PERF_REGS_32_H
+
+#define PERF_X86_32_REG_VERSION		1ULL
+
+enum perf_event_x86_32_regs {
+	PERF_X86_32_REG_EAX,
+	PERF_X86_32_REG_EBX,
+	PERF_X86_32_REG_ECX,
+	PERF_X86_32_REG_EDX,
+	PERF_X86_32_REG_ESI,
+	PERF_X86_32_REG_EDI,
+	PERF_X86_32_REG_EBP,
+	PERF_X86_32_REG_ESP,
+	PERF_X86_32_REG_EIP,
+	PERF_X86_32_REG_FLAGS,
+	PERF_X86_32_REG_CS,
+	PERF_X86_32_REG_DS,
+	PERF_X86_32_REG_ES,
+	PERF_X86_32_REG_FS,
+	PERF_X86_32_REG_GS,
+
+	/* Non ABI */
+	PERF_X86_32_REG_MAX,
+	PERF_REG_IP = PERF_X86_32_REG_EIP,
+	PERF_REG_SP = PERF_X86_32_REG_ESP,
+};
+
+#ifdef __KERNEL__
+
+#define PERF_X86_32_REG_RESERVED (~((1ULL << PERF_X86_32_REG_MAX) - 1ULL))
+
+static inline u64 perf_reg_version(void)
+{
+	return PERF_X86_32_REG_VERSION;
+}
+
+static inline int perf_reg_validate(u64 mask)
+{
+	if (mask & PERF_X86_32_REG_RESERVED)
+		return -EINVAL;
+
+	return 0;
+}
+
+static inline u64 perf_reg_value(struct pt_regs *regs, int idx)
+{
+	switch (idx) {
+	case PERF_X86_32_REG_EAX:
+		return regs->ax;
+	case PERF_X86_32_REG_EBX:
+		return regs->bx;
+	case PERF_X86_32_REG_ECX:
+		return regs->cx;
+	case PERF_X86_32_REG_EDX:
+		return regs->dx;
+	case PERF_X86_32_REG_ESI:
+		return regs->si;
+	case PERF_X86_32_REG_EDI:
+		return regs->di;
+	case PERF_X86_32_REG_EBP:
+		return regs->bp;
+	case PERF_X86_32_REG_ESP:
+		return regs->sp;
+	case PERF_X86_32_REG_EIP:
+		return regs->ip;
+	case PERF_X86_32_REG_FLAGS:
+		return regs->flags;
+	case PERF_X86_32_REG_CS:
+		return regs->cs;
+	case PERF_X86_32_REG_DS:
+		return regs->ds;
+	case PERF_X86_32_REG_ES:
+		return regs->es;
+	case PERF_X86_32_REG_FS:
+		return regs->fs;
+	case PERF_X86_32_REG_GS:
+		return regs->gs;
+	}
+
+	return 0;
+}
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_X86_PERF_REGS_32_H */
diff --git a/arch/x86/include/asm/perf_regs_64.h b/arch/x86/include/asm/perf_regs_64.h
new file mode 100644
index 0000000..88f8eb1
--- /dev/null
+++ b/arch/x86/include/asm/perf_regs_64.h
@@ -0,0 +1,101 @@
+#ifndef _ASM_X86_PERF_REGS_64_H
+#define _ASM_X86_PERF_REGS_64_H
+
+#define PERF_X86_64_REG_VERSION		1ULL
+
+enum perf_event_x86_64_regs {
+	PERF_X86_64_REG_RAX,
+	PERF_X86_64_REG_RBX,
+	PERF_X86_64_REG_RCX,
+	PERF_X86_64_REG_RDX,
+	PERF_X86_64_REG_RSI,
+	PERF_X86_64_REG_RDI,
+	PERF_X86_64_REG_R8,
+	PERF_X86_64_REG_R9,
+	PERF_X86_64_REG_R10,
+	PERF_X86_64_REG_R11,
+	PERF_X86_64_REG_R12,
+	PERF_X86_64_REG_R13,
+	PERF_X86_64_REG_R14,
+	PERF_X86_64_REG_R15,
+	PERF_X86_64_REG_RBP,
+	PERF_X86_64_REG_RSP,
+	PERF_X86_64_REG_RIP,
+	PERF_X86_64_REG_FLAGS,
+	PERF_X86_64_REG_CS,
+	PERF_X86_64_REG_SS,
+
+	/* Non ABI */
+	PERF_X86_64_REG_MAX,
+	PERF_REG_IP = PERF_X86_64_REG_RIP,
+	PERF_REG_SP = PERF_X86_64_REG_RSP,
+};
+
+#ifdef __KERNEL__
+
+#define PERF_X86_64_REG_RESERVED (~((1ULL << PERF_X86_64_REG_MAX) - 1ULL))
+
+static inline u64 perf_reg_version(void)
+{
+	return PERF_X86_64_REG_VERSION;
+}
+
+static inline int perf_reg_validate(u64 mask)
+{
+	if (mask & PERF_X86_64_REG_RESERVED)
+		return -EINVAL;
+
+	return 0;
+}
+
+static inline u64 perf_reg_value(struct pt_regs *regs, int idx)
+{
+	switch (idx) {
+	case PERF_X86_64_REG_RAX:
+		return regs->ax;
+	case PERF_X86_64_REG_RBX:
+		return regs->bx;
+	case PERF_X86_64_REG_RCX:
+		return regs->cx;
+	case PERF_X86_64_REG_RDX:
+		return regs->dx;
+	case PERF_X86_64_REG_RSI:
+		return regs->si;
+	case PERF_X86_64_REG_RDI:
+		return regs->di;
+	case PERF_X86_64_REG_R8:
+		return regs->r8;
+	case PERF_X86_64_REG_R9:
+		return regs->r8;
+	case PERF_X86_64_REG_R10:
+		return regs->r8;
+	case PERF_X86_64_REG_R11:
+		return regs->r8;
+	case PERF_X86_64_REG_R12:
+		return regs->r8;
+	case PERF_X86_64_REG_R13:
+		return regs->r8;
+	case PERF_X86_64_REG_R14:
+		return regs->r8;
+	case PERF_X86_64_REG_R15:
+		return regs->r8;
+	case PERF_X86_64_REG_RBP:
+		return regs->bp;
+	case PERF_X86_64_REG_RSP:
+		return regs->sp;
+	case PERF_X86_64_REG_RIP:
+		return regs->ip;
+	case PERF_X86_64_REG_FLAGS:
+		return regs->flags;
+	case PERF_X86_64_REG_CS:
+		return regs->cs;
+	case PERF_X86_64_REG_SS:
+		return regs->ss;
+	}
+
+	return 0;
+}
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_X86_PERF_REGS_64_H */
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 04/15] perf: Add ability to dump user regs
  2012-03-28 12:35 [RFC 00/15] perf: Add backtrace post dwarf unwind Jiri Olsa
                   ` (2 preceding siblings ...)
  2012-03-28 12:35 ` [PATCH 03/15] perf: Unified API to record selective sets of arch registers Jiri Olsa
@ 2012-03-28 12:35 ` Jiri Olsa
  2012-03-28 14:01   ` Frank Ch. Eigler
  2012-03-30 14:42   ` Frederic Weisbecker
  2012-03-28 12:35 ` [PATCH 05/15] perf: Add ability to dump part of the user stack Jiri Olsa
                   ` (11 subsequent siblings)
  15 siblings, 2 replies; 36+ messages in thread
From: Jiri Olsa @ 2012-03-28 12:35 UTC (permalink / raw)
  To: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec
  Cc: eranian, gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	fche, linux-kernel, Jiri Olsa

Add new attr->user_regs bitmap that lets a user choose a set
of user registers to dump to the sample. The layout of this
bitmap is described in asm/perf_regs.h for archs that
support CONFIG_HAVE_PERF_REGS_DEFS, otherwise the perf
syscall will fail if attr->user_regs is non zero.

The register value here are those of the user space context as
it was before the user entered the kernel for whatever reason
(syscall, irq, exception, or a PMI happening in userspace).

This is going to be useful to bring Dwarf CFI based stack unwinding
on top of samples.

FIXME: the issue of compat regs has yet to be solved. I think we
need to split the regs bitmap in:

	attr->user_regs32
	attr->user_regs64

So that userspace doesn't need to care about beeing a compat task or
not, running on a 32 bits kernel or not, it can provide both bitmaps
and let the kernel handle that, ignore user_regs64 if it is a 32 bits
kernel, handle it otherwise and also user_regs32 for compat tasks,
etc...

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
---
 include/linux/perf_event.h |   26 ++++++++++++++++++
 kernel/events/core.c       |   61 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index ddbb6a9..9f3df6e 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -272,6 +272,12 @@ struct perf_event_attr {
 		__u64		config2; /* extension of config1 */
 	};
 	__u64	branch_sample_type; /* enum branch_sample_type */
+
+	/*
+	 * Arch specific mask that defines a set of user regs to dump on
+	 * samples. See asm/perf_regs.h for details.
+	 */
+	__u64			user_regs;
 };
 
 /*
@@ -1079,6 +1085,25 @@ struct perf_output_handle {
 
 #ifdef CONFIG_PERF_EVENTS
 
+#ifdef CONFIG_HAVE_PERF_REGS_DEFS
+#include <asm/perf_regs.h>
+#else
+static inline int perf_reg_value(struct pt_regs *regs, int idx)
+{
+	return 0;
+}
+
+static inline int perf_reg_version(void)
+{
+	return -EINVAL;
+}
+
+static inline int perf_reg_validate(u64 mask)
+{
+	return -ENOSYS;
+}
+#endif /*CONFIG_HAVE_PERF_REGS_DUMP */
+
 extern int perf_pmu_register(struct pmu *pmu, char *name, int type);
 extern void perf_pmu_unregister(struct pmu *pmu);
 
@@ -1130,6 +1155,7 @@ struct perf_sample_data {
 	struct perf_callchain_entry	*callchain;
 	struct perf_raw_record		*raw;
 	struct perf_branch_stack	*br_stack;
+	struct pt_regs			*uregs;
 };
 
 static inline void perf_sample_data_init(struct perf_sample_data *data, u64 addr)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index a6a9ec4..57f63fe 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3751,6 +3751,37 @@ int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
 }
 EXPORT_SYMBOL_GPL(perf_unregister_guest_info_callbacks);
 
+static void
+perf_output_sample_regs(struct perf_output_handle *handle,
+			struct pt_regs *regs, u64 mask)
+{
+	int i = 0;
+
+	do {
+		u64 val;
+
+		if (mask & 1) {
+			val = perf_reg_value(regs, i);
+			perf_output_put(handle, val);
+		}
+
+		mask >>= 1;
+		i++;
+	} while (mask);
+}
+
+static struct pt_regs *perf_sample_uregs(struct pt_regs *regs)
+{
+	if (!user_mode(regs)) {
+		if (current->mm)
+			regs = task_pt_regs(current);
+		else
+			regs = NULL;
+	}
+
+	return regs;
+}
+
 static void __perf_event_header__init_id(struct perf_event_header *header,
 					 struct perf_sample_data *data,
 					 struct perf_event *event)
@@ -4011,6 +4042,22 @@ void perf_output_sample(struct perf_output_handle *handle,
 			perf_output_put(handle, nr);
 		}
 	}
+
+	if (event->attr.user_regs) {
+		u64 id;
+
+		/* If there is no regs to dump, notice it through a 0 version */
+		if (!data->uregs) {
+			id = 0;
+			perf_output_put(handle, id);
+		} else {
+
+			id = perf_reg_version();
+			perf_output_put(handle, id);
+			perf_output_sample_regs(handle, data->uregs,
+						event->attr.user_regs);
+		}
+	}
 }
 
 void perf_prepare_sample(struct perf_event_header *header,
@@ -4062,6 +4109,17 @@ void perf_prepare_sample(struct perf_event_header *header,
 		}
 		header->size += size;
 	}
+
+	if (event->attr.user_regs) {
+		int size = sizeof(u64); /* the version size */
+
+		data->uregs = perf_sample_uregs(regs);
+		if (data->uregs) {
+			/* Regs values */
+			size += hweight64(event->attr.user_regs) * sizeof(u64);
+		}
+		header->size += size;
+	}
 }
 
 static void perf_event_output(struct perf_event *event,
@@ -6112,6 +6170,9 @@ static int perf_copy_attr(struct perf_event_attr __user *uattr,
 			attr->branch_sample_type = mask;
 		}
 	}
+
+	ret = perf_reg_validate(attr->user_regs);
+
 out:
 	return ret;
 
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 05/15] perf: Add ability to dump part of the user stack
  2012-03-28 12:35 [RFC 00/15] perf: Add backtrace post dwarf unwind Jiri Olsa
                   ` (3 preceding siblings ...)
  2012-03-28 12:35 ` [PATCH 04/15] perf: Add ability to dump user regs Jiri Olsa
@ 2012-03-28 12:35 ` Jiri Olsa
  2012-03-28 12:35 ` [PATCH 06/15] perf: Add attribute to filter out user callchains Jiri Olsa
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 36+ messages in thread
From: Jiri Olsa @ 2012-03-28 12:35 UTC (permalink / raw)
  To: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec
  Cc: eranian, gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	fche, linux-kernel, Jiri Olsa

Beeing able to dump parts of the user stack, starting from the
stack pointer, will be useful to make a post mortem dwarf CFI based
stack unwinding.

This is done through the new ustack_dump_size perf attribute. If it
is non zero, the user stack will dumped in samples following the
requested size in bytes.

The longer is the dump, the deeper will be the resulting retrieved
callchain.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
---
 include/linux/perf_event.h  |    6 +++-
 kernel/events/core.c        |   63 +++++++++++++++++++++++++++++++++++++++++++
 kernel/events/internal.h    |   56 ++++++++++++++++++++++++--------------
 kernel/events/ring_buffer.c |    4 +-
 4 files changed, 104 insertions(+), 25 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 9f3df6e..5852b4c 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -278,6 +278,7 @@ struct perf_event_attr {
 	 * samples. See asm/perf_regs.h for details.
 	 */
 	__u64			user_regs;
+	__u32			ustack_dump_size;
 };
 
 /*
@@ -1309,8 +1310,9 @@ static inline bool has_branch_stack(struct perf_event *event)
 extern int perf_output_begin(struct perf_output_handle *handle,
 			     struct perf_event *event, unsigned int size);
 extern void perf_output_end(struct perf_output_handle *handle);
-extern void perf_output_copy(struct perf_output_handle *handle,
-			     const void *buf, unsigned int len);
+extern unsigned int
+perf_output_copy(struct perf_output_handle *handle,
+		 const void *buf, unsigned int len);
 extern int perf_swevent_get_recursion_context(void);
 extern void perf_swevent_put_recursion_context(int rctx);
 extern void perf_event_enable(struct perf_event *event);
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 57f63fe..0468987 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -4058,6 +4058,43 @@ void perf_output_sample(struct perf_output_handle *handle,
 						event->attr.user_regs);
 		}
 	}
+
+	if (event->attr.ustack_dump_size) {
+		unsigned long sp;
+		unsigned int rem;
+		u64 size, dyn_size;
+
+		/* Case of a kernel thread, nothing to dump */
+		if (!data->uregs) {
+			size = 0;
+			perf_output_put(handle, size);
+		} else {
+
+			/*
+			 * Static size: we always dump the size requested by
+			 * the user because most of the time, the top of the
+			 * user stack is not paged out. Perhaps we should
+			 * force ustack_dump_size to be % 8.
+			 */
+			size = event->attr.ustack_dump_size;
+			size = round_up(size, sizeof(u64));
+			perf_output_put(handle, size);
+
+			/* FIXME: it's missing on some archs */
+			sp = user_stack_pointer(data->uregs);
+			rem = __output_copy_user_gup(handle, (void *)sp, size);
+			dyn_size = size - rem;
+
+			/* What couldn't be dumped is zero padded */
+			while (rem--) {
+				char zero = 0;
+				perf_output_put(handle, zero);
+			}
+
+			/* Dynamic size: whole dump - padding */
+			perf_output_put(handle, dyn_size);
+		}
+	}
 }
 
 void perf_prepare_sample(struct perf_event_header *header,
@@ -4120,6 +4157,32 @@ void perf_prepare_sample(struct perf_event_header *header,
 		}
 		header->size += size;
 	}
+
+	if (event->attr.ustack_dump_size) {
+		if (!event->attr.user_regs)
+			data->uregs = perf_sample_uregs(regs);
+
+		/*
+		 * A first field that tells the _static_ size of the dump. 0 if
+		 * there is nothing to dump (ie: we are in a kernel thread)
+		 * otherwise the requested size.
+		 */
+		header->size += sizeof(u64);
+
+		/*
+		 * If there is something to dump, add space for the dump itself
+		 * and for the field that tells the _dynamic_ size, which is
+		 * how many have been actually dumped. What couldn't be dumped
+		 * will be zero-padded.
+		 */
+		if (data->uregs) {
+			u64 size = event->attr.ustack_dump_size;
+
+			size = round_up(size, sizeof(u64));
+			header->size += size;
+			header->size += sizeof(u64);
+		}
+	}
 }
 
 static void perf_event_output(struct perf_event *event,
diff --git a/kernel/events/internal.h b/kernel/events/internal.h
index b0b107f..1ae5270 100644
--- a/kernel/events/internal.h
+++ b/kernel/events/internal.h
@@ -76,30 +76,44 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
 	return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
 }
 
-static inline void
-__output_copy(struct perf_output_handle *handle,
-		   const void *buf, unsigned int len)
+static int memcpy_common(void *dst, const void *src, size_t n)
 {
-	do {
-		unsigned long size = min_t(unsigned long, handle->size, len);
-
-		memcpy(handle->addr, buf, size);
-
-		len -= size;
-		handle->addr += size;
-		buf += size;
-		handle->size -= size;
-		if (!handle->size) {
-			struct ring_buffer *rb = handle->rb;
-
-			handle->page++;
-			handle->page &= rb->nr_pages - 1;
-			handle->addr = rb->data_pages[handle->page];
-			handle->size = PAGE_SIZE << page_order(rb);
-		}
-	} while (len);
+	memcpy(dst, src, n);
+	return n;
 }
 
+#define DEFINE_PERF_OUTPUT_COPY(func_name, memcpy_func)			\
+static inline unsigned int						\
+func_name(struct perf_output_handle *handle,				\
+	  const void *buf, unsigned int len)				\
+{									\
+	unsigned long size, written;					\
+									\
+	do {								\
+		size = min_t(unsigned long, handle->size, len);		\
+									\
+		written = memcpy_func(handle->addr, buf, size);		\
+									\
+		len -= written;						\
+		handle->addr += written;				\
+		buf += written;						\
+		handle->size -= written;				\
+		if (!handle->size) {					\
+			struct ring_buffer *rb = handle->rb;		\
+									\
+			handle->page++;					\
+			handle->page &= rb->nr_pages - 1;		\
+			handle->addr = rb->data_pages[handle->page];	\
+			handle->size = PAGE_SIZE << page_order(rb);	\
+		}							\
+	} while (len && written == size);				\
+									\
+	return len;							\
+}
+
+DEFINE_PERF_OUTPUT_COPY(__output_copy, memcpy_common)
+DEFINE_PERF_OUTPUT_COPY(__output_copy_user_gup, copy_from_user_gup)
+
 /* Callchain handling */
 extern struct perf_callchain_entry *perf_callchain(struct pt_regs *regs);
 extern int get_callchain_buffers(void);
diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index 6ddaba4..b4c2ad3 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -182,10 +182,10 @@ out:
 	return -ENOSPC;
 }
 
-void perf_output_copy(struct perf_output_handle *handle,
+unsigned int perf_output_copy(struct perf_output_handle *handle,
 		      const void *buf, unsigned int len)
 {
-	__output_copy(handle, buf, len);
+	return __output_copy(handle, buf, len);
 }
 
 void perf_output_end(struct perf_output_handle *handle)
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 06/15] perf: Add attribute to filter out user callchains
  2012-03-28 12:35 [RFC 00/15] perf: Add backtrace post dwarf unwind Jiri Olsa
                   ` (4 preceding siblings ...)
  2012-03-28 12:35 ` [PATCH 05/15] perf: Add ability to dump part of the user stack Jiri Olsa
@ 2012-03-28 12:35 ` Jiri Olsa
  2012-03-28 12:35 ` [PATCH 07/15] perf, tool: Factor DSO symtab types to generic binary types Jiri Olsa
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 36+ messages in thread
From: Jiri Olsa @ 2012-03-28 12:35 UTC (permalink / raw)
  To: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec
  Cc: eranian, gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	fche, linux-kernel, Jiri Olsa

Add the new exclude_user_callchain attribute to filter out
frame pointer based user callchains. This is something we
want to select when we use the dwarf cfi callchain mode,
because frame pointer based user callchains are useless in
this mode.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
---
 include/linux/perf_event.h |    4 +++-
 kernel/events/callchain.c  |    4 ++--
 kernel/events/core.c       |    3 ++-
 kernel/events/internal.h   |    3 ++-
 4 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 5852b4c..785a67a 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -255,7 +255,9 @@ struct perf_event_attr {
 				exclude_host   :  1, /* don't count in host   */
 				exclude_guest  :  1, /* don't count in guest  */
 
-				__reserved_1   : 43;
+				exclude_user_callchain : 1, /* only record kernel callchains */
+
+				__reserved_1   : 42;
 
 	union {
 		__u32		wakeup_events;	  /* wakeup every n events */
diff --git a/kernel/events/callchain.c b/kernel/events/callchain.c
index 6581a04..884e997 100644
--- a/kernel/events/callchain.c
+++ b/kernel/events/callchain.c
@@ -153,7 +153,7 @@ put_callchain_entry(int rctx)
 	put_recursion_context(__get_cpu_var(callchain_recursion), rctx);
 }
 
-struct perf_callchain_entry *perf_callchain(struct pt_regs *regs)
+struct perf_callchain_entry *perf_callchain(struct pt_regs *regs, int user)
 {
 	int rctx;
 	struct perf_callchain_entry *entry;
@@ -177,7 +177,7 @@ struct perf_callchain_entry *perf_callchain(struct pt_regs *regs)
 			regs = NULL;
 	}
 
-	if (regs) {
+	if (user && regs) {
 		perf_callchain_store(entry, PERF_CONTEXT_USER);
 		perf_callchain_user(entry, regs);
 	}
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 0468987..2df82df 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -4117,8 +4117,9 @@ void perf_prepare_sample(struct perf_event_header *header,
 
 	if (sample_type & PERF_SAMPLE_CALLCHAIN) {
 		int size = 1;
+		int user = !event->attr.exclude_user_callchain;
 
-		data->callchain = perf_callchain(regs);
+		data->callchain = perf_callchain(regs, user);
 
 		if (data->callchain)
 			size += data->callchain->nr;
diff --git a/kernel/events/internal.h b/kernel/events/internal.h
index 1ae5270..b3ade19 100644
--- a/kernel/events/internal.h
+++ b/kernel/events/internal.h
@@ -115,7 +115,8 @@ DEFINE_PERF_OUTPUT_COPY(__output_copy, memcpy_common)
 DEFINE_PERF_OUTPUT_COPY(__output_copy_user_gup, copy_from_user_gup)
 
 /* Callchain handling */
-extern struct perf_callchain_entry *perf_callchain(struct pt_regs *regs);
+extern struct perf_callchain_entry *perf_callchain(struct pt_regs *regs,
+						   int user);
 extern int get_callchain_buffers(void);
 extern void put_callchain_buffers(void);
 
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 07/15] perf, tool: Factor DSO symtab types to generic binary types
  2012-03-28 12:35 [RFC 00/15] perf: Add backtrace post dwarf unwind Jiri Olsa
                   ` (5 preceding siblings ...)
  2012-03-28 12:35 ` [PATCH 06/15] perf: Add attribute to filter out user callchains Jiri Olsa
@ 2012-03-28 12:35 ` Jiri Olsa
  2012-03-28 12:35 ` [PATCH 08/15] perf, tool: Add interface to read DSO image data Jiri Olsa
                   ` (8 subsequent siblings)
  15 siblings, 0 replies; 36+ messages in thread
From: Jiri Olsa @ 2012-03-28 12:35 UTC (permalink / raw)
  To: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec
  Cc: eranian, gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	fche, linux-kernel, Jiri Olsa

Adding interface to access DSOs so it could be used
from another place.

New DSO binary type is added - making current SYMTAB__*
types more general:
   DSO_BINARY_TYPE__* = SYMTAB__*

Folowing function is added to return path based on the specified
binary type:
   dso__binary_type_file

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
---
 tools/perf/builtin-top.c   |    2 +-
 tools/perf/util/annotate.c |    2 +-
 tools/perf/util/symbol.c   |  181 +++++++++++++++++++++++++++-----------------
 tools/perf/util/symbol.h   |   32 ++++----
 4 files changed, 129 insertions(+), 88 deletions(-)

diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index e3c63ae..c740bd0 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -123,7 +123,7 @@ static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he)
 	/*
 	 * We can't annotate with just /proc/kallsyms
 	 */
-	if (map->dso->symtab_type == SYMTAB__KALLSYMS) {
+	if (map->dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS) {
 		pr_err("Can't annotate %s: No vmlinux file was found in the "
 		       "path\n", sym->name);
 		sleep(1);
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index e5a462f..008195a 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -296,7 +296,7 @@ fallback:
 		free_filename = false;
 	}
 
-	if (dso->symtab_type == SYMTAB__KALLSYMS) {
+	if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS) {
 		char bf[BUILD_ID_SIZE * 2 + 16] = " with build id ";
 		char *build_id_msg = NULL;
 
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 5dd83c3..49f7042 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -49,6 +49,22 @@ struct symbol_conf symbol_conf = {
 	.symfs            = "",
 };
 
+static enum dso_binary_type binary_type_symtab[] = {
+	DSO_BINARY_TYPE__KALLSYMS,
+	DSO_BINARY_TYPE__GUEST_KALLSYMS,
+	DSO_BINARY_TYPE__JAVA_JIT,
+	DSO_BINARY_TYPE__BUILD_ID_CACHE,
+	DSO_BINARY_TYPE__FEDORA_DEBUGINFO,
+	DSO_BINARY_TYPE__UBUNTU_DEBUGINFO,
+	DSO_BINARY_TYPE__BUILDID_DEBUGINFO,
+	DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
+	DSO_BINARY_TYPE__GUEST_KMODULE,
+	DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE,
+	DSO_BINARY_TYPE__NOT_FOUND,
+};
+
+#define DSO_BINARY_TYPE__SYMTAB_CNT sizeof(binary_type_symtab)
+
 int dso__name_len(const struct dso *dso)
 {
 	if (verbose)
@@ -317,7 +333,7 @@ struct dso *dso__new(const char *name)
 		dso__set_short_name(dso, dso->name);
 		for (i = 0; i < MAP__NR_TYPES; ++i)
 			dso->symbols[i] = dso->symbol_names[i] = RB_ROOT;
-		dso->symtab_type = SYMTAB__NOT_FOUND;
+		dso->symtab_type = DSO_BINARY_TYPE__NOT_FOUND;
 		dso->loaded = 0;
 		dso->sorted_by_name = 0;
 		dso->has_build_id = 0;
@@ -804,9 +820,9 @@ int dso__load_kallsyms(struct dso *dso, const char *filename,
 	symbols__fixup_end(&dso->symbols[map->type]);
 
 	if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
-		dso->symtab_type = SYMTAB__GUEST_KALLSYMS;
+		dso->symtab_type = DSO_BINARY_TYPE__GUEST_KALLSYMS;
 	else
-		dso->symtab_type = SYMTAB__KALLSYMS;
+		dso->symtab_type = DSO_BINARY_TYPE__KALLSYMS;
 
 	return dso__split_kallsyms(dso, map, filter);
 }
@@ -1563,31 +1579,96 @@ out:
 char dso__symtab_origin(const struct dso *dso)
 {
 	static const char origin[] = {
-		[SYMTAB__KALLSYMS]	      = 'k',
-		[SYMTAB__JAVA_JIT]	      = 'j',
-		[SYMTAB__BUILD_ID_CACHE]      = 'B',
-		[SYMTAB__FEDORA_DEBUGINFO]    = 'f',
-		[SYMTAB__UBUNTU_DEBUGINFO]    = 'u',
-		[SYMTAB__BUILDID_DEBUGINFO]   = 'b',
-		[SYMTAB__SYSTEM_PATH_DSO]     = 'd',
-		[SYMTAB__SYSTEM_PATH_KMODULE] = 'K',
-		[SYMTAB__GUEST_KALLSYMS]      =  'g',
-		[SYMTAB__GUEST_KMODULE]	      =  'G',
+		[DSO_BINARY_TYPE__KALLSYMS]		= 'k',
+		[DSO_BINARY_TYPE__JAVA_JIT]		= 'j',
+		[DSO_BINARY_TYPE__BUILD_ID_CACHE]	= 'B',
+		[DSO_BINARY_TYPE__FEDORA_DEBUGINFO]	= 'f',
+		[DSO_BINARY_TYPE__UBUNTU_DEBUGINFO]	= 'u',
+		[DSO_BINARY_TYPE__BUILDID_DEBUGINFO]	= 'b',
+		[DSO_BINARY_TYPE__SYSTEM_PATH_DSO]	= 'd',
+		[DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE]	= 'K',
+		[DSO_BINARY_TYPE__GUEST_KALLSYMS]	= 'g',
+		[DSO_BINARY_TYPE__GUEST_KMODULE]	= 'G',
 	};
 
-	if (dso == NULL || dso->symtab_type == SYMTAB__NOT_FOUND)
+	if (dso == NULL || dso->symtab_type == DSO_BINARY_TYPE__NOT_FOUND)
 		return '!';
 	return origin[dso->symtab_type];
 }
 
+int dso__binary_type_file(struct dso *dso, enum dso_binary_type type,
+			  char *root_dir, char *file, size_t size)
+{
+	char build_id_hex[BUILD_ID_SIZE * 2 + 1];
+	int ret = 0;
+
+	switch (type) {
+	case DSO_BINARY_TYPE__BUILD_ID_CACHE:
+		/* skip the locally configured cache if a symfs is given */
+		if (symbol_conf.symfs[0] ||
+		    (dso__build_id_filename(dso, file, size) == NULL))
+			ret = -1;
+		break;
+
+	case DSO_BINARY_TYPE__FEDORA_DEBUGINFO:
+		snprintf(file, size, "%s/usr/lib/debug%s.debug",
+			 symbol_conf.symfs, dso->long_name);
+		break;
+
+	case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO:
+		snprintf(file, size, "%s/usr/lib/debug%s",
+			 symbol_conf.symfs, dso->long_name);
+		break;
+
+	case DSO_BINARY_TYPE__BUILDID_DEBUGINFO:
+		if (!dso->has_build_id) {
+			ret = -1;
+			break;
+		}
+
+		build_id__sprintf(dso->build_id,
+				  sizeof(dso->build_id),
+				  build_id_hex);
+		snprintf(file, size,
+			 "%s/usr/lib/debug/.build-id/%.2s/%s.debug",
+			 symbol_conf.symfs, build_id_hex, build_id_hex + 2);
+		break;
+
+	case DSO_BINARY_TYPE__SYSTEM_PATH_DSO:
+		snprintf(file, size, "%s%s",
+			 symbol_conf.symfs, dso->long_name);
+		break;
+
+	case DSO_BINARY_TYPE__GUEST_KMODULE:
+		snprintf(file, size, "%s%s%s", symbol_conf.symfs,
+			 root_dir, dso->long_name);
+		break;
+
+	case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE:
+		snprintf(file, size, "%s%s", symbol_conf.symfs,
+			 dso->long_name);
+		break;
+
+	default:
+	case DSO_BINARY_TYPE__KALLSYMS:
+	case DSO_BINARY_TYPE__GUEST_KALLSYMS:
+	case DSO_BINARY_TYPE__JAVA_JIT:
+	case DSO_BINARY_TYPE__NOT_FOUND:
+		ret = -1;
+		break;
+	}
+
+	return ret;
+}
+
 int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
 {
-	int size = PATH_MAX;
 	char *name;
 	int ret = -1;
 	int fd;
+	u_int i;
 	struct machine *machine;
-	const char *root_dir;
+	char *root_dir = (char *) "";
 	int want_symtab;
 
 	dso__set_loaded(dso, map->type);
@@ -1602,7 +1683,7 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
 	else
 		machine = NULL;
 
-	name = malloc(size);
+	name = malloc(PATH_MAX);
 	if (!name)
 		return -1;
 
@@ -1621,69 +1702,27 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
 		}
 
 		ret = dso__load_perf_map(dso, map, filter);
-		dso->symtab_type = ret > 0 ? SYMTAB__JAVA_JIT :
-					      SYMTAB__NOT_FOUND;
+		dso->symtab_type = ret > 0 ? DSO_BINARY_TYPE__JAVA_JIT :
+					     DSO_BINARY_TYPE__NOT_FOUND;
 		return ret;
 	}
 
+	if (machine)
+		root_dir = machine->root_dir;
+
 	/* Iterate over candidate debug images.
 	 * On the first pass, only load images if they have a full symtab.
 	 * Failing that, do a second pass where we accept .dynsym also
 	 */
 	want_symtab = 1;
 restart:
-	for (dso->symtab_type = SYMTAB__BUILD_ID_CACHE;
-	     dso->symtab_type != SYMTAB__NOT_FOUND;
-	     dso->symtab_type++) {
-		switch (dso->symtab_type) {
-		case SYMTAB__BUILD_ID_CACHE:
-			/* skip the locally configured cache if a symfs is given */
-			if (symbol_conf.symfs[0] ||
-			    (dso__build_id_filename(dso, name, size) == NULL)) {
-				continue;
-			}
-			break;
-		case SYMTAB__FEDORA_DEBUGINFO:
-			snprintf(name, size, "%s/usr/lib/debug%s.debug",
-				 symbol_conf.symfs, dso->long_name);
-			break;
-		case SYMTAB__UBUNTU_DEBUGINFO:
-			snprintf(name, size, "%s/usr/lib/debug%s",
-				 symbol_conf.symfs, dso->long_name);
-			break;
-		case SYMTAB__BUILDID_DEBUGINFO: {
-			char build_id_hex[BUILD_ID_SIZE * 2 + 1];
-
-			if (!dso->has_build_id)
-				continue;
+	for (i = 0; i < DSO_BINARY_TYPE__SYMTAB_CNT; i++) {
 
-			build_id__sprintf(dso->build_id,
-					  sizeof(dso->build_id),
-					  build_id_hex);
-			snprintf(name, size,
-				 "%s/usr/lib/debug/.build-id/%.2s/%s.debug",
-				 symbol_conf.symfs, build_id_hex, build_id_hex + 2);
-			}
-			break;
-		case SYMTAB__SYSTEM_PATH_DSO:
-			snprintf(name, size, "%s%s",
-			     symbol_conf.symfs, dso->long_name);
-			break;
-		case SYMTAB__GUEST_KMODULE:
-			if (map->groups && machine)
-				root_dir = machine->root_dir;
-			else
-				root_dir = "";
-			snprintf(name, size, "%s%s%s", symbol_conf.symfs,
-				 root_dir, dso->long_name);
-			break;
+		dso->symtab_type = binary_type_symtab[i];
 
-		case SYMTAB__SYSTEM_PATH_KMODULE:
-			snprintf(name, size, "%s%s", symbol_conf.symfs,
-				 dso->long_name);
-			break;
-		default:;
-		}
+		if (dso__binary_type_file(dso, dso->symtab_type,
+					  root_dir, name, PATH_MAX))
+			continue;
 
 		/* Name is now the name of the next image to try */
 		fd = open(name, O_RDONLY);
@@ -1899,9 +1938,9 @@ struct map *machine__new_module(struct machine *machine, u64 start,
 		return NULL;
 
 	if (machine__is_host(machine))
-		dso->symtab_type = SYMTAB__SYSTEM_PATH_KMODULE;
+		dso->symtab_type = DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE;
 	else
-		dso->symtab_type = SYMTAB__GUEST_KMODULE;
+		dso->symtab_type = DSO_BINARY_TYPE__GUEST_KMODULE;
 	map_groups__insert(&machine->kmaps, map);
 	return map;
 }
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index ac49ef2..13c3618 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -149,6 +149,20 @@ struct addr_location {
 	s32	      cpu;
 };
 
+enum dso_binary_type {
+	DSO_BINARY_TYPE__KALLSYMS = 0,
+	DSO_BINARY_TYPE__GUEST_KALLSYMS,
+	DSO_BINARY_TYPE__JAVA_JIT,
+	DSO_BINARY_TYPE__BUILD_ID_CACHE,
+	DSO_BINARY_TYPE__FEDORA_DEBUGINFO,
+	DSO_BINARY_TYPE__UBUNTU_DEBUGINFO,
+	DSO_BINARY_TYPE__BUILDID_DEBUGINFO,
+	DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
+	DSO_BINARY_TYPE__GUEST_KMODULE,
+	DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE,
+	DSO_BINARY_TYPE__NOT_FOUND,
+};
+
 enum dso_kernel_type {
 	DSO_TYPE_USER = 0,
 	DSO_TYPE_KERNEL,
@@ -160,13 +174,13 @@ struct dso {
 	struct rb_root	 symbols[MAP__NR_TYPES];
 	struct rb_root	 symbol_names[MAP__NR_TYPES];
 	enum dso_kernel_type	kernel;
+	enum dso_binary_type	symtab_type;
 	u8		 adjust_symbols:1;
 	u8		 has_build_id:1;
 	u8		 hit:1;
 	u8		 annotate_warned:1;
 	u8		 sname_alloc:1;
 	u8		 lname_alloc:1;
-	unsigned char	 symtab_type;
 	u8		 sorted_by_name;
 	u8		 loaded;
 	u8		 build_id[BUILD_ID_SIZE];
@@ -218,20 +232,6 @@ size_t dso__fprintf_symbols_by_name(struct dso *dso,
 				    enum map_type type, FILE *fp);
 size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp);
 
-enum symtab_type {
-	SYMTAB__KALLSYMS = 0,
-	SYMTAB__GUEST_KALLSYMS,
-	SYMTAB__JAVA_JIT,
-	SYMTAB__BUILD_ID_CACHE,
-	SYMTAB__FEDORA_DEBUGINFO,
-	SYMTAB__UBUNTU_DEBUGINFO,
-	SYMTAB__BUILDID_DEBUGINFO,
-	SYMTAB__SYSTEM_PATH_DSO,
-	SYMTAB__GUEST_KMODULE,
-	SYMTAB__SYSTEM_PATH_KMODULE,
-	SYMTAB__NOT_FOUND,
-};
-
 char dso__symtab_origin(const struct dso *dso);
 void dso__set_long_name(struct dso *dso, char *name);
 void dso__set_build_id(struct dso *dso, void *build_id);
@@ -267,4 +267,6 @@ bool symbol_type__is_a(char symbol_type, enum map_type map_type);
 
 size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
 
+int dso__binary_type_file(struct dso *dso, enum dso_binary_type type,
+			  char *root_dir, char *file, size_t size);
 #endif /* __PERF_SYMBOL */
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 08/15] perf, tool: Add interface to read DSO image data
  2012-03-28 12:35 [RFC 00/15] perf: Add backtrace post dwarf unwind Jiri Olsa
                   ` (6 preceding siblings ...)
  2012-03-28 12:35 ` [PATCH 07/15] perf, tool: Factor DSO symtab types to generic binary types Jiri Olsa
@ 2012-03-28 12:35 ` Jiri Olsa
  2012-03-28 12:35 ` [PATCH 09/15] perf, tool: Add '.note' check into search for NOTE section Jiri Olsa
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 36+ messages in thread
From: Jiri Olsa @ 2012-03-28 12:35 UTC (permalink / raw)
  To: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec
  Cc: eranian, gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	fche, linux-kernel, Jiri Olsa

Adding following interface for DSO object to allow
reading of DSO image data:

  dso__data_fd
    - opens DSO and returns file descriptor
      Binary types are used to locate/open DSO in following order:
        DSO_BINARY_TYPE__BUILD_ID_CACHE
        DSO_BINARY_TYPE__SYSTEM_PATH_DSO
      In other word we first try to open DSO build-id path,
      and if that fails we try to open DSO system path.

  dso__data_read_offset
    - reads DSO data from specified offset

  dso__data_read_addr
    - reads DSO data from specified addres/map.

TODO:
  Implement read cache. Currently following no-op hooks are added:
  dso_cache_add/dso_cache_read to store/retrieve dso read data.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
---
 tools/perf/util/symbol.c |  107 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/symbol.h |    8 +++
 2 files changed, 115 insertions(+), 0 deletions(-)

diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 49f7042..2b8fa4b 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -65,6 +65,14 @@ static enum dso_binary_type binary_type_symtab[] = {
 
 #define DSO_BINARY_TYPE__SYMTAB_CNT sizeof(binary_type_symtab)
 
+static enum dso_binary_type binary_type_data[] = {
+	DSO_BINARY_TYPE__BUILD_ID_CACHE,
+	DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
+	DSO_BINARY_TYPE__NOT_FOUND,
+};
+
+#define DSO_BINARY_TYPE__DATA_CNT sizeof(binary_type_data)
+
 int dso__name_len(const struct dso *dso)
 {
 	if (verbose)
@@ -334,6 +342,7 @@ struct dso *dso__new(const char *name)
 		for (i = 0; i < MAP__NR_TYPES; ++i)
 			dso->symbols[i] = dso->symbol_names[i] = RB_ROOT;
 		dso->symtab_type = DSO_BINARY_TYPE__NOT_FOUND;
+		dso->data_type   = DSO_BINARY_TYPE__NOT_FOUND;
 		dso->loaded = 0;
 		dso->sorted_by_name = 0;
 		dso->has_build_id = 0;
@@ -2822,3 +2831,101 @@ int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
 
 	return ret;
 }
+
+static int open_dso(struct dso *dso, struct machine *machine)
+{
+	char *root_dir = (char *) "";
+	char *name;
+	int fd;
+
+	name = malloc(PATH_MAX);
+	if (!name)
+		return -ENOMEM;
+
+	if (machine)
+		root_dir = machine->root_dir;
+
+	if (dso__binary_type_file(dso, dso->data_type,
+				  root_dir, name, PATH_MAX))
+		return -EINVAL;
+
+	fd = open(name, O_RDONLY);
+	free(name);
+	return fd;
+}
+
+int dso__data_fd(struct dso *dso, struct machine *machine)
+{
+	int i = 0;
+
+	if (dso->data_type != DSO_BINARY_TYPE__NOT_FOUND)
+		return open_dso(dso, machine);
+
+	do {
+		int fd;
+
+		dso->data_type = binary_type_data[i++];
+
+		fd = open_dso(dso, machine);
+		if (fd >= 0)
+			return fd;
+
+	} while (dso->data_type != DSO_BINARY_TYPE__NOT_FOUND);
+
+	return -EINVAL;
+}
+
+static ssize_t dso_cache_read(struct dso *dso __used, u64 offset __used,
+			      u8 *data __used, ssize_t size __used)
+{
+	return -EINVAL;
+}
+
+static int dso_cache_add(struct dso *dso __used, u64 offset __used,
+			 u8 *data __used, ssize_t size __used)
+{
+	return 0;
+}
+
+static ssize_t read_dso_data(struct dso *dso, struct machine *machine,
+		     u64 offset, u8 *data, ssize_t size)
+{
+	ssize_t rsize = -1;
+	int fd;
+
+	fd = dso__data_fd(dso, machine);
+	if (fd < 0)
+		return -1;
+
+	do {
+		if (-1 == lseek(fd, offset, SEEK_SET))
+			break;
+
+		rsize = read(fd, data, size);
+		if (-1 == rsize)
+			break;
+
+		if (dso_cache_add(dso, offset, data, size))
+			pr_err("Failed to add data int dso cache.");
+
+	} while (0);
+
+	close(fd);
+	return rsize;
+}
+
+ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine,
+			      u64 offset, u8 *data, ssize_t size)
+{
+	if (dso_cache_read(dso, offset, data, size))
+		return read_dso_data(dso, machine, offset, data, size);
+	return 0;
+}
+
+ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
+			    struct machine *machine, u64 addr,
+			    u8 *data, ssize_t size)
+{
+	u64 offset = map->map_ip(map, addr);
+	return dso__data_read_offset(dso, machine, offset, data, size);
+}
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 13c3618..b62321f 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -175,6 +175,7 @@ struct dso {
 	struct rb_root	 symbol_names[MAP__NR_TYPES];
 	enum dso_kernel_type	kernel;
 	enum dso_binary_type	symtab_type;
+	enum dso_binary_type	data_type;
 	u8		 adjust_symbols:1;
 	u8		 has_build_id:1;
 	u8		 hit:1;
@@ -269,4 +270,11 @@ size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
 
 int dso__binary_type_file(struct dso *dso, enum dso_binary_type type,
 			  char *root_dir, char *file, size_t size);
+
+int dso__data_fd(struct dso *dso, struct machine *machine);
+ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine,
+			      u64 offset, u8 *data, ssize_t size);
+ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
+			    struct machine *machine, u64 addr,
+			    u8 *data, ssize_t size);
 #endif /* __PERF_SYMBOL */
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 09/15] perf, tool: Add '.note' check into search for NOTE section
  2012-03-28 12:35 [RFC 00/15] perf: Add backtrace post dwarf unwind Jiri Olsa
                   ` (7 preceding siblings ...)
  2012-03-28 12:35 ` [PATCH 08/15] perf, tool: Add interface to read DSO image data Jiri Olsa
@ 2012-03-28 12:35 ` Jiri Olsa
  2012-03-28 12:35 ` [PATCH 10/15] perf, tool: Back [vdso] DSO with real data Jiri Olsa
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 36+ messages in thread
From: Jiri Olsa @ 2012-03-28 12:35 UTC (permalink / raw)
  To: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec
  Cc: eranian, gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	fche, linux-kernel, Jiri Olsa

Adding '.note' section name to be check when looking for notes
section. The '.note' name is used by kernel VDSO.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
---
 tools/perf/util/symbol.c |   29 +++++++++++++++++++++++------
 1 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 2b8fa4b..4a0b1fa 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1473,14 +1473,31 @@ static int elf_read_build_id(Elf *elf, void *bf, size_t size)
 		goto out;
 	}
 
-	sec = elf_section_by_name(elf, &ehdr, &shdr,
-				  ".note.gnu.build-id", NULL);
-	if (sec == NULL) {
+	/*
+	 * Check following sections for notes:
+	 *   '.note.gnu.build-id'
+	 *   '.notes'
+	 *   '.note' (VDSO specific)
+	 */
+	do {
+		sec = elf_section_by_name(elf, &ehdr, &shdr,
+					  ".note.gnu.build-id", NULL);
+		if (sec)
+			break;
+
 		sec = elf_section_by_name(elf, &ehdr, &shdr,
 					  ".notes", NULL);
-		if (sec == NULL)
-			goto out;
-	}
+		if (sec)
+			break;
+
+		sec = elf_section_by_name(elf, &ehdr, &shdr,
+					  ".note", NULL);
+		if (sec)
+			break;
+
+		return err;
+
+	} while (0);
 
 	data = elf_getdata(sec, NULL);
 	if (data == NULL)
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 10/15] perf, tool: Back [vdso] DSO with real data
  2012-03-28 12:35 [RFC 00/15] perf: Add backtrace post dwarf unwind Jiri Olsa
                   ` (8 preceding siblings ...)
  2012-03-28 12:35 ` [PATCH 09/15] perf, tool: Add '.note' check into search for NOTE section Jiri Olsa
@ 2012-03-28 12:35 ` Jiri Olsa
  2012-03-28 12:35 ` [PATCH 11/15] perf, tool: Add interface to arch registers sets Jiri Olsa
                   ` (5 subsequent siblings)
  15 siblings, 0 replies; 36+ messages in thread
From: Jiri Olsa @ 2012-03-28 12:35 UTC (permalink / raw)
  To: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec
  Cc: eranian, gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	fche, linux-kernel, Jiri Olsa

Storing data for VDSO shared object, because we need it for
the unwind process.

The idea is that VDSO shared object is same for all process
on a running system, so it makes no difference if we store
it inside the tracer - perf.

The record command:
When [vdso] map memory is hit, we retrieve [vdso] DSO image
and store it into temporary file. During the build-id
processing the [vdso] DSO image is stored as in build-id db,
and build-id refference is made inside perf.data. The temporary
file is removed when record is finished.

The report command:
We read build-id from perf.data and store [vdso] DSO object.
This object is refferenced and attached to map when the MMAP
events are processed. Thus during the SAMPLE event processing
we have correct mmap/dso attached.

Adding following functions for vdso object:
  vdso__get_filename
    - finds and store VDSO image into temp file,
      the temp file path is returned

  vdso__exit
    - removes temporary VDSO image if there's any

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
---
 tools/perf/Makefile         |    2 +
 tools/perf/builtin-record.c |    3 +
 tools/perf/util/map.c       |   16 +++++++-
 tools/perf/util/vdso.c      |   92 +++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/vdso.h      |    7 +++
 5 files changed, 119 insertions(+), 1 deletions(-)
 create mode 100644 tools/perf/util/vdso.c
 create mode 100644 tools/perf/util/vdso.h

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 2f42886..1097d1d 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -317,6 +317,7 @@ LIB_H += util/cpumap.h
 LIB_H += util/top.h
 LIB_H += $(ARCH_INCLUDE)
 LIB_H += util/cgroup.h
+LIB_H += util/vdso.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
@@ -378,6 +379,7 @@ LIB_OBJS += $(OUTPUT)util/util.o
 LIB_OBJS += $(OUTPUT)util/xyarray.o
 LIB_OBJS += $(OUTPUT)util/cpumap.o
 LIB_OBJS += $(OUTPUT)util/cgroup.o
+LIB_OBJS += $(OUTPUT)util/vdso.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
 
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index be4e1ee..7b98fa9 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -26,6 +26,7 @@
 #include "util/symbol.h"
 #include "util/cpumap.h"
 #include "util/thread_map.h"
+#include "util/vdso.h"
 
 #include <unistd.h>
 #include <sched.h>
@@ -336,6 +337,7 @@ static void perf_record__exit(int status __used, void *arg)
 		perf_session__delete(rec->session);
 		perf_evlist__delete(rec->evlist);
 		symbol__exit();
+		vdso__exit();
 	}
 }
 
@@ -924,5 +926,6 @@ out_free_fd:
 	perf_evlist__delete_maps(evsel_list);
 out_symbol_exit:
 	symbol__exit();
+	vdso__exit();
 	return err;
 }
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index dea6d1c..f47dd80 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -7,6 +7,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include "map.h"
+#include "vdso.h"
 
 const char *map_type__name[MAP__NR_TYPES] = {
 	[MAP__FUNCTION] = "Functions",
@@ -18,10 +19,14 @@ static inline int is_anon_memory(const char *filename)
 	return strcmp(filename, "//anon") == 0;
 }
 
+static inline int is_vdso_memory(const char *filename)
+{
+	return !strcmp(filename, "[vdso]");
+}
+
 static inline int is_no_dso_memory(const char *filename)
 {
 	return !strcmp(filename, "[stack]") ||
-	       !strcmp(filename, "[vdso]")  ||
 	       !strcmp(filename, "[heap]");
 }
 
@@ -63,6 +68,15 @@ struct map *map__new(struct list_head *dsos__list, u64 start, u64 len,
 		if (dso == NULL)
 			goto out_delete;
 
+		if (is_vdso_memory(filename) && !dso->has_build_id) {
+			char *vdso = vdso__get_filename();
+			if (vdso) {
+				dso__set_long_name(dso, vdso);
+				pgoff = 0;
+			} else
+				no_dso = 1;
+		}
+
 		map__init(self, type, start, start + len, pgoff, dso);
 
 		if (anon || no_dso) {
diff --git a/tools/perf/util/vdso.c b/tools/perf/util/vdso.c
new file mode 100644
index 0000000..62dcdd0
--- /dev/null
+++ b/tools/perf/util/vdso.c
@@ -0,0 +1,92 @@
+
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <linux/kernel.h>
+#include "vdso.h"
+#include "util.h"
+
+static const char vdso_path[] = "/tmp/perf-vdso.so";
+static bool vdso_found;
+
+static int find_vdso_map(void **start, void **end)
+{
+	FILE *maps;
+	char line[128];
+	int found = 0;
+
+	maps = fopen("/proc/self/maps", "r");
+	if (!maps) {
+		pr_err("vdso: cannot open maps\n");
+		return -1;
+	}
+
+	while (!found && fgets(line, sizeof(line), maps)) {
+		int m = -1;
+
+		/* We care only about private r-x mappings. */
+		if (2 != sscanf(line, "%p-%p r-xp %*x %*x:%*x %*u %n",
+				start, end, &m))
+			continue;
+		if (m < 0)
+			continue;
+
+		pr_debug("vdso: start %p, end %p\n", *start, *end);
+
+		if (!strncmp(&line[m], "[vdso]", 6))
+			found = 1;
+	}
+
+	fclose(maps);
+	return !found;
+}
+
+char *vdso__get_filename(void)
+{
+	char *vdso = NULL;
+	char *buf = NULL;
+	void *start, *end;
+
+	do {
+		int fd, size;
+
+		if (vdso_found) {
+			vdso = (char *) vdso_path;
+			break;
+		}
+
+		if (find_vdso_map(&start, &end))
+			break;
+
+		size = end - start;
+		buf = malloc(size);
+		if (!buf)
+			break;
+
+		memcpy(buf, start, size);
+
+		fd = open(vdso_path, O_CREAT|O_WRONLY|O_TRUNC, S_IRWXU);
+		if (fd < 0)
+			break;
+
+		if (size == write(fd, buf, size))
+			vdso = (char *) vdso_path;
+
+		close(fd);
+	} while (0);
+
+	if (buf)
+		free(buf);
+
+	vdso_found = (vdso != NULL);
+	return vdso;
+}
+
+void vdso__exit(void)
+{
+	if (vdso_found)
+		unlink(vdso_path);
+}
diff --git a/tools/perf/util/vdso.h b/tools/perf/util/vdso.h
new file mode 100644
index 0000000..188fa9f
--- /dev/null
+++ b/tools/perf/util/vdso.h
@@ -0,0 +1,7 @@
+#ifndef __VDSO__
+#define __VDSO__
+
+char *vdso__get_filename(void);
+void  vdso__exit(void);
+
+#endif /* __VDSO__ */
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 11/15] perf, tool: Add interface to arch registers sets
  2012-03-28 12:35 [RFC 00/15] perf: Add backtrace post dwarf unwind Jiri Olsa
                   ` (9 preceding siblings ...)
  2012-03-28 12:35 ` [PATCH 10/15] perf, tool: Back [vdso] DSO with real data Jiri Olsa
@ 2012-03-28 12:35 ` Jiri Olsa
  2012-03-28 12:35 ` [PATCH 12/15] perf, tool: Add libunwind dependency for dwarf cfi unwinding Jiri Olsa
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 36+ messages in thread
From: Jiri Olsa @ 2012-03-28 12:35 UTC (permalink / raw)
  To: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec
  Cc: eranian, gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	fche, linux-kernel, Jiri Olsa

Adding header files to access unified API for arch registers.

In addition adding a way to obtain register name based on the
API ID value.

Also adding PERF_REGS_MASK macro with mask definition of
all current arch registers (will be used in unwind patches).

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
---
 tools/perf/Makefile                     |    9 +++-
 tools/perf/arch/x86/include/perf_regs.h |  101 +++++++++++++++++++++++++++++++
 tools/perf/util/perf_regs.h             |   10 +++
 3 files changed, 119 insertions(+), 1 deletions(-)
 create mode 100644 tools/perf/arch/x86/include/perf_regs.h
 create mode 100644 tools/perf/util/perf_regs.h

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 1097d1d..0f53b98 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -58,6 +58,7 @@ ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
 				  -e s/s390x/s390/ -e s/parisc64/parisc/ \
 				  -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
 				  -e s/sh[234].*/sh/ )
+NO_PERF_REGS_DEFS := 1
 
 CC = $(CROSS_COMPILE)gcc
 AR = $(CROSS_COMPILE)ar
@@ -66,7 +67,8 @@ BISON= $(CROSS_COMPILE)bison
 
 # Additional ARCH settings for x86
 ifeq ($(ARCH),i386)
-        ARCH := x86
+	ARCH := x86
+	NO_PERF_REGS_DEFS := 0
 endif
 ifeq ($(ARCH),x86_64)
 	ARCH := x86
@@ -79,6 +81,7 @@ ifeq ($(ARCH),x86_64)
 		ARCH_CFLAGS := -DARCH_X86_64
 		ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
 	endif
+	NO_PERF_REGS_DEFS := 0
 endif
 
 # Treat warnings as errors unless directed not to
@@ -318,6 +321,7 @@ LIB_H += util/top.h
 LIB_H += $(ARCH_INCLUDE)
 LIB_H += util/cgroup.h
 LIB_H += util/vdso.h
+LIB_H += util/perf_regs.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
@@ -655,6 +659,9 @@ else
 	endif
 endif
 
+ifeq ($(NO_PERF_REGS_DEFS),1)
+	BASIC_CFLAGS += -DNO_PERF_REGS_DEFS
+endif
 
 ifdef NO_STRLCPY
 	BASIC_CFLAGS += -DNO_STRLCPY
diff --git a/tools/perf/arch/x86/include/perf_regs.h b/tools/perf/arch/x86/include/perf_regs.h
new file mode 100644
index 0000000..97c0a25
--- /dev/null
+++ b/tools/perf/arch/x86/include/perf_regs.h
@@ -0,0 +1,101 @@
+#ifndef PERF_REGS_H
+#define PERF_REGS_H
+
+#include <stdlib.h>
+
+#ifdef ARCH_X86_64
+#include "../../../../../arch/x86/include/asm/perf_regs_64.h"
+#define PERF_REGS_MASK ((1 << PERF_X86_64_REG_MAX) - 1)
+
+static inline const char *perf_reg_name(int id)
+{
+	switch (id) {
+	case PERF_X86_64_REG_RAX:
+		return "RAX";
+	case PERF_X86_64_REG_RBX:
+		return "RBX";
+	case PERF_X86_64_REG_RCX:
+		return "RCX";
+	case PERF_X86_64_REG_RDX:
+		return "RDX";
+	case PERF_X86_64_REG_RSI:
+		return "RSI";
+	case PERF_X86_64_REG_RDI:
+		return "RDI";
+	case PERF_X86_64_REG_R8:
+		return "R8";
+	case PERF_X86_64_REG_R9:
+		return "R9";
+	case PERF_X86_64_REG_R10:
+		return "R10";
+	case PERF_X86_64_REG_R11:
+		return "R11";
+	case PERF_X86_64_REG_R12:
+		return "R12";
+	case PERF_X86_64_REG_R13:
+		return "R13";
+	case PERF_X86_64_REG_R14:
+		return "R14";
+	case PERF_X86_64_REG_R15:
+		return "R15";
+	case PERF_X86_64_REG_RBP:
+		return "RBP";
+	case PERF_X86_64_REG_RSP:
+		return "RSP";
+	case PERF_X86_64_REG_RIP:
+		return "RIP";
+	case PERF_X86_64_REG_FLAGS:
+		return "FLAGS";
+	case PERF_X86_64_REG_CS:
+		return "CS";
+	case PERF_X86_64_REG_SS:
+		return "SS";
+	default:
+		return NULL;
+	}
+	return NULL;
+}
+#else
+#include "../../../../../arch/x86/include/asm/perf_regs_32.h"
+#define PERF_REGS_MASK ((1 << PERF_X86_32_REG_MAX) - 1)
+
+static inline const char *perf_reg_name(int id)
+{
+	switch (id) {
+	case PERF_X86_32_REG_EAX:
+		return "EAX";
+	case PERF_X86_32_REG_EBX:
+		return "EBX";
+	case PERF_X86_32_REG_ECX:
+		return "ECX";
+	case PERF_X86_32_REG_EDX:
+		return "EDX";
+	case PERF_X86_32_REG_ESI:
+		return "ESI";
+	case PERF_X86_32_REG_EDI:
+		return "EDI";
+	case PERF_X86_32_REG_EBP:
+		return "EBP";
+	case PERF_X86_32_REG_ESP:
+		return "ESP";
+	case PERF_X86_32_REG_EIP:
+		return "EIP";
+	case PERF_X86_32_REG_FLAGS:
+		return "FLAGS";
+	case PERF_X86_32_REG_CS:
+		return "CS";
+	case PERF_X86_32_REG_DS:
+		return "DS";
+	case PERF_X86_32_REG_ES:
+		return "ES";
+	case PERF_X86_32_REG_FS:
+		return "FS";
+	case PERF_X86_32_REG_GS:
+		return "GS";
+	default:
+		return NULL;
+	}
+	return NULL;
+}
+#endif /* ARCH_X86_64 */
+#endif /* PERF_REGS_H */
diff --git a/tools/perf/util/perf_regs.h b/tools/perf/util/perf_regs.h
new file mode 100644
index 0000000..5e2a945
--- /dev/null
+++ b/tools/perf/util/perf_regs.h
@@ -0,0 +1,10 @@
+#ifndef __PERF_REGS_H
+#define __PERF_REGS_H
+
+#ifndef NO_PERF_REGS_DEFS
+#include <perf_regs.h>
+#else
+#define PERF_REGS_MASK	0
+#endif /* NO_PERF_REGS_DEFS */
+
+#endif /* __PERF_REGS_H */
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 12/15] perf, tool: Add libunwind dependency for dwarf cfi unwinding
  2012-03-28 12:35 [RFC 00/15] perf: Add backtrace post dwarf unwind Jiri Olsa
                   ` (10 preceding siblings ...)
  2012-03-28 12:35 ` [PATCH 11/15] perf, tool: Add interface to arch registers sets Jiri Olsa
@ 2012-03-28 12:35 ` Jiri Olsa
  2012-03-28 12:35 ` [PATCH 13/15] perf, tool: Support user regs and stack in sample parsing Jiri Olsa
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 36+ messages in thread
From: Jiri Olsa @ 2012-03-28 12:35 UTC (permalink / raw)
  To: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec
  Cc: eranian, gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	fche, linux-kernel, Jiri Olsa

Adding libunwind to be linked with perf if available. It's required
for the to get dwarf cfi unwinding support.

Also building perf with the dwarf call frame informations by default,
so that we can unwind callchains in perf itself.

Adding LIBUNWIND_DIR Makefile variable allowing user to specify
the directory with libunwind to be linked. This is used for
debug purposes.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
---
 tools/perf/Makefile                 |   27 ++++++++++++++++++++++++++-
 tools/perf/config/feature-tests.mak |   25 +++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 1 deletions(-)

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 0f53b98..d8b0a05 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -69,6 +69,7 @@ BISON= $(CROSS_COMPILE)bison
 ifeq ($(ARCH),i386)
 	ARCH := x86
 	NO_PERF_REGS_DEFS := 0
+	LIBUNWIND_LIBS = -lunwind -lunwind-x86
 endif
 ifeq ($(ARCH),x86_64)
 	ARCH := x86
@@ -82,6 +83,7 @@ ifeq ($(ARCH),x86_64)
 		ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
 	endif
 	NO_PERF_REGS_DEFS := 0
+	LIBUNWIND_LIBS = -lunwind -lunwind-x86_64
 endif
 
 # Treat warnings as errors unless directed not to
@@ -121,7 +123,7 @@ ifndef PERF_DEBUG
   CFLAGS_OPTIMIZE = -O6
 endif
 
-CFLAGS = -fno-omit-frame-pointer -ggdb3 -Wall -Wextra -std=gnu99 $(CFLAGS_WERROR) $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
+CFLAGS = -fno-omit-frame-pointer -ggdb3 -funwind-tables -Wall -Wextra -std=gnu99 $(CFLAGS_WERROR) $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
 EXTLIBS = -lpthread -lrt -lelf -lm
 ALL_CFLAGS = $(CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
 ALL_LDFLAGS = $(LDFLAGS)
@@ -454,6 +456,21 @@ ifneq ($(call try-cc,$(SOURCE_DWARF),$(FLAGS_DWARF)),y)
 endif # Dwarf support
 endif # NO_DWARF
 
+ifndef NO_LIBUNWIND
+# for linding with debug library, run like:
+# make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
+ifdef LIBUNWIND_DIR
+	LIBUNWIND_CFLAGS  := -I$(LIBUNWIND_DIR)/include
+	LIBUNWIND_LDFLAGS := -L$(LIBUNWIND_DIR)/lib
+endif
+
+FLAGS_UNWIND=$(LIBUNWIND_CFLAGS) $(ALL_CFLAGS) $(LIBUNWIND_LDFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) $(LIBUNWIND_LIBS)
+ifneq ($(call try-cc,$(SOURCE_LIBUNWIND),$(FLAGS_UNWIND)),y)
+	msg := $(warning No libunwind found. Please install libunwind >= 0.99);
+	NO_LIBUNWIND := 1
+endif # Libunwind support
+endif # NO_LIBUNWIND
+
 -include arch/$(ARCH)/Makefile
 
 ifneq ($(OUTPUT),)
@@ -485,6 +502,14 @@ else
 endif # PERF_HAVE_DWARF_REGS
 endif # NO_DWARF
 
+ifdef NO_LIBUNWIND
+	BASIC_CFLAGS += -DNO_LIBUNWIND_SUPPORT
+else
+	EXTLIBS += $(LIBUNWIND_LIBS)
+	BASIC_CFLAGS := $(LIBUNWIND_CFLAGS) $(BASIC_CFLAGS)
+	BASIC_LDFLAGS := $(LIBUNWIND_LDFLAGS) $(BASIC_LDFLAGS)
+endif
+
 ifdef NO_NEWT
 	BASIC_CFLAGS += -DNO_NEWT_SUPPORT
 else
diff --git a/tools/perf/config/feature-tests.mak b/tools/perf/config/feature-tests.mak
index d9084e0..51cd201 100644
--- a/tools/perf/config/feature-tests.mak
+++ b/tools/perf/config/feature-tests.mak
@@ -141,3 +141,28 @@ int main(void)
 	return 0;
 }
 endef
+
+ifndef NO_LIBUNWIND
+define SOURCE_LIBUNWIND
+#include <libunwind.h>
+#include <stdlib.h>
+
+extern int UNW_OBJ(dwarf_search_unwind_table) (unw_addr_space_t as,
+                                      unw_word_t ip,
+                                      unw_dyn_info_t *di,
+                                      unw_proc_info_t *pi,
+                                      int need_unwind_info, void *arg);
+
+
+#define dwarf_search_unwind_table UNW_OBJ(dwarf_search_unwind_table)
+
+int main(void)
+{
+	unw_addr_space_t addr_space;
+	addr_space = unw_create_addr_space(NULL, 0);
+	unw_init_remote(NULL, addr_space, NULL);
+	dwarf_search_unwind_table(addr_space, 0, NULL, NULL, 0, NULL);
+	return 0;
+}
+endef
+endif
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 13/15] perf, tool: Support user regs and stack in sample parsing
  2012-03-28 12:35 [RFC 00/15] perf: Add backtrace post dwarf unwind Jiri Olsa
                   ` (11 preceding siblings ...)
  2012-03-28 12:35 ` [PATCH 12/15] perf, tool: Add libunwind dependency for dwarf cfi unwinding Jiri Olsa
@ 2012-03-28 12:35 ` Jiri Olsa
  2012-03-28 12:35 ` [PATCH 14/15] perf, tool: Support for dwarf cfi unwinding on post processing Jiri Olsa
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 36+ messages in thread
From: Jiri Olsa @ 2012-03-28 12:35 UTC (permalink / raw)
  To: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec
  Cc: eranian, gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	fche, linux-kernel, Jiri Olsa

Adding following info to be parsed out of the event sample:
 - user register set
 - user stack dump

Both are global and specific to all events within the session.
This info will be used in the unwind patches comming in shortly.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
---
 tools/perf/builtin-test.c |    3 ++-
 tools/perf/util/event.h   |   15 ++++++++++++++-
 tools/perf/util/evlist.c  |   16 ++++++++++++++++
 tools/perf/util/evlist.h  |    2 ++
 tools/perf/util/evsel.c   |   25 +++++++++++++++++++++++++
 tools/perf/util/python.c  |    3 ++-
 tools/perf/util/session.c |    3 +++
 tools/perf/util/session.h |    7 ++++++-
 8 files changed, 70 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c
index 1c5b980..a434aaa 100644
--- a/tools/perf/builtin-test.c
+++ b/tools/perf/builtin-test.c
@@ -564,7 +564,7 @@ static int test__basic_mmap(void)
 		}
 
 		err = perf_event__parse_sample(event, attr.sample_type, sample_size,
-					       false, &sample, false);
+					       false, 0, false, &sample, false);
 		if (err) {
 			pr_err("Can't parse sample, err = %d\n", err);
 			goto out_munmap;
@@ -1307,6 +1307,7 @@ static int test__PERF_RECORD(void)
 
 				err = perf_event__parse_sample(event, sample_type,
 							       sample_size, true,
+							       0, false,
 							       &sample, false);
 				if (err < 0) {
 					if (verbose)
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 1b19728..31d3e8c 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -69,6 +69,16 @@ struct sample_event {
 	u64 array[];
 };
 
+struct user_regs {
+	u64 version;
+	u64 *regs;
+};
+
+struct user_stack_dump {
+	u64 size;
+	char *data;
+};
+
 struct perf_sample {
 	u64 ip;
 	u32 pid, tid;
@@ -82,6 +92,8 @@ struct perf_sample {
 	void *raw_data;
 	struct ip_callchain *callchain;
 	struct branch_stack *branch_stack;
+	struct user_regs uregs;
+	struct user_stack_dump stack;
 };
 
 #define BUILD_ID_SIZE 20
@@ -199,7 +211,8 @@ const char *perf_event__name(unsigned int id);
 
 int perf_event__parse_sample(const union perf_event *event, u64 type,
 			     int sample_size, bool sample_id_all,
-			     struct perf_sample *sample, bool swapped);
+			     u64 sample_uregs, bool sample_ustack,
+			     struct perf_sample *data, bool swapped);
 int perf_event__synthesize_sample(union perf_event *event, u64 type,
 				  const struct perf_sample *sample,
 				  bool swapped);
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 1986d80..70010b1 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -672,6 +672,22 @@ bool perf_evlist__valid_sample_type(const struct perf_evlist *evlist)
 	return true;
 }
 
+u64 perf_evlist_sample_uregs(const struct perf_evlist *evlist)
+{
+	struct perf_evsel *first;
+
+	first = list_entry(evlist->entries.next, struct perf_evsel, node);
+	return first->attr.user_regs;
+}
+
+bool perf_evlist_sample_ustack(const struct perf_evlist *evlist)
+{
+	struct perf_evsel *first;
+
+	first = list_entry(evlist->entries.next, struct perf_evsel, node);
+	return (first->attr.ustack_dump_size != 0);
+}
+
 u64 perf_evlist__sample_type(const struct perf_evlist *evlist)
 {
 	struct perf_evsel *first;
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 21f1c9e..2cd6c93 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -117,6 +117,8 @@ u16 perf_evlist__id_hdr_size(const struct perf_evlist *evlist);
 
 bool perf_evlist__valid_sample_type(const struct perf_evlist *evlist);
 bool perf_evlist__valid_sample_id_all(const struct perf_evlist *evlist);
+u64 perf_evlist_sample_uregs(const struct perf_evlist *evlist);
+bool perf_evlist_sample_ustack(const struct perf_evlist *evlist);
 
 void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
 				   struct list_head *list,
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 56a9689..656eaeb 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -8,6 +8,7 @@
  */
 
 #include <byteswap.h>
+#include <linux/bitops.h>
 #include "asm/bug.h"
 #include "evsel.h"
 #include "evlist.h"
@@ -453,8 +454,10 @@ static bool sample_overlap(const union perf_event *event,
 
 int perf_event__parse_sample(const union perf_event *event, u64 type,
 			     int sample_size, bool sample_id_all,
+			     u64 sample_uregs, bool sample_ustack,
 			     struct perf_sample *data, bool swapped)
 {
+	int sample_uregs_nr = hweight_long(sample_uregs);
 	const u64 *array;
 
 	/*
@@ -593,6 +596,28 @@ int perf_event__parse_sample(const union perf_event *event, u64 type,
 		sz /= sizeof(u64);
 		array += sz;
 	}
+
+	if (sample_uregs_nr) {
+		data->uregs.version = *array++;
+
+		if (data->uregs.version) {
+			data->uregs.regs = (u64 *)array;
+			array += sample_uregs_nr;
+		}
+	}
+
+	if (sample_ustack) {
+		u64 size = *array++;
+
+		if (!size) {
+			data->stack.size = 0;
+		} else {
+			data->stack.data = (char *)array;
+			array += size / sizeof(*array);
+			data->stack.size = *array;
+		}
+	}
+
 	return 0;
 }
 
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index e03b58a..257efcd 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -807,7 +807,8 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
 		first = list_entry(evlist->entries.next, struct perf_evsel, node);
 		err = perf_event__parse_sample(event, first->attr.sample_type,
 					       perf_evsel__sample_size(first),
-					       sample_id_all, &pevent->sample, false);
+					       sample_id_all, 0, false,
+					       &pevent->sample, false);
 		if (err)
 			return PyErr_Format(PyExc_OSError,
 					    "perf: can't parse sample, err=%d", err);
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 9412e3b..57b0ba2 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -86,6 +86,9 @@ void perf_session__update_sample_type(struct perf_session *self)
 	self->sample_id_all = perf_evlist__sample_id_all(self->evlist);
 	self->id_hdr_size = perf_evlist__id_hdr_size(self->evlist);
 	self->host_machine.id_hdr_size = self->id_hdr_size;
+
+	self->sample_uregs    = perf_evlist_sample_uregs(self->evlist);
+	self->sample_ustack   = perf_evlist_sample_ustack(self->evlist);
 }
 
 int perf_session__create_kernel_maps(struct perf_session *self)
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 7a5434c..182c0e5 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -42,6 +42,8 @@ struct perf_session {
 	struct hists		hists;
 	u64			sample_type;
 	int			sample_size;
+	u64			sample_uregs;
+	bool			sample_ustack;
 	int			fd;
 	bool			fd_pipe;
 	bool			repipe;
@@ -134,7 +136,10 @@ static inline int perf_session__parse_sample(struct perf_session *session,
 {
 	return perf_event__parse_sample(event, session->sample_type,
 					session->sample_size,
-					session->sample_id_all, sample,
+					session->sample_id_all,
+					session->sample_uregs,
+					session->sample_ustack,
+					sample,
 					session->header.needs_swap);
 }
 
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 14/15] perf, tool: Support for dwarf cfi unwinding on post processing
  2012-03-28 12:35 [RFC 00/15] perf: Add backtrace post dwarf unwind Jiri Olsa
                   ` (12 preceding siblings ...)
  2012-03-28 12:35 ` [PATCH 13/15] perf, tool: Support user regs and stack in sample parsing Jiri Olsa
@ 2012-03-28 12:35 ` Jiri Olsa
  2012-03-28 12:35 ` [PATCH 15/15] perf, tool: Support for dwarf mode callchain on perf record Jiri Olsa
  2012-03-29 17:04 ` [RFC 00/15] perf: Add backtrace post dwarf unwind Stephane Eranian
  15 siblings, 0 replies; 36+ messages in thread
From: Jiri Olsa @ 2012-03-28 12:35 UTC (permalink / raw)
  To: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec
  Cc: eranian, gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	fche, linux-kernel, Jiri Olsa

This brings the support for dwarf cfi unwinding on perf post
processing. Call frame informations are retrieved and then passed
to libunwind that requests memory and register content from the
applications.

Adding unwind object to handle the user stack backtrace based
on the user register values and user stack dump.

The unwind object access the libunwind via remote interface
and provides to it all the necessary data to unwind the stack.

The unwind interface provides following function:
	unwind__get_entries

And callback (specified in above function) to retrieve
the backtrace entries:
	typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry,
					 void *arg);

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
---
 tools/perf/Makefile                                |    2 +
 tools/perf/arch/x86/Makefile                       |    3 +
 tools/perf/arch/x86/util/unwind.c                  |  111 ++++
 tools/perf/builtin-report.c                        |   24 +-
 tools/perf/builtin-script.c                        |   56 ++-
 tools/perf/builtin-top.c                           |    5 +-
 tools/perf/util/include/linux/compiler.h           |    1 +
 tools/perf/util/map.h                              |    7 +-
 .../perf/util/scripting-engines/trace-event-perl.c |    3 +-
 .../util/scripting-engines/trace-event-python.c    |    3 +-
 tools/perf/util/session.c                          |   97 +++-
 tools/perf/util/session.h                          |    3 +-
 tools/perf/util/trace-event-scripting.c            |    3 +-
 tools/perf/util/trace-event.h                      |    5 +-
 tools/perf/util/unwind.c                           |  563 ++++++++++++++++++++
 tools/perf/util/unwind.h                           |   34 ++
 16 files changed, 867 insertions(+), 53 deletions(-)
 create mode 100644 tools/perf/arch/x86/util/unwind.c
 create mode 100644 tools/perf/util/unwind.c
 create mode 100644 tools/perf/util/unwind.h

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index d8b0a05..ddd4641 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -324,6 +324,7 @@ LIB_H += $(ARCH_INCLUDE)
 LIB_H += util/cgroup.h
 LIB_H += util/vdso.h
 LIB_H += util/perf_regs.h
+LIB_H += util/unwind.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
@@ -508,6 +509,7 @@ else
 	EXTLIBS += $(LIBUNWIND_LIBS)
 	BASIC_CFLAGS := $(LIBUNWIND_CFLAGS) $(BASIC_CFLAGS)
 	BASIC_LDFLAGS := $(LIBUNWIND_LDFLAGS) $(BASIC_LDFLAGS)
+	LIB_OBJS += $(OUTPUT)util/unwind.o
 endif
 
 ifdef NO_NEWT
diff --git a/tools/perf/arch/x86/Makefile b/tools/perf/arch/x86/Makefile
index 744e629..815841c 100644
--- a/tools/perf/arch/x86/Makefile
+++ b/tools/perf/arch/x86/Makefile
@@ -2,4 +2,7 @@ ifndef NO_DWARF
 PERF_HAVE_DWARF_REGS := 1
 LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
 endif
+ifndef NO_LIBUNWIND
+LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/unwind.o
+endif
 LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o
diff --git a/tools/perf/arch/x86/util/unwind.c b/tools/perf/arch/x86/util/unwind.c
new file mode 100644
index 0000000..1efae9e
--- /dev/null
+++ b/tools/perf/arch/x86/util/unwind.c
@@ -0,0 +1,111 @@
+
+#include <errno.h>
+#include <libunwind.h>
+#include "perf_regs.h"
+#include "../../util/unwind.h"
+
+#ifdef ARCH_X86_64
+int unwind__arch_reg_id(int regnum)
+{
+	int id;
+
+	switch (regnum) {
+	case UNW_X86_64_RAX:
+		id = PERF_X86_64_REG_RAX;
+		break;
+	case UNW_X86_64_RDX:
+		id = PERF_X86_64_REG_RDX;
+		break;
+	case UNW_X86_64_RCX:
+		id = PERF_X86_64_REG_RCX;
+		break;
+	case UNW_X86_64_RBX:
+		id = PERF_X86_64_REG_RBX;
+		break;
+	case UNW_X86_64_RSI:
+		id = PERF_X86_64_REG_RSI;
+		break;
+	case UNW_X86_64_RDI:
+		id = PERF_X86_64_REG_RDI;
+		break;
+	case UNW_X86_64_RBP:
+		id = PERF_X86_64_REG_RBP;
+		break;
+	case UNW_X86_64_RSP:
+		id = PERF_X86_64_REG_RSP;
+		break;
+	case UNW_X86_64_R8:
+		id = PERF_X86_64_REG_R8;
+		break;
+	case UNW_X86_64_R9:
+		id = PERF_X86_64_REG_R9;
+		break;
+	case UNW_X86_64_R10:
+		id = PERF_X86_64_REG_R10;
+		break;
+	case UNW_X86_64_R11:
+		id = PERF_X86_64_REG_R11;
+		break;
+	case UNW_X86_64_R12:
+		id = PERF_X86_64_REG_R12;
+		break;
+	case UNW_X86_64_R13:
+		id = PERF_X86_64_REG_R13;
+		break;
+	case UNW_X86_64_R14:
+		id = PERF_X86_64_REG_R14;
+		break;
+	case UNW_X86_64_R15:
+		id = PERF_X86_64_REG_R15;
+		break;
+	case UNW_X86_64_RIP:
+		id = PERF_X86_64_REG_RIP;
+		break;
+	default:
+		pr_err("can't read reg %d\n", regnum);
+		return -EINVAL;
+	}
+
+	return id;
+}
+#else
+int unwind__arch_reg_id(int regnum)
+{
+	int id;
+
+	switch (regnum) {
+	case UNW_X86_EAX:
+		id = PERF_X86_32_REG_EAX;
+		break;
+	case UNW_X86_EDX:
+		id = PERF_X86_32_REG_EDX;
+		break;
+	case UNW_X86_ECX:
+		id = PERF_X86_32_REG_ECX;
+		break;
+	case UNW_X86_EBX:
+		id = PERF_X86_32_REG_EBX;
+		break;
+	case UNW_X86_ESI:
+		id = PERF_X86_32_REG_ESI;
+		break;
+	case UNW_X86_EDI:
+		id = PERF_X86_32_REG_EDI;
+		break;
+	case UNW_X86_EBP:
+		id = PERF_X86_32_REG_EBP;
+		break;
+	case UNW_X86_ESP:
+		id = PERF_X86_32_REG_ESP;
+		break;
+	case UNW_X86_EIP:
+		id = PERF_X86_32_REG_EIP;
+		break;
+	default:
+		pr_err("can't read reg %d\n", regnum);
+		return -EINVAL;
+	}
+
+	return id;
+}
+#endif /* ARCH_X86_64 */
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 2e31743..43acaf7 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -69,8 +69,8 @@ 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,
-						 sample->callchain, &parent);
+		err = machine__resolve_callchain(rep->session, machine, evsel,
+						 al->thread, sample, &parent);
 		if (err)
 			return err;
 	}
@@ -130,7 +130,8 @@ out:
 	return err;
 }
 
-static int perf_evsel__add_hist_entry(struct perf_evsel *evsel,
+static int perf_evsel__add_hist_entry(struct perf_session *session,
+				      struct perf_evsel *evsel,
 				      struct addr_location *al,
 				      struct perf_sample *sample,
 				      struct machine *machine)
@@ -140,8 +141,8 @@ 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,
-						 sample->callchain, &parent);
+		err = machine__resolve_callchain(session, machine, evsel,
+						 al->thread, sample, &parent);
 		if (err)
 			return err;
 	}
@@ -213,7 +214,8 @@ static int process_sample_event(struct perf_tool *tool,
 		if (al.map != NULL)
 			al.map->dso->hit = 1;
 
-		if (perf_evsel__add_hist_entry(evsel, &al, sample, machine)) {
+		if (perf_evsel__add_hist_entry(rep->session, evsel, &al,
+					       sample, machine)) {
 			pr_debug("problem incrementing symbol period, skipping event\n");
 			return -1;
 		}
@@ -386,17 +388,17 @@ static int __cmd_report(struct perf_report *rep)
 "If some relocation was applied (e.g. kexec) symbols may be misresolved.");
 	}
 
-	if (dump_trace) {
-		perf_session__fprintf_nr_events(session, stdout);
-		goto out_delete;
-	}
-
 	if (verbose > 3)
 		perf_session__fprintf(session, stdout);
 
 	if (verbose > 2)
 		perf_session__fprintf_dsos(session, stdout);
 
+	if (dump_trace) {
+		perf_session__fprintf_nr_events(session, stdout);
+		goto out_delete;
+	}
+
 	nr_samples = 0;
 	list_for_each_entry(pos, &session->evlist->entries, node) {
 		struct hists *hists = &pos->hists;
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index d4ce733..0967c97 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -28,6 +28,11 @@ static bool			system_wide;
 static const char		*cpu_list;
 static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
 
+struct perf_script {
+	struct perf_tool tool;
+	struct perf_session *session;
+};
+
 enum perf_output_field {
 	PERF_OUTPUT_COMM            = 1U << 0,
 	PERF_OUTPUT_TID             = 1U << 1,
@@ -373,7 +378,8 @@ static void print_sample_addr(union perf_event *event,
 	}
 }
 
-static void print_sample_bts(union perf_event *event,
+static void print_sample_bts(struct perf_session *session,
+			     union perf_event *event,
 			     struct perf_sample *sample,
 			     struct perf_evsel *evsel,
 			     struct machine *machine,
@@ -387,7 +393,7 @@ static void print_sample_bts(union perf_event *event,
 			printf(" ");
 		else
 			printf("\n");
-		perf_event__print_ip(event, sample, machine, evsel,
+		perf_event__print_ip(session, event, sample, machine, evsel,
 				     PRINT_FIELD(SYM), PRINT_FIELD(DSO),
 				     PRINT_FIELD(SYMOFFSET));
 	}
@@ -401,7 +407,8 @@ static void print_sample_bts(union perf_event *event,
 	printf("\n");
 }
 
-static void process_event(union perf_event *event __unused,
+static void process_event(struct perf_session *session,
+			  union perf_event *event __unused,
 			  struct perf_sample *sample,
 			  struct perf_evsel *evsel,
 			  struct machine *machine,
@@ -415,7 +422,8 @@ static void process_event(union perf_event *event __unused,
 	print_sample_start(sample, thread, attr);
 
 	if (is_bts_event(attr)) {
-		print_sample_bts(event, sample, evsel, machine, thread);
+		print_sample_bts(session, event, sample, evsel,
+				 machine, thread);
 		return;
 	}
 
@@ -431,7 +439,7 @@ static void process_event(union perf_event *event __unused,
 			printf(" ");
 		else
 			printf("\n");
-		perf_event__print_ip(event, sample, machine, evsel,
+		perf_event__print_ip(session, event, sample, machine, evsel,
 				     PRINT_FIELD(SYM), PRINT_FIELD(DSO),
 				     PRINT_FIELD(SYMOFFSET));
 	}
@@ -488,6 +496,8 @@ static int process_sample_event(struct perf_tool *tool __used,
 				struct perf_evsel *evsel,
 				struct machine *machine)
 {
+	struct perf_script *script = container_of(tool, struct perf_script,
+						  tool);
 	struct addr_location al;
 	struct thread *thread = machine__findnew_thread(machine, event->ip.tid);
 
@@ -520,24 +530,27 @@ static int process_sample_event(struct perf_tool *tool __used,
 	if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
 		return 0;
 
-	scripting_ops->process_event(event, sample, evsel, machine, thread);
+	scripting_ops->process_event(script->session, event, sample, evsel,
+				     machine, thread);
 
 	evsel->hists.stats.total_period += sample->period;
 	return 0;
 }
 
-static struct perf_tool perf_script = {
-	.sample		 = process_sample_event,
-	.mmap		 = perf_event__process_mmap,
-	.comm		 = perf_event__process_comm,
-	.exit		 = perf_event__process_task,
-	.fork		 = perf_event__process_task,
-	.attr		 = perf_event__process_attr,
-	.event_type	 = perf_event__process_event_type,
-	.tracing_data	 = perf_event__process_tracing_data,
-	.build_id	 = perf_event__process_build_id,
-	.ordered_samples = true,
-	.ordering_requires_timestamps = true,
+static struct perf_script perf_script = {
+	.tool = {
+		.sample		 = process_sample_event,
+		.mmap		 = perf_event__process_mmap,
+		.comm		 = perf_event__process_comm,
+		.exit		 = perf_event__process_task,
+		.fork		 = perf_event__process_task,
+		.attr		 = perf_event__process_attr,
+		.event_type	 = perf_event__process_event_type,
+		.tracing_data	 = perf_event__process_tracing_data,
+		.build_id	 = perf_event__process_build_id,
+		.ordered_samples = true,
+		.ordering_requires_timestamps = true,
+	},
 };
 
 extern volatile int session_done;
@@ -553,7 +566,7 @@ static int __cmd_script(struct perf_session *session)
 
 	signal(SIGINT, sig_handler);
 
-	ret = perf_session__process_events(session, &perf_script);
+	ret = perf_session__process_events(session, &perf_script.tool);
 
 	if (debug_mode)
 		pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered);
@@ -1335,10 +1348,13 @@ int cmd_script(int argc, const char **argv, const char *prefix __used)
 	if (!script_name)
 		setup_pager();
 
-	session = perf_session__new(input_name, O_RDONLY, 0, false, &perf_script);
+	session = perf_session__new(input_name, O_RDONLY, 0, false,
+				    &perf_script.tool);
 	if (session == NULL)
 		return -ENOMEM;
 
+	perf_script.session = session;
+
 	if (cpu_list) {
 		if (perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap))
 			return -1;
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index c740bd0..3be3167 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -740,8 +740,9 @@ 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,
-							 sample->callchain, &parent);
+			err = machine__resolve_callchain(top->session,
+						machine, evsel, al.thread,
+						sample, &parent);
 			if (err)
 				return;
 		}
diff --git a/tools/perf/util/include/linux/compiler.h b/tools/perf/util/include/linux/compiler.h
index 547628e..2dc8671 100644
--- a/tools/perf/util/include/linux/compiler.h
+++ b/tools/perf/util/include/linux/compiler.h
@@ -10,5 +10,6 @@
 #endif
 
 #define __used		__attribute__((__unused__))
+#define __packed	__attribute__((__packed__))
 
 #endif
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index b100c20..a71a9ac 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -155,9 +155,12 @@ int machine__init(struct machine *self, const char *root_dir, pid_t pid);
 void machine__exit(struct machine *self);
 void machine__delete(struct machine *self);
 
-int machine__resolve_callchain(struct machine *machine,
+struct perf_session;
+struct perf_sample;
+int machine__resolve_callchain(struct perf_session *session,
+			       struct machine *machine,
 			       struct perf_evsel *evsel, struct thread *thread,
-			       struct ip_callchain *chain,
+			       struct perf_sample *sample,
 			       struct symbol **parent);
 int maps__set_kallsyms_ref_reloc_sym(struct map **maps, const char *symbol_name,
 				     u64 addr);
diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c
index e30749e..ae07098 100644
--- a/tools/perf/util/scripting-engines/trace-event-perl.c
+++ b/tools/perf/util/scripting-engines/trace-event-perl.c
@@ -364,7 +364,8 @@ static void perl_process_event_generic(union perf_event *pevent __unused,
 	LEAVE;
 }
 
-static void perl_process_event(union perf_event *pevent,
+static void perl_process_event(struct perf_session *session __used,
+			       union perf_event *pevent,
 			       struct perf_sample *sample,
 			       struct perf_evsel *evsel,
 			       struct machine *machine,
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index c2623c6..c593ba9 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -205,7 +205,8 @@ static inline struct event *find_cache_event(int type)
 	return event;
 }
 
-static void python_process_event(union perf_event *pevent __unused,
+static void python_process_event(struct perf_session *session,
+				 union perf_event *pevent __unused,
 				 struct perf_sample *sample,
 				 struct perf_evsel *evsel __unused,
 				 struct machine *machine __unused,
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 57b0ba2..c20a940 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -14,6 +14,8 @@
 #include "sort.h"
 #include "util.h"
 #include "cpumap.h"
+#include "unwind.h"
+#include "perf_regs.h"
 
 static int perf_session__open(struct perf_session *self, bool force)
 {
@@ -291,17 +293,17 @@ struct branch_info *machine__resolve_bstack(struct machine *self,
 	return bi;
 }
 
-int machine__resolve_callchain(struct machine *self, struct perf_evsel *evsel,
-			       struct thread *thread,
-			       struct ip_callchain *chain,
-			       struct symbol **parent)
+static int
+resolve_callchain_sample(struct machine *machine,
+			 struct perf_evsel *evsel,
+			 struct thread *thread,
+			 struct ip_callchain *chain,
+			 struct symbol **parent)
 {
 	u8 cpumode = PERF_RECORD_MISC_USER;
 	unsigned int i;
 	int err;
 
-	callchain_cursor_reset(&evsel->hists.callchain_cursor);
-
 	for (i = 0; i < chain->nr; i++) {
 		u64 ip;
 		struct addr_location al;
@@ -314,11 +316,14 @@ int machine__resolve_callchain(struct machine *self, struct perf_evsel *evsel,
 		if (ip >= PERF_CONTEXT_MAX) {
 			switch (ip) {
 			case PERF_CONTEXT_HV:
-				cpumode = PERF_RECORD_MISC_HYPERVISOR;	break;
+				cpumode = PERF_RECORD_MISC_HYPERVISOR;
+				break;
 			case PERF_CONTEXT_KERNEL:
-				cpumode = PERF_RECORD_MISC_KERNEL;	break;
+				cpumode = PERF_RECORD_MISC_KERNEL;
+				break;
 			case PERF_CONTEXT_USER:
-				cpumode = PERF_RECORD_MISC_USER;	break;
+				cpumode = PERF_RECORD_MISC_USER;
+				break;
 			default:
 				break;
 			}
@@ -326,7 +331,7 @@ int machine__resolve_callchain(struct machine *self, struct perf_evsel *evsel,
 		}
 
 		al.filtered = false;
-		thread__find_addr_location(thread, self, cpumode,
+		thread__find_addr_location(thread, machine, cpumode,
 					   MAP__FUNCTION, ip, &al, NULL);
 		if (al.sym != NULL) {
 			if (sort__has_parent && !*parent &&
@@ -345,6 +350,38 @@ int machine__resolve_callchain(struct machine *self, struct perf_evsel *evsel,
 	return 0;
 }
 
+static int unwind_entry(struct unwind_entry *entry, void *arg)
+{
+	struct callchain_cursor *cursor = arg;
+	return callchain_cursor_append(cursor, entry->ip,
+				       entry->map, entry->sym);
+}
+
+int machine__resolve_callchain(struct perf_session *session,
+			       struct machine *self,
+			       struct perf_evsel *evsel,
+			       struct thread *thread,
+			       struct perf_sample *sample,
+			       struct symbol **parent)
+{
+	int ret;
+
+	callchain_cursor_reset(&evsel->hists.callchain_cursor);
+
+	ret = resolve_callchain_sample(self, evsel, thread,
+				       sample->callchain, parent);
+	if (ret)
+		return ret;
+
+	if (!session->sample_uregs || !session->sample_ustack)
+		return 0;
+
+	return unwind__get_entries(unwind_entry,
+				   &evsel->hists.callchain_cursor,
+				   self, thread,
+				   session->sample_uregs, sample);
+}
+
 static int process_event_synth_tracing_data_stub(union perf_event *event __used,
 						 struct perf_session *session __used)
 {
@@ -771,6 +808,33 @@ static void branch_stack__printf(struct perf_sample *sample)
 			sample->branch_stack->entries[i].to);
 }
 
+static void uregs_printf(struct perf_sample *sample, u64 sample_uregs)
+{
+	struct user_regs *uregs = &sample->uregs;
+	int i = 0, rid = 0;
+
+	printf("... uregs: mask 0x%" PRIx64 "\n", sample_uregs);
+
+	do {
+		u64 val;
+
+		if (sample_uregs & 1) {
+			val = uregs->regs[i++];
+			printf(".... %-5s 0x%" PRIx64 "\n",
+			       perf_reg_name(rid), val);
+		}
+
+		rid++;
+		sample_uregs >>= 1;
+
+	} while (sample_uregs);
+}
+
+static void ustack_printf(struct perf_sample *sample)
+{
+	printf("... ustack: size %" PRIu64 "\n", sample->stack.size);
+}
+
 static void perf_session__print_tstamp(struct perf_session *session,
 				       union perf_event *event,
 				       struct perf_sample *sample)
@@ -821,6 +885,12 @@ static void dump_sample(struct perf_session *session, union perf_event *event,
 
 	if (session->sample_type & PERF_SAMPLE_BRANCH_STACK)
 		branch_stack__printf(sample);
+
+	if (session->sample_uregs)
+		uregs_printf(sample, session->sample_uregs);
+
+	if (session->sample_ustack)
+		ustack_printf(sample);
 }
 
 static struct machine *
@@ -1378,7 +1448,8 @@ struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
 	return NULL;
 }
 
-void perf_event__print_ip(union perf_event *event, struct perf_sample *sample,
+void perf_event__print_ip(struct perf_session *session,
+			  union perf_event *event, struct perf_sample *sample,
 			  struct machine *machine, struct perf_evsel *evsel,
 			  int print_sym, int print_dso, int print_symoffset)
 {
@@ -1395,8 +1466,8 @@ 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,
-						sample->callchain, NULL) != 0) {
+		if (machine__resolve_callchain(session, machine, evsel,
+					al.thread, sample, NULL) != 0) {
 			if (verbose)
 				error("Failed to resolve callchain. Skipping\n");
 			return;
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 182c0e5..090563a 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -154,7 +154,8 @@ static inline int perf_session__synthesize_sample(struct perf_session *session,
 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,
+void perf_event__print_ip(struct perf_session *session,
+			  union perf_event *event, struct perf_sample *sample,
 			  struct machine *machine, struct perf_evsel *evsel,
 			  int print_sym, int print_dso, int print_symoffset);
 
diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trace-event-scripting.c
index 18ae6c1..496c8d2 100644
--- a/tools/perf/util/trace-event-scripting.c
+++ b/tools/perf/util/trace-event-scripting.c
@@ -35,7 +35,8 @@ static int stop_script_unsupported(void)
 	return 0;
 }
 
-static void process_event_unsupported(union perf_event *event __unused,
+static void process_event_unsupported(struct perf_session *session __used,
+				      union perf_event *event __unused,
 				      struct perf_sample *sample __unused,
 				      struct perf_evsel *evsel __unused,
 				      struct machine *machine __unused,
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index 58ae14c..15b3133 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -289,11 +289,14 @@ enum trace_flag_type {
 	TRACE_FLAG_SOFTIRQ		= 0x10,
 };
 
+struct perf_session;
+
 struct scripting_ops {
 	const char *name;
 	int (*start_script) (const char *script, int argc, const char **argv);
 	int (*stop_script) (void);
-	void (*process_event) (union perf_event *event,
+	void (*process_event) (struct perf_session *session,
+			       union perf_event *event,
 			       struct perf_sample *sample,
 			       struct perf_evsel *evsel,
 			       struct machine *machine,
diff --git a/tools/perf/util/unwind.c b/tools/perf/util/unwind.c
new file mode 100644
index 0000000..7b2dbe8
--- /dev/null
+++ b/tools/perf/util/unwind.c
@@ -0,0 +1,563 @@
+/*
+ * Post mortem Dwarf CFI based unwinding on top of regs and stack dumps.
+ *
+ * Lots of this code have been borrowed or heavily inspired from parts of
+ * the libunwind 0.99 code which are (amongst other contributors I may have
+ * forgotten):
+ *
+ * Copyright (C) 2002-2007 Hewlett-Packard Co
+ *	Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
+ *
+ * And the bugs have been added by:
+ *
+ * Copyright (C) 2010, Frederic Weisbecker <fweisbec@gmail.com>
+ * Copyright (C) 2012, Jiri Olsa <jolsa@redhat.com>
+ *
+ */
+
+#include <elf.h>
+#include <gelf.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <linux/list.h>
+#include <libunwind.h>
+#include <libunwind-ptrace.h>
+#include "thread.h"
+#include "session.h"
+#include "perf_regs.h"
+#include "unwind.h"
+#include "util.h"
+
+extern int
+UNW_OBJ(dwarf_search_unwind_table) (unw_addr_space_t as,
+				    unw_word_t ip,
+				    unw_dyn_info_t *di,
+				    unw_proc_info_t *pi,
+				    int need_unwind_info, void *arg);
+
+#define dwarf_search_unwind_table UNW_OBJ(dwarf_search_unwind_table)
+
+#define DW_EH_PE_FORMAT_MASK	0x0f	/* format of the encoded value */
+#define DW_EH_PE_APPL_MASK	0x70	/* how the value is to be applied */
+
+/* Pointer-encoding formats: */
+#define DW_EH_PE_omit		0xff
+#define DW_EH_PE_ptr		0x00	/* pointer-sized unsigned value */
+#define DW_EH_PE_udata4		0x03	/* unsigned 32-bit value */
+#define DW_EH_PE_udata8		0x04	/* unsigned 64-bit value */
+#define DW_EH_PE_sdata4		0x0b	/* signed 32-bit value */
+#define DW_EH_PE_sdata8		0x0c	/* signed 64-bit value */
+
+/* Pointer-encoding application: */
+#define DW_EH_PE_absptr		0x00	/* absolute value */
+#define DW_EH_PE_pcrel		0x10	/* rel. to addr. of encoded value */
+
+/*
+ * The following are not documented by LSB v1.3, yet they are used by
+ * GCC, presumably they aren't documented by LSB since they aren't
+ * used on Linux:
+ */
+#define DW_EH_PE_funcrel	0x40	/* start-of-procedure-relative */
+#define DW_EH_PE_aligned	0x50	/* aligned pointer */
+
+/* Flags intentionaly not handled, since they're not needed:
+ * #define DW_EH_PE_indirect      0x80
+ * #define DW_EH_PE_uleb128       0x01
+ * #define DW_EH_PE_udata2        0x02
+ * #define DW_EH_PE_sleb128       0x09
+ * #define DW_EH_PE_sdata2        0x0a
+ * #define DW_EH_PE_textrel       0x20
+ * #define DW_EH_PE_datarel       0x30
+ */
+
+struct unwind_info {
+	struct perf_sample	*sample;
+	struct machine		*machine;
+	struct thread		*thread;
+	u64			sample_uregs;
+};
+
+#define dw_read(ptr, type, end) ({	\
+	type *__p = (type *) ptr;	\
+	type  __v;			\
+	if ((__p + 1) > (type *) end)	\
+		return -EINVAL;		\
+	__v = *__p++;			\
+	ptr = (typeof(ptr)) __p;	\
+	__v;				\
+	})
+
+static int __dw_read_encoded_value(u8 **p, u8 *end, u64 *val,
+				   u8 encoding)
+{
+	u8 *cur = *p;
+	*val = 0;
+
+	switch (encoding) {
+	case DW_EH_PE_omit:
+		*val = 0;
+		goto out;
+	case DW_EH_PE_ptr:
+		*val = dw_read(cur, unsigned long, end);
+		goto out;
+	default:
+		break;
+	}
+
+	switch (encoding & DW_EH_PE_APPL_MASK) {
+	case DW_EH_PE_absptr:
+		break;
+	case DW_EH_PE_pcrel:
+		*val = (unsigned long) cur;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	if ((encoding & 0x07) == 0x00)
+		encoding |= DW_EH_PE_udata4;
+
+	switch (encoding & DW_EH_PE_FORMAT_MASK) {
+	case DW_EH_PE_sdata4:
+		*val += dw_read(cur, s32, end);
+		break;
+	case DW_EH_PE_udata4:
+		*val += dw_read(cur, u32, end);
+		break;
+	case DW_EH_PE_sdata8:
+		*val += dw_read(cur, s64, end);
+		break;
+	case DW_EH_PE_udata8:
+		*val += dw_read(cur, u64, end);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+ out:
+	*p = cur;
+	return 0;
+}
+
+#define dw_read_encoded_value(ptr, end, enc) ({			\
+	u64 __v;						\
+	if (__dw_read_encoded_value(&ptr, end, &__v, enc)) {	\
+		return -EINVAL;                                 \
+	}                                                       \
+	__v;                                                    \
+	})
+
+static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
+				    GElf_Shdr *shp, const char *name)
+{
+	Elf_Scn *sec = NULL;
+
+	while ((sec = elf_nextscn(elf, sec)) != NULL) {
+		char *str;
+
+		gelf_getshdr(sec, shp);
+		str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name);
+		if (!strcmp(name, str))
+			break;
+	}
+
+	return sec;
+}
+
+static u64 elf_section_offset(int fd, const char *name)
+{
+	Elf *elf;
+	GElf_Ehdr ehdr;
+	GElf_Shdr shdr;
+	u64 offset = 0;
+
+	elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
+	if (elf == NULL)
+		return 0;
+
+	do {
+		if (gelf_getehdr(elf, &ehdr) == NULL)
+			break;
+
+		if (!elf_section_by_name(elf, &ehdr, &shdr, name))
+			break;
+
+		offset = shdr.sh_offset;
+	} while (0);
+
+	elf_end(elf);
+	return offset;
+}
+
+struct table_entry {
+	u32 start_ip_offset;
+	u32 fde_offset;
+};
+
+struct eh_frame_hdr {
+	unsigned char version;
+	unsigned char eh_frame_ptr_enc;
+	unsigned char fde_count_enc;
+	unsigned char table_enc;
+
+	/*
+	 * The rest of the header is variable-length and consists of the
+	 * following members:
+	 *
+	 *	encoded_t eh_frame_ptr;
+	 *	encoded_t fde_count;
+	 */
+
+	/* A single encoded pointer should not be more than 8 bytes. */
+	u64 enc[2];
+
+	/*
+	 * struct {
+	 *    encoded_t start_ip;
+	 *    encoded_t fde_addr;
+	 * } binary_search_table[fde_count];
+	 */
+	char data[0];
+} __packed;
+
+static int unwind_spec_ehframe(struct dso *dso, struct machine *machine,
+			       u64 offset, u64 *table_data, u64 *segbase,
+			       u64 *fde_count)
+{
+	struct eh_frame_hdr hdr;
+	u8 *enc = (u8 *) &hdr.enc;
+	u8 *end = (u8 *) &hdr.data;
+	ssize_t r;
+
+	r = dso__data_read_offset(dso, machine, offset,
+				  (u8 *) &hdr, sizeof(hdr));
+	if (r != sizeof(hdr))
+		return -EINVAL;
+
+	/* We dont need eh_frame_ptr, just skip it. */
+	dw_read_encoded_value(enc, end, hdr.eh_frame_ptr_enc);
+
+	*fde_count  = dw_read_encoded_value(enc, end, hdr.fde_count_enc);
+	*segbase    = offset;
+	*table_data = (enc - (u8 *) &hdr) + offset;
+	return 0;
+}
+
+static int read_unwind_spec(struct dso *dso, struct machine *machine,
+			    u64 *table_data, u64 *segbase, u64 *fde_count)
+{
+	int ret = -EINVAL, fd;
+	u64 offset;
+
+	fd = dso__data_fd(dso, machine);
+	if (fd < 0)
+		return -EINVAL;
+
+	offset = elf_section_offset(fd, ".eh_frame_hdr");
+	close(fd);
+
+	if (offset)
+		ret = unwind_spec_ehframe(dso, machine, offset,
+					  table_data, segbase,
+					  fde_count);
+
+	/* TODO .debug_frame check if eh_frame_hdr fails */
+	return ret;
+}
+
+static struct map *find_map(unw_word_t ip, struct unwind_info *ui)
+{
+	struct addr_location al;
+
+	thread__find_addr_map(ui->thread, ui->machine, PERF_RECORD_MISC_USER,
+			      MAP__FUNCTION, ip, &al);
+	return al.map;
+}
+
+static int
+find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
+	       int need_unwind_info, void *arg)
+{
+	struct unwind_info *ui = arg;
+	struct map *map;
+	unw_dyn_info_t di;
+	u64 table_data, segbase, fde_count;
+
+	map = find_map(ip, ui);
+	if (!map || !map->dso)
+		return -EINVAL;
+
+	if (read_unwind_spec(map->dso, ui->machine,
+			     &table_data, &segbase, &fde_count))
+		return -EINVAL;
+
+	memset(&di, 0, sizeof(di));
+	di.format   = UNW_INFO_FORMAT_REMOTE_TABLE;
+	di.start_ip = map->start;
+	di.end_ip   = map->end;
+	di.u.rti.segbase    = map->start + segbase;
+	di.u.rti.table_data = map->start + table_data;
+	di.u.rti.table_len  = fde_count * sizeof(struct table_entry)
+			      / sizeof(unw_word_t);
+	return dwarf_search_unwind_table(as, ip, &di, pi,
+					 need_unwind_info, arg);
+}
+
+static int access_fpreg(unw_addr_space_t __used as, unw_regnum_t __used num,
+			unw_fpreg_t __used *val, int __used __write,
+			void __used *arg)
+{
+	pr_err("unwind: access_fpreg unsupported\n");
+	return -UNW_EINVAL;
+}
+
+static int get_dyn_info_list_addr(unw_addr_space_t __used as,
+				  unw_word_t __used *dil_addr,
+				  void __used *arg)
+{
+	return -UNW_ENOINFO;
+}
+
+static int resume(unw_addr_space_t __used as, unw_cursor_t __used *cu,
+		  void __used *arg)
+{
+	pr_err("unwind: resume unsupported\n");
+	return -UNW_EINVAL;
+}
+
+static int
+get_proc_name(unw_addr_space_t __used as, unw_word_t __used addr,
+		char __used *bufp, size_t __used buf_len,
+		unw_word_t __used *offp, void __used *arg)
+{
+	pr_err("unwind: get_proc_name unsupported\n");
+	return -UNW_EINVAL;
+}
+
+static int access_dso_mem(struct unwind_info *ui, unw_word_t addr,
+			  unw_word_t *data)
+{
+	struct addr_location al;
+	ssize_t size;
+
+	thread__find_addr_map(ui->thread, ui->machine, PERF_RECORD_MISC_USER,
+			      MAP__FUNCTION, addr, &al);
+	if (!al.map) {
+		pr_err("unwind: not found map for %lx\n", (unsigned long)addr);
+		return -1;
+	}
+
+	if (!al.map->dso)
+		return -1;
+
+	size = dso__data_read_addr(al.map->dso, al.map, ui->machine,
+				   addr, (u8 *) data, sizeof(*data));
+
+	return !(size == sizeof(*data));
+}
+
+static int reg_value(unw_word_t *valp, struct user_regs *regs, int id,
+		     u64 sample_regs)
+{
+	int i, idx = 0;
+
+	if (!(sample_regs & (1 << id)))
+		return -EINVAL;
+
+	for (i = 0; i < id; i++) {
+		if (sample_regs & (1 << i))
+			idx++;
+	}
+
+	*valp = regs->regs[idx];
+	return 0;
+}
+
+static int access_mem(unw_addr_space_t __used as,
+		      unw_word_t addr, unw_word_t *valp,
+		      int __write, void *arg)
+{
+	struct unwind_info *ui = arg;
+	struct user_stack_dump *stack = &ui->sample->stack;
+	unw_word_t start, end;
+	int offset;
+	int ret;
+
+	/* Don't support write, probably not needed */
+	if (__write || !stack || !ui->sample->uregs.version) {
+		*valp = 0;
+		return 0;
+	}
+
+	ret = reg_value(&start, &ui->sample->uregs, PERF_REG_SP,
+			ui->sample_uregs);
+	if (ret)
+		return ret;
+
+	end = start + stack->size;
+
+	if (addr < start || addr + sizeof(unw_word_t) >= end) {
+		ret = access_dso_mem(ui, addr, valp);
+		if (ret) {
+			pr_debug("unwind: access_mem %p not inside range %p-%p\n",
+				(void *)addr, (void *)start, (void *)end);
+			*valp = 0;
+			return ret;
+		}
+		return 0;
+	}
+
+	offset = addr - start;
+	*valp  = *(unw_word_t *)&stack->data[offset];
+	pr_debug("unwind: access_mem %p %lx\n",
+		 (void *)addr, (unsigned long)*valp);
+	return 0;
+}
+
+static int access_reg(unw_addr_space_t __used as,
+		      unw_regnum_t regnum, unw_word_t *valp,
+		      int __write, void *arg)
+{
+	struct unwind_info *ui = arg;
+	int id, ret;
+
+	/* Don't support write, I suspect we don't need it. */
+	if (__write) {
+		pr_err("unwind: access_reg w %d\n", regnum);
+		return 0;
+	}
+
+	if (!ui->sample->uregs.version) {
+		*valp = 0;
+		return 0;
+	}
+
+	id = unwind__arch_reg_id(regnum);
+	if (id < 0) {
+		pr_err("unwind: can't read reg %d\n", regnum);
+		return -EINVAL;
+	}
+
+	ret = reg_value(valp, &ui->sample->uregs, id, ui->sample_uregs);
+	if (ret) {
+		pr_err("unwind: can't read reg %d\n", regnum);
+		return ret;
+	}
+
+	pr_debug("unwind: reg %d, val %lx\n", regnum, (unsigned long)*valp);
+	return 0;
+}
+
+static void put_unwind_info(unw_addr_space_t __used as,
+			    unw_proc_info_t *pi __used,
+			    void *arg __used)
+{
+	pr_debug("unwind: put_unwind_info called\n");
+}
+
+static int entry(u64 ip, struct thread *thread, struct machine *machine,
+		 unwind_entry_cb_t cb, void *arg)
+{
+	struct unwind_entry e;
+	struct addr_location al;
+
+	thread__find_addr_location(thread, machine,
+				   PERF_RECORD_MISC_USER,
+				   MAP__FUNCTION, ip, &al, NULL);
+
+	e.ip = ip;
+	e.map = al.map;
+	e.sym = al.sym;
+
+	pr_debug("unwind: %s:ip = 0x%" PRIx64 " (0x%" PRIx64 "\n",
+		 al.sym ? al.sym->name : "[]",
+		 ip,
+		 al.map ? al.map->map_ip(al.map, ip) : (u64) 0);
+
+	return cb(&e, arg);
+}
+
+static void display_error(int err)
+{
+	switch (err) {
+	case UNW_EINVAL:
+		pr_err("unwind: Only supports local.\n");
+		break;
+	case UNW_EUNSPEC:
+		pr_err("Unwind: Unspecified error.\n");
+		break;
+	case UNW_EBADREG:
+		pr_err("Unwind: Uegister unavailable.\n");
+		break;
+	default:
+		break;
+	}
+}
+
+static unw_accessors_t accessors = {
+	.find_proc_info		= find_proc_info,
+	.put_unwind_info	= put_unwind_info,
+	.get_dyn_info_list_addr	= get_dyn_info_list_addr,
+	.access_mem		= access_mem,
+	.access_reg		= access_reg,
+	.access_fpreg		= access_fpreg,
+	.resume			= resume,
+	.get_proc_name		= get_proc_name,
+};
+
+static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb,
+		       void *arg)
+{
+	unw_addr_space_t addr_space;
+	unw_cursor_t c;
+	int ret;
+
+	addr_space = unw_create_addr_space(&accessors, 0);
+	if (!addr_space) {
+		pr_err("unwind: Can't create unwind address space.\n");
+		return -ENOMEM;
+	}
+
+	ret = unw_init_remote(&c, addr_space, ui);
+	if (ret)
+		display_error(ret);
+
+	while (!ret && (unw_step(&c) > 0)) {
+		unw_word_t ip;
+
+		unw_get_reg(&c, UNW_REG_IP, &ip);
+		ret = entry(ip, ui->thread, ui->machine, cb, arg);
+	}
+
+	unw_destroy_addr_space(addr_space);
+	return ret;
+}
+
+int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
+			struct machine *machine, struct thread *thread,
+			u64 sample_uregs, struct perf_sample *data)
+{
+	unw_word_t ip;
+	struct unwind_info ui = {
+		.sample       = data,
+		.sample_uregs = sample_uregs,
+		.thread       = thread,
+		.machine      = machine,
+	};
+	int ret;
+
+	if (!data->uregs.version)
+		return -EINVAL;
+
+	ret = reg_value(&ip, &data->uregs, PERF_REG_IP, sample_uregs);
+	if (ret)
+		return ret;
+
+	ret = entry(ip, thread, machine, cb, arg);
+	if (ret)
+		return -ENOMEM;
+
+	return get_entries(&ui, cb, arg);
+}
diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h
new file mode 100644
index 0000000..919bd6a
--- /dev/null
+++ b/tools/perf/util/unwind.h
@@ -0,0 +1,34 @@
+#ifndef __UNWIND_H
+#define __UNWIND_H
+
+#include "types.h"
+#include "event.h"
+#include "symbol.h"
+
+struct unwind_entry {
+	struct map	*map;
+	struct symbol	*sym;
+	u64		ip;
+};
+
+typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg);
+
+#ifndef NO_LIBUNWIND_SUPPORT
+int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
+			struct machine *machine,
+			struct thread *thread,
+			u64 sample_uregs,
+			struct perf_sample *data);
+int unwind__arch_reg_id(int regnum);
+#else
+static inline int
+unwind__get_entries(unwind_entry_cb_t cb __used, void *arg __used,
+		    struct machine *machine __used,
+		    struct thread *thread __used,
+		    u64 sample_uregs __used,
+		    struct perf_sample *data __used)
+{
+	return 0;
+}
+#endif /* NO_LIBUNWIND_SUPPORT */
+#endif /* __UNWIND_H */
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH 15/15] perf, tool: Support for dwarf mode callchain on perf record
  2012-03-28 12:35 [RFC 00/15] perf: Add backtrace post dwarf unwind Jiri Olsa
                   ` (13 preceding siblings ...)
  2012-03-28 12:35 ` [PATCH 14/15] perf, tool: Support for dwarf cfi unwinding on post processing Jiri Olsa
@ 2012-03-28 12:35 ` Jiri Olsa
  2012-03-29 17:04 ` [RFC 00/15] perf: Add backtrace post dwarf unwind Stephane Eranian
  15 siblings, 0 replies; 36+ messages in thread
From: Jiri Olsa @ 2012-03-28 12:35 UTC (permalink / raw)
  To: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec
  Cc: eranian, gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	fche, linux-kernel, Jiri Olsa

This patch enables perf to use the dwarf unwind code.

It extends the perf record '-g' option with following arguments:
  'fp'           - provides framepointer based user
                   stack backtrace
  'dwarf[,size]' - provides dwarf (libunwind) based user stack
                   backtrace. The size specifies the size of the
                   user stack dump. If ommited it is 8192 by default.

If libunwind is found during the perf build, then the 'dwarf'
argument becomes the default option. If not, 'fp' stays as
default and 'dwarf' is not available. The '-g' usage help text
is updated accordingly.

Examples: (perf compiled with libunwind)

   perf record -g -- ls
   perf record -g dwarf ls
      - provide dwarf unwind with 8192 as stack dump size

   perf record -g dwarf,4096 ls
      - provides dwarf unwind with 4096 as stack dump size

   perf record -g fp ls
      - provides frame pointer unwind

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
---
 tools/perf/builtin-record.c |   86 ++++++++++++++++++++++++++++++++++++++++++-
 tools/perf/perf.h           |    9 ++++-
 tools/perf/util/evsel.c     |   10 ++++-
 3 files changed, 101 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 7b98fa9..578d58b 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -27,11 +27,25 @@
 #include "util/cpumap.h"
 #include "util/thread_map.h"
 #include "util/vdso.h"
+#include "util/perf_regs.h"
 
 #include <unistd.h>
 #include <sched.h>
 #include <sys/mman.h>
 
+#define CALLCHAIN_HELP "do call-graph (stack chain/backtrace) recording "
+
+#ifdef NO_LIBUNWIND_SUPPORT
+static const char callchain_default_opt[] = "fp";
+static unsigned long default_stack_dump_size;
+static char callchain_help[] = CALLCHAIN_HELP "[fp]";
+#else
+static const char callchain_default_opt[] = "dwarf";
+static unsigned long default_stack_dump_size = 8192;
+static char callchain_help[] = CALLCHAIN_HELP "[dwarf]";
+#endif
+
+
 enum write_mode_t {
 	WRITE_FORCE,
 	WRITE_APPEND
@@ -727,6 +741,73 @@ error:
 	return ret;
 }
 
+static int
+parse_callchain_opt(const struct option *opt __used, const char *arg,
+		    int unset)
+{
+	struct perf_record *rec = (struct perf_record *)opt->value;
+	char *tok, *name, *saveptr = NULL;
+	char buf[20];
+	int ret = -1;
+
+	/* --no-call-graph */
+	if (unset)
+		return 0;
+
+	/* We specified default option if none is provided. */
+	BUG_ON(!arg);
+
+	/* We need buffer that we know we can write to. */
+	snprintf(buf, 20, "%s", arg);
+
+	tok = strtok_r((char *)buf, ",", &saveptr);
+	name = tok ? : (char *)buf;
+
+	do {
+		/* Framepointer style */
+		if (!strncmp(name, "fp", sizeof("fp"))) {
+			if (!strtok_r(NULL, ",", &saveptr)) {
+				rec->opts.call_graph = CALLCHAIN_FP;
+				ret = 0;
+			} else
+				pr_err("callchain: No more arguments "
+				       "needed for -g fp\n");
+			break;
+		}
+
+		/* Dwarf style */
+		if (strncmp(name, "dwarf", sizeof("dwarf"))) {
+			pr_err("callchain: Unknown -g option "
+			       "value: %s\n", name);
+			break;
+		}
+
+		ret = 0;
+		rec->opts.call_graph = CALLCHAIN_DWARF;
+		rec->opts.stack_dump_size = default_stack_dump_size;
+
+		tok = strtok_r(NULL, ",", &saveptr);
+		if (tok) {
+			char *endptr;
+
+			rec->opts.stack_dump_size = strtoul(tok, &endptr, 0);
+			if (*endptr) {
+				pr_err("callchain: Incorrect stack "
+				       "dump size: %s\n", tok);
+				ret = -1;
+			}
+		}
+
+	} while (0);
+
+	if (!ret)
+		pr_debug("callchain: type %d, size %lu\n",
+			rec->opts.call_graph,
+			rec->opts.stack_dump_size);
+
+	return ret;
+}
+
 static const char * const record_usage[] = {
 	"perf record [<options>] [<command>]",
 	"perf record [<options>] -- <command> [<options>]",
@@ -795,8 +876,9 @@ const struct option record_options[] = {
 		     "number of mmap data pages"),
 	OPT_BOOLEAN(0, "group", &record.opts.group,
 		    "put the counters into a counter group"),
-	OPT_BOOLEAN('g', "call-graph", &record.opts.call_graph,
-		    "do call-graph (stack chain/backtrace) recording"),
+	OPT_CALLBACK_DEFAULT('g', "call-graph", &record, "mode,dump_size",
+			     callchain_help, &parse_callchain_opt,
+			     callchain_default_opt),
 	OPT_INCR('v', "verbose", &verbose,
 		    "be more verbose (show counter open errors, etc)"),
 	OPT_BOOLEAN('q', "quiet", &quiet, "don't print any message"),
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index 89e3355..505f7ff 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -207,11 +207,17 @@ extern const char perf_version_string[];
 
 void pthread__unblock_sigwinch(void);
 
+enum perf_call_graph_mode {
+	CALLCHAIN_NONE,
+	CALLCHAIN_FP,
+	CALLCHAIN_DWARF
+};
+
 struct perf_record_opts {
 	const char   *target_pid;
 	const char   *target_tid;
 	uid_t	     uid;
-	bool	     call_graph;
+	int	      call_graph;
 	bool	     group;
 	bool	     inherit_stat;
 	bool	     no_delay;
@@ -232,6 +238,7 @@ struct perf_record_opts {
 	u64	     default_interval;
 	u64	     user_interval;
 	const char   *cpu_list;
+	unsigned long stack_dump_size;
 };
 
 #endif
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 656eaeb..81c5853 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -15,6 +15,7 @@
 #include "util.h"
 #include "cpumap.h"
 #include "thread_map.h"
+#include "perf_regs.h"
 
 #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
 #define GROUP_FD(group_fd, cpu) (*(int *)xyarray__entry(group_fd, cpu, 0))
@@ -104,9 +105,16 @@ void perf_evsel__config(struct perf_evsel *evsel, struct perf_record_opts *opts,
 		attr->mmap_data = track;
 	}
 
-	if (opts->call_graph)
+	if (opts->call_graph) {
 		attr->sample_type	|= PERF_SAMPLE_CALLCHAIN;
 
+		if (opts->call_graph == CALLCHAIN_DWARF) {
+			attr->user_regs = PERF_REGS_MASK;
+			attr->ustack_dump_size = opts->stack_dump_size;
+			attr->exclude_user_callchain = 1;
+		}
+	}
+
 	if (opts->system_wide)
 		attr->sample_type	|= PERF_SAMPLE_CPU;
 
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* Re: [PATCH 04/15] perf: Add ability to dump user regs
  2012-03-28 12:35 ` [PATCH 04/15] perf: Add ability to dump user regs Jiri Olsa
@ 2012-03-28 14:01   ` Frank Ch. Eigler
  2012-03-28 14:20     ` Jiri Olsa
  2012-03-30 14:42   ` Frederic Weisbecker
  1 sibling, 1 reply; 36+ messages in thread
From: Frank Ch. Eigler @ 2012-03-28 14:01 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec, eranian,
	gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	linux-kernel, mjw

Hi, Jiri -

On Wed, Mar 28, 2012 at 02:35:47PM +0200, Jiri Olsa wrote:
> [...]
> The register value here are those of the user space context as
> it was before the user entered the kernel for whatever reason
> (syscall, irq, exception, or a PMI happening in userspace).
> [...]

As I understand the situation, there is a complication here that you
haven't accounted for.  Upon a normal syscall entry to the kernel, not
all user registers are saved explicitly for such easy retrieval.  The
others may be spilled to the stack by gcc during the various sys_*
functions or elsewhere.  It turns out that some of these saved
registers are sometimes necessary to accomplish a user-space unwind.

To recover these registers at run time, we found that the kernel stack
itself has to be partially unwound - and not via frame pointers, but
the full dwarf unwind/cfi machinery.  This RFC code does not appear
aware of the difference between the explicitly saved and the
incidentally-spilled registers, and thus may accidentally pass garbage
data to perf userspace.  Correcting this could require a kernel-space
libunwind.

- FChE

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 04/15] perf: Add ability to dump user regs
  2012-03-28 14:01   ` Frank Ch. Eigler
@ 2012-03-28 14:20     ` Jiri Olsa
  2012-03-28 15:12       ` Frank Ch. Eigler
  0 siblings, 1 reply; 36+ messages in thread
From: Jiri Olsa @ 2012-03-28 14:20 UTC (permalink / raw)
  To: Frank Ch. Eigler
  Cc: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec, eranian,
	gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	linux-kernel, mjw

On Wed, Mar 28, 2012 at 10:01:15AM -0400, Frank Ch. Eigler wrote:
> Hi, Jiri -
> 
> On Wed, Mar 28, 2012 at 02:35:47PM +0200, Jiri Olsa wrote:
> > [...]
> > The register value here are those of the user space context as
> > it was before the user entered the kernel for whatever reason
> > (syscall, irq, exception, or a PMI happening in userspace).
> > [...]
> 
> As I understand the situation, there is a complication here that you
> haven't accounted for.  Upon a normal syscall entry to the kernel, not
> all user registers are saved explicitly for such easy retrieval.  The
> others may be spilled to the stack by gcc during the various sys_*
> functions or elsewhere.  It turns out that some of these saved
> registers are sometimes necessary to accomplish a user-space unwind.

Are you reffering to x86_64 where only portion of registers
is stored by SAVE_ARGS macro? Seems like 32 bits stores the
whole pt_regs.

Generally you could need all the registers to start the unwind,
but I was assuming that for most cases the stack pointer and
instruction pointer should be enough.. but I might be wrong here.

> 
> To recover these registers at run time, we found that the kernel stack
> itself has to be partially unwound - and not via frame pointers, but
> the full dwarf unwind/cfi machinery.  This RFC code does not appear
> aware of the difference between the explicitly saved and the
> incidentally-spilled registers, and thus may accidentally pass garbage
> data to perf userspace.  Correcting this could require a kernel-space
> libunwind.

AFAIK not going to happen any time soon ;)

thanks,
jirka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 04/15] perf: Add ability to dump user regs
  2012-03-28 14:20     ` Jiri Olsa
@ 2012-03-28 15:12       ` Frank Ch. Eigler
  2012-03-28 16:01         ` Jiri Olsa
  2012-03-28 16:06         ` Frederic Weisbecker
  0 siblings, 2 replies; 36+ messages in thread
From: Frank Ch. Eigler @ 2012-03-28 15:12 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec, eranian,
	gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	linux-kernel, mjw

Hi, Jiri -

> [...]
> > [...]  Upon a normal syscall entry to the kernel, not
> > all user registers are saved explicitly for such easy retrieval.  The
> > others may be spilled to the stack by gcc during the various sys_*
> > functions or elsewhere.  [...]
> 
> Are you reffering to x86_64 where only portion of registers
> is stored by SAVE_ARGS macro? Seems like 32 bits stores the
> whole pt_regs.

I believe that's the right area.  I'm not sure even the 32-bit variant
is complete enough, for example exempting MMX/SSE registers.  These
may also contain spilled registers before long.


> Generally you could need all the registers to start the unwind, but
> I was assuming that for most cases the stack pointer and instruction
> pointer should be enough.. but I might be wrong here.

Yeah; the question is how much is missed besides those "most cases".


> > To recover these registers at run time, we found that the kernel
> > stack itself has to be partially unwound [... Without that, it ...]
> > may accidentally pass garbage data to perf userspace.  Correcting
> > this could require a kernel-space libunwind.

> AFAIK not going to happen any time soon ;)

Understood.  Then the code needs to ensure that it does not purport to
pass register values that it does not know.  (Back when we were at
this stage in systemtap, we got some reasonable backtraces even
without kernel unwinding, ie. tolerating missing registers.)


- FChE

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 04/15] perf: Add ability to dump user regs
  2012-03-28 15:12       ` Frank Ch. Eigler
@ 2012-03-28 16:01         ` Jiri Olsa
  2012-03-28 16:10           ` Frederic Weisbecker
  2012-03-28 16:06         ` Frederic Weisbecker
  1 sibling, 1 reply; 36+ messages in thread
From: Jiri Olsa @ 2012-03-28 16:01 UTC (permalink / raw)
  To: Frank Ch. Eigler
  Cc: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec, eranian,
	gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	linux-kernel, mjw

On Wed, Mar 28, 2012 at 11:12:30AM -0400, Frank Ch. Eigler wrote:
> Hi, Jiri -
> 
> > [...]
> > > [...]  Upon a normal syscall entry to the kernel, not
> > > all user registers are saved explicitly for such easy retrieval.  The
> > > others may be spilled to the stack by gcc during the various sys_*
> > > functions or elsewhere.  [...]
> > 
> > Are you reffering to x86_64 where only portion of registers
> > is stored by SAVE_ARGS macro? Seems like 32 bits stores the
> > whole pt_regs.
> 
> I believe that's the right area.  I'm not sure even the 32-bit variant
> is complete enough, for example exempting MMX/SSE registers.  These
> may also contain spilled registers before long.

right, I covered only general registers... need to check about mmc/sse

jirka

> 
> 
> > Generally you could need all the registers to start the unwind, but
> > I was assuming that for most cases the stack pointer and instruction
> > pointer should be enough.. but I might be wrong here.
> 
> Yeah; the question is how much is missed besides those "most cases".
> 
> 
> > > To recover these registers at run time, we found that the kernel
> > > stack itself has to be partially unwound [... Without that, it ...]
> > > may accidentally pass garbage data to perf userspace.  Correcting
> > > this could require a kernel-space libunwind.
> 
> > AFAIK not going to happen any time soon ;)
> 
> Understood.  Then the code needs to ensure that it does not purport to
> pass register values that it does not know.  (Back when we were at
> this stage in systemtap, we got some reasonable backtraces even
> without kernel unwinding, ie. tolerating missing registers.)
> 
> 
> - FChE

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 04/15] perf: Add ability to dump user regs
  2012-03-28 15:12       ` Frank Ch. Eigler
  2012-03-28 16:01         ` Jiri Olsa
@ 2012-03-28 16:06         ` Frederic Weisbecker
  2012-03-28 17:02           ` Jiri Olsa
  1 sibling, 1 reply; 36+ messages in thread
From: Frederic Weisbecker @ 2012-03-28 16:06 UTC (permalink / raw)
  To: Frank Ch. Eigler
  Cc: Jiri Olsa, acme, a.p.zijlstra, mingo, paulus, cjashfor, eranian,
	gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	linux-kernel, mjw

On Wed, Mar 28, 2012 at 11:12:30AM -0400, Frank Ch. Eigler wrote:
> Hi, Jiri -
> 
> > [...]
> > > [...]  Upon a normal syscall entry to the kernel, not
> > > all user registers are saved explicitly for such easy retrieval.  The
> > > others may be spilled to the stack by gcc during the various sys_*
> > > functions or elsewhere.  [...]
> > 
> > Are you reffering to x86_64 where only portion of registers
> > is stored by SAVE_ARGS macro? Seems like 32 bits stores the
> > whole pt_regs.
> 
> I believe that's the right area.  I'm not sure even the 32-bit variant
> is complete enough, for example exempting MMX/SSE registers.  These
> may also contain spilled registers before long.
> 
> 
> > Generally you could need all the registers to start the unwind, but
> > I was assuming that for most cases the stack pointer and instruction
> > pointer should be enough.. but I might be wrong here.
> 
> Yeah; the question is how much is missed besides those "most cases".
> 
> 
> > > To recover these registers at run time, we found that the kernel
> > > stack itself has to be partially unwound [... Without that, it ...]
> > > may accidentally pass garbage data to perf userspace.  Correcting
> > > this could require a kernel-space libunwind.
> 
> > AFAIK not going to happen any time soon ;)
> 
> Understood.  Then the code needs to ensure that it does not purport to
> pass register values that it does not know.  (Back when we were at
> this stage in systemtap, we got some reasonable backtraces even
> without kernel unwinding, ie. tolerating missing registers.)

Right.

I think in normal syscall case we save rdi, rsi, rdx, rax and rip.
If we take the syscall slow path we save rbx, rbp, r12-15.

Unfortunately we don't save rsp, which must be the most important
for cfi unwinding.

We probably need to check what is saved in irqs (set_irq_regs())
and exceptions as well.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 04/15] perf: Add ability to dump user regs
  2012-03-28 16:01         ` Jiri Olsa
@ 2012-03-28 16:10           ` Frederic Weisbecker
  0 siblings, 0 replies; 36+ messages in thread
From: Frederic Weisbecker @ 2012-03-28 16:10 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Frank Ch. Eigler, acme, a.p.zijlstra, mingo, paulus, cjashfor,
	eranian, gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	linux-kernel, mjw

On Wed, Mar 28, 2012 at 06:01:56PM +0200, Jiri Olsa wrote:
> On Wed, Mar 28, 2012 at 11:12:30AM -0400, Frank Ch. Eigler wrote:
> > Hi, Jiri -
> > 
> > > [...]
> > > > [...]  Upon a normal syscall entry to the kernel, not
> > > > all user registers are saved explicitly for such easy retrieval.  The
> > > > others may be spilled to the stack by gcc during the various sys_*
> > > > functions or elsewhere.  [...]
> > > 
> > > Are you reffering to x86_64 where only portion of registers
> > > is stored by SAVE_ARGS macro? Seems like 32 bits stores the
> > > whole pt_regs.
> > 
> > I believe that's the right area.  I'm not sure even the 32-bit variant
> > is complete enough, for example exempting MMX/SSE registers.  These
> > may also contain spilled registers before long.
> 
> right, I covered only general registers... need to check about mmc/sse

I think you can forget that. At least for now.

I believe in most cases you'll only need rsp for the unwinding. Then on some
tricky frame setups you might need more general registers values but I guess
this shouldn't be too frequent.

But you won't need MMX/SSE.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 04/15] perf: Add ability to dump user regs
  2012-03-28 16:06         ` Frederic Weisbecker
@ 2012-03-28 17:02           ` Jiri Olsa
  2012-03-28 21:41             ` Frederic Weisbecker
  0 siblings, 1 reply; 36+ messages in thread
From: Jiri Olsa @ 2012-03-28 17:02 UTC (permalink / raw)
  To: Frederic Weisbecker
  Cc: Frank Ch. Eigler, acme, a.p.zijlstra, mingo, paulus, cjashfor,
	eranian, gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	linux-kernel, mjw

On Wed, Mar 28, 2012 at 06:06:13PM +0200, Frederic Weisbecker wrote:
> On Wed, Mar 28, 2012 at 11:12:30AM -0400, Frank Ch. Eigler wrote:
> > Hi, Jiri -
> > 
> > > [...]
> > > > [...]  Upon a normal syscall entry to the kernel, not
> > > > all user registers are saved explicitly for such easy retrieval.  The
> > > > others may be spilled to the stack by gcc during the various sys_*
> > > > functions or elsewhere.  [...]
> > > 
> > > Are you reffering to x86_64 where only portion of registers
> > > is stored by SAVE_ARGS macro? Seems like 32 bits stores the
> > > whole pt_regs.
> > 
> > I believe that's the right area.  I'm not sure even the 32-bit variant
> > is complete enough, for example exempting MMX/SSE registers.  These
> > may also contain spilled registers before long.
> > 
> > 
> > > Generally you could need all the registers to start the unwind, but
> > > I was assuming that for most cases the stack pointer and instruction
> > > pointer should be enough.. but I might be wrong here.
> > 
> > Yeah; the question is how much is missed besides those "most cases".
> > 
> > 
> > > > To recover these registers at run time, we found that the kernel
> > > > stack itself has to be partially unwound [... Without that, it ...]
> > > > may accidentally pass garbage data to perf userspace.  Correcting
> > > > this could require a kernel-space libunwind.
> > 
> > > AFAIK not going to happen any time soon ;)
> > 
> > Understood.  Then the code needs to ensure that it does not purport to
> > pass register values that it does not know.  (Back when we were at
> > this stage in systemtap, we got some reasonable backtraces even
> > without kernel unwinding, ie. tolerating missing registers.)
> 
> Right.
> 
> I think in normal syscall case we save rdi, rsi, rdx, rax and rip.
> If we take the syscall slow path we save rbx, rbp, r12-15.
> 
> Unfortunately we don't save rsp, which must be the most important
> for cfi unwinding.

hm, I think we always have stack pointer

should be saved by cpu itself together with other control
regs like: ip cs eflags sp ss

For syscalls, we also have the ones stored by SAVE_ARGS
The rest of the registers (SAVE_REST) are available
only for the sake of the syscall_trace_enter during
the slow path, but it's poped out before executing
the actuall syscall.

jirka

> 
> We probably need to check what is saved in irqs (set_irq_regs())
> and exceptions as well.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 04/15] perf: Add ability to dump user regs
  2012-03-28 17:02           ` Jiri Olsa
@ 2012-03-28 21:41             ` Frederic Weisbecker
  0 siblings, 0 replies; 36+ messages in thread
From: Frederic Weisbecker @ 2012-03-28 21:41 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Frank Ch. Eigler, acme, a.p.zijlstra, mingo, paulus, cjashfor,
	eranian, gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	linux-kernel, mjw

On Wed, Mar 28, 2012 at 07:02:34PM +0200, Jiri Olsa wrote:
> On Wed, Mar 28, 2012 at 06:06:13PM +0200, Frederic Weisbecker wrote:
> > On Wed, Mar 28, 2012 at 11:12:30AM -0400, Frank Ch. Eigler wrote:
> > > Hi, Jiri -
> > > 
> > > > [...]
> > > > > [...]  Upon a normal syscall entry to the kernel, not
> > > > > all user registers are saved explicitly for such easy retrieval.  The
> > > > > others may be spilled to the stack by gcc during the various sys_*
> > > > > functions or elsewhere.  [...]
> > > > 
> > > > Are you reffering to x86_64 where only portion of registers
> > > > is stored by SAVE_ARGS macro? Seems like 32 bits stores the
> > > > whole pt_regs.
> > > 
> > > I believe that's the right area.  I'm not sure even the 32-bit variant
> > > is complete enough, for example exempting MMX/SSE registers.  These
> > > may also contain spilled registers before long.
> > > 
> > > 
> > > > Generally you could need all the registers to start the unwind, but
> > > > I was assuming that for most cases the stack pointer and instruction
> > > > pointer should be enough.. but I might be wrong here.
> > > 
> > > Yeah; the question is how much is missed besides those "most cases".
> > > 
> > > 
> > > > > To recover these registers at run time, we found that the kernel
> > > > > stack itself has to be partially unwound [... Without that, it ...]
> > > > > may accidentally pass garbage data to perf userspace.  Correcting
> > > > > this could require a kernel-space libunwind.
> > > 
> > > > AFAIK not going to happen any time soon ;)
> > > 
> > > Understood.  Then the code needs to ensure that it does not purport to
> > > pass register values that it does not know.  (Back when we were at
> > > this stage in systemtap, we got some reasonable backtraces even
> > > without kernel unwinding, ie. tolerating missing registers.)
> > 
> > Right.
> > 
> > I think in normal syscall case we save rdi, rsi, rdx, rax and rip.
> > If we take the syscall slow path we save rbx, rbp, r12-15.
> > 
> > Unfortunately we don't save rsp, which must be the most important
> > for cfi unwinding.
> 
> hm, I think we always have stack pointer
> 
> should be saved by cpu itself together with other control
> regs like: ip cs eflags sp ss
> 
> For syscalls, we also have the ones stored by SAVE_ARGS
> The rest of the registers (SAVE_REST) are available
> only for the sake of the syscall_trace_enter during
> the slow path, but it's poped out before executing
> the actuall syscall.

Ah good point!

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [RFC 00/15] perf: Add backtrace post dwarf unwind
  2012-03-28 12:35 [RFC 00/15] perf: Add backtrace post dwarf unwind Jiri Olsa
                   ` (14 preceding siblings ...)
  2012-03-28 12:35 ` [PATCH 15/15] perf, tool: Support for dwarf mode callchain on perf record Jiri Olsa
@ 2012-03-29 17:04 ` Stephane Eranian
  2012-03-29 23:59   ` Peter Zijlstra
  15 siblings, 1 reply; 36+ messages in thread
From: Stephane Eranian @ 2012-03-29 17:04 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec, gorcunov,
	tzanussi, mhiramat, rostedt, robert.richter, fche, linux-kernel

On Wed, Mar 28, 2012 at 5:35 AM, Jiri Olsa <jolsa@redhat.com> wrote:
> hi,
> sending RFC version of 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.
>
Although I understand why you need this for user level
dwarf unwinding, I think you also need to look at the more general
problem of capturing the machine state registers at the interrupted
IP as well. There are interesting measurements one can make with
those, such as sampling of function arguments.

I think the mechanism should allow the user to select which registers
(you have that) but also where they are captured. You have
the user level state, but you also want the interrupted state or the
precise state, i.e., extracting the register at retirement of an instruction
that caused the sampling PMU event (PEBS on Intel). Personally, I
am interested in the last two. I had a prototype patch for those.
It is based on the same approach in terms of register naming. You
need to be able to name individual registers. That's obviously arch
specific and you have that. Now there needs to be a way to indicate
where the registers must to be captured. Note that you may want
to combine user + interrupt states. So I think we may need multiple
register bitmasks.

I am aware of the security issues with smapling machine state registers
at the kernel level but they can be restricted, just like system-wide sessions.



> attached patches:
>  01/15 perf, tool: Fix the array pointer to follow event data properly
>  02/15 uaccess: Add new copy_from_user_gup API
>  03/15 perf: Unified API to record selective sets of arch registers
>  04/15 perf: Add ability to dump user regs
>  05/15 perf: Add ability to dump part of the user stack
>  06/15 perf: Add attribute to filter out user callchains
>  07/15 perf, tool: Factor DSO symtab types to generic binary types
>  08/15 perf, tool: Add interface to read DSO image data
>  09/15 perf, tool: Add '.note' check into search for NOTE section
>  10/15 perf, tool: Back [vdso] DSO with real data
>  11/15 perf, tool: Add interface to arch registers sets
>  12/15 perf, tool: Add libunwind dependency for dwarf cfi unwinding
>  13/15 perf, tool: Support user regs and stack in sample parsing
>  14/15 perf, tool: Support for dwarf cfi unwinding on post processing
>  15/15 perf, tool: Support for dwarf mode callchain on perf record
>
> The unwind processing could considerably prolong the computing
> time of the report command, but I believe this could be improved.
>   - caching DSO data accesses (as suggested in patch 8/15)
>   - maybe separate thread with unwind processing on background,
>     so the user does no need to wait for all the data to be
>     processed.
>
> 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
>
> I'd like to have some automated tests on this, but so far nothing
> smart is comming to me.. ;)
>
> thanks for comments,
> jirka
> ---
>  arch/Kconfig                                       |    7 +
>  arch/x86/Kconfig                                   |    1 +
>  arch/x86/include/asm/perf_regs.h                   |   15 +
>  arch/x86/include/asm/perf_regs_32.h                |   86 +++
>  arch/x86/include/asm/perf_regs_64.h                |  101 ++++
>  arch/x86/include/asm/uaccess.h                     |    8 +-
>  arch/x86/kernel/cpu/perf_event.c                   |    4 +-
>  arch/x86/kernel/cpu/perf_event_intel_ds.c          |    3 +-
>  arch/x86/kernel/cpu/perf_event_intel_lbr.c         |    2 +-
>  arch/x86/lib/usercopy.c                            |    4 +-
>  arch/x86/oprofile/backtrace.c                      |    4 +-
>  include/asm-generic/uaccess.h                      |    4 +
>  include/linux/perf_event.h                         |   36 ++-
>  kernel/events/callchain.c                          |    4 +-
>  kernel/events/core.c                               |  127 +++++-
>  kernel/events/internal.h                           |   59 ++-
>  kernel/events/ring_buffer.c                        |    4 +-
>  tools/perf/Makefile                                |   40 ++-
>  tools/perf/arch/x86/Makefile                       |    3 +
>  tools/perf/arch/x86/include/perf_regs.h            |  101 ++++
>  tools/perf/arch/x86/util/unwind.c                  |  111 ++++
>  tools/perf/builtin-record.c                        |   89 +++-
>  tools/perf/builtin-report.c                        |   24 +-
>  tools/perf/builtin-script.c                        |   56 ++-
>  tools/perf/builtin-test.c                          |    3 +-
>  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/event.h                            |   15 +-
>  tools/perf/util/evlist.c                           |   16 +
>  tools/perf/util/evlist.h                           |    2 +
>  tools/perf/util/evsel.c                            |   36 ++-
>  tools/perf/util/include/linux/compiler.h           |    1 +
>  tools/perf/util/map.c                              |   16 +-
>  tools/perf/util/map.h                              |    7 +-
>  tools/perf/util/perf_regs.h                        |   10 +
>  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                          |  100 +++-
>  tools/perf/util/session.h                          |   10 +-
>  tools/perf/util/symbol.c                           |  317 +++++++++---
>  tools/perf/util/symbol.h                           |   40 +-
>  tools/perf/util/trace-event-scripting.c            |    3 +-
>  tools/perf/util/trace-event.h                      |    5 +-
>  tools/perf/util/unwind.c                           |  563 ++++++++++++++++++++
>  tools/perf/util/unwind.h                           |   34 ++
>  tools/perf/util/vdso.c                             |   92 ++++
>  tools/perf/util/vdso.h                             |    7 +
>  50 files changed, 2023 insertions(+), 199 deletions(-)

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [RFC 00/15] perf: Add backtrace post dwarf unwind
  2012-03-29 17:04 ` [RFC 00/15] perf: Add backtrace post dwarf unwind Stephane Eranian
@ 2012-03-29 23:59   ` Peter Zijlstra
  2012-03-30  0:38     ` Stephane Eranian
  0 siblings, 1 reply; 36+ messages in thread
From: Peter Zijlstra @ 2012-03-29 23:59 UTC (permalink / raw)
  To: Stephane Eranian
  Cc: Jiri Olsa, acme, mingo, paulus, cjashfor, fweisbec, gorcunov,
	tzanussi, mhiramat, rostedt, robert.richter, fche, linux-kernel,
	Masami Hiramatsu

On Thu, 2012-03-29 at 10:04 -0700, Stephane Eranian wrote:
> I think the mechanism should allow the user to select which registers
> (you have that) but also where they are captured. You have
> the user level state, but you also want the interrupted state or the
> precise state, i.e., extracting the register at retirement of an
> instruction
> that caused the sampling PMU event (PEBS on Intel). Personally, I
> am interested in the last two. I had a prototype patch for those.
> It is based on the same approach in terms of register naming. You
> need to be able to name individual registers. That's obviously arch
> specific and you have that. Now there needs to be a way to indicate
> where the registers must to be captured. Note that you may want
> to combine user + interrupt states. So I think we may need multiple
> register bitmasks. 

This all comes very close to something I suggested to Masami once where
you could specify data to grab on [ku]probe hits. 

That is, when creating a [ku]probe based tracepoint you can specify
several variable/argument names and the userspace perf-probe bits will
use the dwarf info to figure out how to obtain the value of said var/arg
at the probe point (if possible, if not bail).

The kernel would simply get something along the lines of %rax->foo->bar,
or (%esp+x)->blah along with a size of the data structure to be found
there and copy whatever it finds out to the raw field.

So what you're saying is you basically want this for any possible
sample, not just [ku]probes.




^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [RFC 00/15] perf: Add backtrace post dwarf unwind
  2012-03-29 23:59   ` Peter Zijlstra
@ 2012-03-30  0:38     ` Stephane Eranian
  2012-03-30  0:44       ` Peter Zijlstra
  0 siblings, 1 reply; 36+ messages in thread
From: Stephane Eranian @ 2012-03-30  0:38 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Jiri Olsa, acme, mingo, paulus, cjashfor, fweisbec, gorcunov,
	tzanussi, mhiramat, rostedt, robert.richter, fche, linux-kernel,
	Masami Hiramatsu

On Thu, Mar 29, 2012 at 4:59 PM, Peter Zijlstra <a.p.zijlstra@chello.nl> wrote:
> On Thu, 2012-03-29 at 10:04 -0700, Stephane Eranian wrote:
>> I think the mechanism should allow the user to select which registers
>> (you have that) but also where they are captured. You have
>> the user level state, but you also want the interrupted state or the
>> precise state, i.e., extracting the register at retirement of an
>> instruction
>> that caused the sampling PMU event (PEBS on Intel). Personally, I
>> am interested in the last two. I had a prototype patch for those.
>> It is based on the same approach in terms of register naming. You
>> need to be able to name individual registers. That's obviously arch
>> specific and you have that. Now there needs to be a way to indicate
>> where the registers must to be captured. Note that you may want
>> to combine user + interrupt states. So I think we may need multiple
>> register bitmasks.
>
> This all comes very close to something I suggested to Masami once where
> you could specify data to grab on [ku]probe hits.
>
> That is, when creating a [ku]probe based tracepoint you can specify
> several variable/argument names and the userspace perf-probe bits will
> use the dwarf info to figure out how to obtain the value of said var/arg
> at the probe point (if possible, if not bail).
>
> The kernel would simply get something along the lines of %rax->foo->bar,
> or (%esp+x)->blah along with a size of the data structure to be found
> there and copy whatever it finds out to the raw field.
>
> So what you're saying is you basically want this for any possible
> sample, not just [ku]probes.
>
>
What I'd like to have is something similar to:
    attr->sample_type |= PERF_SAMPLE_REGS
    attr->sample_regs = EAX | EBX | EDI | ESI |.....
    attr->sample_reg_mode = { INTR, PRECISE, USER }

Then in each sample for the event you dump the u64 values
of the requested registers.  The order is that of the enum
enum regs {}. That enum is arch specific.

When you are in precise mode on Intel, you extract the regs
from PEBS. You already know the registers supported by PEBS
so you can reject any request for  unsupported regs.

When you are in intr they you get the regs from pt_regs.
The user mode case is taken care of by the this patch series
already.

I am not sure the sample_reg_mode needs to be a bitmask, i.e.,
do we need the reg state for INTR+PRECISE or USER+INTR?
But if so, then we would need attr->sample_regs[3] as not all
registers may be available in each mode.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [RFC 00/15] perf: Add backtrace post dwarf unwind
  2012-03-30  0:38     ` Stephane Eranian
@ 2012-03-30  0:44       ` Peter Zijlstra
  2012-03-30  0:52         ` Stephane Eranian
  0 siblings, 1 reply; 36+ messages in thread
From: Peter Zijlstra @ 2012-03-30  0:44 UTC (permalink / raw)
  To: Stephane Eranian
  Cc: Jiri Olsa, acme, mingo, paulus, cjashfor, fweisbec, gorcunov,
	tzanussi, mhiramat, rostedt, robert.richter, fche, linux-kernel,
	Masami Hiramatsu

On Thu, 2012-03-29 at 17:38 -0700, Stephane Eranian wrote:
> What I'd like to have is something similar to:
>     attr->sample_type |= PERF_SAMPLE_REGS
>     attr->sample_regs = EAX | EBX | EDI | ESI |.....
>     attr->sample_reg_mode = { INTR, PRECISE, USER }
> 
> Then in each sample for the event you dump the u64 values
> of the requested registers.  The order is that of the enum
> enum regs {}. That enum is arch specific.
> 
> When you are in precise mode on Intel, you extract the regs
> from PEBS. You already know the registers supported by PEBS
> so you can reject any request for  unsupported regs.
> 
> When you are in intr they you get the regs from pt_regs.
> The user mode case is taken care of by the this patch series
> already.
> 
> I am not sure the sample_reg_mode needs to be a bitmask, i.e.,
> do we need the reg state for INTR+PRECISE or USER+INTR?
> But if so, then we would need attr->sample_regs[3] as not all
> registers may be available in each mode. 

I'm really having trouble seeing how useful this is. You mentioned
sampling function arguments, but most samples would be in the middle of
functions where the regs are completely unrelated to arguments. Also
isn't the 'normal' C ABI passing args on stack rather than registers?




^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [RFC 00/15] perf: Add backtrace post dwarf unwind
  2012-03-30  0:44       ` Peter Zijlstra
@ 2012-03-30  0:52         ` Stephane Eranian
  2012-03-30  7:25           ` Robert Richter
  2012-03-30 12:10           ` Masami Hiramatsu
  0 siblings, 2 replies; 36+ messages in thread
From: Stephane Eranian @ 2012-03-30  0:52 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Jiri Olsa, acme, mingo, paulus, cjashfor, fweisbec, gorcunov,
	tzanussi, mhiramat, rostedt, robert.richter, fche, linux-kernel,
	Masami Hiramatsu

On Thu, Mar 29, 2012 at 5:44 PM, Peter Zijlstra <a.p.zijlstra@chello.nl> wrote:
> On Thu, 2012-03-29 at 17:38 -0700, Stephane Eranian wrote:
>> What I'd like to have is something similar to:
>>     attr->sample_type |= PERF_SAMPLE_REGS
>>     attr->sample_regs = EAX | EBX | EDI | ESI |.....
>>     attr->sample_reg_mode = { INTR, PRECISE, USER }
>>
>> Then in each sample for the event you dump the u64 values
>> of the requested registers.  The order is that of the enum
>> enum regs {}. That enum is arch specific.
>>
>> When you are in precise mode on Intel, you extract the regs
>> from PEBS. You already know the registers supported by PEBS
>> so you can reject any request for  unsupported regs.
>>
>> When you are in intr they you get the regs from pt_regs.
>> The user mode case is taken care of by the this patch series
>> already.
>>
>> I am not sure the sample_reg_mode needs to be a bitmask, i.e.,
>> do we need the reg state for INTR+PRECISE or USER+INTR?
>> But if so, then we would need attr->sample_regs[3] as not all
>> registers may be available in each mode.
>
> I'm really having trouble seeing how useful this is. You mentioned
> sampling function arguments, but most samples would be in the middle of
> functions where the regs are completely unrelated to arguments. Also
> isn't the 'normal' C ABI passing args on stack rather than registers?
>
If you look at the SNB events, you'll see that br_inst_retired:near_call
supports PEBS. The sample is taken at retirement of the call, i.e., the
first instruction of the function, exactly where you want it to be.

Unless I am mistaken, the x86_64 calling convention passes the first 6
integer arguments in registers.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [RFC 00/15] perf: Add backtrace post dwarf unwind
  2012-03-30  0:52         ` Stephane Eranian
@ 2012-03-30  7:25           ` Robert Richter
  2012-03-30 12:10           ` Masami Hiramatsu
  1 sibling, 0 replies; 36+ messages in thread
From: Robert Richter @ 2012-03-30  7:25 UTC (permalink / raw)
  To: Stephane Eranian
  Cc: Peter Zijlstra, Jiri Olsa, acme, mingo, paulus, cjashfor,
	fweisbec, gorcunov, tzanussi, mhiramat, rostedt, fche,
	linux-kernel, Masami Hiramatsu

On 29.03.12 17:52:50, Stephane Eranian wrote:
> Unless I am mistaken, the x86_64 calling convention passes the first 6
> integer arguments in registers.

This is documented here:

 http://www.x86-64.org/documentation/abi.pdf
 3.2.3 Parameter Passing

-Robert

-- 
Advanced Micro Devices, Inc.
Operating System Research Center


^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [RFC 00/15] perf: Add backtrace post dwarf unwind
  2012-03-30  0:52         ` Stephane Eranian
  2012-03-30  7:25           ` Robert Richter
@ 2012-03-30 12:10           ` Masami Hiramatsu
  2012-03-30 13:46             ` Ulrich Drepper
  2012-03-30 17:54             ` Stephane Eranian
  1 sibling, 2 replies; 36+ messages in thread
From: Masami Hiramatsu @ 2012-03-30 12:10 UTC (permalink / raw)
  To: Stephane Eranian
  Cc: Peter Zijlstra, Jiri Olsa, acme, mingo, paulus, cjashfor,
	fweisbec, gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	fche, linux-kernel, yrl.pp-manager.tt

(2012/03/30 9:52), Stephane Eranian wrote:
> On Thu, Mar 29, 2012 at 5:44 PM, Peter Zijlstra <a.p.zijlstra@chello.nl> wrote:
>> On Thu, 2012-03-29 at 17:38 -0700, Stephane Eranian wrote:
>>> What I'd like to have is something similar to:
>>>     attr->sample_type |= PERF_SAMPLE_REGS
>>>     attr->sample_regs = EAX | EBX | EDI | ESI |.....
>>>     attr->sample_reg_mode = { INTR, PRECISE, USER }
>>>
>>> Then in each sample for the event you dump the u64 values
>>> of the requested registers.  The order is that of the enum
>>> enum regs {}. That enum is arch specific.
>>>
>>> When you are in precise mode on Intel, you extract the regs
>>> from PEBS. You already know the registers supported by PEBS
>>> so you can reject any request for  unsupported regs.
>>>
>>> When you are in intr they you get the regs from pt_regs.
>>> The user mode case is taken care of by the this patch series
>>> already.
>>>
>>> I am not sure the sample_reg_mode needs to be a bitmask, i.e.,
>>> do we need the reg state for INTR+PRECISE or USER+INTR?
>>> But if so, then we would need attr->sample_regs[3] as not all
>>> registers may be available in each mode.

Would you have any good reason why we use INTR? Without PEBS,
it may mislead users because the register value can be changed
before interrupted. Personally, I would not like to use such
values for debugging use :)
So, I think this regs options may be good for the option of
PEBS events.

>> I'm really having trouble seeing how useful this is. You mentioned
>> sampling function arguments, but most samples would be in the middle of
>> functions where the regs are completely unrelated to arguments. Also
>> isn't the 'normal' C ABI passing args on stack rather than registers?
>>
> If you look at the SNB events, you'll see that br_inst_retired:near_call
> supports PEBS. The sample is taken at retirement of the call, i.e., the
> first instruction of the function, exactly where you want it to be.
> 
> Unless I am mistaken, the x86_64 calling convention passes the first 6
> integer arguments in registers.

Right, almost all function arguments are passed by register on x86-64.
Hmm, this might be useful because it can trace function register-arguments
in user-space applications... even though it causes interruption on every
sampling calls...


Thanks,

-- 
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 03/15] perf: Unified API to record selective sets of arch registers
  2012-03-28 12:35 ` [PATCH 03/15] perf: Unified API to record selective sets of arch registers Jiri Olsa
@ 2012-03-30 12:51   ` Cyrill Gorcunov
  2012-03-30 13:01     ` Jiri Olsa
  0 siblings, 1 reply; 36+ messages in thread
From: Cyrill Gorcunov @ 2012-03-30 12:51 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec, eranian,
	tzanussi, mhiramat, rostedt, robert.richter, fche, linux-kernel

On Wed, Mar 28, 2012 at 02:35:46PM +0200, Jiri Olsa wrote:
...
> +static inline u64 perf_reg_value(struct pt_regs *regs, int idx)
> +{
> +	switch (idx) {
> +	case PERF_X86_64_REG_RAX:
> +		return regs->ax;
> +	case PERF_X86_64_REG_RBX:
> +		return regs->bx;
> +	case PERF_X86_64_REG_RCX:
> +		return regs->cx;
> +	case PERF_X86_64_REG_RDX:
> +		return regs->dx;
> +	case PERF_X86_64_REG_RSI:
> +		return regs->si;
> +	case PERF_X86_64_REG_RDI:
> +		return regs->di;
> +	case PERF_X86_64_REG_R8:
> +		return regs->r8;
> +	case PERF_X86_64_REG_R9:
> +		return regs->r8;
> +	case PERF_X86_64_REG_R10:
> +		return regs->r8;
> +	case PERF_X86_64_REG_R11:
> +		return regs->r8;
> +	case PERF_X86_64_REG_R12:
> +		return regs->r8;
> +	case PERF_X86_64_REG_R13:
> +		return regs->r8;
> +	case PERF_X86_64_REG_R14:
> +		return regs->r8;
> +	case PERF_X86_64_REG_R15:
> +		return regs->r8;

I guess there are too much r8's :-)

	Cyrill

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 03/15] perf: Unified API to record selective sets of arch registers
  2012-03-30 12:51   ` Cyrill Gorcunov
@ 2012-03-30 13:01     ` Jiri Olsa
  0 siblings, 0 replies; 36+ messages in thread
From: Jiri Olsa @ 2012-03-30 13:01 UTC (permalink / raw)
  To: Cyrill Gorcunov
  Cc: acme, a.p.zijlstra, mingo, paulus, cjashfor, fweisbec, eranian,
	tzanussi, mhiramat, rostedt, robert.richter, fche, linux-kernel

On Fri, Mar 30, 2012 at 04:51:58PM +0400, Cyrill Gorcunov wrote:
> On Wed, Mar 28, 2012 at 02:35:46PM +0200, Jiri Olsa wrote:
> ...
> > +static inline u64 perf_reg_value(struct pt_regs *regs, int idx)
> > +{
> > +	switch (idx) {
> > +	case PERF_X86_64_REG_RAX:
> > +		return regs->ax;
> > +	case PERF_X86_64_REG_RBX:
> > +		return regs->bx;
> > +	case PERF_X86_64_REG_RCX:
> > +		return regs->cx;
> > +	case PERF_X86_64_REG_RDX:
> > +		return regs->dx;
> > +	case PERF_X86_64_REG_RSI:
> > +		return regs->si;
> > +	case PERF_X86_64_REG_RDI:
> > +		return regs->di;
> > +	case PERF_X86_64_REG_R8:
> > +		return regs->r8;
> > +	case PERF_X86_64_REG_R9:
> > +		return regs->r8;
> > +	case PERF_X86_64_REG_R10:
> > +		return regs->r8;
> > +	case PERF_X86_64_REG_R11:
> > +		return regs->r8;
> > +	case PERF_X86_64_REG_R12:
> > +		return regs->r8;
> > +	case PERF_X86_64_REG_R13:
> > +		return regs->r8;
> > +	case PERF_X86_64_REG_R14:
> > +		return regs->r8;
> > +	case PERF_X86_64_REG_R15:
> > +		return regs->r8;
> 
> I guess there are too much r8's :-)
> 
> 	Cyrill

yay :)) right, one should be enough..

thanks,
jirka

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [RFC 00/15] perf: Add backtrace post dwarf unwind
  2012-03-30 12:10           ` Masami Hiramatsu
@ 2012-03-30 13:46             ` Ulrich Drepper
  2012-03-30 17:54             ` Stephane Eranian
  1 sibling, 0 replies; 36+ messages in thread
From: Ulrich Drepper @ 2012-03-30 13:46 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Stephane Eranian, Peter Zijlstra, Jiri Olsa, acme, mingo, paulus,
	cjashfor, fweisbec, gorcunov, tzanussi, mhiramat, rostedt,
	robert.richter, fche, linux-kernel, yrl.pp-manager.tt

On Fri, Mar 30, 2012 at 08:10, Masami Hiramatsu
<masami.hiramatsu.pt@hitachi.com> wrote:
> Right, almost all function arguments are passed by register on x86-64.
> Hmm, this might be useful because it can trace function register-arguments
> in user-space applications... even though it causes interruption on every
> sampling calls...

You only have to do this for the first call frame and only if the
breakpoint is at the first instruction of the function.

Otherwise the register content can of course already be destroyed.

Given this, is it really worth it?  For instance, for any backtrace
from the breakpoint in kernel there is nothing at all you gain from
recording the register content.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH 04/15] perf: Add ability to dump user regs
  2012-03-28 12:35 ` [PATCH 04/15] perf: Add ability to dump user regs Jiri Olsa
  2012-03-28 14:01   ` Frank Ch. Eigler
@ 2012-03-30 14:42   ` Frederic Weisbecker
  1 sibling, 0 replies; 36+ messages in thread
From: Frederic Weisbecker @ 2012-03-30 14:42 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: acme, a.p.zijlstra, mingo, paulus, cjashfor, eranian, gorcunov,
	tzanussi, mhiramat, rostedt, robert.richter, fche, linux-kernel

On Wed, Mar 28, 2012 at 02:35:47PM +0200, Jiri Olsa wrote:
> Add new attr->user_regs bitmap that lets a user choose a set
> of user registers to dump to the sample. The layout of this
> bitmap is described in asm/perf_regs.h for archs that
> support CONFIG_HAVE_PERF_REGS_DEFS, otherwise the perf
> syscall will fail if attr->user_regs is non zero.
> 
> The register value here are those of the user space context as
> it was before the user entered the kernel for whatever reason
> (syscall, irq, exception, or a PMI happening in userspace).
> 
> This is going to be useful to bring Dwarf CFI based stack unwinding
> on top of samples.
> 
> FIXME: the issue of compat regs has yet to be solved. I think we
> need to split the regs bitmap in:
> 
> 	attr->user_regs32
> 	attr->user_regs64
> 
> So that userspace doesn't need to care about beeing a compat task or
> not, running on a 32 bits kernel or not, it can provide both bitmaps
> and let the kernel handle that, ignore user_regs64 if it is a 32 bits
> kernel, handle it otherwise and also user_regs32 for compat tasks,
> etc...
> 
> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
> Signed-off-by: Jiri Olsa <jolsa@redhat.com>
> ---
>  include/linux/perf_event.h |   26 ++++++++++++++++++
>  kernel/events/core.c       |   61 ++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 87 insertions(+), 0 deletions(-)
> 
> diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
> index ddbb6a9..9f3df6e 100644
> --- a/include/linux/perf_event.h
> +++ b/include/linux/perf_event.h
> @@ -272,6 +272,12 @@ struct perf_event_attr {
>  		__u64		config2; /* extension of config1 */
>  	};
>  	__u64	branch_sample_type; /* enum branch_sample_type */
> +
> +	/*
> +	 * Arch specific mask that defines a set of user regs to dump on
> +	 * samples. See asm/perf_regs.h for details.
> +	 */
> +	__u64			user_regs;
>  };
>  
>  /*
> @@ -1079,6 +1085,25 @@ struct perf_output_handle {
>  
>  #ifdef CONFIG_PERF_EVENTS
>  
> +#ifdef CONFIG_HAVE_PERF_REGS_DEFS
> +#include <asm/perf_regs.h>
> +#else
> +static inline int perf_reg_value(struct pt_regs *regs, int idx)
> +{
> +	return 0;
> +}
> +
> +static inline int perf_reg_version(void)
> +{
> +	return -EINVAL;
> +}
> +
> +static inline int perf_reg_validate(u64 mask)
> +{
> +	return -ENOSYS;
> +}
> +#endif /*CONFIG_HAVE_PERF_REGS_DUMP */
> +
>  extern int perf_pmu_register(struct pmu *pmu, char *name, int type);
>  extern void perf_pmu_unregister(struct pmu *pmu);
>  
> @@ -1130,6 +1155,7 @@ struct perf_sample_data {
>  	struct perf_callchain_entry	*callchain;
>  	struct perf_raw_record		*raw;
>  	struct perf_branch_stack	*br_stack;
> +	struct pt_regs			*uregs;
>  };
>  
>  static inline void perf_sample_data_init(struct perf_sample_data *data, u64 addr)
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index a6a9ec4..57f63fe 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -3751,6 +3751,37 @@ int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
>  }
>  EXPORT_SYMBOL_GPL(perf_unregister_guest_info_callbacks);
>  
> +static void
> +perf_output_sample_regs(struct perf_output_handle *handle,
> +			struct pt_regs *regs, u64 mask)
> +{
> +	int i = 0;
> +
> +	do {
> +		u64 val;
> +
> +		if (mask & 1) {
> +			val = perf_reg_value(regs, i);
> +			perf_output_put(handle, val);
> +		}
> +
> +		mask >>= 1;
> +		i++;
> +	} while (mask);
> +}
> +
> +static struct pt_regs *perf_sample_uregs(struct pt_regs *regs)
> +{
> +	if (!user_mode(regs)) {
> +		if (current->mm)
> +			regs = task_pt_regs(current);
> +		else
> +			regs = NULL;
> +	}
> +
> +	return regs;
> +}
> +
>  static void __perf_event_header__init_id(struct perf_event_header *header,
>  					 struct perf_sample_data *data,
>  					 struct perf_event *event)
> @@ -4011,6 +4042,22 @@ void perf_output_sample(struct perf_output_handle *handle,
>  			perf_output_put(handle, nr);
>  		}
>  	}
> +
> +	if (event->attr.user_regs) {
> +		u64 id;
> +
> +		/* If there is no regs to dump, notice it through a 0 version */
> +		if (!data->uregs) {
> +			id = 0;
> +			perf_output_put(handle, id);
> +		} else {
> +
> +			id = perf_reg_version();
> +			perf_output_put(handle, id);

I have the feeling we don't need this arch version thing.
Depending on the current task, whether it is a 32, compat or 64,
let the arch return the right reg value requested.

Then let the perf tools look at the elf headers of the dsos to find out the
architecture (32 - 64) of a task. On top of that we can know what we are dealing
with.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [RFC 00/15] perf: Add backtrace post dwarf unwind
  2012-03-30 12:10           ` Masami Hiramatsu
  2012-03-30 13:46             ` Ulrich Drepper
@ 2012-03-30 17:54             ` Stephane Eranian
  1 sibling, 0 replies; 36+ messages in thread
From: Stephane Eranian @ 2012-03-30 17:54 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Peter Zijlstra, Jiri Olsa, acme, mingo, paulus, cjashfor,
	fweisbec, gorcunov, tzanussi, mhiramat, rostedt, robert.richter,
	fche, linux-kernel, yrl.pp-manager.tt

On Fri, Mar 30, 2012 at 5:10 AM, Masami Hiramatsu
<masami.hiramatsu.pt@hitachi.com> wrote:
> (2012/03/30 9:52), Stephane Eranian wrote:
>> On Thu, Mar 29, 2012 at 5:44 PM, Peter Zijlstra <a.p.zijlstra@chello.nl> wrote:
>>> On Thu, 2012-03-29 at 17:38 -0700, Stephane Eranian wrote:
>>>> What I'd like to have is something similar to:
>>>>     attr->sample_type |= PERF_SAMPLE_REGS
>>>>     attr->sample_regs = EAX | EBX | EDI | ESI |.....
>>>>     attr->sample_reg_mode = { INTR, PRECISE, USER }
>>>>
>>>> Then in each sample for the event you dump the u64 values
>>>> of the requested registers.  The order is that of the enum
>>>> enum regs {}. That enum is arch specific.
>>>>
>>>> When you are in precise mode on Intel, you extract the regs
>>>> from PEBS. You already know the registers supported by PEBS
>>>> so you can reject any request for  unsupported regs.
>>>>
>>>> When you are in intr they you get the regs from pt_regs.
>>>> The user mode case is taken care of by the this patch series
>>>> already.
>>>>
>>>> I am not sure the sample_reg_mode needs to be a bitmask, i.e.,
>>>> do we need the reg state for INTR+PRECISE or USER+INTR?
>>>> But if so, then we would need attr->sample_regs[3] as not all
>>>> registers may be available in each mode.
>
> Would you have any good reason why we use INTR? Without PEBS,
> it may mislead users because the register value can be changed
> before interrupted. Personally, I would not like to use such
> values for debugging use :)

By INTR I meant PMU interrupt. That gives you the machine
state at the interrupted IP. That is interesting in the case of
stalls (sampling on cycles for instance). You may be able
to backtrack to the cause of the stalls. Take the following
simple example:

     0x1000: ld r1=[r32] <--- long latency miss
     ....
     0x100a: add r2=r1,1 <--- use point

Suppose you get a long latency miss of the load @ 0x1000,
you stall at the use point (not the load), here the add instruction
@ 0x100a. If you sample on cycles, you'll get an IP=0x100a.
No skid on stalls because you have nothing else to execute.

Let's assume r32 is not modified between 0x1000 and
0x100a, then you can figure out the miss address just
by looking at the machine state at 0x100a. You need
some static analysis of the code but this can be done.

In fact, I know that for sure because some tools did that
years ago:
http://www.supercomp.org/sc2003/paperpdfs/pap182.pdf
Section 2.2.3 for instance.

> So, I think this regs options may be good for the option of
> PEBS events.
>
Yes, that one is more obvious and requires no static analysis
of the code in most cases.

>>> I'm really having trouble seeing how useful this is. You mentioned
>>> sampling function arguments, but most samples would be in the middle of
>>> functions where the regs are completely unrelated to arguments. Also
>>> isn't the 'normal' C ABI passing args on stack rather than registers?
>>>
>> If you look at the SNB events, you'll see that br_inst_retired:near_call
>> supports PEBS. The sample is taken at retirement of the call, i.e., the
>> first instruction of the function, exactly where you want it to be.
>>
>> Unless I am mistaken, the x86_64 calling convention passes the first 6
>> integer arguments in registers.
>
> Right, almost all function arguments are passed by register on x86-64.

Including some of the FP registers but that's not captured by PEBS,
unfortunately.

> Hmm, this might be useful because it can trace function register-arguments
> in user-space applications... even though it causes interruption on every
> sampling calls...
>
It's not on every call to a function. This is statistical sampling not tracing.

Also I am not necessarily interested in using the machine state to unwind
the call stack. In the example above it's to support a local static
code analysis

^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2012-03-30 17:54 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-28 12:35 [RFC 00/15] perf: Add backtrace post dwarf unwind Jiri Olsa
2012-03-28 12:35 ` [PATCH 01/15] perf, tool: Fix the array pointer to follow event data properly Jiri Olsa
2012-03-28 12:35 ` [PATCH 02/15] uaccess: Add new copy_from_user_gup API Jiri Olsa
2012-03-28 12:35 ` [PATCH 03/15] perf: Unified API to record selective sets of arch registers Jiri Olsa
2012-03-30 12:51   ` Cyrill Gorcunov
2012-03-30 13:01     ` Jiri Olsa
2012-03-28 12:35 ` [PATCH 04/15] perf: Add ability to dump user regs Jiri Olsa
2012-03-28 14:01   ` Frank Ch. Eigler
2012-03-28 14:20     ` Jiri Olsa
2012-03-28 15:12       ` Frank Ch. Eigler
2012-03-28 16:01         ` Jiri Olsa
2012-03-28 16:10           ` Frederic Weisbecker
2012-03-28 16:06         ` Frederic Weisbecker
2012-03-28 17:02           ` Jiri Olsa
2012-03-28 21:41             ` Frederic Weisbecker
2012-03-30 14:42   ` Frederic Weisbecker
2012-03-28 12:35 ` [PATCH 05/15] perf: Add ability to dump part of the user stack Jiri Olsa
2012-03-28 12:35 ` [PATCH 06/15] perf: Add attribute to filter out user callchains Jiri Olsa
2012-03-28 12:35 ` [PATCH 07/15] perf, tool: Factor DSO symtab types to generic binary types Jiri Olsa
2012-03-28 12:35 ` [PATCH 08/15] perf, tool: Add interface to read DSO image data Jiri Olsa
2012-03-28 12:35 ` [PATCH 09/15] perf, tool: Add '.note' check into search for NOTE section Jiri Olsa
2012-03-28 12:35 ` [PATCH 10/15] perf, tool: Back [vdso] DSO with real data Jiri Olsa
2012-03-28 12:35 ` [PATCH 11/15] perf, tool: Add interface to arch registers sets Jiri Olsa
2012-03-28 12:35 ` [PATCH 12/15] perf, tool: Add libunwind dependency for dwarf cfi unwinding Jiri Olsa
2012-03-28 12:35 ` [PATCH 13/15] perf, tool: Support user regs and stack in sample parsing Jiri Olsa
2012-03-28 12:35 ` [PATCH 14/15] perf, tool: Support for dwarf cfi unwinding on post processing Jiri Olsa
2012-03-28 12:35 ` [PATCH 15/15] perf, tool: Support for dwarf mode callchain on perf record Jiri Olsa
2012-03-29 17:04 ` [RFC 00/15] perf: Add backtrace post dwarf unwind Stephane Eranian
2012-03-29 23:59   ` Peter Zijlstra
2012-03-30  0:38     ` Stephane Eranian
2012-03-30  0:44       ` Peter Zijlstra
2012-03-30  0:52         ` Stephane Eranian
2012-03-30  7:25           ` Robert Richter
2012-03-30 12:10           ` Masami Hiramatsu
2012-03-30 13:46             ` Ulrich Drepper
2012-03-30 17:54             ` Stephane Eranian

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.