[PATCH v1 09/40] perf test: Use valid for PMU tests

Ian Rogers posted 40 patches 2 years, 7 months ago
There is a newer version of this series
[PATCH v1 09/40] perf test: Use valid for PMU tests
Posted by Ian Rogers 2 years, 7 months ago
Rather than skip all tests in test__events_pmu if PMU cpu isn't
present, use the per-test valid test. This allows the running of
software PMU tests on hybrid and arm systems.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/tests/parse-events.c | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 385bbbc4a409..08d6b8a3015d 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -1430,6 +1430,11 @@ static int test__checkevent_config_cache(struct evlist *evlist)
 	return TEST_OK;
 }
 
+static bool test__pmu_cpu_valid(void)
+{
+	return !!perf_pmu__find("cpu");
+}
+
 static bool test__intel_pt_valid(void)
 {
 	return !!perf_pmu__find("intel_pt");
@@ -1979,21 +1984,25 @@ static const struct evlist_test test__events[] = {
 static const struct evlist_test test__events_pmu[] = {
 	{
 		.name  = "cpu/config=10,config1,config2=3,period=1000/u",
+		.valid = test__pmu_cpu_valid,
 		.check = test__checkevent_pmu,
 		/* 0 */
 	},
 	{
 		.name  = "cpu/config=1,name=krava/u,cpu/config=2/u",
+		.valid = test__pmu_cpu_valid,
 		.check = test__checkevent_pmu_name,
 		/* 1 */
 	},
 	{
 		.name  = "cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/",
+		.valid = test__pmu_cpu_valid,
 		.check = test__checkevent_pmu_partial_time_callgraph,
 		/* 2 */
 	},
 	{
 		.name  = "cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp",
+		.valid = test__pmu_cpu_valid,
 		.check = test__checkevent_complex_name,
 		/* 3 */
 	},
@@ -2209,21 +2218,6 @@ static int test__terms2(struct test_suite *test __maybe_unused, int subtest __ma
 	return test_terms(test__terms, ARRAY_SIZE(test__terms));
 }
 
-static int test_pmu(void)
-{
-	struct stat st;
-	char path[PATH_MAX];
-	int ret;
-
-	snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
-		 sysfs__mountpoint());
-
-	ret = stat(path, &st);
-	if (ret)
-		pr_debug("omitting PMU cpu tests\n");
-	return !ret;
-}
-
 static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
 {
 	struct perf_pmu *pmu;
@@ -2305,9 +2299,6 @@ static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest
 
 static int test__pmu_events2(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
 {
-	if (!test_pmu())
-		return TEST_SKIP;
-
 	return test_events(test__events_pmu, ARRAY_SIZE(test__events_pmu));
 }
 
-- 
2.40.1.495.gc816e09b53d-goog
Re: [PATCH v1 09/40] perf test: Use valid for PMU tests
Posted by Liang, Kan 2 years, 7 months ago

On 2023-04-26 3:00 a.m., Ian Rogers wrote:
> Rather than skip all tests in test__events_pmu if PMU cpu isn't
> present, use the per-test valid test. This allows the running of
> software PMU tests on hybrid and arm systems.
> 
> Signed-off-by: Ian Rogers <irogers@google.com>

Run the test on Cascade Lake and Alder Lake. It looks good.

Tested-by: Kan Liang <kan.liang@linux.intel.com>

Thanks,
Kan

> ---
>  tools/perf/tests/parse-events.c | 27 +++++++++------------------
>  1 file changed, 9 insertions(+), 18 deletions(-)
> 
> diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
> index 385bbbc4a409..08d6b8a3015d 100644
> --- a/tools/perf/tests/parse-events.c
> +++ b/tools/perf/tests/parse-events.c
> @@ -1430,6 +1430,11 @@ static int test__checkevent_config_cache(struct evlist *evlist)
>  	return TEST_OK;
>  }
>  
> +static bool test__pmu_cpu_valid(void)
> +{
> +	return !!perf_pmu__find("cpu");
> +}
> +
>  static bool test__intel_pt_valid(void)
>  {
>  	return !!perf_pmu__find("intel_pt");
> @@ -1979,21 +1984,25 @@ static const struct evlist_test test__events[] = {
>  static const struct evlist_test test__events_pmu[] = {
>  	{
>  		.name  = "cpu/config=10,config1,config2=3,period=1000/u",
> +		.valid = test__pmu_cpu_valid,
>  		.check = test__checkevent_pmu,
>  		/* 0 */
>  	},
>  	{
>  		.name  = "cpu/config=1,name=krava/u,cpu/config=2/u",
> +		.valid = test__pmu_cpu_valid,
>  		.check = test__checkevent_pmu_name,
>  		/* 1 */
>  	},
>  	{
>  		.name  = "cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/",
> +		.valid = test__pmu_cpu_valid,
>  		.check = test__checkevent_pmu_partial_time_callgraph,
>  		/* 2 */
>  	},
>  	{
>  		.name  = "cpu/name='COMPLEX_CYCLES_NAME:orig=cycles,desc=chip-clock-ticks',period=0x1,event=0x2/ukp",
> +		.valid = test__pmu_cpu_valid,
>  		.check = test__checkevent_complex_name,
>  		/* 3 */
>  	},
> @@ -2209,21 +2218,6 @@ static int test__terms2(struct test_suite *test __maybe_unused, int subtest __ma
>  	return test_terms(test__terms, ARRAY_SIZE(test__terms));
>  }
>  
> -static int test_pmu(void)
> -{
> -	struct stat st;
> -	char path[PATH_MAX];
> -	int ret;
> -
> -	snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/",
> -		 sysfs__mountpoint());
> -
> -	ret = stat(path, &st);
> -	if (ret)
> -		pr_debug("omitting PMU cpu tests\n");
> -	return !ret;
> -}
> -
>  static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
>  {
>  	struct perf_pmu *pmu;
> @@ -2305,9 +2299,6 @@ static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest
>  
>  static int test__pmu_events2(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
>  {
> -	if (!test_pmu())
> -		return TEST_SKIP;
> -
>  	return test_events(test__events_pmu, ARRAY_SIZE(test__events_pmu));
>  }
>