linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>,
	linux-kernel@vger.kernel.org,
	Stephane Eranian <eranian@google.com>
Subject: [PATCH 3/8] perf tools: Add time conversion event
Date: Thu,  3 Mar 2016 13:50:51 +0200	[thread overview]
Message-ID: <1457005856-6143-4-git-send-email-adrian.hunter@intel.com> (raw)
In-Reply-To: <1457005856-6143-1-git-send-email-adrian.hunter@intel.com>

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

  parent reply	other threads:[~2016-03-03 11:56 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Adrian Hunter [this message]
2016-03-08  8:38   ` [PATCH V2 3/8] perf tools: Add time conversion event 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1457005856-6143-4-git-send-email-adrian.hunter@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=eranian@google.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).