linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/7] perf arm-spe: Refactor data source encoding
@ 2024-10-03 18:53 Leo Yan
  2024-10-03 18:53 ` [PATCH v3 1/7] perf arm-spe: Rename arm_spe__synth_data_source_generic() Leo Yan
                   ` (8 more replies)
  0 siblings, 9 replies; 12+ messages in thread
From: Leo Yan @ 2024-10-03 18:53 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Besar Wicaksono,
	James Clark, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, Liang, Kan, John Garry, Will Deacon,
	Mike Leach, linux-perf-users, linux-kernel, linux-arm-kernel
  Cc: Leo Yan

As more Arm CPU variants (not only Neoverse CPUs) support data source
encoding, they share the same format for the data source packet.

To extend supporting these CPU variants for Arm SPE data source, this
series refactors the code. It converts the Neoverse specific naming to
the common naming, and then based on the MIDR stored in the metadata to
decide if the CPU follows up the common encoding format.

At the last, it extends CPU list for Neoverse-V2 and Cortex CPUs.

This patch series is dependent on the metadata version 2 series [1] for
retrieving CPU MIDR. It has been verified for per CPU mode and per
thread mode on Cortex-A725 CPUs.

[1] https://lore.kernel.org/linux-perf-users/20241003184302.190806-1-leo.yan@arm.com/T/#t

Changes from v2:
- Rebased on the latest metadata version 2 series [1].

Changes from v1:
- Dropped LDS bit checking in data source parsing.


Besar Wicaksono (1):
  perf arm-spe: Add Neoverse-V2 to common data source encoding list

Leo Yan (6):
  perf arm-spe: Rename arm_spe__synth_data_source_generic()
  perf arm-spe: Rename the common data source encoding
  perf arm-spe: Introduce arm_spe__is_homogeneous()
  perf arm-spe: Use metadata to decide the data source feature
  perf arm-spe: Remove the unused 'midr' field
  perf arm-spe: Add Cortex CPUs to common data source encoding list

 .../util/arm-spe-decoder/arm-spe-decoder.h    |  18 +--
 tools/perf/util/arm-spe.c                     | 135 +++++++++++++++---
 2 files changed, 121 insertions(+), 32 deletions(-)

-- 
2.34.1


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

* [PATCH v3 1/7] perf arm-spe: Rename arm_spe__synth_data_source_generic()
  2024-10-03 18:53 [PATCH v3 0/7] perf arm-spe: Refactor data source encoding Leo Yan
@ 2024-10-03 18:53 ` Leo Yan
  2024-10-03 18:53 ` [PATCH v3 2/7] perf arm-spe: Rename the common data source encoding Leo Yan
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Leo Yan @ 2024-10-03 18:53 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Besar Wicaksono,
	James Clark, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, Liang, Kan, John Garry, Will Deacon,
	Mike Leach, linux-perf-users, linux-kernel, linux-arm-kernel
  Cc: Leo Yan

The arm_spe__synth_data_source_generic() function is invoked when the
tool detects that CPUs do not support data source packets and falls back
to synthesizing only the memory level.

Rename it to arm_spe__synth_memory_level() for better reflecting its
purpose.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/perf/util/arm-spe.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
index 13fd2c8afebd..34e147e8a963 100644
--- a/tools/perf/util/arm-spe.c
+++ b/tools/perf/util/arm-spe.c
@@ -496,8 +496,8 @@ static void arm_spe__synth_data_source_neoverse(const struct arm_spe_record *rec
 	}
 }
 
