Skip to contentSkip to conversation

perf arm-spe: Add support for SPE Data Source packet on AmpereOne

PATCH Superseded Ilkka Koskinen 2 participants 7 messages Nov 6, 2024 – Nov 7, 2024

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover perf arm-spe: Add support for SPE Data Source packet on AmpereOne

v1:
* https://lore.kernel.org/all/[email protected]/

v2:
* Doesn't use read_cpuid_implementor() anymore as that was broken and unnecessary.
* Convert AmpereOne source field to matching common source fields to avoid duplicating the code.
* Rebased on top of perf-tools-next/perf-tools-next (ba993e5ada1d)
* https://lore.kernel.org/all/[email protected]/

v3:
* Changed source mapping to simple switch statement
* Dropped is_xyz() stuff
* Added table to map midr to data source decoding function

Ilkka Koskinen (2):
perf arm-spe: Prepare for adding data source packet implementations
for other cores
perf arm-spe: Add support for SPE Data Source packet on AmpereOne

 .../util/arm-spe-decoder/arm-spe-decoder.h    |   9 ++
 tools/perf/util/arm-spe.c                     | 104 +++++++++++++-----
 2 files changed, 88 insertions(+), 25 deletions(-)
Signature · 1 line
2.47.0
#1 lore raw

PATCH v3 1/2 perf arm-spe: Prepare for adding data source packet implementations for other cores

Split Data Source Packet handling to prepare adding support for other implementations.

---
 tools/perf/util/arm-spe.c | 65 ++++++++++++++++++++++++---------------
 1 file changed, 40 insertions(+), 25 deletions(-)
tools/perf/util/arm-spe.c +40 -25
index dbf13f47879c..b222557cc27a 100644
@@ -103,6 +103,18 @@ struct arm_spe_queue {
 	u32				flags;
 };
 
+struct data_src {
+	struct midr_range midr_range;
+	void (*ds_synth)(const struct arm_spe_record *record,
+			 union perf_mem_data_src *data_src);
+};
+
+#define DS(range, func)			\
+	{						\
+		.midr_range = range,			\
+		.ds_synth = arm_spe__synth_##func,	\
+	}
+
 static void arm_spe_dump(struct arm_spe *spe __maybe_unused,
 			 unsigned char *buf, size_t len)
 {
@@ -430,19 +442,6 @@ 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 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),
-	MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V2),
-	{},
-};
-
 static void arm_spe__sample_flags(struct arm_spe_queue *speq)
 {
 	const struct arm_spe_record *record = &speq->decoder->record;
@@ -532,6 +531,19 @@ static void arm_spe__synth_data_source_common(const struct arm_spe_record *recor
 	}
 }
 
