2021-07-08 01:40:37

by Jin Yao

[permalink] [raw]
Subject: [PATCH v2 0/4] 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(-)

--
2.17.1


2021-07-08 01:44:18

by Jin Yao

[permalink] [raw]
Subject: [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.

Signed-off-by: Jin Yao <[email protected]>
---
tools/perf/util/pmu.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 88c8ecdc60b0..cb20a9f69a04 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -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);
--
2.17.1

2021-07-08 01:45:53

by Jin Yao

[permalink] [raw]
Subject: [PATCH v2 2/4] perf tests: Fix 'Parse event definition strings' on core-only system

If the atom CPUs are offlined, the 'cpu_atom' is not valid.
We don't need the test case for 'cpu_atom'.

Signed-off-by: Jin Yao <[email protected]>
---
tools/perf/tests/parse-events.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 0f113b2b36a3..3ca515fb141f 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -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,
},
--
2.17.1

2021-07-08 01:50:00

by Jin Yao

[permalink] [raw]
Subject: [PATCH v2 4/4] perf tests: Fix 'Convert perf time to TSC' on core-only system

If the atom CPUs are offlined, the 'cpu_atom' is not valid.
We don't need the test case for 'cpu_atom'.

Signed-off-by: Jin Yao <[email protected]>
---
tools/perf/tests/perf-time-to-tsc.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/tests/perf-time-to-tsc.c b/tools/perf/tests/perf-time-to-tsc.c
index 85d75b9b25a1..7c56bc1f4cff 100644
--- a/tools/perf/tests/perf-time-to-tsc.c
+++ b/tools/perf/tests/perf-time-to-tsc.c
@@ -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;
--
2.17.1

2021-07-08 01:50:32

by Jin Yao

[permalink] [raw]
Subject: [PATCH v2 3/4] perf tests: Fix 'Roundtrip evsel->name' on core-only system

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

Signed-off-by: Jin Yao <[email protected]>
---
tools/perf/tests/evsel-roundtrip-name.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/tests/evsel-roundtrip-name.c b/tools/perf/tests/evsel-roundtrip-name.c
index b74cf80d1f10..26c49dc3e01e 100644
--- a/tools/perf/tests/evsel-roundtrip-name.c
+++ b/tools/perf/tests/evsel-roundtrip-name.c
@@ -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);
--
2.17.1

2021-07-11 16:00:00

by Jiri Olsa

[permalink] [raw]
Subject: Re: [PATCH v2 0/4] perf tool: Skip invalid hybrid PMU

On Thu, Jul 08, 2021 at 09:36:57AM +0800, Jin Yao wrote:
> 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

Acked-by: Jiri Olsa <[email protected]>

thanks,
jirka

>
> 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(-)
>
> --
> 2.17.1
>

2021-07-12 18:08:49

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH v2 0/4] perf tool: Skip invalid hybrid PMU

Em Sun, Jul 11, 2021 at 05:52:48PM +0200, Jiri Olsa escreveu:
> On Thu, Jul 08, 2021 at 09:36:57AM +0800, Jin Yao wrote:
> > 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
>
> Acked-by: Jiri Olsa <[email protected]>

Thanks, applied to perf/urgent.

- Arnaldo