perf core: Add a 'nr' field to perf_event_callchain_context
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 10 May 2016 21:08:32 +0000 (18:08 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 17 May 2016 02:11:51 +0000 (23:11 -0300)
We will use it to count how many addresses are in the entry->ip[] array,
excluding PERF_CONTEXT_{KERNEL,USER,etc} entries, so that we can really
return the number of entries specified by the user via the relevant
sysctl, kernel.perf_event_max_contexts, or via the per event
perf_event_attr.sample_max_stack knob.

This way we keep the perf_sample->ip_callchain->nr meaning, that is the
number of entries, be it real addresses or PERF_CONTEXT_ entries, while
honouring the max_stack knobs, i.e. the end result will be max_stack
entries if we have at least that many entries in a given stack trace.

Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/n/tip-s8teto51tdqvlfhefndtat9r@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
arch/arm/kernel/perf_callchain.c
arch/arm64/kernel/perf_callchain.c
arch/metag/kernel/perf_callchain.c
arch/mips/kernel/perf_event.c
arch/powerpc/perf/callchain.c
arch/sparc/kernel/perf_event.c
arch/x86/events/core.c
include/linux/perf_event.h
kernel/events/callchain.c

index bc552e813e7b4c1260fe97acf87cf5e84e544b3d..22bf1f64d99a44291bd037a74b61ec1d249ec01e 100644 (file)
@@ -75,7 +75,7 @@ perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs
 
        tail = (struct frame_tail __user *)regs->ARM_fp - 1;
 
-       while ((entry->entry->nr < entry->max_stack) &&
+       while ((entry->nr < entry->max_stack) &&
               tail && !((unsigned long)tail & 0x3))
                tail = user_backtrace(tail, entry);
 }
index 0d60150057cfddfefbf51e2cb3584942b24b659d..713ca824f266a7fa771b3609ec8dec5264eef3ed 100644 (file)
@@ -122,7 +122,7 @@ void perf_callchain_user(struct perf_callchain_entry_ctx *entry,
 
                tail = (struct frame_tail __user *)regs->regs[29];
 
-               while (entry->entry->nr < entry->max_stack &&
+               while (entry->nr < entry->max_stack &&
                       tail && !((unsigned long)tail & 0xf))
                        tail = user_backtrace(tail, entry);
        } else {
@@ -132,7 +132,7 @@ void perf_callchain_user(struct perf_callchain_entry_ctx *entry,
 
                tail = (struct compat_frame_tail __user *)regs->compat_fp - 1;
 
-               while ((entry->entry->nr < entry->max_stack) &&
+               while ((entry->nr < entry->max_stack) &&
                        tail && !((unsigned long)tail & 0x3))
                        tail = compat_user_backtrace(tail, entry);
 #endif
index b3261a98b15b5b1ecf0a63cc80d6439198ad7c94..3e8e048040dfc96c0f73fbd48fb7c75d036937d9 100644 (file)
@@ -65,7 +65,7 @@ perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs
 
        --frame;
 
-       while ((entry->entry->nr < entry->max_stack) && frame)
+       while ((entry->nr < entry->max_stack) && frame)
                frame = user_backtrace(frame, entry);
 }
 
index 22395c7d7030a46ac95c155c9574e5af686cfc81..d64056e0bb567ad9c18174b2cc6aa584579caa40 100644 (file)
@@ -35,7 +35,7 @@ static void save_raw_perf_callchain(struct perf_callchain_entry_ctx *entry,
                addr = *sp++;
                if (__kernel_text_address(addr)) {
                        perf_callchain_store(entry, addr);
-                       if (entry->entry->nr >= entry->max_stack)
+                       if (entry->nr >= entry->max_stack)
                                break;
                }
        }
@@ -59,7 +59,7 @@ void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry,
        }
        do {
                perf_callchain_store(entry, pc);
-               if (entry->entry->nr >= entry->max_stack)
+               if (entry->nr >= entry->max_stack)
                        break;
                pc = unwind_stack(current, &sp, pc, &ra);
        } while (pc);
index c9260c1dfdbc3708b306089b8c920dbec0e5f4b7..f68f213dc36c28aabd1e4193f0972b0f5fd6d7be 100644 (file)
@@ -247,7 +247,7 @@ static void perf_callchain_user_64(struct perf_callchain_entry_ctx *entry,
        sp = regs->gpr[1];
        perf_callchain_store(entry, next_ip);
 
-       while (entry->entry->nr < entry->max_stack) {
+       while (entry->nr < entry->max_stack) {
                fp = (unsigned long __user *) sp;
                if (!valid_user_sp(sp, 1) || read_user_stack_64(fp, &next_sp))
                        return;
@@ -453,7 +453,7 @@ static void perf_callchain_user_32(struct perf_callchain_entry_ctx *entry,
        sp = regs->gpr[1];
        perf_callchain_store(entry, next_ip);
 
-       while (entry->entry->nr < entry->max_stack) {
+       while (entry->nr < entry->max_stack) {
                fp = (unsigned int __user *) (unsigned long) sp;
                if (!valid_user_sp(sp, 0) || read_user_stack_32(fp, &next_sp))
                        return;
index bcc5376db74b9479575d3e48d9d52eaa24d65f5d..710f3278d448d910df1c4224f0146ad3bf555b89 100644 (file)
@@ -1756,7 +1756,7 @@ void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry,
                        }
                }
 #endif
-       } while (entry->entry->nr < entry->max_stack);
+       } while (entry->nr < entry->max_stack);
 }
 
 static inline int
@@ -1790,7 +1790,7 @@ static void perf_callchain_user_64(struct perf_callchain_entry_ctx *entry,
                pc = sf.callers_pc;
                ufp = (unsigned long)sf.fp + STACK_BIAS;
                perf_callchain_store(entry, pc);
-       } while (entry->entry->nr < entry->max_stack);
+       } while (entry->nr < entry->max_stack);
 }
 
 static void perf_callchain_user_32(struct perf_callchain_entry_ctx *entry,
@@ -1822,7 +1822,7 @@ static void perf_callchain_user_32(struct perf_callchain_entry_ctx *entry,
                        ufp = (unsigned long)sf.fp;
                }
                perf_callchain_store(entry, pc);
-       } while (entry->entry->nr < entry->max_stack);
+       } while (entry->nr < entry->max_stack);
 }
 
 void
