perf tools: Cache register accesses for unwind processing
authorJiri Olsa <jolsa@kernel.org>
Thu, 17 Apr 2014 17:39:10 +0000 (19:39 +0200)
committerJiri Olsa <jolsa@kernel.org>
Thu, 12 Jun 2014 14:53:19 +0000 (16:53 +0200)
Caching registers value into an array. Got about 4% speed up
of perf_reg_value function for report command processing
dwarf unwind stacks.

Output from report over 1.5 GB data with DWARF unwind stacks:
(TODO fix perf diff)

  current code:
   5.84%     perf  perf                       [.] perf_reg_value
  change:
   1.94%     perf  perf                       [.] perf_reg_value

And little bit of overall speed up:
(perf stat -r 5 -e '{cycles,instructions}:u' ...)

  current code:
   310,298,611,754      cycles                     ( +-  0.33% )
   439,669,689,341      instructions               ( +-  0.03% )

     188.656753166 seconds time elapsed            ( +-  0.82% )

  change:
   291,315,329,878      cycles                     ( +-  0.22% )
   391,763,485,304      instructions               ( +-  0.03%  )

     180.742249687 seconds time elapsed            ( +-  0.64% )

Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jean Pihet <jean.pihet@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1401892622-30848-2-git-send-email-jolsa@kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
tools/perf/util/event.h
tools/perf/util/perf_regs.c
tools/perf/util/perf_regs.h

index 9ba2eb3bdcfd75c234fe367bff5cd97b450e9929..e5dd40addb30e0d4b4efcdede4d0e129c8be6a0d 100644 (file)
@@ -7,6 +7,7 @@
 #include "../perf.h"
 #include "map.h"
 #include "build-id.h"
+#include "perf_regs.h"
 
 struct mmap_event {
        struct perf_event_header header;
@@ -89,6 +90,10 @@ struct regs_dump {
        u64 abi;
        u64 mask;
        u64 *regs;
+
+       /* Cached values/mask filled by first register access. */
+       u64 cache_regs[PERF_REGS_MAX];
+       u64 cache_mask;
 };
 
 struct stack_dump {
index a3539ef30b15a180674613f0974ecc2bdd7f7bf8..43168fb0d9a28a1151721cd3379b1d3234fef0ab 100644 (file)
@@ -1,11 +1,15 @@
 #include <errno.h>
 #include "perf_regs.h"
+#include "event.h"
 
 int perf_reg_value(u64 *valp, struct regs_dump *regs, int id)
 {
        int i, idx = 0;
        u64 mask = regs->mask;
 
+       if (regs->cache_mask & (1 << id))
+               goto out;
+
        if (!(mask & (1 << id)))
                return -EINVAL;
 
@@ -14,6 +18,10 @@ int perf_reg_value(u64 *valp, struct regs_dump *regs, int id)
                        idx++;
        }
 
-       *valp = regs->regs[idx];
+       regs->cache_mask |= (1 << id);
+       regs->cache_regs[id] = regs->regs[idx];
+
+out:
+       *valp = regs->cache_regs[id];
        return 0;
 }
index 79c78f74e0cf882db1acc55c169115c92ed73d95..980dbf76bc98418322eed0d5ff245cf9ec6edb2c 100644 (file)
@@ -2,7 +2,8 @@
 #define __PERF_REGS_H
 
 #include <linux/types.h>
-#include "event.h"
+
+struct regs_dump;
 
 #ifdef HAVE_PERF_REGS_SUPPORT
 #include <perf_regs.h>
@@ -11,6 +12,7 @@ int perf_reg_value(u64 *valp, struct regs_dump *regs, int id);
 
 #else
 #define PERF_REGS_MASK 0
+#define PERF_REGS_MAX  0
 
 static inline const char *perf_reg_name(int id __maybe_unused)
 {