linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] perf tools: fix endless record after being terminated
@ 2020-02-14 13:26 Adrian Hunter
  2020-02-14 13:26 ` [PATCH V2 1/5] perf tools: intel-pt: " Adrian Hunter
                   ` (4 more replies)
  0 siblings, 5 replies; 19+ messages in thread
From: Adrian Hunter @ 2020-02-14 13:26 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Tan Xiaojun, Wei Li

Hi

Wei Li sent some fixes.  I have tweaked them a bit, and added a tidy-up
patch.


Adrian Hunter (2):
      perf tools: arm-spe: fix endless record after being terminated
      perf auxtrace: Add auxtrace_record__read_finish()

Wei Li (3):
      perf tools: intel-pt: fix endless record after being terminated
      perf tools: intel-bts: fix endless record after being terminated
      perf tools: cs-etm: fix endless record after being terminated

 tools/perf/arch/arm/util/cs-etm.c    | 18 ++----------------
 tools/perf/arch/arm64/util/arm-spe.c | 17 ++---------------
 tools/perf/arch/x86/util/intel-bts.c | 17 ++---------------
 tools/perf/arch/x86/util/intel-pt.c  | 17 ++---------------
 tools/perf/util/auxtrace.c           | 22 +++++++++++++++++++++-
 tools/perf/util/auxtrace.h           |  6 ++++++
 6 files changed, 35 insertions(+), 62 deletions(-)


Regards
Adrian

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

* [PATCH V2 1/5] perf tools: intel-pt: fix endless record after being terminated
  2020-02-14 13:26 [PATCH 0/5] perf tools: fix endless record after being terminated Adrian Hunter
@ 2020-02-14 13:26 ` Adrian Hunter
  2020-02-26 14:20   ` [tip: perf/urgent] perf intel-pt: Fix " tip-bot2 for Wei Li
  2020-02-14 13:26 ` [PATCH V2 2/5] perf tools: intel-bts: fix " Adrian Hunter
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 19+ messages in thread
From: Adrian Hunter @ 2020-02-14 13:26 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Tan Xiaojun, Wei Li

From: Wei Li <liwei391@huawei.com>

In __cmd_record(), when receiving SIGINT(ctrl + c), a done flag will
be set and the event list will be disabled by evlist__disable() once.

While in auxtrace_record.read_finish(), the related events will be
enabled again, if they are continuous, the recording seems to be endless.

If the intel_pt event is disabled, we don't enable it again here.

Before the patch:
huawei@huawei-2288H-V5:~/linux-5.5-rc4/tools/perf$ ./perf record -e \
intel_pt//u -p 46803
^C^C^C^C^C^C

After the patch:
huawei@huawei-2288H-V5:~/linux-5.5-rc4/tools/perf$ ./perf record -e \
intel_pt//u -p 48591
^C[ perf record: Woken up 0 times to write data ]
Warning:
AUX data lost 504 times out of 4816!

[ perf record: Captured and wrote 2024.405 MB perf.data ]

Signed-off-by: Wei Li <liwei391@huawei.com>
[ahunter: removed redundant 'else' after 'return']
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: stable@vger.kernel.org # 5.4+
---
 tools/perf/arch/x86/util/intel-pt.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index ec75445ef7cf..2f0a0832907f 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -1177,9 +1177,12 @@ static int intel_pt_read_finish(struct auxtrace_record *itr, int idx)
 	struct evsel *evsel;
 
 	evlist__for_each_entry(ptr->evlist, evsel) {
-		if (evsel->core.attr.type == ptr->intel_pt_pmu->type)
+		if (evsel->core.attr.type == ptr->intel_pt_pmu->type) {
+			if (evsel->disabled)
+				return 0;
 			return perf_evlist__enable_event_idx(ptr->evlist, evsel,
 							     idx);
+		}
 	}
 	return -EINVAL;
 }
-- 
2.17.1


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

* [PATCH V2 2/5] perf tools: intel-bts: fix endless record after being terminated
  2020-02-14 13:26 [PATCH 0/5] perf tools: fix endless record after being terminated Adrian Hunter
  2020-02-14 13:26 ` [PATCH V2 1/5] perf tools: intel-pt: " Adrian Hunter
@ 2020-02-14 13:26 ` Adrian Hunter
  2020-02-26 14:20   ` [tip: perf/urgent] perf intel-bts: Fix " tip-bot2 for Wei Li
  2020-02-14 13:26 ` [PATCH V2 3/5] perf tools: cs-etm: fix " Adrian Hunter
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 19+ messages in thread
From: Adrian Hunter @ 2020-02-14 13:26 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Tan Xiaojun, Wei Li

From: Wei Li <liwei391@huawei.com>

In __cmd_record(), when receiving SIGINT(ctrl + c), a done flag will
be set and the event list will be disabled by evlist__disable() once.

While in auxtrace_record.read_finish(), the related events will be
enabled again, if they are continuous, the recording seems to be endless.

If the intel_bts event is disabled, we don't enable it again here.

Note: This patch is NOT tested since i don't have such a machine with
intel_bts feature, but the code seems buggy same as arm-spe and intel-pt.

Signed-off-by: Wei Li <liwei391@huawei.com>
[ahunter: removed redundant 'else' after 'return']
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: stable@vger.kernel.org # 5.4+
---
 tools/perf/arch/x86/util/intel-bts.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c
index 27d9e214d068..39e363151ad7 100644
--- a/tools/perf/arch/x86/util/intel-bts.c
+++ b/tools/perf/arch/x86/util/intel-bts.c
@@ -420,9 +420,12 @@ static int intel_bts_read_finish(struct auxtrace_record *itr, int idx)
 	struct evsel *evsel;
 
 	evlist__for_each_entry(btsr->evlist, evsel) {
-		if (evsel->core.attr.type == btsr->intel_bts_pmu->type)
+		if (evsel->core.attr.type == btsr->intel_bts_pmu->type) {
+			if (evsel->disabled)
+				return 0;
 			return perf_evlist__enable_event_idx(btsr->evlist,
 							     evsel, idx);
+		}
 	}
 	return -EINVAL;
 }
-- 
2.17.1


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

* [PATCH V2 3/5] perf tools: cs-etm: fix endless record after being terminated
  2020-02-14 13:26 [PATCH 0/5] perf tools: fix endless record after being terminated Adrian Hunter
  2020-02-14 13:26 ` [PATCH V2 1/5] perf tools: intel-pt: " Adrian Hunter
  2020-02-14 13:26 ` [PATCH V2 2/5] perf tools: intel-bts: fix " Adrian Hunter
@ 2020-02-14 13:26 ` Adrian Hunter
  2020-02-14 14:07   ` Adrian Hunter
                     ` (3 more replies)
  2020-02-14 13:26 ` [PATCH 4/5] perf tools: arm-spe: fix " Adrian Hunter
  2020-02-14 13:26 ` [PATCH 5/5] perf auxtrace: Add auxtrace_record__read_finish() Adrian Hunter
  4 siblings, 4 replies; 19+ messages in thread
From: Adrian Hunter @ 2020-02-14 13:26 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Tan Xiaojun, Wei Li

From: Wei Li <liwei391@huawei.com>

In __cmd_record(), when receiving SIGINT(ctrl + c), a done flag will
be set and the event list will be disabled by evlist__disable() once.

While in auxtrace_record.read_finish(), the related events will be
enabled again, if they are continuous, the recording seems to be endless.

If the cs_etm event is disabled, we don't enable it again here.

Note: This patch is NOT tested since i don't have such a machine with
coresight feature, but the code seems buggy same as arm-spe and intel-pt.

Signed-off-by: Wei Li <liwei391@huawei.com>
[ahunter: removed redundant 'else' after 'return']
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: stable@vger.kernel.org # 5.4+
---
 tools/perf/arch/arm/util/cs-etm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
index 2898cfdf8fe1..60141c3007a9 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -865,9 +865,12 @@ static int cs_etm_read_finish(struct auxtrace_record *itr, int idx)
 	struct evsel *evsel;
 
 	evlist__for_each_entry(ptr->evlist, evsel) {
-		if (evsel->core.attr.type == ptr->cs_etm_pmu->type)
+		if (evsel->core.attr.type == ptr->cs_etm_pmu->type) {
+			if (evsel->disabled)
+				return 0;
 			return perf_evlist__enable_event_idx(ptr->evlist,
 							     evsel, idx);
+		}
 	}
 
 	return -EINVAL;
-- 
2.17.1


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

* [PATCH 4/5] perf tools: arm-spe: fix endless record after being terminated
  2020-02-14 13:26 [PATCH 0/5] perf tools: fix endless record after being terminated Adrian Hunter
                   ` (2 preceding siblings ...)
  2020-02-14 13:26 ` [PATCH V2 3/5] perf tools: cs-etm: fix " Adrian Hunter
@ 2020-02-14 13:26 ` Adrian Hunter
  2020-02-26 14:20   ` [tip: perf/urgent] perf arm-spe: Fix " tip-bot2 for Adrian Hunter
  2020-02-14 13:26 ` [PATCH 5/5] perf auxtrace: Add auxtrace_record__read_finish() Adrian Hunter
  4 siblings, 1 reply; 19+ messages in thread
From: Adrian Hunter @ 2020-02-14 13:26 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Tan Xiaojun, Wei Li

In __cmd_record(), when receiving SIGINT(ctrl + c), a done flag will
be set and the event list will be disabled by evlist__disable() once.

While in auxtrace_record.read_finish(), the related events will be
enabled again, if they are continuous, the recording seems to be endless.

If the event is disabled, don't enable it again here.

Based-on-patch-by: Wei Li <liwei391@huawei.com>
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: stable@vger.kernel.org # 5.4+
---
 tools/perf/arch/arm64/util/arm-spe.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
index eba6541ec0f1..1d993c27242b 100644
--- a/tools/perf/arch/arm64/util/arm-spe.c
+++ b/tools/perf/arch/arm64/util/arm-spe.c
@@ -165,9 +165,12 @@ static int arm_spe_read_finish(struct auxtrace_record *itr, int idx)
 	struct evsel *evsel;
 
 	evlist__for_each_entry(sper->evlist, evsel) {
-		if (evsel->core.attr.type == sper->arm_spe_pmu->type)
+		if (evsel->core.attr.type == sper->arm_spe_pmu->type) {
+			if (evsel->disabled)
+				return 0;
 			return perf_evlist__enable_event_idx(sper->evlist,
 							     evsel, idx);
+		}
 	}
 	return -EINVAL;
 }
-- 
2.17.1


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

* [PATCH 5/5] perf auxtrace: Add auxtrace_record__read_finish()
  2020-02-14 13:26 [PATCH 0/5] perf tools: fix endless record after being terminated Adrian Hunter
                   ` (3 preceding siblings ...)
  2020-02-14 13:26 ` [PATCH 4/5] perf tools: arm-spe: fix " Adrian Hunter
@ 2020-02-14 13:26 ` Adrian Hunter
  2020-02-14 14:08   ` Adrian Hunter
                     ` (2 more replies)
  4 siblings, 3 replies; 19+ messages in thread
From: Adrian Hunter @ 2020-02-14 13:26 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: Jiri Olsa, linux-kernel, Tan Xiaojun, Wei Li

All ->read_finish() implementations are doing the same thing. Add a
helper function so that they can share the same implementation.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/arch/arm/util/cs-etm.c    | 21 ++-------------------
 tools/perf/arch/arm64/util/arm-spe.c | 20 ++------------------
 tools/perf/arch/x86/util/intel-bts.c | 20 ++------------------
 tools/perf/arch/x86/util/intel-pt.c  | 20 ++------------------
 tools/perf/util/auxtrace.c           | 22 +++++++++++++++++++++-
 tools/perf/util/auxtrace.h           |  6 ++++++
 6 files changed, 35 insertions(+), 74 deletions(-)

diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
index 60141c3007a9..00126e7df465 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -858,24 +858,6 @@ static void cs_etm_recording_free(struct auxtrace_record *itr)
 	free(ptr);
 }
 
-static int cs_etm_read_finish(struct auxtrace_record *itr, int idx)
-{
-	struct cs_etm_recording *ptr =
-			container_of(itr, struct cs_etm_recording, itr);
-	struct evsel *evsel;
-
-	evlist__for_each_entry(ptr->evlist, evsel) {
-		if (evsel->core.attr.type == ptr->cs_etm_pmu->type) {
-			if (evsel->disabled)
-				return 0;
-			return perf_evlist__enable_event_idx(ptr->evlist,
-							     evsel, idx);
-		}
-	}
-
-	return -EINVAL;
-}
-
 struct auxtrace_record *cs_etm_record_init(int *err)
 {
 	struct perf_pmu *cs_etm_pmu;
@@ -895,6 +877,7 @@ struct auxtrace_record *cs_etm_record_init(int *err)
 	}
 
 	ptr->cs_etm_pmu			= cs_etm_pmu;
+	ptr->itr.cs_etm_pmu		= cs_etm_pmu;
 	ptr->itr.parse_snapshot_options	= cs_etm_parse_snapshot_options;
 	ptr->itr.recording_options	= cs_etm_recording_options;
 	ptr->itr.info_priv_size		= cs_etm_info_priv_size;
@@ -904,7 +887,7 @@ struct auxtrace_record *cs_etm_record_init(int *err)
 	ptr->itr.snapshot_finish	= cs_etm_snapshot_finish;
 	ptr->itr.reference		= cs_etm_reference;
 	ptr->itr.free			= cs_etm_recording_free;
-	ptr->itr.read_finish		= cs_etm_read_finish;
+	ptr->itr.read_finish		= auxtrace_record__read_finish;
 
 	*err = 0;
 	return &ptr->itr;
diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
index 1d993c27242b..8d6821d9c3f6 100644
--- a/tools/perf/arch/arm64/util/arm-spe.c
+++ b/tools/perf/arch/arm64/util/arm-spe.c
@@ -158,23 +158,6 @@ static void arm_spe_recording_free(struct auxtrace_record *itr)
 	free(sper);
 }
 