index 07f2b01cfb725daec6a2560d1b58eda46e66b5e9..5de96a18cd9cf78e93814f378f490f2d16068a43 100644 (file)
@@ -2283,7 +2283,7 @@ perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry_ctx *ent
 
        fp = compat_ptr(ss_base + regs->bp);
        pagefault_disable();
-       while (entry->entry->nr < entry->max_stack) {
+       while (entry->nr < entry->max_stack) {
                unsigned long bytes;
                frame.next_frame     = 0;
                frame.return_address = 0;
@@ -2343,7 +2343,7 @@ perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs
                return;
 
        pagefault_disable();
-       while (entry->entry->nr < entry->max_stack) {
+       while (entry->nr < entry->max_stack) {
                unsigned long bytes;
                frame.next_frame             = NULL;
                frame.return_address = 0;
index dbd18246b36e6f01c8299f5e73ad4793e4e80a3e..3803bb1a862b079f4bacccf21dd6d7ab32b50191 100644 (file)
@@ -64,6 +64,7 @@ struct perf_callchain_entry {
 struct perf_callchain_entry_ctx {
        struct perf_callchain_entry *entry;
        u32                         max_stack;
+       u32                         nr;
 };
 
 struct perf_raw_record {
@@ -1080,9 +1081,10 @@ extern int sysctl_perf_event_max_stack;
 
 static inline int perf_callchain_store(struct perf_callchain_entry_ctx *ctx, u64 ip)
 {
-       struct perf_callchain_entry *entry = ctx->entry;
-       if (entry->nr < ctx->max_stack) {
+       if (ctx->nr < ctx->max_stack) {
+               struct perf_callchain_entry *entry = ctx->entry;
                entry->ip[entry->nr++] = ip;
+               ++ctx->nr;
                return 0;
        } else {
                return -1; /* no more room, stop walking the stack */
index af95ad92893a2cfeaa7220f68b29f98582585b7f..8774ff86debb0295511eac77f68534c58309f872 100644 (file)
@@ -196,8 +196,7 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
 
        ctx.entry     = entry;
        ctx.max_stack = max_stack;
-
-       entry->nr = init_nr;
+       ctx.nr        = entry->nr = init_nr;
 
        if (kernel && !user_mode(regs)) {
                if (add_mark)