Skip to contentSkip to conversation

perf test: Improve pmu-events support

PATCH In review John Garry 2 participants 22 messages Jul 29, 2021 – Aug 11, 2021 perf events

lore
Share & tools
lore

John Garry

author
#0 lore raw

cover perf test: Improve pmu-events support

Recently it has been shown that the pmu-events tests do not always catch broken uncore PMU alias support.

The main problem is that the alias matching only tests uncore PMUs which are present in the host system, so pretty useless.

This series improves that by using fake uncore PMUs, and verifying aliases generated for those PMUs match known expected values.

This means that even if one arch does not have PMUs which support some special aliasing, like multiple tokens, we can still have a fake uncore PMU test on that arch.

Support is also added to test system PMUs alias matching.

Based on 5.14-rc1 + "perf pmu: Fix alias matching".

John Garry (11):
perf test: Factor out pmu-events event comparison perf jevents: Relocate test events to cpu folder perf test: Declare pmu-events test events separately perf test: Factor out pmu-events alias comparison perf test: Test pmu-events core aliases separately perf pmu: Check .is_uncore field in pmu_add_cpu_aliases_map() perf test: Re-add pmu-event uncore PMU alias test perf test: Add more pmu-events uncore aliases
perf pmu: Make pmu_add_sys_aliases() public
perf jevents: Print SoC name per system event table perf test: Add pmu-events sys event support

 .../{test_cpu => test_soc/cpu}/branch.json    |   0
 .../{test_cpu => test_soc/cpu}/cache.json     |   0
 .../{test_cpu => test_soc/cpu}/other.json     |   0
 .../{test_cpu => test_soc/cpu}/uncore.json    |  23 +-
 .../arch/test/test_soc/sys/uncore.json        |   9 +
 tools/perf/pmu-events/jevents.c               |   5 +-
 tools/perf/pmu-events/pmu-events.h            |   1 +
 tools/perf/tests/pmu-events.c                 | 699 +++++++++++++-----
 tools/perf/util/pmu.c                         |   5 +-
 tools/perf/util/pmu.h                         |   1 +
 10 files changed, 533 insertions(+), 210 deletions(-)
 rename tools/perf/pmu-events/arch/test/{test_cpu => test_soc/cpu}/branch.json (100%)
 rename tools/perf/pmu-events/arch/test/{test_cpu => test_soc/cpu}/cache.json (100%)
 rename tools/perf/pmu-events/arch/test/{test_cpu => test_soc/cpu}/other.json (100%)
 rename tools/perf/pmu-events/arch/test/{test_cpu => test_soc/cpu}/uncore.json (51%)
 create mode 100644 tools/perf/pmu-events/arch/test/test_soc/sys/uncore.json
Signature · 1 line
2.26.2
author
#1 lore raw

PATCH 1/11 perf test: Factor out pmu-events event comparison

Factor out event comparison which will be used in multiple places.

Also test "pmu" and "compat" fields.

---
 tools/perf/tests/pmu-events.c | 119 +++++++++++++++++++---------------
 1 file changed, 66 insertions(+), 53 deletions(-)
tools/perf/tests/pmu-events.c +66 -53
index b8aff8fb50d8..c064f08c63c9 100644
@@ -161,6 +161,71 @@ static struct pmu_events_map *__test_pmu_get_events_map(void)
 	return NULL;
 }
 
+static int compare_pmu_events(struct pmu_event *e1, const struct pmu_event *e2)
+{
+	if (!is_same(e1->desc, e2->desc)) {
+		pr_debug2("testing event e1 %s: mismatched desc, %s vs %s\n",
+			  e1->name, e1->desc, e2->desc);
+		return -1;
+	}
+
+	if (!is_same(e1->topic, e2->topic)) {
+		pr_debug2("testing event e1 %s: mismatched topic, %s vs %s\n",
+			  e1->name, e1->topic, e2->topic);
+		return -1;
+	}
+
+	if (!is_same(e1->long_desc, e2->long_desc)) {
+		pr_debug2("testing event e1 %s: mismatched long_desc, %s vs %s\n",
+			  e1->name, e1->long_desc, e2->long_desc);
+		return -1;
+	}
+
+	if (!is_same(e1->unit, e2->unit)) {
+		pr_debug2("testing event e1 %s: mismatched unit, %s vs %s\n",
+			  e1->name, e1->unit, e2->unit);
+		return -1;
+	}
+
+	if (!is_same(e1->perpkg, e2->perpkg)) {
+		pr_debug2("testing event e1 %s: mismatched perpkg, %s vs %s\n",
+			  e1->name, e1->perpkg, e2->perpkg);
+		return -1;
+	}
+
+	if (!is_same(e1->metric_expr, e2->metric_expr)) {
+		pr_debug2("testing event e1 %s: mismatched metric_expr, %s vs %s\n",
+			  e1->name, e1->metric_expr, e2->metric_expr);
+		return -1;
+	}
+
+	if (!is_same(e1->metric_name, e2->metric_name)) {
+		pr_debug2("testing event e1 %s: mismatched metric_name, %s vs %s\n",
+			  e1->name,	e1->metric_name, e2->metric_name);
+		return -1;
+	}
+
+	if (!is_same(e1->deprecated, e2->deprecated)) {
+		pr_debug2("testing event e1 %s: mismatched deprecated, %s vs %s\n",
+			  e1->name, e1->deprecated, e2->deprecated);
+		return -1;
+	}
+
+	if (!is_same(e1->pmu, e2->pmu)) {
+		pr_debug2("testing event e1 %s: mismatched pmu string, %s vs %s\n",
+			  e1->name, e1->pmu, e2->pmu);
+		return -1;
+	}
+
+	if (!is_same(e1->compat, e2->compat)) {
+		pr_debug2("testing event e1 %s: mismatched compat string, %s vs %s\n",
+			  e1->name, e1->compat, e2->compat);
+		return -1;
+	}
+
+	return 0;
+}
+
 /* Verify generated events from pmu-events.c is as expected */
 static int test_pmu_event_table(void)
 {
@@ -193,60 +258,8 @@ static int test_pmu_event_table(void)
 			found = true;
 			map_events++;
 
-			if (!is_same(table->desc, te->desc)) {
-				pr_debug2("testing event table %s: mismatched desc, %s vs %s\n",
-					  table->name, table->desc, te->desc);
-				return -1;
-			}
-
-			if (!is_same(table->topic, te->topic)) {
-				pr_debug2("testing event table %s: mismatched topic, %s vs %s\n",
-					  table->name, table->topic,
-					  te->topic);
-				return -1;
-			}
-
-			if (!is_same(table->long_desc, te->long_desc)) {
-				pr_debug2("testing event table %s: mismatched long_desc, %s vs %s\n",
-					  table->name, table->long_desc,
-					  te->long_desc);
-				return -1;
-			}
-
-			if (!is_same(table->unit, te->unit)) {
-				pr_debug2("testing event table %s: mismatched unit, %s vs %s\n",
-					  table->name, table->unit,
-					  te->unit);
-				return -1;
-			}
-
-			if (!is_same(table->perpkg, te->perpkg)) {
-				pr_debug2("testing event table %s: mismatched perpkg, %s vs %s\n",
-					  table->name, table->perpkg,
-					  te->perpkg);
-				return -1;
-			}
-
-			if (!is_same(table->metric_expr, te->metric_expr)) {
-				pr_debug2("testing event table %s: mismatched metric_expr, %s vs %s\n",
-					  table->name, table->metric_expr,
-					  te->metric_expr);
+			if (compare_pmu_events(table, te))
 				return -1;
-			}
-
-			if (!is_same(table->metric_name, te->metric_name)) {
-				pr_debug2("testing event table %s: mismatched metric_name, %s vs %s\n",
-					  table->name,  table->metric_name,
-					  te->metric_name);
-				return -1;
-			}
-
-			if (!is_same(table->deprecated, te->deprecated)) {
-				pr_debug2("testing event table %s: mismatched deprecated, %s vs %s\n",
-					  table->name, table->deprecated,
-					  te->deprecated);
-				return -1;
-			}
 
 			pr_debug("testing event table %s: pass\n", table->name);
 		}
Signature · 1 line
2.26.2
author
#2 lore raw

PATCH 2/11 perf jevents: Relocate test events to cpu folder

