All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
	Andi Kleen <ak@linux.intel.com>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH V3 25/37] perf script: Add synthesized Intel PT power and ptwrite events
Date: Fri, 30 Jun 2017 11:36:42 +0300	[thread overview]
Message-ID: <1498811802-2301-1-git-send-email-adrian.hunter@intel.com> (raw)
In-Reply-To: <1495786658-18063-26-git-send-email-adrian.hunter@intel.com>

Add definitions for synthesized Intel PT events for power and ptwrite.

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


Changes in V3:

	Avoid using __packed


 tools/perf/builtin-script.c | 114 +++++++++++++++++++++++++++++++++++++++++-
 tools/perf/util/event.h     | 118 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 231 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index e87b480bbdd0..b458a0cc3544 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1203,10 +1203,122 @@ static void print_sample_bpf_output(struct perf_sample *sample)
 		       (char *)(sample->raw_data));
 }
 
-static void print_sample_synth(struct perf_sample *sample __maybe_unused,
+static void print_sample_spacing(int len, int spacing)
+{
+	if (len > 0 && len < spacing)
+		printf("%*s", spacing - len, "");
+}
+
+static void print_sample_pt_spacing(int len)
+{
+	print_sample_spacing(len, 34);
+}
+
+static void print_sample_synth_ptwrite(struct perf_sample *sample)
+{
+	struct perf_synth_intel_ptwrite *data = perf_sample__synth_ptr(sample);
+	int len;
+
+	if (perf_sample__bad_synth_size(sample, *data))
+		return;
+
+	len = printf(" IP: %u payload: %#" PRIx64 " ",
+		     data->ip, le64_to_cpu(data->payload));
+	print_sample_pt_spacing(len);
+}
+
+static void print_sample_synth_mwait(struct perf_sample *sample)
+{
+	struct perf_synth_intel_mwait *data = perf_sample__synth_ptr(sample);
+	int len;
+
+	if (perf_sample__bad_synth_size(sample, *data))
+		return;
+
+	len = printf(" hints: %#x extensions: %#x ",
+		     data->hints, data->extensions);
+	print_sample_pt_spacing(len);
+}
+
+static void print_sample_synth_pwre(struct perf_sample *sample)
+{
+	struct perf_synth_intel_pwre *data = perf_sample__synth_ptr(sample);
+	int len;
+
+	if (perf_sample__bad_synth_size(sample, *data))
+		return;
+
+	len = printf(" hw: %u cstate: %u sub-cstate: %u ",
+		     data->hw, data->cstate, data->subcstate);
+	print_sample_pt_spacing(len);
+}
+
+static void print_sample_synth_exstop(struct perf_sample *sample)
+{
+	struct perf_synth_intel_exstop *data = perf_sample__synth_ptr(sample);
+	int len;
+
+	if (perf_sample__bad_synth_size(sample, *data))
+		return;
+
+	len = printf(" IP: %u ", data->ip);
+	print_sample_pt_spacing(len);
+}
+
+static void print_sample_synth_pwrx(struct perf_sample *sample)
+{
+	struct perf_synth_intel_pwrx *data = perf_sample__synth_ptr(sample);
+	int len;
+
+	if (perf_sample__bad_synth_size(sample, *data))
+		return;
+
+	len = printf(" deepest cstate: %u last cstate: %u wake reason: %#x ",
+		     data->deepest_cstate, data->last_cstate,
+		     data->wake_reason);
+	print_sample_pt_spacing(len);
+}
+
+static void print_sample_synth_cbr(struct perf_sample *sample)
+{
+	struct perf_synth_intel_cbr *data = perf_sample__synth_ptr(sample);
+	unsigned int percent, freq;
+	int len;
+
+	if (perf_sample__bad_synth_size(sample, *data))
+		return;
+
+	freq = (le32_to_cpu(data->freq) + 500) / 1000;
+	len = printf(" cbr: %2u freq: %4u MHz ", data->cbr, freq);
+	if (data->max_nonturbo) {
+		percent = (5 + (1000 * data->cbr) / data->max_nonturbo) / 10;
+		len += printf("(%3u%%) ", percent);
+	}
+	print_sample_pt_spacing(len);
+}
+
+static void print_sample_synth(struct perf_sample *sample,
 			       struct perf_evsel *evsel)
 {
 	switch (evsel->attr.config) {
+	case PERF_SYNTH_INTEL_PTWRITE:
+		print_sample_synth_ptwrite(sample);
+		break;
+	case PERF_SYNTH_INTEL_MWAIT:
+		print_sample_synth_mwait(sample);
+		break;
+	case PERF_SYNTH_INTEL_PWRE:
+		print_sample_synth_pwre(sample);
+		break;
+	case PERF_SYNTH_INTEL_EXSTOP:
+		print_sample_synth_exstop(sample);
+		break;
+	case PERF_SYNTH_INTEL_PWRX:
+		print_sample_synth_pwrx(sample);
+		break;
+	case PERF_SYNTH_INTEL_CBR:
+		print_sample_synth_cbr(sample);
+		break;
 	default:
 		break;
 	}
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 855733c2adcf..9967c87af7a6 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -255,6 +255,124 @@ enum auxtrace_error_type {
 /* Attribute type for custom synthesized events */
 #define PERF_TYPE_SYNTH		(INT_MAX + 1U)
 
+/* Attribute config for custom synthesized events */
+enum perf_synth_id {
+	PERF_SYNTH_INTEL_PTWRITE,
+	PERF_SYNTH_INTEL_MWAIT,
+	PERF_SYNTH_INTEL_PWRE,
+	PERF_SYNTH_INTEL_EXSTOP,
+	PERF_SYNTH_INTEL_PWRX,
+	PERF_SYNTH_INTEL_CBR,
+};
+
+/*
+ * Raw data formats for synthesized events. Note that 4 bytes of padding are
+ * present to match the 'size' member of PERF_SAMPLE_RAW data which is always
+ * 8-byte aligned. That means we must dereference raw_data with an offset of 4.
+ * Refer perf_sample__synth_ptr() and perf_synth__raw_data().  It also means the
+ * structure sizes are 4 bytes bigger than the raw_size, refer
+ * perf_synth__raw_size().
+ */
+
+struct perf_synth_intel_ptwrite {
+	u32 padding;
+	union {
+		struct {
+			u32	ip		:  1,
+				reserved	: 31;
+		};
+		u32	flags;
+	};
+	u64	payload;
+};
+
+struct perf_synth_intel_mwait {
+	u32 padding;
+	u32 reserved;
+	union {
+		struct {
+			u64	hints		:  8,
+				reserved1	: 24,
+				extensions	:  2,
+				reserved2	: 30;
+		};
+		u64	payload;
+	};
+};
+
+struct perf_synth_intel_pwre {
+	u32 padding;
+	u32 reserved;
+	union {
+		struct {
+			u64	reserved1	:  7,
+				hw		:  1,
+				subcstate	:  4,
+				cstate		:  4,
+				reserved2	: 48;
+		};
+		u64	payload;
+	};
+};
+
+struct perf_synth_intel_exstop {
+	u32 padding;
+	union {
+		struct {
+			u32	ip		:  1,
+				reserved	: 31;
+		};
+		u32	flags;
+	};
+};
+
+struct perf_synth_intel_pwrx {
+	u32 padding;
+	u32 reserved;
+	union {
+		struct {
+			u64	deepest_cstate	:  4,
+				last_cstate	:  4,
+				wake_reason	:  4,
+				reserved1	: 52;
+		};
+		u64	payload;
+	};
+};
+
+struct perf_synth_intel_cbr {
+	u32 padding;
+	union {
+		struct {
+			u32	cbr		:  8,
+				reserved1	:  8,
+				max_nonturbo	:  8,
+				reserved2	:  8;
+		};
+		u32	flags;
+	};
+	u32 freq;
+	u32 reserved3;
+};
+
+/*
+ * raw_data is always 4 bytes from an 8-byte boundary, so subtract 4 to get
+ * 8-byte alignment.
+ */
+static inline void *perf_sample__synth_ptr(struct perf_sample *sample)
+{
+	return sample->raw_data - 4;
+}
+
+static inline void *perf_synth__raw_data(void *p)
+{
+	return p + 4;
+}
+
+#define perf_synth__raw_size(d) (sizeof(d) - 4)
+
+#define perf_sample__bad_synth_size(s, d) ((s)->raw_size < sizeof(d) - 4)
+
 /*
  * The kernel collects the number of events it couldn't send in a stretch and
  * when possible sends this number in a PERF_RECORD_LOST event. The number of
-- 
1.9.1

  parent reply	other threads:[~2017-06-30  8:42 UTC|newest]

Thread overview: 100+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 01/37] perf intel-pt: Move decoder error setting into one condition Adrian Hunter
2017-06-21 18:19   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 02/37] perf intel-pt: Improve sample timestamp Adrian Hunter
2017-06-21 18:20   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 03/37] perf intel-pt: Fix missing stack clear Adrian Hunter
2017-06-21 18:20   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 04/37] perf intel-pt: Ensure IP is zero when state is INTEL_PT_STATE_NO_IP Adrian Hunter
2017-06-21 18:21   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 05/37] perf intel-pt: Fix last_ip usage Adrian Hunter
2017-06-21 18:22   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 06/37] perf intel-pt: Ensure never to set 'last_ip' when packet 'count' is zero Adrian Hunter
2017-06-21 18:22   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 07/37] perf intel-pt: Use FUP always when scanning for an IP Adrian Hunter
2017-06-21 18:23   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 08/37] perf intel-pt: Clear FUP flag on error Adrian Hunter
2017-06-21 18:23   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 09/37] perf intel-pt: Add missing __fallthrough Adrian Hunter
2017-06-21 18:24   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 10/37] perf intel-pt: Allow decoding with branch tracing disabled Adrian Hunter
2017-06-21 18:24   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 11/37] perf intel-pt: Add default config for pass-through branch enable Adrian Hunter
2017-06-21 18:25   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 12/37] perf intel-pt: Add documentation for new config terms Adrian Hunter
2017-06-21 18:25   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 13/37] perf intel-pt: Add decoder support for ptwrite and power event packets Adrian Hunter
2017-06-21 18:26   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 14/37] perf intel-pt: Add reserved byte to CBR packet payload Adrian Hunter
2017-06-21 18:27   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 15/37] perf intel-pt: Add decoder support for CBR events Adrian Hunter
2017-06-21 18:27   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 16/37] perf intel-pt: Remove redundant initial_skip checks Adrian Hunter
2017-06-21 18:28   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 17/37] perf intel-pt: Fix transactions_sample_type Adrian Hunter
2017-06-21 18:28   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 18/37] perf tools: Fix message because cpu list option is -C not -c Adrian Hunter
2017-06-21 18:29   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 19/37] perf script: Fix message because field list option is -F not -f Adrian Hunter
2017-06-21 18:29   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 20/37] perf script: Add 'synth' event type for synthesized events Adrian Hunter
2017-06-21 10:17   ` [PATCH V3 " Adrian Hunter
2017-06-21 13:51     ` Arnaldo Carvalho de Melo
2017-06-21 16:41       ` Adrian Hunter
2017-06-21 17:29         ` Arnaldo Carvalho de Melo
2017-06-21 20:20           ` Adrian Hunter
2017-06-22 14:59             ` Arnaldo Carvalho de Melo
2017-07-01  8:50     ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 21/37] perf script: Add 'synth' field for synthesized event payloads Adrian Hunter
2017-06-21 10:17   ` [PATCH V3 " Adrian Hunter
2017-07-01  8:51   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 22/37] tools include: Add byte-swapping macros to kernel.h Adrian Hunter
2017-07-01  8:50   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 23/37] perf auxtrace: Add itrace option to output ptwrite events Adrian Hunter
2017-07-01  8:51   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 24/37] perf auxtrace: Add itrace option to output power events Adrian Hunter
2017-07-01  8:51   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events Adrian Hunter
2017-06-28 13:04   ` Arnaldo Carvalho de Melo
2017-06-28 17:40     ` Adrian Hunter
2017-06-28 18:53       ` Arnaldo Carvalho de Melo
2017-06-28 20:21         ` Hunter, Adrian
2017-06-28 20:26           ` Arnaldo Carvalho de Melo
2017-06-29 19:56             ` Adrian Hunter
2017-06-29 20:13               ` Arnaldo Carvalho de Melo
2017-06-30  2:08                 ` Arnaldo Carvalho de Melo
2017-06-30  8:51                   ` Adrian Hunter
2017-06-30 14:54                     ` Arnaldo Carvalho de Melo
2017-06-30 19:37                       ` Hunter, Adrian
2017-06-30  8:36   ` Adrian Hunter [this message]
2017-07-01  8:52     ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 26/37] perf intel-pt: Factor out common code synthesizing event samples Adrian Hunter
2017-07-01  8:52   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 27/37] perf intel-pt: Remove unused instructions_sample_period Adrian Hunter
2017-07-01  8:52   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 28/37] perf intel-pt: Join needlessly wrapped lines Adrian Hunter
2017-07-01  8:53   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 29/37] perf intel-pt: Tidy Intel PT evsel lookup into separate function Adrian Hunter
2017-07-01  8:53   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 30/37] perf intel-pt: Tidy messages into called function intel_pt_synth_event() Adrian Hunter
2017-07-01  8:53   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 31/37] perf intel-pt: Factor out intel_pt_set_event_name() Adrian Hunter
2017-07-01  8:54   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 32/37] perf intel-pt: Move code in intel_pt_synth_events() to simplify attr setting Adrian Hunter
2017-07-01  8:54   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 33/37] perf intel-pt: Synthesize new power and ptwrite events Adrian Hunter
2017-06-30  8:36   ` [PATCH V3 " Adrian Hunter
2017-07-01  8:54     ` [tip:perf/core] perf intel-pt: Synthesize new power and "ptwrite" events tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 34/37] perf intel-pt: Add example script for power events and PTWRITE Adrian Hunter
2017-07-01  8:55   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 35/37] perf intel-pt: Update documentation to include new ptwrite and power events Adrian Hunter
2017-07-01  8:55   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 36/37] perf intel-pt: Do not use TSC packets for calculating CPU cycles to TSC Adrian Hunter
2017-07-01  8:56   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-05-26  8:17 ` [PATCH V2 37/37] perf auxtrace: Add CPU filter support Adrian Hunter
2017-07-01  8:56   ` [tip:perf/core] " tip-bot for Adrian Hunter
2017-06-12 13:04 ` [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
2017-06-12 13:56   ` Arnaldo Carvalho de Melo
2017-06-21 10:20     ` Adrian Hunter
2017-06-21 13:40       ` Arnaldo Carvalho de Melo
2017-06-27 15:27     ` Arnaldo Carvalho de Melo

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=1498811802-2301-1-git-send-email-adrian.hunter@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.