Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Cache register accesses for unwind processing

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>

Jiri Olsa 0c4e774f 17314e23

+17 -2
+5
tools/perf/util/event.h
··· 7 7 #include "../perf.h" 8 8 #include "map.h" 9 9 #include "build-id.h" 10 + #include "perf_regs.h" 10 11 11 12 struct mmap_event { 12 13 struct perf_event_header header; ··· 90 89 u64 abi; 91 90 u64 mask; 92 91 u64 *regs; 92 + 93 + /* Cached values/mask filled by first register access. */ 94 + u64 cache_regs[PERF_REGS_MAX]; 95 + u64 cache_mask; 93 96 }; 94 97 95 98 struct stack_dump {
+9 -1
tools/perf/util/perf_regs.c
··· 1 1 #include <errno.h> 2 2 #include "perf_regs.h" 3 + #include "event.h" 3 4 4 5 int perf_reg_value(u64 *valp, struct regs_dump *regs, int id) 5 6 { 6 7 int i, idx = 0; 7 8 u64 mask = regs->mask; 9 + 10 + if (regs->cache_mask & (1 << id)) 11 + goto out; 8 12 9 13 if (!(mask & (1 << id))) 10 14 return -EINVAL; ··· 18 14 idx++; 19 15 } 20 16 21 - *valp = regs->regs[idx]; 17 + regs->cache_mask |= (1 << id); 18 + regs->cache_regs[id] = regs->regs[idx]; 19 + 20 + out: 21 + *valp = regs->cache_regs[id]; 22 22 return 0; 23 23 }
+3 -1
tools/perf/util/perf_regs.h
··· 2 2 #define __PERF_REGS_H 3 3 4 4 #include <linux/types.h> 5 - #include "event.h" 5 + 6 + struct regs_dump; 6 7 7 8 #ifdef HAVE_PERF_REGS_SUPPORT 8 9 #include <perf_regs.h> ··· 12 11 13 12 #else 14 13 #define PERF_REGS_MASK 0 14 + #define PERF_REGS_MAX 0 15 15 16 16 static inline const char *perf_reg_name(int id __maybe_unused) 17 17 {