Skip to contentSkip to conversation

perf intel-pt: Add support for Event Trace and TNT disable

PATCH Applied Adrian Hunter 2 participants 30 messages Jan 24, 2022 – Feb 16, 2022 perf events

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore

Adrian Hunter

author reviewer
#0 lore raw

cover perf intel-pt: Add support for Event Trace and TNT disable

Hi

Brief documentation is in the last patch with more technical details in Intel SDM (https://www.intel.com/sdm) version 076.

The patches touch mostly Intel PT and auxtrace code, with a few supporting changes to perf script.

I am not aware of any hardware that has the new capabilities yet.

Patches can also be found here:

https://github.com/ahunter6/linux/tree/event-trace

Adrian Hunter (25):
perf intel-pt: pkt-decoder-test: Fix scope of test_data perf intel-pt: pkt-decoder: Remove misplaced linebreak perf intel-pt: pkt-decoder: Add CFE and EVD packets
perf intel-pt: pkt-decoder: Add MODE.Exec IFLAG bit
perf intel-pt: decoder: Add config bit definitions
perf intel-pt: decoder: Factor out clearing of FUP event variables perf intel-pt: decoder: Add CFE and EVD processing
perf intel-pt: decoder: Add MODE.Exec IFLAG processing perf tools: Define Intel PT CFE / EVD event
perf tools: Define Intel PT iflag synthesized event
perf tools: Define new D and t flags
perf auxtrace: Add itrace option "I"
perf intel-pt: Record Event Trace capability flag
perf intel-pt: Synthesize CFE / EVD event
perf intel-pt: Synthesize iflag event
perf intel-pt: Synthesize new D and t flags
perf intel-pt: Force 'quick' mode when TNT is disabled perf script: Display Intel PT CFE / EVD synthesized event perf script: Display Intel PT iflag synthesized event perf script: Display new D and t flags
perf scripts python: intel-pt-events.py: Add Event Trace perf scripting python: Add all sample flags to DB export perf scripts python: export-to-sqlite.py: Export all sample flags perf scripts python: export-to-postgresql.py: Export all sample flags perf intel-pt: Add documentation for Event Trace and TNT disable

 tools/perf/Documentation/itrace.txt                |   2 +
 tools/perf/Documentation/perf-intel-pt.txt         | 104 ++++++++-
 tools/perf/Documentation/perf-script.txt           |  13 +-
 .../arch/x86/tests/intel-pt-pkt-decoder-test.c     |  17 +-
 tools/perf/arch/x86/util/intel-pt.c                |   7 +
 tools/perf/builtin-script.c                        |  78 ++++++-
 tools/perf/scripts/python/export-to-postgresql.py  |  17 +-
 tools/perf/scripts/python/export-to-sqlite.py      |  19 +-
 tools/perf/scripts/python/intel-pt-events.py       |  55 ++++-
 tools/perf/util/auxtrace.c                         |   4 +
 tools/perf/util/auxtrace.h                         |   4 +
 tools/perf/util/event.h                            |  45 +++-
 .../perf/util/intel-pt-decoder/intel-pt-decoder.c  | 245 +++++++++++++++++++--
 .../perf/util/intel-pt-decoder/intel-pt-decoder.h  |  21 ++
 .../util/intel-pt-decoder/intel-pt-pkt-decoder.c   |  47 +++-
 .../util/intel-pt-decoder/intel-pt-pkt-decoder.h   |   3 +
 tools/perf/util/intel-pt.c                         | 164 +++++++++++++-
 .../util/scripting-engines/trace-event-python.c    |   3 +-
 18 files changed, 779 insertions(+), 69 deletions(-)

Regards
Adrian

author reviewer
#1 lore raw

PATCH 1/25 perf intel-pt: pkt-decoder-test: Fix scope of test_data

Make test_data 'static' otherwise it will conflict with any global variable of the same name.

---
 tools/perf/arch/x86/tests/intel-pt-pkt-decoder-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/arch/x86/tests/intel-pt-pkt-decoder-test.c +1 -1
index 2fc882ab24c1..395de4471840 100644
@@ -17,7 +17,7 @@
  * @new_ctx: expected new packet context
  * @ctx_unchanged: the packet context must not change
  */
-struct test_data {
+static struct test_data {
 	int len;
 	u8 bytes[INTEL_PT_PKT_MAX_SZ];
 	enum intel_pt_pkt_ctx ctx;
Signature · 1 line
2.25.1
author reviewer
#2 lore raw

PATCH 2/25 perf intel-pt: pkt-decoder: Remove misplaced linebreak

In reply to Adrian Hunter

Minor whitespace fix up.

---
 tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c +1 -2
index 4bd154848cad..fada96746705 100644
@@ -197,8 +197,7 @@ static int intel_pt_get_mnt(const unsigned char *buf, size_t len,
 		return INTEL_PT_NEED_MORE_BYTES;
 	packet->type = INTEL_PT_MNT;
 	memcpy_le64(&packet->payload, buf + 3, 8);
-	return 11
-;
+	return 11;
 }
 
 static int intel_pt_get_3byte(const unsigned char *buf, size_t len,
Signature · 1 line
2.25.1
author reviewer
#3 lore raw

PATCH 3/25 perf intel-pt: pkt-decoder: Add CFE and EVD packets

In reply to Adrian Hunter

As of Intel SDM (https://www.intel.com/sdm) version 076, there is a new Intel PT feature called Event Trace which requires 2 new packets CFE and EVD. Add them to the packet decoder and packet decoder test.

---
 .../x86/tests/intel-pt-pkt-decoder-test.c     |  8 ++++
 .../util/intel-pt-decoder/intel-pt-decoder.c  | 32 +++++++++++++++
 .../intel-pt-decoder/intel-pt-pkt-decoder.c   | 40 +++++++++++++++++++
 .../intel-pt-decoder/intel-pt-pkt-decoder.h   |  3 ++
 4 files changed, 83 insertions(+)
tools/perf/arch/x86/tests/intel-pt-pkt-decoder-test.c +8 -0
index 395de4471840..0155215c1d41 100644
@@ -166,6 +166,14 @@ static struct test_data {
 	{2, {0x02, 0xb3}, INTEL_PT_BLK_4_CTX, {INTEL_PT_BEP_IP, 0, 0}, 0, 0 },
 	{2, {0x02, 0x33}, INTEL_PT_BLK_8_CTX, {INTEL_PT_BEP, 0, 0}, 0, 0 },
 	{2, {0x02, 0xb3}, INTEL_PT_BLK_8_CTX, {INTEL_PT_BEP_IP, 0, 0}, 0, 0 },
+	/* Control Flow Event Packet */
+	{4, {0x02, 0x13, 0x01, 0x03}, 0, {INTEL_PT_CFE, 1, 3}, 0, 0 },
+	{4, {0x02, 0x13, 0x81, 0x03}, 0, {INTEL_PT_CFE_IP, 1, 3}, 0, 0 },
+	{4, {0x02, 0x13, 0x1f, 0x00}, 0, {INTEL_PT_CFE, 0x1f, 0}, 0, 0 },
+	{4, {0x02, 0x13, 0x9f, 0xff}, 0, {INTEL_PT_CFE_IP, 0x1f, 0xff}, 0, 0 },
+	/*  */
+	{11, {0x02, 0x53, 0x09, 1, 2, 3, 4, 5, 6, 7}, 0, {INTEL_PT_EVD, 0x09, 0x7060504030201}, 0, 0 },
+	{11, {0x02, 0x53, 0x3f, 2, 3, 4, 5, 6, 7, 8}, 0, {INTEL_PT_EVD, 0x3f, 0x8070605040302}, 0, 0 },
 	/* Terminator */
 	{0, {0}, 0, {0, 0, 0}, 0, 0 },
 };
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +32 -0
index 0e013c2d9eb4..3980ee2080ae 100644
@@ -820,6 +820,9 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info)
 	case INTEL_PT_BIP:
 	case INTEL_PT_BEP:
 	case INTEL_PT_BEP_IP:
+	case INTEL_PT_CFE:
+	case INTEL_PT_CFE_IP:
+	case INTEL_PT_EVD:
 		return 0;
 
 	case INTEL_PT_MTC:
@@ -1873,6 +1876,9 @@ static int intel_pt_walk_psbend(struct intel_pt_decoder *decoder)
 		case INTEL_PT_BIP:
 		case INTEL_PT_BEP:
 		case INTEL_PT_BEP_IP:
+		case INTEL_PT_CFE:
+		case INTEL_PT_CFE_IP:
+		case INTEL_PT_EVD:
 			decoder->have_tma = false;
 			intel_pt_log("ERROR: Unexpected packet\n");
 			err = -EAGAIN;
@@ -1975,6 +1981,9 @@ static int intel_pt_walk_fup_tip(struct intel_pt_decoder *decoder)
 		case INTEL_PT_BIP:
 		case INTEL_PT_BEP:
 		case INTEL_PT_BEP_IP:
+		case INTEL_PT_CFE:
+		case INTEL_PT_CFE_IP:
+		case INTEL_PT_EVD:
 			intel_pt_log("ERROR: Missing TIP after FUP\n");
 			decoder->pkt_state = INTEL_PT_STATE_ERR3;
 			decoder->pkt_step = 0;
@@ -2134,6 +2143,9 @@ static int intel_pt_vm_psb_lookahead_cb(struct intel_pt_pkt_info *pkt_info)
 	case INTEL_PT_TIP:
 	case INTEL_PT_PSB:
 	case INTEL_PT_TRACESTOP:
+	case INTEL_PT_CFE:
+	case INTEL_PT_CFE_IP:
+	case INTEL_PT_EVD:
 	default:
 		return 1;
 	}
@@ -2653,6 +2665,9 @@ static int intel_pt_vm_time_correlation(struct intel_pt_decoder *decoder)
 			decoder->blk_type = 0;
 			break;
 
+		case INTEL_PT_CFE:
+		case INTEL_PT_CFE_IP:
+		case INTEL_PT_EVD:
 		case INTEL_PT_MODE_EXEC:
 		case INTEL_PT_MODE_TSX:
 		case INTEL_PT_MNT:
@@ -2789,6 +2804,9 @@ static int intel_pt_hop_trace(struct intel_pt_decoder *decoder, bool *no_tip, in
 	case INTEL_PT_BIP:
 	case INTEL_PT_BEP:
 	case INTEL_PT_BEP_IP:
+	case INTEL_PT_CFE:
+	case INTEL_PT_CFE_IP:
+	case INTEL_PT_EVD:
 	default:
 		return HOP_PROCESS;
 	}
@@ -2857,6 +2875,9 @@ static int intel_pt_psb_lookahead_cb(struct intel_pt_pkt_info *pkt_info)
 	case INTEL_PT_BIP:
 	case INTEL_PT_BEP:
 	case INTEL_PT_BEP_IP:
+	case INTEL_PT_CFE:
+	case INTEL_PT_CFE_IP:
+	case INTEL_PT_EVD:
 		if (data->after_psbend) {
 			data->after_psbend -= 1;
 			if (!data->after_psbend)
@@ -3223,6 +3244,11 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)
 			}
 			goto next;
 
+		case INTEL_PT_CFE:
+		case INTEL_PT_CFE_IP:
+		case INTEL_PT_EVD:
+			break;
+
 		default:
 			return intel_pt_bug(decoder);
 		}
@@ -3265,6 +3291,9 @@ static int intel_pt_walk_psb(struct intel_pt_decoder *decoder)
 		case INTEL_PT_BIP:
 		case INTEL_PT_BEP:
 		case INTEL_PT_BEP_IP:
+		case INTEL_PT_CFE:
+		case INTEL_PT_CFE_IP:
+		case INTEL_PT_EVD:
 			intel_pt_log("ERROR: Unexpected packet\n");
 			err = -ENOENT;
 			goto out;
@@ -3476,6 +3505,9 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)
 		case INTEL_PT_BIP:
 		case INTEL_PT_BEP:
 		case INTEL_PT_BEP_IP:
+		case INTEL_PT_CFE:
+		case INTEL_PT_CFE_IP:
+		case INTEL_PT_EVD:
 		default:
 			break;
 		}
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c +40 -0
index fada96746705..885174964c27 100644
@@ -64,6 +64,9 @@ static const char * const packet_name[] = {
 	[INTEL_PT_BIP]		= "BIP",
 	[INTEL_PT_BEP]		= "BEP",
 	[INTEL_PT_BEP_IP]	= "BEP",
+	[INTEL_PT_CFE]		= "CFE",
+	[INTEL_PT_CFE_IP]	= "CFE",
+	[INTEL_PT_EVD]		= "EVD",
 };
 
 const char *intel_pt_pkt_name(enum intel_pt_pkt_type type)
@@ -328,6 +331,29 @@ static int intel_pt_get_bep_ip(size_t len, struct intel_pt_pkt *packet)
 	return 2;
 }
 
