{
int paranoid;
- if ((err == ENOENT || err == ENXIO || err == ENODEV) &&
- evsel->core.attr.type == PERF_TYPE_HARDWARE &&
- evsel->core.attr.config == PERF_COUNT_HW_CPU_CYCLES) {
+ if ((err == ENODEV || err == ENOENT || err == ENXIO) &&
+ evsel__match(evsel, HARDWARE, HW_CPU_CYCLES)) {
/*
- * If it's cycles then fall back to hrtimer based cpu-clock sw
- * counter, which is always available even if no PMU support.
- *
- * PPC returns ENXIO until 2.6.37 (behavior changed with commit
- * b0a873e).
+ * If it's the legacy hardware cycles event fails then fall back
+ * to hrtimer based cpu-clock sw counter, which is always
+ * available even if no PMU support. PPC returned ENXIO rather
+ * than ENODEV or ENOENT until 2.6.37.
*/
- evsel->core.attr.type = PERF_TYPE_SOFTWARE;
+ evsel->pmu = perf_pmus__find_by_type(PERF_TYPE_SOFTWARE);
+ assert(evsel->pmu); /* software is a "well-known" and can't fail PMU type. */
+
+ /* Configure the event. */
+ evsel->core.attr.type = PERF_TYPE_SOFTWARE;
evsel->core.attr.config = target__has_cpu(target)
? PERF_COUNT_SW_CPU_CLOCK
: PERF_COUNT_SW_TASK_CLOCK;
- scnprintf(msg, msgsize,
- "The cycles event is not supported, trying to fall back to %s",
- target__has_cpu(target) ? "cpu-clock" : "task-clock");
+ evsel->core.is_pmu_core = false;
+
+ /* Remove excludes for new event. */
+ if (evsel->fallenback_eacces) {
+ evsel->core.attr.exclude_kernel = 0;
+ evsel->core.attr.exclude_hv = 0;
+ evsel->fallenback_eacces = false;
+ }
+ if (evsel->fallenback_eopnotsupp) {
+ evsel->core.attr.exclude_guest = 0;
+ evsel->fallenback_eopnotsupp = false;
+ }
+ /* Name is recomputed by evsel__name. */
zfree(&evsel->name);
+
+ /* Log message. */
+ scnprintf(msg, msgsize,
+ "The cycles event is not supported, trying to fall back to %s",
+ evsel__name(evsel));
return true;
} else if (err == EACCES && !evsel->core.attr.exclude_kernel &&
(paranoid = perf_event_paranoid()) > 1) {
" samples", paranoid);
evsel->core.attr.exclude_kernel = 1;
evsel->core.attr.exclude_hv = 1;
-
+ evsel->fallenback_eacces = true;
return true;
} else if (err == EOPNOTSUPP && !evsel->core.attr.exclude_guest &&
!evsel->exclude_GH) {
/* Apple M1 requires exclude_guest */
scnprintf(msg, msgsize, "Trying to fall back to excluding guest samples");
evsel->core.attr.exclude_guest = 1;
-
+ evsel->fallenback_eopnotsupp = true;
return true;
}
no_fallback: