linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] perf tools: Add Intel PT support for jitdump
@ 2016-03-03 11:50 Adrian Hunter
  2016-03-03 11:50 ` [PATCH 1/8] perf inject: Hit all DSOs for AUX data in JIT and other cases Adrian Hunter
                   ` (8 more replies)
  0 siblings, 9 replies; 31+ messages in thread
From: Adrian Hunter @ 2016-03-03 11:50 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Stephane Eranian

Hi

In order to use Intel PT with jitdump, changes are needed
because Intel PT uses TSC as a timestamp not the monotonic clock.

These patches enable TSC to be used which allows the following
using a simple HelloWorld java app:

	perf record -e intel_pt//u -o java.perf.data java -agentpath:/home/ahunter/git/linux-perf/tools/perf/jvmti/libjvmti.so HelloWorldApp

	perf inject -i java.perf.data --jit -o java.perf.data.jitted

	perf report -i java.perf.data.jitted

	perf script -i java.perf.data.jitted | less

Note, there will be some decoder errors because not all the
generated code is reported to the agent.

Lazily, there is also an unrelated patch:

	perf tools: Use 64-bit shifts with (TSC) time conversion"


Adrian Hunter (8):
      perf inject: Hit all DSOs for AUX data in JIT and other cases
      perf session: Simplify tool stubs
      perf tools: Add time conversion event
      perf jit: Let jit_process() return errors
      perf jit: Move clockid validation
      perf jit: Add support for using TSC as a timestamp
      perf intel-pt/bts: Define JITDUMP_USE_ARCH_TIMESTAMP
      perf tools: Use 64-bit shifts with (TSC) time conversion

 tools/perf/arch/x86/tests/rdpmc.c    |  2 +-
 tools/perf/arch/x86/util/intel-bts.c |  5 +++
 tools/perf/arch/x86/util/intel-pt.c  |  5 +++
 tools/perf/arch/x86/util/tsc.c       | 31 +++++++++++++++++
 tools/perf/builtin-inject.c          | 53 ++++++++++++-----------------
 tools/perf/builtin-record.c          | 15 +++++++++
 tools/perf/jvmti/jvmti_agent.c       | 43 ++++++++++++++++++++++--
 tools/perf/util/event.c              |  1 +
 tools/perf/util/event.h              |  9 +++++
 tools/perf/util/jitdump.c            | 64 ++++++++++++++++++++++++++++++++----
 tools/perf/util/jitdump.h            |  3 ++
 tools/perf/util/session.c            | 46 ++++++++------------------
 tools/perf/util/session.h            |  1 +
 tools/perf/util/tool.h               |  1 +
 tools/perf/util/tsc.c                |  2 +-
 tools/perf/util/tsc.h                | 10 ++++++
 16 files changed, 216 insertions(+), 75 deletions(-)


Regards
Adrian

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH 1/8] perf inject: Hit all DSOs for AUX data in JIT and other cases
  2016-03-03 11:50 [PATCH 0/8] perf tools: Add Intel PT support for jitdump Adrian Hunter
@ 2016-03-03 11:50 ` Adrian Hunter
  2016-03-08 10:30   ` [tip:perf/core] " tip-bot for Adrian Hunter
  2016-03-03 11:50 ` [PATCH 2/8] perf session: Simplify tool stubs Adrian Hunter
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 31+ messages in thread
From: Adrian Hunter @ 2016-03-03 11:50 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Stephane Eranian

Currently, when injecting build ids, if there is AUX data
then 'perf inject' hits all DSOs because it is not known
which DSOs the trace data would hit.

That needs to be done for JIT injection also, and in fact
there is no reason to distinguish what kind of injection
is being done.  That is, any time there is AUX data and
the HEADER_BUID_ID feature flag is set, and the AUX data
is not being processed, then hit all DSOs.  This patch
does that.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/builtin-inject.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index b38445f08c2f..c6a4f2f94ab1 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -679,12 +679,16 @@ static int __cmd_inject(struct perf_inject *inject)
 	ret = perf_session__process_events(session);
 
 	if (!file_out->is_pipe) {
-		if (inject->build_ids) {
+		if (inject->build_ids)
 			perf_header__set_feat(&session->header,
 					      HEADER_BUILD_ID);
-			if (inject->have_auxtrace)
-				dsos__hit_all(session);
-		}
+		/*
+		 * Keep all buildids when there is unprocessed AUX data because
+		 * it is not known which ones the AUX trace hits.
+		 */
+		if (perf_header__has_feat(&session->header, HEADER_BUILD_ID) &&
+		    inject->have_auxtrace && !inject->itrace_synth_opts.set)
+			dsos__hit_all(session);
 		/*
 		 * The AUX areas have been removed and replaced with
 		 * synthesized hardware events, so clear the feature flag and
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 2/8] perf session: Simplify tool stubs
  2016-03-03 11:50 [PATCH 0/8] perf tools: Add Intel PT support for jitdump Adrian Hunter
  2016-03-03 11:50 ` [PATCH 1/8] perf inject: Hit all DSOs for AUX data in JIT and other cases Adrian Hunter
@ 2016-03-03 11:50 ` Adrian Hunter
  2016-03-08  8:38   ` [PATCH V2 " Adrian Hunter
  2016-03-08 10:30   ` [tip:perf/core] " tip-bot for Adrian Hunter
  2016-03-03 11:50 ` [PATCH 3/8] perf tools: Add time conversion event Adrian Hunter
                   ` (6 subsequent siblings)
  8 siblings, 2 replies; 31+ messages in thread
From: Adrian Hunter @ 2016-03-03 11:50 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Stephane Eranian

From: Adrian Hunter <ajhunter@gmail.com>

Some of the stubs are identical so just have one function
for them.

Signed-off-by: Adrian Hunter <ajhunter@gmail.com>
---
 tools/perf/util/session.c | 40 +++++++---------------------------------
 1 file changed, 7 insertions(+), 33 deletions(-)

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 40b7a0d0905b..60b3593d210d 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -240,14 +240,6 @@ static int process_event_stub(struct perf_tool *tool __maybe_unused,
 	return 0;
 }
 
-static int process_build_id_stub(struct perf_tool *tool __maybe_unused,
-				 union perf_event *event __maybe_unused,
-				 struct perf_session *session __maybe_unused)
-{
-	dump_printf(": unhandled!\n");
-	return 0;
-}
-
 static int process_finished_round_stub(struct perf_tool *tool __maybe_unused,
 				       union perf_event *event __maybe_unused,
 				       struct ordered_events *oe __maybe_unused)
@@ -260,23 +252,6 @@ static int process_finished_round(struct perf_tool *tool,
 				  union perf_event *event,
 				  struct ordered_events *oe);
 
-static int process_id_index_stub(struct perf_tool *tool __maybe_unused,
-				 union perf_event *event __maybe_unused,
-				 struct perf_session *perf_session
-				 __maybe_unused)
-{
-	dump_printf(": unhandled!\n");
-	return 0;
-}
-
-static int process_event_auxtrace_info_stub(struct perf_tool *tool __maybe_unused,
-				union perf_event *event __maybe_unused,
-				struct perf_session *session __maybe_unused)
-{
-	dump_printf(": unhandled!\n");
-	return 0;
-}
-
 static int skipn(int fd, off_t n)
 {
 	char buf[4096];
@@ -303,10 +278,9 @@ static s64 process_event_auxtrace_stub(struct perf_tool *tool __maybe_unused,
 	return event->auxtrace.size;
 }
 
-static
-int process_event_auxtrace_error_stub(struct perf_tool *tool __maybe_unused,
-				      union perf_event *event __maybe_unused,
-				      struct perf_session *session __maybe_unused)
+static int process_event_op2_stub(struct perf_tool *tool __maybe_unused,
+				  union perf_event *event __maybe_unused,
+				  struct perf_session *session __maybe_unused)
 {
 	dump_printf(": unhandled!\n");
 	return 0;
@@ -410,7 +384,7 @@ void perf_tool__fill_defaults(struct perf_tool *tool)
 	if (tool->tracing_data == NULL)
 		tool->tracing_data = process_event_synth_tracing_data_stub;
 	if (tool->build_id == NULL)
-		tool->build_id = process_build_id_stub;
+		tool->build_id = process_event_op2_stub;
 	if (tool->finished_round == NULL) {
 		if (tool->ordered_events)
 			tool->finished_round = process_finished_round;
@@ -418,13 +392,13 @@ void perf_tool__fill_defaults(struct perf_tool *tool)
 			tool->finished_round = process_finished_round_stub;
 	}
 	if (tool->id_index == NULL)
-		tool->id_index = process_id_index_stub;
+		tool->id_index = process_event_op2_stub;
 	if (tool->auxtrace_info == NULL)
-		tool->auxtrace_info = process_event_auxtrace_info_stub;
+		tool->auxtrace_info = process_event_op2_stub;
 	if (tool->auxtrace == NULL)
 		tool->auxtrace = process_event_auxtrace_stub;
 	if (tool->auxtrace_error == NULL)
-		tool->auxtrace_error = process_event_auxtrace_error_stub;
+		tool->auxtrace_error = process_event_op2_stub;
 	if (tool->thread_map == NULL)
 		tool->thread_map = process_event_thread_map_stub;
 	if (tool->cpu_map == NULL)
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 3/8] perf tools: Add time conversion event
  2016-03-03 11:50 [PATCH 0/8] perf tools: Add Intel PT support for jitdump Adrian Hunter
  2016-03-03 11:50 ` [PATCH 1/8] perf inject: Hit all DSOs for AUX data in JIT and other cases Adrian Hunter
  2016-03-03 11:50 ` [PATCH 2/8] perf session: Simplify tool stubs Adrian Hunter
@ 2016-03-03 11:50 ` Adrian Hunter
  2016-03-08  8:38   ` [PATCH V2 " Adrian Hunter
  2016-03-03 11:50 ` [PATCH 4/8] perf jit: Let jit_process() return errors Adrian Hunter
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 31+ messages in thread
From: Adrian Hunter @ 2016-03-03 11:50 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Stephane Eranian

From: Adrian Hunter <ajhunter@gmail.com>

Intel PT uses the time members from the perf_event_mmap_page
to convert between TSC and perf time.

Due to a lack of foresight when Intel PT was implemented,
those time members were recorded in the (implementation
dependent) AUXTRACE_INFO event, the structure of which is
generally inaccessible outside of the Intel PT decoder.
However now the conversion between TSC and perf time is needed
when processing a jitdump file when Intel PT has been used for
tracing.

So add a user event to record the time members.  'perf record'
will synthesize the event if the information is available.
And session processing will put a copy of the event on the
session so that tools like 'perf inject' can easily access it.

Signed-off-by: Adrian Hunter <ajhunter@gmail.com>
---
 tools/perf/arch/x86/util/tsc.c | 31 +++++++++++++++++++++++++++++++
 tools/perf/builtin-inject.c    |  1 +
 tools/perf/builtin-record.c    | 15 +++++++++++++++
 tools/perf/util/event.c        |  1 +
 tools/perf/util/event.h        |  9 +++++++++
 tools/perf/util/session.c      |  6 ++++++
 tools/perf/util/session.h      |  1 +
 tools/perf/util/tool.h         |  1 +
 tools/perf/util/tsc.h          | 10 ++++++++++
 9 files changed, 75 insertions(+)

diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c
index fd2868490d00..70ff7c14bea6 100644
--- a/tools/perf/arch/x86/util/tsc.c
+++ b/tools/perf/arch/x86/util/tsc.c
@@ -46,3 +46,34 @@ u64 rdtsc(void)
 
 	return low | ((u64)high) << 32;
 }
+
+int perf_event__synth_time_conv(const struct perf_event_mmap_page *pc,
+				struct perf_tool *tool,
+				perf_event__handler_t process,
+				struct machine *machine)
+{
+	union perf_event event = {
+		.time_conv = {
+			.header = {
+				.type = PERF_RECORD_TIME_CONV,
+				.size = sizeof(struct time_conv_event),
+			},
+		},
+	};
+	struct perf_tsc_conversion tc;
+	int err;
+
+	err = perf_read_tsc_conversion(pc, &tc);
+	if (err == -EOPNOTSUPP)
+		return 0;
+	if (err)
+		return err;
+
+	pr_debug2("Synthesizing TSC conversion information\n");
+
+	event.time_conv.time_mult  = tc.time_mult;
+	event.time_conv.time_shift = tc.time_shift;
+	event.time_conv.time_zero  = tc.time_zero;
+
+	return process(tool, &event, NULL, machine);
+}
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index c6a4f2f94ab1..29dfe68b2fb1 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -761,6 +761,7 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
 			.auxtrace_info	= perf_event__repipe_op2_synth,
 			.auxtrace	= perf_event__repipe_auxtrace,
 			.auxtrace_error	= perf_event__repipe_op2_synth,
+			.time_conv	= perf_event__repipe_op2_synth,
 			.finished_round	= perf_event__repipe_oe_synth,
 			.build_id	= perf_event__repipe_op2_synth,
 			.id_index	= perf_event__repipe_op2_synth,
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 515510ecc76a..410035c6e300 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -29,6 +29,7 @@
 #include "util/data.h"
 #include "util/perf_regs.h"
 #include "util/auxtrace.h"
+#include "util/tsc.h"
 #include "util/parse-branch-options.h"
 #include "util/parse-regs-options.h"
 #include "util/llvm-utils.h"
@@ -512,6 +513,15 @@ static void workload_exec_failed_signal(int signo __maybe_unused,
 
 static void snapshot_sig_handler(int sig);
 
+int __weak
+perf_event__synth_time_conv(const struct perf_event_mmap_page *pc __maybe_unused,
+			    struct perf_tool *tool __maybe_unused,
+			    perf_event__handler_t process __maybe_unused,
+			    struct machine *machine __maybe_unused)
+{
+	return 0;
+}
+
 static int record__synthesize(struct record *rec)
 {
 	struct perf_session *session = rec->session;
@@ -549,6 +559,11 @@ static int record__synthesize(struct record *rec)
 		}
 	}
 
+	err = perf_event__synth_time_conv(rec->evlist->mmap[0].base, tool,
+					  process_synthesized_event, machine);
+	if (err)
+		goto out;
+
 	if (rec->opts.full_auxtrace) {
 		err = perf_event__synthesize_auxtrace_info(rec->itr, tool,
 					session, process_synthesized_event);
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 7bad5c3fa7b7..025509129cda 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -45,6 +45,7 @@ static const char *perf_event__names[] = {
 	[PERF_RECORD_STAT]			= "STAT",
 	[PERF_RECORD_STAT_ROUND]		= "STAT_ROUND",
 	[PERF_RECORD_EVENT_UPDATE]		= "EVENT_UPDATE",
+	[PERF_RECORD_TIME_CONV]			= "TIME_CONV",
 };
 
 const char *perf_event__name(unsigned int id)
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index b7ffb7ee9971..f1dafa05e8bf 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -232,6 +232,7 @@ enum perf_user_event_type { /* above any possible kernel type */
 	PERF_RECORD_STAT			= 76,
 	PERF_RECORD_STAT_ROUND			= 77,
 	PERF_RECORD_EVENT_UPDATE		= 78,
+	PERF_RECORD_TIME_CONV			= 79,
 	PERF_RECORD_HEADER_MAX
 };
 
@@ -468,6 +469,13 @@ struct stat_round_event {
 	u64				time;
 };
 
+struct time_conv_event {
+	struct perf_event_header header;
+	u64 time_shift;
+	u64 time_mult;
+	u64 time_zero;
+};
+
 union perf_event {
 	struct perf_event_header	header;
 	struct mmap_event		mmap;
@@ -496,6 +504,7 @@ union perf_event {
 	struct stat_config_event	stat_config;
 	struct stat_event		stat;
 	struct stat_round_event		stat_round;
+	struct time_conv_event		time_conv;
 };
 
 void perf_event__print_totals(void);
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 60b3593d210d..ee1778a9c0c7 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -409,6 +409,8 @@ void perf_tool__fill_defaults(struct perf_tool *tool)
 		tool->stat = process_stat_stub;
 	if (tool->stat_round == NULL)
 		tool->stat_round = process_stat_round_stub;
+	if (tool->time_conv == NULL)
+		tool->time_conv = process_event_op2_stub;
 }
 
 static void swap_sample_id_all(union perf_event *event, void *data)
@@ -794,6 +796,7 @@ static perf_event__swap_op perf_event__swap_ops[] = {
 	[PERF_RECORD_STAT]		  = perf_event__stat_swap,
 	[PERF_RECORD_STAT_ROUND]	  = perf_event__stat_round_swap,
 	[PERF_RECORD_EVENT_UPDATE]	  = perf_event__event_update_swap,
+	[PERF_RECORD_TIME_CONV]		  = perf_event__all64_swap,
 	[PERF_RECORD_HEADER_MAX]	  = NULL,
 };
 
@@ -1342,6 +1345,9 @@ static s64 perf_session__process_user_event(struct perf_session *session,
 		return tool->stat(tool, event, session);
 	case PERF_RECORD_STAT_ROUND:
 		return tool->stat_round(tool, event, session);
+	case PERF_RECORD_TIME_CONV:
+		session->time_conv = event->time_conv;
+		return tool->time_conv(tool, event, session);
 	default:
 		return -EINVAL;
 	}
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 5f792e35d4c1..f96fc9e8c52e 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -26,6 +26,7 @@ struct perf_session {
 	struct itrace_synth_opts *itrace_synth_opts;
 	struct list_head	auxtrace_index;
 	struct trace_event	tevent;
+	struct time_conv_event	time_conv;
 	bool			repipe;
 	bool			one_mmap;
 	void			*one_mmap_addr;
diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h
index 55de4cffcd4e..ac2590a3de2d 100644
--- a/tools/perf/util/tool.h
+++ b/tools/perf/util/tool.h
@@ -57,6 +57,7 @@ struct perf_tool {
 			id_index,
 			auxtrace_info,
 			auxtrace_error,
+			time_conv,
 			thread_map,
 			cpu_map,
 			stat_config,
diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h
index a8b78f1b3243..280ddc067556 100644
--- a/tools/perf/util/tsc.h
+++ b/tools/perf/util/tsc.h
@@ -3,10 +3,20 @@
 
 #include <linux/types.h>
 
+#include "event.h"
 #include "../arch/x86/util/tsc.h"
 
 u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc);
 u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc);
 u64 rdtsc(void);
 
+struct perf_event_mmap_page;
+struct perf_tool;
+struct machine;
+
+int perf_event__synth_time_conv(const struct perf_event_mmap_page *pc,
+				struct perf_tool *tool,
+				perf_event__handler_t process,
+				struct machine *machine);
+
 #endif
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 4/8] perf jit: Let jit_process() return errors
  2016-03-03 11:50 [PATCH 0/8] perf tools: Add Intel PT support for jitdump Adrian Hunter
                   ` (2 preceding siblings ...)
  2016-03-03 11:50 ` [PATCH 3/8] perf tools: Add time conversion event Adrian Hunter
