Skip to contentSkip to conversation

powerpc/perf: Adjust callchain based on DWARF debug info

PATCH Jiri Olsa 2 participants 4 messages Jun 2, 2014 – Jun 4, 2014 1 message not in the archive perf events

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Jiri Olsa

author
#1 lore raw
Quoted 16 lines · Jiri Olsa
Quoted 15 lines · Sukadev Bhattiprolu

Jiri Olsa [[email protected]] wrote:

| On Fri, May 16, 2014 at 02:03:33PM -0700, Sukadev Bhattiprolu wrote:
| > Hi Arnaldo, Jiri
| > 
| > Do you have any comments on this patch ? Pls let me know if you need
| > me to resend this. The TODO is for a less frequent case and can be
| > addressed independently.
| 
| hi,
| I can take it, but it does not apply to my perf/core,
| there're some ARM related unwind changes already:
|   git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
| 
| please resend updated patch
Quoted 9 lines
Quoted 6 lines

Jiri,

I resent the patch. Can you please let me know if you have any comments ?

	https://lkml.org/lkml/2014/5/22/695

sry, got distracted.. yep, that one seems looks ok now, I'll queue it

so.. I tried some performance test and looks like this adds some considerable penalty also for archs != powerpc

test data:

  $ sudo ./perf record -a -g -F 50000 # perf.data size is ~1.1GB

before your patch:

Performance counter stats for './perf.old report --stdio' (5 runs):

    60,345,248,146      cycles                     ( +-  0.50% ) █▁▁▂▂
    72,766,496,819      instructions              #    1.21  insns per cycle          ( +-  0.00% ) █▁▄▁▅

      19.930324523 seconds time elapsed                                          ( +-  1.07% ) █▄▁▁▁

with your patch:

    62,559,079,470      cycles                     ( +-  2.10% ) ▁▁▂▁█
    72,649,781,930      instructions              #    1.16  insns per cycle          ( +-  0.00% ) ▄▃▅█▁

      23.355028944 seconds time elapsed                                          ( +-  9.85% ) ▁▁▁▂█

I think the issue is following hunk (I havent verified with record/report):

@@ -1300,14 +1301,25 @@ static int machine__resolve_callchain_sample(struct machine *machine,

                return 0;
        }