-static int arm_spe_read_finish(struct auxtrace_record *itr, int idx)
-{
-	struct arm_spe_recording *sper =
-			container_of(itr, struct arm_spe_recording, itr);
-	struct evsel *evsel;
-
-	evlist__for_each_entry(sper->evlist, evsel) {
-		if (evsel->core.attr.type == sper->arm_spe_pmu->type) {
-			if (evsel->disabled)
-				return 0;
-			return perf_evlist__enable_event_idx(sper->evlist,
-							     evsel, idx);
-		}
-	}
-	return -EINVAL;
-}
-
 struct auxtrace_record *arm_spe_recording_init(int *err,
 					       struct perf_pmu *arm_spe_pmu)
 {
@@ -192,12 +175,13 @@ struct auxtrace_record *arm_spe_recording_init(int *err,
 	}
 
 	sper->arm_spe_pmu = arm_spe_pmu;
+	sper->itr.pmu = arm_spe_pmu;
 	sper->itr.recording_options = arm_spe_recording_options;
 	sper->itr.info_priv_size = arm_spe_info_priv_size;
 	sper->itr.info_fill = arm_spe_info_fill;
 	sper->itr.free = arm_spe_recording_free;
 	sper->itr.reference = arm_spe_reference;
-	sper->itr.read_finish = arm_spe_read_finish;
+	sper->itr.read_finish = auxtrace_record__read_finish;
 	sper->itr.alignment = 0;
 
 	*err = 0;
diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c
index 39e363151ad7..26cee1052179 100644
--- a/tools/perf/arch/x86/util/intel-bts.c
+++ b/tools/perf/arch/x86/util/intel-bts.c
@@ -413,23 +413,6 @@ static int intel_bts_find_snapshot(struct auxtrace_record *itr, int idx,
 	return err;
 }
 
-static int intel_bts_read_finish(struct auxtrace_record *itr, int idx)
-{
-	struct intel_bts_recording *btsr =
-			container_of(itr, struct intel_bts_recording, itr);
-	struct evsel *evsel;
-
-	evlist__for_each_entry(btsr->evlist, evsel) {
-		if (evsel->core.attr.type == btsr->intel_bts_pmu->type) {
-			if (evsel->disabled)
-				return 0;
-			return perf_evlist__enable_event_idx(btsr->evlist,
-							     evsel, idx);
-		}
-	}
-	return -EINVAL;
-}
-
 struct auxtrace_record *intel_bts_recording_init(int *err)
 {
 	struct perf_pmu *intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME);
@@ -450,6 +433,7 @@ struct auxtrace_record *intel_bts_recording_init(int *err)
 	}
 
 	btsr->intel_bts_pmu = intel_bts_pmu;
+	btsr->itr.pmu = intel_bts_pmu;
 	btsr->itr.recording_options = intel_bts_recording_options;
 	btsr->itr.info_priv_size = intel_bts_info_priv_size;
 	btsr->itr.info_fill = intel_bts_info_fill;
@@ -459,7 +443,7 @@ struct auxtrace_record *intel_bts_recording_init(int *err)
 	btsr->itr.find_snapshot = intel_bts_find_snapshot;
 	btsr->itr.parse_snapshot_options = intel_bts_parse_snapshot_options;
 	btsr->itr.reference = intel_bts_reference;
-	btsr->itr.read_finish = intel_bts_read_finish;
+	btsr->itr.read_finish = auxtrace_record__read_finish;
 	btsr->itr.alignment = sizeof(struct branch);
 	return &btsr->itr;
 }
diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index 2f0a0832907f..acadaa10c65d 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -1170,23 +1170,6 @@ static u64 intel_pt_reference(struct auxtrace_record *itr __maybe_unused)
 	return rdtsc();
 }
 
-static int intel_pt_read_finish(struct auxtrace_record *itr, int idx)
-{
-	struct intel_pt_recording *ptr =
-			container_of(itr, struct intel_pt_recording, itr);
-	struct evsel *evsel;
-
-	evlist__for_each_entry(ptr->evlist, evsel) {
-		if (evsel->core.attr.type == ptr->intel_pt_pmu->type) {
-			if (evsel->disabled)
-				return 0;
-			return perf_evlist__enable_event_idx(ptr->evlist, evsel,
-							     idx);
-		}
-	}
-	return -EINVAL;
-}
-
 struct auxtrace_record *intel_pt_recording_init(int *err)
 {
 	struct perf_pmu *intel_pt_pmu = perf_pmu__find(INTEL_PT_PMU_NAME);
@@ -1207,6 +1190,7 @@ struct auxtrace_record *intel_pt_recording_init(int *err)
 	}
 
 	ptr->intel_pt_pmu = intel_pt_pmu;
+	ptr->itr.pmu = intel_pt_pmu;
 	ptr->itr.recording_options = intel_pt_recording_options;
 	ptr->itr.info_priv_size = intel_pt_info_priv_size;
 	ptr->itr.info_fill = intel_pt_info_fill;
@@ -1216,7 +1200,7 @@ struct auxtrace_record *intel_pt_recording_init(int *err)
 	ptr->itr.find_snapshot = intel_pt_find_snapshot;
 	ptr->itr.parse_snapshot_options = intel_pt_parse_snapshot_options;
 	ptr->itr.reference = intel_pt_reference;