@ 2016-03-03 11:50 ` Adrian Hunter
  2016-03-08 10:30   ` [tip:perf/core] " tip-bot for Adrian Hunter
  2016-03-03 11:50 ` [PATCH 5/8] perf jit: Move clockid validation Adrian Hunter
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 31+ messages in thread
From: Adrian Hunter @ 2016-03-03 11:50 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Stephane Eranian

In preparation for moving clockid validation into jit_process().

Previously a return value of zero meant the processing had been
done and non-zero meant either the processing was not done
(i.e. not the jitdump file mmap event) or an error occurred.

Change it so that zero means the processing was not done, one
means the processing was done and successful, and negative
values are an error.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/builtin-inject.c | 16 ++++++++++++----
 tools/perf/util/jitdump.c   |  6 ++++--
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index 29dfe68b2fb1..1635533921e8 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -253,12 +253,16 @@ static int perf_event__jit_repipe_mmap(struct perf_tool *tool,
 {
 	struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
 	u64 n = 0;
+	int ret;
 
 	/*
 	 * if jit marker, then inject jit mmaps and generate ELF images
 	 */
-	if (!jit_process(inject->session, &inject->output, machine,
-			 event->mmap.filename, sample->pid, &n)) {
+	ret = jit_process(inject->session, &inject->output, machine,
+			  event->mmap.filename, sample->pid, &n);
+	if (ret < 0)
+		return ret;
+	if (ret) {
 		inject->bytes_written += n;
 		return 0;
 	}
@@ -287,12 +291,16 @@ static int perf_event__jit_repipe_mmap2(struct perf_tool *tool,
 {
 	struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
 	u64 n = 0;
+	int ret;
 
 	/*
 	 * if jit marker, then inject jit mmaps and generate ELF images
 	 */
-	if (!jit_process(inject->session, &inject->output, machine,
-			  event->mmap2.filename, sample->pid, &n)) {
+	ret = jit_process(inject->session, &inject->output, machine,
+			  event->mmap2.filename, sample->pid, &n);
+	if (ret < 0)
+		return ret;
+	if (ret) {
 		inject->bytes_written += n;
 		return 0;
 	}
diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index 99fa5eee9fe0..bd9e44f9fff2 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -647,7 +647,7 @@ jit_process(struct perf_session *session,
 	 * first, detect marker mmap (i.e., the jitdump mmap)
 	 */
 	if (jit_detect(filename, pid))
-		return -1;
+		return 0;
 
 	memset(&jd, 0, sizeof(jd));
 
@@ -665,8 +665,10 @@ jit_process(struct perf_session *session,
 	*nbytes = 0;
 
 	ret = jit_inject(&jd, filename);
-	if (!ret)
+	if (!ret) {
 		*nbytes = jd.bytes_written;
+		ret = 1;
+	}
 
 	return ret;
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 5/8] perf jit: Move clockid validation
  2016-03-03 11:50 [PATCH 0/8] perf tools: Add Intel PT support for jitdump Adrian Hunter
                   ` (3 preceding siblings ...)
  2016-03-03 11:50 ` [PATCH 4/8] perf jit: Let jit_process() return errors Adrian Hunter
@ 2016-03-03 11:50 ` Adrian Hunter
  2016-03-08  8:38   ` [PATCH V2 " Adrian Hunter
  2016-03-08 10:31   ` [tip:perf/core] " tip-bot for Adrian Hunter
  2016-03-03 11:50 ` [PATCH 6/8] perf jit: Add support for using TSC as a timestamp Adrian Hunter
                   ` (3 subsequent siblings)
  8 siblings, 2 replies; 31+ messages in thread
From: Adrian Hunter @ 2016-03-03 11:50 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Stephane Eranian

From: Adrian Hunter <ajhunter@gmail.com>

Move clockid validation into jit_process() so it can later be
made conditional.

Signed-off-by: Adrian Hunter <ajhunter@gmail.com>
---
 tools/perf/builtin-inject.c | 24 ------------------------
 tools/perf/util/jitdump.c   | 23 +++++++++++++++++++++++
 2 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index 1635533921e8..319b7b4f7743 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -729,23 +729,6 @@ static int __cmd_inject(struct perf_inject *inject)
 	return ret;
 }
 
-#ifdef HAVE_LIBELF_SUPPORT
-static int
-jit_validate_events(struct perf_session *session)
-{
-	struct perf_evsel *evsel;
-
-	/*
-	 * check that all events use CLOCK_MONOTONIC
-	 */
-	evlist__for_each(session->evlist, evsel) {
-		if (evsel->attr.use_clockid == 0 || evsel->attr.clockid != CLOCK_MONOTONIC)
-			return -1;
-	}
-	return 0;
-}
-#endif
-
 int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
 {
 	struct perf_inject inject = {
@@ -853,13 +836,6 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
 	}
 #ifdef HAVE_LIBELF_SUPPORT
 	if (inject.jit_mode) {
-		/*
-		 * validate event is using the correct clockid
-		 */
-		if (jit_validate_events(inject.session)) {
-			fprintf(stderr, "error, jitted code must be sampled with perf record -k 1\n");
-			return -1;
-		}
 		inject.tool.mmap2	   = perf_event__jit_repipe_mmap2;
 		inject.tool.mmap	   = perf_event__jit_repipe_mmap;
 		inject.tool.ordered_events = true;
diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index bd9e44f9fff2..cd272cc21e05 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -99,6 +99,21 @@ jit_close(struct jit_buf_desc *jd)
 }
 
 static int
+jit_validate_events(struct perf_session *session)
+{
+	struct perf_evsel *evsel;
+
+	/*
+	 * check that all events use CLOCK_MONOTONIC
+	 */
+	evlist__for_each(session->evlist, evsel) {
+		if (evsel->attr.use_clockid == 0 || evsel->attr.clockid != CLOCK_MONOTONIC)
+			return -1;
+	}
+	return 0;
+}
+
+static int
 jit_open(struct jit_buf_desc *jd, const char *name)
 {
 	struct jitheader header;
@@ -157,6 +172,14 @@ jit_open(struct jit_buf_desc *jd, const char *name)
 		goto error;
 	}
 
+	/*
+	 * validate event is using the correct clockid
+	 */
+	if (jit_validate_events(jd->session)) {
+		pr_err("error, jitted code must be sampled with perf record -k 1\n");
+		goto error;
+	}
+
 	bs = header.total_size - sizeof(header);
 
 	if (bs > bsz) {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 6/8] perf jit: Add support for using TSC as a timestamp
  2016-03-03 11:50 [PATCH 0/8] perf tools: Add Intel PT support for jitdump Adrian Hunter
                   ` (4 preceding siblings ...)
  2016-03-03 11:50 ` [PATCH 5/8] perf jit: Move clockid validation Adrian Hunter
@ 2016-03-03 11:50 ` Adrian Hunter
  2016-03-08  8:38   ` [PATCH V2 " Adrian Hunter
  2016-03-03 11:50 ` [PATCH 7/8] perf intel-pt/bts: Define JITDUMP_USE_ARCH_TIMESTAMP Adrian Hunter
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 31+ messages in thread
From: Adrian Hunter @ 2016-03-03 11:50 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Stephane Eranian

From: Adrian Hunter <ajhunter@gmail.com>

Intel PT uses TSC as a timestamp, so add support for using TSC
instead of the monotonic clock.  Use of TSC is selected by
an environment variable "JITDUMP_USE_ARCH_TIMESTAMP" and flagged
in the jitdump file with flag JITDUMP_FLAGS_ARCH_TIMESTAMP.

Signed-off-by: Adrian Hunter <ajhunter@gmail.com>
---
 tools/perf/jvmti/jvmti_agent.c | 43 ++++++++++++++++++++++++++++++++++++++++--
 tools/perf/util/jitdump.c      | 37 +++++++++++++++++++++++++++++++-----
 tools/perf/util/jitdump.h      |  3 +++
 3 files changed, 76 insertions(+), 7 deletions(-)

diff --git a/tools/perf/jvmti/jvmti_agent.c b/tools/perf/jvmti/jvmti_agent.c
index 6461e02ab940..3573f315f955 100644
--- a/tools/perf/jvmti/jvmti_agent.c
+++ b/tools/perf/jvmti/jvmti_agent.c
@@ -92,6 +92,22 @@ error:
 	return ret;
 }
 
+static int use_arch_timestamp;
+
+static inline uint64_t
+get_arch_timestamp(void)
+{
+#if defined(__i386__) || defined(__x86_64__)
+	unsigned int low, high;
+
+	asm volatile("rdtsc" : "=a" (low), "=d" (high));
+
+	return low | ((uint64_t)high) << 32;
+#else
+	return 0;
+#endif
+}
+
 #define NSEC_PER_SEC	1000000000
 static int perf_clk_id = CLOCK_MONOTONIC;
 
@@ -107,6 +123,9 @@ perf_get_timestamp(void)
 	struct timespec ts;
 	int ret;
 
+	if (use_arch_timestamp)
+		return get_arch_timestamp();
+
 	ret = clock_gettime(perf_clk_id, &ts);
 	if (ret)
 		return 0;
@@ -203,6 +222,17 @@ perf_close_marker_file(void)
 	munmap(marker_addr, pgsz);
 }
 
+static void
+init_arch_timestamp(void)
+{
+	char *str = getenv("JITDUMP_USE_ARCH_TIMESTAMP");
+
+	if (!str || !*str || !strcmp(str, "0"))
+		return;
+
+	use_arch_timestamp = 1;
+}
+
 void *jvmti_open(void)
 {
 	int pad_cnt;
@@ -211,11 +241,17 @@ void *jvmti_open(void)
 	int fd;
 	FILE *fp;
 
+	init_arch_timestamp();
+
 	/*
 	 * check if clockid is supported
 	 */
-	if (!perf_get_timestamp())
-		warnx("jvmti: kernel does not support %d clock id", perf_clk_id);
+	if (!perf_get_timestamp()) {
+		if (use_arch_timestamp)
+			warnx("jvmti: arch timestamp not supported");
+		else
+			warnx("jvmti: kernel does not support %d clock id", perf_clk_id);
+	}
 
 	memset(&header, 0, sizeof(header));
 
@@ -263,6 +299,9 @@ void *jvmti_open(void)
 
 	header.timestamp = perf_get_timestamp();
 
+	if (use_arch_timestamp)
+		header.flags |= JITDUMP_FLAGS_ARCH_TIMESTAMP;
+
 	if (!fwrite(&header, sizeof(header), 1, fp)) {
 		warn("jvmti: cannot write dumpfile header");
 		goto error;
diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index cd272cc21e05..5608179dff34 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -17,6 +17,7 @@
 #include "strlist.h"
 #include <elf.h>
 
+#include "tsc.h"
 #include "session.h"
 #include "jit.h"
 #include "jitdump.h"
@@ -33,6 +34,7 @@ struct jit_buf_desc {
 	size_t           bufsize;
 	FILE             *in;
 	bool		 needs_bswap; /* handles cross-endianess */
+	bool		 use_arch_timestamp;
 	void		 *debug_data;
 	size_t		 nr_debug_entries;
 	uint32_t         code_load_count;
@@ -158,13 +160,16 @@ jit_open(struct jit_buf_desc *jd, const char *name)
 		header.flags      = bswap_64(header.flags);
 	}
 
+	jd->use_arch_timestamp = header.flags & JITDUMP_FLAGS_ARCH_TIMESTAMP;
+
 	if (verbose > 2)
-		pr_debug("version=%u\nhdr.size=%u\nts=0x%llx\npid=%d\nelf_mach=%d\n",
+		pr_debug("version=%u\nhdr.size=%u\nts=0x%llx\npid=%d\nelf_mach=%d\nuse_arch_timestamp=%d\n",
 			header.version,
 			header.total_size,
 			(unsigned long long)header.timestamp,
 			header.pid,
-			header.elf_mach);
+			header.elf_mach,
+			jd->use_arch_timestamp);
 
 	if (header.flags & JITDUMP_FLAGS_RESERVED) {
 		pr_err("jitdump file contains invalid or unsupported flags 0x%llx\n",
@@ -172,10 +177,15 @@ jit_open(struct jit_buf_desc *jd, const char *name)
 		goto error;
 	}
 
+	if (jd->use_arch_timestamp && !jd->session->time_conv.time_mult) {
+		pr_err("jitdump file uses arch timestamps but there is no timestamp conversion\n");
+		goto error;
+	}
+
 	/*
 	 * validate event is using the correct clockid
 	 */
-	if (jit_validate_events(jd->session)) {
+	if (!jd->use_arch_timestamp && jit_validate_events(jd->session)) {
 		pr_err("error, jitted code must be sampled with perf record -k 1\n");
 		goto error;
 	}
@@ -329,6 +339,23 @@ jit_inject_event(struct jit_buf_desc *jd, union perf_event *event)
 	return 0;
 }
 
+static uint64_t convert_timestamp(struct jit_buf_desc *jd, uint64_t timestamp)
+{
+	struct perf_tsc_conversion tc;
+
+	if (!jd->use_arch_timestamp)
+		return timestamp;
+
+	tc.time_shift = jd->session->time_conv.time_shift;
+	tc.time_mult  = jd->session->time_conv.time_mult;
+	tc.time_zero  = jd->session->time_conv.time_zero;
+
+	if (!tc.time_mult)
+		return 0;
+
+	return tsc_to_perf_time(timestamp, &tc);
+}
+
 static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
 {
 	struct perf_sample sample;
@@ -410,7 +437,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
 		id->tid  = tid;
 	}
 	if (jd->sample_type & PERF_SAMPLE_TIME)
-		id->time = jr->load.p.timestamp;
+		id->time = convert_timestamp(jd, jr->load.p.timestamp);
 
 	/*
 	 * create pseudo sample to induce dso hit increment
@@ -498,7 +525,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
 		id->tid  = tid;
 	}
 	if (jd->sample_type & PERF_SAMPLE_TIME)
-		id->time = jr->load.p.timestamp;
+		id->time = convert_timestamp(jd, jr->load.p.timestamp);
 
 	/*
 	 * create pseudo sample to induce dso hit increment
diff --git a/tools/perf/util/jitdump.h b/tools/perf/util/jitdump.h
index b66c1f503d9e..bcacd20d0c1c 100644
--- a/tools/perf/util/jitdump.h
+++ b/tools/perf/util/jitdump.h
@@ -23,9 +23,12 @@
 #define JITHEADER_VERSION 1
 
 enum jitdump_flags_bits {
+	JITDUMP_FLAGS_ARCH_TIMESTAMP_BIT,
 	JITDUMP_FLAGS_MAX_BIT,
 };
 
+#define JITDUMP_FLAGS_ARCH_TIMESTAMP	(1ULL << JITDUMP_FLAGS_ARCH_TIMESTAMP_BIT)
+
 #define JITDUMP_FLAGS_RESERVED (JITDUMP_FLAGS_MAX_BIT < 64 ? \
 				(~((1ULL << JITDUMP_FLAGS_MAX_BIT) - 1)) : 0)
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 7/8] perf intel-pt/bts: Define JITDUMP_USE_ARCH_TIMESTAMP
  2016-03-03 11:50 [PATCH 0/8] perf tools: Add Intel PT support for jitdump Adrian Hunter
                   ` (5 preceding siblings ...)
  2016-03-03 11:50 ` [PATCH 6/8] perf jit: Add support for using TSC as a timestamp Adrian Hunter
@ 2016-03-03 11:50 ` Adrian Hunter
  2016-03-08  8:38   ` [PATCH V2 " Adrian Hunter
  2016-03-03 11:50 ` [PATCH 8/8] perf tools: Use 64-bit shifts with (TSC) time conversion Adrian Hunter
  2016-03-08  8:49 ` [PATCH 0/8] perf tools: Add Intel PT support for jitdump Adrian Hunter
  8 siblings, 1 reply; 31+ messages in thread
From: Adrian Hunter @ 2016-03-03 11:50 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Stephane Eranian

From: Adrian Hunter <ajhunter@gmail.com>

For Intel PT / BTS, define the environment variable that selects
TSC timestamps in the jitdump file.

Signed-off-by: Adrian Hunter <ajhunter@gmail.com>
---
 tools/perf/arch/x86/util/intel-bts.c | 5 +++++
 tools/perf/arch/x86/util/intel-pt.c  | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c
index d66f9ad4df2e..7dc30637cf66 100644
--- a/tools/perf/arch/x86/util/intel-bts.c
+++ b/tools/perf/arch/x86/util/intel-bts.c
@@ -438,6 +438,11 @@ struct auxtrace_record *intel_bts_recording_init(int *err)
 	if (!intel_bts_pmu)
 		return NULL;
 
+	if (setenv("JITDUMP_USE_ARCH_TIMESTAMP", "1", 1)) {
+		*err = -errno;
+		return NULL;
+	}
+
 	btsr = zalloc(sizeof(struct intel_bts_recording));
 	if (!btsr) {
 		*err = -ENOMEM;
diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index a3395179c9ee..a07b9605e93b 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -1027,6 +1027,11 @@ struct auxtrace_record *intel_pt_recording_init(int *err)
 	if (!intel_pt_pmu)
 		return NULL;
 
+	if (setenv("JITDUMP_USE_ARCH_TIMESTAMP", "1", 1)) {
+		*err = -errno;
+		return NULL;
+	}
+
 	ptr = zalloc(sizeof(struct intel_pt_recording));
 	if (!ptr) {
 		*err = -ENOMEM;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 8/8] perf tools: Use 64-bit shifts with (TSC) time conversion
  2016-03-03 11:50 [PATCH 0/8] perf tools: Add Intel PT support for jitdump Adrian Hunter
                   ` (6 preceding siblings ...)
  2016-03-03 11:50 ` [PATCH 7/8] perf intel-pt/bts: Define JITDUMP_USE_ARCH_TIMESTAMP Adrian Hunter
@ 2016-03-03 11:50 ` Adrian Hunter
  2016-03-08 10:31   ` [tip:perf/core] " tip-bot for Adrian Hunter
  2016-03-08  8:49 ` [PATCH 0/8] perf tools: Add Intel PT support for jitdump Adrian Hunter
  8 siblings, 1 reply; 31+ messages in thread
From: Adrian Hunter @ 2016-03-03 11:50 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Stephane Eranian

Commit b9511cd761fa ("perf/x86: Fix time_shift in perf_event_mmap_page")
altered the time conversion algorithms documented in the perf_event.h
header file, to use 64-bit shifts.  That was done to make the code more
future-proof (i.e. some time in the future a 32-bit shift could be
allowed).  Reflect those changes in perf tools.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/arch/x86/tests/rdpmc.c | 2 +-
 tools/perf/util/tsc.c             | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/arch/x86/tests/rdpmc.c b/tools/perf/arch/x86/tests/rdpmc.c
index 7945462851a4..72193f19d6d7 100644
--- a/tools/perf/arch/x86/tests/rdpmc.c
+++ b/tools/perf/arch/x86/tests/rdpmc.c
@@ -59,7 +59,7 @@ static u64 mmap_read_self(void *addr)
 		u64 quot, rem;
 
 		quot = (cyc >> time_shift);
-		rem = cyc & ((1 << time_shift) - 1);
+		rem = cyc & (((u64)1 << time_shift) - 1);
 		delta = time_offset + quot * time_mult +
 			((rem * time_mult) >> time_shift);
 
diff --git a/tools/perf/util/tsc.c b/tools/perf/util/tsc.c
index 4d4210d4e13d..1b741646eed0 100644
--- a/tools/perf/util/tsc.c
+++ b/tools/perf/util/tsc.c
@@ -19,7 +19,7 @@ u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc)
 	u64 quot, rem;
 
 	quot = cyc >> tc->time_shift;
-	rem  = cyc & ((1 << tc->time_shift) - 1);
+	rem  = cyc & (((u64)1 << tc->time_shift) - 1);
 	return tc->time_zero + quot * tc->time_mult +
 	       ((rem * tc->time_mult) >> tc->time_shift);
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH V2 2/8] perf session: Simplify tool stubs
  2016-03-03 11:50 ` [PATCH 2/8] perf session: Simplify tool stubs Adrian Hunter
@ 2016-03-08  8:38   ` Adrian Hunter
  2016-03-08 10:30   ` [tip:perf/core] " tip-bot for Adrian Hunter
  1 sibling, 0 replies; 31+ messages in thread
From: Adrian Hunter @ 2016-03-08  8:38 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Stephane Eranian

Some of the stubs are identical so just have one function
for them.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---

Changes in V2:

	Fixed "From" and "Signed-off-by" email addresses

 tools/perf/util/session.c | 40 +++++++---------------------------------
 1 file changed, 7 insertions(+), 33 deletions(-)

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 40b7a0d0905b..60b3593d210d 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -240,14 +240,6 @@ static int process_event_stub(struct perf_tool *tool __maybe_unused,
 	return 0;
 }
 
-static int process_build_id_stub(struct perf_tool *tool __maybe_unused,
-				 union perf_event *event __maybe_unused,
-				 struct perf_session *session __maybe_unused)
-{
-	dump_printf(": unhandled!\n");
-	return 0;
-}
-
 static int process_finished_round_stub(struct perf_tool *tool __maybe_unused,
 				       union perf_event *event __maybe_unused,
 				       struct ordered_events *oe __maybe_unused)
@@ -260,23 +252,6 @@ static int process_finished_round(struct perf_tool *tool,
 				  union perf_event *event,
 				  struct ordered_events *oe);
 
-static int process_id_index_stub(struct perf_tool *tool __maybe_unused,
-				 union perf_event *event __maybe_unused,
-				 struct perf_session *perf_session
-				 __maybe_unused)
-{
-	dump_printf(": unhandled!\n");
-	return 0;
-}
-
-static int process_event_auxtrace_info_stub(struct perf_tool *tool __maybe_unused,
-				union perf_event *event __maybe_unused,
-				struct perf_session *session __maybe_unused)
-{
-	dump_printf(": unhandled!\n");
-	return 0;
-}
-
 static int skipn(int fd, off_t n)
 {
 	char buf[4096];
@@ -303,10 +278,9 @@ static s64 process_event_auxtrace_stub(struct perf_tool *tool __maybe_unused,
 	return event->auxtrace.size;
 }
 
-static
-int process_event_auxtrace_error_stub(struct perf_tool *tool __maybe_unused,
-				      union perf_event *event __maybe_unused,
-				      struct perf_session *session __maybe_unused)
+static int process_event_op2_stub(struct perf_tool *tool __maybe_unused,
+				  union perf_event *event __maybe_unused,
+				  struct perf_session *session __maybe_unused)
 {
 	dump_printf(": unhandled!\n");
 	return 0;
@@ -410,7 +384,7 @@ void perf_tool__fill_defaults(struct perf_tool *tool)
 	if (tool->tracing_data == NULL)
 		tool->tracing_data = process_event_synth_tracing_data_stub;
 	if (tool->build_id == NULL)
-		tool->build_id = process_build_id_stub;
+		tool->build_id = process_event_op2_stub;
 	if (tool->finished_round == NULL) {
 		if (tool->ordered_events)
 			tool->finished_round = process_finished_round;
@@ -418,13 +392,13 @@ void perf_tool__fill_defaults(struct perf_tool *tool)
 			tool->finished_round = process_finished_round_stub;
 	}
 	if (tool->id_index == NULL)
-		tool->id_index = process_id_index_stub;
+		tool->id_index = process_event_op2_stub;
 	if (tool->auxtrace_info == NULL)
-		tool->auxtrace_info = process_event_auxtrace_info_stub;
+		tool->auxtrace_info = process_event_op2_stub;
 	if (tool->auxtrace == NULL)
 		tool->auxtrace = process_event_auxtrace_stub;
 	if (tool->auxtrace_error == NULL)
-		tool->auxtrace_error = process_event_auxtrace_error_stub;
+		tool->auxtrace_error = process_event_op2_stub;
 	if (tool->thread_map == NULL)
 		tool->thread_map = process_event_thread_map_stub;
 	if (tool->cpu_map == NULL)
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH V2 3/8] perf tools: Add time conversion event
  2016-03-03 11:50 ` [PATCH 3/8] perf tools: Add time conversion event Adrian Hunter
