Skip to content

Commit 0c4e774

Browse files
committed
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>
1 parent 17314e2 commit 0c4e774

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

‎tools/perf/util/event.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "../perf.h"
88
#include "map.h"
99
#include "build-id.h"
10+
#include "perf_regs.h"
1011

1112
struct mmap_event {
1213
struct perf_event_header header;
@@ -89,6 +90,10 @@ struct regs_dump {
8990
u64 abi;
9091
u64 mask;
9192
u64 *regs;
93+
94+
/* Cached values/mask filled by first register access. */
95+
u64 cache_regs[PERF_REGS_MAX];
96+
u64 cache_mask;
9297
};
9398

9499
struct stack_dump {

‎tools/perf/util/perf_regs.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#include <errno.h>
22
#include "perf_regs.h"
3+
#include "event.h"
34

45
int perf_reg_value(u64 *valp, struct regs_dump *regs, int id)
56
{
67
int i, idx = 0;
78
u64 mask = regs->mask;
89

10+
if (regs->cache_mask & (1 << id))
11+
goto out;
12+
913
if (!(mask & (1 << id)))
1014
return -EINVAL;
1115

@@ -14,6 +18,10 @@ int perf_reg_value(u64 *valp, struct regs_dump *regs, int id)
1418
idx++;
1519
}
1620

17-
*valp = regs->regs[idx];
21+
regs->cache_mask |= (1 << id);
22+
regs->cache_regs[id] = regs->regs[idx];
23+
24+
out:
25+
*valp = regs->cache_regs[id];
1826
return 0;
1927
}

‎tools/perf/util/perf_regs.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#define __PERF_REGS_H
33

44
#include <linux/types.h>
5-
#include "event.h"
5+
6+
struct regs_dump;
67

78
#ifdef HAVE_PERF_REGS_SUPPORT
89
#include <perf_regs.h>
@@ -11,6 +12,7 @@ int perf_reg_value(u64 *valp, struct regs_dump *regs, int id);
1112

1213
#else
1314
#define PERF_REGS_MASK 0
15+
#define PERF_REGS_MAX 0
1416

1517
static inline const char *perf_reg_name(int id __maybe_unused)
1618
{

0 commit comments

Comments
 (0)