Skip to content

Commit 82fe2e4

Browse files
committed
perf pmus: Check if we can encode the PMU number in perf_event_attr.type
In some architectures we can't encode the PMU number in perf_event_attr.type and thus can't just ask for the same event in multiple CPUs (and thus PMUs), that is what we want in hybrid systems but we can't when that encoding isn't understood by the kernel, such as in ARM64's big.LITTLE. If that is the case, fallback to the previous behaviour till we find a better solution to have consistent output accross architectures with hybrid CPU configurations. Co-developed-with: Ian Rogers <[email protected]> Cc: James Clark <[email protected]> Cc: John Garry <[email protected]> Cc: Leo Yan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mike Leach <[email protected]> Cc: Sumanth Korikkar <[email protected]> Cc: Suzuki K Poulose <[email protected]> Cc: Thomas Richter <[email protected]> Cc: Will Deacon <[email protected]> Link: https://lore.kernel.org/linux-perf-users/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent e2be066 commit 82fe2e4

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

tools/perf/util/pmus.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <subcmd/pager.h>
55
#include <sys/types.h>
66
#include <dirent.h>
7+
#include <pthread.h>
78
#include <string.h>
89
#include <unistd.h>
910
#include "debug.h"
@@ -492,9 +493,35 @@ int perf_pmus__num_core_pmus(void)
492493
return count;
493494
}
494495

496+
static bool __perf_pmus__supports_extended_type(void)
497+
{
498+
struct perf_pmu *pmu = NULL;
499+
500+
if (perf_pmus__num_core_pmus() <= 1)
501+
return false;
502+
503+
while ((pmu = perf_pmus__scan_core(pmu)) != NULL) {
504+
if (!is_event_supported(PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES | ((__u64)pmu->type << PERF_PMU_TYPE_SHIFT)))
505+
return false;
506+
}
507+
508+
return true;
509+
}
510+
511+
static bool perf_pmus__do_support_extended_type;
512+
513+
static void perf_pmus__init_supports_extended_type(void)
514+
{
515+
perf_pmus__do_support_extended_type = __perf_pmus__supports_extended_type();
516+
}
517+
495518
bool perf_pmus__supports_extended_type(void)
496519
{
497-
return perf_pmus__num_core_pmus() > 1;
520+
static pthread_once_t extended_type_once = PTHREAD_ONCE_INIT;
521+
522+
pthread_once(&extended_type_once, perf_pmus__init_supports_extended_type);
523+
524+
return perf_pmus__do_support_extended_type;
498525
}
499526

500527
struct perf_pmu *evsel__find_pmu(const struct evsel *evsel)

0 commit comments

Comments
 (0)