git: d2e7fcb6dd79 - main - hwpmc: do not register RAPL when the unit register reads as zero

Alexander Leidinger <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a8aab37.3e25e.62f7baa2__22372.065465764$1787472717$gmane$org@gitrepo.freebsd.org>
The branch main has been updated by netchild:

URL: https://cgit.FreeBSD.org/src/commit/?id=d2e7fcb6dd79691d336c3700e4727a887e5cabdc

commit d2e7fcb6dd79691d336c3700e4727a887e5cabdc
Author:     Alexander Leidinger <[email protected]>
AuthorDate: 2026-08-22 07:59:03 +0000
Commit:     Alexander Leidinger <[email protected]>
CommitDate: 2026-08-23 08:09:36 +0000

    hwpmc: do not register RAPL when the unit register reads as zero
    
    An energy status unit of zero means one joule per raw tick, which no part
    reports; it is what a hypervisor returns for an MSR it does not implement.
    Both energy rows are scaled by that field, so the class would be
    registered with counters that read zero forever.
    
    Refuse it, as the class is already refused when no energy MSR responds.
    
    Assisted-by:    Claude Code (Opus 5)
---
 sys/dev/hwpmc/hwpmc_rapl.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/sys/dev/hwpmc/hwpmc_rapl.c b/sys/dev/hwpmc/hwpmc_rapl.c
index 4ca76bc12403..c505ae35c248 100644
--- a/sys/dev/hwpmc/hwpmc_rapl.c
+++ b/sys/dev/hwpmc/hwpmc_rapl.c
@@ -535,6 +535,11 @@ pmc_rapl_initialize(struct pmc_mdep *md, int maxcpu, int classindex)
 	if (rdmsr_safe(unit_msr, &unit_val) != 0)
 		return (ENXIO);
 	esu = (unit_val >> 8) & 0x1f;
+
+	/* A zero unit is a hypervisor's answer for an MSR it does not have. */
+	if (esu == 0)
+		return (ENXIO);
+
 	dram_unit = rapl_intel_fixed_dram_unit() ? 16 : esu;
 
 	/* Build the event table from the MSRs that actually respond. */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.