+static int intel_pt_get_cfe(const unsigned char *buf, size_t len,
+			    struct intel_pt_pkt *packet)
+{
+	if (len < 4)
+		return INTEL_PT_NEED_MORE_BYTES;
+	packet->type = buf[2] & 0x80 ? INTEL_PT_CFE_IP : INTEL_PT_CFE;
+	packet->count = buf[2] & 0x1f;
+	packet->payload = buf[3];
+	return 4;
+}
+
+static int intel_pt_get_evd(const unsigned char *buf, size_t len,
+			    struct intel_pt_pkt *packet)
+{
+	if (len < 11)
+		return INTEL_PT_NEED_MORE_BYTES;
+	packet->type = INTEL_PT_EVD;
+	packet->count = buf[2] & 0x3f;
+	packet->payload = buf[3];
+	memcpy_le64(&packet->payload, buf + 3, 8);
+	return 11;
+}
+
 static int intel_pt_get_ext(const unsigned char *buf, size_t len,
 			    struct intel_pt_pkt *packet)
 {
@@ -374,6 +400,10 @@ static int intel_pt_get_ext(const unsigned char *buf, size_t len,
 		return intel_pt_get_bep(len, packet);
 	case 0xb3: /* BEP with IP */
 		return intel_pt_get_bep_ip(len, packet);
+	case 0x13: /* CFE */
+		return intel_pt_get_cfe(buf, len, packet);
+	case 0x53: /* EVD */
+		return intel_pt_get_evd(buf, len, packet);
 	default:
 		return INTEL_PT_BAD_PACKET;
 	}
@@ -623,6 +653,9 @@ void intel_pt_upd_pkt_ctx(const struct intel_pt_pkt *packet,
 	case INTEL_PT_MWAIT:
 	case INTEL_PT_BEP:
 	case INTEL_PT_BEP_IP:
+	case INTEL_PT_CFE:
+	case INTEL_PT_CFE_IP:
+	case INTEL_PT_EVD:
 		*ctx = INTEL_PT_NO_CTX;
 		break;
 	case INTEL_PT_BBP:
@@ -750,6 +783,13 @@ int intel_pt_pkt_desc(const struct intel_pt_pkt *packet, char *buf,
 	case INTEL_PT_BIP:
 		return snprintf(buf, buf_len, "%s ID 0x%02x Value 0x%llx",
 				name, packet->count, payload);
+	case INTEL_PT_CFE:
+	case INTEL_PT_CFE_IP:
+		return snprintf(buf, buf_len, "%s IP:%d Type 0x%02x Vector 0x%llx",
+				name, packet->type == INTEL_PT_CFE_IP, packet->count, payload);
+	case INTEL_PT_EVD:
+		return snprintf(buf, buf_len, "%s Type 0x%02x Payload 0x%llx",
+				name, packet->count, payload);
 	default:
 		break;
 	}
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.h +3 -0
index 996090cb84f6..496ba4be875c 100644
@@ -56,6 +56,9 @@ enum intel_pt_pkt_type {
 	INTEL_PT_BIP,
 	INTEL_PT_BEP,
 	INTEL_PT_BEP_IP,
+	INTEL_PT_CFE,
+	INTEL_PT_CFE_IP,
+	INTEL_PT_EVD,
 };
 
 struct intel_pt_pkt {
Signature · 1 line
2.25.1
author reviewer
#4 lore raw

PATCH 4/25 perf intel-pt: pkt-decoder: Add MODE.Exec IFLAG bit

In reply to Adrian Hunter

As of Intel SDM (https://www.intel.com/sdm) version 076, there is a new Intel PT feature called Event Trace which adds a bit to the existing MODE.Exec packet to record the interrupt flag. Amend the packet decoder and packet decoder test accordingly.

---
 tools/perf/arch/x86/tests/intel-pt-pkt-decoder-test.c   | 7 +++++--
 tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c | 4 +++-
 2 files changed, 8 insertions(+), 3 deletions(-)
tools/perf/arch/x86/tests/intel-pt-pkt-decoder-test.c +5 -2
index 0155215c1d41..42237656f453 100644
@@ -70,8 +70,11 @@ static struct test_data {
 	{8, {0x02, 0x43, 3, 4, 6, 8, 10, 12}, 0, {INTEL_PT_PIP, 0, 0xC0A08060403}, 0, 0 },
 	/* Mode Exec Packet */
 	{2, {0x99, 0x00}, 0, {INTEL_PT_MODE_EXEC, 0, 16}, 0, 0 },
-	{2, {0x99, 0x01}, 0, {INTEL_PT_MODE_EXEC, 0, 64}, 0, 0 },
-	{2, {0x99, 0x02}, 0, {INTEL_PT_MODE_EXEC, 0, 32}, 0, 0 },
+	{2, {0x99, 0x01}, 0, {INTEL_PT_MODE_EXEC, 1, 64}, 0, 0 },
+	{2, {0x99, 0x02}, 0, {INTEL_PT_MODE_EXEC, 2, 32}, 0, 0 },
+	{2, {0x99, 0x04}, 0, {INTEL_PT_MODE_EXEC, 4, 16}, 0, 0 },
+	{2, {0x99, 0x05}, 0, {INTEL_PT_MODE_EXEC, 5, 64}, 0, 0 },
+	{2, {0x99, 0x06}, 0, {INTEL_PT_MODE_EXEC, 6, 32}, 0, 0 },
 	/* Mode TSX Packet */
 	{2, {0x99, 0x20}, 0, {INTEL_PT_MODE_TSX, 0, 0}, 0, 0 },
 	{2, {0x99, 0x21}, 0, {INTEL_PT_MODE_TSX, 0, 1}, 0, 0 },
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c +3 -1
index 885174964c27..18f97f43e01a 100644
@@ -504,6 +504,7 @@ static int intel_pt_get_mode(const unsigned char *buf, size_t len,
 	switch (buf[1] >> 5) {
 	case 0:
 		packet->type = INTEL_PT_MODE_EXEC;
+		packet->count = buf[1];
 		switch (buf[1] & 3) {
 		case 0:
 			packet->payload = 16;
@@ -741,7 +742,8 @@ int intel_pt_pkt_desc(const struct intel_pt_pkt *packet, char *buf,
 		return snprintf(buf, buf_len, "%s CTC 0x%x FC 0x%x", name,
 				(unsigned)payload, packet->count);
 	case INTEL_PT_MODE_EXEC:
-		return snprintf(buf, buf_len, "%s %lld", name, payload);
+		return snprintf(buf, buf_len, "%s IF:%d %lld",
+				name, !!(packet->count & 4), payload);
 	case INTEL_PT_MODE_TSX:
 		return snprintf(buf, buf_len, "%s TXAbort:%u InTX:%u",
 				name, (unsigned)(payload >> 1) & 1,
Signature · 1 line
2.25.1
author reviewer
#6 lore raw

PATCH 6/25 perf intel-pt: decoder: Factor out clearing of FUP event variables

In reply to Adrian Hunter

Factor out clearing of FUP event variables, to avoid code duplication.

---
 .../util/intel-pt-decoder/intel-pt-decoder.c  | 24 +++++++++----------
 1 file changed, 12 insertions(+), 12 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +12 -12
index 3980ee2080ae..5792d536b458 100644
@@ -1206,6 +1206,16 @@ static int intel_pt_walk_insn(struct intel_pt_decoder *decoder,
 	return err;
 }
 
+static void intel_pt_clear_fup_event(struct intel_pt_decoder *decoder)
+{
+	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;
+	decoder->set_fup_bep = false;
+}
+
 static bool intel_pt_fup_event(struct intel_pt_decoder *decoder)
 {
 	enum intel_pt_sample_type type = decoder->state.type;
@@ -1623,12 +1633,7 @@ static int intel_pt_overflow(struct intel_pt_decoder *decoder)
 	decoder->state.from_ip = decoder->ip;
 	decoder->ip = 0;
 	decoder->pge = false;
-	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;
-	decoder->set_fup_bep = false;
+	intel_pt_clear_fup_event(decoder);
 	decoder->overflow = true;
 	return -EOVERFLOW;
 }
@@ -3518,12 +3523,7 @@ 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;
-	decoder->set_fup_bep = false;
+	intel_pt_clear_fup_event(decoder);
 	decoder->overflow = false;
 
 	if (!decoder->branch_enable) {
Signature · 1 line
2.25.1
author reviewer
#5 lore raw

PATCH 5/25 perf intel-pt: decoder: Add config bit definitions

In reply to Adrian Hunter

Tidy up config bit constants to use #define.

---
 tools/perf/util/intel-pt.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tools/perf/util/intel-pt.c +7 -2
index e8613cbda331..f3e5c2dfee25 100644
@@ -46,6 +46,10 @@
 
 #define MAX_TIMESTAMP (~0ULL)
 
+#define INTEL_PT_CFG_PASS_THRU	BIT_ULL(0)
+#define INTEL_PT_CFG_PWR_EVT_EN	BIT_ULL(4)
+#define INTEL_PT_CFG_BRANCH_EN	BIT_ULL(13)
+
 struct range {
 	u64 start;
 	u64 end;
@@ -953,7 +957,8 @@ static bool intel_pt_branch_enable(struct intel_pt *pt)
 
 	evlist__for_each_entry(pt->session->evlist, evsel) {
 		if (intel_pt_get_config(pt, &evsel->core.attr, &config) &&
-		    (config & 1) && !(config & 0x2000))
+		    (config & INTEL_PT_CFG_PASS_THRU) &&
+		    !(config & INTEL_PT_CFG_BRANCH_EN))
 			return false;
 	}
 	return true;
@@ -3429,7 +3434,7 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 		id += 1;
 	}
 
-	if (pt->synth_opts.pwr_events && (evsel->core.attr.config & 0x10)) {
+	if (pt->synth_opts.pwr_events && (evsel->core.attr.config & INTEL_PT_CFG_PWR_EVT_EN)) {
 		attr.config = PERF_SYNTH_INTEL_MWAIT;
 		err = intel_pt_synth_event(session, "mwait", &attr, id);
 		if (err)
Signature · 1 line
2.25.1
author reviewer
#9 lore raw

PATCH 9/25 perf tools: Define Intel PT CFE / EVD event

In reply to Adrian Hunter

Similar to other Intel PT synth events, define structures to hold CFE and EVD data.

---
 tools/perf/util/event.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
tools/perf/util/event.h +28 -0
index c59331eea1d9..27ea7bd93df5 100644
@@ -182,6 +182,7 @@ enum perf_synth_id {
 	PERF_SYNTH_INTEL_PWRX,
 	PERF_SYNTH_INTEL_CBR,
 	PERF_SYNTH_INTEL_PSB,
+	PERF_SYNTH_INTEL_EVT,
 };
 
 /*
@@ -280,6 +281,33 @@ struct perf_synth_intel_psb {
 	u64 offset;
 };
 
+struct perf_synth_intel_evd {
+	union {
+		struct {
+			u8	evd_type;
+			u8	reserved[7];
+		};
+		u64	et;
+	};
+	u64	payload;
+};
+
+/* Intel PT Event Trace */
+struct perf_synth_intel_evt {
+	u32 padding;
+	union {
+		struct {
+			u32	type		:  5,
+				reserved	:  2,
+				ip		:  1,
+				vector		:  8,
+				evd_cnt		: 16;
+		};
+		u32	cfe;
+	};
+	struct perf_synth_intel_evd evd[];
+};
+
 /*
  * raw_data is always 4 bytes from an 8-byte boundary, so subtract 4 to get
  * 8-byte alignment.
Signature · 1 line
2.25.1
author reviewer
#7 lore raw

PATCH 7/25 perf intel-pt: decoder: Add CFE and EVD processing

In reply to Adrian Hunter

As of Intel SDM (https://www.intel.com/sdm) version 076, there is a new Intel PT feature called Event Trace which requires 2 new packets CFE and EVD. Each Event Trace event is represented by a CFE packet that is preceded by zero or more EVD packets. It may be bound to a following FUP packet that provides the IP.

Event Trace exposes details about asynchronous events. The CFE packet contains a type field to identify one of the following:

1 INTR interrupt, fault, exception, NMI
2 IRET interrupt return
3 SMI system management interrupt
4 RSM resume from system management mode
5 SIPI startup interprocessor interrupt
6 INIT INIT signal
7 VMENTRY VM-Entry
8 VMEXIT VM-Entry
9 VMEXIT_INTR VM-Exit due to interrupt
10 SHUTDOWN Shutdown

For more details, refer to the Intel SDM, Intel Processor Trace chapter.

Add processing to the decoder for the new packets.

---
 .../util/intel-pt-decoder/intel-pt-decoder.c  | 62 +++++++++++++++++++
 .../util/intel-pt-decoder/intel-pt-decoder.h  | 17 +++++
 2 files changed, 79 insertions(+)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +62 -0
index 5792d536b458..1a39119706d6 100644
@@ -213,6 +213,8 @@ struct intel_pt_decoder {
 	bool set_fup_pwre;
 	bool set_fup_exstop;
 	bool set_fup_bep;
+	bool set_fup_cfe_ip;
+	bool set_fup_cfe;
 	bool sample_cyc;
 	unsigned int fup_tx_flags;
 	unsigned int tx_flags;
@@ -223,6 +225,7 @@ struct intel_pt_decoder {
 	uint64_t timestamp_insn_cnt;
 	uint64_t sample_insn_cnt;
 	uint64_t stuck_ip;
+	struct intel_pt_pkt fup_cfe_pkt;
 	int max_loops;
 	int no_progress;
 	int stuck_ip_prd;
@@ -231,6 +234,8 @@ struct intel_pt_decoder {
 	const unsigned char *next_buf;
 	size_t next_len;
 	unsigned char temp_buf[INTEL_PT_PKT_MAX_SZ];
+	int evd_cnt;
+	struct intel_pt_evd evd[INTEL_PT_MAX_EVDS];
 };
 
 static uint64_t intel_pt_lower_power_of_2(uint64_t x)
@@ -1214,6 +1219,9 @@ static void intel_pt_clear_fup_event(struct intel_pt_decoder *decoder)
 	decoder->set_fup_pwre = false;
 	decoder->set_fup_exstop = false;
 	decoder->set_fup_bep = false;
+	decoder->set_fup_cfe_ip = false;
+	decoder->set_fup_cfe = false;
+	decoder->evd_cnt = 0;
 }
 
 static bool intel_pt_fup_event(struct intel_pt_decoder *decoder)
@@ -1223,6 +1231,23 @@ static bool intel_pt_fup_event(struct intel_pt_decoder *decoder)
 
 	decoder->state.type &= ~INTEL_PT_BRANCH;
 
+	if (decoder->set_fup_cfe_ip || decoder->set_fup_cfe) {
+		bool ip = decoder->set_fup_cfe_ip;
+
+		decoder->set_fup_cfe_ip = false;
+		decoder->set_fup_cfe = false;
+		decoder->state.type |= INTEL_PT_EVT;
+		if (!ip && decoder->pge)
+			decoder->state.type |= INTEL_PT_BRANCH;
+		decoder->state.cfe_type = decoder->fup_cfe_pkt.count;
+		decoder->state.cfe_vector = decoder->fup_cfe_pkt.payload;
+		decoder->state.evd_cnt = decoder->evd_cnt;
+		decoder->state.evd = decoder->evd;
+		decoder->evd_cnt = 0;
+		if (ip || decoder->pge)
+			decoder->state.flags |= INTEL_PT_FUP_IP;
+		ret = true;
+	}
 	if (decoder->set_fup_tx_flags) {
 		decoder->set_fup_tx_flags = false;
 		decoder->tx_flags = decoder->fup_tx_flags;
@@ -1540,6 +1565,19 @@ static int intel_pt_mode_tsx(struct intel_pt_decoder *decoder, bool *no_tip)
 	return 0;
 }
 
+static int intel_pt_evd(struct intel_pt_decoder *decoder)
+{
+	if (decoder->evd_cnt >= INTEL_PT_MAX_EVDS) {
+		intel_pt_log_at("ERROR: Too many EVD packets", decoder->pos);
+		return -ENOSYS;
+	}
+	decoder->evd[decoder->evd_cnt++] = (struct intel_pt_evd){
+		.type = decoder->packet.count,
+		.payload = decoder->packet.payload,
+	};
+	return 0;
+}
+
 static uint64_t intel_pt_8b_tsc(uint64_t timestamp, uint64_t ref_timestamp)
 {
 	timestamp |= (ref_timestamp & (0xffULL << 56));
@@ -3250,8 +3288,32 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)
 			goto next;
 
 		case INTEL_PT_CFE:
+			decoder->fup_cfe_pkt = decoder->packet;
+			decoder->set_fup_cfe = true;
+			if (!decoder->pge) {
+				intel_pt_fup_event(decoder);
+				return 0;
+			}
+			break;
+
 		case INTEL_PT_CFE_IP:
+			decoder->fup_cfe_pkt = decoder->packet;
+			err = intel_pt_get_next_packet(decoder);
+			if (err)
+				return err;
+			if (decoder->packet.type == INTEL_PT_FUP) {
+				decoder->set_fup_cfe_ip = true;
+				no_tip = true;
+			} else {
+				intel_pt_log_at("ERROR: Missing FUP after CFE",
+						decoder->pos);
+			}
+			goto next;
+
 		case INTEL_PT_EVD:
+			err = intel_pt_evd(decoder);
+			if (err)
+				return err;
 			break;
 
 		default:
tools/perf/util/intel-pt-decoder/intel-pt-decoder.h +17 -0
index 8fd68f7a0963..59ef4b41ec67 100644
@@ -35,6 +35,7 @@ enum intel_pt_sample_type {
 	INTEL_PT_TRACE_END	= 1 << 10,
 	INTEL_PT_BLK_ITEMS	= 1 << 11,
 	INTEL_PT_PSB_EVT	= 1 << 12,
+	INTEL_PT_EVT		= 1 << 13,
 };
 
 enum intel_pt_period_type {
@@ -209,6 +210,18 @@ struct intel_pt_vmcs_info {
 	bool error_printed;
 };
 
+/*
+ * Maximum number of event trace data in one go, assuming at most 1 per type
+ * and 6-bits of type in the EVD packet.
+ */
+#define INTEL_PT_MAX_EVDS 64
+
+/* Event trace data from EVD packet */
+struct intel_pt_evd {
+	int type;
+	uint64_t payload;
+};
+
 struct intel_pt_state {
 	enum intel_pt_sample_type type;
 	bool from_nr;
@@ -234,6 +247,10 @@ struct intel_pt_state {
 	int insn_len;
 	char insn[INTEL_PT_INSN_BUF_SZ];
 	struct intel_pt_blk_items items;
+	int cfe_type;
+	int cfe_vector;
+	int evd_cnt;
+	struct intel_pt_evd *evd;
 };
 
 struct intel_pt_insn;
Signature · 1 line
2.25.1
author reviewer
#12 lore raw

PATCH 12/25 perf auxtrace: Add itrace option "I"

In reply to Adrian Hunter

Add itrace option "I" to synthesize interrupt or similar (asynchronous) events. This will be used for Intel PT Event Trace events.

---
 tools/perf/Documentation/itrace.txt | 2 ++
 tools/perf/util/auxtrace.c          | 4 ++++
 tools/perf/util/auxtrace.h          | 4 ++++
 3 files changed, 10 insertions(+)
tools/perf/Documentation/itrace.txt +2 -0
index c52755481e2f..6b189669c450 100644
@@ -7,6 +7,8 @@
 		p	synthesize power events (incl. PSB events for Intel PT)
 		o	synthesize other events recorded due to the use
 			of aux-output (refer to perf record)
+		I	synthesize interrupt or similar (asynchronous) events
+			(e.g. Intel PT Event Trace)
 		e	synthesize error events
 		d	create a debug log
 		f	synthesize first level cache events
tools/perf/util/auxtrace.c +4 -0
index 825336304a37..9e48652662d4 100644
@@ -1333,6 +1333,7 @@ void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts,
 	synth_opts->ptwrites = true;
 	synth_opts->pwr_events = true;
 	synth_opts->other_events = true;
+	synth_opts->intr_events = true;
 	synth_opts->errors = true;
 	synth_opts->flc = true;
 	synth_opts->llc = true;
@@ -1479,6 +1480,9 @@ int itrace_do_parse_synth_opts(struct itrace_synth_opts *synth_opts,
 		case 'o':
 			synth_opts->other_events = true;
 			break;
+		case 'I':
+			synth_opts->intr_events = true;
+			break;
 		case 'e':
 			synth_opts->errors = true;
 			if (get_flags(&p, &synth_opts->error_plus_flags,
tools/perf/util/auxtrace.h +4 -0
index 19910b9011f3..dc38b6f57232 100644
@@ -76,6 +76,7 @@ enum itrace_period_type {
  * @pwr_events: whether to synthesize power events
  * @other_events: whether to synthesize other events recorded due to the use of
  *                aux_output
+ * @intr_events: whether to synthesize interrupt events
  * @errors: whether to synthesize decoder error events
  * @dont_decode: whether to skip decoding entirely
  * @log: write a decoding log
@@ -120,6 +121,7 @@ struct itrace_synth_opts {
 	bool			ptwrites;
 	bool			pwr_events;
 	bool			other_events;
+	bool			intr_events;
 	bool			errors;
 	bool			dont_decode;
 	bool			log;
@@ -636,6 +638,8 @@ bool auxtrace__evsel_is_auxtrace(struct perf_session *session,
 "				p:	    		synthesize power events\n"			\
 "				o:			synthesize other events recorded due to the use\n" \
 "							of aux-output (refer to perf record)\n"	\
+"				I:			synthesize interrupt or similar (asynchronous) events\n" \
+"							(e.g. Intel PT Event Trace)\n" \
 "				e[flags]:		synthesize error events\n" \
 "							each flag must be preceded by + or -\n" \
 "							error flags are: o (overflow)\n" \
Signature · 1 line
2.25.1
author reviewer
#11 lore raw

PATCH 11/25 perf tools: Define new D and t flags

In reply to Adrian Hunter

Define 2 new flags to represent:
- when interrupts are disabled (D)
- when interrupt disabling toggles (t)

This gives 4 combinations:
no flag, interrupts enabled
t interrupts were enabled but become disabled
D interrupts are disabled
Dt interrupts were disabled but become enabled

---
 tools/perf/util/event.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/event.h +3 -1
index 9354619953e9..320cbcd5b902 100644
@@ -101,9 +101,11 @@ enum {
 	PERF_IP_FLAG_IN_TX		= 1ULL << 10,
 	PERF_IP_FLAG_VMENTRY		= 1ULL << 11,
 	PERF_IP_FLAG_VMEXIT		= 1ULL << 12,
+	PERF_IP_FLAG_INTR_DISABLE	= 1ULL << 13,
+	PERF_IP_FLAG_INTR_TOGGLE	= 1ULL << 14,
 };
 
-#define PERF_IP_FLAG_CHARS "bcrosyiABExgh"
+#define PERF_IP_FLAG_CHARS "bcrosyiABExghDt"
 
 #define PERF_BRANCH_MASK		(\
 	PERF_IP_FLAG_BRANCH		|\
Signature · 1 line
2.25.1
author reviewer
#13 lore raw

PATCH 13/25 perf intel-pt: Record Event Trace capability flag

In reply to Adrian Hunter

The change to the MODE.Exec packet means processing must distinguish between the old and new cases. Record the Event Trace capability flag to make that possible.

---
 tools/perf/arch/x86/util/intel-pt.c |  7 +++++++
 tools/perf/util/intel-pt.c          | 10 +++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)
tools/perf/arch/x86/util/intel-pt.c +7 -0
index 6df0dc00d73a..8c31578d6f4a 100644
@@ -306,6 +306,7 @@ intel_pt_info_priv_size(struct auxtrace_record *itr, struct evlist *evlist)
 
 	ptr->priv_size = (INTEL_PT_AUXTRACE_PRIV_MAX * sizeof(u64)) +
 			 intel_pt_filter_bytes(filter);
+	ptr->priv_size += sizeof(u64); /* Cap Event Trace */
 
 	return ptr->priv_size;
 }
@@ -335,6 +336,7 @@ static int intel_pt_info_fill(struct auxtrace_record *itr,
 	unsigned long max_non_turbo_ratio;
 	size_t filter_str_len;
 	const char *filter;
+	int event_trace;
 	__u64 *info;
 	int err;
 
@@ -357,6 +359,9 @@ static int intel_pt_info_fill(struct auxtrace_record *itr,
 	if (perf_pmu__scan_file(intel_pt_pmu, "max_nonturbo_ratio",
 				"%lu", &max_non_turbo_ratio) != 1)
 		max_non_turbo_ratio = 0;
+	if (perf_pmu__scan_file(intel_pt_pmu, "caps/event_trace",
+				"%d", &event_trace) != 1)
+		event_trace = 0;
 
 	filter = intel_pt_find_filter(session->evlist, ptr->intel_pt_pmu);
 	filter_str_len = filter ? strlen(filter) : 0;
@@ -407,6 +412,8 @@ static int intel_pt_info_fill(struct auxtrace_record *itr,
 		info += len >> 3;
 	}
 
+	*info++ = event_trace;
+
 	return 0;
 }
 
tools/perf/util/intel-pt.c +9 -1
index f3e5c2dfee25..23cb272e3d03 100644
@@ -75,6 +75,7 @@ struct intel_pt {
 	bool mispred_all;
 	bool use_thread_stack;
 	bool callstack;
+	bool cap_event_trace;
 	unsigned int br_stack_sz;
 	unsigned int br_stack_sz_plus;
 	int have_sched_switch;
@@ -3795,7 +3796,7 @@ int intel_pt_process_auxtrace_info(union perf_event *event,
 	}
 
 	info = &auxtrace_info->priv[INTEL_PT_FILTER_STR_LEN] + 1;
-	info_end = (void *)info + auxtrace_info->header.size;
+	info_end = (void *)auxtrace_info + auxtrace_info->header.size;
 
 	if (intel_pt_has(auxtrace_info, INTEL_PT_FILTER_STR_LEN)) {
 		size_t len;
@@ -3834,6 +3835,13 @@ int intel_pt_process_auxtrace_info(union perf_event *event,
 		intel_pt_print_info_str("Filter string", pt->filter);
 	}
 
+	if ((void *)info < info_end) {
+		pt->cap_event_trace = *info++;
+		if (dump_trace)
+			fprintf(stdout, "  Cap Event Trace     %d\n",
+				pt->cap_event_trace);
+	}
+
 	pt->timeless_decoding = intel_pt_timeless_decoding(pt);
 	if (pt->timeless_decoding && !pt->tc.time_mult)
 		pt->tc.time_mult = 1;
Signature · 1 line
2.25.1
author reviewer
#14 lore raw

PATCH 14/25 perf intel-pt: Synthesize CFE / EVD event

In reply to Adrian Hunter

Synthesize an attribute event and sample events for Intel PT Event Trace events represented by CFE and EVD packets.

---
 tools/perf/util/intel-pt.c | 62 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
tools/perf/util/intel-pt.c +62 -0
index 23cb272e3d03..1e07a3c03102 100644
@@ -49,6 +49,7 @@
 #define INTEL_PT_CFG_PASS_THRU	BIT_ULL(0)
 #define INTEL_PT_CFG_PWR_EVT_EN	BIT_ULL(4)
 #define INTEL_PT_CFG_BRANCH_EN	BIT_ULL(13)
+#define INTEL_PT_CFG_EVT_EN	BIT_ULL(31)
 
 struct range {
 	u64 start;
@@ -120,6 +121,9 @@ struct intel_pt {
 	bool sample_pebs;
 	struct evsel *pebs_evsel;
 
+	u64 evt_sample_type;
+	u64 evt_id;
+
 	u64 tsc_bit;
 	u64 mtc_bit;
 	u64 mtc_freq_bits;
@@ -2166,6 +2170,45 @@ static int intel_pt_synth_pebs_sample(struct intel_pt_queue *ptq)
 	return err;
 }
 
+static int intel_pt_synth_events_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 {
+		struct perf_synth_intel_evt cfe;
+		struct perf_synth_intel_evd evd[INTEL_PT_MAX_EVDS];
+	} raw;
+	int i;
+
+	if (intel_pt_skip_event(pt))
+		return 0;
+
+	intel_pt_prep_p_sample(pt, ptq, event, &sample);
+
+	sample.id        = ptq->pt->evt_id;
+	sample.stream_id = ptq->pt->evt_id;
+
+	raw.cfe.type     = ptq->state->cfe_type;
+	raw.cfe.reserved = 0;
+	raw.cfe.ip       = !!(ptq->state->flags & INTEL_PT_FUP_IP);
+	raw.cfe.vector   = ptq->state->cfe_vector;
+	raw.cfe.evd_cnt  = ptq->state->evd_cnt;
+
+	for (i = 0; i < ptq->state->evd_cnt; i++) {
+		raw.evd[i].et       = 0;
+		raw.evd[i].evd_type = ptq->state->evd[i].type;
+		raw.evd[i].payload  = ptq->state->evd[i].payload;
+	}
+
+	sample.raw_size = perf_synth__raw_size(raw) +
+			  ptq->state->evd_cnt * sizeof(struct perf_synth_intel_evd);
+	sample.raw_data = perf_synth__raw_data(&raw);
+
+	return intel_pt_deliver_synth_event(pt, event, &sample,
+					    pt->evt_sample_type);
+}
+
 static int intel_pt_synth_error(struct intel_pt *pt, int code, int cpu,
 				pid_t pid, pid_t tid, u64 ip, u64 timestamp)
 {
@@ -2272,6 +2315,14 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)
 			return err;
 	}
 
+	if (pt->synth_opts.intr_events) {
+		if (state->type & INTEL_PT_EVT) {
+			err = intel_pt_synth_events_sample(ptq);
+			if (err)
+				return err;
+		}
+	}
+
 	if (pt->sample_pwr_events) {
 		if (state->type & INTEL_PT_PSB_EVT) {
 			err = intel_pt_synth_psb_sample(ptq);
@@ -3469,6 +3520,17 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 		id += 1;
 	}
 
+	if (pt->synth_opts.intr_events && (evsel->core.attr.config & INTEL_PT_CFG_EVT_EN)) {
+		attr.config = PERF_SYNTH_INTEL_EVT;
+		err = intel_pt_synth_event(session, "evt", &attr, id);
+		if (err)
+			return err;
+		pt->evt_sample_type = attr.sample_type;
+		pt->evt_id = id;
+		intel_pt_set_event_name(evlist, id, "evt");
+		id += 1;
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.25.1
author reviewer
#15 lore raw

PATCH 15/25 perf intel-pt: Synthesize iflag event

In reply to Adrian Hunter

Synthesize an attribute event and sample events for changes to the interrupt flag represented by the MODE.Exec packet.

---
 tools/perf/util/intel-pt.c | 52 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
tools/perf/util/intel-pt.c +52 -0
index 1e07a3c03102..c5b860c842f0 100644
@@ -124,6 +124,9 @@ struct intel_pt {
 	u64 evt_sample_type;
 	u64 evt_id;
 
+	u64 iflag_chg_sample_type;
+	u64 iflag_chg_id;
+
 	u64 tsc_bit;
 	u64 mtc_bit;
 	u64 mtc_freq_bits;
@@ -2209,6 +2212,39 @@ static int intel_pt_synth_events_sample(struct intel_pt_queue *ptq)
 					    pt->evt_sample_type);
 }
 
+static int intel_pt_synth_iflag_chg_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_iflag_chg raw;
+
+	if (intel_pt_skip_event(pt))
+		return 0;
+
+	intel_pt_prep_p_sample(pt, ptq, event, &sample);
+
+	sample.id = ptq->pt->iflag_chg_id;
+	sample.stream_id = ptq->pt->iflag_chg_id;
+
+	raw.flags = 0;
+	raw.iflag = ptq->state->to_iflag;
+
+	if (ptq->state->type & INTEL_PT_BRANCH) {
+		raw.via_branch = 1;
+		raw.branch_ip = ptq->state->to_ip;
+	} else {
+		sample.addr = 0;
+	}
+	sample.flags = ptq->flags;
+
+	sample.raw_size = perf_synth__raw_size(raw);
+	sample.raw_data = perf_synth__raw_data(&raw);
+
+	return intel_pt_deliver_synth_event(pt, event, &sample,
+					    pt->iflag_chg_sample_type);
+}
+
 static int intel_pt_synth_error(struct intel_pt *pt, int code, int cpu,
 				pid_t pid, pid_t tid, u64 ip, u64 timestamp)
 {
@@ -2321,6 +2357,11 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)
 			if (err)
 				return err;
 		}
+		if (state->type & INTEL_PT_IFLAG_CHG) {
+			err = intel_pt_synth_iflag_chg_sample(ptq);
+			if (err)
+				return err;
+		}
 	}
 
 	if (pt->sample_pwr_events) {
@@ -3531,6 +3572,17 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 		id += 1;
 	}
 
+	if (pt->synth_opts.intr_events && pt->cap_event_trace) {
+		attr.config = PERF_SYNTH_INTEL_IFLAG_CHG;
+		err = intel_pt_synth_event(session, "iflag", &attr, id);
+		if (err)
+			return err;
+		pt->iflag_chg_sample_type = attr.sample_type;
+		pt->iflag_chg_id = id;
+		intel_pt_set_event_name(evlist, id, "iflag");
+		id += 1;
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.25.1
author reviewer
#16 lore raw

PATCH 16/25 perf intel-pt: Synthesize new D and t flags

In reply to Adrian Hunter

Update sample flags to represent the state and changes to the interrupt flag.

---
 tools/perf/util/intel-pt.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
tools/perf/util/intel-pt.c +13 -0
index c5b860c842f0..d76e4b865cb0 100644
@@ -1329,6 +1329,8 @@ static void intel_pt_set_pid_tid_cpu(struct intel_pt *pt,
 
 static void intel_pt_sample_flags(struct intel_pt_queue *ptq)
 {
+	struct intel_pt *pt = ptq->pt;
+
 	ptq->insn_len = 0;
 	if (ptq->state->flags & INTEL_PT_ABORT_TX) {
 		ptq->flags = PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TX_ABORT;
@@ -1359,6 +1361,17 @@ static void intel_pt_sample_flags(struct intel_pt_queue *ptq)
 		ptq->flags |= PERF_IP_FLAG_TRACE_BEGIN;
 	if (ptq->state->type & INTEL_PT_TRACE_END)
 		ptq->flags |= PERF_IP_FLAG_TRACE_END;
+
+	if (pt->cap_event_trace) {
+		if (ptq->state->type & INTEL_PT_IFLAG_CHG) {
+			if (!ptq->state->from_iflag)
+				ptq->flags |= PERF_IP_FLAG_INTR_DISABLE;
+			if (ptq->state->from_iflag != ptq->state->to_iflag)
+				ptq->flags |= PERF_IP_FLAG_INTR_TOGGLE;
+		} else if (!ptq->state->to_iflag) {
+			ptq->flags |= PERF_IP_FLAG_INTR_DISABLE;
+		}
+	}
 }
 
 static void intel_pt_setup_time_range(struct intel_pt *pt,
Signature · 1 line
2.25.1
author reviewer
#17 lore raw

PATCH 17/25 perf intel-pt: Force 'quick' mode when TNT is disabled

In reply to Adrian Hunter

It is not possible to walk the executable code without TNT packets, so force 'quick' mode when TNT is disabled, because 'quick' mode does not walk the code.

---
 tools/perf/util/intel-pt.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
tools/perf/util/intel-pt.c +18 -0
index d76e4b865cb0..ec43d364d0de 100644
@@ -50,6 +50,7 @@
 #define INTEL_PT_CFG_PWR_EVT_EN	BIT_ULL(4)
 #define INTEL_PT_CFG_BRANCH_EN	BIT_ULL(13)
 #define INTEL_PT_CFG_EVT_EN	BIT_ULL(31)
+#define INTEL_PT_CFG_TNT_DIS	BIT_ULL(55)
 
 struct range {
 	u64 start;
@@ -972,6 +973,19 @@ static bool intel_pt_branch_enable(struct intel_pt *pt)
 	return true;
 }
 
+static bool intel_pt_disabled_tnt(struct intel_pt *pt)
+{
+	struct evsel *evsel;
+	u64 config;
+
+	evlist__for_each_entry(pt->session->evlist, evsel) {
+		if (intel_pt_get_config(pt, &evsel->core.attr, &config) &&
+		    config & INTEL_PT_CFG_TNT_DIS)
+			return true;
+	}
+	return false;
+}
+
 static unsigned int intel_pt_mtc_period(struct intel_pt *pt)
 {
 	struct evsel *evsel;
@@ -1227,6 +1241,10 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt,
 	params.first_timestamp = pt->first_timestamp;
 	params.max_loops = pt->max_loops;
 
+	/* Cannot walk code without TNT, so force 'quick' mode */
+	if (params.branch_enable && intel_pt_disabled_tnt(pt) && !params.quick)
+		params.quick = 1;
+
 	if (pt->filts.cnt > 0)
 		params.pgd_ip = intel_pt_pgd_ip;
 
Signature · 1 line
2.25.1
author reviewer
#18 lore raw

PATCH 18/25 perf script: Display Intel PT CFE / EVD synthesized event

In reply to Adrian Hunter

Similar to other Intel PT synth events, display Event Trace events recorded by CFE / EVD packets.

---
 tools/perf/builtin-script.c | 39 +++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
tools/perf/builtin-script.c +39 -0
index abae8184e171..08e8ef5fcf83 100644
@@ -1811,6 +1811,43 @@ static int perf_sample__fprintf_synth_psb(struct perf_sample *sample, FILE *fp)
 	return len + perf_sample__fprintf_pt_spacing(len, fp);
 }
 
+/* Intel PT Event Trace */
+static int perf_sample__fprintf_synth_evt(struct perf_sample *sample, FILE *fp)
+{
+	struct perf_synth_intel_evt *data = perf_sample__synth_ptr(sample);
+	const char *cfe[32] = {NULL, "INTR", "IRET", "SMI", "RSM", "SIPI",
+			       "INIT", "VMENTRY", "VMEXIT", "VMEXIT_INTR",
+			       "SHUTDOWN"};
+	const char *evd[64] = {"PFA", "VMXQ", "VMXR"};
+	const char *s;
+	int len, i;
+
+	if (perf_sample__bad_synth_size(sample, *data))
+		return 0;
+
+	s = cfe[data->type];
+	if (s) {
+		len = fprintf(fp, " cfe: %s IP: %d vector: %u",
+			      s, data->ip, data->vector);
+	} else {
+		len = fprintf(fp, " cfe: %u IP: %d vector: %u",
+			      data->type, data->ip, data->vector);
+	}
+	for (i = 0; i < data->evd_cnt; i++) {
+		unsigned int et = data->evd[i].evd_type & 0x3f;
+
+		s = evd[et];
+		if (s) {
+			len += fprintf(fp, " %s: %#" PRIx64,
+				       s, data->evd[i].payload);
+		} else {
+			len += fprintf(fp, " EVD_%u: %#" PRIx64,
+				       et, data->evd[i].payload);
+		}
+	}
+	return len + perf_sample__fprintf_pt_spacing(len, fp);
+}
+
 static int perf_sample__fprintf_synth(struct perf_sample *sample,
 				      struct evsel *evsel, FILE *fp)
 {
@@ -1829,6 +1866,8 @@ static int perf_sample__fprintf_synth(struct perf_sample *sample,
 		return perf_sample__fprintf_synth_cbr(sample, fp);
 	case PERF_SYNTH_INTEL_PSB:
 		return perf_sample__fprintf_synth_psb(sample, fp);
+	case PERF_SYNTH_INTEL_EVT:
+		return perf_sample__fprintf_synth_evt(sample, fp);
 	default:
 		break;
 	}
Signature · 1 line
2.25.1
author reviewer
#19 lore raw

PATCH 19/25 perf script: Display Intel PT iflag synthesized event

In reply to Adrian Hunter

Similar to other Intel PT synth events, display changes to the interrupt flag represented by the MODE.Exec packet.

---
 tools/perf/builtin-script.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
tools/perf/builtin-script.c +15 -0
index 08e8ef5fcf83..517d5f7a7d39 100644
@@ -1848,6 +1848,19 @@ static int perf_sample__fprintf_synth_evt(struct perf_sample *sample, FILE *fp)
 	return len + perf_sample__fprintf_pt_spacing(len, fp);
 }
 
+static int perf_sample__fprintf_synth_iflag_chg(struct perf_sample *sample, FILE *fp)
+{
+	struct perf_synth_intel_iflag_chg *data = perf_sample__synth_ptr(sample);
+	int len;
+
+	if (perf_sample__bad_synth_size(sample, *data))
+		return 0;
+
+	len = fprintf(fp, " IFLAG: %d->%d %s branch", !data->iflag, data->iflag,
+		      data->via_branch ? "via" : "non");
+	return len + perf_sample__fprintf_pt_spacing(len, fp);
+}
+
 static int perf_sample__fprintf_synth(struct perf_sample *sample,
 				      struct evsel *evsel, FILE *fp)
 {
@@ -1868,6 +1881,8 @@ static int perf_sample__fprintf_synth(struct perf_sample *sample,
 		return perf_sample__fprintf_synth_psb(sample, fp);
 	case PERF_SYNTH_INTEL_EVT:
 		return perf_sample__fprintf_synth_evt(sample, fp);
+	case PERF_SYNTH_INTEL_IFLAG_CHG:
+		return perf_sample__fprintf_synth_iflag_chg(sample, fp);
 	default:
 		break;
 	}
Signature · 1 line
2.25.1
author reviewer
#20 lore raw

PATCH 20/25 perf script: Display new D and t flags

In reply to Adrian Hunter

Amend the display to include D and t flags in the same way as the x flag.

---
 tools/perf/Documentation/perf-script.txt | 13 ++++++++-----
 tools/perf/builtin-script.c              | 24 ++++++++++++++++--------
 2 files changed, 24 insertions(+), 13 deletions(-)
tools/perf/Documentation/perf-script.txt +8 -5
index b0070718784d..afd4718475c9 100644
@@ -195,16 +195,19 @@ OPTIONS
 	At this point usage is displayed, and perf-script exits.
 
 	The flags field is synthesized and may have a value when Instruction
-	Trace decoding. The flags are "bcrosyiABExgh" which stand for branch,
+	Trace decoding. The flags are "bcrosyiABExghDt" which stand for branch,
 	call, return, conditional, system, asynchronous, interrupt,
-	transaction abort, trace begin, trace end, in transaction, VM-Entry, and VM-Exit
-	respectively. Known combinations of flags are printed more nicely e.g.
+	transaction abort, trace begin, trace end, in transaction, VM-Entry,
+	VM-Exit, interrupt disabled and interrupt disable toggle respectively.
+	Known combinations of flags are printed more nicely e.g.
 	"call" for "bc", "return" for "br", "jcc" for "bo", "jmp" for "b",
 	"int" for "bci", "iret" for "bri", "syscall" for "bcs", "sysret" for "brs",
 	"async" for "by", "hw int" for "bcyi", "tx abrt" for "bA", "tr strt" for "bB",
 	"tr end" for "bE", "vmentry" for "bcg", "vmexit" for "bch".
-	However the "x" flag will be displayed separately in those
-	cases e.g. "jcc     (x)" for a condition branch within a transaction.
+	However the "x", "D" and "t" flags will be displayed separately in those
+	cases e.g. "jcc     (xD)" for a condition branch within a transaction
+	with interrupts disabled. Note, interrupts becoming disabled is "t",
+	whereas interrupts becoming enabled is "Dt".
 
 	The callindent field is synthesized and may have a value when
 	Instruction Trace decoding. For calls and returns, it will display the
tools/perf/builtin-script.c +16 -8
index 517d5f7a7d39..9e032343f1c6 100644
@@ -1579,26 +1579,34 @@ static const char *sample_flags_to_name(u32 flags)
 
 int perf_sample__sprintf_flags(u32 flags, char *str, size_t sz)
 {
+	u32 xf = PERF_IP_FLAG_IN_TX | PERF_IP_FLAG_INTR_DISABLE |
+		 PERF_IP_FLAG_INTR_TOGGLE;
 	const char *chars = PERF_IP_FLAG_CHARS;
 	const size_t n = strlen(PERF_IP_FLAG_CHARS);
-	bool in_tx = flags & PERF_IP_FLAG_IN_TX;
 	const char *name = NULL;
 	size_t i, pos = 0;
+	char xs[16] = {0};
 
-	name = sample_flags_to_name(flags & ~PERF_IP_FLAG_IN_TX);
+	if (flags & xf)
+		snprintf(xs, sizeof(xs), "(%s%s%s)",
+			 flags & PERF_IP_FLAG_IN_TX ? "x" : "",
+			 flags & PERF_IP_FLAG_INTR_DISABLE ? "D" : "",
+			 flags & PERF_IP_FLAG_INTR_TOGGLE ? "t" : "");
+
+	name = sample_flags_to_name(flags & ~xf);
 	if (name)
-		return snprintf(str, sz, "%-15s%4s", name, in_tx ? "(x)" : "");
+		return snprintf(str, sz, "%-15s%6s", name, xs);
 
 	if (flags & PERF_IP_FLAG_TRACE_BEGIN) {
-		name = sample_flags_to_name(flags & ~(PERF_IP_FLAG_IN_TX | PERF_IP_FLAG_TRACE_BEGIN));
+		name = sample_flags_to_name(flags & ~(xf | PERF_IP_FLAG_TRACE_BEGIN));
 		if (name)
-			return snprintf(str, sz, "tr strt %-7s%4s", name, in_tx ? "(x)" : "");
+			return snprintf(str, sz, "tr strt %-7s%6s", name, xs);
 	}
 
 	if (flags & PERF_IP_FLAG_TRACE_END) {
-		name = sample_flags_to_name(flags & ~(PERF_IP_FLAG_IN_TX | PERF_IP_FLAG_TRACE_END));
+		name = sample_flags_to_name(flags & ~(xf | PERF_IP_FLAG_TRACE_END));
 		if (name)
-			return snprintf(str, sz, "tr end  %-7s%4s", name, in_tx ? "(x)" : "");
+			return snprintf(str, sz, "tr end  %-7s%6s", name, xs);
 	}
 
 	for (i = 0; i < n; i++, flags >>= 1) {
@@ -1620,7 +1628,7 @@ static int perf_sample__fprintf_flags(u32 flags, FILE *fp)
 	char str[SAMPLE_FLAGS_BUF_SIZE];
 
 	perf_sample__sprintf_flags(flags, str, sizeof(str));
-	return fprintf(fp, "  %-19s ", str);
+	return fprintf(fp, "  %-21s ", str);
 }
 
 struct printer_data {
Signature · 1 line
2.25.1
author reviewer
#21 lore raw

PATCH 21/25 perf scripts python: intel-pt-events.py: Add Event Trace

In reply to Adrian Hunter

Add Event Trace to the intel-pt-events.py script. This shows how to unpack the raw data from the new sample events in a Python script.

---
 tools/perf/scripts/python/intel-pt-events.py | 55 ++++++++++++++++++--
 1 file changed, 50 insertions(+), 5 deletions(-)
tools/perf/scripts/python/intel-pt-events.py +50 -5
index 66452a8ec358..973bd12b7b40 100644
@@ -76,16 +76,16 @@ def trace_begin():
 	glb_args = ap.parse_args()
 	if glb_args.insn_trace:
 		print("Intel PT Instruction Trace")
-		itrace = "i0nsepwx"
+		itrace = "i0nsepwxI"
 		glb_insn = True
 	elif glb_args.src_trace:
 		print("Intel PT Source Trace")
-		itrace = "i0nsepwx"
+		itrace = "i0nsepwxI"
 		glb_insn = True
 		glb_src = True
 	else:
-		print("Intel PT Branch Trace, Power Events and PTWRITE")
-		itrace = "bepwx"
+		print("Intel PT Branch Trace, Power Events, Event Trace and PTWRITE")
+		itrace = "bepwxI"
 	global glb_disassembler
 	try:
 		glb_disassembler = LibXED()
@@ -149,6 +149,43 @@ def print_psb(raw_buf):
 	offset = data[1]
 	print("offset: %#x" % (offset), end=' ')
 
+glb_cfe = ["", "INTR", "IRET", "SMI", "RSM", "SIPI", "INIT", "VMENTRY", "VMEXIT",
+		"VMEXIT_INTR", "SHUTDOWN", "", "UINT", "UIRET"] + [""] * 18
+glb_evd = ["", "PFA", "VMXQ", "VMXR"] + [""] * 60
+
+def print_evt(raw_buf):
+	data = struct.unpack_from("<BBH", raw_buf)
+	typ = data[0] & 0x1f
+	ip_flag = (data[0] & 0x80) >> 7
+	vector = data[1]
+	evd_cnt = data[2]
+	s = glb_cfe[typ]
+	if s:
+		print(" cfe: %s IP: %u vector: %u" % (s, ip_flag, vector), end=' ')
+	else:
+		print(" cfe: %u IP: %u vector: %u" % (typ, ip_flag, vector), end=' ')
+	pos = 4
+	for i in range(evd_cnt):
+		data = struct.unpack_from("<QQ", raw_buf)
+		et = data[0] & 0x3f
+		s = glb_evd[et]
+		if s:
+			print("%s: %#x" % (s, data[1]), end=' ')
+		else:
+			print("EVD_%u: %#x" % (et, data[1]), end=' ')
+
+def print_iflag(raw_buf):
+	data = struct.unpack_from("<IQ", raw_buf)
+	iflag = data[0] & 1
+	old_iflag = iflag ^ 1
+	via_branch = data[0] & 2
+	branch_ip = data[1]
+	if via_branch:
+		s = "via"
+	else:
+		s = "non"
+	print("IFLAG: %u->%u %s branch" % (old_iflag, iflag, s), end=' ')
+
 def common_start_str(comm, sample):
 	ts = sample["time"]
 	cpu = sample["cpu"]
@@ -164,7 +201,7 @@ def print_common_start(comm, sample, name):
 	# weight      = sample["weight"]
 	# transaction = sample["transaction"]
 	# cpumode     = get_optional_zero(sample, "cpumode")
-	print(common_start_str(comm, sample) + "%7s  %19s" % (name, flags_disp), end=' ')
+	print(common_start_str(comm, sample) + "%8s  %21s" % (name, flags_disp), end=' ')
 
 def print_instructions_start(comm, sample):
 	if "x" in get_optional_null(sample, "flags"):
@@ -315,6 +352,14 @@ def do_process_event(param_dict):
 		print_common_start(comm, sample, name)
 		print_psb(raw_buf)
 		print_common_ip(param_dict, sample, symbol, dso)
+	elif name == "evt":
+		print_common_start(comm, sample, name)
+		print_evt(raw_buf)
+		print_common_ip(param_dict, sample, symbol, dso)
+	elif name == "iflag":
+		print_common_start(comm, sample, name)
+		print_iflag(raw_buf)
+		print_common_ip(param_dict, sample, symbol, dso)
 	else:
 		print_common_start(comm, sample, name)
 		print_common_ip(param_dict, sample, symbol, dso)
Signature · 1 line
2.25.1
author reviewer
#22 lore raw

PATCH 22/25 perf scripting python: Add all sample flags to DB export

In reply to Adrian Hunter

Currently, the transaction flag (x) is kept separate from branch flags. Instead of doing the same for the interrupt disabled flags (D and t), add all flags so that new flags will not need to be handled separately in the future.

---
 tools/perf/util/scripting-engines/trace-event-python.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/scripting-engines/trace-event-python.c +2 -1
index e752e1f4a5f0..413f2d19c13f 100644
@@ -1216,7 +1216,7 @@ static void python_export_sample_table(struct db_export *dbe,
 	struct tables *tables = container_of(dbe, struct tables, dbe);
 	PyObject *t;
 
-	t = tuple_new(24);
+	t = tuple_new(25);
 
 	tuple_set_d64(t, 0, es->db_id);
 	tuple_set_d64(t, 1, es->evsel->db_id);
@@ -1242,6 +1242,7 @@ static void python_export_sample_table(struct db_export *dbe,
 	tuple_set_d64(t, 21, es->call_path_id);
 	tuple_set_d64(t, 22, es->sample->insn_cnt);
 	tuple_set_d64(t, 23, es->sample->cyc_cnt);
+	tuple_set_s32(t, 24, es->sample->flags);
 
 	call_object(tables->sample_handler, t, "sample_table");
 
Signature · 1 line
2.25.1
author reviewer
#23 lore raw

PATCH 23/25 perf scripts python: export-to-sqlite.py: Export all sample flags

In reply to Adrian Hunter

Add sample flags to the SQLite database definition and export.

---
 tools/perf/scripts/python/export-to-sqlite.py | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
tools/perf/scripts/python/export-to-sqlite.py +11 -8
index 8043a7272a56..73c992feb1b9 100644
@@ -223,7 +223,8 @@ if branches:
 		'in_tx		boolean,'
 		'call_path_id	bigint,'
 		'insn_count	bigint,'
-		'cyc_count	bigint)')
+		'cyc_count	bigint,'
+		'flags		integer)')
 else:
 	do_query(query, 'CREATE TABLE samples ('
 		'id		integer		NOT NULL	PRIMARY KEY,'
@@ -249,7 +250,8 @@ else:
 		'in_tx		boolean,'
 		'call_path_id	bigint,'
 		'insn_count	bigint,'
-		'cyc_count	bigint)')
+		'cyc_count	bigint,'
+		'flags		integer)')
 
 if perf_db_export_calls or perf_db_export_callchains:
 	do_query(query, 'CREATE TABLE call_paths ('
@@ -442,7 +444,8 @@ do_query(query, 'CREATE VIEW samples_view AS '
 		'in_tx,'
 		'insn_count,'
 		'cyc_count,'
-		'CASE WHEN cyc_count=0 THEN CAST(0 AS FLOAT) ELSE ROUND(CAST(insn_count AS FLOAT) / cyc_count, 2) END AS IPC'
+		'CASE WHEN cyc_count=0 THEN CAST(0 AS FLOAT) ELSE ROUND(CAST(insn_count AS FLOAT) / cyc_count, 2) END AS IPC,'
+		'flags'
 	' FROM samples')
 
 do_query(query, 'CREATE VIEW ptwrite_view AS '
@@ -584,9 +587,9 @@ branch_type_query = QSqlQuery(db)
 branch_type_query.prepare("INSERT INTO branch_types VALUES (?, ?)")
 sample_query = QSqlQuery(db)
 if branches:
-	sample_query.prepare("INSERT INTO samples VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
+	sample_query.prepare("INSERT INTO samples VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
 else:
-	sample_query.prepare("INSERT INTO samples VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
+	sample_query.prepare("INSERT INTO samples VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
 if perf_db_export_calls or perf_db_export_callchains:
 	call_path_query = QSqlQuery(db)
 	call_path_query.prepare("INSERT INTO call_paths VALUES (?, ?, ?, ?)")
@@ -618,7 +621,7 @@ def trace_begin():
 	comm_table(0, "unknown", 0, 0, 0)
 	dso_table(0, 0, "unknown", "unknown", "")
 	symbol_table(0, 0, 0, 0, 0, "unknown")
-	sample_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
+	sample_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
 	if perf_db_export_calls or perf_db_export_callchains:
 		call_path_table(0, 0, 0, 0)
 		call_return_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
@@ -703,11 +706,11 @@ def sample_table(*x):
 	if branches:
 		for xx in x[0:15]:
 			sample_query.addBindValue(str(xx))
-		for xx in x[19:24]:
+		for xx in x[19:25]:
 			sample_query.addBindValue(str(xx))
 		do_query_(sample_query)
 	else:
-		bind_exec(sample_query, 24, x)
+		bind_exec(sample_query, 25, x)
 
 def call_path_table(*x):
 	bind_exec(call_path_query, 4, x)
Signature · 1 line
2.25.1
author reviewer
#24 lore raw

PATCH 24/25 perf scripts python: export-to-postgresql.py: Export all sample flags

In reply to Adrian Hunter

Add sample flags to the PostgreSQL database definition and export.

---
 .../perf/scripts/python/export-to-postgresql.py | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
tools/perf/scripts/python/export-to-postgresql.py +10 -7
index d187e46c2683..3a6bdcd74e60 100644
@@ -399,7 +399,8 @@ if branches:
 		'in_tx		boolean,'
 		'call_path_id	bigint,'
 		'insn_count	bigint,'
-		'cyc_count	bigint)')
+		'cyc_count	bigint,'
+		'flags		integer)')
 else:
 	do_query(query, 'CREATE TABLE samples ('
 		'id		bigint		NOT NULL,'
@@ -425,7 +426,8 @@ else:
 		'in_tx		boolean,'
 		'call_path_id	bigint,'
 		'insn_count	bigint,'
-		'cyc_count	bigint)')
+		'cyc_count	bigint,'
+		'flags		integer)')
 
 if perf_db_export_calls or perf_db_export_callchains:
 	do_query(query, 'CREATE TABLE call_paths ('
@@ -604,7 +606,8 @@ do_query(query, 'CREATE VIEW samples_view AS '
 		'in_tx,'
 		'insn_count,'
 		'cyc_count,'
-		'CASE WHEN cyc_count=0 THEN CAST(0 AS NUMERIC(20, 2)) ELSE CAST((CAST(insn_count AS FLOAT) / cyc_count) AS NUMERIC(20, 2)) END AS IPC'
+		'CASE WHEN cyc_count=0 THEN CAST(0 AS NUMERIC(20, 2)) ELSE CAST((CAST(insn_count AS FLOAT) / cyc_count) AS NUMERIC(20, 2)) END AS IPC,'
+		'flags'
 	' FROM samples')
 
 do_query(query, 'CREATE VIEW ptwrite_view AS '
@@ -804,7 +807,7 @@ def trace_begin():
 	comm_table(0, "unknown", 0, 0, 0)
 	dso_table(0, 0, "unknown", "unknown", "")
 	symbol_table(0, 0, 0, 0, 0, "unknown")
-	sample_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
+	sample_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
 	if perf_db_export_calls or perf_db_export_callchains:
 		call_path_table(0, 0, 0, 0)
 		call_return_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
@@ -1025,11 +1028,11 @@ def branch_type_table(branch_type, name, *x):
 	value = struct.pack(fmt, 2, 4, branch_type, n, name)
 	branch_type_file.write(value)
 
-def sample_table(sample_id, evsel_id, machine_id, thread_id, comm_id, dso_id, symbol_id, sym_offset, ip, time, cpu, to_dso_id, to_symbol_id, to_sym_offset, to_ip, period, weight, transaction, data_src, branch_type, in_tx, call_path_id, insn_cnt, cyc_cnt, *x):
+def sample_table(sample_id, evsel_id, machine_id, thread_id, comm_id, dso_id, symbol_id, sym_offset, ip, time, cpu, to_dso_id, to_symbol_id, to_sym_offset, to_ip, period, weight, transaction, data_src, branch_type, in_tx, call_path_id, insn_cnt, cyc_cnt, flags, *x):
 	if branches:
-		value = struct.pack("!hiqiqiqiqiqiqiqiqiqiqiiiqiqiqiqiiiBiqiqiq", 20, 8, sample_id, 8, evsel_id, 8, machine_id, 8, thread_id, 8, comm_id, 8, dso_id, 8, symbol_id, 8, sym_offset, 8, ip, 8, time, 4, cpu, 8, to_dso_id, 8, to_symbol_id, 8, to_sym_offset, 8, to_ip, 4, branch_type, 1, in_tx, 8, call_path_id, 8, insn_cnt, 8, cyc_cnt)
+		value = struct.pack("!hiqiqiqiqiqiqiqiqiqiqiiiqiqiqiqiiiBiqiqiqii", 21, 8, sample_id, 8, evsel_id, 8, machine_id, 8, thread_id, 8, comm_id, 8, dso_id, 8, symbol_id, 8, sym_offset, 8, ip, 8, time, 4, cpu, 8, to_dso_id, 8, to_symbol_id, 8, to_sym_offset, 8, to_ip, 4, branch_type, 1, in_tx, 8, call_path_id, 8, insn_cnt, 8, cyc_cnt, 4, flags)
 	else:
-		value = struct.pack("!hiqiqiqiqiqiqiqiqiqiqiiiqiqiqiqiqiqiqiqiiiBiqiqiq", 24, 8, sample_id, 8, evsel_id, 8, machine_id, 8, thread_id, 8, comm_id, 8, dso_id, 8, symbol_id, 8, sym_offset, 8, ip, 8, time, 4, cpu, 8, to_dso_id, 8, to_symbol_id, 8, to_sym_offset, 8, to_ip, 8, period, 8, weight, 8, transaction, 8, data_src, 4, branch_type, 1, in_tx, 8, call_path_id, 8, insn_cnt, 8, cyc_cnt)
+		value = struct.pack("!hiqiqiqiqiqiqiqiqiqiqiiiqiqiqiqiqiqiqiqiiiBiqiqiqii", 25, 8, sample_id, 8, evsel_id, 8, machine_id, 8, thread_id, 8, comm_id, 8, dso_id, 8, symbol_id, 8, sym_offset, 8, ip, 8, time, 4, cpu, 8, to_dso_id, 8, to_symbol_id, 8, to_sym_offset, 8, to_ip, 8, period, 8, weight, 8, transaction, 8, data_src, 4, branch_type, 1, in_tx, 8, call_path_id, 8, insn_cnt, 8, cyc_cnt, 4, flags)
 	sample_file.write(value)
 
 def call_path_table(cp_id, parent_id, symbol_id, ip, *x):
Signature · 1 line
2.25.1
author reviewer
#25 lore raw

PATCH 25/25 perf intel-pt: Add documentation for Event Trace and TNT disable

In reply to Adrian Hunter

Add documentation for Event Trace and TNT disable to the perf Intel PT man page.

---
 tools/perf/Documentation/perf-intel-pt.txt | 104 ++++++++++++++++++++-
 1 file changed, 102 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-intel-pt.txt +102 -2
index cbb920f5d056..ff58bd4c381b 100644
@@ -108,9 +108,10 @@ displayed as follows:
 
 	perf script --itrace=ibxwpe -F+flags
 
-The flags are "bcrosyiABExgh" which stand for branch, call, return, conditional,
+The flags are "bcrosyiABExghDt" which stand for branch, call, return, conditional,
 system, asynchronous, interrupt, transaction abort, trace begin, trace end,
-in transaction, VM-entry, and VM-exit respectively.
+in transaction, VM-entry, VM-exit, interrupt disabled, and interrupt disable
+toggle respectively.
 
 perf script also supports higher level ways to dump instruction traces:
 
@@ -483,6 +484,30 @@ pwr_evt		Enable power events.  The power events provide information about
 		which contains "1" if the feature is supported and
 		"0" otherwise.
 
+event		Enable Event Trace.  The events provide information about asynchronous
+		events.
+
+		Support for this feature is indicated by:
+
+			/sys/bus/event_source/devices/intel_pt/caps/event_trace
+
+		which contains "1" if the feature is supported and
+		"0" otherwise.
+
+notnt		Disable TNT packets.  Without TNT packets, it is not possible to walk
+		executable code to reconstruct control flow, however FUP, TIP, TIP.PGE
+		and TIP.PGD packets still indicate asynchronous control flow, and (if
+		return compression is disabled - see noretcomp) return statements.
+		The advantage of eliminating TNT packets is reducing the size of the
+		trace and corresponding tracing overhead.
+
+		Support for this feature is indicated by:
+
+			/sys/bus/event_source/devices/intel_pt/caps/tnt_disable
+
+		which contains "1" if the feature is supported and
+		"0" otherwise.
+
 
 AUX area sampling option
 ~~~~~~~~~~~~~~~~~~~~~~~~
@@ -876,6 +901,8 @@ The letters are:
 	p	synthesize "power" events (incl. PSB events)
 	c	synthesize branches events (calls only)
 	r	synthesize branches events (returns only)
+	o	synthesize PEBS-via-PT events
+	I	synthesize Event Trace events
 	e	synthesize tracing error events
 	d	create a debug log
 	g	synthesize a call chain (use with i or x)
@@ -1371,6 +1398,79 @@ There were none.
           :17006 17006 [001] 11500.262869216:  ffffffff8220116e error_entry+0xe ([guest.kernel.kallsyms])               pushq  %rax
 
 
+Event Trace
+-----------
+
+Event Trace records information about asynchronous events, for example interrupts,
+faults, VM exits and entries.  The information is recorded in CFE and EVD packets,
+and also the Interrupt Flag is recorded on the MODE.Exec packet.  The CFE packet
+contains a type field to identify one of the following:
+
+	 1	INTR		interrupt, fault, exception, NMI
+	 2	IRET		interrupt return
+	 3	SMI		system management interrupt
+	 4	RSM		resume from system management mode
+	 5	SIPI		startup interprocessor interrupt
+	 6	INIT		INIT signal
+	 7	VMENTRY		VM-Entry
+	 8	VMEXIT		VM-Entry
+	 9	VMEXIT_INTR	VM-Exit due to interrupt
+	10	SHUTDOWN	Shutdown
+
+For more details, refer to the Intel 64 and IA-32 Architectures Software
+Developer Manuals (version 076 or later).
+
+The capability to do Event Trace is indicated by the
+/sys/bus/event_source/devices/intel_pt/caps/event_trace file.
+
+Event trace is selected for recording using the "event" config term. e.g.
+
+	perf record -e intel_pt/event/u uname
+
+Event trace events are output using the --itrace I option. e.g.
+
+	perf script --itrace=Ie
+
+perf script displays events containing CFE type, vector and event data,
+in the form:
+
+	  evt:   hw int            (t)  cfe: INTR IP: 1 vector: 3 PFA: 0x8877665544332211
+
+The IP flag indicates if the event binds to an IP, which includes any case where
+flow control packet generation is enabled, as well as when CFE packet IP bit is
+set.
+
+perf script displays events containing changes to the Interrupt Flag in the form:
+
+	iflag:   t                      IFLAG: 1->0 via branch
+
+where "via branch" indicates a branch (interrupt or return from interrupt) and
+"non branch" indicates an instruction such as CFI, STI or POPF).
+
+In addition, the current state of the interrupt flag is indicated by the presence
+or absence of the "D" (interrupt disabled) perf script flag.  If the interrupt
+flag is changed, then the "t" flag is also included i.e.
+
+		no flag, interrupts enabled IF=1
+	t	interrupts become disabled IF=1 -> IF=0
+	D	interrupts are disabled IF=0
+	Dt	interrupts become enabled  IF=0 -> IF=1
+
+The intel-pt-events.py script illustrates how to access Event Trace information
+using a Python script.
+
+
+TNT Disable
+-----------
+
+TNT packets are disabled using the "notnt" config term. e.g.
+
+	perf record -e intel_pt/notnt/u uname
+
+In that case the --itrace q option is forced because walking executable code
+to reconstruct the control flow is not possible.
+
+
 
 SEE ALSO
 --------
Signature · 1 line
2.25.1
author reviewer
#8 lore raw

PATCH 8/25 perf intel-pt: decoder: Add MODE.Exec IFLAG processing

In reply to Adrian Hunter

As of Intel SDM (https://www.intel.com/sdm) version 076, there is a new Intel PT feature called Event Trace which adds a bit to the existing MODE.Exec packet to record the interrupt flag.

Previously, the MODE.Exec packet did not generate any events, so the new processing required is practically the same as a new packet.

---
 .../util/intel-pt-decoder/intel-pt-decoder.c  | 129 ++++++++++++++++--
 .../util/intel-pt-decoder/intel-pt-decoder.h  |   4 +
 2 files changed, 121 insertions(+), 12 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +117 -12
index 1a39119706d6..e1d8f7504cbe 100644
@@ -144,6 +144,8 @@ struct intel_pt_decoder {
 	bool vm_tm_corr_continuous;
 	bool nr;
 	bool next_nr;
+	bool iflag;
+	bool next_iflag;
 	enum intel_pt_param_flags flags;
 	uint64_t pos;
 	uint64_t last_ip;
@@ -215,6 +217,7 @@ struct intel_pt_decoder {
 	bool set_fup_bep;
 	bool set_fup_cfe_ip;
 	bool set_fup_cfe;
+	bool set_fup_mode_exec;
 	bool sample_cyc;
 	unsigned int fup_tx_flags;
 	unsigned int tx_flags;
@@ -1102,6 +1105,52 @@ static void intel_pt_sample_insn(struct intel_pt_decoder *decoder)
 	decoder->state.type |= INTEL_PT_INSTRUCTION;
 }
 
+/*
+ * Sample FUP instruction at the same time as reporting the FUP event, so the
+ * instruction sample gets the same flags as the FUP event.
+ */
+static void intel_pt_sample_fup_insn(struct intel_pt_decoder *decoder)
+{
+	struct intel_pt_insn intel_pt_insn;
+	uint64_t max_insn_cnt, insn_cnt = 0;
+	int err;
+
+	decoder->state.insn_op = INTEL_PT_OP_OTHER;
+	decoder->state.insn_len = 0;
+
+	if (!decoder->branch_enable || !decoder->pge || decoder->hop ||
+	    decoder->ip != decoder->last_ip)
+		return;
+
+	if (!decoder->mtc_insn)
+		decoder->mtc_insn = true;
+
+	max_insn_cnt = intel_pt_next_sample(decoder);
+	if (max_insn_cnt != 1)
+		return;
+
+	err = decoder->walk_insn(&intel_pt_insn, &insn_cnt, &decoder->ip,
+				 0, max_insn_cnt, decoder->data);
+	/* Ignore error, it will be reported next walk anyway */
+	if (err)
+		return;
+
+	if (intel_pt_insn.branch != INTEL_PT_BR_NO_BRANCH) {
+		intel_pt_log_at("ERROR: Unexpected branch at FUP instruction", decoder->ip);
+		return;
+	}
+
+	decoder->tot_insn_cnt += insn_cnt;
+	decoder->timestamp_insn_cnt += insn_cnt;
+	decoder->sample_insn_cnt += insn_cnt;
+	decoder->period_insn_cnt += insn_cnt;
+
+	intel_pt_sample_insn(decoder);
+
+	decoder->state.type |= INTEL_PT_INSTRUCTION;
+	decoder->ip += intel_pt_insn.length;
+}
+
 static int intel_pt_walk_insn(struct intel_pt_decoder *decoder,
 			      struct intel_pt_insn *intel_pt_insn, uint64_t ip)
 {
@@ -1211,6 +1260,39 @@ static int intel_pt_walk_insn(struct intel_pt_decoder *decoder,
 	return err;
 }
 
+static void intel_pt_mode_exec_status(struct intel_pt_decoder *decoder)
+{
+	bool iflag = decoder->packet.count & INTEL_PT_IFLAG;
+
+	decoder->exec_mode = decoder->packet.payload;
+	decoder->iflag = iflag;
+	decoder->next_iflag = iflag;
+	decoder->state.from_iflag = iflag;
+	decoder->state.to_iflag = iflag;
+}
+
+static void intel_pt_mode_exec(struct intel_pt_decoder *decoder)
+{
+	bool iflag = decoder->packet.count & INTEL_PT_IFLAG;
+
+	decoder->exec_mode = decoder->packet.payload;
+	decoder->next_iflag = iflag;
+}
+
+static void intel_pt_sample_iflag(struct intel_pt_decoder *decoder)
+{
+	decoder->state.type |= INTEL_PT_IFLAG_CHG;
+	decoder->state.from_iflag = decoder->iflag;
+	decoder->state.to_iflag = decoder->next_iflag;
+	decoder->iflag = decoder->next_iflag;
+}
+
+static void intel_pt_sample_iflag_chg(struct intel_pt_decoder *decoder)
+{
+	if (decoder->iflag != decoder->next_iflag)
+		intel_pt_sample_iflag(decoder);
+}
+
 static void intel_pt_clear_fup_event(struct intel_pt_decoder *decoder)
 {
 	decoder->set_fup_tx_flags = false;
@@ -1222,11 +1304,14 @@ static void intel_pt_clear_fup_event(struct intel_pt_decoder *decoder)
 	decoder->set_fup_cfe_ip = false;
 	decoder->set_fup_cfe = false;
 	decoder->evd_cnt = 0;
+	decoder->set_fup_mode_exec = false;
+	decoder->iflag = decoder->next_iflag;
 }
 
-static bool intel_pt_fup_event(struct intel_pt_decoder *decoder)
+static bool intel_pt_fup_event(struct intel_pt_decoder *decoder, bool no_tip)
 {
 	enum intel_pt_sample_type type = decoder->state.type;
+	bool sample_fup_insn = false;
 	bool ret = false;
 
 	decoder->state.type &= ~INTEL_PT_BRANCH;
@@ -1248,6 +1333,12 @@ static bool intel_pt_fup_event(struct intel_pt_decoder *decoder)
 			decoder->state.flags |= INTEL_PT_FUP_IP;
 		ret = true;
 	}
+	if (decoder->set_fup_mode_exec) {
+		decoder->set_fup_mode_exec = false;
+		intel_pt_sample_iflag(decoder);
+		sample_fup_insn = no_tip;
+		ret = true;
+	}
 	if (decoder->set_fup_tx_flags) {
 		decoder->set_fup_tx_flags = false;
 		decoder->tx_flags = decoder->fup_tx_flags;
@@ -1304,6 +1395,8 @@ static bool intel_pt_fup_event(struct intel_pt_decoder *decoder)
 	if (ret) {
 		decoder->state.from_ip = decoder->ip;
 		decoder->state.to_ip = 0;
+		if (sample_fup_insn)
+			intel_pt_sample_fup_insn(decoder);
 	} else {
 		decoder->state.type = type;
 	}
@@ -1336,7 +1429,7 @@ static int intel_pt_walk_fup(struct intel_pt_decoder *decoder)
 			bool no_tip = decoder->pkt_state != INTEL_PT_STATE_FUP;
 
 			decoder->pkt_state = INTEL_PT_STATE_IN_SYNC;
-			if (intel_pt_fup_event(decoder) && no_tip)
+			if (intel_pt_fup_event(decoder, no_tip) && no_tip)
 				return 0;
 			return -EAGAIN;
 		}
@@ -1388,6 +1481,7 @@ static int intel_pt_walk_tip(struct intel_pt_decoder *decoder)
 		return err;
 
 	intel_pt_update_nr(decoder);
+	intel_pt_sample_iflag_chg(decoder);
 
 	if (intel_pt_insn.branch == INTEL_PT_BR_INDIRECT) {
 		if (decoder->pkt_state == INTEL_PT_STATE_TIP_PGD) {
@@ -1502,6 +1596,7 @@ static int intel_pt_walk_tnt(struct intel_pt_decoder *decoder)
 			decoder->state.to_ip = decoder->last_ip;
 			decoder->ip = decoder->last_ip;
 			intel_pt_update_nr(decoder);
+			intel_pt_sample_iflag_chg(decoder);
 			return 0;
 		}
 
@@ -1944,7 +2039,7 @@ static int intel_pt_walk_psbend(struct intel_pt_decoder *decoder)
 			break;
 
 		case INTEL_PT_MODE_EXEC:
-			decoder->exec_mode = decoder->packet.payload;
+			intel_pt_mode_exec_status(decoder);
 			break;
 
 		case INTEL_PT_PIP:
@@ -2078,6 +2173,7 @@ static int intel_pt_walk_fup_tip(struct intel_pt_decoder *decoder)
 				decoder->state.to_ip = decoder->ip;
 			}
 			intel_pt_update_nr(decoder);
+			intel_pt_sample_iflag_chg(decoder);
 			return 0;
 
 		case INTEL_PT_PIP:
@@ -2095,7 +2191,7 @@ static int intel_pt_walk_fup_tip(struct intel_pt_decoder *decoder)
 			break;
 
 		case INTEL_PT_MODE_EXEC:
-			decoder->exec_mode = decoder->packet.payload;
+			intel_pt_mode_exec(decoder);
 			break;
 
 		case INTEL_PT_VMCS:
@@ -2777,6 +2873,7 @@ static int intel_pt_hop_trace(struct intel_pt_decoder *decoder, bool *no_tip, in
 		decoder->state.from_ip = decoder->ip;
 		decoder->state.to_ip = 0;
 		intel_pt_update_nr(decoder);
+		intel_pt_sample_iflag_chg(decoder);
 		return HOP_RETURN;
 
 	case INTEL_PT_FUP:
@@ -2791,10 +2888,10 @@ static int intel_pt_hop_trace(struct intel_pt_decoder *decoder, bool *no_tip, in
 			decoder->state.type = INTEL_PT_INSTRUCTION;
 			decoder->state.from_ip = decoder->ip;
 			decoder->state.to_ip = 0;
-			intel_pt_fup_event(decoder);
+			intel_pt_fup_event(decoder, *no_tip);
 			return HOP_RETURN;
 		}
-		intel_pt_fup_event(decoder);
+		intel_pt_fup_event(decoder, *no_tip);
 		decoder->state.type |= INTEL_PT_INSTRUCTION | INTEL_PT_BRANCH;
 		*err = intel_pt_walk_fup_tip(decoder);
 		if (!*err && decoder->state.to_ip)
@@ -3058,6 +3155,7 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)
 						decoder->pos);
 				break;
 			}
+			intel_pt_sample_iflag_chg(decoder);
 			intel_pt_set_ip(decoder);
 			decoder->state.from_ip = 0;
 			decoder->state.to_ip = decoder->ip;
@@ -3090,7 +3188,7 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)
 			intel_pt_set_last_ip(decoder);
 			if (!decoder->branch_enable || !decoder->pge) {
 				decoder->ip = decoder->last_ip;
-				if (intel_pt_fup_event(decoder))
+				if (intel_pt_fup_event(decoder, no_tip))
 					return 0;
 				no_tip = false;
 				break;
@@ -3172,8 +3270,15 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)
 			break;
 
 		case INTEL_PT_MODE_EXEC:
-			decoder->exec_mode = decoder->packet.payload;
-			break;
+			intel_pt_mode_exec(decoder);
+			err = intel_pt_get_next_packet(decoder);
+			if (err)
+				return err;
+			if (decoder->packet.type == INTEL_PT_FUP) {
+				decoder->set_fup_mode_exec = true;
+				no_tip = true;
+			}
+			goto next;
 
 		case INTEL_PT_MODE_TSX:
 			/* MODE_TSX need not be followed by FUP */
@@ -3291,7 +3396,7 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)
 			decoder->fup_cfe_pkt = decoder->packet;
 			decoder->set_fup_cfe = true;
 			if (!decoder->pge) {
-				intel_pt_fup_event(decoder);
+				intel_pt_fup_event(decoder, true);
 				return 0;
 			}
 			break;
@@ -3403,7 +3508,7 @@ static int intel_pt_walk_psb(struct intel_pt_decoder *decoder)
 			break;
 
 		case INTEL_PT_MODE_EXEC:
-			decoder->exec_mode = decoder->packet.payload;
+			intel_pt_mode_exec_status(decoder);
 			break;
 
 		case INTEL_PT_MODE_TSX:
@@ -3522,7 +3627,7 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)
 			break;
 
 		case INTEL_PT_MODE_EXEC:
-			decoder->exec_mode = decoder->packet.payload;
+			intel_pt_mode_exec_status(decoder);
 			break;
 
 		case INTEL_PT_MODE_TSX:
tools/perf/util/intel-pt-decoder/intel-pt-decoder.h +4 -0
index 59ef4b41ec67..efb2cb3ae0ca 100644
@@ -17,6 +17,7 @@
 
 #define INTEL_PT_IN_TX		(1 << 0)
 #define INTEL_PT_ABORT_TX	(1 << 1)
+#define INTEL_PT_IFLAG		(1 << 2)
 #define INTEL_PT_ASYNC		(1 << 2)
 #define INTEL_PT_FUP_IP		(1 << 3)
 #define INTEL_PT_SAMPLE_IPC	(1 << 4)
@@ -36,6 +37,7 @@ enum intel_pt_sample_type {
 	INTEL_PT_BLK_ITEMS	= 1 << 11,
 	INTEL_PT_PSB_EVT	= 1 << 12,
 	INTEL_PT_EVT		= 1 << 13,
+	INTEL_PT_IFLAG_CHG	= 1 << 14,
 };
 
 enum intel_pt_period_type {
@@ -226,6 +228,8 @@ struct intel_pt_state {
 	enum intel_pt_sample_type type;
 	bool from_nr;
 	bool to_nr;
+	bool from_iflag;
+	bool to_iflag;
 	int err;
 	uint64_t from_ip;
 	uint64_t to_ip;
Signature · 1 line
2.25.1
author reviewer
#10 lore raw

PATCH 10/25 perf tools: Define Intel PT iflag synthesized event

In reply to Adrian Hunter

Similar to other Intel PT synth events, define a structure to hold information about a change to the interrupt flag.

---
 tools/perf/util/event.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)
tools/perf/util/event.h +13 -0
index 27ea7bd93df5..9354619953e9 100644
@@ -183,6 +183,7 @@ enum perf_synth_id {
 	PERF_SYNTH_INTEL_CBR,
 	PERF_SYNTH_INTEL_PSB,
 	PERF_SYNTH_INTEL_EVT,
+	PERF_SYNTH_INTEL_IFLAG_CHG,
 };
 
 /*
@@ -308,6 +309,18 @@ struct perf_synth_intel_evt {
 	struct perf_synth_intel_evd evd[];
 };
 
+struct perf_synth_intel_iflag_chg {
+	u32 padding;
+	union {
+		struct {
+			u32	iflag		:  1,
+				via_branch	:  1;
+		};
+		u32	flags;
+	};
+	u64	branch_ip; /* If via_branch */
+};
+
 /*
  * raw_data is always 4 bytes from an 8-byte boundary, so subtract 4 to get
  * 8-byte alignment.
Signature · 1 line
2.25.1
maintainer Applied
#26 lore raw
In reply to Adrian Hunter

Em Mon, Jan 24, 2022 at 10:41:36AM +0200, Adrian Hunter escreveu:

Quoted 5 lines

Hi

Brief documentation is in the last patch with more technical details in Intel SDM (https://www.intel.com/sdm) version 076.

Quoted 9 lines

The patches touch mostly Intel PT and auxtrace code, with a few supporting changes to perf script.

I am not aware of any hardware that has the new capabilities yet.

Patches can also be found here:

https://github.com/ahunter6/linux/tree/event-trace

Thanks, applied.

- Arnaldo

Quoted 50 lines

Adrian Hunter (25):
perf intel-pt: pkt-decoder-test: Fix scope of test_data perf intel-pt: pkt-decoder: Remove misplaced linebreak perf intel-pt: pkt-decoder: Add CFE and EVD packets
perf intel-pt: pkt-decoder: Add MODE.Exec IFLAG bit
perf intel-pt: decoder: Add config bit definitions
perf intel-pt: decoder: Factor out clearing of FUP event variables perf intel-pt: decoder: Add CFE and EVD processing
perf intel-pt: decoder: Add MODE.Exec IFLAG processing perf tools: Define Intel PT CFE / EVD event
perf tools: Define Intel PT iflag synthesized event
perf tools: Define new D and t flags
perf auxtrace: Add itrace option "I"
perf intel-pt: Record Event Trace capability flag
perf intel-pt: Synthesize CFE / EVD event
perf intel-pt: Synthesize iflag event
perf intel-pt: Synthesize new D and t flags
perf intel-pt: Force 'quick' mode when TNT is disabled perf script: Display Intel PT CFE / EVD synthesized event perf script: Display Intel PT iflag synthesized event perf script: Display new D and t flags
perf scripts python: intel-pt-events.py: Add Event Trace perf scripting python: Add all sample flags to DB export perf scripts python: export-to-sqlite.py: Export all sample flags perf scripts python: export-to-postgresql.py: Export all sample flags perf intel-pt: Add documentation for Event Trace and TNT disable

 tools/perf/Documentation/itrace.txt                |   2 +
 tools/perf/Documentation/perf-intel-pt.txt         | 104 ++++++++-
 tools/perf/Documentation/perf-script.txt           |  13 +-
 .../arch/x86/tests/intel-pt-pkt-decoder-test.c     |  17 +-
 tools/perf/arch/x86/util/intel-pt.c                |   7 +
 tools/perf/builtin-script.c                        |  78 ++++++-
 tools/perf/scripts/python/export-to-postgresql.py  |  17 +-
 tools/perf/scripts/python/export-to-sqlite.py      |  19 +-
 tools/perf/scripts/python/intel-pt-events.py       |  55 ++++-
 tools/perf/util/auxtrace.c                         |   4 +
 tools/perf/util/auxtrace.h                         |   4 +
 tools/perf/util/event.h                            |  45 +++-
 .../perf/util/intel-pt-decoder/intel-pt-decoder.c  | 245 +++++++++++++++++++--
 .../perf/util/intel-pt-decoder/intel-pt-decoder.h  |  21 ++
 .../util/intel-pt-decoder/intel-pt-pkt-decoder.c   |  47 +++-
 .../util/intel-pt-decoder/intel-pt-pkt-decoder.h   |   3 +
 tools/perf/util/intel-pt.c                         | 164 +++++++++++++-
 .../util/scripting-engines/trace-event-python.c    |   3 +-
 18 files changed, 779 insertions(+), 69 deletions(-)

Regards
Adrian

Signature · 1 line
- Arnaldo
#27 lore raw

Em Tue, Feb 15, 2022 at 11:27:34AM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 9 lines

Em Mon, Jan 24, 2022 at 10:41:36AM +0200, Adrian Hunter escreveu:

Quoted 8 lines

Hi

Brief documentation is in the last patch with more technical details in Intel SDM (https://www.intel.com/sdm) version 076.

The patches touch mostly Intel PT and auxtrace code, with a few supporting changes to perf script.

Quoted 8 lines
Quoted 6 lines

I am not aware of any hardware that has the new capabilities yet.

Patches can also be found here:

https://github.com/ahunter6/linux/tree/event-trace

Thanks, applied.

So there were some problems in some compilers:

[perfbuilder@five ~]$ grep FAIL dm.log/summary

   1    51.67 almalinux:8                   : FAIL clang version 12.0.1 (Red Hat 12.0.1-4.module_el8.5.0+1025+93159d6c)
   2    28.48 alpine:3.4                    : FAIL clang version 3.8.0 (tags/RELEASE_380/final)
   3    28.89 alpine:3.5                    : FAIL clang version 3.8.1 (tags/RELEASE_381/final)
   4    30.20 alpine:3.6                    : FAIL clang version 4.0.0 (tags/RELEASE_400/final)
   5    31.39 alpine:3.7                    : FAIL gcc version 6.4.0 (Alpine 6.4.0)
   6    31.59 alpine:3.8                    : FAIL gcc version 6.4.0 (Alpine 6.4.0)
   7    32.90 alpine:3.9                    : FAIL gcc version 8.3.0 (Alpine 8.3.0)
   8    38.92 alpine:3.10                   : FAIL gcc version 8.3.0 (Alpine 8.3.0)
   9    43.02 alpine:3.11                   : FAIL gcc version 9.3.0 (Alpine 9.3.0)
  10    55.58 alpine:3.12                   : FAIL gcc version 9.3.0 (Alpine 9.3.0)
  11    59.70 alpine:3.13                   : FAIL gcc version 10.2.1 20201203 (Alpine 10.2.1_pre1)
  12    56.18 alpine:3.14                   : FAIL gcc version 10.3.1 20210424 (Alpine 10.3.1_git20210424)
  13    55.98 alpine:3.15                   : FAIL gcc version 10.3.1 20211027 (Alpine 10.3.1_git20211027)
  14    57.38 alpine:edge                   : FAIL gcc version 11.2.1 20211128 (Alpine 11.2.1_git20211128)
  15    26.99 alt:p8                        : FAIL clang version 3.8.0 (tags/RELEASE_380/final)
  16    44.66 alt:p9                        : FAIL clang version 10.0.0
  17    44.95 alt:p10                       : FAIL clang version 11.0.1
  18    44.74 alt:sisyphus                  : FAIL gcc version 11.2.1 20211202 (ALT Sisyphus 11.2.1-alt2) (GCC)
  19    27.89 amazonlinux:1                 : FAIL clang version 3.6.2 (tags/RELEASE_362/final)
  20    45.55 amazonlinux:2                 : FAIL clang version 11.1.0 (Amazon Linux 2 11.1.0-1.amzn2.0.2)
  21    35.92 archlinux:base                : FAIL clang version 13.0.0
  22    37.83 centos:8                      : FAIL clang version 11.0.1 (Red Hat 11.0.1-1.module_el8.4.0+966+2995ef20)
  23    51.37 centos:stream                 : FAIL clang version 12.0.1 (Red Hat 12.0.1-2.module_el8.6.0+937+1cafe22c)
  25    30.89 debian:9                      : FAIL clang version 3.8.1-24 (tags/RELEASE_381/final)
  26    29.59 debian:10                     : FAIL clang version 7.0.1-8+deb10u2 (tags/RELEASE_701/final)
  27    41.13 debian:11                     : FAIL gcc version 10.2.1 20210110 (Debian 10.2.1-6)
  28    47.06 debian:experimental           : FAIL gcc version 11.2.0 (Debian 11.2.0-14)
  34    29.28 fedora:23                     : FAIL clang version 3.7.0 (tags/RELEASE_370/final)
  35    38.12 fedora:24                     : FAIL clang version 3.8.1 (tags/RELEASE_381/final)
  37    33.10 fedora:25                     : FAIL clang version 3.9.1 (tags/RELEASE_391/final)
  38    40.72 fedora:26                     : FAIL clang version 4.0.1 (tags/RELEASE_401/final)
  39    35.32 fedora:27                     : FAIL clang version 5.0.2 (tags/RELEASE_502/final)
  40    38.51 fedora:28                     : FAIL clang version 6.0.1 (tags/RELEASE_601/final)
  41    40.61 fedora:29                     : FAIL clang version 7.0.1 (Fedora 7.0.1-6.fc29)
  42    41.63 fedora:30                     : FAIL clang version 8.0.0 (Fedora 8.0.0-3.fc30)
  43    35.51 fedora:31                     : FAIL clang version 9.0.1 (Fedora 9.0.1-4.fc31)
  44    45.26 fedora:32                     : FAIL clang version 10.0.1 (Fedora 10.0.1-3.fc32)
  45    44.66 fedora:33                     : FAIL clang version 11.0.0 (Fedora 11.0.0-3.fc33)
  46    46.36 fedora:34                     : FAIL clang version 12.0.1 (Fedora 12.0.1-1.fc34)
  49    49.97 fedora:35                     : FAIL clang version 13.0.0 (Fedora 13.0.0-3.fc35)
  50     6.78 fedora:rawhide                : FAIL gcc version 12.0.1 20220205 (Red Hat 12.0.1-0) (GCC)
  51    44.84 gentoo-stage3:latest          : FAIL clang version 13.0.0
  52    32.99 mageia:6                      : FAIL clang version 3.9.1 (tags/RELEASE_391/final)
  53    39.01 mageia:7                      : FAIL clang version 8.0.0 (Mageia 8.0.0-1.mga7)
  54    47.66 manjaro:base                  : FAIL clang version 13.0.0
  55     6.49 openmandriva:cooker           : FAIL gcc version 11.2.0 20210728 (OpenMandriva) (GCC)
  56    46.54 opensuse:15.0                 : FAIL clang version 5.0.1 (tags/RELEASE_501/final 312548)
  57    48.74 opensuse:15.1                 : FAIL clang version 7.0.1 (tags/RELEASE_701/final 349238)
  58    54.96 opensuse:15.2                 : FAIL clang version 9.0.1
  59    67.79 opensuse:15.3                 : FAIL clang version 11.0.1
  60    67.69 opensuse:15.4                 : FAIL clang version 11.0.1
  61    75.25 opensuse:tumbleweed           : FAIL clang version 13.0.0
  62    50.15 oraclelinux:8                 : FAIL clang version 12.0.1 (Red Hat 12.0.1-4.0.1.module+el8.5.0+20428+2b4ecd47)
  63    56.68 rockylinux:8                  : FAIL clang version 12.0.1 (Red Hat 12.0.1-4.module+el8.5.0+715+58f51d49)
  64    38.11 ubuntu:16.04                  : FAIL clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
  71    38.11 ubuntu:18.04                  : FAIL clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
  82    41.43 ubuntu:20.04                  : FAIL clang version 10.0.0-4ubuntu1
  84    30.21 ubuntu:20.10                  : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1~20.10)
  85    39.23 ubuntu:21.04                  : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1)
  86     1.07 ubuntu:21.04-x-mips64         : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1)
  87    40.23 ubuntu:21.10                  : FAIL gcc version 11.2.0 (Ubuntu 11.2.0-7ubuntu2)
  88    52.77 ubuntu:22.04                  : FAIL gcc version 11.2.0 (Ubuntu 11.2.0-14ubuntu1)

[perfbuilder@five ~]$

:-)

Sometimes its clang, sometimes its gcc, but mostly is this:

[perfbuilder@five ~]$ tail -25 dm.log/ubuntu\:22.04

  LD      /tmp/build/perf/util/arm-spe-decoder/perf-in.o
  CC      /tmp/build/perf/util/clockid.o
  CC      /tmp/build/perf/util/list_sort.o
  CC      /tmp/build/perf/util/bpf-loader.o
util/intel-pt.c:2213:31: error: field 'cfe' with variable sized type 'struct perf_synth_intel_evt' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]
                struct perf_synth_intel_evt cfe;
                                            ^
  CC      /tmp/build/perf/util/bpf_map.o
  CC      /tmp/build/perf/util/bpf-prologue.o
  CC      /tmp/build/perf/util/symbol-elf.o

1 error generated.
CC /tmp/build/perf/util/probe-file.o
make[4]: *** [/git/perf-5.17.0-rc3/tools/build/Makefile.build:97: /tmp/build/perf/util/intel-pt.o] Error 1 make[4]: *** Waiting for unfinished jobs....

  LD      /tmp/build/perf/libbpf/staticobjs/libbpf-in.o
  LINK    /tmp/build/perf/libbpf/libbpf.a
  LD      /tmp/build/perf/util/scripting-engines/perf-in.o
  LD      /tmp/build/perf/util/intel-pt-decoder/perf-in.o

make[3]: *** [/git/perf-5.17.0-rc3/tools/build/Makefile.build:139: util] Error 2 make[2]: *** [Makefile.perf:665: /tmp/build/perf/perf-in.o] Error 2 make[2]: *** Waiting for unfinished jobs....
make[1]: *** [Makefile.perf:240: sub-make] Error 2
make: *** [Makefile:70: all] Error 2
make: Leaving directory '/git/perf-5.17.0-rc3/tools/perf'
+ exit 1
[perfbuilder@five ~]$[perfbuilder@five ~]$ tail -25 dm.log/ubuntu\:22.04

  LD      /tmp/build/perf/util/arm-spe-decoder/perf-in.o
  CC      /tmp/build/perf/util/clockid.o
  CC      /tmp/build/perf/util/list_sort.o
  CC      /tmp/build/perf/util/bpf-loader.o
util/intel-pt.c:2213:31: error: field 'cfe' with variable sized type 'struct perf_synth_intel_evt' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]
                struct perf_synth_intel_evt cfe;
                                            ^
  CC      /tmp/build/perf/util/bpf_map.o
  CC      /tmp/build/perf/util/bpf-prologue.o
  CC      /tmp/build/perf/util/symbol-elf.o

1 error generated.
CC /tmp/build/perf/util/probe-file.o
make[4]: *** [/git/perf-5.17.0-rc3/tools/build/Makefile.build:97: /tmp/build/perf/util/intel-pt.o] Error 1 make[4]: *** Waiting for unfinished jobs....

  LD      /tmp/build/perf/libbpf/staticobjs/libbpf-in.o
  LINK    /tmp/build/perf/libbpf/libbpf.a
  LD      /tmp/build/perf/util/scripting-engines/perf-in.o
  LD      /tmp/build/perf/util/intel-pt-decoder/perf-in.o

make[3]: *** [/git/perf-5.17.0-rc3/tools/build/Makefile.build:139: util] Error 2 make[2]: *** [Makefile.perf:665: /tmp/build/perf/perf-in.o] Error 2 make[2]: *** Waiting for unfinished jobs....
make[1]: *** [Makefile.perf:240: sub-make] Error 2
make: *** [Makefile:70: all] Error 2
make: Leaving directory '/git/perf-5.17.0-rc3/tools/perf'
+ exit 1
[perfbuilder@five ~]$

I'm trying to fix this now, lets see...

- Arnaldo

Quoted 55 lines
Quoted 51 lines

Adrian Hunter (25):
perf intel-pt: pkt-decoder-test: Fix scope of test_data perf intel-pt: pkt-decoder: Remove misplaced linebreak perf intel-pt: pkt-decoder: Add CFE and EVD packets
perf intel-pt: pkt-decoder: Add MODE.Exec IFLAG bit
perf intel-pt: decoder: Add config bit definitions
perf intel-pt: decoder: Factor out clearing of FUP event variables perf intel-pt: decoder: Add CFE and EVD processing
perf intel-pt: decoder: Add MODE.Exec IFLAG processing perf tools: Define Intel PT CFE / EVD event
perf tools: Define Intel PT iflag synthesized event
perf tools: Define new D and t flags
perf auxtrace: Add itrace option "I"
perf intel-pt: Record Event Trace capability flag
perf intel-pt: Synthesize CFE / EVD event
perf intel-pt: Synthesize iflag event
perf intel-pt: Synthesize new D and t flags
perf intel-pt: Force 'quick' mode when TNT is disabled perf script: Display Intel PT CFE / EVD synthesized event perf script: Display Intel PT iflag synthesized event perf script: Display new D and t flags
perf scripts python: intel-pt-events.py: Add Event Trace perf scripting python: Add all sample flags to DB export perf scripts python: export-to-sqlite.py: Export all sample flags perf scripts python: export-to-postgresql.py: Export all sample flags perf intel-pt: Add documentation for Event Trace and TNT disable

 tools/perf/Documentation/itrace.txt                |   2 +
 tools/perf/Documentation/perf-intel-pt.txt         | 104 ++++++++-
 tools/perf/Documentation/perf-script.txt           |  13 +-
 .../arch/x86/tests/intel-pt-pkt-decoder-test.c     |  17 +-
 tools/perf/arch/x86/util/intel-pt.c                |   7 +
 tools/perf/builtin-script.c                        |  78 ++++++-
 tools/perf/scripts/python/export-to-postgresql.py  |  17 +-
 tools/perf/scripts/python/export-to-sqlite.py      |  19 +-
 tools/perf/scripts/python/intel-pt-events.py       |  55 ++++-
 tools/perf/util/auxtrace.c                         |   4 +
 tools/perf/util/auxtrace.h                         |   4 +
 tools/perf/util/event.h                            |  45 +++-
 .../perf/util/intel-pt-decoder/intel-pt-decoder.c  | 245 +++++++++++++++++++--
 .../perf/util/intel-pt-decoder/intel-pt-decoder.h  |  21 ++
 .../util/intel-pt-decoder/intel-pt-pkt-decoder.c   |  47 +++-
 .../util/intel-pt-decoder/intel-pt-pkt-decoder.h   |   3 +
 tools/perf/util/intel-pt.c                         | 164 +++++++++++++-
 .../util/scripting-engines/trace-event-python.c    |   3 +-
 18 files changed, 779 insertions(+), 69 deletions(-)

Regards
Adrian

Signature · 1 line
- Arnaldo
Signature · 1 line
- Arnaldo
author reviewer
#28 lore raw
Quoted 144 lines · Arnaldo Carvalho de Melo

Em Tue, Feb 15, 2022 at 11:27:34AM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 9 lines

Em Mon, Jan 24, 2022 at 10:41:36AM +0200, Adrian Hunter escreveu:

Quoted 8 lines

Hi

Brief documentation is in the last patch with more technical details in Intel SDM (https://www.intel.com/sdm) version 076.

The patches touch mostly Intel PT and auxtrace code, with a few supporting changes to perf script.

Quoted 8 lines
Quoted 6 lines

I am not aware of any hardware that has the new capabilities yet.

Patches can also be found here:

https://github.com/ahunter6/linux/tree/event-trace

Thanks, applied.

So there were some problems in some compilers:

[perfbuilder@five ~]$ grep FAIL dm.log/summary

   1    51.67 almalinux:8                   : FAIL clang version 12.0.1 (Red Hat 12.0.1-4.module_el8.5.0+1025+93159d6c)
   2    28.48 alpine:3.4                    : FAIL clang version 3.8.0 (tags/RELEASE_380/final)
   3    28.89 alpine:3.5                    : FAIL clang version 3.8.1 (tags/RELEASE_381/final)
   4    30.20 alpine:3.6                    : FAIL clang version 4.0.0 (tags/RELEASE_400/final)
   5    31.39 alpine:3.7                    : FAIL gcc version 6.4.0 (Alpine 6.4.0)
   6    31.59 alpine:3.8                    : FAIL gcc version 6.4.0 (Alpine 6.4.0)
   7    32.90 alpine:3.9                    : FAIL gcc version 8.3.0 (Alpine 8.3.0)
   8    38.92 alpine:3.10                   : FAIL gcc version 8.3.0 (Alpine 8.3.0)
   9    43.02 alpine:3.11                   : FAIL gcc version 9.3.0 (Alpine 9.3.0)
  10    55.58 alpine:3.12                   : FAIL gcc version 9.3.0 (Alpine 9.3.0)
  11    59.70 alpine:3.13                   : FAIL gcc version 10.2.1 20201203 (Alpine 10.2.1_pre1)
  12    56.18 alpine:3.14                   : FAIL gcc version 10.3.1 20210424 (Alpine 10.3.1_git20210424)
  13    55.98 alpine:3.15                   : FAIL gcc version 10.3.1 20211027 (Alpine 10.3.1_git20211027)
  14    57.38 alpine:edge                   : FAIL gcc version 11.2.1 20211128 (Alpine 11.2.1_git20211128)
  15    26.99 alt:p8                        : FAIL clang version 3.8.0 (tags/RELEASE_380/final)
  16    44.66 alt:p9                        : FAIL clang version 10.0.0
  17    44.95 alt:p10                       : FAIL clang version 11.0.1
  18    44.74 alt:sisyphus                  : FAIL gcc version 11.2.1 20211202 (ALT Sisyphus 11.2.1-alt2) (GCC)
  19    27.89 amazonlinux:1                 : FAIL clang version 3.6.2 (tags/RELEASE_362/final)
  20    45.55 amazonlinux:2                 : FAIL clang version 11.1.0 (Amazon Linux 2 11.1.0-1.amzn2.0.2)
  21    35.92 archlinux:base                : FAIL clang version 13.0.0
  22    37.83 centos:8                      : FAIL clang version 11.0.1 (Red Hat 11.0.1-1.module_el8.4.0+966+2995ef20)
  23    51.37 centos:stream                 : FAIL clang version 12.0.1 (Red Hat 12.0.1-2.module_el8.6.0+937+1cafe22c)
  25    30.89 debian:9                      : FAIL clang version 3.8.1-24 (tags/RELEASE_381/final)
  26    29.59 debian:10                     : FAIL clang version 7.0.1-8+deb10u2 (tags/RELEASE_701/final)
  27    41.13 debian:11                     : FAIL gcc version 10.2.1 20210110 (Debian 10.2.1-6)
  28    47.06 debian:experimental           : FAIL gcc version 11.2.0 (Debian 11.2.0-14)
  34    29.28 fedora:23                     : FAIL clang version 3.7.0 (tags/RELEASE_370/final)
  35    38.12 fedora:24                     : FAIL clang version 3.8.1 (tags/RELEASE_381/final)
  37    33.10 fedora:25                     : FAIL clang version 3.9.1 (tags/RELEASE_391/final)
  38    40.72 fedora:26                     : FAIL clang version 4.0.1 (tags/RELEASE_401/final)
  39    35.32 fedora:27                     : FAIL clang version 5.0.2 (tags/RELEASE_502/final)
  40    38.51 fedora:28                     : FAIL clang version 6.0.1 (tags/RELEASE_601/final)
  41    40.61 fedora:29                     : FAIL clang version 7.0.1 (Fedora 7.0.1-6.fc29)
  42    41.63 fedora:30                     : FAIL clang version 8.0.0 (Fedora 8.0.0-3.fc30)
  43    35.51 fedora:31                     : FAIL clang version 9.0.1 (Fedora 9.0.1-4.fc31)
  44    45.26 fedora:32                     : FAIL clang version 10.0.1 (Fedora 10.0.1-3.fc32)
  45    44.66 fedora:33                     : FAIL clang version 11.0.0 (Fedora 11.0.0-3.fc33)
  46    46.36 fedora:34                     : FAIL clang version 12.0.1 (Fedora 12.0.1-1.fc34)
  49    49.97 fedora:35                     : FAIL clang version 13.0.0 (Fedora 13.0.0-3.fc35)
  50     6.78 fedora:rawhide                : FAIL gcc version 12.0.1 20220205 (Red Hat 12.0.1-0) (GCC)
  51    44.84 gentoo-stage3:latest          : FAIL clang version 13.0.0
  52    32.99 mageia:6                      : FAIL clang version 3.9.1 (tags/RELEASE_391/final)
  53    39.01 mageia:7                      : FAIL clang version 8.0.0 (Mageia 8.0.0-1.mga7)
  54    47.66 manjaro:base                  : FAIL clang version 13.0.0
  55     6.49 openmandriva:cooker           : FAIL gcc version 11.2.0 20210728 (OpenMandriva) (GCC)
  56    46.54 opensuse:15.0                 : FAIL clang version 5.0.1 (tags/RELEASE_501/final 312548)
  57    48.74 opensuse:15.1                 : FAIL clang version 7.0.1 (tags/RELEASE_701/final 349238)
  58    54.96 opensuse:15.2                 : FAIL clang version 9.0.1
  59    67.79 opensuse:15.3                 : FAIL clang version 11.0.1
  60    67.69 opensuse:15.4                 : FAIL clang version 11.0.1
  61    75.25 opensuse:tumbleweed           : FAIL clang version 13.0.0
  62    50.15 oraclelinux:8                 : FAIL clang version 12.0.1 (Red Hat 12.0.1-4.0.1.module+el8.5.0+20428+2b4ecd47)
  63    56.68 rockylinux:8                  : FAIL clang version 12.0.1 (Red Hat 12.0.1-4.module+el8.5.0+715+58f51d49)
  64    38.11 ubuntu:16.04                  : FAIL clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
  71    38.11 ubuntu:18.04                  : FAIL clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
  82    41.43 ubuntu:20.04                  : FAIL clang version 10.0.0-4ubuntu1
  84    30.21 ubuntu:20.10                  : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1~20.10)
  85    39.23 ubuntu:21.04                  : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1)
  86     1.07 ubuntu:21.04-x-mips64         : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1)
  87    40.23 ubuntu:21.10                  : FAIL gcc version 11.2.0 (Ubuntu 11.2.0-7ubuntu2)
  88    52.77 ubuntu:22.04                  : FAIL gcc version 11.2.0 (Ubuntu 11.2.0-14ubuntu1)

[perfbuilder@five ~]$

:-)

Sometimes its clang, sometimes its gcc, but mostly is this:

[perfbuilder@five ~]$ tail -25 dm.log/ubuntu\:22.04

  LD      /tmp/build/perf/util/arm-spe-decoder/perf-in.o
  CC      /tmp/build/perf/util/clockid.o
  CC      /tmp/build/perf/util/list_sort.o
  CC      /tmp/build/perf/util/bpf-loader.o
util/intel-pt.c:2213:31: error: field 'cfe' with variable sized type 'struct perf_synth_intel_evt' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]
                struct perf_synth_intel_evt cfe;
                                            ^
  CC      /tmp/build/perf/util/bpf_map.o
  CC      /tmp/build/perf/util/bpf-prologue.o
  CC      /tmp/build/perf/util/symbol-elf.o

1 error generated.
CC /tmp/build/perf/util/probe-file.o
make[4]: *** [/git/perf-5.17.0-rc3/tools/build/Makefile.build:97: /tmp/build/perf/util/intel-pt.o] Error 1 make[4]: *** Waiting for unfinished jobs....

  LD      /tmp/build/perf/libbpf/staticobjs/libbpf-in.o
  LINK    /tmp/build/perf/libbpf/libbpf.a
  LD      /tmp/build/perf/util/scripting-engines/perf-in.o
  LD      /tmp/build/perf/util/intel-pt-decoder/perf-in.o

make[3]: *** [/git/perf-5.17.0-rc3/tools/build/Makefile.build:139: util] Error 2 make[2]: *** [Makefile.perf:665: /tmp/build/perf/perf-in.o] Error 2 make[2]: *** Waiting for unfinished jobs....
make[1]: *** [Makefile.perf:240: sub-make] Error 2
make: *** [Makefile:70: all] Error 2
make: Leaving directory '/git/perf-5.17.0-rc3/tools/perf'
+ exit 1
[perfbuilder@five ~]$[perfbuilder@five ~]$ tail -25 dm.log/ubuntu\:22.04

  LD      /tmp/build/perf/util/arm-spe-decoder/perf-in.o
  CC      /tmp/build/perf/util/clockid.o
  CC      /tmp/build/perf/util/list_sort.o
  CC      /tmp/build/perf/util/bpf-loader.o
util/intel-pt.c:2213:31: error: field 'cfe' with variable sized type 'struct perf_synth_intel_evt' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]
                struct perf_synth_intel_evt cfe;
                                            ^
  CC      /tmp/build/perf/util/bpf_map.o
  CC      /tmp/build/perf/util/bpf-prologue.o
  CC      /tmp/build/perf/util/symbol-elf.o

1 error generated.
CC /tmp/build/perf/util/probe-file.o
make[4]: *** [/git/perf-5.17.0-rc3/tools/build/Makefile.build:97: /tmp/build/perf/util/intel-pt.o] Error 1 make[4]: *** Waiting for unfinished jobs....

  LD      /tmp/build/perf/libbpf/staticobjs/libbpf-in.o
  LINK    /tmp/build/perf/libbpf/libbpf.a
  LD      /tmp/build/perf/util/scripting-engines/perf-in.o
  LD      /tmp/build/perf/util/intel-pt-decoder/perf-in.o

make[3]: *** [/git/perf-5.17.0-rc3/tools/build/Makefile.build:139: util] Error 2 make[2]: *** [Makefile.perf:665: /tmp/build/perf/perf-in.o] Error 2 make[2]: *** Waiting for unfinished jobs....
make[1]: *** [Makefile.perf:240: sub-make] Error 2
make: *** [Makefile:70: all] Error 2
make: Leaving directory '/git/perf-5.17.0-rc3/tools/perf'
+ exit 1
[perfbuilder@five ~]$

Quoted 1 line

I'm trying to fix this now, lets see...

What about this?

tools/perf/util/event.h +7 -1
index 320cbcd5b902..73a414643010 100644
@@ -295,6 +295,12 @@ struct perf_synth_intel_evd {
 	u64	payload;
 };
 
+/*
+ * Maximum number of event trace data in one go, assuming at most 1 per type
+ * and 6-bits of type in the EVD packet.
+ */
+#define INTEL_PT_MAX_EVDS 64
+
 /* Intel PT Event Trace */
 struct perf_synth_intel_evt {
 	u32 padding;
@@ -308,7 +314,7 @@ struct perf_synth_intel_evt {
 		};
 		u32	cfe;
 	};
-	struct perf_synth_intel_evd evd[];
+	struct perf_synth_intel_evd evd[INTEL_PT_MAX_EVDS];
 };
 
 struct perf_synth_intel_iflag_chg {
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +1 -0
index e1d8f7504cbe..44822d041199 100644
@@ -18,6 +18,7 @@
 #include <linux/zalloc.h>
 
 #include "../auxtrace.h"
+#include "../event.h"
 
 #include "intel-pt-insn-decoder.h"
 #include "intel-pt-pkt-decoder.h"
tools/perf/util/intel-pt-decoder/intel-pt-decoder.h +0 -6
index efb2cb3ae0ca..fec832a7cf75 100644
@@ -212,12 +212,6 @@ struct intel_pt_vmcs_info {
 	bool error_printed;
 };
 
-/*
- * Maximum number of event trace data in one go, assuming at most 1 per type
- * and 6-bits of type in the EVD packet.
- */
-#define INTEL_PT_MAX_EVDS 64
-
 /* Event trace data from EVD packet */
 struct intel_pt_evd {
 	int type;
tools/perf/util/intel-pt.c +6 -9
index 6fa76b584537..a00ca10f11a6 100644
@@ -2211,10 +2211,7 @@ static int intel_pt_synth_events_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 {
-		struct perf_synth_intel_evt cfe;
-		struct perf_synth_intel_evd evd[INTEL_PT_MAX_EVDS];
-	} raw;
+	struct perf_synth_intel_evt raw;
 	int i;
 
 	if (intel_pt_skip_event(pt))
@@ -2225,11 +2222,11 @@ static int intel_pt_synth_events_sample(struct intel_pt_queue *ptq)
 	sample.id        = ptq->pt->evt_id;
 	sample.stream_id = ptq->pt->evt_id;
 
-	raw.cfe.type     = ptq->state->cfe_type;
-	raw.cfe.reserved = 0;
-	raw.cfe.ip       = !!(ptq->state->flags & INTEL_PT_FUP_IP);
-	raw.cfe.vector   = ptq->state->cfe_vector;
-	raw.cfe.evd_cnt  = ptq->state->evd_cnt;
+	raw.type     = ptq->state->cfe_type;
+	raw.reserved = 0;
+	raw.ip       = !!(ptq->state->flags & INTEL_PT_FUP_IP);
+	raw.vector   = ptq->state->cfe_vector;
+	raw.evd_cnt  = ptq->state->evd_cnt;
 
 	for (i = 0; i < ptq->state->evd_cnt; i++) {
 		raw.evd[i].et       = 0;
Quoted 60 lines

- Arnaldo

Quoted 55 lines
Quoted 51 lines

Adrian Hunter (25):
perf intel-pt: pkt-decoder-test: Fix scope of test_data perf intel-pt: pkt-decoder: Remove misplaced linebreak perf intel-pt: pkt-decoder: Add CFE and EVD packets
perf intel-pt: pkt-decoder: Add MODE.Exec IFLAG bit
perf intel-pt: decoder: Add config bit definitions
perf intel-pt: decoder: Factor out clearing of FUP event variables perf intel-pt: decoder: Add CFE and EVD processing
perf intel-pt: decoder: Add MODE.Exec IFLAG processing perf tools: Define Intel PT CFE / EVD event
perf tools: Define Intel PT iflag synthesized event
perf tools: Define new D and t flags
perf auxtrace: Add itrace option "I"
perf intel-pt: Record Event Trace capability flag
perf intel-pt: Synthesize CFE / EVD event
perf intel-pt: Synthesize iflag event
perf intel-pt: Synthesize new D and t flags
perf intel-pt: Force 'quick' mode when TNT is disabled perf script: Display Intel PT CFE / EVD synthesized event perf script: Display Intel PT iflag synthesized event perf script: Display new D and t flags
perf scripts python: intel-pt-events.py: Add Event Trace perf scripting python: Add all sample flags to DB export perf scripts python: export-to-sqlite.py: Export all sample flags perf scripts python: export-to-postgresql.py: Export all sample flags perf intel-pt: Add documentation for Event Trace and TNT disable

 tools/perf/Documentation/itrace.txt                |   2 +
 tools/perf/Documentation/perf-intel-pt.txt         | 104 ++++++++-
 tools/perf/Documentation/perf-script.txt           |  13 +-
 .../arch/x86/tests/intel-pt-pkt-decoder-test.c     |  17 +-
 tools/perf/arch/x86/util/intel-pt.c                |   7 +
 tools/perf/builtin-script.c                        |  78 ++++++-
 tools/perf/scripts/python/export-to-postgresql.py  |  17 +-
 tools/perf/scripts/python/export-to-sqlite.py      |  19 +-
 tools/perf/scripts/python/intel-pt-events.py       |  55 ++++-
 tools/perf/util/auxtrace.c                         |   4 +
 tools/perf/util/auxtrace.h                         |   4 +
 tools/perf/util/event.h                            |  45 +++-
 .../perf/util/intel-pt-decoder/intel-pt-decoder.c  | 245 +++++++++++++++++++--
 .../perf/util/intel-pt-decoder/intel-pt-decoder.h  |  21 ++
 .../util/intel-pt-decoder/intel-pt-pkt-decoder.c   |  47 +++-
 .../util/intel-pt-decoder/intel-pt-pkt-decoder.h   |   3 +
 tools/perf/util/intel-pt.c                         | 164 +++++++++++++-
 .../util/scripting-engines/trace-event-python.c    |   3 +-
 18 files changed, 779 insertions(+), 69 deletions(-)

Regards
Adrian

Signature · 1 line
- Arnaldo
#29 lore raw

Em Wed, Feb 16, 2022 at 08:12:08AM +0200, Adrian Hunter escreveu:

Quoted 154 lines · Arnaldo Carvalho de Melo
Quoted 144 lines

Em Tue, Feb 15, 2022 at 11:27:34AM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 9 lines

Em Mon, Jan 24, 2022 at 10:41:36AM +0200, Adrian Hunter escreveu:

Quoted 8 lines

Hi

Brief documentation is in the last patch with more technical details in Intel SDM (https://www.intel.com/sdm) version 076.

The patches touch mostly Intel PT and auxtrace code, with a few supporting changes to perf script.

Quoted 8 lines
Quoted 6 lines

I am not aware of any hardware that has the new capabilities yet.

Patches can also be found here:

https://github.com/ahunter6/linux/tree/event-trace

Thanks, applied.

So there were some problems in some compilers:

[perfbuilder@five ~]$ grep FAIL dm.log/summary

   1    51.67 almalinux:8                   : FAIL clang version 12.0.1 (Red Hat 12.0.1-4.module_el8.5.0+1025+93159d6c)
   2    28.48 alpine:3.4                    : FAIL clang version 3.8.0 (tags/RELEASE_380/final)
   3    28.89 alpine:3.5                    : FAIL clang version 3.8.1 (tags/RELEASE_381/final)
   4    30.20 alpine:3.6                    : FAIL clang version 4.0.0 (tags/RELEASE_400/final)
   5    31.39 alpine:3.7                    : FAIL gcc version 6.4.0 (Alpine 6.4.0)
   6    31.59 alpine:3.8                    : FAIL gcc version 6.4.0 (Alpine 6.4.0)
   7    32.90 alpine:3.9                    : FAIL gcc version 8.3.0 (Alpine 8.3.0)
   8    38.92 alpine:3.10                   : FAIL gcc version 8.3.0 (Alpine 8.3.0)
   9    43.02 alpine:3.11                   : FAIL gcc version 9.3.0 (Alpine 9.3.0)
  10    55.58 alpine:3.12                   : FAIL gcc version 9.3.0 (Alpine 9.3.0)
  11    59.70 alpine:3.13                   : FAIL gcc version 10.2.1 20201203 (Alpine 10.2.1_pre1)
  12    56.18 alpine:3.14                   : FAIL gcc version 10.3.1 20210424 (Alpine 10.3.1_git20210424)
  13    55.98 alpine:3.15                   : FAIL gcc version 10.3.1 20211027 (Alpine 10.3.1_git20211027)
  14    57.38 alpine:edge                   : FAIL gcc version 11.2.1 20211128 (Alpine 11.2.1_git20211128)
  15    26.99 alt:p8                        : FAIL clang version 3.8.0 (tags/RELEASE_380/final)
  16    44.66 alt:p9                        : FAIL clang version 10.0.0
  17    44.95 alt:p10                       : FAIL clang version 11.0.1
  18    44.74 alt:sisyphus                  : FAIL gcc version 11.2.1 20211202 (ALT Sisyphus 11.2.1-alt2) (GCC)
  19    27.89 amazonlinux:1                 : FAIL clang version 3.6.2 (tags/RELEASE_362/final)
  20    45.55 amazonlinux:2                 : FAIL clang version 11.1.0 (Amazon Linux 2 11.1.0-1.amzn2.0.2)
  21    35.92 archlinux:base                : FAIL clang version 13.0.0
  22    37.83 centos:8                      : FAIL clang version 11.0.1 (Red Hat 11.0.1-1.module_el8.4.0+966+2995ef20)
  23    51.37 centos:stream                 : FAIL clang version 12.0.1 (Red Hat 12.0.1-2.module_el8.6.0+937+1cafe22c)
  25    30.89 debian:9                      : FAIL clang version 3.8.1-24 (tags/RELEASE_381/final)
  26    29.59 debian:10                     : FAIL clang version 7.0.1-8+deb10u2 (tags/RELEASE_701/final)
  27    41.13 debian:11                     : FAIL gcc version 10.2.1 20210110 (Debian 10.2.1-6)
  28    47.06 debian:experimental           : FAIL gcc version 11.2.0 (Debian 11.2.0-14)
  34    29.28 fedora:23                     : FAIL clang version 3.7.0 (tags/RELEASE_370/final)
  35    38.12 fedora:24                     : FAIL clang version 3.8.1 (tags/RELEASE_381/final)
  37    33.10 fedora:25                     : FAIL clang version 3.9.1 (tags/RELEASE_391/final)
  38    40.72 fedora:26                     : FAIL clang version 4.0.1 (tags/RELEASE_401/final)
  39    35.32 fedora:27                     : FAIL clang version 5.0.2 (tags/RELEASE_502/final)
  40    38.51 fedora:28                     : FAIL clang version 6.0.1 (tags/RELEASE_601/final)
  41    40.61 fedora:29                     : FAIL clang version 7.0.1 (Fedora 7.0.1-6.fc29)
  42    41.63 fedora:30                     : FAIL clang version 8.0.0 (Fedora 8.0.0-3.fc30)
  43    35.51 fedora:31                     : FAIL clang version 9.0.1 (Fedora 9.0.1-4.fc31)
  44    45.26 fedora:32                     : FAIL clang version 10.0.1 (Fedora 10.0.1-3.fc32)
  45    44.66 fedora:33                     : FAIL clang version 11.0.0 (Fedora 11.0.0-3.fc33)
  46    46.36 fedora:34                     : FAIL clang version 12.0.1 (Fedora 12.0.1-1.fc34)
  49    49.97 fedora:35                     : FAIL clang version 13.0.0 (Fedora 13.0.0-3.fc35)
  50     6.78 fedora:rawhide                : FAIL gcc version 12.0.1 20220205 (Red Hat 12.0.1-0) (GCC)
  51    44.84 gentoo-stage3:latest          : FAIL clang version 13.0.0
  52    32.99 mageia:6                      : FAIL clang version 3.9.1 (tags/RELEASE_391/final)
  53    39.01 mageia:7                      : FAIL clang version 8.0.0 (Mageia 8.0.0-1.mga7)
  54    47.66 manjaro:base                  : FAIL clang version 13.0.0
  55     6.49 openmandriva:cooker           : FAIL gcc version 11.2.0 20210728 (OpenMandriva) (GCC)
  56    46.54 opensuse:15.0                 : FAIL clang version 5.0.1 (tags/RELEASE_501/final 312548)
  57    48.74 opensuse:15.1                 : FAIL clang version 7.0.1 (tags/RELEASE_701/final 349238)
  58    54.96 opensuse:15.2                 : FAIL clang version 9.0.1
  59    67.79 opensuse:15.3                 : FAIL clang version 11.0.1
  60    67.69 opensuse:15.4                 : FAIL clang version 11.0.1
  61    75.25 opensuse:tumbleweed           : FAIL clang version 13.0.0
  62    50.15 oraclelinux:8                 : FAIL clang version 12.0.1 (Red Hat 12.0.1-4.0.1.module+el8.5.0+20428+2b4ecd47)
  63    56.68 rockylinux:8                  : FAIL clang version 12.0.1 (Red Hat 12.0.1-4.module+el8.5.0+715+58f51d49)
  64    38.11 ubuntu:16.04                  : FAIL clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
  71    38.11 ubuntu:18.04                  : FAIL clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
  82    41.43 ubuntu:20.04                  : FAIL clang version 10.0.0-4ubuntu1
  84    30.21 ubuntu:20.10                  : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1~20.10)
  85    39.23 ubuntu:21.04                  : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1)
  86     1.07 ubuntu:21.04-x-mips64         : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1)
  87    40.23 ubuntu:21.10                  : FAIL gcc version 11.2.0 (Ubuntu 11.2.0-7ubuntu2)
  88    52.77 ubuntu:22.04                  : FAIL gcc version 11.2.0 (Ubuntu 11.2.0-14ubuntu1)

[perfbuilder@five ~]$

:-)

Sometimes its clang, sometimes its gcc, but mostly is this:

[perfbuilder@five ~]$ tail -25 dm.log/ubuntu\:22.04

  LD      /tmp/build/perf/util/arm-spe-decoder/perf-in.o
  CC      /tmp/build/perf/util/clockid.o
  CC      /tmp/build/perf/util/list_sort.o
  CC      /tmp/build/perf/util/bpf-loader.o
util/intel-pt.c:2213:31: error: field 'cfe' with variable sized type 'struct perf_synth_intel_evt' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]
                struct perf_synth_intel_evt cfe;
                                            ^
  CC      /tmp/build/perf/util/bpf_map.o
  CC      /tmp/build/perf/util/bpf-prologue.o
  CC      /tmp/build/perf/util/symbol-elf.o

1 error generated.
CC /tmp/build/perf/util/probe-file.o
make[4]: *** [/git/perf-5.17.0-rc3/tools/build/Makefile.build:97: /tmp/build/perf/util/intel-pt.o] Error 1 make[4]: *** Waiting for unfinished jobs....

  LD      /tmp/build/perf/libbpf/staticobjs/libbpf-in.o
  LINK    /tmp/build/perf/libbpf/libbpf.a
  LD      /tmp/build/perf/util/scripting-engines/perf-in.o
  LD      /tmp/build/perf/util/intel-pt-decoder/perf-in.o

make[3]: *** [/git/perf-5.17.0-rc3/tools/build/Makefile.build:139: util] Error 2 make[2]: *** [Makefile.perf:665: /tmp/build/perf/perf-in.o] Error 2 make[2]: *** Waiting for unfinished jobs....
make[1]: *** [Makefile.perf:240: sub-make] Error 2
make: *** [Makefile:70: all] Error 2
make: Leaving directory '/git/perf-5.17.0-rc3/tools/perf'
+ exit 1
[perfbuilder@five ~]$[perfbuilder@five ~]$ tail -25 dm.log/ubuntu\:22.04

  LD      /tmp/build/perf/util/arm-spe-decoder/perf-in.o
  CC      /tmp/build/perf/util/clockid.o
  CC      /tmp/build/perf/util/list_sort.o
  CC      /tmp/build/perf/util/bpf-loader.o
util/intel-pt.c:2213:31: error: field 'cfe' with variable sized type 'struct perf_synth_intel_evt' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]
                struct perf_synth_intel_evt cfe;
                                            ^
  CC      /tmp/build/perf/util/bpf_map.o
  CC      /tmp/build/perf/util/bpf-prologue.o
  CC      /tmp/build/perf/util/symbol-elf.o

1 error generated.
CC /tmp/build/perf/util/probe-file.o
make[4]: *** [/git/perf-5.17.0-rc3/tools/build/Makefile.build:97: /tmp/build/perf/util/intel-pt.o] Error 1 make[4]: *** Waiting for unfinished jobs....

  LD      /tmp/build/perf/libbpf/staticobjs/libbpf-in.o
  LINK    /tmp/build/perf/libbpf/libbpf.a
  LD      /tmp/build/perf/util/scripting-engines/perf-in.o
  LD      /tmp/build/perf/util/intel-pt-decoder/perf-in.o

make[3]: *** [/git/perf-5.17.0-rc3/tools/build/Makefile.build:139: util] Error 2 make[2]: *** [Makefile.perf:665: /tmp/build/perf/perf-in.o] Error 2 make[2]: *** Waiting for unfinished jobs....
make[1]: *** [Makefile.perf:240: sub-make] Error 2
make: *** [Makefile:70: all] Error 2
make: Leaving directory '/git/perf-5.17.0-rc3/tools/perf'
+ exit 1
[perfbuilder@five ~]$

Quoted 1 line

I'm trying to fix this now, lets see...

What about this?

tools/perf/util/event.h +0 -0
index 320cbcd5b902..73a414643010 100644

tools/perf/util/event.h struct perf_synth_intel_evd { · line 303

Quoted 9 lines
tools/perf/util/event.h +6 -0
@@ -295,6 +295,12 @@ struct perf_synth_intel_evd {
 	u64	payload;
 };
 
+/*
+ * Maximum number of event trace data in one go, assuming at most 1 per type
+ * and 6-bits of type in the EVD packet.
+ */
+#define INTEL_PT_MAX_EVDS 64
+

I ended up making it:

  struct perf_synth_intel_evd evd[0];

And that made all compilers happy, but since there is an effort to remove this in the kernel sources, I'll apply your patch on top of everything, as I already pushed it out to my kernel.org perf/core branch.

Thanks!

- Arnaldo

Quoted 137 lines
tools/perf/util/event.h +1 -1
 /* Intel PT Event Trace */
 struct perf_synth_intel_evt {
 	u32 padding;
@@ -308,7 +314,7 @@ struct perf_synth_intel_evt {
 		};
 		u32	cfe;
 	};
-	struct perf_synth_intel_evd evd[];
+	struct perf_synth_intel_evd evd[INTEL_PT_MAX_EVDS];
 };
 
 struct perf_synth_intel_iflag_chg {
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +1 -0
index e1d8f7504cbe..44822d041199 100644
@@ -18,6 +18,7 @@
 #include <linux/zalloc.h>
 
 #include "../auxtrace.h"
+#include "../event.h"
 
 #include "intel-pt-insn-decoder.h"
 #include "intel-pt-pkt-decoder.h"
tools/perf/util/intel-pt-decoder/intel-pt-decoder.h +0 -6
index efb2cb3ae0ca..fec832a7cf75 100644
@@ -212,12 +212,6 @@ struct intel_pt_vmcs_info {
 	bool error_printed;
 };
 
-/*
- * Maximum number of event trace data in one go, assuming at most 1 per type
- * and 6-bits of type in the EVD packet.
- */
-#define INTEL_PT_MAX_EVDS 64
-
 /* Event trace data from EVD packet */
 struct intel_pt_evd {
 	int type;
tools/perf/util/intel-pt.c +6 -9
index 6fa76b584537..a00ca10f11a6 100644
@@ -2211,10 +2211,7 @@ static int intel_pt_synth_events_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 {
-		struct perf_synth_intel_evt cfe;
-		struct perf_synth_intel_evd evd[INTEL_PT_MAX_EVDS];
-	} raw;
+	struct perf_synth_intel_evt raw;
 	int i;
 
 	if (intel_pt_skip_event(pt))
@@ -2225,11 +2222,11 @@ static int intel_pt_synth_events_sample(struct intel_pt_queue *ptq)
 	sample.id        = ptq->pt->evt_id;
 	sample.stream_id = ptq->pt->evt_id;
 
-	raw.cfe.type     = ptq->state->cfe_type;
-	raw.cfe.reserved = 0;
-	raw.cfe.ip       = !!(ptq->state->flags & INTEL_PT_FUP_IP);
-	raw.cfe.vector   = ptq->state->cfe_vector;
-	raw.cfe.evd_cnt  = ptq->state->evd_cnt;
+	raw.type     = ptq->state->cfe_type;
+	raw.reserved = 0;
+	raw.ip       = !!(ptq->state->flags & INTEL_PT_FUP_IP);
+	raw.vector   = ptq->state->cfe_vector;
+	raw.evd_cnt  = ptq->state->evd_cnt;
 
 	for (i = 0; i < ptq->state->evd_cnt; i++) {
 		raw.evd[i].et       = 0;
Quoted 63 lines

- Arnaldo

Quoted 55 lines
Quoted 51 lines

Adrian Hunter (25):
perf intel-pt: pkt-decoder-test: Fix scope of test_data perf intel-pt: pkt-decoder: Remove misplaced linebreak perf intel-pt: pkt-decoder: Add CFE and EVD packets
perf intel-pt: pkt-decoder: Add MODE.Exec IFLAG bit
perf intel-pt: decoder: Add config bit definitions
perf intel-pt: decoder: Factor out clearing of FUP event variables perf intel-pt: decoder: Add CFE and EVD processing
perf intel-pt: decoder: Add MODE.Exec IFLAG processing perf tools: Define Intel PT CFE / EVD event
perf tools: Define Intel PT iflag synthesized event
perf tools: Define new D and t flags
perf auxtrace: Add itrace option "I"
perf intel-pt: Record Event Trace capability flag
perf intel-pt: Synthesize CFE / EVD event
perf intel-pt: Synthesize iflag event
perf intel-pt: Synthesize new D and t flags
perf intel-pt: Force 'quick' mode when TNT is disabled perf script: Display Intel PT CFE / EVD synthesized event perf script: Display Intel PT iflag synthesized event perf script: Display new D and t flags
perf scripts python: intel-pt-events.py: Add Event Trace perf scripting python: Add all sample flags to DB export perf scripts python: export-to-sqlite.py: Export all sample flags perf scripts python: export-to-postgresql.py: Export all sample flags perf intel-pt: Add documentation for Event Trace and TNT disable

 tools/perf/Documentation/itrace.txt                |   2 +
 tools/perf/Documentation/perf-intel-pt.txt         | 104 ++++++++-
 tools/perf/Documentation/perf-script.txt           |  13 +-
 .../arch/x86/tests/intel-pt-pkt-decoder-test.c     |  17 +-
 tools/perf/arch/x86/util/intel-pt.c                |   7 +
 tools/perf/builtin-script.c                        |  78 ++++++-
 tools/perf/scripts/python/export-to-postgresql.py  |  17 +-
 tools/perf/scripts/python/export-to-sqlite.py      |  19 +-
 tools/perf/scripts/python/intel-pt-events.py       |  55 ++++-
 tools/perf/util/auxtrace.c                         |   4 +
 tools/perf/util/auxtrace.h                         |   4 +
 tools/perf/util/event.h                            |  45 +++-
 .../perf/util/intel-pt-decoder/intel-pt-decoder.c  | 245 +++++++++++++++++++--
 .../perf/util/intel-pt-decoder/intel-pt-decoder.h  |  21 ++
 .../util/intel-pt-decoder/intel-pt-pkt-decoder.c   |  47 +++-
 .../util/intel-pt-decoder/intel-pt-pkt-decoder.h   |   3 +
 tools/perf/util/intel-pt.c                         | 164 +++++++++++++-
 .../util/scripting-engines/trace-event-python.c    |   3 +-
 18 files changed, 779 insertions(+), 69 deletions(-)

Regards
Adrian

Signature · 1 line
- Arnaldo
Signature · 1 line
- Arnaldo