git: 457873bda393 - main - tests/sys/pmc: Skip pmc_ss and getmsr_refusals without a hardware PMC
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 19 Nov 2026 17:40:11 UTC
The branch main has been updated by mhorne:
URL: https://cgit.FreeBSD.org/src/commit/?id=457873bda393224f2f7f95f93dbb4d2d52520b25
commit 457873bda393224f2f7f95f93dbb4d2d52520b25
Author: Osvaldo Janeri Filho <ojanerif@amd.com>
AuthorDate: 2026-11-19 17:38:25 +0000
Commit: Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2026-11-19 17:38:26 +0000
tests/sys/pmc: Skip pmc_ss and getmsr_refusals without a hardware PMC
In a guest without a PMU, hwpmc(4) registers only the SOFT class, but
the "instructions" alias still resolves from the pmu-events tables, so
pmc_allocate() fails with EINVAL. pmc_ss_test checked only the alias
and getmsr_refusals required the allocation, so both failed in CI
instead of skipping.
Probe the allocation the tests make and skip if it fails, as
rdpmc_reads_own_counter already does.
PR: 300856 (https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300856)
Reported by: ngie
Reviewed by: mhorne, ngie
Fixes: d546356523f3 ("tests/sys/pmc: add PERF, RDPMC, row, sampling and unload tests")
Sponsored by: Advanced Micro Devices, Inc.
Signed-off-by: Osvaldo Janeri Filho <ojanerif@amd.com>
Differential Revision: https://reviews.freebsd.org/D61689
---
tests/sys/pmc/pmc_rdpmc_test.c | 4 +++-
tests/sys/pmc/pmc_ss_test.c | 12 ++++++++----
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/tests/sys/pmc/pmc_rdpmc_test.c b/tests/sys/pmc/pmc_rdpmc_test.c
index a79ef7b6e7bd..53064c98b8ec 100644
--- a/tests/sys/pmc/pmc_rdpmc_test.c
+++ b/tests/sys/pmc/pmc_rdpmc_test.c
@@ -126,7 +126,9 @@ ATF_TC_BODY(getmsr_refusals, tc)
setup();
id = PMC_ID_INVALID;
- ATF_REQUIRE(pmc_allocate(EVENT, PMC_MODE_SC, 0, 0, &id, 0) == 0);
+ if (pmc_allocate(EVENT, PMC_MODE_SC, 0, 0, &id, 0) != 0)
+ atf_tc_skip("pmc_allocate(%s) failed: %s", EVENT,
+ strerror(errno));
error = getmsr_errno(id);
ATF_CHECK_MSG(error == EINVAL, "system mode: errno %d", error);
ATF_CHECK(pmc_release(id) == 0);
diff --git a/tests/sys/pmc/pmc_ss_test.c b/tests/sys/pmc/pmc_ss_test.c
index 4716080903ab..3ed9d9c4cd76 100644
--- a/tests/sys/pmc/pmc_ss_test.c
+++ b/tests/sys/pmc/pmc_ss_test.c
@@ -213,23 +213,27 @@ run_owner(int cpu, struct result *r)
static int
sample(struct result *r)
{
- struct pmc_op_pmcallocate cfg;
cpuset_t mask;
+ pmc_id_t id;
pid_t child;
ssize_t n;
int cpu, fds[2], status;
if (pmc_init() != 0)
atf_tc_skip("hwpmc(4) is not loaded: %s", strerror(errno));
- memset(&cfg, 0, sizeof(cfg));
- if (pmc_pmu_pmcallocate(EVENT, &cfg) != 0)
- atf_tc_skip("no %s event in the pmu-events tables", EVENT);
ATF_REQUIRE(cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1,
sizeof(mask), &mask) == 0);
cpu = CPU_FFS(&mask) - 1;
ATF_REQUIRE(cpu >= 0);
+ /* A guest without a PMU has the event name but no counter for it. */
+ id = PMC_ID_INVALID;
+ if (pmc_allocate(EVENT, PMC_MODE_SS, 0, cpu, &id, PERIOD) != 0)
+ atf_tc_skip("pmc_allocate(%s) failed: %s", EVENT,
+ strerror(errno));
+ ATF_REQUIRE(pmc_release(id) == 0);
+
ATF_REQUIRE(pipe(fds) == 0);
child = fork();
ATF_REQUIRE(child >= 0);