All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE
@ 2017-05-26  8:17 Adrian Hunter
  2017-05-26  8:17 ` [PATCH V2 01/37] perf intel-pt: Move decoder error setting into one condition Adrian Hunter
                   ` (37 more replies)
  0 siblings, 38 replies; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Hi

Here are some patches to support Intel PT Power events and PTWRITE.
Power events report changes to C-state but I have also added support
for the existing CBR (core-to-bus ratio) packet and included that
when outputting power events.  The PTWRITE packet is associated with
the new ptwrite instruction, which is essentially just a way to stuff
a 32 or 64 bit value into the PT trace.  More details can be found in
the patches that add documentation and in the Intel SDM.

As far as I know, there isn't any hardware released that supports
the new packets, however the CBR packet is not new and will now be
visible by default.

There are also some miscellaneous improvements to Intel PT.

There are 3 patches that introduce a new way to define synthesized
events that carry arbitrary raw_data.  I sent an RFC about that earlier.
The 3 patches are:
      perf script: Add 'synth' event type for synthesized events
      perf script: Add 'synth' field for synthesized event payloads
      perf script: Add synthesized Intel PT power and ptwrite events


Changes in V2:

	Reorder patches and add stable tags to fixes.


Adrian Hunter (37):
      perf intel-pt: Move decoder error setting into one condition
      perf intel-pt: Improve sample timestamp
      perf intel-pt: Fix missing stack clear
      perf intel-pt: Ensure IP is zero when state is INTEL_PT_STATE_NO_IP
      perf intel-pt: Fix last_ip usage
      perf intel-pt: Ensure never to set 'last_ip' when packet 'count' is zero
      perf intel-pt: Use FUP always when scanning for an IP
      perf intel-pt: Clear FUP flag on error
      perf intel-pt: Add missing __fallthrough
      perf intel-pt: Allow decoding with branch tracing disabled
      perf intel-pt: Add default config for pass-through branch enable
      perf intel-pt: Add documentation for new config terms
      perf intel-pt: Add decoder support for ptwrite and power event packets
      perf intel-pt: Add reserved byte to CBR packet payload
      perf intel-pt: Add decoder support for CBR events
      perf intel-pt: Remove redundant initial_skip checks
      perf intel-pt: Fix transactions_sample_type
      perf tools: Fix message because cpu list option is -C not -c
      perf script: Fix message because field list option is -F not -f
      perf script: Add 'synth' event type for synthesized events
      perf script: Add 'synth' field for synthesized event payloads
      tools include: Add byte-swapping macros to kernel.h
      perf auxtrace: Add itrace option to output ptwrite events
      perf auxtrace: Add itrace option to output power events
      perf script: Add synthesized Intel PT power and ptwrite events
      perf intel-pt: Factor out common code synthesizing event samples
      perf intel-pt: Remove unused instructions_sample_period
      perf intel-pt: Join needlessly wrapped lines
      perf intel-pt: Tidy Intel PT evsel lookup into separate function
      perf intel-pt: Tidy messages into called function intel_pt_synth_event()
      perf intel-pt: Factor out intel_pt_set_event_name()
      perf intel-pt: Move code in intel_pt_synth_events() to simplify attr setting
      perf intel-pt: Synthesize new power and ptwrite events
      perf intel-pt: Add example script for power events and PTWRITE
      perf intel-pt: Update documentation to include new ptwrite and power events
      perf intel-pt: Do not use TSC packets for calculating CPU cycles to TSC
      perf auxtrace: Add CPU filter support

 tools/include/linux/kernel.h                       |  35 +-
 tools/perf/Documentation/intel-pt.txt              |  78 ++-
 tools/perf/Documentation/itrace.txt                |   8 +-
 tools/perf/Documentation/perf-script.txt           |   6 +-
 tools/perf/arch/x86/util/intel-pt.c                |   5 +
 tools/perf/builtin-report.c                        |   1 +
 tools/perf/builtin-script.c                        | 207 ++++++-
 .../perf/scripts/python/bin/intel-pt-events-record |  13 +
 .../perf/scripts/python/bin/intel-pt-events-report |   3 +
 tools/perf/scripts/python/intel-pt-events.py       | 128 ++++
 tools/perf/util/auxtrace.c                         |  18 +
 tools/perf/util/auxtrace.h                         |   6 +
 tools/perf/util/event.h                            |  93 +++
 .../perf/util/intel-pt-decoder/intel-pt-decoder.c  | 304 +++++++++-
 .../perf/util/intel-pt-decoder/intel-pt-decoder.h  |  13 +
 .../util/intel-pt-decoder/intel-pt-pkt-decoder.c   | 110 +++-
 .../util/intel-pt-decoder/intel-pt-pkt-decoder.h   |   7 +
 tools/perf/util/intel-pt.c                         | 642 +++++++++++++++------
 tools/perf/util/session.c                          |   2 +-
 19 files changed, 1435 insertions(+), 244 deletions(-)
 create mode 100644 tools/perf/scripts/python/bin/intel-pt-events-record
 create mode 100644 tools/perf/scripts/python/bin/intel-pt-events-report
 create mode 100644 tools/perf/scripts/python/intel-pt-events.py


Regards
Adrian

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

* [PATCH V2 01/37] perf intel-pt: Move decoder error setting into one condition
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (36 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Move decoder error setting into one condition.

Cc'ed to stable because later fixes depend on it.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: stable@vger.kernel.org
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 7cf7f7aca4d2..5a9676c6e23f 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -2130,15 +2130,18 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)
 		}
 	} while (err == -ENOLINK);
 
-	decoder->state.err = err ? intel_pt_ext_err(err) : 0;
+	if (err) {
+		decoder->state.err = intel_pt_ext_err(err);
+		decoder->state.from_ip = decoder->ip;
+	} else {
+		decoder->state.err = 0;
+	}
+
 	decoder->state.timestamp = decoder->timestamp;
 	decoder->state.est_timestamp = intel_pt_est_timestamp(decoder);
 	decoder->state.cr3 = decoder->cr3;
 	decoder->state.tot_insn_cnt = decoder->tot_insn_cnt;
 
-	if (err)
-		decoder->state.from_ip = decoder->ip;
-
 	return &decoder->state;
 }
 
-- 
1.9.1

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

* [PATCH V2 02/37] perf intel-pt: Improve sample timestamp
  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-05-26  8:17 ` 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
                   ` (35 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

The decoder uses its current timestamp in samples. Usually that is a
timestamp that has already passed, but in some cases it is a timestamp for
a branch that the decoder is walking towards, and consequently hasn't
reached. Improve that situation by using the pkt_state to determine when
to use the current or previous timestamp.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: stable@vger.kernel.org
---
 .../perf/util/intel-pt-decoder/intel-pt-decoder.c  | 34 ++++++++++++++++++++--
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 5a9676c6e23f..d5c69e822282 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -64,6 +64,25 @@ enum intel_pt_pkt_state {
 	INTEL_PT_STATE_FUP_NO_TIP,
 };
 
+static inline bool intel_pt_sample_time(enum intel_pt_pkt_state pkt_state)
+{
+	switch (pkt_state) {
+	case INTEL_PT_STATE_NO_PSB:
+	case INTEL_PT_STATE_NO_IP:
+	case INTEL_PT_STATE_ERR_RESYNC:
+	case INTEL_PT_STATE_IN_SYNC:
+	case INTEL_PT_STATE_TNT:
+		return true;
+	case INTEL_PT_STATE_TIP:
+	case INTEL_PT_STATE_TIP_PGD:
+	case INTEL_PT_STATE_FUP:
+	case INTEL_PT_STATE_FUP_NO_TIP:
+		return false;
+	default:
+		return true;
+	};
+}
+
 #ifdef INTEL_PT_STRICT
 #define INTEL_PT_STATE_ERR1	INTEL_PT_STATE_NO_PSB
 #define INTEL_PT_STATE_ERR2	INTEL_PT_STATE_NO_PSB
@@ -99,6 +118,7 @@ struct intel_pt_decoder {
 	uint64_t timestamp;
 	uint64_t tsc_timestamp;
 	uint64_t ref_timestamp;
+	uint64_t sample_timestamp;
 	uint64_t ret_addr;
 	uint64_t ctc_timestamp;
 	uint64_t ctc_delta;
@@ -139,6 +159,7 @@ struct intel_pt_decoder {
 	unsigned int fup_tx_flags;
 	unsigned int tx_flags;
 	uint64_t timestamp_insn_cnt;
+	uint64_t sample_insn_cnt;
 	uint64_t stuck_ip;
 	int no_progress;
 	int stuck_ip_prd;
@@ -898,6 +919,7 @@ static int intel_pt_walk_insn(struct intel_pt_decoder *decoder,
 
 	decoder->tot_insn_cnt += insn_cnt;
 	decoder->timestamp_insn_cnt += insn_cnt;
+	decoder->sample_insn_cnt += insn_cnt;
 	decoder->period_insn_cnt += insn_cnt;
 
 	if (err) {
@@ -2069,7 +2091,7 @@ static int intel_pt_sync(struct intel_pt_decoder *decoder)
 
 static uint64_t intel_pt_est_timestamp(struct intel_pt_decoder *decoder)
 {
-	uint64_t est = decoder->timestamp_insn_cnt << 1;
+	uint64_t est = decoder->sample_insn_cnt << 1;
 
 	if (!decoder->cbr || !decoder->max_non_turbo_ratio)
 		goto out;
@@ -2077,7 +2099,7 @@ static uint64_t intel_pt_est_timestamp(struct intel_pt_decoder *decoder)
 	est *= decoder->max_non_turbo_ratio;
 	est /= decoder->cbr;
 out:
-	return decoder->timestamp + est;
+	return decoder->sample_timestamp + est;
 }
 
 const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)
@@ -2133,11 +2155,17 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)
 	if (err) {
 		decoder->state.err = intel_pt_ext_err(err);
 		decoder->state.from_ip = decoder->ip;
+		decoder->sample_timestamp = decoder->timestamp;
+		decoder->sample_insn_cnt = decoder->timestamp_insn_cnt;
 	} else {
 		decoder->state.err = 0;
+		if (intel_pt_sample_time(decoder->pkt_state)) {
+			decoder->sample_timestamp = decoder->timestamp;
+			decoder->sample_insn_cnt = decoder->timestamp_insn_cnt;
+		}
 	}
 
-	decoder->state.timestamp = decoder->timestamp;
+	decoder->state.timestamp = decoder->sample_timestamp;
 	decoder->state.est_timestamp = intel_pt_est_timestamp(decoder);
 	decoder->state.cr3 = decoder->cr3;
 	decoder->state.tot_insn_cnt = decoder->tot_insn_cnt;
-- 
1.9.1

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

* [PATCH V2 03/37] perf intel-pt: Fix missing stack clear
  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-05-26  8:17 ` [PATCH V2 02/37] perf intel-pt: Improve sample timestamp Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (34 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

The return compression stack must be cleared whenever there is a PSB. Fix
one case where that was not happening.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: stable@vger.kernel.org
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index d5c69e822282..28b16c3acdde 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -1932,6 +1932,7 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)
 			break;
 
 		case INTEL_PT_PSB:
+			intel_pt_clear_stack(&decoder->stack);
 			err = intel_pt_walk_psb(decoder);
 			if (err)
 				return err;
-- 
1.9.1

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

* [PATCH V2 04/37] perf intel-pt: Ensure IP is zero when state is INTEL_PT_STATE_NO_IP
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (2 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 03/37] perf intel-pt: Fix missing stack clear Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (33 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

A value of zero is used to indicate that there is no IP. Ensure the value
is zero when the state is INTEL_PT_STATE_NO_IP.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: stable@vger.kernel.org
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 28b16c3acdde..f9cd3aaef488 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -2117,6 +2117,7 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)
 			break;
 		case INTEL_PT_STATE_NO_IP:
 			decoder->last_ip = 0;
+			decoder->ip = 0;
 			/* Fall through */
 		case INTEL_PT_STATE_ERR_RESYNC:
 			err = intel_pt_sync_ip(decoder);
-- 
1.9.1

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

* [PATCH V2 05/37] perf intel-pt: Fix last_ip usage
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (3 preceding siblings ...)
  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-05-26  8:17 ` 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
                   ` (32 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Intel PT uses IP compression based on the last IP. For decoding purposes,
'last IP' is considered to be reset to zero whenever there is a
synchronization packet (PSB). The decoder wasn't doing that, and was
treating the zero value to mean that there was no last IP, whereas
compression can be done against the zero value. Fix by setting last_ip to
zero when a PSB is received and keep track of have_last_ip.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: stable@vger.kernel.org # prereq. e1717e0485af
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index f9cd3aaef488..62e2c2ad3f1d 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -111,6 +111,7 @@ struct intel_pt_decoder {
 	bool have_tma;
 	bool have_cyc;
 	bool fixup_last_mtc;
+	bool have_last_ip;
 	uint64_t pos;
 	uint64_t last_ip;
 	uint64_t ip;
@@ -419,6 +420,7 @@ static uint64_t intel_pt_calc_ip(const struct intel_pt_pkt *packet,
 static inline void intel_pt_set_last_ip(struct intel_pt_decoder *decoder)
 {
 	decoder->last_ip = intel_pt_calc_ip(&decoder->packet, decoder->last_ip);
+	decoder->have_last_ip = true;
 }
 
 static inline void intel_pt_set_ip(struct intel_pt_decoder *decoder)
@@ -1672,6 +1674,8 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)
 			break;
 
 		case INTEL_PT_PSB:
+			decoder->last_ip = 0;
+			decoder->have_last_ip = true;
 			intel_pt_clear_stack(&decoder->stack);
 			err = intel_pt_walk_psbend(decoder);
 			if (err == -EAGAIN)
@@ -1752,7 +1756,7 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)
 
 static inline bool intel_pt_have_ip(struct intel_pt_decoder *decoder)
 {
-	return decoder->last_ip || decoder->packet.count == 0 ||
+	return decoder->have_last_ip || decoder->packet.count == 0 ||
 	       decoder->packet.count == 3 || decoder->packet.count == 6;
 }
 
@@ -1882,7 +1886,7 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)
 				if (decoder->ip)
 					return 0;
 			}
-			if (decoder->packet.count)
+			if (decoder->packet.count && decoder->have_last_ip)
 				intel_pt_set_last_ip(decoder);
 			break;
 
@@ -1932,6 +1936,8 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)
 			break;
 
 		case INTEL_PT_PSB:
+			decoder->last_ip = 0;
+			decoder->have_last_ip = true;
 			intel_pt_clear_stack(&decoder->stack);
 			err = intel_pt_walk_psb(decoder);
 			if (err)
@@ -2066,6 +2072,7 @@ static int intel_pt_sync(struct intel_pt_decoder *decoder)
 
 	decoder->pge = false;
 	decoder->continuous_period = false;
+	decoder->have_last_ip = false;
 	decoder->last_ip = 0;
 	decoder->ip = 0;
 	intel_pt_clear_stack(&decoder->stack);
@@ -2074,6 +2081,7 @@ static int intel_pt_sync(struct intel_pt_decoder *decoder)
 	if (err)
 		return err;
 
+	decoder->have_last_ip = true;
 	decoder->pkt_state = INTEL_PT_STATE_NO_IP;
 
 	err = intel_pt_walk_psb(decoder);
@@ -2116,6 +2124,7 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)
 			err = intel_pt_sync(decoder);
 			break;
 		case INTEL_PT_STATE_NO_IP:
+			decoder->have_last_ip = false;
 			decoder->last_ip = 0;
 			decoder->ip = 0;
 			/* Fall through */
-- 
1.9.1

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

* [PATCH V2 06/37] perf intel-pt: Ensure never to set 'last_ip' when packet 'count' is zero
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (4 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 05/37] perf intel-pt: Fix last_ip usage Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (31 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Intel PT uses IP compression based on the last IP. For decoding purposes,
'last IP' is not updated when a branch target has been suppressed, which is
indicated by IPBytes == 0. IPBytes is stored in the packet 'count', so
ensure never to set 'last_ip' when packet 'count' is zero.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: stable@vger.kernel.org
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 62e2c2ad3f1d..72b9dc8135a2 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -1470,7 +1470,8 @@ static int intel_pt_walk_psbend(struct intel_pt_decoder *decoder)
 
 		case INTEL_PT_FUP:
 			decoder->pge = true;
-			intel_pt_set_last_ip(decoder);
+			if (decoder->packet.count)
+				intel_pt_set_last_ip(decoder);
 			break;
 
 		case INTEL_PT_MODE_TSX:
@@ -1756,8 +1757,9 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)
 
 static inline bool intel_pt_have_ip(struct intel_pt_decoder *decoder)
 {
-	return decoder->have_last_ip || decoder->packet.count == 0 ||
-	       decoder->packet.count == 3 || decoder->packet.count == 6;
+	return decoder->packet.count &&
+	       (decoder->have_last_ip || decoder->packet.count == 3 ||
+		decoder->packet.count == 6);
 }
 
 /* Walk PSB+ packets to get in sync. */
-- 
1.9.1

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

* [PATCH V2 07/37] perf intel-pt: Use FUP always when scanning for an IP
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (5 preceding siblings ...)
  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-05-26  8:17 ` 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
                   ` (30 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

The decoder will try to use branch packets to find an IP to start decoding
or to recover from errors. Currently the FUP packet is used only in the
case of an overflow, however there is no reason for that to be a special
case. So just use FUP always when scanning for an IP.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: stable@vger.kernel.org
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 72b9dc8135a2..923c60efda26 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -1882,14 +1882,10 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)
 			break;
 
 		case INTEL_PT_FUP:
-			if (decoder->overflow) {
-				if (intel_pt_have_ip(decoder))
-					intel_pt_set_ip(decoder);
-				if (decoder->ip)
-					return 0;
-			}
-			if (decoder->packet.count && decoder->have_last_ip)
-				intel_pt_set_last_ip(decoder);
+			if (intel_pt_have_ip(decoder))
+				intel_pt_set_ip(decoder);
+			if (decoder->ip)
+				return 0;
 			break;
 
 		case INTEL_PT_MTC:
-- 
1.9.1

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

* [PATCH V2 08/37] perf intel-pt: Clear FUP flag on error
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (6 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 07/37] perf intel-pt: Use FUP always when scanning for an IP Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (29 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Sometimes a FUP packet is associated with a TSX transaction and a flag is
set to indicate that. Ensure that flag is cleared on any error condition
because at that point the decoder can no longer assume it is correct.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: stable@vger.kernel.org
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 923c60efda26..a97710162e07 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -1962,6 +1962,8 @@ static int intel_pt_sync_ip(struct intel_pt_decoder *decoder)
 {
 	int err;
 
+	decoder->set_fup_tx_flags = false;
+
 	intel_pt_log("Scanning for full IP\n");
 	err = intel_pt_walk_to_ip(decoder);
 	if (err)
-- 
1.9.1

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

* [PATCH V2 09/37] perf intel-pt: Add missing __fallthrough
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (7 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 08/37] perf intel-pt: Clear FUP flag on error Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (28 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

perf tools uses __fallthrough. Add missing  __fallthrough to a switch
statement.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index a97710162e07..cad40fe93bd2 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -2127,7 +2127,7 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)
 			decoder->have_last_ip = false;
 			decoder->last_ip = 0;
 			decoder->ip = 0;
-			/* Fall through */
+			__fallthrough;
 		case INTEL_PT_STATE_ERR_RESYNC:
 			err = intel_pt_sync_ip(decoder);
 			break;
-- 
1.9.1

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

* [PATCH V2 10/37] perf intel-pt: Allow decoding with branch tracing disabled
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (8 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 09/37] perf intel-pt: Add missing __fallthrough Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (27 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

The kernel now supports the disabling of branch tracing, however the
decoder assumes branch tracing is always enabled. Pass through a parameter
to indicate whether branch tracing is enabled and use it to avoid cases
when the decoder is expecting branch packets. There are 2 such cases.
First, FUP packets which can bind to an IP even when there is no branch
tracing. Secondly, the decoder will try to use branch packets to find an IP
to start decoding or to recover from errors.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 13 +++++++++++++
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.h |  1 +
 tools/perf/util/intel-pt.c                          | 14 ++++++++++++++
 3 files changed, 28 insertions(+)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index cad40fe93bd2..dacb9223e743 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -106,6 +106,7 @@ struct intel_pt_decoder {
 	const unsigned char *buf;
 	size_t len;
 	bool return_compression;
+	bool branch_enable;
 	bool mtc_insn;
 	bool pge;
 	bool have_tma;
@@ -214,6 +215,7 @@ struct intel_pt_decoder *intel_pt_decoder_new(struct intel_pt_params *params)
 	decoder->pgd_ip             = params->pgd_ip;
 	decoder->data               = params->data;
 	decoder->return_compression = params->return_compression;
+	decoder->branch_enable      = params->branch_enable;
 
 	decoder->period             = params->period;
 	decoder->period_type        = params->period_type;
@@ -1650,6 +1652,10 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)
 				break;
 			}
 			intel_pt_set_last_ip(decoder);
+			if (!decoder->branch_enable) {
+				decoder->ip = decoder->last_ip;
+				break;
+			}
 			err = intel_pt_walk_fup(decoder);
 			if (err != -EAGAIN) {
 				if (err)
@@ -1964,6 +1970,13 @@ static int intel_pt_sync_ip(struct intel_pt_decoder *decoder)
 
 	decoder->set_fup_tx_flags = false;
 
+	if (!decoder->branch_enable) {
+		decoder->pkt_state = INTEL_PT_STATE_IN_SYNC;
+		decoder->overflow = false;
+		decoder->state.type = 0; /* Do not have a sample */
+		return 0;
+	}
+
 	intel_pt_log("Scanning for full IP\n");
 	err = intel_pt_walk_to_ip(decoder);
 	if (err)
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
index e90619a43c0c..add3bed58349 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
@@ -87,6 +87,7 @@ struct intel_pt_params {
 	bool (*pgd_ip)(uint64_t ip, void *data);
 	void *data;
 	bool return_compression;
+	bool branch_enable;
 	uint64_t period;
 	enum intel_pt_period_type period_type;
 	unsigned max_non_turbo_ratio;
diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 4c7718f87a08..5c59b8c6a719 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -668,6 +668,19 @@ static bool intel_pt_return_compression(struct intel_pt *pt)
 	return true;
 }
 
+static bool intel_pt_branch_enable(struct intel_pt *pt)
+{
+	struct perf_evsel *evsel;
+	u64 config;
+
+	evlist__for_each_entry(pt->session->evlist, evsel) {
+		if (intel_pt_get_config(pt, &evsel->attr, &config) &&
+		    (config & 1) && !(config & 0x2000))
+			return false;
+	}
+	return true;
+}
+
 static unsigned int intel_pt_mtc_period(struct intel_pt *pt)
 {
 	struct perf_evsel *evsel;
@@ -799,6 +812,7 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt,
 	params.walk_insn = intel_pt_walk_next_insn;
 	params.data = ptq;
 	params.return_compression = intel_pt_return_compression(pt);
+	params.branch_enable = intel_pt_branch_enable(pt);
 	params.max_non_turbo_ratio = pt->max_non_turbo_ratio;
 	params.mtc_period = intel_pt_mtc_period(pt);
 	params.tsc_ctc_ratio_n = pt->tsc_ctc_ratio_n;
-- 
1.9.1

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

* [PATCH V2 11/37] perf intel-pt: Add default config for pass-through branch enable
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (9 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 10/37] perf intel-pt: Allow decoding with branch tracing disabled Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (26 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Branch tracing is enabled by default, so a fake config bit called 'pt'
(pass-through) was added to allow the 'branch enable' bit to have affect.
Add default config 'pt,branch' which will allow users to disable branch
tracing using 'branch=0' instead of having to specify 'pt,branch=0'.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/arch/x86/util/intel-pt.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index f630de0206a1..007621a7e420 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -196,6 +196,7 @@ static u64 intel_pt_default_config(struct perf_pmu *intel_pt_pmu)
 	int psb_cyc, psb_periods, psb_period;
 	int pos = 0;
 	u64 config;
+	char c;
 
 	pos += scnprintf(buf + pos, sizeof(buf) - pos, "tsc");
 
@@ -229,6 +230,10 @@ static u64 intel_pt_default_config(struct perf_pmu *intel_pt_pmu)
 		}
 	}
 
+	if (perf_pmu__scan_file(intel_pt_pmu, "format/pt", "%c", &c) == 1 &&
+	    perf_pmu__scan_file(intel_pt_pmu, "format/branch", "%c", &c) == 1)
+		pos += scnprintf(buf + pos, sizeof(buf) - pos, ",pt,branch");
+
 	pr_debug2("%s default config: %s\n", intel_pt_pmu->name, buf);
 
 	intel_pt_parse_terms(&intel_pt_pmu->format, buf, &config);
-- 
1.9.1

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

* [PATCH V2 12/37] perf intel-pt: Add documentation for new config terms
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (10 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 11/37] perf intel-pt: Add default config for pass-through branch enable Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (25 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Add documentation for new config terms.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/Documentation/intel-pt.txt | 36 +++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/tools/perf/Documentation/intel-pt.txt b/tools/perf/Documentation/intel-pt.txt
index b0b3007d3c9c..d157dee7a4ec 100644
--- a/tools/perf/Documentation/intel-pt.txt
+++ b/tools/perf/Documentation/intel-pt.txt
@@ -364,6 +364,42 @@ cyc_thresh	Specifies how frequently CYC packets are produced - see cyc
 
 		CYC packets are not requested by default.
 
+pt		Specifies pass-through which enables the 'branch' config term.
+
+		The default config selects 'pt' if it is available, so a user will
+		never need to specify this term.
+
+branch		Enable branch tracing.  Branch tracing is enabled by default so to
+		disable branch tracing use 'branch=0'.
+
+		The default config selects 'branch' if it is available.
+
+ptw		Enable PTWRITE packets which are produced when a ptwrite instruction
+		is executed.
+
+		Support for this feature is indicated by:
+
+			/sys/bus/event_source/devices/intel_pt/caps/ptwrite
+
+		which contains "1" if the feature is supported and
+		"0" otherwise.
+
+fup_on_ptw	Enable a FUP packet to follow the PTWRITE packet.  The FUP packet
+		provides the address of the ptwrite instruction.  In the absence of
+		fup_on_ptw, the decoder will use the address of the previous branch
+		if branch tracing is enabled, otherwise the address will be zero.
+		Note that fup_on_ptw will work even when branch tracing is disabled.
+
+pwr_evt		Enable power events.  The power events provide information about
+		changes to the CPU C-state.
+
+		Support for this feature is indicated by:
+
+			/sys/bus/event_source/devices/intel_pt/caps/power_event_trace
+
+		which contains "1" if the feature is supported and
+		"0" otherwise.
+
 
 new snapshot option
 -------------------
-- 
1.9.1

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

* [PATCH V2 13/37] perf intel-pt: Add decoder support for ptwrite and power event packets
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (11 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 12/37] perf intel-pt: Add documentation for new config terms Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (24 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Add decoder support for PTWRITE, MWAIT, PWRE, PWRX and EXSTOP packets. This
patch only affects the decoder, so the tools still do not select or consume
the new information. That is added in subsequent patches.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 .../perf/util/intel-pt-decoder/intel-pt-decoder.c  | 176 ++++++++++++++++++++-
 .../perf/util/intel-pt-decoder/intel-pt-decoder.h  |  10 ++
 .../util/intel-pt-decoder/intel-pt-pkt-decoder.c   | 108 +++++++++++++
 .../util/intel-pt-decoder/intel-pt-pkt-decoder.h   |   7 +
 4 files changed, 293 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index dacb9223e743..e42804d10001 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -158,8 +158,15 @@ struct intel_pt_decoder {
 	bool continuous_period;
 	bool overflow;
 	bool set_fup_tx_flags;
+	bool set_fup_ptw;
+	bool set_fup_mwait;
+	bool set_fup_pwre;
+	bool set_fup_exstop;
 	unsigned int fup_tx_flags;
 	unsigned int tx_flags;
+	uint64_t fup_ptw_payload;
+	uint64_t fup_mwait_payload;
+	uint64_t fup_pwre_payload;
 	uint64_t timestamp_insn_cnt;
 	uint64_t sample_insn_cnt;
 	uint64_t stuck_ip;
@@ -660,6 +667,8 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info)
 	case INTEL_PT_PAD:
 	case INTEL_PT_VMCS:
 	case INTEL_PT_MNT:
+	case INTEL_PT_PTWRITE:
+	case INTEL_PT_PTWRITE_IP:
 		return 0;
 
 	case INTEL_PT_MTC:
@@ -758,6 +767,11 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info)
 
 	case INTEL_PT_TIP_PGD:
 	case INTEL_PT_TRACESTOP:
+	case INTEL_PT_EXSTOP:
+	case INTEL_PT_EXSTOP_IP:
+	case INTEL_PT_MWAIT:
+	case INTEL_PT_PWRE:
+	case INTEL_PT_PWRX:
 	case INTEL_PT_OVF:
 	case INTEL_PT_BAD: /* Does not happen */
 	default:
@@ -1016,6 +1030,57 @@ static int intel_pt_walk_insn(struct intel_pt_decoder *decoder,
 	return err;
 }
 
+static bool intel_pt_fup_event(struct intel_pt_decoder *decoder)
+{
+	bool ret = false;
+
+	if (decoder->set_fup_tx_flags) {
+		decoder->set_fup_tx_flags = false;
+		decoder->tx_flags = decoder->fup_tx_flags;
+		decoder->state.type = INTEL_PT_TRANSACTION;
+		decoder->state.from_ip = decoder->ip;
+		decoder->state.to_ip = 0;
+		decoder->state.flags = decoder->fup_tx_flags;
+		return true;
+	}
+	if (decoder->set_fup_ptw) {
+		decoder->set_fup_ptw = false;
+		decoder->state.type = INTEL_PT_PTW;
+		decoder->state.flags |= INTEL_PT_FUP_IP;
+		decoder->state.from_ip = decoder->ip;
+		decoder->state.to_ip = 0;
+		decoder->state.ptw_payload = decoder->fup_ptw_payload;
+		return true;
+	}
+	if (decoder->set_fup_mwait) {
+		decoder->set_fup_mwait = false;
+		decoder->state.type = INTEL_PT_MWAIT_OP;
+		decoder->state.from_ip = decoder->ip;
+		decoder->state.to_ip = 0;
+		decoder->state.mwait_payload = decoder->fup_mwait_payload;
+		ret = true;
+	}
+	if (decoder->set_fup_pwre) {
+		decoder->set_fup_pwre = false;
+		decoder->state.type |= INTEL_PT_PWR_ENTRY;
+		decoder->state.type &= ~INTEL_PT_BRANCH;
+		decoder->state.from_ip = decoder->ip;
+		decoder->state.to_ip = 0;
+		decoder->state.pwre_payload = decoder->fup_pwre_payload;
+		ret = true;
+	}
+	if (decoder->set_fup_exstop) {
+		decoder->set_fup_exstop = false;
+		decoder->state.type |= INTEL_PT_EX_STOP;
+		decoder->state.type &= ~INTEL_PT_BRANCH;
+		decoder->state.flags |= INTEL_PT_FUP_IP;
+		decoder->state.from_ip = decoder->ip;
+		decoder->state.to_ip = 0;
+		ret = true;
+	}
+	return ret;
+}
+
 static int intel_pt_walk_fup(struct intel_pt_decoder *decoder)
 {
 	struct intel_pt_insn intel_pt_insn;
@@ -1029,15 +1094,8 @@ static int intel_pt_walk_fup(struct intel_pt_decoder *decoder)
 		if (err == INTEL_PT_RETURN)
 			return 0;
 		if (err == -EAGAIN) {
-			if (decoder->set_fup_tx_flags) {
-				decoder->set_fup_tx_flags = false;
-				decoder->tx_flags = decoder->fup_tx_flags;
-				decoder->state.type = INTEL_PT_TRANSACTION;
-				decoder->state.from_ip = decoder->ip;
-				decoder->state.to_ip = 0;
-				decoder->state.flags = decoder->fup_tx_flags;
+			if (intel_pt_fup_event(decoder))
 				return 0;
-			}
 			return err;
 		}
 		decoder->set_fup_tx_flags = false;
@@ -1443,6 +1501,13 @@ static int intel_pt_walk_psbend(struct intel_pt_decoder *decoder)
 		case INTEL_PT_TRACESTOP:
 		case INTEL_PT_BAD:
 		case INTEL_PT_PSB:
+		case INTEL_PT_PTWRITE:
+		case INTEL_PT_PTWRITE_IP:
+		case INTEL_PT_EXSTOP:
+		case INTEL_PT_EXSTOP_IP:
+		case INTEL_PT_MWAIT:
+		case INTEL_PT_PWRE:
+		case INTEL_PT_PWRX:
 			decoder->have_tma = false;
 			intel_pt_log("ERROR: Unexpected packet\n");
 			return -EAGAIN;
@@ -1524,6 +1589,13 @@ static int intel_pt_walk_fup_tip(struct intel_pt_decoder *decoder)
 		case INTEL_PT_MODE_TSX:
 		case INTEL_PT_BAD:
 		case INTEL_PT_PSBEND:
+		case INTEL_PT_PTWRITE:
+		case INTEL_PT_PTWRITE_IP:
+		case INTEL_PT_EXSTOP:
+		case INTEL_PT_EXSTOP_IP:
+		case INTEL_PT_MWAIT:
+		case INTEL_PT_PWRE:
+		case INTEL_PT_PWRX:
 			intel_pt_log("ERROR: Missing TIP after FUP\n");
 			decoder->pkt_state = INTEL_PT_STATE_ERR3;
 			return -ENOENT;
@@ -1654,8 +1726,13 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)
 			intel_pt_set_last_ip(decoder);
 			if (!decoder->branch_enable) {
 				decoder->ip = decoder->last_ip;
+				if (intel_pt_fup_event(decoder))
+					return 0;
+				no_tip = false;
 				break;
 			}
+			if (decoder->set_fup_mwait)
+				no_tip = true;
 			err = intel_pt_walk_fup(decoder);
 			if (err != -EAGAIN) {
 				if (err)
@@ -1755,6 +1832,71 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)
 		case INTEL_PT_PAD:
 			break;
 
+		case INTEL_PT_PTWRITE_IP:
+			decoder->fup_ptw_payload = decoder->packet.payload;
+			err = intel_pt_get_next_packet(decoder);
+			if (err)
+				return err;
+			if (decoder->packet.type == INTEL_PT_FUP) {
+				decoder->set_fup_ptw = true;
+				no_tip = true;
+			} else {
+				intel_pt_log_at("ERROR: Missing FUP after PTWRITE",
+						decoder->pos);
+			}
+			goto next;
+
+		case INTEL_PT_PTWRITE:
+			decoder->state.type = INTEL_PT_PTW;
+			decoder->state.from_ip = decoder->ip;
+			decoder->state.to_ip = 0;
+			decoder->state.ptw_payload = decoder->packet.payload;
+			return 0;
+
+		case INTEL_PT_MWAIT:
+			decoder->fup_mwait_payload = decoder->packet.payload;
+			decoder->set_fup_mwait = true;
+			break;
+
+		case INTEL_PT_PWRE:
+			if (decoder->set_fup_mwait) {
+				decoder->fup_pwre_payload =
+							decoder->packet.payload;
+				decoder->set_fup_pwre = true;
+				break;
+			}
+			decoder->state.type = INTEL_PT_PWR_ENTRY;
+			decoder->state.from_ip = decoder->ip;
+			decoder->state.to_ip = 0;
+			decoder->state.pwrx_payload = decoder->packet.payload;
+			return 0;
+
+		case INTEL_PT_EXSTOP_IP:
+			err = intel_pt_get_next_packet(decoder);
+			if (err)
+				return err;
+			if (decoder->packet.type == INTEL_PT_FUP) {
+				decoder->set_fup_exstop = true;
+				no_tip = true;
+			} else {
+				intel_pt_log_at("ERROR: Missing FUP after EXSTOP",
+						decoder->pos);
+			}
+			goto next;
+
+		case INTEL_PT_EXSTOP:
+			decoder->state.type = INTEL_PT_EX_STOP;
+			decoder->state.from_ip = decoder->ip;
+			decoder->state.to_ip = 0;
+			return 0;
+
+		case INTEL_PT_PWRX:
+			decoder->state.type = INTEL_PT_PWR_EXIT;
+			decoder->state.from_ip = decoder->ip;
+			decoder->state.to_ip = 0;
+			decoder->state.pwrx_payload = decoder->packet.payload;
+			return 0;
+
 		default:
 			return intel_pt_bug(decoder);
 		}
@@ -1784,6 +1926,13 @@ static int intel_pt_walk_psb(struct intel_pt_decoder *decoder)
 			__fallthrough;
 		case INTEL_PT_TIP_PGE:
 		case INTEL_PT_TIP:
+		case INTEL_PT_PTWRITE:
+		case INTEL_PT_PTWRITE_IP:
+		case INTEL_PT_EXSTOP:
+		case INTEL_PT_EXSTOP_IP:
+		case INTEL_PT_MWAIT:
+		case INTEL_PT_PWRE:
+		case INTEL_PT_PWRX:
 			intel_pt_log("ERROR: Unexpected packet\n");
 			return -ENOENT;
 
@@ -1958,6 +2107,13 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)
 		case INTEL_PT_VMCS:
 		case INTEL_PT_MNT:
 		case INTEL_PT_PAD:
+		case INTEL_PT_PTWRITE:
+		case INTEL_PT_PTWRITE_IP:
+		case INTEL_PT_EXSTOP:
+		case INTEL_PT_EXSTOP_IP:
+		case INTEL_PT_MWAIT:
+		case INTEL_PT_PWRE:
+		case INTEL_PT_PWRX:
 		default:
 			break;
 		}
@@ -1969,6 +2125,10 @@ static int intel_pt_sync_ip(struct intel_pt_decoder *decoder)
 	int err;
 
 	decoder->set_fup_tx_flags = false;
+	decoder->set_fup_ptw = false;
+	decoder->set_fup_mwait = false;
+	decoder->set_fup_pwre = false;
+	decoder->set_fup_exstop = false;
 
 	if (!decoder->branch_enable) {
 		decoder->pkt_state = INTEL_PT_STATE_IN_SYNC;
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
index add3bed58349..414c88e9e0da 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
@@ -25,11 +25,17 @@
 #define INTEL_PT_IN_TX		(1 << 0)
 #define INTEL_PT_ABORT_TX	(1 << 1)
 #define INTEL_PT_ASYNC		(1 << 2)
+#define INTEL_PT_FUP_IP		(1 << 3)
 
 enum intel_pt_sample_type {
 	INTEL_PT_BRANCH		= 1 << 0,
 	INTEL_PT_INSTRUCTION	= 1 << 1,
 	INTEL_PT_TRANSACTION	= 1 << 2,
+	INTEL_PT_PTW		= 1 << 3,
+	INTEL_PT_MWAIT_OP	= 1 << 4,
+	INTEL_PT_PWR_ENTRY	= 1 << 5,
+	INTEL_PT_EX_STOP	= 1 << 6,
+	INTEL_PT_PWR_EXIT	= 1 << 7,
 };
 
 enum intel_pt_period_type {
@@ -63,6 +69,10 @@ struct intel_pt_state {
 	uint64_t timestamp;
 	uint64_t est_timestamp;
 	uint64_t trace_nr;
+	uint64_t ptw_payload;
+	uint64_t mwait_payload;
+	uint64_t pwre_payload;
+	uint64_t pwrx_payload;
 	uint32_t flags;
 	enum intel_pt_insn_op insn_op;
 	int insn_len;
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
index 7528ae4f7e28..accdb646a03d 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
@@ -64,6 +64,13 @@
 	[INTEL_PT_PIP]		= "PIP",
 	[INTEL_PT_OVF]		= "OVF",
 	[INTEL_PT_MNT]		= "MNT",
+	[INTEL_PT_PTWRITE]	= "PTWRITE",
+	[INTEL_PT_PTWRITE_IP]	= "PTWRITE",
+	[INTEL_PT_EXSTOP]	= "EXSTOP",
+	[INTEL_PT_EXSTOP_IP]	= "EXSTOP",
+	[INTEL_PT_MWAIT]	= "MWAIT",
+	[INTEL_PT_PWRE]		= "PWRE",
+	[INTEL_PT_PWRX]		= "PWRX",
 };
 
 const char *intel_pt_pkt_name(enum intel_pt_pkt_type type)
@@ -217,12 +224,80 @@ static int intel_pt_get_3byte(const unsigned char *buf, size_t len,
 	}
 }
 
+static int intel_pt_get_ptwrite(const unsigned char *buf, size_t len,
+				struct intel_pt_pkt *packet)
+{
+	packet->count = (buf[1] >> 5) & 0x3;
+	packet->type = buf[1] & BIT(7) ? INTEL_PT_PTWRITE_IP :
+					 INTEL_PT_PTWRITE;
+
+	switch (packet->count) {
+	case 0:
+		if (len < 6)
+			return INTEL_PT_NEED_MORE_BYTES;
+		packet->payload = le32_to_cpu(*(uint32_t *)(buf + 2));
+		return 6;
+	case 1:
+		if (len < 10)
+			return INTEL_PT_NEED_MORE_BYTES;
+		packet->payload = le64_to_cpu(*(uint64_t *)(buf + 2));
+		return 10;
+	default:
+		return INTEL_PT_BAD_PACKET;
+	}
+}
+
+static int intel_pt_get_exstop(struct intel_pt_pkt *packet)
+{
+	packet->type = INTEL_PT_EXSTOP;
+	return 2;
+}
+
+static int intel_pt_get_exstop_ip(struct intel_pt_pkt *packet)
+{
+	packet->type = INTEL_PT_EXSTOP_IP;
+	return 2;
+}
+
+static int intel_pt_get_mwait(const unsigned char *buf, size_t len,
+			      struct intel_pt_pkt *packet)
+{
+	if (len < 10)
+		return INTEL_PT_NEED_MORE_BYTES;
+	packet->type = INTEL_PT_MWAIT;
+	packet->payload = le64_to_cpu(*(uint64_t *)(buf + 2));
+	return 10;
+}
+
+static int intel_pt_get_pwre(const unsigned char *buf, size_t len,
+			     struct intel_pt_pkt *packet)
+{
+	if (len < 4)
+		return INTEL_PT_NEED_MORE_BYTES;
+	packet->type = INTEL_PT_PWRE;
+	memcpy_le64(&packet->payload, buf + 2, 2);
+	return 4;
+}
+
+static int intel_pt_get_pwrx(const unsigned char *buf, size_t len,
+			     struct intel_pt_pkt *packet)
+{
+	if (len < 7)
+		return INTEL_PT_NEED_MORE_BYTES;
+	packet->type = INTEL_PT_PWRX;
+	memcpy_le64(&packet->payload, buf + 2, 5);
+	return 7;
+}
+
 static int intel_pt_get_ext(const unsigned char *buf, size_t len,
 			    struct intel_pt_pkt *packet)
 {
 	if (len < 2)
 		return INTEL_PT_NEED_MORE_BYTES;
 
+	if ((buf[1] & 0x1f) == 0x12)
+		return intel_pt_get_ptwrite(buf, len, packet);
+
 	switch (buf[1]) {
 	case 0xa3: /* Long TNT */
 		return intel_pt_get_long_tnt(buf, len, packet);
@@ -244,6 +319,16 @@ static int intel_pt_get_ext(const unsigned char *buf, size_t len,
 		return intel_pt_get_tma(buf, len, packet);
 	case 0xC3: /* 3-byte header */
 		return intel_pt_get_3byte(buf, len, packet);
+	case 0x62: /* EXSTOP no IP */
+		return intel_pt_get_exstop(packet);
+	case 0xE2: /* EXSTOP with IP */
+		return intel_pt_get_exstop_ip(packet);
+	case 0xC2: /* MWAIT */
+		return intel_pt_get_mwait(buf, len, packet);
+	case 0x22: /* PWRE */
+		return intel_pt_get_pwre(buf, len, packet);
+	case 0xA2: /* PWRX */
+		return intel_pt_get_pwrx(buf, len, packet);
 	default:
 		return INTEL_PT_BAD_PACKET;
 	}
@@ -522,6 +607,29 @@ int intel_pt_pkt_desc(const struct intel_pt_pkt *packet, char *buf,
 		ret = snprintf(buf, buf_len, "%s 0x%llx (NR=%d)",
 			       name, payload, nr);
 		return ret;
+	case INTEL_PT_PTWRITE:
+		return snprintf(buf, buf_len, "%s 0x%llx IP:0", name, payload);
+	case INTEL_PT_PTWRITE_IP:
+		return snprintf(buf, buf_len, "%s 0x%llx IP:1", name, payload);
+	case INTEL_PT_EXSTOP:
+		return snprintf(buf, buf_len, "%s IP:0", name);
+	case INTEL_PT_EXSTOP_IP:
+		return snprintf(buf, buf_len, "%s IP:1", name);
+	case INTEL_PT_MWAIT:
+		return snprintf(buf, buf_len, "%s 0x%llx Hints 0x%x Extensions 0x%x",
+				name, payload, (unsigned int)(payload & 0xff),
+				(unsigned int)((payload >> 32) & 0x3));
+	case INTEL_PT_PWRE:
+		return snprintf(buf, buf_len, "%s 0x%llx HW:%u CState:%u Sub-CState:%u",
+				name, payload, !!(payload & 0x80),
+				(unsigned int)((payload >> 12) & 0xf),
+				(unsigned int)((payload >> 8) & 0xf));
+	case INTEL_PT_PWRX:
+		return snprintf(buf, buf_len, "%s 0x%llx Last CState:%u Deepest CState:%u Wake Reason 0x%x",
+				name, payload,
+				(unsigned int)((payload >> 4) & 0xf),
+				(unsigned int)(payload & 0xf),
+				(unsigned int)((payload >> 8) & 0xf));
 	default:
 		break;
 	}
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.h b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.h
index 781bb79883bd..73ddc3a88d07 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.h
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.h
@@ -52,6 +52,13 @@ enum intel_pt_pkt_type {
 	INTEL_PT_PIP,
 	INTEL_PT_OVF,
 	INTEL_PT_MNT,
+	INTEL_PT_PTWRITE,
+	INTEL_PT_PTWRITE_IP,
+	INTEL_PT_EXSTOP,
+	INTEL_PT_EXSTOP_IP,
+	INTEL_PT_MWAIT,
+	INTEL_PT_PWRE,
+	INTEL_PT_PWRX,
 };
 
 struct intel_pt_pkt {
-- 
1.9.1

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

* [PATCH V2 14/37] perf intel-pt: Add reserved byte to CBR packet payload
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (12 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 13/37] perf intel-pt: Add decoder support for ptwrite and power event packets Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (23 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Future proof CBR packet decoding by passing through also the undefined
'reserved' byte in the packet payload.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c     | 2 +-
 tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index e42804d10001..96bf8d8e83c0 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -1444,7 +1444,7 @@ static void intel_pt_calc_mtc_timestamp(struct intel_pt_decoder *decoder)
 
 static void intel_pt_calc_cbr(struct intel_pt_decoder *decoder)
 {
-	unsigned int cbr = decoder->packet.payload;
+	unsigned int cbr = decoder->packet.payload & 0xff;
 
 	if (decoder->cbr == cbr)
 		return;
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
index accdb646a03d..ba4c9dd18643 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
@@ -130,7 +130,7 @@ static int intel_pt_get_cbr(const unsigned char *buf, size_t len,
 	if (len < 4)
 		return INTEL_PT_NEED_MORE_BYTES;
 	packet->type = INTEL_PT_CBR;
-	packet->payload = buf[2];
+	packet->payload = le16_to_cpu(*(uint16_t *)(buf + 2));
 	return 4;
 }
 
-- 
1.9.1

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

* [PATCH V2 15/37] perf intel-pt: Add decoder support for CBR events
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (13 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 14/37] perf intel-pt: Add reserved byte to CBR packet payload Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (22 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Add decoder support for informing the tools of changes to the core-to-bus
ratio (CBR).

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 19 +++++++++++++++++++
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.h |  2 ++
 2 files changed, 21 insertions(+)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 96bf8d8e83c0..5dea06289db5 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -141,6 +141,7 @@ struct intel_pt_decoder {
 	int pkt_len;
 	int last_packet_type;
 	unsigned int cbr;
+	unsigned int cbr_seen;
 	unsigned int max_non_turbo_ratio;
 	double max_non_turbo_ratio_fp;
 	double cbr_cyc_to_tsc;
@@ -167,6 +168,7 @@ struct intel_pt_decoder {
 	uint64_t fup_ptw_payload;
 	uint64_t fup_mwait_payload;
 	uint64_t fup_pwre_payload;
+	uint64_t cbr_payload;
 	uint64_t timestamp_insn_cnt;
 	uint64_t sample_insn_cnt;
 	uint64_t stuck_ip;
@@ -1446,6 +1448,8 @@ static void intel_pt_calc_cbr(struct intel_pt_decoder *decoder)
 {
 	unsigned int cbr = decoder->packet.payload & 0xff;
 
+	decoder->cbr_payload = decoder->packet.payload;
+
 	if (decoder->cbr == cbr)
 		return;
 
@@ -1806,6 +1810,16 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)
 
 		case INTEL_PT_CBR:
 			intel_pt_calc_cbr(decoder);
+			if (!decoder->branch_enable &&
+			    decoder->cbr != decoder->cbr_seen) {
+				decoder->cbr_seen = decoder->cbr;
+				decoder->state.type = INTEL_PT_CBR_CHG;
+				decoder->state.from_ip = decoder->ip;
+				decoder->state.to_ip = 0;
+				decoder->state.cbr_payload =
+							decoder->packet.payload;
+				return 0;
+			}
 			break;
 
 		case INTEL_PT_MODE_EXEC:
@@ -2343,6 +2357,11 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)
 		decoder->sample_insn_cnt = decoder->timestamp_insn_cnt;
 	} else {
 		decoder->state.err = 0;
+		if (decoder->cbr != decoder->cbr_seen && decoder->state.type) {
+			decoder->cbr_seen = decoder->cbr;
+			decoder->state.type |= INTEL_PT_CBR_CHG;
+			decoder->state.cbr_payload = decoder->cbr_payload;
+		}
 		if (intel_pt_sample_time(decoder->pkt_state)) {
 			decoder->sample_timestamp = decoder->timestamp;
 			decoder->sample_insn_cnt = decoder->timestamp_insn_cnt;
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
index 414c88e9e0da..921b22e8ca0e 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
@@ -36,6 +36,7 @@ enum intel_pt_sample_type {
 	INTEL_PT_PWR_ENTRY	= 1 << 5,
 	INTEL_PT_EX_STOP	= 1 << 6,
 	INTEL_PT_PWR_EXIT	= 1 << 7,
+	INTEL_PT_CBR_CHG	= 1 << 8,
 };
 
 enum intel_pt_period_type {
@@ -73,6 +74,7 @@ struct intel_pt_state {
 	uint64_t mwait_payload;
 	uint64_t pwre_payload;
 	uint64_t pwrx_payload;
+	uint64_t cbr_payload;
 	uint32_t flags;
 	enum intel_pt_insn_op insn_op;
 	int insn_len;
-- 
1.9.1

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

* [PATCH V2 16/37] perf intel-pt: Remove redundant initial_skip checks
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (14 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 15/37] perf intel-pt: Add decoder support for CBR events Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (21 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

'initial_skip' is checked inside the sample synthesis functions which means
it is actually being done twice for 'instructions' and 'transactions'
samples. Remove the redundant checks.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/intel-pt.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 5c59b8c6a719..3ae03f920253 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1322,18 +1322,14 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)
 	ptq->have_sample = false;
 
 	if (pt->sample_instructions &&
-	    (state->type & INTEL_PT_INSTRUCTION) &&
-	    (!pt->synth_opts.initial_skip ||
-	     pt->num_events++ >= pt->synth_opts.initial_skip)) {
+	    (state->type & INTEL_PT_INSTRUCTION)) {
 		err = intel_pt_synth_instruction_sample(ptq);
 		if (err)
 			return err;
 	}
 
 	if (pt->sample_transactions &&
-	    (state->type & INTEL_PT_TRANSACTION) &&
-	    (!pt->synth_opts.initial_skip ||
-	     pt->num_events++ >= pt->synth_opts.initial_skip)) {
+	    (state->type & INTEL_PT_TRANSACTION)) {
 		err = intel_pt_synth_transaction_sample(ptq);
 		if (err)
 			return err;
-- 
1.9.1

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

* [PATCH V2 17/37] perf intel-pt: Fix transactions_sample_type
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (15 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 16/37] perf intel-pt: Remove redundant initial_skip checks Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (20 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

'transactions_sample_type' is needed to correctly inject transactions
samples but it was not being set. Set it from the event sample type.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/intel-pt.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 3ae03f920253..6df836469f2b 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -2035,6 +2035,7 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 			return err;
 		}
 		pt->sample_transactions = true;
+		pt->transactions_sample_type = attr.sample_type;
 		pt->transactions_id = id;
 		id += 1;
 		evlist__for_each_entry(evlist, evsel) {
-- 
1.9.1

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

* [PATCH V2 18/37] perf tools: Fix message because cpu list option is -C not -c
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (16 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 17/37] perf intel-pt: Fix transactions_sample_type Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (19 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Fix message because cpu list option is -C not -c

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/session.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 7dc1096264c5..d19c40a81040 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -2035,7 +2035,7 @@ int perf_session__cpu_bitmap(struct perf_session *session,
 
 		if (!(evsel->attr.sample_type & PERF_SAMPLE_CPU)) {
 			pr_err("File does not contain CPU events. "
-			       "Remove -c option to proceed.\n");
+			       "Remove -C option to proceed.\n");
 			return -1;
 		}
 	}
-- 
1.9.1

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

* [PATCH V2 19/37] perf script: Fix message because field list option is -F not -f
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (17 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 18/37] perf tools: Fix message because cpu list option is -C not -c Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (18 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Fix message because field list option is -F not -f.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/builtin-script.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index d05aec491cff..79a101e0e13b 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -383,7 +383,7 @@ static int perf_session__check_output_opt(struct perf_session *session)
 		 */
 		if (!evsel && output[j].user_set && !output[j].wildcard_set) {
 			pr_err("%s events do not exist. "
-			       "Remove corresponding -f option to proceed.\n",
+			       "Remove corresponding -F option to proceed.\n",
 			       event_type(j));
 			return -1;
 		}
-- 
1.9.1

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

* [PATCH V2 20/37] perf script: Add 'synth' event type for synthesized events
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (18 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 19/37] perf script: Fix message because field list option is -F not -f Adrian Hunter
@ 2017-05-26  8:17 ` Adrian Hunter
  2017-06-21 10:17   ` [PATCH V3 " Adrian Hunter
  2017-05-26  8:17 ` [PATCH V2 21/37] perf script: Add 'synth' field for synthesized event payloads Adrian Hunter
                   ` (17 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Instruction trace decoders such as Intel PT may have additional information
recorded in the trace. For example, Intel PT has power information and a
there is a new instruction 'ptwrite' that can write a value into a PTWRITE
trace packet. Such information may be associated with an IP and so can be
treated as a sample (PERF_RECORD_SAMPLE). Custom data can be incorporated
in the sample as raw_data (PERF_SAMPLE_RAW). However a means of identifying
the raw data format is needed. That will be done by synthesizing an
attribute for it. So add an attribute type for custom synthesized events.
Different synthesized events will be identified by the attribute 'config'.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/builtin-script.c | 74 +++++++++++++++++++++++++++++++++++----------
 tools/perf/util/event.h     |  3 ++
 2 files changed, 61 insertions(+), 16 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 79a101e0e13b..99167bafe81c 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -117,6 +117,11 @@ struct output_option {
 	{.str = "brstackinsn", .field = PERF_OUTPUT_BRSTACKINSN},
 };
 
+enum {
+	OUTPUT_TYPE_SYNTH = PERF_TYPE_MAX,
+	OUTPUT_TYPE_MAX
+};
+
 /* default set to maintain compatibility with current format */
 static struct {
 	bool user_set;
@@ -124,7 +129,7 @@ struct output_option {
 	unsigned int print_ip_opts;
 	u64 fields;
 	u64 invalid_fields;
-} output[PERF_TYPE_MAX] = {
+} output[OUTPUT_TYPE_MAX] = {
 
 	[PERF_TYPE_HARDWARE] = {
 		.user_set = false,
@@ -182,12 +187,43 @@ struct output_option {
 
 		.invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
 	},
+
+	[OUTPUT_TYPE_SYNTH] = {
+		.user_set = false,
+
+		.fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
+			      PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
+			      PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
+			      PERF_OUTPUT_SYM | PERF_OUTPUT_DSO,
+
+		.invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
+	},
 };
 
+static inline int output_type(unsigned int type)
+{
+	switch (type) {
+	case PERF_TYPE_SYNTH:
+		return OUTPUT_TYPE_SYNTH;
+	default:
+		return type;
+	}
+}
+
+static inline unsigned int attr_type(unsigned int type)
+{
+	switch (type) {
+	case OUTPUT_TYPE_SYNTH:
+		return PERF_TYPE_SYNTH;
+	default:
+		return type;
+	}
+}
+
 static bool output_set_by_user(void)
 {
 	int j;
-	for (j = 0; j < PERF_TYPE_MAX; ++j) {
+	for (j = 0; j < OUTPUT_TYPE_MAX; ++j) {
 		if (output[j].user_set)
 			return true;
 	}
@@ -208,7 +244,7 @@ static const char *output_field2str(enum perf_output_field field)
 	return str;
 }
 
-#define PRINT_FIELD(x)  (output[attr->type].fields & PERF_OUTPUT_##x)
+#define PRINT_FIELD(x)  (output[output_type(attr->type)].fields & PERF_OUTPUT_##x)
 
 static int perf_evsel__do_check_stype(struct perf_evsel *evsel,
 				      u64 sample_type, const char *sample_msg,
@@ -216,7 +252,7 @@ static int perf_evsel__do_check_stype(struct perf_evsel *evsel,
 				      bool allow_user_set)
 {
 	struct perf_event_attr *attr = &evsel->attr;
-	int type = attr->type;
+	int type = output_type(attr->type);
 	const char *evname;
 
 	if (attr->sample_type & sample_type)
@@ -346,7 +382,7 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,
 
 static void set_print_ip_opts(struct perf_event_attr *attr)
 {
-	unsigned int type = attr->type;
+	unsigned int type = output_type(attr->type);
 
 	output[type].print_ip_opts = 0;
 	if (PRINT_FIELD(IP))
@@ -374,14 +410,15 @@ static int perf_session__check_output_opt(struct perf_session *session)
 	unsigned int j;
 	struct perf_evsel *evsel;
 
-	for (j = 0; j < PERF_TYPE_MAX; ++j) {
-		evsel = perf_session__find_first_evtype(session, j);
+	for (j = 0; j < OUTPUT_TYPE_MAX; ++j) {
+		evsel = perf_session__find_first_evtype(session, attr_type(j));
 
 		/*
 		 * even if fields is set to 0 (ie., show nothing) event must
 		 * exist if user explicitly includes it on the command line
 		 */
-		if (!evsel && output[j].user_set && !output[j].wildcard_set) {
+		if (!evsel && output[j].user_set && !output[j].wildcard_set &&
+		    j != OUTPUT_TYPE_SYNTH) {
 			pr_err("%s events do not exist. "
 			       "Remove corresponding -F option to proceed.\n",
 			       event_type(j));
@@ -906,6 +943,7 @@ static void print_sample_bts(struct perf_sample *sample,
 			     struct machine *machine)
 {
 	struct perf_event_attr *attr = &evsel->attr;
+	unsigned int type = output_type(attr->type);
 	bool print_srcline_last = false;
 
 	if (PRINT_FIELD(CALLINDENT))
@@ -913,7 +951,7 @@ static void print_sample_bts(struct perf_sample *sample,
 
 	/* print branch_from information */
 	if (PRINT_FIELD(IP)) {
-		unsigned int print_opts = output[attr->type].print_ip_opts;
+		unsigned int print_opts = output[type].print_ip_opts;
 		struct callchain_cursor *cursor = NULL;
 
 		if (symbol_conf.use_callchain && sample->callchain &&
@@ -936,7 +974,7 @@ static void print_sample_bts(struct perf_sample *sample,
 	/* print branch_to information */
 	if (PRINT_FIELD(ADDR) ||
 	    ((evsel->attr.sample_type & PERF_SAMPLE_ADDR) &&
-	     !output[attr->type].user_set)) {
+	     !output[type].user_set)) {
 		printf(" => ");
 		print_sample_addr(sample, thread, attr);
 	}
@@ -1132,8 +1170,9 @@ static void process_event(struct perf_script *script,
 {
 	struct thread *thread = al->thread;
 	struct perf_event_attr *attr = &evsel->attr;
+	unsigned int type = output_type(attr->type);
 
-	if (output[attr->type].fields == 0)
+	if (output[type].fields == 0)
 		return;
 
 	print_sample_start(sample, thread, evsel);
@@ -1180,7 +1219,7 @@ static void process_event(struct perf_script *script,
 			cursor = &callchain_cursor;
 
 		putchar(cursor ? '\n' : ' ');
-		sample__fprintf_sym(sample, al, 0, output[attr->type].print_ip_opts, cursor, stdout);
+		sample__fprintf_sym(sample, al, 0, output[type].print_ip_opts, cursor, stdout);
 	}
 
 	if (PRINT_FIELD(IREGS))
@@ -1325,7 +1364,8 @@ static int process_attr(struct perf_tool *tool, union perf_event *event,
 	evlist = *pevlist;
 	evsel = perf_evlist__last(*pevlist);
 
-	if (evsel->attr.type >= PERF_TYPE_MAX)
+	if (evsel->attr.type >= PERF_TYPE_MAX &&
+	    evsel->attr.type != PERF_TYPE_SYNTH)
 		return 0;
 
 	evlist__for_each_entry(evlist, pos) {
@@ -1749,6 +1789,8 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
 			type = PERF_TYPE_RAW;
 		else if (!strcmp(str, "break"))
 			type = PERF_TYPE_BREAKPOINT;
+		else if (!strcmp(str, "synth"))
+			type = OUTPUT_TYPE_SYNTH;
 		else {
 			fprintf(stderr, "Invalid event type in field string.\n");
 			rc = -EINVAL;
@@ -1775,7 +1817,7 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
 		if (output_set_by_user())
 			pr_warning("Overriding previous field request for all events.\n");
 
-		for (j = 0; j < PERF_TYPE_MAX; ++j) {
+		for (j = 0; j < OUTPUT_TYPE_MAX; ++j) {
 			output[j].fields = 0;
 			output[j].user_set = true;
 			output[j].wildcard_set = true;
@@ -1801,7 +1843,7 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
 			/* add user option to all events types for
 			 * which it is valid
 			 */
-			for (j = 0; j < PERF_TYPE_MAX; ++j) {
+			for (j = 0; j < OUTPUT_TYPE_MAX; ++j) {
 				if (output[j].invalid_fields & all_output_options[i].field) {
 					pr_warning("\'%s\' not valid for %s events. Ignoring.\n",
 						   all_output_options[i].str, event_type(j));
@@ -2444,7 +2486,7 @@ int cmd_script(int argc, const char **argv)
 		     symbol__config_symfs),
 	OPT_CALLBACK('F', "fields", NULL, "str",
 		     "comma separated output fields prepend with 'type:'. "
-		     "Valid types: hw,sw,trace,raw. "
+		     "Valid types: hw,sw,trace,raw,synth. "
 		     "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
 		     "addr,symoff,period,iregs,brstack,brstacksym,flags,"
 		     "bpf-output,callindent,insn,insnlen,brstackinsn",
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 27ac047490c3..af285ed951f4 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -252,6 +252,9 @@ enum auxtrace_error_type {
 	PERF_AUXTRACE_ERROR_MAX
 };
 
+/* Attribute type for custom synthesized events */
+#define PERF_TYPE_SYNTH		3000000000
+
 /*
  * 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

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

* [PATCH V2 21/37] perf script: Add 'synth' field for synthesized event payloads
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (19 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 20/37] perf script: Add 'synth' event type for synthesized events Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (16 subsequent siblings)
  37 siblings, 2 replies; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Add a field to display the content the raw_data of a synthesized event.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/Documentation/perf-script.txt |  6 +++++-
 tools/perf/builtin-script.c              | 20 ++++++++++++++++++--
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index cb0eda3925e6..43770f174f64 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -117,7 +117,8 @@ OPTIONS
         Comma separated list of fields to print. Options are:
         comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
         srcline, period, iregs, brstack, brstacksym, flags, bpf-output, brstackinsn,
-        callindent, insn, insnlen. Field list can be prepended with the type, trace, sw or hw,
+        callindent, insn, insnlen, synth.
+        Field list can be prepended with the type, trace, sw or hw,
         to indicate to which event type the field list applies.
         e.g., -F sw:comm,tid,time,ip,sym  and -F trace:time,cpu,trace
 
@@ -185,6 +186,9 @@ OPTIONS
 	instruction bytes and the instruction length of the current
 	instruction.
 
+	The synth field is used by synthesized events which may be created when
+	Instruction Trace decoding.
+
 	Finally, a user may not set fields to none for all event types.
 	i.e., -F "" is not allowed.
 
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 99167bafe81c..f7a5130d2fd0 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -85,6 +85,7 @@ enum perf_output_field {
 	PERF_OUTPUT_INSN	    = 1U << 21,
 	PERF_OUTPUT_INSNLEN	    = 1U << 22,
 	PERF_OUTPUT_BRSTACKINSN	    = 1U << 23,
+	PERF_OUTPUT_SYNTH	    = 1U << 24,
 };
 
 struct output_option {
@@ -115,6 +116,7 @@ struct output_option {
 	{.str = "insn", .field = PERF_OUTPUT_INSN},
 	{.str = "insnlen", .field = PERF_OUTPUT_INSNLEN},
 	{.str = "brstackinsn", .field = PERF_OUTPUT_BRSTACKINSN},
+	{.str = "synth", .field = PERF_OUTPUT_SYNTH},
 };
 
 enum {
@@ -194,7 +196,8 @@ enum {
 		.fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
 			      PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
 			      PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
-			      PERF_OUTPUT_SYM | PERF_OUTPUT_DSO,
+			      PERF_OUTPUT_SYM | PERF_OUTPUT_DSO |
+			      PERF_OUTPUT_SYNTH,
 
 		.invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
 	},
@@ -1117,6 +1120,15 @@ 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,
+			       struct perf_evsel *evsel)
+{
+	switch (evsel->attr.config) {
+	default:
+		break;
+	}
+}
+
 struct perf_script {
 	struct perf_tool	tool;
 	struct perf_session	*session;
@@ -1201,6 +1213,10 @@ static void process_event(struct perf_script *script,
 	if (PRINT_FIELD(TRACE))
 		event_format__print(evsel->tp_format, sample->cpu,
 				    sample->raw_data, sample->raw_size);
+
+	if (attr->type == PERF_TYPE_SYNTH && PRINT_FIELD(SYNTH))
+		print_sample_synth(sample, evsel);
+
 	if (PRINT_FIELD(ADDR))
 		print_sample_addr(sample, thread, attr);
 
@@ -2489,7 +2505,7 @@ int cmd_script(int argc, const char **argv)
 		     "Valid types: hw,sw,trace,raw,synth. "
 		     "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
 		     "addr,symoff,period,iregs,brstack,brstacksym,flags,"
-		     "bpf-output,callindent,insn,insnlen,brstackinsn",
+		     "bpf-output,callindent,insn,insnlen,brstackinsn,synth",
 		     parse_output_fields),
 	OPT_BOOLEAN('a', "all-cpus", &system_wide,
 		    "system-wide collection from all CPUs"),
-- 
1.9.1

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

* [PATCH V2 22/37] tools include: Add byte-swapping macros to kernel.h
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (20 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 21/37] perf script: Add 'synth' field for synthesized event payloads Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (15 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Add byte-swapping macros to kernel.h

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/include/linux/kernel.h | 35 +++++++++++++++++++++++++++++------
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/tools/include/linux/kernel.h b/tools/include/linux/kernel.h
index 73ccc48126bb..039bb85e4171 100644
--- a/tools/include/linux/kernel.h
+++ b/tools/include/linux/kernel.h
@@ -5,6 +5,8 @@
 #include <stddef.h>
 #include <assert.h>
 #include <linux/compiler.h>
+#include <endian.h>
+#include <byteswap.h>
 
 #ifndef UINT_MAX
 #define UINT_MAX	(~0U)
@@ -67,12 +69,33 @@
 #endif
 #endif
 
-/*
- * Both need more care to handle endianness
- * (Don't use bitmap_copy_le() for now)
- */
-#define cpu_to_le64(x)	(x)
-#define cpu_to_le32(x)	(x)
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define cpu_to_le16 bswap_16
+#define cpu_to_le32 bswap_32
+#define cpu_to_le64 bswap_64
+#define le16_to_cpu bswap_16
+#define le32_to_cpu bswap_32
+#define le64_to_cpu bswap_64
+#define cpu_to_be16
+#define cpu_to_be32
+#define cpu_to_be64
+#define be16_to_cpu
+#define be32_to_cpu
+#define be64_to_cpu
+#else
+#define cpu_to_le16
+#define cpu_to_le32
+#define cpu_to_le64
+#define le16_to_cpu
+#define le32_to_cpu
+#define le64_to_cpu
+#define cpu_to_be16 bswap_16
+#define cpu_to_be32 bswap_32
+#define cpu_to_be64 bswap_64
+#define be16_to_cpu bswap_16
+#define be32_to_cpu bswap_32
+#define be64_to_cpu bswap_64
+#endif
 
 int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
 int scnprintf(char * buf, size_t size, const char * fmt, ...);
-- 
1.9.1

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

* [PATCH V2 23/37] perf auxtrace: Add itrace option to output ptwrite events
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (21 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 22/37] tools include: Add byte-swapping macros to kernel.h Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (14 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Add itrace option to output ptwrite events.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/Documentation/itrace.txt | 7 ++++---
 tools/perf/util/auxtrace.c          | 4 ++++
 tools/perf/util/auxtrace.h          | 2 ++
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Documentation/itrace.txt b/tools/perf/Documentation/itrace.txt
index e2a4c5e0dbe5..deafd16692b6 100644
--- a/tools/perf/Documentation/itrace.txt
+++ b/tools/perf/Documentation/itrace.txt
@@ -3,13 +3,14 @@
 		c	synthesize branches events (calls only)
 		r	synthesize branches events (returns only)
 		x	synthesize transactions events
+		w	synthesize ptwrite events
 		e	synthesize error events
 		d	create a debug log
 		g	synthesize a call chain (use with i or x)
 		l	synthesize last branch entries (use with i or x)
 		s       skip initial number of events
 
-	The default is all events i.e. the same as --itrace=ibxe
+	The default is all events i.e. the same as --itrace=ibxwe
 
 	In addition, the period (default 100000) for instructions events
 	can be specified in units of:
@@ -26,8 +27,8 @@
 	Also the number of last branch entries (default 64, max. 1024) for
 	instructions or transactions events can be specified.
 
-	It is also possible to skip events generated (instructions, branches, transactions)
-	at the beginning. This is useful to ignore initialization code.
+	It is also possible to skip events generated (instructions, branches, transactions,
+	ptwrite) at the beginning. This is useful to ignore initialization code.
 
 	--itrace=i0nss1000000
 
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index 0daf63b9ee3e..baad91ed1e05 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -947,6 +947,7 @@ void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts)
 	synth_opts->instructions = true;
 	synth_opts->branches = true;
 	synth_opts->transactions = true;
+	synth_opts->ptwrites = true;
 	synth_opts->errors = true;
 	synth_opts->period_type = PERF_ITRACE_DEFAULT_PERIOD_TYPE;
 	synth_opts->period = PERF_ITRACE_DEFAULT_PERIOD;
@@ -1030,6 +1031,9 @@ int itrace_parse_synth_opts(const struct option *opt, const char *str,
 		case 'x':
 			synth_opts->transactions = true;
 			break;
+		case 'w':
+			synth_opts->ptwrites = true;
+			break;
 		case 'e':
 			synth_opts->errors = true;
 			break;
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 9f0de72d58e2..b48afb2f18f3 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -59,6 +59,7 @@ enum itrace_period_type {
  * @instructions: whether to synthesize 'instructions' events
  * @branches: whether to synthesize 'branches' events
  * @transactions: whether to synthesize events for transactions
+ * @ptwrites: whether to synthesize events for ptwrites
  * @errors: whether to synthesize decoder error events
  * @dont_decode: whether to skip decoding entirely
  * @log: write a decoding log
@@ -79,6 +80,7 @@ struct itrace_synth_opts {
 	bool			instructions;
 	bool			branches;
 	bool			transactions;
+	bool			ptwrites;
 	bool			errors;
 	bool			dont_decode;
 	bool			log;
-- 
1.9.1

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

* [PATCH V2 24/37] perf auxtrace: Add itrace option to output power events
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (22 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 23/37] perf auxtrace: Add itrace option to output ptwrite events Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (13 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Add itrace option to output power events.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/Documentation/itrace.txt | 5 +++--
 tools/perf/util/auxtrace.c          | 4 ++++
 tools/perf/util/auxtrace.h          | 2 ++
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/itrace.txt b/tools/perf/Documentation/itrace.txt
index deafd16692b6..a3abe04c779d 100644
--- a/tools/perf/Documentation/itrace.txt
+++ b/tools/perf/Documentation/itrace.txt
@@ -4,13 +4,14 @@
 		r	synthesize branches events (returns only)
 		x	synthesize transactions events
 		w	synthesize ptwrite events
+		p	synthesize power events
 		e	synthesize error events
 		d	create a debug log
 		g	synthesize a call chain (use with i or x)
 		l	synthesize last branch entries (use with i or x)
 		s       skip initial number of events
 
-	The default is all events i.e. the same as --itrace=ibxwe
+	The default is all events i.e. the same as --itrace=ibxwpe
 
 	In addition, the period (default 100000) for instructions events
 	can be specified in units of:
@@ -28,7 +29,7 @@
 	instructions or transactions events can be specified.
 
 	It is also possible to skip events generated (instructions, branches, transactions,
-	ptwrite) at the beginning. This is useful to ignore initialization code.
+	ptwrite, power) at the beginning. This is useful to ignore initialization code.
 
 	--itrace=i0nss1000000
 
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index baad91ed1e05..651c01dfa5d3 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -948,6 +948,7 @@ void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts)
 	synth_opts->branches = true;
 	synth_opts->transactions = true;
 	synth_opts->ptwrites = true;
+	synth_opts->pwr_events = true;
 	synth_opts->errors = true;
 	synth_opts->period_type = PERF_ITRACE_DEFAULT_PERIOD_TYPE;
 	synth_opts->period = PERF_ITRACE_DEFAULT_PERIOD;
@@ -1034,6 +1035,9 @@ int itrace_parse_synth_opts(const struct option *opt, const char *str,
 		case 'w':
 			synth_opts->ptwrites = true;
 			break;
+		case 'p':
+			synth_opts->pwr_events = true;
+			break;
 		case 'e':
 			synth_opts->errors = true;
 			break;
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index b48afb2f18f3..68e0aa40b24a 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -60,6 +60,7 @@ enum itrace_period_type {
  * @branches: whether to synthesize 'branches' events
  * @transactions: whether to synthesize events for transactions
  * @ptwrites: whether to synthesize events for ptwrites
+ * @pwr_events: whether to synthesize power events
  * @errors: whether to synthesize decoder error events
  * @dont_decode: whether to skip decoding entirely
  * @log: write a decoding log
@@ -81,6 +82,7 @@ struct itrace_synth_opts {
 	bool			branches;
 	bool			transactions;
 	bool			ptwrites;
+	bool			pwr_events;
 	bool			errors;
 	bool			dont_decode;
 	bool			log;
-- 
1.9.1

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

* [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (23 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 24/37] perf auxtrace: Add itrace option to output power events Adrian Hunter
@ 2017-05-26  8:17 ` Adrian Hunter
  2017-06-28 13:04   ` Arnaldo Carvalho de Melo
  2017-06-30  8:36   ` [PATCH V3 " Adrian Hunter
  2017-05-26  8:17 ` [PATCH V2 26/37] perf intel-pt: Factor out common code synthesizing event samples Adrian Hunter
                   ` (12 subsequent siblings)
  37 siblings, 2 replies; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

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

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/builtin-script.c | 114 +++++++++++++++++++++++++++++++++++++++++++-
 tools/perf/util/event.h     |  90 ++++++++++++++++++++++++++++++++++
 2 files changed, 203 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index f7a5130d2fd0..4a13daacba25 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1120,10 +1120,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 = sample->raw_data;
+	int len;
+
+	if (sample->raw_size < sizeof(*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 = sample->raw_data;
+	int len;
+
+	if (sample->raw_size < sizeof(*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 = sample->raw_data;
+	int len;
+
+	if (sample->raw_size < sizeof(*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 = sample->raw_data;
+	int len;
+
+	if (sample->raw_size < sizeof(*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 = sample->raw_data;
+	int len;
+
+	if (sample->raw_size < sizeof(*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 = sample->raw_data;
+	unsigned int percent, freq;
+	int len;
+
+	if (sample->raw_size < sizeof(*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 af285ed951f4..7823d43315b7 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -255,6 +255,96 @@ enum auxtrace_error_type {
 /* Attribute type for custom synthesized events */
 #define PERF_TYPE_SYNTH		3000000000
 
+/* 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 raw data plus the raw data
+ * size (4 bytes) must align to 8-bytes.
+ */
+
+struct perf_synth_intel_ptwrite {
+	union {
+		struct {
+			u32	ip		:  1,
+				reserved	: 31;
+		};
+		u32	flags;
+	};
+	u64	payload;
+} __packed;
+
+struct perf_synth_intel_mwait {
+	u32 reserved;
+	union {
+		struct {
+			u64	hints		:  8,
+				reserved1	: 24,
+				extensions	:  2,
+				reserved2	: 30;
+		};
+		u64	payload;
+	};
+} __packed;
+
+struct perf_synth_intel_pwre {
+	u32 reserved;
+	union {
+		struct {
+			u64	reserved1	:  7,
+				hw		:  1,
+				subcstate	:  4,
+				cstate		:  4,
+				reserved2	: 48;
+		};
+		u64	payload;
+	};
+} __packed;
+
+struct perf_synth_intel_exstop {
+	union {
+		struct {
+			u32	ip		:  1,
+				reserved	: 31;
+		};
+		u32	flags;
+	};
+};
+
+struct perf_synth_intel_pwrx {
+	u32 reserved;
+	union {
+		struct {
+			u64	deepest_cstate	:  4,
+				last_cstate	:  4,
+				wake_reason	:  4,
+				reserved1	: 52;
+		};
+		u64	payload;
+	};
+} __packed;
+
+struct perf_synth_intel_cbr {
+	union {
+		struct {
+			u32	cbr		:  8,
+				reserved1	:  8,
+				max_nonturbo	:  8,
+				reserved2	:  8;
+		};
+		u32	flags;
+	};
+	u32 freq;
+	u32 reserved3;
+};
+
 /*
  * 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

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

* [PATCH V2 26/37] perf intel-pt: Factor out common code synthesizing event samples
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (24 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (11 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Factor out common code in functions synthesizing event samples i.e.
intel_pt_synth_branch_sample(), intel_pt_synth_instruction_sample() and
intel_pt_synth_transaction_sample().

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/intel-pt.c | 222 ++++++++++++++++++++-------------------------
 1 file changed, 100 insertions(+), 122 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 6df836469f2b..dbff5dca09f0 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1058,6 +1058,36 @@ static void intel_pt_update_last_branch_rb(struct intel_pt_queue *ptq)
 		bs->nr += 1;
 }
 
+static inline bool intel_pt_skip_event(struct intel_pt *pt)
+{
+	return pt->synth_opts.initial_skip &&
+	       pt->num_events++ < pt->synth_opts.initial_skip;
+}
+
+static void intel_pt_prep_b_sample(struct intel_pt *pt,
+				   struct intel_pt_queue *ptq,
+				   union perf_event *event,
+				   struct perf_sample *sample)
+{
+	event->sample.header.type = PERF_RECORD_SAMPLE;
+	event->sample.header.misc = PERF_RECORD_MISC_USER;
+	event->sample.header.size = sizeof(struct perf_event_header);
+
+	if (!pt->timeless_decoding)
+		sample->time = tsc_to_perf_time(ptq->timestamp, &pt->tc);
+
+	sample->cpumode = PERF_RECORD_MISC_USER;
+	sample->ip = ptq->state->from_ip;
+	sample->pid = ptq->pid;
+	sample->tid = ptq->tid;
+	sample->addr = ptq->state->to_ip;
+	sample->period = 1;
+	sample->cpu = ptq->cpu;
+	sample->flags = ptq->flags;
+	sample->insn_len = ptq->insn_len;
+	memcpy(sample->insn, ptq->insn, INTEL_PT_INSN_BUF_SZ);
+}
+
 static int intel_pt_inject_event(union perf_event *event,
 				 struct perf_sample *sample, u64 type,
 				 bool swapped)
@@ -1066,9 +1096,35 @@ static int intel_pt_inject_event(union perf_event *event,
 	return perf_event__synthesize_sample(event, type, 0, sample, swapped);
 }
 
-static int intel_pt_synth_branch_sample(struct intel_pt_queue *ptq)
+static inline int intel_pt_opt_inject(struct intel_pt *pt,
+				      union perf_event *event,
+				      struct perf_sample *sample, u64 type)
+{
+	if (!pt->synth_opts.inject)
+		return 0;
+
+	return intel_pt_inject_event(event, sample, type, pt->synth_needs_swap);
+}
+
+static int intel_pt_deliver_synth_b_event(struct intel_pt *pt,
+					  union perf_event *event,
+					  struct perf_sample *sample, u64 type)
 {
 	int ret;
+
+	ret = intel_pt_opt_inject(pt, event, sample, type);
+	if (ret)
+		return ret;
+
+	ret = perf_session__deliver_synth_event(pt->session, event, sample);
+	if (ret)
+		pr_err("Intel PT: failed to deliver event, error %d\n", ret);
+
+	return ret;
+}
+
+static int intel_pt_synth_branch_sample(struct intel_pt_queue *ptq)
+{
 	struct intel_pt *pt = ptq->pt;
 	union perf_event *event = ptq->event_buf;
 	struct perf_sample sample = { .ip = 0, };
@@ -1080,29 +1136,13 @@ static int intel_pt_synth_branch_sample(struct intel_pt_queue *ptq)
 	if (pt->branches_filter && !(pt->branches_filter & ptq->flags))
 		return 0;
 
-	if (pt->synth_opts.initial_skip &&
-	    pt->num_events++ < pt->synth_opts.initial_skip)
+	if (intel_pt_skip_event(pt))
 		return 0;
 
-	event->sample.header.type = PERF_RECORD_SAMPLE;
-	event->sample.header.misc = PERF_RECORD_MISC_USER;
-	event->sample.header.size = sizeof(struct perf_event_header);
+	intel_pt_prep_b_sample(pt, ptq, event, &sample);
 
-	if (!pt->timeless_decoding)
-		sample.time = tsc_to_perf_time(ptq->timestamp, &pt->tc);
-
-	sample.cpumode = PERF_RECORD_MISC_USER;
-	sample.ip = ptq->state->from_ip;
-	sample.pid = ptq->pid;
-	sample.tid = ptq->tid;
-	sample.addr = ptq->state->to_ip;
 	sample.id = ptq->pt->branches_id;
 	sample.stream_id = ptq->pt->branches_id;
-	sample.period = 1;
-	sample.cpu = ptq->cpu;
-	sample.flags = ptq->flags;
-	sample.insn_len = ptq->insn_len;
-	memcpy(sample.insn, ptq->insn, INTEL_PT_INSN_BUF_SZ);
 
 	/*
 	 * perf report cannot handle events without a branch stack when using
@@ -1119,78 +1159,38 @@ static int intel_pt_synth_branch_sample(struct intel_pt_queue *ptq)
 		sample.branch_stack = (struct branch_stack *)&dummy_bs;
 	}
 
-	if (pt->synth_opts.inject) {
-		ret = intel_pt_inject_event(event, &sample,
-					    pt->branches_sample_type,
-					    pt->synth_needs_swap);
-		if (ret)
-			return ret;
-	}
-
-	ret = perf_session__deliver_synth_event(pt->session, event, &sample);
-	if (ret)
-		pr_err("Intel Processor Trace: failed to deliver branch event, error %d\n",
-		       ret);
-
-	return ret;
+	return intel_pt_deliver_synth_b_event(pt, event, &sample,
+					      pt->branches_sample_type);
 }
 
-static int intel_pt_synth_instruction_sample(struct intel_pt_queue *ptq)
+static void intel_pt_prep_sample(struct intel_pt *pt,
+				 struct intel_pt_queue *ptq,
+				 union perf_event *event,
+				 struct perf_sample *sample)
 {
-	int ret;
-	struct intel_pt *pt = ptq->pt;
-	union perf_event *event = ptq->event_buf;
-	struct perf_sample sample = { .ip = 0, };
-
-	if (pt->synth_opts.initial_skip &&
-	    pt->num_events++ < pt->synth_opts.initial_skip)
-		return 0;
-
-	event->sample.header.type = PERF_RECORD_SAMPLE;
-	event->sample.header.misc = PERF_RECORD_MISC_USER;
-	event->sample.header.size = sizeof(struct perf_event_header);
-
-	if (!pt->timeless_decoding)
-		sample.time = tsc_to_perf_time(ptq->timestamp, &pt->tc);
-
-	sample.cpumode = PERF_RECORD_MISC_USER;
-	sample.ip = ptq->state->from_ip;
-	sample.pid = ptq->pid;
-	sample.tid = ptq->tid;
-	sample.addr = ptq->state->to_ip;
-	sample.id = ptq->pt->instructions_id;
-	sample.stream_id = ptq->pt->instructions_id;
-	sample.period = ptq->state->tot_insn_cnt - ptq->last_insn_cnt;
-	sample.cpu = ptq->cpu;
-	sample.flags = ptq->flags;
-	sample.insn_len = ptq->insn_len;
-	memcpy(sample.insn, ptq->insn, INTEL_PT_INSN_BUF_SZ);
-
-	ptq->last_insn_cnt = ptq->state->tot_insn_cnt;
+	intel_pt_prep_b_sample(pt, ptq, event, sample);
 
 	if (pt->synth_opts.callchain) {
 		thread_stack__sample(ptq->thread, ptq->chain,
-				     pt->synth_opts.callchain_sz, sample.ip);
-		sample.callchain = ptq->chain;
+				     pt->synth_opts.callchain_sz, sample->ip);
+		sample->callchain = ptq->chain;
 	}
 
 	if (pt->synth_opts.last_branch) {
 		intel_pt_copy_last_branch_rb(ptq);
-		sample.branch_stack = ptq->last_branch;
+		sample->branch_stack = ptq->last_branch;
 	}
+}
 
-	if (pt->synth_opts.inject) {
-		ret = intel_pt_inject_event(event, &sample,
-					    pt->instructions_sample_type,
-					    pt->synth_needs_swap);
-		if (ret)
-			return ret;
-	}
+static inline int intel_pt_deliver_synth_event(struct intel_pt *pt,
+					       struct intel_pt_queue *ptq,
+					       union perf_event *event,
+					       struct perf_sample *sample,
+					       u64 type)
+{
+	int ret;
 
-	ret = perf_session__deliver_synth_event(pt->session, event, &sample);
-	if (ret)
-		pr_err("Intel Processor Trace: failed to deliver instruction event, error %d\n",
-		       ret);
+	ret = intel_pt_deliver_synth_b_event(pt, event, sample, type);
 
 	if (pt->synth_opts.last_branch)
 		intel_pt_reset_last_branch_rb(ptq);
@@ -1198,65 +1198,43 @@ static int intel_pt_synth_instruction_sample(struct intel_pt_queue *ptq)
 	return ret;
 }
 
-static int intel_pt_synth_transaction_sample(struct intel_pt_queue *ptq)
+static int intel_pt_synth_instruction_sample(struct intel_pt_queue *ptq)
 {
-	int ret;
 	struct intel_pt *pt = ptq->pt;
 	union perf_event *event = ptq->event_buf;
 	struct perf_sample sample = { .ip = 0, };
 
-	if (pt->synth_opts.initial_skip &&
-	    pt->num_events++ < pt->synth_opts.initial_skip)
+	if (intel_pt_skip_event(pt))
 		return 0;
 
-	event->sample.header.type = PERF_RECORD_SAMPLE;
-	event->sample.header.misc = PERF_RECORD_MISC_USER;
-	event->sample.header.size = sizeof(struct perf_event_header);
+	intel_pt_prep_sample(pt, ptq, event, &sample);
 
-	if (!pt->timeless_decoding)
-		sample.time = tsc_to_perf_time(ptq->timestamp, &pt->tc);
+	sample.id = ptq->pt->instructions_id;
+	sample.stream_id = ptq->pt->instructions_id;
+	sample.period = ptq->state->tot_insn_cnt - ptq->last_insn_cnt;
 
-	sample.cpumode = PERF_RECORD_MISC_USER;
-	sample.ip = ptq->state->from_ip;
-	sample.pid = ptq->pid;
-	sample.tid = ptq->tid;
-	sample.addr = ptq->state->to_ip;
-	sample.id = ptq->pt->transactions_id;
-	sample.stream_id = ptq->pt->transactions_id;
-	sample.period = 1;
-	sample.cpu = ptq->cpu;
-	sample.flags = ptq->flags;
-	sample.insn_len = ptq->insn_len;
-	memcpy(sample.insn, ptq->insn, INTEL_PT_INSN_BUF_SZ);
+	ptq->last_insn_cnt = ptq->state->tot_insn_cnt;
 
-	if (pt->synth_opts.callchain) {
-		thread_stack__sample(ptq->thread, ptq->chain,
-				     pt->synth_opts.callchain_sz, sample.ip);
-		sample.callchain = ptq->chain;
-	}
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->instructions_sample_type);
+}
 
-	if (pt->synth_opts.last_branch) {
-		intel_pt_copy_last_branch_rb(ptq);
-		sample.branch_stack = ptq->last_branch;
-	}
+static int intel_pt_synth_transaction_sample(struct intel_pt_queue *ptq)
+{
+	struct intel_pt *pt = ptq->pt;
+	union perf_event *event = ptq->event_buf;
+	struct perf_sample sample = { .ip = 0, };
 
-	if (pt->synth_opts.inject) {
-		ret = intel_pt_inject_event(event, &sample,
-					    pt->transactions_sample_type,
-					    pt->synth_needs_swap);
-		if (ret)
-			return ret;
-	}
+	if (intel_pt_skip_event(pt))
+		return 0;
 
-	ret = perf_session__deliver_synth_event(pt->session, event, &sample);
-	if (ret)
-		pr_err("Intel Processor Trace: failed to deliver transaction event, error %d\n",
-		       ret);
+	intel_pt_prep_sample(pt, ptq, event, &sample);
 
-	if (pt->synth_opts.last_branch)
-		intel_pt_reset_last_branch_rb(ptq);
+	sample.id = ptq->pt->transactions_id;
+	sample.stream_id = ptq->pt->transactions_id;
 
-	return ret;
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->transactions_sample_type);
 }
 
 static int intel_pt_synth_error(struct intel_pt *pt, int code, int cpu,
-- 
1.9.1

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

* [PATCH V2 27/37] perf intel-pt: Remove unused instructions_sample_period
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (25 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 26/37] perf intel-pt: Factor out common code synthesizing event samples Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (10 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Remove unused struct intel_pt member instructions_sample_period.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/intel-pt.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index dbff5dca09f0..f8237a0e2946 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -81,7 +81,6 @@ struct intel_pt {
 
 	bool sample_instructions;
 	u64 instructions_sample_type;
-	u64 instructions_sample_period;
 	u64 instructions_id;
 
 	bool sample_branches;
@@ -1978,7 +1977,6 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 				intel_pt_ns_to_ticks(pt, pt->synth_opts.period);
 		else
 			attr.sample_period = pt->synth_opts.period;
-		pt->instructions_sample_period = attr.sample_period;
 		if (pt->synth_opts.callchain)
 			attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
 		if (pt->synth_opts.last_branch)
-- 
1.9.1

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

* [PATCH V2 28/37] perf intel-pt: Join needlessly wrapped lines
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (26 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 27/37] perf intel-pt: Remove unused instructions_sample_period Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (9 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Join needlessly wrapped lines.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/intel-pt.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index f8237a0e2946..b670502b0264 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1298,15 +1298,13 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)
 
 	ptq->have_sample = false;
 
-	if (pt->sample_instructions &&
-	    (state->type & INTEL_PT_INSTRUCTION)) {
+	if (pt->sample_instructions && (state->type & INTEL_PT_INSTRUCTION)) {
 		err = intel_pt_synth_instruction_sample(ptq);
 		if (err)
 			return err;
 	}
 
-	if (pt->sample_transactions &&
-	    (state->type & INTEL_PT_TRANSACTION)) {
+	if (pt->sample_transactions && (state->type & INTEL_PT_TRANSACTION)) {
 		err = intel_pt_synth_transaction_sample(ptq);
 		if (err)
 			return err;
-- 
1.9.1

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

* [PATCH V2 29/37] perf intel-pt: Tidy Intel PT evsel lookup into separate function
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (27 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 28/37] perf intel-pt: Join needlessly wrapped lines Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (8 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Tidy the lookup of the Intel PT selected event (perf_evsel) into a separate
function.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/intel-pt.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index b670502b0264..a9486b57584f 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1922,24 +1922,29 @@ static int intel_pt_synth_event(struct perf_session *session,
 					   &id, intel_pt_event_synth);
 }
 
+static struct perf_evsel *intel_pt_evsel(struct intel_pt *pt,
+					 struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel;
+
+	evlist__for_each_entry(evlist, evsel) {
+		if (evsel->attr.type == pt->pmu_type && evsel->ids)
+			return evsel;
+	}
+
+	return NULL;
+}
+
 static int intel_pt_synth_events(struct intel_pt *pt,
 				 struct perf_session *session)
 {
 	struct perf_evlist *evlist = session->evlist;
-	struct perf_evsel *evsel;
+	struct perf_evsel *evsel = intel_pt_evsel(pt, evlist);
 	struct perf_event_attr attr;
-	bool found = false;
 	u64 id;
 	int err;
 
-	evlist__for_each_entry(evlist, evsel) {
-		if (evsel->attr.type == pt->pmu_type && evsel->ids) {
-			found = true;
-			break;
-		}
-	}
-
-	if (!found) {
+	if (!evsel) {
 		pr_debug("There are no selected events with Intel Processor Trace data\n");
 		return 0;
 	}
-- 
1.9.1

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

* [PATCH V2 30/37] perf intel-pt: Tidy messages into called function intel_pt_synth_event()
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (28 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 29/37] perf intel-pt: Tidy Intel PT evsel lookup into separate function Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (7 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Tidy print messages into called function intel_pt_synth_event().

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/intel-pt.c | 42 ++++++++++++++++++------------------------
 1 file changed, 18 insertions(+), 24 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index a9486b57584f..81907f60e7da 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1910,16 +1910,25 @@ static int intel_pt_event_synth(struct perf_tool *tool,
 						 NULL);
 }
 
-static int intel_pt_synth_event(struct perf_session *session,
+static int intel_pt_synth_event(struct perf_session *session, const char *name,
 				struct perf_event_attr *attr, u64 id)
 {
 	struct intel_pt_synth intel_pt_synth;
+	int err;
+
+	pr_debug("Synthesizing '%s' event with id %" PRIu64 " sample type %#" PRIx64 "\n",
+		 name, id, (u64)attr->sample_type);
 
 	memset(&intel_pt_synth, 0, sizeof(struct intel_pt_synth));
 	intel_pt_synth.session = session;
 
-	return perf_event__synthesize_attr(&intel_pt_synth.dummy_tool, attr, 1,
-					   &id, intel_pt_event_synth);
+	err = perf_event__synthesize_attr(&intel_pt_synth.dummy_tool, attr, 1,
+					  &id, intel_pt_event_synth);
+	if (err)
+		pr_err("%s: failed to synthesize '%s' event type\n",
+		       __func__, name);
+
+	return err;
 }
 
 static struct perf_evsel *intel_pt_evsel(struct intel_pt *pt,
@@ -1984,14 +1993,9 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 			attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
 		if (pt->synth_opts.last_branch)
 			attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
-		pr_debug("Synthesizing 'instructions' event with id %" PRIu64 " sample type %#" PRIx64 "\n",
-			 id, (u64)attr.sample_type);
-		err = intel_pt_synth_event(session, &attr, id);
-		if (err) {
-			pr_err("%s: failed to synthesize 'instructions' event type\n",
-			       __func__);
+		err = intel_pt_synth_event(session, "instructions", &attr, id);
+		if (err)
 			return err;
-		}
 		pt->sample_instructions = true;
 		pt->instructions_sample_type = attr.sample_type;
 		pt->instructions_id = id;
@@ -2005,14 +2009,9 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 			attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
 		if (pt->synth_opts.last_branch)
 			attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
-		pr_debug("Synthesizing 'transactions' event with id %" PRIu64 " sample type %#" PRIx64 "\n",
-			 id, (u64)attr.sample_type);
-		err = intel_pt_synth_event(session, &attr, id);
-		if (err) {
-			pr_err("%s: failed to synthesize 'transactions' event type\n",
-			       __func__);
+		err = intel_pt_synth_event(session, "transactions", &attr, id);
+		if (err)
 			return err;
-		}
 		pt->sample_transactions = true;
 		pt->transactions_sample_type = attr.sample_type;
 		pt->transactions_id = id;
@@ -2033,14 +2032,9 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 		attr.sample_type |= PERF_SAMPLE_ADDR;
 		attr.sample_type &= ~(u64)PERF_SAMPLE_CALLCHAIN;
 		attr.sample_type &= ~(u64)PERF_SAMPLE_BRANCH_STACK;
-		pr_debug("Synthesizing 'branches' event with id %" PRIu64 " sample type %#" PRIx64 "\n",
-			 id, (u64)attr.sample_type);
-		err = intel_pt_synth_event(session, &attr, id);
-		if (err) {
-			pr_err("%s: failed to synthesize 'branches' event type\n",
-			       __func__);
+		err = intel_pt_synth_event(session, "branches", &attr, id);
+		if (err)
 			return err;
-		}
 		pt->sample_branches = true;
 		pt->branches_sample_type = attr.sample_type;
 		pt->branches_id = id;
-- 
1.9.1

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

* [PATCH V2 31/37] perf intel-pt: Factor out intel_pt_set_event_name()
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (29 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 30/37] perf intel-pt: Tidy messages into called function intel_pt_synth_event() Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (6 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Factor out intel_pt_set_event_name() so it can be reused.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/intel-pt.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 81907f60e7da..a20712e1ed28 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1931,6 +1931,21 @@ static int intel_pt_synth_event(struct perf_session *session, const char *name,
 	return err;
 }
 
+static void intel_pt_set_event_name(struct perf_evlist *evlist, u64 id,
+				    const char *name)
+{
+	struct perf_evsel *evsel;
+
+	evlist__for_each_entry(evlist, evsel) {
+		if (evsel->id && evsel->id[0] == id) {
+			if (evsel->name)
+				zfree(&evsel->name);
+			evsel->name = strdup(name);
+			break;
+		}
+	}
+}
+
 static struct perf_evsel *intel_pt_evsel(struct intel_pt *pt,
 					 struct perf_evlist *evlist)
 {
@@ -2015,15 +2030,8 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 		pt->sample_transactions = true;
 		pt->transactions_sample_type = attr.sample_type;
 		pt->transactions_id = id;
+		intel_pt_set_event_name(evlist, id, "transactions");
 		id += 1;
-		evlist__for_each_entry(evlist, evsel) {
-			if (evsel->id && evsel->id[0] == pt->transactions_id) {
-				if (evsel->name)
-					zfree(&evsel->name);
-				evsel->name = strdup("transactions");
-				break;
-			}
-		}
 	}
 
 	if (pt->synth_opts.branches) {
-- 
1.9.1

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

* [PATCH V2 32/37] perf intel-pt: Move code in intel_pt_synth_events() to simplify attr setting
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (30 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 31/37] perf intel-pt: Factor out intel_pt_set_event_name() Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (5 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

intel_pt_synth_events() uses the same attr structure to create each event.
Move the code around a bit to simplify that.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/intel-pt.c | 45 ++++++++++++++++++++++-----------------------
 1 file changed, 22 insertions(+), 23 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index a20712e1ed28..ace79a405f98 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1997,6 +1997,25 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 	if (!id)
 		id = 1;
 
+	if (pt->synth_opts.branches) {
+		attr.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS;
+		attr.sample_period = 1;
+		attr.sample_type |= PERF_SAMPLE_ADDR;
+		err = intel_pt_synth_event(session, "branches", &attr, id);
+		if (err)
+			return err;
+		pt->sample_branches = true;
+		pt->branches_sample_type = attr.sample_type;
+		pt->branches_id = id;
+		id += 1;
+		attr.sample_type &= ~(u64)PERF_SAMPLE_ADDR;
+	}
+
+	if (pt->synth_opts.callchain)
+		attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
+	if (pt->synth_opts.last_branch)
+		attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
+
 	if (pt->synth_opts.instructions) {
 		attr.config = PERF_COUNT_HW_INSTRUCTIONS;
 		if (pt->synth_opts.period_type == PERF_ITRACE_PERIOD_NANOSECS)
@@ -2004,10 +2023,6 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 				intel_pt_ns_to_ticks(pt, pt->synth_opts.period);
 		else
 			attr.sample_period = pt->synth_opts.period;
-		if (pt->synth_opts.callchain)
-			attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
-		if (pt->synth_opts.last_branch)
-			attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
 		err = intel_pt_synth_event(session, "instructions", &attr, id);
 		if (err)
 			return err;
@@ -2017,13 +2032,11 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 		id += 1;
 	}
 
+	attr.sample_type &= ~(u64)PERF_SAMPLE_PERIOD;
+	attr.sample_period = 1;
+
 	if (pt->synth_opts.transactions) {
 		attr.config = PERF_COUNT_HW_INSTRUCTIONS;
-		attr.sample_period = 1;
-		if (pt->synth_opts.callchain)
-			attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
-		if (pt->synth_opts.last_branch)
-			attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
 		err = intel_pt_synth_event(session, "transactions", &attr, id);
 		if (err)
 			return err;
@@ -2034,20 +2047,6 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 		id += 1;
 	}
 
-	if (pt->synth_opts.branches) {
-		attr.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS;
-		attr.sample_period = 1;
-		attr.sample_type |= PERF_SAMPLE_ADDR;
-		attr.sample_type &= ~(u64)PERF_SAMPLE_CALLCHAIN;
-		attr.sample_type &= ~(u64)PERF_SAMPLE_BRANCH_STACK;
-		err = intel_pt_synth_event(session, "branches", &attr, id);
-		if (err)
-			return err;
-		pt->sample_branches = true;
-		pt->branches_sample_type = attr.sample_type;
-		pt->branches_id = id;
-	}
-
 	pt->synth_needs_swap = evsel->needs_swap;
 
 	return 0;
-- 
1.9.1

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

* [PATCH V2 33/37] perf intel-pt: Synthesize new power and ptwrite events
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (31 preceding siblings ...)
  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-05-26  8:17 ` Adrian Hunter
  2017-06-30  8:36   ` [PATCH V3 " Adrian Hunter
  2017-05-26  8:17 ` [PATCH V2 34/37] perf intel-pt: Add example script for power events and PTWRITE Adrian Hunter
                   ` (4 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Synthesize new power and ptwrite events.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/intel-pt.c | 283 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 283 insertions(+)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index ace79a405f98..754e92ee6c3e 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -92,6 +92,18 @@ struct intel_pt {
 	u64 transactions_sample_type;
 	u64 transactions_id;
 
+	bool sample_ptwrites;
+	u64 ptwrites_sample_type;
+	u64 ptwrites_id;
+
+	bool sample_pwr_events;
+	u64 pwr_events_sample_type;
+	u64 mwait_id;
+	u64 pwre_id;
+	u64 exstop_id;
+	u64 pwrx_id;
+	u64 cbr_id;
+
 	bool synth_needs_swap;
 
 	u64 tsc_bit;
@@ -102,6 +114,7 @@ struct intel_pt {
 	u64 cyc_bit;
 	u64 noretcomp_bit;
 	unsigned max_non_turbo_ratio;
+	unsigned cbr2khz;
 
 	unsigned long num_events;
 
@@ -1236,6 +1249,175 @@ static int intel_pt_synth_transaction_sample(struct intel_pt_queue *ptq)
 					    pt->transactions_sample_type);
 }
 
+static void intel_pt_prep_p_sample(struct intel_pt *pt,
+				   struct intel_pt_queue *ptq,
+				   union perf_event *event,
+				   struct perf_sample *sample)
+{
+	intel_pt_prep_sample(pt, ptq, event, sample);
+
+	/*
+	 * Zero IP is used to mean "trace start" but that is not the case for
+	 * power or PTWRITE events with no IP, so clear the flags.
+	 */
+	if (!sample->ip)
+		sample->flags = 0;
+}
+
+static int intel_pt_synth_ptwrite_sample(struct intel_pt_queue *ptq)
+{
+	struct intel_pt *pt = ptq->pt;
+	union perf_event *event = ptq->event_buf;
+	struct perf_sample sample = { .ip = 0, };
+	struct perf_synth_intel_ptwrite raw;
+
+	if (intel_pt_skip_event(pt))
+		return 0;
+
+	intel_pt_prep_p_sample(pt, ptq, event, &sample);
+
+	sample.id = ptq->pt->ptwrites_id;
+	sample.stream_id = ptq->pt->ptwrites_id;
+
+	raw.flags = 0;
+	raw.ip = !!(ptq->state->flags & INTEL_PT_FUP_IP);
+	raw.payload = cpu_to_le64(ptq->state->ptw_payload);
+
+	sample.raw_size = sizeof(raw);
+	sample.raw_data = &raw;
+
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->ptwrites_sample_type);
+}
+
+static int intel_pt_synth_cbr_sample(struct intel_pt_queue *ptq)
+{
+	struct intel_pt *pt = ptq->pt;
+	union perf_event *event = ptq->event_buf;
+	struct perf_sample sample = { .ip = 0, };
+	struct perf_synth_intel_cbr raw;
+	u32 flags;
+
+	if (intel_pt_skip_event(pt))
+		return 0;
+
+	intel_pt_prep_p_sample(pt, ptq, event, &sample);
+
+	sample.id = ptq->pt->cbr_id;
+	sample.stream_id = ptq->pt->cbr_id;
+
+	flags = (u16)ptq->state->cbr_payload | (pt->max_non_turbo_ratio << 16);
+	raw.flags = cpu_to_le32(flags);
+	raw.freq = cpu_to_le32(raw.cbr * pt->cbr2khz);
+	raw.reserved3 = 0;
+
+	sample.raw_size = sizeof(raw);
+	sample.raw_data = &raw;
+
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->pwr_events_sample_type);
+}
+
+static int intel_pt_synth_mwait_sample(struct intel_pt_queue *ptq)
+{
+	struct intel_pt *pt = ptq->pt;
+	union perf_event *event = ptq->event_buf;
+	struct perf_sample sample = { .ip = 0, };
+	struct perf_synth_intel_mwait raw;
+
+	if (intel_pt_skip_event(pt))
+		return 0;
+
+	intel_pt_prep_p_sample(pt, ptq, event, &sample);
+
+	sample.id = ptq->pt->mwait_id;
+	sample.stream_id = ptq->pt->mwait_id;
+
+	raw.reserved = 0;
+	raw.payload = cpu_to_le64(ptq->state->mwait_payload);
+
+	sample.raw_size = sizeof(raw);
+	sample.raw_data = &raw;
+
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->pwr_events_sample_type);
+}
+
+static int intel_pt_synth_pwre_sample(struct intel_pt_queue *ptq)
+{
+	struct intel_pt *pt = ptq->pt;
+	union perf_event *event = ptq->event_buf;
+	struct perf_sample sample = { .ip = 0, };
+	struct perf_synth_intel_pwre raw;
+
+	if (intel_pt_skip_event(pt))
+		return 0;
+
+	intel_pt_prep_p_sample(pt, ptq, event, &sample);
+
+	sample.id = ptq->pt->pwre_id;
+	sample.stream_id = ptq->pt->pwre_id;
+
+	raw.reserved = 0;
+	raw.payload = cpu_to_le64(ptq->state->pwre_payload);
+
+	sample.raw_size = sizeof(raw);
+	sample.raw_data = &raw;
+
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->pwr_events_sample_type);
+}
+
+static int intel_pt_synth_exstop_sample(struct intel_pt_queue *ptq)
+{
+	struct intel_pt *pt = ptq->pt;
+	union perf_event *event = ptq->event_buf;
+	struct perf_sample sample = { .ip = 0, };
+	struct perf_synth_intel_exstop raw;
+
+	if (intel_pt_skip_event(pt))
+		return 0;
+
+	intel_pt_prep_p_sample(pt, ptq, event, &sample);
+
+	sample.id = ptq->pt->exstop_id;
+	sample.stream_id = ptq->pt->exstop_id;
+
+	raw.flags = 0;
+	raw.ip = !!(ptq->state->flags & INTEL_PT_FUP_IP);
+
+	sample.raw_size = sizeof(raw);
+	sample.raw_data = &raw;
+
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->pwr_events_sample_type);
+}
+
+static int intel_pt_synth_pwrx_sample(struct intel_pt_queue *ptq)
+{
+	struct intel_pt *pt = ptq->pt;
+	union perf_event *event = ptq->event_buf;
+	struct perf_sample sample = { .ip = 0, };
+	struct perf_synth_intel_pwrx raw;
+
+	if (intel_pt_skip_event(pt))
+		return 0;
+
+	intel_pt_prep_p_sample(pt, ptq, event, &sample);
+
+	sample.id = ptq->pt->pwrx_id;
+	sample.stream_id = ptq->pt->pwrx_id;
+
+	raw.reserved = 0;
+	raw.payload = cpu_to_le64(ptq->state->pwrx_payload);
+
+	sample.raw_size = sizeof(raw);
+	sample.raw_data = &raw;
+
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->pwr_events_sample_type);
+}
+
 static int intel_pt_synth_error(struct intel_pt *pt, int code, int cpu,
 				pid_t pid, pid_t tid, u64 ip)
 {
@@ -1287,6 +1469,10 @@ static inline bool intel_pt_is_switch_ip(struct intel_pt_queue *ptq, u64 ip)
 			       PERF_IP_FLAG_INTERRUPT | PERF_IP_FLAG_TX_ABORT));
 }
 
+#define INTEL_PT_PWR_EVT (INTEL_PT_MWAIT_OP | INTEL_PT_PWR_ENTRY | \
+			  INTEL_PT_EX_STOP | INTEL_PT_PWR_EXIT | \
+			  INTEL_PT_CBR_CHG)
+
 static int intel_pt_sample(struct intel_pt_queue *ptq)
 {
 	const struct intel_pt_state *state = ptq->state;
@@ -1298,6 +1484,34 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)
 
 	ptq->have_sample = false;
 
+	if (pt->sample_pwr_events && (state->type & INTEL_PT_PWR_EVT)) {
+		if (state->type & INTEL_PT_CBR_CHG) {
+			err = intel_pt_synth_cbr_sample(ptq);
+			if (err)
+				return err;
+		}
+		if (state->type & INTEL_PT_MWAIT_OP) {
+			err = intel_pt_synth_mwait_sample(ptq);
+			if (err)
+				return err;
+		}
+		if (state->type & INTEL_PT_PWR_ENTRY) {
+			err = intel_pt_synth_pwre_sample(ptq);
+			if (err)
+				return err;
+		}
+		if (state->type & INTEL_PT_EX_STOP) {
+			err = intel_pt_synth_exstop_sample(ptq);
+			if (err)
+				return err;
+		}
+		if (state->type & INTEL_PT_PWR_EXIT) {
+			err = intel_pt_synth_pwrx_sample(ptq);
+			if (err)
+				return err;
+		}
+	}
+
 	if (pt->sample_instructions && (state->type & INTEL_PT_INSTRUCTION)) {
 		err = intel_pt_synth_instruction_sample(ptq);
 		if (err)
@@ -1310,6 +1524,12 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)
 			return err;
 	}
 
+	if (pt->sample_ptwrites && (state->type & INTEL_PT_PTW)) {
+		err = intel_pt_synth_ptwrite_sample(ptq);
+		if (err)
+			return err;
+	}
+
 	if (!(state->type & INTEL_PT_BRANCH))
 		return 0;
 
@@ -2047,6 +2267,68 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 		id += 1;
 	}
 
+	attr.type = PERF_TYPE_SYNTH;
+	attr.sample_type |= PERF_SAMPLE_RAW;
+
+	if (pt->synth_opts.ptwrites) {
+		attr.config = PERF_SYNTH_INTEL_PTWRITE;
+		err = intel_pt_synth_event(session, "ptwrite", &attr, id);
+		if (err)
+			return err;
+		pt->sample_ptwrites = true;
+		pt->ptwrites_sample_type = attr.sample_type;
+		pt->ptwrites_id = id;
+		intel_pt_set_event_name(evlist, id, "ptwrite");
+		id += 1;
+	}
+
+	if (pt->synth_opts.pwr_events) {
+		pt->sample_pwr_events = true;
+		pt->pwr_events_sample_type = attr.sample_type;
+
+		attr.config = PERF_SYNTH_INTEL_CBR;
+		err = intel_pt_synth_event(session, "cbr", &attr, id);
+		if (err)
+			return err;
+		pt->cbr_id = id;
+		intel_pt_set_event_name(evlist, id, "cbr");
+		id += 1;
+	}
+
+	if (pt->synth_opts.pwr_events && (evsel->attr.config & 0x10)) {
+		attr.config = PERF_SYNTH_INTEL_MWAIT;
+		err = intel_pt_synth_event(session, "mwait", &attr, id);
+		if (err)
+			return err;
+		pt->mwait_id = id;
+		intel_pt_set_event_name(evlist, id, "mwait");
+		id += 1;
+
+		attr.config = PERF_SYNTH_INTEL_PWRE;
+		err = intel_pt_synth_event(session, "pwre", &attr, id);
+		if (err)
+			return err;
+		pt->pwre_id = id;
+		intel_pt_set_event_name(evlist, id, "pwre");
+		id += 1;
+
+		attr.config = PERF_SYNTH_INTEL_EXSTOP;
+		err = intel_pt_synth_event(session, "exstop", &attr, id);
+		if (err)
+			return err;
+		pt->exstop_id = id;
+		intel_pt_set_event_name(evlist, id, "exstop");
+		id += 1;
+
+		attr.config = PERF_SYNTH_INTEL_PWRX;
+		err = intel_pt_synth_event(session, "pwrx", &attr, id);
+		if (err)
+			return err;
+		pt->pwrx_id = id;
+		intel_pt_set_event_name(evlist, id, "pwrx");
+		id += 1;
+	}
+
 	pt->synth_needs_swap = evsel->needs_swap;
 
 	return 0;
@@ -2313,6 +2595,7 @@ int intel_pt_process_auxtrace_info(union perf_event *event,
 		intel_pt_log("TSC frequency %"PRIu64"\n", tsc_freq);
 		intel_pt_log("Maximum non-turbo ratio %u\n",
 			     pt->max_non_turbo_ratio);
+		pt->cbr2khz = tsc_freq / pt->max_non_turbo_ratio / 1000;
 	}
 
 	if (pt->synth_opts.calls)
-- 
1.9.1

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

* [PATCH V2 34/37] perf intel-pt: Add example script for power events and PTWRITE
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (32 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 33/37] perf intel-pt: Synthesize new power and ptwrite events Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (3 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Add script intel-pt-events.py that provides an example of how to unpack the
raw data for power events and PTWRITE.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 .../perf/scripts/python/bin/intel-pt-events-record |  13 +++
 .../perf/scripts/python/bin/intel-pt-events-report |   3 +
 tools/perf/scripts/python/intel-pt-events.py       | 128 +++++++++++++++++++++
 3 files changed, 144 insertions(+)
 create mode 100644 tools/perf/scripts/python/bin/intel-pt-events-record
 create mode 100644 tools/perf/scripts/python/bin/intel-pt-events-report
 create mode 100644 tools/perf/scripts/python/intel-pt-events.py

diff --git a/tools/perf/scripts/python/bin/intel-pt-events-record b/tools/perf/scripts/python/bin/intel-pt-events-record
new file mode 100644
index 000000000000..10fe2b6977d4
--- /dev/null
+++ b/tools/perf/scripts/python/bin/intel-pt-events-record
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+#
+# print Intel PT Power Events and PTWRITE. The intel_pt PMU event needs
+# to be specified with appropriate config terms.
+#
+if ! echo "$@" | grep -q intel_pt ; then
+	echo "Options must include the Intel PT event e.g. -e intel_pt/pwr_evt,ptw/"
+	echo "and for power events it probably needs to be system wide i.e. -a option"
+	echo "For example: -a -e intel_pt/pwr_evt,branch=0/ sleep 1"
+	exit 1
+fi
+perf record $@
diff --git a/tools/perf/scripts/python/bin/intel-pt-events-report b/tools/perf/scripts/python/bin/intel-pt-events-report
new file mode 100644
index 000000000000..9a9c92fcd026
--- /dev/null
+++ b/tools/perf/scripts/python/bin/intel-pt-events-report
@@ -0,0 +1,3 @@
+#!/bin/bash
+# description: print Intel PT Power Events and PTWRITE
+perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/intel-pt-events.py
\ No newline at end of file
diff --git a/tools/perf/scripts/python/intel-pt-events.py b/tools/perf/scripts/python/intel-pt-events.py
new file mode 100644
index 000000000000..b19172d673af
--- /dev/null
+++ b/tools/perf/scripts/python/intel-pt-events.py
@@ -0,0 +1,128 @@
+# intel-pt-events.py: Print Intel PT Power Events and PTWRITE
+# Copyright (c) 2017, Intel Corporation.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms and conditions of the GNU General Public License,
+# version 2, as published by the Free Software Foundation.
+#
+# This program is distributed in the hope it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+
+import os
+import sys
+import struct
+
+sys.path.append(os.environ['PERF_EXEC_PATH'] + \
+	'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
+
+# These perf imports are not used at present
+#from perf_trace_context import *
+#from Core import *
+
+def trace_begin():
+	print "Intel PT Power Events and PTWRITE"
+
+def trace_end():
+	print "End"
+
+def trace_unhandled(event_name, context, event_fields_dict):
+		print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())])
+
+def print_ptwrite(raw_buf):
+	data = struct.unpack_from("<IQ", raw_buf)
+	flags = data[0]
+	payload = data[1]
+	exact_ip = flags & 1
+	print "IP: %u payload: %#x" % (exact_ip, payload),
+
+def print_cbr(raw_buf):
+	data = struct.unpack_from("<BBBBII", raw_buf)
+	cbr = data[0]
+	f = (data[4] + 500) / 1000
+	p = ((cbr * 1000 / data[2]) + 5) / 10
+	print "%3u  freq: %4u MHz  (%3u%%)" % (cbr, f, p),
+
+def print_mwait(raw_buf):
+	data = struct.unpack_from("<IQ", raw_buf)
+	payload = data[1]
+	hints = payload & 0xff
+	extensions = (payload >> 32) & 0x3
+	print "hints: %#x extensions: %#x" % (hints, extensions),
+
+def print_pwre(raw_buf):
+	data = struct.unpack_from("<IQ", raw_buf)
+	payload = data[1]
+	hw = (payload >> 7) & 1
+	cstate = (payload >> 12) & 0xf
+	subcstate = (payload >> 8) & 0xf
+	print "hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate),
+
+def print_exstop(raw_buf):
+	data = struct.unpack_from("<I", raw_buf)
+	flags = data[0]
+	exact_ip = flags & 1
+	print "IP: %u" % (exact_ip),
+
+def print_pwrx(raw_buf):
+	data = struct.unpack_from("<IQ", raw_buf)
+	payload = data[1]
+	deepest_cstate = payload & 0xf
+	last_cstate = (payload >> 4) & 0xf
+	wake_reason = (payload >> 8) & 0xf
+	print "deepest cstate: %u last cstate: %u wake reason: %#x" % (deepest_cstate, last_cstate, wake_reason),
+
+def print_common_start(comm, sample, name):
+	ts = sample["time"]
+	cpu = sample["cpu"]
+	pid = sample["pid"]
+	tid = sample["tid"]
+	print "%16s %5u/%-5u [%03u] %9u.%09u %7s:" % (comm, pid, tid, cpu, ts / 1000000000, ts %1000000000, name),
+
+def print_common_ip(sample, symbol, dso):
+	ip = sample["ip"]
+	print "%16x %s (%s)" % (ip, symbol, dso)
+
+def process_event(param_dict):
+        event_attr = param_dict["attr"]
+        sample     = param_dict["sample"]
+        raw_buf    = param_dict["raw_buf"]
+        comm       = param_dict["comm"]
+        name       = param_dict["ev_name"]
+
+        # Symbol and dso info are not always resolved
+        if (param_dict.has_key("dso")):
+                dso = param_dict["dso"]
+        else:
+                dso = "[unknown]"
+
+        if (param_dict.has_key("symbol")):
+                symbol = param_dict["symbol"]
+        else:
+                symbol = "[unknown]"
+
+	if name == "ptwrite":
+		print_common_start(comm, sample, name)
+		print_ptwrite(raw_buf)
+		print_common_ip(sample, symbol, dso)
+	elif name == "cbr":
+		print_common_start(comm, sample, name)
+		print_cbr(raw_buf)
+		print_common_ip(sample, symbol, dso)
+	elif name == "mwait":
+		print_common_start(comm, sample, name)
+		print_mwait(raw_buf)
+		print_common_ip(sample, symbol, dso)
+	elif name == "pwre":
+		print_common_start(comm, sample, name)
+		print_pwre(raw_buf)
+		print_common_ip(sample, symbol, dso)
+	elif name == "exstop":
+		print_common_start(comm, sample, name)
+		print_exstop(raw_buf)
+		print_common_ip(sample, symbol, dso)
+	elif name == "pwrx":
+		print_common_start(comm, sample, name)
+		print_pwrx(raw_buf)
+		print_common_ip(sample, symbol, dso)
-- 
1.9.1

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

* [PATCH V2 35/37] perf intel-pt: Update documentation to include new ptwrite and power events
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (33 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 34/37] perf intel-pt: Add example script for power events and PTWRITE Adrian Hunter
@ 2017-05-26  8:17 ` 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
                   ` (2 subsequent siblings)
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Update documentation to include new ptwrite and power events.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/Documentation/intel-pt.txt | 42 +++++++++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/intel-pt.txt b/tools/perf/Documentation/intel-pt.txt
index d157dee7a4ec..4b6cdbf8f935 100644
--- a/tools/perf/Documentation/intel-pt.txt
+++ b/tools/perf/Documentation/intel-pt.txt
@@ -108,6 +108,9 @@ approach is available to export the data to a postgresql database.  Refer to
 script export-to-postgresql.py for more details, and to script
 call-graph-from-postgresql.py for an example of using the database.
 
+There is also script intel-pt-events.py which provides an example of how to
+unpack the raw data for power events and PTWRITE.
+
 As mentioned above, it is easy to capture too much data.  One way to limit the
 data captured is to use 'snapshot' mode which is explained further below.
 Refer to 'new snapshot option' and 'Intel PT modes of operation' further below.
@@ -710,13 +713,15 @@ Having no option is the same as
 
 which, in turn, is the same as
 
-	--itrace=ibxe
+	--itrace=ibxwpe
 
 The letters are:
 
 	i	synthesize "instructions" events
 	b	synthesize "branches" events
 	x	synthesize "transactions" events
+	w	synthesize "ptwrite" events
+	p	synthesize "power" events
 	c	synthesize branches events (calls only)
 	r	synthesize branches events (returns only)
 	e	synthesize tracing error events
@@ -735,7 +740,40 @@ and "r" can be combined to get calls and returns.
 'flags' field can be used in perf script to determine whether the event is a
 tranasaction start, commit or abort.
 
-Error events are new.  They show where the decoder lost the trace.  Error events
+Note that "instructions", "branches" and "transactions" events depend on code
+flow packets which can be disabled by using the config term "branch=0".  Refer
+to the config terms section above.
+
+"ptwrite" events record the payload of the ptwrite instruction and whether
+"fup_on_ptw" was used.  "ptwrite" events depend on PTWRITE packets which are
+recorded only if the "ptw" config term was used.  Refer to the config terms
+section above.  perf script "synth" field displays "ptwrite" information like
+this: "ip: 0 payload: 0x123456789abcdef0"  where "ip" is 1 if "fup_on_ptw" was
+used.
+
+"Power" events correspond to power event packets and CBR (core-to-bus ratio)
+packets.  While CBR packets are always recorded when tracing is enabled, power
+event packets are recorded only if the "pwr_evt" config term was used.  Refer to
+the config terms section above.  The power events record information about
+C-state changes, whereas CBR is indicative of CPU frequency.  perf script
+"event,synth" fields display information like this:
+	cbr:  cbr: 22 freq: 2189 MHz (200%)
+	mwait:  hints: 0x60 extensions: 0x1
+	pwre:  hw: 0 cstate: 2 sub-cstate: 0
+	exstop:  ip: 1
+	pwrx:  deepest cstate: 2 last cstate: 2 wake reason: 0x4
+Where:
+	"cbr" includes the frequency and the percentage of maximum non-turbo
+	"mwait" shows mwait hints and extensions
+	"pwre" shows C-state transitions (to a C-state deeper than C0) and
+	whether	initiated by hardware
+	"exstop" indicates execution stopped and whether the IP was recorded
+	exactly,
+	"pwrx" indicates return to C0
+For more details refer to the Intel 64 and IA-32 Architectures Software
+Developer Manuals.
+
+Error events show where the decoder lost the trace.  Error events
 are quite important.  Users must know if what they are seeing is a complete
 picture or not.
 
-- 
1.9.1

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

* [PATCH V2 36/37] perf intel-pt: Do not use TSC packets for calculating CPU cycles to TSC
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (34 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 35/37] perf intel-pt: Update documentation to include new ptwrite and power events Adrian Hunter
@ 2017-05-26  8:17 ` 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-06-12 13:04 ` [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

CBR (core-to-bus ratio) packets provide an indication of CPU frequency. A
more accurate measure can be made by counting the cycles (given by CYC
packets) in between other timing packets (either MTC or TSC). Using TSC
packets has at least 2 issues: 1) timing might have stopped (e.g. mwait) or
2) TSC packets within PSB+ might slip past CYC packets. For now, simply do
not use TSC packets for calculating CPU cycles to TSC. That leaves the case
where 2 MTC packets are used, otherwise falling back to the CBR value.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 5dea06289db5..aa1593ce551d 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -711,6 +711,12 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info)
 		break;
 
 	case INTEL_PT_TSC:
+		/*
+		 * For now, do not support using TSC packets - refer
+		 * intel_pt_calc_cyc_to_tsc().
+		 */
+		if (data->from_mtc)
+			return 1;
 		timestamp = pkt_info->packet.payload |
 			    (data->timestamp & (0xffULL << 56));
 		if (data->from_mtc && timestamp < data->timestamp &&
@@ -828,6 +834,14 @@ static void intel_pt_calc_cyc_to_tsc(struct intel_pt_decoder *decoder,
 		.cbr_cyc_to_tsc = 0,
 	};
 
+	/*
+	 * For now, do not support using TSC packets for at least the reasons:
+	 * 1) timing might have stopped
+	 * 2) TSC packets within PSB+ can slip against CYC packets
+	 */
+	if (!from_mtc)
+		return;
+
 	intel_pt_pkt_lookahead(decoder, intel_pt_calc_cyc_cb, &data);
 }
 
-- 
1.9.1

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

* [PATCH V2 37/37] perf auxtrace: Add CPU filter support
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (35 preceding siblings ...)
  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-05-26  8:17 ` 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
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-05-26  8:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Decoding auxtrace data can take a long time. To avoid decoding
unnecessarily, filter auxtrace data that is collected per-cpu before it is
decoded.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/builtin-report.c |  1 +
 tools/perf/builtin-script.c |  1 +
 tools/perf/util/auxtrace.c  | 10 ++++++++++
 tools/perf/util/auxtrace.h  |  2 ++
 4 files changed, 14 insertions(+)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 22478ff2b706..6de88f156ec6 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -558,6 +558,7 @@ static int __cmd_report(struct report *rep)
 			ui__error("failed to set cpu bitmap\n");
 			return ret;
 		}
+		session->itrace_synth_opts->cpu_bitmap = rep->cpu_bitmap;
 	}
 
 	if (rep->show_threads) {
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 4a13daacba25..4c41d0358966 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2874,6 +2874,7 @@ int cmd_script(int argc, const char **argv)
 		err = perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap);
 		if (err < 0)
 			goto out_delete;
+		itrace_synth_opts.cpu_bitmap = cpu_bitmap;
 	}
 
 	if (!no_callchain)
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index 651c01dfa5d3..5547457566a7 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -322,6 +322,13 @@ static int auxtrace_queues__add_event_buffer(struct auxtrace_queues *queues,
 	return auxtrace_queues__add_buffer(queues, idx, buffer);
 }
 
+static bool filter_cpu(struct perf_session *session, int cpu)
+{
+	unsigned long *cpu_bitmap = session->itrace_synth_opts->cpu_bitmap;
+
+	return cpu_bitmap && cpu != -1 && !test_bit(cpu, cpu_bitmap);
+}
+
 int auxtrace_queues__add_event(struct auxtrace_queues *queues,
 			       struct perf_session *session,
 			       union perf_event *event, off_t data_offset,
@@ -331,6 +338,9 @@ int auxtrace_queues__add_event(struct auxtrace_queues *queues,
 	unsigned int idx;
 	int err;
 
+	if (filter_cpu(session, event->auxtrace.cpu))
+		return 0;
+
 	buffer = zalloc(sizeof(struct auxtrace_buffer));
 	if (!buffer)
 		return -ENOMEM;
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 68e0aa40b24a..33b5e6cdf38c 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -74,6 +74,7 @@ enum itrace_period_type {
  * @period: 'instructions' events period
  * @period_type: 'instructions' events period type
  * @initial_skip: skip N events at the beginning.
+ * @cpu_bitmap: CPUs for which to synthesize events, or NULL for all
  */
 struct itrace_synth_opts {
 	bool			set;
@@ -96,6 +97,7 @@ struct itrace_synth_opts {
 	unsigned long long	period;
 	enum itrace_period_type	period_type;
 	unsigned long		initial_skip;
+	unsigned long		*cpu_bitmap;
 };
 
 /**
-- 
1.9.1

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

* Re: [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE
  2017-05-26  8:17 [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE Adrian Hunter
                   ` (36 preceding siblings ...)
  2017-05-26  8:17 ` [PATCH V2 37/37] perf auxtrace: Add CPU filter support Adrian Hunter
@ 2017-06-12 13:04 ` Adrian Hunter
  2017-06-12 13:56   ` Arnaldo Carvalho de Melo
  37 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-06-12 13:04 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Andi Kleen, linux-kernel

On 26/05/17 11:17, Adrian Hunter wrote:
> Hi
> 
> Here are some patches to support Intel PT Power events and PTWRITE.
> Power events report changes to C-state but I have also added support
> for the existing CBR (core-to-bus ratio) packet and included that
> when outputting power events.  The PTWRITE packet is associated with
> the new ptwrite instruction, which is essentially just a way to stuff
> a 32 or 64 bit value into the PT trace.  More details can be found in
> the patches that add documentation and in the Intel SDM.
> 
> As far as I know, there isn't any hardware released that supports
> the new packets, however the CBR packet is not new and will now be
> visible by default.
> 
> There are also some miscellaneous improvements to Intel PT.
> 
> There are 3 patches that introduce a new way to define synthesized
> events that carry arbitrary raw_data.  I sent an RFC about that earlier.
> The 3 patches are:
>       perf script: Add 'synth' event type for synthesized events
>       perf script: Add 'synth' field for synthesized event payloads
>       perf script: Add synthesized Intel PT power and ptwrite events
> 
> 
> Changes in V2:
> 
> 	Reorder patches and add stable tags to fixes.
> 

Apart from "perf script: Add 'synth' event type for synthesized events"
patches still apply.  Any comments?

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

* Re: [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE
  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-27 15:27     ` Arnaldo Carvalho de Melo
  0 siblings, 2 replies; 100+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-06-12 13:56 UTC (permalink / raw)
  To: Adrian Hunter; +Cc: Andi Kleen, linux-kernel

Em Mon, Jun 12, 2017 at 04:04:44PM +0300, Adrian Hunter escreveu:
> On 26/05/17 11:17, Adrian Hunter wrote:
> > Hi
> > 
> > Here are some patches to support Intel PT Power events and PTWRITE.
> > Power events report changes to C-state but I have also added support
> > for the existing CBR (core-to-bus ratio) packet and included that
> > when outputting power events.  The PTWRITE packet is associated with
> > the new ptwrite instruction, which is essentially just a way to stuff
> > a 32 or 64 bit value into the PT trace.  More details can be found in
> > the patches that add documentation and in the Intel SDM.
> > 
> > As far as I know, there isn't any hardware released that supports
> > the new packets, however the CBR packet is not new and will now be
> > visible by default.
> > 
> > There are also some miscellaneous improvements to Intel PT.
> > 
> > There are 3 patches that introduce a new way to define synthesized
> > events that carry arbitrary raw_data.  I sent an RFC about that earlier.
> > The 3 patches are:
> >       perf script: Add 'synth' event type for synthesized events
> >       perf script: Add 'synth' field for synthesized event payloads
> >       perf script: Add synthesized Intel PT power and ptwrite events
> > 
> > 
> > Changes in V2:
> > 
> > 	Reorder patches and add stable tags to fixes.
> > 
> 
> Apart from "perf script: Add 'synth' event type for synthesized events"
> patches still apply.  Any comments?

I'll look at it today,

- Arnaldo

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

* [PATCH V3 20/37] perf script: Add 'synth' event type for synthesized events
  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   ` Adrian Hunter
  2017-06-21 13:51     ` Arnaldo Carvalho de Melo
  2017-07-01  8:50     ` [tip:perf/core] " tip-bot for Adrian Hunter
  0 siblings, 2 replies; 100+ messages in thread
From: Adrian Hunter @ 2017-06-21 10:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Instruction trace decoders such as Intel PT may have additional information
recorded in the trace. For example, Intel PT has power information and a
there is a new instruction 'ptwrite' that can write a value into a PTWRITE
trace packet. Such information may be associated with an IP and so can be
treated as a sample (PERF_RECORD_SAMPLE). Custom data can be incorporated
in the sample as raw_data (PERF_SAMPLE_RAW). However a means of identifying
the raw data format is needed. That will be done by synthesizing an
attribute for it. So add an attribute type for custom synthesized events.
Different synthesized events will be identified by the attribute 'config'.

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


Changes in V3:

	Re-base on Arnaldo's perf/core branch


 tools/perf/builtin-script.c | 74 +++++++++++++++++++++++++++++++++++----------
 tools/perf/util/event.h     |  3 ++
 2 files changed, 61 insertions(+), 16 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 4bce7d8679cb..2999e7e425f6 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -119,6 +119,11 @@ struct output_option {
 	{.str = "brstackoff", .field = PERF_OUTPUT_BRSTACKOFF},
 };
 
+enum {
+	OUTPUT_TYPE_SYNTH = PERF_TYPE_MAX,
+	OUTPUT_TYPE_MAX
+};
+
 /* default set to maintain compatibility with current format */
 static struct {
 	bool user_set;
@@ -126,7 +131,7 @@ struct output_option {
 	unsigned int print_ip_opts;
 	u64 fields;
 	u64 invalid_fields;
-} output[PERF_TYPE_MAX] = {
+} output[OUTPUT_TYPE_MAX] = {
 
 	[PERF_TYPE_HARDWARE] = {
 		.user_set = false,
@@ -184,12 +189,43 @@ struct output_option {
 
 		.invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
 	},
+
+	[OUTPUT_TYPE_SYNTH] = {
+		.user_set = false,
+
+		.fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
+			      PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
+			      PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
+			      PERF_OUTPUT_SYM | PERF_OUTPUT_DSO,
+
+		.invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
+	},
 };
 
+static inline int output_type(unsigned int type)
+{
+	switch (type) {
+	case PERF_TYPE_SYNTH:
+		return OUTPUT_TYPE_SYNTH;
+	default:
+		return type;
+	}
+}
+
+static inline unsigned int attr_type(unsigned int type)
+{
+	switch (type) {
+	case OUTPUT_TYPE_SYNTH:
+		return PERF_TYPE_SYNTH;
+	default:
+		return type;
+	}
+}
+
 static bool output_set_by_user(void)
 {
 	int j;
-	for (j = 0; j < PERF_TYPE_MAX; ++j) {
+	for (j = 0; j < OUTPUT_TYPE_MAX; ++j) {
 		if (output[j].user_set)
 			return true;
 	}
@@ -210,7 +246,7 @@ static const char *output_field2str(enum perf_output_field field)
 	return str;
 }
 
-#define PRINT_FIELD(x)  (output[attr->type].fields & PERF_OUTPUT_##x)
+#define PRINT_FIELD(x)  (output[output_type(attr->type)].fields & PERF_OUTPUT_##x)
 
 static int perf_evsel__do_check_stype(struct perf_evsel *evsel,
 				      u64 sample_type, const char *sample_msg,
@@ -218,7 +254,7 @@ static int perf_evsel__do_check_stype(struct perf_evsel *evsel,
 				      bool allow_user_set)
 {
 	struct perf_event_attr *attr = &evsel->attr;
-	int type = attr->type;
+	int type = output_type(attr->type);
 	const char *evname;
 
 	if (attr->sample_type & sample_type)
@@ -348,7 +384,7 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,
 
 static void set_print_ip_opts(struct perf_event_attr *attr)
 {
-	unsigned int type = attr->type;
+	unsigned int type = output_type(attr->type);
 
 	output[type].print_ip_opts = 0;
 	if (PRINT_FIELD(IP))
@@ -376,14 +412,15 @@ static int perf_session__check_output_opt(struct perf_session *session)
 	unsigned int j;
 	struct perf_evsel *evsel;
 
-	for (j = 0; j < PERF_TYPE_MAX; ++j) {
-		evsel = perf_session__find_first_evtype(session, j);
+	for (j = 0; j < OUTPUT_TYPE_MAX; ++j) {
+		evsel = perf_session__find_first_evtype(session, attr_type(j));
 
 		/*
 		 * even if fields is set to 0 (ie., show nothing) event must
 		 * exist if user explicitly includes it on the command line
 		 */
-		if (!evsel && output[j].user_set && !output[j].wildcard_set) {
+		if (!evsel && output[j].user_set && !output[j].wildcard_set &&
+		    j != OUTPUT_TYPE_SYNTH) {
 			pr_err("%s events do not exist. "
 			       "Remove corresponding -F option to proceed.\n",
 			       event_type(j));
@@ -989,6 +1026,7 @@ static void print_sample_bts(struct perf_sample *sample,
 			     struct machine *machine)
 {
 	struct perf_event_attr *attr = &evsel->attr;
+	unsigned int type = output_type(attr->type);
 	bool print_srcline_last = false;
 
 	if (PRINT_FIELD(CALLINDENT))
@@ -996,7 +1034,7 @@ static void print_sample_bts(struct perf_sample *sample,
 
 	/* print branch_from information */
 	if (PRINT_FIELD(IP)) {
-		unsigned int print_opts = output[attr->type].print_ip_opts;
+		unsigned int print_opts = output[type].print_ip_opts;
 		struct callchain_cursor *cursor = NULL;
 
 		if (symbol_conf.use_callchain && sample->callchain &&
@@ -1019,7 +1057,7 @@ static void print_sample_bts(struct perf_sample *sample,
 	/* print branch_to information */
 	if (PRINT_FIELD(ADDR) ||
 	    ((evsel->attr.sample_type & PERF_SAMPLE_ADDR) &&
-	     !output[attr->type].user_set)) {
+	     !output[type].user_set)) {
 		printf(" => ");
 		print_sample_addr(sample, thread, attr);
 	}
@@ -1215,8 +1253,9 @@ static void process_event(struct perf_script *script,
 {
 	struct thread *thread = al->thread;
 	struct perf_event_attr *attr = &evsel->attr;
+	unsigned int type = output_type(attr->type);
 
-	if (output[attr->type].fields == 0)
+	if (output[type].fields == 0)
 		return;
 
 	print_sample_start(sample, thread, evsel);
@@ -1263,7 +1302,7 @@ static void process_event(struct perf_script *script,
 			cursor = &callchain_cursor;
 
 		putchar(cursor ? '\n' : ' ');
-		sample__fprintf_sym(sample, al, 0, output[attr->type].print_ip_opts, cursor, stdout);
+		sample__fprintf_sym(sample, al, 0, output[type].print_ip_opts, cursor, stdout);
 	}
 
 	if (PRINT_FIELD(IREGS))
@@ -1410,7 +1449,8 @@ static int process_attr(struct perf_tool *tool, union perf_event *event,
 	evlist = *pevlist;
 	evsel = perf_evlist__last(*pevlist);
 
-	if (evsel->attr.type >= PERF_TYPE_MAX)
+	if (evsel->attr.type >= PERF_TYPE_MAX &&
+	    evsel->attr.type != PERF_TYPE_SYNTH)
 		return 0;
 
 	evlist__for_each_entry(evlist, pos) {
@@ -1835,6 +1875,8 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
 			type = PERF_TYPE_RAW;
 		else if (!strcmp(str, "break"))
 			type = PERF_TYPE_BREAKPOINT;
+		else if (!strcmp(str, "synth"))
+			type = OUTPUT_TYPE_SYNTH;
 		else {
 			fprintf(stderr, "Invalid event type in field string.\n");
 			rc = -EINVAL;
@@ -1865,7 +1907,7 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
 		if (output_set_by_user())
 			pr_warning("Overriding previous field request for all events.\n");
 
-		for (j = 0; j < PERF_TYPE_MAX; ++j) {
+		for (j = 0; j < OUTPUT_TYPE_MAX; ++j) {
 			output[j].fields = 0;
 			output[j].user_set = true;
 			output[j].wildcard_set = true;
@@ -1908,7 +1950,7 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
 			/* add user option to all events types for
 			 * which it is valid
 			 */
-			for (j = 0; j < PERF_TYPE_MAX; ++j) {
+			for (j = 0; j < OUTPUT_TYPE_MAX; ++j) {
 				if (output[j].invalid_fields & all_output_options[i].field) {
 					pr_warning("\'%s\' not valid for %s events. Ignoring.\n",
 						   all_output_options[i].str, event_type(j));
@@ -2560,7 +2602,7 @@ int cmd_script(int argc, const char **argv)
 	OPT_CALLBACK('F', "fields", NULL, "str",
 		     "comma separated output fields prepend with 'type:'. "
 		     "+field to add and -field to remove."
-		     "Valid types: hw,sw,trace,raw. "
+		     "Valid types: hw,sw,trace,raw,synth. "
 		     "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
 		     "addr,symoff,period,iregs,brstack,brstacksym,flags,"
 		     "bpf-output,callindent,insn,insnlen,brstackinsn",
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 7c3fa1c8cbcd..4162e72eb1b0 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -252,6 +252,9 @@ enum auxtrace_error_type {
 	PERF_AUXTRACE_ERROR_MAX
 };
 
+/* Attribute type for custom synthesized events */
+#define PERF_TYPE_SYNTH		3000000000
+
 /*
  * 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

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

* [PATCH V3 21/37] perf script: Add 'synth' field for synthesized event payloads
  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   ` Adrian Hunter
  2017-07-01  8:51   ` [tip:perf/core] " tip-bot for Adrian Hunter
  1 sibling, 0 replies; 100+ messages in thread
From: Adrian Hunter @ 2017-06-21 10:17 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Add a field to display the content the raw_data of a synthesized event.

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


Changes in V3:

	Re-base on Arnaldo's perf/core branch


 tools/perf/Documentation/perf-script.txt |  6 +++++-
 tools/perf/builtin-script.c              | 20 ++++++++++++++++++--
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index e2468ed6a307..5ee8796be96e 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -117,7 +117,8 @@ OPTIONS
         Comma separated list of fields to print. Options are:
         comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
         srcline, period, iregs, brstack, brstacksym, flags, bpf-output, brstackinsn, brstackoff,
-        callindent, insn, insnlen. Field list can be prepended with the type, trace, sw or hw,
+        callindent, insn, insnlen, synth.
+        Field list can be prepended with the type, trace, sw or hw,
         to indicate to which event type the field list applies.
         e.g., -F sw:comm,tid,time,ip,sym  and -F trace:time,cpu,trace
 
@@ -193,6 +194,9 @@ OPTIONS
 	instruction bytes and the instruction length of the current
 	instruction.
 
+	The synth field is used by synthesized events which may be created when
+	Instruction Trace decoding.
+
 	Finally, a user may not set fields to none for all event types.
 	i.e., -F "" is not allowed.
 
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 2999e7e425f6..8a827e813a9e 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -86,6 +86,7 @@ enum perf_output_field {
 	PERF_OUTPUT_INSNLEN	    = 1U << 22,
 	PERF_OUTPUT_BRSTACKINSN	    = 1U << 23,
 	PERF_OUTPUT_BRSTACKOFF	    = 1U << 24,
+	PERF_OUTPUT_SYNTH	    = 1U << 25,
 };
 
 struct output_option {
@@ -117,6 +118,7 @@ struct output_option {
 	{.str = "insnlen", .field = PERF_OUTPUT_INSNLEN},
 	{.str = "brstackinsn", .field = PERF_OUTPUT_BRSTACKINSN},
 	{.str = "brstackoff", .field = PERF_OUTPUT_BRSTACKOFF},
+	{.str = "synth", .field = PERF_OUTPUT_SYNTH},
 };
 
 enum {
@@ -196,7 +198,8 @@ enum {
 		.fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
 			      PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
 			      PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
-			      PERF_OUTPUT_SYM | PERF_OUTPUT_DSO,
+			      PERF_OUTPUT_SYM | PERF_OUTPUT_DSO |
+			      PERF_OUTPUT_SYNTH,
 
 		.invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
 	},
@@ -1200,6 +1203,15 @@ 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,
+			       struct perf_evsel *evsel)
+{
+	switch (evsel->attr.config) {
+	default:
+		break;
+	}
+}
+
 struct perf_script {
 	struct perf_tool	tool;
 	struct perf_session	*session;
@@ -1284,6 +1296,10 @@ static void process_event(struct perf_script *script,
 	if (PRINT_FIELD(TRACE))
 		event_format__print(evsel->tp_format, sample->cpu,
 				    sample->raw_data, sample->raw_size);
+
+	if (attr->type == PERF_TYPE_SYNTH && PRINT_FIELD(SYNTH))
+		print_sample_synth(sample, evsel);
+
 	if (PRINT_FIELD(ADDR))
 		print_sample_addr(sample, thread, attr);
 
@@ -2605,7 +2621,7 @@ int cmd_script(int argc, const char **argv)
 		     "Valid types: hw,sw,trace,raw,synth. "
 		     "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
 		     "addr,symoff,period,iregs,brstack,brstacksym,flags,"
-		     "bpf-output,callindent,insn,insnlen,brstackinsn",
+		     "bpf-output,callindent,insn,insnlen,brstackinsn,synth",
 		     parse_output_fields),
 	OPT_BOOLEAN('a', "all-cpus", &system_wide,
 		    "system-wide collection from all CPUs"),
-- 
1.9.1

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

* Re: [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE
  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
  1 sibling, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-06-21 10:20 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Andi Kleen, linux-kernel

On 12/06/17 16:56, Arnaldo Carvalho de Melo wrote:
> Em Mon, Jun 12, 2017 at 04:04:44PM +0300, Adrian Hunter escreveu:
>> On 26/05/17 11:17, Adrian Hunter wrote:
>>> Hi
>>>
>>> Here are some patches to support Intel PT Power events and PTWRITE.
>>> Power events report changes to C-state but I have also added support
>>> for the existing CBR (core-to-bus ratio) packet and included that
>>> when outputting power events.  The PTWRITE packet is associated with
>>> the new ptwrite instruction, which is essentially just a way to stuff
>>> a 32 or 64 bit value into the PT trace.  More details can be found in
>>> the patches that add documentation and in the Intel SDM.
>>>
>>> As far as I know, there isn't any hardware released that supports
>>> the new packets, however the CBR packet is not new and will now be
>>> visible by default.
>>>
>>> There are also some miscellaneous improvements to Intel PT.
>>>
>>> There are 3 patches that introduce a new way to define synthesized
>>> events that carry arbitrary raw_data.  I sent an RFC about that earlier.
>>> The 3 patches are:
>>>       perf script: Add 'synth' event type for synthesized events
>>>       perf script: Add 'synth' field for synthesized event payloads
>>>       perf script: Add synthesized Intel PT power and ptwrite events
>>>
>>>
>>> Changes in V2:
>>>
>>> 	Reorder patches and add stable tags to fixes.
>>>
>>
>> Apart from "perf script: Add 'synth' event type for synthesized events"
>> patches still apply.  Any comments?
> 
> I'll look at it today,

I have sent V3 of two patches that did not now apply cleanly.

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

* Re: [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE
  2017-06-21 10:20     ` Adrian Hunter
@ 2017-06-21 13:40       ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 100+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-06-21 13:40 UTC (permalink / raw)
  To: Adrian Hunter; +Cc: Andi Kleen, linux-kernel

Em Wed, Jun 21, 2017 at 01:20:52PM +0300, Adrian Hunter escreveu:
> On 12/06/17 16:56, Arnaldo Carvalho de Melo wrote:
> > Em Mon, Jun 12, 2017 at 04:04:44PM +0300, Adrian Hunter escreveu:
> >> On 26/05/17 11:17, Adrian Hunter wrote:
> >>> Hi
> >>>
> >>> Here are some patches to support Intel PT Power events and PTWRITE.
> >>> Power events report changes to C-state but I have also added support
> >>> for the existing CBR (core-to-bus ratio) packet and included that
> >>> when outputting power events.  The PTWRITE packet is associated with
> >>> the new ptwrite instruction, which is essentially just a way to stuff
> >>> a 32 or 64 bit value into the PT trace.  More details can be found in
> >>> the patches that add documentation and in the Intel SDM.
> >>>
> >>> As far as I know, there isn't any hardware released that supports
> >>> the new packets, however the CBR packet is not new and will now be
> >>> visible by default.
> >>>
> >>> There are also some miscellaneous improvements to Intel PT.
> >>>
> >>> There are 3 patches that introduce a new way to define synthesized
> >>> events that carry arbitrary raw_data.  I sent an RFC about that earlier.
> >>> The 3 patches are:
> >>>       perf script: Add 'synth' event type for synthesized events
> >>>       perf script: Add 'synth' field for synthesized event payloads
> >>>       perf script: Add synthesized Intel PT power and ptwrite events
> >>>
> >>>
> >>> Changes in V2:
> >>>
> >>> 	Reorder patches and add stable tags to fixes.
> >>>
> >>
> >> Apart from "perf script: Add 'synth' event type for synthesized events"
> >> patches still apply.  Any comments?
> > 
> > I'll look at it today,
> 
> I have sent V3 of two patches that did not now apply cleanly.

Thanks, I'm going thru that lot now, trying to understand the synth
event types handling in perf script, the ones affected by these
refreshed patches...

- Arnaldo

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

* Re: [PATCH V3 20/37] perf script: Add 'synth' event type for synthesized events
  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-07-01  8:50     ` [tip:perf/core] " tip-bot for Adrian Hunter
  1 sibling, 1 reply; 100+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-06-21 13:51 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Andi Kleen, Peter Zijlstra, Jiri Olsa, Namhyung Kim, Wang Nan,
	David Ahern, Alexander Shishkin, linux-perf-users, linux-kernel

Em Wed, Jun 21, 2017 at 01:17:19PM +0300, Adrian Hunter escreveu:
> +++ b/tools/perf/util/event.h
> @@ -252,6 +252,9 @@ enum auxtrace_error_type {
>        PERF_AUXTRACE_ERROR_MAX
> };

> +/* Attribute type for custom synthesized events */
> +#define PERF_TYPE_SYNTH		3000000000

Why don't you make it PERF_TYPE_MAX and bump PERF_TYPE_MAX by one? I.e.
this way we have what can be in attr.type in a nice enumeration, can
validate it more easily (attr.type < PERF_TYPE_MAX) and will not need to 
do those conversions to/from OUTPUT_TYPE_/PERF_TYPE_).

Peter: now its not the PERF_RECORD_ namespace that userspaces want a
chunk of, its PERF_TYPE_, which so far has been pretty stable, grabing
_one_ for event synthesizing things like Intel PT (and ARM's coresight,
I think) directly at include/uapi/linux/perf_event.h's perf_type_id enum
looks cleaner, no?

- Arnaldo

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

* Re: [PATCH V3 20/37] perf script: Add 'synth' event type for synthesized events
  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
  0 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-06-21 16:41 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Andi Kleen, Peter Zijlstra, Jiri Olsa, Namhyung Kim, Wang Nan,
	David Ahern, Alexander Shishkin, linux-perf-users, linux-kernel

On 06/21/2017 04:51 PM, Arnaldo Carvalho de Melo wrote:
> Em Wed, Jun 21, 2017 at 01:17:19PM +0300, Adrian Hunter escreveu:
>> +++ b/tools/perf/util/event.h
>> @@ -252,6 +252,9 @@ enum auxtrace_error_type {
>>        PERF_AUXTRACE_ERROR_MAX
>> };
> 
>> +/* Attribute type for custom synthesized events */
>> +#define PERF_TYPE_SYNTH		3000000000
> 
> Why don't you make it PERF_TYPE_MAX and bump PERF_TYPE_MAX by one? I.e.
> this way we have what can be in attr.type in a nice enumeration, can
> validate it more easily (attr.type < PERF_TYPE_MAX) and will not need to 
> do those conversions to/from OUTPUT_TYPE_/PERF_TYPE_).

PERF_TYPE_ is dynamically allocated above PERF_TYPE_MAX for PMUs.  Presently
perf_pmu_register() calls idr_alloc() with end=0 which limits the allocation
to INT_MAX.

> Peter: now its not the PERF_RECORD_ namespace that userspaces want a
> chunk of, its PERF_TYPE_, which so far has been pretty stable, grabing
> _one_ for event synthesizing things like Intel PT (and ARM's coresight,
> I think) directly at include/uapi/linux/perf_event.h's perf_type_id enum
> looks cleaner, no?

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

* Re: [PATCH V3 20/37] perf script: Add 'synth' event type for synthesized events
  2017-06-21 16:41       ` Adrian Hunter
@ 2017-06-21 17:29         ` Arnaldo Carvalho de Melo
  2017-06-21 20:20           ` Adrian Hunter
  0 siblings, 1 reply; 100+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-06-21 17:29 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Andi Kleen, Peter Zijlstra, Jiri Olsa, Namhyung Kim, Wang Nan,
	David Ahern, Alexander Shishkin, linux-perf-users, linux-kernel

Em Wed, Jun 21, 2017 at 07:41:04PM +0300, Adrian Hunter escreveu:
> On 06/21/2017 04:51 PM, Arnaldo Carvalho de Melo wrote:
> > Em Wed, Jun 21, 2017 at 01:17:19PM +0300, Adrian Hunter escreveu:
> >> +++ b/tools/perf/util/event.h
> >> @@ -252,6 +252,9 @@ enum auxtrace_error_type {
> >>        PERF_AUXTRACE_ERROR_MAX
> >> };
> > 
> >> +/* Attribute type for custom synthesized events */
> >> +#define PERF_TYPE_SYNTH		3000000000
> > 
> > Why don't you make it PERF_TYPE_MAX and bump PERF_TYPE_MAX by one? I.e.
> > this way we have what can be in attr.type in a nice enumeration, can
> > validate it more easily (attr.type < PERF_TYPE_MAX) and will not need to 
> > do those conversions to/from OUTPUT_TYPE_/PERF_TYPE_).
 
> PERF_TYPE_ is dynamically allocated above PERF_TYPE_MAX for PMUs.  Presently
> perf_pmu_register() calls idr_alloc() with end=0 which limits the allocation
> to INT_MAX.

Oh, forgot about that, guess a comment right beside PERF_TYPE_MAX is in
demand :-\

So why not:

/*
 * PERF_TYPE_ is dynamically allocated above PERF_TYPE_MAX for PMUs.  Presently
 * perf_pmu_register() calls idr_alloc() with end=0 which limits the allocation
 * to INT_MAX.
 */
#define PERF_TYPE_SYNTH		(INT_MAX + 1L)

I.e. wouldn't be some arbitrarily huge value, but one right after what
was defined as the area for the dynamicly allocated PERF_TYPE_
"namespace" for PMUs, right?

> > Peter: now its not the PERF_RECORD_ namespace that userspaces want a
> > chunk of, its PERF_TYPE_, which so far has been pretty stable, grabing
> > _one_ for event synthesizing things like Intel PT (and ARM's coresight,
> > I think) directly at include/uapi/linux/perf_event.h's perf_type_id enum
> > looks cleaner, no?

- Arnaldo

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

* [tip:perf/core] perf intel-pt: Move decoder error setting into one condition
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-06-21 18:19 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: tglx, linux-kernel, hpa, mingo, ak, acme, adrian.hunter

Commit-ID:  22c06892332d8916115525145b78e606e9cc6492
Gitweb:     http://git.kernel.org/tip/22c06892332d8916115525145b78e606e9cc6492
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:02 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 21 Jun 2017 11:35:43 -0300

perf intel-pt: Move decoder error setting into one condition

Move decoder error setting into one condition.

Cc'ed to stable because later fixes depend on it.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/1495786658-18063-2-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 7cf7f7a..5a9676c 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -2130,15 +2130,18 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)
 		}
 	} while (err == -ENOLINK);
 
-	decoder->state.err = err ? intel_pt_ext_err(err) : 0;
+	if (err) {
+		decoder->state.err = intel_pt_ext_err(err);
+		decoder->state.from_ip = decoder->ip;
+	} else {
+		decoder->state.err = 0;
+	}
+
 	decoder->state.timestamp = decoder->timestamp;
 	decoder->state.est_timestamp = intel_pt_est_timestamp(decoder);
 	decoder->state.cr3 = decoder->cr3;
 	decoder->state.tot_insn_cnt = decoder->tot_insn_cnt;
 
-	if (err)
-		decoder->state.from_ip = decoder->ip;
-
 	return &decoder->state;
 }
 

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

* [tip:perf/core] perf intel-pt: Improve sample timestamp
  2017-05-26  8:17 ` [PATCH V2 02/37] perf intel-pt: Improve sample timestamp Adrian Hunter
@ 2017-06-21 18:20   ` tip-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-06-21 18:20 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: ak, adrian.hunter, tglx, mingo, hpa, linux-kernel, acme

Commit-ID:  3f04d98e972b59706bd43d6cc75efac91f8fba50
Gitweb:     http://git.kernel.org/tip/3f04d98e972b59706bd43d6cc75efac91f8fba50
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:03 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 21 Jun 2017 11:35:43 -0300

perf intel-pt: Improve sample timestamp

The decoder uses its current timestamp in samples. Usually that is a
timestamp that has already passed, but in some cases it is a timestamp
for a branch that the decoder is walking towards, and consequently
hasn't reached. Improve that situation by using the pkt_state to
determine when to use the current or previous timestamp.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/1495786658-18063-3-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 .../perf/util/intel-pt-decoder/intel-pt-decoder.c  | 34 ++++++++++++++++++++--
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 5a9676c..d5c69e8 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -64,6 +64,25 @@ enum intel_pt_pkt_state {
 	INTEL_PT_STATE_FUP_NO_TIP,
 };
 
+static inline bool intel_pt_sample_time(enum intel_pt_pkt_state pkt_state)
+{
+	switch (pkt_state) {
+	case INTEL_PT_STATE_NO_PSB:
+	case INTEL_PT_STATE_NO_IP:
+	case INTEL_PT_STATE_ERR_RESYNC:
+	case INTEL_PT_STATE_IN_SYNC:
+	case INTEL_PT_STATE_TNT:
+		return true;
+	case INTEL_PT_STATE_TIP:
+	case INTEL_PT_STATE_TIP_PGD:
+	case INTEL_PT_STATE_FUP:
+	case INTEL_PT_STATE_FUP_NO_TIP:
+		return false;
+	default:
+		return true;
+	};
+}
+
 #ifdef INTEL_PT_STRICT
 #define INTEL_PT_STATE_ERR1	INTEL_PT_STATE_NO_PSB
 #define INTEL_PT_STATE_ERR2	INTEL_PT_STATE_NO_PSB
@@ -99,6 +118,7 @@ struct intel_pt_decoder {
 	uint64_t timestamp;
 	uint64_t tsc_timestamp;
 	uint64_t ref_timestamp;
+	uint64_t sample_timestamp;
 	uint64_t ret_addr;
 	uint64_t ctc_timestamp;
 	uint64_t ctc_delta;
@@ -139,6 +159,7 @@ struct intel_pt_decoder {
 	unsigned int fup_tx_flags;
 	unsigned int tx_flags;
 	uint64_t timestamp_insn_cnt;
+	uint64_t sample_insn_cnt;
 	uint64_t stuck_ip;
 	int no_progress;
 	int stuck_ip_prd;
@@ -898,6 +919,7 @@ static int intel_pt_walk_insn(struct intel_pt_decoder *decoder,
 
 	decoder->tot_insn_cnt += insn_cnt;
 	decoder->timestamp_insn_cnt += insn_cnt;
+	decoder->sample_insn_cnt += insn_cnt;
 	decoder->period_insn_cnt += insn_cnt;
 
 	if (err) {
@@ -2069,7 +2091,7 @@ static int intel_pt_sync(struct intel_pt_decoder *decoder)
 
 static uint64_t intel_pt_est_timestamp(struct intel_pt_decoder *decoder)
 {
-	uint64_t est = decoder->timestamp_insn_cnt << 1;
+	uint64_t est = decoder->sample_insn_cnt << 1;
 
 	if (!decoder->cbr || !decoder->max_non_turbo_ratio)
 		goto out;
@@ -2077,7 +2099,7 @@ static uint64_t intel_pt_est_timestamp(struct intel_pt_decoder *decoder)
 	est *= decoder->max_non_turbo_ratio;
 	est /= decoder->cbr;
 out:
-	return decoder->timestamp + est;
+	return decoder->sample_timestamp + est;
 }
 
 const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)
@@ -2133,11 +2155,17 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)
 	if (err) {
 		decoder->state.err = intel_pt_ext_err(err);
 		decoder->state.from_ip = decoder->ip;
+		decoder->sample_timestamp = decoder->timestamp;
+		decoder->sample_insn_cnt = decoder->timestamp_insn_cnt;
 	} else {
 		decoder->state.err = 0;
+		if (intel_pt_sample_time(decoder->pkt_state)) {
+			decoder->sample_timestamp = decoder->timestamp;
+			decoder->sample_insn_cnt = decoder->timestamp_insn_cnt;
+		}
 	}
 
-	decoder->state.timestamp = decoder->timestamp;
+	decoder->state.timestamp = decoder->sample_timestamp;
 	decoder->state.est_timestamp = intel_pt_est_timestamp(decoder);
 	decoder->state.cr3 = decoder->cr3;
 	decoder->state.tot_insn_cnt = decoder->tot_insn_cnt;

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

* [tip:perf/core] perf intel-pt: Fix missing stack clear
  2017-05-26  8:17 ` [PATCH V2 03/37] perf intel-pt: Fix missing stack clear Adrian Hunter
@ 2017-06-21 18:20   ` tip-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-06-21 18:20 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: adrian.hunter, linux-kernel, acme, tglx, ak, hpa, mingo

Commit-ID:  12b7080609097753fd8198cc1daf589be3ec1cca
Gitweb:     http://git.kernel.org/tip/12b7080609097753fd8198cc1daf589be3ec1cca
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:04 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 21 Jun 2017 11:35:44 -0300

perf intel-pt: Fix missing stack clear

The return compression stack must be cleared whenever there is a PSB. Fix
one case where that was not happening.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/1495786658-18063-4-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index d5c69e8..28b16c3 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -1932,6 +1932,7 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)
 			break;
 
 		case INTEL_PT_PSB:
+			intel_pt_clear_stack(&decoder->stack);
 			err = intel_pt_walk_psb(decoder);
 			if (err)
 				return err;

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

* [tip:perf/core] perf intel-pt: Ensure IP is zero when state is INTEL_PT_STATE_NO_IP
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-06-21 18:21 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: ak, adrian.hunter, acme, hpa, linux-kernel, tglx, mingo

Commit-ID:  ad7167a8cd174ba7d8c0d0ed8d8410521206d104
Gitweb:     http://git.kernel.org/tip/ad7167a8cd174ba7d8c0d0ed8d8410521206d104
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:05 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 21 Jun 2017 11:35:44 -0300

perf intel-pt: Ensure IP is zero when state is INTEL_PT_STATE_NO_IP

A value of zero is used to indicate that there is no IP. Ensure the
value is zero when the state is INTEL_PT_STATE_NO_IP.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/1495786658-18063-5-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 28b16c3..f9cd3aa 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -2117,6 +2117,7 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)
 			break;
 		case INTEL_PT_STATE_NO_IP:
 			decoder->last_ip = 0;
+			decoder->ip = 0;
 			/* Fall through */
 		case INTEL_PT_STATE_ERR_RESYNC:
 			err = intel_pt_sync_ip(decoder);

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

* [tip:perf/core] perf intel-pt: Fix last_ip usage
  2017-05-26  8:17 ` [PATCH V2 05/37] perf intel-pt: Fix last_ip usage Adrian Hunter
@ 2017-06-21 18:22   ` tip-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-06-21 18:22 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: mingo, linux-kernel, tglx, ak, adrian.hunter, acme, hpa

Commit-ID:  ee14ac0ef6827cd6f9a572cc83dd0191ea17812c
Gitweb:     http://git.kernel.org/tip/ee14ac0ef6827cd6f9a572cc83dd0191ea17812c
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:06 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 21 Jun 2017 11:35:45 -0300

perf intel-pt: Fix last_ip usage

Intel PT uses IP compression based on the last IP. For decoding
purposes, 'last IP' is considered to be reset to zero whenever there is
a synchronization packet (PSB). The decoder wasn't doing that, and was
treating the zero value to mean that there was no last IP, whereas
compression can be done against the zero value. Fix by setting last_ip
to zero when a PSB is received and keep track of have_last_ip.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/1495786658-18063-6-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index f9cd3aa..62e2c2a 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -111,6 +111,7 @@ struct intel_pt_decoder {
 	bool have_tma;
 	bool have_cyc;
 	bool fixup_last_mtc;
+	bool have_last_ip;
 	uint64_t pos;
 	uint64_t last_ip;
 	uint64_t ip;
@@ -419,6 +420,7 @@ static uint64_t intel_pt_calc_ip(const struct intel_pt_pkt *packet,
 static inline void intel_pt_set_last_ip(struct intel_pt_decoder *decoder)
 {
 	decoder->last_ip = intel_pt_calc_ip(&decoder->packet, decoder->last_ip);
+	decoder->have_last_ip = true;
 }
 
 static inline void intel_pt_set_ip(struct intel_pt_decoder *decoder)
@@ -1672,6 +1674,8 @@ next:
 			break;
 
 		case INTEL_PT_PSB:
+			decoder->last_ip = 0;
+			decoder->have_last_ip = true;
 			intel_pt_clear_stack(&decoder->stack);
 			err = intel_pt_walk_psbend(decoder);
 			if (err == -EAGAIN)
@@ -1752,7 +1756,7 @@ next:
 
 static inline bool intel_pt_have_ip(struct intel_pt_decoder *decoder)
 {
-	return decoder->last_ip || decoder->packet.count == 0 ||
+	return decoder->have_last_ip || decoder->packet.count == 0 ||
 	       decoder->packet.count == 3 || decoder->packet.count == 6;
 }
 
@@ -1882,7 +1886,7 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)
 				if (decoder->ip)
 					return 0;
 			}
-			if (decoder->packet.count)
+			if (decoder->packet.count && decoder->have_last_ip)
 				intel_pt_set_last_ip(decoder);
 			break;
 
@@ -1932,6 +1936,8 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)
 			break;
 
 		case INTEL_PT_PSB:
+			decoder->last_ip = 0;
+			decoder->have_last_ip = true;
 			intel_pt_clear_stack(&decoder->stack);
 			err = intel_pt_walk_psb(decoder);
 			if (err)
@@ -2066,6 +2072,7 @@ static int intel_pt_sync(struct intel_pt_decoder *decoder)
 
 	decoder->pge = false;
 	decoder->continuous_period = false;
+	decoder->have_last_ip = false;
 	decoder->last_ip = 0;
 	decoder->ip = 0;
 	intel_pt_clear_stack(&decoder->stack);
@@ -2074,6 +2081,7 @@ static int intel_pt_sync(struct intel_pt_decoder *decoder)
 	if (err)
 		return err;
 
+	decoder->have_last_ip = true;
 	decoder->pkt_state = INTEL_PT_STATE_NO_IP;
 
 	err = intel_pt_walk_psb(decoder);
@@ -2116,6 +2124,7 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)
 			err = intel_pt_sync(decoder);
 			break;
 		case INTEL_PT_STATE_NO_IP:
+			decoder->have_last_ip = false;
 			decoder->last_ip = 0;
 			decoder->ip = 0;
 			/* Fall through */

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

* [tip:perf/core] perf intel-pt: Ensure never to set 'last_ip' when packet 'count' is zero
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-06-21 18:22 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: ak, adrian.hunter, linux-kernel, hpa, mingo, tglx, acme

Commit-ID:  f952eaceb089b691eba7c4e13686e742a8f26bf5
Gitweb:     http://git.kernel.org/tip/f952eaceb089b691eba7c4e13686e742a8f26bf5
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:07 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 21 Jun 2017 11:35:46 -0300

perf intel-pt: Ensure never to set 'last_ip' when packet 'count' is zero

Intel PT uses IP compression based on the last IP. For decoding purposes,
'last IP' is not updated when a branch target has been suppressed, which is
indicated by IPBytes == 0. IPBytes is stored in the packet 'count', so
ensure never to set 'last_ip' when packet 'count' is zero.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/1495786658-18063-7-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 62e2c2a..72b9dc8 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -1470,7 +1470,8 @@ static int intel_pt_walk_psbend(struct intel_pt_decoder *decoder)
 
 		case INTEL_PT_FUP:
 			decoder->pge = true;
-			intel_pt_set_last_ip(decoder);
+			if (decoder->packet.count)
+				intel_pt_set_last_ip(decoder);
 			break;
 
 		case INTEL_PT_MODE_TSX:
@@ -1756,8 +1757,9 @@ next:
 
 static inline bool intel_pt_have_ip(struct intel_pt_decoder *decoder)
 {
-	return decoder->have_last_ip || decoder->packet.count == 0 ||
-	       decoder->packet.count == 3 || decoder->packet.count == 6;
+	return decoder->packet.count &&
+	       (decoder->have_last_ip || decoder->packet.count == 3 ||
+		decoder->packet.count == 6);
 }
 
 /* Walk PSB+ packets to get in sync. */

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

* [tip:perf/core] perf intel-pt: Use FUP always when scanning for an IP
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-06-21 18:23 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, acme, tglx, adrian.hunter, ak, mingo, hpa

Commit-ID:  622b7a47b843c78626f40c1d1aeef8483383fba2
Gitweb:     http://git.kernel.org/tip/622b7a47b843c78626f40c1d1aeef8483383fba2
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:08 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 21 Jun 2017 11:35:46 -0300

perf intel-pt: Use FUP always when scanning for an IP

The decoder will try to use branch packets to find an IP to start decoding
or to recover from errors. Currently the FUP packet is used only in the
case of an overflow, however there is no reason for that to be a special
case. So just use FUP always when scanning for an IP.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/1495786658-18063-8-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 72b9dc8..923c60e 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -1882,14 +1882,10 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)
 			break;
 
 		case INTEL_PT_FUP:
-			if (decoder->overflow) {
-				if (intel_pt_have_ip(decoder))
-					intel_pt_set_ip(decoder);
-				if (decoder->ip)
-					return 0;
-			}
-			if (decoder->packet.count && decoder->have_last_ip)
-				intel_pt_set_last_ip(decoder);
+			if (intel_pt_have_ip(decoder))
+				intel_pt_set_ip(decoder);
+			if (decoder->ip)
+				return 0;
 			break;
 
 		case INTEL_PT_MTC:

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

* [tip:perf/core] perf intel-pt: Clear FUP flag on error
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-06-21 18:23 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: tglx, ak, adrian.hunter, hpa, mingo, linux-kernel, acme

Commit-ID:  6a558f12dbe85437acbdec5e149ea07b5554eced
Gitweb:     http://git.kernel.org/tip/6a558f12dbe85437acbdec5e149ea07b5554eced
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:09 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 21 Jun 2017 11:35:47 -0300

perf intel-pt: Clear FUP flag on error

Sometimes a FUP packet is associated with a TSX transaction and a flag is
set to indicate that. Ensure that flag is cleared on any error condition
because at that point the decoder can no longer assume it is correct.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/1495786658-18063-9-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 923c60e..a977101 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -1962,6 +1962,8 @@ static int intel_pt_sync_ip(struct intel_pt_decoder *decoder)
 {
 	int err;
 
+	decoder->set_fup_tx_flags = false;
+
 	intel_pt_log("Scanning for full IP\n");
 	err = intel_pt_walk_to_ip(decoder);
 	if (err)

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

* [tip:perf/core] perf intel-pt: Add missing __fallthrough
  2017-05-26  8:17 ` [PATCH V2 09/37] perf intel-pt: Add missing __fallthrough Adrian Hunter
@ 2017-06-21 18:24   ` tip-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-06-21 18:24 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, tglx, hpa, mingo, acme, adrian.hunter, ak

Commit-ID:  04194207fe6424c7a1bfd6f43ef7deb90cdf716f
Gitweb:     http://git.kernel.org/tip/04194207fe6424c7a1bfd6f43ef7deb90cdf716f
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:10 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 21 Jun 2017 11:35:47 -0300

perf intel-pt: Add missing __fallthrough

perf tools uses __fallthrough. Add missing  __fallthrough to a switch
statement.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-10-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index a977101..cad40fe 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -2127,7 +2127,7 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)
 			decoder->have_last_ip = false;
 			decoder->last_ip = 0;
 			decoder->ip = 0;
-			/* Fall through */
+			__fallthrough;
 		case INTEL_PT_STATE_ERR_RESYNC:
 			err = intel_pt_sync_ip(decoder);
 			break;

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

* [tip:perf/core] perf intel-pt: Allow decoding with branch tracing disabled
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-06-21 18:24 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, ak, hpa, tglx, adrian.hunter, acme, mingo

Commit-ID:  839598176b0554967238234e1e92c7d1e3f0d53d
Gitweb:     http://git.kernel.org/tip/839598176b0554967238234e1e92c7d1e3f0d53d
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:11 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 21 Jun 2017 11:35:48 -0300

perf intel-pt: Allow decoding with branch tracing disabled

The kernel now supports the disabling of branch tracing, however the
decoder assumes branch tracing is always enabled. Pass through a parameter
to indicate whether branch tracing is enabled and use it to avoid cases
when the decoder is expecting branch packets. There are 2 such cases.
First, FUP packets which can bind to an IP even when there is no branch
tracing. Secondly, the decoder will try to use branch packets to find an IP
to start decoding or to recover from errors.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-11-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 13 +++++++++++++
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.h |  1 +
 tools/perf/util/intel-pt.c                          | 14 ++++++++++++++
 3 files changed, 28 insertions(+)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index cad40fe..dacb922 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -106,6 +106,7 @@ struct intel_pt_decoder {
 	const unsigned char *buf;
 	size_t len;
 	bool return_compression;
+	bool branch_enable;
 	bool mtc_insn;
 	bool pge;
 	bool have_tma;
@@ -214,6 +215,7 @@ struct intel_pt_decoder *intel_pt_decoder_new(struct intel_pt_params *params)
 	decoder->pgd_ip             = params->pgd_ip;
 	decoder->data               = params->data;
 	decoder->return_compression = params->return_compression;
+	decoder->branch_enable      = params->branch_enable;
 
 	decoder->period             = params->period;
 	decoder->period_type        = params->period_type;
@@ -1650,6 +1652,10 @@ next:
 				break;
 			}
 			intel_pt_set_last_ip(decoder);
+			if (!decoder->branch_enable) {
+				decoder->ip = decoder->last_ip;
+				break;
+			}
 			err = intel_pt_walk_fup(decoder);
 			if (err != -EAGAIN) {
 				if (err)
@@ -1964,6 +1970,13 @@ static int intel_pt_sync_ip(struct intel_pt_decoder *decoder)
 
 	decoder->set_fup_tx_flags = false;
 
+	if (!decoder->branch_enable) {
+		decoder->pkt_state = INTEL_PT_STATE_IN_SYNC;
+		decoder->overflow = false;
+		decoder->state.type = 0; /* Do not have a sample */
+		return 0;
+	}
+
 	intel_pt_log("Scanning for full IP\n");
 	err = intel_pt_walk_to_ip(decoder);
 	if (err)
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
index e90619a..add3bed 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
@@ -87,6 +87,7 @@ struct intel_pt_params {
 	bool (*pgd_ip)(uint64_t ip, void *data);
 	void *data;
 	bool return_compression;
+	bool branch_enable;
 	uint64_t period;
 	enum intel_pt_period_type period_type;
 	unsigned max_non_turbo_ratio;
diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 4c7718f..5c59b8c 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -668,6 +668,19 @@ static bool intel_pt_return_compression(struct intel_pt *pt)
 	return true;
 }
 
+static bool intel_pt_branch_enable(struct intel_pt *pt)
+{
+	struct perf_evsel *evsel;
+	u64 config;
+
+	evlist__for_each_entry(pt->session->evlist, evsel) {
+		if (intel_pt_get_config(pt, &evsel->attr, &config) &&
+		    (config & 1) && !(config & 0x2000))
+			return false;
+	}
+	return true;
+}
+
 static unsigned int intel_pt_mtc_period(struct intel_pt *pt)
 {
 	struct perf_evsel *evsel;
@@ -799,6 +812,7 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt,
 	params.walk_insn = intel_pt_walk_next_insn;
 	params.data = ptq;
 	params.return_compression = intel_pt_return_compression(pt);
+	params.branch_enable = intel_pt_branch_enable(pt);
 	params.max_non_turbo_ratio = pt->max_non_turbo_ratio;
 	params.mtc_period = intel_pt_mtc_period(pt);
 	params.tsc_ctc_ratio_n = pt->tsc_ctc_ratio_n;

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

* [tip:perf/core] perf intel-pt: Add default config for pass-through branch enable
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-06-21 18:25 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: hpa, mingo, acme, ak, adrian.hunter, linux-kernel, tglx

Commit-ID:  9fd629f9a6d0eded133f5f9866226f6bbfe5f50d
Gitweb:     http://git.kernel.org/tip/9fd629f9a6d0eded133f5f9866226f6bbfe5f50d
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:12 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 21 Jun 2017 11:35:48 -0300

perf intel-pt: Add default config for pass-through branch enable

Branch tracing is enabled by default, so a fake config bit called 'pt'
(pass-through) was added to allow the 'branch enable' bit to have affect.
Add default config 'pt,branch' which will allow users to disable branch
tracing using 'branch=0' instead of having to specify 'pt,branch=0'.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-12-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/arch/x86/util/intel-pt.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index 6fe667b..9535be5 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -192,6 +192,7 @@ static u64 intel_pt_default_config(struct perf_pmu *intel_pt_pmu)
 	int psb_cyc, psb_periods, psb_period;
 	int pos = 0;
 	u64 config;
+	char c;
 
 	pos += scnprintf(buf + pos, sizeof(buf) - pos, "tsc");
 
@@ -225,6 +226,10 @@ static u64 intel_pt_default_config(struct perf_pmu *intel_pt_pmu)
 		}
 	}
 
+	if (perf_pmu__scan_file(intel_pt_pmu, "format/pt", "%c", &c) == 1 &&
+	    perf_pmu__scan_file(intel_pt_pmu, "format/branch", "%c", &c) == 1)
+		pos += scnprintf(buf + pos, sizeof(buf) - pos, ",pt,branch");
+
 	pr_debug2("%s default config: %s\n", intel_pt_pmu->name, buf);
 
 	intel_pt_parse_terms(&intel_pt_pmu->format, buf, &config);

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

* [tip:perf/core] perf intel-pt: Add documentation for new config terms
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-06-21 18:25 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: acme, linux-kernel, adrian.hunter, ak, mingo, hpa, tglx

Commit-ID:  2bc60ffd663fc706ba70e603c369ae8ba0523b25
Gitweb:     http://git.kernel.org/tip/2bc60ffd663fc706ba70e603c369ae8ba0523b25
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:13 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 21 Jun 2017 11:35:49 -0300

perf intel-pt: Add documentation for new config terms

Add documentation for new config terms.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-13-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/intel-pt.txt | 36 +++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/tools/perf/Documentation/intel-pt.txt b/tools/perf/Documentation/intel-pt.txt
index b0b3007..d157dee 100644
--- a/tools/perf/Documentation/intel-pt.txt
+++ b/tools/perf/Documentation/intel-pt.txt
@@ -364,6 +364,42 @@ cyc_thresh	Specifies how frequently CYC packets are produced - see cyc
 
 		CYC packets are not requested by default.
 
+pt		Specifies pass-through which enables the 'branch' config term.
+
+		The default config selects 'pt' if it is available, so a user will
+		never need to specify this term.
+
+branch		Enable branch tracing.  Branch tracing is enabled by default so to
+		disable branch tracing use 'branch=0'.
+
+		The default config selects 'branch' if it is available.
+
+ptw		Enable PTWRITE packets which are produced when a ptwrite instruction
+		is executed.
+
+		Support for this feature is indicated by:
+
+			/sys/bus/event_source/devices/intel_pt/caps/ptwrite
+
+		which contains "1" if the feature is supported and
+		"0" otherwise.
+
+fup_on_ptw	Enable a FUP packet to follow the PTWRITE packet.  The FUP packet
+		provides the address of the ptwrite instruction.  In the absence of
+		fup_on_ptw, the decoder will use the address of the previous branch
+		if branch tracing is enabled, otherwise the address will be zero.
+		Note that fup_on_ptw will work even when branch tracing is disabled.
+
+pwr_evt		Enable power events.  The power events provide information about
+		changes to the CPU C-state.
+
+		Support for this feature is indicated by:
+
+			/sys/bus/event_source/devices/intel_pt/caps/power_event_trace
+
+		which contains "1" if the feature is supported and
+		"0" otherwise.
+
 
 new snapshot option
 -------------------

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

* [tip:perf/core] perf intel-pt: Add decoder support for ptwrite and power event packets
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-06-21 18:26 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: adrian.hunter, tglx, linux-kernel, mingo, acme, ak, hpa

Commit-ID:  a472e65fc490ab87e30b7fecb8981f02dbb2b865
Gitweb:     http://git.kernel.org/tip/a472e65fc490ab87e30b7fecb8981f02dbb2b865
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:14 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 21 Jun 2017 11:35:50 -0300

perf intel-pt: Add decoder support for ptwrite and power event packets

Add decoder support for PTWRITE, MWAIT, PWRE, PWRX and EXSTOP packets. This
patch only affects the decoder, so the tools still do not select or consume
the new information. That is added in subsequent patches.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-14-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 .../perf/util/intel-pt-decoder/intel-pt-decoder.c  | 176 ++++++++++++++++++++-
 .../perf/util/intel-pt-decoder/intel-pt-decoder.h  |  10 ++
 .../util/intel-pt-decoder/intel-pt-pkt-decoder.c   | 108 +++++++++++++
 .../util/intel-pt-decoder/intel-pt-pkt-decoder.h   |   7 +
 4 files changed, 293 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index dacb922..e42804d 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -158,8 +158,15 @@ struct intel_pt_decoder {
 	bool continuous_period;
 	bool overflow;
 	bool set_fup_tx_flags;
+	bool set_fup_ptw;
+	bool set_fup_mwait;
+	bool set_fup_pwre;
+	bool set_fup_exstop;
 	unsigned int fup_tx_flags;
 	unsigned int tx_flags;
+	uint64_t fup_ptw_payload;
+	uint64_t fup_mwait_payload;
+	uint64_t fup_pwre_payload;
 	uint64_t timestamp_insn_cnt;
 	uint64_t sample_insn_cnt;
 	uint64_t stuck_ip;
@@ -660,6 +667,8 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info)
 	case INTEL_PT_PAD:
 	case INTEL_PT_VMCS:
 	case INTEL_PT_MNT:
+	case INTEL_PT_PTWRITE:
+	case INTEL_PT_PTWRITE_IP:
 		return 0;
 
 	case INTEL_PT_MTC:
@@ -758,6 +767,11 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info)
 
 	case INTEL_PT_TIP_PGD:
 	case INTEL_PT_TRACESTOP:
+	case INTEL_PT_EXSTOP:
+	case INTEL_PT_EXSTOP_IP:
+	case INTEL_PT_MWAIT:
+	case INTEL_PT_PWRE:
+	case INTEL_PT_PWRX:
 	case INTEL_PT_OVF:
 	case INTEL_PT_BAD: /* Does not happen */
 	default:
@@ -1016,6 +1030,57 @@ out_no_progress:
 	return err;
 }
 
+static bool intel_pt_fup_event(struct intel_pt_decoder *decoder)
+{
+	bool ret = false;
+
+	if (decoder->set_fup_tx_flags) {
+		decoder->set_fup_tx_flags = false;
+		decoder->tx_flags = decoder->fup_tx_flags;
+		decoder->state.type = INTEL_PT_TRANSACTION;
+		decoder->state.from_ip = decoder->ip;
+		decoder->state.to_ip = 0;
+		decoder->state.flags = decoder->fup_tx_flags;
+		return true;
+	}
+	if (decoder->set_fup_ptw) {
+		decoder->set_fup_ptw = false;
+		decoder->state.type = INTEL_PT_PTW;
+		decoder->state.flags |= INTEL_PT_FUP_IP;
+		decoder->state.from_ip = decoder->ip;
+		decoder->state.to_ip = 0;
+		decoder->state.ptw_payload = decoder->fup_ptw_payload;
+		return true;
+	}
+	if (decoder->set_fup_mwait) {
+		decoder->set_fup_mwait = false;
+		decoder->state.type = INTEL_PT_MWAIT_OP;
+		decoder->state.from_ip = decoder->ip;
+		decoder->state.to_ip = 0;
+		decoder->state.mwait_payload = decoder->fup_mwait_payload;
+		ret = true;
+	}
+	if (decoder->set_fup_pwre) {
+		decoder->set_fup_pwre = false;
+		decoder->state.type |= INTEL_PT_PWR_ENTRY;
+		decoder->state.type &= ~INTEL_PT_BRANCH;
+		decoder->state.from_ip = decoder->ip;
+		decoder->state.to_ip = 0;
+		decoder->state.pwre_payload = decoder->fup_pwre_payload;
+		ret = true;
+	}
+	if (decoder->set_fup_exstop) {
+		decoder->set_fup_exstop = false;
+		decoder->state.type |= INTEL_PT_EX_STOP;
+		decoder->state.type &= ~INTEL_PT_BRANCH;
+		decoder->state.flags |= INTEL_PT_FUP_IP;
+		decoder->state.from_ip = decoder->ip;
+		decoder->state.to_ip = 0;
+		ret = true;
+	}
+	return ret;
+}
+
 static int intel_pt_walk_fup(struct intel_pt_decoder *decoder)
 {
 	struct intel_pt_insn intel_pt_insn;
@@ -1029,15 +1094,8 @@ static int intel_pt_walk_fup(struct intel_pt_decoder *decoder)
 		if (err == INTEL_PT_RETURN)
 			return 0;
 		if (err == -EAGAIN) {
-			if (decoder->set_fup_tx_flags) {
-				decoder->set_fup_tx_flags = false;
-				decoder->tx_flags = decoder->fup_tx_flags;
-				decoder->state.type = INTEL_PT_TRANSACTION;
-				decoder->state.from_ip = decoder->ip;
-				decoder->state.to_ip = 0;
-				decoder->state.flags = decoder->fup_tx_flags;
+			if (intel_pt_fup_event(decoder))
 				return 0;
-			}
 			return err;
 		}
 		decoder->set_fup_tx_flags = false;
@@ -1443,6 +1501,13 @@ static int intel_pt_walk_psbend(struct intel_pt_decoder *decoder)
 		case INTEL_PT_TRACESTOP:
 		case INTEL_PT_BAD:
 		case INTEL_PT_PSB:
+		case INTEL_PT_PTWRITE:
+		case INTEL_PT_PTWRITE_IP:
+		case INTEL_PT_EXSTOP:
+		case INTEL_PT_EXSTOP_IP:
+		case INTEL_PT_MWAIT:
+		case INTEL_PT_PWRE:
+		case INTEL_PT_PWRX:
 			decoder->have_tma = false;
 			intel_pt_log("ERROR: Unexpected packet\n");
 			return -EAGAIN;
@@ -1524,6 +1589,13 @@ static int intel_pt_walk_fup_tip(struct intel_pt_decoder *decoder)
 		case INTEL_PT_MODE_TSX:
 		case INTEL_PT_BAD:
 		case INTEL_PT_PSBEND:
+		case INTEL_PT_PTWRITE:
+		case INTEL_PT_PTWRITE_IP:
+		case INTEL_PT_EXSTOP:
+		case INTEL_PT_EXSTOP_IP:
+		case INTEL_PT_MWAIT:
+		case INTEL_PT_PWRE:
+		case INTEL_PT_PWRX:
 			intel_pt_log("ERROR: Missing TIP after FUP\n");
 			decoder->pkt_state = INTEL_PT_STATE_ERR3;
 			return -ENOENT;
@@ -1654,8 +1726,13 @@ next:
 			intel_pt_set_last_ip(decoder);
 			if (!decoder->branch_enable) {
 				decoder->ip = decoder->last_ip;
+				if (intel_pt_fup_event(decoder))
+					return 0;
+				no_tip = false;
 				break;
 			}
+			if (decoder->set_fup_mwait)
+				no_tip = true;
 			err = intel_pt_walk_fup(decoder);
 			if (err != -EAGAIN) {
 				if (err)
@@ -1755,6 +1832,71 @@ next:
 		case INTEL_PT_PAD:
 			break;
 
+		case INTEL_PT_PTWRITE_IP:
+			decoder->fup_ptw_payload = decoder->packet.payload;
+			err = intel_pt_get_next_packet(decoder);
+			if (err)
+				return err;
+			if (decoder->packet.type == INTEL_PT_FUP) {
+				decoder->set_fup_ptw = true;
+				no_tip = true;
+			} else {
+				intel_pt_log_at("ERROR: Missing FUP after PTWRITE",
+						decoder->pos);
+			}
+			goto next;
+
+		case INTEL_PT_PTWRITE:
+			decoder->state.type = INTEL_PT_PTW;
+			decoder->state.from_ip = decoder->ip;
+			decoder->state.to_ip = 0;
+			decoder->state.ptw_payload = decoder->packet.payload;
+			return 0;
+
+		case INTEL_PT_MWAIT:
+			decoder->fup_mwait_payload = decoder->packet.payload;
+			decoder->set_fup_mwait = true;
+			break;
+
+		case INTEL_PT_PWRE:
+			if (decoder->set_fup_mwait) {
+				decoder->fup_pwre_payload =
+							decoder->packet.payload;
+				decoder->set_fup_pwre = true;
+				break;
+			}
+			decoder->state.type = INTEL_PT_PWR_ENTRY;
+			decoder->state.from_ip = decoder->ip;
+			decoder->state.to_ip = 0;
+			decoder->state.pwrx_payload = decoder->packet.payload;
+			return 0;
+
+		case INTEL_PT_EXSTOP_IP:
+			err = intel_pt_get_next_packet(decoder);
+			if (err)
+				return err;
+			if (decoder->packet.type == INTEL_PT_FUP) {
+				decoder->set_fup_exstop = true;
+				no_tip = true;
+			} else {
+				intel_pt_log_at("ERROR: Missing FUP after EXSTOP",
+						decoder->pos);
+			}
+			goto next;
+
+		case INTEL_PT_EXSTOP:
+			decoder->state.type = INTEL_PT_EX_STOP;
+			decoder->state.from_ip = decoder->ip;
+			decoder->state.to_ip = 0;
+			return 0;
+
+		case INTEL_PT_PWRX:
+			decoder->state.type = INTEL_PT_PWR_EXIT;
+			decoder->state.from_ip = decoder->ip;
+			decoder->state.to_ip = 0;
+			decoder->state.pwrx_payload = decoder->packet.payload;
+			return 0;
+
 		default:
 			return intel_pt_bug(decoder);
 		}
@@ -1784,6 +1926,13 @@ static int intel_pt_walk_psb(struct intel_pt_decoder *decoder)
 			__fallthrough;
 		case INTEL_PT_TIP_PGE:
 		case INTEL_PT_TIP:
+		case INTEL_PT_PTWRITE:
+		case INTEL_PT_PTWRITE_IP:
+		case INTEL_PT_EXSTOP:
+		case INTEL_PT_EXSTOP_IP:
+		case INTEL_PT_MWAIT:
+		case INTEL_PT_PWRE:
+		case INTEL_PT_PWRX:
 			intel_pt_log("ERROR: Unexpected packet\n");
 			return -ENOENT;
 
@@ -1958,6 +2107,13 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)
 		case INTEL_PT_VMCS:
 		case INTEL_PT_MNT:
 		case INTEL_PT_PAD:
+		case INTEL_PT_PTWRITE:
+		case INTEL_PT_PTWRITE_IP:
+		case INTEL_PT_EXSTOP:
+		case INTEL_PT_EXSTOP_IP:
+		case INTEL_PT_MWAIT:
+		case INTEL_PT_PWRE:
+		case INTEL_PT_PWRX:
 		default:
 			break;
 		}
@@ -1969,6 +2125,10 @@ static int intel_pt_sync_ip(struct intel_pt_decoder *decoder)
 	int err;
 
 	decoder->set_fup_tx_flags = false;
+	decoder->set_fup_ptw = false;
+	decoder->set_fup_mwait = false;
+	decoder->set_fup_pwre = false;
+	decoder->set_fup_exstop = false;
 
 	if (!decoder->branch_enable) {
 		decoder->pkt_state = INTEL_PT_STATE_IN_SYNC;
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
index add3bed..414c88e 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
@@ -25,11 +25,17 @@
 #define INTEL_PT_IN_TX		(1 << 0)
 #define INTEL_PT_ABORT_TX	(1 << 1)
 #define INTEL_PT_ASYNC		(1 << 2)
+#define INTEL_PT_FUP_IP		(1 << 3)
 
 enum intel_pt_sample_type {
 	INTEL_PT_BRANCH		= 1 << 0,
 	INTEL_PT_INSTRUCTION	= 1 << 1,
 	INTEL_PT_TRANSACTION	= 1 << 2,
+	INTEL_PT_PTW		= 1 << 3,
+	INTEL_PT_MWAIT_OP	= 1 << 4,
+	INTEL_PT_PWR_ENTRY	= 1 << 5,
+	INTEL_PT_EX_STOP	= 1 << 6,
+	INTEL_PT_PWR_EXIT	= 1 << 7,
 };
 
 enum intel_pt_period_type {
@@ -63,6 +69,10 @@ struct intel_pt_state {
 	uint64_t timestamp;
 	uint64_t est_timestamp;
 	uint64_t trace_nr;
+	uint64_t ptw_payload;
+	uint64_t mwait_payload;
+	uint64_t pwre_payload;
+	uint64_t pwrx_payload;
 	uint32_t flags;
 	enum intel_pt_insn_op insn_op;
 	int insn_len;
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
index 7528ae4..accdb64 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
@@ -64,6 +64,13 @@ static const char * const packet_name[] = {
 	[INTEL_PT_PIP]		= "PIP",
 	[INTEL_PT_OVF]		= "OVF",
 	[INTEL_PT_MNT]		= "MNT",
+	[INTEL_PT_PTWRITE]	= "PTWRITE",
+	[INTEL_PT_PTWRITE_IP]	= "PTWRITE",
+	[INTEL_PT_EXSTOP]	= "EXSTOP",
+	[INTEL_PT_EXSTOP_IP]	= "EXSTOP",
+	[INTEL_PT_MWAIT]	= "MWAIT",
+	[INTEL_PT_PWRE]		= "PWRE",
+	[INTEL_PT_PWRX]		= "PWRX",
 };
 
 const char *intel_pt_pkt_name(enum intel_pt_pkt_type type)
@@ -217,12 +224,80 @@ static int intel_pt_get_3byte(const unsigned char *buf, size_t len,
 	}
 }
 
+static int intel_pt_get_ptwrite(const unsigned char *buf, size_t len,
+				struct intel_pt_pkt *packet)
+{
+	packet->count = (buf[1] >> 5) & 0x3;
+	packet->type = buf[1] & BIT(7) ? INTEL_PT_PTWRITE_IP :
+					 INTEL_PT_PTWRITE;
+
+	switch (packet->count) {
+	case 0:
+		if (len < 6)
+			return INTEL_PT_NEED_MORE_BYTES;
+		packet->payload = le32_to_cpu(*(uint32_t *)(buf + 2));
+		return 6;
+	case 1:
+		if (len < 10)
+			return INTEL_PT_NEED_MORE_BYTES;
+		packet->payload = le64_to_cpu(*(uint64_t *)(buf + 2));
+		return 10;
+	default:
+		return INTEL_PT_BAD_PACKET;
+	}
+}
+
+static int intel_pt_get_exstop(struct intel_pt_pkt *packet)
+{
+	packet->type = INTEL_PT_EXSTOP;
+	return 2;
+}
+
+static int intel_pt_get_exstop_ip(struct intel_pt_pkt *packet)
+{
+	packet->type = INTEL_PT_EXSTOP_IP;
+	return 2;
+}
+
+static int intel_pt_get_mwait(const unsigned char *buf, size_t len,
+			      struct intel_pt_pkt *packet)
+{
+	if (len < 10)
+		return INTEL_PT_NEED_MORE_BYTES;
+	packet->type = INTEL_PT_MWAIT;
+	packet->payload = le64_to_cpu(*(uint64_t *)(buf + 2));
+	return 10;
+}
+
+static int intel_pt_get_pwre(const unsigned char *buf, size_t len,
+			     struct intel_pt_pkt *packet)
+{
+	if (len < 4)
+		return INTEL_PT_NEED_MORE_BYTES;
+	packet->type = INTEL_PT_PWRE;
+	memcpy_le64(&packet->payload, buf + 2, 2);
+	return 4;
+}
+
+static int intel_pt_get_pwrx(const unsigned char *buf, size_t len,
+			     struct intel_pt_pkt *packet)
+{
+	if (len < 7)
+		return INTEL_PT_NEED_MORE_BYTES;
+	packet->type = INTEL_PT_PWRX;
+	memcpy_le64(&packet->payload, buf + 2, 5);
+	return 7;
+}
+
 static int intel_pt_get_ext(const unsigned char *buf, size_t len,
 			    struct intel_pt_pkt *packet)
 {
 	if (len < 2)
 		return INTEL_PT_NEED_MORE_BYTES;
 
+	if ((buf[1] & 0x1f) == 0x12)
+		return intel_pt_get_ptwrite(buf, len, packet);
+
 	switch (buf[1]) {
 	case 0xa3: /* Long TNT */
 		return intel_pt_get_long_tnt(buf, len, packet);
@@ -244,6 +319,16 @@ static int intel_pt_get_ext(const unsigned char *buf, size_t len,
 		return intel_pt_get_tma(buf, len, packet);
 	case 0xC3: /* 3-byte header */
 		return intel_pt_get_3byte(buf, len, packet);
+	case 0x62: /* EXSTOP no IP */
+		return intel_pt_get_exstop(packet);
+	case 0xE2: /* EXSTOP with IP */
+		return intel_pt_get_exstop_ip(packet);
+	case 0xC2: /* MWAIT */
+		return intel_pt_get_mwait(buf, len, packet);
+	case 0x22: /* PWRE */
+		return intel_pt_get_pwre(buf, len, packet);
+	case 0xA2: /* PWRX */
+		return intel_pt_get_pwrx(buf, len, packet);
 	default:
 		return INTEL_PT_BAD_PACKET;
 	}
@@ -522,6 +607,29 @@ int intel_pt_pkt_desc(const struct intel_pt_pkt *packet, char *buf,
 		ret = snprintf(buf, buf_len, "%s 0x%llx (NR=%d)",
 			       name, payload, nr);
 		return ret;
+	case INTEL_PT_PTWRITE:
+		return snprintf(buf, buf_len, "%s 0x%llx IP:0", name, payload);
+	case INTEL_PT_PTWRITE_IP:
+		return snprintf(buf, buf_len, "%s 0x%llx IP:1", name, payload);
+	case INTEL_PT_EXSTOP:
+		return snprintf(buf, buf_len, "%s IP:0", name);
+	case INTEL_PT_EXSTOP_IP:
+		return snprintf(buf, buf_len, "%s IP:1", name);
+	case INTEL_PT_MWAIT:
+		return snprintf(buf, buf_len, "%s 0x%llx Hints 0x%x Extensions 0x%x",
+				name, payload, (unsigned int)(payload & 0xff),
+				(unsigned int)((payload >> 32) & 0x3));
+	case INTEL_PT_PWRE:
+		return snprintf(buf, buf_len, "%s 0x%llx HW:%u CState:%u Sub-CState:%u",
+				name, payload, !!(payload & 0x80),
+				(unsigned int)((payload >> 12) & 0xf),
+				(unsigned int)((payload >> 8) & 0xf));
+	case INTEL_PT_PWRX:
+		return snprintf(buf, buf_len, "%s 0x%llx Last CState:%u Deepest CState:%u Wake Reason 0x%x",
+				name, payload,
+				(unsigned int)((payload >> 4) & 0xf),
+				(unsigned int)(payload & 0xf),
+				(unsigned int)((payload >> 8) & 0xf));
 	default:
 		break;
 	}
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.h b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.h
index 781bb79..73ddc3a 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.h
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.h
@@ -52,6 +52,13 @@ enum intel_pt_pkt_type {
 	INTEL_PT_PIP,
 	INTEL_PT_OVF,
 	INTEL_PT_MNT,
+	INTEL_PT_PTWRITE,
+	INTEL_PT_PTWRITE_IP,
+	INTEL_PT_EXSTOP,
+	INTEL_PT_EXSTOP_IP,
+	INTEL_PT_MWAIT,
+	INTEL_PT_PWRE,
+	INTEL_PT_PWRX,
 };
 
 struct intel_pt_pkt {

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

* [tip:perf/core] perf intel-pt: Add reserved byte to CBR packet payload
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-06-21 18:27 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, ak, adrian.hunter, mingo, tglx, acme

Commit-ID:  26fb2fb19c28ec692d6604bb01cbb4f03a4ee009
Gitweb:     http://git.kernel.org/tip/26fb2fb19c28ec692d6604bb01cbb4f03a4ee009
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:15 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 21 Jun 2017 11:35:50 -0300

perf intel-pt: Add reserved byte to CBR packet payload

Future proof CBR packet decoding by passing through also the undefined
'reserved' byte in the packet payload.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-15-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c     | 2 +-
 tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index e42804d..96bf8d8 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -1444,7 +1444,7 @@ static void intel_pt_calc_mtc_timestamp(struct intel_pt_decoder *decoder)
 
 static void intel_pt_calc_cbr(struct intel_pt_decoder *decoder)
 {
-	unsigned int cbr = decoder->packet.payload;
+	unsigned int cbr = decoder->packet.payload & 0xff;
 
 	if (decoder->cbr == cbr)
 		return;
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
index accdb64..ba4c9dd 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
@@ -130,7 +130,7 @@ static int intel_pt_get_cbr(const unsigned char *buf, size_t len,
 	if (len < 4)
 		return INTEL_PT_NEED_MORE_BYTES;
 	packet->type = INTEL_PT_CBR;
-	packet->payload = buf[2];
+	packet->payload = le16_to_cpu(*(uint16_t *)(buf + 2));
 	return 4;
 }
 

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

* [tip:perf/core] perf intel-pt: Add decoder support for CBR events
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-06-21 18:27 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: tglx, linux-kernel, acme, adrian.hunter, mingo, ak, hpa

Commit-ID:  0a7c700d23450bd4467855d5162920d5edf314b0
Gitweb:     http://git.kernel.org/tip/0a7c700d23450bd4467855d5162920d5edf314b0
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:16 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 21 Jun 2017 11:35:51 -0300

perf intel-pt: Add decoder support for CBR events

Add decoder support for informing the tools of changes to the core-to-bus
ratio (CBR).

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-16-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 19 +++++++++++++++++++
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.h |  2 ++
 2 files changed, 21 insertions(+)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 96bf8d8..5dea062 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -141,6 +141,7 @@ struct intel_pt_decoder {
 	int pkt_len;
 	int last_packet_type;
 	unsigned int cbr;
+	unsigned int cbr_seen;
 	unsigned int max_non_turbo_ratio;
 	double max_non_turbo_ratio_fp;
 	double cbr_cyc_to_tsc;
@@ -167,6 +168,7 @@ struct intel_pt_decoder {
 	uint64_t fup_ptw_payload;
 	uint64_t fup_mwait_payload;
 	uint64_t fup_pwre_payload;
+	uint64_t cbr_payload;
 	uint64_t timestamp_insn_cnt;
 	uint64_t sample_insn_cnt;
 	uint64_t stuck_ip;
@@ -1446,6 +1448,8 @@ static void intel_pt_calc_cbr(struct intel_pt_decoder *decoder)
 {
 	unsigned int cbr = decoder->packet.payload & 0xff;
 
+	decoder->cbr_payload = decoder->packet.payload;
+
 	if (decoder->cbr == cbr)
 		return;
 
@@ -1806,6 +1810,16 @@ next:
 
 		case INTEL_PT_CBR:
 			intel_pt_calc_cbr(decoder);
+			if (!decoder->branch_enable &&
+			    decoder->cbr != decoder->cbr_seen) {
+				decoder->cbr_seen = decoder->cbr;
+				decoder->state.type = INTEL_PT_CBR_CHG;
+				decoder->state.from_ip = decoder->ip;
+				decoder->state.to_ip = 0;
+				decoder->state.cbr_payload =
+							decoder->packet.payload;
+				return 0;
+			}
 			break;
 
 		case INTEL_PT_MODE_EXEC:
@@ -2343,6 +2357,11 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)
 		decoder->sample_insn_cnt = decoder->timestamp_insn_cnt;
 	} else {
 		decoder->state.err = 0;
+		if (decoder->cbr != decoder->cbr_seen && decoder->state.type) {
+			decoder->cbr_seen = decoder->cbr;
+			decoder->state.type |= INTEL_PT_CBR_CHG;
+			decoder->state.cbr_payload = decoder->cbr_payload;
+		}
 		if (intel_pt_sample_time(decoder->pkt_state)) {
 			decoder->sample_timestamp = decoder->timestamp;
 			decoder->sample_insn_cnt = decoder->timestamp_insn_cnt;
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
index 414c88e..921b22e 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
@@ -36,6 +36,7 @@ enum intel_pt_sample_type {
 	INTEL_PT_PWR_ENTRY	= 1 << 5,
 	INTEL_PT_EX_STOP	= 1 << 6,
 	INTEL_PT_PWR_EXIT	= 1 << 7,
+	INTEL_PT_CBR_CHG	= 1 << 8,
 };
 
 enum intel_pt_period_type {
@@ -73,6 +74,7 @@ struct intel_pt_state {
 	uint64_t mwait_payload;
 	uint64_t pwre_payload;
 	uint64_t pwrx_payload;
+	uint64_t cbr_payload;
 	uint32_t flags;
 	enum intel_pt_insn_op insn_op;
 	int insn_len;

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

* [tip:perf/core] perf intel-pt: Remove redundant initial_skip checks
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-06-21 18:28 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: hpa, adrian.hunter, acme, ak, linux-kernel, tglx, mingo

Commit-ID:  5da3b23b3b03d34fbb8cb9947c1a99ea77c2203f
Gitweb:     http://git.kernel.org/tip/5da3b23b3b03d34fbb8cb9947c1a99ea77c2203f
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:17 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 21 Jun 2017 11:35:51 -0300

perf intel-pt: Remove redundant initial_skip checks

'initial_skip' is checked inside the sample synthesis functions which means
it is actually being done twice for 'instructions' and 'transactions'
samples. Remove the redundant checks.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-17-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 5c59b8c..3ae03f9 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1322,18 +1322,14 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)
 	ptq->have_sample = false;
 
 	if (pt->sample_instructions &&
-	    (state->type & INTEL_PT_INSTRUCTION) &&
-	    (!pt->synth_opts.initial_skip ||
-	     pt->num_events++ >= pt->synth_opts.initial_skip)) {
+	    (state->type & INTEL_PT_INSTRUCTION)) {
 		err = intel_pt_synth_instruction_sample(ptq);
 		if (err)
 			return err;
 	}
 
 	if (pt->sample_transactions &&
-	    (state->type & INTEL_PT_TRANSACTION) &&
-	    (!pt->synth_opts.initial_skip ||
-	     pt->num_events++ >= pt->synth_opts.initial_skip)) {
+	    (state->type & INTEL_PT_TRANSACTION)) {
 		err = intel_pt_synth_transaction_sample(ptq);
 		if (err)
 			return err;

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

* [tip:perf/core] perf intel-pt: Fix transactions_sample_type
  2017-05-26  8:17 ` [PATCH V2 17/37] perf intel-pt: Fix transactions_sample_type Adrian Hunter
@ 2017-06-21 18:28   ` tip-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-06-21 18:28 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: hpa, mingo, linux-kernel, tglx, acme, adrian.hunter, ak

Commit-ID:  2116074898ff9ff093963adc0fefcabbbbd7ec41
Gitweb:     http://git.kernel.org/tip/2116074898ff9ff093963adc0fefcabbbbd7ec41
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:18 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 21 Jun 2017 11:35:52 -0300

perf intel-pt: Fix transactions_sample_type

'transactions_sample_type' is needed to correctly inject transactions
samples but it was not being set. Set it from the event sample type.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-18-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 3ae03f9..6df8364 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -2035,6 +2035,7 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 			return err;
 		}
 		pt->sample_transactions = true;
+		pt->transactions_sample_type = attr.sample_type;
 		pt->transactions_id = id;
 		id += 1;
 		evlist__for_each_entry(evlist, evsel) {

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

* [tip:perf/core] perf tools: Fix message because cpu list option is -C not -c
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-06-21 18:29 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: ak, acme, adrian.hunter, tglx, linux-kernel, hpa, mingo

Commit-ID:  30795467e54f3fe0d00f2dba4e58e6475b8fd2e7
Gitweb:     http://git.kernel.org/tip/30795467e54f3fe0d00f2dba4e58e6475b8fd2e7
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:19 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 21 Jun 2017 11:35:53 -0300

perf tools: Fix message because cpu list option is -C not -c

Fix message because cpu list option is -C not -c

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-19-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/session.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 7dc1096..d19c40a 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -2035,7 +2035,7 @@ int perf_session__cpu_bitmap(struct perf_session *session,
 
 		if (!(evsel->attr.sample_type & PERF_SAMPLE_CPU)) {
 			pr_err("File does not contain CPU events. "
-			       "Remove -c option to proceed.\n");
+			       "Remove -C option to proceed.\n");
 			return -1;
 		}
 	}

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

* [tip:perf/core] perf script: Fix message because field list option is -F not -f
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-06-21 18:29 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: ak, acme, tglx, adrian.hunter, mingo, hpa, linux-kernel

Commit-ID:  701516ae3dec801084bc913d21e03fce15c61a0b
Gitweb:     http://git.kernel.org/tip/701516ae3dec801084bc913d21e03fce15c61a0b
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:20 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 21 Jun 2017 11:35:53 -0300

perf script: Fix message because field list option is -F not -f

Fix message because field list option is -F not -f.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-20-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-script.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index db5261c..4bce7d8 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -385,7 +385,7 @@ static int perf_session__check_output_opt(struct perf_session *session)
 		 */
 		if (!evsel && output[j].user_set && !output[j].wildcard_set) {
 			pr_err("%s events do not exist. "
-			       "Remove corresponding -f option to proceed.\n",
+			       "Remove corresponding -F option to proceed.\n",
 			       event_type(j));
 			return -1;
 		}

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

* Re: [PATCH V3 20/37] perf script: Add 'synth' event type for synthesized events
  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
  0 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-06-21 20:20 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Andi Kleen, Peter Zijlstra, Jiri Olsa, Namhyung Kim, Wang Nan,
	David Ahern, Alexander Shishkin, linux-perf-users, linux-kernel

On 06/21/2017 08:29 PM, Arnaldo Carvalho de Melo wrote:
> Em Wed, Jun 21, 2017 at 07:41:04PM +0300, Adrian Hunter escreveu:
>> On 06/21/2017 04:51 PM, Arnaldo Carvalho de Melo wrote:
>>> Em Wed, Jun 21, 2017 at 01:17:19PM +0300, Adrian Hunter escreveu:
>>>> +++ b/tools/perf/util/event.h
>>>> @@ -252,6 +252,9 @@ enum auxtrace_error_type {
>>>>        PERF_AUXTRACE_ERROR_MAX
>>>> };
>>>
>>>> +/* Attribute type for custom synthesized events */
>>>> +#define PERF_TYPE_SYNTH		3000000000
>>>
>>> Why don't you make it PERF_TYPE_MAX and bump PERF_TYPE_MAX by one? I.e.
>>> this way we have what can be in attr.type in a nice enumeration, can
>>> validate it more easily (attr.type < PERF_TYPE_MAX) and will not need to 
>>> do those conversions to/from OUTPUT_TYPE_/PERF_TYPE_).
>  
>> PERF_TYPE_ is dynamically allocated above PERF_TYPE_MAX for PMUs.  Presently
>> perf_pmu_register() calls idr_alloc() with end=0 which limits the allocation
>> to INT_MAX.
> 
> Oh, forgot about that, guess a comment right beside PERF_TYPE_MAX is in
> demand :-\
> 
> So why not:
> 
> /*
>  * PERF_TYPE_ is dynamically allocated above PERF_TYPE_MAX for PMUs.  Presently
>  * perf_pmu_register() calls idr_alloc() with end=0 which limits the allocation
>  * to INT_MAX.
>  */
> #define PERF_TYPE_SYNTH		(INT_MAX + 1L)
> 
> I.e. wouldn't be some arbitrarily huge value, but one right after what
> was defined as the area for the dynamicly allocated PERF_TYPE_
> "namespace" for PMUs, right?

That seems fine.  Pedantically it should be (INT_MAX + 1U) otherwise it will
be negative on a 32-bit system.

> 
>>> Peter: now its not the PERF_RECORD_ namespace that userspaces want a
>>> chunk of, its PERF_TYPE_, which so far has been pretty stable, grabing
>>> _one_ for event synthesizing things like Intel PT (and ARM's coresight,
>>> I think) directly at include/uapi/linux/perf_event.h's perf_type_id enum
>>> looks cleaner, no?
> 
> - Arnaldo
> 

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

* Re: [PATCH V3 20/37] perf script: Add 'synth' event type for synthesized events
  2017-06-21 20:20           ` Adrian Hunter
@ 2017-06-22 14:59             ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 100+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-06-22 14:59 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Andi Kleen, Peter Zijlstra, Jiri Olsa, Namhyung Kim, Wang Nan,
	David Ahern, Alexander Shishkin, linux-perf-users, linux-kernel

Em Wed, Jun 21, 2017 at 11:20:03PM +0300, Adrian Hunter escreveu:
> On 06/21/2017 08:29 PM, Arnaldo Carvalho de Melo wrote:
> > Em Wed, Jun 21, 2017 at 07:41:04PM +0300, Adrian Hunter escreveu:
> >> PERF_TYPE_ is dynamically allocated above PERF_TYPE_MAX for PMUs.  Presently
> >> perf_pmu_register() calls idr_alloc() with end=0 which limits the allocation
> >> to INT_MAX.

> > Oh, forgot about that, guess a comment right beside PERF_TYPE_MAX is in
> > demand :-\

> > So why not:

> > /*
> >  * PERF_TYPE_ is dynamically allocated above PERF_TYPE_MAX for PMUs.  Presently
> >  * perf_pmu_register() calls idr_alloc() with end=0 which limits the allocation
> >  * to INT_MAX.
> >  */
> > #define PERF_TYPE_SYNTH		(INT_MAX + 1L)

> > I.e. wouldn't be some arbitrarily huge value, but one right after what
> > was defined as the area for the dynamicly allocated PERF_TYPE_
> > "namespace" for PMUs, right?
 
> That seems fine.  Pedantically it should be (INT_MAX + 1U) otherwise it will
> be negative on a 32-bit system.

oh, not pedantic at all, thanks for the fix, will update your patch and
continue from there, Ingo already pulled everything up to this point,
btw.

- Arnaldo

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

* Re: [PATCH V2 00/37] perf intel-pt: Power events and PTWRITE
  2017-06-12 13:56   ` Arnaldo Carvalho de Melo
  2017-06-21 10:20     ` Adrian Hunter
@ 2017-06-27 15:27     ` Arnaldo Carvalho de Melo
  1 sibling, 0 replies; 100+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-06-27 15:27 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Adrian Hunter, Andi Kleen, linux-kernel

Em Mon, Jun 12, 2017 at 10:56:05AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Mon, Jun 12, 2017 at 04:04:44PM +0300, Adrian Hunter escreveu:
> > On 26/05/17 11:17, Adrian Hunter wrote:
> > > Hi
> > > 
> > > Here are some patches to support Intel PT Power events and PTWRITE.
> > > Power events report changes to C-state but I have also added support
> > > for the existing CBR (core-to-bus ratio) packet and included that
> > > when outputting power events.  The PTWRITE packet is associated with
> > > the new ptwrite instruction, which is essentially just a way to stuff
> > > a 32 or 64 bit value into the PT trace.  More details can be found in
> > > the patches that add documentation and in the Intel SDM.
> > > 
> > > As far as I know, there isn't any hardware released that supports
> > > the new packets, however the CBR packet is not new and will now be
> > > visible by default.
> > > 
> > > There are also some miscellaneous improvements to Intel PT.
> > > 
> > > There are 3 patches that introduce a new way to define synthesized
> > > events that carry arbitrary raw_data.  I sent an RFC about that earlier.
> > > The 3 patches are:
> > >       perf script: Add 'synth' event type for synthesized events
> > >       perf script: Add 'synth' field for synthesized event payloads
> > >       perf script: Add synthesized Intel PT power and ptwrite events
> > > 
> > > 
> > > Changes in V2:
> > > 
> > > 	Reorder patches and add stable tags to fixes.
> > > 
> > 
> > Apart from "perf script: Add 'synth' event type for synthesized events"
> > patches still apply.  Any comments?
> 
> I'll look at it today,

Applied, will do some testing on a Kaby Lake machine before pushing to
Ingo, will leave in my tmp.perf/core branch before that.

- Arnaldo

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

* Re: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
  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-30  8:36   ` [PATCH V3 " Adrian Hunter
  1 sibling, 1 reply; 100+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-06-28 13:04 UTC (permalink / raw)
  To: Adrian Hunter; +Cc: Andi Kleen, linux-kernel

Em Fri, May 26, 2017 at 11:17:26AM +0300, Adrian Hunter escreveu:
> Add definitions for synthesized Intel PT events for power and ptwrite.
 
> +++ b/tools/perf/util/event.h
> +/*
> + * Raw data formats for synthesized events. Note that raw data plus the raw data
> + * size (4 bytes) must align to 8-bytes.
> + */
> +
> +struct perf_synth_intel_ptwrite {
> +	union {
> +		struct {
> +			u32	ip		:  1,
> +				reserved	: 31;
> +		};
> +		u32	flags;
> +	};
> +	u64	payload;
> +} __packed;


some versions of clang and gcc dislike this __packed here:

In file included from builtin-script.c:5:
In file included from /git/linux/tools/perf/util/debug.h:8:
/git/linux/tools/perf/util/event.h:274:2: error: packed attribute is unnecessary for (null) [-Werror,-Wpacked]
        union {
        ^
/git/linux/tools/perf/util/event.h:285:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked]
        u32 reserved;
            ^
/git/linux/tools/perf/util/event.h:298:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked]
        u32 reserved;
            ^
/git/linux/tools/perf/util/event.h:322:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked]
        u32 reserved;
            ^
4 errors generated.
mv: can't rename '/tmp/build/perf/.builtin-script.o.tmp': No such file or directory

/git/linux/tools/build/Makefile.build:101: recipe for target '/tmp/build/perf/builtin-script.o' failed

Failing in various distros:

[root@jouet ~]# waitp 3940 ; time dm
   1 92.3684147260 alpine:3.4: FAIL
   2 95.9136365930 alpine:3.5: FAIL
   3 104.8328303770 alpine:3.6: FAIL
   4 121.6584964930 alpine:edge: FAIL
   5 37.2536373490 android-ndk:r12b-arm: Ok
   6 83.9077612370 archlinux:latest: Ok
   7 14.7094639200 centos:5: FAIL
   8 16.6371634320 centos:6: FAIL

Investigating...

> +
> +struct perf_synth_intel_mwait {
> +	u32 reserved;
> +	union {
> +		struct {
> +			u64	hints		:  8,
> +				reserved1	: 24,
> +				extensions	:  2,
> +				reserved2	: 30;
> +		};
> +		u64	payload;
> +	};
> +} __packed;
> +
> +struct perf_synth_intel_pwre {
> +	u32 reserved;
> +	union {
> +		struct {
> +			u64	reserved1	:  7,
> +				hw		:  1,
> +				subcstate	:  4,
> +				cstate		:  4,
> +				reserved2	: 48;
> +		};
> +		u64	payload;
> +	};
> +} __packed;
> +
> +struct perf_synth_intel_exstop {
> +	union {
> +		struct {
> +			u32	ip		:  1,
> +				reserved	: 31;
> +		};
> +		u32	flags;
> +	};
> +};
> +
> +struct perf_synth_intel_pwrx {
> +	u32 reserved;
> +	union {
> +		struct {
> +			u64	deepest_cstate	:  4,
> +				last_cstate	:  4,
> +				wake_reason	:  4,
> +				reserved1	: 52;
> +		};
> +		u64	payload;
> +	};
> +} __packed;
> +
> +struct perf_synth_intel_cbr {
> +	union {
> +		struct {
> +			u32	cbr		:  8,
> +				reserved1	:  8,
> +				max_nonturbo	:  8,
> +				reserved2	:  8;
> +		};
> +		u32	flags;
> +	};
> +	u32 freq;
> +	u32 reserved3;
> +};
> +
>  /*
>   * 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

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

* Re: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
  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
  0 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-06-28 17:40 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Andi Kleen, linux-kernel

On 06/28/2017 04:04 PM, Arnaldo Carvalho de Melo wrote:
> Em Fri, May 26, 2017 at 11:17:26AM +0300, Adrian Hunter escreveu:
>> Add definitions for synthesized Intel PT events for power and ptwrite.
>  
>> +++ b/tools/perf/util/event.h
>> +/*
>> + * Raw data formats for synthesized events. Note that raw data plus the raw data
>> + * size (4 bytes) must align to 8-bytes.
>> + */
>> +
>> +struct perf_synth_intel_ptwrite {
>> +	union {
>> +		struct {
>> +			u32	ip		:  1,
>> +				reserved	: 31;
>> +		};
>> +		u32	flags;
>> +	};
>> +	u64	payload;
>> +} __packed;
> 
> 
> some versions of clang and gcc dislike this __packed here:
> 
> In file included from builtin-script.c:5:
> In file included from /git/linux/tools/perf/util/debug.h:8:
> /git/linux/tools/perf/util/event.h:274:2: error: packed attribute is unnecessary for (null) [-Werror,-Wpacked]
>         union {
>         ^
> /git/linux/tools/perf/util/event.h:285:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked]
>         u32 reserved;
>             ^
> /git/linux/tools/perf/util/event.h:298:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked]
>         u32 reserved;
>             ^
> /git/linux/tools/perf/util/event.h:322:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked]
>         u32 reserved;
>             ^
> 4 errors generated.
> mv: can't rename '/tmp/build/perf/.builtin-script.o.tmp': No such file or directory
> 
> /git/linux/tools/build/Makefile.build:101: recipe for target '/tmp/build/perf/builtin-script.o' failed
> 
> Failing in various distros:
> 
> [root@jouet ~]# waitp 3940 ; time dm
>    1 92.3684147260 alpine:3.4: FAIL
>    2 95.9136365930 alpine:3.5: FAIL
>    3 104.8328303770 alpine:3.6: FAIL
>    4 121.6584964930 alpine:edge: FAIL
>    5 37.2536373490 android-ndk:r12b-arm: Ok
>    6 83.9077612370 archlinux:latest: Ok
>    7 14.7094639200 centos:5: FAIL
>    8 16.6371634320 centos:6: FAIL
> 
> Investigating...

Re-reading the documentation for __packed, it seems like the following
might be better:

diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index c283603f59c7..a7547cb3b760 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -278,8 +278,8 @@ struct perf_synth_intel_ptwrite {
 		};
 		u32	flags;
 	};
-	u64	payload;
-} __packed;
+	u64	payload __packed;
+};
 
 struct perf_synth_intel_mwait {
 	u32 reserved;
@@ -291,8 +291,8 @@ struct perf_synth_intel_mwait {
 				reserved2	: 30;
 		};
 		u64	payload;
-	};
-} __packed;
+	} __packed;
+};
 
 struct perf_synth_intel_pwre {
 	u32 reserved;
@@ -305,8 +305,8 @@ struct perf_synth_intel_pwre {
 				reserved2	: 48;
 		};
 		u64	payload;
-	};
-} __packed;
+	} __packed;
+};
 
 struct perf_synth_intel_exstop {
 	union {
@@ -328,8 +328,8 @@ struct perf_synth_intel_pwrx {
 				reserved1	: 52;
 		};
 		u64	payload;
-	};
-} __packed;
+	} __packed;
+};
 
 struct perf_synth_intel_cbr {
 	union {

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

* Re: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
  2017-06-28 17:40     ` Adrian Hunter
@ 2017-06-28 18:53       ` Arnaldo Carvalho de Melo
  2017-06-28 20:21         ` Hunter, Adrian
  0 siblings, 1 reply; 100+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-06-28 18:53 UTC (permalink / raw)
  To: Adrian Hunter; +Cc: Andi Kleen, linux-kernel

Em Wed, Jun 28, 2017 at 08:40:25PM +0300, Adrian Hunter escreveu:
> On 06/28/2017 04:04 PM, Arnaldo Carvalho de Melo wrote:
> > Em Fri, May 26, 2017 at 11:17:26AM +0300, Adrian Hunter escreveu:
> >> Add definitions for synthesized Intel PT events for power and ptwrite.
> >  
> >> +++ b/tools/perf/util/event.h
> >> +/*
> >> + * Raw data formats for synthesized events. Note that raw data plus the raw data
> >> + * size (4 bytes) must align to 8-bytes.
> >> + */
> >> +
> >> +struct perf_synth_intel_ptwrite {
> >> +	union {
> >> +		struct {
> >> +			u32	ip		:  1,
> >> +				reserved	: 31;
> >> +		};
> >> +		u32	flags;
> >> +	};
> >> +	u64	payload;
> >> +} __packed;
> > 
> > 
> > some versions of clang and gcc dislike this __packed here:
> > 
> > In file included from builtin-script.c:5:
> > In file included from /git/linux/tools/perf/util/debug.h:8:
> > /git/linux/tools/perf/util/event.h:274:2: error: packed attribute is unnecessary for (null) [-Werror,-Wpacked]
> >         union {
> >         ^
> > /git/linux/tools/perf/util/event.h:285:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked]
> >         u32 reserved;
> >             ^
> > /git/linux/tools/perf/util/event.h:298:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked]
> >         u32 reserved;
> >             ^
> > /git/linux/tools/perf/util/event.h:322:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked]
> >         u32 reserved;
> >             ^
> > 4 errors generated.
> > mv: can't rename '/tmp/build/perf/.builtin-script.o.tmp': No such file or directory
> > 
> > /git/linux/tools/build/Makefile.build:101: recipe for target '/tmp/build/perf/builtin-script.o' failed
> > 
> > Failing in various distros:
> > 
> > [root@jouet ~]# waitp 3940 ; time dm
> >    1 92.3684147260 alpine:3.4: FAIL
> >    2 95.9136365930 alpine:3.5: FAIL
> >    3 104.8328303770 alpine:3.6: FAIL
> >    4 121.6584964930 alpine:edge: FAIL
> >    5 37.2536373490 android-ndk:r12b-arm: Ok
> >    6 83.9077612370 archlinux:latest: Ok
> >    7 14.7094639200 centos:5: FAIL
> >    8 16.6371634320 centos:6: FAIL
> > 
> > Investigating...
> 
> Re-reading the documentation for __packed, it seems like the following
> might be better:

Humm, can you provide the URL for such docs? I always saw packed as an
attribute for a struct, not for a member... For members "aligned" is
what I'm used to see:

   __attribute__ ((aligned (8)))

In the kernel sources there are a few such cases as you suggest:

[acme@jouet linux]$ find include/ -name "*.h"| xargs grep -w __packed | grep -v } | grep -v "struct __packed" | wc -l
12
[acme@jouet linux]$

But most are the other way, i.e. tagging the packed attribute to the
whole struct, as you originally did :-\

- Arnaldo
 
> diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
> index c283603f59c7..a7547cb3b760 100644
> --- a/tools/perf/util/event.h
> +++ b/tools/perf/util/event.h
> @@ -278,8 +278,8 @@ struct perf_synth_intel_ptwrite {
>  		};
>  		u32	flags;
>  	};
> -	u64	payload;
> -} __packed;
> +	u64	payload __packed;
> +};
>  
>  struct perf_synth_intel_mwait {
>  	u32 reserved;
> @@ -291,8 +291,8 @@ struct perf_synth_intel_mwait {
>  				reserved2	: 30;
>  		};
>  		u64	payload;
> -	};
> -} __packed;
> +	} __packed;
> +};
>  
>  struct perf_synth_intel_pwre {
>  	u32 reserved;
> @@ -305,8 +305,8 @@ struct perf_synth_intel_pwre {
>  				reserved2	: 48;
>  		};
>  		u64	payload;
> -	};
> -} __packed;
> +	} __packed;
> +};
>  
>  struct perf_synth_intel_exstop {
>  	union {
> @@ -328,8 +328,8 @@ struct perf_synth_intel_pwrx {
>  				reserved1	: 52;
>  		};
>  		u64	payload;
> -	};
> -} __packed;
> +	} __packed;
> +};
>  
>  struct perf_synth_intel_cbr {
>  	union {

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

* RE: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
  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
  0 siblings, 1 reply; 100+ messages in thread
From: Hunter, Adrian @ 2017-06-28 20:21 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Andi Kleen, linux-kernel

Sorry for the top-post...

Yeah, I've now mixed up the variable attribute:

	https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes
 
with the type attribute:

	https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#Common-Type-Attributes

Late here, so maybe it will make more sense tomorrow.

-----Original Message-----
From: Arnaldo Carvalho de Melo [mailto:acme@kernel.org] 
Sent: Wednesday, June 28, 2017 9:54 PM
To: Hunter, Adrian <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>; linux-kernel@vger.kernel.org
Subject: Re: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events

Em Wed, Jun 28, 2017 at 08:40:25PM +0300, Adrian Hunter escreveu:
> On 06/28/2017 04:04 PM, Arnaldo Carvalho de Melo wrote:
> > Em Fri, May 26, 2017 at 11:17:26AM +0300, Adrian Hunter escreveu:
> >> Add definitions for synthesized Intel PT events for power and ptwrite.
> >  
> >> +++ b/tools/perf/util/event.h
> >> +/*
> >> + * Raw data formats for synthesized events. Note that raw data 
> >> +plus the raw data
> >> + * size (4 bytes) must align to 8-bytes.
> >> + */
> >> +
> >> +struct perf_synth_intel_ptwrite {
> >> +	union {
> >> +		struct {
> >> +			u32	ip		:  1,
> >> +				reserved	: 31;
> >> +		};
> >> +		u32	flags;
> >> +	};
> >> +	u64	payload;
> >> +} __packed;
> > 
> > 
> > some versions of clang and gcc dislike this __packed here:
> > 
> > In file included from builtin-script.c:5:
> > In file included from /git/linux/tools/perf/util/debug.h:8:
> > /git/linux/tools/perf/util/event.h:274:2: error: packed attribute is unnecessary for (null) [-Werror,-Wpacked]
> >         union {
> >         ^
> > /git/linux/tools/perf/util/event.h:285:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked]
> >         u32 reserved;
> >             ^
> > /git/linux/tools/perf/util/event.h:298:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked]
> >         u32 reserved;
> >             ^
> > /git/linux/tools/perf/util/event.h:322:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked]
> >         u32 reserved;
> >             ^
> > 4 errors generated.
> > mv: can't rename '/tmp/build/perf/.builtin-script.o.tmp': No such 
> > file or directory
> > 
> > /git/linux/tools/build/Makefile.build:101: recipe for target 
> > '/tmp/build/perf/builtin-script.o' failed
> > 
> > Failing in various distros:
> > 
> > [root@jouet ~]# waitp 3940 ; time dm
> >    1 92.3684147260 alpine:3.4: FAIL
> >    2 95.9136365930 alpine:3.5: FAIL
> >    3 104.8328303770 alpine:3.6: FAIL
> >    4 121.6584964930 alpine:edge: FAIL
> >    5 37.2536373490 android-ndk:r12b-arm: Ok
> >    6 83.9077612370 archlinux:latest: Ok
> >    7 14.7094639200 centos:5: FAIL
> >    8 16.6371634320 centos:6: FAIL
> > 
> > Investigating...
> 
> Re-reading the documentation for __packed, it seems like the following 
> might be better:

Humm, can you provide the URL for such docs? I always saw packed as an attribute for a struct, not for a member... For members "aligned" is what I'm used to see:

   __attribute__ ((aligned (8)))

In the kernel sources there are a few such cases as you suggest:

[acme@jouet linux]$ find include/ -name "*.h"| xargs grep -w __packed | grep -v } | grep -v "struct __packed" | wc -l
12
[acme@jouet linux]$

But most are the other way, i.e. tagging the packed attribute to the whole struct, as you originally did :-\

- Arnaldo
 
> diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index 
> c283603f59c7..a7547cb3b760 100644
> --- a/tools/perf/util/event.h
> +++ b/tools/perf/util/event.h
> @@ -278,8 +278,8 @@ struct perf_synth_intel_ptwrite {
>  		};
>  		u32	flags;
>  	};
> -	u64	payload;
> -} __packed;
> +	u64	payload __packed;
> +};
>  
>  struct perf_synth_intel_mwait {
>  	u32 reserved;
> @@ -291,8 +291,8 @@ struct perf_synth_intel_mwait {
>  				reserved2	: 30;
>  		};
>  		u64	payload;
> -	};
> -} __packed;
> +	} __packed;
> +};
>  
>  struct perf_synth_intel_pwre {
>  	u32 reserved;
> @@ -305,8 +305,8 @@ struct perf_synth_intel_pwre {
>  				reserved2	: 48;
>  		};
>  		u64	payload;
> -	};
> -} __packed;
> +	} __packed;
> +};
>  
>  struct perf_synth_intel_exstop {
>  	union {
> @@ -328,8 +328,8 @@ struct perf_synth_intel_pwrx {
>  				reserved1	: 52;
>  		};
>  		u64	payload;
> -	};
> -} __packed;
> +	} __packed;
> +};
>  
>  struct perf_synth_intel_cbr {
>  	union {

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

* Re: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
  2017-06-28 20:21         ` Hunter, Adrian
@ 2017-06-28 20:26           ` Arnaldo Carvalho de Melo
  2017-06-29 19:56             ` Adrian Hunter
  0 siblings, 1 reply; 100+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-06-28 20:26 UTC (permalink / raw)
  To: Hunter, Adrian; +Cc: Andi Kleen, linux-kernel

Em Wed, Jun 28, 2017 at 08:21:37PM +0000, Hunter, Adrian escreveu:
> Sorry for the top-post...
> 
> Yeah, I've now mixed up the variable attribute:
> 
> 	https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes
>  
> with the type attribute:
> 
> 	https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#Common-Type-Attributes
> 
> Late here, so maybe it will make more sense tomorrow.

Right, and I've not been able to focus on this, but I think the problem
is with packed mixed with unnamed unions :-\

- Arnaldo
 
> -----Original Message-----
> From: Arnaldo Carvalho de Melo [mailto:acme@kernel.org] 
> Sent: Wednesday, June 28, 2017 9:54 PM
> To: Hunter, Adrian <adrian.hunter@intel.com>
> Cc: Andi Kleen <ak@linux.intel.com>; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
> 
> Em Wed, Jun 28, 2017 at 08:40:25PM +0300, Adrian Hunter escreveu:
> > On 06/28/2017 04:04 PM, Arnaldo Carvalho de Melo wrote:
> > > Em Fri, May 26, 2017 at 11:17:26AM +0300, Adrian Hunter escreveu:
> > >> Add definitions for synthesized Intel PT events for power and ptwrite.
> > >  
> > >> +++ b/tools/perf/util/event.h
> > >> +/*
> > >> + * Raw data formats for synthesized events. Note that raw data 
> > >> +plus the raw data
> > >> + * size (4 bytes) must align to 8-bytes.
> > >> + */
> > >> +
> > >> +struct perf_synth_intel_ptwrite {
> > >> +	union {
> > >> +		struct {
> > >> +			u32	ip		:  1,
> > >> +				reserved	: 31;
> > >> +		};
> > >> +		u32	flags;
> > >> +	};
> > >> +	u64	payload;
> > >> +} __packed;
> > > 
> > > 
> > > some versions of clang and gcc dislike this __packed here:
> > > 
> > > In file included from builtin-script.c:5:
> > > In file included from /git/linux/tools/perf/util/debug.h:8:
> > > /git/linux/tools/perf/util/event.h:274:2: error: packed attribute is unnecessary for (null) [-Werror,-Wpacked]
> > >         union {
> > >         ^
> > > /git/linux/tools/perf/util/event.h:285:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked]
> > >         u32 reserved;
> > >             ^
> > > /git/linux/tools/perf/util/event.h:298:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked]
> > >         u32 reserved;
> > >             ^
> > > /git/linux/tools/perf/util/event.h:322:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked]
> > >         u32 reserved;
> > >             ^
> > > 4 errors generated.
> > > mv: can't rename '/tmp/build/perf/.builtin-script.o.tmp': No such 
> > > file or directory
> > > 
> > > /git/linux/tools/build/Makefile.build:101: recipe for target 
> > > '/tmp/build/perf/builtin-script.o' failed
> > > 
> > > Failing in various distros:
> > > 
> > > [root@jouet ~]# waitp 3940 ; time dm
> > >    1 92.3684147260 alpine:3.4: FAIL
> > >    2 95.9136365930 alpine:3.5: FAIL
> > >    3 104.8328303770 alpine:3.6: FAIL
> > >    4 121.6584964930 alpine:edge: FAIL
> > >    5 37.2536373490 android-ndk:r12b-arm: Ok
> > >    6 83.9077612370 archlinux:latest: Ok
> > >    7 14.7094639200 centos:5: FAIL
> > >    8 16.6371634320 centos:6: FAIL
> > > 
> > > Investigating...
> > 
> > Re-reading the documentation for __packed, it seems like the following 
> > might be better:
> 
> Humm, can you provide the URL for such docs? I always saw packed as an attribute for a struct, not for a member... For members "aligned" is what I'm used to see:
> 
>    __attribute__ ((aligned (8)))
> 
> In the kernel sources there are a few such cases as you suggest:
> 
> [acme@jouet linux]$ find include/ -name "*.h"| xargs grep -w __packed | grep -v } | grep -v "struct __packed" | wc -l
> 12
> [acme@jouet linux]$
> 
> But most are the other way, i.e. tagging the packed attribute to the whole struct, as you originally did :-\
> 
> - Arnaldo
>  
> > diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index 
> > c283603f59c7..a7547cb3b760 100644
> > --- a/tools/perf/util/event.h
> > +++ b/tools/perf/util/event.h
> > @@ -278,8 +278,8 @@ struct perf_synth_intel_ptwrite {
> >  		};
> >  		u32	flags;
> >  	};
> > -	u64	payload;
> > -} __packed;
> > +	u64	payload __packed;
> > +};
> >  
> >  struct perf_synth_intel_mwait {
> >  	u32 reserved;
> > @@ -291,8 +291,8 @@ struct perf_synth_intel_mwait {
> >  				reserved2	: 30;
> >  		};
> >  		u64	payload;
> > -	};
> > -} __packed;
> > +	} __packed;
> > +};
> >  
> >  struct perf_synth_intel_pwre {
> >  	u32 reserved;
> > @@ -305,8 +305,8 @@ struct perf_synth_intel_pwre {
> >  				reserved2	: 48;
> >  		};
> >  		u64	payload;
> > -	};
> > -} __packed;
> > +	} __packed;
> > +};
> >  
> >  struct perf_synth_intel_exstop {
> >  	union {
> > @@ -328,8 +328,8 @@ struct perf_synth_intel_pwrx {
> >  				reserved1	: 52;
> >  		};
> >  		u64	payload;
> > -	};
> > -} __packed;
> > +	} __packed;
> > +};
> >  
> >  struct perf_synth_intel_cbr {
> >  	union {

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

* Re: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
  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
  0 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-06-29 19:56 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Andi Kleen, linux-kernel

On 06/28/2017 11:26 PM, Arnaldo Carvalho de Melo wrote:
> Em Wed, Jun 28, 2017 at 08:21:37PM +0000, Hunter, Adrian escreveu:
>> Sorry for the top-post...
>>
>> Yeah, I've now mixed up the variable attribute:
>>
>> 	https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes
>>  
>> with the type attribute:
>>
>> 	https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#Common-Type-Attributes
>>
>> Late here, so maybe it will make more sense tomorrow.
> 
> Right, and I've not been able to focus on this, but I think the problem
> is with packed mixed with unnamed unions :-\

Another possibility is to avoid packed altogether e.g.

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index ea8534dd44b6..83cdc0a61fd6 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1216,10 +1216,10 @@ static void print_sample_pt_spacing(int len)
 
 static void print_sample_synth_ptwrite(struct perf_sample *sample)
 {
-	struct perf_synth_intel_ptwrite *data = sample->raw_data;
+	struct perf_synth_intel_ptwrite *data = perf_sample__synth_ptr(sample);
 	int len;
 
-	if (sample->raw_size < sizeof(*data))
+	if (perf_sample__bad_synth_size(sample, *data))
 		return;
 
 	len = printf(" IP: %u payload: %#" PRIx64 " ",
@@ -1229,10 +1229,10 @@ static void print_sample_synth_ptwrite(struct perf_sample *sample)
 
 static void print_sample_synth_mwait(struct perf_sample *sample)
 {
-	struct perf_synth_intel_mwait *data = sample->raw_data;
+	struct perf_synth_intel_mwait *data = perf_sample__synth_ptr(sample);
 	int len;
 
-	if (sample->raw_size < sizeof(*data))
+	if (perf_sample__bad_synth_size(sample, *data))
 		return;
 
 	len = printf(" hints: %#x extensions: %#x ",
@@ -1242,10 +1242,10 @@ static void print_sample_synth_mwait(struct perf_sample *sample)
 
 static void print_sample_synth_pwre(struct perf_sample *sample)
 {
-	struct perf_synth_intel_pwre *data = sample->raw_data;
+	struct perf_synth_intel_pwre *data = perf_sample__synth_ptr(sample);
 	int len;
 
-	if (sample->raw_size < sizeof(*data))
+	if (perf_sample__bad_synth_size(sample, *data))
 		return;
 
 	len = printf(" hw: %u cstate: %u sub-cstate: %u ",
@@ -1255,10 +1255,10 @@ static void print_sample_synth_pwre(struct perf_sample *sample)
 
 static void print_sample_synth_exstop(struct perf_sample *sample)
 {
-	struct perf_synth_intel_exstop *data = sample->raw_data;
+	struct perf_synth_intel_exstop *data = perf_sample__synth_ptr(sample);
 	int len;
 
-	if (sample->raw_size < sizeof(*data))
+	if (perf_sample__bad_synth_size(sample, *data))
 		return;
 
 	len = printf(" IP: %u ", data->ip);
@@ -1267,10 +1267,10 @@ static void print_sample_synth_exstop(struct perf_sample *sample)
 
 static void print_sample_synth_pwrx(struct perf_sample *sample)
 {
-	struct perf_synth_intel_pwrx *data = sample->raw_data;
+	struct perf_synth_intel_pwrx *data = perf_sample__synth_ptr(sample);
 	int len;
 
-	if (sample->raw_size < sizeof(*data))
+	if (perf_sample__bad_synth_size(sample, *data))
 		return;
 
 	len = printf(" deepest cstate: %u last cstate: %u wake reason: %#x ",
@@ -1281,11 +1281,11 @@ static void print_sample_synth_pwrx(struct perf_sample *sample)
 
 static void print_sample_synth_cbr(struct perf_sample *sample)
 {
-	struct perf_synth_intel_cbr *data = sample->raw_data;
+	struct perf_synth_intel_cbr *data = perf_sample__synth_ptr(sample);
 	unsigned int percent, freq;
 	int len;
 
-	if (sample->raw_size < sizeof(*data))
+	if (perf_sample__bad_synth_size(sample, *data))
 		return;
 
 	freq = (le32_to_cpu(data->freq) + 500) / 1000;
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index d93a6825ce09..9967c87af7a6 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -266,11 +266,16 @@ enum perf_synth_id {
 };
 
 /*
- * Raw data formats for synthesized events. Note that raw data plus the raw data
- * size (4 bytes) must align to 8-bytes.
+ * 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,
@@ -279,9 +284,10 @@ struct perf_synth_intel_ptwrite {
 		u32	flags;
 	};
 	u64	payload;
-} __packed;
+};
 
 struct perf_synth_intel_mwait {
+	u32 padding;
 	u32 reserved;
 	union {
 		struct {
@@ -292,9 +298,10 @@ struct perf_synth_intel_mwait {
 		};
 		u64	payload;
 	};
-} __packed;
+};
 
 struct perf_synth_intel_pwre {
+	u32 padding;
 	u32 reserved;
 	union {
 		struct {
@@ -306,9 +313,10 @@ struct perf_synth_intel_pwre {
 		};
 		u64	payload;
 	};
-} __packed;
+};
 
 struct perf_synth_intel_exstop {
+	u32 padding;
 	union {
 		struct {
 			u32	ip		:  1,
@@ -319,6 +327,7 @@ struct perf_synth_intel_exstop {
 };
 
 struct perf_synth_intel_pwrx {
+	u32 padding;
 	u32 reserved;
 	union {
 		struct {
@@ -329,9 +338,10 @@ struct perf_synth_intel_pwrx {
 		};
 		u64	payload;
 	};
-} __packed;
+};
 
 struct perf_synth_intel_cbr {
+	u32 padding;
 	union {
 		struct {
 			u32	cbr		:  8,
@@ -346,6 +356,24 @@ struct perf_synth_intel_cbr {
 };
 
 /*
+ * 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
  * such "chunks" of lost events is stored in .nr_events[PERF_EVENT_LOST] while
diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 754e92ee6c3e..b58f9fd1e2ee 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1283,8 +1283,8 @@ static int intel_pt_synth_ptwrite_sample(struct intel_pt_queue *ptq)
 	raw.ip = !!(ptq->state->flags & INTEL_PT_FUP_IP);
 	raw.payload = cpu_to_le64(ptq->state->ptw_payload);
 
-	sample.raw_size = sizeof(raw);
-	sample.raw_data = &raw;
+	sample.raw_size = perf_synth__raw_size(raw);
+	sample.raw_data = perf_synth__raw_data(&raw);
 
 	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
 					    pt->ptwrites_sample_type);
@@ -1311,8 +1311,8 @@ static int intel_pt_synth_cbr_sample(struct intel_pt_queue *ptq)
 	raw.freq = cpu_to_le32(raw.cbr * pt->cbr2khz);
 	raw.reserved3 = 0;
 
-	sample.raw_size = sizeof(raw);
-	sample.raw_data = &raw;
+	sample.raw_size = perf_synth__raw_size(raw);
+	sample.raw_data = perf_synth__raw_data(&raw);
 
 	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
 					    pt->pwr_events_sample_type);
@@ -1336,8 +1336,8 @@ static int intel_pt_synth_mwait_sample(struct intel_pt_queue *ptq)
 	raw.reserved = 0;
 	raw.payload = cpu_to_le64(ptq->state->mwait_payload);
 
-	sample.raw_size = sizeof(raw);
-	sample.raw_data = &raw;
+	sample.raw_size = perf_synth__raw_size(raw);
+	sample.raw_data = perf_synth__raw_data(&raw);
 
 	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
 					    pt->pwr_events_sample_type);
@@ -1361,8 +1361,8 @@ static int intel_pt_synth_pwre_sample(struct intel_pt_queue *ptq)
 	raw.reserved = 0;
 	raw.payload = cpu_to_le64(ptq->state->pwre_payload);
 
-	sample.raw_size = sizeof(raw);
-	sample.raw_data = &raw;
+	sample.raw_size = perf_synth__raw_size(raw);
+	sample.raw_data = perf_synth__raw_data(&raw);
 
 	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
 					    pt->pwr_events_sample_type);
@@ -1386,8 +1386,8 @@ static int intel_pt_synth_exstop_sample(struct intel_pt_queue *ptq)
 	raw.flags = 0;
 	raw.ip = !!(ptq->state->flags & INTEL_PT_FUP_IP);
 
-	sample.raw_size = sizeof(raw);
-	sample.raw_data = &raw;
+	sample.raw_size = perf_synth__raw_size(raw);
+	sample.raw_data = perf_synth__raw_data(&raw);
 
 	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
 					    pt->pwr_events_sample_type);
@@ -1411,8 +1411,8 @@ static int intel_pt_synth_pwrx_sample(struct intel_pt_queue *ptq)
 	raw.reserved = 0;
 	raw.payload = cpu_to_le64(ptq->state->pwrx_payload);
 
-	sample.raw_size = sizeof(raw);
-	sample.raw_data = &raw;
+	sample.raw_size = perf_synth__raw_size(raw);
+	sample.raw_data = perf_synth__raw_data(&raw);
 
 	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
 					    pt->pwr_events_sample_type);



>  
>> -----Original Message-----
>> From: Arnaldo Carvalho de Melo [mailto:acme@kernel.org] 
>> Sent: Wednesday, June 28, 2017 9:54 PM
>> To: Hunter, Adrian <adrian.hunter@intel.com>
>> Cc: Andi Kleen <ak@linux.intel.com>; linux-kernel@vger.kernel.org
>> Subject: Re: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
>>
>> Em Wed, Jun 28, 2017 at 08:40:25PM +0300, Adrian Hunter escreveu:
>>> On 06/28/2017 04:04 PM, Arnaldo Carvalho de Melo wrote:
>>>> Em Fri, May 26, 2017 at 11:17:26AM +0300, Adrian Hunter escreveu:
>>>>> Add definitions for synthesized Intel PT events for power and ptwrite.
>>>>  
>>>>> +++ b/tools/perf/util/event.h
>>>>> +/*
>>>>> + * Raw data formats for synthesized events. Note that raw data 
>>>>> +plus the raw data
>>>>> + * size (4 bytes) must align to 8-bytes.
>>>>> + */
>>>>> +
>>>>> +struct perf_synth_intel_ptwrite {
>>>>> +	union {
>>>>> +		struct {
>>>>> +			u32	ip		:  1,
>>>>> +				reserved	: 31;
>>>>> +		};
>>>>> +		u32	flags;
>>>>> +	};
>>>>> +	u64	payload;
>>>>> +} __packed;
>>>>
>>>>
>>>> some versions of clang and gcc dislike this __packed here:
>>>>
>>>> In file included from builtin-script.c:5:
>>>> In file included from /git/linux/tools/perf/util/debug.h:8:
>>>> /git/linux/tools/perf/util/event.h:274:2: error: packed attribute is unnecessary for (null) [-Werror,-Wpacked]
>>>>         union {
>>>>         ^
>>>> /git/linux/tools/perf/util/event.h:285:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked]
>>>>         u32 reserved;
>>>>             ^
>>>> /git/linux/tools/perf/util/event.h:298:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked]
>>>>         u32 reserved;
>>>>             ^
>>>> /git/linux/tools/perf/util/event.h:322:6: error: packed attribute is unnecessary for 'reserved' [-Werror,-Wpacked]
>>>>         u32 reserved;
>>>>             ^
>>>> 4 errors generated.
>>>> mv: can't rename '/tmp/build/perf/.builtin-script.o.tmp': No such 
>>>> file or directory
>>>>
>>>> /git/linux/tools/build/Makefile.build:101: recipe for target 
>>>> '/tmp/build/perf/builtin-script.o' failed
>>>>
>>>> Failing in various distros:
>>>>
>>>> [root@jouet ~]# waitp 3940 ; time dm
>>>>    1 92.3684147260 alpine:3.4: FAIL
>>>>    2 95.9136365930 alpine:3.5: FAIL
>>>>    3 104.8328303770 alpine:3.6: FAIL
>>>>    4 121.6584964930 alpine:edge: FAIL
>>>>    5 37.2536373490 android-ndk:r12b-arm: Ok
>>>>    6 83.9077612370 archlinux:latest: Ok
>>>>    7 14.7094639200 centos:5: FAIL
>>>>    8 16.6371634320 centos:6: FAIL
>>>>
>>>> Investigating...
>>>
>>> Re-reading the documentation for __packed, it seems like the following 
>>> might be better:
>>
>> Humm, can you provide the URL for such docs? I always saw packed as an attribute for a struct, not for a member... For members "aligned" is what I'm used to see:
>>
>>    __attribute__ ((aligned (8)))
>>
>> In the kernel sources there are a few such cases as you suggest:
>>
>> [acme@jouet linux]$ find include/ -name "*.h"| xargs grep -w __packed | grep -v } | grep -v "struct __packed" | wc -l
>> 12
>> [acme@jouet linux]$
>>
>> But most are the other way, i.e. tagging the packed attribute to the whole struct, as you originally did :-\
>>
>> - Arnaldo
>>  
>>> diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index 
>>> c283603f59c7..a7547cb3b760 100644
>>> --- a/tools/perf/util/event.h
>>> +++ b/tools/perf/util/event.h
>>> @@ -278,8 +278,8 @@ struct perf_synth_intel_ptwrite {
>>>  		};
>>>  		u32	flags;
>>>  	};
>>> -	u64	payload;
>>> -} __packed;
>>> +	u64	payload __packed;
>>> +};
>>>  
>>>  struct perf_synth_intel_mwait {
>>>  	u32 reserved;
>>> @@ -291,8 +291,8 @@ struct perf_synth_intel_mwait {
>>>  				reserved2	: 30;
>>>  		};
>>>  		u64	payload;
>>> -	};
>>> -} __packed;
>>> +	} __packed;
>>> +};
>>>  
>>>  struct perf_synth_intel_pwre {
>>>  	u32 reserved;
>>> @@ -305,8 +305,8 @@ struct perf_synth_intel_pwre {
>>>  				reserved2	: 48;
>>>  		};
>>>  		u64	payload;
>>> -	};
>>> -} __packed;
>>> +	} __packed;
>>> +};
>>>  
>>>  struct perf_synth_intel_exstop {
>>>  	union {
>>> @@ -328,8 +328,8 @@ struct perf_synth_intel_pwrx {
>>>  				reserved1	: 52;
>>>  		};
>>>  		u64	payload;
>>> -	};
>>> -} __packed;
>>> +	} __packed;
>>> +};
>>>  
>>>  struct perf_synth_intel_cbr {
>>>  	union {
> 

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

* Re: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
  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
  0 siblings, 1 reply; 100+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-06-29 20:13 UTC (permalink / raw)
  To: Adrian Hunter; +Cc: Andi Kleen, linux-kernel

Em Thu, Jun 29, 2017 at 10:56:25PM +0300, Adrian Hunter escreveu:
> On 06/28/2017 11:26 PM, Arnaldo Carvalho de Melo wrote:
> > Em Wed, Jun 28, 2017 at 08:21:37PM +0000, Hunter, Adrian escreveu:
> >> Sorry for the top-post...
> >>
> >> Yeah, I've now mixed up the variable attribute:
> >>
> >> 	https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes
> >>  
> >> with the type attribute:
> >>
> >> 	https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#Common-Type-Attributes
> >>
> >> Late here, so maybe it will make more sense tomorrow.
> > 
> > Right, and I've not been able to focus on this, but I think the problem
> > is with packed mixed with unnamed unions :-\
> 
> Another possibility is to avoid packed altogether e.g.

This one builds on centos:6, now running the full set of containers,
will let you know the results.

- Arnaldo

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

* Re: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
  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
  0 siblings, 1 reply; 100+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-06-30  2:08 UTC (permalink / raw)
  To: Adrian Hunter; +Cc: Andi Kleen, linux-kernel

Em Thu, Jun 29, 2017 at 05:13:54PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Thu, Jun 29, 2017 at 10:56:25PM +0300, Adrian Hunter escreveu:
> > On 06/28/2017 11:26 PM, Arnaldo Carvalho de Melo wrote:
> > > Right, and I've not been able to focus on this, but I think the problem
> > > is with packed mixed with unnamed unions :-\
 
> > Another possibility is to avoid packed altogether e.g.

> This one builds on centos:6, now running the full set of containers,
> will let you know the results.

Ok, passes all tests (gcc, clang where available) on:


  # dm
   1 alpine:3.4: Ok
   2 alpine:3.5: Ok
   3 alpine:3.6: Ok
   4 alpine:edge: Ok
   5 android-ndk:r12b-arm: Ok
   6 archlinux:latest: Ok
   7 centos:5: Ok
   8 centos:6: Ok
   9 centos:7: Ok
  10 debian:7: Ok
  11 debian:8: Ok
  12 debian:9: Ok
  13 debian:experimental: Ok
  14 debian:experimental-x-arm64: Ok
  15 debian:experimental-x-mips: Ok
  16 debian:experimental-x-mips64: Ok
  17 debian:experimental-x-mipsel: Ok
  18 fedora:20: Ok
  19 fedora:21: Ok
  20 fedora:22: Ok
  21 fedora:23: Ok
  22 fedora:24: Ok
  23 fedora:24-x-ARC-uClibc: Ok
  24 fedora:25: Ok
  25 fedora:rawhide: Ok
  26 mageia:5: Ok
  27 opensuse:13.2: Ok
  28 opensuse:42.1: Ok
  29 opensuse:tumbleweed: Ok
  30 ubuntu:12.04.5: Ok
  31 ubuntu:14.04.4: Ok
  32 ubuntu:14.04.4-x-linaro-arm64: Ok
  33 ubuntu:15.10: Ok
  34 ubuntu:16.04: Ok
  35 ubuntu:16.04-x-arm: Ok
  36 ubuntu:16.04-x-arm64: Ok
  37 ubuntu:16.04-x-powerpc: Ok
  38 ubuntu:16.04-x-powerpc64: Ok
  39 ubuntu:16.04-x-powerpc64el: Ok
  40 ubuntu:16.04-x-s390: Ok
  41 ubuntu:16.10: Ok
  42 ubuntu:17.04: Ok
  #

Can you provide new versions for the relevant patches?

Thanks,

- Arnaldo

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

* [PATCH V3 25/37] perf script: Add synthesized Intel PT power and ptwrite events
  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-30  8:36   ` Adrian Hunter
  2017-07-01  8:52     ` [tip:perf/core] " tip-bot for Adrian Hunter
  1 sibling, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-06-30  8:36 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

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

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

* [PATCH V3 33/37] perf intel-pt: Synthesize new power and ptwrite events
  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   ` Adrian Hunter
  2017-07-01  8:54     ` [tip:perf/core] perf intel-pt: Synthesize new power and "ptwrite" events tip-bot for Adrian Hunter
  0 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-06-30  8:36 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Andi Kleen; +Cc: linux-kernel

Synthesize new power and ptwrite events.

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


Changes in V3:

	Use perf_synth__raw_size() and perf_synth__raw_data()
	as a result of avoiding __packed


 tools/perf/util/intel-pt.c | 283 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 283 insertions(+)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index ace79a405f98..b58f9fd1e2ee 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -92,6 +92,18 @@ struct intel_pt {
 	u64 transactions_sample_type;
 	u64 transactions_id;
 
+	bool sample_ptwrites;
+	u64 ptwrites_sample_type;
+	u64 ptwrites_id;
+
+	bool sample_pwr_events;
+	u64 pwr_events_sample_type;
+	u64 mwait_id;
+	u64 pwre_id;
+	u64 exstop_id;
+	u64 pwrx_id;
+	u64 cbr_id;
+
 	bool synth_needs_swap;
 
 	u64 tsc_bit;
@@ -102,6 +114,7 @@ struct intel_pt {
 	u64 cyc_bit;
 	u64 noretcomp_bit;
 	unsigned max_non_turbo_ratio;
+	unsigned cbr2khz;
 
 	unsigned long num_events;
 
@@ -1236,6 +1249,175 @@ static int intel_pt_synth_transaction_sample(struct intel_pt_queue *ptq)
 					    pt->transactions_sample_type);
 }
 
+static void intel_pt_prep_p_sample(struct intel_pt *pt,
+				   struct intel_pt_queue *ptq,
+				   union perf_event *event,
+				   struct perf_sample *sample)
+{
+	intel_pt_prep_sample(pt, ptq, event, sample);
+
+	/*
+	 * Zero IP is used to mean "trace start" but that is not the case for
+	 * power or PTWRITE events with no IP, so clear the flags.
+	 */
+	if (!sample->ip)
+		sample->flags = 0;
+}
+
+static int intel_pt_synth_ptwrite_sample(struct intel_pt_queue *ptq)
+{
+	struct intel_pt *pt = ptq->pt;
+	union perf_event *event = ptq->event_buf;
+	struct perf_sample sample = { .ip = 0, };
+	struct perf_synth_intel_ptwrite raw;
+
+	if (intel_pt_skip_event(pt))
+		return 0;
+
+	intel_pt_prep_p_sample(pt, ptq, event, &sample);
+
+	sample.id = ptq->pt->ptwrites_id;
+	sample.stream_id = ptq->pt->ptwrites_id;
+
+	raw.flags = 0;
+	raw.ip = !!(ptq->state->flags & INTEL_PT_FUP_IP);
+	raw.payload = cpu_to_le64(ptq->state->ptw_payload);
+
+	sample.raw_size = perf_synth__raw_size(raw);
+	sample.raw_data = perf_synth__raw_data(&raw);
+
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->ptwrites_sample_type);
+}
+
+static int intel_pt_synth_cbr_sample(struct intel_pt_queue *ptq)
+{
+	struct intel_pt *pt = ptq->pt;
+	union perf_event *event = ptq->event_buf;
+	struct perf_sample sample = { .ip = 0, };
+	struct perf_synth_intel_cbr raw;
+	u32 flags;
+
+	if (intel_pt_skip_event(pt))
+		return 0;
+
+	intel_pt_prep_p_sample(pt, ptq, event, &sample);
+
+	sample.id = ptq->pt->cbr_id;
+	sample.stream_id = ptq->pt->cbr_id;
+
+	flags = (u16)ptq->state->cbr_payload | (pt->max_non_turbo_ratio << 16);
+	raw.flags = cpu_to_le32(flags);
+	raw.freq = cpu_to_le32(raw.cbr * pt->cbr2khz);
+	raw.reserved3 = 0;
+
+	sample.raw_size = perf_synth__raw_size(raw);
+	sample.raw_data = perf_synth__raw_data(&raw);
+
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->pwr_events_sample_type);
+}
+
+static int intel_pt_synth_mwait_sample(struct intel_pt_queue *ptq)
+{
+	struct intel_pt *pt = ptq->pt;
+	union perf_event *event = ptq->event_buf;
+	struct perf_sample sample = { .ip = 0, };
+	struct perf_synth_intel_mwait raw;
+
+	if (intel_pt_skip_event(pt))
+		return 0;
+
+	intel_pt_prep_p_sample(pt, ptq, event, &sample);
+
+	sample.id = ptq->pt->mwait_id;
+	sample.stream_id = ptq->pt->mwait_id;
+
+	raw.reserved = 0;
+	raw.payload = cpu_to_le64(ptq->state->mwait_payload);
+
+	sample.raw_size = perf_synth__raw_size(raw);
+	sample.raw_data = perf_synth__raw_data(&raw);
+
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->pwr_events_sample_type);
+}
+
+static int intel_pt_synth_pwre_sample(struct intel_pt_queue *ptq)
+{
+	struct intel_pt *pt = ptq->pt;
+	union perf_event *event = ptq->event_buf;
+	struct perf_sample sample = { .ip = 0, };
+	struct perf_synth_intel_pwre raw;
+
+	if (intel_pt_skip_event(pt))
+		return 0;
+
+	intel_pt_prep_p_sample(pt, ptq, event, &sample);
+
+	sample.id = ptq->pt->pwre_id;
+	sample.stream_id = ptq->pt->pwre_id;
+
+	raw.reserved = 0;
+	raw.payload = cpu_to_le64(ptq->state->pwre_payload);
+
+	sample.raw_size = perf_synth__raw_size(raw);
+	sample.raw_data = perf_synth__raw_data(&raw);
+
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->pwr_events_sample_type);
+}
+
+static int intel_pt_synth_exstop_sample(struct intel_pt_queue *ptq)
+{
+	struct intel_pt *pt = ptq->pt;
+	union perf_event *event = ptq->event_buf;
+	struct perf_sample sample = { .ip = 0, };
+	struct perf_synth_intel_exstop raw;
+
+	if (intel_pt_skip_event(pt))
+		return 0;
+
+	intel_pt_prep_p_sample(pt, ptq, event, &sample);
+
+	sample.id = ptq->pt->exstop_id;
+	sample.stream_id = ptq->pt->exstop_id;
+
+	raw.flags = 0;
+	raw.ip = !!(ptq->state->flags & INTEL_PT_FUP_IP);
+
+	sample.raw_size = perf_synth__raw_size(raw);
+	sample.raw_data = perf_synth__raw_data(&raw);
+
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->pwr_events_sample_type);
+}
+
+static int intel_pt_synth_pwrx_sample(struct intel_pt_queue *ptq)
+{
+	struct intel_pt *pt = ptq->pt;
+	union perf_event *event = ptq->event_buf;
+	struct perf_sample sample = { .ip = 0, };
+	struct perf_synth_intel_pwrx raw;
+
+	if (intel_pt_skip_event(pt))
+		return 0;
+
+	intel_pt_prep_p_sample(pt, ptq, event, &sample);
+
+	sample.id = ptq->pt->pwrx_id;
+	sample.stream_id = ptq->pt->pwrx_id;
+
+	raw.reserved = 0;
+	raw.payload = cpu_to_le64(ptq->state->pwrx_payload);
+
+	sample.raw_size = perf_synth__raw_size(raw);
+	sample.raw_data = perf_synth__raw_data(&raw);
+
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->pwr_events_sample_type);
+}
+
 static int intel_pt_synth_error(struct intel_pt *pt, int code, int cpu,
 				pid_t pid, pid_t tid, u64 ip)
 {
@@ -1287,6 +1469,10 @@ static inline bool intel_pt_is_switch_ip(struct intel_pt_queue *ptq, u64 ip)
 			       PERF_IP_FLAG_INTERRUPT | PERF_IP_FLAG_TX_ABORT));
 }
 
+#define INTEL_PT_PWR_EVT (INTEL_PT_MWAIT_OP | INTEL_PT_PWR_ENTRY | \
+			  INTEL_PT_EX_STOP | INTEL_PT_PWR_EXIT | \
+			  INTEL_PT_CBR_CHG)
+
 static int intel_pt_sample(struct intel_pt_queue *ptq)
 {
 	const struct intel_pt_state *state = ptq->state;
@@ -1298,6 +1484,34 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)
 
 	ptq->have_sample = false;
 
+	if (pt->sample_pwr_events && (state->type & INTEL_PT_PWR_EVT)) {
+		if (state->type & INTEL_PT_CBR_CHG) {
+			err = intel_pt_synth_cbr_sample(ptq);
+			if (err)
+				return err;
+		}
+		if (state->type & INTEL_PT_MWAIT_OP) {
+			err = intel_pt_synth_mwait_sample(ptq);
+			if (err)
+				return err;
+		}
+		if (state->type & INTEL_PT_PWR_ENTRY) {
+			err = intel_pt_synth_pwre_sample(ptq);
+			if (err)
+				return err;
+		}
+		if (state->type & INTEL_PT_EX_STOP) {
+			err = intel_pt_synth_exstop_sample(ptq);
+			if (err)
+				return err;
+		}
+		if (state->type & INTEL_PT_PWR_EXIT) {
+			err = intel_pt_synth_pwrx_sample(ptq);
+			if (err)
+				return err;
+		}
+	}
+
 	if (pt->sample_instructions && (state->type & INTEL_PT_INSTRUCTION)) {
 		err = intel_pt_synth_instruction_sample(ptq);
 		if (err)
@@ -1310,6 +1524,12 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)
 			return err;
 	}
 
+	if (pt->sample_ptwrites && (state->type & INTEL_PT_PTW)) {
+		err = intel_pt_synth_ptwrite_sample(ptq);
+		if (err)
+			return err;
+	}
+
 	if (!(state->type & INTEL_PT_BRANCH))
 		return 0;
 
@@ -2047,6 +2267,68 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 		id += 1;
 	}
 
+	attr.type = PERF_TYPE_SYNTH;
+	attr.sample_type |= PERF_SAMPLE_RAW;
+
+	if (pt->synth_opts.ptwrites) {
+		attr.config = PERF_SYNTH_INTEL_PTWRITE;
+		err = intel_pt_synth_event(session, "ptwrite", &attr, id);
+		if (err)
+			return err;
+		pt->sample_ptwrites = true;
+		pt->ptwrites_sample_type = attr.sample_type;
+		pt->ptwrites_id = id;
+		intel_pt_set_event_name(evlist, id, "ptwrite");
+		id += 1;
+	}
+
+	if (pt->synth_opts.pwr_events) {
+		pt->sample_pwr_events = true;
+		pt->pwr_events_sample_type = attr.sample_type;
+
+		attr.config = PERF_SYNTH_INTEL_CBR;
+		err = intel_pt_synth_event(session, "cbr", &attr, id);
+		if (err)
+			return err;
+		pt->cbr_id = id;
+		intel_pt_set_event_name(evlist, id, "cbr");
+		id += 1;
+	}
+
+	if (pt->synth_opts.pwr_events && (evsel->attr.config & 0x10)) {
+		attr.config = PERF_SYNTH_INTEL_MWAIT;
+		err = intel_pt_synth_event(session, "mwait", &attr, id);
+		if (err)
+			return err;
+		pt->mwait_id = id;
+		intel_pt_set_event_name(evlist, id, "mwait");
+		id += 1;
+
+		attr.config = PERF_SYNTH_INTEL_PWRE;
+		err = intel_pt_synth_event(session, "pwre", &attr, id);
+		if (err)
+			return err;
+		pt->pwre_id = id;
+		intel_pt_set_event_name(evlist, id, "pwre");
+		id += 1;
+
+		attr.config = PERF_SYNTH_INTEL_EXSTOP;
+		err = intel_pt_synth_event(session, "exstop", &attr, id);
+		if (err)
+			return err;
+		pt->exstop_id = id;
+		intel_pt_set_event_name(evlist, id, "exstop");
+		id += 1;
+
+		attr.config = PERF_SYNTH_INTEL_PWRX;
+		err = intel_pt_synth_event(session, "pwrx", &attr, id);
+		if (err)
+			return err;
+		pt->pwrx_id = id;
+		intel_pt_set_event_name(evlist, id, "pwrx");
+		id += 1;
+	}
+
 	pt->synth_needs_swap = evsel->needs_swap;
 
 	return 0;
@@ -2313,6 +2595,7 @@ int intel_pt_process_auxtrace_info(union perf_event *event,
 		intel_pt_log("TSC frequency %"PRIu64"\n", tsc_freq);
 		intel_pt_log("Maximum non-turbo ratio %u\n",
 			     pt->max_non_turbo_ratio);
+		pt->cbr2khz = tsc_freq / pt->max_non_turbo_ratio / 1000;
 	}
 
 	if (pt->synth_opts.calls)
-- 
1.9.1

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

* Re: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
  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
  0 siblings, 1 reply; 100+ messages in thread
From: Adrian Hunter @ 2017-06-30  8:51 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Andi Kleen, linux-kernel

On 06/30/2017 05:08 AM, Arnaldo Carvalho de Melo wrote:
> Em Thu, Jun 29, 2017 at 05:13:54PM -0300, Arnaldo Carvalho de Melo escreveu:
>> Em Thu, Jun 29, 2017 at 10:56:25PM +0300, Adrian Hunter escreveu:
>>> On 06/28/2017 11:26 PM, Arnaldo Carvalho de Melo wrote:
>>>> Right, and I've not been able to focus on this, but I think the problem
>>>> is with packed mixed with unnamed unions :-\
>  
>>> Another possibility is to avoid packed altogether e.g.
> 
>> This one builds on centos:6, now running the full set of containers,
>> will let you know the results.
> 
> Ok, passes all tests (gcc, clang where available) on:
> 
> 
>   # dm
>    1 alpine:3.4: Ok
>    2 alpine:3.5: Ok
>    3 alpine:3.6: Ok
>    4 alpine:edge: Ok
>    5 android-ndk:r12b-arm: Ok
>    6 archlinux:latest: Ok
>    7 centos:5: Ok
>    8 centos:6: Ok
>    9 centos:7: Ok
>   10 debian:7: Ok
>   11 debian:8: Ok
>   12 debian:9: Ok
>   13 debian:experimental: Ok
>   14 debian:experimental-x-arm64: Ok
>   15 debian:experimental-x-mips: Ok
>   16 debian:experimental-x-mips64: Ok
>   17 debian:experimental-x-mipsel: Ok
>   18 fedora:20: Ok
>   19 fedora:21: Ok
>   20 fedora:22: Ok
>   21 fedora:23: Ok
>   22 fedora:24: Ok
>   23 fedora:24-x-ARC-uClibc: Ok
>   24 fedora:25: Ok
>   25 fedora:rawhide: Ok
>   26 mageia:5: Ok
>   27 opensuse:13.2: Ok
>   28 opensuse:42.1: Ok
>   29 opensuse:tumbleweed: Ok
>   30 ubuntu:12.04.5: Ok
>   31 ubuntu:14.04.4: Ok
>   32 ubuntu:14.04.4-x-linaro-arm64: Ok
>   33 ubuntu:15.10: Ok
>   34 ubuntu:16.04: Ok
>   35 ubuntu:16.04-x-arm: Ok
>   36 ubuntu:16.04-x-arm64: Ok
>   37 ubuntu:16.04-x-powerpc: Ok
>   38 ubuntu:16.04-x-powerpc64: Ok
>   39 ubuntu:16.04-x-powerpc64el: Ok
>   40 ubuntu:16.04-x-s390: Ok
>   41 ubuntu:16.10: Ok
>   42 ubuntu:17.04: Ok
>   #
> 
> Can you provide new versions for the relevant patches?

I have sent new versions of the 2 patches affected.

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

* Re: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
  2017-06-30  8:51                   ` Adrian Hunter
@ 2017-06-30 14:54                     ` Arnaldo Carvalho de Melo
  2017-06-30 19:37                       ` Hunter, Adrian
  0 siblings, 1 reply; 100+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-06-30 14:54 UTC (permalink / raw)
  To: Adrian Hunter; +Cc: Andi Kleen, linux-kernel

Em Fri, Jun 30, 2017 at 11:51:22AM +0300, Adrian Hunter escreveu:
> On 06/30/2017 05:08 AM, Arnaldo Carvalho de Melo wrote:
> > Em Thu, Jun 29, 2017 at 05:13:54PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Ok, passes all tests (gcc, clang where available) on:

> >   41 ubuntu:16.10: Ok
> >   42 ubuntu:17.04: Ok

> > Can you provide new versions for the relevant patches?
 
> I have sent new versions of the 2 patches affected.

Thanks, a grafted those in my branch, will perform the usual build
tests, then try it on a kaby lake machine.

Have you thought about further "perf test" test cases to make sure this
code stays working with all this infrastructure and details?

Things like running synthetic workloads and getting a short sequence
known to have these new packet types, checking if the hardware
performing the tests is capable of generating such traces, etc?

- Arnaldo

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

* RE: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events
  2017-06-30 14:54                     ` Arnaldo Carvalho de Melo
@ 2017-06-30 19:37                       ` Hunter, Adrian
  0 siblings, 0 replies; 100+ messages in thread
From: Hunter, Adrian @ 2017-06-30 19:37 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Andi Kleen, linux-kernel

-----Original Message-----
From: Arnaldo Carvalho de Melo [mailto:acme@kernel.org] 
Sent: Friday, June 30, 2017 5:54 PM
To: Hunter, Adrian <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>; linux-kernel@vger.kernel.org
Subject: Re: [PATCH V2 25/37] perf script: Add synthesized Intel PT power and ptwrite events

> Em Fri, Jun 30, 2017 at 11:51:22AM +0300, Adrian Hunter escreveu:
> > On 06/30/2017 05:08 AM, Arnaldo Carvalho de Melo wrote:
> > > Em Thu, Jun 29, 2017 at 05:13:54PM -0300, Arnaldo Carvalho de Melo escreveu:
> > > Ok, passes all tests (gcc, clang where available) on:
>
> > >   41 ubuntu:16.10: Ok
> > >   42 ubuntu:17.04: Ok
>
> > > Can you provide new versions for the relevant patches?
 
> > I have sent new versions of the 2 patches affected.

> Thanks, a grafted those in my branch, will perform the usual build tests, then try it on a kaby lake machine.

> Have you thought about further "perf test" test cases to make sure this code stays working with all this infrastructure and details?

> Things like running synthetic workloads and getting a short sequence known to have these new packet types, checking if the hardware performing the tests is capable of generating such traces, etc?

The power events might not occur.  Ptwrite and cbr might be possible.  Perhaps simpler to just synthesize and then parse the events back to check them.

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

* [tip:perf/core] perf script: Add 'synth' event type for synthesized events
  2017-06-21 10:17   ` [PATCH V3 " Adrian Hunter
  2017-06-21 13:51     ` Arnaldo Carvalho de Melo
@ 2017-07-01  8:50     ` tip-bot for Adrian Hunter
  1 sibling, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-07-01  8:50 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: adrian.hunter, hpa, linux-kernel, tglx, mingo, acme, ak

Commit-ID:  1405720d4f2669e5ebaed192bd727aca74f64732
Gitweb:     http://git.kernel.org/tip/1405720d4f2669e5ebaed192bd727aca74f64732
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Wed, 21 Jun 2017 13:17:19 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 27 Jun 2017 12:03:09 -0300

perf script: Add 'synth' event type for synthesized events

Instruction trace decoders such as Intel PT may have additional information
recorded in the trace. For example, Intel PT has power information and a
there is a new instruction 'ptwrite' that can write a value into a PTWRITE
trace packet.

Such information may be associated with an IP and so can be treated as a
sample (PERF_RECORD_SAMPLE). Custom data can be incorporated in the
sample as raw_data (PERF_SAMPLE_RAW).

However a means of identifying the raw data format is needed. That will
be done by synthesizing an attribute for it.

So add an attribute type for custom synthesized events.  Different
synthesized events will be identified by the attribute 'config'.

Committer notes:

Start those PERF_TYPE_ after the PMU range, i.e. after (INT_MAX + 1U),
i.e. after perf_pmu_register() -> idr_alloc(end=0).

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1498040239-32418-1-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-script.c | 74 +++++++++++++++++++++++++++++++++++----------
 tools/perf/util/event.h     |  3 ++
 2 files changed, 61 insertions(+), 16 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 4bce7d8..2999e7e 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -119,6 +119,11 @@ struct output_option {
 	{.str = "brstackoff", .field = PERF_OUTPUT_BRSTACKOFF},
 };
 
+enum {
+	OUTPUT_TYPE_SYNTH = PERF_TYPE_MAX,
+	OUTPUT_TYPE_MAX
+};
+
 /* default set to maintain compatibility with current format */
 static struct {
 	bool user_set;
@@ -126,7 +131,7 @@ static struct {
 	unsigned int print_ip_opts;
 	u64 fields;
 	u64 invalid_fields;
-} output[PERF_TYPE_MAX] = {
+} output[OUTPUT_TYPE_MAX] = {
 
 	[PERF_TYPE_HARDWARE] = {
 		.user_set = false,
@@ -184,12 +189,43 @@ static struct {
 
 		.invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
 	},
+
+	[OUTPUT_TYPE_SYNTH] = {
+		.user_set = false,
+
+		.fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
+			      PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
+			      PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
+			      PERF_OUTPUT_SYM | PERF_OUTPUT_DSO,
+
+		.invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
+	},
 };
 
+static inline int output_type(unsigned int type)
+{
+	switch (type) {
+	case PERF_TYPE_SYNTH:
+		return OUTPUT_TYPE_SYNTH;
+	default:
+		return type;
+	}
+}
+
+static inline unsigned int attr_type(unsigned int type)
+{
+	switch (type) {
+	case OUTPUT_TYPE_SYNTH:
+		return PERF_TYPE_SYNTH;
+	default:
+		return type;
+	}
+}
+
 static bool output_set_by_user(void)
 {
 	int j;
-	for (j = 0; j < PERF_TYPE_MAX; ++j) {
+	for (j = 0; j < OUTPUT_TYPE_MAX; ++j) {
 		if (output[j].user_set)
 			return true;
 	}
@@ -210,7 +246,7 @@ static const char *output_field2str(enum perf_output_field field)
 	return str;
 }
 
-#define PRINT_FIELD(x)  (output[attr->type].fields & PERF_OUTPUT_##x)
+#define PRINT_FIELD(x)  (output[output_type(attr->type)].fields & PERF_OUTPUT_##x)
 
 static int perf_evsel__do_check_stype(struct perf_evsel *evsel,
 				      u64 sample_type, const char *sample_msg,
@@ -218,7 +254,7 @@ static int perf_evsel__do_check_stype(struct perf_evsel *evsel,
 				      bool allow_user_set)
 {
 	struct perf_event_attr *attr = &evsel->attr;
-	int type = attr->type;
+	int type = output_type(attr->type);
 	const char *evname;
 
 	if (attr->sample_type & sample_type)
@@ -348,7 +384,7 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,
 
 static void set_print_ip_opts(struct perf_event_attr *attr)
 {
-	unsigned int type = attr->type;
+	unsigned int type = output_type(attr->type);
 
 	output[type].print_ip_opts = 0;
 	if (PRINT_FIELD(IP))
@@ -376,14 +412,15 @@ static int perf_session__check_output_opt(struct perf_session *session)
 	unsigned int j;
 	struct perf_evsel *evsel;
 
-	for (j = 0; j < PERF_TYPE_MAX; ++j) {
-		evsel = perf_session__find_first_evtype(session, j);
+	for (j = 0; j < OUTPUT_TYPE_MAX; ++j) {
+		evsel = perf_session__find_first_evtype(session, attr_type(j));
 
 		/*
 		 * even if fields is set to 0 (ie., show nothing) event must
 		 * exist if user explicitly includes it on the command line
 		 */
-		if (!evsel && output[j].user_set && !output[j].wildcard_set) {
+		if (!evsel && output[j].user_set && !output[j].wildcard_set &&
+		    j != OUTPUT_TYPE_SYNTH) {
 			pr_err("%s events do not exist. "
 			       "Remove corresponding -F option to proceed.\n",
 			       event_type(j));
@@ -989,6 +1026,7 @@ static void print_sample_bts(struct perf_sample *sample,
 			     struct machine *machine)
 {
 	struct perf_event_attr *attr = &evsel->attr;
+	unsigned int type = output_type(attr->type);
 	bool print_srcline_last = false;
 
 	if (PRINT_FIELD(CALLINDENT))
@@ -996,7 +1034,7 @@ static void print_sample_bts(struct perf_sample *sample,
 
 	/* print branch_from information */
 	if (PRINT_FIELD(IP)) {
-		unsigned int print_opts = output[attr->type].print_ip_opts;
+		unsigned int print_opts = output[type].print_ip_opts;
 		struct callchain_cursor *cursor = NULL;
 
 		if (symbol_conf.use_callchain && sample->callchain &&
@@ -1019,7 +1057,7 @@ static void print_sample_bts(struct perf_sample *sample,
 	/* print branch_to information */
 	if (PRINT_FIELD(ADDR) ||
 	    ((evsel->attr.sample_type & PERF_SAMPLE_ADDR) &&
-	     !output[attr->type].user_set)) {
+	     !output[type].user_set)) {
 		printf(" => ");
 		print_sample_addr(sample, thread, attr);
 	}
@@ -1215,8 +1253,9 @@ static void process_event(struct perf_script *script,
 {
 	struct thread *thread = al->thread;
 	struct perf_event_attr *attr = &evsel->attr;
+	unsigned int type = output_type(attr->type);
 
-	if (output[attr->type].fields == 0)
+	if (output[type].fields == 0)
 		return;
 
 	print_sample_start(sample, thread, evsel);
@@ -1263,7 +1302,7 @@ static void process_event(struct perf_script *script,
 			cursor = &callchain_cursor;
 
 		putchar(cursor ? '\n' : ' ');
-		sample__fprintf_sym(sample, al, 0, output[attr->type].print_ip_opts, cursor, stdout);
+		sample__fprintf_sym(sample, al, 0, output[type].print_ip_opts, cursor, stdout);
 	}
 
 	if (PRINT_FIELD(IREGS))
@@ -1410,7 +1449,8 @@ static int process_attr(struct perf_tool *tool, union perf_event *event,
 	evlist = *pevlist;
 	evsel = perf_evlist__last(*pevlist);
 
-	if (evsel->attr.type >= PERF_TYPE_MAX)
+	if (evsel->attr.type >= PERF_TYPE_MAX &&
+	    evsel->attr.type != PERF_TYPE_SYNTH)
 		return 0;
 
 	evlist__for_each_entry(evlist, pos) {
@@ -1835,6 +1875,8 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
 			type = PERF_TYPE_RAW;
 		else if (!strcmp(str, "break"))
 			type = PERF_TYPE_BREAKPOINT;
+		else if (!strcmp(str, "synth"))
+			type = OUTPUT_TYPE_SYNTH;
 		else {
 			fprintf(stderr, "Invalid event type in field string.\n");
 			rc = -EINVAL;
@@ -1865,7 +1907,7 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
 		if (output_set_by_user())
 			pr_warning("Overriding previous field request for all events.\n");
 
-		for (j = 0; j < PERF_TYPE_MAX; ++j) {
+		for (j = 0; j < OUTPUT_TYPE_MAX; ++j) {
 			output[j].fields = 0;
 			output[j].user_set = true;
 			output[j].wildcard_set = true;
@@ -1908,7 +1950,7 @@ parse:
 			/* add user option to all events types for
 			 * which it is valid
 			 */
-			for (j = 0; j < PERF_TYPE_MAX; ++j) {
+			for (j = 0; j < OUTPUT_TYPE_MAX; ++j) {
 				if (output[j].invalid_fields & all_output_options[i].field) {
 					pr_warning("\'%s\' not valid for %s events. Ignoring.\n",
 						   all_output_options[i].str, event_type(j));
@@ -2560,7 +2602,7 @@ int cmd_script(int argc, const char **argv)
 	OPT_CALLBACK('F', "fields", NULL, "str",
 		     "comma separated output fields prepend with 'type:'. "
 		     "+field to add and -field to remove."
-		     "Valid types: hw,sw,trace,raw. "
+		     "Valid types: hw,sw,trace,raw,synth. "
 		     "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
 		     "addr,symoff,period,iregs,brstack,brstacksym,flags,"
 		     "bpf-output,callindent,insn,insnlen,brstackinsn",
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 7c3fa1c..855733c 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -252,6 +252,9 @@ enum auxtrace_error_type {
 	PERF_AUXTRACE_ERROR_MAX
 };
 
+/* Attribute type for custom synthesized events */
+#define PERF_TYPE_SYNTH		(INT_MAX + 1U)
+
 /*
  * 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

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

* [tip:perf/core] tools include: Add byte-swapping macros to kernel.h
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-07-01  8:50 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: tglx, acme, mingo, ak, adrian.hunter, linux-kernel, hpa

Commit-ID:  07fda552f14830e71f0b5e8e4e31124369903aa3
Gitweb:     http://git.kernel.org/tip/07fda552f14830e71f0b5e8e4e31124369903aa3
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:23 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 27 Jun 2017 12:08:13 -0300

tools include: Add byte-swapping macros to kernel.h

Add byte-swapping macros to kernel.h

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-23-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/include/linux/kernel.h | 35 +++++++++++++++++++++++++++++------
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/tools/include/linux/kernel.h b/tools/include/linux/kernel.h
index 73ccc48..039bb85 100644
--- a/tools/include/linux/kernel.h
+++ b/tools/include/linux/kernel.h
@@ -5,6 +5,8 @@
 #include <stddef.h>
 #include <assert.h>
 #include <linux/compiler.h>
+#include <endian.h>
+#include <byteswap.h>
 
 #ifndef UINT_MAX
 #define UINT_MAX	(~0U)
@@ -67,12 +69,33 @@
 #endif
 #endif
 
-/*
- * Both need more care to handle endianness
- * (Don't use bitmap_copy_le() for now)
- */
-#define cpu_to_le64(x)	(x)
-#define cpu_to_le32(x)	(x)
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define cpu_to_le16 bswap_16
+#define cpu_to_le32 bswap_32
+#define cpu_to_le64 bswap_64
+#define le16_to_cpu bswap_16
+#define le32_to_cpu bswap_32
+#define le64_to_cpu bswap_64
+#define cpu_to_be16
+#define cpu_to_be32
+#define cpu_to_be64
+#define be16_to_cpu
+#define be32_to_cpu
+#define be64_to_cpu
+#else
+#define cpu_to_le16
+#define cpu_to_le32
+#define cpu_to_le64
+#define le16_to_cpu
+#define le32_to_cpu
+#define le64_to_cpu
+#define cpu_to_be16 bswap_16
+#define cpu_to_be32 bswap_32
+#define cpu_to_be64 bswap_64
+#define be16_to_cpu bswap_16
+#define be32_to_cpu bswap_32
+#define be64_to_cpu bswap_64
+#endif
 
 int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
 int scnprintf(char * buf, size_t size, const char * fmt, ...);

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

* [tip:perf/core] perf auxtrace: Add itrace option to output ptwrite events
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-07-01  8:51 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: acme, ak, hpa, tglx, mingo, adrian.hunter, linux-kernel

Commit-ID:  3bdafdffa9baf2b34aebad1c98bc17b50202cb78
Gitweb:     http://git.kernel.org/tip/3bdafdffa9baf2b34aebad1c98bc17b50202cb78
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:24 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 27 Jun 2017 12:09:20 -0300

perf auxtrace: Add itrace option to output ptwrite events

Add itrace option to output ptwrite events.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-24-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/itrace.txt | 7 ++++---
 tools/perf/util/auxtrace.c          | 4 ++++
 tools/perf/util/auxtrace.h          | 2 ++
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Documentation/itrace.txt b/tools/perf/Documentation/itrace.txt
index e2a4c5e..deafd16 100644
--- a/tools/perf/Documentation/itrace.txt
+++ b/tools/perf/Documentation/itrace.txt
@@ -3,13 +3,14 @@
 		c	synthesize branches events (calls only)
 		r	synthesize branches events (returns only)
 		x	synthesize transactions events
+		w	synthesize ptwrite events
 		e	synthesize error events
 		d	create a debug log
 		g	synthesize a call chain (use with i or x)
 		l	synthesize last branch entries (use with i or x)
 		s       skip initial number of events
 
-	The default is all events i.e. the same as --itrace=ibxe
+	The default is all events i.e. the same as --itrace=ibxwe
 
 	In addition, the period (default 100000) for instructions events
 	can be specified in units of:
@@ -26,8 +27,8 @@
 	Also the number of last branch entries (default 64, max. 1024) for
 	instructions or transactions events can be specified.
 
-	It is also possible to skip events generated (instructions, branches, transactions)
-	at the beginning. This is useful to ignore initialization code.
+	It is also possible to skip events generated (instructions, branches, transactions,
+	ptwrite) at the beginning. This is useful to ignore initialization code.
 
 	--itrace=i0nss1000000
 
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index 0daf63b..baad91e 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -947,6 +947,7 @@ void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts)
 	synth_opts->instructions = true;
 	synth_opts->branches = true;
 	synth_opts->transactions = true;
+	synth_opts->ptwrites = true;
 	synth_opts->errors = true;
 	synth_opts->period_type = PERF_ITRACE_DEFAULT_PERIOD_TYPE;
 	synth_opts->period = PERF_ITRACE_DEFAULT_PERIOD;
@@ -1030,6 +1031,9 @@ int itrace_parse_synth_opts(const struct option *opt, const char *str,
 		case 'x':
 			synth_opts->transactions = true;
 			break;
+		case 'w':
+			synth_opts->ptwrites = true;
+			break;
 		case 'e':
 			synth_opts->errors = true;
 			break;
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 9f0de72..b48afb2 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -59,6 +59,7 @@ enum itrace_period_type {
  * @instructions: whether to synthesize 'instructions' events
  * @branches: whether to synthesize 'branches' events
  * @transactions: whether to synthesize events for transactions
+ * @ptwrites: whether to synthesize events for ptwrites
  * @errors: whether to synthesize decoder error events
  * @dont_decode: whether to skip decoding entirely
  * @log: write a decoding log
@@ -79,6 +80,7 @@ struct itrace_synth_opts {
 	bool			instructions;
 	bool			branches;
 	bool			transactions;
+	bool			ptwrites;
 	bool			errors;
 	bool			dont_decode;
 	bool			log;

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

* [tip:perf/core] perf auxtrace: Add itrace option to output power events
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-07-01  8:51 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: mingo, acme, hpa, adrian.hunter, ak, tglx, linux-kernel

Commit-ID:  70d110d775993ff1f63905bbdbc70e3f6bd8da8a
Gitweb:     http://git.kernel.org/tip/70d110d775993ff1f63905bbdbc70e3f6bd8da8a
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:25 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 27 Jun 2017 12:09:58 -0300

perf auxtrace: Add itrace option to output power events

Add itrace option to output power events.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-25-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/itrace.txt | 5 +++--
 tools/perf/util/auxtrace.c          | 4 ++++
 tools/perf/util/auxtrace.h          | 2 ++
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/itrace.txt b/tools/perf/Documentation/itrace.txt
index deafd16..a3abe04 100644
--- a/tools/perf/Documentation/itrace.txt
+++ b/tools/perf/Documentation/itrace.txt
@@ -4,13 +4,14 @@
 		r	synthesize branches events (returns only)
 		x	synthesize transactions events
 		w	synthesize ptwrite events
+		p	synthesize power events
 		e	synthesize error events
 		d	create a debug log
 		g	synthesize a call chain (use with i or x)
 		l	synthesize last branch entries (use with i or x)
 		s       skip initial number of events
 
-	The default is all events i.e. the same as --itrace=ibxwe
+	The default is all events i.e. the same as --itrace=ibxwpe
 
 	In addition, the period (default 100000) for instructions events
 	can be specified in units of:
@@ -28,7 +29,7 @@
 	instructions or transactions events can be specified.
 
 	It is also possible to skip events generated (instructions, branches, transactions,
-	ptwrite) at the beginning. This is useful to ignore initialization code.
+	ptwrite, power) at the beginning. This is useful to ignore initialization code.
 
 	--itrace=i0nss1000000
 
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index baad91e..651c01d 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -948,6 +948,7 @@ void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts)
 	synth_opts->branches = true;
 	synth_opts->transactions = true;
 	synth_opts->ptwrites = true;
+	synth_opts->pwr_events = true;
 	synth_opts->errors = true;
 	synth_opts->period_type = PERF_ITRACE_DEFAULT_PERIOD_TYPE;
 	synth_opts->period = PERF_ITRACE_DEFAULT_PERIOD;
@@ -1034,6 +1035,9 @@ int itrace_parse_synth_opts(const struct option *opt, const char *str,
 		case 'w':
 			synth_opts->ptwrites = true;
 			break;
+		case 'p':
+			synth_opts->pwr_events = true;
+			break;
 		case 'e':
 			synth_opts->errors = true;
 			break;
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index b48afb2..68e0aa4 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -60,6 +60,7 @@ enum itrace_period_type {
  * @branches: whether to synthesize 'branches' events
  * @transactions: whether to synthesize events for transactions
  * @ptwrites: whether to synthesize events for ptwrites
+ * @pwr_events: whether to synthesize power events
  * @errors: whether to synthesize decoder error events
  * @dont_decode: whether to skip decoding entirely
  * @log: write a decoding log
@@ -81,6 +82,7 @@ struct itrace_synth_opts {
 	bool			branches;
 	bool			transactions;
 	bool			ptwrites;
+	bool			pwr_events;
 	bool			errors;
 	bool			dont_decode;
 	bool			log;

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

* [tip:perf/core] perf script: Add 'synth' field for synthesized event payloads
  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-bot for Adrian Hunter
  1 sibling, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-07-01  8:51 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: acme, tglx, mingo, linux-kernel, ak, adrian.hunter, hpa

Commit-ID:  47e780848e6229b102e601deeb1ce571dc69a84a
Gitweb:     http://git.kernel.org/tip/47e780848e6229b102e601deeb1ce571dc69a84a
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:22 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 27 Jun 2017 12:19:10 -0300

perf script: Add 'synth' field for synthesized event payloads

Add a field to display the content the raw_data of a synthesized event.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-22-git-send-email-adrian.hunter@intel.com
[ Resolved conflict with 106dacd86f04 ("perf script: Support -F brstackoff,dso") ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-script.txt |  6 +++++-
 tools/perf/builtin-script.c              | 20 ++++++++++++++++++--
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index e2468ed..5ee8796 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -117,7 +117,8 @@ OPTIONS
         Comma separated list of fields to print. Options are:
         comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
         srcline, period, iregs, brstack, brstacksym, flags, bpf-output, brstackinsn, brstackoff,
-        callindent, insn, insnlen. Field list can be prepended with the type, trace, sw or hw,
+        callindent, insn, insnlen, synth.
+        Field list can be prepended with the type, trace, sw or hw,
         to indicate to which event type the field list applies.
         e.g., -F sw:comm,tid,time,ip,sym  and -F trace:time,cpu,trace
 
@@ -193,6 +194,9 @@ OPTIONS
 	instruction bytes and the instruction length of the current
 	instruction.
 
+	The synth field is used by synthesized events which may be created when
+	Instruction Trace decoding.
+
 	Finally, a user may not set fields to none for all event types.
 	i.e., -F "" is not allowed.
 
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 2999e7e..e87b480 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -86,6 +86,7 @@ enum perf_output_field {
 	PERF_OUTPUT_INSNLEN	    = 1U << 22,
 	PERF_OUTPUT_BRSTACKINSN	    = 1U << 23,
 	PERF_OUTPUT_BRSTACKOFF	    = 1U << 24,
+	PERF_OUTPUT_SYNTH           = 1U << 25,
 };
 
 struct output_option {
@@ -117,6 +118,7 @@ struct output_option {
 	{.str = "insnlen", .field = PERF_OUTPUT_INSNLEN},
 	{.str = "brstackinsn", .field = PERF_OUTPUT_BRSTACKINSN},
 	{.str = "brstackoff", .field = PERF_OUTPUT_BRSTACKOFF},
+	{.str = "synth", .field = PERF_OUTPUT_SYNTH},
 };
 
 enum {
@@ -196,7 +198,8 @@ static struct {
 		.fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
 			      PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
 			      PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
-			      PERF_OUTPUT_SYM | PERF_OUTPUT_DSO,
+			      PERF_OUTPUT_SYM | PERF_OUTPUT_DSO |
+			      PERF_OUTPUT_SYNTH,
 
 		.invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
 	},
@@ -1200,6 +1203,15 @@ 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,
+			       struct perf_evsel *evsel)
+{
+	switch (evsel->attr.config) {
+	default:
+		break;
+	}
+}
+
 struct perf_script {
 	struct perf_tool	tool;
 	struct perf_session	*session;
@@ -1284,6 +1296,10 @@ static void process_event(struct perf_script *script,
 	if (PRINT_FIELD(TRACE))
 		event_format__print(evsel->tp_format, sample->cpu,
 				    sample->raw_data, sample->raw_size);
+
+	if (attr->type == PERF_TYPE_SYNTH && PRINT_FIELD(SYNTH))
+		print_sample_synth(sample, evsel);
+
 	if (PRINT_FIELD(ADDR))
 		print_sample_addr(sample, thread, attr);
 
@@ -2605,7 +2621,7 @@ int cmd_script(int argc, const char **argv)
 		     "Valid types: hw,sw,trace,raw,synth. "
 		     "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
 		     "addr,symoff,period,iregs,brstack,brstacksym,flags,"
-		     "bpf-output,callindent,insn,insnlen,brstackinsn",
+		     "bpf-output,callindent,insn,insnlen,brstackinsn,synth",
 		     parse_output_fields),
 	OPT_BOOLEAN('a', "all-cpus", &system_wide,
 		    "system-wide collection from all CPUs"),

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

* [tip:perf/core] perf script: Add synthesized Intel PT power and ptwrite events
  2017-06-30  8:36   ` [PATCH V3 " Adrian Hunter
@ 2017-07-01  8:52     ` tip-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-07-01  8:52 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: adrian.hunter, hpa, ak, mingo, linux-kernel, tglx, acme

Commit-ID:  65c5e18f9df078f40abd22a3f6983eb9804b6d02
Gitweb:     http://git.kernel.org/tip/65c5e18f9df078f40abd22a3f6983eb9804b6d02
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 30 Jun 2017 11:36:42 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 30 Jun 2017 11:40:20 -0300

perf script: Add synthesized Intel PT power and ptwrite events

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

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1498811802-2301-1-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 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 e87b480..b458a0c 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 855733c..9967c87 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

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

* [tip:perf/core] perf intel-pt: Factor out common code synthesizing event samples
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-07-01  8:52 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: tglx, adrian.hunter, hpa, ak, acme, mingo, linux-kernel

Commit-ID:  0f3e53799cd5fad1dcc8c077a3d9cc260243328f
Gitweb:     http://git.kernel.org/tip/0f3e53799cd5fad1dcc8c077a3d9cc260243328f
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:27 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 30 Jun 2017 11:44:33 -0300

perf intel-pt: Factor out common code synthesizing event samples

Factor out common code in functions synthesizing event samples i.e.
intel_pt_synth_branch_sample(), intel_pt_synth_instruction_sample() and
intel_pt_synth_transaction_sample().

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-27-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt.c | 222 ++++++++++++++++++++-------------------------
 1 file changed, 100 insertions(+), 122 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 6df8364..dbff5dc 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1058,6 +1058,36 @@ static void intel_pt_update_last_branch_rb(struct intel_pt_queue *ptq)
 		bs->nr += 1;
 }
 
+static inline bool intel_pt_skip_event(struct intel_pt *pt)
+{
+	return pt->synth_opts.initial_skip &&
+	       pt->num_events++ < pt->synth_opts.initial_skip;
+}
+
+static void intel_pt_prep_b_sample(struct intel_pt *pt,
+				   struct intel_pt_queue *ptq,
+				   union perf_event *event,
+				   struct perf_sample *sample)
+{
+	event->sample.header.type = PERF_RECORD_SAMPLE;
+	event->sample.header.misc = PERF_RECORD_MISC_USER;
+	event->sample.header.size = sizeof(struct perf_event_header);
+
+	if (!pt->timeless_decoding)
+		sample->time = tsc_to_perf_time(ptq->timestamp, &pt->tc);
+
+	sample->cpumode = PERF_RECORD_MISC_USER;
+	sample->ip = ptq->state->from_ip;
+	sample->pid = ptq->pid;
+	sample->tid = ptq->tid;
+	sample->addr = ptq->state->to_ip;
+	sample->period = 1;
+	sample->cpu = ptq->cpu;
+	sample->flags = ptq->flags;
+	sample->insn_len = ptq->insn_len;
+	memcpy(sample->insn, ptq->insn, INTEL_PT_INSN_BUF_SZ);
+}
+
 static int intel_pt_inject_event(union perf_event *event,
 				 struct perf_sample *sample, u64 type,
 				 bool swapped)
@@ -1066,9 +1096,35 @@ static int intel_pt_inject_event(union perf_event *event,
 	return perf_event__synthesize_sample(event, type, 0, sample, swapped);
 }
 
-static int intel_pt_synth_branch_sample(struct intel_pt_queue *ptq)
+static inline int intel_pt_opt_inject(struct intel_pt *pt,
+				      union perf_event *event,
+				      struct perf_sample *sample, u64 type)
+{
+	if (!pt->synth_opts.inject)
+		return 0;
+
+	return intel_pt_inject_event(event, sample, type, pt->synth_needs_swap);
+}
+
+static int intel_pt_deliver_synth_b_event(struct intel_pt *pt,
+					  union perf_event *event,
+					  struct perf_sample *sample, u64 type)
 {
 	int ret;
+
+	ret = intel_pt_opt_inject(pt, event, sample, type);
+	if (ret)
+		return ret;
+
+	ret = perf_session__deliver_synth_event(pt->session, event, sample);
+	if (ret)
+		pr_err("Intel PT: failed to deliver event, error %d\n", ret);
+
+	return ret;
+}
+
+static int intel_pt_synth_branch_sample(struct intel_pt_queue *ptq)
+{
 	struct intel_pt *pt = ptq->pt;
 	union perf_event *event = ptq->event_buf;
 	struct perf_sample sample = { .ip = 0, };
@@ -1080,29 +1136,13 @@ static int intel_pt_synth_branch_sample(struct intel_pt_queue *ptq)
 	if (pt->branches_filter && !(pt->branches_filter & ptq->flags))
 		return 0;
 
-	if (pt->synth_opts.initial_skip &&
-	    pt->num_events++ < pt->synth_opts.initial_skip)
+	if (intel_pt_skip_event(pt))
 		return 0;
 
-	event->sample.header.type = PERF_RECORD_SAMPLE;
-	event->sample.header.misc = PERF_RECORD_MISC_USER;
-	event->sample.header.size = sizeof(struct perf_event_header);
+	intel_pt_prep_b_sample(pt, ptq, event, &sample);
 
-	if (!pt->timeless_decoding)
-		sample.time = tsc_to_perf_time(ptq->timestamp, &pt->tc);
-
-	sample.cpumode = PERF_RECORD_MISC_USER;
-	sample.ip = ptq->state->from_ip;
-	sample.pid = ptq->pid;
-	sample.tid = ptq->tid;
-	sample.addr = ptq->state->to_ip;
 	sample.id = ptq->pt->branches_id;
 	sample.stream_id = ptq->pt->branches_id;
-	sample.period = 1;
-	sample.cpu = ptq->cpu;
-	sample.flags = ptq->flags;
-	sample.insn_len = ptq->insn_len;
-	memcpy(sample.insn, ptq->insn, INTEL_PT_INSN_BUF_SZ);
 
 	/*
 	 * perf report cannot handle events without a branch stack when using
@@ -1119,78 +1159,38 @@ static int intel_pt_synth_branch_sample(struct intel_pt_queue *ptq)
 		sample.branch_stack = (struct branch_stack *)&dummy_bs;
 	}
 
-	if (pt->synth_opts.inject) {
-		ret = intel_pt_inject_event(event, &sample,
-					    pt->branches_sample_type,
-					    pt->synth_needs_swap);
-		if (ret)
-			return ret;
-	}
-
-	ret = perf_session__deliver_synth_event(pt->session, event, &sample);
-	if (ret)
-		pr_err("Intel Processor Trace: failed to deliver branch event, error %d\n",
-		       ret);
-
-	return ret;
+	return intel_pt_deliver_synth_b_event(pt, event, &sample,
+					      pt->branches_sample_type);
 }
 
-static int intel_pt_synth_instruction_sample(struct intel_pt_queue *ptq)
+static void intel_pt_prep_sample(struct intel_pt *pt,
+				 struct intel_pt_queue *ptq,
+				 union perf_event *event,
+				 struct perf_sample *sample)
 {
-	int ret;
-	struct intel_pt *pt = ptq->pt;
-	union perf_event *event = ptq->event_buf;
-	struct perf_sample sample = { .ip = 0, };
-
-	if (pt->synth_opts.initial_skip &&
-	    pt->num_events++ < pt->synth_opts.initial_skip)
-		return 0;
-
-	event->sample.header.type = PERF_RECORD_SAMPLE;
-	event->sample.header.misc = PERF_RECORD_MISC_USER;
-	event->sample.header.size = sizeof(struct perf_event_header);
-
-	if (!pt->timeless_decoding)
-		sample.time = tsc_to_perf_time(ptq->timestamp, &pt->tc);
-
-	sample.cpumode = PERF_RECORD_MISC_USER;
-	sample.ip = ptq->state->from_ip;
-	sample.pid = ptq->pid;
-	sample.tid = ptq->tid;
-	sample.addr = ptq->state->to_ip;
-	sample.id = ptq->pt->instructions_id;
-	sample.stream_id = ptq->pt->instructions_id;
-	sample.period = ptq->state->tot_insn_cnt - ptq->last_insn_cnt;
-	sample.cpu = ptq->cpu;
-	sample.flags = ptq->flags;
-	sample.insn_len = ptq->insn_len;
-	memcpy(sample.insn, ptq->insn, INTEL_PT_INSN_BUF_SZ);
-
-	ptq->last_insn_cnt = ptq->state->tot_insn_cnt;
+	intel_pt_prep_b_sample(pt, ptq, event, sample);
 
 	if (pt->synth_opts.callchain) {
 		thread_stack__sample(ptq->thread, ptq->chain,
-				     pt->synth_opts.callchain_sz, sample.ip);
-		sample.callchain = ptq->chain;
+				     pt->synth_opts.callchain_sz, sample->ip);
+		sample->callchain = ptq->chain;
 	}
 
 	if (pt->synth_opts.last_branch) {
 		intel_pt_copy_last_branch_rb(ptq);
-		sample.branch_stack = ptq->last_branch;
+		sample->branch_stack = ptq->last_branch;
 	}
+}
 
-	if (pt->synth_opts.inject) {
-		ret = intel_pt_inject_event(event, &sample,
-					    pt->instructions_sample_type,
-					    pt->synth_needs_swap);
-		if (ret)
-			return ret;
-	}
+static inline int intel_pt_deliver_synth_event(struct intel_pt *pt,
+					       struct intel_pt_queue *ptq,
+					       union perf_event *event,
+					       struct perf_sample *sample,
+					       u64 type)
+{
+	int ret;
 
-	ret = perf_session__deliver_synth_event(pt->session, event, &sample);
-	if (ret)
-		pr_err("Intel Processor Trace: failed to deliver instruction event, error %d\n",
-		       ret);
+	ret = intel_pt_deliver_synth_b_event(pt, event, sample, type);
 
 	if (pt->synth_opts.last_branch)
 		intel_pt_reset_last_branch_rb(ptq);
@@ -1198,65 +1198,43 @@ static int intel_pt_synth_instruction_sample(struct intel_pt_queue *ptq)
 	return ret;
 }
 
-static int intel_pt_synth_transaction_sample(struct intel_pt_queue *ptq)
+static int intel_pt_synth_instruction_sample(struct intel_pt_queue *ptq)
 {
-	int ret;
 	struct intel_pt *pt = ptq->pt;
 	union perf_event *event = ptq->event_buf;
 	struct perf_sample sample = { .ip = 0, };
 
-	if (pt->synth_opts.initial_skip &&
-	    pt->num_events++ < pt->synth_opts.initial_skip)
+	if (intel_pt_skip_event(pt))
 		return 0;
 
-	event->sample.header.type = PERF_RECORD_SAMPLE;
-	event->sample.header.misc = PERF_RECORD_MISC_USER;
-	event->sample.header.size = sizeof(struct perf_event_header);
+	intel_pt_prep_sample(pt, ptq, event, &sample);
 
-	if (!pt->timeless_decoding)
-		sample.time = tsc_to_perf_time(ptq->timestamp, &pt->tc);
+	sample.id = ptq->pt->instructions_id;
+	sample.stream_id = ptq->pt->instructions_id;
+	sample.period = ptq->state->tot_insn_cnt - ptq->last_insn_cnt;
 
-	sample.cpumode = PERF_RECORD_MISC_USER;
-	sample.ip = ptq->state->from_ip;
-	sample.pid = ptq->pid;
-	sample.tid = ptq->tid;
-	sample.addr = ptq->state->to_ip;
-	sample.id = ptq->pt->transactions_id;
-	sample.stream_id = ptq->pt->transactions_id;
-	sample.period = 1;
-	sample.cpu = ptq->cpu;
-	sample.flags = ptq->flags;
-	sample.insn_len = ptq->insn_len;
-	memcpy(sample.insn, ptq->insn, INTEL_PT_INSN_BUF_SZ);
+	ptq->last_insn_cnt = ptq->state->tot_insn_cnt;
 
-	if (pt->synth_opts.callchain) {
-		thread_stack__sample(ptq->thread, ptq->chain,
-				     pt->synth_opts.callchain_sz, sample.ip);
-		sample.callchain = ptq->chain;
-	}
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->instructions_sample_type);
+}
 
-	if (pt->synth_opts.last_branch) {
-		intel_pt_copy_last_branch_rb(ptq);
-		sample.branch_stack = ptq->last_branch;
-	}
+static int intel_pt_synth_transaction_sample(struct intel_pt_queue *ptq)
+{
+	struct intel_pt *pt = ptq->pt;
+	union perf_event *event = ptq->event_buf;
+	struct perf_sample sample = { .ip = 0, };
 
-	if (pt->synth_opts.inject) {
-		ret = intel_pt_inject_event(event, &sample,
-					    pt->transactions_sample_type,
-					    pt->synth_needs_swap);
-		if (ret)
-			return ret;
-	}
+	if (intel_pt_skip_event(pt))
+		return 0;
 
-	ret = perf_session__deliver_synth_event(pt->session, event, &sample);
-	if (ret)
-		pr_err("Intel Processor Trace: failed to deliver transaction event, error %d\n",
-		       ret);
+	intel_pt_prep_sample(pt, ptq, event, &sample);
 
-	if (pt->synth_opts.last_branch)
-		intel_pt_reset_last_branch_rb(ptq);
+	sample.id = ptq->pt->transactions_id;
+	sample.stream_id = ptq->pt->transactions_id;
 
-	return ret;
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->transactions_sample_type);
 }
 
 static int intel_pt_synth_error(struct intel_pt *pt, int code, int cpu,

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

* [tip:perf/core] perf intel-pt: Remove unused instructions_sample_period
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-07-01  8:52 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: adrian.hunter, tglx, mingo, hpa, acme, linux-kernel, ak

Commit-ID:  f90d07a9f6d76e46ed99b4103747031394b16dd7
Gitweb:     http://git.kernel.org/tip/f90d07a9f6d76e46ed99b4103747031394b16dd7
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:28 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 30 Jun 2017 11:44:33 -0300

perf intel-pt: Remove unused instructions_sample_period

Remove unused struct intel_pt member instructions_sample_period.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-28-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index dbff5dc..f8237a0 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -81,7 +81,6 @@ struct intel_pt {
 
 	bool sample_instructions;
 	u64 instructions_sample_type;
-	u64 instructions_sample_period;
 	u64 instructions_id;
 
 	bool sample_branches;
@@ -1978,7 +1977,6 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 				intel_pt_ns_to_ticks(pt, pt->synth_opts.period);
 		else
 			attr.sample_period = pt->synth_opts.period;
-		pt->instructions_sample_period = attr.sample_period;
 		if (pt->synth_opts.callchain)
 			attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
 		if (pt->synth_opts.last_branch)

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

* [tip:perf/core] perf intel-pt: Join needlessly wrapped lines
  2017-05-26  8:17 ` [PATCH V2 28/37] perf intel-pt: Join needlessly wrapped lines Adrian Hunter
@ 2017-07-01  8:53   ` tip-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-07-01  8:53 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: tglx, ak, adrian.hunter, mingo, acme, linux-kernel, hpa

Commit-ID:  406a180501f6d0d4e43d5acc5f580abfc95c742d
Gitweb:     http://git.kernel.org/tip/406a180501f6d0d4e43d5acc5f580abfc95c742d
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:29 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 30 Jun 2017 11:44:34 -0300

perf intel-pt: Join needlessly wrapped lines

Join needlessly wrapped lines.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-29-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index f8237a0..b670502 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1298,15 +1298,13 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)
 
 	ptq->have_sample = false;
 
-	if (pt->sample_instructions &&
-	    (state->type & INTEL_PT_INSTRUCTION)) {
+	if (pt->sample_instructions && (state->type & INTEL_PT_INSTRUCTION)) {
 		err = intel_pt_synth_instruction_sample(ptq);
 		if (err)
 			return err;
 	}
 
-	if (pt->sample_transactions &&
-	    (state->type & INTEL_PT_TRANSACTION)) {
+	if (pt->sample_transactions && (state->type & INTEL_PT_TRANSACTION)) {
 		err = intel_pt_synth_transaction_sample(ptq);
 		if (err)
 			return err;

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

* [tip:perf/core] perf intel-pt: Tidy Intel PT evsel lookup into separate function
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-07-01  8:53 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: tglx, acme, mingo, adrian.hunter, hpa, linux-kernel, ak

Commit-ID:  85a564d26dfb45bbf0c0095e0fcee3bdc4a49a85
Gitweb:     http://git.kernel.org/tip/85a564d26dfb45bbf0c0095e0fcee3bdc4a49a85
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:30 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 30 Jun 2017 11:44:35 -0300

perf intel-pt: Tidy Intel PT evsel lookup into separate function

Tidy the lookup of the Intel PT selected event (perf_evsel) into a separate
function.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-30-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index b670502..a9486b5 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1922,24 +1922,29 @@ static int intel_pt_synth_event(struct perf_session *session,
 					   &id, intel_pt_event_synth);
 }
 
+static struct perf_evsel *intel_pt_evsel(struct intel_pt *pt,
+					 struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel;
+
+	evlist__for_each_entry(evlist, evsel) {
+		if (evsel->attr.type == pt->pmu_type && evsel->ids)
+			return evsel;
+	}
+
+	return NULL;
+}
+
 static int intel_pt_synth_events(struct intel_pt *pt,
 				 struct perf_session *session)
 {
 	struct perf_evlist *evlist = session->evlist;
-	struct perf_evsel *evsel;
+	struct perf_evsel *evsel = intel_pt_evsel(pt, evlist);
 	struct perf_event_attr attr;
-	bool found = false;
 	u64 id;
 	int err;
 
-	evlist__for_each_entry(evlist, evsel) {
-		if (evsel->attr.type == pt->pmu_type && evsel->ids) {
-			found = true;
-			break;
-		}
-	}
-
-	if (!found) {
+	if (!evsel) {
 		pr_debug("There are no selected events with Intel Processor Trace data\n");
 		return 0;
 	}

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

* [tip:perf/core] perf intel-pt: Tidy messages into called function intel_pt_synth_event()
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-07-01  8:53 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: hpa, tglx, mingo, adrian.hunter, linux-kernel, ak, acme

Commit-ID:  63a22cd9f8400fe914ddc3d597d925594f212519
Gitweb:     http://git.kernel.org/tip/63a22cd9f8400fe914ddc3d597d925594f212519
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:31 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 30 Jun 2017 11:44:35 -0300

perf intel-pt: Tidy messages into called function intel_pt_synth_event()

Tidy print messages into called function intel_pt_synth_event().

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-31-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt.c | 42 ++++++++++++++++++------------------------
 1 file changed, 18 insertions(+), 24 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index a9486b5..81907f6 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1910,16 +1910,25 @@ static int intel_pt_event_synth(struct perf_tool *tool,
 						 NULL);
 }
 
-static int intel_pt_synth_event(struct perf_session *session,
+static int intel_pt_synth_event(struct perf_session *session, const char *name,
 				struct perf_event_attr *attr, u64 id)
 {
 	struct intel_pt_synth intel_pt_synth;
+	int err;
+
+	pr_debug("Synthesizing '%s' event with id %" PRIu64 " sample type %#" PRIx64 "\n",
+		 name, id, (u64)attr->sample_type);
 
 	memset(&intel_pt_synth, 0, sizeof(struct intel_pt_synth));
 	intel_pt_synth.session = session;
 
-	return perf_event__synthesize_attr(&intel_pt_synth.dummy_tool, attr, 1,
-					   &id, intel_pt_event_synth);
+	err = perf_event__synthesize_attr(&intel_pt_synth.dummy_tool, attr, 1,
+					  &id, intel_pt_event_synth);
+	if (err)
+		pr_err("%s: failed to synthesize '%s' event type\n",
+		       __func__, name);
+
+	return err;
 }
 
 static struct perf_evsel *intel_pt_evsel(struct intel_pt *pt,
@@ -1984,14 +1993,9 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 			attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
 		if (pt->synth_opts.last_branch)
 			attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
-		pr_debug("Synthesizing 'instructions' event with id %" PRIu64 " sample type %#" PRIx64 "\n",
-			 id, (u64)attr.sample_type);
-		err = intel_pt_synth_event(session, &attr, id);
-		if (err) {
-			pr_err("%s: failed to synthesize 'instructions' event type\n",
-			       __func__);
+		err = intel_pt_synth_event(session, "instructions", &attr, id);
+		if (err)
 			return err;
-		}
 		pt->sample_instructions = true;
 		pt->instructions_sample_type = attr.sample_type;
 		pt->instructions_id = id;
@@ -2005,14 +2009,9 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 			attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
 		if (pt->synth_opts.last_branch)
 			attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
-		pr_debug("Synthesizing 'transactions' event with id %" PRIu64 " sample type %#" PRIx64 "\n",
-			 id, (u64)attr.sample_type);
-		err = intel_pt_synth_event(session, &attr, id);
-		if (err) {
-			pr_err("%s: failed to synthesize 'transactions' event type\n",
-			       __func__);
+		err = intel_pt_synth_event(session, "transactions", &attr, id);
+		if (err)
 			return err;
-		}
 		pt->sample_transactions = true;
 		pt->transactions_sample_type = attr.sample_type;
 		pt->transactions_id = id;
@@ -2033,14 +2032,9 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 		attr.sample_type |= PERF_SAMPLE_ADDR;
 		attr.sample_type &= ~(u64)PERF_SAMPLE_CALLCHAIN;
 		attr.sample_type &= ~(u64)PERF_SAMPLE_BRANCH_STACK;
-		pr_debug("Synthesizing 'branches' event with id %" PRIu64 " sample type %#" PRIx64 "\n",
-			 id, (u64)attr.sample_type);
-		err = intel_pt_synth_event(session, &attr, id);
-		if (err) {
-			pr_err("%s: failed to synthesize 'branches' event type\n",
-			       __func__);
+		err = intel_pt_synth_event(session, "branches", &attr, id);
+		if (err)
 			return err;
-		}
 		pt->sample_branches = true;
 		pt->branches_sample_type = attr.sample_type;
 		pt->branches_id = id;

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

* [tip:perf/core] perf intel-pt: Factor out intel_pt_set_event_name()
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-07-01  8:54 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: acme, adrian.hunter, hpa, linux-kernel, mingo, ak, tglx

Commit-ID:  bbac88ed64436201d6b6f2b00177d58081d56707
Gitweb:     http://git.kernel.org/tip/bbac88ed64436201d6b6f2b00177d58081d56707
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:32 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 30 Jun 2017 11:44:36 -0300

perf intel-pt: Factor out intel_pt_set_event_name()

Factor out intel_pt_set_event_name() so it can be reused.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-32-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index 81907f6..a20712e 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1931,6 +1931,21 @@ static int intel_pt_synth_event(struct perf_session *session, const char *name,
 	return err;
 }
 
+static void intel_pt_set_event_name(struct perf_evlist *evlist, u64 id,
+				    const char *name)
+{
+	struct perf_evsel *evsel;
+
+	evlist__for_each_entry(evlist, evsel) {
+		if (evsel->id && evsel->id[0] == id) {
+			if (evsel->name)
+				zfree(&evsel->name);
+			evsel->name = strdup(name);
+			break;
+		}
+	}
+}
+
 static struct perf_evsel *intel_pt_evsel(struct intel_pt *pt,
 					 struct perf_evlist *evlist)
 {
@@ -2015,15 +2030,8 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 		pt->sample_transactions = true;
 		pt->transactions_sample_type = attr.sample_type;
 		pt->transactions_id = id;
+		intel_pt_set_event_name(evlist, id, "transactions");
 		id += 1;
-		evlist__for_each_entry(evlist, evsel) {
-			if (evsel->id && evsel->id[0] == pt->transactions_id) {
-				if (evsel->name)
-					zfree(&evsel->name);
-				evsel->name = strdup("transactions");
-				break;
-			}
-		}
 	}
 
 	if (pt->synth_opts.branches) {

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

* [tip:perf/core] perf intel-pt: Move code in intel_pt_synth_events() to simplify attr setting
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-07-01  8:54 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: hpa, acme, ak, adrian.hunter, tglx, mingo, linux-kernel

Commit-ID:  4a9fd4e0effc94b9ec79250946a0054d4dd1a963
Gitweb:     http://git.kernel.org/tip/4a9fd4e0effc94b9ec79250946a0054d4dd1a963
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:33 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 30 Jun 2017 11:44:36 -0300

perf intel-pt: Move code in intel_pt_synth_events() to simplify attr setting

intel_pt_synth_events() uses the same attr structure to create each event.
Move the code around a bit to simplify that.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-33-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt.c | 45 ++++++++++++++++++++++-----------------------
 1 file changed, 22 insertions(+), 23 deletions(-)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index a20712e..ace79a4 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -1997,6 +1997,25 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 	if (!id)
 		id = 1;
 
+	if (pt->synth_opts.branches) {
+		attr.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS;
+		attr.sample_period = 1;
+		attr.sample_type |= PERF_SAMPLE_ADDR;
+		err = intel_pt_synth_event(session, "branches", &attr, id);
+		if (err)
+			return err;
+		pt->sample_branches = true;
+		pt->branches_sample_type = attr.sample_type;
+		pt->branches_id = id;
+		id += 1;
+		attr.sample_type &= ~(u64)PERF_SAMPLE_ADDR;
+	}
+
+	if (pt->synth_opts.callchain)
+		attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
+	if (pt->synth_opts.last_branch)
+		attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
+
 	if (pt->synth_opts.instructions) {
 		attr.config = PERF_COUNT_HW_INSTRUCTIONS;
 		if (pt->synth_opts.period_type == PERF_ITRACE_PERIOD_NANOSECS)
@@ -2004,10 +2023,6 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 				intel_pt_ns_to_ticks(pt, pt->synth_opts.period);
 		else
 			attr.sample_period = pt->synth_opts.period;
-		if (pt->synth_opts.callchain)
-			attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
-		if (pt->synth_opts.last_branch)
-			attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
 		err = intel_pt_synth_event(session, "instructions", &attr, id);
 		if (err)
 			return err;
@@ -2017,13 +2032,11 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 		id += 1;
 	}
 
+	attr.sample_type &= ~(u64)PERF_SAMPLE_PERIOD;
+	attr.sample_period = 1;
+
 	if (pt->synth_opts.transactions) {
 		attr.config = PERF_COUNT_HW_INSTRUCTIONS;
-		attr.sample_period = 1;
-		if (pt->synth_opts.callchain)
-			attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
-		if (pt->synth_opts.last_branch)
-			attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
 		err = intel_pt_synth_event(session, "transactions", &attr, id);
 		if (err)
 			return err;
@@ -2034,20 +2047,6 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 		id += 1;
 	}
 
-	if (pt->synth_opts.branches) {
-		attr.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS;
-		attr.sample_period = 1;
-		attr.sample_type |= PERF_SAMPLE_ADDR;
-		attr.sample_type &= ~(u64)PERF_SAMPLE_CALLCHAIN;
-		attr.sample_type &= ~(u64)PERF_SAMPLE_BRANCH_STACK;
-		err = intel_pt_synth_event(session, "branches", &attr, id);
-		if (err)
-			return err;
-		pt->sample_branches = true;
-		pt->branches_sample_type = attr.sample_type;
-		pt->branches_id = id;
-	}
-
 	pt->synth_needs_swap = evsel->needs_swap;
 
 	return 0;

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

* [tip:perf/core] perf intel-pt: Synthesize new power and "ptwrite" events
  2017-06-30  8:36   ` [PATCH V3 " Adrian Hunter
@ 2017-07-01  8:54     ` tip-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-07-01  8:54 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: tglx, linux-kernel, adrian.hunter, ak, acme, hpa, mingo

Commit-ID:  3797307576191d7fb4c974cd461188162ac36f33
Gitweb:     http://git.kernel.org/tip/3797307576191d7fb4c974cd461188162ac36f33
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 30 Jun 2017 11:36:45 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 30 Jun 2017 11:48:28 -0300

perf intel-pt: Synthesize new power and "ptwrite" events

Synthesize new power and ptwrite events.

Power events report changes to C-state but I have also added support
for the existing CBR (core-to-bus ratio) packet and included that
when outputting power events.

The PTWRITE packet is associated with the new "ptwrite" instruction,
which is essentially just a way to stuff a 32 or 64 bit value into the
PT trace.

More details can be found in the patches that add documentation and in
the Intel SDM.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1498811805-2335-1-git-send-email-adrian.hunter@intel.com
[ Copy the description of such packet from the patchkit cover message ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt.c | 283 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 283 insertions(+)

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index ace79a4..b58f9fd 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -92,6 +92,18 @@ struct intel_pt {
 	u64 transactions_sample_type;
 	u64 transactions_id;
 
+	bool sample_ptwrites;
+	u64 ptwrites_sample_type;
+	u64 ptwrites_id;
+
+	bool sample_pwr_events;
+	u64 pwr_events_sample_type;
+	u64 mwait_id;
+	u64 pwre_id;
+	u64 exstop_id;
+	u64 pwrx_id;
+	u64 cbr_id;
+
 	bool synth_needs_swap;
 
 	u64 tsc_bit;
@@ -102,6 +114,7 @@ struct intel_pt {
 	u64 cyc_bit;
 	u64 noretcomp_bit;
 	unsigned max_non_turbo_ratio;
+	unsigned cbr2khz;
 
 	unsigned long num_events;
 
@@ -1236,6 +1249,175 @@ static int intel_pt_synth_transaction_sample(struct intel_pt_queue *ptq)
 					    pt->transactions_sample_type);
 }
 
+static void intel_pt_prep_p_sample(struct intel_pt *pt,
+				   struct intel_pt_queue *ptq,
+				   union perf_event *event,
+				   struct perf_sample *sample)
+{
+	intel_pt_prep_sample(pt, ptq, event, sample);
+
+	/*
+	 * Zero IP is used to mean "trace start" but that is not the case for
+	 * power or PTWRITE events with no IP, so clear the flags.
+	 */
+	if (!sample->ip)
+		sample->flags = 0;
+}
+
+static int intel_pt_synth_ptwrite_sample(struct intel_pt_queue *ptq)
+{
+	struct intel_pt *pt = ptq->pt;
+	union perf_event *event = ptq->event_buf;
+	struct perf_sample sample = { .ip = 0, };
+	struct perf_synth_intel_ptwrite raw;
+
+	if (intel_pt_skip_event(pt))
+		return 0;
+
+	intel_pt_prep_p_sample(pt, ptq, event, &sample);
+
+	sample.id = ptq->pt->ptwrites_id;
+	sample.stream_id = ptq->pt->ptwrites_id;
+
+	raw.flags = 0;
+	raw.ip = !!(ptq->state->flags & INTEL_PT_FUP_IP);
+	raw.payload = cpu_to_le64(ptq->state->ptw_payload);
+
+	sample.raw_size = perf_synth__raw_size(raw);
+	sample.raw_data = perf_synth__raw_data(&raw);
+
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->ptwrites_sample_type);
+}
+
+static int intel_pt_synth_cbr_sample(struct intel_pt_queue *ptq)
+{
+	struct intel_pt *pt = ptq->pt;
+	union perf_event *event = ptq->event_buf;
+	struct perf_sample sample = { .ip = 0, };
+	struct perf_synth_intel_cbr raw;
+	u32 flags;
+
+	if (intel_pt_skip_event(pt))
+		return 0;
+
+	intel_pt_prep_p_sample(pt, ptq, event, &sample);
+
+	sample.id = ptq->pt->cbr_id;
+	sample.stream_id = ptq->pt->cbr_id;
+
+	flags = (u16)ptq->state->cbr_payload | (pt->max_non_turbo_ratio << 16);
+	raw.flags = cpu_to_le32(flags);
+	raw.freq = cpu_to_le32(raw.cbr * pt->cbr2khz);
+	raw.reserved3 = 0;
+
+	sample.raw_size = perf_synth__raw_size(raw);
+	sample.raw_data = perf_synth__raw_data(&raw);
+
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->pwr_events_sample_type);
+}
+
+static int intel_pt_synth_mwait_sample(struct intel_pt_queue *ptq)
+{
+	struct intel_pt *pt = ptq->pt;
+	union perf_event *event = ptq->event_buf;
+	struct perf_sample sample = { .ip = 0, };
+	struct perf_synth_intel_mwait raw;
+
+	if (intel_pt_skip_event(pt))
+		return 0;
+
+	intel_pt_prep_p_sample(pt, ptq, event, &sample);
+
+	sample.id = ptq->pt->mwait_id;
+	sample.stream_id = ptq->pt->mwait_id;
+
+	raw.reserved = 0;
+	raw.payload = cpu_to_le64(ptq->state->mwait_payload);
+
+	sample.raw_size = perf_synth__raw_size(raw);
+	sample.raw_data = perf_synth__raw_data(&raw);
+
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->pwr_events_sample_type);
+}
+
+static int intel_pt_synth_pwre_sample(struct intel_pt_queue *ptq)
+{
+	struct intel_pt *pt = ptq->pt;
+	union perf_event *event = ptq->event_buf;
+	struct perf_sample sample = { .ip = 0, };
+	struct perf_synth_intel_pwre raw;
+
+	if (intel_pt_skip_event(pt))
+		return 0;
+
+	intel_pt_prep_p_sample(pt, ptq, event, &sample);
+
+	sample.id = ptq->pt->pwre_id;
+	sample.stream_id = ptq->pt->pwre_id;
+
+	raw.reserved = 0;
+	raw.payload = cpu_to_le64(ptq->state->pwre_payload);
+
+	sample.raw_size = perf_synth__raw_size(raw);
+	sample.raw_data = perf_synth__raw_data(&raw);
+
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->pwr_events_sample_type);
+}
+
+static int intel_pt_synth_exstop_sample(struct intel_pt_queue *ptq)
+{
+	struct intel_pt *pt = ptq->pt;
+	union perf_event *event = ptq->event_buf;
+	struct perf_sample sample = { .ip = 0, };
+	struct perf_synth_intel_exstop raw;
+
+	if (intel_pt_skip_event(pt))
+		return 0;
+
+	intel_pt_prep_p_sample(pt, ptq, event, &sample);
+
+	sample.id = ptq->pt->exstop_id;
+	sample.stream_id = ptq->pt->exstop_id;
+
+	raw.flags = 0;
+	raw.ip = !!(ptq->state->flags & INTEL_PT_FUP_IP);
+
+	sample.raw_size = perf_synth__raw_size(raw);
+	sample.raw_data = perf_synth__raw_data(&raw);
+
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->pwr_events_sample_type);
+}
+
+static int intel_pt_synth_pwrx_sample(struct intel_pt_queue *ptq)
+{
+	struct intel_pt *pt = ptq->pt;
+	union perf_event *event = ptq->event_buf;
+	struct perf_sample sample = { .ip = 0, };
+	struct perf_synth_intel_pwrx raw;
+
+	if (intel_pt_skip_event(pt))
+		return 0;
+
+	intel_pt_prep_p_sample(pt, ptq, event, &sample);
+
+	sample.id = ptq->pt->pwrx_id;
+	sample.stream_id = ptq->pt->pwrx_id;
+
+	raw.reserved = 0;
+	raw.payload = cpu_to_le64(ptq->state->pwrx_payload);
+
+	sample.raw_size = perf_synth__raw_size(raw);
+	sample.raw_data = perf_synth__raw_data(&raw);
+
+	return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
+					    pt->pwr_events_sample_type);
+}
+
 static int intel_pt_synth_error(struct intel_pt *pt, int code, int cpu,
 				pid_t pid, pid_t tid, u64 ip)
 {
@@ -1287,6 +1469,10 @@ static inline bool intel_pt_is_switch_ip(struct intel_pt_queue *ptq, u64 ip)
 			       PERF_IP_FLAG_INTERRUPT | PERF_IP_FLAG_TX_ABORT));
 }
 
+#define INTEL_PT_PWR_EVT (INTEL_PT_MWAIT_OP | INTEL_PT_PWR_ENTRY | \
+			  INTEL_PT_EX_STOP | INTEL_PT_PWR_EXIT | \
+			  INTEL_PT_CBR_CHG)
+
 static int intel_pt_sample(struct intel_pt_queue *ptq)
 {
 	const struct intel_pt_state *state = ptq->state;
@@ -1298,6 +1484,34 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)
 
 	ptq->have_sample = false;
 
+	if (pt->sample_pwr_events && (state->type & INTEL_PT_PWR_EVT)) {
+		if (state->type & INTEL_PT_CBR_CHG) {
+			err = intel_pt_synth_cbr_sample(ptq);
+			if (err)
+				return err;
+		}
+		if (state->type & INTEL_PT_MWAIT_OP) {
+			err = intel_pt_synth_mwait_sample(ptq);
+			if (err)
+				return err;
+		}
+		if (state->type & INTEL_PT_PWR_ENTRY) {
+			err = intel_pt_synth_pwre_sample(ptq);
+			if (err)
+				return err;
+		}
+		if (state->type & INTEL_PT_EX_STOP) {
+			err = intel_pt_synth_exstop_sample(ptq);
+			if (err)
+				return err;
+		}
+		if (state->type & INTEL_PT_PWR_EXIT) {
+			err = intel_pt_synth_pwrx_sample(ptq);
+			if (err)
+				return err;
+		}
+	}
+
 	if (pt->sample_instructions && (state->type & INTEL_PT_INSTRUCTION)) {
 		err = intel_pt_synth_instruction_sample(ptq);
 		if (err)
@@ -1310,6 +1524,12 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)
 			return err;
 	}
 
+	if (pt->sample_ptwrites && (state->type & INTEL_PT_PTW)) {
+		err = intel_pt_synth_ptwrite_sample(ptq);
+		if (err)
+			return err;
+	}
+
 	if (!(state->type & INTEL_PT_BRANCH))
 		return 0;
 
@@ -2047,6 +2267,68 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 		id += 1;
 	}
 
+	attr.type = PERF_TYPE_SYNTH;
+	attr.sample_type |= PERF_SAMPLE_RAW;
+
+	if (pt->synth_opts.ptwrites) {
+		attr.config = PERF_SYNTH_INTEL_PTWRITE;
+		err = intel_pt_synth_event(session, "ptwrite", &attr, id);
+		if (err)
+			return err;
+		pt->sample_ptwrites = true;
+		pt->ptwrites_sample_type = attr.sample_type;
+		pt->ptwrites_id = id;
+		intel_pt_set_event_name(evlist, id, "ptwrite");
+		id += 1;
+	}
+
+	if (pt->synth_opts.pwr_events) {
+		pt->sample_pwr_events = true;
+		pt->pwr_events_sample_type = attr.sample_type;
+
+		attr.config = PERF_SYNTH_INTEL_CBR;
+		err = intel_pt_synth_event(session, "cbr", &attr, id);
+		if (err)
+			return err;
+		pt->cbr_id = id;
+		intel_pt_set_event_name(evlist, id, "cbr");
+		id += 1;
+	}
+
+	if (pt->synth_opts.pwr_events && (evsel->attr.config & 0x10)) {
+		attr.config = PERF_SYNTH_INTEL_MWAIT;
+		err = intel_pt_synth_event(session, "mwait", &attr, id);
+		if (err)
+			return err;
+		pt->mwait_id = id;
+		intel_pt_set_event_name(evlist, id, "mwait");
+		id += 1;
+
+		attr.config = PERF_SYNTH_INTEL_PWRE;
+		err = intel_pt_synth_event(session, "pwre", &attr, id);
+		if (err)
+			return err;
+		pt->pwre_id = id;
+		intel_pt_set_event_name(evlist, id, "pwre");
+		id += 1;
+
+		attr.config = PERF_SYNTH_INTEL_EXSTOP;
+		err = intel_pt_synth_event(session, "exstop", &attr, id);
+		if (err)
+			return err;
+		pt->exstop_id = id;
+		intel_pt_set_event_name(evlist, id, "exstop");
+		id += 1;
+
+		attr.config = PERF_SYNTH_INTEL_PWRX;
+		err = intel_pt_synth_event(session, "pwrx", &attr, id);
+		if (err)
+			return err;
+		pt->pwrx_id = id;
+		intel_pt_set_event_name(evlist, id, "pwrx");
+		id += 1;
+	}
+
 	pt->synth_needs_swap = evsel->needs_swap;
 
 	return 0;
@@ -2313,6 +2595,7 @@ int intel_pt_process_auxtrace_info(union perf_event *event,
 		intel_pt_log("TSC frequency %"PRIu64"\n", tsc_freq);
 		intel_pt_log("Maximum non-turbo ratio %u\n",
 			     pt->max_non_turbo_ratio);
+		pt->cbr2khz = tsc_freq / pt->max_non_turbo_ratio / 1000;
 	}
 
 	if (pt->synth_opts.calls)

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

* [tip:perf/core] perf intel-pt: Add example script for power events and PTWRITE
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-07-01  8:55 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: hpa, ak, tglx, adrian.hunter, mingo, linux-kernel, acme

Commit-ID:  cc892720d85a31cc04f4c01c03d88a0eb3c437fa
Gitweb:     http://git.kernel.org/tip/cc892720d85a31cc04f4c01c03d88a0eb3c437fa
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:35 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 30 Jun 2017 11:50:53 -0300

perf intel-pt: Add example script for power events and PTWRITE

Add script intel-pt-events.py that provides an example of how to unpack the
raw data for power events and PTWRITE.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-35-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 .../perf/scripts/python/bin/intel-pt-events-record |  13 +++
 .../perf/scripts/python/bin/intel-pt-events-report |   3 +
 tools/perf/scripts/python/intel-pt-events.py       | 128 +++++++++++++++++++++
 3 files changed, 144 insertions(+)

diff --git a/tools/perf/scripts/python/bin/intel-pt-events-record b/tools/perf/scripts/python/bin/intel-pt-events-record
new file mode 100644
index 0000000..10fe2b6
--- /dev/null
+++ b/tools/perf/scripts/python/bin/intel-pt-events-record
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+#
+# print Intel PT Power Events and PTWRITE. The intel_pt PMU event needs
+# to be specified with appropriate config terms.
+#
+if ! echo "$@" | grep -q intel_pt ; then
+	echo "Options must include the Intel PT event e.g. -e intel_pt/pwr_evt,ptw/"
+	echo "and for power events it probably needs to be system wide i.e. -a option"
+	echo "For example: -a -e intel_pt/pwr_evt,branch=0/ sleep 1"
+	exit 1
+fi
+perf record $@
diff --git a/tools/perf/scripts/python/bin/intel-pt-events-report b/tools/perf/scripts/python/bin/intel-pt-events-report
new file mode 100644
index 0000000..9a9c92f
--- /dev/null
+++ b/tools/perf/scripts/python/bin/intel-pt-events-report
@@ -0,0 +1,3 @@
+#!/bin/bash
+# description: print Intel PT Power Events and PTWRITE
+perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/intel-pt-events.py
\ No newline at end of file
diff --git a/tools/perf/scripts/python/intel-pt-events.py b/tools/perf/scripts/python/intel-pt-events.py
new file mode 100644
index 0000000..b19172d
--- /dev/null
+++ b/tools/perf/scripts/python/intel-pt-events.py
@@ -0,0 +1,128 @@
+# intel-pt-events.py: Print Intel PT Power Events and PTWRITE
+# Copyright (c) 2017, Intel Corporation.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms and conditions of the GNU General Public License,
+# version 2, as published by the Free Software Foundation.
+#
+# This program is distributed in the hope it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+
+import os
+import sys
+import struct
+
+sys.path.append(os.environ['PERF_EXEC_PATH'] + \
+	'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
+
+# These perf imports are not used at present
+#from perf_trace_context import *
+#from Core import *
+
+def trace_begin():
+	print "Intel PT Power Events and PTWRITE"
+
+def trace_end():
+	print "End"
+
+def trace_unhandled(event_name, context, event_fields_dict):
+		print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())])
+
+def print_ptwrite(raw_buf):
+	data = struct.unpack_from("<IQ", raw_buf)
+	flags = data[0]
+	payload = data[1]
+	exact_ip = flags & 1
+	print "IP: %u payload: %#x" % (exact_ip, payload),
+
+def print_cbr(raw_buf):
+	data = struct.unpack_from("<BBBBII", raw_buf)
+	cbr = data[0]
+	f = (data[4] + 500) / 1000
+	p = ((cbr * 1000 / data[2]) + 5) / 10
+	print "%3u  freq: %4u MHz  (%3u%%)" % (cbr, f, p),
+
+def print_mwait(raw_buf):
+	data = struct.unpack_from("<IQ", raw_buf)
+	payload = data[1]
+	hints = payload & 0xff
+	extensions = (payload >> 32) & 0x3
+	print "hints: %#x extensions: %#x" % (hints, extensions),
+
+def print_pwre(raw_buf):
+	data = struct.unpack_from("<IQ", raw_buf)
+	payload = data[1]
+	hw = (payload >> 7) & 1
+	cstate = (payload >> 12) & 0xf
+	subcstate = (payload >> 8) & 0xf
+	print "hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate),
+
+def print_exstop(raw_buf):
+	data = struct.unpack_from("<I", raw_buf)
+	flags = data[0]
+	exact_ip = flags & 1
+	print "IP: %u" % (exact_ip),
+
+def print_pwrx(raw_buf):
+	data = struct.unpack_from("<IQ", raw_buf)
+	payload = data[1]
+	deepest_cstate = payload & 0xf
+	last_cstate = (payload >> 4) & 0xf
+	wake_reason = (payload >> 8) & 0xf
+	print "deepest cstate: %u last cstate: %u wake reason: %#x" % (deepest_cstate, last_cstate, wake_reason),
+
+def print_common_start(comm, sample, name):
+	ts = sample["time"]
+	cpu = sample["cpu"]
+	pid = sample["pid"]
+	tid = sample["tid"]
+	print "%16s %5u/%-5u [%03u] %9u.%09u %7s:" % (comm, pid, tid, cpu, ts / 1000000000, ts %1000000000, name),
+
+def print_common_ip(sample, symbol, dso):
+	ip = sample["ip"]
+	print "%16x %s (%s)" % (ip, symbol, dso)
+
+def process_event(param_dict):
+        event_attr = param_dict["attr"]
+        sample     = param_dict["sample"]
+        raw_buf    = param_dict["raw_buf"]
+        comm       = param_dict["comm"]
+        name       = param_dict["ev_name"]
+
+        # Symbol and dso info are not always resolved
+        if (param_dict.has_key("dso")):
+                dso = param_dict["dso"]
+        else:
+                dso = "[unknown]"
+
+        if (param_dict.has_key("symbol")):
+                symbol = param_dict["symbol"]
+        else:
+                symbol = "[unknown]"
+
+	if name == "ptwrite":
+		print_common_start(comm, sample, name)
+		print_ptwrite(raw_buf)
+		print_common_ip(sample, symbol, dso)
+	elif name == "cbr":
+		print_common_start(comm, sample, name)
+		print_cbr(raw_buf)
+		print_common_ip(sample, symbol, dso)
+	elif name == "mwait":
+		print_common_start(comm, sample, name)
+		print_mwait(raw_buf)
+		print_common_ip(sample, symbol, dso)
+	elif name == "pwre":
+		print_common_start(comm, sample, name)
+		print_pwre(raw_buf)
+		print_common_ip(sample, symbol, dso)
+	elif name == "exstop":
+		print_common_start(comm, sample, name)
+		print_exstop(raw_buf)
+		print_common_ip(sample, symbol, dso)
+	elif name == "pwrx":
+		print_common_start(comm, sample, name)
+		print_pwrx(raw_buf)
+		print_common_ip(sample, symbol, dso)

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

* [tip:perf/core] perf intel-pt: Update documentation to include new ptwrite and power events
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-07-01  8:55 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: acme, hpa, linux-kernel, mingo, adrian.hunter, ak, tglx

Commit-ID:  ead2bfdb85ab311bc3e1c2e55bff207aafaab096
Gitweb:     http://git.kernel.org/tip/ead2bfdb85ab311bc3e1c2e55bff207aafaab096
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:36 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 30 Jun 2017 11:50:54 -0300

perf intel-pt: Update documentation to include new ptwrite and power events

Update documentation to include new ptwrite and power events.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-36-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/intel-pt.txt | 42 +++++++++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/intel-pt.txt b/tools/perf/Documentation/intel-pt.txt
index d157dee..4b6cdbf 100644
--- a/tools/perf/Documentation/intel-pt.txt
+++ b/tools/perf/Documentation/intel-pt.txt
@@ -108,6 +108,9 @@ approach is available to export the data to a postgresql database.  Refer to
 script export-to-postgresql.py for more details, and to script
 call-graph-from-postgresql.py for an example of using the database.
 
+There is also script intel-pt-events.py which provides an example of how to
+unpack the raw data for power events and PTWRITE.
+
 As mentioned above, it is easy to capture too much data.  One way to limit the
 data captured is to use 'snapshot' mode which is explained further below.
 Refer to 'new snapshot option' and 'Intel PT modes of operation' further below.
@@ -710,13 +713,15 @@ Having no option is the same as
 
 which, in turn, is the same as
 
-	--itrace=ibxe
+	--itrace=ibxwpe
 
 The letters are:
 
 	i	synthesize "instructions" events
 	b	synthesize "branches" events
 	x	synthesize "transactions" events
+	w	synthesize "ptwrite" events
+	p	synthesize "power" events
 	c	synthesize branches events (calls only)
 	r	synthesize branches events (returns only)
 	e	synthesize tracing error events
@@ -735,7 +740,40 @@ and "r" can be combined to get calls and returns.
 'flags' field can be used in perf script to determine whether the event is a
 tranasaction start, commit or abort.
 
-Error events are new.  They show where the decoder lost the trace.  Error events
+Note that "instructions", "branches" and "transactions" events depend on code
+flow packets which can be disabled by using the config term "branch=0".  Refer
+to the config terms section above.
+
+"ptwrite" events record the payload of the ptwrite instruction and whether
+"fup_on_ptw" was used.  "ptwrite" events depend on PTWRITE packets which are
+recorded only if the "ptw" config term was used.  Refer to the config terms
+section above.  perf script "synth" field displays "ptwrite" information like
+this: "ip: 0 payload: 0x123456789abcdef0"  where "ip" is 1 if "fup_on_ptw" was
+used.
+
+"Power" events correspond to power event packets and CBR (core-to-bus ratio)
+packets.  While CBR packets are always recorded when tracing is enabled, power
+event packets are recorded only if the "pwr_evt" config term was used.  Refer to
+the config terms section above.  The power events record information about
+C-state changes, whereas CBR is indicative of CPU frequency.  perf script
+"event,synth" fields display information like this:
+	cbr:  cbr: 22 freq: 2189 MHz (200%)
+	mwait:  hints: 0x60 extensions: 0x1
+	pwre:  hw: 0 cstate: 2 sub-cstate: 0
+	exstop:  ip: 1
+	pwrx:  deepest cstate: 2 last cstate: 2 wake reason: 0x4
+Where:
+	"cbr" includes the frequency and the percentage of maximum non-turbo
+	"mwait" shows mwait hints and extensions
+	"pwre" shows C-state transitions (to a C-state deeper than C0) and
+	whether	initiated by hardware
+	"exstop" indicates execution stopped and whether the IP was recorded
+	exactly,
+	"pwrx" indicates return to C0
+For more details refer to the Intel 64 and IA-32 Architectures Software
+Developer Manuals.
+
+Error events show where the decoder lost the trace.  Error events
 are quite important.  Users must know if what they are seeing is a complete
 picture or not.
 

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

* [tip:perf/core] perf intel-pt: Do not use TSC packets for calculating CPU cycles to TSC
  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-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-07-01  8:56 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: adrian.hunter, acme, linux-kernel, hpa, tglx, mingo, ak

Commit-ID:  38b65b0891dc129dc0a5ce148a21c481e667b395
Gitweb:     http://git.kernel.org/tip/38b65b0891dc129dc0a5ce148a21c481e667b395
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:37 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 30 Jun 2017 11:50:55 -0300

perf intel-pt: Do not use TSC packets for calculating CPU cycles to TSC

CBR (core-to-bus ratio) packets provide an indication of CPU frequency. A
more accurate measure can be made by counting the cycles (given by CYC
packets) in between other timing packets (either MTC or TSC). Using TSC
packets has at least 2 issues: 1) timing might have stopped (e.g. mwait) or
2) TSC packets within PSB+ might slip past CYC packets. For now, simply do
not use TSC packets for calculating CPU cycles to TSC. That leaves the case
where 2 MTC packets are used, otherwise falling back to the CBR value.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-37-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index 5dea062..aa1593c 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -711,6 +711,12 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info)
 		break;
 
 	case INTEL_PT_TSC:
+		/*
+		 * For now, do not support using TSC packets - refer
+		 * intel_pt_calc_cyc_to_tsc().
+		 */
+		if (data->from_mtc)
+			return 1;
 		timestamp = pkt_info->packet.payload |
 			    (data->timestamp & (0xffULL << 56));
 		if (data->from_mtc && timestamp < data->timestamp &&
@@ -828,6 +834,14 @@ static void intel_pt_calc_cyc_to_tsc(struct intel_pt_decoder *decoder,
 		.cbr_cyc_to_tsc = 0,
 	};
 
+	/*
+	 * For now, do not support using TSC packets for at least the reasons:
+	 * 1) timing might have stopped
+	 * 2) TSC packets within PSB+ can slip against CYC packets
+	 */
+	if (!from_mtc)
+		return;
+
 	intel_pt_pkt_lookahead(decoder, intel_pt_calc_cyc_cb, &data);
 }
 

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

* [tip:perf/core] perf auxtrace: Add CPU filter support
  2017-05-26  8:17 ` [PATCH V2 37/37] perf auxtrace: Add CPU filter support Adrian Hunter
@ 2017-07-01  8:56   ` tip-bot for Adrian Hunter
  0 siblings, 0 replies; 100+ messages in thread
From: tip-bot for Adrian Hunter @ 2017-07-01  8:56 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, adrian.hunter, tglx, acme, ak, hpa, mingo

Commit-ID:  644e0840ad4615e032d67adec6ee60f821b669fe
Gitweb:     http://git.kernel.org/tip/644e0840ad4615e032d67adec6ee60f821b669fe
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Fri, 26 May 2017 11:17:38 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 30 Jun 2017 11:50:55 -0300

perf auxtrace: Add CPU filter support

Decoding auxtrace data can take a long time. To avoid decoding
unnecessarily, filter auxtrace data that is collected per-cpu before it is
decoded.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1495786658-18063-38-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-report.c |  1 +
 tools/perf/builtin-script.c |  1 +
 tools/perf/util/auxtrace.c  | 10 ++++++++++
 tools/perf/util/auxtrace.h  |  2 ++
 4 files changed, 14 insertions(+)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 1174a42..79a33eb 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -557,6 +557,7 @@ static int __cmd_report(struct report *rep)
 			ui__error("failed to set cpu bitmap\n");
 			return ret;
 		}
+		session->itrace_synth_opts->cpu_bitmap = rep->cpu_bitmap;
 	}
 
 	if (rep->show_threads) {
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index b458a0c..83cdc0a 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2992,6 +2992,7 @@ int cmd_script(int argc, const char **argv)
 		err = perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap);
 		if (err < 0)
 			goto out_delete;
+		itrace_synth_opts.cpu_bitmap = cpu_bitmap;
 	}
 
 	if (!no_callchain)
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index 651c01d..5547457 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -322,6 +322,13 @@ static int auxtrace_queues__add_event_buffer(struct auxtrace_queues *queues,
 	return auxtrace_queues__add_buffer(queues, idx, buffer);
 }
 
+static bool filter_cpu(struct perf_session *session, int cpu)
+{
+	unsigned long *cpu_bitmap = session->itrace_synth_opts->cpu_bitmap;
+
+	return cpu_bitmap && cpu != -1 && !test_bit(cpu, cpu_bitmap);
+}
+
 int auxtrace_queues__add_event(struct auxtrace_queues *queues,
 			       struct perf_session *session,
 			       union perf_event *event, off_t data_offset,
@@ -331,6 +338,9 @@ int auxtrace_queues__add_event(struct auxtrace_queues *queues,
 	unsigned int idx;
 	int err;
 
+	if (filter_cpu(session, event->auxtrace.cpu))
+		return 0;
+
 	buffer = zalloc(sizeof(struct auxtrace_buffer));
 	if (!buffer)
 		return -ENOMEM;
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 68e0aa4..33b5e6c 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -74,6 +74,7 @@ enum itrace_period_type {
  * @period: 'instructions' events period
  * @period_type: 'instructions' events period type
  * @initial_skip: skip N events at the beginning.
+ * @cpu_bitmap: CPUs for which to synthesize events, or NULL for all
  */
 struct itrace_synth_opts {
 	bool			set;
@@ -96,6 +97,7 @@ struct itrace_synth_opts {
 	unsigned long long	period;
 	enum itrace_period_type	period_type;
 	unsigned long		initial_skip;
+	unsigned long		*cpu_bitmap;
 };
 
 /**

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

end of thread, other threads:[~2017-07-01  8:57 UTC | newest]

Thread overview: 100+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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   ` [PATCH V3 " Adrian Hunter
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

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.