git: b2e0fce71fed - main - tests/sys/pmc/amd: Call pmc_cpuinfo() in amd_test_find_classinfo()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 26 Nov 2026 14:12:08 UTC
The branch main has been updated by mhorne:
URL: https://cgit.FreeBSD.org/src/commit/?id=b2e0fce71fed9610f3788fc21914208922c614d5
commit b2e0fce71fed9610f3788fc21914208922c614d5
Author: Osvaldo Janeri Filho <ojanerif@amd.com>
AuthorDate: 2026-11-26 14:07:59 +0000
Commit: Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2026-11-26 14:12:04 +0000
tests/sys/pmc/amd: Call pmc_cpuinfo() in amd_test_find_classinfo()
Every caller of amd_test_find_classinfo() calls pmc_cpuinfo() right
before it. Do that in the helper and drop the ibs_classinfo() and
rapl_classinfo() wrappers.
rapl_domains_test now fails instead of skipping when pmc_cpuinfo()
fails after pmc_init() succeeded, like the other tests.
Suggested by: mhorne
Reviewed by: mhorne
Sponsored by: Advanced Micro Devices, Inc.
Signed-off-by: Osvaldo Janeri Filho <ojanerif@amd.com>
Differential Revision: https://reviews.freebsd.org/D62106
---
tests/sys/pmc/amd/amd_pmc_test_common.h | 11 +++++------
tests/sys/pmc/amd/pmc_ibs_test.c | 14 ++------------
tests/sys/pmc/amd/pmu_detect_test.c | 17 ++++-------------
tests/sys/pmc/amd/rapl_domains_test.c | 16 ++--------------
4 files changed, 13 insertions(+), 45 deletions(-)
diff --git a/tests/sys/pmc/amd/amd_pmc_test_common.h b/tests/sys/pmc/amd/amd_pmc_test_common.h
index ea43f3384264..ab161983b8d9 100644
--- a/tests/sys/pmc/amd/amd_pmc_test_common.h
+++ b/tests/sys/pmc/amd/amd_pmc_test_common.h
@@ -232,10 +232,13 @@ amd_test_bind_cpu0(void)
}
static inline const struct pmc_classinfo *
-amd_test_find_classinfo(const struct pmc_cpuinfo *cpuinfo, enum pmc_class cl)
+amd_test_find_classinfo(enum pmc_class cl)
{
+ const struct pmc_cpuinfo *cpuinfo;
uint32_t i;
+ ATF_REQUIRE_MSG(pmc_cpuinfo(&cpuinfo) == 0,
+ "pmc_cpuinfo() failed: %s", strerror(errno));
for (i = 0; i < cpuinfo->pm_nclass; i++)
if (cpuinfo->pm_classes[i].pm_class == cl)
return (&cpuinfo->pm_classes[i]);
@@ -251,11 +254,7 @@ amd_test_find_classinfo(const struct pmc_cpuinfo *cpuinfo, enum pmc_class cl)
static inline void
amd_test_skip_unless_class(enum pmc_class cl)
{
- const struct pmc_cpuinfo *cpuinfo;
-
- ATF_REQUIRE_MSG(pmc_cpuinfo(&cpuinfo) == 0,
- "pmc_cpuinfo() failed: %s", strerror(errno));
- if (amd_test_find_classinfo(cpuinfo, cl) == NULL)
+ if (amd_test_find_classinfo(cl) == NULL)
atf_tc_skip("hwpmc did not register %s",
pmc_name_of_class(cl));
}
diff --git a/tests/sys/pmc/amd/pmc_ibs_test.c b/tests/sys/pmc/amd/pmc_ibs_test.c
index cd99cf459929..7790c29b02e2 100644
--- a/tests/sys/pmc/amd/pmc_ibs_test.c
+++ b/tests/sys/pmc/amd/pmc_ibs_test.c
@@ -39,16 +39,6 @@
PMC_CAP_PRECISE)
#define LOG_WAIT_SECONDS 5
-static const struct pmc_classinfo *
-ibs_classinfo(void)
-{
- const struct pmc_cpuinfo *cpuinfo;
-
- ATF_REQUIRE_MSG(pmc_cpuinfo(&cpuinfo) == 0,
- "pmc_cpuinfo() failed: %s", strerror(errno));
- return (amd_test_find_classinfo(cpuinfo, PMC_CLASS_IBS));
-}
-
static void
skip_unless_ibs(void)
{
@@ -64,7 +54,7 @@ skip_unless_ibs(void)
CPUID_IBSID_FETCHSAM | CPUID_IBSID_OPSAM))
atf_tc_skip("CPU lacks IBS Fetch or Op sampling");
amd_test_skip_unless_hwpmc();
- if (ibs_classinfo() == NULL)
+ if (amd_test_find_classinfo(PMC_CLASS_IBS) == NULL)
atf_tc_skip("hwpmc does not expose PMC_CLASS_IBS");
}
@@ -133,7 +123,7 @@ ATF_TC_BODY(class_info, tc)
const struct pmc_classinfo *ci;
skip_unless_ibs();
- ci = ibs_classinfo();
+ ci = amd_test_find_classinfo(PMC_CLASS_IBS);
ATF_CHECK_EQ_MSG(ci->pm_num, 2, "IBS class has %u PMCs", ci->pm_num);
ATF_CHECK_EQ_MSG(ci->pm_width, 0, "IBS class width is %u",
ci->pm_width);
diff --git a/tests/sys/pmc/amd/pmu_detect_test.c b/tests/sys/pmc/amd/pmu_detect_test.c
index 03a12bb0c716..415e5f3e40b8 100644
--- a/tests/sys/pmc/amd/pmu_detect_test.c
+++ b/tests/sys/pmc/amd/pmu_detect_test.c
@@ -37,16 +37,13 @@ ATF_TC_HEAD(pmu_detect_k8_class_present, tc)
ATF_TC_BODY(pmu_detect_k8_class_present, tc)
{
- const struct pmc_cpuinfo *cpuinfo;
struct amd_test_cpu cpu;
amd_test_skip_unless_zen(&cpu);
amd_test_skip_unless_perfctr_extcore();
amd_test_skip_unless_hwpmc();
- ATF_REQUIRE_MSG(pmc_cpuinfo(&cpuinfo) == 0,
- "pmc_cpuinfo() failed: %s", strerror(errno));
- ATF_CHECK_MSG(amd_test_find_classinfo(cpuinfo, PMC_CLASS_K8) != NULL,
+ ATF_CHECK_MSG(amd_test_find_classinfo(PMC_CLASS_K8) != NULL,
"PMC_CLASS_K8 not registered on %s", amd_test_zen_name(cpu.zen));
}
@@ -60,7 +57,6 @@ ATF_TC_HEAD(pmu_detect_counter_width, tc)
ATF_TC_BODY(pmu_detect_counter_width, tc)
{
- const struct pmc_cpuinfo *cpuinfo;
const struct pmc_classinfo *ci;
struct amd_test_cpu cpu;
@@ -68,9 +64,7 @@ ATF_TC_BODY(pmu_detect_counter_width, tc)
amd_test_skip_unless_perfctr_extcore();
amd_test_skip_unless_hwpmc();
- ATF_REQUIRE_MSG(pmc_cpuinfo(&cpuinfo) == 0,
- "pmc_cpuinfo() failed: %s", strerror(errno));
- ci = amd_test_find_classinfo(cpuinfo, PMC_CLASS_K8);
+ ci = amd_test_find_classinfo(PMC_CLASS_K8);
ATF_REQUIRE_MSG(ci != NULL, "PMC_CLASS_K8 not registered");
ATF_CHECK_MSG(ci->pm_width == 48,
@@ -111,18 +105,15 @@ ATF_TC_HEAD(pmu_detect_tsc_class_coexists, tc)
ATF_TC_BODY(pmu_detect_tsc_class_coexists, tc)
{
- const struct pmc_cpuinfo *cpuinfo;
struct amd_test_cpu cpu;
amd_test_skip_unless_zen(&cpu);
amd_test_skip_unless_perfctr_extcore();
amd_test_skip_unless_hwpmc();
- ATF_REQUIRE_MSG(pmc_cpuinfo(&cpuinfo) == 0,
- "pmc_cpuinfo() failed: %s", strerror(errno));
- ATF_CHECK_MSG(amd_test_find_classinfo(cpuinfo, PMC_CLASS_K8) != NULL,
+ ATF_CHECK_MSG(amd_test_find_classinfo(PMC_CLASS_K8) != NULL,
"PMC_CLASS_K8 not registered");
- ATF_CHECK_MSG(amd_test_find_classinfo(cpuinfo, PMC_CLASS_TSC) != NULL,
+ ATF_CHECK_MSG(amd_test_find_classinfo(PMC_CLASS_TSC) != NULL,
"PMC_CLASS_TSC not registered");
}
diff --git a/tests/sys/pmc/amd/rapl_domains_test.c b/tests/sys/pmc/amd/rapl_domains_test.c
index 93a35b787549..6370000e0c84 100644
--- a/tests/sys/pmc/amd/rapl_domains_test.c
+++ b/tests/sys/pmc/amd/rapl_domains_test.c
@@ -28,18 +28,6 @@
/* CPU the SC-mode RAPL PMCs are allocated on. */
#define RAPL_CPU 0
-/* Return the PMC_CLASS_RAPL classinfo, or NULL if it is not registered. */
-static const struct pmc_classinfo *
-rapl_classinfo(void)
-{
- const struct pmc_cpuinfo *cpuinfo;
-
- if (pmc_cpuinfo(&cpuinfo) != 0)
- return (NULL);
-
- return (amd_test_find_classinfo(cpuinfo, PMC_CLASS_RAPL));
-}
-
/* Skip unless this is AMD with hwpmc and a registered RAPL class. */
static void
skip_unless_rapl(void)
@@ -47,7 +35,7 @@ skip_unless_rapl(void)
amd_test_skip_unless_amd();
amd_test_skip_unless_hwpmc();
- if (rapl_classinfo() == NULL)
+ if (amd_test_find_classinfo(PMC_CLASS_RAPL) == NULL)
atf_tc_skip("PMC_CLASS_RAPL not registered: the RAPL energy "
"MSRs did not respond (VM or unsupported CPU)");
}
@@ -68,7 +56,7 @@ ATF_TC_BODY(rapl_metadata_names, tc)
skip_unless_rapl();
- ci = rapl_classinfo();
+ ci = amd_test_find_classinfo(PMC_CLASS_RAPL);
ATF_REQUIRE(ci != NULL);
/* The driver registers only the rows whose MSR responds. */
ATF_CHECK_MSG(ci->pm_num >= 1 && ci->pm_num <= 2,