In reply to John Garry

In future to add support for sys events, relocate the core and uncore events to a cpu folder.

---
 .../pmu-events/arch/test/{test_cpu => test_soc/cpu}/branch.json | 0
 .../pmu-events/arch/test/{test_cpu => test_soc/cpu}/cache.json  | 0
 .../pmu-events/arch/test/{test_cpu => test_soc/cpu}/other.json  | 0
 .../pmu-events/arch/test/{test_cpu => test_soc/cpu}/uncore.json | 0
 tools/perf/pmu-events/jevents.c                                 | 2 +-
 5 files changed, 1 insertion(+), 1 deletion(-)
 rename tools/perf/pmu-events/arch/test/{test_cpu => test_soc/cpu}/branch.json (100%)
 rename tools/perf/pmu-events/arch/test/{test_cpu => test_soc/cpu}/cache.json (100%)
 rename tools/perf/pmu-events/arch/test/{test_cpu => test_soc/cpu}/other.json (100%)
 rename tools/perf/pmu-events/arch/test/{test_cpu => test_soc/cpu}/uncore.json (100%)
tools/perf/pmu-events/arch/test/test_soc/cpu/branch.json renamed from tools/perf/pmu-events/arch/test/test_cpu/branch.json +0 -0
similarity index 100%
rename from tools/perf/pmu-events/arch/test/test_cpu/branch.json
rename to tools/perf/pmu-events/arch/test/test_soc/cpu/branch.json
tools/perf/pmu-events/arch/test/test_soc/cpu/cache.json renamed from tools/perf/pmu-events/arch/test/test_cpu/cache.json +0 -0
similarity index 100%
rename from tools/perf/pmu-events/arch/test/test_cpu/cache.json
rename to tools/perf/pmu-events/arch/test/test_soc/cpu/cache.json
tools/perf/pmu-events/arch/test/test_soc/cpu/other.json renamed from tools/perf/pmu-events/arch/test/test_cpu/other.json +0 -0
similarity index 100%
rename from tools/perf/pmu-events/arch/test/test_cpu/other.json
rename to tools/perf/pmu-events/arch/test/test_soc/cpu/other.json
tools/perf/pmu-events/arch/test/test_soc/cpu/uncore.json renamed from tools/perf/pmu-events/arch/test/test_cpu/uncore.json +0 -0
similarity index 100%
rename from tools/perf/pmu-events/arch/test/test_cpu/uncore.json
rename to tools/perf/pmu-events/arch/test/test_soc/cpu/uncore.json
tools/perf/pmu-events/jevents.c +1 -1
index 9604446f8360..405bdd36b9b9 100644
@@ -814,7 +814,7 @@ static void print_mapping_test_table(FILE *outfp)
 	fprintf(outfp, "\t.cpuid = \"testcpu\",\n");
 	fprintf(outfp, "\t.version = \"v1\",\n");
 	fprintf(outfp, "\t.type = \"core\",\n");
-	fprintf(outfp, "\t.table = pme_test_cpu,\n");
+	fprintf(outfp, "\t.table = pme_test_soc_cpu,\n");
 	fprintf(outfp, "},\n");
 }
 
Signature · 1 line
2.26.2
#3 lore raw

Re: [PATCH 02/11] perf jevents: Relocate test events to cpu folder

Em Thu, Jul 29, 2021 at 09:56:17PM +0800, John Garry escreveu:

Quoted 37 lines

In future to add support for sys events, relocate the core and uncore events to a cpu folder.

---
 .../pmu-events/arch/test/{test_cpu => test_soc/cpu}/branch.json | 0
 .../pmu-events/arch/test/{test_cpu => test_soc/cpu}/cache.json  | 0
 .../pmu-events/arch/test/{test_cpu => test_soc/cpu}/other.json  | 0
 .../pmu-events/arch/test/{test_cpu => test_soc/cpu}/uncore.json | 0
 tools/perf/pmu-events/jevents.c                                 | 2 +-
 5 files changed, 1 insertion(+), 1 deletion(-)
 rename tools/perf/pmu-events/arch/test/{test_cpu => test_soc/cpu}/branch.json (100%)
 rename tools/perf/pmu-events/arch/test/{test_cpu => test_soc/cpu}/cache.json (100%)
 rename tools/perf/pmu-events/arch/test/{test_cpu => test_soc/cpu}/other.json (100%)
 rename tools/perf/pmu-events/arch/test/{test_cpu => test_soc/cpu}/uncore.json (100%)
tools/perf/pmu-events/arch/test/test_soc/cpu/branch.json renamed from tools/perf/pmu-events/arch/test/test_cpu/branch.json +0 -0
similarity index 100%
rename from tools/perf/pmu-events/arch/test/test_cpu/branch.json
rename to tools/perf/pmu-events/arch/test/test_soc/cpu/branch.json
tools/perf/pmu-events/arch/test/test_soc/cpu/cache.json renamed from tools/perf/pmu-events/arch/test/test_cpu/cache.json +0 -0
similarity index 100%
rename from tools/perf/pmu-events/arch/test/test_cpu/cache.json
rename to tools/perf/pmu-events/arch/test/test_soc/cpu/cache.json
tools/perf/pmu-events/arch/test/test_soc/cpu/other.json renamed from tools/perf/pmu-events/arch/test/test_cpu/other.json +0 -0
similarity index 100%
rename from tools/perf/pmu-events/arch/test/test_cpu/other.json
rename to tools/perf/pmu-events/arch/test/test_soc/cpu/other.json
tools/perf/pmu-events/arch/test/test_soc/cpu/uncore.json renamed from tools/perf/pmu-events/arch/test/test_cpu/uncore.json +0 -0
similarity index 100%
rename from tools/perf/pmu-events/arch/test/test_cpu/uncore.json
rename to tools/perf/pmu-events/arch/test/test_soc/cpu/uncore.json
tools/perf/pmu-events/jevents.c +0 -0
index 9604446f8360..405bdd36b9b9 100644

tools/perf/pmu-events/jevents.c static void print_mapping_test_table(FILE *outfp) · line 817

Quoted 5 lines
tools/perf/pmu-events/jevents.c +1 -1
@@ -814,7 +814,7 @@ static void print_mapping_test_table(FILE *outfp)
 	fprintf(outfp, "\t.cpuid = \"testcpu\",\n");
 	fprintf(outfp, "\t.version = \"v1\",\n");
 	fprintf(outfp, "\t.type = \"core\",\n");
-	fprintf(outfp, "\t.table = pme_test_cpu,\n");
+	fprintf(outfp, "\t.table = pme_test_soc_cpu,\n");

Humm, is this already generated by some script? I.e. this 'pme_test_soc_cpu' table? Or does this works only when applying the full patchset?

- Arnaldo

Quoted 6 lines
tools/perf/pmu-events/jevents.c +0 -0
 	fprintf(outfp, "},\n");
 }
 
Signature · 1 line
2.26.2
Signature · 1 line
- Arnaldo
author
#4 lore raw

Re: [PATCH 02/11] perf jevents: Relocate test events to cpu folder

Quoted 38 lines · Arnaldo Carvalho de Melo

Em Thu, Jul 29, 2021 at 09:56:17PM +0800, John Garry escreveu:

Quoted 37 lines

In future to add support for sys events, relocate the core and uncore events to a cpu folder.

---
  .../pmu-events/arch/test/{test_cpu => test_soc/cpu}/branch.json | 0
  .../pmu-events/arch/test/{test_cpu => test_soc/cpu}/cache.json  | 0
  .../pmu-events/arch/test/{test_cpu => test_soc/cpu}/other.json  | 0
  .../pmu-events/arch/test/{test_cpu => test_soc/cpu}/uncore.json | 0
  tools/perf/pmu-events/jevents.c                                 | 2 +-
  5 files changed, 1 insertion(+), 1 deletion(-)

rename tools/perf/pmu-events/arch/test/{test_cpu => test_soc/cpu}/branch.json (100%) rename tools/perf/pmu-events/arch/test/{test_cpu => test_soc/cpu}/cache.json (100%) rename tools/perf/pmu-events/arch/test/{test_cpu => test_soc/cpu}/other.json (100%) rename tools/perf/pmu-events/arch/test/{test_cpu => test_soc/cpu}/uncore.json (100%)

