git: c1e813d12309 - main - hwpmc: Correct selection of Intel fixed counters.

From: Alexander Motin <mav_at_FreeBSD.org>
Date: Tue, 31 May 2022 00:05:22 UTC
The branch main has been updated by mav:

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

commit c1e813d1230915e19a236ec687cadc1051841e56
Author:     Alexander Motin <mav@FreeBSD.org>
AuthorDate: 2022-05-30 23:46:48 +0000
Commit:     Alexander Motin <mav@FreeBSD.org>
CommitDate: 2022-05-31 00:05:15 +0000

    hwpmc: Correct selection of Intel fixed counters.
    
    Intel json's use event=0 to specify fixed counter number via umask.
    Alternatively fixed counters have equivalent programmable event/umask.
    
    MFC after:      1 month
---
 sys/dev/hwpmc/hwpmc_core.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/sys/dev/hwpmc/hwpmc_core.c b/sys/dev/hwpmc/hwpmc_core.c
index fce97cbd5b8e..73cfee0b3975 100644
--- a/sys/dev/hwpmc/hwpmc_core.c
+++ b/sys/dev/hwpmc/hwpmc_core.c
@@ -245,15 +245,31 @@ iaf_allocate_pmc(int cpu, int ri, struct pmc *pm,
 	ev = IAP_EVSEL_GET(config);
 	umask = IAP_UMASK_GET(config);
 
-	/* INST_RETIRED.ANY */
-	if (ev == 0xC0 && ri != 0)
-		return (EINVAL);
-	/* CPU_CLK_UNHALTED.THREAD */
-	if (ev == 0x3C && ri != 1)
-		return (EINVAL);
-	/* CPU_CLK_UNHALTED.REF */
-	if (ev == 0x0 && umask == 0x3 && ri != 2)
-		return (EINVAL);
+	if (ev == 0x0) {
+		if (umask != ri + 1)
+			return (EINVAL);
+	} else {
+		switch (ri) {
+		case 0:	/* INST_RETIRED.ANY */
+			if (ev != 0xC0 || umask != 0x00)
+				return (EINVAL);
+			break;
+		case 1:	/* CPU_CLK_UNHALTED.THREAD */
+			if (ev != 0x3C || umask != 0x00)
+				return (EINVAL);
+			break;
+		case 2:	/* CPU_CLK_UNHALTED.REF */
+			if (ev != 0x3C || umask != 0x01)
+				return (EINVAL);
+			break;
+		case 3:	/* TOPDOWN.SLOTS */
+			if (ev != 0xA4 || umask != 0x01)
+				return (EINVAL);
+			break;
+		default:
+			return (EINVAL);
+		}
+	}
 
 	pmc_alloc_refs++;
 	if ((cpu_stdext_feature3 & CPUID_STDEXT3_TSXFA) != 0 &&