perf tool: Skip invalid hybrid PMU
v2 cover perf tool: Skip invalid hybrid PMU
On hybrid platform, such as Alderlake, if atom CPUs are offlined, the kernel still exports the sysfs path '/sys/devices/cpu_atom/' for 'cpu_atom' pmu but the file '/sys/devices/cpu_atom/cpus' is empty, which indicates this is an invalid pmu. So we need to check and skip the invalid hybrid pmu.
Also we need to update some perf test cases for core-only system.
Jin Yao (4):
perf pmu: Skip invalid hybrid pmu
perf tests: Fix 'Parse event definition strings' on core-only system perf tests: Fix 'Roundtrip evsel->name' on core-only system perf tests: Fix 'Convert perf time to TSC' on core-only system
tools/perf/tests/evsel-roundtrip-name.c | 3 ++- tools/perf/tests/parse-events.c | 16 ++++++++++------ tools/perf/tests/perf-time-to-tsc.c | 3 ++- tools/perf/util/pmu.c | 9 ++++++++- 4 files changed, 22 insertions(+), 9 deletions(-)
Signature · 1 line
2.17.1
PATCH v2 1/4 perf pmu: Skip invalid hybrid pmu
On hybrid platform, such as Alderlake, if atom CPUs are offlined, the kernel still exports the sysfs path '/sys/devices/cpu_atom/' for 'cpu_atom' pmu but the file '/sys/devices/cpu_atom/cpus' is empty, which indicates this is an invalid pmu.
Need to check and skip the invalid hybrid pmu.
Before:
# perf list ... branch-instructions OR cpu_atom/branch-instructions/ [Kernel PMU event] branch-instructions OR cpu_core/branch-instructions/ [Kernel PMU event] branch-misses OR cpu_atom/branch-misses/ [Kernel PMU event] branch-misses OR cpu_core/branch-misses/ [Kernel PMU event] bus-cycles OR cpu_atom/bus-cycles/ [Kernel PMU event] bus-cycles OR cpu_core/bus-cycles/ [Kernel PMU event] ...
The cpu_atom events are still displayed even if atom CPUs are offlined.
After:
# perf list ... branch-instructions OR cpu_core/branch-instructions/ [Kernel PMU event] branch-misses OR cpu_core/branch-misses/ [Kernel PMU event] bus-cycles OR cpu_core/bus-cycles/ [Kernel PMU event] ...
Now only cpu_core events are displayed.
--- tools/perf/util/pmu.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
tools/perf/util/pmu.c +8 -1
@@ -927,6 +927,13 @@ static struct perf_pmu *pmu_lookup(const char *name)LIST_HEAD (format);LIST_HEAD (aliases);__u32 type; +bool is_hybrid =perf_pmu__hybrid_mounted (name); + +/* +* Check pmu name for hybrid and the pmu may be invalid in sysfs +*/ +if (!strncmp (name,"cpu_" ,4 ) && !is_hybrid) +return NULL ;/* * The pmu data we store & need consists of the pmu
@@ -955,7 +962,7 @@ static struct perf_pmu *pmu_lookup(const char *name) pmu->is_uncore =pmu_is_uncore (name);if (pmu->is_uncore) pmu->id =pmu_id (name); - pmu->is_hybrid =perf_pmu__hybrid_mounted (name); + pmu->is_hybrid = is_hybrid; pmu->max_precise =pmu_max_precise (name);pmu_add_cpu_aliases (&aliases, pmu);pmu_add_sys_aliases (&aliases, pmu);
Signature · 1 line
2.17.1
PATCH v2 2/4 perf tests: Fix 'Parse event definition strings' on core-only system
In reply to Jin YaoIf the atom CPUs are offlined, the 'cpu_atom' is not valid. We don't need the test case for 'cpu_atom'.
--- tools/perf/tests/parse-events.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
tools/perf/tests/parse-events.c +10 -6
@@ -6,6 +6,7 @@#include "tests.h" #include "debug.h" #include "pmu.h" +#include "pmu-hybrid.h" #include <dirent.h> #include <errno.h> #include <sys/types.h>
@@ -1596,6 +1597,13 @@ static int test__hybrid_raw1(struct evlist *evlist) {struct evsel *evsel =evlist__first (evlist); +if (!perf_pmu__hybrid_mounted ("cpu_atom" )) { +TEST_ASSERT_VAL ("wrong number of entries" ,1 == evlist->core.nr_entries); +TEST_ASSERT_VAL ("wrong type" ,PERF_TYPE_RAW == evsel->core.attr.type); +TEST_ASSERT_VAL ("wrong config" ,0x1a == evsel->core.attr.config); +return 0 ; + } +TEST_ASSERT_VAL ("wrong number of entries" ,2 == evlist->core.nr_entries);TEST_ASSERT_VAL ("wrong type" ,PERF_TYPE_RAW == evsel->core.attr.type);TEST_ASSERT_VAL ("wrong config" ,0x1a == evsel->core.attr.config);
@@ -1620,13 +1628,9 @@ static int test__hybrid_cache_event(struct evlist *evlist) {struct evsel *evsel =evlist__first (evlist); -TEST_ASSERT_VAL ("wrong number of entries" ,2 == evlist->core.nr_entries); +TEST_ASSERT_VAL ("wrong number of entries" ,1 == evlist->core.nr_entries);TEST_ASSERT_VAL ("wrong type" ,PERF_TYPE_HW_CACHE == evsel->core.attr.type);TEST_ASSERT_VAL ("wrong config" ,0x2 == (evsel->core.attr.config &0xffffffff )); - - evsel =evsel__next (evsel); -TEST_ASSERT_VAL ("wrong type" ,PERF_TYPE_HW_CACHE == evsel->core.attr.type); -TEST_ASSERT_VAL ("wrong config" ,0x10002 == (evsel->core.attr.config &0xffffffff ));return 0 ; }
@@ -2028,7 +2032,7 @@ static struct evlist_test test__hybrid_events[] = { .id = 7, }, { - .name = "cpu_core/LLC-loads/,cpu_atom/LLC-load-misses/", + .name = "cpu_core/LLC-loads/", .check = test__hybrid_cache_event, .id = 8, },
Signature · 1 line
2.17.1
PATCH v2 3/4 perf tests: Fix 'Roundtrip evsel->name' on core-only system
In reply to Jin YaoIf the atom CPUs are offlined, the 'cpu_atom' is not valid. Perf will not create two events for one hw event, so the evsel->idx doesn't need to be divided by 2 before comparing.
--- tools/perf/tests/evsel-roundtrip-name.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/tests/evsel-roundtrip-name.c +2 -1
@@ -5,6 +5,7 @@#include "tests.h" #include "debug.h" #include "pmu.h" +#include "pmu-hybrid.h" #include <errno.h> #include <linux/kernel.h>
@@ -102,7 +103,7 @@ int test__perf_evsel__roundtrip_name_test(struct test *test __maybe_unused, int {int err =0 , ret =0 ; -if (perf_pmu__has_hybrid ()) +if (perf_pmu__has_hybrid () &&perf_pmu__hybrid_mounted ("cpu_atom" ))return perf_evsel__name_array_test (evsel__hw_names,2 ); err =perf_evsel__name_array_test (evsel__hw_names,1 );
Signature · 1 line
2.17.1
PATCH v2 4/4 perf tests: Fix 'Convert perf time to TSC' on core-only system
In reply to Jin YaoIf the atom CPUs are offlined, the 'cpu_atom' is not valid. We don't need the test case for 'cpu_atom'.
--- tools/perf/tests/perf-time-to-tsc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/tests/perf-time-to-tsc.c +2 -1
@@ -21,6 +21,7 @@#include "mmap.h" #include "tests.h" #include "pmu.h" +#include "pmu-hybrid.h" #define CHECK__ (x) { \ while ((x) < 0) { \
@@ -93,7 +94,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, int subtest __maybe* For hybrid "cycles:u", it creates two events. * Init the second evsel here. */ -if (perf_pmu__has_hybrid ()) { +if (perf_pmu__has_hybrid () &&perf_pmu__hybrid_mounted ("cpu_atom" )) { evsel =evsel__next (evsel); evsel->core.attr.comm =1 ; evsel->core.attr.disabled =1 ;
Signature · 1 line
2.17.1
Quoted 6 lines · Jin Yao
On hybrid platform, such as Alderlake, if atom CPUs are offlined, the kernel still exports the sysfs path '
/sys/devices/cpu_atom/' for 'cpu_atom' pmu but the file '/sys/devices/cpu_atom/cpus' is empty, which indicates this is an invalid pmu. So we need to check and skip the invalid hybrid pmu.
Quoted 7 lines
Also we need to update some perf test cases for core-only system.
Jin Yao (4):
perf pmu: Skip invalid hybrid pmu
perf tests: Fix 'Parse event definition strings' on core-only system perf tests: Fix 'Roundtripevsel->name' on core-only system perf tests: Fix 'Convert perf time to TSC' on core-only system
thanks,
jirka
Quoted 10 lines
tools/perf/tests/evsel-roundtrip-name.c | 3 ++- tools/perf/tests/parse-events.c | 16 ++++++++++------ tools/perf/tests/perf-time-to-tsc.c | 3 ++- tools/perf/util/pmu.c | 9 ++++++++- 4 files changed, 22 insertions(+), 9 deletions(-)Signature · 1 line
2.17.1
Em Sun, Jul 11, 2021 at 05:52:48PM +0200, Jiri Olsa escreveu:
Quoted 9 lines · Jin Yao
Quoted 8 lines
On hybrid platform, such as Alderlake, if atom CPUs are offlined, the kernel still exports the sysfs path '
/sys/devices/cpu_atom/' for 'cpu_atom' pmu but the file '/sys/devices/cpu_atom/cpus' is empty, which indicates this is an invalid pmu. So we need to check and skip the invalid hybrid pmu.Also we need to update some perf test cases for core-only system.
Quoted 7 lines
Quoted 5 lines
Jin Yao (4):
perf pmu: Skip invalid hybrid pmu
perf tests: Fix 'Parse event definition strings' on core-only system perf tests: Fix 'Roundtripevsel->name' on core-only system perf tests: Fix 'Convert perf time to TSC' on core-only systemAcked-by Jiri Olsa <[email protected]>
Thanks, applied to perf/urgent.
- Arnaldo