+static const struct data_src data_sources[] = {
+	DS(MIDR_ALL_VERSIONS(MIDR_CORTEX_A720), data_source_common),
+	DS(MIDR_ALL_VERSIONS(MIDR_CORTEX_A725), data_source_common),
+	DS(MIDR_ALL_VERSIONS(MIDR_CORTEX_X1C), data_source_common),
+	DS(MIDR_ALL_VERSIONS(MIDR_CORTEX_X3), data_source_common),
+	DS(MIDR_ALL_VERSIONS(MIDR_CORTEX_X925), data_source_common),
+	DS(MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N1), data_source_common),
+	DS(MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N2), data_source_common),
+	DS(MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V1), data_source_common),
+	DS(MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V2), data_source_common),
+	{},
+};
+
 static void arm_spe__synth_memory_level(const struct arm_spe_record *record,
 					union perf_mem_data_src *data_src)
 {
@@ -555,12 +567,14 @@ static void arm_spe__synth_memory_level(const struct arm_spe_record *record,
 		data_src->mem_lvl |= PERF_MEM_LVL_REM_CCE1;
 }
 
-static bool arm_spe__is_common_ds_encoding(struct arm_spe_queue *speq)
+static bool arm_spe__synth_ds(struct arm_spe_queue *speq,
+			      const struct arm_spe_record *record,
+			      union perf_mem_data_src *data_src)
 {
 	struct arm_spe *spe = speq->spe;
-	bool is_in_cpu_list;
+	const struct data_src *src = data_sources;
 	u64 *metadata = NULL;
-	u64 midr = 0;
+	u64 midr;
 
 	/* Metadata version 1 assumes all CPUs are the same (old behavior) */
 	if (spe->metadata_ver == 1) {
@@ -592,18 +606,21 @@ static bool arm_spe__is_common_ds_encoding(struct arm_spe_queue *speq)
 		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;
+	while (src->midr_range.model) {
+		if (is_midr_in_range(midr, &src->midr_range)) {
+			src->ds_synth(record, data_src);
+			return true;
+		}
+		src++;
+	}
+
+	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 = arm_spe__is_common_ds_encoding(speq);
 
 	if (record->op & ARM_SPE_OP_LD)
 		data_src.mem_op = PERF_MEM_OP_LOAD;
@@ -612,9 +629,7 @@ static u64 arm_spe__synth_data_source(struct arm_spe_queue *speq,
 	else
 		return 0;
 
-	if (is_common)
-		arm_spe__synth_data_source_common(record, &data_src);
-	else
+	if (!arm_spe__synth_ds(speq, record, &data_src))
 		arm_spe__synth_memory_level(record, &data_src);
 
 	if (record->type & (ARM_SPE_TLB_ACCESS | ARM_SPE_TLB_MISS)) {
Signature · 1 line
2.47.0
#2 lore raw

Re: [PATCH v3 1/2] perf arm-spe: Prepare for adding data source packet implementations for other cores

Hi Ilkka,

This is a good refactoring for me. Just several minor comments.

Quoted 14 lines · Ilkka Koskinen

Split Data Source Packet handling to prepare adding support for other implementations.

---
 tools/perf/util/arm-spe.c | 65 ++++++++++++++++++++++++---------------
 1 file changed, 40 insertions(+), 25 deletions(-)
tools/perf/util/arm-spe.c +0 -0
index dbf13f47879c..b222557cc27a 100644

tools/perf/util/arm-spe.c struct arm_spe_queue { · line 110

Quoted 8 lines
tools/perf/util/arm-spe.c +5 -0
@@ -103,6 +103,18 @@ struct arm_spe_queue {
        u32                             flags;
 };
 
+struct data_src {
+       struct midr_range midr_range;
+       void (*ds_synth)(const struct arm_spe_record *record,
+                        union perf_mem_data_src *data_src);
+};

The naming is a bit mess. The data structure and the parameter both are called "data_src", though this will not cause building issue.

How about rename the structure "data_src" to "data_source_handle" or "data_source_class"?

For the "midr_range" field, I'd like to change it to a pointer:

struct midr_range *midr_range;

Please see below comments, which will present the reason for defining it as a pointer.

Quoted 16 lines
tools/perf/util/arm-spe.c +7 -2
+
+#define DS(range, func)                        \
+       {                                               \
+               .midr_range = range,                    \
+               .ds_synth = arm_spe__synth_##func,      \
+       }
+
 static void arm_spe_dump(struct arm_spe *spe __maybe_unused,
                         unsigned char *buf, size_t len)
 {
@@ -430,19 +442,6 @@ 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 common_ds_encoding_cpus[] = {
-       MIDR_ALL_VERSIONS(MIDR_CORTEX_A720),

tools/perf/util/arm-spe.c static int arm_spe__synth_instruction_sample(struct arm_spe_queue *speq, · line 444

Quoted 10 lines
tools/perf/util/arm-spe.c +0 -10
-       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),
-       MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V2),
-       {},
-};

We can keep this data structure. For Ampere CPUs, you can add a new data structure:

  static const struct midr_range ampereone_ds_encoding_cpus[] = {
      MIDR_ALL_VERSIONS(MIDR_AMPERE1A),
      {},
  };
Quoted 11 lines
tools/perf/util/arm-spe.c +3 -1
-
 static void arm_spe__sample_flags(struct arm_spe_queue *speq)
 {
        const struct arm_spe_record *record = &speq->decoder->record;
@@ -532,6 +531,19 @@ static void arm_spe__synth_data_source_common(const struct arm_spe_record *recor
        }
 }
 
+static const struct data_src data_sources[] = {
+       DS(MIDR_ALL_VERSIONS(MIDR_CORTEX_A720), data_source_common),
+       DS(MIDR_ALL_VERSIONS(MIDR_CORTEX_A725), data_source_common),

tools/perf/util/arm-spe.c static void arm_spe__synth_data_source_common(const struct arm_spe_record *recor · line 546

Quoted 10 lines
tools/perf/util/arm-spe.c +10 -0
+       DS(MIDR_ALL_VERSIONS(MIDR_CORTEX_X1C), data_source_common),
+       DS(MIDR_ALL_VERSIONS(MIDR_CORTEX_X3), data_source_common),
+       DS(MIDR_ALL_VERSIONS(MIDR_CORTEX_X925), data_source_common),
+       DS(MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N1), data_source_common),
+       DS(MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N2), data_source_common),
+       DS(MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V1), data_source_common),
+       DS(MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V2), data_source_common),
+       {},
+};
+

As a result, we can simplify the structure as:

  static const struct data_src data_sources[] = {
         DS(common_ds_encoding_cpus, data_source_common),
         DS(ampereone_ds_encoding_cpus, data_source_ampereone),
  };
Quoted 27 lines
tools/perf/util/arm-spe.c +5 -5
 static void arm_spe__synth_memory_level(const struct arm_spe_record *record,
                                        union perf_mem_data_src *data_src)
 {
@@ -555,12 +567,14 @@ static void arm_spe__synth_memory_level(const struct arm_spe_record *record,
                data_src->mem_lvl |= PERF_MEM_LVL_REM_CCE1;
 }
 
-static bool arm_spe__is_common_ds_encoding(struct arm_spe_queue *speq)
+static bool arm_spe__synth_ds(struct arm_spe_queue *speq,
+                             const struct arm_spe_record *record,
+                             union perf_mem_data_src *data_src)
 {
        struct arm_spe *spe = speq->spe;
-       bool is_in_cpu_list;
+       const struct data_src *src = data_sources;
        u64 *metadata = NULL;
-       u64 midr = 0;
+       u64 midr;
 
        /* Metadata version 1 assumes all CPUs are the same (old behavior) */
        if (spe->metadata_ver == 1) {
@@ -592,18 +606,21 @@ static bool arm_spe__is_common_ds_encoding(struct arm_spe_queue *speq)
                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)

tools/perf/util/arm-spe.c static bool arm_spe__is_common_ds_encoding(struct arm_spe_queue *speq) · line 615

Quoted 10 lines
tools/perf/util/arm-spe.c +7 -3
-               return true;
-       else
-               return false;
+       while (src->midr_range.model) {
+               if (is_midr_in_range(midr, &src->midr_range)) {
+                       src->ds_synth(record, data_src);
+                       return true;
+               }
+               src++;
+       }

Here we can traverse the 'data_sources' array:

          for (i = 0; i < ARRAY_SIZE(data_sources); i++) {
               if (is_midr_in_range(midr, data_sources[i]->midr_range)) {
                   ...
               }
          }

Thanks,
Leo

Quoted 27 lines
tools/perf/util/arm-spe.c +3 -5
+
+       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 = arm_spe__is_common_ds_encoding(speq);
 
        if (record->op & ARM_SPE_OP_LD)
                data_src.mem_op = PERF_MEM_OP_LOAD;
@@ -612,9 +629,7 @@ static u64 arm_spe__synth_data_source(struct arm_spe_queue *speq,
        else
                return 0;
 
-       if (is_common)
-               arm_spe__synth_data_source_common(record, &data_src);
-       else
+       if (!arm_spe__synth_ds(speq, record, &data_src))
                arm_spe__synth_memory_level(record, &data_src);
 
        if (record->type & (ARM_SPE_TLB_ACCESS | ARM_SPE_TLB_MISS)) {
--

2.47.0

#3 lore raw

Re: [PATCH v3 1/2] perf arm-spe: Prepare for adding data source packet implementations for other cores

Hi Leo,

Quoted 31 lines · Leo Yan

Hi Ilkka,

This is a good refactoring for me. Just several minor comments.

Quoted 14 lines · Ilkka Koskinen

Split Data Source Packet handling to prepare adding support for other implementations.

---
 tools/perf/util/arm-spe.c | 65 ++++++++++++++++++++++++---------------
 1 file changed, 40 insertions(+), 25 deletions(-)
tools/perf/util/arm-spe.c +0 -0
index dbf13f47879c..b222557cc27a 100644

tools/perf/util/arm-spe.c struct arm_spe_queue { · line 110

Quoted 8 lines
tools/perf/util/arm-spe.c +5 -0
@@ -103,6 +103,18 @@ struct arm_spe_queue {
        u32                             flags;
 };
 
+struct data_src {
+       struct midr_range midr_range;
+       void (*ds_synth)(const struct arm_spe_record *record,
+                        union perf_mem_data_src *data_src);
+};

The naming is a bit mess. The data structure and the parameter both are called "data_src", though this will not cause building issue.

Quoted 2 lines

How about rename the structure "data_src" to "data_source_handle" or "data_source_class"?

Yeah, I forgot to revisit the naming part. I like "data"source_handle", that should clarify it quite a bit.

Quoted 38 lines

For the "midr_range" field, I'd like to change it to a pointer:

struct midr_range *midr_range;

Please see below comments, which will present the reason for defining it as a pointer.

Quoted 16 lines
tools/perf/util/arm-spe.c +7 -2
+
+#define DS(range, func)                        \
+       {                                               \
+               .midr_range = range,                    \
+               .ds_synth = arm_spe__synth_##func,      \
+       }
+
 static void arm_spe_dump(struct arm_spe *spe __maybe_unused,
                         unsigned char *buf, size_t len)
 {
@@ -430,19 +442,6 @@ 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 common_ds_encoding_cpus[] = {
-       MIDR_ALL_VERSIONS(MIDR_CORTEX_A720),

tools/perf/util/arm-spe.c static int arm_spe__synth_instruction_sample(struct arm_spe_queue *speq, · line 444

Quoted 10 lines
tools/perf/util/arm-spe.c +0 -10
-       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),
-       MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V2),
-       {},
-};

We can keep this data structure. For Ampere CPUs, you can add a new data structure:

Quoted 4 lines
 static const struct midr_range ampereone_ds_encoding_cpus[] = {
     MIDR_ALL_VERSIONS(MIDR_AMPERE1A),
     {},

};

Sounds good to me. I change all those.

Cheers, Ilkka

Quoted 107 lines
Quoted 12 lines
tools/perf/util/arm-spe.c +3 -1
-
 static void arm_spe__sample_flags(struct arm_spe_queue *speq)
 {
        const struct arm_spe_record *record = &speq->decoder->record;
@@ -532,6 +531,19 @@ static void arm_spe__synth_data_source_common(const struct arm_spe_record *recor
        }
 }
 
+static const struct data_src data_sources[] = {
+       DS(MIDR_ALL_VERSIONS(MIDR_CORTEX_A720), data_source_common),
+       DS(MIDR_ALL_VERSIONS(MIDR_CORTEX_A725), data_source_common),

tools/perf/util/arm-spe.c static void arm_spe__synth_data_source_common(const struct arm_spe_record *recor · line 546

Quoted 10 lines
tools/perf/util/arm-spe.c +10 -0
+       DS(MIDR_ALL_VERSIONS(MIDR_CORTEX_X1C), data_source_common),
+       DS(MIDR_ALL_VERSIONS(MIDR_CORTEX_X3), data_source_common),
+       DS(MIDR_ALL_VERSIONS(MIDR_CORTEX_X925), data_source_common),
+       DS(MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N1), data_source_common),
+       DS(MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N2), data_source_common),
+       DS(MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V1), data_source_common),
+       DS(MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V2), data_source_common),
+       {},
+};
+

As a result, we can simplify the structure as:

static const struct data_src data_sources[] = {
DS(common_ds_encoding_cpus, data_source_common), DS(ampereone_ds_encoding_cpus, data_source_ampereone),
};

Quoted 27 lines
tools/perf/util/arm-spe.c +5 -5
 static void arm_spe__synth_memory_level(const struct arm_spe_record *record,
                                        union perf_mem_data_src *data_src)
 {
@@ -555,12 +567,14 @@ static void arm_spe__synth_memory_level(const struct arm_spe_record *record,
                data_src->mem_lvl |= PERF_MEM_LVL_REM_CCE1;
 }
 
-static bool arm_spe__is_common_ds_encoding(struct arm_spe_queue *speq)
+static bool arm_spe__synth_ds(struct arm_spe_queue *speq,
+                             const struct arm_spe_record *record,
+                             union perf_mem_data_src *data_src)
 {
        struct arm_spe *spe = speq->spe;
-       bool is_in_cpu_list;
+       const struct data_src *src = data_sources;
        u64 *metadata = NULL;
-       u64 midr = 0;
+       u64 midr;
 
        /* Metadata version 1 assumes all CPUs are the same (old behavior) */
        if (spe->metadata_ver == 1) {
@@ -592,18 +606,21 @@ static bool arm_spe__is_common_ds_encoding(struct arm_spe_queue *speq)
                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)

tools/perf/util/arm-spe.c static bool arm_spe__is_common_ds_encoding(struct arm_spe_queue *speq) · line 615

Quoted 10 lines
tools/perf/util/arm-spe.c +7 -3
-               return true;
-       else
-               return false;
+       while (src->midr_range.model) {
+               if (is_midr_in_range(midr, &src->midr_range)) {
+                       src->ds_synth(record, data_src);
+                       return true;
+               }
+               src++;
+       }

Here we can traverse the 'data_sources' array:

         for (i = 0; i < ARRAY_SIZE(data_sources); i++) {
              if (is_midr_in_range(midr, data_sources[i]->midr_range)) {
                  ...
              }
         }

Thanks,
Leo

Quoted 27 lines
tools/perf/util/arm-spe.c +3 -5
+
+       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 = arm_spe__is_common_ds_encoding(speq);
 
        if (record->op & ARM_SPE_OP_LD)
                data_src.mem_op = PERF_MEM_OP_LOAD;
@@ -612,9 +629,7 @@ static u64 arm_spe__synth_data_source(struct arm_spe_queue *speq,
        else
                return 0;
 
-       if (is_common)
-               arm_spe__synth_data_source_common(record, &data_src);
-       else
+       if (!arm_spe__synth_ds(speq, record, &data_src))
                arm_spe__synth_memory_level(record, &data_src);
 
        if (record->type & (ARM_SPE_TLB_ACCESS | ARM_SPE_TLB_MISS)) {
--

2.47.0

#4 lore raw

PATCH v3 2/2 perf arm-spe: Add support for SPE Data Source packet on AmpereOne

In reply to Ilkka Koskinen

Decode SPE Data Source packets on AmpereOne. The field is IMPDEF.

---
 .../util/arm-spe-decoder/arm-spe-decoder.h    |  9 +++++
 tools/perf/util/arm-spe.c                     | 39 +++++++++++++++++++
 2 files changed, 48 insertions(+)
tools/perf/util/arm-spe-decoder/arm-spe-decoder.h +9 -0
index 358c611eeddb..4bcd627e859f 100644
@@ -67,6 +67,15 @@ enum arm_spe_common_data_source {
 	ARM_SPE_COMMON_DS_DRAM		= 0xe,
 };
 
+enum arm_spe_ampereone_data_source {
+	ARM_SPE_AMPEREONE_LOCAL_CHIP_CACHE_OR_DEVICE    = 0x0,
+	ARM_SPE_AMPEREONE_SLC                           = 0x3,
+	ARM_SPE_AMPEREONE_REMOTE_CHIP_CACHE             = 0x5,
+	ARM_SPE_AMPEREONE_DDR                           = 0x7,
+	ARM_SPE_AMPEREONE_L1D                           = 0x8,
+	ARM_SPE_AMPEREONE_L2D                           = 0x9,
+};
+
 struct arm_spe_record {
 	enum arm_spe_sample_type type;
 	int err;
tools/perf/util/arm-spe.c +39 -0
index b222557cc27a..40847a3d18b0 100644
@@ -531,6 +531,44 @@ static void arm_spe__synth_data_source_common(const struct arm_spe_record *recor
 	}
 }
 
+/*
+ * Source is IMPDEF. Here we convert the source code used on AmpereOne cores
+ * to the common (Neoverse, Cortex) to avoid duplicating the decoding code.
+ */
+static void arm_spe__synth_data_source_ampereone(const struct arm_spe_record *record,
+						 union perf_mem_data_src *data_src)
+{
+	struct arm_spe_record common_record;
+
+	switch (record->source) {
+	case ARM_SPE_AMPEREONE_LOCAL_CHIP_CACHE_OR_DEVICE:
+		common_record.source = ARM_SPE_COMMON_DS_PEER_CORE;
+		break;
+	case ARM_SPE_AMPEREONE_SLC:
+		common_record.source = ARM_SPE_COMMON_DS_SYS_CACHE;
+		break;
+	case ARM_SPE_AMPEREONE_REMOTE_CHIP_CACHE:
+		common_record.source = ARM_SPE_COMMON_DS_REMOTE;
+		break;
+	case ARM_SPE_AMPEREONE_DDR:
+		common_record.source = ARM_SPE_COMMON_DS_DRAM;
+		break;
+	case ARM_SPE_AMPEREONE_L1D:
+		common_record.source = ARM_SPE_COMMON_DS_L1D;
+		break;
+	case ARM_SPE_AMPEREONE_L2D:
+		common_record.source = ARM_SPE_COMMON_DS_L2;
+		break;
+	default:
+		/* Assign a bogus value that's not used for common coding */
+		common_record.source = 0xffff;
+		break;
+	}
+
+	common_record.op = record->op;
+	arm_spe__synth_data_source_common(&common_record, data_src);
+}
+
 static const struct data_src data_sources[] = {
 	DS(MIDR_ALL_VERSIONS(MIDR_CORTEX_A720), data_source_common),
 	DS(MIDR_ALL_VERSIONS(MIDR_CORTEX_A725), data_source_common),
@@ -541,6 +579,7 @@ static const struct data_src data_sources[] = {
 	DS(MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N2), data_source_common),
 	DS(MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V1), data_source_common),
 	DS(MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V2), data_source_common),
+	DS(MIDR_ALL_VERSIONS(MIDR_AMPERE1A), data_source_ampereone),
 	{},
 };
 
Signature · 1 line
2.47.0
#5 lore raw
Quoted 60 lines · Ilkka Koskinen

Warning: EXTERNAL SENDER, use caution when opening links or attachments.

Decode SPE Data Source packets on AmpereOne. The field is IMPDEF.

---
 .../util/arm-spe-decoder/arm-spe-decoder.h    |  9 +++++
 tools/perf/util/arm-spe.c                     | 39 +++++++++++++++++++
 2 files changed, 48 insertions(+)
tools/perf/util/arm-spe-decoder/arm-spe-decoder.h +9 -0
index 358c611eeddb..4bcd627e859f 100644
@@ -67,6 +67,15 @@ enum arm_spe_common_data_source {
        ARM_SPE_COMMON_DS_DRAM          = 0xe,
 };
 
+enum arm_spe_ampereone_data_source {
+       ARM_SPE_AMPEREONE_LOCAL_CHIP_CACHE_OR_DEVICE    = 0x0,
+       ARM_SPE_AMPEREONE_SLC                           = 0x3,
+       ARM_SPE_AMPEREONE_REMOTE_CHIP_CACHE             = 0x5,
+       ARM_SPE_AMPEREONE_DDR                           = 0x7,
+       ARM_SPE_AMPEREONE_L1D                           = 0x8,
+       ARM_SPE_AMPEREONE_L2D                           = 0x9,
+};
+
 struct arm_spe_record {
        enum arm_spe_sample_type type;
        int err;
tools/perf/util/arm-spe.c +21 -0
index b222557cc27a..40847a3d18b0 100644
@@ -531,6 +531,44 @@ static void arm_spe__synth_data_source_common(const struct arm_spe_record *recor
        }
 }
 
+/*
+ * Source is IMPDEF. Here we convert the source code used on AmpereOne cores
+ * to the common (Neoverse, Cortex) to avoid duplicating the decoding code.
+ */
+static void arm_spe__synth_data_source_ampereone(const struct arm_spe_record *record,
+                                                union perf_mem_data_src *data_src)
+{
+       struct arm_spe_record common_record;
+
+       switch (record->source) {
+       case ARM_SPE_AMPEREONE_LOCAL_CHIP_CACHE_OR_DEVICE:
+               common_record.source = ARM_SPE_COMMON_DS_PEER_CORE;
+               break;
+       case ARM_SPE_AMPEREONE_SLC:
+               common_record.source = ARM_SPE_COMMON_DS_SYS_CACHE;
+               break;
+       case ARM_SPE_AMPEREONE_REMOTE_CHIP_CACHE:
+               common_record.source = ARM_SPE_COMMON_DS_REMOTE;
+               break;
+       case ARM_SPE_AMPEREONE_DDR:
+               common_record.source = ARM_SPE_COMMON_DS_DRAM;

tools/perf/util/arm-spe.c static void arm_spe__synth_data_source_common(const struct arm_spe_record *recor · line 564

Quoted 10 lines
tools/perf/util/arm-spe.c +10 -0
+               break;
+       case ARM_SPE_AMPEREONE_L1D:
+               common_record.source = ARM_SPE_COMMON_DS_L1D;
+               break;
+       case ARM_SPE_AMPEREONE_L2D:
+               common_record.source = ARM_SPE_COMMON_DS_L2;
+               break;
+       default:
+               /* Assign a bogus value that's not used for common coding */
+               common_record.source = 0xffff;

For unsupported source value, just bail out and no need to calling arm_spe__synth_data_source_common().

It is good to use pr_warning_once() to print out warning log to remind users.

Thanks,
Leo

Quoted 22 lines
tools/perf/util/arm-spe.c +8 -1
+               break;
+       }
+
+       common_record.op = record->op;
+       arm_spe__synth_data_source_common(&common_record, data_src);
+}
+
 static const struct data_src data_sources[] = {
        DS(MIDR_ALL_VERSIONS(MIDR_CORTEX_A720), data_source_common),
        DS(MIDR_ALL_VERSIONS(MIDR_CORTEX_A725), data_source_common),
@@ -541,6 +579,7 @@ static const struct data_src data_sources[] = {
        DS(MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N2), data_source_common),
        DS(MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V1), data_source_common),
        DS(MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V2), data_source_common),
+       DS(MIDR_ALL_VERSIONS(MIDR_AMPERE1A), data_source_ampereone),
        {},
 };
 
--

2.47.0

#6 lore raw
Quoted 75 lines · Leo Yan
Quoted 60 lines · Ilkka Koskinen

Warning: EXTERNAL SENDER, use caution when opening links or attachments.

Decode SPE Data Source packets on AmpereOne. The field is IMPDEF.

---
 .../util/arm-spe-decoder/arm-spe-decoder.h    |  9 +++++
 tools/perf/util/arm-spe.c                     | 39 +++++++++++++++++++
 2 files changed, 48 insertions(+)
tools/perf/util/arm-spe-decoder/arm-spe-decoder.h +9 -0
index 358c611eeddb..4bcd627e859f 100644
@@ -67,6 +67,15 @@ enum arm_spe_common_data_source {
        ARM_SPE_COMMON_DS_DRAM          = 0xe,
 };
 
+enum arm_spe_ampereone_data_source {
+       ARM_SPE_AMPEREONE_LOCAL_CHIP_CACHE_OR_DEVICE    = 0x0,
+       ARM_SPE_AMPEREONE_SLC                           = 0x3,
+       ARM_SPE_AMPEREONE_REMOTE_CHIP_CACHE             = 0x5,
+       ARM_SPE_AMPEREONE_DDR                           = 0x7,
+       ARM_SPE_AMPEREONE_L1D                           = 0x8,
+       ARM_SPE_AMPEREONE_L2D                           = 0x9,
+};
+
 struct arm_spe_record {
        enum arm_spe_sample_type type;
        int err;
tools/perf/util/arm-spe.c +21 -0
index b222557cc27a..40847a3d18b0 100644
@@ -531,6 +531,44 @@ static void arm_spe__synth_data_source_common(const struct arm_spe_record *recor
        }
 }
 
+/*
+ * Source is IMPDEF. Here we convert the source code used on AmpereOne cores
+ * to the common (Neoverse, Cortex) to avoid duplicating the decoding code.
+ */
+static void arm_spe__synth_data_source_ampereone(const struct arm_spe_record *record,
+                                                union perf_mem_data_src *data_src)
+{
+       struct arm_spe_record common_record;
+
+       switch (record->source) {
+       case ARM_SPE_AMPEREONE_LOCAL_CHIP_CACHE_OR_DEVICE:
+               common_record.source = ARM_SPE_COMMON_DS_PEER_CORE;
+               break;
+       case ARM_SPE_AMPEREONE_SLC:
+               common_record.source = ARM_SPE_COMMON_DS_SYS_CACHE;
+               break;
+       case ARM_SPE_AMPEREONE_REMOTE_CHIP_CACHE:
+               common_record.source = ARM_SPE_COMMON_DS_REMOTE;
+               break;
+       case ARM_SPE_AMPEREONE_DDR:
+               common_record.source = ARM_SPE_COMMON_DS_DRAM;

tools/perf/util/arm-spe.c static void arm_spe__synth_data_source_common(const struct arm_spe_record *recor · line 564

Quoted 10 lines
tools/perf/util/arm-spe.c +10 -0
+               break;
+       case ARM_SPE_AMPEREONE_L1D:
+               common_record.source = ARM_SPE_COMMON_DS_L1D;
+               break;
+       case ARM_SPE_AMPEREONE_L2D:
+               common_record.source = ARM_SPE_COMMON_DS_L2;
+               break;
+       default:
+               /* Assign a bogus value that's not used for common coding */
+               common_record.source = 0xffff;

For unsupported source value, just bail out and no need to calling arm_spe__synth_data_source_common().

Quoted 2 lines

It is good to use pr_warning_once() to print out warning log to remind users.

Hi Leo,

Makes sense, I'll do that.

--Ilkka

Quoted 27 lines

Thanks,
Leo

Quoted 22 lines
tools/perf/util/arm-spe.c +8 -1
+               break;
+       }
+
+       common_record.op = record->op;
+       arm_spe__synth_data_source_common(&common_record, data_src);
+}
+
 static const struct data_src data_sources[] = {
        DS(MIDR_ALL_VERSIONS(MIDR_CORTEX_A720), data_source_common),
        DS(MIDR_ALL_VERSIONS(MIDR_CORTEX_A725), data_source_common),
@@ -541,6 +579,7 @@ static const struct data_src data_sources[] = {
        DS(MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N2), data_source_common),
        DS(MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V1), data_source_common),
        DS(MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V2), data_source_common),
+       DS(MIDR_ALL_VERSIONS(MIDR_AMPERE1A), data_source_ampereone),
        {},
 };
 
--

2.47.0