@ 2016-03-08  8:38   ` Adrian Hunter
  2016-03-31  6:33     ` Adrian Hunter
  2016-04-06  7:07     ` [tip:perf/core] " tip-bot for Adrian Hunter
  0 siblings, 2 replies; 31+ messages in thread
From: Adrian Hunter @ 2016-03-08  8:38 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Stephane Eranian

Intel PT uses the time members from the perf_event_mmap_page
to convert between TSC and perf time.

Due to a lack of foresight when Intel PT was implemented,
those time members were recorded in the (implementation
dependent) AUXTRACE_INFO event, the structure of which is
generally inaccessible outside of the Intel PT decoder.
However now the conversion between TSC and perf time is needed
when processing a jitdump file when Intel PT has been used for
tracing.

So add a user event to record the time members.  'perf record'
will synthesize the event if the information is available.
And session processing will put a copy of the event on the
session so that tools like 'perf inject' can easily access it.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---

Changes in V2:

	Fixed "From" and "Signed-off-by" email addresses

 tools/perf/arch/x86/util/tsc.c | 31 +++++++++++++++++++++++++++++++
 tools/perf/builtin-inject.c    |  1 +
 tools/perf/builtin-record.c    | 15 +++++++++++++++
 tools/perf/util/event.c        |  1 +
 tools/perf/util/event.h        |  9 +++++++++
 tools/perf/util/session.c      |  6 ++++++
 tools/perf/util/session.h      |  1 +
 tools/perf/util/tool.h         |  1 +
 tools/perf/util/tsc.h          | 10 ++++++++++
 9 files changed, 75 insertions(+)

diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c
index fd2868490d00..70ff7c14bea6 100644
--- a/tools/perf/arch/x86/util/tsc.c
+++ b/tools/perf/arch/x86/util/tsc.c
@@ -46,3 +46,34 @@ u64 rdtsc(void)
 
 	return low | ((u64)high) << 32;
 }
+
+int perf_event__synth_time_conv(const struct perf_event_mmap_page *pc,
+				struct perf_tool *tool,
+				perf_event__handler_t process,
+				struct machine *machine)
+{
+	union perf_event event = {
+		.time_conv = {
+			.header = {
+				.type = PERF_RECORD_TIME_CONV,
+				.size = sizeof(struct time_conv_event),
+			},
+		},
+	};
+	struct perf_tsc_conversion tc;
+	int err;
+
+	err = perf_read_tsc_conversion(pc, &tc);
+	if (err == -EOPNOTSUPP)
+		return 0;
+	if (err)
+		return err;
+
+	pr_debug2("Synthesizing TSC conversion information\n");
+
+	event.time_conv.time_mult  = tc.time_mult;
+	event.time_conv.time_shift = tc.time_shift;
+	event.time_conv.time_zero  = tc.time_zero;
+
+	return process(tool, &event, NULL, machine);
+}
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index c6a4f2f94ab1..29dfe68b2fb1 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -761,6 +761,7 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
 			.auxtrace_info	= perf_event__repipe_op2_synth,
 			.auxtrace	= perf_event__repipe_auxtrace,
 			.auxtrace_error	= perf_event__repipe_op2_synth,
+			.time_conv	= perf_event__repipe_op2_synth,
 			.finished_round	= perf_event__repipe_oe_synth,
 			.build_id	= perf_event__repipe_op2_synth,
 			.id_index	= perf_event__repipe_op2_synth,
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 515510ecc76a..410035c6e300 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -29,6 +29,7 @@
 #include "util/data.h"
 #include "util/perf_regs.h"
 #include "util/auxtrace.h"
+#include "util/tsc.h"
 #include "util/parse-branch-options.h"
 #include "util/parse-regs-options.h"
 #include "util/llvm-utils.h"
@@ -512,6 +513,15 @@ static void workload_exec_failed_signal(int signo __maybe_unused,
 
 static void snapshot_sig_handler(int sig);
 
+int __weak
+perf_event__synth_time_conv(const struct perf_event_mmap_page *pc __maybe_unused,
+			    struct perf_tool *tool __maybe_unused,
+			    perf_event__handler_t process __maybe_unused,
+			    struct machine *machine __maybe_unused)
+{
+	return 0;
+}
+
 static int record__synthesize(struct record *rec)
 {
 	struct perf_session *session = rec->session;
@@ -549,6 +559,11 @@ static int record__synthesize(struct record *rec)
 		}
 	}
 
+	err = perf_event__synth_time_conv(rec->evlist->mmap[0].base, tool,
+					  process_synthesized_event, machine);
+	if (err)
+		goto out;
+
 	if (rec->opts.full_auxtrace) {
 		err = perf_event__synthesize_auxtrace_info(rec->itr, tool,
 					session, process_synthesized_event);
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 7bad5c3fa7b7..025509129cda 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -45,6 +45,7 @@ static const char *perf_event__names[] = {
 	[PERF_RECORD_STAT]			= "STAT",
 	[PERF_RECORD_STAT_ROUND]		= "STAT_ROUND",
 	[PERF_RECORD_EVENT_UPDATE]		= "EVENT_UPDATE",
+	[PERF_RECORD_TIME_CONV]			= "TIME_CONV",
 };
 
 const char *perf_event__name(unsigned int id)
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index b7ffb7ee9971..f1dafa05e8bf 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -232,6 +232,7 @@ enum perf_user_event_type { /* above any possible kernel type */
 	PERF_RECORD_STAT			= 76,
 	PERF_RECORD_STAT_ROUND			= 77,
 	PERF_RECORD_EVENT_UPDATE		= 78,
+	PERF_RECORD_TIME_CONV			= 79,
 	PERF_RECORD_HEADER_MAX
 };
 
@@ -468,6 +469,13 @@ struct stat_round_event {
 	u64				time;
 };
 
+struct time_conv_event {
+	struct perf_event_header header;
+	u64 time_shift;
+	u64 time_mult;
+	u64 time_zero;
+};
+
 union perf_event {
 	struct perf_event_header	header;
 	struct mmap_event		mmap;
@@ -496,6 +504,7 @@ union perf_event {
 	struct stat_config_event	stat_config;
 	struct stat_event		stat;
 	struct stat_round_event		stat_round;
+	struct time_conv_event		time_conv;
 };
 
 void perf_event__print_totals(void);
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 60b3593d210d..ee1778a9c0c7 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -409,6 +409,8 @@ void perf_tool__fill_defaults(struct perf_tool *tool)
 		tool->stat = process_stat_stub;
 	if (tool->stat_round == NULL)
 		tool->stat_round = process_stat_round_stub;
+	if (tool->time_conv == NULL)
+		tool->time_conv = process_event_op2_stub;
 }
 
 static void swap_sample_id_all(union perf_event *event, void *data)
@@ -794,6 +796,7 @@ static perf_event__swap_op perf_event__swap_ops[] = {
 	[PERF_RECORD_STAT]		  = perf_event__stat_swap,
 	[PERF_RECORD_STAT_ROUND]	  = perf_event__stat_round_swap,
 	[PERF_RECORD_EVENT_UPDATE]	  = perf_event__event_update_swap,
+	[PERF_RECORD_TIME_CONV]		  = perf_event__all64_swap,
 	[PERF_RECORD_HEADER_MAX]	  = NULL,
 };
 
@@ -1342,6 +1345,9 @@ static s64 perf_session__process_user_event(struct perf_session *session,
 		return tool->stat(tool, event, session);
 	case PERF_RECORD_STAT_ROUND:
 		return tool->stat_round(tool, event, session);
+	case PERF_RECORD_TIME_CONV:
+		session->time_conv = event->time_conv;
+		return tool->time_conv(tool, event, session);
 	default:
 		return -EINVAL;
 	}
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 5f792e35d4c1..f96fc9e8c52e 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -26,6 +26,7 @@ struct perf_session {
 	struct itrace_synth_opts *itrace_synth_opts;
 	struct list_head	auxtrace_index;
 	struct trace_event	tevent;
+	struct time_conv_event	time_conv;
 	bool			repipe;
 	bool			one_mmap;
 	void			*one_mmap_addr;
diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h
index 55de4cffcd4e..ac2590a3de2d 100644
--- a/tools/perf/util/tool.h
+++ b/tools/perf/util/tool.h
@@ -57,6 +57,7 @@ struct perf_tool {
 			id_index,
 			auxtrace_info,
 			auxtrace_error,
+			time_conv,
 			thread_map,
 			cpu_map,
 			stat_config,
diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h
index a8b78f1b3243..280ddc067556 100644
--- a/tools/perf/util/tsc.h
+++ b/tools/perf/util/tsc.h
@@ -3,10 +3,20 @@
 
 #include <linux/types.h>
 
+#include "event.h"
 #include "../arch/x86/util/tsc.h"
 
 u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc);
 u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc);
 u64 rdtsc(void);
 
+struct perf_event_mmap_page;
+struct perf_tool;
+struct machine;
+
+int perf_event__synth_time_conv(const struct perf_event_mmap_page *pc,
+				struct perf_tool *tool,
+				perf_event__handler_t process,
+				struct machine *machine);
+
 #endif
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH V2 5/8] perf jit: Move clockid validation
  2016-03-03 11:50 ` [PATCH 5/8] perf jit: Move clockid validation Adrian Hunter
@ 2016-03-08  8:38   ` Adrian Hunter
  2016-03-08 10:31   ` [tip:perf/core] " tip-bot for Adrian Hunter
  1 sibling, 0 replies; 31+ messages in thread
From: Adrian Hunter @ 2016-03-08  8:38 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Stephane Eranian

Move clockid validation into jit_process() so it can later be
made conditional.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---

Changes in V2:

	Fixed "From" and "Signed-off-by" email addresses

 tools/perf/builtin-inject.c | 24 ------------------------
 tools/perf/util/jitdump.c   | 23 +++++++++++++++++++++++
 2 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index 1635533921e8..319b7b4f7743 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -729,23 +729,6 @@ static int __cmd_inject(struct perf_inject *inject)
 	return ret;
 }
 