tools/perf/pmu-events/arch/test/test_soc/cpu/branch.json renamed from tools/perf/pmu-events/arch/test/test_cpu/branch.json +0 -0
similarity index 100%
rename from tools/perf/pmu-events/arch/test/test_cpu/branch.json
rename to tools/perf/pmu-events/arch/test/test_soc/cpu/branch.json
tools/perf/pmu-events/arch/test/test_soc/cpu/cache.json renamed from tools/perf/pmu-events/arch/test/test_cpu/cache.json +0 -0
similarity index 100%
rename from tools/perf/pmu-events/arch/test/test_cpu/cache.json
rename to tools/perf/pmu-events/arch/test/test_soc/cpu/cache.json
tools/perf/pmu-events/arch/test/test_soc/cpu/other.json renamed from tools/perf/pmu-events/arch/test/test_cpu/other.json +0 -0
similarity index 100%
rename from tools/perf/pmu-events/arch/test/test_cpu/other.json
rename to tools/perf/pmu-events/arch/test/test_soc/cpu/other.json
tools/perf/pmu-events/arch/test/test_soc/cpu/uncore.json renamed from tools/perf/pmu-events/arch/test/test_cpu/uncore.json +0 -0
similarity index 100%
rename from tools/perf/pmu-events/arch/test/test_cpu/uncore.json
rename to tools/perf/pmu-events/arch/test/test_soc/cpu/uncore.json
tools/perf/pmu-events/jevents.c +0 -0
index 9604446f8360..405bdd36b9b9 100644
@@ -814,7 +814,7 @@ static void print_mapping_test_table(FILE *outfp)
Quoted 8 lines

tools/perf/pmu-events/jevents.c static void print_mapping_test_table(FILE *outfp) · line 817

Quoted 5 lines
tools/perf/pmu-events/jevents.c +1 -1
  	fprintf(outfp, "\t.cpuid = \"testcpu\",\n");
  	fprintf(outfp, "\t.version = \"v1\",\n");
  	fprintf(outfp, "\t.type = \"core\",\n");
-	fprintf(outfp, "\t.table = pme_test_cpu,\n");
+	fprintf(outfp, "\t.table = pme_test_soc_cpu,\n");

Humm, is this already generated by some script? I.e. this 'pme_test_soc_cpu' table? Or does this works only when applying the full patchset?

Hi Arnaldo,

This file jevents.c generates a table in tools/perf/pmu-events/pmu-events.c

Are you having some issue in applying and building this?

I ask as I think that there is some pre-existing dependency issue which I mean to fix, i.e. so please try a clean build.

Thanks,
John

author
#5 lore raw

Re: [PATCH 02/11] perf jevents: Relocate test events to cpu folder

In reply to Arnaldo Carvalho de Melo
Quoted 38 lines · Arnaldo Carvalho de Melo

Em Thu, Jul 29, 2021 at 09:56:17PM +0800, John Garry escreveu:

Quoted 37 lines

In future to add support for sys events, relocate the core and uncore events to a cpu folder.

---
  .../pmu-events/arch/test/{test_cpu => test_soc/cpu}/branch.json | 0
  .../pmu-events/arch/test/{test_cpu => test_soc/cpu}/cache.json  | 0
  .../pmu-events/arch/test/{test_cpu => test_soc/cpu}/other.json  | 0
  .../pmu-events/arch/test/{test_cpu => test_soc/cpu}/uncore.json | 0
  tools/perf/pmu-events/jevents.c                                 | 2 +-
  5 files changed, 1 insertion(+), 1 deletion(-)

rename tools/perf/pmu-events/arch/test/{test_cpu => test_soc/cpu}/branch.json (100%) rename tools/perf/pmu-events/arch/test/{test_cpu => test_soc/cpu}/cache.json (100%) rename tools/perf/pmu-events/arch/test/{test_cpu => test_soc/cpu}/other.json (100%) rename tools/perf/pmu-events/arch/test/{test_cpu => test_soc/cpu}/uncore.json (100%)

tools/perf/pmu-events/arch/test/test_soc/cpu/branch.json renamed from tools/perf/pmu-events/arch/test/test_cpu/branch.json +0 -0
similarity index 100%
rename from tools/perf/pmu-events/arch/test/test_cpu/branch.json
rename to tools/perf/pmu-events/arch/test/test_soc/cpu/branch.json
tools/perf/pmu-events/arch/test/test_soc/cpu/cache.json renamed from tools/perf/pmu-events/arch/test/test_cpu/cache.json +0 -0
similarity index 100%
rename from tools/perf/pmu-events/arch/test/test_cpu/cache.json
rename to tools/perf/pmu-events/arch/test/test_soc/cpu/cache.json
tools/perf/pmu-events/arch/test/test_soc/cpu/other.json renamed from tools/perf/pmu-events/arch/test/test_cpu/other.json +0 -0
similarity index 100%
rename from tools/perf/pmu-events/arch/test/test_cpu/other.json
rename to tools/perf/pmu-events/arch/test/test_soc/cpu/other.json
tools/perf/pmu-events/arch/test/test_soc/cpu/uncore.json renamed from tools/perf/pmu-events/arch/test/test_cpu/uncore.json +0 -0
similarity index 100%
rename from tools/perf/pmu-events/arch/test/test_cpu/uncore.json
rename to tools/perf/pmu-events/arch/test/test_soc/cpu/uncore.json
tools/perf/pmu-events/jevents.c +0 -0
index 9604446f8360..405bdd36b9b9 100644
@@ -814,7 +814,7 @@ static void print_mapping_test_table(FILE *outfp)
Quoted 8 lines

tools/perf/pmu-events/jevents.c static void print_mapping_test_table(FILE *outfp) · line 817

Quoted 5 lines
tools/perf/pmu-events/jevents.c +1 -1
  	fprintf(outfp, "\t.cpuid = \"testcpu\",\n");
  	fprintf(outfp, "\t.version = \"v1\",\n");
  	fprintf(outfp, "\t.type = \"core\",\n");
-	fprintf(outfp, "\t.table = pme_test_cpu,\n");
+	fprintf(outfp, "\t.table = pme_test_soc_cpu,\n");

Humm, is this already generated by some script? I.e. this 'pme_test_soc_cpu' table? Or does this works only when applying the full patchset?

So I think we need something like this:

----->8--------

From a08df563665e9ec088b1af86ceed058497e112a4 Mon Sep 17 00:00:00 2001
From: John Garry <[email protected]>
Date: Tue, 3 Aug 2021 08:44:09 +0100
Subject: [PATCH] perf jevents: Make build dependency on test JSONs

Currently all JSONs and the mapfile for an arch are dependencies for building pmu-events.c

The test JSONs are missing as a dependency, so add them.

tools/perf/pmu-events/Build +4 -1
index 215ba30b8534..a055dee6a46a 100644
@@ -6,10 +6,13 @@ pmu-events-y	+= pmu-events.o
 JDIR		=  pmu-events/arch/$(SRCARCH)
 JSON		=  $(shell [ -d $(JDIR) ] &&				\
 			find $(JDIR) -name '*.json' -o -name 'mapfile.csv')
+JDIR_TEST	=  pmu-events/arch/test
+JSON_TEST	=  $(shell [ -d $(JDIR_TEST) ] &&			\
+			find $(JDIR_TEST) -name '*.json')
 
 #
 # Locate/process JSON files in pmu-events/arch/
 # directory and create tables in pmu-events.c.
 #
-$(OUTPUT)pmu-events/pmu-events.c: $(JSON) $(JEVENTS)
+$(OUTPUT)pmu-events/pmu-events.c: $(JSON) $(JSON_TEST) $(JEVENTS)
 	$(Q)$(call echo-cmd,gen)$(JEVENTS) $(SRCARCH) pmu-events/arch 

$(OUTPUT)pmu-events/pmu-events.c $(V)

-----8<-----

Thanks,
john

author
#6 lore raw

Re: [PATCH 02/11] perf jevents: Relocate test events to cpu folder

Quoted 38 lines · John Garry

So I think we need something like this:

----->8--------

From a08df563665e9ec088b1af86ceed058497e112a4 Mon Sep 17 00:00:00 2001
From: John Garry <[email protected]>
Date: Tue, 3 Aug 2021 08:44:09 +0100
Subject: [PATCH] perf jevents: Make build dependency on test JSONs

