From nobody Fri Dec 31 07:48:37 2021 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 D97221925473; Fri, 31 Dec 2021 07:48:37 +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 4JQHM93xvlz4pYs; Fri, 31 Dec 2021 07:48:37 +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 5956E27D23; Fri, 31 Dec 2021 07:48:37 +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 1BV7mbh2006495; Fri, 31 Dec 2021 07:48:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BV7mbX9006494; Fri, 31 Dec 2021 07:48:37 GMT (envelope-from git) Date: Fri, 31 Dec 2021 07:48:37 GMT Message-Id: <202112310748.1BV7mbX9006494@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: abae2c01c5c7 - main - hwpmc: deorbit mips support 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: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: abae2c01c5c79c6b81bb278b4c7ba79db27ffdec Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1640936917; 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=Mp236bMwsifp/bUmaq2M4w+iqBoNKq0s4iR5FgDjB54=; b=BXWYx5EZOc6JWI7RGp3S9W4+Nyb7Vd5KtI/xna3rEX6VDTdeSZAQgGKdWqDI7Aa4YgQTS5 RzaFuVhMwt4cp+QLqX5oPDRIegUPx46FM1MrTxFbhZF/7SoZlUGehNXb9mTks++1/u1IN1 IkTOmSRBezu1t9yF5T3/T5laMm+dmcYgIKcFUGaz2EW7jln6Jvis/Gvt49cpJXWUvTaEPt HMjoZMotR6JELqVXa6LS85R06fMFYNoQoy/xOkdo3QSnWTV4m0HlhsljtsGOENnfQKd5o5 eqmjWnT5UxaQK3QZTRZCNfxRdhHpYkC0LxXU3E24J5A9mEIooIFB6W0ONGXCYQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1640936917; a=rsa-sha256; cv=none; b=mRsHPjmV5auu/JpZHNOnq2CvblDVop1V3ouayXQXyTXsR1dzf+7MOR5ol5FKcsmuOhGrwG GNE0jdgrF7dasuDjQNJE82jOmTeyzAZTuQo4ehC4tieG94z+cbN/t++gYprHwoqJiZ3wBV oGz7uVwIxVvM9Sd5AWkehckYW3K/HQnmcOQqlzjg1s+2rhD/4mGiVEXnvkt3xjdpPlbVaD U9/PYiS+nIXpIDwQQ13QSVlGZ0q8f6sm3wYUz3iWxrvf50P/pJ8gLzZtIjMPmOPqPcAqsV 4IRlBZQzWLYpHZRa+yGmKQnFnbE9KGsuPz4Ei0K7R3MET7M4GSxMJnUs9AFeMA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=abae2c01c5c79c6b81bb278b4c7ba79db27ffdec commit abae2c01c5c79c6b81bb278b4c7ba79db27ffdec Author: Warner Losh AuthorDate: 2021-12-31 07:46:56 +0000 Commit: Warner Losh CommitDate: 2021-12-31 07:46:56 +0000 hwpmc: deorbit mips support Sponsored by: Netflix --- sys/dev/hwpmc/hwpmc_beri.c | 540 ------------------------- sys/dev/hwpmc/hwpmc_beri.h | 107 ----- sys/dev/hwpmc/hwpmc_mips.c | 809 ------------------------------------- sys/dev/hwpmc/hwpmc_mips24k.c | 230 ----------- sys/dev/hwpmc/hwpmc_mips74k.c | 260 ------------ sys/dev/hwpmc/hwpmc_octeon.c | 197 --------- sys/modules/Makefile | 7 - sys/modules/hwpmc_mips24k/Makefile | 17 - sys/modules/hwpmc_mips74k/Makefile | 17 - 9 files changed, 2184 deletions(-) diff --git a/sys/dev/hwpmc/hwpmc_beri.c b/sys/dev/hwpmc/hwpmc_beri.c deleted file mode 100644 index 4fec1b950299..000000000000 --- a/sys/dev/hwpmc/hwpmc_beri.c +++ /dev/null @@ -1,540 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause - * - * Copyright (c) 2019 Ruslan Bukin - * - * This software was developed by SRI International and the University of - * Cambridge Computer Laboratory (Department of Computer Science and - * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the - * DARPA SSITH research programme. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include "opt_hwpmc_hooks.h" - -#include -#include - -#include - -#define BERI_NCOUNTERS 56 -#define BERI_PMC_CAPS (PMC_CAP_USER | PMC_CAP_SYSTEM | \ - PMC_CAP_READ | PMC_CAP_WRITE ) - -struct beri_event_code_map { - uint32_t pe_ev; /* enum value */ - uint64_t (*get_func)(void); -}; - -const struct beri_event_code_map beri_event_codes[BERI_NCOUNTERS] = { - { PMC_EV_BERI_CYCLE, - statcounters_get_cycle_count }, - { PMC_EV_BERI_INST, - statcounters_get_inst_count }, - { PMC_EV_BERI_INST_USER, - statcounters_get_inst_user_count }, - { PMC_EV_BERI_INST_KERNEL, - statcounters_get_inst_kernel_count }, - { PMC_EV_BERI_IMPRECISE_SETBOUNDS, - statcounters_get_imprecise_setbounds_count }, - { PMC_EV_BERI_UNREPRESENTABLE_CAPS, - statcounters_get_unrepresentable_caps_count }, - { PMC_EV_BERI_ITLB_MISS, - statcounters_get_itlb_miss_count }, - { PMC_EV_BERI_DTLB_MISS, - statcounters_get_dtlb_miss_count }, - { PMC_EV_BERI_ICACHE_WRITE_HIT, - statcounters_get_icache_write_hit_count }, - { PMC_EV_BERI_ICACHE_WRITE_MISS, - statcounters_get_icache_write_miss_count }, - { PMC_EV_BERI_ICACHE_READ_HIT, - statcounters_get_icache_read_hit_count }, - { PMC_EV_BERI_ICACHE_READ_MISS, - statcounters_get_icache_read_miss_count }, - { PMC_EV_BERI_ICACHE_EVICT, - statcounters_get_icache_evict_count }, - { PMC_EV_BERI_DCACHE_WRITE_HIT, - statcounters_get_dcache_write_hit_count }, - { PMC_EV_BERI_DCACHE_WRITE_MISS, - statcounters_get_dcache_write_miss_count }, - { PMC_EV_BERI_DCACHE_READ_HIT, - statcounters_get_dcache_read_hit_count }, - { PMC_EV_BERI_DCACHE_READ_MISS, - statcounters_get_dcache_read_miss_count }, - { PMC_EV_BERI_DCACHE_EVICT, - statcounters_get_dcache_evict_count }, - { PMC_EV_BERI_DCACHE_SET_TAG_WRITE, - statcounters_get_dcache_set_tag_write_count }, - { PMC_EV_BERI_DCACHE_SET_TAG_READ, - statcounters_get_dcache_set_tag_read_count }, - { PMC_EV_BERI_L2CACHE_WRITE_HIT, - statcounters_get_l2cache_write_hit_count }, - { PMC_EV_BERI_L2CACHE_WRITE_MISS, - statcounters_get_l2cache_write_miss_count }, - { PMC_EV_BERI_L2CACHE_READ_HIT, - statcounters_get_l2cache_read_hit_count }, - { PMC_EV_BERI_L2CACHE_READ_MISS, - statcounters_get_l2cache_read_miss_count }, - { PMC_EV_BERI_L2CACHE_EVICT, - statcounters_get_l2cache_evict_count }, - { PMC_EV_BERI_L2CACHE_SET_TAG_WRITE, - statcounters_get_l2cache_set_tag_write_count }, - { PMC_EV_BERI_L2CACHE_SET_TAG_READ, - statcounters_get_l2cache_set_tag_read_count }, - { PMC_EV_BERI_MEM_BYTE_READ, - statcounters_get_mem_byte_read_count }, - { PMC_EV_BERI_MEM_BYTE_WRITE, - statcounters_get_mem_byte_write_count }, - { PMC_EV_BERI_MEM_HWORD_READ, - statcounters_get_mem_hword_read_count }, - { PMC_EV_BERI_MEM_HWORD_WRITE, - statcounters_get_mem_hword_write_count }, - { PMC_EV_BERI_MEM_WORD_READ, - statcounters_get_mem_word_read_count }, - { PMC_EV_BERI_MEM_WORD_WRITE, - statcounters_get_mem_word_write_count }, - { PMC_EV_BERI_MEM_DWORD_READ, - statcounters_get_mem_dword_read_count }, - { PMC_EV_BERI_MEM_DWORD_WRITE, - statcounters_get_mem_dword_write_count }, - { PMC_EV_BERI_MEM_CAP_READ, - statcounters_get_mem_cap_read_count }, - { PMC_EV_BERI_MEM_CAP_WRITE, - statcounters_get_mem_cap_write_count }, - { PMC_EV_BERI_MEM_CAP_READ_TAG_SET, - statcounters_get_mem_cap_read_tag_set_count }, - { PMC_EV_BERI_MEM_CAP_WRITE_TAG_SET, - statcounters_get_mem_cap_write_tag_set_count }, - { PMC_EV_BERI_TAGCACHE_WRITE_HIT, - statcounters_get_tagcache_write_hit_count }, - { PMC_EV_BERI_TAGCACHE_WRITE_MISS, - statcounters_get_tagcache_write_miss_count }, - { PMC_EV_BERI_TAGCACHE_READ_HIT, - statcounters_get_tagcache_read_hit_count }, - { PMC_EV_BERI_TAGCACHE_READ_MISS, - statcounters_get_tagcache_read_miss_count }, - { PMC_EV_BERI_TAGCACHE_EVICT, - statcounters_get_tagcache_evict_count }, - { PMC_EV_BERI_L2CACHEMASTER_READ_REQ, - statcounters_get_l2cachemaster_read_req_count }, - { PMC_EV_BERI_L2CACHEMASTER_WRITE_REQ, - statcounters_get_l2cachemaster_write_req_count }, - { PMC_EV_BERI_L2CACHEMASTER_WRITE_REQ_FLIT, - statcounters_get_l2cachemaster_write_req_flit_count }, - { PMC_EV_BERI_L2CACHEMASTER_READ_RSP, - statcounters_get_l2cachemaster_read_rsp_count }, - { PMC_EV_BERI_L2CACHEMASTER_READ_RSP_FLIT, - statcounters_get_l2cachemaster_read_rsp_flit_count }, - { PMC_EV_BERI_L2CACHEMASTER_WRITE_RSP, - statcounters_get_l2cachemaster_write_rsp_count }, - { PMC_EV_BERI_TAGCACHEMASTER_READ_REQ, - statcounters_get_tagcachemaster_read_req_count }, - { PMC_EV_BERI_TAGCACHEMASTER_WRITE_REQ, - statcounters_get_tagcachemaster_write_req_count }, - { PMC_EV_BERI_TAGCACHEMASTER_WRITE_REQ_FLIT, - statcounters_get_tagcachemaster_write_req_flit_count }, - { PMC_EV_BERI_TAGCACHEMASTER_READ_RSP, - statcounters_get_tagcachemaster_read_rsp_count }, - { PMC_EV_BERI_TAGCACHEMASTER_READ_RSP_FLIT, - statcounters_get_tagcachemaster_read_rsp_flit_count }, - { PMC_EV_BERI_TAGCACHEMASTER_WRITE_RSP, - statcounters_get_tagcachemaster_write_rsp_count }, -}; - -struct mips_pmc_spec beri_pmc_spec = { - .ps_cpuclass = PMC_CLASS_BERI, - .ps_cputype = PMC_CPU_MIPS_BERI, - .ps_capabilities = BERI_PMC_CAPS, - .ps_counter_width = 64 -}; - -/* - * Per-processor information. - */ -struct beri_cpu { - struct pmc_hw *pc_beripmcs; - uint64_t start_values[BERI_NCOUNTERS]; - uint64_t stop_values[BERI_NCOUNTERS]; - uint64_t saved_values[BERI_NCOUNTERS]; -}; - -int beri_npmcs; -static struct beri_cpu **beri_pcpu; - -static int -beri_allocate_pmc(int cpu, int ri, struct pmc *pm, - const struct pmc_op_pmcallocate *a) -{ - uint32_t config; - int i; - - KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), - ("[beri,%d] illegal CPU value %d", __LINE__, cpu)); - KASSERT(ri >= 0 && ri < beri_npmcs, - ("[beri,%d] illegal row index %d", __LINE__, ri)); - - if (a->pm_class != beri_pmc_spec.ps_cpuclass) - return (EINVAL); - - for (i = 0; i < BERI_NCOUNTERS; i++) { - if (beri_event_codes[i].pe_ev == a->pm_ev) { - config = i; - break; - } - } - - if (i == BERI_NCOUNTERS) - return (EINVAL); - - pm->pm_md.pm_mips_evsel = config; - - PMCDBG2(MDP,ALL,2,"beri-allocate ri=%d -> config=0x%x", ri, config); - - return (0); -} - -static int -beri_read_pmc(int cpu, int ri, pmc_value_t *v) -{ - uint32_t config; - struct pmc *pm; - pmc_value_t new; - pmc_value_t start_val; - pmc_value_t stop_val; - pmc_value_t saved_val; - pmc_value_t result; - - KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), - ("[beri,%d] illegal CPU value %d", __LINE__, cpu)); - KASSERT(ri >= 0 && ri < beri_npmcs, - ("[beri,%d] illegal row index %d", __LINE__, ri)); - - pm = beri_pcpu[cpu]->pc_beripmcs[ri].phw_pmc; - config = pm->pm_md.pm_mips_evsel; - - start_val = beri_pcpu[cpu]->start_values[config]; - if (PMC_IS_SYSTEM_MODE(PMC_TO_MODE(pm))) { - stop_val = beri_event_codes[config].get_func(); - } else - stop_val = beri_pcpu[cpu]->stop_values[config]; - - if (start_val <= stop_val) - result = stop_val - start_val; - else { - if (config == 0) /* CYCLE counter is 48 bit */ - result = 0x00ffffffffffffffUL; - else - result = 0xffffffffffffffffUL; - result -= start_val; - result += stop_val; - } - - saved_val = beri_pcpu[cpu]->saved_values[config]; - - *v = result + saved_val; - - return (0); -} - -static int -beri_write_pmc(int cpu, int ri, pmc_value_t v) -{ - struct pmc *pm; - uint32_t config; - - KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), - ("[beri,%d] illegal CPU value %d", __LINE__, cpu)); - KASSERT(ri >= 0 && ri < beri_npmcs, - ("[beri,%d] illegal row-index %d", __LINE__, ri)); - - pm = beri_pcpu[cpu]->pc_beripmcs[ri].phw_pmc; - config = pm->pm_md.pm_mips_evsel; - - if (PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) - v = (1UL << (beri_pmc_spec.ps_counter_width - 1)) - v; - - PMCDBG3(MDP,WRI,1,"beri-write cpu=%d ri=%d v=%jx", cpu, ri, v); - - if (PMC_IS_SYSTEM_MODE(PMC_TO_MODE(pm))) - beri_pcpu[cpu]->saved_values[config] = 0; - else - beri_pcpu[cpu]->saved_values[config] = v; - - return (0); -} - -static int -beri_config_pmc(int cpu, int ri, struct pmc *pm) -{ - struct pmc_hw *phw; - - PMCDBG3(MDP,CFG,1, "cpu=%d ri=%d pm=%p", cpu, ri, pm); - - KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), - ("[beri,%d] illegal CPU value %d", __LINE__, cpu)); - KASSERT(ri >= 0 && ri < beri_npmcs, - ("[beri,%d] illegal row-index %d", __LINE__, ri)); - - phw = &beri_pcpu[cpu]->pc_beripmcs[ri]; - - KASSERT(pm == NULL || phw->phw_pmc == NULL, - ("[beri,%d] pm=%p phw->pm=%p hwpmc not unconfigured", - __LINE__, pm, phw->phw_pmc)); - - phw->phw_pmc = pm; - - return (0); -} - -static int -beri_start_pmc(int cpu, int ri) -{ - uint32_t config; - struct pmc *pm; - struct pmc_hw *phw; - pmc_value_t v; - - phw = &beri_pcpu[cpu]->pc_beripmcs[ri]; - pm = phw->phw_pmc; - config = pm->pm_md.pm_mips_evsel; - - v = beri_event_codes[config].get_func(); - beri_pcpu[cpu]->start_values[config] = v; - - return (0); -} - -static int -beri_stop_pmc(int cpu, int ri) -{ - uint32_t config; - struct pmc *pm; - struct pmc_hw *phw; - pmc_value_t v; - - phw = &beri_pcpu[cpu]->pc_beripmcs[ri]; - pm = phw->phw_pmc; - config = pm->pm_md.pm_mips_evsel; - - v = beri_event_codes[config].get_func(); - beri_pcpu[cpu]->stop_values[config] = v; - - return (0); -} - -static int -beri_release_pmc(int cpu, int ri, struct pmc *pmc) -{ - struct pmc_hw *phw; - - KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), - ("[beri,%d] illegal CPU value %d", __LINE__, cpu)); - KASSERT(ri >= 0 && ri < beri_npmcs, - ("[beri,%d] illegal row-index %d", __LINE__, ri)); - - phw = &beri_pcpu[cpu]->pc_beripmcs[ri]; - KASSERT(phw->phw_pmc == NULL, - ("[beri,%d] PHW pmc %p non-NULL", __LINE__, phw->phw_pmc)); - - return (0); -} - -static int -beri_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc) -{ - struct pmc_hw *phw; - char beri_name[PMC_NAME_MAX]; - int error; - - KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), - ("[beri,%d], illegal CPU %d", __LINE__, cpu)); - KASSERT(ri >= 0 && ri < beri_npmcs, - ("[beri,%d] row-index %d out of range", __LINE__, ri)); - - phw = &beri_pcpu[cpu]->pc_beripmcs[ri]; - snprintf(beri_name, sizeof(beri_name), "MIPS-%d", ri); - if ((error = copystr(beri_name, pi->pm_name, PMC_NAME_MAX, - NULL)) != 0) - return error; - pi->pm_class = beri_pmc_spec.ps_cpuclass; - if (phw->phw_state & PMC_PHW_FLAG_IS_ENABLED) { - pi->pm_enabled = TRUE; - *ppmc = phw->phw_pmc; - } else { - pi->pm_enabled = FALSE; - *ppmc = NULL; - } - - return (0); -} - -static int -beri_get_config(int cpu, int ri, struct pmc **ppm) -{ - - *ppm = beri_pcpu[cpu]->pc_beripmcs[ri].phw_pmc; - - return (0); -} - -static int -beri_pmc_switch_in(struct pmc_cpu *pc, struct pmc_process *pp) -{ - - return (0); -} - -static int -beri_pmc_switch_out(struct pmc_cpu *pc, struct pmc_process *pp) -{ - - return (0); -} - -static int -beri_pcpu_init(struct pmc_mdep *md, int cpu) -{ - int first_ri, i; - struct pmc_cpu *pc; - struct beri_cpu *pac; - struct pmc_hw *phw; - - KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), - ("[beri,%d] wrong cpu number %d", __LINE__, cpu)); - PMCDBG1(MDP,INI,1,"beri-init cpu=%d", cpu); - - beri_pcpu[cpu] = pac = malloc(sizeof(struct beri_cpu), M_PMC, - M_WAITOK|M_ZERO); - pac->pc_beripmcs = malloc(sizeof(struct pmc_hw) * beri_npmcs, - M_PMC, M_WAITOK|M_ZERO); - pc = pmc_pcpu[cpu]; - first_ri = md->pmd_classdep[PMC_MDEP_CLASS_INDEX_MIPS].pcd_ri; - KASSERT(pc != NULL, ("[beri,%d] NULL per-cpu pointer", __LINE__)); - - for (i = 0, phw = pac->pc_beripmcs; i < beri_npmcs; i++, phw++) { - phw->phw_state = PMC_PHW_FLAG_IS_ENABLED | - PMC_PHW_CPU_TO_STATE(cpu) | PMC_PHW_INDEX_TO_STATE(i); - phw->phw_pmc = NULL; - pc->pc_hwpmcs[i + first_ri] = phw; - } - - return (0); -} - -static int -beri_pcpu_fini(struct pmc_mdep *md, int cpu) -{ - - return (0); -} - -struct pmc_mdep * -pmc_beri_initialize() -{ - struct pmc_mdep *pmc_mdep; - struct pmc_classdep *pcd; - - snprintf(pmc_cpuid, sizeof(pmc_cpuid), "beri"); - - beri_npmcs = 2; - - PMCDBG1(MDP,INI,1,"beri-init npmcs=%d", beri_npmcs); - - /* - * Allocate space for pointers to PMC HW descriptors and for - * the MDEP structure used by MI code. - */ - beri_pcpu = malloc(sizeof(struct beri_cpu *) * pmc_cpu_max(), M_PMC, - M_WAITOK|M_ZERO); - - /* Just one class */ - pmc_mdep = pmc_mdep_alloc(1); - - pmc_mdep->pmd_cputype = beri_pmc_spec.ps_cputype; - - pcd = &pmc_mdep->pmd_classdep[PMC_MDEP_CLASS_INDEX_MIPS]; - pcd->pcd_caps = beri_pmc_spec.ps_capabilities; - pcd->pcd_class = beri_pmc_spec.ps_cpuclass; - pcd->pcd_num = beri_npmcs; - pcd->pcd_ri = pmc_mdep->pmd_npmc; - pcd->pcd_width = beri_pmc_spec.ps_counter_width; - - pcd->pcd_allocate_pmc = beri_allocate_pmc; - pcd->pcd_config_pmc = beri_config_pmc; - pcd->pcd_pcpu_fini = beri_pcpu_fini; - pcd->pcd_pcpu_init = beri_pcpu_init; - pcd->pcd_describe = beri_describe; - pcd->pcd_get_config = beri_get_config; - pcd->pcd_read_pmc = beri_read_pmc; - pcd->pcd_release_pmc = beri_release_pmc; - pcd->pcd_start_pmc = beri_start_pmc; - pcd->pcd_stop_pmc = beri_stop_pmc; - pcd->pcd_write_pmc = beri_write_pmc; - - pmc_mdep->pmd_intr = NULL; - pmc_mdep->pmd_switch_in = beri_pmc_switch_in; - pmc_mdep->pmd_switch_out = beri_pmc_switch_out; - - pmc_mdep->pmd_npmc += beri_npmcs; - - return (pmc_mdep); -} - -void -pmc_beri_finalize(struct pmc_mdep *md) -{ - -} - -struct pmc_mdep * -pmc_md_initialize() -{ - - return (pmc_beri_initialize()); -} - -void -pmc_md_finalize(struct pmc_mdep *md) -{ - - return (pmc_beri_finalize(md)); -} - -int -pmc_save_kernel_callchain(uintptr_t *cc, int nframes, - struct trapframe *tf) -{ - - return (0); -} - -int -pmc_save_user_callchain(uintptr_t *cc, int nframes, - struct trapframe *tf) -{ - - return (0); -} diff --git a/sys/dev/hwpmc/hwpmc_beri.h b/sys/dev/hwpmc/hwpmc_beri.h deleted file mode 100644 index 8f9aa48c7bae..000000000000 --- a/sys/dev/hwpmc/hwpmc_beri.h +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause - * - * Copyright (c) 2019 Alex Richardson - * - * This software was developed by SRI International and the University of - * Cambridge Computer Laboratory (Department of Computer Science and - * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the - * DARPA SSITH research programme. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef _DEV_HWPMC_HWPMC_BERI_H_ -#define _DEV_HWPMC_HWPMC_BERI_H_ - -#define STATCOUNTER_ITEM(name, X, Y) \ -static inline uint64_t statcounters_get_##name##_count(void) \ -{ \ - uint64_t ret; \ - __asm __volatile( \ - ".word (0x1f << 26) | (0x0 << 21) | \ - (12 << 16) | ("#X" << 11) | \ - ( "#Y" << 6) | 0x3b\n\t" \ - "move %0,$12" : "=r" (ret) :: "$12"); \ - return (ret); \ -} - -STATCOUNTER_ITEM(cycle,2,0) -STATCOUNTER_ITEM(inst,4,0) -STATCOUNTER_ITEM(inst_user,4,1) -STATCOUNTER_ITEM(inst_kernel,4,2) -STATCOUNTER_ITEM(imprecise_setbounds,4,3) -STATCOUNTER_ITEM(unrepresentable_caps,4,4) -STATCOUNTER_ITEM(itlb_miss,5,0) -STATCOUNTER_ITEM(dtlb_miss,6,0) -STATCOUNTER_ITEM(icache_write_hit,8,0) -STATCOUNTER_ITEM(icache_write_miss,8,1) -STATCOUNTER_ITEM(icache_read_hit,8,2) -STATCOUNTER_ITEM(icache_read_miss,8,3) -STATCOUNTER_ITEM(icache_evict,8,6) -STATCOUNTER_ITEM(dcache_write_hit,9,0) -STATCOUNTER_ITEM(dcache_write_miss,9,1) -STATCOUNTER_ITEM(dcache_read_hit,9,2) -STATCOUNTER_ITEM(dcache_read_miss,9,3) -STATCOUNTER_ITEM(dcache_evict,9,6) -STATCOUNTER_ITEM(dcache_set_tag_write,9,8) -STATCOUNTER_ITEM(dcache_set_tag_read,9,9) -STATCOUNTER_ITEM(l2cache_write_hit,10,0) -STATCOUNTER_ITEM(l2cache_write_miss,10,1) -STATCOUNTER_ITEM(l2cache_read_hit,10,2) -STATCOUNTER_ITEM(l2cache_read_miss,10,3) -STATCOUNTER_ITEM(l2cache_evict,10,6) -STATCOUNTER_ITEM(l2cache_set_tag_write,10,8) -STATCOUNTER_ITEM(l2cache_set_tag_read,10,9) -STATCOUNTER_ITEM(mem_byte_read,11,0) -STATCOUNTER_ITEM(mem_byte_write,11,1) -STATCOUNTER_ITEM(mem_hword_read,11,2) -STATCOUNTER_ITEM(mem_hword_write,11,3) -STATCOUNTER_ITEM(mem_word_read,11,4) -STATCOUNTER_ITEM(mem_word_write,11,5) -STATCOUNTER_ITEM(mem_dword_read,11,6) -STATCOUNTER_ITEM(mem_dword_write,11,7) -STATCOUNTER_ITEM(mem_cap_read,11,8) -STATCOUNTER_ITEM(mem_cap_write,11,9) -STATCOUNTER_ITEM(mem_cap_read_tag_set,11,10) -STATCOUNTER_ITEM(mem_cap_write_tag_set,11,11) -STATCOUNTER_ITEM(tagcache_write_hit,12,0) -STATCOUNTER_ITEM(tagcache_write_miss,12,1) -STATCOUNTER_ITEM(tagcache_read_hit,12,2) -STATCOUNTER_ITEM(tagcache_read_miss,12,3) -STATCOUNTER_ITEM(tagcache_evict,12,6) -STATCOUNTER_ITEM(l2cachemaster_read_req,13,0) -STATCOUNTER_ITEM(l2cachemaster_write_req,13,1) -STATCOUNTER_ITEM(l2cachemaster_write_req_flit,13,2) -STATCOUNTER_ITEM(l2cachemaster_read_rsp,13,3) -STATCOUNTER_ITEM(l2cachemaster_read_rsp_flit,13,4) -STATCOUNTER_ITEM(l2cachemaster_write_rsp,13,5) -STATCOUNTER_ITEM(tagcachemaster_read_req,14,0) -STATCOUNTER_ITEM(tagcachemaster_write_req,14,1) -STATCOUNTER_ITEM(tagcachemaster_write_req_flit,14,2) -STATCOUNTER_ITEM(tagcachemaster_read_rsp,14,3) -STATCOUNTER_ITEM(tagcachemaster_read_rsp_flit,14,4) -STATCOUNTER_ITEM(tagcachemaster_write_rsp,14,5) - -#endif /* !_DEV_HWPMC_HWPMC_BERI_H_ */ diff --git a/sys/dev/hwpmc/hwpmc_mips.c b/sys/dev/hwpmc/hwpmc_mips.c deleted file mode 100644 index edf83154dc57..000000000000 --- a/sys/dev/hwpmc/hwpmc_mips.c +++ /dev/null @@ -1,809 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD - * - * Copyright (c) 2010, George V. Neville-Neil - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ - -#include -__FBSDID("$FreeBSD$"); - -#include "opt_hwpmc_hooks.h" - -#include -#include -#include -#include - -#include -#include -#include -#include - -int mips_npmcs; - -/* - * Per-processor information. - */ -struct mips_cpu { - struct pmc_hw *pc_mipspmcs; -}; - -static struct mips_cpu **mips_pcpu; - -#if defined(__mips_n64) -# define MIPS_IS_VALID_KERNELADDR(reg) ((((reg) & 3) == 0) && \ - ((vm_offset_t)(reg) >= MIPS_XKPHYS_START)) -#else -# define MIPS_IS_VALID_KERNELADDR(reg) ((((reg) & 3) == 0) && \ - ((vm_offset_t)(reg) >= MIPS_KSEG0_START)) -#endif - -/* - * We need some reasonable default to prevent backtrace code - * from wandering too far - */ -#define MAX_FUNCTION_SIZE 0x10000 -#define MAX_PROLOGUE_SIZE 0x100 - -static int -mips_allocate_pmc(int cpu, int ri, struct pmc *pm, - const struct pmc_op_pmcallocate *a) -{ - enum pmc_event pe; - uint32_t caps, config, counter; - uint32_t event; - int i; - - KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), - ("[mips,%d] illegal CPU value %d", __LINE__, cpu)); - KASSERT(ri >= 0 && ri < mips_npmcs, - ("[mips,%d] illegal row index %d", __LINE__, ri)); - - caps = a->pm_caps; - if (a->pm_class != mips_pmc_spec.ps_cpuclass) - return (EINVAL); - pe = a->pm_ev; - counter = MIPS_CTR_ALL; - event = 0; - for (i = 0; i < mips_event_codes_size; i++) { - if (mips_event_codes[i].pe_ev == pe) { - event = mips_event_codes[i].pe_code; - counter = mips_event_codes[i].pe_counter; - break; - } - } - - if (i == mips_event_codes_size) - return (EINVAL); - - if ((counter != MIPS_CTR_ALL) && (counter != ri)) - return (EINVAL); - - config = mips_get_perfctl(cpu, ri, event, caps); - - pm->pm_md.pm_mips_evsel = config; - - PMCDBG2(MDP,ALL,2,"mips-allocate ri=%d -> config=0x%x", ri, config); - - return 0; -} - - -static int -mips_read_pmc(int cpu, int ri, pmc_value_t *v) -{ - struct pmc *pm; - pmc_value_t tmp; - - KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), - ("[mips,%d] illegal CPU value %d", __LINE__, cpu)); - KASSERT(ri >= 0 && ri < mips_npmcs, - ("[mips,%d] illegal row index %d", __LINE__, ri)); - - pm = mips_pcpu[cpu]->pc_mipspmcs[ri].phw_pmc; - tmp = mips_pmcn_read(ri); - PMCDBG2(MDP,REA,2,"mips-read id=%d -> %jd", ri, tmp); - - if (PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) - *v = tmp - (1UL << (mips_pmc_spec.ps_counter_width - 1)); - else - *v = tmp; - - return 0; -} - -static int -mips_write_pmc(int cpu, int ri, pmc_value_t v) -{ - struct pmc *pm; - - KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), - ("[mips,%d] illegal CPU value %d", __LINE__, cpu)); - KASSERT(ri >= 0 && ri < mips_npmcs, - ("[mips,%d] illegal row-index %d", __LINE__, ri)); - - pm = mips_pcpu[cpu]->pc_mipspmcs[ri].phw_pmc; - - if (PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) - v = (1UL << (mips_pmc_spec.ps_counter_width - 1)) - v; - - PMCDBG3(MDP,WRI,1,"mips-write cpu=%d ri=%d v=%jx", cpu, ri, v); - - mips_pmcn_write(ri, v); - - return 0; -} - -static int -mips_config_pmc(int cpu, int ri, struct pmc *pm) -{ - struct pmc_hw *phw; - - PMCDBG3(MDP,CFG,1, "cpu=%d ri=%d pm=%p", cpu, ri, pm); - - KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), - ("[mips,%d] illegal CPU value %d", __LINE__, cpu)); - KASSERT(ri >= 0 && ri < mips_npmcs, - ("[mips,%d] illegal row-index %d", __LINE__, ri)); - - phw = &mips_pcpu[cpu]->pc_mipspmcs[ri]; - - KASSERT(pm == NULL || phw->phw_pmc == NULL, - ("[mips,%d] pm=%p phw->pm=%p hwpmc not unconfigured", - __LINE__, pm, phw->phw_pmc)); - - phw->phw_pmc = pm; - - return 0; -} - -static int -mips_start_pmc(int cpu, int ri) -{ - uint32_t config; - struct pmc *pm; - struct pmc_hw *phw; - - phw = &mips_pcpu[cpu]->pc_mipspmcs[ri]; - pm = phw->phw_pmc; - config = pm->pm_md.pm_mips_evsel; - - /* Enable the PMC. */ - switch (ri) { - case 0: - mips_wr_perfcnt0(config); - break; - case 1: - mips_wr_perfcnt2(config); - break; - default: - break; - } - - return 0; -} - -static int -mips_stop_pmc(int cpu, int ri) -{ - struct pmc *pm; - struct pmc_hw *phw; - - phw = &mips_pcpu[cpu]->pc_mipspmcs[ri]; - pm = phw->phw_pmc; - - /* - * Disable the PMCs. - * - * Clearing the entire register turns the counter off as well - * as removes the previously sampled event. - */ - switch (ri) { - case 0: - mips_wr_perfcnt0(0); - break; - case 1: - mips_wr_perfcnt2(0); - break; - default: - break; - } - return 0; -} - -static int -mips_release_pmc(int cpu, int ri, struct pmc *pmc) -{ - struct pmc_hw *phw; - - KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), - ("[mips,%d] illegal CPU value %d", __LINE__, cpu)); - KASSERT(ri >= 0 && ri < mips_npmcs, - ("[mips,%d] illegal row-index %d", __LINE__, ri)); - - phw = &mips_pcpu[cpu]->pc_mipspmcs[ri]; - KASSERT(phw->phw_pmc == NULL, - ("[mips,%d] PHW pmc %p non-NULL", __LINE__, phw->phw_pmc)); - - return 0; -} - -static int -mips_pmc_intr(struct trapframe *tf) -{ - int error; - int retval, ri, cpu; - struct pmc *pm; - struct mips_cpu *pc; - uint32_t r0, r2; - pmc_value_t r; - - cpu = curcpu; - KASSERT(cpu >= 0 && cpu < pmc_cpu_max(), - ("[mips,%d] CPU %d out of range", __LINE__, cpu)); - - retval = 0; - pc = mips_pcpu[cpu]; - - /* Stop PMCs without clearing the counter */ - r0 = mips_rd_perfcnt0(); - mips_wr_perfcnt0(r0 & ~(0x1f)); - r2 = mips_rd_perfcnt2(); - mips_wr_perfcnt2(r2 & ~(0x1f)); - - for (ri = 0; ri < mips_npmcs; ri++) { - pm = mips_pcpu[cpu]->pc_mipspmcs[ri].phw_pmc; - if (pm == NULL) - continue; - if (! PMC_IS_SAMPLING_MODE(PMC_TO_MODE(pm))) - continue; - - r = mips_pmcn_read(ri); - - /* If bit 31 is set, the counter has overflowed */ - if ((r & (1UL << (mips_pmc_spec.ps_counter_width - 1))) == 0) - continue; - - retval = 1; - if (pm->pm_state != PMC_STATE_RUNNING) - continue; - error = pmc_process_interrupt(PMC_HR, pm, tf); - if (error) { - /* Clear/disable the relevant counter */ - if (ri == 0) - r0 = 0; *** 1288 LINES SKIPPED ***