aboutsummaryrefslogtreecommitdiff
path: root/lib/libpmc
diff options
context:
space:
mode:
authorMitchell Horne <mhorne@FreeBSD.org>2021-05-19 16:11:33 +0000
committerMitchell Horne <mhorne@FreeBSD.org>2021-07-29 15:02:05 +0000
commit83166f87140764c36d7c6bdfab0433aceada66a9 (patch)
treea37337f938c302bfc088fead41ac6b6a8766ef50 /lib/libpmc
parentd876c5a052fb589f213d20da2c146e5471047044 (diff)
downloadsrc-83166f87140764c36d7c6bdfab0433aceada66a9.tar.gz
src-83166f87140764c36d7c6bdfab0433aceada66a9.zip
arm64 support for pmu-events
8cc3815f: hwpmc_arm64: accept raw event codes for PMC_OP_PMCALLOCATE Make it possible to specify event codes without an offset of PMC_EV_ARMV8_FIRST, by setting a machine-dependent flag. This is required to make use of event definitions from pmu-events. Reviewed by: ray (slightly earlier version) MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D30602 28dd6730: libpmc: enable pmu_utils on arm64 This allows supported libpmc to query/select from the pmu-events table, which may have a more complete set of events than what we define manually. A future update to these definitions should greatly improve this support. The alias table is empty for now, until this future import is complete. Add the Foundation's copyright for recent work on this file. Reviewed by: ray (slightly earlier version) MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D30603 27ea55fc: 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 (cherry picked from commit 8cc3815f02be9fa2a96e47713ad989e6d787e12a) (cherry picked from commit 28dd6730a5d6bc73aca4c015c0ff875a9def25ac) (cherry picked from commit 27ea55fc655b0081f760a34ff5dd5526ba02a0fb)
Diffstat (limited to 'lib/libpmc')
-rw-r--r--lib/libpmc/libpmc_pmu_util.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/libpmc/libpmc_pmu_util.c b/lib/libpmc/libpmc_pmu_util.c
index 81320a3dc954..e6f74e6abe81 100644
--- a/lib/libpmc/libpmc_pmu_util.c
+++ b/lib/libpmc/libpmc_pmu_util.c
@@ -2,6 +2,10 @@
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2018, Matthew Macy
+ * Copyright (c) 2021, The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Mitchell Horne
+ * under sponsorship from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -139,6 +143,24 @@ pmu_alias_get(const char *name)
return (name);
}
+#elif defined(__aarch64__)
+
+static struct pmu_alias pmu_armv8_alias_table[] = {
+ {NULL, NULL},
+};
+
+static const char *
+pmu_alias_get(const char *name)
+{
+ struct pmu_alias *pa;
+
+ for (pa = pmu_armv8_alias_table; pa->pa_alias != NULL; pa++)
+ if (strcasecmp(name, pa->pa_alias) == 0)
+ return (pa->pa_name);
+
+ return (name);
+}
+
#else
static const char *
@@ -549,6 +571,33 @@ pmc_pmu_pmcallocate(const char *event_name, struct pmc_op_pmcallocate *pm)
return (pmc_pmu_amd_pmcallocate(event_name, pm, &ped));
}
+#elif defined(__aarch64__)
+
+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);
+ if ((pe = pmu_event_get(NULL, event_name, &idx)) == NULL)
+ 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);
+
+ return (0);
+}
+
#else
int