Currently all JSONs and the mapfile for an arch are dependencies for building pmu-events.c

The test JSONs are missing as a dependency, so add them.

tools/perf/pmu-events/Build +4 -1
index 215ba30b8534..a055dee6a46a 100644
@@ -6,10 +6,13 @@ pmu-events-y    += pmu-events.o
  JDIR        =  pmu-events/arch/$(SRCARCH)
  JSON        =  $(shell [ -d $(JDIR) ] &&                \
              find $(JDIR) -name '*.json' -o -name 'mapfile.csv')
+JDIR_TEST    =  pmu-events/arch/test
+JSON_TEST    =  $(shell [ -d $(JDIR_TEST) ] &&            \
+            find $(JDIR_TEST) -name '*.json')
 
  #
  # Locate/process JSON files in pmu-events/arch/
  # directory and create tables in pmu-events.c.
  #
-$(OUTPUT)pmu-events/pmu-events.c: $(JSON) $(JEVENTS)
+$(OUTPUT)pmu-events/pmu-events.c: $(JSON) $(JSON_TEST) $(JEVENTS)
      $(Q)$(call echo-cmd,gen)$(JEVENTS) $(SRCARCH) pmu-events/arch 

$(OUTPUT)pmu-events/pmu-events.c $(V)

Quoted 1 line

-----8<-----

Hi Arnaldo,

Shall I send this as a formal patch?

Thanks!

#7 lore raw

Re: [PATCH 02/11] perf jevents: Relocate test events to cpu folder

Em Mon, Aug 09, 2021 at 04:46:04PM +0100, John Garry escreveu:

Quoted 39 lines · John Garry
Quoted 38 lines

So I think we need something like this:

----->8--------

From a08df563665e9ec088b1af86ceed058497e112a4 Mon Sep 17 00:00:00 2001
From: John Garry <[email protected]>
Date: Tue, 3 Aug 2021 08:44:09 +0100
Subject: [PATCH] perf jevents: Make build dependency on test JSONs

Currently all JSONs and the mapfile for an arch are dependencies for building pmu-events.c

The test JSONs are missing as a dependency, so add them.

tools/perf/pmu-events/Build +4 -1
index 215ba30b8534..a055dee6a46a 100644
@@ -6,10 +6,13 @@ pmu-events-y    += pmu-events.o
  JDIR        =  pmu-events/arch/$(SRCARCH)
  JSON        =  $(shell [ -d $(JDIR) ] &&                \
              find $(JDIR) -name '*.json' -o -name 'mapfile.csv')
+JDIR_TEST    =  pmu-events/arch/test
+JSON_TEST    =  $(shell [ -d $(JDIR_TEST) ] &&            \
+            find $(JDIR_TEST) -name '*.json')
 
  #
  # Locate/process JSON files in pmu-events/arch/
  # directory and create tables in pmu-events.c.
  #
-$(OUTPUT)pmu-events/pmu-events.c: $(JSON) $(JEVENTS)
+$(OUTPUT)pmu-events/pmu-events.c: $(JSON) $(JSON_TEST) $(JEVENTS)
      $(Q)$(call echo-cmd,gen)$(JEVENTS) $(SRCARCH) pmu-events/arch

$(OUTPUT)pmu-events/pmu-events.c $(V)

Quoted 5 lines
Quoted 1 line

-----8<-----

Hi Arnaldo,

Shall I send this as a formal patch?

The question is when should I apply this patch? After this series? After the patch I commented about, before?

- Arnaldo

author
#8 lore raw

Re: [PATCH 02/11] perf jevents: Relocate test events to cpu folder

Quoted 4 lines · Arnaldo Carvalho de Melo
Quoted 1 line

Shall I send this as a formal patch?

The question is when should I apply this patch? After this series? After the patch I commented about, before?

Hi Arnaldo,

I think that you can apply it before the series. This is a pre-existing issue that there was no dependency checking on the test events folder for rebuilding pmu-event.c .

Thanks

#9 lore raw

Re: [PATCH 02/11] perf jevents: Relocate test events to cpu folder

Em Tue, Aug 10, 2021 at 03:23:07PM +0100, John Garry escreveu:

Quoted 11 lines · Arnaldo Carvalho de Melo
Quoted 4 lines
Quoted 1 line

Shall I send this as a formal patch?

The question is when should I apply this patch? After this series? After the patch I commented about, before?

Hi Arnaldo,

I think that you can apply it before the series. This is a pre-existing issue that there was no dependency checking on the test events folder for rebuilding pmu-event.c .

Ok, will do so, thanks for clarifying.

- Arnaldo

#10 lore raw

Re: [PATCH 02/11] perf jevents: Relocate test events to cpu folder

In reply to John Garry

Em Tue, Aug 10, 2021 at 03:23:07PM +0100, John Garry escreveu:

Quoted 11 lines · Arnaldo Carvalho de Melo
Quoted 4 lines
Quoted 1 line

Shall I send this as a formal patch?

The question is when should I apply this patch? After this series? After the patch I commented about, before?

Hi Arnaldo,

I think that you can apply it before the series. This is a pre-existing issue that there was no dependency checking on the test events folder for rebuilding pmu-event.c .

Its all now in tmp.perf/core, will move to perf/core as soon as my test suite finishes.

- Arnaldo

author
#11 lore raw

Re: [PATCH 02/11] perf jevents: Relocate test events to cpu folder

Quoted 5 lines · Arnaldo Carvalho de Melo
Quoted 3 lines

I think that you can apply it before the series. This is a pre-existing issue that there was no dependency checking on the test events folder for rebuilding pmu-event.c .

Its all now in tmp.perf/core, will move to perf/core as soon as my test suite finishes.

Excellent, thanks!

#12 lore raw

Re: [PATCH 02/11] perf jevents: Relocate test events to cpu folder

Em Wed, Aug 11, 2021 at 08:59:24AM +0100, John Garry escreveu:

Quoted 8 lines · Arnaldo Carvalho de Melo
Quoted 5 lines
Quoted 3 lines

I think that you can apply it before the series. This is a pre-existing issue that there was no dependency checking on the test events folder for rebuilding pmu-event.c .

Its all now in tmp.perf/core, will move to perf/core as soon as my test suite finishes.

Excellent, thanks!

Passed, its in perf/core.

- Arnaldo

author
#13 lore raw

PATCH 3/11 perf test: Declare pmu-events test events separately

In reply to John Garry

Currently all test events are put into arrays of test events.

Create pointer arrays of test events instead, so the test events may be referenced later for tighter alias verification.

---
 tools/perf/tests/pmu-events.c | 244 ++++++++++++++++++----------------
 1 file changed, 126 insertions(+), 118 deletions(-)
tools/perf/tests/pmu-events.c +126 -118
index c064f08c63c9..0837f2c9d882 100644
@@ -30,108 +30,114 @@ struct perf_pmu_test_event {
 	const char *alias_long_desc;
 };
 
