Skip to contentSkip to conversation

perf intel-pt: Fixes

PATCH Applied Adrian Hunter 3 participants 10 messages May 31, 2018 – Jun 7, 2018 perf events

lore
Share & tools
lore

Adrian Hunter

author reviewer
#0 lore raw

cover perf intel-pt: Fixes

Hi

Here are some small non-urgent fixes for Intel PT.

Adrian Hunter (4):
perf intel-pt: Fix sync_switch INTEL_PT_SS_NOT_TRACING
perf intel-pt: Fix decoding to accept CBR between FUP and corresponding TIP perf intel-pt: Fix MTC timing after overflow
perf intel-pt: Fix "Unexpected indirect branch" error

 .../perf/util/intel-pt-decoder/intel-pt-decoder.c  | 23 ++++++++++++++++++----
 .../perf/util/intel-pt-decoder/intel-pt-decoder.h  |  9 +++++++++
 tools/perf/util/intel-pt.c                         |  5 +++++
 3 files changed, 33 insertions(+), 4 deletions(-)

Regards
Adrian

author reviewer
#1 lore raw

PATCH 1/4 perf intel-pt: Fix sync_switch INTEL_PT_SS_NOT_TRACING

sync_switch is a facility to synchronize decoding more closely with the point in the kernel when the context actually switched.

In one case, INTEL_PT_SS_NOT_TRACING state was not correctly transitioning to INTEL_PT_SS_TRACING state due to a missing case clause. Add it.

---
 tools/perf/util/intel-pt.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/intel-pt.c +1 -0
