libpmc: fall-back to kernel tables if pmu-events fails

On x86, the pmu_events table is the source of truth for finding
supported events. However, events not found there may still be present
in the kernel's static event tables. For example, the pmc.soft(3) events
will never be available from pmu-events.

Update pmc_allocate() to search the legacy event tables if
pmc_pmu_pmcallocate() fails to return a result. This allows both event
sources to be consulted before giving up, thus restoring pmc.soft(3) and
pmc.tsc(3) on x86.

Reviewed by:	emaste
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D30216
This commit is contained in:
Mitchell Horne 2021-05-13 15:57:37 -03:00
parent da13ef6aa0
commit dfdc57e8aa

View File

@ -989,25 +989,25 @@ pmc_allocate(const char *ctrspec, enum pmc_mode mode,
pmc_config.pm_count = count; pmc_config.pm_count = count;
if (PMC_IS_SAMPLING_MODE(mode)) if (PMC_IS_SAMPLING_MODE(mode))
pmc_config.pm_caps |= PMC_CAP_INTERRUPT; pmc_config.pm_caps |= PMC_CAP_INTERRUPT;
/* /*
* Can we pull this straight from the pmu table? * Try to pull the raw event ID directly from the pmu-events table. If
* this is unsupported on the platform, or the event is not found,
* continue with searching the regular event tables.
*/ */
r = spec_copy = strdup(ctrspec); r = spec_copy = strdup(ctrspec);
ctrname = strsep(&r, ","); ctrname = strsep(&r, ",");
if (pmc_pmu_enabled()) { if (pmc_pmu_enabled()) {
if (pmc_pmu_pmcallocate(ctrname, &pmc_config) == 0) { if (pmc_pmu_pmcallocate(ctrname, &pmc_config) == 0)
if (PMC_CALL(PMCALLOCATE, &pmc_config) < 0) { goto found;
goto out;
/* Otherwise, reset any changes */
pmc_config.pm_ev = 0;
pmc_config.pm_caps = 0;
pmc_config.pm_class = 0;
} }
retval = 0;
*pmcid = pmc_config.pm_pmcid;
goto out;
}
errx(EX_USAGE, "ERROR: pmc_pmu_allocate failed, check for ctrname %s\n", ctrname);
} else {
free(spec_copy); free(spec_copy);
spec_copy = NULL; spec_copy = NULL;
}
/* replace an event alias with the canonical event specifier */ /* replace an event alias with the canonical event specifier */
if (pmc_mdep_event_aliases) if (pmc_mdep_event_aliases)
@ -1064,13 +1064,11 @@ pmc_allocate(const char *ctrspec, enum pmc_mode mode,
goto out; goto out;
} }
if (PMC_CALL(PMCALLOCATE, &pmc_config) < 0) found:
goto out; if (PMC_CALL(PMCALLOCATE, &pmc_config) == 0) {
*pmcid = pmc_config.pm_pmcid; *pmcid = pmc_config.pm_pmcid;
retval = 0; retval = 0;
}
out: out:
if (spec_copy) if (spec_copy)
free(spec_copy); free(spec_copy);