From owner-dev-commits-src-branches@freebsd.org Thu Jul 29 15:25:19 2021 Return-Path: Delivered-To: dev-commits-src-branches@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 9C940675C23; Thu, 29 Jul 2021 15:25:19 +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 4GbDqg339sz4sph; Thu, 29 Jul 2021 15:25:19 +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 4778113FE3; Thu, 29 Jul 2021 15:25:19 +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 16TFPJDq009705; Thu, 29 Jul 2021 15:25:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 16TFPJla009704; Thu, 29 Jul 2021 15:25:19 GMT (envelope-from git) Date: Thu, 29 Jul 2021 15:25:19 GMT Message-Id: <202107291525.16TFPJla009704@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: dfb4fb41166b - stable/13 - libpmc: fall-back to kernel tables if pmu-events fails 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/stable/13 X-Git-Reftype: branch X-Git-Commit: dfb4fb41166bc35935e5f6fd9351a0ada0f71159 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Jul 2021 15:25:19 -0000 The branch stable/13 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=dfb4fb41166bc35935e5f6fd9351a0ada0f71159 commit dfb4fb41166bc35935e5f6fd9351a0ada0f71159 Author: Mitchell Horne AuthorDate: 2021-05-13 18:57:37 +0000 Commit: Mitchell Horne CommitDate: 2021-07-29 15:01:09 +0000 libpmc: fall-back to kernel tables if pmu-events fails On x86, the pmu_events table is the source of truth for finding supported events. However, events not found there may still be present in the kernel's static event tables. For example, the pmc.soft(3) events will never be available from pmu-events. Update pmc_allocate() to search the legacy event tables if pmc_pmu_pmcallocate() fails to return a result. This allows both event sources to be consulted before giving up, thus restoring pmc.soft(3) and pmc.tsc(3) on x86. Reviewed by: emaste MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D30216 (cherry picked from commit dfdc57e8aa8ba4b4e4484f736e8c7645ab69b54a) --- lib/libpmc/libpmc.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/lib/libpmc/libpmc.c b/lib/libpmc/libpmc.c index 6636c974cb73..e2422f167267 100644 --- a/lib/libpmc/libpmc.c +++ b/lib/libpmc/libpmc.c @@ -989,25 +989,25 @@ pmc_allocate(const char *ctrspec, enum pmc_mode mode, pmc_config.pm_count = count; if (PMC_IS_SAMPLING_MODE(mode)) pmc_config.pm_caps |= PMC_CAP_INTERRUPT; + /* - * Can we pull this straight from the pmu table? + * Try to pull the raw event ID directly from the pmu-events table. If + * this is unsupported on the platform, or the event is not found, + * continue with searching the regular event tables. */ r = spec_copy = strdup(ctrspec); ctrname = strsep(&r, ","); if (pmc_pmu_enabled()) { - if (pmc_pmu_pmcallocate(ctrname, &pmc_config) == 0) { - if (PMC_CALL(PMCALLOCATE, &pmc_config) < 0) { - goto out; - } - retval = 0; - *pmcid = pmc_config.pm_pmcid; - goto out; - } - errx(EX_USAGE, "ERROR: pmc_pmu_allocate failed, check for ctrname %s\n", ctrname); - } else { - free(spec_copy); - spec_copy = NULL; + if (pmc_pmu_pmcallocate(ctrname, &pmc_config) == 0) + goto found; + + /* Otherwise, reset any changes */ + pmc_config.pm_ev = 0; + pmc_config.pm_caps = 0; + pmc_config.pm_class = 0; } + free(spec_copy); + spec_copy = NULL; /* replace an event alias with the canonical event specifier */ if (pmc_mdep_event_aliases) @@ -1064,14 +1064,12 @@ pmc_allocate(const char *ctrspec, enum pmc_mode mode, goto out; } - if (PMC_CALL(PMCALLOCATE, &pmc_config) < 0) - goto out; - - *pmcid = pmc_config.pm_pmcid; - - retval = 0; - - out: +found: + if (PMC_CALL(PMCALLOCATE, &pmc_config) == 0) { + *pmcid = pmc_config.pm_pmcid; + retval = 0; + } +out: if (spec_copy) free(spec_copy);