+ /*

+        * Based on DWARF debug information, some architectures skip
+        * some of the callchain entries saved by the kernel.
+        */
+       skip_slot = arch_skip_callchain_idx(machine, thread, chain);
+
        for (i = 0; i < chain_nr; i++) {
                u64 ip;
                struct addr_location al;

- if (callchain_param.order == ORDER_CALLEE)
+ if (callchain_param.order == ORDER_CALLEE) {
+ if (i == skip_slot)

+                               continue;
                        ip = chain->ips[i];
-               else
+               } else {
+                       if ((int)(chain->nr - i - 1) == skip_slot)
+                               continue;
                        ip = chain->ips[chain->nr - i - 1];

+ }

could you please change this, so it's nop for arch != powerpc via #ifdef I guess.. or some other smart way ;-)

adding some other folks and lkml to the loop

thanks,
jirka

#2 lore raw

Jiri Olsa [[email protected]] wrote:

| On Fri, May 30, 2014 at 05:59:25PM +0200, Jiri Olsa wrote:
| > On Fri, May 30, 2014 at 08:50:19AM -0700, Sukadev Bhattiprolu wrote:
| > > Jiri Olsa [[email protected]] wrote:
| > > | On Fri, May 16, 2014 at 02:03:33PM -0700, Sukadev Bhattiprolu wrote:
| > > | > Hi Arnaldo, Jiri
| > > | > 
| > > | > Do you have any comments on this patch ? Pls let me know if you need
| > > | > me to resend this. The TODO is for a less frequent case and can be
| > > | > addressed independently.
| > > | 
| > > | hi,
| > > | I can take it, but it does not apply to my perf/core,
| > > | there're some ARM related unwind changes already:
| > > |   git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
| > > | 
| > > | please resend updated patch
| > > 
| > > Jiri,
| > > 
| > > I resent the patch. Can you please let me know if you have any
| > > comments ?
| > > 
| > > 	https://lkml.org/lkml/2014/5/22/695
| > 
| > sry, got distracted.. yep, that one seems looks ok now, I'll queue it
| > 
| 
| so.. I tried some performance test and looks like this
| adds some considerable penalty also for archs != powerpc
| 
| test data:
|   $ sudo ./perf record -a -g -F 50000 # perf.data size is ~1.1GB
| 
| before your patch:
| 
|  Performance counter stats for './perf.old report --stdio' (5 runs):
| 
|     60,345,248,146      cycles                     ( +-  0.50% ) █▁▁▂▂
|     72,766,496,819      instructions              #    1.21  insns per cycle          ( +-  0.00% ) █▁▄▁▅
| 
|       19.930324523 seconds time elapsed                                          ( +-  1.07% ) █▄▁▁▁
| 
| with your patch:
|     62,559,079,470      cycles                     ( +-  2.10% ) ▁▁▂▁█
|     72,649,781,930      instructions              #    1.16  insns per cycle          ( +-  0.00% ) ▄▃▅█▁
| 
|       23.355028944 seconds time elapsed                                          ( +-  9.85% ) ▁▁▁▂█
| 
| 
| I think the issue is following hunk (I havent verified with record/report):
| 
| @@ -1300,14 +1301,25 @@ static int machine__resolve_callchain_sample(struct machine *machine,
|                 return 0;
|         }
| 
| +       /*
| +        * Based on DWARF debug information, some architectures skip
| +        * some of the callchain entries saved by the kernel.
| +        */
| +       skip_slot = arch_skip_callchain_idx(machine, thread, chain);
| +
|         for (i = 0; i < chain_nr; i++) {
|                 u64 ip;
|                 struct addr_location al;
| 
| -               if (callchain_param.order == ORDER_CALLEE)
| +               if (callchain_param.order == ORDER_CALLEE) {
| +                       if (i == skip_slot)
| +                               continue;
|                         ip = chain->ips[i];
| -               else
| +               } else {
| +                       if ((int)(chain->nr - i - 1) == skip_slot)
| +                               continue;
|                         ip = chain->ips[chain->nr - i - 1];
| +               }
| 
| 
| could you please change this, so it's nop for arch != powerpc
| via #ifdef I guess.. or some other smart way ;-)

I was trying to avoid the #ifdef in the middle of the function.

How about adding a PERF_CONTEXT_IGNORE and doing something like this:

---

include/uapi/linux/perf_event.h +2 -0
index e3fc8f0..b671abf 100644
@@ -719,6 +719,8 @@ enum perf_callchain_context {
 	PERF_CONTEXT_GUEST_KERNEL	= (__u64)-2176,
 	PERF_CONTEXT_GUEST_USER		= (__u64)-2560,
 
+	PERF_CONTEXT_IGNORE		= (__u64)-3840,
+
 	PERF_CONTEXT_MAX		= (__u64)-4095,
 };
 
tools/perf/config/Makefile +4 -0
index 729bbdf..8d1417d 100644
@@ -48,6 +48,10 @@ ifneq ($(ARCH),$(filter $(ARCH),x86 arm))
   NO_LIBDW_DWARF_UNWIND := 1
 endif
 
+ifeq ($(ARCH),powerpc)
+  CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX
+endif
+
 ifeq ($(LIBUNWIND_LIBS),)
   NO_LIBUNWIND := 1
 else
tools/perf/util/callchain.h +52 -0

56 lines not on this page · raw message

tools/perf/util/machine.c +12 -4
index 7409ac8..a604ea4 100644
@@ -1288,8 +1288,10 @@ static int machine__resolve_callchain_sample(struct machine *machine,
 {
 	u8 cpumode = PERF_RECORD_MISC_USER;
 	int chain_nr = min(max_stack, (int)chain->nr);
+	enum chain_order order = callchain_param.order;
 	int i;
 	int err;
+	int skip_idx;
 
 	callchain_cursor_reset(&callchain_cursor);
 
@@ -1298,14 +1300,17 @@ static int machine__resolve_callchain_sample(struct machine *machine,
 		return 0;
 	}
 
+	/*
+	 * Based on DWARF debug information, some architectures skip
+	 * some of the callchain entries saved by the kernel.
+	 */
+	skip_idx = arch_skip_callchain_idx(machine, thread, chain);
+
 	for (i = 0; i < chain_nr; i++) {
 		u64 ip;
 		struct addr_location al;
 
-		if (callchain_param.order == ORDER_CALLEE)
-			ip = chain->ips[i];
-		else
-			ip = chain->ips[chain->nr - i - 1];
+		ip = arch_next_callchain_ip(chain, order, i, skip_idx);
 
 		if (ip >= PERF_CONTEXT_MAX) {
 			switch (ip) {
@@ -1318,6 +1323,9 @@ static int machine__resolve_callchain_sample(struct machine *machine,
 			case PERF_CONTEXT_USER:
 				cpumode = PERF_RECORD_MISC_USER;
 				break;
+			case PERF_CONTEXT_IGNORE:
+				/* ignore entry. Eg: based on DWARF debug */
+				break;
 			default:
 				pr_debug("invalid callchain context: "
 					 "%"PRId64"\n", (s64) ip);
tools/perf/arch/powerpc/Makefile +1 -0
index 744e629..b92219b 100644
@@ -3,3 +3,4 @@ PERF_HAVE_DWARF_REGS := 1
 LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
 endif
 LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o
+LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/skip-callchain-idx.o
tools/perf/arch/powerpc/util/skip-callchain-idx.c new file +266 -0

266 lines not on this page · raw message

author
#3 lore raw

On Tue, Jun 03, 2014 at 12:47:10AM -0700, Sukadev Bhattiprolu wrote:

SNIP

Quoted 8 lines
| 
| 
| could you please change this, so it's nop for arch != powerpc
| via #ifdef I guess.. or some other smart way ;-)

I was trying to avoid the #ifdef in the middle of the function.

How about adding a PERF_CONTEXT_IGNORE and doing something like this:

hum, 2 arch calls.. seems too complicated.. :-\

so if you are already introducing PERF_CONTEXT_IGNORE, why dont we go with the chain duplication/fixing in arch code you mentioned before?

this way the callchain loop stays simple and it's extendbable to future changes (I think u mentioned we could change more than one entry in future..?)

thoughts.. anyone? ;-)

thanks,
jirka

#4 lore raw

Jiri Olsa [[email protected]] wrote:

| On Tue, Jun 03, 2014 at 12:47:10AM -0700, Sukadev Bhattiprolu wrote:
| 
| SNIP
| 
| > | 
| > | 
| > | could you please change this, so it's nop for arch != powerpc
| > | via #ifdef I guess.. or some other smart way ;-)
| > 
| > I was trying to avoid the #ifdef in the middle of the function.
| > 
| > How about adding a PERF_CONTEXT_IGNORE and doing something like this:
| 
| hum, 2 arch calls.. seems too complicated.. :-\

Other than an 'arch_' prefix in their name the non-powerpc functions themselves are trivial, no ?

| 
| so if you are already introducing PERF_CONTEXT_IGNORE, why
| dont we go with the chain duplication/fixing in arch code
| you mentioned before?
| 
| this way the callchain loop stays simple and it's extendbable
| to future changes (I think u mentioned we could change more
| than one entry in future..?)

The memdup() on each call chain entry can impact performance for powerpc. AFAICT, only one entry needs to be adjusted, so the memdup() looked like an overkill.

| 
| thoughts.. anyone? ;-)
| 
| thanks,
| jirka