-static struct perf_pmu_test_event test_cpu_events[] = {
-	{
-		.event = {
-			.name = "bp_l1_btb_correct",
-			.event = "event=0x8a",
-			.desc = "L1 BTB Correction",
-			.topic = "branch",
-		},
-		.alias_str = "event=0x8a",
-		.alias_long_desc = "L1 BTB Correction",
-	},
-	{
-		.event = {
-			.name = "bp_l2_btb_correct",
-			.event = "event=0x8b",
-			.desc = "L2 BTB Correction",
-			.topic = "branch",
-		},
-		.alias_str = "event=0x8b",
-		.alias_long_desc = "L2 BTB Correction",
+static const struct perf_pmu_test_event bp_l1_btb_correct = {
+	.event = {
+		.name = "bp_l1_btb_correct",
+		.event = "event=0x8a",
+		.desc = "L1 BTB Correction",
+		.topic = "branch",
 	},
-	{
-		.event = {
-			.name = "segment_reg_loads.any",
-			.event = "umask=0x80,period=200000,event=0x6",
-			.desc = "Number of segment register loads",
-			.topic = "other",
-		},
-		.alias_str = "umask=0x80,(null)=0x30d40,event=0x6",
-		.alias_long_desc = "Number of segment register loads",
+	.alias_str = "event=0x8a",
+	.alias_long_desc = "L1 BTB Correction",
+};
+
+static const struct perf_pmu_test_event bp_l2_btb_correct = {
+	.event = {
+		.name = "bp_l2_btb_correct",
+		.event = "event=0x8b",
+		.desc = "L2 BTB Correction",
+		.topic = "branch",
 	},
-	{
-		.event = {
-			.name = "dispatch_blocked.any",
-			.event = "umask=0x20,period=200000,event=0x9",
-			.desc = "Memory cluster signals to block micro-op dispatch for any reason",
-			.topic = "other",
-		},
-		.alias_str = "umask=0x20,(null)=0x30d40,event=0x9",
-		.alias_long_desc = "Memory cluster signals to block micro-op dispatch for any reason",
+	.alias_str = "event=0x8b",
+	.alias_long_desc = "L2 BTB Correction",
+};
+
+static const struct perf_pmu_test_event segment_reg_loads_any = {
+	.event = {
+		.name = "segment_reg_loads.any",
+		.event = "umask=0x80,period=200000,event=0x6",
+		.desc = "Number of segment register loads",
+		.topic = "other",
 	},
-	{
-		.event = {
-			.name = "eist_trans",
-			.event = "umask=0x0,period=200000,event=0x3a",
-			.desc = "Number of Enhanced Intel SpeedStep(R) Technology (EIST) transitions",
-			.topic = "other",
-		},
-		.alias_str = "umask=0,(null)=0x30d40,event=0x3a",
-		.alias_long_desc = "Number of Enhanced Intel SpeedStep(R) Technology (EIST) transitions",
+	.alias_str = "umask=0x80,(null)=0x30d40,event=0x6",
+	.alias_long_desc = "Number of segment register loads",
+};
+
+static const struct perf_pmu_test_event dispatch_blocked_any = {
+	.event = {
+		.name = "dispatch_blocked.any",
+		.event = "umask=0x20,period=200000,event=0x9",
+		.desc = "Memory cluster signals to block micro-op dispatch for any reason",
+		.topic = "other",
 	},
-	{
-		.event = {
-			.name = "l3_cache_rd",
-			.event = "event=0x40",
-			.desc = "L3 cache access, read",
-			.long_desc = "Attributable Level 3 cache access, read",
-			.topic = "cache",
-		},
-		.alias_str = "event=0x40",
-		.alias_long_desc = "Attributable Level 3 cache access, read",
+	.alias_str = "umask=0x20,(null)=0x30d40,event=0x9",
+	.alias_long_desc = "Memory cluster signals to block micro-op dispatch for any reason",
+};
+
+static const struct perf_pmu_test_event eist_trans = {
+	.event = {
+		.name = "eist_trans",
+		.event = "umask=0x0,period=200000,event=0x3a",
+		.desc = "Number of Enhanced Intel SpeedStep(R) Technology (EIST) transitions",
+		.topic = "other",
 	},
-	{ /* sentinel */
-		.event = {
-			.name = NULL,
-		},
+	.alias_str = "umask=0,(null)=0x30d40,event=0x3a",
+	.alias_long_desc = "Number of Enhanced Intel SpeedStep(R) Technology (EIST) transitions",
+};
+
+static const struct perf_pmu_test_event l3_cache_rd = {
+	.event = {
+		.name = "l3_cache_rd",
+		.event = "event=0x40",
+		.desc = "L3 cache access, read",
+		.long_desc = "Attributable Level 3 cache access, read",
+		.topic = "cache",
 	},
+	.alias_str = "event=0x40",
+	.alias_long_desc = "Attributable Level 3 cache access, read",
 };
 
-static struct perf_pmu_test_event test_uncore_events[] = {
-	{
-		.event = {
-			.name = "uncore_hisi_ddrc.flux_wcmd",
-			.event = "event=0x2",
-			.desc = "DDRC write commands. Unit: hisi_sccl,ddrc ",
-			.topic = "uncore",
-			.long_desc = "DDRC write commands",
-			.pmu = "hisi_sccl,ddrc",
-		},
-		.alias_str = "event=0x2",
-		.alias_long_desc = "DDRC write commands",
+static const struct perf_pmu_test_event *core_events[] = {
+	&bp_l1_btb_correct,
+	&bp_l2_btb_correct,
+	&segment_reg_loads_any,
+	&dispatch_blocked_any,
+	&eist_trans,
+	&l3_cache_rd,
+	NULL
+};
+
+static const struct perf_pmu_test_event uncore_hisi_ddrc_flux_wcmd = {
+	.event = {
+		.name = "uncore_hisi_ddrc.flux_wcmd",
+		.event = "event=0x2",
+		.desc = "DDRC write commands. Unit: hisi_sccl,ddrc ",
+		.topic = "uncore",
+		.long_desc = "DDRC write commands",
+		.pmu = "hisi_sccl,ddrc",
 	},
-	{
-		.event = {
-			.name = "unc_cbo_xsnp_response.miss_eviction",
-			.event = "umask=0x81,event=0x22",
-			.desc = "Unit: uncore_cbox A cross-core snoop resulted from L3 Eviction which misses in some processor core",
-			.topic = "uncore",
-			.long_desc = "A cross-core snoop resulted from L3 Eviction which misses in some processor core",
-			.pmu = "uncore_cbox",
-		},
-		.alias_str = "umask=0x81,event=0x22",
-		.alias_long_desc = "A cross-core snoop resulted from L3 Eviction which misses in some processor core",
+	.alias_str = "event=0x2",
+	.alias_long_desc = "DDRC write commands",
+};
+
+static const struct perf_pmu_test_event unc_cbo_xsnp_response_miss_eviction = {
+	.event = {
+		.name = "unc_cbo_xsnp_response.miss_eviction",
+		.event = "umask=0x81,event=0x22",
+		.desc = "Unit: uncore_cbox A cross-core snoop resulted from L3 Eviction which misses in some processor core",
+		.topic = "uncore",
+		.long_desc = "A cross-core snoop resulted from L3 Eviction which misses in some processor core",
+		.pmu = "uncore_cbox",
 	},
-	{ /* sentinel */
-		.event = {
-			.name = NULL,
-		},
-	}
+	.alias_str = "umask=0x81,event=0x22",
+	.alias_long_desc = "A cross-core snoop resulted from L3 Eviction which misses in some processor core",
 };
 
-const int total_test_events_size = ARRAY_SIZE(test_uncore_events);
+static const struct perf_pmu_test_event *uncore_events[] = {
+	&uncore_hisi_ddrc_flux_wcmd,
+	&unc_cbo_xsnp_response_miss_eviction,
+	NULL
+};
 
 static bool is_same(const char *reference, const char *test)
 {
@@ -226,7 +232,7 @@ static int compare_pmu_events(struct pmu_event *e1, const struct pmu_event *e2)
 	return 0;
 }
 
-/* Verify generated events from pmu-events.c is as expected */
+/* Verify generated events from pmu-events.c are as expected */
 static int test_pmu_event_table(void)
 {
 	struct pmu_events_map *map = __test_pmu_get_events_map();
@@ -234,31 +240,31 @@ static int test_pmu_event_table(void)
 	int map_events = 0, expected_events;
 
 	/* ignore 2x sentinels */
-	expected_events = ARRAY_SIZE(test_cpu_events) +
-			  ARRAY_SIZE(test_uncore_events) - 2;
+	expected_events = ARRAY_SIZE(core_events) +
+			  ARRAY_SIZE(uncore_events) - 2;
 
 	if (!map)
 		return -1;
 
 	for (table = map->table; table->name; table++) {
-		struct perf_pmu_test_event *test;
-		struct pmu_event *te;
+		struct perf_pmu_test_event const **test_event_table;
 		bool found = false;
 
 		if (table->pmu)
-			test = &test_uncore_events[0];
+			test_event_table = &uncore_events[0];
 		else
-			test = &test_cpu_events[0];
+			test_event_table = &core_events[0];
 
-		te = &test->event;
+		for (; *test_event_table; test_event_table++) {
+			struct perf_pmu_test_event const *test_event = *test_event_table;
+			struct pmu_event const *event = &test_event->event;
 
-		for (; te->name; test++, te = &test->event) {
-			if (strcmp(table->name, te->name))
+			if (strcmp(table->name, event->name))
 				continue;
 			found = true;
 			map_events++;
 
-			if (compare_pmu_events(table, te))
+			if (compare_pmu_events(table, event))
 				return -1;
 
 			pr_debug("testing event table %s: pass\n", table->name);
@@ -294,8 +300,7 @@ static struct perf_pmu_alias *find_alias(const char *test_event, struct list_hea
 /* Verify aliases are as expected */
 static int __test__pmu_event_aliases(char *pmu_name, int *count)
 {
-	struct perf_pmu_test_event *test;
-	struct pmu_event *te;
+	struct perf_pmu_test_event const **test_event_table;
 	struct perf_pmu *pmu;
 	LIST_HEAD(aliases);
 	int res = 0;
@@ -307,10 +312,10 @@ static int __test__pmu_event_aliases(char *pmu_name, int *count)
 		return -1;
 
 	if (is_pmu_core(pmu_name)) {
-		test = &test_cpu_events[0];
+		test_event_table = &core_events[0];
 		use_uncore_table = false;
 	} else {
-		test = &test_uncore_events[0];
+		test_event_table = &uncore_events[0];
 		use_uncore_table = true;
 	}
 
@@ -322,50 +327,53 @@ static int __test__pmu_event_aliases(char *pmu_name, int *count)
 
 	pmu_add_cpu_aliases_map(&aliases, pmu, map);
 
-	for (te = &test->event; te->name; test++, te = &test->event) {
-		struct perf_pmu_alias *alias = find_alias(te->name, &aliases);
+	for (; *test_event_table; test_event_table++) {
+		struct perf_pmu_test_event const *test_event = *test_event_table;
+		struct pmu_event const *event = &test_event->event;
+
+		struct perf_pmu_alias *alias = find_alias(event->name, &aliases);
 
 		if (!alias) {
 			bool uncore_match = pmu_uncore_alias_match(pmu_name,
-								   te->pmu);
+								   event->pmu);
 
 			if (use_uncore_table && !uncore_match) {
 				pr_debug3("testing aliases PMU %s: skip matching alias %s\n",
-					  pmu_name, te->name);
+					  pmu_name, event->name);
 				continue;
 			}
 
 			pr_debug2("testing aliases PMU %s: no alias, alias_table->name=%s\n",
-				  pmu_name, te->name);
+				  pmu_name, event->name);
 			res = -1;
 			break;
 		}
 
-		if (!is_same(alias->desc, te->desc)) {
+		if (!is_same(alias->desc, event->desc)) {
 			pr_debug2("testing aliases PMU %s: mismatched desc, %s vs %s\n",
-				  pmu_name, alias->desc, te->desc);
+				  pmu_name, alias->desc, event->desc);
 			res = -1;
 			break;
 		}
 
-		if (!is_same(alias->long_desc, test->alias_long_desc)) {
+		if (!is_same(alias->long_desc, test_event->alias_long_desc)) {
 			pr_debug2("testing aliases PMU %s: mismatched long_desc, %s vs %s\n",
 				  pmu_name, alias->long_desc,
-				  test->alias_long_desc);
+				  test_event->alias_long_desc);
 			res = -1;
 			break;
 		}
 
-		if (!is_same(alias->str, test->alias_str)) {
+		if (!is_same(alias->str, test_event->alias_str)) {
 			pr_debug2("testing aliases PMU %s: mismatched str, %s vs %s\n",
-				  pmu_name, alias->str, test->alias_str);
+				  pmu_name, alias->str, test_event->alias_str);
 			res = -1;
 			break;
 		}
 
-		if (!is_same(alias->topic, te->topic)) {
+		if (!is_same(alias->topic, event->topic)) {
 			pr_debug2("testing aliases PMU %s: mismatched topic, %s vs %s\n",
-				  pmu_name, alias->topic, te->topic);
+				  pmu_name, alias->topic, event->topic);
 			res = -1;
 			break;
 		}
Signature · 1 line
2.26.2
author
#14 lore raw

PATCH 4/11 perf test: Factor out pmu-events alias comparison

In reply to John Garry

Factor out alias test which will be used in multiple places.

Also test missing fields.

---
 tools/perf/tests/pmu-events.c | 80 ++++++++++++++++++++++++-----------
 1 file changed, 55 insertions(+), 25 deletions(-)
tools/perf/tests/pmu-events.c +55 -25
index 0837f2c9d882..8fb5df6ee500 100644
@@ -232,6 +232,60 @@ static int compare_pmu_events(struct pmu_event *e1, const struct pmu_event *e2)
 	return 0;
 }
 
+static int compare_alias_to_test_event(struct perf_pmu_alias *alias,
+				struct perf_pmu_test_event const *test_event,
+				char const *pmu_name)
+{
+	struct pmu_event const *event = &test_event->event;
+
+	/* An alias was found, ensure everything is in order */
+	if (!is_same(alias->name, event->name)) {
+		pr_debug("testing aliases PMU %s: mismatched name, %s vs %s\n",
+			  pmu_name, alias->name, event->name);
+		return -1;
+	}
+
+	if (!is_same(alias->desc, event->desc)) {
+		pr_debug("testing aliases PMU %s: mismatched desc, %s vs %s\n",
+			  pmu_name, alias->desc, event->desc);
+		return -1;
+	}
+
+	if (!is_same(alias->long_desc, test_event->alias_long_desc)) {
+		pr_debug("testing aliases PMU %s: mismatched long_desc, %s vs %s\n",
+			  pmu_name, alias->long_desc,
+			  test_event->alias_long_desc);
+		return -1;
+	}
+
+	if (!is_same(alias->topic, event->topic)) {
+		pr_debug("testing aliases PMU %s: mismatched topic, %s vs %s\n",
+			  pmu_name, alias->topic, event->topic);
+		return -1;
+	}
+
+	if (!is_same(alias->str, test_event->alias_str)) {
+		pr_debug("testing aliases PMU %s: mismatched str, %s vs %s\n",
+			  pmu_name, alias->str, test_event->alias_str);
+		return -1;
+	}
+
+	if (!is_same(alias->long_desc, test_event->alias_long_desc)) {
+		pr_debug("testing aliases PMU %s: mismatched long desc, %s vs %s\n",
+			  pmu_name, alias->str, test_event->alias_long_desc);
+		return -1;
+	}
+
+
+	if (!is_same(alias->pmu_name, test_event->event.pmu)) {
+		pr_debug("testing aliases PMU %s: mismatched pmu_name, %s vs %s\n",
+			  pmu_name, alias->pmu_name, test_event->event.pmu);
+		return -1;
+	}
+
+	return 0;
+}
+
 /* Verify generated events from pmu-events.c are as expected */
 static int test_pmu_event_table(void)
 {
@@ -349,31 +403,7 @@ static int __test__pmu_event_aliases(char *pmu_name, int *count)
 			break;
 		}
 
-		if (!is_same(alias->desc, event->desc)) {
-			pr_debug2("testing aliases PMU %s: mismatched desc, %s vs %s\n",
-				  pmu_name, alias->desc, event->desc);
-			res = -1;
-			break;
-		}
-
-		if (!is_same(alias->long_desc, test_event->alias_long_desc)) {
-			pr_debug2("testing aliases PMU %s: mismatched long_desc, %s vs %s\n",
-				  pmu_name, alias->long_desc,
-				  test_event->alias_long_desc);
-			res = -1;
-			break;
-		}
-
-		if (!is_same(alias->str, test_event->alias_str)) {
-			pr_debug2("testing aliases PMU %s: mismatched str, %s vs %s\n",
-				  pmu_name, alias->str, test_event->alias_str);
-			res = -1;
-			break;
-		}
-
-		if (!is_same(alias->topic, event->topic)) {
-			pr_debug2("testing aliases PMU %s: mismatched topic, %s vs %s\n",
-				  pmu_name, alias->topic, event->topic);
+		if (compare_alias_to_test_event(alias, test_event, pmu_name)) {
 			res = -1;
 			break;
 		}
Signature · 1 line
2.26.2
author
#15 lore raw

PATCH 5/11 perf test: Test pmu-events core aliases separately

In reply to John Garry

The current method to test uncore event aliasing is limited, as it relies on the uncore PMU being present in the host system to test.

As such, breakages of uncore PMU aliases goes unnoticed. To make this more robust, a new method of testing uncore PMUs with fake PMUs will be used in future. This will be separate to testing core PMU aliases.

So make the current test function core PMU only. Uncore PMU alias support will be re-added later.

---
 tools/perf/tests/pmu-events.c | 45 +++++++++++++----------------------
 1 file changed, 16 insertions(+), 29 deletions(-)
tools/perf/tests/pmu-events.c +16 -29
index 8fb5df6ee500..9537bbdd09f0 100644
@@ -352,26 +352,19 @@ static struct perf_pmu_alias *find_alias(const char *test_event, struct list_hea
 }
 
 /* Verify aliases are as expected */
-static int __test__pmu_event_aliases(char *pmu_name, int *count)
+static int __test_core_pmu_event_aliases(char *pmu_name, int *count)
 {
 	struct perf_pmu_test_event const **test_event_table;
 	struct perf_pmu *pmu;
 	LIST_HEAD(aliases);
 	int res = 0;
-	bool use_uncore_table;
 	struct pmu_events_map *map = __test_pmu_get_events_map();
 	struct perf_pmu_alias *a, *tmp;
 
 	if (!map)
 		return -1;
 
-	if (is_pmu_core(pmu_name)) {
-		test_event_table = &core_events[0];
-		use_uncore_table = false;
-	} else {
-		test_event_table = &uncore_events[0];
-		use_uncore_table = true;
-	}
+	test_event_table = &core_events[0];
 
 	pmu = zalloc(sizeof(*pmu));
 	if (!pmu)
@@ -384,20 +377,10 @@ static int __test__pmu_event_aliases(char *pmu_name, int *count)
 	for (; *test_event_table; test_event_table++) {
 		struct perf_pmu_test_event const *test_event = *test_event_table;
 		struct pmu_event const *event = &test_event->event;
-
 		struct perf_pmu_alias *alias = find_alias(event->name, &aliases);
 
 		if (!alias) {
-			bool uncore_match = pmu_uncore_alias_match(pmu_name,
-								   event->pmu);
-
-			if (use_uncore_table && !uncore_match) {
-				pr_debug3("testing aliases PMU %s: skip matching alias %s\n",
-					  pmu_name, event->name);
-				continue;
-			}
-
-			pr_debug2("testing aliases PMU %s: no alias, alias_table->name=%s\n",
+			pr_debug("testing aliases core PMU %s: no alias, alias_table->name=%s\n",
 				  pmu_name, event->name);
 			res = -1;
 			break;
@@ -409,7 +392,7 @@ static int __test__pmu_event_aliases(char *pmu_name, int *count)
 		}
 
 		(*count)++;
-		pr_debug2("testing aliases PMU %s: matched event %s\n",
+		pr_debug2("testing aliases core PMU %s: matched event %s\n",
 			  pmu_name, alias->name);
 	}
 
@@ -421,7 +404,6 @@ static int __test__pmu_event_aliases(char *pmu_name, int *count)
 	return res;
 }
 
-
 /* Test that aliases generated are as expected */
 static int test_aliases(void)
 {
@@ -430,21 +412,26 @@ static int test_aliases(void)
 	while ((pmu = perf_pmu__scan(pmu)) != NULL) {
 		int count = 0;
 
+		if (!is_pmu_core(pmu->name))
+			continue;
+
 		if (list_empty(&pmu->format)) {
-			pr_debug2("skipping testing PMU %s\n", pmu->name);
+			pr_debug2("skipping testing core PMU %s\n", pmu->name);
 			continue;
 		}
 
-		if (__test__pmu_event_aliases(pmu->name, &count)) {
-			pr_debug("testing PMU %s aliases: failed\n", pmu->name);
+		if (__test_core_pmu_event_aliases(pmu->name, &count)) {
+			pr_debug("testing core PMU %s aliases: failed\n", pmu->name);
 			return -1;
 		}
 
-		if (count == 0)
-			pr_debug3("testing PMU %s aliases: no events to match\n",
+		if (count == 0) {
+			pr_debug("testing core PMU %s aliases: no events to match\n",
 				  pmu->name);
-		else
-			pr_debug("testing PMU %s aliases: pass\n", pmu->name);
+			return -1;
+		}
+
+		pr_debug("testing core PMU %s aliases: pass\n", pmu->name);
 	}
 
 	return 0;
Signature · 1 line
2.26.2
author
#16 lore raw

PATCH 6/11 perf pmu: Check .is_uncore field in pmu_add_cpu_aliases_map()

In reply to John Garry

Calling pmu_is_uncore() for fake PMUs does not work, as it checks sysfs for the PMU details (which won't exist).

Check .is_uncore field instead, which makes sense anyway.

---
 tools/perf/util/pmu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/perf/util/pmu.c +1 -2
index 538b8fa8a710..238792197006 100644
@@ -843,8 +843,7 @@ void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu,
 			break;
 		}
 
-		if (pmu_is_uncore(name) &&
-		    pmu_uncore_alias_match(pname, name))
+		if (pmu->is_uncore && pmu_uncore_alias_match(pname, name))
 			goto new_alias;
 
 		if (strcmp(pname, name))
Signature · 1 line
2.26.2
author
#17 lore raw

PATCH 7/11 perf test: Re-add pmu-event uncore PMU alias test

In reply to John Garry

Add support to match aliases for uncore PMUs.

Since we cannot rely on the PMUs being present on the host system, use fake PMUs.

The following conditions in the test are ensures:
- Expected count of aliases created
- All aliases can be matched to an expected alias in perf_pmu_test_pmu.aliases

This will catch the condition fixed in commit c47a5599eda3 ("perf tools:
Fix pattern matching for same substring in different PMU type"), where excess events were created for a PMU. It will also fix the scenario inadvertently broken there, where no aliases were created for aliases with multiple tokens.

---
 tools/perf/tests/pmu-events.c | 110 ++++++++++++++++++++++++++++++++++
 1 file changed, 110 insertions(+)
tools/perf/tests/pmu-events.c +110 -0
index 9537bbdd09f0..74c7dfe0a97f 100644
@@ -28,6 +28,14 @@ struct perf_pmu_test_event {
 	 * be set in the alias.
 	 */
 	const char *alias_long_desc;
+
+	/* PMU which we should match against */
+	const char *matching_pmu;
+};
+
+struct perf_pmu_test_pmu {
+	struct perf_pmu pmu;
+	struct perf_pmu_test_event const *aliases[10];
 };
 
 static const struct perf_pmu_test_event bp_l1_btb_correct = {
@@ -118,6 +126,7 @@ static const struct perf_pmu_test_event uncore_hisi_ddrc_flux_wcmd = {
 	},
 	.alias_str = "event=0x2",
 	.alias_long_desc = "DDRC write commands",
+	.matching_pmu = "hisi_sccl1_ddrc2",
 };
 
 static const struct perf_pmu_test_event unc_cbo_xsnp_response_miss_eviction = {
@@ -131,6 +140,7 @@ static const struct perf_pmu_test_event unc_cbo_xsnp_response_miss_eviction = {
 	},
 	.alias_str = "umask=0x81,event=0x22",
 	.alias_long_desc = "A cross-core snoop resulted from L3 Eviction which misses in some processor core",
+	.matching_pmu = "uncore_cbox_0",
 };
 
 static const struct perf_pmu_test_event *uncore_events[] = {
@@ -404,10 +414,103 @@ static int __test_core_pmu_event_aliases(char *pmu_name, int *count)
 	return res;
 }
 
+static int __test_uncore_pmu_event_aliases(struct perf_pmu_test_pmu *test_pmu)
+{
+	int alias_count = 0, to_match_count = 0, matched_count = 0;
+	struct perf_pmu_test_event const **table;
+	struct perf_pmu *pmu = &test_pmu->pmu;
+	const char *pmu_name = pmu->name;
+	struct perf_pmu_alias *a, *tmp, *alias;
+	struct pmu_events_map *map;
+	LIST_HEAD(aliases);
+	int res = 0;
+
+	map = __test_pmu_get_events_map();
+	if (!map)
+		return -1;
+	pmu_add_cpu_aliases_map(&aliases, pmu, map);
+
+	/* Count how many aliases we generated */
+	list_for_each_entry(alias, &aliases, list)
+		alias_count++;
+
+	/* Count how many aliases we expect from the known table */
+	for (table = &test_pmu->aliases[0]; *table; table++)
+		to_match_count++;
+
+	if (alias_count != to_match_count) {
+		pr_debug("testing aliases uncore PMU %s: mismatch expected aliases (%d) vs found (%d)\n",
+			 pmu_name, to_match_count, alias_count);
+		res = -1;
+		goto out;
+	}
+
+	list_for_each_entry(alias, &aliases, list) {
+		bool matched = false;
+
+		for (table = &test_pmu->aliases[0]; *table; table++) {
+			struct perf_pmu_test_event const *test_event = *table;
+			struct pmu_event const *event = &test_event->event;
+
+			if (!strcmp(event->name, alias->name)) {
+				if (compare_alias_to_test_event(alias,
+							test_event,
+							pmu_name)) {
+					continue;
+				}
+				matched = true;
+				matched_count++;
+			}
+		}
+
+		if (matched == false) {
+			pr_debug("testing aliases uncore PMU %s: could not match alias %s\n",
+				 pmu_name, alias->name);
+			res = -1;
+			goto out;
+		}
+	}
+
+	if (alias_count != matched_count) {
+		pr_debug("testing aliases uncore PMU %s: mismatch found aliases (%d) vs matched (%d)\n",
+			 pmu_name, matched_count, alias_count);
+		res = -1;
+	}
+
+out:
+	list_for_each_entry_safe(a, tmp, &aliases, list) {
+		list_del(&a->list);
+		perf_pmu_free_alias(a);
+	}
+	return res;
+}
+
+static struct perf_pmu_test_pmu test_pmus[] = {
+	{
+		.pmu = {
+			.name = (char *)"hisi_sccl1_ddrc2",
+			.is_uncore = 1,
+		},
+		.aliases = {
+			&uncore_hisi_ddrc_flux_wcmd,
+		},
+	},
+	{
+		.pmu = {
+			.name = (char *)"uncore_cbox_0",
+			.is_uncore = 1,
+		},
+		.aliases = {
+			&unc_cbo_xsnp_response_miss_eviction,
+		},
+	},
+};
+
 /* Test that aliases generated are as expected */
 static int test_aliases(void)
 {
 	struct perf_pmu *pmu = NULL;
+	unsigned long i;
 
 	while ((pmu = perf_pmu__scan(pmu)) != NULL) {
 		int count = 0;
@@ -434,6 +537,13 @@ static int test_aliases(void)
 		pr_debug("testing core PMU %s aliases: pass\n", pmu->name);
 	}
 
+	for (i = 0; i < ARRAY_SIZE(test_pmus); i++) {
+		int res = __test_uncore_pmu_event_aliases(&test_pmus[i]);
+
+		if (res)
+			return res;
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.26.2
author
#18 lore raw

PATCH 8/11 perf test: Add more pmu-events uncore aliases

In reply to John Garry

Add more events to cover the scenarios fixed and also inadvertently broken by commit c47a5599eda3 ("perf tools: Fix pattern matching for same substring in different PMU type").

---
 .../arch/test/test_soc/cpu/uncore.json        | 23 +++++-
 tools/perf/tests/pmu-events.c                 | 72 +++++++++++++++++++
 2 files changed, 94 insertions(+), 1 deletion(-)
tools/perf/pmu-events/arch/test/test_soc/cpu/uncore.json +22 -1
index d0a890cc814d..788766f45dbc 100644
@@ -17,5 +17,26 @@
 	    "CounterMask": "0",
 	    "Invert": "0",
 	    "EdgeDetect": "0"
-  }
+  },
+  {
+	    "EventCode": "0x7",
+	    "EventName": "uncore_hisi_l3c.rd_hit_cpipe",
+	    "BriefDescription": "Total read hits",
+	    "PublicDescription": "Total read hits",
+	    "Unit": "hisi_sccl,l3c"
+  },
+  {
+	    "EventCode": "0x12",
+	    "EventName": "uncore_imc_free_running.cache_miss",
+	    "BriefDescription": "Total cache misses",
+	    "PublicDescription": "Total cache misses",
+	    "Unit": "imc_free_running"
+  },
+  {
+	    "EventCode": "0x34",
+	    "EventName": "uncore_imc.cache_hits",
+	    "BriefDescription": "Total cache hits",
+	    "PublicDescription": "Total cache hits",
+	    "Unit": "imc"
+  },
 ]
tools/perf/tests/pmu-events.c +72 -0

87 lines not on this page · raw message

Signature · 1 line
2.26.2
author
#19 lore raw

PATCH 9/11 perf pmu: Make pmu_add_sys_aliases() public

In reply to John Garry

Function pmu_add_sys_aliases() will be required for the PMU events test for system events aliases, so make it public.

---
 tools/perf/util/pmu.c | 2 +-
 tools/perf/util/pmu.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/pmu.c +1 -1
index 238792197006..534b91ccb2a2 100644
@@ -926,7 +926,7 @@ static int pmu_add_sys_aliases_iter_fn(struct pmu_event *pe, void *data)
 	return 0;
 }
 
-static void pmu_add_sys_aliases(struct list_head *head, struct perf_pmu *pmu)
+void pmu_add_sys_aliases(struct list_head *head, struct perf_pmu *pmu)
 {
 	struct pmu_sys_event_iter_data idata = {
 		.head = head,
tools/perf/util/pmu.h +1 -0
index 926da483a141..033e8211c025 100644
@@ -81,6 +81,7 @@ struct perf_pmu_alias {
 
 struct perf_pmu *perf_pmu__find(const char *name);
 struct perf_pmu *perf_pmu__find_by_type(unsigned int type);
+void pmu_add_sys_aliases(struct list_head *head, struct perf_pmu *pmu);
 int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
 		     struct list_head *head_terms,
 		     struct parse_events_error *error);
Signature · 1 line
2.26.2
author
#20 lore raw

PATCH 10/11 perf jevents: Print SoC name per system event table

In reply to John Garry

Print the SoC name per system event table, which will allow the test SoC be identified by the pmu-events test.

---
 tools/perf/pmu-events/jevents.c    | 3 ++-
 tools/perf/pmu-events/pmu-events.h | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
tools/perf/pmu-events/jevents.c +2 -1
index 405bdd36b9b9..6731b3cf0c2f 100644
@@ -836,7 +836,8 @@ static int process_system_event_tables(FILE *outfp)
 	print_system_event_mapping_table_prefix(outfp);
 
 	list_for_each_entry(sys_event_table, &sys_event_tables, list) {
-		fprintf(outfp, "\n\t{\n\t\t.table = %s,\n\t},",
+		fprintf(outfp, "\n\t{\n\t\t.table = %s,\n\t\t.name = \"%s\",\n\t},",
+			sys_event_table->soc_id,
 			sys_event_table->soc_id);
 	}
 
tools/perf/pmu-events/pmu-events.h +1 -0
index d1172f6aebf1..5c2bf7275c1c 100644
@@ -45,6 +45,7 @@ struct pmu_events_map {
 };
 
 struct pmu_sys_events {
+	const char *name;
 	struct pmu_event *table;
 };
 
Signature · 1 line
2.26.2
author
#21 lore raw

PATCH 11/11 perf test: Add pmu-events sys event support

In reply to John Garry

Add support for system events, along with core and uncore events.

Support for a sample PMU is also added.

---
 .../arch/test/test_soc/sys/uncore.json        |  9 +++
 tools/perf/tests/pmu-events.c                 | 77 ++++++++++++++++++-
 2 files changed, 83 insertions(+), 3 deletions(-)
 create mode 100644 tools/perf/pmu-events/arch/test/test_soc/sys/uncore.json
tools/perf/pmu-events/arch/test/test_soc/sys/uncore.json new file +9 -0
new file mode 100644
index 000000000000..0f681a6e10ea
@@ -0,0 +1,9 @@
+[
+  {
+           "BriefDescription": "ddr write-cycles event",
+           "EventCode": "0x2b",
+           "EventName": "sys_ddr_pmu.write_cycles",
+           "Unit": "sys_ddr_pmu",
+           "Compat": "v8"
+   },
+]
tools/perf/tests/pmu-events.c +74 -3

119 lines not on this page · raw message

Signature · 1 line
2.26.2