-#ifdef HAVE_LIBELF_SUPPORT
-static int
-jit_validate_events(struct perf_session *session)
-{
-	struct perf_evsel *evsel;
-
-	/*
-	 * check that all events use CLOCK_MONOTONIC
-	 */
-	evlist__for_each(session->evlist, evsel) {
-		if (evsel->attr.use_clockid == 0 || evsel->attr.clockid != CLOCK_MONOTONIC)
-			return -1;
-	}
-	return 0;
-}
-#endif
-
 int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
 {
 	struct perf_inject inject = {
@@ -853,13 +836,6 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
 	}
 #ifdef HAVE_LIBELF_SUPPORT
 	if (inject.jit_mode) {
-		/*
-		 * validate event is using the correct clockid
-		 */
-		if (jit_validate_events(inject.session)) {
-			fprintf(stderr, "error, jitted code must be sampled with perf record -k 1\n");
-			return -1;
-		}
 		inject.tool.mmap2	   = perf_event__jit_repipe_mmap2;
 		inject.tool.mmap	   = perf_event__jit_repipe_mmap;
 		inject.tool.ordered_events = true;
diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index bd9e44f9fff2..cd272cc21e05 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -99,6 +99,21 @@ jit_close(struct jit_buf_desc *jd)
 }
 
 static int
+jit_validate_events(struct perf_session *session)
+{
+	struct perf_evsel *evsel;
+
+	/*
+	 * check that all events use CLOCK_MONOTONIC
+	 */
+	evlist__for_each(session->evlist, evsel) {
+		if (evsel->attr.use_clockid == 0 || evsel->attr.clockid != CLOCK_MONOTONIC)
+			return -1;
+	}
+	return 0;
+}
+
+static int
 jit_open(struct jit_buf_desc *jd, const char *name)
 {
 	struct jitheader header;
@@ -157,6 +172,14 @@ jit_open(struct jit_buf_desc *jd, const char *name)
 		goto error;
 	}
 
+	/*
+	 * validate event is using the correct clockid
+	 */
+	if (jit_validate_events(jd->session)) {
+		pr_err("error, jitted code must be sampled with perf record -k 1\n");
+		goto error;
+	}
+
 	bs = header.total_size - sizeof(header);
 
 	if (bs > bsz) {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH V2 6/8] perf jit: Add support for using TSC as a timestamp
  2016-03-03 11:50 ` [PATCH 6/8] perf jit: Add support for using TSC as a timestamp Adrian Hunter
@ 2016-03-08  8:38   ` Adrian Hunter
  2016-04-01  3:49     ` [PATCH] perf tools: Fix build errors on tsc functions for archs other than x86 He Kuang
  0 siblings, 1 reply; 31+ messages in thread
From: Adrian Hunter @ 2016-03-08  8:38 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Stephane Eranian

Intel PT uses TSC as a timestamp, so add support for using TSC
instead of the monotonic clock.  Use of TSC is selected by
an environment variable "JITDUMP_USE_ARCH_TIMESTAMP" and flagged
in the jitdump file with flag JITDUMP_FLAGS_ARCH_TIMESTAMP.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---

Changes in V2:

	Fixed "From" and "Signed-off-by" email addresses

 tools/perf/jvmti/jvmti_agent.c | 43 ++++++++++++++++++++++++++++++++++++++++--
 tools/perf/util/jitdump.c      | 37 +++++++++++++++++++++++++++++++-----
 tools/perf/util/jitdump.h      |  3 +++
 3 files changed, 76 insertions(+), 7 deletions(-)

diff --git a/tools/perf/jvmti/jvmti_agent.c b/tools/perf/jvmti/jvmti_agent.c
index 6461e02ab940..3573f315f955 100644
--- a/tools/perf/jvmti/jvmti_agent.c
+++ b/tools/perf/jvmti/jvmti_agent.c
@@ -92,6 +92,22 @@ error:
 	return ret;
 }
 
+static int use_arch_timestamp;
+
+static inline uint64_t
+get_arch_timestamp(void)
+{
+#if defined(__i386__) || defined(__x86_64__)
+	unsigned int low, high;
+
+	asm volatile("rdtsc" : "=a" (low), "=d" (high));
+
+	return low | ((uint64_t)high) << 32;
+#else
+	return 0;
+#endif
+}
+
 #define NSEC_PER_SEC	1000000000
 static int perf_clk_id = CLOCK_MONOTONIC;
 
@@ -107,6 +123,9 @@ perf_get_timestamp(void)
 	struct timespec ts;
 	int ret;
 
+	if (use_arch_timestamp)
+		return get_arch_timestamp();
+
 	ret = clock_gettime(perf_clk_id, &ts);
 	if (ret)
 		return 0;
@@ -203,6 +222,17 @@ perf_close_marker_file(void)
 	munmap(marker_addr, pgsz);
 }
 
+static void
+init_arch_timestamp(void)
+{
+	char *str = getenv("JITDUMP_USE_ARCH_TIMESTAMP");
+
+	if (!str || !*str || !strcmp(str, "0"))
+		return;
+
+	use_arch_timestamp = 1;
+}
+
 void *jvmti_open(void)
 {
 	int pad_cnt;
@@ -211,11 +241,17 @@ void *jvmti_open(void)
 	int fd;
 	FILE *fp;
 
+	init_arch_timestamp();
+
 	/*
 	 * check if clockid is supported
 	 */
-	if (!perf_get_timestamp())
-		warnx("jvmti: kernel does not support %d clock id", perf_clk_id);
+	if (!perf_get_timestamp()) {
+		if (use_arch_timestamp)
+			warnx("jvmti: arch timestamp not supported");
+		else
+			warnx("jvmti: kernel does not support %d clock id", perf_clk_id);
+	}
 
 	memset(&header, 0, sizeof(header));
 
@@ -263,6 +299,9 @@ void *jvmti_open(void)
 
 	header.timestamp = perf_get_timestamp();
 
+	if (use_arch_timestamp)
+		header.flags |= JITDUMP_FLAGS_ARCH_TIMESTAMP;
+
 	if (!fwrite(&header, sizeof(header), 1, fp)) {
 		warn("jvmti: cannot write dumpfile header");
 		goto error;
diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index cd272cc21e05..5608179dff34 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -17,6 +17,7 @@
 #include "strlist.h"
 #include <elf.h>
 
+#include "tsc.h"
 #include "session.h"
 #include "jit.h"
 #include "jitdump.h"
@@ -33,6 +34,7 @@ struct jit_buf_desc {
 	size_t           bufsize;
 	FILE             *in;
 	bool		 needs_bswap; /* handles cross-endianess */
+	bool		 use_arch_timestamp;
 	void		 *debug_data;
 	size_t		 nr_debug_entries;
 	uint32_t         code_load_count;
@@ -158,13 +160,16 @@ jit_open(struct jit_buf_desc *jd, const char *name)
 		header.flags      = bswap_64(header.flags);
 	}
 
+	jd->use_arch_timestamp = header.flags & JITDUMP_FLAGS_ARCH_TIMESTAMP;
+
 	if (verbose > 2)
-		pr_debug("version=%u\nhdr.size=%u\nts=0x%llx\npid=%d\nelf_mach=%d\n",
+		pr_debug("version=%u\nhdr.size=%u\nts=0x%llx\npid=%d\nelf_mach=%d\nuse_arch_timestamp=%d\n",
 			header.version,
 			header.total_size,
 			(unsigned long long)header.timestamp,
 			header.pid,
-			header.elf_mach);
+			header.elf_mach,
+			jd->use_arch_timestamp);
 
 	if (header.flags & JITDUMP_FLAGS_RESERVED) {
 		pr_err("jitdump file contains invalid or unsupported flags 0x%llx\n",
@@ -172,10 +177,15 @@ jit_open(struct jit_buf_desc *jd, const char *name)
 		goto error;
 	}
 
+	if (jd->use_arch_timestamp && !jd->session->time_conv.time_mult) {
+		pr_err("jitdump file uses arch timestamps but there is no timestamp conversion\n");
+		goto error;
+	}
+
 	/*
 	 * validate event is using the correct clockid
 	 */
-	if (jit_validate_events(jd->session)) {
+	if (!jd->use_arch_timestamp && jit_validate_events(jd->session)) {
 		pr_err("error, jitted code must be sampled with perf record -k 1\n");
 		goto error;
 	}
@@ -329,6 +339,23 @@ jit_inject_event(struct jit_buf_desc *jd, union perf_event *event)
 	return 0;
 }
 
+static uint64_t convert_timestamp(struct jit_buf_desc *jd, uint64_t timestamp)
+{
+	struct perf_tsc_conversion tc;
+
+	if (!jd->use_arch_timestamp)
+		return timestamp;
+
+	tc.time_shift = jd->session->time_conv.time_shift;
+	tc.time_mult  = jd->session->time_conv.time_mult;
+	tc.time_zero  = jd->session->time_conv.time_zero;
+
+	if (!tc.time_mult)
+		return 0;
+
+	return tsc_to_perf_time(timestamp, &tc);
+}
+
 static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
 {
 	struct perf_sample sample;
@@ -410,7 +437,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
 		id->tid  = tid;
 	}
 	if (jd->sample_type & PERF_SAMPLE_TIME)
-		id->time = jr->load.p.timestamp;
+		id->time = convert_timestamp(jd, jr->load.p.timestamp);
 
 	/*
 	 * create pseudo sample to induce dso hit increment
@@ -498,7 +525,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
 		id->tid  = tid;
 	}
 	if (jd->sample_type & PERF_SAMPLE_TIME)
-		id->time = jr->load.p.timestamp;
+		id->time = convert_timestamp(jd, jr->load.p.timestamp);
 
 	/*
 	 * create pseudo sample to induce dso hit increment
diff --git a/tools/perf/util/jitdump.h b/tools/perf/util/jitdump.h
index b66c1f503d9e..bcacd20d0c1c 100644
--- a/tools/perf/util/jitdump.h
+++ b/tools/perf/util/jitdump.h
@@ -23,9 +23,12 @@
 #define JITHEADER_VERSION 1
 
 enum jitdump_flags_bits {
+	JITDUMP_FLAGS_ARCH_TIMESTAMP_BIT,
 	JITDUMP_FLAGS_MAX_BIT,
 };
 
+#define JITDUMP_FLAGS_ARCH_TIMESTAMP	(1ULL << JITDUMP_FLAGS_ARCH_TIMESTAMP_BIT)
+
 #define JITDUMP_FLAGS_RESERVED (JITDUMP_FLAGS_MAX_BIT < 64 ? \
 				(~((1ULL << JITDUMP_FLAGS_MAX_BIT) - 1)) : 0)
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH V2 7/8] perf intel-pt/bts: Define JITDUMP_USE_ARCH_TIMESTAMP
  2016-03-03 11:50 ` [PATCH 7/8] perf intel-pt/bts: Define JITDUMP_USE_ARCH_TIMESTAMP Adrian Hunter
@ 2016-03-08  8:38   ` Adrian Hunter
  2016-04-06  7:08     ` [tip:perf/core] " tip-bot for Adrian Hunter
  0 siblings, 1 reply; 31+ messages in thread
From: Adrian Hunter @ 2016-03-08  8:38 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Stephane Eranian

For Intel PT / BTS, define the environment variable that selects
TSC timestamps in the jitdump file.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---

Changes in V2:

	Fixed "From" and "Signed-off-by" email addresses

 tools/perf/arch/x86/util/intel-bts.c | 5 +++++
 tools/perf/arch/x86/util/intel-pt.c  | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c
index d66f9ad4df2e..7dc30637cf66 100644
--- a/tools/perf/arch/x86/util/intel-bts.c
+++ b/tools/perf/arch/x86/util/intel-bts.c
@@ -438,6 +438,11 @@ struct auxtrace_record *intel_bts_recording_init(int *err)
 	if (!intel_bts_pmu)
 		return NULL;
 
+	if (setenv("JITDUMP_USE_ARCH_TIMESTAMP", "1", 1)) {
+		*err = -errno;
+		return NULL;
+	}
+
 	btsr = zalloc(sizeof(struct intel_bts_recording));
 	if (!btsr) {
 		*err = -ENOMEM;
diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index a3395179c9ee..a07b9605e93b 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -1027,6 +1027,11 @@ struct auxtrace_record *intel_pt_recording_init(int *err)
 	if (!intel_pt_pmu)
 		return NULL;
 
+	if (setenv("JITDUMP_USE_ARCH_TIMESTAMP", "1", 1)) {
+		*err = -errno;
+		return NULL;
+	}
+
 	ptr = zalloc(sizeof(struct intel_pt_recording));
 	if (!ptr) {
 		*err = -ENOMEM;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* Re: [PATCH 0/8] perf tools: Add Intel PT support for jitdump
  2016-03-03 11:50 [PATCH 0/8] perf tools: Add Intel PT support for jitdump Adrian Hunter
                   ` (7 preceding siblings ...)
  2016-03-03 11:50 ` [PATCH 8/8] perf tools: Use 64-bit shifts with (TSC) time conversion Adrian Hunter
@ 2016-03-08  8:49 ` Adrian Hunter
  8 siblings, 0 replies; 31+ messages in thread
From: Adrian Hunter @ 2016-03-08  8:49 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Stephane Eranian

Hi

I have just sent V2 of patches 2, 3, 5, 6, 7 because the email address was
wrong in the "From" and "Signed-off-by".

I realize you have already processed some of the patches.  Very sorry for
the inconvenience.

Regards
Adrian

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [tip:perf/core] perf inject: Hit all DSOs for AUX data in JIT and other cases
  2016-03-03 11:50 ` [PATCH 1/8] perf inject: Hit all DSOs for AUX data in JIT and other cases Adrian Hunter
@ 2016-03-08 10:30   ` tip-bot for Adrian Hunter
  0 siblings, 0 replies; 31+ messages in thread
From: tip-bot for Adrian Hunter @ 2016-03-08 10:30 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, tglx, linux-kernel, eranian, jolsa, dsahern, adrian.hunter,
	alexander.shishkin, hpa, peterz, mingo, namhyung

Commit-ID:  640dad47988ec4b734d71934be103bb6e931279f
Gitweb:     http://git.kernel.org/tip/640dad47988ec4b734d71934be103bb6e931279f
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Mon, 7 Mar 2016 16:44:38 -0300
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 8 Mar 2016 10:11:16 +0100

perf inject: Hit all DSOs for AUX data in JIT and other cases

Currently, when injecting build ids, if there is AUX data then 'perf
inject' hits all DSOs because it is not known which DSOs the trace data
would hit.

That needs to be done for JIT injection also, and in fact there is no
reason to distinguish what kind of injection is being done.  That is,
any time there is AUX data and the HEADER_BUID_ID feature flag is set,
and the AUX data is not being processed, then hit all DSOs.  This patch
does that.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1457005856-6143-2-git-send-email-adrian.hunter@intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 tools/perf/builtin-inject.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index b38445f..c6a4f2f 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -679,12 +679,16 @@ static int __cmd_inject(struct perf_inject *inject)
 	ret = perf_session__process_events(session);
 
 	if (!file_out->is_pipe) {
-		if (inject->build_ids) {
+		if (inject->build_ids)
 			perf_header__set_feat(&session->header,
 					      HEADER_BUILD_ID);
-			if (inject->have_auxtrace)
-				dsos__hit_all(session);
-		}
+		/*
+		 * Keep all buildids when there is unprocessed AUX data because
+		 * it is not known which ones the AUX trace hits.
+		 */
+		if (perf_header__has_feat(&session->header, HEADER_BUILD_ID) &&
+		    inject->have_auxtrace && !inject->itrace_synth_opts.set)
+			dsos__hit_all(session);
 		/*
 		 * The AUX areas have been removed and replaced with
 		 * synthesized hardware events, so clear the feature flag and

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [tip:perf/core] perf session: Simplify tool stubs
  2016-03-03 11:50 ` [PATCH 2/8] perf session: Simplify tool stubs Adrian Hunter
  2016-03-08  8:38   ` [PATCH V2 " Adrian Hunter
@ 2016-03-08 10:30   ` tip-bot for Adrian Hunter
  1 sibling, 0 replies; 31+ messages in thread
From: tip-bot for Adrian Hunter @ 2016-03-08 10:30 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, peterz, eranian, dsahern, tglx, adrian.hunter, hpa,
	namhyung, alexander.shishkin, jolsa, mingo, linux-kernel

Commit-ID:  5fb0ac16c5091f48eecf1a77e461f6957a463d61
Gitweb:     http://git.kernel.org/tip/5fb0ac16c5091f48eecf1a77e461f6957a463d61
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Mon, 7 Mar 2016 16:44:39 -0300
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 8 Mar 2016 10:11:17 +0100

perf session: Simplify tool stubs

Some of the stubs are identical so just have one function for them.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1457005856-6143-3-git-send-email-adrian.hunter@intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 tools/perf/util/session.c | 40 +++++++---------------------------------
 1 file changed, 7 insertions(+), 33 deletions(-)

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 40b7a0d..60b3593 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -240,14 +240,6 @@ static int process_event_stub(struct perf_tool *tool __maybe_unused,
 	return 0;
 }
 
-static int process_build_id_stub(struct perf_tool *tool __maybe_unused,
-				 union perf_event *event __maybe_unused,
-				 struct perf_session *session __maybe_unused)
-{
-	dump_printf(": unhandled!\n");
-	return 0;
-}
-
 static int process_finished_round_stub(struct perf_tool *tool __maybe_unused,
 				       union perf_event *event __maybe_unused,
 				       struct ordered_events *oe __maybe_unused)
@@ -260,23 +252,6 @@ static int process_finished_round(struct perf_tool *tool,
 				  union perf_event *event,
 				  struct ordered_events *oe);
 
-static int process_id_index_stub(struct perf_tool *tool __maybe_unused,
-				 union perf_event *event __maybe_unused,
-				 struct perf_session *perf_session
-				 __maybe_unused)
-{
-	dump_printf(": unhandled!\n");
-	return 0;
-}
-
-static int process_event_auxtrace_info_stub(struct perf_tool *tool __maybe_unused,
-				union perf_event *event __maybe_unused,
-				struct perf_session *session __maybe_unused)
-{
-	dump_printf(": unhandled!\n");
-	return 0;
-}
-
 static int skipn(int fd, off_t n)
 {
 	char buf[4096];
@@ -303,10 +278,9 @@ static s64 process_event_auxtrace_stub(struct perf_tool *tool __maybe_unused,
 	return event->auxtrace.size;
 }
 
-static
-int process_event_auxtrace_error_stub(struct perf_tool *tool __maybe_unused,
-				      union perf_event *event __maybe_unused,
-				      struct perf_session *session __maybe_unused)
+static int process_event_op2_stub(struct perf_tool *tool __maybe_unused,
+				  union perf_event *event __maybe_unused,
+				  struct perf_session *session __maybe_unused)
 {
 	dump_printf(": unhandled!\n");
 	return 0;
@@ -410,7 +384,7 @@ void perf_tool__fill_defaults(struct perf_tool *tool)
 	if (tool->tracing_data == NULL)
 		tool->tracing_data = process_event_synth_tracing_data_stub;
 	if (tool->build_id == NULL)
-		tool->build_id = process_build_id_stub;
+		tool->build_id = process_event_op2_stub;
 	if (tool->finished_round == NULL) {
 		if (tool->ordered_events)
 			tool->finished_round = process_finished_round;
@@ -418,13 +392,13 @@ void perf_tool__fill_defaults(struct perf_tool *tool)
 			tool->finished_round = process_finished_round_stub;
 	}
 	if (tool->id_index == NULL)
-		tool->id_index = process_id_index_stub;
+		tool->id_index = process_event_op2_stub;
 	if (tool->auxtrace_info == NULL)
-		tool->auxtrace_info = process_event_auxtrace_info_stub;
+		tool->auxtrace_info = process_event_op2_stub;
 	if (tool->auxtrace == NULL)
 		tool->auxtrace = process_event_auxtrace_stub;
 	if (tool->auxtrace_error == NULL)
-		tool->auxtrace_error = process_event_auxtrace_error_stub;
+		tool->auxtrace_error = process_event_op2_stub;
 	if (tool->thread_map == NULL)
 		tool->thread_map = process_event_thread_map_stub;
 	if (tool->cpu_map == NULL)

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [tip:perf/core] perf jit: Let jit_process() return errors
  2016-03-03 11:50 ` [PATCH 4/8] perf jit: Let jit_process() return errors Adrian Hunter
@ 2016-03-08 10:30   ` tip-bot for Adrian Hunter
  0 siblings, 0 replies; 31+ messages in thread
From: tip-bot for Adrian Hunter @ 2016-03-08 10:30 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: peterz, namhyung, tglx, alexander.shishkin, adrian.hunter, jolsa,
	eranian, mingo, hpa, dsahern, acme, linux-kernel

Commit-ID:  570735b33d122bcb259ef67c6aa63e5609af5752
Gitweb:     http://git.kernel.org/tip/570735b33d122bcb259ef67c6aa63e5609af5752
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Mon, 7 Mar 2016 16:44:40 -0300
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 8 Mar 2016 10:11:17 +0100

perf jit: Let jit_process() return errors

In preparation for moving clockid validation into jit_process().

Previously a return value of zero meant the processing had been done and
non-zero meant either the processing was not done (i.e. not the jitdump
file mmap event) or an error occurred.

Change it so that zero means the processing was not done, one means the
processing was done and successful, and negative values are an error.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1457005856-6143-5-git-send-email-adrian.hunter@intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 tools/perf/builtin-inject.c | 16 ++++++++++++----
 tools/perf/util/jitdump.c   |  6 ++++--
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index c6a4f2f..2512d71 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -253,12 +253,16 @@ static int perf_event__jit_repipe_mmap(struct perf_tool *tool,
 {
 	struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
 	u64 n = 0;
+	int ret;
 
 	/*
 	 * if jit marker, then inject jit mmaps and generate ELF images
 	 */
-	if (!jit_process(inject->session, &inject->output, machine,
-			 event->mmap.filename, sample->pid, &n)) {
+	ret = jit_process(inject->session, &inject->output, machine,
+			  event->mmap.filename, sample->pid, &n);
+	if (ret < 0)
+		return ret;
+	if (ret) {
 		inject->bytes_written += n;
 		return 0;
 	}
@@ -287,12 +291,16 @@ static int perf_event__jit_repipe_mmap2(struct perf_tool *tool,
 {
 	struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
 	u64 n = 0;
+	int ret;
 
 	/*
 	 * if jit marker, then inject jit mmaps and generate ELF images
 	 */
-	if (!jit_process(inject->session, &inject->output, machine,
-			  event->mmap2.filename, sample->pid, &n)) {
+	ret = jit_process(inject->session, &inject->output, machine,
+			  event->mmap2.filename, sample->pid, &n);
+	if (ret < 0)
+		return ret;
+	if (ret) {
 		inject->bytes_written += n;
 		return 0;
 	}
diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index 99fa5ee..bd9e44f 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -647,7 +647,7 @@ jit_process(struct perf_session *session,
 	 * first, detect marker mmap (i.e., the jitdump mmap)
 	 */
 	if (jit_detect(filename, pid))
-		return -1;
+		return 0;
 
 	memset(&jd, 0, sizeof(jd));
 
@@ -665,8 +665,10 @@ jit_process(struct perf_session *session,
 	*nbytes = 0;
 
 	ret = jit_inject(&jd, filename);
-	if (!ret)
+	if (!ret) {
 		*nbytes = jd.bytes_written;
+		ret = 1;
+	}
 
 	return ret;
 }

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [tip:perf/core] perf jit: Move clockid validation
  2016-03-03 11:50 ` [PATCH 5/8] perf jit: Move clockid validation Adrian Hunter
  2016-03-08  8:38   ` [PATCH V2 " Adrian Hunter
@ 2016-03-08 10:31   ` tip-bot for Adrian Hunter
  1 sibling, 0 replies; 31+ messages in thread
From: tip-bot for Adrian Hunter @ 2016-03-08 10:31 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: adrian.hunter, acme, alexander.shishkin, eranian, namhyung,
	mingo, hpa, linux-kernel, jolsa, dsahern, peterz, tglx

Commit-ID:  4a018cc47932ef1e68a0600ce3ac100df70fab2a
Gitweb:     http://git.kernel.org/tip/4a018cc47932ef1e68a0600ce3ac100df70fab2a
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Mon, 7 Mar 2016 16:44:41 -0300
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 8 Mar 2016 10:11:17 +0100

perf jit: Move clockid validation

Move clockid validation into jit_process() so it can later be made
conditional.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1457005856-6143-6-git-send-email-adrian.hunter@intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 tools/perf/builtin-inject.c | 24 ------------------------
 tools/perf/util/jitdump.c   | 23 +++++++++++++++++++++++
 2 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index 2512d71..b288577 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -729,23 +729,6 @@ static int __cmd_inject(struct perf_inject *inject)
 	return ret;
 }
 
-#ifdef HAVE_LIBELF_SUPPORT
-static int
-jit_validate_events(struct perf_session *session)
-{
-	struct perf_evsel *evsel;
-
-	/*
-	 * check that all events use CLOCK_MONOTONIC
-	 */
-	evlist__for_each(session->evlist, evsel) {
-		if (evsel->attr.use_clockid == 0 || evsel->attr.clockid != CLOCK_MONOTONIC)
-			return -1;
-	}
-	return 0;
-}
-#endif
-
 int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
 {
 	struct perf_inject inject = {
@@ -852,13 +835,6 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
 	}
 #ifdef HAVE_LIBELF_SUPPORT
 	if (inject.jit_mode) {
-		/*
-		 * validate event is using the correct clockid
-		 */
-		if (jit_validate_events(inject.session)) {
-			fprintf(stderr, "error, jitted code must be sampled with perf record -k 1\n");
-			return -1;
-		}
 		inject.tool.mmap2	   = perf_event__jit_repipe_mmap2;
 		inject.tool.mmap	   = perf_event__jit_repipe_mmap;
 		inject.tool.ordered_events = true;
diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index bd9e44f..cd272cc 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -99,6 +99,21 @@ jit_close(struct jit_buf_desc *jd)
 }
 
 static int
+jit_validate_events(struct perf_session *session)
+{
+	struct perf_evsel *evsel;
+
+	/*
+	 * check that all events use CLOCK_MONOTONIC
+	 */
+	evlist__for_each(session->evlist, evsel) {
+		if (evsel->attr.use_clockid == 0 || evsel->attr.clockid != CLOCK_MONOTONIC)
+			return -1;
+	}
+	return 0;
+}
+
+static int
 jit_open(struct jit_buf_desc *jd, const char *name)
 {
 	struct jitheader header;
@@ -157,6 +172,14 @@ jit_open(struct jit_buf_desc *jd, const char *name)
 		goto error;
 	}
 
+	/*
+	 * validate event is using the correct clockid
+	 */
+	if (jit_validate_events(jd->session)) {
+		pr_err("error, jitted code must be sampled with perf record -k 1\n");
+		goto error;
+	}
+
 	bs = header.total_size - sizeof(header);
 
 	if (bs > bsz) {

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [tip:perf/core] perf tools: Use 64-bit shifts with (TSC) time conversion
  2016-03-03 11:50 ` [PATCH 8/8] perf tools: Use 64-bit shifts with (TSC) time conversion Adrian Hunter
@ 2016-03-08 10:31   ` tip-bot for Adrian Hunter
  0 siblings, 0 replies; 31+ messages in thread
From: tip-bot for Adrian Hunter @ 2016-03-08 10:31 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: eranian, jolsa, hpa, acme, linux-kernel, namhyung,
	alexander.shishkin, adrian.hunter, peterz, dsahern, tglx, mingo

Commit-ID:  a23f96ee4d51ebd50b83ce0dbb5d04898fb8e3cb
Gitweb:     http://git.kernel.org/tip/a23f96ee4d51ebd50b83ce0dbb5d04898fb8e3cb
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Mon, 7 Mar 2016 16:44:42 -0300
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 8 Mar 2016 10:11:18 +0100

perf tools: Use 64-bit shifts with (TSC) time conversion

Commit b9511cd761fa ("perf/x86: Fix time_shift in perf_event_mmap_page")
altered the time conversion algorithms documented in the perf_event.h
header file, to use 64-bit shifts.  That was done to make the code more
future-proof (i.e. some time in the future a 32-bit shift could be
allowed).  Reflect those changes in perf tools.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1457005856-6143-9-git-send-email-adrian.hunter@intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 tools/perf/arch/x86/tests/rdpmc.c | 2 +-
 tools/perf/util/tsc.c             | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/arch/x86/tests/rdpmc.c b/tools/perf/arch/x86/tests/rdpmc.c
index 7945462..72193f1 100644
--- a/tools/perf/arch/x86/tests/rdpmc.c
+++ b/tools/perf/arch/x86/tests/rdpmc.c
@@ -59,7 +59,7 @@ static u64 mmap_read_self(void *addr)
 		u64 quot, rem;
 
 		quot = (cyc >> time_shift);
-		rem = cyc & ((1 << time_shift) - 1);
+		rem = cyc & (((u64)1 << time_shift) - 1);
 		delta = time_offset + quot * time_mult +
 			((rem * time_mult) >> time_shift);
 
diff --git a/tools/perf/util/tsc.c b/tools/perf/util/tsc.c
index 4d4210d..1b74164 100644
--- a/tools/perf/util/tsc.c
+++ b/tools/perf/util/tsc.c
@@ -19,7 +19,7 @@ u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc)
 	u64 quot, rem;
 
 	quot = cyc >> tc->time_shift;
-	rem  = cyc & ((1 << tc->time_shift) - 1);
+	rem  = cyc & (((u64)1 << tc->time_shift) - 1);
 	return tc->time_zero + quot * tc->time_mult +
 	       ((rem * tc->time_mult) >> tc->time_shift);
 }

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* Re: [PATCH V2 3/8] perf tools: Add time conversion event
  2016-03-08  8:38   ` [PATCH V2 " Adrian Hunter
@ 2016-03-31  6:33     ` Adrian Hunter
  2016-03-31 13:53       ` Arnaldo Carvalho de Melo
  2016-04-06  7:07     ` [tip:perf/core] " tip-bot for Adrian Hunter
  1 sibling, 1 reply; 31+ messages in thread
From: Adrian Hunter @ 2016-03-31  6:33 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Stephane Eranian

On 08/03/16 10:38, Adrian Hunter wrote:
> Intel PT uses the time members from the perf_event_mmap_page
> to convert between TSC and perf time.
> 
> Due to a lack of foresight when Intel PT was implemented,
> those time members were recorded in the (implementation
> dependent) AUXTRACE_INFO event, the structure of which is
> generally inaccessible outside of the Intel PT decoder.
> However now the conversion between TSC and perf time is needed
> when processing a jitdump file when Intel PT has been used for
> tracing.
> 
> So add a user event to record the time members.  'perf record'
> will synthesize the event if the information is available.
> And session processing will put a copy of the event on the
> session so that tools like 'perf inject' can easily access it.
> 
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>

This patch (patch 3) and the V2 versions of patches 6 and 7 i.e.

[PATCH V2 3/8] perf tools: Add time conversion event
[PATCH V2 6/8] perf jit: Add support for using TSC as a timestamp
[PATCH V2 7/8] perf intel-pt/bts: Define JITDUMP_USE_ARCH_TIMESTAMP

still apply.  Do you have any comments?

> ---
> 
> Changes in V2:
> 
> 	Fixed "From" and "Signed-off-by" email addresses
> 
>  tools/perf/arch/x86/util/tsc.c | 31 +++++++++++++++++++++++++++++++
>  tools/perf/builtin-inject.c    |  1 +
>  tools/perf/builtin-record.c    | 15 +++++++++++++++
>  tools/perf/util/event.c        |  1 +
>  tools/perf/util/event.h        |  9 +++++++++
>  tools/perf/util/session.c      |  6 ++++++
>  tools/perf/util/session.h      |  1 +
>  tools/perf/util/tool.h         |  1 +
>  tools/perf/util/tsc.h          | 10 ++++++++++
>  9 files changed, 75 insertions(+)
> 
> diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c
> index fd2868490d00..70ff7c14bea6 100644
> --- a/tools/perf/arch/x86/util/tsc.c
> +++ b/tools/perf/arch/x86/util/tsc.c
> @@ -46,3 +46,34 @@ u64 rdtsc(void)
>  
>  	return low | ((u64)high) << 32;
>  }
> +
> +int perf_event__synth_time_conv(const struct perf_event_mmap_page *pc,
> +				struct perf_tool *tool,
> +				perf_event__handler_t process,
> +				struct machine *machine)
> +{
> +	union perf_event event = {
> +		.time_conv = {
> +			.header = {
> +				.type = PERF_RECORD_TIME_CONV,
> +				.size = sizeof(struct time_conv_event),
> +			},
> +		},
> +	};
> +	struct perf_tsc_conversion tc;
> +	int err;
> +
> +	err = perf_read_tsc_conversion(pc, &tc);
> +	if (err == -EOPNOTSUPP)
> +		return 0;
> +	if (err)
> +		return err;
> +
> +	pr_debug2("Synthesizing TSC conversion information\n");
> +
> +	event.time_conv.time_mult  = tc.time_mult;
> +	event.time_conv.time_shift = tc.time_shift;
> +	event.time_conv.time_zero  = tc.time_zero;
> +
> +	return process(tool, &event, NULL, machine);
> +}
> diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
> index c6a4f2f94ab1..29dfe68b2fb1 100644
> --- a/tools/perf/builtin-inject.c
> +++ b/tools/perf/builtin-inject.c
> @@ -761,6 +761,7 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
>  			.auxtrace_info	= perf_event__repipe_op2_synth,
>  			.auxtrace	= perf_event__repipe_auxtrace,
>  			.auxtrace_error	= perf_event__repipe_op2_synth,
> +			.time_conv	= perf_event__repipe_op2_synth,
>  			.finished_round	= perf_event__repipe_oe_synth,
>  			.build_id	= perf_event__repipe_op2_synth,
>  			.id_index	= perf_event__repipe_op2_synth,
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index 515510ecc76a..410035c6e300 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -29,6 +29,7 @@
>  #include "util/data.h"
>  #include "util/perf_regs.h"
>  #include "util/auxtrace.h"
> +#include "util/tsc.h"
>  #include "util/parse-branch-options.h"
>  #include "util/parse-regs-options.h"
>  #include "util/llvm-utils.h"
> @@ -512,6 +513,15 @@ static void workload_exec_failed_signal(int signo __maybe_unused,
>  
>  static void snapshot_sig_handler(int sig);
>  
> +int __weak
> +perf_event__synth_time_conv(const struct perf_event_mmap_page *pc __maybe_unused,
> +			    struct perf_tool *tool __maybe_unused,
> +			    perf_event__handler_t process __maybe_unused,
> +			    struct machine *machine __maybe_unused)
> +{
> +	return 0;
> +}
> +
>  static int record__synthesize(struct record *rec)
>  {
>  	struct perf_session *session = rec->session;
> @@ -549,6 +559,11 @@ static int record__synthesize(struct record *rec)
>  		}
>  	}
>  
> +	err = perf_event__synth_time_conv(rec->evlist->mmap[0].base, tool,
> +					  process_synthesized_event, machine);
> +	if (err)
> +		goto out;
> +
>  	if (rec->opts.full_auxtrace) {
>  		err = perf_event__synthesize_auxtrace_info(rec->itr, tool,
>  					session, process_synthesized_event);
> diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
> index 7bad5c3fa7b7..025509129cda 100644
> --- a/tools/perf/util/event.c
> +++ b/tools/perf/util/event.c
> @@ -45,6 +45,7 @@ static const char *perf_event__names[] = {
>  	[PERF_RECORD_STAT]			= "STAT",
>  	[PERF_RECORD_STAT_ROUND]		= "STAT_ROUND",
>  	[PERF_RECORD_EVENT_UPDATE]		= "EVENT_UPDATE",
> +	[PERF_RECORD_TIME_CONV]			= "TIME_CONV",
>  };
>  
>  const char *perf_event__name(unsigned int id)
> diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
> index b7ffb7ee9971..f1dafa05e8bf 100644
> --- a/tools/perf/util/event.h
> +++ b/tools/perf/util/event.h
> @@ -232,6 +232,7 @@ enum perf_user_event_type { /* above any possible kernel type */
>  	PERF_RECORD_STAT			= 76,
>  	PERF_RECORD_STAT_ROUND			= 77,
>  	PERF_RECORD_EVENT_UPDATE		= 78,
> +	PERF_RECORD_TIME_CONV			= 79,
>  	PERF_RECORD_HEADER_MAX
>  };
>  
> @@ -468,6 +469,13 @@ struct stat_round_event {
>  	u64				time;
>  };
>  
> +struct time_conv_event {
> +	struct perf_event_header header;
> +	u64 time_shift;
> +	u64 time_mult;
> +	u64 time_zero;
> +};
> +
>  union perf_event {
>  	struct perf_event_header	header;
>  	struct mmap_event		mmap;
> @@ -496,6 +504,7 @@ union perf_event {
>  	struct stat_config_event	stat_config;
>  	struct stat_event		stat;
>  	struct stat_round_event		stat_round;
> +	struct time_conv_event		time_conv;
>  };
>  
>  void perf_event__print_totals(void);
> diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
> index 60b3593d210d..ee1778a9c0c7 100644
> --- a/tools/perf/util/session.c
> +++ b/tools/perf/util/session.c
> @@ -409,6 +409,8 @@ void perf_tool__fill_defaults(struct perf_tool *tool)
>  		tool->stat = process_stat_stub;
>  	if (tool->stat_round == NULL)
>  		tool->stat_round = process_stat_round_stub;
> +	if (tool->time_conv == NULL)
> +		tool->time_conv = process_event_op2_stub;
>  }
>  
>  static void swap_sample_id_all(union perf_event *event, void *data)
> @@ -794,6 +796,7 @@ static perf_event__swap_op perf_event__swap_ops[] = {
>  	[PERF_RECORD_STAT]		  = perf_event__stat_swap,
>  	[PERF_RECORD_STAT_ROUND]	  = perf_event__stat_round_swap,
>  	[PERF_RECORD_EVENT_UPDATE]	  = perf_event__event_update_swap,
> +	[PERF_RECORD_TIME_CONV]		  = perf_event__all64_swap,
>  	[PERF_RECORD_HEADER_MAX]	  = NULL,
>  };
>  
> @@ -1342,6 +1345,9 @@ static s64 perf_session__process_user_event(struct perf_session *session,
>  		return tool->stat(tool, event, session);
>  	case PERF_RECORD_STAT_ROUND:
>  		return tool->stat_round(tool, event, session);
> +	case PERF_RECORD_TIME_CONV:
> +		session->time_conv = event->time_conv;
> +		return tool->time_conv(tool, event, session);
>  	default:
>  		return -EINVAL;
>  	}
> diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
> index 5f792e35d4c1..f96fc9e8c52e 100644
> --- a/tools/perf/util/session.h
> +++ b/tools/perf/util/session.h
> @@ -26,6 +26,7 @@ struct perf_session {
>  	struct itrace_synth_opts *itrace_synth_opts;
>  	struct list_head	auxtrace_index;
>  	struct trace_event	tevent;
> +	struct time_conv_event	time_conv;
>  	bool			repipe;
>  	bool			one_mmap;
>  	void			*one_mmap_addr;
> diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h
> index 55de4cffcd4e..ac2590a3de2d 100644
> --- a/tools/perf/util/tool.h
> +++ b/tools/perf/util/tool.h
> @@ -57,6 +57,7 @@ struct perf_tool {
>  			id_index,
>  			auxtrace_info,
>  			auxtrace_error,
> +			time_conv,
>  			thread_map,
>  			cpu_map,
>  			stat_config,
> diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h
> index a8b78f1b3243..280ddc067556 100644
> --- a/tools/perf/util/tsc.h
> +++ b/tools/perf/util/tsc.h
> @@ -3,10 +3,20 @@
>  
>  #include <linux/types.h>
>  
> +#include "event.h"
>  #include "../arch/x86/util/tsc.h"
>  
>  u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc);
>  u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc);
>  u64 rdtsc(void);
>  
> +struct perf_event_mmap_page;
> +struct perf_tool;
> +struct machine;
> +
> +int perf_event__synth_time_conv(const struct perf_event_mmap_page *pc,
> +				struct perf_tool *tool,
> +				perf_event__handler_t process,
> +				struct machine *machine);
> +
>  #endif
> 

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH V2 3/8] perf tools: Add time conversion event
  2016-03-31  6:33     ` Adrian Hunter
@ 2016-03-31 13:53       ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 31+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-03-31 13:53 UTC (permalink / raw)
  To: Adrian Hunter; +Cc: Jiri Olsa, linux-kernel, Stephane Eranian

Em Thu, Mar 31, 2016 at 09:33:04AM +0300, Adrian Hunter escreveu:
> On 08/03/16 10:38, Adrian Hunter wrote:
> > Intel PT uses the time members from the perf_event_mmap_page
> > to convert between TSC and perf time.
> > 
> > Due to a lack of foresight when Intel PT was implemented,
> > those time members were recorded in the (implementation
> > dependent) AUXTRACE_INFO event, the structure of which is
> > generally inaccessible outside of the Intel PT decoder.
> > However now the conversion between TSC and perf time is needed
> > when processing a jitdump file when Intel PT has been used for
> > tracing.
> > 
> > So add a user event to record the time members.  'perf record'
> > will synthesize the event if the information is available.
> > And session processing will put a copy of the event on the
> > session so that tools like 'perf inject' can easily access it.
> > 
> > Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> 
> This patch (patch 3) and the V2 versions of patches 6 and 7 i.e.
> 
> [PATCH V2 3/8] perf tools: Add time conversion event
> [PATCH V2 6/8] perf jit: Add support for using TSC as a timestamp
> [PATCH V2 7/8] perf intel-pt/bts: Define JITDUMP_USE_ARCH_TIMESTAMP
> 
> still apply.  Do you have any comments?

I was waiting for Stephane to say something, but judging from the fact
that this is just making existing infrastructure to be available more
widely, I am applying it.

- Arnaldo
 
> > ---
> > 
> > Changes in V2:
> > 
> > 	Fixed "From" and "Signed-off-by" email addresses
> > 
> >  tools/perf/arch/x86/util/tsc.c | 31 +++++++++++++++++++++++++++++++
> >  tools/perf/builtin-inject.c    |  1 +
> >  tools/perf/builtin-record.c    | 15 +++++++++++++++
> >  tools/perf/util/event.c        |  1 +
> >  tools/perf/util/event.h        |  9 +++++++++
> >  tools/perf/util/session.c      |  6 ++++++
> >  tools/perf/util/session.h      |  1 +
> >  tools/perf/util/tool.h         |  1 +
> >  tools/perf/util/tsc.h          | 10 ++++++++++
> >  9 files changed, 75 insertions(+)
> > 
> > diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c
> > index fd2868490d00..70ff7c14bea6 100644
> > --- a/tools/perf/arch/x86/util/tsc.c
> > +++ b/tools/perf/arch/x86/util/tsc.c
> > @@ -46,3 +46,34 @@ u64 rdtsc(void)
> >  
> >  	return low | ((u64)high) << 32;
> >  }
> > +
> > +int perf_event__synth_time_conv(const struct perf_event_mmap_page *pc,
> > +				struct perf_tool *tool,
> > +				perf_event__handler_t process,
> > +				struct machine *machine)
> > +{
> > +	union perf_event event = {
> > +		.time_conv = {
> > +			.header = {
> > +				.type = PERF_RECORD_TIME_CONV,
> > +				.size = sizeof(struct time_conv_event),
> > +			},
> > +		},
> > +	};
> > +	struct perf_tsc_conversion tc;
> > +	int err;
> > +
> > +	err = perf_read_tsc_conversion(pc, &tc);
> > +	if (err == -EOPNOTSUPP)
> > +		return 0;
> > +	if (err)
> > +		return err;
> > +
> > +	pr_debug2("Synthesizing TSC conversion information\n");
> > +
> > +	event.time_conv.time_mult  = tc.time_mult;
> > +	event.time_conv.time_shift = tc.time_shift;
> > +	event.time_conv.time_zero  = tc.time_zero;
> > +
> > +	return process(tool, &event, NULL, machine);
> > +}
> > diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
> > index c6a4f2f94ab1..29dfe68b2fb1 100644
> > --- a/tools/perf/builtin-inject.c
> > +++ b/tools/perf/builtin-inject.c
> > @@ -761,6 +761,7 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
> >  			.auxtrace_info	= perf_event__repipe_op2_synth,
> >  			.auxtrace	= perf_event__repipe_auxtrace,
> >  			.auxtrace_error	= perf_event__repipe_op2_synth,
> > +			.time_conv	= perf_event__repipe_op2_synth,
> >  			.finished_round	= perf_event__repipe_oe_synth,
> >  			.build_id	= perf_event__repipe_op2_synth,
> >  			.id_index	= perf_event__repipe_op2_synth,
> > diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> > index 515510ecc76a..410035c6e300 100644
> > --- a/tools/perf/builtin-record.c
> > +++ b/tools/perf/builtin-record.c
> > @@ -29,6 +29,7 @@
> >  #include "util/data.h"
> >  #include "util/perf_regs.h"
> >  #include "util/auxtrace.h"
> > +#include "util/tsc.h"
> >  #include "util/parse-branch-options.h"
> >  #include "util/parse-regs-options.h"
> >  #include "util/llvm-utils.h"
> > @@ -512,6 +513,15 @@ static void workload_exec_failed_signal(int signo __maybe_unused,
> >  
> >  static void snapshot_sig_handler(int sig);
> >  
> > +int __weak
> > +perf_event__synth_time_conv(const struct perf_event_mmap_page *pc __maybe_unused,
> > +			    struct perf_tool *tool __maybe_unused,
> > +			    perf_event__handler_t process __maybe_unused,
> > +			    struct machine *machine __maybe_unused)
> > +{
> > +	return 0;
> > +}
> > +
> >  static int record__synthesize(struct record *rec)
> >  {
> >  	struct perf_session *session = rec->session;
> > @@ -549,6 +559,11 @@ static int record__synthesize(struct record *rec)
> >  		}
> >  	}
> >  
> > +	err = perf_event__synth_time_conv(rec->evlist->mmap[0].base, tool,
> > +					  process_synthesized_event, machine);
> > +	if (err)
> > +		goto out;
> > +
> >  	if (rec->opts.full_auxtrace) {
> >  		err = perf_event__synthesize_auxtrace_info(rec->itr, tool,
> >  					session, process_synthesized_event);
> > diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
> > index 7bad5c3fa7b7..025509129cda 100644
> > --- a/tools/perf/util/event.c
> > +++ b/tools/perf/util/event.c
> > @@ -45,6 +45,7 @@ static const char *perf_event__names[] = {
> >  	[PERF_RECORD_STAT]			= "STAT",
> >  	[PERF_RECORD_STAT_ROUND]		= "STAT_ROUND",
> >  	[PERF_RECORD_EVENT_UPDATE]		= "EVENT_UPDATE",
> > +	[PERF_RECORD_TIME_CONV]			= "TIME_CONV",
> >  };
> >  
> >  const char *perf_event__name(unsigned int id)
> > diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
> > index b7ffb7ee9971..f1dafa05e8bf 100644
> > --- a/tools/perf/util/event.h
> > +++ b/tools/perf/util/event.h
> > @@ -232,6 +232,7 @@ enum perf_user_event_type { /* above any possible kernel type */
> >  	PERF_RECORD_STAT			= 76,
> >  	PERF_RECORD_STAT_ROUND			= 77,
> >  	PERF_RECORD_EVENT_UPDATE		= 78,
> > +	PERF_RECORD_TIME_CONV			= 79,
> >  	PERF_RECORD_HEADER_MAX
> >  };
> >  
> > @@ -468,6 +469,13 @@ struct stat_round_event {
> >  	u64				time;
> >  };
> >  
> > +struct time_conv_event {
> > +	struct perf_event_header header;
> > +	u64 time_shift;
> > +	u64 time_mult;
> > +	u64 time_zero;
> > +};
> > +
> >  union perf_event {
> >  	struct perf_event_header	header;
> >  	struct mmap_event		mmap;
> > @@ -496,6 +504,7 @@ union perf_event {
> >  	struct stat_config_event	stat_config;
> >  	struct stat_event		stat;
> >  	struct stat_round_event		stat_round;
> > +	struct time_conv_event		time_conv;
> >  };
> >  
> >  void perf_event__print_totals(void);
> > diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
> > index 60b3593d210d..ee1778a9c0c7 100644
> > --- a/tools/perf/util/session.c
> > +++ b/tools/perf/util/session.c
> > @@ -409,6 +409,8 @@ void perf_tool__fill_defaults(struct perf_tool *tool)
> >  		tool->stat = process_stat_stub;
> >  	if (tool->stat_round == NULL)
> >  		tool->stat_round = process_stat_round_stub;
> > +	if (tool->time_conv == NULL)
> > +		tool->time_conv = process_event_op2_stub;
> >  }
> >  
> >  static void swap_sample_id_all(union perf_event *event, void *data)
> > @@ -794,6 +796,7 @@ static perf_event__swap_op perf_event__swap_ops[] = {
> >  	[PERF_RECORD_STAT]		  = perf_event__stat_swap,
> >  	[PERF_RECORD_STAT_ROUND]	  = perf_event__stat_round_swap,
> >  	[PERF_RECORD_EVENT_UPDATE]	  = perf_event__event_update_swap,
> > +	[PERF_RECORD_TIME_CONV]		  = perf_event__all64_swap,
> >  	[PERF_RECORD_HEADER_MAX]	  = NULL,
> >  };
> >  
> > @@ -1342,6 +1345,9 @@ static s64 perf_session__process_user_event(struct perf_session *session,
> >  		return tool->stat(tool, event, session);
> >  	case PERF_RECORD_STAT_ROUND:
> >  		return tool->stat_round(tool, event, session);
> > +	case PERF_RECORD_TIME_CONV:
> > +		session->time_conv = event->time_conv;
> > +		return tool->time_conv(tool, event, session);
> >  	default:
> >  		return -EINVAL;
> >  	}
> > diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
> > index 5f792e35d4c1..f96fc9e8c52e 100644
> > --- a/tools/perf/util/session.h
> > +++ b/tools/perf/util/session.h
> > @@ -26,6 +26,7 @@ struct perf_session {
> >  	struct itrace_synth_opts *itrace_synth_opts;
> >  	struct list_head	auxtrace_index;
> >  	struct trace_event	tevent;
> > +	struct time_conv_event	time_conv;
> >  	bool			repipe;
> >  	bool			one_mmap;
> >  	void			*one_mmap_addr;
> > diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h
> > index 55de4cffcd4e..ac2590a3de2d 100644
> > --- a/tools/perf/util/tool.h
> > +++ b/tools/perf/util/tool.h
> > @@ -57,6 +57,7 @@ struct perf_tool {
> >  			id_index,
> >  			auxtrace_info,
> >  			auxtrace_error,
> > +			time_conv,
> >  			thread_map,
> >  			cpu_map,
> >  			stat_config,
> > diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h
> > index a8b78f1b3243..280ddc067556 100644
> > --- a/tools/perf/util/tsc.h
> > +++ b/tools/perf/util/tsc.h
> > @@ -3,10 +3,20 @@
> >  
> >  #include <linux/types.h>
> >  
> > +#include "event.h"
> >  #include "../arch/x86/util/tsc.h"
> >  
> >  u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc);
> >  u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc);
> >  u64 rdtsc(void);
> >  
> > +struct perf_event_mmap_page;
> > +struct perf_tool;
> > +struct machine;
> > +
> > +int perf_event__synth_time_conv(const struct perf_event_mmap_page *pc,
> > +				struct perf_tool *tool,
> > +				perf_event__handler_t process,
> > +				struct machine *machine);
> > +
> >  #endif
> > 

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH] perf tools: Fix build errors on tsc functions for archs other than x86
@ 2016-04-01  3:49     ` He Kuang
  2016-04-01  7:13       ` Adrian Hunter
                         ` (2 more replies)
  0 siblings, 3 replies; 31+ messages in thread
From: He Kuang @ 2016-04-01  3:49 UTC (permalink / raw)
  To: peterz, mingo, acme, alexander.shishkin, adrian.hunter, jolsa,
	jpoimboe, sukadev, eranian, wangnan0
  Cc: hekuang, linux-kernel

Build errors on aarch64:

  libperf.a(libperf-in.o): In function `convert_timestamp':
  util/jitdump.c:356: undefined reference to `tsc_to_perf_time'
  collect2: error: ld returned 1 exit status
  Makefile.perf:347: recipe for target 'perf' failed
  make[1]: *** [perf] Error 1
  Makefile:68: recipe for target 'all' failed
  make: *** [all] Error 2

Since tsc conversion functions were moved out from arch dir, move
'tsc.h' out from x86 dir to make it possible to compile for other archs.

Signed-off-by: He Kuang <hekuang@huawei.com>
---
 tools/perf/arch/x86/util/tsc.c |  1 -
 tools/perf/arch/x86/util/tsc.h | 17 -----------------
 tools/perf/util/Build          |  3 +--
 tools/perf/util/tsc.h          | 11 ++++++++++-
 4 files changed, 11 insertions(+), 21 deletions(-)
 delete mode 100644 tools/perf/arch/x86/util/tsc.h

diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c
index 70ff7c1..357f1b1 100644
--- a/tools/perf/arch/x86/util/tsc.c
+++ b/tools/perf/arch/x86/util/tsc.c
@@ -7,7 +7,6 @@
 #include <linux/types.h>
 #include "../../util/debug.h"
 #include "../../util/tsc.h"
-#include "tsc.h"
 
 int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
 			     struct perf_tsc_conversion *tc)
diff --git a/tools/perf/arch/x86/util/tsc.h b/tools/perf/arch/x86/util/tsc.h
deleted file mode 100644
index 2edc4d3..0000000
--- a/tools/perf/arch/x86/util/tsc.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef TOOLS_PERF_ARCH_X86_UTIL_TSC_H__
-#define TOOLS_PERF_ARCH_X86_UTIL_TSC_H__
-
-#include <linux/types.h>
-
-struct perf_tsc_conversion {
-	u16 time_shift;
-	u32 time_mult;
-	u64 time_zero;
-};
-
-struct perf_event_mmap_page;
-
-int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
-			     struct perf_tsc_conversion *tc);
-
-#endif /* TOOLS_PERF_ARCH_X86_UTIL_TSC_H__ */
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index da48fd8..85ceff3 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -69,8 +69,7 @@ libperf-y += stat-shadow.o
 libperf-y += record.o
 libperf-y += srcline.o
 libperf-y += data.o
-libperf-$(CONFIG_X86) += tsc.o
-libperf-$(CONFIG_AUXTRACE) += tsc.o
+libperf-y += tsc.o
 libperf-y += cloexec.o
 libperf-y += thread-stack.o
 libperf-$(CONFIG_AUXTRACE) += auxtrace.o
diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h
index 280ddc0..d5b11e2 100644
--- a/tools/perf/util/tsc.h
+++ b/tools/perf/util/tsc.h
@@ -4,7 +4,16 @@
 #include <linux/types.h>
 
 #include "event.h"
-#include "../arch/x86/util/tsc.h"
+
+struct perf_tsc_conversion {
+	u16 time_shift;
+	u32 time_mult;
+	u64 time_zero;
+};
+struct perf_event_mmap_page;
+
+int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
+			     struct perf_tsc_conversion *tc);
 
 u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc);
 u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc);
-- 
1.8.5.2

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* Re: [PATCH] perf tools: Fix build errors on tsc functions for archs other than x86
  2016-04-01  3:49     ` [PATCH] perf tools: Fix build errors on tsc functions for archs other than x86 He Kuang
@ 2016-04-01  7:13       ` Adrian Hunter
  2016-04-01 13:13       ` Arnaldo Carvalho de Melo
  2016-04-06  7:08       ` [tip:perf/core] perf jit: Add support for using TSC as a timestamp tip-bot for Adrian Hunter
  2 siblings, 0 replies; 31+ messages in thread
From: Adrian Hunter @ 2016-04-01  7:13 UTC (permalink / raw)
  To: He Kuang, acme
  Cc: peterz, mingo, alexander.shishkin, jolsa, jpoimboe, sukadev,
	eranian, wangnan0, linux-kernel

On 01/04/16 06:49, He Kuang wrote:
> Build errors on aarch64:
> 
>   libperf.a(libperf-in.o): In function `convert_timestamp':
>   util/jitdump.c:356: undefined reference to `tsc_to_perf_time'
>   collect2: error: ld returned 1 exit status
>   Makefile.perf:347: recipe for target 'perf' failed
>   make[1]: *** [perf] Error 1
>   Makefile:68: recipe for target 'all' failed
>   make: *** [all] Error 2

Sorry about that :-(

> 
> Since tsc conversion functions were moved out from arch dir, move
> 'tsc.h' out from x86 dir to make it possible to compile for other archs.

So this is the case where data can be collected on x86 and then processed on
another arch.

Originally, it wasn't wanted to be compiled in:

	http://marc.info/?l=linux-kernel&m=142445842131011

But that has been causing problems:

	http://marc.info/?l=linux-kernel&m=144109627003194

So this seems better.

> 
> Signed-off-by: He Kuang <hekuang@huawei.com>

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  tools/perf/arch/x86/util/tsc.c |  1 -
>  tools/perf/arch/x86/util/tsc.h | 17 -----------------
>  tools/perf/util/Build          |  3 +--
>  tools/perf/util/tsc.h          | 11 ++++++++++-
>  4 files changed, 11 insertions(+), 21 deletions(-)
>  delete mode 100644 tools/perf/arch/x86/util/tsc.h
> 
> diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c
> index 70ff7c1..357f1b1 100644
> --- a/tools/perf/arch/x86/util/tsc.c
> +++ b/tools/perf/arch/x86/util/tsc.c
> @@ -7,7 +7,6 @@
>  #include <linux/types.h>
>  #include "../../util/debug.h"
>  #include "../../util/tsc.h"
> -#include "tsc.h"
>  
>  int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
>  			     struct perf_tsc_conversion *tc)
> diff --git a/tools/perf/arch/x86/util/tsc.h b/tools/perf/arch/x86/util/tsc.h
> deleted file mode 100644
> index 2edc4d3..0000000
> --- a/tools/perf/arch/x86/util/tsc.h
> +++ /dev/null
> @@ -1,17 +0,0 @@
> -#ifndef TOOLS_PERF_ARCH_X86_UTIL_TSC_H__
> -#define TOOLS_PERF_ARCH_X86_UTIL_TSC_H__
> -
> -#include <linux/types.h>
> -
> -struct perf_tsc_conversion {
> -	u16 time_shift;
> -	u32 time_mult;
> -	u64 time_zero;
> -};
> -
> -struct perf_event_mmap_page;
> -
> -int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
> -			     struct perf_tsc_conversion *tc);
> -
> -#endif /* TOOLS_PERF_ARCH_X86_UTIL_TSC_H__ */
> diff --git a/tools/perf/util/Build b/tools/perf/util/Build
> index da48fd8..85ceff3 100644
> --- a/tools/perf/util/Build
> +++ b/tools/perf/util/Build
> @@ -69,8 +69,7 @@ libperf-y += stat-shadow.o
>  libperf-y += record.o
>  libperf-y += srcline.o
>  libperf-y += data.o
> -libperf-$(CONFIG_X86) += tsc.o
> -libperf-$(CONFIG_AUXTRACE) += tsc.o
> +libperf-y += tsc.o
>  libperf-y += cloexec.o
>  libperf-y += thread-stack.o
>  libperf-$(CONFIG_AUXTRACE) += auxtrace.o
> diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h
> index 280ddc0..d5b11e2 100644
> --- a/tools/perf/util/tsc.h
> +++ b/tools/perf/util/tsc.h
> @@ -4,7 +4,16 @@
>  #include <linux/types.h>
>  
>  #include "event.h"
> -#include "../arch/x86/util/tsc.h"
> +
> +struct perf_tsc_conversion {
> +	u16 time_shift;
> +	u32 time_mult;
> +	u64 time_zero;
> +};
> +struct perf_event_mmap_page;
> +
> +int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
> +			     struct perf_tsc_conversion *tc);
>  
>  u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc);
>  u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc);
> 

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] perf tools: Fix build errors on tsc functions for archs other than x86
  2016-04-01  3:49     ` [PATCH] perf tools: Fix build errors on tsc functions for archs other than x86 He Kuang
  2016-04-01  7:13       ` Adrian Hunter
@ 2016-04-01 13:13       ` Arnaldo Carvalho de Melo
  2016-04-01 13:19         ` Hekuang
  2016-04-01 13:24         ` Arnaldo Carvalho de Melo
  2016-04-06  7:08       ` [tip:perf/core] perf jit: Add support for using TSC as a timestamp tip-bot for Adrian Hunter
  2 siblings, 2 replies; 31+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-04-01 13:13 UTC (permalink / raw)
  To: He Kuang
  Cc: peterz, mingo, alexander.shishkin, adrian.hunter, jolsa,
	jpoimboe, sukadev, eranian, wangnan0, linux-kernel

Em Fri, Apr 01, 2016 at 03:49:32AM +0000, He Kuang escreveu:
> Build errors on aarch64:
> 
>   libperf.a(libperf-in.o): In function `convert_timestamp':
>   util/jitdump.c:356: undefined reference to `tsc_to_perf_time'
>   collect2: error: ld returned 1 exit status
>   Makefile.perf:347: recipe for target 'perf' failed
>   make[1]: *** [perf] Error 1
>   Makefile:68: recipe for target 'all' failed
>   make: *** [all] Error 2

Got it, my cross-compile environment for aarch64 doesn't build jitdump.c
because it needs a package I haven't found in ubuntu:

config/Makefile:416: No libcrypto.h found, disables jitted code injection, please install libssl-devel or libssl-dev
minimal-ubuntu-x-arm64: Ok

BTW, He, what environment do you use to build for arm64, is it a cross
compile one? Yocto?

- Arnaldo


 
> Since tsc conversion functions were moved out from arch dir, move
> 'tsc.h' out from x86 dir to make it possible to compile for other archs.
> 
> Signed-off-by: He Kuang <hekuang@huawei.com>
> ---
>  tools/perf/arch/x86/util/tsc.c |  1 -
>  tools/perf/arch/x86/util/tsc.h | 17 -----------------
>  tools/perf/util/Build          |  3 +--
>  tools/perf/util/tsc.h          | 11 ++++++++++-
>  4 files changed, 11 insertions(+), 21 deletions(-)
>  delete mode 100644 tools/perf/arch/x86/util/tsc.h
> 
> diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c
> index 70ff7c1..357f1b1 100644
> --- a/tools/perf/arch/x86/util/tsc.c
> +++ b/tools/perf/arch/x86/util/tsc.c
> @@ -7,7 +7,6 @@
>  #include <linux/types.h>
>  #include "../../util/debug.h"
>  #include "../../util/tsc.h"
> -#include "tsc.h"
>  
>  int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
>  			     struct perf_tsc_conversion *tc)
> diff --git a/tools/perf/arch/x86/util/tsc.h b/tools/perf/arch/x86/util/tsc.h
> deleted file mode 100644
> index 2edc4d3..0000000
> --- a/tools/perf/arch/x86/util/tsc.h
> +++ /dev/null
> @@ -1,17 +0,0 @@
> -#ifndef TOOLS_PERF_ARCH_X86_UTIL_TSC_H__
> -#define TOOLS_PERF_ARCH_X86_UTIL_TSC_H__
> -
> -#include <linux/types.h>
> -
> -struct perf_tsc_conversion {
> -	u16 time_shift;
> -	u32 time_mult;
> -	u64 time_zero;
> -};
> -
> -struct perf_event_mmap_page;
> -
> -int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
> -			     struct perf_tsc_conversion *tc);
> -
> -#endif /* TOOLS_PERF_ARCH_X86_UTIL_TSC_H__ */
> diff --git a/tools/perf/util/Build b/tools/perf/util/Build
> index da48fd8..85ceff3 100644
> --- a/tools/perf/util/Build
> +++ b/tools/perf/util/Build
> @@ -69,8 +69,7 @@ libperf-y += stat-shadow.o
>  libperf-y += record.o
>  libperf-y += srcline.o
>  libperf-y += data.o
> -libperf-$(CONFIG_X86) += tsc.o
> -libperf-$(CONFIG_AUXTRACE) += tsc.o
> +libperf-y += tsc.o
>  libperf-y += cloexec.o
>  libperf-y += thread-stack.o
>  libperf-$(CONFIG_AUXTRACE) += auxtrace.o
> diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h
> index 280ddc0..d5b11e2 100644
> --- a/tools/perf/util/tsc.h
> +++ b/tools/perf/util/tsc.h
> @@ -4,7 +4,16 @@
>  #include <linux/types.h>
>  
>  #include "event.h"
> -#include "../arch/x86/util/tsc.h"
> +
> +struct perf_tsc_conversion {
> +	u16 time_shift;
> +	u32 time_mult;
> +	u64 time_zero;
> +};
> +struct perf_event_mmap_page;
> +
> +int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
> +			     struct perf_tsc_conversion *tc);
>  
>  u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc);
>  u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc);
> -- 
> 1.8.5.2

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] perf tools: Fix build errors on tsc functions for archs other than x86
  2016-04-01 13:13       ` Arnaldo Carvalho de Melo
@ 2016-04-01 13:19         ` Hekuang
  2016-04-01 13:24         ` Arnaldo Carvalho de Melo
  1 sibling, 0 replies; 31+ messages in thread
From: Hekuang @ 2016-04-01 13:19 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: peterz, mingo, alexander.shishkin, adrian.hunter, jolsa,
	jpoimboe, sukadev, eranian, wangnan0, linux-kernel


hi,
在 2016/4/1 21:13, Arnaldo Carvalho de Melo 写道:
> Em Fri, Apr 01, 2016 at 03:49:32AM +0000, He Kuang escreveu:
>> Build errors on aarch64:
>>
>>    libperf.a(libperf-in.o): In function `convert_timestamp':
>>    util/jitdump.c:356: undefined reference to `tsc_to_perf_time'
>>    collect2: error: ld returned 1 exit status
>>    Makefile.perf:347: recipe for target 'perf' failed
>>    make[1]: *** [perf] Error 1
>>    Makefile:68: recipe for target 'all' failed
>>    make: *** [all] Error 2
> Got it, my cross-compile environment for aarch64 doesn't build jitdump.c
> because it needs a package I haven't found in ubuntu:
>
> config/Makefile:416: No libcrypto.h found, disables jitted code injection, please install libssl-devel or libssl-dev
> minimal-ubuntu-x-arm64: Ok
>
> BTW, He, what environment do you use to build for arm64, is it a cross
> compile one? Yocto?

I use buildroot, though my colleague prefers yocto(oxygen).

In my environment, libcrypto is on.
...                     libcrypto: [ on  ]

>
> - Arnaldo
>
>
>   
>> Since tsc conversion functions were moved out from arch dir, move
>> 'tsc.h' out from x86 dir to make it possible to compile for other archs.
>>
>> Signed-off-by: He Kuang <hekuang@huawei.com>
>> ---
>>   tools/perf/arch/x86/util/tsc.c |  1 -
>>   tools/perf/arch/x86/util/tsc.h | 17 -----------------
>>   tools/perf/util/Build          |  3 +--
>>   tools/perf/util/tsc.h          | 11 ++++++++++-
>>   4 files changed, 11 insertions(+), 21 deletions(-)
>>   delete mode 100644 tools/perf/arch/x86/util/tsc.h
>>
>> diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c
>> index 70ff7c1..357f1b1 100644
>> --- a/tools/perf/arch/x86/util/tsc.c
>> +++ b/tools/perf/arch/x86/util/tsc.c
>> @@ -7,7 +7,6 @@
>>   #include <linux/types.h>
>>   #include "../../util/debug.h"
>>   #include "../../util/tsc.h"
>> -#include "tsc.h"
>>   
>>   int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
>>   			     struct perf_tsc_conversion *tc)
>> diff --git a/tools/perf/arch/x86/util/tsc.h b/tools/perf/arch/x86/util/tsc.h
>> deleted file mode 100644
>> index 2edc4d3..0000000
>> --- a/tools/perf/arch/x86/util/tsc.h
>> +++ /dev/null
>> @@ -1,17 +0,0 @@
>> -#ifndef TOOLS_PERF_ARCH_X86_UTIL_TSC_H__
>> -#define TOOLS_PERF_ARCH_X86_UTIL_TSC_H__
>> -
>> -#include <linux/types.h>
>> -
>> -struct perf_tsc_conversion {
>> -	u16 time_shift;
>> -	u32 time_mult;
>> -	u64 time_zero;
>> -};
>> -
>> -struct perf_event_mmap_page;
>> -
>> -int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
>> -			     struct perf_tsc_conversion *tc);
>> -
>> -#endif /* TOOLS_PERF_ARCH_X86_UTIL_TSC_H__ */
>> diff --git a/tools/perf/util/Build b/tools/perf/util/Build
>> index da48fd8..85ceff3 100644
>> --- a/tools/perf/util/Build
>> +++ b/tools/perf/util/Build
>> @@ -69,8 +69,7 @@ libperf-y += stat-shadow.o
>>   libperf-y += record.o
>>   libperf-y += srcline.o
>>   libperf-y += data.o
>> -libperf-$(CONFIG_X86) += tsc.o
>> -libperf-$(CONFIG_AUXTRACE) += tsc.o
>> +libperf-y += tsc.o
>>   libperf-y += cloexec.o
>>   libperf-y += thread-stack.o
>>   libperf-$(CONFIG_AUXTRACE) += auxtrace.o
>> diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h
>> index 280ddc0..d5b11e2 100644
>> --- a/tools/perf/util/tsc.h
>> +++ b/tools/perf/util/tsc.h
>> @@ -4,7 +4,16 @@
>>   #include <linux/types.h>
>>   
>>   #include "event.h"
>> -#include "../arch/x86/util/tsc.h"
>> +
>> +struct perf_tsc_conversion {
>> +	u16 time_shift;
>> +	u32 time_mult;
>> +	u64 time_zero;
>> +};
>> +struct perf_event_mmap_page;
>> +
>> +int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
>> +			     struct perf_tsc_conversion *tc);
>>   
>>   u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc);
>>   u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc);
>> -- 
>> 1.8.5.2

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] perf tools: Fix build errors on tsc functions for archs other than x86
  2016-04-01 13:13       ` Arnaldo Carvalho de Melo
  2016-04-01 13:19         ` Hekuang
@ 2016-04-01 13:24         ` Arnaldo Carvalho de Melo
  2016-04-01 13:39           ` Adrian Hunter
  1 sibling, 1 reply; 31+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-04-01 13:24 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: He Kuang, peterz, Ingo Molnar, alexander.shishkin, Jiri Olsa,
	jpoimboe, sukadev, eranian, wangnan0, linux-kernel

Em Fri, Apr 01, 2016 at 10:13:12AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Apr 01, 2016 at 03:49:32AM +0000, He Kuang escreveu:
> > Build errors on aarch64:
> > 
> >   libperf.a(libperf-in.o): In function `convert_timestamp':
> >   util/jitdump.c:356: undefined reference to `tsc_to_perf_time'
> >   collect2: error: ld returned 1 exit status
> >   Makefile.perf:347: recipe for target 'perf' failed
> >   make[1]: *** [perf] Error 1
> >   Makefile:68: recipe for target 'all' failed
> >   make: *** [all] Error 2
> 
> Got it, my cross-compile environment for aarch64 doesn't build jitdump.c
> because it needs a package I haven't found in ubuntu:
> 
> config/Makefile:416: No libcrypto.h found, disables jitted code injection, please install libssl-devel or libssl-dev
> minimal-ubuntu-x-arm64: Ok
> 
> BTW, He, what environment do you use to build for arm64, is it a cross
> compile one? Yocto?

Adrian, BTW, Ok with this? I'm adding a:

Fixes: d3e58a3b8b3b ("perf jit: Add support for using TSC as a timestamp")

And would appreciate your Acked-by.

Thanks,

- Arnaldo

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH] perf tools: Fix build errors on tsc functions for archs other than x86
  2016-04-01 13:24         ` Arnaldo Carvalho de Melo
@ 2016-04-01 13:39           ` Adrian Hunter
  0 siblings, 0 replies; 31+ messages in thread
From: Adrian Hunter @ 2016-04-01 13:39 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: He Kuang, peterz, Ingo Molnar, alexander.shishkin, Jiri Olsa,
	jpoimboe, sukadev, eranian, wangnan0, linux-kernel

On 01/04/16 16:24, Arnaldo Carvalho de Melo wrote:
> Em Fri, Apr 01, 2016 at 10:13:12AM -0300, Arnaldo Carvalho de Melo escreveu:
>> Em Fri, Apr 01, 2016 at 03:49:32AM +0000, He Kuang escreveu:
>>> Build errors on aarch64:
>>>
>>>   libperf.a(libperf-in.o): In function `convert_timestamp':
>>>   util/jitdump.c:356: undefined reference to `tsc_to_perf_time'
>>>   collect2: error: ld returned 1 exit status
>>>   Makefile.perf:347: recipe for target 'perf' failed
>>>   make[1]: *** [perf] Error 1
>>>   Makefile:68: recipe for target 'all' failed
>>>   make: *** [all] Error 2
>>
>> Got it, my cross-compile environment for aarch64 doesn't build jitdump.c
>> because it needs a package I haven't found in ubuntu:
>>
>> config/Makefile:416: No libcrypto.h found, disables jitted code injection, please install libssl-devel or libssl-dev
>> minimal-ubuntu-x-arm64: Ok
>>
>> BTW, He, what environment do you use to build for arm64, is it a cross
>> compile one? Yocto?
> 
> Adrian, BTW, Ok with this? I'm adding a:
> 
> Fixes: d3e58a3b8b3b ("perf jit: Add support for using TSC as a timestamp")
> 
> And would appreciate your Acked-by.

Sure, already did in http://marc.info/?l=linux-kernel&m=145949505329251

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [tip:perf/core] perf tools: Add time conversion event
  2016-03-08  8:38   ` [PATCH V2 " Adrian Hunter
  2016-03-31  6:33     ` Adrian Hunter
@ 2016-04-06  7:07     ` tip-bot for Adrian Hunter
  1 sibling, 0 replies; 31+ messages in thread
From: tip-bot for Adrian Hunter @ 2016-04-06  7:07 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, mingo, linux-kernel, eranian, tglx, adrian.hunter, jolsa, acme

Commit-ID:  46bc29b970f0011a9099077f1db8f3540aa829fe
Gitweb:     http://git.kernel.org/tip/46bc29b970f0011a9099077f1db8f3540aa829fe
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Tue, 8 Mar 2016 10:38:44 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 31 Mar 2016 10:52:24 -0300

perf tools: Add time conversion event

Intel PT uses the time members from the perf_event_mmap_page to convert
between TSC and perf time.

Due to a lack of foresight when Intel PT was implemented, those time
members were recorded in the (implementation dependent) AUXTRACE_INFO
event, the structure of which is generally inaccessible outside of the
Intel PT decoder.  However now the conversion between TSC and perf time
is needed when processing a jitdump file when Intel PT has been used for
tracing.

So add a user event to record the time members.  'perf record' will
synthesize the event if the information is available.  And session
processing will put a copy of the event on the session so that tools
like 'perf inject' can easily access it.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1457426324-30158-1-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/arch/x86/util/tsc.c | 31 +++++++++++++++++++++++++++++++
 tools/perf/builtin-inject.c    |  1 +
 tools/perf/builtin-record.c    | 15 +++++++++++++++
 tools/perf/util/event.c        |  1 +
 tools/perf/util/event.h        |  9 +++++++++
 tools/perf/util/session.c      |  6 ++++++
 tools/perf/util/session.h      |  1 +
 tools/perf/util/tool.h         |  1 +
 tools/perf/util/tsc.h          | 10 ++++++++++
 9 files changed, 75 insertions(+)

diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c
index fd28684..70ff7c1 100644
--- a/tools/perf/arch/x86/util/tsc.c
+++ b/tools/perf/arch/x86/util/tsc.c
@@ -46,3 +46,34 @@ u64 rdtsc(void)
 
 	return low | ((u64)high) << 32;
 }
+
+int perf_event__synth_time_conv(const struct perf_event_mmap_page *pc,
+				struct perf_tool *tool,
+				perf_event__handler_t process,
+				struct machine *machine)
+{
+	union perf_event event = {
+		.time_conv = {
+			.header = {
+				.type = PERF_RECORD_TIME_CONV,
+				.size = sizeof(struct time_conv_event),
+			},
+		},
+	};
+	struct perf_tsc_conversion tc;
+	int err;
+
+	err = perf_read_tsc_conversion(pc, &tc);
+	if (err == -EOPNOTSUPP)
+		return 0;
+	if (err)
+		return err;
+
+	pr_debug2("Synthesizing TSC conversion information\n");
+
+	event.time_conv.time_mult  = tc.time_mult;
+	event.time_conv.time_shift = tc.time_shift;
+	event.time_conv.time_zero  = tc.time_zero;
+
+	return process(tool, &event, NULL, machine);
+}
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index d1a2d10..e5afa8f 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -748,6 +748,7 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
 			.auxtrace_info	= perf_event__repipe_op2_synth,
 			.auxtrace	= perf_event__repipe_auxtrace,
 			.auxtrace_error	= perf_event__repipe_op2_synth,
+			.time_conv	= perf_event__repipe_op2_synth,
 			.finished_round	= perf_event__repipe_oe_synth,
 			.build_id	= perf_event__repipe_op2_synth,
 			.id_index	= perf_event__repipe_op2_synth,
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 515510e..410035c 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -29,6 +29,7 @@
 #include "util/data.h"
 #include "util/perf_regs.h"
 #include "util/auxtrace.h"
+#include "util/tsc.h"
 #include "util/parse-branch-options.h"
 #include "util/parse-regs-options.h"
 #include "util/llvm-utils.h"
@@ -512,6 +513,15 @@ static void workload_exec_failed_signal(int signo __maybe_unused,
 
 static void snapshot_sig_handler(int sig);
 
+int __weak
+perf_event__synth_time_conv(const struct perf_event_mmap_page *pc __maybe_unused,
+			    struct perf_tool *tool __maybe_unused,
+			    perf_event__handler_t process __maybe_unused,
+			    struct machine *machine __maybe_unused)
+{
+	return 0;
+}
+
 static int record__synthesize(struct record *rec)
 {
 	struct perf_session *session = rec->session;
@@ -549,6 +559,11 @@ static int record__synthesize(struct record *rec)
 		}
 	}
 
+	err = perf_event__synth_time_conv(rec->evlist->mmap[0].base, tool,
+					  process_synthesized_event, machine);
+	if (err)
+		goto out;
+
 	if (rec->opts.full_auxtrace) {
 		err = perf_event__synthesize_auxtrace_info(rec->itr, tool,
 					session, process_synthesized_event);
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index dad55d0..b689590 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -45,6 +45,7 @@ static const char *perf_event__names[] = {
 	[PERF_RECORD_STAT]			= "STAT",
 	[PERF_RECORD_STAT_ROUND]		= "STAT_ROUND",
 	[PERF_RECORD_EVENT_UPDATE]		= "EVENT_UPDATE",
+	[PERF_RECORD_TIME_CONV]			= "TIME_CONV",
 };
 
 const char *perf_event__name(unsigned int id)
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 6bb1c92..8d363d5 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -233,6 +233,7 @@ enum perf_user_event_type { /* above any possible kernel type */
 	PERF_RECORD_STAT			= 76,
 	PERF_RECORD_STAT_ROUND			= 77,
 	PERF_RECORD_EVENT_UPDATE		= 78,
+	PERF_RECORD_TIME_CONV			= 79,
 	PERF_RECORD_HEADER_MAX
 };
 
@@ -469,6 +470,13 @@ struct stat_round_event {
 	u64				time;
 };
 
+struct time_conv_event {
+	struct perf_event_header header;
+	u64 time_shift;
+	u64 time_mult;
+	u64 time_zero;
+};
+
 union perf_event {
 	struct perf_event_header	header;
 	struct mmap_event		mmap;
@@ -497,6 +505,7 @@ union perf_event {
 	struct stat_config_event	stat_config;
 	struct stat_event		stat;
 	struct stat_round_event		stat_round;
+	struct time_conv_event		time_conv;
 };
 
 void perf_event__print_totals(void);
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 4abd85c..ef37055 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -409,6 +409,8 @@ void perf_tool__fill_defaults(struct perf_tool *tool)
 		tool->stat = process_stat_stub;
 	if (tool->stat_round == NULL)
 		tool->stat_round = process_stat_round_stub;
+	if (tool->time_conv == NULL)
+		tool->time_conv = process_event_op2_stub;
 }
 
 static void swap_sample_id_all(union perf_event *event, void *data)
@@ -794,6 +796,7 @@ static perf_event__swap_op perf_event__swap_ops[] = {
 	[PERF_RECORD_STAT]		  = perf_event__stat_swap,
 	[PERF_RECORD_STAT_ROUND]	  = perf_event__stat_round_swap,
 	[PERF_RECORD_EVENT_UPDATE]	  = perf_event__event_update_swap,
+	[PERF_RECORD_TIME_CONV]		  = perf_event__all64_swap,
 	[PERF_RECORD_HEADER_MAX]	  = NULL,
 };
 
@@ -1341,6 +1344,9 @@ static s64 perf_session__process_user_event(struct perf_session *session,
 		return tool->stat(tool, event, session);
 	case PERF_RECORD_STAT_ROUND:
 		return tool->stat_round(tool, event, session);
+	case PERF_RECORD_TIME_CONV:
+		session->time_conv = event->time_conv;
+		return tool->time_conv(tool, event, session);
 	default:
 		return -EINVAL;
 	}
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 5f792e3..f96fc9e8c 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -26,6 +26,7 @@ struct perf_session {
 	struct itrace_synth_opts *itrace_synth_opts;
 	struct list_head	auxtrace_index;
 	struct trace_event	tevent;
+	struct time_conv_event	time_conv;
 	bool			repipe;
 	bool			one_mmap;
 	void			*one_mmap_addr;
diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h
index 55de4cf..ac2590a 100644
--- a/tools/perf/util/tool.h
+++ b/tools/perf/util/tool.h
@@ -57,6 +57,7 @@ struct perf_tool {
 			id_index,
 			auxtrace_info,
 			auxtrace_error,
+			time_conv,
 			thread_map,
 			cpu_map,
 			stat_config,
diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h
index a8b78f1..280ddc0 100644
--- a/tools/perf/util/tsc.h
+++ b/tools/perf/util/tsc.h
@@ -3,10 +3,20 @@
 
 #include <linux/types.h>
 
+#include "event.h"
 #include "../arch/x86/util/tsc.h"
 
 u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc);
 u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc);
 u64 rdtsc(void);
 
+struct perf_event_mmap_page;
+struct perf_tool;
+struct machine;
+
+int perf_event__synth_time_conv(const struct perf_event_mmap_page *pc,
+				struct perf_tool *tool,
+				perf_event__handler_t process,
+				struct machine *machine);
+
 #endif

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [tip:perf/core] perf jit: Add support for using TSC as a timestamp
  2016-04-01  3:49     ` [PATCH] perf tools: Fix build errors on tsc functions for archs other than x86 He Kuang
  2016-04-01  7:13       ` Adrian Hunter
  2016-04-01 13:13       ` Arnaldo Carvalho de Melo
@ 2016-04-06  7:08       ` tip-bot for Adrian Hunter
  2 siblings, 0 replies; 31+ messages in thread
From: tip-bot for Adrian Hunter @ 2016-04-06  7:08 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, acme, alexander.shishkin, hekuang, wangnan0, jpoimboe,
	jolsa, hpa, linux-kernel, adrian.hunter, eranian, peterz,
	sukadev, mingo

Commit-ID:  2a28e23049af99e1c810111ef5e56455cafeda45
Gitweb:     http://git.kernel.org/tip/2a28e23049af99e1c810111ef5e56455cafeda45
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Tue, 8 Mar 2016 10:38:50 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 1 Apr 2016 18:42:55 -0300

perf jit: Add support for using TSC as a timestamp

Intel PT uses TSC as a timestamp, so add support for using TSC instead
of the monotonic clock.  Use of TSC is selected by an environment
variable "JITDUMP_USE_ARCH_TIMESTAMP" and flagged in the jitdump file
with flag JITDUMP_FLAGS_ARCH_TIMESTAMP.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1457426330-30226-1-git-send-email-adrian.hunter@intel.com
[ Added the fixup from He Kuang to make it build on other arches, ]
[ such as aarch64, to avoid inserting this bisectiong breakage upstream ]
Link: http://lkml.kernel.org/r/1459482572-129494-1-git-send-email-hekuang@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/arch/x86/util/tsc.c |  1 -
 tools/perf/arch/x86/util/tsc.h | 17 -----------------
 tools/perf/jvmti/jvmti_agent.c | 43 ++++++++++++++++++++++++++++++++++++++++--
 tools/perf/util/Build          |  3 +--
 tools/perf/util/jitdump.c      | 37 +++++++++++++++++++++++++++++++-----
 tools/perf/util/jitdump.h      |  3 +++
 tools/perf/util/tsc.h          | 11 ++++++++++-
 7 files changed, 87 insertions(+), 28 deletions(-)

diff --git a/tools/perf/arch/x86/util/tsc.c b/tools/perf/arch/x86/util/tsc.c
index 70ff7c1..357f1b1 100644
--- a/tools/perf/arch/x86/util/tsc.c
+++ b/tools/perf/arch/x86/util/tsc.c
@@ -7,7 +7,6 @@
 #include <linux/types.h>
 #include "../../util/debug.h"
 #include "../../util/tsc.h"
-#include "tsc.h"
 
 int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
 			     struct perf_tsc_conversion *tc)
diff --git a/tools/perf/arch/x86/util/tsc.h b/tools/perf/arch/x86/util/tsc.h
deleted file mode 100644
index 2edc4d3..0000000
--- a/tools/perf/arch/x86/util/tsc.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef TOOLS_PERF_ARCH_X86_UTIL_TSC_H__
-#define TOOLS_PERF_ARCH_X86_UTIL_TSC_H__
-
-#include <linux/types.h>
-
-struct perf_tsc_conversion {
-	u16 time_shift;
-	u32 time_mult;
-	u64 time_zero;
-};
-
-struct perf_event_mmap_page;
-
-int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
-			     struct perf_tsc_conversion *tc);
-
-#endif /* TOOLS_PERF_ARCH_X86_UTIL_TSC_H__ */
diff --git a/tools/perf/jvmti/jvmti_agent.c b/tools/perf/jvmti/jvmti_agent.c
index 6461e02..3573f31 100644
--- a/tools/perf/jvmti/jvmti_agent.c
+++ b/tools/perf/jvmti/jvmti_agent.c
@@ -92,6 +92,22 @@ error:
 	return ret;
 }
 
+static int use_arch_timestamp;
+
+static inline uint64_t
+get_arch_timestamp(void)
+{
+#if defined(__i386__) || defined(__x86_64__)
+	unsigned int low, high;
+
+	asm volatile("rdtsc" : "=a" (low), "=d" (high));
+
+	return low | ((uint64_t)high) << 32;
+#else
+	return 0;
+#endif
+}
+
 #define NSEC_PER_SEC	1000000000
 static int perf_clk_id = CLOCK_MONOTONIC;
 
@@ -107,6 +123,9 @@ perf_get_timestamp(void)
 	struct timespec ts;
 	int ret;
 
+	if (use_arch_timestamp)
+		return get_arch_timestamp();
+
 	ret = clock_gettime(perf_clk_id, &ts);
 	if (ret)
 		return 0;
@@ -203,6 +222,17 @@ perf_close_marker_file(void)
 	munmap(marker_addr, pgsz);
 }
 
+static void
+init_arch_timestamp(void)
+{
+	char *str = getenv("JITDUMP_USE_ARCH_TIMESTAMP");
+
+	if (!str || !*str || !strcmp(str, "0"))
+		return;
+
+	use_arch_timestamp = 1;
+}
+
 void *jvmti_open(void)
 {
 	int pad_cnt;
@@ -211,11 +241,17 @@ void *jvmti_open(void)
 	int fd;
 	FILE *fp;
 
+	init_arch_timestamp();
+
 	/*
 	 * check if clockid is supported
 	 */
-	if (!perf_get_timestamp())
-		warnx("jvmti: kernel does not support %d clock id", perf_clk_id);
+	if (!perf_get_timestamp()) {
+		if (use_arch_timestamp)
+			warnx("jvmti: arch timestamp not supported");
+		else
+			warnx("jvmti: kernel does not support %d clock id", perf_clk_id);
+	}
 
 	memset(&header, 0, sizeof(header));
 
@@ -263,6 +299,9 @@ void *jvmti_open(void)
 
 	header.timestamp = perf_get_timestamp();
 
+	if (use_arch_timestamp)
+		header.flags |= JITDUMP_FLAGS_ARCH_TIMESTAMP;
+
 	if (!fwrite(&header, sizeof(header), 1, fp)) {
 		warn("jvmti: cannot write dumpfile header");
 		goto error;
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index da48fd8..85ceff3 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -69,8 +69,7 @@ libperf-y += stat-shadow.o
 libperf-y += record.o
 libperf-y += srcline.o
 libperf-y += data.o
-libperf-$(CONFIG_X86) += tsc.o
-libperf-$(CONFIG_AUXTRACE) += tsc.o
+libperf-y += tsc.o
 libperf-y += cloexec.o
 libperf-y += thread-stack.o
 libperf-$(CONFIG_AUXTRACE) += auxtrace.o
diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
index ad0c0bb..52fcef3 100644
--- a/tools/perf/util/jitdump.c
+++ b/tools/perf/util/jitdump.c
@@ -17,6 +17,7 @@
 #include "strlist.h"
 #include <elf.h>
 
+#include "tsc.h"
 #include "session.h"
 #include "jit.h"
 #include "jitdump.h"
@@ -33,6 +34,7 @@ struct jit_buf_desc {
 	size_t           bufsize;
 	FILE             *in;
 	bool		 needs_bswap; /* handles cross-endianess */
+	bool		 use_arch_timestamp;
 	void		 *debug_data;
 	size_t		 nr_debug_entries;
 	uint32_t         code_load_count;
@@ -158,13 +160,16 @@ jit_open(struct jit_buf_desc *jd, const char *name)
 		header.flags      = bswap_64(header.flags);
 	}
 
+	jd->use_arch_timestamp = header.flags & JITDUMP_FLAGS_ARCH_TIMESTAMP;
+
 	if (verbose > 2)
-		pr_debug("version=%u\nhdr.size=%u\nts=0x%llx\npid=%d\nelf_mach=%d\n",
+		pr_debug("version=%u\nhdr.size=%u\nts=0x%llx\npid=%d\nelf_mach=%d\nuse_arch_timestamp=%d\n",
 			header.version,
 			header.total_size,
 			(unsigned long long)header.timestamp,
 			header.pid,
-			header.elf_mach);
+			header.elf_mach,
+			jd->use_arch_timestamp);
 
 	if (header.flags & JITDUMP_FLAGS_RESERVED) {
 		pr_err("jitdump file contains invalid or unsupported flags 0x%llx\n",
@@ -172,10 +177,15 @@ jit_open(struct jit_buf_desc *jd, const char *name)
 		goto error;
 	}
 
+	if (jd->use_arch_timestamp && !jd->session->time_conv.time_mult) {
+		pr_err("jitdump file uses arch timestamps but there is no timestamp conversion\n");
+		goto error;
+	}
+
 	/*
 	 * validate event is using the correct clockid
 	 */
-	if (jit_validate_events(jd->session)) {
+	if (!jd->use_arch_timestamp && jit_validate_events(jd->session)) {
 		pr_err("error, jitted code must be sampled with perf record -k 1\n");
 		goto error;
 	}
@@ -329,6 +339,23 @@ jit_inject_event(struct jit_buf_desc *jd, union perf_event *event)
 	return 0;
 }
 
+static uint64_t convert_timestamp(struct jit_buf_desc *jd, uint64_t timestamp)
+{
+	struct perf_tsc_conversion tc;
+
+	if (!jd->use_arch_timestamp)
+		return timestamp;
+
+	tc.time_shift = jd->session->time_conv.time_shift;
+	tc.time_mult  = jd->session->time_conv.time_mult;
+	tc.time_zero  = jd->session->time_conv.time_zero;
+
+	if (!tc.time_mult)
+		return 0;
+
+	return tsc_to_perf_time(timestamp, &tc);
+}
+
 static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
 {
 	struct perf_sample sample;
@@ -410,7 +437,7 @@ static int jit_repipe_code_load(struct jit_buf_desc *jd, union jr_entry *jr)
 		id->tid  = tid;
 	}
 	if (jd->sample_type & PERF_SAMPLE_TIME)
-		id->time = jr->load.p.timestamp;
+		id->time = convert_timestamp(jd, jr->load.p.timestamp);
 
 	/*
 	 * create pseudo sample to induce dso hit increment
@@ -499,7 +526,7 @@ static int jit_repipe_code_move(struct jit_buf_desc *jd, union jr_entry *jr)
 		id->tid  = tid;
 	}
 	if (jd->sample_type & PERF_SAMPLE_TIME)
-		id->time = jr->load.p.timestamp;
+		id->time = convert_timestamp(jd, jr->load.p.timestamp);
 
 	/*
 	 * create pseudo sample to induce dso hit increment
diff --git a/tools/perf/util/jitdump.h b/tools/perf/util/jitdump.h
index b66c1f5..bcacd20 100644
--- a/tools/perf/util/jitdump.h
+++ b/tools/perf/util/jitdump.h
@@ -23,9 +23,12 @@
 #define JITHEADER_VERSION 1
 
 enum jitdump_flags_bits {
+	JITDUMP_FLAGS_ARCH_TIMESTAMP_BIT,
 	JITDUMP_FLAGS_MAX_BIT,
 };
 
+#define JITDUMP_FLAGS_ARCH_TIMESTAMP	(1ULL << JITDUMP_FLAGS_ARCH_TIMESTAMP_BIT)
+
 #define JITDUMP_FLAGS_RESERVED (JITDUMP_FLAGS_MAX_BIT < 64 ? \
 				(~((1ULL << JITDUMP_FLAGS_MAX_BIT) - 1)) : 0)
 
diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h
index 280ddc0..d5b11e2 100644
--- a/tools/perf/util/tsc.h
+++ b/tools/perf/util/tsc.h
@@ -4,7 +4,16 @@
 #include <linux/types.h>
 
 #include "event.h"
-#include "../arch/x86/util/tsc.h"
+
+struct perf_tsc_conversion {
+	u16 time_shift;
+	u32 time_mult;
+	u64 time_zero;
+};
+struct perf_event_mmap_page;
+
+int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc,
+			     struct perf_tsc_conversion *tc);
 
 u64 perf_time_to_tsc(u64 ns, struct perf_tsc_conversion *tc);
 u64 tsc_to_perf_time(u64 cyc, struct perf_tsc_conversion *tc);

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [tip:perf/core] perf intel-pt/bts: Define JITDUMP_USE_ARCH_TIMESTAMP
  2016-03-08  8:38   ` [PATCH V2 " Adrian Hunter
@ 2016-04-06  7:08     ` tip-bot for Adrian Hunter
  0 siblings, 0 replies; 31+ messages in thread
From: tip-bot for Adrian Hunter @ 2016-04-06  7:08 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, eranian, hpa, tglx, acme, mingo, jolsa, adrian.hunter

Commit-ID:  bd0c7a54219cc3745ce7f36970d8e5ffb3f8d80e
Gitweb:     http://git.kernel.org/tip/bd0c7a54219cc3745ce7f36970d8e5ffb3f8d80e
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Tue, 8 Mar 2016 10:38:53 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 1 Apr 2016 18:46:24 -0300

perf intel-pt/bts: Define JITDUMP_USE_ARCH_TIMESTAMP

For Intel PT / BTS, define the environment variable that selects TSC
timestamps in the jitdump file.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1457426333-30260-1-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/arch/x86/util/intel-bts.c | 5 +++++
 tools/perf/arch/x86/util/intel-pt.c  | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c
index d66f9ad..7dc3063 100644
--- a/tools/perf/arch/x86/util/intel-bts.c
+++ b/tools/perf/arch/x86/util/intel-bts.c
@@ -438,6 +438,11 @@ struct auxtrace_record *intel_bts_recording_init(int *err)
 	if (!intel_bts_pmu)
 		return NULL;
 
+	if (setenv("JITDUMP_USE_ARCH_TIMESTAMP", "1", 1)) {
+		*err = -errno;
+		return NULL;
+	}
+
 	btsr = zalloc(sizeof(struct intel_bts_recording));
 	if (!btsr) {
 		*err = -ENOMEM;
diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index a339517..a07b960 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -1027,6 +1027,11 @@ struct auxtrace_record *intel_pt_recording_init(int *err)
 	if (!intel_pt_pmu)
 		return NULL;
 
+	if (setenv("JITDUMP_USE_ARCH_TIMESTAMP", "1", 1)) {
+		*err = -errno;
+		return NULL;
+	}
+
 	ptr = zalloc(sizeof(struct intel_pt_recording));
 	if (!ptr) {
 		*err = -ENOMEM;

^ permalink raw reply related	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2016-04-06  7:09 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-03 11:50 [PATCH 0/8] perf tools: Add Intel PT support for jitdump Adrian Hunter
2016-03-03 11:50 ` [PATCH 1/8] perf inject: Hit all DSOs for AUX data in JIT and other cases Adrian Hunter
2016-03-08 10:30   ` [tip:perf/core] " tip-bot for Adrian Hunter
2016-03-03 11:50 ` [PATCH 2/8] perf session: Simplify tool stubs Adrian Hunter
2016-03-08  8:38   ` [PATCH V2 " Adrian Hunter
2016-03-08 10:30   ` [tip:perf/core] " tip-bot for Adrian Hunter
2016-03-03 11:50 ` [PATCH 3/8] perf tools: Add time conversion event Adrian Hunter
2016-03-08  8:38   ` [PATCH V2 " Adrian Hunter
2016-03-31  6:33     ` Adrian Hunter
2016-03-31 13:53       ` Arnaldo Carvalho de Melo
2016-04-06  7:07     ` [tip:perf/core] " tip-bot for Adrian Hunter
2016-03-03 11:50 ` [PATCH 4/8] perf jit: Let jit_process() return errors Adrian Hunter
2016-03-08 10:30   ` [tip:perf/core] " tip-bot for Adrian Hunter
2016-03-03 11:50 ` [PATCH 5/8] perf jit: Move clockid validation Adrian Hunter
2016-03-08  8:38   ` [PATCH V2 " Adrian Hunter
2016-03-08 10:31   ` [tip:perf/core] " tip-bot for Adrian Hunter
2016-03-03 11:50 ` [PATCH 6/8] perf jit: Add support for using TSC as a timestamp Adrian Hunter
2016-03-08  8:38   ` [PATCH V2 " Adrian Hunter
2016-04-01  3:49     ` [PATCH] perf tools: Fix build errors on tsc functions for archs other than x86 He Kuang
2016-04-01  7:13       ` Adrian Hunter
2016-04-01 13:13       ` Arnaldo Carvalho de Melo
2016-04-01 13:19         ` Hekuang
2016-04-01 13:24         ` Arnaldo Carvalho de Melo
2016-04-01 13:39           ` Adrian Hunter
2016-04-06  7:08       ` [tip:perf/core] perf jit: Add support for using TSC as a timestamp tip-bot for Adrian Hunter
2016-03-03 11:50 ` [PATCH 7/8] perf intel-pt/bts: Define JITDUMP_USE_ARCH_TIMESTAMP Adrian Hunter
2016-03-08  8:38   ` [PATCH V2 " Adrian Hunter
2016-04-06  7:08     ` [tip:perf/core] " tip-bot for Adrian Hunter
2016-03-03 11:50 ` [PATCH 8/8] perf tools: Use 64-bit shifts with (TSC) time conversion Adrian Hunter
2016-03-08 10:31   ` [tip:perf/core] " tip-bot for Adrian Hunter
2016-03-08  8:49 ` [PATCH 0/8] perf tools: Add Intel PT support for jitdump Adrian Hunter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).