From nobody Sat May 6 17:49:53 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QDFSL0ln2z49sw4; Sat, 6 May 2023 17:49:54 +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 4QDFSK73MLz3GWW; Sat, 6 May 2023 17:49:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683395394; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=HuBguxfgg+zLQ+53NeuB8Yv/d4YuuL9HB+oEZP3aJ6E=; b=I5pRLxpvT5h3cwTvQrGbxZQ2GTKirY/fnWZmnMvKxJgympuvswYeO+MKb7PQ+FzE2mzjta LDXbd0tJw5ObjXrfm9vdWjSQeuO/XlTlfYjrP+NdUJHSBKwPJCwxbJ7sYYxoFByI/YYCa4 OywqxdM91BV3EEUTXux7uaPWhetBAnxpapx1IKqUMunVEJalYJmnGtw8IzWEDual5N+Fcs eGOoOEkCVB4wZsInAwaW7HKLT6y23eoInwE9xWHHcpndykJ37Hxzr7y1x6r8ToDuhvC9rC wNUcUh6Lg/bsg0KEHhgl8PdYVY6wLawuWxWlshXVFWok0md4lFZ7yFFdF7VVPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683395394; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=HuBguxfgg+zLQ+53NeuB8Yv/d4YuuL9HB+oEZP3aJ6E=; b=ZOQ0VhmZhjYbU1zX1tAUpvy2JN7DdOg9d466Nqe0QWaxFM44sZlAUPPRwv9TSNiL1M339L 3tKH1nnOoAUrk27sItemXoUcLoxOWrNeth/Q4kYpINwAybSASt9dQgJeJJYz2S5D7j+ZDu +puKJRW8hb6jTRtMggBb0dkX1n4RF20JdeLzd01BX0v8iBkl2L87gdUxdK10PRVG0bVJJo gWkk/OMvM1psfE1UxpP8rqRp65RetJNyEPm/5EsinXf/Ydr7hbGMf5FMslOfVRBe0QeaW4 jYoGj1iV/vjzPtp0X/NsVfpswDp9N5D+qCA0bneDf8SKmzTzI13MdhDYvqRgOw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1683395394; a=rsa-sha256; cv=none; b=JMaUqTV7fxGZPPlrcUMJ2EISsGNOHPD2AR8Cy8kJVaocCo7QEFvOTWtDYvImMRI9k+SS+x VLtrnjaoINIdJwn/PZMNqp0HVZ9/2uc7/5+IKt6PHcYJcymgpu629h+Rvo+CVJ96fGcGkW lJkn4STrbH/+3HU5UFGe2rF0wlXuG4TTy/4IRiDzeODQn8qTS1HcrbA2WeZQ27dbYDI5Fn CdYmy5ZEPy2oG5w/1LrytldvSX0QnayIgZhTGH/LKnJKz9DVNiLCimyX6+CLFpApWyC1Ff Llg1PdMrefg/yqEbHgi/e9o7xqS8X72JpTJAr+gChVPhC5eTkoCeiHOQRTc6Yw== 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 4QDFSK68n7zlnJ; Sat, 6 May 2023 17:49:53 +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 346Hnr2f018104; Sat, 6 May 2023 17:49:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 346HnrUw018103; Sat, 6 May 2023 17:49:53 GMT (envelope-from git) Date: Sat, 6 May 2023 17:49:53 GMT Message-Id: <202305061749.346HnrUw018103@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: 39f92a76a99a - main - hwpmc: pass pmc pointer to more class methods List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org 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: 39f92a76a99a2ceb747250da4f2d627b9c317f8c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=39f92a76a99a2ceb747250da4f2d627b9c317f8c commit 39f92a76a99a2ceb747250da4f2d627b9c317f8c Author: Mitchell Horne AuthorDate: 2023-05-05 22:00:02 +0000 Commit: Mitchell Horne CommitDate: 2023-05-06 17:49:19 +0000 hwpmc: pass pmc pointer to more class methods In many cases this avoids an extra lookup, since the callers always have pm at hand. We can also eliminate several assertions, mostly for pm != NULL. The class methods are an internal interface, and the callers already handle such a scenario. No functional change intended. Reviewed by: jkoshy MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D39915 --- sys/dev/hwpmc/hwpmc_amd.c | 39 ++++----------------------- sys/dev/hwpmc/hwpmc_arm64.c | 22 +++++---------- sys/dev/hwpmc/hwpmc_armv7.c | 26 +++++------------- sys/dev/hwpmc/hwpmc_cmn600.c | 36 +++++-------------------- sys/dev/hwpmc/hwpmc_core.c | 62 ++++++------------------------------------- sys/dev/hwpmc/hwpmc_dmc620.c | 42 ++++++----------------------- sys/dev/hwpmc/hwpmc_e500.c | 2 +- sys/dev/hwpmc/hwpmc_mod.c | 34 +++++++++++++----------- sys/dev/hwpmc/hwpmc_powerpc.c | 25 +++++------------ sys/dev/hwpmc/hwpmc_powerpc.h | 8 +++--- sys/dev/hwpmc/hwpmc_soft.c | 41 ++++------------------------ sys/dev/hwpmc/hwpmc_tsc.c | 17 ++++-------- sys/dev/hwpmc/hwpmc_uncore.c | 62 ++++++------------------------------------- sys/sys/pmc.h | 12 +++++---- 14 files changed, 94 insertions(+), 334 deletions(-) diff --git a/sys/dev/hwpmc/hwpmc_amd.c b/sys/dev/hwpmc/hwpmc_amd.c index 43812951a8e5..9fe1f4f8ed87 100644 --- a/sys/dev/hwpmc/hwpmc_amd.c +++ b/sys/dev/hwpmc/hwpmc_amd.c @@ -397,11 +397,10 @@ static struct amd_cpu **amd_pcpu; */ static int -amd_read_pmc(int cpu, int ri, pmc_value_t *v) +amd_read_pmc(int cpu, int ri, struct pmc *pm, pmc_value_t *v) { enum pmc_mode mode; const struct amd_descr *pd; - struct pmc *pm; pmc_value_t tmp; KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), @@ -411,13 +410,7 @@ amd_read_pmc(int cpu, int ri, pmc_value_t *v) KASSERT(amd_pcpu[cpu], ("[amd,%d] null per-cpu, cpu %d", __LINE__, cpu)); - pm = amd_pcpu[cpu]->pc_amdpmcs[ri].phw_pmc; pd = &amd_pmcdesc[ri]; - - KASSERT(pm != NULL, - ("[amd,%d] No owner for HWPMC [cpu%d,pmc%d]", __LINE__, - cpu, ri)); - mode = PMC_TO_MODE(pm); PMCDBG2(MDP,REA,1,"amd-read id=%d class=%d", ri, pd->pm_descr.pd_class); @@ -456,24 +449,17 @@ amd_read_pmc(int cpu, int ri, pmc_value_t *v) */ static int -amd_write_pmc(int cpu, int ri, pmc_value_t v) +amd_write_pmc(int cpu, int ri, struct pmc *pm, pmc_value_t v) { const struct amd_descr *pd; enum pmc_mode mode; - struct pmc *pm; KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[amd,%d] illegal CPU value %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < AMD_NPMCS, ("[amd,%d] illegal row-index %d", __LINE__, ri)); - pm = amd_pcpu[cpu]->pc_amdpmcs[ri].phw_pmc; pd = &amd_pmcdesc[ri]; - - KASSERT(pm != NULL, - ("[amd,%d] PMC not owned (cpu%d,pmc%d)", __LINE__, - cpu, ri)); - mode = PMC_TO_MODE(pm); #ifdef HWPMC_DEBUG @@ -705,11 +691,9 @@ amd_release_pmc(int cpu, int ri, struct pmc *pmc) */ static int -amd_start_pmc(int cpu, int ri) +amd_start_pmc(int cpu, int ri, struct pmc *pm) { uint64_t config; - struct pmc *pm; - struct pmc_hw *phw; const struct amd_descr *pd; KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), @@ -717,14 +701,8 @@ amd_start_pmc(int cpu, int ri) KASSERT(ri >= 0 && ri < AMD_NPMCS, ("[amd,%d] illegal row-index %d", __LINE__, ri)); - phw = &amd_pcpu[cpu]->pc_amdpmcs[ri]; - pm = phw->phw_pmc; pd = &amd_pmcdesc[ri]; - KASSERT(pm != NULL, - ("[amd,%d] starting cpu%d,pmc%d with null pmc record", __LINE__, - cpu, ri)); - PMCDBG2(MDP,STA,1,"amd-start cpu=%d ri=%d", cpu, ri); KASSERT(AMD_PMC_IS_STOPPED(pd->pm_evsel), @@ -745,10 +723,8 @@ amd_start_pmc(int cpu, int ri) */ static int -amd_stop_pmc(int cpu, int ri) +amd_stop_pmc(int cpu, int ri, struct pmc *pm) { - struct pmc *pm; - struct pmc_hw *phw; const struct amd_descr *pd; uint64_t config; int i; @@ -758,13 +734,8 @@ amd_stop_pmc(int cpu, int ri) KASSERT(ri >= 0 && ri < AMD_NPMCS, ("[amd,%d] illegal row-index %d", __LINE__, ri)); - phw = &amd_pcpu[cpu]->pc_amdpmcs[ri]; - pm = phw->phw_pmc; - pd = &amd_pmcdesc[ri]; + pd = &amd_pmcdesc[ri]; - KASSERT(pm != NULL, - ("[amd,%d] cpu%d,pmc%d no PMC to stop", __LINE__, - cpu, ri)); KASSERT(!AMD_PMC_IS_STOPPED(pd->pm_evsel), ("[amd,%d] PMC%d, CPU%d \"%s\" already stopped", __LINE__, ri, cpu, pd->pm_descr.pd_name)); diff --git a/sys/dev/hwpmc/hwpmc_arm64.c b/sys/dev/hwpmc/hwpmc_arm64.c index e3fefc96ff8f..bbd3edf84ea0 100644 --- a/sys/dev/hwpmc/hwpmc_arm64.c +++ b/sys/dev/hwpmc/hwpmc_arm64.c @@ -211,10 +211,9 @@ arm64_allocate_pmc(int cpu, int ri, struct pmc *pm, static int -arm64_read_pmc(int cpu, int ri, pmc_value_t *v) +arm64_read_pmc(int cpu, int ri, struct pmc *pm, pmc_value_t *v) { pmc_value_t tmp; - struct pmc *pm; register_t s; int reg; @@ -223,8 +222,6 @@ arm64_read_pmc(int cpu, int ri, pmc_value_t *v) KASSERT(ri >= 0 && ri < arm64_npmcs, ("[arm64,%d] illegal row index %d", __LINE__, ri)); - pm = arm64_pcpu[cpu]->pc_arm64pmcs[ri].phw_pmc; - /* * Ensure we don't get interrupted while updating the overflow count. */ @@ -260,17 +257,14 @@ arm64_read_pmc(int cpu, int ri, pmc_value_t *v) } static int -arm64_write_pmc(int cpu, int ri, pmc_value_t v) +arm64_write_pmc(int cpu, int ri, struct pmc *pm, pmc_value_t v) { - struct pmc *pm; KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[arm64,%d] illegal CPU value %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < arm64_npmcs, ("[arm64,%d] illegal row-index %d", __LINE__, ri)); - pm = arm64_pcpu[cpu]->pc_arm64pmcs[ri].phw_pmc; - if (PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) v = ARMV8_RELOAD_COUNT_TO_PERFCTR_VALUE(v); @@ -306,14 +300,10 @@ arm64_config_pmc(int cpu, int ri, struct pmc *pm) } static int -arm64_start_pmc(int cpu, int ri) +arm64_start_pmc(int cpu, int ri, struct pmc *pm) { - struct pmc_hw *phw; uint32_t config; - struct pmc *pm; - phw = &arm64_pcpu[cpu]->pc_arm64pmcs[ri]; - pm = phw->phw_pmc; config = pm->pm_md.pm_arm64.pm_arm64_evsel; /* @@ -334,7 +324,7 @@ arm64_start_pmc(int cpu, int ri) } static int -arm64_stop_pmc(int cpu, int ri) +arm64_stop_pmc(int cpu, int ri, struct pmc *pm __unused) { /* * Disable the PMCs. @@ -404,10 +394,10 @@ arm64_intr(struct trapframe *tf) error = pmc_process_interrupt(PMC_HR, pm, tf); if (error) - arm64_stop_pmc(cpu, ri); + arm64_stop_pmc(cpu, ri, pm); /* Reload sampling count */ - arm64_write_pmc(cpu, ri, pm->pm_sc.pm_reloadcount); + arm64_write_pmc(cpu, ri, pm, pm->pm_sc.pm_reloadcount); } return (retval); diff --git a/sys/dev/hwpmc/hwpmc_armv7.c b/sys/dev/hwpmc/hwpmc_armv7.c index 526f9c59b4c8..89cb27457bd2 100644 --- a/sys/dev/hwpmc/hwpmc_armv7.c +++ b/sys/dev/hwpmc/hwpmc_armv7.c @@ -160,10 +160,9 @@ armv7_allocate_pmc(int cpu, int ri, struct pmc *pm, static int -armv7_read_pmc(int cpu, int ri, pmc_value_t *v) +armv7_read_pmc(int cpu, int ri, struct pmc *pm, pmc_value_t *v) { pmc_value_t tmp; - struct pmc *pm; register_t s; u_int reg; @@ -172,8 +171,6 @@ armv7_read_pmc(int cpu, int ri, pmc_value_t *v) KASSERT(ri >= 0 && ri < armv7_npmcs, ("[armv7,%d] illegal row index %d", __LINE__, ri)); - pm = armv7_pcpu[cpu]->pc_armv7pmcs[ri].phw_pmc; - s = intr_disable(); tmp = armv7_pmcn_read(ri, pm->pm_md.pm_armv7.pm_armv7_evsel); @@ -212,17 +209,14 @@ armv7_read_pmc(int cpu, int ri, pmc_value_t *v) } static int -armv7_write_pmc(int cpu, int ri, pmc_value_t v) +armv7_write_pmc(int cpu, int ri, struct pmc *pm, pmc_value_t v) { - struct pmc *pm; KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[armv7,%d] illegal CPU value %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < armv7_npmcs, ("[armv7,%d] illegal row-index %d", __LINE__, ri)); - pm = armv7_pcpu[cpu]->pc_armv7pmcs[ri].phw_pmc; - if (PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) v = ARMV7_RELOAD_COUNT_TO_PERFCTR_VALUE(v); @@ -261,14 +255,10 @@ armv7_config_pmc(int cpu, int ri, struct pmc *pm) } static int -armv7_start_pmc(int cpu, int ri) +armv7_start_pmc(int cpu, int ri, struct pmc *pm) { - struct pmc_hw *phw; uint32_t config; - struct pmc *pm; - phw = &armv7_pcpu[cpu]->pc_armv7pmcs[ri]; - pm = phw->phw_pmc; config = pm->pm_md.pm_armv7.pm_armv7_evsel; /* @@ -290,14 +280,10 @@ armv7_start_pmc(int cpu, int ri) } static int -armv7_stop_pmc(int cpu, int ri) +armv7_stop_pmc(int cpu, int ri, struct pmc *pm) { - struct pmc_hw *phw; - struct pmc *pm; uint32_t config; - phw = &armv7_pcpu[cpu]->pc_armv7pmcs[ri]; - pm = phw->phw_pmc; config = pm->pm_md.pm_armv7.pm_armv7_evsel; if (config == PMC_EV_CPU_CYCLES) ri = 31; @@ -372,10 +358,10 @@ armv7_intr(struct trapframe *tf) error = pmc_process_interrupt(PMC_HR, pm, tf); if (error) - armv7_stop_pmc(cpu, ri); + armv7_stop_pmc(cpu, ri, pm); /* Reload sampling count */ - armv7_write_pmc(cpu, ri, pm->pm_sc.pm_reloadcount); + armv7_write_pmc(cpu, ri, pm, pm->pm_sc.pm_reloadcount); } return (retval); diff --git a/sys/dev/hwpmc/hwpmc_cmn600.c b/sys/dev/hwpmc/hwpmc_cmn600.c index 82b6e553801a..762063a4a173 100644 --- a/sys/dev/hwpmc/hwpmc_cmn600.c +++ b/sys/dev/hwpmc/hwpmc_cmn600.c @@ -141,11 +141,10 @@ cmn600_pmu_writecntr(void *arg, u_int nodeid, u_int xpcntr, u_int dtccntr, * read a pmc register */ static int -cmn600_read_pmc(int cpu, int ri, pmc_value_t *v) +cmn600_read_pmc(int cpu, int ri, struct pmc *pm, pmc_value_t *v) { int counter, local_counter, nodeid; struct cmn600_descr *desc; - struct pmc *pm; void *arg; KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), @@ -155,15 +154,10 @@ cmn600_read_pmc(int cpu, int ri, pmc_value_t *v) counter = ri % CMN600_COUNTERS_N; desc = cmn600desc(ri); - pm = desc->pd_phw->phw_pmc; arg = desc->pd_rw_arg; nodeid = pm->pm_md.pm_cmn600.pm_cmn600_nodeid; local_counter = pm->pm_md.pm_cmn600.pm_cmn600_local_counter; - KASSERT(pm != NULL, - ("[cmn600,%d] No owner for HWPMC [cpu%d,pmc%d]", __LINE__, - cpu, ri)); - *v = cmn600_pmu_readcntr(arg, nodeid, local_counter, counter, 4); PMCDBG3(MDP, REA, 2, "%s id=%d -> %jd", __func__, ri, *v); @@ -174,11 +168,10 @@ cmn600_read_pmc(int cpu, int ri, pmc_value_t *v) * Write a pmc register. */ static int -cmn600_write_pmc(int cpu, int ri, pmc_value_t v) +cmn600_write_pmc(int cpu, int ri, struct pmc *pm, pmc_value_t v) { int counter, local_counter, nodeid; struct cmn600_descr *desc; - struct pmc *pm; void *arg; KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), @@ -188,7 +181,6 @@ cmn600_write_pmc(int cpu, int ri, pmc_value_t v) counter = ri % CMN600_COUNTERS_N; desc = cmn600desc(ri); - pm = desc->pd_phw->phw_pmc; arg = desc->pd_rw_arg; nodeid = pm->pm_md.pm_cmn600.pm_cmn600_nodeid; local_counter = pm->pm_md.pm_cmn600.pm_cmn600_local_counter; @@ -424,13 +416,11 @@ cmn600_encode_source(int node_type, int counter, int port, int sub) */ static int -cmn600_start_pmc(int cpu, int ri) +cmn600_start_pmc(int cpu, int ri, struct pmc *pm) { int counter, local_counter, node_type, shift; uint64_t config, occupancy, source, xp_pmucfg; struct cmn600_descr *desc; - struct pmc_hw *phw; - struct pmc *pm; uint8_t event, port, sub; uint16_t nodeid; void *arg; @@ -442,14 +432,8 @@ cmn600_start_pmc(int cpu, int ri) counter = ri % CMN600_COUNTERS_N; desc = cmn600desc(ri); - phw = desc->pd_phw; - pm = phw->phw_pmc; arg = desc->pd_rw_arg; - KASSERT(pm != NULL, - ("[cmn600,%d] starting cpu%d,pmc%d with null pmc record", __LINE__, - cpu, ri)); - PMCDBG3(MDP, STA, 1, "%s cpu=%d ri=%d", __func__, cpu, ri); config = pm->pm_md.pm_cmn600.pm_cmn600_config; @@ -541,11 +525,9 @@ cmn600_start_pmc(int cpu, int ri) */ static int -cmn600_stop_pmc(int cpu, int ri) +cmn600_stop_pmc(int cpu, int ri, struct pmc *pm) { struct cmn600_descr *desc; - struct pmc_hw *phw; - struct pmc *pm; int local_counter; uint64_t val; @@ -555,12 +537,6 @@ cmn600_stop_pmc(int cpu, int ri) ri)); desc = cmn600desc(ri); - phw = desc->pd_phw; - pm = phw->phw_pmc; - - KASSERT(pm != NULL, - ("[cmn600,%d] cpu%d,pmc%d no PMC to stop", __LINE__, - cpu, ri)); PMCDBG2(MDP, STO, 1, "%s ri=%d", __func__, ri); @@ -696,10 +672,10 @@ cmn600_pmu_intr(struct trapframe *tf, int unit, int i) error = pmc_process_interrupt(PMC_HR, pm, tf); if (error) - cmn600_stop_pmc(cpu, ri); + cmn600_stop_pmc(cpu, ri, pm); /* Reload sampling count */ - cmn600_write_pmc(cpu, ri, pm->pm_sc.pm_reloadcount); + cmn600_write_pmc(cpu, ri, pm, pm->pm_sc.pm_reloadcount); return (0); } diff --git a/sys/dev/hwpmc/hwpmc_core.c b/sys/dev/hwpmc/hwpmc_core.c index 76ffbdb9b0d2..02165898aeed 100644 --- a/sys/dev/hwpmc/hwpmc_core.c +++ b/sys/dev/hwpmc/hwpmc_core.c @@ -368,9 +368,8 @@ iaf_get_msr(int ri, uint32_t *msr) } static int -iaf_read_pmc(int cpu, int ri, pmc_value_t *v) +iaf_read_pmc(int cpu, int ri, struct pmc *pm, pmc_value_t *v) { - struct pmc *pm; pmc_value_t tmp; KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), @@ -378,12 +377,6 @@ iaf_read_pmc(int cpu, int ri, pmc_value_t *v) KASSERT(ri >= 0 && ri < core_iaf_npmc, ("[core,%d] illegal row-index %d", __LINE__, ri)); - pm = core_pcpu[cpu]->pc_corepmcs[ri + core_iaf_ri].phw_pmc; - - KASSERT(pm, - ("[core,%d] cpu %d ri %d(%d) pmc not configured", __LINE__, cpu, - ri, ri + core_iaf_ri)); - tmp = rdpmc(IAF_RI_TO_MSR(ri)); if (PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) @@ -421,9 +414,8 @@ iaf_release_pmc(int cpu, int ri, struct pmc *pmc) } static int -iaf_start_pmc(int cpu, int ri) +iaf_start_pmc(int cpu, int ri, struct pmc *pm) { - struct pmc *pm; struct core_cpu *cc; KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), @@ -434,8 +426,6 @@ iaf_start_pmc(int cpu, int ri) PMCDBG2(MDP,STA,1,"iaf-start cpu=%d ri=%d", cpu, ri); cc = core_pcpu[cpu]; - pm = cc->pc_corepmcs[ri + core_iaf_ri].phw_pmc; - cc->pc_iafctrl |= pm->pm_md.pm_iaf.pm_iaf_ctrl; wrmsr(IAF_CTRL, cc->pc_iafctrl); @@ -450,7 +440,7 @@ iaf_start_pmc(int cpu, int ri) } static int -iaf_stop_pmc(int cpu, int ri) +iaf_stop_pmc(int cpu, int ri, struct pmc *pm) { struct core_cpu *cc; @@ -476,10 +466,9 @@ iaf_stop_pmc(int cpu, int ri) } static int -iaf_write_pmc(int cpu, int ri, pmc_value_t v) +iaf_write_pmc(int cpu, int ri, struct pmc *pm, pmc_value_t v) { struct core_cpu *cc; - struct pmc *pm; KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[core,%d] illegal cpu value %d", __LINE__, cpu)); @@ -487,10 +476,6 @@ iaf_write_pmc(int cpu, int ri, pmc_value_t v) ("[core,%d] illegal row-index %d", __LINE__, ri)); cc = core_pcpu[cpu]; - pm = cc->pc_corepmcs[ri + core_iaf_ri].phw_pmc; - - KASSERT(pm, - ("[core,%d] cpu %d ri %d pmc not configured", __LINE__, cpu, ri)); if (PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) v = iaf_reload_count_to_perfctr_value(v); @@ -846,9 +831,8 @@ iap_get_msr(int ri, uint32_t *msr) } static int -iap_read_pmc(int cpu, int ri, pmc_value_t *v) +iap_read_pmc(int cpu, int ri, struct pmc *pm, pmc_value_t *v) { - struct pmc *pm; pmc_value_t tmp; KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), @@ -856,12 +840,6 @@ iap_read_pmc(int cpu, int ri, pmc_value_t *v) KASSERT(ri >= 0 && ri < core_iap_npmc, ("[core,%d] illegal row-index %d", __LINE__, ri)); - pm = core_pcpu[cpu]->pc_corepmcs[ri].phw_pmc; - - KASSERT(pm, - ("[core,%d] cpu %d ri %d pmc not configured", __LINE__, cpu, - ri)); - tmp = rdpmc(ri); if (PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) *v = iap_perfctr_value_to_reload_count(tmp); @@ -894,9 +872,8 @@ iap_release_pmc(int cpu, int ri, struct pmc *pm) } static int -iap_start_pmc(int cpu, int ri) +iap_start_pmc(int cpu, int ri, struct pmc *pm) { - struct pmc *pm; uint64_t evsel; struct core_cpu *cc; @@ -906,11 +883,6 @@ iap_start_pmc(int cpu, int ri) ("[core,%d] illegal row-index %d", __LINE__, ri)); cc = core_pcpu[cpu]; - pm = cc->pc_corepmcs[ri].phw_pmc; - - KASSERT(pm, - ("[core,%d] starting cpu%d,ri%d with no pmc configured", - __LINE__, cpu, ri)); PMCDBG2(MDP,STA,1, "iap-start cpu=%d ri=%d", cpu, ri); @@ -943,23 +915,14 @@ iap_start_pmc(int cpu, int ri) } static int -iap_stop_pmc(int cpu, int ri) +iap_stop_pmc(int cpu, int ri, struct pmc *pm __unused) { - struct pmc *pm __diagused; - struct core_cpu *cc; KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[core,%d] illegal cpu value %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < core_iap_npmc, ("[core,%d] illegal row index %d", __LINE__, ri)); - cc = core_pcpu[cpu]; - pm = cc->pc_corepmcs[ri].phw_pmc; - - KASSERT(pm, - ("[core,%d] cpu%d ri%d no configured PMC to stop", __LINE__, - cpu, ri)); - PMCDBG2(MDP,STO,1, "iap-stop cpu=%d ri=%d", cpu, ri); wrmsr(IAP_EVSEL0 + ri, 0); @@ -970,23 +933,14 @@ iap_stop_pmc(int cpu, int ri) } static int -iap_write_pmc(int cpu, int ri, pmc_value_t v) +iap_write_pmc(int cpu, int ri, struct pmc *pm, pmc_value_t v) { - struct pmc *pm; - struct core_cpu *cc; KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[core,%d] illegal cpu value %d", __LINE__, cpu)); KASSERT(ri >= 0 && ri < core_iap_npmc, ("[core,%d] illegal row index %d", __LINE__, ri)); - cc = core_pcpu[cpu]; - pm = cc->pc_corepmcs[ri].phw_pmc; - - KASSERT(pm, - ("[core,%d] cpu%d ri%d no configured PMC to stop", __LINE__, - cpu, ri)); - if (PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) v = iap_reload_count_to_perfctr_value(v); diff --git a/sys/dev/hwpmc/hwpmc_dmc620.c b/sys/dev/hwpmc/hwpmc_dmc620.c index 6152e264a169..f32199df15e7 100644 --- a/sys/dev/hwpmc/hwpmc_dmc620.c +++ b/sys/dev/hwpmc/hwpmc_dmc620.c @@ -192,10 +192,10 @@ class_ri2unit(int class, int ri) * read a pmc register */ -CLASSDEP_FN3(dmc620_read_pmc, int, cpu, int, ri, pmc_value_t *, v) +CLASSDEP_FN4(dmc620_read_pmc, int, cpu, int, ri, struct pmc *, pm, + pmc_value_t *, v) { struct dmc620_descr *desc; - struct pmc *pm; KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[dmc620,%d] illegal CPU value %d", __LINE__, cpu)); @@ -203,11 +203,6 @@ CLASSDEP_FN3(dmc620_read_pmc, int, cpu, int, ri, pmc_value_t *, v) ri)); desc = dmc620desc(class, cpu, ri); - pm = desc->pd_phw->phw_pmc; - - KASSERT(pm != NULL, - ("[dmc620,%d] No owner for HWPMC [cpu%d,pmc%d]", __LINE__, - cpu, ri)); PMCDBG3(MDP,REA,1,"%s id=%d class=%d", __func__, ri, class); @@ -229,10 +224,10 @@ CLASSDEP_FN3(dmc620_read_pmc, int, cpu, int, ri, pmc_value_t *, v) * Write a pmc register. */ -CLASSDEP_FN3(dmc620_write_pmc, int, cpu, int, ri, pmc_value_t, v) +CLASSDEP_FN4(dmc620_write_pmc, int, cpu, int, ri, struct pmc *, pm, + pmc_value_t, v) { struct dmc620_descr *desc; - struct pmc *pm __diagused; KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[dmc620,%d] illegal CPU value %d", __LINE__, cpu)); @@ -240,11 +235,6 @@ CLASSDEP_FN3(dmc620_write_pmc, int, cpu, int, ri, pmc_value_t, v) ri)); desc = dmc620desc(class, cpu, ri); - pm = desc->pd_phw->phw_pmc; - - KASSERT(pm != NULL, - ("[dmc620,%d] PMC not owned (cpu%d,pmc%d)", __LINE__, - cpu, ri)); PMCDBG4(MDP, WRI, 1, "%s cpu=%d ri=%d v=%jx", __func__, cpu, ri, v); @@ -374,12 +364,10 @@ CLASSDEP_FN3(dmc620_release_pmc, int, cpu, int, ri, struct pmc *, pmc) * start a PMC. */ -CLASSDEP_FN2(dmc620_start_pmc, int, cpu, int, ri) +CLASSDEP_FN3(dmc620_start_pmc, int, cpu, int, ri, struct pmc *, pm) { struct dmc620_descr *desc; - struct pmc_hw *phw; uint64_t control; - struct pmc *pm; KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[dmc620,%d] illegal CPU value %d", __LINE__, cpu)); @@ -387,12 +375,6 @@ CLASSDEP_FN2(dmc620_start_pmc, int, cpu, int, ri) ri)); desc = dmc620desc(class, cpu, ri); - phw = desc->pd_phw; - pm = phw->phw_pmc; - - KASSERT(pm != NULL, - ("[dmc620,%d] starting cpu%d,pmc%d with null pmc record", __LINE__, - cpu, ri)); PMCDBG3(MDP, STA, 1, "%s cpu=%d ri=%d", __func__, cpu, ri); @@ -418,11 +400,9 @@ CLASSDEP_FN2(dmc620_start_pmc, int, cpu, int, ri) * Stop a PMC. */ -CLASSDEP_FN2(dmc620_stop_pmc, int, cpu, int, ri) +CLASSDEP_FN3(dmc620_stop_pmc, int, cpu, int, ri, struct pmc *, pm) { struct dmc620_descr *desc; - struct pmc_hw *phw; - struct pmc *pm; uint64_t control; KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), @@ -431,12 +411,6 @@ CLASSDEP_FN2(dmc620_stop_pmc, int, cpu, int, ri) ri)); desc = dmc620desc(class, cpu, ri); - phw = desc->pd_phw; - pm = phw->phw_pmc; - - KASSERT(pm != NULL, - ("[dmc620,%d] cpu%d,pmc%d no PMC to stop", __LINE__, - cpu, ri)); PMCDBG2(MDP, STO, 1, "%s ri=%d", __func__, ri); @@ -564,10 +538,10 @@ dmc620_intr(struct trapframe *tf, int class, int unit, int i) error = pmc_process_interrupt(PMC_HR, pm, tf); if (error) - dmc620_stop_pmc(class, cpu, ri); + dmc620_stop_pmc(class, cpu, ri, pm); /* Reload sampling count */ - dmc620_write_pmc(class, cpu, ri, pm->pm_sc.pm_reloadcount); + dmc620_write_pmc(class, cpu, ri, pm, pm->pm_sc.pm_reloadcount); return (0); } diff --git a/sys/dev/hwpmc/hwpmc_e500.c b/sys/dev/hwpmc/hwpmc_e500.c index b82bada95fe3..020337830eb5 100644 --- a/sys/dev/hwpmc/hwpmc_e500.c +++ b/sys/dev/hwpmc/hwpmc_e500.c @@ -341,7 +341,7 @@ e500_pcpu_init(struct pmc_mdep *md, int cpu) for (i = 0; i < E500_MAX_PMCS; i++) /* Initialize the PMC to stopped */ - powerpc_stop_pmc(cpu, i); + e500_set_pmc(cpu, i, PMCN_NONE); /* Unfreeze global register. */ mtpmr(PMR_PMGC0, PMGC_PMIE | PMGC_FCECE); diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c index fd90e62e3f2c..0c39271cf991 100644 --- a/sys/dev/hwpmc/hwpmc_mod.c +++ b/sys/dev/hwpmc/hwpmc_mod.c @@ -1488,7 +1488,7 @@ pmc_process_csw_in(struct thread *td) PMCDBG3(CSW,SWI,1,"cpu=%d ri=%d new=%jd", cpu, ri, newvalue); - pcd->pcd_write_pmc(cpu, adjri, newvalue); + pcd->pcd_write_pmc(cpu, adjri, pm, newvalue); /* If a sampling mode PMC, reset stalled state. */ if (PMC_TO_MODE(pm) == PMC_MODE_TS) @@ -1498,7 +1498,7 @@ pmc_process_csw_in(struct thread *td) pm->pm_pcpu_state[cpu].pps_cpustate = 1; /* Start the PMC. */ - pcd->pcd_start_pmc(cpu, adjri); + pcd->pcd_start_pmc(cpu, adjri, pm); } /* @@ -1601,7 +1601,7 @@ pmc_process_csw_out(struct thread *td) */ pm->pm_pcpu_state[cpu].pps_cpustate = 0; if (pm->pm_pcpu_state[cpu].pps_stalled == 0) - pcd->pcd_stop_pmc(cpu, adjri); + pcd->pcd_stop_pmc(cpu, adjri, pm); KASSERT(counter_u64_fetch(pm->pm_runcount) > 0, ("[pmc,%d] pm=%p runcount %ld", __LINE__, (void *) pm, @@ -1625,7 +1625,7 @@ pmc_process_csw_out(struct thread *td) ("[pmc,%d] pp refcnt = %d", __LINE__, pp->pp_refcnt)); - pcd->pcd_read_pmc(cpu, adjri, &newvalue); + pcd->pcd_read_pmc(cpu, adjri, pm, &newvalue); if (mode == PMC_MODE_TS) { PMCDBG3(CSW,SWO,1,"cpu=%d ri=%d val=%jd (samp)", @@ -2824,7 +2824,7 @@ pmc_release_pmc_descriptor(struct pmc *pm) PMCDBG2(PMC,REL,2, "stopping cpu=%d ri=%d", cpu, ri); critical_enter(); - pcd->pcd_stop_pmc(cpu, adjri); + pcd->pcd_stop_pmc(cpu, adjri, pm); critical_exit(); } @@ -3246,7 +3246,7 @@ pmc_start(struct pmc *pm) pm->pm_state = PMC_STATE_RUNNING; critical_enter(); - if ((error = pcd->pcd_write_pmc(cpu, adjri, + if ((error = pcd->pcd_write_pmc(cpu, adjri, pm, PMC_IS_SAMPLING_MODE(mode) ? pm->pm_sc.pm_reloadcount : pm->pm_sc.pm_initial)) == 0) { @@ -3256,7 +3256,7 @@ pmc_start(struct pmc *pm) /* Indicate that we desire this to run. Start it. */ pm->pm_pcpu_state[cpu].pps_cpustate = 1; - error = pcd->pcd_start_pmc(cpu, adjri); + error = pcd->pcd_start_pmc(cpu, adjri, pm); } critical_exit(); @@ -3321,8 +3321,9 @@ pmc_stop(struct pmc *pm) pm->pm_pcpu_state[cpu].pps_cpustate = 0; critical_enter(); - if ((error = pcd->pcd_stop_pmc(cpu, adjri)) == 0) - error = pcd->pcd_read_pmc(cpu, adjri, &pm->pm_sc.pm_initial); + if ((error = pcd->pcd_stop_pmc(cpu, adjri, pm)) == 0) + error = pcd->pcd_read_pmc(cpu, adjri, pm, + &pm->pm_sc.pm_initial); critical_exit(); pmc_restore_cpu_binding(&pb); @@ -4400,7 +4401,7 @@ pmc_syscall_handler(struct thread *td, void *syscall_args) if ((pm->pm_flags & PMC_F_ATTACHED_TO_OWNER) && (pm->pm_state == PMC_STATE_RUNNING)) error = (*pcd->pcd_read_pmc)(cpu, adjri, - &oldvalue); + pm, &oldvalue); else oldvalue = pm->pm_gv.pm_savedvalue; } @@ -4425,13 +4426,14 @@ pmc_syscall_handler(struct thread *td, void *syscall_args) critical_enter(); /* save old value */ - if (prw.pm_flags & PMC_F_OLDVALUE) + if (prw.pm_flags & PMC_F_OLDVALUE) { if ((error = (*pcd->pcd_read_pmc)(cpu, adjri, - &oldvalue))) + pm, &oldvalue))) goto error; + } /* write out new value */ if (prw.pm_flags & PMC_F_NEWVALUE) - error = (*pcd->pcd_write_pmc)(cpu, adjri, + error = (*pcd->pcd_write_pmc)(cpu, adjri, pm, prw.pm_value); error: critical_exit(); @@ -5028,7 +5030,7 @@ pmc_process_samples(int cpu, ring_type_t ring) continue; pm->pm_pcpu_state[cpu].pps_stalled = 0; - (*pcd->pcd_start_pmc)(cpu, adjri); + (*pcd->pcd_start_pmc)(cpu, adjri, pm); } } @@ -5162,11 +5164,11 @@ pmc_process_exit(void *arg __unused, struct proc *p) if (pm->pm_pcpu_state[cpu].pps_cpustate) { pm->pm_pcpu_state[cpu].pps_cpustate = 0; if (!pm->pm_pcpu_state[cpu].pps_stalled) { - (void) pcd->pcd_stop_pmc(cpu, adjri); + (void) pcd->pcd_stop_pmc(cpu, adjri, pm); if (PMC_TO_MODE(pm) == PMC_MODE_TC) { pcd->pcd_read_pmc(cpu, adjri, - &newvalue); + pm, &newvalue); tmp = newvalue - PMC_PCPU_SAVED(cpu,ri); diff --git a/sys/dev/hwpmc/hwpmc_powerpc.c b/sys/dev/hwpmc/hwpmc_powerpc.c index e2ce979d0ba8..7c9a9395ab46 100644 --- a/sys/dev/hwpmc/hwpmc_powerpc.c +++ b/sys/dev/hwpmc/hwpmc_powerpc.c @@ -248,19 +248,17 @@ powerpc_release_pmc(int cpu, int ri, struct pmc *pmc) } int -powerpc_start_pmc(int cpu, int ri) +powerpc_start_pmc(int cpu, int ri, struct pmc *pm) { - struct pmc *pm; PMCDBG2(MDP,STA,1,"powerpc-start cpu=%d ri=%d", cpu, ri); - pm = powerpc_pcpu[cpu]->pc_ppcpmcs[ri].phw_pmc; powerpc_set_pmc(cpu, ri, pm->pm_md.pm_powerpc.pm_powerpc_evsel); return (0); } int -powerpc_stop_pmc(int cpu, int ri) +powerpc_stop_pmc(int cpu, int ri, struct pmc *pm __unused) { PMCDBG2(MDP,STO,1, "powerpc-stop cpu=%d ri=%d", cpu, ri); powerpc_set_pmc(cpu, ri, PMCN_NONE); @@ -363,9 +361,8 @@ powerpc_pmcn_write_default(unsigned int pmc, uint32_t val) } int -powerpc_read_pmc(int cpu, int ri, pmc_value_t *v) +powerpc_read_pmc(int cpu, int ri, struct pmc *pm, pmc_value_t *v) { - struct pmc *pm; pmc_value_t p, r, tmp; KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), @@ -373,11 +370,6 @@ powerpc_read_pmc(int cpu, int ri, pmc_value_t *v) KASSERT(ri >= 0 && ri < ppc_max_pmcs, ("[powerpc,%d] illegal row index %d", __LINE__, ri)); - pm = powerpc_pcpu[cpu]->pc_ppcpmcs[ri].phw_pmc; - KASSERT(pm, - ("[core,%d] cpu %d ri %d pmc not configured", __LINE__, cpu, - ri)); - /* * After an interrupt occurs because of a PMC overflow, the PMC value * is not always MAX_PMC_VALUE + 1, but may be a little above it. @@ -416,9 +408,8 @@ powerpc_read_pmc(int cpu, int ri, pmc_value_t *v) } int -powerpc_write_pmc(int cpu, int ri, pmc_value_t v) +powerpc_write_pmc(int cpu, int ri, struct pmc *pm, pmc_value_t v) { - struct pmc *pm; pmc_value_t vlo; KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), @@ -426,8 +417,6 @@ powerpc_write_pmc(int cpu, int ri, pmc_value_t v) KASSERT(ri >= 0 && ri < ppc_max_pmcs, ("[powerpc,%d] illegal row-index %d", __LINE__, ri)); - pm = powerpc_pcpu[cpu]->pc_ppcpmcs[ri].phw_pmc; - if (PMC_IS_COUNTING_MODE(PMC_TO_MODE(pm))) { PPC_OVERFLOWCNT(pm) = v / (POWERPC_MAX_PMC_VALUE + 1); vlo = v % (POWERPC_MAX_PMC_VALUE + 1); @@ -482,7 +471,7 @@ powerpc_pmc_intr(struct trapframe *tf) if ((pm = pc->pc_ppcpmcs[i].phw_pmc) != NULL && PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) { if (pm->pm_state != PMC_STATE_RUNNING) { - powerpc_write_pmc(cpu, i, + powerpc_write_pmc(cpu, i, pm, pm->pm_sc.pm_reloadcount); continue; } @@ -504,11 +493,11 @@ powerpc_pmc_intr(struct trapframe *tf) PMCDBG3(MDP,INT,3, "cpu=%d ri=%d: error %d processing interrupt", cpu, i, error); - powerpc_stop_pmc(cpu, i); + powerpc_stop_pmc(cpu, i, pm); } /* Reload sampling count */ - powerpc_write_pmc(cpu, i, pm->pm_sc.pm_reloadcount); + powerpc_write_pmc(cpu, i, pm, pm->pm_sc.pm_reloadcount); } if (retval) diff --git a/sys/dev/hwpmc/hwpmc_powerpc.h b/sys/dev/hwpmc/hwpmc_powerpc.h index 25b041327b84..efd7aca1b9ef 100644 --- a/sys/dev/hwpmc/hwpmc_powerpc.h +++ b/sys/dev/hwpmc/hwpmc_powerpc.h @@ -101,13 +101,13 @@ int powerpc_pcpu_fini(struct pmc_mdep *md, int cpu); int powerpc_allocate_pmc(int cpu, int ri, struct pmc *pm, const struct pmc_op_pmcallocate *a); int powerpc_release_pmc(int cpu, int ri, struct pmc *pmc); -int powerpc_start_pmc(int cpu, int ri); -int powerpc_stop_pmc(int cpu, int ri); +int powerpc_start_pmc(int cpu, int ri, struct pmc *pm); +int powerpc_stop_pmc(int cpu, int ri, struct pmc *pm); *** 389 LINES SKIPPED ***