git: 27ea55fc655b - main - libpmc/hwpmc: fix issues with arm64 pmu-events support

Mitchell Horne mhorne at FreeBSD.org
Wed Jul 21 23:18:40 UTC 2021


The branch main has been updated by mhorne:

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

commit 27ea55fc655b0081f760a34ff5dd5526ba02a0fb
Author:     Mitchell Horne <mhorne at FreeBSD.org>
AuthorDate: 2021-07-21 22:59:27 +0000
Commit:     Mitchell Horne <mhorne at FreeBSD.org>
CommitDate: 2021-07-21 23:18:00 +0000

    libpmc/hwpmc: fix issues with arm64 pmu-events support
    
    Due to a mis-merge, the changes committed to libpmc never called
    pmu_parse_event(), or set pm->pm_ev. However, this field shouldn't be
    used to carry the actual pmc event code anyway, as it is expected to
    contain the index into the pmu event array (otherwise, it breaks event
    name lookup in pmclog_get_event()). Add a new MD field,
    pm_md.pm_md_config, to pass the raw event code to arm64_allocate_pmc().
    
    Additionally, the change made to pmc_md_op_pmcallocate was incorrect, as
    this is a union, not a struct. Restore the proper padding size.
    
    Reviewed by:    luporl, ray, andrew
    Fixes:          28dd6730a5d6 ("libpmc: enable pmu_utils on arm64")
    Fixes:          8cc3815f02be ("hwpmc_arm64: accept raw event codes...")
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D31221
---
 lib/libpmc/libpmc_pmu_util.c | 5 +++++
 sys/arm64/include/pmc_mdep.h | 8 +++++---
 sys/dev/hwpmc/hwpmc_arm64.c  | 4 ++--
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/lib/libpmc/libpmc_pmu_util.c b/lib/libpmc/libpmc_pmu_util.c
index d33abdb50acc..e6f74e6abe81 100644
--- a/lib/libpmc/libpmc_pmu_util.c
+++ b/lib/libpmc/libpmc_pmu_util.c
@@ -577,6 +577,7 @@ int
 pmc_pmu_pmcallocate(const char *event_name, struct pmc_op_pmcallocate *pm)
 {
 	const struct pmu_event *pe;
+	struct pmu_event_desc ped;
 	int idx = -1;
 
 	event_name = pmu_alias_get(event_name);
@@ -584,8 +585,12 @@ pmc_pmu_pmcallocate(const char *event_name, struct pmc_op_pmcallocate *pm)
 		return (ENOENT);
 	if (pe->event == NULL)
 		return (ENOENT);
+	if (pmu_parse_event(&ped, pe->event))
+		return (ENOENT);
 
 	assert(idx >= 0);
+	pm->pm_ev = idx;
+	pm->pm_md.pm_md_config = ped.ped_event;
 	pm->pm_md.pm_md_flags |= PM_MD_RAW_EVENT;
 	pm->pm_class = PMC_CLASS_ARMV8;
 	pm->pm_caps |= (PMC_CAP_READ | PMC_CAP_WRITE);
diff --git a/sys/arm64/include/pmc_mdep.h b/sys/arm64/include/pmc_mdep.h
index f4f31aba6305..dec90b386b13 100644
--- a/sys/arm64/include/pmc_mdep.h
+++ b/sys/arm64/include/pmc_mdep.h
@@ -38,10 +38,12 @@
 #include <dev/hwpmc/hwpmc_arm64.h>
 
 union pmc_md_op_pmcallocate {
-	uint32_t		pm_md_flags;
+	struct {
+		uint32_t	pm_md_config;
+		uint32_t	pm_md_flags;
 #define	PM_MD_RAW_EVENT		0x1
-	uint32_t		__pad32;
-	uint64_t		__pad[3];
+	};
+	uint64_t		__pad[4];
 };
 
 /* Logging */
diff --git a/sys/dev/hwpmc/hwpmc_arm64.c b/sys/dev/hwpmc/hwpmc_arm64.c
index 84a8791287f7..8a149f5f508f 100644
--- a/sys/dev/hwpmc/hwpmc_arm64.c
+++ b/sys/dev/hwpmc/hwpmc_arm64.c
@@ -182,9 +182,9 @@ arm64_allocate_pmc(int cpu, int ri, struct pmc *pm,
 	pe = a->pm_ev;
 
 	/* Adjust the config value if needed. */
-	config = (uint32_t)pe;
+	config = a->pm_md.pm_md_config;
 	if ((a->pm_md.pm_md_flags & PM_MD_RAW_EVENT) == 0) {
-		config -= PMC_EV_ARMV8_FIRST;
+		config = (uint32_t)pe - PMC_EV_ARMV8_FIRST;
 		if (config > (PMC_EV_ARMV8_LAST - PMC_EV_ARMV8_FIRST))
 			return (EINVAL);
 	}


More information about the dev-commits-src-all mailing list