index 492986a25ef6..3db7f0ee52a8 100644
@@ -1521,6 +1521,7 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)
 
 	if (intel_pt_is_switch_ip(ptq, state->to_ip)) {
 		switch (ptq->switch_state) {
+		case INTEL_PT_SS_NOT_TRACING:
 		case INTEL_PT_SS_UNKNOWN:
 		case INTEL_PT_SS_EXPECTING_SWITCH_IP:
 			err = intel_pt_next_tid(pt, ptq);
Signature · 1 line
1.9.1
#2 lore raw

[tip:perf/urgent] perf intel-pt: Fix sync_switch INTEL_PT_SS_NOT_TRACING

perf intel-pt: Fix sync_switch INTEL_PT_SS_NOT_TRACING
Commit-ID:  dbcb82b93f3e8322891e47472c89e63058b81e99
Gitweb:     https://git.kernel.org/tip/dbcb82b93f3e8322891e47472c89e63058b81e99
Author:     Adrian Hunter <[email protected]>
AuthorDate: Thu, 31 May 2018 13:23:42 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 6 Jun 2018 12:52:07 -0300

perf intel-pt: Fix sync_switch INTEL_PT_SS_NOT_TRACING

sync_switch is a facility to synchronize decoding more closely with the point in the kernel when the context actually switched.

In one case, INTEL_PT_SS_NOT_TRACING state was not correctly transitioning to INTEL_PT_SS_TRACING state due to a missing case clause. Add it.

---
 tools/perf/util/intel-pt.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/intel-pt.c +1 -0
index 492986a25ef6..3db7f0ee52a8 100644
@@ -1521,6 +1521,7 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)
 
 	if (intel_pt_is_switch_ip(ptq, state->to_ip)) {
 		switch (ptq->switch_state) {
+		case INTEL_PT_SS_NOT_TRACING:
 		case INTEL_PT_SS_UNKNOWN:
 		case INTEL_PT_SS_EXPECTING_SWITCH_IP:
 			err = intel_pt_next_tid(pt, ptq);
author reviewer
#3 lore raw

PATCH 2/4 perf intel-pt: Fix decoding to accept CBR between FUP and corresponding TIP

In reply to Adrian Hunter

It is possible to have a CBR packet between a FUP packet and corresponding TIP packet. Stop treating it as an error.

---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +4 -1
index f9157aed1289..e5eb91777383 100644
@@ -1604,7 +1604,6 @@ static int intel_pt_walk_fup_tip(struct intel_pt_decoder *decoder)
 		case INTEL_PT_PSB:
 		case INTEL_PT_TSC:
 		case INTEL_PT_TMA:
-		case INTEL_PT_CBR:
 		case INTEL_PT_MODE_TSX:
 		case INTEL_PT_BAD:
 		case INTEL_PT_PSBEND:
@@ -1620,6 +1619,10 @@ static int intel_pt_walk_fup_tip(struct intel_pt_decoder *decoder)
 			decoder->pkt_step = 0;
 			return -ENOENT;
 
+		case INTEL_PT_CBR:
+			intel_pt_calc_cbr(decoder);
+			break;
+
 		case INTEL_PT_OVF:
 			return intel_pt_overflow(decoder);
 
Signature · 1 line
1.9.1
#4 lore raw

[tip:perf/urgent] perf intel-pt: Fix decoding to accept CBR between FUP and corresponding TIP

perf intel-pt: Fix decoding to accept CBR between FUP and corresponding TIP
Commit-ID:  bd2e49ec48feb1855f7624198849eea4610e2286
Gitweb:     https://git.kernel.org/tip/bd2e49ec48feb1855f7624198849eea4610e2286
Author:     Adrian Hunter <[email protected]>
AuthorDate: Thu, 31 May 2018 13:23:43 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 6 Jun 2018 12:52:07 -0300

perf intel-pt: Fix decoding to accept CBR between FUP and corresponding TIP

It is possible to have a CBR packet between a FUP packet and corresponding TIP packet. Stop treating it as an error.

---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +4 -1
index f9157aed1289..e5eb91777383 100644
@@ -1604,7 +1604,6 @@ static int intel_pt_walk_fup_tip(struct intel_pt_decoder *decoder)
 		case INTEL_PT_PSB:
 		case INTEL_PT_TSC:
 		case INTEL_PT_TMA:
-		case INTEL_PT_CBR:
 		case INTEL_PT_MODE_TSX:
 		case INTEL_PT_BAD:
 		case INTEL_PT_PSBEND:
@@ -1620,6 +1619,10 @@ static int intel_pt_walk_fup_tip(struct intel_pt_decoder *decoder)
 			decoder->pkt_step = 0;
 			return -ENOENT;
 
+		case INTEL_PT_CBR:
+			intel_pt_calc_cbr(decoder);
+			break;
+
 		case INTEL_PT_OVF:
 			return intel_pt_overflow(decoder);
 
author reviewer
#5 lore raw

PATCH 3/4 perf intel-pt: Fix MTC timing after overflow

In reply to Adrian Hunter

On some platforms, overflows will clear before MTC wraparound, and there is no following TSC/TMA packet. In that case the previous TMA is valid. Since there will be a valid TMA either way, stop setting 'have_tma' to false upon overflow.

---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 1 -
 1 file changed, 1 deletion(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +0 -1
index e5eb91777383..881d7c5e5e2a 100644
@@ -1376,7 +1376,6 @@ static int intel_pt_overflow(struct intel_pt_decoder *decoder)
 {
 	intel_pt_log("ERROR: Buffer overflow\n");
 	intel_pt_clear_tx_flags(decoder);
-	decoder->have_tma = false;
 	decoder->cbr = 0;
 	decoder->timestamp_insn_cnt = 0;
 	decoder->pkt_state = INTEL_PT_STATE_ERR_RESYNC;
Signature · 1 line
1.9.1
#6 lore raw

[tip:perf/urgent] perf intel-pt: Fix MTC timing after overflow

perf intel-pt: Fix MTC timing after overflow
Commit-ID:  dd27b87ab5fcf3ea1c060b5e3ab5d31cc78e9f4c
Gitweb:     https://git.kernel.org/tip/dd27b87ab5fcf3ea1c060b5e3ab5d31cc78e9f4c
Author:     Adrian Hunter <[email protected]>
AuthorDate: Thu, 31 May 2018 13:23:44 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 6 Jun 2018 12:52:08 -0300

perf intel-pt: Fix MTC timing after overflow

On some platforms, overflows will clear before MTC wraparound, and there is no following TSC/TMA packet. In that case the previous TMA is valid. Since there will be a valid TMA either way, stop setting 'have_tma' to false upon overflow.

---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 1 -
 1 file changed, 1 deletion(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +0 -1
index e5eb91777383..881d7c5e5e2a 100644
@@ -1376,7 +1376,6 @@ static int intel_pt_overflow(struct intel_pt_decoder *decoder)
 {
 	intel_pt_log("ERROR: Buffer overflow\n");
 	intel_pt_clear_tx_flags(decoder);
-	decoder->have_tma = false;
 	decoder->cbr = 0;
 	decoder->timestamp_insn_cnt = 0;
 	decoder->pkt_state = INTEL_PT_STATE_ERR_RESYNC;
author reviewer
#7 lore raw

PATCH 4/4 perf intel-pt: Fix "Unexpected indirect branch" error

In reply to Adrian Hunter

Some Atom CPUs can produce FUP packets that contain NLIP (next linear instruction pointer) instead of CLIP (current linear instruction pointer). That will result in "Unexpected indirect branch" errors. Fix by comparing IP to NLIP in that case.

---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 17 +++++++++++++++--
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.h |  9 +++++++++
 tools/perf/util/intel-pt.c                          |  4 ++++
 3 files changed, 28 insertions(+), 2 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +15 -2
index 881d7c5e5e2a..d404bed7003a 100644
@@ -113,6 +113,7 @@ struct intel_pt_decoder {
 	bool have_cyc;
 	bool fixup_last_mtc;
 	bool have_last_ip;
+	enum intel_pt_param_flags flags;
 	uint64_t pos;
 	uint64_t last_ip;
 	uint64_t ip;
@@ -226,6 +227,8 @@ struct intel_pt_decoder *intel_pt_decoder_new(struct intel_pt_params *params)
 	decoder->return_compression = params->return_compression;
 	decoder->branch_enable      = params->branch_enable;
 
+	decoder->flags              = params->flags;
+
 	decoder->period             = params->period;
 	decoder->period_type        = params->period_type;
 
@@ -1097,6 +1100,15 @@ static bool intel_pt_fup_event(struct intel_pt_decoder *decoder)
 	return ret;
 }
 
+static inline bool intel_pt_fup_with_nlip(struct intel_pt_decoder *decoder,
+					  struct intel_pt_insn *intel_pt_insn,
+					  uint64_t ip, int err)
+{
+	return decoder->flags & INTEL_PT_FUP_WITH_NLIP && !err &&
+	       intel_pt_insn->branch == INTEL_PT_BR_INDIRECT &&
+	       ip == decoder->ip + intel_pt_insn->length;
+}
+
 static int intel_pt_walk_fup(struct intel_pt_decoder *decoder)
 {
 	struct intel_pt_insn intel_pt_insn;
@@ -1109,10 +1121,11 @@ static int intel_pt_walk_fup(struct intel_pt_decoder *decoder)
 		err = intel_pt_walk_insn(decoder, &intel_pt_insn, ip);
 		if (err == INTEL_PT_RETURN)
 			return 0;
-		if (err == -EAGAIN) {
+		if (err == -EAGAIN ||
+		    intel_pt_fup_with_nlip(decoder, &intel_pt_insn, ip, err)) {
 			if (intel_pt_fup_event(decoder))
 				return 0;
-			return err;
+			return -EAGAIN;
 		}
 		decoder->set_fup_tx_flags = false;
 		if (err)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.h +9 -0
index fc1752d50019..51c18d67f4ca 100644
@@ -60,6 +60,14 @@ enum {
 	INTEL_PT_ERR_MAX,
 };
 
+enum intel_pt_param_flags {
+	/*
+	 * FUP packet can contain next linear instruction pointer instead of
+	 * current linear instruction pointer.
+	 */
+	INTEL_PT_FUP_WITH_NLIP	= 1 << 0,
+};
+
 struct intel_pt_state {
 	enum intel_pt_sample_type type;
 	int err;
@@ -106,6 +114,7 @@ struct intel_pt_params {
 	unsigned int mtc_period;
 	uint32_t tsc_ctc_ratio_n;
 	uint32_t tsc_ctc_ratio_d;
+	enum intel_pt_param_flags flags;
 };
 
 struct intel_pt_decoder;
tools/perf/util/intel-pt.c +4 -0
index 3db7f0ee52a8..aec68908d604 100644
@@ -749,6 +749,7 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt,
 						   unsigned int queue_nr)
 {
 	struct intel_pt_params params = { .get_trace = 0, };
+	struct perf_env *env = pt->machine->env;
 	struct intel_pt_queue *ptq;
 
 	ptq = zalloc(sizeof(struct intel_pt_queue));
@@ -830,6 +831,9 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt,
 		}
 	}
 
+	if (env->cpuid && !strncmp(env->cpuid, "GenuineIntel,6,92,", 18))
+		params.flags |= INTEL_PT_FUP_WITH_NLIP;
+
 	ptq->decoder = intel_pt_decoder_new(&params);
 	if (!ptq->decoder)
 		goto out_free;
Signature · 1 line
1.9.1
#8 lore raw

[tip:perf/urgent] perf intel-pt: Fix "Unexpected indirect branch" error

perf intel-pt: Fix "Unexpected indirect branch" error
Commit-ID:  9fb523363f6e3984457fee95bb7019395384ffa7
Gitweb:     https://git.kernel.org/tip/9fb523363f6e3984457fee95bb7019395384ffa7
Author:     Adrian Hunter <[email protected]>
AuthorDate: Thu, 31 May 2018 13:23:45 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 6 Jun 2018 12:52:08 -0300

perf intel-pt: Fix "Unexpected indirect branch" error

Some Atom CPUs can produce FUP packets that contain NLIP (next linear instruction pointer) instead of CLIP (current linear instruction pointer). That will result in "Unexpected indirect branch" errors. Fix by comparing IP to NLIP in that case.

---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 17 +++++++++++++++--
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.h |  9 +++++++++
 tools/perf/util/intel-pt.c                          |  4 ++++
 3 files changed, 28 insertions(+), 2 deletions(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +15 -2
index 881d7c5e5e2a..d404bed7003a 100644
@@ -113,6 +113,7 @@ struct intel_pt_decoder {
 	bool have_cyc;
 	bool fixup_last_mtc;
 	bool have_last_ip;
+	enum intel_pt_param_flags flags;
 	uint64_t pos;
 	uint64_t last_ip;
 	uint64_t ip;
@@ -226,6 +227,8 @@ struct intel_pt_decoder *intel_pt_decoder_new(struct intel_pt_params *params)
 	decoder->return_compression = params->return_compression;
 	decoder->branch_enable      = params->branch_enable;
 
+	decoder->flags              = params->flags;
+
 	decoder->period             = params->period;
 	decoder->period_type        = params->period_type;
 
@@ -1097,6 +1100,15 @@ static bool intel_pt_fup_event(struct intel_pt_decoder *decoder)
 	return ret;
 }
 
+static inline bool intel_pt_fup_with_nlip(struct intel_pt_decoder *decoder,
+					  struct intel_pt_insn *intel_pt_insn,
+					  uint64_t ip, int err)
+{
+	return decoder->flags & INTEL_PT_FUP_WITH_NLIP && !err &&
+	       intel_pt_insn->branch == INTEL_PT_BR_INDIRECT &&
+	       ip == decoder->ip + intel_pt_insn->length;
+}
+
 static int intel_pt_walk_fup(struct intel_pt_decoder *decoder)
 {
 	struct intel_pt_insn intel_pt_insn;
@@ -1109,10 +1121,11 @@ static int intel_pt_walk_fup(struct intel_pt_decoder *decoder)
 		err = intel_pt_walk_insn(decoder, &intel_pt_insn, ip);
 		if (err == INTEL_PT_RETURN)
 			return 0;
-		if (err == -EAGAIN) {
+		if (err == -EAGAIN ||
+		    intel_pt_fup_with_nlip(decoder, &intel_pt_insn, ip, err)) {
 			if (intel_pt_fup_event(decoder))
 				return 0;
-			return err;
+			return -EAGAIN;
 		}
 		decoder->set_fup_tx_flags = false;
 		if (err)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.h +9 -0
index fc1752d50019..51c18d67f4ca 100644
@@ -60,6 +60,14 @@ enum {
 	INTEL_PT_ERR_MAX,
 };
 
+enum intel_pt_param_flags {
+	/*
+	 * FUP packet can contain next linear instruction pointer instead of
+	 * current linear instruction pointer.
+	 */
+	INTEL_PT_FUP_WITH_NLIP	= 1 << 0,
+};
+
 struct intel_pt_state {
 	enum intel_pt_sample_type type;
 	int err;
@@ -106,6 +114,7 @@ struct intel_pt_params {
 	unsigned int mtc_period;
 	uint32_t tsc_ctc_ratio_n;
 	uint32_t tsc_ctc_ratio_d;
+	enum intel_pt_param_flags flags;
 };
 
 struct intel_pt_decoder;
tools/perf/util/intel-pt.c +4 -0
index 3db7f0ee52a8..aec68908d604 100644
@@ -749,6 +749,7 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt,
 						   unsigned int queue_nr)
 {
 	struct intel_pt_params params = { .get_trace = 0, };
+	struct perf_env *env = pt->machine->env;
 	struct intel_pt_queue *ptq;
 
 	ptq = zalloc(sizeof(struct intel_pt_queue));
@@ -830,6 +831,9 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt,
 		}
 	}
 
+	if (env->cpuid && !strncmp(env->cpuid, "GenuineIntel,6,92,", 18))
+		params.flags |= INTEL_PT_FUP_WITH_NLIP;
+
 	ptq->decoder = intel_pt_decoder_new(&params);
 	if (!ptq->decoder)
 		goto out_free;
maintainer Applied
#9 lore raw
In reply to Adrian Hunter

Em Thu, May 31, 2018 at 01:23:41PM +0300, Adrian Hunter escreveu:

Quoted 3 lines

Hi

Here are some small non-urgent fixes for Intel PT.

Thanks, applied the kit,

- Arnaldo

Quoted 15 lines

Adrian Hunter (4):
perf intel-pt: Fix sync_switch INTEL_PT_SS_NOT_TRACING
perf intel-pt: Fix decoding to accept CBR between FUP and corresponding TIP perf intel-pt: Fix MTC timing after overflow
perf intel-pt: Fix "Unexpected indirect branch" error

 .../perf/util/intel-pt-decoder/intel-pt-decoder.c  | 23 ++++++++++++++++++----
 .../perf/util/intel-pt-decoder/intel-pt-decoder.h  |  9 +++++++++
 tools/perf/util/intel-pt.c                         |  5 +++++
 3 files changed, 33 insertions(+), 4 deletions(-)

Regards
Adrian