From owner-svn-src-all@freebsd.org Tue May 29 04:23:24 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1AE83F9BB11; Tue, 29 May 2018 04:23:24 +0000 (UTC) (envelope-from mmacy@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5C20975A0D; Tue, 29 May 2018 04:23:22 +0000 (UTC) (envelope-from mmacy@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6EF9B171F8; Tue, 29 May 2018 04:23:22 +0000 (UTC) (envelope-from mmacy@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w4T4NMhR059072; Tue, 29 May 2018 04:23:22 GMT (envelope-from mmacy@FreeBSD.org) Received: (from mmacy@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w4T4NMip059071; Tue, 29 May 2018 04:23:22 GMT (envelope-from mmacy@FreeBSD.org) Message-Id: <201805290423.w4T4NMip059071@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mmacy set sender to mmacy@FreeBSD.org using -f From: Matt Macy Date: Tue, 29 May 2018 04:23:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334313 - head/lib/libpmc X-SVN-Group: head X-SVN-Commit-Author: mmacy X-SVN-Commit-Paths: head/lib/libpmc X-SVN-Commit-Revision: 334313 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 May 2018 04:23:24 -0000 Author: mmacy Date: Tue May 29 04:23:21 2018 New Revision: 334313 URL: https://svnweb.freebsd.org/changeset/base/334313 Log: libpmc: add support for using fixed function counters Modified: head/lib/libpmc/libpmc_pmu_util.c (contents, props changed) Modified: head/lib/libpmc/libpmc_pmu_util.c ============================================================================== --- head/lib/libpmc/libpmc_pmu_util.c Tue May 29 04:23:16 2018 (r334312) +++ head/lib/libpmc/libpmc_pmu_util.c Tue May 29 04:23:21 2018 (r334313) @@ -63,6 +63,14 @@ static struct pmu_alias pmu_alias_table[] = { { NULL, NULL }, }; +static const char *fixed_mode_cntrs[] = { + "inst_retired.any", + "cpu_clk_unhalted.thread", + "cpu_clk_unhalted.thread_any", + "cpu_clk_unhalted.ref_tsc", + NULL +}; + static const char * pmu_alias_get(const char *name) { @@ -288,11 +296,15 @@ pmc_pmu_pmcallocate(const char *event_name, struct pmc const struct pmu_event *pe; struct pmu_event_desc ped; struct pmc_md_iap_op_pmcallocate *iap; - int idx; + struct pmc_md_iaf_op_pmcallocate *iaf; + int idx, isfixed; iap = &pm->pm_md.pm_iap; + iaf = &pm->pm_md.pm_iaf; + isfixed = 0; bzero(iap, sizeof(*iap)); event_name = pmu_alias_get(event_name); + pm->pm_caps |= (PMC_CAP_READ | PMC_CAP_WRITE); if ((pe = pmu_event_get(event_name, &idx)) == NULL) return (ENOENT); if (pe->alias && (pe = pmu_event_get(pe->alias, &idx)) == NULL) @@ -302,6 +314,29 @@ pmc_pmu_pmcallocate(const char *event_name, struct pmc if (pmu_parse_event(&ped, pe->event)) return (ENOENT); + for (idx = 0; fixed_mode_cntrs[idx] != NULL; idx++) + if (strcmp(fixed_mode_cntrs[idx], event_name) == 0) { + isfixed = 1; + printf("%s is fixed\n", event_name); + } + + if (isfixed) { + if (strcasestr(pe->desc, "retired") != NULL) + pm->pm_ev = PMC_EV_IAF_INSTR_RETIRED_ANY; + else if (strcasestr(pe->desc, "core") != NULL || + strcasestr(pe->desc, "unhalted")) + pm->pm_ev = PMC_EV_IAF_CPU_CLK_UNHALTED_CORE; + else if (strcasestr(pe->desc, "ref") != NULL) + pm->pm_ev = PMC_EV_IAF_CPU_CLK_UNHALTED_REF; + iaf->pm_iaf_flags |= (IAF_USR | IAF_OS); + if (ped.ped_any) + iaf->pm_iaf_flags |= IAF_ANY; + if (pm->pm_caps & PMC_CAP_INTERRUPT) + iaf->pm_iaf_flags |= IAF_PMI; + pm->pm_class = PMC_CLASS_IAF; + return (0); + } + pm->pm_caps |= PMC_CAP_QUALIFIER; pm->pm_class = PMC_CLASS_IAP; pm->pm_ev = idx; iap->pm_iap_config |= IAP_EVSEL(ped.ped_event); @@ -325,11 +360,12 @@ pmc_pmu_pmcallocate(const char *event_name, struct pmc * Ultimately rely on AMD calling theirs the same */ static const char *stat_mode_cntrs[] = { + "cpu_clk_unhalted.thread_any", "inst_retired.any", - "cpu_clk_unhalted.thread_p_any", "br_inst_retired.all_branches", "br_misp_retired.all_branches", - "cpu_clk_unhalted.thread_p_any" + "longest_lat_cache.reference", + "longest_lat_cache.miss", }; int