From owner-dev-commits-src-main@freebsd.org Wed Jul 21 23:18:40 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3A5BF66E868; Wed, 21 Jul 2021 23:18:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GVWjX0qQGz3s9p; Wed, 21 Jul 2021 23:18:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F407B26B37; Wed, 21 Jul 2021 23:18:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 16LNIdZb047849; Wed, 21 Jul 2021 23:18:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 16LNIdcB047848; Wed, 21 Jul 2021 23:18:39 GMT (envelope-from git) Date: Wed, 21 Jul 2021 23:18:39 GMT Message-Id: <202107212318.16LNIdcB047848@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: 27ea55fc655b - main - libpmc/hwpmc: fix issues with arm64 pmu-events support MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 27ea55fc655b0081f760a34ff5dd5526ba02a0fb Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Jul 2021 23:18:40 -0000 The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=27ea55fc655b0081f760a34ff5dd5526ba02a0fb commit 27ea55fc655b0081f760a34ff5dd5526ba02a0fb Author: Mitchell Horne AuthorDate: 2021-07-21 22:59:27 +0000 Commit: Mitchell Horne 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 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); }