From owner-dev-commits-src-main@freebsd.org Mon Jan 4 17:23:05 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 0512F4DD8B0; Mon, 4 Jan 2021 17:23:05 +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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4D8jBc6ms3z3LZq; Mon, 4 Jan 2021 17:23:04 +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 D0CC31D666; Mon, 4 Jan 2021 17:23:04 +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 104HN4EF014194; Mon, 4 Jan 2021 17:23:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 104HN46E014193; Mon, 4 Jan 2021 17:23:04 GMT (envelope-from git) Date: Mon, 4 Jan 2021 17:23:04 GMT Message-Id: <202101041723.104HN46E014193@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: 12d053032b6b - main - Support overflow count in hwpmc on arm64 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 12d053032b6bf51e0563c2720c82a4dba0cc8b82 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: Mon, 04 Jan 2021 17:23:05 -0000 The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=12d053032b6bf51e0563c2720c82a4dba0cc8b82 commit 12d053032b6bf51e0563c2720c82a4dba0cc8b82 Author: Andrew Turner AuthorDate: 2020-12-29 12:44:45 +0000 Commit: Andrew Turner CommitDate: 2021-01-04 17:14:41 +0000 Support overflow count in hwpmc on arm64 We increment the overflow count when receiving an overflow interrupt with special care to check if it happens while reading the event counter. Sponsored by: Innovate UK --- sys/dev/hwpmc/hwpmc_arm64.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/sys/dev/hwpmc/hwpmc_arm64.c b/sys/dev/hwpmc/hwpmc_arm64.c index 4ae8645abaf6..15ea4f892ed0 100644 --- a/sys/dev/hwpmc/hwpmc_arm64.c +++ b/sys/dev/hwpmc/hwpmc_arm64.c @@ -195,6 +195,8 @@ arm64_read_pmc(int cpu, int ri, pmc_value_t *v) { pmc_value_t tmp; struct pmc *pm; + register_t s; + int reg; KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), ("[arm64,%d] illegal CPU value %d", __LINE__, cpu)); @@ -203,7 +205,23 @@ arm64_read_pmc(int cpu, int ri, pmc_value_t *v) pm = arm64_pcpu[cpu]->pc_arm64pmcs[ri].phw_pmc; + /* + * Ensure we don't get interrupted while updating the overflow count. + */ + s = intr_disable(); tmp = arm64_pmcn_read(ri); + reg = (1 << ri); + if ((READ_SPECIALREG(pmovsclr_el0) & reg) != 0) { + /* Clear Overflow Flag */ + WRITE_SPECIALREG(pmovsclr_el0, reg); + if (!PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) + pm->pm_overflowcnt++; + + /* Reread counter in case we raced. */ + tmp = arm64_pmcn_read(ri); + } + tmp += 0x100000000llu * pm->pm_overflowcnt; + intr_restore(s); PMCDBG2(MDP, REA, 2, "arm64-read id=%d -> %jd", ri, tmp); if (PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) @@ -231,6 +249,7 @@ arm64_write_pmc(int cpu, int ri, pmc_value_t v) PMCDBG3(MDP, WRI, 1, "arm64-write cpu=%d ri=%d v=%jx", cpu, ri, v); + pm->pm_overflowcnt = v >> 32; arm64_pmcn_write(ri, v); return 0; @@ -342,9 +361,6 @@ arm64_intr(struct trapframe *tf) pm = arm64_pcpu[cpu]->pc_arm64pmcs[ri].phw_pmc; if (pm == NULL) continue; - if (!PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) - continue; - /* Check if counter is overflowed */ reg = (1 << ri); if ((READ_SPECIALREG(pmovsclr_el0) & reg) == 0) @@ -355,6 +371,12 @@ arm64_intr(struct trapframe *tf) isb(); retval = 1; /* Found an interrupting PMC. */ + + if (!PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) { + pm->pm_overflowcnt += 1; + continue; + } + if (pm->pm_state != PMC_STATE_RUNNING) continue;