-	ptr->itr.read_finish = intel_pt_read_finish;
+	ptr->itr.read_finish = auxtrace_record__read_finish;
 	/*
 	 * Decoding starts at a PSB packet. Minimum PSB period is 2K so 4K
 	 * should give at least 1 PSB per sample.
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index eb087e7df6f4..3571ce72ca28 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -629,8 +629,10 @@ int auxtrace_record__options(struct auxtrace_record *itr,
 			     struct evlist *evlist,
 			     struct record_opts *opts)
 {
-	if (itr)
+	if (itr) {
+		itr->evlist = evlist;
 		return itr->recording_options(itr, evlist, opts);
+	}
 	return 0;
 }
 
@@ -664,6 +666,24 @@ int auxtrace_parse_snapshot_options(struct auxtrace_record *itr,
 	return -EINVAL;
 }
 
+int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx)
+{
+	struct evsel *evsel;
+
+	if (!itr->evlist || !itr->pmu)
+		return -EINVAL;
+
+	evlist__for_each_entry(itr->evlist, evsel) {
+		if (evsel->core.attr.type == itr->pmu->type) {
+			if (evsel->disabled)
+				return 0;
+			return perf_evlist__enable_event_idx(itr->evlist, evsel,
+							     idx);
+		}
+	}
+	return -EINVAL;
+}
+
 /*
  * Event record size is 16-bit which results in a maximum size of about 64KiB.
  * Allow about 4KiB for the rest of the sample record, to give a maximum
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 749d72cd9c7b..e58ef160b599 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -29,6 +29,7 @@ struct record_opts;
 struct perf_record_auxtrace_error;
 struct perf_record_auxtrace_info;
 struct events_stats;
+struct perf_pmu;
 
 enum auxtrace_error_type {
        PERF_AUXTRACE_ERROR_ITRACE  = 1,
@@ -322,6 +323,8 @@ struct auxtrace_mmap_params {
  * @read_finish: called after reading from an auxtrace mmap
  * @alignment: alignment (if any) for AUX area data
  * @default_aux_sample_size: default sample size for --aux sample option
+ * @pmu: associated pmu
+ * @evlist: selected events list
  */
 struct auxtrace_record {
 	int (*recording_options)(struct auxtrace_record *itr,
@@ -346,6 +349,8 @@ struct auxtrace_record {
 	int (*read_finish)(struct auxtrace_record *itr, int idx);
 	unsigned int alignment;
 	unsigned int default_aux_sample_size;
+	struct perf_pmu *pmu;
+	struct evlist *evlist;
 };
 
 /**
@@ -537,6 +542,7 @@ int auxtrace_record__find_snapshot(struct auxtrace_record *itr, int idx,
 				   struct auxtrace_mmap *mm,
 				   unsigned char *data, u64 *head, u64 *old);
 u64 auxtrace_record__reference(struct auxtrace_record *itr);
+int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx);
 
 int auxtrace_index__auxtrace_event(struct list_head *head, union perf_event *event,
 				   off_t file_offset);
-- 
2.17.1


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

* Re: [PATCH V2 3/5] perf tools: cs-etm: fix endless record after being terminated
  2020-02-14 13:26 ` [PATCH V2 3/5] perf tools: cs-etm: fix " Adrian Hunter
@ 2020-02-14 14:07   ` Adrian Hunter
  2020-02-14 14:43   ` Leo Yan
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 19+ messages in thread
From: Adrian Hunter @ 2020-02-14 14:07 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Leo Yan; +Cc: Jiri Olsa, linux-kernel, Wei Li

+ Leo Yan <leo.yan@linaro.org>


On 14/02/20 3:26 pm, Adrian Hunter wrote:
> From: Wei Li <liwei391@huawei.com>
> 
> In __cmd_record(), when receiving SIGINT(ctrl + c), a done flag will
> be set and the event list will be disabled by evlist__disable() once.
> 
> While in auxtrace_record.read_finish(), the related events will be
> enabled again, if they are continuous, the recording seems to be endless.
> 
> If the cs_etm event is disabled, we don't enable it again here.
> 
> Note: This patch is NOT tested since i don't have such a machine with
> coresight feature, but the code seems buggy same as arm-spe and intel-pt.
> 
> Signed-off-by: Wei Li <liwei391@huawei.com>
> [ahunter: removed redundant 'else' after 'return']
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> Cc: stable@vger.kernel.org # 5.4+
> ---
>  tools/perf/arch/arm/util/cs-etm.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
> index 2898cfdf8fe1..60141c3007a9 100644
> --- a/tools/perf/arch/arm/util/cs-etm.c
> +++ b/tools/perf/arch/arm/util/cs-etm.c
> @@ -865,9 +865,12 @@ static int cs_etm_read_finish(struct auxtrace_record *itr, int idx)
>  	struct evsel *evsel;
>  
>  	evlist__for_each_entry(ptr->evlist, evsel) {
> -		if (evsel->core.attr.type == ptr->cs_etm_pmu->type)
> +		if (evsel->core.attr.type == ptr->cs_etm_pmu->type) {
> +			if (evsel->disabled)
> +				return 0;
>  			return perf_evlist__enable_event_idx(ptr->evlist,
>  							     evsel, idx);
> +		}
>  	}
>  
>  	return -EINVAL;
> 


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

* Re: [PATCH 5/5] perf auxtrace: Add auxtrace_record__read_finish()
  2020-02-14 13:26 ` [PATCH 5/5] perf auxtrace: Add auxtrace_record__read_finish() Adrian Hunter
@ 2020-02-14 14:08   ` Adrian Hunter
  2020-02-14 14:48   ` Leo Yan
  2020-02-14 18:27   ` [PATCH 5/5] " Mathieu Poirier
  2 siblings, 0 replies; 19+ messages in thread
From: Adrian Hunter @ 2020-02-14 14:08 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Leo Yan; +Cc: Jiri Olsa, linux-kernel, Wei Li

+ Leo Yan <leo.yan@linaro.org>

On 14/02/20 3:26 pm, Adrian Hunter wrote:
> All ->read_finish() implementations are doing the same thing. Add a
> helper function so that they can share the same implementation.
> 
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
>  tools/perf/arch/arm/util/cs-etm.c    | 21 ++-------------------
>  tools/perf/arch/arm64/util/arm-spe.c | 20 ++------------------
>  tools/perf/arch/x86/util/intel-bts.c | 20 ++------------------
>  tools/perf/arch/x86/util/intel-pt.c  | 20 ++------------------
>  tools/perf/util/auxtrace.c           | 22 +++++++++++++++++++++-
>  tools/perf/util/auxtrace.h           |  6 ++++++
>  6 files changed, 35 insertions(+), 74 deletions(-)
> 
> diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
> index 60141c3007a9..00126e7df465 100644
> --- a/tools/perf/arch/arm/util/cs-etm.c
> +++ b/tools/perf/arch/arm/util/cs-etm.c
> @@ -858,24 +858,6 @@ static void cs_etm_recording_free(struct auxtrace_record *itr)
>  	free(ptr);
>  }
>  
> -static int cs_etm_read_finish(struct auxtrace_record *itr, int idx)
> -{
> -	struct cs_etm_recording *ptr =
> -			container_of(itr, struct cs_etm_recording, itr);
> -	struct evsel *evsel;
> -
> -	evlist__for_each_entry(ptr->evlist, evsel) {
> -		if (evsel->core.attr.type == ptr->cs_etm_pmu->type) {
> -			if (evsel->disabled)
> -				return 0;
> -			return perf_evlist__enable_event_idx(ptr->evlist,
> -							     evsel, idx);
> -		}
> -	}
> -
> -	return -EINVAL;
> -}
> -
>  struct auxtrace_record *cs_etm_record_init(int *err)
>  {
>  	struct perf_pmu *cs_etm_pmu;
> @@ -895,6 +877,7 @@ struct auxtrace_record *cs_etm_record_init(int *err)
>  	}
>  
>  	ptr->cs_etm_pmu			= cs_etm_pmu;
> +	ptr->itr.cs_etm_pmu		= cs_etm_pmu;
>  	ptr->itr.parse_snapshot_options	= cs_etm_parse_snapshot_options;
>  	ptr->itr.recording_options	= cs_etm_recording_options;
>  	ptr->itr.info_priv_size		= cs_etm_info_priv_size;
> @@ -904,7 +887,7 @@ struct auxtrace_record *cs_etm_record_init(int *err)
>  	ptr->itr.snapshot_finish	= cs_etm_snapshot_finish;
>  	ptr->itr.reference		= cs_etm_reference;
>  	ptr->itr.free			= cs_etm_recording_free;
> -	ptr->itr.read_finish		= cs_etm_read_finish;
> +	ptr->itr.read_finish		= auxtrace_record__read_finish;
>  
>  	*err = 0;
>  	return &ptr->itr;
> diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
> index 1d993c27242b..8d6821d9c3f6 100644
> --- a/tools/perf/arch/arm64/util/arm-spe.c
> +++ b/tools/perf/arch/arm64/util/arm-spe.c
> @@ -158,23 +158,6 @@ static void arm_spe_recording_free(struct auxtrace_record *itr)
>  	free(sper);
>  }
>  
> -static int arm_spe_read_finish(struct auxtrace_record *itr, int idx)
> -{
> -	struct arm_spe_recording *sper =
> -			container_of(itr, struct arm_spe_recording, itr);
> -	struct evsel *evsel;
> -
> -	evlist__for_each_entry(sper->evlist, evsel) {
> -		if (evsel->core.attr.type == sper->arm_spe_pmu->type) {
> -			if (evsel->disabled)
> -				return 0;
> -			return perf_evlist__enable_event_idx(sper->evlist,
> -							     evsel, idx);
> -		}
> -	}
> -	return -EINVAL;
> -}
> -
>  struct auxtrace_record *arm_spe_recording_init(int *err,
>  					       struct perf_pmu *arm_spe_pmu)
>  {
> @@ -192,12 +175,13 @@ struct auxtrace_record *arm_spe_recording_init(int *err,
>  	}
>  
>  	sper->arm_spe_pmu = arm_spe_pmu;
> +	sper->itr.pmu = arm_spe_pmu;
>  	sper->itr.recording_options = arm_spe_recording_options;
>  	sper->itr.info_priv_size = arm_spe_info_priv_size;
>  	sper->itr.info_fill = arm_spe_info_fill;
>  	sper->itr.free = arm_spe_recording_free;
>  	sper->itr.reference = arm_spe_reference;
> -	sper->itr.read_finish = arm_spe_read_finish;
> +	sper->itr.read_finish = auxtrace_record__read_finish;
>  	sper->itr.alignment = 0;
>  
>  	*err = 0;
> diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c
> index 39e363151ad7..26cee1052179 100644
> --- a/tools/perf/arch/x86/util/intel-bts.c
> +++ b/tools/perf/arch/x86/util/intel-bts.c
> @@ -413,23 +413,6 @@ static int intel_bts_find_snapshot(struct auxtrace_record *itr, int idx,
>  	return err;
>  }
>  
> -static int intel_bts_read_finish(struct auxtrace_record *itr, int idx)
> -{
> -	struct intel_bts_recording *btsr =
> -			container_of(itr, struct intel_bts_recording, itr);
> -	struct evsel *evsel;
> -
> -	evlist__for_each_entry(btsr->evlist, evsel) {
> -		if (evsel->core.attr.type == btsr->intel_bts_pmu->type) {
> -			if (evsel->disabled)
> -				return 0;
> -			return perf_evlist__enable_event_idx(btsr->evlist,
> -							     evsel, idx);
> -		}
> -	}
> -	return -EINVAL;
> -}
> -
>  struct auxtrace_record *intel_bts_recording_init(int *err)
>  {
>  	struct perf_pmu *intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME);
> @@ -450,6 +433,7 @@ struct auxtrace_record *intel_bts_recording_init(int *err)
>  	}
>  
>  	btsr->intel_bts_pmu = intel_bts_pmu;
> +	btsr->itr.pmu = intel_bts_pmu;
>  	btsr->itr.recording_options = intel_bts_recording_options;
>  	btsr->itr.info_priv_size = intel_bts_info_priv_size;
>  	btsr->itr.info_fill = intel_bts_info_fill;
> @@ -459,7 +443,7 @@ struct auxtrace_record *intel_bts_recording_init(int *err)
>  	btsr->itr.find_snapshot = intel_bts_find_snapshot;
>  	btsr->itr.parse_snapshot_options = intel_bts_parse_snapshot_options;
>  	btsr->itr.reference = intel_bts_reference;
> -	btsr->itr.read_finish = intel_bts_read_finish;
> +	btsr->itr.read_finish = auxtrace_record__read_finish;
>  	btsr->itr.alignment = sizeof(struct branch);
>  	return &btsr->itr;
>  }
> diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
> index 2f0a0832907f..acadaa10c65d 100644
> --- a/tools/perf/arch/x86/util/intel-pt.c
> +++ b/tools/perf/arch/x86/util/intel-pt.c
> @@ -1170,23 +1170,6 @@ static u64 intel_pt_reference(struct auxtrace_record *itr __maybe_unused)
>  	return rdtsc();
>  }
>  
> -static int intel_pt_read_finish(struct auxtrace_record *itr, int idx)
> -{
> -	struct intel_pt_recording *ptr =
> -			container_of(itr, struct intel_pt_recording, itr);
> -	struct evsel *evsel;
> -
> -	evlist__for_each_entry(ptr->evlist, evsel) {
> -		if (evsel->core.attr.type == ptr->intel_pt_pmu->type) {
> -			if (evsel->disabled)
> -				return 0;
> -			return perf_evlist__enable_event_idx(ptr->evlist, evsel,
> -							     idx);
> -		}
> -	}
> -	return -EINVAL;
> -}
> -
>  struct auxtrace_record *intel_pt_recording_init(int *err)
>  {
>  	struct perf_pmu *intel_pt_pmu = perf_pmu__find(INTEL_PT_PMU_NAME);
> @@ -1207,6 +1190,7 @@ struct auxtrace_record *intel_pt_recording_init(int *err)
>  	}
>  
>  	ptr->intel_pt_pmu = intel_pt_pmu;
> +	ptr->itr.pmu = intel_pt_pmu;
>  	ptr->itr.recording_options = intel_pt_recording_options;
>  	ptr->itr.info_priv_size = intel_pt_info_priv_size;
>  	ptr->itr.info_fill = intel_pt_info_fill;
> @@ -1216,7 +1200,7 @@ struct auxtrace_record *intel_pt_recording_init(int *err)
>  	ptr->itr.find_snapshot = intel_pt_find_snapshot;
>  	ptr->itr.parse_snapshot_options = intel_pt_parse_snapshot_options;
>  	ptr->itr.reference = intel_pt_reference;
> -	ptr->itr.read_finish = intel_pt_read_finish;
> +	ptr->itr.read_finish = auxtrace_record__read_finish;
>  	/*
>  	 * Decoding starts at a PSB packet. Minimum PSB period is 2K so 4K
>  	 * should give at least 1 PSB per sample.
> diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
> index eb087e7df6f4..3571ce72ca28 100644
> --- a/tools/perf/util/auxtrace.c
> +++ b/tools/perf/util/auxtrace.c
> @@ -629,8 +629,10 @@ int auxtrace_record__options(struct auxtrace_record *itr,
>  			     struct evlist *evlist,
>  			     struct record_opts *opts)
>  {
> -	if (itr)
> +	if (itr) {
> +		itr->evlist = evlist;
>  		return itr->recording_options(itr, evlist, opts);
> +	}
>  	return 0;
>  }
>  
> @@ -664,6 +666,24 @@ int auxtrace_parse_snapshot_options(struct auxtrace_record *itr,
>  	return -EINVAL;
>  }
>  
> +int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx)
> +{
> +	struct evsel *evsel;
> +
> +	if (!itr->evlist || !itr->pmu)
> +		return -EINVAL;
> +
> +	evlist__for_each_entry(itr->evlist, evsel) {
> +		if (evsel->core.attr.type == itr->pmu->type) {
> +			if (evsel->disabled)
> +				return 0;
> +			return perf_evlist__enable_event_idx(itr->evlist, evsel,
> +							     idx);
> +		}
> +	}
> +	return -EINVAL;
> +}
> +
>  /*
>   * Event record size is 16-bit which results in a maximum size of about 64KiB.
>   * Allow about 4KiB for the rest of the sample record, to give a maximum
> diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
> index 749d72cd9c7b..e58ef160b599 100644
> --- a/tools/perf/util/auxtrace.h
> +++ b/tools/perf/util/auxtrace.h
> @@ -29,6 +29,7 @@ struct record_opts;
>  struct perf_record_auxtrace_error;
>  struct perf_record_auxtrace_info;
>  struct events_stats;
> +struct perf_pmu;
>  
>  enum auxtrace_error_type {
>         PERF_AUXTRACE_ERROR_ITRACE  = 1,
> @@ -322,6 +323,8 @@ struct auxtrace_mmap_params {
>   * @read_finish: called after reading from an auxtrace mmap
>   * @alignment: alignment (if any) for AUX area data
>   * @default_aux_sample_size: default sample size for --aux sample option
> + * @pmu: associated pmu
> + * @evlist: selected events list
>   */
>  struct auxtrace_record {
>  	int (*recording_options)(struct auxtrace_record *itr,
> @@ -346,6 +349,8 @@ struct auxtrace_record {
>  	int (*read_finish)(struct auxtrace_record *itr, int idx);
>  	unsigned int alignment;
>  	unsigned int default_aux_sample_size;
> +	struct perf_pmu *pmu;
> +	struct evlist *evlist;
>  };
>  
>  /**
> @@ -537,6 +542,7 @@ int auxtrace_record__find_snapshot(struct auxtrace_record *itr, int idx,
>  				   struct auxtrace_mmap *mm,
>  				   unsigned char *data, u64 *head, u64 *old);
>  u64 auxtrace_record__reference(struct auxtrace_record *itr);
> +int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx);
>  
>  int auxtrace_index__auxtrace_event(struct list_head *head, union perf_event *event,
>  				   off_t file_offset);
> 


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

* Re: [PATCH V2 3/5] perf tools: cs-etm: fix endless record after being terminated
  2020-02-14 13:26 ` [PATCH V2 3/5] perf tools: cs-etm: fix " Adrian Hunter
  2020-02-14 14:07   ` Adrian Hunter
@ 2020-02-14 14:43   ` Leo Yan
  2020-02-14 18:24   ` Mathieu Poirier
  2020-02-26 14:20   ` [tip: perf/urgent] perf cs-etm: Fix " tip-bot2 for Wei Li
  3 siblings, 0 replies; 19+ messages in thread
From: Leo Yan @ 2020-02-14 14:43 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, linux-kernel, Tan Xiaojun, Wei Li

On Fri, Feb 14, 2020 at 03:26:52PM +0200, Adrian Hunter wrote:
> From: Wei Li <liwei391@huawei.com>
> 
> In __cmd_record(), when receiving SIGINT(ctrl + c), a done flag will
> be set and the event list will be disabled by evlist__disable() once.
> 
> While in auxtrace_record.read_finish(), the related events will be
> enabled again, if they are continuous, the recording seems to be endless.
> 
> If the cs_etm event is disabled, we don't enable it again here.
> 
> Note: This patch is NOT tested since i don't have such a machine with
> coresight feature, but the code seems buggy same as arm-spe and intel-pt.
> 
> Signed-off-by: Wei Li <liwei391@huawei.com>
> [ahunter: removed redundant 'else' after 'return']
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> Cc: stable@vger.kernel.org # 5.4+

Thanks for looping, Adrian.  Applied this patch and tested with
CoreSight on juno board, it works well:

Reviewed-and-Tested-by: Leo Yan <leo.yan@linaro.org>


> ---
>  tools/perf/arch/arm/util/cs-etm.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
> index 2898cfdf8fe1..60141c3007a9 100644
> --- a/tools/perf/arch/arm/util/cs-etm.c
> +++ b/tools/perf/arch/arm/util/cs-etm.c
> @@ -865,9 +865,12 @@ static int cs_etm_read_finish(struct auxtrace_record *itr, int idx)
>  	struct evsel *evsel;
>  
>  	evlist__for_each_entry(ptr->evlist, evsel) {
> -		if (evsel->core.attr.type == ptr->cs_etm_pmu->type)
> +		if (evsel->core.attr.type == ptr->cs_etm_pmu->type) {
> +			if (evsel->disabled)
> +				return 0;
>  			return perf_evlist__enable_event_idx(ptr->evlist,
>  							     evsel, idx);
> +		}
>  	}
>  
>  	return -EINVAL;
> -- 
> 2.17.1
> 

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

* Re: [PATCH 5/5] perf auxtrace: Add auxtrace_record__read_finish()
  2020-02-14 13:26 ` [PATCH 5/5] perf auxtrace: Add auxtrace_record__read_finish() Adrian Hunter
  2020-02-14 14:08   ` Adrian Hunter
@ 2020-02-14 14:48   ` Leo Yan
  2020-02-17  8:23     ` [PATCH V2 " Adrian Hunter
  2020-02-14 18:27   ` [PATCH 5/5] " Mathieu Poirier
  2 siblings, 1 reply; 19+ messages in thread
From: Leo Yan @ 2020-02-14 14:48 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, linux-kernel, Tan Xiaojun, Wei Li

On Fri, Feb 14, 2020 at 03:26:54PM +0200, Adrian Hunter wrote:
> All ->read_finish() implementations are doing the same thing. Add a
> helper function so that they can share the same implementation.
> 
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
>  tools/perf/arch/arm/util/cs-etm.c    | 21 ++-------------------
>  tools/perf/arch/arm64/util/arm-spe.c | 20 ++------------------
>  tools/perf/arch/x86/util/intel-bts.c | 20 ++------------------
>  tools/perf/arch/x86/util/intel-pt.c  | 20 ++------------------
>  tools/perf/util/auxtrace.c           | 22 +++++++++++++++++++++-
>  tools/perf/util/auxtrace.h           |  6 ++++++
>  6 files changed, 35 insertions(+), 74 deletions(-)
> 
> diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
> index 60141c3007a9..00126e7df465 100644
> --- a/tools/perf/arch/arm/util/cs-etm.c
> +++ b/tools/perf/arch/arm/util/cs-etm.c
> @@ -858,24 +858,6 @@ static void cs_etm_recording_free(struct auxtrace_record *itr)
>  	free(ptr);
>  }
>  
> -static int cs_etm_read_finish(struct auxtrace_record *itr, int idx)
> -{
> -	struct cs_etm_recording *ptr =
> -			container_of(itr, struct cs_etm_recording, itr);
> -	struct evsel *evsel;
> -
> -	evlist__for_each_entry(ptr->evlist, evsel) {
> -		if (evsel->core.attr.type == ptr->cs_etm_pmu->type) {
> -			if (evsel->disabled)
> -				return 0;
> -			return perf_evlist__enable_event_idx(ptr->evlist,
> -							     evsel, idx);
> -		}
> -	}
> -
> -	return -EINVAL;
> -}
> -
>  struct auxtrace_record *cs_etm_record_init(int *err)
>  {
>  	struct perf_pmu *cs_etm_pmu;
> @@ -895,6 +877,7 @@ struct auxtrace_record *cs_etm_record_init(int *err)
>  	}
>  
>  	ptr->cs_etm_pmu			= cs_etm_pmu;
> +	ptr->itr.cs_etm_pmu		= cs_etm_pmu;

Should change to:
        ptr->itr.pmu                    = cs_etm_pmu;

With this change:
Reviewed-and-Tested-by: Leo Yan <leo.yan@linaro.org>

>  	ptr->itr.parse_snapshot_options	= cs_etm_parse_snapshot_options;
>  	ptr->itr.recording_options	= cs_etm_recording_options;
>  	ptr->itr.info_priv_size		= cs_etm_info_priv_size;
> @@ -904,7 +887,7 @@ struct auxtrace_record *cs_etm_record_init(int *err)
>  	ptr->itr.snapshot_finish	= cs_etm_snapshot_finish;
>  	ptr->itr.reference		= cs_etm_reference;
>  	ptr->itr.free			= cs_etm_recording_free;
> -	ptr->itr.read_finish		= cs_etm_read_finish;
> +	ptr->itr.read_finish		= auxtrace_record__read_finish;
>  
>  	*err = 0;
>  	return &ptr->itr;
> diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
> index 1d993c27242b..8d6821d9c3f6 100644
> --- a/tools/perf/arch/arm64/util/arm-spe.c
> +++ b/tools/perf/arch/arm64/util/arm-spe.c
> @@ -158,23 +158,6 @@ static void arm_spe_recording_free(struct auxtrace_record *itr)
>  	free(sper);
>  }
>  
> -static int arm_spe_read_finish(struct auxtrace_record *itr, int idx)
> -{
> -	struct arm_spe_recording *sper =
> -			container_of(itr, struct arm_spe_recording, itr);
> -	struct evsel *evsel;
> -
> -	evlist__for_each_entry(sper->evlist, evsel) {
> -		if (evsel->core.attr.type == sper->arm_spe_pmu->type) {
> -			if (evsel->disabled)
> -				return 0;
> -			return perf_evlist__enable_event_idx(sper->evlist,
> -							     evsel, idx);
> -		}
> -	}
> -	return -EINVAL;
> -}
> -
>  struct auxtrace_record *arm_spe_recording_init(int *err,
>  					       struct perf_pmu *arm_spe_pmu)
>  {
> @@ -192,12 +175,13 @@ struct auxtrace_record *arm_spe_recording_init(int *err,
>  	}
>  
>  	sper->arm_spe_pmu = arm_spe_pmu;
> +	sper->itr.pmu = arm_spe_pmu;
>  	sper->itr.recording_options = arm_spe_recording_options;
>  	sper->itr.info_priv_size = arm_spe_info_priv_size;
>  	sper->itr.info_fill = arm_spe_info_fill;
>  	sper->itr.free = arm_spe_recording_free;
>  	sper->itr.reference = arm_spe_reference;
> -	sper->itr.read_finish = arm_spe_read_finish;
> +	sper->itr.read_finish = auxtrace_record__read_finish;
>  	sper->itr.alignment = 0;
>  
>  	*err = 0;
> diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c
> index 39e363151ad7..26cee1052179 100644
> --- a/tools/perf/arch/x86/util/intel-bts.c
> +++ b/tools/perf/arch/x86/util/intel-bts.c
> @@ -413,23 +413,6 @@ static int intel_bts_find_snapshot(struct auxtrace_record *itr, int idx,
>  	return err;
>  }
>  
> -static int intel_bts_read_finish(struct auxtrace_record *itr, int idx)
> -{
> -	struct intel_bts_recording *btsr =
> -			container_of(itr, struct intel_bts_recording, itr);
> -	struct evsel *evsel;
> -
> -	evlist__for_each_entry(btsr->evlist, evsel) {
> -		if (evsel->core.attr.type == btsr->intel_bts_pmu->type) {
> -			if (evsel->disabled)
> -				return 0;
> -			return perf_evlist__enable_event_idx(btsr->evlist,
> -							     evsel, idx);
> -		}
> -	}
> -	return -EINVAL;
> -}
> -
>  struct auxtrace_record *intel_bts_recording_init(int *err)
>  {
>  	struct perf_pmu *intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME);
> @@ -450,6 +433,7 @@ struct auxtrace_record *intel_bts_recording_init(int *err)
>  	}
>  
>  	btsr->intel_bts_pmu = intel_bts_pmu;
> +	btsr->itr.pmu = intel_bts_pmu;
>  	btsr->itr.recording_options = intel_bts_recording_options;
>  	btsr->itr.info_priv_size = intel_bts_info_priv_size;
>  	btsr->itr.info_fill = intel_bts_info_fill;
> @@ -459,7 +443,7 @@ struct auxtrace_record *intel_bts_recording_init(int *err)
>  	btsr->itr.find_snapshot = intel_bts_find_snapshot;
>  	btsr->itr.parse_snapshot_options = intel_bts_parse_snapshot_options;
>  	btsr->itr.reference = intel_bts_reference;
> -	btsr->itr.read_finish = intel_bts_read_finish;
> +	btsr->itr.read_finish = auxtrace_record__read_finish;
>  	btsr->itr.alignment = sizeof(struct branch);
>  	return &btsr->itr;
>  }
> diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
> index 2f0a0832907f..acadaa10c65d 100644
> --- a/tools/perf/arch/x86/util/intel-pt.c
> +++ b/tools/perf/arch/x86/util/intel-pt.c
> @@ -1170,23 +1170,6 @@ static u64 intel_pt_reference(struct auxtrace_record *itr __maybe_unused)
>  	return rdtsc();
>  }
>  
> -static int intel_pt_read_finish(struct auxtrace_record *itr, int idx)
> -{
> -	struct intel_pt_recording *ptr =
> -			container_of(itr, struct intel_pt_recording, itr);
> -	struct evsel *evsel;
> -
> -	evlist__for_each_entry(ptr->evlist, evsel) {
> -		if (evsel->core.attr.type == ptr->intel_pt_pmu->type) {
> -			if (evsel->disabled)
> -				return 0;
> -			return perf_evlist__enable_event_idx(ptr->evlist, evsel,
> -							     idx);
> -		}
> -	}
> -	return -EINVAL;
> -}
> -
>  struct auxtrace_record *intel_pt_recording_init(int *err)
>  {
>  	struct perf_pmu *intel_pt_pmu = perf_pmu__find(INTEL_PT_PMU_NAME);
> @@ -1207,6 +1190,7 @@ struct auxtrace_record *intel_pt_recording_init(int *err)
>  	}
>  
>  	ptr->intel_pt_pmu = intel_pt_pmu;
> +	ptr->itr.pmu = intel_pt_pmu;
>  	ptr->itr.recording_options = intel_pt_recording_options;
>  	ptr->itr.info_priv_size = intel_pt_info_priv_size;
>  	ptr->itr.info_fill = intel_pt_info_fill;
> @@ -1216,7 +1200,7 @@ struct auxtrace_record *intel_pt_recording_init(int *err)
>  	ptr->itr.find_snapshot = intel_pt_find_snapshot;
>  	ptr->itr.parse_snapshot_options = intel_pt_parse_snapshot_options;
>  	ptr->itr.reference = intel_pt_reference;
> -	ptr->itr.read_finish = intel_pt_read_finish;
> +	ptr->itr.read_finish = auxtrace_record__read_finish;
>  	/*
>  	 * Decoding starts at a PSB packet. Minimum PSB period is 2K so 4K
>  	 * should give at least 1 PSB per sample.
> diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
> index eb087e7df6f4..3571ce72ca28 100644
> --- a/tools/perf/util/auxtrace.c
> +++ b/tools/perf/util/auxtrace.c
> @@ -629,8 +629,10 @@ int auxtrace_record__options(struct auxtrace_record *itr,
>  			     struct evlist *evlist,
>  			     struct record_opts *opts)
>  {
> -	if (itr)
> +	if (itr) {
> +		itr->evlist = evlist;
>  		return itr->recording_options(itr, evlist, opts);
> +	}
>  	return 0;
>  }
>  
> @@ -664,6 +666,24 @@ int auxtrace_parse_snapshot_options(struct auxtrace_record *itr,
>  	return -EINVAL;
>  }
>  
> +int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx)
> +{
> +	struct evsel *evsel;
> +
> +	if (!itr->evlist || !itr->pmu)
> +		return -EINVAL;
> +
> +	evlist__for_each_entry(itr->evlist, evsel) {
> +		if (evsel->core.attr.type == itr->pmu->type) {
> +			if (evsel->disabled)
> +				return 0;
> +			return perf_evlist__enable_event_idx(itr->evlist, evsel,
> +							     idx);
> +		}
> +	}
> +	return -EINVAL;
> +}
> +
>  /*
>   * Event record size is 16-bit which results in a maximum size of about 64KiB.
>   * Allow about 4KiB for the rest of the sample record, to give a maximum
> diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
> index 749d72cd9c7b..e58ef160b599 100644
> --- a/tools/perf/util/auxtrace.h
> +++ b/tools/perf/util/auxtrace.h
> @@ -29,6 +29,7 @@ struct record_opts;
>  struct perf_record_auxtrace_error;
>  struct perf_record_auxtrace_info;
>  struct events_stats;
> +struct perf_pmu;
>  
>  enum auxtrace_error_type {
>         PERF_AUXTRACE_ERROR_ITRACE  = 1,
> @@ -322,6 +323,8 @@ struct auxtrace_mmap_params {
>   * @read_finish: called after reading from an auxtrace mmap
>   * @alignment: alignment (if any) for AUX area data
>   * @default_aux_sample_size: default sample size for --aux sample option
> + * @pmu: associated pmu
> + * @evlist: selected events list
>   */
>  struct auxtrace_record {
>  	int (*recording_options)(struct auxtrace_record *itr,
> @@ -346,6 +349,8 @@ struct auxtrace_record {
>  	int (*read_finish)(struct auxtrace_record *itr, int idx);
>  	unsigned int alignment;
>  	unsigned int default_aux_sample_size;
> +	struct perf_pmu *pmu;
> +	struct evlist *evlist;
>  };
>  
>  /**
> @@ -537,6 +542,7 @@ int auxtrace_record__find_snapshot(struct auxtrace_record *itr, int idx,
>  				   struct auxtrace_mmap *mm,
>  				   unsigned char *data, u64 *head, u64 *old);
>  u64 auxtrace_record__reference(struct auxtrace_record *itr);
> +int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx);
>  
>  int auxtrace_index__auxtrace_event(struct list_head *head, union perf_event *event,
>  				   off_t file_offset);
> -- 
> 2.17.1
> 

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

* Re: [PATCH V2 3/5] perf tools: cs-etm: fix endless record after being terminated
  2020-02-14 13:26 ` [PATCH V2 3/5] perf tools: cs-etm: fix " Adrian Hunter
  2020-02-14 14:07   ` Adrian Hunter
  2020-02-14 14:43   ` Leo Yan
@ 2020-02-14 18:24   ` Mathieu Poirier
  2020-02-26 14:20   ` [tip: perf/urgent] perf cs-etm: Fix " tip-bot2 for Wei Li
  3 siblings, 0 replies; 19+ messages in thread
From: Mathieu Poirier @ 2020-02-14 18:24 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, linux-kernel, Tan Xiaojun, Wei Li

On Fri, Feb 14, 2020 at 03:26:52PM +0200, Adrian Hunter wrote:
> From: Wei Li <liwei391@huawei.com>
> 
> In __cmd_record(), when receiving SIGINT(ctrl + c), a done flag will
> be set and the event list will be disabled by evlist__disable() once.
> 
> While in auxtrace_record.read_finish(), the related events will be
> enabled again, if they are continuous, the recording seems to be endless.
> 
> If the cs_etm event is disabled, we don't enable it again here.
> 
> Note: This patch is NOT tested since i don't have such a machine with
> coresight feature, but the code seems buggy same as arm-spe and intel-pt.
> 
> Signed-off-by: Wei Li <liwei391@huawei.com>
> [ahunter: removed redundant 'else' after 'return']
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> Cc: stable@vger.kernel.org # 5.4+
> ---
>  tools/perf/arch/arm/util/cs-etm.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
> index 2898cfdf8fe1..60141c3007a9 100644
> --- a/tools/perf/arch/arm/util/cs-etm.c
> +++ b/tools/perf/arch/arm/util/cs-etm.c
> @@ -865,9 +865,12 @@ static int cs_etm_read_finish(struct auxtrace_record *itr, int idx)
>  	struct evsel *evsel;
>  
>  	evlist__for_each_entry(ptr->evlist, evsel) {
> -		if (evsel->core.attr.type == ptr->cs_etm_pmu->type)
> +		if (evsel->core.attr.type == ptr->cs_etm_pmu->type) {
> +			if (evsel->disabled)
> +				return 0;
>  			return perf_evlist__enable_event_idx(ptr->evlist,
>  							     evsel, idx);
> +		}

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

>  	}
>  
>  	return -EINVAL;
> -- 
> 2.17.1
> 

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

* Re: [PATCH 5/5] perf auxtrace: Add auxtrace_record__read_finish()
  2020-02-14 13:26 ` [PATCH 5/5] perf auxtrace: Add auxtrace_record__read_finish() Adrian Hunter
  2020-02-14 14:08   ` Adrian Hunter
  2020-02-14 14:48   ` Leo Yan
@ 2020-02-14 18:27   ` Mathieu Poirier
  2 siblings, 0 replies; 19+ messages in thread
From: Mathieu Poirier @ 2020-02-14 18:27 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, linux-kernel, Tan Xiaojun, Wei Li

On Fri, Feb 14, 2020 at 03:26:54PM +0200, Adrian Hunter wrote:
> All ->read_finish() implementations are doing the same thing. Add a
> helper function so that they can share the same implementation.
> 
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
>  tools/perf/arch/arm/util/cs-etm.c    | 21 ++-------------------
>  tools/perf/arch/arm64/util/arm-spe.c | 20 ++------------------
>  tools/perf/arch/x86/util/intel-bts.c | 20 ++------------------
>  tools/perf/arch/x86/util/intel-pt.c  | 20 ++------------------
>  tools/perf/util/auxtrace.c           | 22 +++++++++++++++++++++-
>  tools/perf/util/auxtrace.h           |  6 ++++++
>  6 files changed, 35 insertions(+), 74 deletions(-)
> 
> diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
> index 60141c3007a9..00126e7df465 100644
> --- a/tools/perf/arch/arm/util/cs-etm.c
> +++ b/tools/perf/arch/arm/util/cs-etm.c
> @@ -858,24 +858,6 @@ static void cs_etm_recording_free(struct auxtrace_record *itr)
>  	free(ptr);
>  }
>  
> -static int cs_etm_read_finish(struct auxtrace_record *itr, int idx)
> -{
> -	struct cs_etm_recording *ptr =
> -			container_of(itr, struct cs_etm_recording, itr);
> -	struct evsel *evsel;
> -
> -	evlist__for_each_entry(ptr->evlist, evsel) {
> -		if (evsel->core.attr.type == ptr->cs_etm_pmu->type) {
> -			if (evsel->disabled)
> -				return 0;
> -			return perf_evlist__enable_event_idx(ptr->evlist,
> -							     evsel, idx);
> -		}
> -	}
> -
> -	return -EINVAL;
> -}
> -
>  struct auxtrace_record *cs_etm_record_init(int *err)
>  {
>  	struct perf_pmu *cs_etm_pmu;
> @@ -895,6 +877,7 @@ struct auxtrace_record *cs_etm_record_init(int *err)
>  	}
>  
>  	ptr->cs_etm_pmu			= cs_etm_pmu;
> +	ptr->itr.cs_etm_pmu		= cs_etm_pmu;

As Leo pointed out this won't compile.  With this fixed and for cs-etm.c:

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

>  	ptr->itr.parse_snapshot_options	= cs_etm_parse_snapshot_options;
>  	ptr->itr.recording_options	= cs_etm_recording_options;
>  	ptr->itr.info_priv_size		= cs_etm_info_priv_size;
> @@ -904,7 +887,7 @@ struct auxtrace_record *cs_etm_record_init(int *err)
>  	ptr->itr.snapshot_finish	= cs_etm_snapshot_finish;
>  	ptr->itr.reference		= cs_etm_reference;
>  	ptr->itr.free			= cs_etm_recording_free;
> -	ptr->itr.read_finish		= cs_etm_read_finish;
> +	ptr->itr.read_finish		= auxtrace_record__read_finish;
>  
>  	*err = 0;
>  	return &ptr->itr;
> diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
> index 1d993c27242b..8d6821d9c3f6 100644
> --- a/tools/perf/arch/arm64/util/arm-spe.c
> +++ b/tools/perf/arch/arm64/util/arm-spe.c
> @@ -158,23 +158,6 @@ static void arm_spe_recording_free(struct auxtrace_record *itr)
>  	free(sper);
>  }
>  
> -static int arm_spe_read_finish(struct auxtrace_record *itr, int idx)
> -{
> -	struct arm_spe_recording *sper =
> -			container_of(itr, struct arm_spe_recording, itr);
> -	struct evsel *evsel;
> -
> -	evlist__for_each_entry(sper->evlist, evsel) {
> -		if (evsel->core.attr.type == sper->arm_spe_pmu->type) {
> -			if (evsel->disabled)
> -				return 0;
> -			return perf_evlist__enable_event_idx(sper->evlist,
> -							     evsel, idx);
> -		}
> -	}
> -	return -EINVAL;
> -}
> -
>  struct auxtrace_record *arm_spe_recording_init(int *err,
>  					       struct perf_pmu *arm_spe_pmu)
>  {
> @@ -192,12 +175,13 @@ struct auxtrace_record *arm_spe_recording_init(int *err,
>  	}
>  
>  	sper->arm_spe_pmu = arm_spe_pmu;
> +	sper->itr.pmu = arm_spe_pmu;
>  	sper->itr.recording_options = arm_spe_recording_options;
>  	sper->itr.info_priv_size = arm_spe_info_priv_size;
>  	sper->itr.info_fill = arm_spe_info_fill;
>  	sper->itr.free = arm_spe_recording_free;
>  	sper->itr.reference = arm_spe_reference;
> -	sper->itr.read_finish = arm_spe_read_finish;
> +	sper->itr.read_finish = auxtrace_record__read_finish;
>  	sper->itr.alignment = 0;
>  
>  	*err = 0;
> diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c
> index 39e363151ad7..26cee1052179 100644
> --- a/tools/perf/arch/x86/util/intel-bts.c
> +++ b/tools/perf/arch/x86/util/intel-bts.c
> @@ -413,23 +413,6 @@ static int intel_bts_find_snapshot(struct auxtrace_record *itr, int idx,
>  	return err;
>  }
>  
> -static int intel_bts_read_finish(struct auxtrace_record *itr, int idx)
> -{
> -	struct intel_bts_recording *btsr =
> -			container_of(itr, struct intel_bts_recording, itr);
> -	struct evsel *evsel;
> -
> -	evlist__for_each_entry(btsr->evlist, evsel) {
> -		if (evsel->core.attr.type == btsr->intel_bts_pmu->type) {
> -			if (evsel->disabled)
> -				return 0;
> -			return perf_evlist__enable_event_idx(btsr->evlist,
> -							     evsel, idx);
> -		}
> -	}
> -	return -EINVAL;
> -}
> -
>  struct auxtrace_record *intel_bts_recording_init(int *err)
>  {
>  	struct perf_pmu *intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME);
> @@ -450,6 +433,7 @@ struct auxtrace_record *intel_bts_recording_init(int *err)
>  	}
>  
>  	btsr->intel_bts_pmu = intel_bts_pmu;
> +	btsr->itr.pmu = intel_bts_pmu;
>  	btsr->itr.recording_options = intel_bts_recording_options;
>  	btsr->itr.info_priv_size = intel_bts_info_priv_size;
>  	btsr->itr.info_fill = intel_bts_info_fill;
> @@ -459,7 +443,7 @@ struct auxtrace_record *intel_bts_recording_init(int *err)
>  	btsr->itr.find_snapshot = intel_bts_find_snapshot;
>  	btsr->itr.parse_snapshot_options = intel_bts_parse_snapshot_options;
>  	btsr->itr.reference = intel_bts_reference;
> -	btsr->itr.read_finish = intel_bts_read_finish;
> +	btsr->itr.read_finish = auxtrace_record__read_finish;
>  	btsr->itr.alignment = sizeof(struct branch);
>  	return &btsr->itr;
>  }
> diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
> index 2f0a0832907f..acadaa10c65d 100644
> --- a/tools/perf/arch/x86/util/intel-pt.c
> +++ b/tools/perf/arch/x86/util/intel-pt.c
> @@ -1170,23 +1170,6 @@ static u64 intel_pt_reference(struct auxtrace_record *itr __maybe_unused)
>  	return rdtsc();
>  }
>  
> -static int intel_pt_read_finish(struct auxtrace_record *itr, int idx)
> -{
> -	struct intel_pt_recording *ptr =
> -			container_of(itr, struct intel_pt_recording, itr);
> -	struct evsel *evsel;
> -
> -	evlist__for_each_entry(ptr->evlist, evsel) {
> -		if (evsel->core.attr.type == ptr->intel_pt_pmu->type) {
> -			if (evsel->disabled)
> -				return 0;
> -			return perf_evlist__enable_event_idx(ptr->evlist, evsel,
> -							     idx);
> -		}
> -	}
> -	return -EINVAL;
> -}
> -
>  struct auxtrace_record *intel_pt_recording_init(int *err)
>  {
>  	struct perf_pmu *intel_pt_pmu = perf_pmu__find(INTEL_PT_PMU_NAME);
> @@ -1207,6 +1190,7 @@ struct auxtrace_record *intel_pt_recording_init(int *err)
>  	}
>  
>  	ptr->intel_pt_pmu = intel_pt_pmu;
> +	ptr->itr.pmu = intel_pt_pmu;
>  	ptr->itr.recording_options = intel_pt_recording_options;
>  	ptr->itr.info_priv_size = intel_pt_info_priv_size;
>  	ptr->itr.info_fill = intel_pt_info_fill;
> @@ -1216,7 +1200,7 @@ struct auxtrace_record *intel_pt_recording_init(int *err)
>  	ptr->itr.find_snapshot = intel_pt_find_snapshot;
>  	ptr->itr.parse_snapshot_options = intel_pt_parse_snapshot_options;
>  	ptr->itr.reference = intel_pt_reference;
> -	ptr->itr.read_finish = intel_pt_read_finish;
> +	ptr->itr.read_finish = auxtrace_record__read_finish;
>  	/*
>  	 * Decoding starts at a PSB packet. Minimum PSB period is 2K so 4K
>  	 * should give at least 1 PSB per sample.
> diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
> index eb087e7df6f4..3571ce72ca28 100644
> --- a/tools/perf/util/auxtrace.c
> +++ b/tools/perf/util/auxtrace.c
> @@ -629,8 +629,10 @@ int auxtrace_record__options(struct auxtrace_record *itr,
>  			     struct evlist *evlist,
>  			     struct record_opts *opts)
>  {
> -	if (itr)
> +	if (itr) {
> +		itr->evlist = evlist;
>  		return itr->recording_options(itr, evlist, opts);
> +	}
>  	return 0;
>  }
>  
> @@ -664,6 +666,24 @@ int auxtrace_parse_snapshot_options(struct auxtrace_record *itr,
>  	return -EINVAL;
>  }
>  
> +int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx)
> +{
> +	struct evsel *evsel;
> +
> +	if (!itr->evlist || !itr->pmu)
> +		return -EINVAL;
> +
> +	evlist__for_each_entry(itr->evlist, evsel) {
> +		if (evsel->core.attr.type == itr->pmu->type) {
> +			if (evsel->disabled)
> +				return 0;
> +			return perf_evlist__enable_event_idx(itr->evlist, evsel,
> +							     idx);
> +		}
> +	}
> +	return -EINVAL;
> +}
> +
>  /*
>   * Event record size is 16-bit which results in a maximum size of about 64KiB.
>   * Allow about 4KiB for the rest of the sample record, to give a maximum
> diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
> index 749d72cd9c7b..e58ef160b599 100644
> --- a/tools/perf/util/auxtrace.h
> +++ b/tools/perf/util/auxtrace.h
> @@ -29,6 +29,7 @@ struct record_opts;
>  struct perf_record_auxtrace_error;
>  struct perf_record_auxtrace_info;
>  struct events_stats;
> +struct perf_pmu;
>  
>  enum auxtrace_error_type {
>         PERF_AUXTRACE_ERROR_ITRACE  = 1,
> @@ -322,6 +323,8 @@ struct auxtrace_mmap_params {
>   * @read_finish: called after reading from an auxtrace mmap
>   * @alignment: alignment (if any) for AUX area data
>   * @default_aux_sample_size: default sample size for --aux sample option
> + * @pmu: associated pmu
> + * @evlist: selected events list
>   */
>  struct auxtrace_record {
>  	int (*recording_options)(struct auxtrace_record *itr,
> @@ -346,6 +349,8 @@ struct auxtrace_record {
>  	int (*read_finish)(struct auxtrace_record *itr, int idx);
>  	unsigned int alignment;
>  	unsigned int default_aux_sample_size;
> +	struct perf_pmu *pmu;
> +	struct evlist *evlist;
>  };
>  
>  /**
> @@ -537,6 +542,7 @@ int auxtrace_record__find_snapshot(struct auxtrace_record *itr, int idx,
>  				   struct auxtrace_mmap *mm,
>  				   unsigned char *data, u64 *head, u64 *old);
>  u64 auxtrace_record__reference(struct auxtrace_record *itr);
> +int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx);
>  
>  int auxtrace_index__auxtrace_event(struct list_head *head, union perf_event *event,
>  				   off_t file_offset);
> -- 
> 2.17.1
> 

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

* [PATCH V2 5/5] perf auxtrace: Add auxtrace_record__read_finish()
  2020-02-14 14:48   ` Leo Yan
@ 2020-02-17  8:23     ` Adrian Hunter
  2020-02-17 14:42       ` Arnaldo Carvalho de Melo
  2020-02-26 14:20       ` [tip: perf/urgent] " tip-bot2 for Adrian Hunter
  0 siblings, 2 replies; 19+ messages in thread
From: Adrian Hunter @ 2020-02-17  8:23 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jiri Olsa, linux-kernel, Wei Li, Leo Yan, Mathieu Poirier, Kim Phillips

All ->read_finish() implementations are doing the same thing. Add a
helper function so that they can share the same implementation.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Reviewed-and-Tested-by: Leo Yan <leo.yan@linaro.org>
Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
---


Changes in V2:

	Change ptr->itr.cs_etm_pmu to ptr->itr.pmu


 tools/perf/arch/arm/util/cs-etm.c    | 21 ++-------------------
 tools/perf/arch/arm64/util/arm-spe.c | 20 ++------------------
 tools/perf/arch/x86/util/intel-bts.c | 20 ++------------------
 tools/perf/arch/x86/util/intel-pt.c  | 20 ++------------------
 tools/perf/util/auxtrace.c           | 22 +++++++++++++++++++++-
 tools/perf/util/auxtrace.h           |  6 ++++++
 6 files changed, 35 insertions(+), 74 deletions(-)

diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
index 60141c3007a9..941f814820b8 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -858,24 +858,6 @@ static void cs_etm_recording_free(struct auxtrace_record *itr)
 	free(ptr);
 }
 
-static int cs_etm_read_finish(struct auxtrace_record *itr, int idx)
-{
-	struct cs_etm_recording *ptr =
-			container_of(itr, struct cs_etm_recording, itr);
-	struct evsel *evsel;
-
-	evlist__for_each_entry(ptr->evlist, evsel) {
-		if (evsel->core.attr.type == ptr->cs_etm_pmu->type) {
-			if (evsel->disabled)
-				return 0;
-			return perf_evlist__enable_event_idx(ptr->evlist,
-							     evsel, idx);
-		}
-	}
-
-	return -EINVAL;
-}
-
 struct auxtrace_record *cs_etm_record_init(int *err)
 {
 	struct perf_pmu *cs_etm_pmu;
@@ -895,6 +877,7 @@ struct auxtrace_record *cs_etm_record_init(int *err)
 	}
 
 	ptr->cs_etm_pmu			= cs_etm_pmu;
+	ptr->itr.pmu			= cs_etm_pmu;
 	ptr->itr.parse_snapshot_options	= cs_etm_parse_snapshot_options;
 	ptr->itr.recording_options	= cs_etm_recording_options;
 	ptr->itr.info_priv_size		= cs_etm_info_priv_size;
@@ -904,7 +887,7 @@ struct auxtrace_record *cs_etm_record_init(int *err)
 	ptr->itr.snapshot_finish	= cs_etm_snapshot_finish;
 	ptr->itr.reference		= cs_etm_reference;
 	ptr->itr.free			= cs_etm_recording_free;
-	ptr->itr.read_finish		= cs_etm_read_finish;
+	ptr->itr.read_finish		= auxtrace_record__read_finish;
 
 	*err = 0;
 	return &ptr->itr;
diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
index 1d993c27242b..8d6821d9c3f6 100644
--- a/tools/perf/arch/arm64/util/arm-spe.c
+++ b/tools/perf/arch/arm64/util/arm-spe.c
@@ -158,23 +158,6 @@ static void arm_spe_recording_free(struct auxtrace_record *itr)
 	free(sper);
 }
 
-static int arm_spe_read_finish(struct auxtrace_record *itr, int idx)
-{
-	struct arm_spe_recording *sper =
-			container_of(itr, struct arm_spe_recording, itr);
-	struct evsel *evsel;
-
-	evlist__for_each_entry(sper->evlist, evsel) {
-		if (evsel->core.attr.type == sper->arm_spe_pmu->type) {
-			if (evsel->disabled)
-				return 0;
-			return perf_evlist__enable_event_idx(sper->evlist,
-							     evsel, idx);
-		}
-	}
-	return -EINVAL;
-}
-
 struct auxtrace_record *arm_spe_recording_init(int *err,
 					       struct perf_pmu *arm_spe_pmu)
 {
@@ -192,12 +175,13 @@ struct auxtrace_record *arm_spe_recording_init(int *err,
 	}
 
 	sper->arm_spe_pmu = arm_spe_pmu;
+	sper->itr.pmu = arm_spe_pmu;
 	sper->itr.recording_options = arm_spe_recording_options;
 	sper->itr.info_priv_size = arm_spe_info_priv_size;
 	sper->itr.info_fill = arm_spe_info_fill;
 	sper->itr.free = arm_spe_recording_free;
 	sper->itr.reference = arm_spe_reference;
-	sper->itr.read_finish = arm_spe_read_finish;
+	sper->itr.read_finish = auxtrace_record__read_finish;
 	sper->itr.alignment = 0;
 
 	*err = 0;
diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c
index 39e363151ad7..26cee1052179 100644
--- a/tools/perf/arch/x86/util/intel-bts.c
+++ b/tools/perf/arch/x86/util/intel-bts.c
@@ -413,23 +413,6 @@ static int intel_bts_find_snapshot(struct auxtrace_record *itr, int idx,
 	return err;
 }
 
-static int intel_bts_read_finish(struct auxtrace_record *itr, int idx)
-{
-	struct intel_bts_recording *btsr =
-			container_of(itr, struct intel_bts_recording, itr);
-	struct evsel *evsel;
-
-	evlist__for_each_entry(btsr->evlist, evsel) {
-		if (evsel->core.attr.type == btsr->intel_bts_pmu->type) {
-			if (evsel->disabled)
-				return 0;
-			return perf_evlist__enable_event_idx(btsr->evlist,
-							     evsel, idx);
-		}
-	}
-	return -EINVAL;
-}
-
 struct auxtrace_record *intel_bts_recording_init(int *err)
 {
 	struct perf_pmu *intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME);
@@ -450,6 +433,7 @@ struct auxtrace_record *intel_bts_recording_init(int *err)
 	}
 
 	btsr->intel_bts_pmu = intel_bts_pmu;
+	btsr->itr.pmu = intel_bts_pmu;
 	btsr->itr.recording_options = intel_bts_recording_options;
 	btsr->itr.info_priv_size = intel_bts_info_priv_size;
 	btsr->itr.info_fill = intel_bts_info_fill;
@@ -459,7 +443,7 @@ struct auxtrace_record *intel_bts_recording_init(int *err)
 	btsr->itr.find_snapshot = intel_bts_find_snapshot;
 	btsr->itr.parse_snapshot_options = intel_bts_parse_snapshot_options;
 	btsr->itr.reference = intel_bts_reference;
-	btsr->itr.read_finish = intel_bts_read_finish;
+	btsr->itr.read_finish = auxtrace_record__read_finish;
 	btsr->itr.alignment = sizeof(struct branch);
 	return &btsr->itr;
 }
diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index 2f0a0832907f..acadaa10c65d 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -1170,23 +1170,6 @@ static u64 intel_pt_reference(struct auxtrace_record *itr __maybe_unused)
 	return rdtsc();
 }
 
-static int intel_pt_read_finish(struct auxtrace_record *itr, int idx)
-{
-	struct intel_pt_recording *ptr =
-			container_of(itr, struct intel_pt_recording, itr);
-	struct evsel *evsel;
-
-	evlist__for_each_entry(ptr->evlist, evsel) {
-		if (evsel->core.attr.type == ptr->intel_pt_pmu->type) {
-			if (evsel->disabled)
-				return 0;
-			return perf_evlist__enable_event_idx(ptr->evlist, evsel,
-							     idx);
-		}
-	}
-	return -EINVAL;
-}
-
 struct auxtrace_record *intel_pt_recording_init(int *err)
 {
 	struct perf_pmu *intel_pt_pmu = perf_pmu__find(INTEL_PT_PMU_NAME);
@@ -1207,6 +1190,7 @@ struct auxtrace_record *intel_pt_recording_init(int *err)
 	}
 
 	ptr->intel_pt_pmu = intel_pt_pmu;
+	ptr->itr.pmu = intel_pt_pmu;
 	ptr->itr.recording_options = intel_pt_recording_options;
 	ptr->itr.info_priv_size = intel_pt_info_priv_size;
 	ptr->itr.info_fill = intel_pt_info_fill;
@@ -1216,7 +1200,7 @@ struct auxtrace_record *intel_pt_recording_init(int *err)
 	ptr->itr.find_snapshot = intel_pt_find_snapshot;
 	ptr->itr.parse_snapshot_options = intel_pt_parse_snapshot_options;
 	ptr->itr.reference = intel_pt_reference;
-	ptr->itr.read_finish = intel_pt_read_finish;
+	ptr->itr.read_finish = auxtrace_record__read_finish;
 	/*
 	 * Decoding starts at a PSB packet. Minimum PSB period is 2K so 4K
 	 * should give at least 1 PSB per sample.
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index eb087e7df6f4..3571ce72ca28 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -629,8 +629,10 @@ int auxtrace_record__options(struct auxtrace_record *itr,
 			     struct evlist *evlist,
 			     struct record_opts *opts)
 {
-	if (itr)
+	if (itr) {
+		itr->evlist = evlist;
 		return itr->recording_options(itr, evlist, opts);
+	}
 	return 0;
 }
 
@@ -664,6 +666,24 @@ int auxtrace_parse_snapshot_options(struct auxtrace_record *itr,
 	return -EINVAL;
 }
 
+int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx)
+{
+	struct evsel *evsel;
+
+	if (!itr->evlist || !itr->pmu)
+		return -EINVAL;
+
+	evlist__for_each_entry(itr->evlist, evsel) {
+		if (evsel->core.attr.type == itr->pmu->type) {
+			if (evsel->disabled)
+				return 0;
+			return perf_evlist__enable_event_idx(itr->evlist, evsel,
+							     idx);
+		}
+	}
+	return -EINVAL;
+}
+
 /*
  * Event record size is 16-bit which results in a maximum size of about 64KiB.
  * Allow about 4KiB for the rest of the sample record, to give a maximum
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 749d72cd9c7b..e58ef160b599 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -29,6 +29,7 @@ struct record_opts;
 struct perf_record_auxtrace_error;
 struct perf_record_auxtrace_info;
 struct events_stats;
+struct perf_pmu;
 
 enum auxtrace_error_type {
        PERF_AUXTRACE_ERROR_ITRACE  = 1,
@@ -322,6 +323,8 @@ struct auxtrace_mmap_params {
  * @read_finish: called after reading from an auxtrace mmap
  * @alignment: alignment (if any) for AUX area data
  * @default_aux_sample_size: default sample size for --aux sample option
+ * @pmu: associated pmu
+ * @evlist: selected events list
  */
 struct auxtrace_record {
 	int (*recording_options)(struct auxtrace_record *itr,
@@ -346,6 +349,8 @@ struct auxtrace_record {
 	int (*read_finish)(struct auxtrace_record *itr, int idx);
 	unsigned int alignment;
 	unsigned int default_aux_sample_size;
+	struct perf_pmu *pmu;
+	struct evlist *evlist;
 };
 
 /**
@@ -537,6 +542,7 @@ int auxtrace_record__find_snapshot(struct auxtrace_record *itr, int idx,
 				   struct auxtrace_mmap *mm,
 				   unsigned char *data, u64 *head, u64 *old);
 u64 auxtrace_record__reference(struct auxtrace_record *itr);
+int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx);
 
 int auxtrace_index__auxtrace_event(struct list_head *head, union perf_event *event,
 				   off_t file_offset);
-- 
2.17.1


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

* Re: [PATCH V2 5/5] perf auxtrace: Add auxtrace_record__read_finish()
  2020-02-17  8:23     ` [PATCH V2 " Adrian Hunter
@ 2020-02-17 14:42       ` Arnaldo Carvalho de Melo
  2020-02-26 14:20       ` [tip: perf/urgent] " tip-bot2 for Adrian Hunter
  1 sibling, 0 replies; 19+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-02-17 14:42 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: Jiri Olsa, linux-kernel, Wei Li, Leo Yan, Mathieu Poirier, Kim Phillips

Em Mon, Feb 17, 2020 at 10:23:00AM +0200, Adrian Hunter escreveu:
> All ->read_finish() implementations are doing the same thing. Add a
> helper function so that they can share the same implementation.
> 
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> Reviewed-and-Tested-by: Leo Yan <leo.yan@linaro.org>
> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> ---
> 
> 
> Changes in V2:
> 
> 	Change ptr->itr.cs_etm_pmu to ptr->itr.pmu

Series applied to perf/urgent, thanks,

- Arnaldo
 
> 
>  tools/perf/arch/arm/util/cs-etm.c    | 21 ++-------------------
>  tools/perf/arch/arm64/util/arm-spe.c | 20 ++------------------
>  tools/perf/arch/x86/util/intel-bts.c | 20 ++------------------
>  tools/perf/arch/x86/util/intel-pt.c  | 20 ++------------------
>  tools/perf/util/auxtrace.c           | 22 +++++++++++++++++++++-
>  tools/perf/util/auxtrace.h           |  6 ++++++
>  6 files changed, 35 insertions(+), 74 deletions(-)
> 
> diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
> index 60141c3007a9..941f814820b8 100644
> --- a/tools/perf/arch/arm/util/cs-etm.c
> +++ b/tools/perf/arch/arm/util/cs-etm.c
> @@ -858,24 +858,6 @@ static void cs_etm_recording_free(struct auxtrace_record *itr)
>  	free(ptr);
>  }
>  
> -static int cs_etm_read_finish(struct auxtrace_record *itr, int idx)
> -{
> -	struct cs_etm_recording *ptr =
> -			container_of(itr, struct cs_etm_recording, itr);
> -	struct evsel *evsel;
> -
> -	evlist__for_each_entry(ptr->evlist, evsel) {
> -		if (evsel->core.attr.type == ptr->cs_etm_pmu->type) {
> -			if (evsel->disabled)
> -				return 0;
> -			return perf_evlist__enable_event_idx(ptr->evlist,
> -							     evsel, idx);
> -		}
> -	}
> -
> -	return -EINVAL;
> -}
> -
>  struct auxtrace_record *cs_etm_record_init(int *err)
>  {
>  	struct perf_pmu *cs_etm_pmu;
> @@ -895,6 +877,7 @@ struct auxtrace_record *cs_etm_record_init(int *err)
>  	}
>  
>  	ptr->cs_etm_pmu			= cs_etm_pmu;
> +	ptr->itr.pmu			= cs_etm_pmu;
>  	ptr->itr.parse_snapshot_options	= cs_etm_parse_snapshot_options;
>  	ptr->itr.recording_options	= cs_etm_recording_options;
>  	ptr->itr.info_priv_size		= cs_etm_info_priv_size;
> @@ -904,7 +887,7 @@ struct auxtrace_record *cs_etm_record_init(int *err)
>  	ptr->itr.snapshot_finish	= cs_etm_snapshot_finish;
>  	ptr->itr.reference		= cs_etm_reference;
>  	ptr->itr.free			= cs_etm_recording_free;
> -	ptr->itr.read_finish		= cs_etm_read_finish;
> +	ptr->itr.read_finish		= auxtrace_record__read_finish;
>  
>  	*err = 0;
>  	return &ptr->itr;
> diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
> index 1d993c27242b..8d6821d9c3f6 100644
> --- a/tools/perf/arch/arm64/util/arm-spe.c
> +++ b/tools/perf/arch/arm64/util/arm-spe.c
> @@ -158,23 +158,6 @@ static void arm_spe_recording_free(struct auxtrace_record *itr)
>  	free(sper);
>  }
>  
> -static int arm_spe_read_finish(struct auxtrace_record *itr, int idx)
> -{
> -	struct arm_spe_recording *sper =
> -			container_of(itr, struct arm_spe_recording, itr);
> -	struct evsel *evsel;
> -
> -	evlist__for_each_entry(sper->evlist, evsel) {
> -		if (evsel->core.attr.type == sper->arm_spe_pmu->type) {
> -			if (evsel->disabled)
> -				return 0;
> -			return perf_evlist__enable_event_idx(sper->evlist,
> -							     evsel, idx);
> -		}
> -	}
> -	return -EINVAL;
> -}
> -
>  struct auxtrace_record *arm_spe_recording_init(int *err,
>  					       struct perf_pmu *arm_spe_pmu)
>  {
> @@ -192,12 +175,13 @@ struct auxtrace_record *arm_spe_recording_init(int *err,
>  	}
>  
>  	sper->arm_spe_pmu = arm_spe_pmu;
> +	sper->itr.pmu = arm_spe_pmu;
>  	sper->itr.recording_options = arm_spe_recording_options;
>  	sper->itr.info_priv_size = arm_spe_info_priv_size;
>  	sper->itr.info_fill = arm_spe_info_fill;
>  	sper->itr.free = arm_spe_recording_free;
>  	sper->itr.reference = arm_spe_reference;
> -	sper->itr.read_finish = arm_spe_read_finish;
> +	sper->itr.read_finish = auxtrace_record__read_finish;
>  	sper->itr.alignment = 0;
>  
>  	*err = 0;
> diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c
> index 39e363151ad7..26cee1052179 100644
> --- a/tools/perf/arch/x86/util/intel-bts.c
> +++ b/tools/perf/arch/x86/util/intel-bts.c
> @@ -413,23 +413,6 @@ static int intel_bts_find_snapshot(struct auxtrace_record *itr, int idx,
>  	return err;
>  }
>  
> -static int intel_bts_read_finish(struct auxtrace_record *itr, int idx)
> -{
> -	struct intel_bts_recording *btsr =
> -			container_of(itr, struct intel_bts_recording, itr);
> -	struct evsel *evsel;
> -
> -	evlist__for_each_entry(btsr->evlist, evsel) {
> -		if (evsel->core.attr.type == btsr->intel_bts_pmu->type) {
> -			if (evsel->disabled)
> -				return 0;
> -			return perf_evlist__enable_event_idx(btsr->evlist,
> -							     evsel, idx);
> -		}
> -	}
> -	return -EINVAL;
> -}
> -
>  struct auxtrace_record *intel_bts_recording_init(int *err)
>  {
>  	struct perf_pmu *intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME);
> @@ -450,6 +433,7 @@ struct auxtrace_record *intel_bts_recording_init(int *err)
>  	}
>  
>  	btsr->intel_bts_pmu = intel_bts_pmu;
> +	btsr->itr.pmu = intel_bts_pmu;
>  	btsr->itr.recording_options = intel_bts_recording_options;
>  	btsr->itr.info_priv_size = intel_bts_info_priv_size;
>  	btsr->itr.info_fill = intel_bts_info_fill;
> @@ -459,7 +443,7 @@ struct auxtrace_record *intel_bts_recording_init(int *err)
>  	btsr->itr.find_snapshot = intel_bts_find_snapshot;
>  	btsr->itr.parse_snapshot_options = intel_bts_parse_snapshot_options;
>  	btsr->itr.reference = intel_bts_reference;
> -	btsr->itr.read_finish = intel_bts_read_finish;
> +	btsr->itr.read_finish = auxtrace_record__read_finish;
>  	btsr->itr.alignment = sizeof(struct branch);
>  	return &btsr->itr;
>  }
> diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
> index 2f0a0832907f..acadaa10c65d 100644
> --- a/tools/perf/arch/x86/util/intel-pt.c
> +++ b/tools/perf/arch/x86/util/intel-pt.c
> @@ -1170,23 +1170,6 @@ static u64 intel_pt_reference(struct auxtrace_record *itr __maybe_unused)
>  	return rdtsc();
>  }
>  
> -static int intel_pt_read_finish(struct auxtrace_record *itr, int idx)
> -{
> -	struct intel_pt_recording *ptr =
> -			container_of(itr, struct intel_pt_recording, itr);
> -	struct evsel *evsel;
> -
> -	evlist__for_each_entry(ptr->evlist, evsel) {
> -		if (evsel->core.attr.type == ptr->intel_pt_pmu->type) {
> -			if (evsel->disabled)
> -				return 0;
> -			return perf_evlist__enable_event_idx(ptr->evlist, evsel,
> -							     idx);
> -		}
> -	}
> -	return -EINVAL;
> -}
> -
>  struct auxtrace_record *intel_pt_recording_init(int *err)
>  {
>  	struct perf_pmu *intel_pt_pmu = perf_pmu__find(INTEL_PT_PMU_NAME);
> @@ -1207,6 +1190,7 @@ struct auxtrace_record *intel_pt_recording_init(int *err)
>  	}
>  
>  	ptr->intel_pt_pmu = intel_pt_pmu;
> +	ptr->itr.pmu = intel_pt_pmu;
>  	ptr->itr.recording_options = intel_pt_recording_options;
>  	ptr->itr.info_priv_size = intel_pt_info_priv_size;
>  	ptr->itr.info_fill = intel_pt_info_fill;
> @@ -1216,7 +1200,7 @@ struct auxtrace_record *intel_pt_recording_init(int *err)
>  	ptr->itr.find_snapshot = intel_pt_find_snapshot;
>  	ptr->itr.parse_snapshot_options = intel_pt_parse_snapshot_options;
>  	ptr->itr.reference = intel_pt_reference;
> -	ptr->itr.read_finish = intel_pt_read_finish;
> +	ptr->itr.read_finish = auxtrace_record__read_finish;
>  	/*
>  	 * Decoding starts at a PSB packet. Minimum PSB period is 2K so 4K
>  	 * should give at least 1 PSB per sample.
> diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
> index eb087e7df6f4..3571ce72ca28 100644
> --- a/tools/perf/util/auxtrace.c
> +++ b/tools/perf/util/auxtrace.c
> @@ -629,8 +629,10 @@ int auxtrace_record__options(struct auxtrace_record *itr,
>  			     struct evlist *evlist,
>  			     struct record_opts *opts)
>  {
> -	if (itr)
> +	if (itr) {
> +		itr->evlist = evlist;
>  		return itr->recording_options(itr, evlist, opts);
> +	}
>  	return 0;
>  }
>  
> @@ -664,6 +666,24 @@ int auxtrace_parse_snapshot_options(struct auxtrace_record *itr,
>  	return -EINVAL;
>  }
>  
> +int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx)
> +{
> +	struct evsel *evsel;
> +
> +	if (!itr->evlist || !itr->pmu)
> +		return -EINVAL;
> +
> +	evlist__for_each_entry(itr->evlist, evsel) {
> +		if (evsel->core.attr.type == itr->pmu->type) {
> +			if (evsel->disabled)
> +				return 0;
> +			return perf_evlist__enable_event_idx(itr->evlist, evsel,
> +							     idx);
> +		}
> +	}
> +	return -EINVAL;
> +}
> +
>  /*
>   * Event record size is 16-bit which results in a maximum size of about 64KiB.
>   * Allow about 4KiB for the rest of the sample record, to give a maximum
> diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
> index 749d72cd9c7b..e58ef160b599 100644
> --- a/tools/perf/util/auxtrace.h
> +++ b/tools/perf/util/auxtrace.h
> @@ -29,6 +29,7 @@ struct record_opts;
>  struct perf_record_auxtrace_error;
>  struct perf_record_auxtrace_info;
>  struct events_stats;
> +struct perf_pmu;
>  
>  enum auxtrace_error_type {
>         PERF_AUXTRACE_ERROR_ITRACE  = 1,
> @@ -322,6 +323,8 @@ struct auxtrace_mmap_params {
>   * @read_finish: called after reading from an auxtrace mmap
>   * @alignment: alignment (if any) for AUX area data
>   * @default_aux_sample_size: default sample size for --aux sample option
> + * @pmu: associated pmu
> + * @evlist: selected events list
>   */
>  struct auxtrace_record {
>  	int (*recording_options)(struct auxtrace_record *itr,
> @@ -346,6 +349,8 @@ struct auxtrace_record {
>  	int (*read_finish)(struct auxtrace_record *itr, int idx);
>  	unsigned int alignment;
>  	unsigned int default_aux_sample_size;
> +	struct perf_pmu *pmu;
> +	struct evlist *evlist;
>  };
>  
>  /**
> @@ -537,6 +542,7 @@ int auxtrace_record__find_snapshot(struct auxtrace_record *itr, int idx,
>  				   struct auxtrace_mmap *mm,
>  				   unsigned char *data, u64 *head, u64 *old);
>  u64 auxtrace_record__reference(struct auxtrace_record *itr);
> +int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx);
>  
>  int auxtrace_index__auxtrace_event(struct list_head *head, union perf_event *event,
>  				   off_t file_offset);
> -- 
> 2.17.1
> 

-- 

- Arnaldo

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

* [tip: perf/urgent] perf arm-spe: Fix endless record after being terminated
  2020-02-14 13:26 ` [PATCH 4/5] perf tools: arm-spe: fix " Adrian Hunter
@ 2020-02-26 14:20   ` tip-bot2 for Adrian Hunter
  0 siblings, 0 replies; 19+ messages in thread
From: tip-bot2 for Adrian Hunter @ 2020-02-26 14:20 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Adrian Hunter, Jiri Olsa, Tan Xiaojun, stable, #, 5.4+,
	Arnaldo Carvalho de Melo, x86, LKML

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     d6bc34c5ec18c3544c4b0d85963768dfbcd24184
Gitweb:        https://git.kernel.org/tip/d6bc34c5ec18c3544c4b0d85963768dfbcd24184
Author:        Adrian Hunter <adrian.hunter@intel.com>
AuthorDate:    Fri, 14 Feb 2020 15:26:53 +02:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Tue, 18 Feb 2020 10:13:29 -03:00

perf arm-spe: Fix endless record after being terminated

In __cmd_record(), when receiving SIGINT(ctrl + c), a 'done' flag will
be set and the event list will be disabled by evlist__disable() once.

While in auxtrace_record.read_finish(), the related events will be
enabled again, if they are continuous, the recording seems to be
endless.

If the event is disabled, don't enable it again here.

Based-on-patch-by: Wei Li <liwei391@huawei.com>
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Tan Xiaojun <tanxiaojun@huawei.com>
Cc: stable@vger.kernel.org # 5.4+
Link: http://lore.kernel.org/lkml/20200214132654.20395-5-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/arch/arm64/util/arm-spe.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
index eba6541..1d993c2 100644
--- a/tools/perf/arch/arm64/util/arm-spe.c
+++ b/tools/perf/arch/arm64/util/arm-spe.c
@@ -165,9 +165,12 @@ static int arm_spe_read_finish(struct auxtrace_record *itr, int idx)
 	struct evsel *evsel;
 
 	evlist__for_each_entry(sper->evlist, evsel) {
-		if (evsel->core.attr.type == sper->arm_spe_pmu->type)
+		if (evsel->core.attr.type == sper->arm_spe_pmu->type) {
+			if (evsel->disabled)
+				return 0;
 			return perf_evlist__enable_event_idx(sper->evlist,
 							     evsel, idx);
+		}
 	}
 	return -EINVAL;
 }

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

* [tip: perf/urgent] perf auxtrace: Add auxtrace_record__read_finish()
  2020-02-17  8:23     ` [PATCH V2 " Adrian Hunter
  2020-02-17 14:42       ` Arnaldo Carvalho de Melo
@ 2020-02-26 14:20       ` tip-bot2 for Adrian Hunter
  1 sibling, 0 replies; 19+ messages in thread
From: tip-bot2 for Adrian Hunter @ 2020-02-26 14:20 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Adrian Hunter, Leo Yan, Mathieu Poirier, Jiri Olsa, Kim Phillips,
	Wei Li, Arnaldo Carvalho de Melo, x86, LKML

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     ad60ba0c2e6da6ff573c5ac57708fbc443bbb473
Gitweb:        https://git.kernel.org/tip/ad60ba0c2e6da6ff573c5ac57708fbc443bbb473
Author:        Adrian Hunter <adrian.hunter@intel.com>
AuthorDate:    Mon, 17 Feb 2020 10:23:00 +02:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Tue, 18 Feb 2020 10:13:29 -03:00

perf auxtrace: Add auxtrace_record__read_finish()

All ->read_finish() implementations are doing the same thing. Add a
helper function so that they can share the same implementation.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Reviewed-by: Leo Yan <leo.yan@linaro.org>
Tested-by: Leo Yan <leo.yan@linaro.org>
Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Kim Phillips <kim.phillips@arm.com>
Cc: Wei Li <liwei391@huawei.com>
Link: http://lore.kernel.org/lkml/20200217082300.6301-1-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/arch/arm/util/cs-etm.c    | 21 ++-------------------
 tools/perf/arch/arm64/util/arm-spe.c | 20 ++------------------
 tools/perf/arch/x86/util/intel-bts.c | 20 ++------------------
 tools/perf/arch/x86/util/intel-pt.c  | 20 ++------------------
 tools/perf/util/auxtrace.c           | 22 +++++++++++++++++++++-
 tools/perf/util/auxtrace.h           |  6 ++++++
 6 files changed, 35 insertions(+), 74 deletions(-)

diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
index 60141c3..941f814 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -858,24 +858,6 @@ static void cs_etm_recording_free(struct auxtrace_record *itr)
 	free(ptr);
 }
 
-static int cs_etm_read_finish(struct auxtrace_record *itr, int idx)
-{
-	struct cs_etm_recording *ptr =
-			container_of(itr, struct cs_etm_recording, itr);
-	struct evsel *evsel;
-
-	evlist__for_each_entry(ptr->evlist, evsel) {
-		if (evsel->core.attr.type == ptr->cs_etm_pmu->type) {
-			if (evsel->disabled)
-				return 0;
-			return perf_evlist__enable_event_idx(ptr->evlist,
-							     evsel, idx);
-		}
-	}
-
-	return -EINVAL;
-}
-
 struct auxtrace_record *cs_etm_record_init(int *err)
 {
 	struct perf_pmu *cs_etm_pmu;
@@ -895,6 +877,7 @@ struct auxtrace_record *cs_etm_record_init(int *err)
 	}
 
 	ptr->cs_etm_pmu			= cs_etm_pmu;
+	ptr->itr.pmu			= cs_etm_pmu;
 	ptr->itr.parse_snapshot_options	= cs_etm_parse_snapshot_options;
 	ptr->itr.recording_options	= cs_etm_recording_options;
 	ptr->itr.info_priv_size		= cs_etm_info_priv_size;
@@ -904,7 +887,7 @@ struct auxtrace_record *cs_etm_record_init(int *err)
 	ptr->itr.snapshot_finish	= cs_etm_snapshot_finish;
 	ptr->itr.reference		= cs_etm_reference;
 	ptr->itr.free			= cs_etm_recording_free;
-	ptr->itr.read_finish		= cs_etm_read_finish;
+	ptr->itr.read_finish		= auxtrace_record__read_finish;
 
 	*err = 0;
 	return &ptr->itr;
diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
index 1d993c2..8d6821d 100644
--- a/tools/perf/arch/arm64/util/arm-spe.c
+++ b/tools/perf/arch/arm64/util/arm-spe.c
@@ -158,23 +158,6 @@ static void arm_spe_recording_free(struct auxtrace_record *itr)
 	free(sper);
 }
 
-static int arm_spe_read_finish(struct auxtrace_record *itr, int idx)
-{
-	struct arm_spe_recording *sper =
-			container_of(itr, struct arm_spe_recording, itr);
-	struct evsel *evsel;
-
-	evlist__for_each_entry(sper->evlist, evsel) {
-		if (evsel->core.attr.type == sper->arm_spe_pmu->type) {
-			if (evsel->disabled)
-				return 0;
-			return perf_evlist__enable_event_idx(sper->evlist,
-							     evsel, idx);
-		}
-	}
-	return -EINVAL;
-}
-
 struct auxtrace_record *arm_spe_recording_init(int *err,
 					       struct perf_pmu *arm_spe_pmu)
 {
@@ -192,12 +175,13 @@ struct auxtrace_record *arm_spe_recording_init(int *err,
 	}
 
 	sper->arm_spe_pmu = arm_spe_pmu;
+	sper->itr.pmu = arm_spe_pmu;
 	sper->itr.recording_options = arm_spe_recording_options;
 	sper->itr.info_priv_size = arm_spe_info_priv_size;
 	sper->itr.info_fill = arm_spe_info_fill;
 	sper->itr.free = arm_spe_recording_free;
 	sper->itr.reference = arm_spe_reference;
-	sper->itr.read_finish = arm_spe_read_finish;
+	sper->itr.read_finish = auxtrace_record__read_finish;
 	sper->itr.alignment = 0;
 
 	*err = 0;
diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c
index 39e3631..26cee10 100644
--- a/tools/perf/arch/x86/util/intel-bts.c
+++ b/tools/perf/arch/x86/util/intel-bts.c
@@ -413,23 +413,6 @@ out_err:
 	return err;
 }
 
-static int intel_bts_read_finish(struct auxtrace_record *itr, int idx)
-{
-	struct intel_bts_recording *btsr =
-			container_of(itr, struct intel_bts_recording, itr);
-	struct evsel *evsel;
-
-	evlist__for_each_entry(btsr->evlist, evsel) {
-		if (evsel->core.attr.type == btsr->intel_bts_pmu->type) {
-			if (evsel->disabled)
-				return 0;
-			return perf_evlist__enable_event_idx(btsr->evlist,
-							     evsel, idx);
-		}
-	}
-	return -EINVAL;
-}
-
 struct auxtrace_record *intel_bts_recording_init(int *err)
 {
 	struct perf_pmu *intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME);
@@ -450,6 +433,7 @@ struct auxtrace_record *intel_bts_recording_init(int *err)
 	}
 
 	btsr->intel_bts_pmu = intel_bts_pmu;
+	btsr->itr.pmu = intel_bts_pmu;
 	btsr->itr.recording_options = intel_bts_recording_options;
 	btsr->itr.info_priv_size = intel_bts_info_priv_size;
 	btsr->itr.info_fill = intel_bts_info_fill;
@@ -459,7 +443,7 @@ struct auxtrace_record *intel_bts_recording_init(int *err)
 	btsr->itr.find_snapshot = intel_bts_find_snapshot;
 	btsr->itr.parse_snapshot_options = intel_bts_parse_snapshot_options;
 	btsr->itr.reference = intel_bts_reference;
-	btsr->itr.read_finish = intel_bts_read_finish;
+	btsr->itr.read_finish = auxtrace_record__read_finish;
 	btsr->itr.alignment = sizeof(struct branch);
 	return &btsr->itr;
 }
diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index be07d68..7eea4fd 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -1166,23 +1166,6 @@ static u64 intel_pt_reference(struct auxtrace_record *itr __maybe_unused)
 	return rdtsc();
 }
 
-static int intel_pt_read_finish(struct auxtrace_record *itr, int idx)
-{
-	struct intel_pt_recording *ptr =
-			container_of(itr, struct intel_pt_recording, itr);
-	struct evsel *evsel;
-
-	evlist__for_each_entry(ptr->evlist, evsel) {
-		if (evsel->core.attr.type == ptr->intel_pt_pmu->type) {
-			if (evsel->disabled)
-				return 0;
-			return perf_evlist__enable_event_idx(ptr->evlist, evsel,
-							     idx);
-		}
-	}
-	return -EINVAL;
-}
-
 struct auxtrace_record *intel_pt_recording_init(int *err)
 {
 	struct perf_pmu *intel_pt_pmu = perf_pmu__find(INTEL_PT_PMU_NAME);
@@ -1203,6 +1186,7 @@ struct auxtrace_record *intel_pt_recording_init(int *err)
 	}
 
 	ptr->intel_pt_pmu = intel_pt_pmu;
+	ptr->itr.pmu = intel_pt_pmu;
 	ptr->itr.recording_options = intel_pt_recording_options;
 	ptr->itr.info_priv_size = intel_pt_info_priv_size;
 	ptr->itr.info_fill = intel_pt_info_fill;
@@ -1212,7 +1196,7 @@ struct auxtrace_record *intel_pt_recording_init(int *err)
 	ptr->itr.find_snapshot = intel_pt_find_snapshot;
 	ptr->itr.parse_snapshot_options = intel_pt_parse_snapshot_options;
 	ptr->itr.reference = intel_pt_reference;
-	ptr->itr.read_finish = intel_pt_read_finish;
+	ptr->itr.read_finish = auxtrace_record__read_finish;
 	/*
 	 * Decoding starts at a PSB packet. Minimum PSB period is 2K so 4K
 	 * should give at least 1 PSB per sample.
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index eb087e7..3571ce7 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -629,8 +629,10 @@ int auxtrace_record__options(struct auxtrace_record *itr,
 			     struct evlist *evlist,
 			     struct record_opts *opts)
 {
-	if (itr)
+	if (itr) {
+		itr->evlist = evlist;
 		return itr->recording_options(itr, evlist, opts);
+	}
 	return 0;
 }
 
@@ -664,6 +666,24 @@ int auxtrace_parse_snapshot_options(struct auxtrace_record *itr,
 	return -EINVAL;
 }
 
+int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx)
+{
+	struct evsel *evsel;
+
+	if (!itr->evlist || !itr->pmu)
+		return -EINVAL;
+
+	evlist__for_each_entry(itr->evlist, evsel) {
+		if (evsel->core.attr.type == itr->pmu->type) {
+			if (evsel->disabled)
+				return 0;
+			return perf_evlist__enable_event_idx(itr->evlist, evsel,
+							     idx);
+		}
+	}
+	return -EINVAL;
+}
+
 /*
  * Event record size is 16-bit which results in a maximum size of about 64KiB.
  * Allow about 4KiB for the rest of the sample record, to give a maximum
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 749d72c..e58ef16 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -29,6 +29,7 @@ struct record_opts;
 struct perf_record_auxtrace_error;
 struct perf_record_auxtrace_info;
 struct events_stats;
+struct perf_pmu;
 
 enum auxtrace_error_type {
        PERF_AUXTRACE_ERROR_ITRACE  = 1,
@@ -322,6 +323,8 @@ struct auxtrace_mmap_params {
  * @read_finish: called after reading from an auxtrace mmap
  * @alignment: alignment (if any) for AUX area data
  * @default_aux_sample_size: default sample size for --aux sample option
+ * @pmu: associated pmu
+ * @evlist: selected events list
  */
 struct auxtrace_record {
 	int (*recording_options)(struct auxtrace_record *itr,
@@ -346,6 +349,8 @@ struct auxtrace_record {
 	int (*read_finish)(struct auxtrace_record *itr, int idx);
 	unsigned int alignment;
 	unsigned int default_aux_sample_size;
+	struct perf_pmu *pmu;
+	struct evlist *evlist;
 };
 
 /**
@@ -537,6 +542,7 @@ int auxtrace_record__find_snapshot(struct auxtrace_record *itr, int idx,
 				   struct auxtrace_mmap *mm,
 				   unsigned char *data, u64 *head, u64 *old);
 u64 auxtrace_record__reference(struct auxtrace_record *itr);
+int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx);
 
 int auxtrace_index__auxtrace_event(struct list_head *head, union perf_event *event,
 				   off_t file_offset);

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

* [tip: perf/urgent] perf cs-etm: Fix endless record after being terminated
  2020-02-14 13:26 ` [PATCH V2 3/5] perf tools: cs-etm: fix " Adrian Hunter
                     ` (2 preceding siblings ...)
  2020-02-14 18:24   ` Mathieu Poirier
@ 2020-02-26 14:20   ` tip-bot2 for Wei Li
  3 siblings, 0 replies; 19+ messages in thread
From: tip-bot2 for Wei Li @ 2020-02-26 14:20 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Wei Li, Leo Yan, Mathieu Poirier, Jiri Olsa, Tan Xiaojun, stable,
	#, 5.4+,
	Adrian Hunter, Arnaldo Carvalho de Melo, x86, LKML

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     c9f2833cb472cf9e0a49b7bcdc210a96017a7bfd
Gitweb:        https://git.kernel.org/tip/c9f2833cb472cf9e0a49b7bcdc210a96017a7bfd
Author:        Wei Li <liwei391@huawei.com>
AuthorDate:    Fri, 14 Feb 2020 15:26:52 +02:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Tue, 18 Feb 2020 10:13:29 -03:00

perf cs-etm: Fix endless record after being terminated

In __cmd_record(), when receiving SIGINT(ctrl + c), a 'done' flag will
be set and the event list will be disabled by evlist__disable() once.

While in auxtrace_record.read_finish(), the related events will be
enabled again, if they are continuous, the recording seems to be
endless.

If the cs_etm event is disabled, we don't enable it again here.

Note: This patch is NOT tested since i don't have such a machine with
coresight feature, but the code seems buggy same as arm-spe and
intel-pt.

Tester notes:

Thanks for looping, Adrian.  Applied this patch and tested with
CoreSight on juno board, it works well.

Signed-off-by: Wei Li <liwei391@huawei.com>
Reviewed-by: Leo Yan <leo.yan@linaro.org>
Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Tested-by: Leo Yan <leo.yan@linaro.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Tan Xiaojun <tanxiaojun@huawei.com>
Cc: stable@vger.kernel.org # 5.4+
Link: http://lore.kernel.org/lkml/20200214132654.20395-4-adrian.hunter@intel.com
[ahunter: removed redundant 'else' after 'return']
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/arch/arm/util/cs-etm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
index 2898cfd..60141c3 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -865,9 +865,12 @@ static int cs_etm_read_finish(struct auxtrace_record *itr, int idx)
 	struct evsel *evsel;
 
 	evlist__for_each_entry(ptr->evlist, evsel) {
-		if (evsel->core.attr.type == ptr->cs_etm_pmu->type)
+		if (evsel->core.attr.type == ptr->cs_etm_pmu->type) {
+			if (evsel->disabled)
+				return 0;
 			return perf_evlist__enable_event_idx(ptr->evlist,
 							     evsel, idx);
+		}
 	}
 
 	return -EINVAL;

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

* [tip: perf/urgent] perf intel-bts: Fix endless record after being terminated
  2020-02-14 13:26 ` [PATCH V2 2/5] perf tools: intel-bts: fix " Adrian Hunter
@ 2020-02-26 14:20   ` tip-bot2 for Wei Li
  0 siblings, 0 replies; 19+ messages in thread
From: tip-bot2 for Wei Li @ 2020-02-26 14:20 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Wei Li, Jiri Olsa, Tan Xiaojun, stable, #, 5.4+,
	Adrian Hunter, Arnaldo Carvalho de Melo, x86, LKML

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     783fed2f35e2a6771c8dc6ee29b8c4b9930783ce
Gitweb:        https://git.kernel.org/tip/783fed2f35e2a6771c8dc6ee29b8c4b9930783ce
Author:        Wei Li <liwei391@huawei.com>
AuthorDate:    Fri, 14 Feb 2020 15:26:51 +02:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Tue, 18 Feb 2020 10:13:29 -03:00

perf intel-bts: Fix endless record after being terminated

In __cmd_record(), when receiving SIGINT(ctrl + c), a 'done' flag will
be set and the event list will be disabled by evlist__disable() once.

While in auxtrace_record.read_finish(), the related events will be
enabled again, if they are continuous, the recording seems to be
endless.

If the intel_bts event is disabled, we don't enable it again here.

Note: This patch is NOT tested since i don't have such a machine with
intel_bts feature, but the code seems buggy same as arm-spe and
intel-pt.

Signed-off-by: Wei Li <liwei391@huawei.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Tan Xiaojun <tanxiaojun@huawei.com>
Cc: stable@vger.kernel.org # 5.4+
Link: http://lore.kernel.org/lkml/20200214132654.20395-3-adrian.hunter@intel.com
[ahunter: removed redundant 'else' after 'return']
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/arch/x86/util/intel-bts.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c
index 27d9e21..39e3631 100644
--- a/tools/perf/arch/x86/util/intel-bts.c
+++ b/tools/perf/arch/x86/util/intel-bts.c
@@ -420,9 +420,12 @@ static int intel_bts_read_finish(struct auxtrace_record *itr, int idx)
 	struct evsel *evsel;
 
 	evlist__for_each_entry(btsr->evlist, evsel) {
-		if (evsel->core.attr.type == btsr->intel_bts_pmu->type)
+		if (evsel->core.attr.type == btsr->intel_bts_pmu->type) {
+			if (evsel->disabled)
+				return 0;
 			return perf_evlist__enable_event_idx(btsr->evlist,
 							     evsel, idx);
+		}
 	}
 	return -EINVAL;
 }

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

* [tip: perf/urgent] perf intel-pt: Fix endless record after being terminated
  2020-02-14 13:26 ` [PATCH V2 1/5] perf tools: intel-pt: " Adrian Hunter
@ 2020-02-26 14:20   ` tip-bot2 for Wei Li
  0 siblings, 0 replies; 19+ messages in thread
From: tip-bot2 for Wei Li @ 2020-02-26 14:20 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Wei Li, Jiri Olsa, Tan Xiaojun, stable, #, 5.4+,
	Adrian Hunter, Arnaldo Carvalho de Melo, x86, LKML

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     2da4dd3d6973ffdfba4fa07f53240fda7ab22929
Gitweb:        https://git.kernel.org/tip/2da4dd3d6973ffdfba4fa07f53240fda7ab22929
Author:        Wei Li <liwei391@huawei.com>
AuthorDate:    Fri, 14 Feb 2020 15:26:50 +02:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Tue, 18 Feb 2020 10:13:29 -03:00

perf intel-pt: Fix endless record after being terminated

In __cmd_record(), when receiving SIGINT(ctrl + c), a 'done' flag will
be set and the event list will be disabled by evlist__disable() once.

While in auxtrace_record.read_finish(), the related events will be
enabled again, if they are continuous, the recording seems to be endless.

If the intel_pt event is disabled, we don't enable it again here.

Before the patch:

  huawei@huawei-2288H-V5:~/linux-5.5-rc4/tools/perf$ ./perf record -e \
  intel_pt//u -p 46803
  ^C^C^C^C^C^C

After the patch:

  huawei@huawei-2288H-V5:~/linux-5.5-rc4/tools/perf$ ./perf record -e \
  intel_pt//u -p 48591
  ^C[ perf record: Woken up 0 times to write data ]
  Warning:
  AUX data lost 504 times out of 4816!

  [ perf record: Captured and wrote 2024.405 MB perf.data ]

Signed-off-by: Wei Li <liwei391@huawei.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Tan Xiaojun <tanxiaojun@huawei.com>
Cc: stable@vger.kernel.org # 5.4+
Link: http://lore.kernel.org/lkml/20200214132654.20395-2-adrian.hunter@intel.com
[ ahunter: removed redundant 'else' after 'return' ]
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/arch/x86/util/intel-pt.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c
index 20df442..be07d68 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -1173,9 +1173,12 @@ static int intel_pt_read_finish(struct auxtrace_record *itr, int idx)
 	struct evsel *evsel;
 
 	evlist__for_each_entry(ptr->evlist, evsel) {
-		if (evsel->core.attr.type == ptr->intel_pt_pmu->type)
+		if (evsel->core.attr.type == ptr->intel_pt_pmu->type) {
+			if (evsel->disabled)
+				return 0;
 			return perf_evlist__enable_event_idx(ptr->evlist, evsel,
 							     idx);
+		}
 	}
 	return -EINVAL;
 }

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

end of thread, other threads:[~2020-02-26 14:21 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-14 13:26 [PATCH 0/5] perf tools: fix endless record after being terminated Adrian Hunter
2020-02-14 13:26 ` [PATCH V2 1/5] perf tools: intel-pt: " Adrian Hunter
2020-02-26 14:20   ` [tip: perf/urgent] perf intel-pt: Fix " tip-bot2 for Wei Li
2020-02-14 13:26 ` [PATCH V2 2/5] perf tools: intel-bts: fix " Adrian Hunter
2020-02-26 14:20   ` [tip: perf/urgent] perf intel-bts: Fix " tip-bot2 for Wei Li
2020-02-14 13:26 ` [PATCH V2 3/5] perf tools: cs-etm: fix " Adrian Hunter
2020-02-14 14:07   ` Adrian Hunter
2020-02-14 14:43   ` Leo Yan
2020-02-14 18:24   ` Mathieu Poirier
2020-02-26 14:20   ` [tip: perf/urgent] perf cs-etm: Fix " tip-bot2 for Wei Li
2020-02-14 13:26 ` [PATCH 4/5] perf tools: arm-spe: fix " Adrian Hunter
2020-02-26 14:20   ` [tip: perf/urgent] perf arm-spe: Fix " tip-bot2 for Adrian Hunter
2020-02-14 13:26 ` [PATCH 5/5] perf auxtrace: Add auxtrace_record__read_finish() Adrian Hunter
2020-02-14 14:08   ` Adrian Hunter
2020-02-14 14:48   ` Leo Yan
2020-02-17  8:23     ` [PATCH V2 " Adrian Hunter
2020-02-17 14:42       ` Arnaldo Carvalho de Melo
2020-02-26 14:20       ` [tip: perf/urgent] " tip-bot2 for Adrian Hunter
2020-02-14 18:27   ` [PATCH 5/5] " Mathieu Poirier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).