-static void arm_spe__synth_data_source_generic(const struct arm_spe_record *record,
-					       union perf_mem_data_src *data_src)
+static void arm_spe__synth_memory_level(const struct arm_spe_record *record,
+					union perf_mem_data_src *data_src)
 {
 	if (record->type & (ARM_SPE_LLC_ACCESS | ARM_SPE_LLC_MISS)) {
 		data_src->mem_lvl = PERF_MEM_LVL_L3;
@@ -534,7 +534,7 @@ static u64 arm_spe__synth_data_source(const struct arm_spe_record *record, u64 m
 	if (is_neoverse)
 		arm_spe__synth_data_source_neoverse(record, &data_src);
 	else
-		arm_spe__synth_data_source_generic(record, &data_src);
+		arm_spe__synth_memory_level(record, &data_src);
 
 	if (record->type & (ARM_SPE_TLB_ACCESS | ARM_SPE_TLB_MISS)) {
 		data_src.mem_dtlb = PERF_MEM_TLB_WK;
-- 
2.34.1


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

* [PATCH v3 2/7] perf arm-spe: Rename the common data source encoding
  2024-10-03 18:53 [PATCH v3 0/7] perf arm-spe: Refactor data source encoding Leo Yan
  2024-10-03 18:53 ` [PATCH v3 1/7] perf arm-spe: Rename arm_spe__synth_data_source_generic() Leo Yan
@ 2024-10-03 18:53 ` Leo Yan
  2024-10-03 18:53 ` [PATCH v3 3/7] perf arm-spe: Introduce arm_spe__is_homogeneous() Leo Yan
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Leo Yan @ 2024-10-03 18:53 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Besar Wicaksono,
	James Clark, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, Liang, Kan, John Garry, Will Deacon,
	Mike Leach, linux-perf-users, linux-kernel, linux-arm-kernel
  Cc: Leo Yan

The Neoverse CPUs follow the common data source encoding, and other
CPU variants can share the same format.

Rename the CPU list and data source definitions as common data source
names. This change prepares for appending more CPU variants.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 .../util/arm-spe-decoder/arm-spe-decoder.h    | 18 ++++++------
 tools/perf/util/arm-spe.c                     | 28 +++++++++----------
 2 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/tools/perf/util/arm-spe-decoder/arm-spe-decoder.h b/tools/perf/util/arm-spe-decoder/arm-spe-decoder.h
index 1443c28545a9..358c611eeddb 100644
--- a/tools/perf/util/arm-spe-decoder/arm-spe-decoder.h
+++ b/tools/perf/util/arm-spe-decoder/arm-spe-decoder.h
@@ -56,15 +56,15 @@ enum arm_spe_op_type {
 	ARM_SPE_OP_BR_INDIRECT	= 1 << 17,
 };
 
-enum arm_spe_neoverse_data_source {
-	ARM_SPE_NV_L1D		 = 0x0,
-	ARM_SPE_NV_L2		 = 0x8,
-	ARM_SPE_NV_PEER_CORE	 = 0x9,
-	ARM_SPE_NV_LOCAL_CLUSTER = 0xa,
-	ARM_SPE_NV_SYS_CACHE	 = 0xb,
-	ARM_SPE_NV_PEER_CLUSTER	 = 0xc,
-	ARM_SPE_NV_REMOTE	 = 0xd,
-	ARM_SPE_NV_DRAM		 = 0xe,
+enum arm_spe_common_data_source {
+	ARM_SPE_COMMON_DS_L1D		= 0x0,
+	ARM_SPE_COMMON_DS_L2		= 0x8,
+	ARM_SPE_COMMON_DS_PEER_CORE	= 0x9,
+	ARM_SPE_COMMON_DS_LOCAL_CLUSTER = 0xa,
+	ARM_SPE_COMMON_DS_SYS_CACHE	= 0xb,
+	ARM_SPE_COMMON_DS_PEER_CLUSTER	= 0xc,
+	ARM_SPE_COMMON_DS_REMOTE	= 0xd,
+	ARM_SPE_COMMON_DS_DRAM		= 0xe,
 };
 
 struct arm_spe_record {
diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
index 34e147e8a963..b0e9eb6057c3 100644
--- a/tools/perf/util/arm-spe.c
+++ b/tools/perf/util/arm-spe.c
@@ -413,15 +413,15 @@ static int arm_spe__synth_instruction_sample(struct arm_spe_queue *speq,
 	return arm_spe_deliver_synth_event(spe, speq, event, &sample);
 }
 
-static const struct midr_range neoverse_spe[] = {
+static const struct midr_range common_ds_encoding_cpus[] = {
 	MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N1),
 	MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N2),
 	MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V1),
 	{},
 };
 
-static void arm_spe__synth_data_source_neoverse(const struct arm_spe_record *record,
-						union perf_mem_data_src *data_src)
+static void arm_spe__synth_data_source_common(const struct arm_spe_record *record,
+					      union perf_mem_data_src *data_src)
 {
 	/*
 	 * Even though four levels of cache hierarchy are possible, no known
@@ -443,17 +443,17 @@ static void arm_spe__synth_data_source_neoverse(const struct arm_spe_record *rec
 	}
 
 	switch (record->source) {
-	case ARM_SPE_NV_L1D:
+	case ARM_SPE_COMMON_DS_L1D:
 		data_src->mem_lvl = PERF_MEM_LVL_L1 | PERF_MEM_LVL_HIT;
 		data_src->mem_lvl_num = PERF_MEM_LVLNUM_L1;
 		data_src->mem_snoop = PERF_MEM_SNOOP_NONE;
 		break;
-	case ARM_SPE_NV_L2:
+	case ARM_SPE_COMMON_DS_L2:
 		data_src->mem_lvl = PERF_MEM_LVL_L2 | PERF_MEM_LVL_HIT;
 		data_src->mem_lvl_num = PERF_MEM_LVLNUM_L2;
 		data_src->mem_snoop = PERF_MEM_SNOOP_NONE;
 		break;
-	case ARM_SPE_NV_PEER_CORE:
+	case ARM_SPE_COMMON_DS_PEER_CORE:
 		data_src->mem_lvl = PERF_MEM_LVL_L2 | PERF_MEM_LVL_HIT;
 		data_src->mem_lvl_num = PERF_MEM_LVLNUM_L2;
 		data_src->mem_snoopx = PERF_MEM_SNOOPX_PEER;
@@ -462,8 +462,8 @@ static void arm_spe__synth_data_source_neoverse(const struct arm_spe_record *rec
 	 * We don't know if this is L1, L2 but we do know it was a cache-2-cache
 	 * transfer, so set SNOOPX_PEER
 	 */
-	case ARM_SPE_NV_LOCAL_CLUSTER:
-	case ARM_SPE_NV_PEER_CLUSTER:
+	case ARM_SPE_COMMON_DS_LOCAL_CLUSTER:
+	case ARM_SPE_COMMON_DS_PEER_CLUSTER:
 		data_src->mem_lvl = PERF_MEM_LVL_L3 | PERF_MEM_LVL_HIT;
 		data_src->mem_lvl_num = PERF_MEM_LVLNUM_L3;
 		data_src->mem_snoopx = PERF_MEM_SNOOPX_PEER;
@@ -471,7 +471,7 @@ static void arm_spe__synth_data_source_neoverse(const struct arm_spe_record *rec
 	/*
 	 * System cache is assumed to be L3
 	 */
-	case ARM_SPE_NV_SYS_CACHE:
+	case ARM_SPE_COMMON_DS_SYS_CACHE:
 		data_src->mem_lvl = PERF_MEM_LVL_L3 | PERF_MEM_LVL_HIT;
 		data_src->mem_lvl_num = PERF_MEM_LVLNUM_L3;
 		data_src->mem_snoop = PERF_MEM_SNOOP_HIT;
@@ -480,13 +480,13 @@ static void arm_spe__synth_data_source_neoverse(const struct arm_spe_record *rec
 	 * We don't know what level it hit in, except it came from the other
 	 * socket
 	 */
-	case ARM_SPE_NV_REMOTE:
+	case ARM_SPE_COMMON_DS_REMOTE:
 		data_src->mem_lvl = PERF_MEM_LVL_REM_CCE1;
 		data_src->mem_lvl_num = PERF_MEM_LVLNUM_ANY_CACHE;
 		data_src->mem_remote = PERF_MEM_REMOTE_REMOTE;
 		data_src->mem_snoopx = PERF_MEM_SNOOPX_PEER;
 		break;
-	case ARM_SPE_NV_DRAM:
+	case ARM_SPE_COMMON_DS_DRAM:
 		data_src->mem_lvl = PERF_MEM_LVL_LOC_RAM | PERF_MEM_LVL_HIT;
 		data_src->mem_lvl_num = PERF_MEM_LVLNUM_RAM;
 		data_src->mem_snoop = PERF_MEM_SNOOP_NONE;
@@ -522,7 +522,7 @@ static void arm_spe__synth_memory_level(const struct arm_spe_record *record,
 static u64 arm_spe__synth_data_source(const struct arm_spe_record *record, u64 midr)
 {
 	union perf_mem_data_src	data_src = { .mem_op = PERF_MEM_OP_NA };
-	bool is_neoverse = is_midr_in_range_list(midr, neoverse_spe);
+	bool is_common = is_midr_in_range_list(midr, common_ds_encoding_cpus);
 
 	if (record->op & ARM_SPE_OP_LD)
 		data_src.mem_op = PERF_MEM_OP_LOAD;
@@ -531,8 +531,8 @@ static u64 arm_spe__synth_data_source(const struct arm_spe_record *record, u64 m
 	else
 		return 0;
 
-	if (is_neoverse)
-		arm_spe__synth_data_source_neoverse(record, &data_src);
+	if (is_common)
+		arm_spe__synth_data_source_common(record, &data_src);
 	else
 		arm_spe__synth_memory_level(record, &data_src);
 
-- 
2.34.1


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

* [PATCH v3 3/7] perf arm-spe: Introduce arm_spe__is_homogeneous()
  2024-10-03 18:53 [PATCH v3 0/7] perf arm-spe: Refactor data source encoding Leo Yan
  2024-10-03 18:53 ` [PATCH v3 1/7] perf arm-spe: Rename arm_spe__synth_data_source_generic() Leo Yan
  2024-10-03 18:53 ` [PATCH v3 2/7] perf arm-spe: Rename the common data source encoding Leo Yan
@ 2024-10-03 18:53 ` Leo Yan
  2024-10-03 18:53 ` [PATCH v3 4/7] perf arm-spe: Use metadata to decide the data source feature Leo Yan
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Leo Yan @ 2024-10-03 18:53 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Besar Wicaksono,
	James Clark, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, Liang, Kan, John Garry, Will Deacon,
	Mike Leach, linux-perf-users, linux-kernel, linux-arm-kernel
  Cc: Leo Yan

Introduce the arm_spe__is_homogeneous() function, it uses to check if
Arm SPE is homogeneous cross all CPUs.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/perf/util/arm-spe.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
index b0e9eb6057c3..587943b6bdb8 100644
--- a/tools/perf/util/arm-spe.c
+++ b/tools/perf/util/arm-spe.c
@@ -82,6 +82,7 @@ struct arm_spe {
 	u64				**metadata;
 	u64				metadata_ver;
 	u64				metadata_nr_cpu;
+	bool				is_homogeneous;
 };
 
 struct arm_spe_queue {
@@ -1374,6 +1375,30 @@ arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session)
 	return 0;
 }
 
+static bool arm_spe__is_homogeneous(u64 **metadata, int nr_cpu)
+{
+	u64 midr;
+	int i;
+
+	if (!nr_cpu)
+		return false;
+
+	for (i = 0; i < nr_cpu; i++) {
+		if (!metadata[i])
+			return false;
+
+		if (i == 0) {
+			midr = metadata[i][ARM_SPE_CPU_MIDR];
+			continue;
+		}
+
+		if (midr != metadata[i][ARM_SPE_CPU_MIDR])
+			return false;
+	}
+
+	return true;
+}
+
 int arm_spe_process_auxtrace_info(union perf_event *event,
 				  struct perf_session *session)
 {
@@ -1419,6 +1444,7 @@ int arm_spe_process_auxtrace_info(union perf_event *event,
 	spe->metadata = metadata;
 	spe->metadata_ver = metadata_ver;
 	spe->metadata_nr_cpu = nr_cpu;
+	spe->is_homogeneous = arm_spe__is_homogeneous(metadata, nr_cpu);
 
 	spe->timeless_decoding = arm_spe__is_timeless_decoding(spe);
 
-- 
2.34.1


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

* [PATCH v3 4/7] perf arm-spe: Use metadata to decide the data source feature
  2024-10-03 18:53 [PATCH v3 0/7] perf arm-spe: Refactor data source encoding Leo Yan
                   ` (2 preceding siblings ...)
  2024-10-03 18:53 ` [PATCH v3 3/7] perf arm-spe: Introduce arm_spe__is_homogeneous() Leo Yan
@ 2024-10-03 18:53 ` Leo Yan
  2024-10-10 13:53   ` James Clark
  2024-10-03 18:53 ` [PATCH v3 5/7] perf arm-spe: Remove the unused 'midr' field Leo Yan
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 12+ messages in thread
From: Leo Yan @ 2024-10-03 18:53 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Besar Wicaksono,
	James Clark, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, Liang, Kan, John Garry, Will Deacon,
	Mike Leach, linux-perf-users, linux-kernel, linux-arm-kernel
  Cc: Leo Yan

Use the info in the metadata to decide if the data source feature is
supported. The CPU MIDR must be in the CPU list for the common data
source encoding.

For the metadata version 1, it doesn't include info for MIDR. In this
case, due to absent info for making decision, print out warning to
remind users to upgrade tool and returns false.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/perf/util/arm-spe.c | 67 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 64 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
index 587943b6bdb8..9221b2f66bbe 100644
--- a/tools/perf/util/arm-spe.c
+++ b/tools/perf/util/arm-spe.c
@@ -278,6 +278,20 @@ static int arm_spe_set_tid(struct arm_spe_queue *speq, pid_t tid)
 	return 0;
 }
 
+static u64 *arm_spe__get_metadata_by_cpu(struct arm_spe *spe, u64 cpu)
+{
+	u64 i;
+
+	if (!spe->metadata)
+		return NULL;
+
+	for (i = 0; i < spe->metadata_nr_cpu; i++)
+		if (spe->metadata[i][ARM_SPE_CPU] == cpu)
+			return spe->metadata[i];
+
+	return NULL;
+}
+
 static struct simd_flags arm_spe__synth_simd_flags(const struct arm_spe_record *record)
 {
 	struct simd_flags simd_flags = {};
@@ -520,10 +534,57 @@ static void arm_spe__synth_memory_level(const struct arm_spe_record *record,
 		data_src->mem_lvl |= PERF_MEM_LVL_REM_CCE1;
 }
 
-static u64 arm_spe__synth_data_source(const struct arm_spe_record *record, u64 midr)
+static bool arm_spe__is_common_ds_encoding(struct arm_spe_queue *speq)
+{
+	struct arm_spe *spe = speq->spe;
+	bool is_in_cpu_list;
+	u64 *metadata = NULL;
+	u64 midr = 0;
+
+	/*
+	 * Metadata version 1 doesn't contain any info for MIDR.
+	 * Simply return false in this case.
+	 */
+	if (spe->metadata_ver == 1) {
+		pr_warning_once("The data file contains metadata version 1, "
+				"which is absent the info for data source. "
+				"Please upgrade the tool to record data.\n");
+		return false;
+	}
+
+	/* CPU ID is -1 for per-thread mode */
+	if (speq->cpu < 0) {
+		/*
+		 * On the heterogeneous system, due to CPU ID is -1,
+		 * cannot confirm the data source packet is supported.
+		 */
+		if (!spe->is_homogeneous)
+			return false;
+
+		/* In homogeneous system, simply use CPU0's metadata */
+		if (spe->metadata)
+			metadata = spe->metadata[0];
+	} else {
+		metadata = arm_spe__get_metadata_by_cpu(spe, speq->cpu);
+	}
+
+	if (!metadata)
+		return false;
+
+	midr = metadata[ARM_SPE_CPU_MIDR];
+
+	is_in_cpu_list = is_midr_in_range_list(midr, common_ds_encoding_cpus);
+	if (is_in_cpu_list)
+		return true;
+	else
+		return false;
+}
+
+static u64 arm_spe__synth_data_source(struct arm_spe_queue *speq,
+				      const struct arm_spe_record *record)
 {
 	union perf_mem_data_src	data_src = { .mem_op = PERF_MEM_OP_NA };
-	bool is_common = is_midr_in_range_list(midr, common_ds_encoding_cpus);
+	bool is_common = arm_spe__is_common_ds_encoding(speq);
 
 	if (record->op & ARM_SPE_OP_LD)
 		data_src.mem_op = PERF_MEM_OP_LOAD;
@@ -556,7 +617,7 @@ static int arm_spe_sample(struct arm_spe_queue *speq)
 	u64 data_src;
 	int err;
 
-	data_src = arm_spe__synth_data_source(record, spe->midr);
+	data_src = arm_spe__synth_data_source(speq, record);
 
 	if (spe->sample_flc) {
 		if (record->type & ARM_SPE_L1D_MISS) {
-- 
2.34.1


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

* [PATCH v3 5/7] perf arm-spe: Remove the unused 'midr' field
  2024-10-03 18:53 [PATCH v3 0/7] perf arm-spe: Refactor data source encoding Leo Yan
                   ` (3 preceding siblings ...)
  2024-10-03 18:53 ` [PATCH v3 4/7] perf arm-spe: Use metadata to decide the data source feature Leo Yan
@ 2024-10-03 18:53 ` Leo Yan
  2024-10-03 18:53 ` [PATCH v3 6/7] perf arm-spe: Add Neoverse-V2 to common data source encoding list Leo Yan
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Leo Yan @ 2024-10-03 18:53 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Besar Wicaksono,
	James Clark, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, Liang, Kan, John Garry, Will Deacon,
	Mike Leach, linux-perf-users, linux-kernel, linux-arm-kernel
  Cc: Leo Yan

The 'midr' field is replaced by the MIDR values stored in metadata (per
CPU wise). Remove the 'midr' field as it is no longer used.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/perf/util/arm-spe.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
index 9221b2f66bbe..485f60c32309 100644
--- a/tools/perf/util/arm-spe.c
+++ b/tools/perf/util/arm-spe.c
@@ -46,7 +46,6 @@ struct arm_spe {
 	struct perf_session		*session;
 	struct machine			*machine;
 	u32				pmu_type;
-	u64				midr;
 
 	struct perf_tsc_conversion	tc;
 
@@ -1466,8 +1465,6 @@ int arm_spe_process_auxtrace_info(union perf_event *event,
 	struct perf_record_auxtrace_info *auxtrace_info = &event->auxtrace_info;
 	size_t min_sz = ARM_SPE_AUXTRACE_V1_PRIV_SIZE;
 	struct perf_record_time_conv *tc = &session->time_conv;
-	const char *cpuid = perf_env__cpuid(session->evlist->env);
-	u64 midr = strtol(cpuid, NULL, 16);
 	struct arm_spe *spe;
 	u64 **metadata = NULL;
 	u64 metadata_ver;
@@ -1501,7 +1498,6 @@ int arm_spe_process_auxtrace_info(union perf_event *event,
 		spe->pmu_type = auxtrace_info->priv[ARM_SPE_PMU_TYPE];
 	else
 		spe->pmu_type = auxtrace_info->priv[ARM_SPE_PMU_TYPE_V2];
-	spe->midr = midr;
 	spe->metadata = metadata;
 	spe->metadata_ver = metadata_ver;
 	spe->metadata_nr_cpu = nr_cpu;
-- 
2.34.1


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

* [PATCH v3 6/7] perf arm-spe: Add Neoverse-V2 to common data source encoding list
  2024-10-03 18:53 [PATCH v3 0/7] perf arm-spe: Refactor data source encoding Leo Yan
                   ` (4 preceding siblings ...)
  2024-10-03 18:53 ` [PATCH v3 5/7] perf arm-spe: Remove the unused 'midr' field Leo Yan
@ 2024-10-03 18:53 ` Leo Yan
  2024-10-03 18:53 ` [PATCH v3 7/7] perf arm-spe: Add Cortex CPUs " Leo Yan
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 12+ messages in thread
From: Leo Yan @ 2024-10-03 18:53 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Besar Wicaksono,
	James Clark, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, Liang, Kan, John Garry, Will Deacon,
	Mike Leach, linux-perf-users, linux-kernel, linux-arm-kernel
  Cc: Leo Yan

From: Besar Wicaksono <bwicaksono@nvidia.com>

Add Neoverse-V2 MIDR to the common data source encoding range list.

Signed-off-by: Besar Wicaksono <bwicaksono@nvidia.com>
Reviewed-by: Leo Yan <leo.yan@arm.com>
---
 tools/perf/util/arm-spe.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
index 485f60c32309..5c34a9ae3862 100644
--- a/tools/perf/util/arm-spe.c
+++ b/tools/perf/util/arm-spe.c
@@ -431,6 +431,7 @@ static const struct midr_range common_ds_encoding_cpus[] = {
 	MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N1),
 	MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N2),
 	MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V1),
+	MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V2),
 	{},
 };
 
-- 
2.34.1


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

* [PATCH v3 7/7] perf arm-spe: Add Cortex CPUs to common data source encoding list
  2024-10-03 18:53 [PATCH v3 0/7] perf arm-spe: Refactor data source encoding Leo Yan
                   ` (5 preceding siblings ...)
  2024-10-03 18:53 ` [PATCH v3 6/7] perf arm-spe: Add Neoverse-V2 to common data source encoding list Leo Yan
@ 2024-10-03 18:53 ` Leo Yan
  2024-10-10 13:54 ` [PATCH v3 0/7] perf arm-spe: Refactor data source encoding James Clark
  2024-10-16 17:12 ` Namhyung Kim
  8 siblings, 0 replies; 12+ messages in thread
From: Leo Yan @ 2024-10-03 18:53 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Besar Wicaksono,
	James Clark, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, Liang, Kan, John Garry, Will Deacon,
	Mike Leach, linux-perf-users, linux-kernel, linux-arm-kernel
  Cc: Leo Yan

Add Cortex-A720, Cortex-A725, Cortex-X1C, Cortex-X3 and Cortex-X925 into
the common data source encoding list. For everyone of these CPUs, it
technical reference manual defines the data source packet as the common
encoding format.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/perf/util/arm-spe.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
index 5c34a9ae3862..c424e5b9a11d 100644
--- a/tools/perf/util/arm-spe.c
+++ b/tools/perf/util/arm-spe.c
@@ -428,6 +428,11 @@ static int arm_spe__synth_instruction_sample(struct arm_spe_queue *speq,
 }
 
 static const struct midr_range common_ds_encoding_cpus[] = {
+	MIDR_ALL_VERSIONS(MIDR_CORTEX_A720),
+	MIDR_ALL_VERSIONS(MIDR_CORTEX_A725),
+	MIDR_ALL_VERSIONS(MIDR_CORTEX_X1C),
+	MIDR_ALL_VERSIONS(MIDR_CORTEX_X3),
+	MIDR_ALL_VERSIONS(MIDR_CORTEX_X925),
 	MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N1),
 	MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N2),
 	MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V1),
-- 
2.34.1


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

* Re: [PATCH v3 4/7] perf arm-spe: Use metadata to decide the data source feature
  2024-10-03 18:53 ` [PATCH v3 4/7] perf arm-spe: Use metadata to decide the data source feature Leo Yan
@ 2024-10-10 13:53   ` James Clark
  2024-10-10 14:58     ` Leo Yan
  0 siblings, 1 reply; 12+ messages in thread
From: James Clark @ 2024-10-10 13:53 UTC (permalink / raw)
  To: Leo Yan
  Cc: Arnaldo Carvalho de Melo, Namhyung Kim, Besar Wicaksono,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Liang, Kan, John Garry, Will Deacon, Mike Leach,
	linux-perf-users, linux-kernel, linux-arm-kernel



On 03/10/2024 7:53 pm, Leo Yan wrote:
> Use the info in the metadata to decide if the data source feature is
> supported. The CPU MIDR must be in the CPU list for the common data
> source encoding.
> 
> For the metadata version 1, it doesn't include info for MIDR. In this
> case, due to absent info for making decision, print out warning to
> remind users to upgrade tool and returns false.
> 
> Signed-off-by: Leo Yan <leo.yan@arm.com>
> ---
>   tools/perf/util/arm-spe.c | 67 +++++++++++++++++++++++++++++++++++++--
>   1 file changed, 64 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/perf/util/arm-spe.c b/tools/perf/util/arm-spe.c
> index 587943b6bdb8..9221b2f66bbe 100644
> --- a/tools/perf/util/arm-spe.c
> +++ b/tools/perf/util/arm-spe.c
> @@ -278,6 +278,20 @@ static int arm_spe_set_tid(struct arm_spe_queue *speq, pid_t tid)
>   	return 0;
>   }
>   
> +static u64 *arm_spe__get_metadata_by_cpu(struct arm_spe *spe, u64 cpu)
> +{
> +	u64 i;
> +
> +	if (!spe->metadata)
> +		return NULL;
> +
> +	for (i = 0; i < spe->metadata_nr_cpu; i++)
> +		if (spe->metadata[i][ARM_SPE_CPU] == cpu)
> +			return spe->metadata[i];
> +
> +	return NULL;
> +}
> +
>   static struct simd_flags arm_spe__synth_simd_flags(const struct arm_spe_record *record)
>   {
>   	struct simd_flags simd_flags = {};
> @@ -520,10 +534,57 @@ static void arm_spe__synth_memory_level(const struct arm_spe_record *record,
>   		data_src->mem_lvl |= PERF_MEM_LVL_REM_CCE1;
>   }
>   
> -static u64 arm_spe__synth_data_source(const struct arm_spe_record *record, u64 midr)
> +static bool arm_spe__is_common_ds_encoding(struct arm_spe_queue *speq)
> +{
> +	struct arm_spe *spe = speq->spe;
> +	bool is_in_cpu_list;
> +	u64 *metadata = NULL;
> +	u64 midr = 0;
> +
> +	/*
> +	 * Metadata version 1 doesn't contain any info for MIDR.
> +	 * Simply return false in this case.
> +	 */
> +	if (spe->metadata_ver == 1) {
> +		pr_warning_once("The data file contains metadata version 1, "
> +				"which is absent the info for data source. "
> +				"Please upgrade the tool to record data.\n");
> +		return false;
> +	}
> +
> +	/* CPU ID is -1 for per-thread mode */
> +	if (speq->cpu < 0) {
> +		/*
> +		 * On the heterogeneous system, due to CPU ID is -1,
> +		 * cannot confirm the data source packet is supported.
> +		 */
> +		if (!spe->is_homogeneous)
> +			return false;

Technically you could look at timestamps and context switches to find 
the CPU for non-homogeneous per-thread mode. But it's such an edge case 
I'm not sure it's even worth leaving a TODO for.


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

* Re: [PATCH v3 0/7] perf arm-spe: Refactor data source encoding
  2024-10-03 18:53 [PATCH v3 0/7] perf arm-spe: Refactor data source encoding Leo Yan
                   ` (6 preceding siblings ...)
  2024-10-03 18:53 ` [PATCH v3 7/7] perf arm-spe: Add Cortex CPUs " Leo Yan
@ 2024-10-10 13:54 ` James Clark
  2024-10-16 17:12 ` Namhyung Kim
  8 siblings, 0 replies; 12+ messages in thread
From: James Clark @ 2024-10-10 13:54 UTC (permalink / raw)
  To: Leo Yan
  Cc: Arnaldo Carvalho de Melo, Namhyung Kim, Besar Wicaksono,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Liang, Kan, John Garry, Will Deacon, Mike Leach,
	linux-perf-users, linux-kernel, linux-arm-kernel



On 03/10/2024 7:53 pm, Leo Yan wrote:
> As more Arm CPU variants (not only Neoverse CPUs) support data source
> encoding, they share the same format for the data source packet.
> 
> To extend supporting these CPU variants for Arm SPE data source, this
> series refactors the code. It converts the Neoverse specific naming to
> the common naming, and then based on the MIDR stored in the metadata to
> decide if the CPU follows up the common encoding format.
> 
> At the last, it extends CPU list for Neoverse-V2 and Cortex CPUs.
> 
> This patch series is dependent on the metadata version 2 series [1] for
> retrieving CPU MIDR. It has been verified for per CPU mode and per
> thread mode on Cortex-A725 CPUs.
> 
> [1] https://lore.kernel.org/linux-perf-users/20241003184302.190806-1-leo.yan@arm.com/T/#t
> 
> Changes from v2:
> - Rebased on the latest metadata version 2 series [1].
> 
> Changes from v1:
> - Dropped LDS bit checking in data source parsing.
> 
> 
> Besar Wicaksono (1):
>    perf arm-spe: Add Neoverse-V2 to common data source encoding list
> 
> Leo Yan (6):
>    perf arm-spe: Rename arm_spe__synth_data_source_generic()
>    perf arm-spe: Rename the common data source encoding
>    perf arm-spe: Introduce arm_spe__is_homogeneous()
>    perf arm-spe: Use metadata to decide the data source feature
>    perf arm-spe: Remove the unused 'midr' field
>    perf arm-spe: Add Cortex CPUs to common data source encoding list
> 
>   .../util/arm-spe-decoder/arm-spe-decoder.h    |  18 +--
>   tools/perf/util/arm-spe.c                     | 135 +++++++++++++++---
>   2 files changed, 121 insertions(+), 32 deletions(-)
> 

Reviewed-by: James Clark <james.clark@linaro.org>


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

* Re: [PATCH v3 4/7] perf arm-spe: Use metadata to decide the data source feature
  2024-10-10 13:53   ` James Clark
@ 2024-10-10 14:58     ` Leo Yan
  0 siblings, 0 replies; 12+ messages in thread
From: Leo Yan @ 2024-10-10 14:58 UTC (permalink / raw)
  To: James Clark
  Cc: Arnaldo Carvalho de Melo, Namhyung Kim, Besar Wicaksono,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Liang, Kan, John Garry, Will Deacon, Mike Leach,
	linux-perf-users, linux-kernel, linux-arm-kernel

On 10/10/24 14:53, James Clark wrote:

[...]

>> +static bool arm_spe__is_common_ds_encoding(struct arm_spe_queue *speq)
>> +{
>> +     struct arm_spe *spe = speq->spe;
>> +     bool is_in_cpu_list;
>> +     u64 *metadata = NULL;
>> +     u64 midr = 0;
>> +
>> +     /*
>> +      * Metadata version 1 doesn't contain any info for MIDR.
>> +      * Simply return false in this case.
>> +      */
>> +     if (spe->metadata_ver == 1) {
>> +             pr_warning_once("The data file contains metadata version 1, "
>> +                             "which is absent the info for data source. "
>> +                             "Please upgrade the tool to record data.\n");
>> +             return false;
>> +     }
>> +
>> +     /* CPU ID is -1 for per-thread mode */
>> +     if (speq->cpu < 0) {
>> +             /*
>> +              * On the heterogeneous system, due to CPU ID is -1,
>> +              * cannot confirm the data source packet is supported.
>> +              */
>> +             if (!spe->is_homogeneous)
>> +                     return false;
> 
> Technically you could look at timestamps and context switches to find
> the CPU for non-homogeneous per-thread mode. But it's such an edge case
> I'm not sure it's even worth leaving a TODO for.

Good point. Let’s bear the idea in mind in case we need it later.

Thanks,
Leo

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

* Re: [PATCH v3 0/7] perf arm-spe: Refactor data source encoding
  2024-10-03 18:53 [PATCH v3 0/7] perf arm-spe: Refactor data source encoding Leo Yan
                   ` (7 preceding siblings ...)
  2024-10-10 13:54 ` [PATCH v3 0/7] perf arm-spe: Refactor data source encoding James Clark
@ 2024-10-16 17:12 ` Namhyung Kim
  8 siblings, 0 replies; 12+ messages in thread
From: Namhyung Kim @ 2024-10-16 17:12 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Besar Wicaksono, James Clark,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Liang, Kan, John Garry, Will Deacon, Mike Leach,
	linux-perf-users, linux-kernel, linux-arm-kernel, Leo Yan

On Thu, 03 Oct 2024 19:53:15 +0100, Leo Yan wrote:

> As more Arm CPU variants (not only Neoverse CPUs) support data source
> encoding, they share the same format for the data source packet.
> 
> To extend supporting these CPU variants for Arm SPE data source, this
> series refactors the code. It converts the Neoverse specific naming to
> the common naming, and then based on the MIDR stored in the metadata to
> decide if the CPU follows up the common encoding format.
> 
> [...]

Applied to perf-tools-next, thanks!

Best regards,
Namhyung


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

end of thread, other threads:[~2024-10-16 17:12 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-03 18:53 [PATCH v3 0/7] perf arm-spe: Refactor data source encoding Leo Yan
2024-10-03 18:53 ` [PATCH v3 1/7] perf arm-spe: Rename arm_spe__synth_data_source_generic() Leo Yan
2024-10-03 18:53 ` [PATCH v3 2/7] perf arm-spe: Rename the common data source encoding Leo Yan
2024-10-03 18:53 ` [PATCH v3 3/7] perf arm-spe: Introduce arm_spe__is_homogeneous() Leo Yan
2024-10-03 18:53 ` [PATCH v3 4/7] perf arm-spe: Use metadata to decide the data source feature Leo Yan
2024-10-10 13:53   ` James Clark
2024-10-10 14:58     ` Leo Yan
2024-10-03 18:53 ` [PATCH v3 5/7] perf arm-spe: Remove the unused 'midr' field Leo Yan
2024-10-03 18:53 ` [PATCH v3 6/7] perf arm-spe: Add Neoverse-V2 to common data source encoding list Leo Yan
2024-10-03 18:53 ` [PATCH v3 7/7] perf arm-spe: Add Cortex CPUs " Leo Yan
2024-10-10 13:54 ` [PATCH v3 0/7] perf arm-spe: Refactor data source encoding James Clark
2024-10-16 17:12 ` Namhyung Kim

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).