57fb188
From 97db62062ac76e314c8bda4dc5b63f0ea906d15f Mon Sep 17 00:00:00 2001
57fb188
From: Adrian Hunter <adrian.hunter@intel.com>
57fb188
Date: Mon, 31 Aug 2015 21:39:44 +0300
57fb188
Subject: [PATCH 1/9] perf tools: Fix build on powerpc broken by pt/bts
57fb188
MIME-Version: 1.0
57fb188
Content-Type: text/plain; charset=UTF-8
57fb188
Content-Transfer-Encoding: 8bit
57fb188
57fb188
It is theoretically possible to process perf.data files created on x86
57fb188
and that contain Intel PT or Intel BTS data, on any other architecture,
57fb188
which is why it is possible for there to be build errors on powerpc
57fb188
caused by pt/bts.
57fb188
57fb188
The errors were:
57fb188
57fb188
	util/intel-pt-decoder/intel-pt-insn-decoder.c: In function ‘intel_pt_insn_decoder’:
57fb188
	util/intel-pt-decoder/intel-pt-insn-decoder.c:138:3: error: switch missing default case [-Werror=switch-default]
57fb188
	   switch (insn->immediate.nbytes) {
57fb188
	   ^
57fb188
	cc1: all warnings being treated as errors
57fb188
57fb188
	linux-acme.git/tools/perf/perf-obj/libperf.a(libperf-in.o): In function `intel_pt_synth_branch_sample':
57fb188
	sources/linux-acme.git/tools/perf/util/intel-pt.c:871: undefined reference to `tsc_to_perf_time'
57fb188
	linux-acme.git/tools/perf/perf-obj/libperf.a(libperf-in.o): In function `intel_pt_sample':
57fb188
	sources/linux-acme.git/tools/perf/util/intel-pt.c:915: undefined reference to `tsc_to_perf_time'
57fb188
	sources/linux-acme.git/tools/perf/util/intel-pt.c:962: undefined reference to `tsc_to_perf_time'
57fb188
	linux-acme.git/tools/perf/perf-obj/libperf.a(libperf-in.o): In function `intel_pt_process_event':
57fb188
	sources/linux-acme.git/tools/perf/util/intel-pt.c:1454: undefined reference to `perf_time_to_tsc'
57fb188
57fb188
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
57fb188
Cc: Jiri Olsa <jolsa@redhat.com>
57fb188
Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
57fb188
Cc: Wang Nan <wangnan0@huawei.com>
57fb188
Cc: Zefan Li <lizefan@huawei.com>
57fb188
Cc: pi3orama@163.com
57fb188
Link: http://lkml.kernel.org/r/1441046384-28663-1-git-send-email-adrian.hunter@intel.com
57fb188
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
57fb188
---
57fb188
 tools/perf/util/Build                                    | 1 +
57fb188
 tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c | 3 +++
57fb188
 2 files changed, 4 insertions(+)
57fb188
57fb188
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
57fb188
index e912856cc4e5..e79e4522368a 100644
57fb188
--- a/tools/perf/util/Build
57fb188
+++ b/tools/perf/util/Build
57fb188
@@ -75,6 +75,7 @@ libperf-y += record.o
57fb188
 libperf-y += srcline.o
57fb188
 libperf-y += data.o
57fb188
 libperf-$(CONFIG_X86) += tsc.o
57fb188
+libperf-$(CONFIG_AUXTRACE) += tsc.o
57fb188
 libperf-y += cloexec.o
57fb188
 libperf-y += thread-stack.o
57fb188
 libperf-$(CONFIG_AUXTRACE) += auxtrace.o
57fb188
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
57fb188
index 9e4eb8fcd559..d23138c06665 100644
57fb188
--- a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
57fb188
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
57fb188
@@ -146,6 +146,9 @@ static void intel_pt_insn_decoder(struct insn *insn,
57fb188
 		case 4:
57fb188
 			intel_pt_insn->rel = bswap_32(insn->immediate.value);
57fb188
 			break;
57fb188
+		default:
57fb188
+			intel_pt_insn->rel = 0;
57fb188
+			break;
57fb188
 		}
57fb188
 #else
57fb188
 		intel_pt_insn->rel = insn->immediate.value;
57fb188
-- 
57fb188
2.4.3
57fb188
57fb188
57fb188
From acf860ae7c53cc8b0c5d372c218332aac3eeba4f Mon Sep 17 00:00:00 2001
57fb188
From: Wang Nan <wangnan0@huawei.com>
57fb188
Date: Thu, 27 Aug 2015 02:30:55 +0000
57fb188
Subject: [PATCH 2/9] bpf tools: New API to get name from a BPF object
57fb188
57fb188
Before this patch there's no way to connect a loaded bpf object
57fb188
to its source file. However, during applying perf's '--filter' to BPF
57fb188
object, without this connection makes things harder, because perf loads
57fb188
all programs together, but '--filter' setting is for each object.
57fb188
57fb188
The API of bpf_object__open_buffer() is changed to allow passing a name.
57fb188
Fortunately, at this time there's only one user of it (perf test LLVM),
57fb188
so we change it together.
57fb188
57fb188
Signed-off-by: Wang Nan <wangnan0@huawei.com>
57fb188
Cc: Alexei Starovoitov <ast@plumgrid.com>
57fb188
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
57fb188
Cc: Daniel Borkmann <daniel@iogearbox.net>
57fb188
Cc: David Ahern <dsahern@gmail.com>
57fb188
Cc: He Kuang <hekuang@huawei.com>
57fb188
Cc: Jiri Olsa <jolsa@kernel.org>
57fb188
Cc: Kaixu Xia <xiakaixu@huawei.com>
57fb188
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
57fb188
Cc: Namhyung Kim <namhyung@kernel.org>
57fb188
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
57fb188
Cc: Zefan Li <lizefan@huawei.com>
57fb188
Cc: pi3orama@163.com
57fb188
Link: http://lkml.kernel.org/r/1440742821-44548-2-git-send-email-wangnan0@huawei.com
57fb188
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
57fb188
---
57fb188
 tools/lib/bpf/libbpf.c  | 25 ++++++++++++++++++++++---
57fb188
 tools/lib/bpf/libbpf.h  |  4 +++-
57fb188
 tools/perf/tests/llvm.c |  2 +-
57fb188
 3 files changed, 26 insertions(+), 5 deletions(-)
57fb188
57fb188
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
57fb188
index 4fa4bc4505f5..4252fc22f78f 100644
57fb188
--- a/tools/lib/bpf/libbpf.c
57fb188
+++ b/tools/lib/bpf/libbpf.c
57fb188
@@ -880,15 +880,26 @@ struct bpf_object *bpf_object__open(const char *path)
57fb188
 }
57fb188
 
57fb188
 struct bpf_object *bpf_object__open_buffer(void *obj_buf,
57fb188
-					   size_t obj_buf_sz)
57fb188
+					   size_t obj_buf_sz,
57fb188
+					   const char *name)
57fb188
 {
57fb188
+	char tmp_name[64];
57fb188
+
57fb188
 	/* param validation */
57fb188
 	if (!obj_buf || obj_buf_sz <= 0)
57fb188
 		return NULL;
57fb188
 
57fb188
-	pr_debug("loading object from buffer\n");
57fb188
+	if (!name) {
57fb188
+		snprintf(tmp_name, sizeof(tmp_name), "%lx-%lx",
57fb188
+			 (unsigned long)obj_buf,
57fb188
+			 (unsigned long)obj_buf_sz);
57fb188
+		tmp_name[sizeof(tmp_name) - 1] = '\0';
57fb188
+		name = tmp_name;
57fb188
+	}
57fb188
+	pr_debug("loading object '%s' from buffer\n",
57fb188
+		 name);
57fb188
 
57fb188
-	return __bpf_object__open("[buffer]", obj_buf, obj_buf_sz);
57fb188
+	return __bpf_object__open(name, obj_buf, obj_buf_sz);
57fb188
 }
57fb188
 
57fb188
 int bpf_object__unload(struct bpf_object *obj)
57fb188
@@ -975,6 +986,14 @@ bpf_object__next(struct bpf_object *prev)
57fb188
 	return next;
57fb188
 }
57fb188
 
57fb188
+const char *
57fb188
+bpf_object__get_name(struct bpf_object *obj)
57fb188
+{
57fb188
+	if (!obj)
57fb188
+		return NULL;
57fb188
+	return obj->path;
57fb188
+}
57fb188
+
57fb188
 struct bpf_program *
57fb188
 bpf_program__next(struct bpf_program *prev, struct bpf_object *obj)
57fb188
 {
57fb188
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
57fb188
index ea8adc206b62..f16170c95ffd 100644
57fb188
--- a/tools/lib/bpf/libbpf.h
57fb188
+++ b/tools/lib/bpf/libbpf.h
57fb188
@@ -28,12 +28,14 @@ struct bpf_object;
57fb188
 
57fb188
 struct bpf_object *bpf_object__open(const char *path);
57fb188
 struct bpf_object *bpf_object__open_buffer(void *obj_buf,
57fb188
-					   size_t obj_buf_sz);
57fb188
+					   size_t obj_buf_sz,
57fb188
+					   const char *name);
57fb188
 void bpf_object__close(struct bpf_object *object);
57fb188
 
57fb188
 /* Load/unload object into/from kernel */
57fb188
 int bpf_object__load(struct bpf_object *obj);
57fb188
 int bpf_object__unload(struct bpf_object *obj);
57fb188
+const char *bpf_object__get_name(struct bpf_object *obj);
57fb188
 
57fb188
 struct bpf_object *bpf_object__next(struct bpf_object *prev);
57fb188
 #define bpf_object__for_each_safe(pos, tmp)			\
57fb188
diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c
57fb188
index a337356fd979..52d55971f66f 100644
57fb188
--- a/tools/perf/tests/llvm.c
57fb188
+++ b/tools/perf/tests/llvm.c
57fb188
@@ -26,7 +26,7 @@ static int test__bpf_parsing(void *obj_buf, size_t obj_buf_sz)
57fb188
 {
57fb188
 	struct bpf_object *obj;
57fb188
 
57fb188
-	obj = bpf_object__open_buffer(obj_buf, obj_buf_sz);
57fb188
+	obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, NULL);
57fb188
 	if (!obj)
57fb188
 		return -1;
57fb188
 	bpf_object__close(obj);
57fb188
-- 
57fb188
2.4.3
57fb188
57fb188
57fb188
From d988d5ee647861706bc7a391ddbc29429b50f00e Mon Sep 17 00:00:00 2001
57fb188
From: Kan Liang <kan.liang@intel.com>
57fb188
Date: Fri, 21 Aug 2015 02:23:14 -0400
57fb188
Subject: [PATCH 3/9] perf evlist: Open event on evsel cpus and threads
57fb188
57fb188
An evsel may have different cpus and threads than the evlist it is in.
57fb188
57fb188
Use it's own cpus and threads, when opening the evsel in 'perf record'.
57fb188
57fb188
Signed-off-by: Kan Liang <kan.liang@intel.com>
57fb188
Cc: Jiri Olsa <jolsa@kernel.org>
57fb188
Link: http://lkml.kernel.org/r/1440138194-17001-1-git-send-email-kan.liang@intel.com
57fb188
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
57fb188
---
57fb188
 tools/perf/builtin-record.c | 2 +-
57fb188
 tools/perf/util/evlist.c    | 4 ++++
57fb188
 2 files changed, 5 insertions(+), 1 deletion(-)
57fb188
57fb188
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
57fb188
index a660022f2c92..1d14f382f614 100644
57fb188
--- a/tools/perf/builtin-record.c
57fb188
+++ b/tools/perf/builtin-record.c
57fb188
@@ -279,7 +279,7 @@ static int record__open(struct record *rec)
57fb188
 
57fb188
 	evlist__for_each(evlist, pos) {
57fb188
 try_again:
57fb188
-		if (perf_evsel__open(pos, evlist->cpus, evlist->threads) < 0) {
57fb188
+		if (perf_evsel__open(pos, pos->cpus, pos->threads) < 0) {
57fb188
 			if (perf_evsel__fallback(pos, errno, msg, sizeof(msg))) {
57fb188
 				if (verbose)
57fb188
 					ui__warning("%s\n", msg);
57fb188
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
57fb188
index 8d00039d6a20..d51a5200c8af 100644
57fb188
--- a/tools/perf/util/evlist.c
57fb188
+++ b/tools/perf/util/evlist.c
57fb188
@@ -1181,6 +1181,10 @@ int perf_evlist__apply_filters(struct perf_evlist *evlist, struct perf_evsel **e
57fb188
 		if (evsel->filter == NULL)
57fb188
 			continue;
57fb188
 
57fb188
+		/*
57fb188
+		 * filters only work for tracepoint event, which doesn't have cpu limit.
57fb188
+		 * So evlist and evsel should always be same.
57fb188
+		 */
57fb188
 		err = perf_evsel__apply_filter(evsel, ncpus, nthreads, evsel->filter);
57fb188
 		if (err) {
57fb188
 			*err_evsel = evsel;
57fb188
-- 
57fb188
2.4.3
57fb188
57fb188
57fb188
From fc36f9485aee3a62b22be1f561543a31bce6d48e Mon Sep 17 00:00:00 2001
57fb188
From: Stephane Eranian <eranian@google.com>
57fb188
Date: Mon, 31 Aug 2015 18:41:10 +0200
57fb188
Subject: [PATCH 4/9] perf script: Enable printing of interrupted machine state
57fb188
57fb188
This patch adds the output of the interrupted machine state (iregs) to
57fb188
perf script. It presents them  as NAME:VALUE so this is easy to parse
57fb188
during post processing.
57fb188
57fb188
To capture the interrupted machine state:
57fb188
   $ perf record -I ....
57fb188
57fb188
to display iregs, use the -F option:
57fb188
57fb188
   $ perf script -F ip,iregs
57fb188
   40afc2   AX:0x6c5770    BX:0x1e    CX:0x5f4d80a    DX:0x101010101010101    SI:0x1
57fb188
57fb188
Signed-off-by: Stephane Eranian <eranian@google.com>
57fb188
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
57fb188
Cc: Adrian Hunter <adrian.hunter@intel.com>
57fb188
Cc: Andi Kleen <ak@linux.intel.com>
57fb188
Cc: David Ahern <dsahern@gmail.com>
57fb188
Cc: Jiri Olsa <jolsa@redhat.com>
57fb188
Cc: Kan Liang <kan.liang@intel.com>
57fb188
Cc: Namhyung Kim <namhyung@kernel.org>
57fb188
Cc: Peter Zijlstra <peterz@infradead.org>
57fb188
Link: http://lkml.kernel.org/r/1441039273-16260-2-git-send-email-eranian@google.com
57fb188
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
57fb188
---
57fb188
 tools/perf/Documentation/perf-script.txt |  2 +-
57fb188
 tools/perf/builtin-script.c              | 31 ++++++++++++++++++++++++++++++-
57fb188
 2 files changed, 31 insertions(+), 2 deletions(-)
57fb188
57fb188
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
57fb188
index 614b2c7b0293..dc3ec783b7bd 100644
57fb188
--- a/tools/perf/Documentation/perf-script.txt
57fb188
+++ b/tools/perf/Documentation/perf-script.txt
57fb188
@@ -116,7 +116,7 @@ OPTIONS
57fb188
 --fields::
57fb188
         Comma separated list of fields to print. Options are:
57fb188
         comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
57fb188
-	srcline, period, flags.
57fb188
+	srcline, period, iregs, flags.
57fb188
         Field list can be prepended with the type, trace, sw or hw,
57fb188
         to indicate to which event type the field list applies.
57fb188
         e.g., -f sw:comm,tid,time,ip,sym  and -f trace:time,cpu,trace
57fb188
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
57fb188
index 4430340292c0..eb51325e8ad9 100644
57fb188
--- a/tools/perf/builtin-script.c
57fb188
+++ b/tools/perf/builtin-script.c
57fb188
@@ -6,6 +6,7 @@
57fb188
 #include "util/exec_cmd.h"
57fb188
 #include "util/header.h"
57fb188
 #include "util/parse-options.h"
57fb188
+#include "util/perf_regs.h"
57fb188
 #include "util/session.h"
57fb188
 #include "util/tool.h"
57fb188
 #include "util/symbol.h"
57fb188
@@ -46,6 +47,7 @@ enum perf_output_field {
57fb188
 	PERF_OUTPUT_SYMOFFSET       = 1U << 11,
57fb188
 	PERF_OUTPUT_SRCLINE         = 1U << 12,
57fb188
 	PERF_OUTPUT_PERIOD          = 1U << 13,
57fb188
+	PERF_OUTPUT_IREGS	    = 1U << 14,
57fb188
 };
57fb188
 
57fb188
 struct output_option {
57fb188
@@ -66,6 +68,7 @@ struct output_option {
57fb188
 	{.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET},
57fb188
 	{.str = "srcline", .field = PERF_OUTPUT_SRCLINE},
57fb188
 	{.str = "period", .field = PERF_OUTPUT_PERIOD},
57fb188
+	{.str = "iregs", .field = PERF_OUTPUT_IREGS},
57fb188
 };
57fb188
 
57fb188
 /* default set to maintain compatibility with current format */
57fb188
@@ -255,6 +258,11 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,
57fb188
 					PERF_OUTPUT_PERIOD))
57fb188
 		return -EINVAL;
57fb188
 
57fb188
+	if (PRINT_FIELD(IREGS) &&
57fb188
+		perf_evsel__check_stype(evsel, PERF_SAMPLE_REGS_INTR, "IREGS",
57fb188
+					PERF_OUTPUT_IREGS))
57fb188
+		return -EINVAL;
57fb188
+
57fb188
 	return 0;
57fb188
 }
57fb188
 
57fb188
@@ -352,6 +360,24 @@ out:
57fb188
 	return 0;
57fb188
 }
57fb188
 
57fb188
+static void print_sample_iregs(union perf_event *event __maybe_unused,
57fb188
+			  struct perf_sample *sample,
57fb188
+			  struct thread *thread __maybe_unused,
57fb188
+			  struct perf_event_attr *attr)
57fb188
+{
57fb188
+	struct regs_dump *regs = &sample->intr_regs;
57fb188
+	uint64_t mask = attr->sample_regs_intr;
57fb188
+	unsigned i = 0, r;
57fb188
+
57fb188
+	if (!regs)
57fb188
+		return;
57fb188
+
57fb188
+	for_each_set_bit(r, (unsigned long *) &mask, sizeof(mask) * 8) {
57fb188
+		u64 val = regs->regs[i++];
57fb188
+		printf("%5s:0x%"PRIx64" ", perf_reg_name(r), val);
57fb188
+	}
57fb188
+}
57fb188
+
57fb188
 static void print_sample_start(struct perf_sample *sample,
57fb188
 			       struct thread *thread,
57fb188
 			       struct perf_evsel *evsel)
57fb188
@@ -525,6 +551,9 @@ static void process_event(union perf_event *event, struct perf_sample *sample,
57fb188
 				     PERF_MAX_STACK_DEPTH);
57fb188
 	}
57fb188
 
57fb188
+	if (PRINT_FIELD(IREGS))
57fb188
+		print_sample_iregs(event, sample, thread, attr);
57fb188
+
57fb188
 	printf("\n");
57fb188
 }
57fb188
 
57fb188
@@ -1643,7 +1672,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
57fb188
 		     "comma separated output fields prepend with 'type:'. "
57fb188
 		     "Valid types: hw,sw,trace,raw. "
57fb188
 		     "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
57fb188
-		     "addr,symoff,period,flags", parse_output_fields),
57fb188
+		     "addr,symoff,period,iregs,flags", parse_output_fields),
57fb188
 	OPT_BOOLEAN('a', "all-cpus", &system_wide,
57fb188
 		    "system-wide collection from all CPUs"),
57fb188
 	OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
57fb188
-- 
57fb188
2.4.3
57fb188
57fb188
57fb188
From c5e991ee9dff0f8136168ed2d0d1a8cc3620dac4 Mon Sep 17 00:00:00 2001
57fb188
From: Stephane Eranian <eranian@google.com>
57fb188
Date: Mon, 31 Aug 2015 18:41:11 +0200
57fb188
Subject: [PATCH 5/9] perf/x86: Add list of register names
57fb188
57fb188
This patch adds a way to locate a register identifier (PERF_X86_REG_*)
57fb188
based on its name, e.g., AX.
57fb188
57fb188
This will be used by a subsequent patch to improved flexibility of perf
57fb188
record.
57fb188
57fb188
Signed-off-by: Stephane Eranian <eranian@google.com>
57fb188
Cc: Adrian Hunter <adrian.hunter@intel.com>
57fb188
Cc: Andi Kleen <ak@linux.intel.com>
57fb188
Cc: David Ahern <dsahern@gmail.com>
57fb188
Cc: Jiri Olsa <jolsa@redhat.com>
57fb188
Cc: Kan Liang <kan.liang@intel.com>
57fb188
Cc: Namhyung Kim <namhyung@kernel.org>
57fb188
Cc: Peter Zijlstra <peterz@infradead.org>
57fb188
Link: http://lkml.kernel.org/r/1441039273-16260-3-git-send-email-eranian@google.com
57fb188
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
57fb188
---
57fb188
 tools/perf/arch/x86/util/Build       |  1 +
57fb188
 tools/perf/arch/x86/util/perf_regs.c | 30 ++++++++++++++++++++++++++++++
57fb188
 tools/perf/util/perf_regs.h          |  7 +++++++
57fb188
 3 files changed, 38 insertions(+)
57fb188
 create mode 100644 tools/perf/arch/x86/util/perf_regs.c
57fb188
57fb188
diff --git a/tools/perf/arch/x86/util/Build b/tools/perf/arch/x86/util/Build
57fb188
index 2c55e1b336c5..ff63649fa9ac 100644
57fb188
--- a/tools/perf/arch/x86/util/Build
57fb188
+++ b/tools/perf/arch/x86/util/Build
57fb188
@@ -2,6 +2,7 @@ libperf-y += header.o
57fb188
 libperf-y += tsc.o
57fb188
 libperf-y += pmu.o
57fb188
 libperf-y += kvm-stat.o
57fb188
+libperf-y += perf_regs.o
57fb188
 
57fb188
 libperf-$(CONFIG_DWARF) += dwarf-regs.o
57fb188
 
57fb188
diff --git a/tools/perf/arch/x86/util/perf_regs.c b/tools/perf/arch/x86/util/perf_regs.c
57fb188
new file mode 100644
57fb188
index 000000000000..087c84ef5234
57fb188
--- /dev/null
57fb188
+++ b/tools/perf/arch/x86/util/perf_regs.c
57fb188
@@ -0,0 +1,30 @@
57fb188
+#include "../../perf.h"
57fb188
+#include "../../util/perf_regs.h"
57fb188
+
57fb188
+#define REG(n, b) { .name = #n, .mask = 1ULL << (b) }
57fb188
+#define REG_END { .name = NULL }
57fb188
+const struct sample_reg sample_reg_masks[] = {
57fb188
+	REG(AX, PERF_REG_X86_AX),
57fb188
+	REG(BX, PERF_REG_X86_BX),
57fb188
+	REG(CX, PERF_REG_X86_CX),
57fb188
+	REG(DX, PERF_REG_X86_DX),
57fb188
+	REG(SI, PERF_REG_X86_SI),
57fb188
+	REG(DI, PERF_REG_X86_DI),
57fb188
+	REG(BP, PERF_REG_X86_BP),
57fb188
+	REG(SP, PERF_REG_X86_SP),
57fb188
+	REG(IP, PERF_REG_X86_IP),
57fb188
+	REG(FLAGS, PERF_REG_X86_FLAGS),
57fb188
+	REG(CS, PERF_REG_X86_CS),
57fb188
+	REG(SS, PERF_REG_X86_SS),
57fb188
+#ifdef HAVE_ARCH_X86_64_SUPPORT
57fb188
+	REG(R8, PERF_REG_X86_R8),
57fb188
+	REG(R9, PERF_REG_X86_R9),
57fb188
+	REG(R10, PERF_REG_X86_R10),
57fb188
+	REG(R11, PERF_REG_X86_R11),
57fb188
+	REG(R12, PERF_REG_X86_R12),
57fb188
+	REG(R13, PERF_REG_X86_R13),
57fb188
+	REG(R14, PERF_REG_X86_R14),
57fb188
+	REG(R15, PERF_REG_X86_R15),
57fb188
+#endif
57fb188
+	REG_END
57fb188
+};
57fb188
diff --git a/tools/perf/util/perf_regs.h b/tools/perf/util/perf_regs.h
57fb188
index 980dbf76bc98..92c1fff2153e 100644
57fb188
--- a/tools/perf/util/perf_regs.h
57fb188
+++ b/tools/perf/util/perf_regs.h
57fb188
@@ -5,6 +5,13 @@
57fb188
 
57fb188
 struct regs_dump;
57fb188
 
57fb188
+struct sample_reg {
57fb188
+	const char *name;
57fb188
+	uint64_t mask;
57fb188
+};
57fb188
+
57fb188
+extern const struct sample_reg sample_reg_masks[];
57fb188
+
57fb188
 #ifdef HAVE_PERF_REGS_SUPPORT
57fb188
 #include <perf_regs.h>
57fb188
 
57fb188
-- 
57fb188
2.4.3
57fb188
57fb188
57fb188
From bcc84ec65ad1bd9f777a1fade6f8e5e0c5808fa5 Mon Sep 17 00:00:00 2001
57fb188
From: Stephane Eranian <eranian@google.com>
57fb188
Date: Mon, 31 Aug 2015 18:41:12 +0200
57fb188
Subject: [PATCH 6/9] perf record: Add ability to name registers to record
57fb188
57fb188
This patch modifies the -I/--int-regs option to enablepassing the name
57fb188
of the registers to sample on interrupt. Registers can be specified by
57fb188
their symbolic names. For instance on x86, --intr-regs=ax,si.
57fb188
57fb188
The motivation is to reduce the size of the perf.data file and the
57fb188
overhead of sampling by only collecting the registers useful to a
57fb188
specific analysis. For instance, for value profiling, sampling only the
57fb188
registers used to passed arguements to functions.
57fb188
57fb188
With no parameter, the --intr-regs still records all possible registers
57fb188
based on the architecture.
57fb188
57fb188
To name registers, it is necessary to use the long form of the option,
57fb188
i.e., --intr-regs:
57fb188
57fb188
  $ perf record --intr-regs=si,di,r8,r9 .....
57fb188
57fb188
To record any possible registers:
57fb188
57fb188
  $ perf record -I .....
57fb188
  $ perf report --intr-regs ...
57fb188
57fb188
To display the register, one can use perf report -D
57fb188
57fb188
To list the available registers:
57fb188
57fb188
  $ perf record --intr-regs=\?
57fb188
  available registers: AX BX CX DX SI DI BP SP IP FLAGS CS SS R8 R9 R10 R11 R12 R13 R14 R15
57fb188
57fb188
Signed-off-by: Stephane Eranian <eranian@google.com>
57fb188
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
57fb188
Cc: Adrian Hunter <adrian.hunter@intel.com>
57fb188
Cc: Andi Kleen <ak@linux.intel.com>
57fb188
Cc: David Ahern <dsahern@gmail.com>
57fb188
Cc: Jiri Olsa <jolsa@redhat.com>
57fb188
Cc: Kan Liang <kan.liang@intel.com>
57fb188
Cc: Namhyung Kim <namhyung@kernel.org>
57fb188
Cc: Peter Zijlstra <peterz@infradead.org>
57fb188
Link: http://lkml.kernel.org/r/1441039273-16260-4-git-send-email-eranian@google.com
57fb188
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
57fb188
---
57fb188
 tools/perf/Documentation/perf-record.txt |  6 ++-
57fb188
 tools/perf/builtin-record.c              |  7 +++-
57fb188
 tools/perf/perf.h                        |  2 +-
57fb188
 tools/perf/util/Build                    |  1 +
57fb188
 tools/perf/util/evsel.c                  |  2 +-
57fb188
 tools/perf/util/parse-regs-options.c     | 71 ++++++++++++++++++++++++++++++++
57fb188
 tools/perf/util/parse-regs-options.h     |  5 +++
57fb188
 7 files changed, 89 insertions(+), 5 deletions(-)
57fb188
 create mode 100644 tools/perf/util/parse-regs-options.c
57fb188
 create mode 100644 tools/perf/util/parse-regs-options.h
57fb188
57fb188
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
57fb188
index 347a27322ed8..2e9ce77b5e14 100644
57fb188
--- a/tools/perf/Documentation/perf-record.txt
57fb188
+++ b/tools/perf/Documentation/perf-record.txt
57fb188
@@ -276,7 +276,11 @@ filter out the startup phase of the program, which is often very different.
57fb188
 --intr-regs::
57fb188
 Capture machine state (registers) at interrupt, i.e., on counter overflows for
57fb188
 each sample. List of captured registers depends on the architecture. This option
57fb188
-is off by default.
57fb188
+is off by default. It is possible to select the registers to sample using their
57fb188
+symbolic names, e.g. on x86, ax, si. To list the available registers use
57fb188
+--intr-regs=\?. To name registers, pass a comma separated list such as
57fb188
+--intr-regs=ax,bx. The list of register is architecture dependent.
57fb188
+
57fb188
 
57fb188
 --running-time::
57fb188
 Record running and enabled time for read events (:S)
57fb188
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
57fb188
index 1d14f382f614..142eeb341b29 100644
57fb188
--- a/tools/perf/builtin-record.c
57fb188
+++ b/tools/perf/builtin-record.c
57fb188
@@ -27,8 +27,10 @@
57fb188
 #include "util/cpumap.h"
57fb188
 #include "util/thread_map.h"
57fb188
 #include "util/data.h"
57fb188
+#include "util/perf_regs.h"
57fb188
 #include "util/auxtrace.h"
57fb188
 #include "util/parse-branch-options.h"
57fb188
+#include "util/parse-regs-options.h"
57fb188
 
57fb188
 #include <unistd.h>
57fb188
 #include <sched.h>
57fb188
@@ -1080,8 +1082,9 @@ struct option __record_options[] = {
57fb188
 		    "sample transaction flags (special events only)"),
57fb188
 	OPT_BOOLEAN(0, "per-thread", &record.opts.target.per_thread,
57fb188
 		    "use per-thread mmaps"),
57fb188
-	OPT_BOOLEAN('I', "intr-regs", &record.opts.sample_intr_regs,
57fb188
-		    "Sample machine registers on interrupt"),
57fb188
+	OPT_CALLBACK_OPTARG('I', "intr-regs", &record.opts.sample_intr_regs, NULL, "any register",
57fb188
+		    "sample selected machine registers on interrupt,"
57fb188
+		    " use -I ? to list register names", parse_regs),
57fb188
 	OPT_BOOLEAN(0, "running-time", &record.opts.running_time,
57fb188
 		    "Record running/enabled time of read (:S) events"),
57fb188
 	OPT_CALLBACK('k', "clockid", &record.opts,
57fb188
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
57fb188
index cccb4cf575d3..90129accffbe 100644
57fb188
--- a/tools/perf/perf.h
57fb188
+++ b/tools/perf/perf.h
57fb188
@@ -54,7 +54,6 @@ struct record_opts {
57fb188
 	bool	     sample_time_set;
57fb188
 	bool	     callgraph_set;
57fb188
 	bool	     period;
57fb188
-	bool	     sample_intr_regs;
57fb188
 	bool	     running_time;
57fb188
 	bool	     full_auxtrace;
57fb188
 	bool	     auxtrace_snapshot_mode;
57fb188
@@ -64,6 +63,7 @@ struct record_opts {
57fb188
 	unsigned int auxtrace_mmap_pages;
57fb188
 	unsigned int user_freq;
57fb188
 	u64          branch_stack;
57fb188
+	u64	     sample_intr_regs;
57fb188
 	u64	     default_interval;
57fb188
 	u64	     user_interval;
57fb188
 	size_t	     auxtrace_snapshot_size;
57fb188
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
57fb188
index e79e4522368a..349bc96ca1fe 100644
57fb188
--- a/tools/perf/util/Build
57fb188
+++ b/tools/perf/util/Build
57fb188
@@ -83,6 +83,7 @@ libperf-$(CONFIG_AUXTRACE) += intel-pt-decoder/
57fb188
 libperf-$(CONFIG_AUXTRACE) += intel-pt.o
57fb188
 libperf-$(CONFIG_AUXTRACE) += intel-bts.o
57fb188
 libperf-y += parse-branch-options.o
57fb188
+libperf-y += parse-regs-options.o
57fb188
 
57fb188
 libperf-$(CONFIG_LIBELF) += symbol-elf.o
57fb188
 libperf-$(CONFIG_LIBELF) += probe-file.o
57fb188
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
57fb188
index bac25f41a751..c53f79123b37 100644
57fb188
--- a/tools/perf/util/evsel.c
57fb188
+++ b/tools/perf/util/evsel.c
57fb188
@@ -787,7 +787,7 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts)
57fb188
 		perf_evsel__config_callgraph(evsel, opts, &callchain_param);
57fb188
 
57fb188
 	if (opts->sample_intr_regs) {
57fb188
-		attr->sample_regs_intr = PERF_REGS_MASK;
57fb188
+		attr->sample_regs_intr = opts->sample_intr_regs;
57fb188
 		perf_evsel__set_sample_bit(evsel, REGS_INTR);
57fb188
 	}
57fb188
 
57fb188
diff --git a/tools/perf/util/parse-regs-options.c b/tools/perf/util/parse-regs-options.c
57fb188
new file mode 100644
57fb188
index 000000000000..4f2c1c255d81
57fb188
--- /dev/null
57fb188
+++ b/tools/perf/util/parse-regs-options.c
57fb188
@@ -0,0 +1,71 @@
57fb188
+#include "perf.h"
57fb188
+#include "util/util.h"
57fb188
+#include "util/debug.h"
57fb188
+#include "util/parse-options.h"
57fb188
+#include "util/parse-regs-options.h"
57fb188
+
57fb188
+int
57fb188
+parse_regs(const struct option *opt, const char *str, int unset)
57fb188
+{
57fb188
+	uint64_t *mode = (uint64_t *)opt->value;
57fb188
+	const struct sample_reg *r;
57fb188
+	char *s, *os = NULL, *p;
57fb188
+	int ret = -1;
57fb188
+
57fb188
+	if (unset)
57fb188
+		return 0;
57fb188
+
57fb188
+	/*
57fb188
+	 * cannot set it twice
57fb188
+	 */
57fb188
+	if (*mode)
57fb188
+		return -1;
57fb188
+
57fb188
+	/* str may be NULL in case no arg is passed to -I */
57fb188
+	if (str) {
57fb188
+		/* because str is read-only */
57fb188
+		s = os = strdup(str);
57fb188
+		if (!s)
57fb188
+			return -1;
57fb188
+
57fb188
+		for (;;) {
57fb188
+			p = strchr(s, ',');
57fb188
+			if (p)
57fb188
+				*p = '\0';
57fb188
+
57fb188
+			if (!strcmp(s, "?")) {
57fb188
+				fprintf(stderr, "available registers: ");
57fb188
+				for (r = sample_reg_masks; r->name; r++) {
57fb188
+					fprintf(stderr, "%s ", r->name);
57fb188
+				}
57fb188
+				fputc('\n', stderr);
57fb188
+				/* just printing available regs */
57fb188
+				return -1;
57fb188
+			}
57fb188
+			for (r = sample_reg_masks; r->name; r++) {
57fb188
+				if (!strcasecmp(s, r->name))
57fb188
+					break;
57fb188
+			}
57fb188
+			if (!r->name) {
57fb188
+				ui__warning("unknown register %s,"
57fb188
+					    " check man page\n", s);
57fb188
+				goto error;
57fb188
+			}
57fb188
+
57fb188
+			*mode |= r->mask;
57fb188
+
57fb188
+			if (!p)
57fb188
+				break;
57fb188
+
57fb188
+			s = p + 1;
57fb188
+		}
57fb188
+	}
57fb188
+	ret = 0;
57fb188
+
57fb188
+	/* default to all possible regs */
57fb188
+	if (*mode == 0)
57fb188
+		*mode = PERF_REGS_MASK;
57fb188
+error:
57fb188
+	free(os);
57fb188
+	return ret;
57fb188
+}
57fb188
diff --git a/tools/perf/util/parse-regs-options.h b/tools/perf/util/parse-regs-options.h
57fb188
new file mode 100644
57fb188
index 000000000000..7d762b188007
57fb188
--- /dev/null
57fb188
+++ b/tools/perf/util/parse-regs-options.h
57fb188
@@ -0,0 +1,5 @@
57fb188
+#ifndef _PERF_PARSE_REGS_OPTIONS_H
57fb188
+#define _PERF_PARSE_REGS_OPTIONS_H 1
57fb188
+struct option;
57fb188
+int parse_regs(const struct option *opt, const char *str, int unset);
57fb188
+#endif /* _PERF_PARSE_REGS_OPTIONS_H */
57fb188
-- 
57fb188
2.4.3
57fb188
57fb188
57fb188
From 3b27d13940c3710a1128527c43719cb0bb05d73b Mon Sep 17 00:00:00 2001
57fb188
From: Wang Nan <wangnan0@huawei.com>
57fb188
Date: Tue, 1 Sep 2015 03:29:44 +0000
57fb188
Subject: [PATCH 7/9] perf dwarf: Fix potential array out of bounds access
57fb188
57fb188
There is a problem in the dwarf-regs.c files for sh, sparc and x86 where
57fb188
it is possible to make an out-of-bounds array access when searching for
57fb188
register names.
57fb188
57fb188
This patch fixes it by replacing '<=' to '<', so when register (number
57fb188
== XXX_MAX_REGS), get_arch_regstr() will return NULL.
57fb188
57fb188
Signed-off-by: Wang Nan <wangnan0@huawei.com>
57fb188
Reviewed-by: Matt Fleming <matt@console-pimps.org>
57fb188
Acked-by: Jiri Olsa <jolsa@kernel.org>
57fb188
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
57fb188
Cc: David S. Miller <davem@davemloft.net>
57fb188
Cc: Zefan Li <lizefan@huawei.com>
57fb188
Cc: pi3orama@huawei.com
57fb188
Link: http://lkml.kernel.org/r/1441078184-105038-1-git-send-email-wangnan0@huawei.com
57fb188
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
57fb188
---
57fb188
 tools/perf/arch/sh/util/dwarf-regs.c    | 2 +-
57fb188
 tools/perf/arch/sparc/util/dwarf-regs.c | 2 +-
57fb188
 tools/perf/arch/x86/util/dwarf-regs.c   | 2 +-
57fb188
 3 files changed, 3 insertions(+), 3 deletions(-)
57fb188
57fb188
diff --git a/tools/perf/arch/sh/util/dwarf-regs.c b/tools/perf/arch/sh/util/dwarf-regs.c
57fb188
index 0d0897f57a10..f8dfa89696f4 100644
57fb188
--- a/tools/perf/arch/sh/util/dwarf-regs.c
57fb188
+++ b/tools/perf/arch/sh/util/dwarf-regs.c
57fb188
@@ -51,5 +51,5 @@ const char *sh_regs_table[SH_MAX_REGS] = {
57fb188
 /* Return architecture dependent register string (for kprobe-tracer) */
57fb188
 const char *get_arch_regstr(unsigned int n)
57fb188
 {
57fb188
-	return (n <= SH_MAX_REGS) ? sh_regs_table[n] : NULL;
57fb188
+	return (n < SH_MAX_REGS) ? sh_regs_table[n] : NULL;
57fb188
 }
57fb188
diff --git a/tools/perf/arch/sparc/util/dwarf-regs.c b/tools/perf/arch/sparc/util/dwarf-regs.c
57fb188
index 92eda412fed3..b704fdb9237a 100644
57fb188
--- a/tools/perf/arch/sparc/util/dwarf-regs.c
57fb188
+++ b/tools/perf/arch/sparc/util/dwarf-regs.c
57fb188
@@ -39,5 +39,5 @@ const char *sparc_regs_table[SPARC_MAX_REGS] = {
57fb188
  */
57fb188
 const char *get_arch_regstr(unsigned int n)
57fb188
 {
57fb188
-	return (n <= SPARC_MAX_REGS) ? sparc_regs_table[n] : NULL;
57fb188
+	return (n < SPARC_MAX_REGS) ? sparc_regs_table[n] : NULL;
57fb188
 }
57fb188
diff --git a/tools/perf/arch/x86/util/dwarf-regs.c b/tools/perf/arch/x86/util/dwarf-regs.c
57fb188
index be22dd463232..a08de0a35b83 100644
57fb188
--- a/tools/perf/arch/x86/util/dwarf-regs.c
57fb188
+++ b/tools/perf/arch/x86/util/dwarf-regs.c
57fb188
@@ -71,5 +71,5 @@ const char *x86_64_regs_table[X86_64_MAX_REGS] = {
57fb188
 /* Return architecture dependent register string (for kprobe-tracer) */
57fb188
 const char *get_arch_regstr(unsigned int n)
57fb188
 {
57fb188
-	return (n <= ARCH_MAX_REGS) ? arch_regs_table[n] : NULL;
57fb188
+	return (n < ARCH_MAX_REGS) ? arch_regs_table[n] : NULL;
57fb188
 }
57fb188
-- 
57fb188
2.4.3
57fb188
57fb188
57fb188
From 04aa90b529ee45c5ee88997bc214202e07b26979 Mon Sep 17 00:00:00 2001
57fb188
From: Wang Nan <wangnan0@huawei.com>
57fb188
Date: Tue, 1 Sep 2015 05:56:45 +0000
57fb188
Subject: [PATCH 8/9] perf build: Fix Intel PT instruction decoder dependency
57fb188
 problem
57fb188
57fb188
I hit following building error randomly:
57fb188
57fb188
    ...
57fb188
  /bin/sh: /path/to/kernel/buildperf/util/intel-pt-decoder/inat-tables.c: No such file or directory
57fb188
    ...
57fb188
    LINK     /path/to/kernel/buildperf/plugin_mac80211.so
57fb188
    LINK     /path/to/kernel/buildperf/plugin_kmem.so
57fb188
    LINK     /path/to/kernel/buildperf/plugin_xen.so
57fb188
    LINK     /path/to/kernel/buildperf/plugin_hrtimer.so
57fb188
  In file included from util/intel-pt-decoder/intel-pt-insn-decoder.c:25:0:
57fb188
  util/intel-pt-decoder/inat.c:24:25: fatal error: inat-tables.c: No such file or directory
57fb188
   #include "inat-tables.c"
57fb188
                           ^
57fb188
  compilation terminated.
57fb188
  make[4]: *** [/path/to/kernel/buildperf/util/intel-pt-decoder/intel-pt-insn-decoder.o] Error 1
57fb188
  make[4]: *** Waiting for unfinished jobs....
57fb188
    LINK     /path/to/kernel/buildperf/plugin_function.so
57fb188
57fb188
This is caused by tools/perf/util/intel-pt-decoder/Build that, it tries
57fb188
to generate $(OUTPUT)util/intel-pt-decoder/inat-tables.c atomatically
57fb188
but forget to ensure the existance of $(OUTPUT)util/intel-pt-decoder
57fb188
directory.
57fb188
57fb188
This patch fixes it by adding $(call rule_mkdir) like other similar rules.
57fb188
57fb188
Signed-off-by: Wang Nan <wangnan0@huawei.com>
57fb188
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
57fb188
Acked-by: Jiri Olsa <jolsa@kernel.org>
57fb188
Cc: Zefan Li <lizefan@huawei.com>
57fb188
Cc: pi3orama@163.com
57fb188
Link: http://lkml.kernel.org/r/1441087005-107540-1-git-send-email-wangnan0@huawei.com
57fb188
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
57fb188
---
57fb188
 tools/perf/util/intel-pt-decoder/Build | 1 +
57fb188
 1 file changed, 1 insertion(+)
57fb188
57fb188
diff --git a/tools/perf/util/intel-pt-decoder/Build b/tools/perf/util/intel-pt-decoder/Build
57fb188
index 240730d682c1..2386322ece4f 100644
57fb188
--- a/tools/perf/util/intel-pt-decoder/Build
57fb188
+++ b/tools/perf/util/intel-pt-decoder/Build
57fb188
@@ -4,6 +4,7 @@ inat_tables_script = util/intel-pt-decoder/gen-insn-attr-x86.awk
57fb188
 inat_tables_maps = util/intel-pt-decoder/x86-opcode-map.txt
57fb188
 
57fb188
 $(OUTPUT)util/intel-pt-decoder/inat-tables.c: $(inat_tables_script) $(inat_tables_maps)
57fb188
+	$(call rule_mkdir)
57fb188
 	@$(call echo-cmd,gen)$(AWK) -f $(inat_tables_script) $(inat_tables_maps) > $@ || rm -f $@
57fb188
 
57fb188
 $(OUTPUT)util/intel-pt-decoder/intel-pt-insn-decoder.o: util/intel-pt-decoder/inat.c $(OUTPUT)util/intel-pt-decoder/inat-tables.c
57fb188
-- 
57fb188
2.4.3
57fb188
57fb188
57fb188
From af4aeadd8c04303c0aa2d112145c3627e2ebd026 Mon Sep 17 00:00:00 2001
57fb188
From: Stephane Eranian <eranian@google.com>
57fb188
Date: Tue, 1 Sep 2015 11:30:14 +0200
57fb188
Subject: [PATCH 9/9] perf tools: Fix link time error with sample_reg_masks on
57fb188
 non x86
57fb188
57fb188
This patch makes perf compile on non x86 platforms by defining a weak
57fb188
symbol for sample_reg_masks[] in util/perf_regs.c.
57fb188
57fb188
The patch also moves the REG() and REG_END() macros into the
57fb188
util/per_regs.h header file. The macros are renamed to
57fb188
SMPL_REG/SMPL_REG_END to avoid clashes with other header files.
57fb188
57fb188
Signed-off-by: Stephane Eranian <eranian@google.com>
57fb188
Acked-by: Jiri Olsa <jolsa@kernel.org>
57fb188
Cc: Adrian Hunter <adrian.hunter@intel.com>
57fb188
Cc: Andi Kleen <ak@linux.intel.com>
57fb188
Cc: David Ahern <dsahern@gmail.com>
57fb188
Cc: Kan Liang <kan.liang@intel.com>
57fb188
Cc: Namhyung Kim <namhyung@kernel.org>
57fb188
Cc: Peter Zijlstra <peterz@infradead.org>
57fb188
Link: http://lkml.kernel.org/r/1441099814-26783-1-git-send-email-eranian@google.com
57fb188
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
57fb188
---
57fb188
 tools/perf/arch/x86/util/perf_regs.c | 44 +++++++++++++++++-------------------
57fb188
 tools/perf/util/perf_regs.c          |  4 ++++
57fb188
 tools/perf/util/perf_regs.h          |  2 ++
57fb188
 3 files changed, 27 insertions(+), 23 deletions(-)
57fb188
57fb188
diff --git a/tools/perf/arch/x86/util/perf_regs.c b/tools/perf/arch/x86/util/perf_regs.c
57fb188
index 087c84ef5234..c5db14f36cc7 100644
57fb188
--- a/tools/perf/arch/x86/util/perf_regs.c
57fb188
+++ b/tools/perf/arch/x86/util/perf_regs.c
57fb188
@@ -1,30 +1,28 @@
57fb188
 #include "../../perf.h"
57fb188
 #include "../../util/perf_regs.h"
57fb188
 
57fb188
-#define REG(n, b) { .name = #n, .mask = 1ULL << (b) }
57fb188
-#define REG_END { .name = NULL }
57fb188
 const struct sample_reg sample_reg_masks[] = {
57fb188
-	REG(AX, PERF_REG_X86_AX),
57fb188
-	REG(BX, PERF_REG_X86_BX),
57fb188
-	REG(CX, PERF_REG_X86_CX),
57fb188
-	REG(DX, PERF_REG_X86_DX),
57fb188
-	REG(SI, PERF_REG_X86_SI),
57fb188
-	REG(DI, PERF_REG_X86_DI),
57fb188
-	REG(BP, PERF_REG_X86_BP),
57fb188
-	REG(SP, PERF_REG_X86_SP),
57fb188
-	REG(IP, PERF_REG_X86_IP),
57fb188
-	REG(FLAGS, PERF_REG_X86_FLAGS),
57fb188
-	REG(CS, PERF_REG_X86_CS),
57fb188
-	REG(SS, PERF_REG_X86_SS),
57fb188
+	SMPL_REG(AX, PERF_REG_X86_AX),
57fb188
+	SMPL_REG(BX, PERF_REG_X86_BX),
57fb188
+	SMPL_REG(CX, PERF_REG_X86_CX),
57fb188
+	SMPL_REG(DX, PERF_REG_X86_DX),
57fb188
+	SMPL_REG(SI, PERF_REG_X86_SI),
57fb188
+	SMPL_REG(DI, PERF_REG_X86_DI),
57fb188
+	SMPL_REG(BP, PERF_REG_X86_BP),
57fb188
+	SMPL_REG(SP, PERF_REG_X86_SP),
57fb188
+	SMPL_REG(IP, PERF_REG_X86_IP),
57fb188
+	SMPL_REG(FLAGS, PERF_REG_X86_FLAGS),
57fb188
+	SMPL_REG(CS, PERF_REG_X86_CS),
57fb188
+	SMPL_REG(SS, PERF_REG_X86_SS),
57fb188
 #ifdef HAVE_ARCH_X86_64_SUPPORT
57fb188
-	REG(R8, PERF_REG_X86_R8),
57fb188
-	REG(R9, PERF_REG_X86_R9),
57fb188
-	REG(R10, PERF_REG_X86_R10),
57fb188
-	REG(R11, PERF_REG_X86_R11),
57fb188
-	REG(R12, PERF_REG_X86_R12),
57fb188
-	REG(R13, PERF_REG_X86_R13),
57fb188
-	REG(R14, PERF_REG_X86_R14),
57fb188
-	REG(R15, PERF_REG_X86_R15),
57fb188
+	SMPL_REG(R8, PERF_REG_X86_R8),
57fb188
+	SMPL_REG(R9, PERF_REG_X86_R9),
57fb188
+	SMPL_REG(R10, PERF_REG_X86_R10),
57fb188
+	SMPL_REG(R11, PERF_REG_X86_R11),
57fb188
+	SMPL_REG(R12, PERF_REG_X86_R12),
57fb188
+	SMPL_REG(R13, PERF_REG_X86_R13),
57fb188
+	SMPL_REG(R14, PERF_REG_X86_R14),
57fb188
+	SMPL_REG(R15, PERF_REG_X86_R15),
57fb188
 #endif
57fb188
-	REG_END
57fb188
+	SMPL_REG_END
57fb188
 };
57fb188
diff --git a/tools/perf/util/perf_regs.c b/tools/perf/util/perf_regs.c
57fb188
index 43168fb0d9a2..885e8ac83997 100644
57fb188
--- a/tools/perf/util/perf_regs.c
57fb188
+++ b/tools/perf/util/perf_regs.c
57fb188
@@ -2,6 +2,10 @@
57fb188
 #include "perf_regs.h"
57fb188
 #include "event.h"
57fb188
 
57fb188
+const struct sample_reg __weak sample_reg_masks[] = {
57fb188
+	SMPL_REG_END
57fb188
+};
57fb188
+
57fb188
 int perf_reg_value(u64 *valp, struct regs_dump *regs, int id)
57fb188
 {
57fb188
 	int i, idx = 0;
57fb188
diff --git a/tools/perf/util/perf_regs.h b/tools/perf/util/perf_regs.h
57fb188
index 92c1fff2153e..2984dcc54d67 100644
57fb188
--- a/tools/perf/util/perf_regs.h
57fb188
+++ b/tools/perf/util/perf_regs.h
57fb188
@@ -9,6 +9,8 @@ struct sample_reg {
57fb188
 	const char *name;
57fb188
 	uint64_t mask;
57fb188
 };
57fb188
+#define SMPL_REG(n, b) { .name = #n, .mask = 1ULL << (b) }
57fb188
+#define SMPL_REG_END { .name = NULL }
57fb188
 
57fb188
 extern const struct sample_reg sample_reg_masks[];
57fb188
 
57fb188
-- 
57fb188
2.4.3
57fb188