Delete stale files post their move to "sys/dev/hwpmc/".
This commit is contained in:
parent
a550fb9304
commit
4a60353a84
@ -1,995 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2003-2005 Joseph Koshy
|
||||
* 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 <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/* Support for the AMD K7 and later processors */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/pmc.h>
|
||||
#include <sys/smp.h>
|
||||
#include <sys/systm.h>
|
||||
|
||||
#include <machine/md_var.h>
|
||||
|
||||
/* AMD K7 and K8 PMCs */
|
||||
|
||||
#define AMD_PMC_EVSEL_0 0xC0010000
|
||||
#define AMD_PMC_EVSEL_1 0xC0010001
|
||||
#define AMD_PMC_EVSEL_2 0xC0010002
|
||||
#define AMD_PMC_EVSEL_3 0xC0010003
|
||||
|
||||
#define AMD_PMC_PERFCTR_0 0xC0010004
|
||||
#define AMD_PMC_PERFCTR_1 0xC0010005
|
||||
#define AMD_PMC_PERFCTR_2 0xC0010006
|
||||
#define AMD_PMC_PERFCTR_3 0xC0010007
|
||||
|
||||
#define K7_VALID_EVENT_CODE(c) (((c) >= 0x40 && (c) <= 0x47) || \
|
||||
((c) >= 0x80 && (c) <= 0x85) || ((c) >= 0xC0 && (c) <= 0xC7) || \
|
||||
((c) >= 0xCD && (c) <= 0xCF))
|
||||
|
||||
#define AMD_PMC_CAPS (PMC_CAP_INTERRUPT | PMC_CAP_USER | \
|
||||
PMC_CAP_SYSTEM | PMC_CAP_EDGE | PMC_CAP_THRESHOLD | \
|
||||
PMC_CAP_READ | PMC_CAP_WRITE | PMC_CAP_INVERT | PMC_CAP_QUALIFIER)
|
||||
|
||||
/* reserved bits include bit 21 and the top two bits of the unit mask */
|
||||
#define K7_PMC_RESERVED ((1 << 21) | (3 << 13))
|
||||
|
||||
#define K8_PMC_RESERVED (1 << 21)
|
||||
|
||||
#define AMD_PMC_IS_STOPPED(evsel) ((rdmsr((evsel)) & AMD_PMC_ENABLE) == 0)
|
||||
#define AMD_PMC_HAS_OVERFLOWED(pmc) ((rdpmc(pmc) & (1ULL << 47)) == 0)
|
||||
|
||||
#if __i386__
|
||||
#define AMD_NPMCS K7_NPMCS
|
||||
#define AMD_PMC_CLASS PMC_CLASS_K7
|
||||
#define AMD_PMC_COUNTERMASK K7_PMC_COUNTERMASK
|
||||
#define AMD_PMC_TO_COUNTER(x) K7_PMC_TO_COUNTER(x)
|
||||
#define AMD_PMC_INVERT K7_PMC_INVERT
|
||||
#define AMD_PMC_ENABLE K7_PMC_ENABLE
|
||||
#define AMD_PMC_INT K7_PMC_INT
|
||||
#define AMD_PMC_PC K7_PMC_PC
|
||||
#define AMD_PMC_EDGE K7_PMC_EDGE
|
||||
#define AMD_PMC_OS K7_PMC_OS
|
||||
#define AMD_PMC_USR K7_PMC_USR
|
||||
|
||||
#define AMD_PMC_UNITMASK_M K7_PMC_UNITMASK_M
|
||||
#define AMD_PMC_UNITMASK_O K7_PMC_UNITMASK_O
|
||||
#define AMD_PMC_UNITMASK_E K7_PMC_UNITMASK_E
|
||||
#define AMD_PMC_UNITMASK_S K7_PMC_UNITMASK_S
|
||||
#define AMD_PMC_UNITMASK_I K7_PMC_UNITMASK_I
|
||||
|
||||
#define AMD_PMC_UNITMASK K7_PMC_UNITMASK
|
||||
#define AMD_PMC_EVENTMASK K7_PMC_EVENTMASK
|
||||
#define AMD_PMC_TO_UNITMASK(x) K7_PMC_TO_UNITMASK(x)
|
||||
#define AMD_PMC_TO_EVENTMASK(x) K7_PMC_TO_EVENTMASK(x)
|
||||
#define AMD_VALID_BITS K7_VALID_BITS
|
||||
|
||||
#define AMD_PMC_CLASS_NAME "K7-"
|
||||
|
||||
#elif __amd64__
|
||||
|
||||
#define AMD_NPMCS K8_NPMCS
|
||||
#define AMD_PMC_CLASS PMC_CLASS_K8
|
||||
#define AMD_PMC_COUNTERMASK K8_PMC_COUNTERMASK
|
||||
#define AMD_PMC_TO_COUNTER(x) K8_PMC_TO_COUNTER(x)
|
||||
#define AMD_PMC_INVERT K8_PMC_INVERT
|
||||
#define AMD_PMC_ENABLE K8_PMC_ENABLE
|
||||
#define AMD_PMC_INT K8_PMC_INT
|
||||
#define AMD_PMC_PC K8_PMC_PC
|
||||
#define AMD_PMC_EDGE K8_PMC_EDGE
|
||||
#define AMD_PMC_OS K8_PMC_OS
|
||||
#define AMD_PMC_USR K8_PMC_USR
|
||||
|
||||
#define AMD_PMC_UNITMASK_M K8_PMC_UNITMASK_M
|
||||
#define AMD_PMC_UNITMASK_O K8_PMC_UNITMASK_O
|
||||
#define AMD_PMC_UNITMASK_E K8_PMC_UNITMASK_E
|
||||
#define AMD_PMC_UNITMASK_S K8_PMC_UNITMASK_S
|
||||
#define AMD_PMC_UNITMASK_I K8_PMC_UNITMASK_I
|
||||
|
||||
#define AMD_PMC_UNITMASK K8_PMC_UNITMASK
|
||||
#define AMD_PMC_EVENTMASK K8_PMC_EVENTMASK
|
||||
#define AMD_PMC_TO_UNITMASK(x) K8_PMC_TO_UNITMASK(x)
|
||||
#define AMD_PMC_TO_EVENTMASK(x) K8_PMC_TO_EVENTMASK(x)
|
||||
#define AMD_VALID_BITS K8_VALID_BITS
|
||||
|
||||
#define AMD_PMC_CLASS_NAME "K8-"
|
||||
|
||||
#else
|
||||
#error Unsupported architecture.
|
||||
#endif
|
||||
|
||||
/* AMD K7 & K8 PMCs */
|
||||
struct amd_descr {
|
||||
struct pmc_descr pm_descr; /* "base class" */
|
||||
uint32_t pm_evsel; /* address of EVSEL register */
|
||||
uint32_t pm_perfctr; /* address of PERFCTR register */
|
||||
};
|
||||
|
||||
static const struct amd_descr amd_pmcdesc[AMD_NPMCS] =
|
||||
{
|
||||
{
|
||||
.pm_descr =
|
||||
{
|
||||
.pd_name = "TSC",
|
||||
.pd_class = PMC_CLASS_TSC,
|
||||
.pd_caps = PMC_CAP_READ,
|
||||
.pd_width = 64
|
||||
},
|
||||
.pm_evsel = MSR_TSC,
|
||||
.pm_perfctr = 0 /* unused */
|
||||
},
|
||||
|
||||
{
|
||||
.pm_descr =
|
||||
{
|
||||
.pd_name = AMD_PMC_CLASS_NAME "0",
|
||||
.pd_class = AMD_PMC_CLASS,
|
||||
.pd_caps = AMD_PMC_CAPS,
|
||||
.pd_width = 48
|
||||
},
|
||||
.pm_evsel = AMD_PMC_EVSEL_0,
|
||||
.pm_perfctr = AMD_PMC_PERFCTR_0
|
||||
},
|
||||
{
|
||||
.pm_descr =
|
||||
{
|
||||
.pd_name = AMD_PMC_CLASS_NAME "1",
|
||||
.pd_class = AMD_PMC_CLASS,
|
||||
.pd_caps = AMD_PMC_CAPS,
|
||||
.pd_width = 48
|
||||
},
|
||||
.pm_evsel = AMD_PMC_EVSEL_1,
|
||||
.pm_perfctr = AMD_PMC_PERFCTR_1
|
||||
},
|
||||
{
|
||||
.pm_descr =
|
||||
{
|
||||
.pd_name = AMD_PMC_CLASS_NAME "2",
|
||||
.pd_class = AMD_PMC_CLASS,
|
||||
.pd_caps = AMD_PMC_CAPS,
|
||||
.pd_width = 48
|
||||
},
|
||||
.pm_evsel = AMD_PMC_EVSEL_2,
|
||||
.pm_perfctr = AMD_PMC_PERFCTR_2
|
||||
},
|
||||
{
|
||||
.pm_descr =
|
||||
{
|
||||
.pd_name = AMD_PMC_CLASS_NAME "3",
|
||||
.pd_class = AMD_PMC_CLASS,
|
||||
.pd_caps = AMD_PMC_CAPS,
|
||||
.pd_width = 48
|
||||
},
|
||||
.pm_evsel = AMD_PMC_EVSEL_3,
|
||||
.pm_perfctr = AMD_PMC_PERFCTR_3
|
||||
}
|
||||
};
|
||||
|
||||
struct amd_event_code_map {
|
||||
enum pmc_event pe_ev; /* enum value */
|
||||
uint8_t pe_code; /* encoded event mask */
|
||||
uint8_t pe_mask; /* bits allowed in unit mask */
|
||||
};
|
||||
|
||||
const struct amd_event_code_map amd_event_codes[] = {
|
||||
#if __i386__
|
||||
{ PMC_EV_K7_DC_ACCESSES, 0x40, 0 },
|
||||
{ PMC_EV_K7_DC_MISSES, 0x41, 0 },
|
||||
{ PMC_EV_K7_DC_REFILLS_FROM_L2, 0x42, K7_PMC_UNITMASK_MOESI },
|
||||
{ PMC_EV_K7_DC_REFILLS_FROM_SYSTEM, 0x43, K7_PMC_UNITMASK_MOESI },
|
||||
{ PMC_EV_K7_DC_WRITEBACKS, 0x44, K7_PMC_UNITMASK_MOESI },
|
||||
{ PMC_EV_K7_L1_DTLB_MISS_AND_L2_DTLB_HITS, 0x45, 0 },
|
||||
{ PMC_EV_K7_L1_AND_L2_DTLB_MISSES, 0x46, 0 },
|
||||
{ PMC_EV_K7_MISALIGNED_REFERENCES, 0x47, 0 },
|
||||
|
||||
{ PMC_EV_K7_IC_FETCHES, 0x80, 0 },
|
||||
{ PMC_EV_K7_IC_MISSES, 0x81, 0 },
|
||||
|
||||
{ PMC_EV_K7_L1_ITLB_MISSES, 0x84, 0 },
|
||||
{ PMC_EV_K7_L1_L2_ITLB_MISSES, 0x85, 0 },
|
||||
|
||||
{ PMC_EV_K7_RETIRED_INSTRUCTIONS, 0xC0, 0 },
|
||||
{ PMC_EV_K7_RETIRED_OPS, 0xC1, 0 },
|
||||
{ PMC_EV_K7_RETIRED_BRANCHES, 0xC2, 0 },
|
||||
{ PMC_EV_K7_RETIRED_BRANCHES_MISPREDICTED, 0xC3, 0 },
|
||||
{ PMC_EV_K7_RETIRED_TAKEN_BRANCHES, 0xC4, 0 },
|
||||
{ PMC_EV_K7_RETIRED_TAKEN_BRANCHES_MISPREDICTED, 0xC5, 0 },
|
||||
{ PMC_EV_K7_RETIRED_FAR_CONTROL_TRANSFERS, 0xC6, 0 },
|
||||
{ PMC_EV_K7_RETIRED_RESYNC_BRANCHES, 0xC7, 0 },
|
||||
{ PMC_EV_K7_INTERRUPTS_MASKED_CYCLES, 0xCD, 0 },
|
||||
{ PMC_EV_K7_INTERRUPTS_MASKED_WHILE_PENDING_CYCLES, 0xCE, 0 },
|
||||
{ PMC_EV_K7_HARDWARE_INTERRUPTS, 0xCF, 0 }
|
||||
#endif
|
||||
|
||||
#if __amd64__
|
||||
{ PMC_EV_K8_FP_DISPATCHED_FPU_OPS, 0x00, 0x3F },
|
||||
{ PMC_EV_K8_FP_CYCLES_WITH_NO_FPU_OPS_RETIRED, 0x01, 0x00 },
|
||||
{ PMC_EV_K8_FP_DISPATCHED_FPU_FAST_FLAG_OPS, 0x02, 0x00 },
|
||||
|
||||
{ PMC_EV_K8_LS_SEGMENT_REGISTER_LOAD, 0x20, 0x7F },
|
||||
{ PMC_EV_K8_LS_MICROARCHITECTURAL_RESYNC_BY_SELF_MODIFYING_CODE,
|
||||
0x21, 0x00 },
|
||||
{ PMC_EV_K8_LS_MICROARCHITECTURAL_RESYNC_BY_SNOOP, 0x22, 0x00 },
|
||||
{ PMC_EV_K8_LS_BUFFER2_FULL, 0x23, 0x00 },
|
||||
{ PMC_EV_K8_LS_LOCKED_OPERATION, 0x24, 0x07 },
|
||||
{ PMC_EV_K8_LS_MICROARCHITECTURAL_LATE_CANCEL, 0x25, 0x00 },
|
||||
{ PMC_EV_K8_LS_RETIRED_CFLUSH_INSTRUCTIONS, 0x26, 0x00 },
|
||||
{ PMC_EV_K8_LS_RETIRED_CPUID_INSTRUCTIONS, 0x27, 0x00 },
|
||||
|
||||
{ PMC_EV_K8_DC_ACCESS, 0x40, 0x00 },
|
||||
{ PMC_EV_K8_DC_MISS, 0x41, 0x00 },
|
||||
{ PMC_EV_K8_DC_REFILL_FROM_L2, 0x42, 0x1F },
|
||||
{ PMC_EV_K8_DC_REFILL_FROM_SYSTEM, 0x43, 0x1F },
|
||||
{ PMC_EV_K8_DC_COPYBACK, 0x44, 0x1F },
|
||||
{ PMC_EV_K8_DC_L1_DTLB_MISS_AND_L2_DTLB_HIT, 0x45, 0x00 },
|
||||
{ PMC_EV_K8_DC_L1_DTLB_MISS_AND_L2_DTLB_MISS, 0x46, 0x00 },
|
||||
{ PMC_EV_K8_DC_MISALIGNED_DATA_REFERENCE, 0x47, 0x00 },
|
||||
{ PMC_EV_K8_DC_MICROARCHITECTURAL_LATE_CANCEL, 0x48, 0x00 },
|
||||
{ PMC_EV_K8_DC_MICROARCHITECTURAL_EARLY_CANCEL, 0x49, 0x00 },
|
||||
{ PMC_EV_K8_DC_ONE_BIT_ECC_ERROR, 0x4A, 0x03 },
|
||||
{ PMC_EV_K8_DC_DISPATCHED_PREFETCH_INSTRUCTIONS, 0x4B, 0x07 },
|
||||
{ PMC_EV_K8_DC_DCACHE_ACCESSES_BY_LOCKS, 0x4C, 0x03 },
|
||||
|
||||
{ PMC_EV_K8_BU_CPU_CLK_UNHALTED, 0x76, 0x00 },
|
||||
{ PMC_EV_K8_BU_INTERNAL_L2_REQUEST, 0x7D, 0x1F },
|
||||
{ PMC_EV_K8_BU_FILL_REQUEST_L2_MISS, 0x7E, 0x07 },
|
||||
{ PMC_EV_K8_BU_FILL_INTO_L2, 0x7F, 0x03 },
|
||||
|
||||
{ PMC_EV_K8_IC_FETCH, 0x80, 0x00 },
|
||||
{ PMC_EV_K8_IC_MISS, 0x81, 0x00 },
|
||||
{ PMC_EV_K8_IC_REFILL_FROM_L2, 0x82, 0x00 },
|
||||
{ PMC_EV_K8_IC_REFILL_FROM_SYSTEM, 0x83, 0x00 },
|
||||
{ PMC_EV_K8_IC_L1_ITLB_MISS_AND_L2_ITLB_HIT, 0x84, 0x00 },
|
||||
{ PMC_EV_K8_IC_L1_ITLB_MISS_AND_L2_ITLB_MISS, 0x85, 0x00 },
|
||||
{ PMC_EV_K8_IC_MICROARCHITECTURAL_RESYNC_BY_SNOOP, 0x86, 0x00 },
|
||||
{ PMC_EV_K8_IC_INSTRUCTION_FETCH_STALL, 0x87, 0x00 },
|
||||
{ PMC_EV_K8_IC_RETURN_STACK_HIT, 0x88, 0x00 },
|
||||
{ PMC_EV_K8_IC_RETURN_STACK_OVERFLOW, 0x89, 0x00 },
|
||||
|
||||
{ PMC_EV_K8_FR_RETIRED_X86_INSTRUCTIONS, 0xC0, 0x00 },
|
||||
{ PMC_EV_K8_FR_RETIRED_UOPS, 0xC1, 0x00 },
|
||||
{ PMC_EV_K8_FR_RETIRED_BRANCHES, 0xC2, 0x00 },
|
||||
{ PMC_EV_K8_FR_RETIRED_BRANCHES_MISPREDICTED, 0xC3, 0x00 },
|
||||
{ PMC_EV_K8_FR_RETIRED_TAKEN_BRANCHES, 0xC4, 0x00 },
|
||||
{ PMC_EV_K8_FR_RETIRED_TAKEN_BRANCHES_MISPREDICTED, 0xC5, 0x00 },
|
||||
{ PMC_EV_K8_FR_RETIRED_FAR_CONTROL_TRANSFERS, 0xC6, 0x00 },
|
||||
{ PMC_EV_K8_FR_RETIRED_RESYNCS, 0xC7, 0x00 },
|
||||
{ PMC_EV_K8_FR_RETIRED_NEAR_RETURNS, 0xC8, 0x00 },
|
||||
{ PMC_EV_K8_FR_RETIRED_NEAR_RETURNS_MISPREDICTED, 0xC9, 0x00 },
|
||||
{ PMC_EV_K8_FR_RETIRED_TAKEN_BRANCHES_MISPREDICTED_BY_ADDR_MISCOMPARE,
|
||||
0xCA, 0x00 },
|
||||
{ PMC_EV_K8_FR_RETIRED_FPU_INSTRUCTIONS, 0xCB, 0x0F },
|
||||
{ PMC_EV_K8_FR_RETIRED_FASTPATH_DOUBLE_OP_INSTRUCTIONS,
|
||||
0xCC, 0x07 },
|
||||
{ PMC_EV_K8_FR_INTERRUPTS_MASKED_CYCLES, 0xCD, 0x00 },
|
||||
{ PMC_EV_K8_FR_INTERRUPTS_MASKED_WHILE_PENDING_CYCLES, 0xCE, 0x00 },
|
||||
{ PMC_EV_K8_FR_TAKEN_HARDWARE_INTERRUPTS, 0xCF, 0x00 },
|
||||
|
||||
{ PMC_EV_K8_FR_DECODER_EMPTY, 0xD0, 0x00 },
|
||||
{ PMC_EV_K8_FR_DISPATCH_STALLS, 0xD1, 0x00 },
|
||||
{ PMC_EV_K8_FR_DISPATCH_STALL_FROM_BRANCH_ABORT_TO_RETIRE,
|
||||
0xD2, 0x00 },
|
||||
{ PMC_EV_K8_FR_DISPATCH_STALL_FOR_SERIALIZATION, 0xD3, 0x00 },
|
||||
{ PMC_EV_K8_FR_DISPATCH_STALL_FOR_SEGMENT_LOAD, 0xD4, 0x00 },
|
||||
{ PMC_EV_K8_FR_DISPATCH_STALL_WHEN_REORDER_BUFFER_IS_FULL,
|
||||
0xD5, 0x00 },
|
||||
{ PMC_EV_K8_FR_DISPATCH_STALL_WHEN_RESERVATION_STATIONS_ARE_FULL,
|
||||
0xD6, 0x00 },
|
||||
{ PMC_EV_K8_FR_DISPATCH_STALL_WHEN_FPU_IS_FULL, 0xD7, 0x00 },
|
||||
{ PMC_EV_K8_FR_DISPATCH_STALL_WHEN_LS_IS_FULL, 0xD8, 0x00 },
|
||||
{ PMC_EV_K8_FR_DISPATCH_STALL_WHEN_WAITING_FOR_ALL_TO_BE_QUIET,
|
||||
0xD9, 0x00 },
|
||||
{ PMC_EV_K8_FR_DISPATCH_STALL_WHEN_FAR_XFER_OR_RESYNC_BRANCH_PENDING,
|
||||
0xDA, 0x00 },
|
||||
{ PMC_EV_K8_FR_FPU_EXCEPTIONS, 0xDB, 0x0F },
|
||||
{ PMC_EV_K8_FR_NUMBER_OF_BREAKPOINTS_FOR_DR0, 0xDC, 0x00 },
|
||||
{ PMC_EV_K8_FR_NUMBER_OF_BREAKPOINTS_FOR_DR1, 0xDD, 0x00 },
|
||||
{ PMC_EV_K8_FR_NUMBER_OF_BREAKPOINTS_FOR_DR2, 0xDE, 0x00 },
|
||||
{ PMC_EV_K8_FR_NUMBER_OF_BREAKPOINTS_FOR_DR3, 0xDF, 0x00 },
|
||||
|
||||
{ PMC_EV_K8_NB_MEMORY_CONTROLLER_PAGE_ACCESS_EVENT, 0xE0, 0x7 },
|
||||
{ PMC_EV_K8_NB_MEMORY_CONTROLLER_PAGE_TABLE_OVERFLOW, 0xE1, 0x00 },
|
||||
{ PMC_EV_K8_NB_MEMORY_CONTROLLER_DRAM_COMMAND_SLOTS_MISSED,
|
||||
0xE2, 0x00 },
|
||||
{ PMC_EV_K8_NB_MEMORY_CONTROLLER_TURNAROUND, 0xE3, 0x07 },
|
||||
{ PMC_EV_K8_NB_MEMORY_CONTROLLER_BYPASS_SATURATION, 0xE4, 0x0F },
|
||||
{ PMC_EV_K8_NB_SIZED_COMMANDS, 0xEB, 0x7F },
|
||||
{ PMC_EV_K8_NB_PROBE_RESULT, 0xEC, 0x0F },
|
||||
{ PMC_EV_K8_NB_HT_BUS0_BANDWIDTH, 0xF6, 0x0F },
|
||||
{ PMC_EV_K8_NB_HT_BUS1_BANDWIDTH, 0xF7, 0x0F },
|
||||
{ PMC_EV_K8_NB_HT_BUS2_BANDWIDTH, 0xF8, 0x0F }
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
const int amd_event_codes_size =
|
||||
sizeof(amd_event_codes) / sizeof(amd_event_codes[0]);
|
||||
|
||||
/*
|
||||
* read a pmc register
|
||||
*/
|
||||
|
||||
static int
|
||||
amd_read_pmc(int cpu, int ri, pmc_value_t *v)
|
||||
{
|
||||
enum pmc_mode mode;
|
||||
const struct amd_descr *pd;
|
||||
struct pmc *pm;
|
||||
const struct pmc_hw *phw;
|
||||
pmc_value_t tmp;
|
||||
|
||||
KASSERT(cpu >= 0 && cpu < mp_ncpus,
|
||||
("[amd,%d] illegal CPU value %d", __LINE__, cpu));
|
||||
KASSERT(ri >= 0 && ri < AMD_NPMCS,
|
||||
("[amd,%d] illegal row-index %d", __LINE__, ri));
|
||||
|
||||
phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
|
||||
pd = &amd_pmcdesc[ri];
|
||||
pm = phw->phw_pmc;
|
||||
|
||||
KASSERT(pm != NULL,
|
||||
("[amd,%d] No owner for HWPMC [cpu%d,pmc%d]", __LINE__,
|
||||
cpu, ri));
|
||||
|
||||
mode = pm->pm_mode;
|
||||
|
||||
PMCDBG(MDP,REA,1,"amd-read id=%d class=%d", ri, pd->pm_descr.pd_class);
|
||||
|
||||
/* Reading the TSC is a special case */
|
||||
if (pd->pm_descr.pd_class == PMC_CLASS_TSC) {
|
||||
KASSERT(PMC_IS_COUNTING_MODE(mode),
|
||||
("[amd,%d] TSC counter in non-counting mode", __LINE__));
|
||||
*v = rdtsc();
|
||||
PMCDBG(MDP,REA,2,"amd-read id=%d -> %jd", ri, *v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
KASSERT(pd->pm_descr.pd_class == AMD_PMC_CLASS,
|
||||
("[amd,%d] unknown PMC class (%d)", __LINE__,
|
||||
pd->pm_descr.pd_class));
|
||||
|
||||
tmp = rdmsr(pd->pm_perfctr); /* RDMSR serializes */
|
||||
if (PMC_IS_SAMPLING_MODE(mode))
|
||||
*v = -tmp;
|
||||
else
|
||||
*v = tmp;
|
||||
|
||||
PMCDBG(MDP,REA,2,"amd-read id=%d -> %jd", ri, *v);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write a PMC MSR.
|
||||
*/
|
||||
|
||||
static int
|
||||
amd_write_pmc(int cpu, int ri, pmc_value_t v)
|
||||
{
|
||||
const struct amd_descr *pd;
|
||||
struct pmc *pm;
|
||||
const struct pmc_hw *phw;
|
||||
enum pmc_mode mode;
|
||||
|
||||
KASSERT(cpu >= 0 && cpu < mp_ncpus,
|
||||
("[amd,%d] illegal CPU value %d", __LINE__, cpu));
|
||||
KASSERT(ri >= 0 && ri < AMD_NPMCS,
|
||||
("[amd,%d] illegal row-index %d", __LINE__, ri));
|
||||
|
||||
phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
|
||||
pd = &amd_pmcdesc[ri];
|
||||
pm = phw->phw_pmc;
|
||||
|
||||
KASSERT(pm != NULL,
|
||||
("[amd,%d] PMC not owned (cpu%d,pmc%d)", __LINE__,
|
||||
cpu, ri));
|
||||
|
||||
mode = pm->pm_mode;
|
||||
|
||||
if (pd->pm_descr.pd_class == PMC_CLASS_TSC)
|
||||
return 0;
|
||||
|
||||
KASSERT(pd->pm_descr.pd_class == AMD_PMC_CLASS,
|
||||
("[amd,%d] unknown PMC class (%d)", __LINE__,
|
||||
pd->pm_descr.pd_class));
|
||||
|
||||
/* use 2's complement of the count for sampling mode PMCs */
|
||||
if (PMC_IS_SAMPLING_MODE(mode))
|
||||
v = -v;
|
||||
|
||||
PMCDBG(MDP,WRI,1,"amd-write cpu=%d ri=%d v=%jx", cpu, ri, v);
|
||||
|
||||
/* write the PMC value */
|
||||
wrmsr(pd->pm_perfctr, v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* configure hardware pmc according to the configuration recorded in
|
||||
* pmc 'pm'.
|
||||
*/
|
||||
|
||||
static int
|
||||
amd_config_pmc(int cpu, int ri, struct pmc *pm)
|
||||
{
|
||||
struct pmc_hw *phw;
|
||||
|
||||
KASSERT(cpu >= 0 && cpu < mp_ncpus,
|
||||
("[amd,%d] illegal CPU value %d", __LINE__, cpu));
|
||||
KASSERT(ri >= 0 && ri < AMD_NPMCS,
|
||||
("[amd,%d] illegal row-index %d", __LINE__, ri));
|
||||
|
||||
phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
|
||||
|
||||
KASSERT(pm == NULL || phw->phw_pmc == NULL,
|
||||
("[amd,%d] hwpmc not unconfigured before re-config", __LINE__));
|
||||
|
||||
phw->phw_pmc = pm;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Machine dependent actions taken during the context switch in of a
|
||||
* thread.
|
||||
*/
|
||||
|
||||
static int
|
||||
amd_switch_in(struct pmc_cpu *pc)
|
||||
{
|
||||
(void) pc;
|
||||
|
||||
/* enable the RDPMC instruction */
|
||||
load_cr4(rcr4() | CR4_PCE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Machine dependent actions taken during the context switch out of a
|
||||
* thread.
|
||||
*/
|
||||
|
||||
static int
|
||||
amd_switch_out(struct pmc_cpu *pc)
|
||||
{
|
||||
(void) pc;
|
||||
|
||||
/* disallow RDPMC instruction */
|
||||
load_cr4(rcr4() & ~CR4_PCE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if a given allocation is feasible.
|
||||
*/
|
||||
|
||||
static int
|
||||
amd_allocate_pmc(int cpu, int ri, struct pmc *pm,
|
||||
const struct pmc_op_pmcallocate *a)
|
||||
{
|
||||
int i;
|
||||
uint32_t allowed_unitmask, caps, config, unitmask;
|
||||
enum pmc_event pe;
|
||||
const struct pmc_descr *pd;
|
||||
|
||||
(void) cpu;
|
||||
|
||||
KASSERT(cpu >= 0 && cpu < mp_ncpus,
|
||||
("[amd,%d] illegal CPU value %d", __LINE__, cpu));
|
||||
KASSERT(ri >= 0 && ri < AMD_NPMCS,
|
||||
("[amd,%d] illegal row index %d", __LINE__, ri));
|
||||
|
||||
pd = &amd_pmcdesc[ri].pm_descr;
|
||||
|
||||
/* check class match */
|
||||
if (pd->pd_class != pm->pm_class)
|
||||
return EINVAL;
|
||||
|
||||
caps = pm->pm_caps;
|
||||
|
||||
PMCDBG(MDP,ALL,1,"amd-allocate ri=%d caps=0x%x", ri, caps);
|
||||
|
||||
if ((pd->pd_caps & caps) != caps)
|
||||
return EPERM;
|
||||
if (pd->pd_class == PMC_CLASS_TSC) {
|
||||
/* TSC's are always allocated in system-wide counting mode */
|
||||
if (a->pm_ev != PMC_EV_TSC_TSC ||
|
||||
a->pm_mode != PMC_MODE_SC)
|
||||
return EINVAL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
KASSERT(pd->pd_class == AMD_PMC_CLASS,
|
||||
("[amd,%d] Unknown PMC class (%d)", __LINE__, pd->pd_class));
|
||||
|
||||
pe = a->pm_ev;
|
||||
|
||||
/* map ev to the correct event mask code */
|
||||
config = allowed_unitmask = 0;
|
||||
for (i = 0; i < amd_event_codes_size; i++)
|
||||
if (amd_event_codes[i].pe_ev == pe) {
|
||||
config =
|
||||
AMD_PMC_TO_EVENTMASK(amd_event_codes[i].pe_code);
|
||||
allowed_unitmask =
|
||||
AMD_PMC_TO_UNITMASK(amd_event_codes[i].pe_mask);
|
||||
break;
|
||||
}
|
||||
if (i == amd_event_codes_size)
|
||||
return EINVAL;
|
||||
|
||||
unitmask = a->pm_amd_config & AMD_PMC_UNITMASK;
|
||||
if (unitmask & ~allowed_unitmask) /* disallow reserved bits */
|
||||
return EINVAL;
|
||||
|
||||
if (unitmask && (caps & PMC_CAP_QUALIFIER))
|
||||
config |= unitmask;
|
||||
|
||||
if (caps & PMC_CAP_THRESHOLD)
|
||||
config |= a->pm_amd_config & AMD_PMC_COUNTERMASK;
|
||||
|
||||
/* set at least one of the 'usr' or 'os' caps */
|
||||
if (caps & PMC_CAP_USER)
|
||||
config |= AMD_PMC_USR;
|
||||
if (caps & PMC_CAP_SYSTEM)
|
||||
config |= AMD_PMC_OS;
|
||||
if ((caps & (PMC_CAP_USER|PMC_CAP_SYSTEM)) == 0)
|
||||
config |= (AMD_PMC_USR|AMD_PMC_OS);
|
||||
|
||||
if (caps & PMC_CAP_EDGE)
|
||||
config |= AMD_PMC_EDGE;
|
||||
if (caps & PMC_CAP_INVERT)
|
||||
config |= AMD_PMC_INVERT;
|
||||
if (caps & PMC_CAP_INTERRUPT)
|
||||
config |= AMD_PMC_INT;
|
||||
|
||||
pm->pm_md.pm_amd.pm_amd_evsel = config; /* save config value */
|
||||
|
||||
PMCDBG(MDP,ALL,2,"amd-allocate ri=%d -> config=0x%x", ri, config);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Release machine dependent state associated with a PMC. This is a
|
||||
* no-op on this architecture.
|
||||
*
|
||||
*/
|
||||
|
||||
/* ARGSUSED0 */
|
||||
static int
|
||||
amd_release_pmc(int cpu, int ri, struct pmc *pmc)
|
||||
{
|
||||
#if DEBUG
|
||||
const struct amd_descr *pd;
|
||||
#endif
|
||||
struct pmc_hw *phw;
|
||||
|
||||
(void) pmc;
|
||||
|
||||
KASSERT(cpu >= 0 && cpu < mp_ncpus,
|
||||
("[amd,%d] illegal CPU value %d", __LINE__, cpu));
|
||||
KASSERT(ri >= 0 && ri < AMD_NPMCS,
|
||||
("[amd,%d] illegal row-index %d", __LINE__, ri));
|
||||
|
||||
phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
|
||||
|
||||
KASSERT(phw->phw_pmc == NULL,
|
||||
("[amd,%d] PHW pmc %p non-NULL", __LINE__, phw->phw_pmc));
|
||||
|
||||
#if DEBUG
|
||||
pd = &amd_pmcdesc[ri];
|
||||
if (pd->pm_descr.pd_class == AMD_PMC_CLASS)
|
||||
KASSERT(AMD_PMC_IS_STOPPED(pd->pm_evsel),
|
||||
("[amd,%d] PMC %d released while active", __LINE__, ri));
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* start a PMC.
|
||||
*/
|
||||
|
||||
static int
|
||||
amd_start_pmc(int cpu, int ri)
|
||||
{
|
||||
uint32_t config;
|
||||
struct pmc *pm;
|
||||
struct pmc_hw *phw;
|
||||
const struct amd_descr *pd;
|
||||
|
||||
KASSERT(cpu >= 0 && cpu < mp_ncpus,
|
||||
("[amd,%d] illegal CPU value %d", __LINE__, cpu));
|
||||
KASSERT(ri >= 0 && ri < AMD_NPMCS,
|
||||
("[amd,%d] illegal row-index %d", __LINE__, ri));
|
||||
|
||||
phw = pmc_pcpu[cpu]->pc_hwpmcs[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));
|
||||
|
||||
PMCDBG(MDP,STA,1,"amd-start cpu=%d ri=%d", cpu, ri);
|
||||
|
||||
if (pd->pm_descr.pd_class == PMC_CLASS_TSC)
|
||||
return 0; /* TSCs are always running */
|
||||
|
||||
KASSERT(pd->pm_descr.pd_class == AMD_PMC_CLASS,
|
||||
("[amd,%d] unknown PMC class (%d)", __LINE__,
|
||||
pd->pm_descr.pd_class));
|
||||
|
||||
KASSERT(AMD_PMC_IS_STOPPED(pd->pm_evsel),
|
||||
("[amd,%d] pmc%d,cpu%d: Starting active PMC \"%s\"", __LINE__,
|
||||
ri, cpu, pd->pm_descr.pd_name));
|
||||
|
||||
/* turn on the PMC ENABLE bit */
|
||||
config = pm->pm_md.pm_amd.pm_amd_evsel | AMD_PMC_ENABLE;
|
||||
|
||||
PMCDBG(MDP,STA,2,"amd-start config=0x%x", config);
|
||||
|
||||
wrmsr(pd->pm_evsel, config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Stop a PMC.
|
||||
*/
|
||||
|
||||
static int
|
||||
amd_stop_pmc(int cpu, int ri)
|
||||
{
|
||||
struct pmc *pm;
|
||||
struct pmc_hw *phw;
|
||||
const struct amd_descr *pd;
|
||||
uint64_t config;
|
||||
|
||||
KASSERT(cpu >= 0 && cpu < mp_ncpus,
|
||||
("[amd,%d] illegal CPU value %d", __LINE__, cpu));
|
||||
KASSERT(ri >= 0 && ri < AMD_NPMCS,
|
||||
("[amd,%d] illegal row-index %d", __LINE__, ri));
|
||||
|
||||
phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
|
||||
pm = phw->phw_pmc;
|
||||
pd = &amd_pmcdesc[ri];
|
||||
|
||||
KASSERT(pm != NULL,
|
||||
("[amd,%d] cpu%d,pmc%d no PMC to stop", __LINE__,
|
||||
cpu, ri));
|
||||
|
||||
/* can't stop a TSC */
|
||||
if (pd->pm_descr.pd_class == PMC_CLASS_TSC)
|
||||
return 0;
|
||||
|
||||
KASSERT(pd->pm_descr.pd_class == AMD_PMC_CLASS,
|
||||
("[amd,%d] unknown PMC class (%d)", __LINE__,
|
||||
pd->pm_descr.pd_class));
|
||||
|
||||
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));
|
||||
|
||||
PMCDBG(MDP,STO,1,"amd-stop ri=%d", ri);
|
||||
|
||||
/* turn off the PMC ENABLE bit */
|
||||
config = pm->pm_md.pm_amd.pm_amd_evsel & ~AMD_PMC_ENABLE;
|
||||
wrmsr(pd->pm_evsel, config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Interrupt handler. This function needs to return '1' if the
|
||||
* interrupt was this CPU's PMCs or '0' otherwise. It is not allowed
|
||||
* to sleep or do anything a 'fast' interrupt handler is not allowed
|
||||
* to do.
|
||||
*/
|
||||
|
||||
static int
|
||||
amd_intr(int cpu, uintptr_t eip)
|
||||
{
|
||||
int i, retval;
|
||||
enum pmc_mode mode;
|
||||
uint32_t perfctr;
|
||||
struct pmc *pm;
|
||||
struct pmc_cpu *pc;
|
||||
struct pmc_hw *phw;
|
||||
|
||||
KASSERT(cpu >= 0 && cpu < mp_ncpus,
|
||||
("[amd,%d] out of range CPU %d", __LINE__, cpu));
|
||||
|
||||
retval = 0;
|
||||
|
||||
pc = pmc_pcpu[cpu];
|
||||
|
||||
/*
|
||||
* look for all PMCs that have interrupted:
|
||||
* - skip over the TSC [PMC#0]
|
||||
* - look for a PMC with a valid 'struct pmc' association
|
||||
* - look for a PMC in (a) sampling mode and (b) which has
|
||||
* overflowed. If found, we update the process's
|
||||
* histogram or send it a profiling signal by calling
|
||||
* the appropriate helper function.
|
||||
*/
|
||||
|
||||
for (i = 1; i < AMD_NPMCS; i++) {
|
||||
|
||||
phw = pc->pc_hwpmcs[i];
|
||||
perfctr = amd_pmcdesc[i].pm_perfctr;
|
||||
KASSERT(phw != NULL, ("[amd,%d] null PHW pointer", __LINE__));
|
||||
|
||||
if ((pm = phw->phw_pmc) == NULL ||
|
||||
pm->pm_state != PMC_STATE_RUNNING) {
|
||||
atomic_add_int(&pmc_stats.pm_intr_ignored, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
mode = pm->pm_mode;
|
||||
if (PMC_IS_SAMPLING_MODE(mode) &&
|
||||
AMD_PMC_HAS_OVERFLOWED(perfctr)) {
|
||||
atomic_add_int(&pmc_stats.pm_intr_processed, 1);
|
||||
if (PMC_IS_SYSTEM_MODE(mode))
|
||||
pmc_update_histogram(phw, eip);
|
||||
else if (PMC_IS_VIRTUAL_MODE(mode))
|
||||
pmc_send_signal(pm);
|
||||
retval = 1;
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
* describe a PMC
|
||||
*/
|
||||
static int
|
||||
amd_describe(int cpu, int ri, struct pmc_info *pi, struct pmc **ppmc)
|
||||
{
|
||||
int error;
|
||||
size_t copied;
|
||||
const struct amd_descr *pd;
|
||||
struct pmc_hw *phw;
|
||||
|
||||
KASSERT(cpu >= 0 && cpu < mp_ncpus,
|
||||
("[amd,%d] illegal CPU %d", __LINE__, cpu));
|
||||
KASSERT(ri >= 0 && ri < AMD_NPMCS,
|
||||
("[amd,%d] row-index %d out of range", __LINE__, ri));
|
||||
|
||||
phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
|
||||
pd = &amd_pmcdesc[ri];
|
||||
|
||||
if ((error = copystr(pd->pm_descr.pd_name, pi->pm_name,
|
||||
PMC_NAME_MAX, &copied)) != 0)
|
||||
return error;
|
||||
|
||||
pi->pm_class = pd->pm_descr.pd_class;
|
||||
pi->pm_caps = pd->pm_descr.pd_caps;
|
||||
pi->pm_width = pd->pm_descr.pd_width;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
* i386 specific entry points
|
||||
*/
|
||||
|
||||
/*
|
||||
* return the MSR address of the given PMC.
|
||||
*/
|
||||
|
||||
static int
|
||||
amd_get_msr(int ri, uint32_t *msr)
|
||||
{
|
||||
KASSERT(ri >= 0 && ri < AMD_NPMCS,
|
||||
("[amd,%d] ri %d out of range", __LINE__, ri));
|
||||
|
||||
*msr = amd_pmcdesc[ri].pm_perfctr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* processor dependent initialization.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Per-processor data structure
|
||||
*
|
||||
* [common stuff]
|
||||
* [5 struct pmc_hw pointers]
|
||||
* [5 struct pmc_hw structures]
|
||||
*/
|
||||
|
||||
struct amd_cpu {
|
||||
struct pmc_cpu pc_common;
|
||||
struct pmc_hw *pc_hwpmcs[AMD_NPMCS];
|
||||
struct pmc_hw pc_amdpmcs[AMD_NPMCS];
|
||||
};
|
||||
|
||||
|
||||
static int
|
||||
amd_init(int cpu)
|
||||
{
|
||||
int n;
|
||||
struct amd_cpu *pcs;
|
||||
struct pmc_hw *phw;
|
||||
|
||||
KASSERT(cpu >= 0 && cpu < mp_ncpus,
|
||||
("[amd,%d] insane cpu number %d", __LINE__, cpu));
|
||||
|
||||
PMCDBG(MDP,INI,1,"amd-init cpu=%d", cpu);
|
||||
|
||||
MALLOC(pcs, struct amd_cpu *, sizeof(struct amd_cpu), M_PMC,
|
||||
M_WAITOK|M_ZERO);
|
||||
|
||||
if (pcs == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
phw = &pcs->pc_amdpmcs[0];
|
||||
|
||||
/*
|
||||
* Initialize the per-cpu mutex and set the content of the
|
||||
* hardware descriptors to a known state.
|
||||
*/
|
||||
|
||||
for (n = 0; n < AMD_NPMCS; n++, phw++) {
|
||||
phw->phw_state = PMC_PHW_FLAG_IS_ENABLED |
|
||||
PMC_PHW_CPU_TO_STATE(cpu) | PMC_PHW_INDEX_TO_STATE(n);
|
||||
phw->phw_pmc = NULL;
|
||||
pcs->pc_hwpmcs[n] = phw;
|
||||
}
|
||||
|
||||
/* Mark the TSC as shareable */
|
||||
pcs->pc_hwpmcs[0]->phw_state |= PMC_PHW_FLAG_IS_SHAREABLE;
|
||||
|
||||
pmc_pcpu[cpu] = (struct pmc_cpu *) pcs;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* processor dependent cleanup prior to the KLD
|
||||
* being unloaded
|
||||
*/
|
||||
|
||||
static int
|
||||
amd_cleanup(int cpu)
|
||||
{
|
||||
int i;
|
||||
uint32_t evsel;
|
||||
struct pmc_cpu *pcs;
|
||||
|
||||
KASSERT(cpu >= 0 && cpu < mp_ncpus,
|
||||
("[amd,%d] insane cpu number (%d)", __LINE__, cpu));
|
||||
|
||||
PMCDBG(MDP,INI,1,"amd-cleanup cpu=%d", cpu);
|
||||
|
||||
/*
|
||||
* First, turn off all PMCs on this CPU.
|
||||
*/
|
||||
|
||||
for (i = 0; i < 4; i++) { /* XXX this loop is now not needed */
|
||||
evsel = rdmsr(AMD_PMC_EVSEL_0 + i);
|
||||
evsel &= ~AMD_PMC_ENABLE;
|
||||
wrmsr(AMD_PMC_EVSEL_0 + i, evsel);
|
||||
}
|
||||
|
||||
/*
|
||||
* Next, free up allocated space.
|
||||
*/
|
||||
|
||||
pcs = pmc_pcpu[cpu];
|
||||
|
||||
#if DEBUG
|
||||
/* check the TSC */
|
||||
KASSERT(pcs->pc_hwpmcs[0]->phw_pmc == NULL,
|
||||
("[amd,%d] CPU%d,PMC0 still in use", __LINE__, cpu));
|
||||
for (i = 1; i < AMD_NPMCS; i++) {
|
||||
KASSERT(pcs->pc_hwpmcs[i]->phw_pmc == NULL,
|
||||
("[amd,%d] CPU%d/PMC%d in use", __LINE__, cpu, i));
|
||||
KASSERT(AMD_PMC_IS_STOPPED(AMD_PMC_EVSEL_0 + (i-1)),
|
||||
("[amd,%d] CPU%d/PMC%d not stopped", __LINE__, cpu, i));
|
||||
}
|
||||
#endif
|
||||
KASSERT(pcs != NULL,
|
||||
("[amd,%d] null per-cpu state pointer (cpu%d)", __LINE__, cpu));
|
||||
|
||||
pmc_pcpu[cpu] = NULL;
|
||||
FREE(pcs, M_PMC);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize ourselves.
|
||||
*/
|
||||
|
||||
struct pmc_mdep *
|
||||
pmc_amd_initialize(void)
|
||||
{
|
||||
|
||||
struct pmc_mdep *pmc_mdep;
|
||||
|
||||
/* The presence of hardware performance counters on the AMD
|
||||
Athlon, Duron or later processors, is _not_ indicated by
|
||||
any of the processor feature flags set by the 'CPUID'
|
||||
instruction, so we only check the 'instruction family'
|
||||
field returned by CPUID for instruction family >= 6. This
|
||||
test needs to be be refined. */
|
||||
|
||||
if ((cpu_id & 0xF00) < 0x600)
|
||||
return NULL;
|
||||
|
||||
MALLOC(pmc_mdep, struct pmc_mdep *, sizeof(struct pmc_mdep),
|
||||
M_PMC, M_WAITOK|M_ZERO);
|
||||
|
||||
#if __i386__
|
||||
pmc_mdep->pmd_cputype = PMC_CPU_AMD_K7;
|
||||
#elif __amd64__
|
||||
pmc_mdep->pmd_cputype = PMC_CPU_AMD_K8;
|
||||
#else
|
||||
#error Unknown AMD CPU type.
|
||||
#endif
|
||||
|
||||
pmc_mdep->pmd_npmc = AMD_NPMCS;
|
||||
|
||||
/* this processor has two classes of usable PMCs */
|
||||
pmc_mdep->pmd_nclass = 2;
|
||||
pmc_mdep->pmd_classes[0] = PMC_CLASS_TSC;
|
||||
pmc_mdep->pmd_classes[1] = AMD_PMC_CLASS;
|
||||
pmc_mdep->pmd_nclasspmcs[0] = 1;
|
||||
pmc_mdep->pmd_nclasspmcs[1] = (AMD_NPMCS-1);
|
||||
|
||||
pmc_mdep->pmd_init = amd_init;
|
||||
pmc_mdep->pmd_cleanup = amd_cleanup;
|
||||
pmc_mdep->pmd_switch_in = amd_switch_in;
|
||||
pmc_mdep->pmd_switch_out = amd_switch_out;
|
||||
pmc_mdep->pmd_read_pmc = amd_read_pmc;
|
||||
pmc_mdep->pmd_write_pmc = amd_write_pmc;
|
||||
pmc_mdep->pmd_config_pmc = amd_config_pmc;
|
||||
pmc_mdep->pmd_allocate_pmc = amd_allocate_pmc;
|
||||
pmc_mdep->pmd_release_pmc = amd_release_pmc;
|
||||
pmc_mdep->pmd_start_pmc = amd_start_pmc;
|
||||
pmc_mdep->pmd_stop_pmc = amd_stop_pmc;
|
||||
pmc_mdep->pmd_intr = amd_intr;
|
||||
pmc_mdep->pmd_describe = amd_describe;
|
||||
pmc_mdep->pmd_get_msr = amd_get_msr; /* i386 */
|
||||
|
||||
PMCDBG(MDP,INI,0,"%s","amd-initialize");
|
||||
|
||||
return pmc_mdep;
|
||||
}
|
@ -1,141 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2003-2005 Joseph Koshy
|
||||
* 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 <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/pmc.h>
|
||||
#include <sys/pmckern.h>
|
||||
#include <sys/smp.h>
|
||||
#include <sys/systm.h>
|
||||
|
||||
#include <machine/cputypes.h>
|
||||
#include <machine/md_var.h>
|
||||
|
||||
struct pmc_mdep *
|
||||
pmc_intel_initialize(void)
|
||||
{
|
||||
struct pmc_mdep *pmc_mdep;
|
||||
enum pmc_cputype cputype;
|
||||
int error, model;
|
||||
|
||||
KASSERT(strcmp(cpu_vendor, "GenuineIntel") == 0,
|
||||
("[intel,%d] Initializing non-intel processor", __LINE__));
|
||||
|
||||
PMCDBG(MDP,INI,0, "intel-initialize cpuid=0x%x", cpu_id);
|
||||
|
||||
cputype = -1;
|
||||
|
||||
switch (cpu_id & 0xF00) {
|
||||
case 0x500: /* Pentium family processors */
|
||||
cputype = PMC_CPU_INTEL_P5;
|
||||
break;
|
||||
case 0x600: /* Pentium Pro, Celeron, Pentium II & III */
|
||||
switch ((cpu_id & 0xF0) >> 4) { /* model number field */
|
||||
case 0x1:
|
||||
cputype = PMC_CPU_INTEL_P6;
|
||||
break;
|
||||
case 0x3: case 0x5:
|
||||
cputype = PMC_CPU_INTEL_PII;
|
||||
break;
|
||||
case 0x6:
|
||||
cputype = PMC_CPU_INTEL_CL;
|
||||
break;
|
||||
case 0x7: case 0x8: case 0xA: case 0xB:
|
||||
cputype = PMC_CPU_INTEL_PIII;
|
||||
break;
|
||||
case 0x9: case 0xD:
|
||||
cputype = PMC_CPU_INTEL_PM;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 0xF00: /* P4 */
|
||||
model = ((cpu_id & 0xF0000) >> 12) | ((cpu_id & 0xF0) >> 4);
|
||||
if (model >= 0 && model <= 3) /* known models */
|
||||
cputype = PMC_CPU_INTEL_PIV;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((int) cputype == -1) {
|
||||
printf("pmc: Unknown Intel CPU.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MALLOC(pmc_mdep, struct pmc_mdep *, sizeof(struct pmc_mdep),
|
||||
M_PMC, M_WAITOK|M_ZERO);
|
||||
|
||||
pmc_mdep->pmd_cputype = cputype;
|
||||
pmc_mdep->pmd_nclass = 2;
|
||||
pmc_mdep->pmd_classes[0] = PMC_CLASS_TSC;
|
||||
pmc_mdep->pmd_nclasspmcs[0] = 1;
|
||||
|
||||
error = 0;
|
||||
|
||||
switch (cputype) {
|
||||
|
||||
/*
|
||||
* Intel Pentium 4 Processors
|
||||
*/
|
||||
|
||||
case PMC_CPU_INTEL_PIV:
|
||||
error = pmc_initialize_p4(pmc_mdep);
|
||||
break;
|
||||
|
||||
/*
|
||||
* P6 Family Processors
|
||||
*/
|
||||
|
||||
case PMC_CPU_INTEL_P6:
|
||||
case PMC_CPU_INTEL_CL:
|
||||
case PMC_CPU_INTEL_PII:
|
||||
case PMC_CPU_INTEL_PIII:
|
||||
case PMC_CPU_INTEL_PM:
|
||||
|
||||
error = pmc_initialize_p6(pmc_mdep);
|
||||
break;
|
||||
|
||||
/*
|
||||
* Intel Pentium PMCs.
|
||||
*/
|
||||
|
||||
case PMC_CPU_INTEL_P5:
|
||||
error = pmc_initialize_p5(pmc_mdep);
|
||||
break;
|
||||
|
||||
default:
|
||||
KASSERT(0,("[intel,%d] Unknown CPU type", __LINE__));
|
||||
}
|
||||
|
||||
if (error) {
|
||||
FREE(pmc_mdep, M_PMC);
|
||||
pmc_mdep = NULL;
|
||||
}
|
||||
|
||||
return pmc_mdep;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,50 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2003-2005 Joseph Koshy
|
||||
* 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 <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/pmc.h>
|
||||
#include <sys/pmckern.h>
|
||||
#include <sys/smp.h>
|
||||
#include <sys/systm.h>
|
||||
|
||||
#include <machine/cputypes.h>
|
||||
#include <machine/md_var.h>
|
||||
|
||||
/*
|
||||
* Intel Pentium PMCs
|
||||
*/
|
||||
|
||||
int
|
||||
pmc_initialize_p5(struct pmc_mdep *pmc_mdep)
|
||||
{
|
||||
(void) pmc_mdep;
|
||||
return ENOSYS; /* nothing here yet */
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,741 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2003-2005 Joseph Koshy
|
||||
* 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 <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/pmc.h>
|
||||
#include <sys/pmckern.h>
|
||||
#include <sys/smp.h>
|
||||
#include <sys/systm.h>
|
||||
|
||||
#include <machine/cputypes.h>
|
||||
#include <machine/md_var.h>
|
||||
|
||||
/*
|
||||
* PENTIUM PRO SUPPORT
|
||||
*/
|
||||
|
||||
struct p6pmc_descr {
|
||||
struct pmc_descr pm_descr; /* common information */
|
||||
uint32_t pm_pmc_msr;
|
||||
uint32_t pm_evsel_msr;
|
||||
};
|
||||
|
||||
static struct p6pmc_descr p6_pmcdesc[P6_NPMCS] = {
|
||||
|
||||
/* TSC */
|
||||
{
|
||||
.pm_descr =
|
||||
{
|
||||
.pd_name = "TSC",
|
||||
.pd_class = PMC_CLASS_TSC,
|
||||
.pd_caps = PMC_CAP_READ,
|
||||
.pd_width = 64
|
||||
},
|
||||
.pm_pmc_msr = 0x10,
|
||||
.pm_evsel_msr = ~0
|
||||
},
|
||||
|
||||
#define P6_PMC_CAPS (PMC_CAP_INTERRUPT | PMC_CAP_USER | PMC_CAP_SYSTEM | \
|
||||
PMC_CAP_EDGE | PMC_CAP_THRESHOLD | PMC_CAP_READ | PMC_CAP_WRITE | \
|
||||
PMC_CAP_INVERT | PMC_CAP_QUALIFIER)
|
||||
|
||||
/* PMC 0 */
|
||||
{
|
||||
.pm_descr =
|
||||
{
|
||||
.pd_name ="P6-0",
|
||||
.pd_class = PMC_CLASS_P6,
|
||||
.pd_caps = P6_PMC_CAPS,
|
||||
.pd_width = 40
|
||||
},
|
||||
.pm_pmc_msr = P6_MSR_PERFCTR0,
|
||||
.pm_evsel_msr = P6_MSR_EVSEL0
|
||||
},
|
||||
|
||||
/* PMC 1 */
|
||||
{
|
||||
.pm_descr =
|
||||
{
|
||||
.pd_name ="P6-1",
|
||||
.pd_class = PMC_CLASS_P6,
|
||||
.pd_caps = P6_PMC_CAPS,
|
||||
.pd_width = 40
|
||||
},
|
||||
.pm_pmc_msr = P6_MSR_PERFCTR1,
|
||||
.pm_evsel_msr = P6_MSR_EVSEL1
|
||||
}
|
||||
};
|
||||
|
||||
static enum pmc_cputype p6_cputype;
|
||||
|
||||
/*
|
||||
* P6 Event descriptor
|
||||
*/
|
||||
|
||||
struct p6_event_descr {
|
||||
const enum pmc_event pm_event;
|
||||
uint32_t pm_evsel;
|
||||
uint32_t pm_flags;
|
||||
uint32_t pm_unitmask;
|
||||
};
|
||||
|
||||
static const struct p6_event_descr p6_events[] = {
|
||||
|
||||
#define P6_EVDESCR(NAME, EVSEL, FLAGS, UMASK) \
|
||||
{ \
|
||||
.pm_event = PMC_EV_P6_##NAME, \
|
||||
.pm_evsel = (EVSEL), \
|
||||
.pm_flags = (FLAGS), \
|
||||
.pm_unitmask = (UMASK) \
|
||||
}
|
||||
|
||||
#define P6F_P6 (1 << PMC_CPU_INTEL_P6)
|
||||
#define P6F_CL (1 << PMC_CPU_INTEL_CL)
|
||||
#define P6F_PII (1 << PMC_CPU_INTEL_PII)
|
||||
#define P6F_PIII (1 << PMC_CPU_INTEL_PIII)
|
||||
#define P6F_PM (1 << PMC_CPU_INTEL_PM)
|
||||
#define P6F_CTR0 0x0001
|
||||
#define P6F_CTR1 0x0002
|
||||
#define P6F_ALL_CPUS (P6F_P6 | P6F_PII | P6F_CL | P6F_PIII | P6F_PM)
|
||||
#define P6F_ALL_CTRS (P6F_CTR0 | P6F_CTR1)
|
||||
#define P6F_ALL (P6F_ALL_CPUS | P6F_ALL_CTRS)
|
||||
|
||||
#define P6_EVENT_VALID_FOR_CPU(P,CPU) ((P)->pm_flags & (1 << (CPU)))
|
||||
#define P6_EVENT_VALID_FOR_CTR(P,CTR) ((P)->pm_flags & (1 << (CTR)))
|
||||
|
||||
P6_EVDESCR(DATA_MEM_REFS, 0x43, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(DCU_LINES_IN, 0x45, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(DCU_M_LINES_IN, 0x46, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(DCU_M_LINES_OUT, 0x47, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(DCU_MISS_OUTSTANDING, 0x47, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(IFU_FETCH, 0x80, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(IFU_FETCH_MISS, 0x81, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(ITLB_MISS, 0x85, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(IFU_MEM_STALL, 0x86, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(ILD_STALL, 0x87, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(L2_IFETCH, 0x28, P6F_ALL, 0x0F),
|
||||
P6_EVDESCR(L2_LD, 0x29, P6F_ALL, 0x0F),
|
||||
P6_EVDESCR(L2_ST, 0x2A, P6F_ALL, 0x0F),
|
||||
P6_EVDESCR(L2_LINES_IN, 0x24, P6F_ALL, 0x0F),
|
||||
P6_EVDESCR(L2_LINES_OUT, 0x26, P6F_ALL, 0x0F),
|
||||
P6_EVDESCR(L2_M_LINES_INM, 0x25, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(L2_M_LINES_OUTM, 0x27, P6F_ALL, 0x0F),
|
||||
P6_EVDESCR(L2_RQSTS, 0x2E, P6F_ALL, 0x0F),
|
||||
P6_EVDESCR(L2_ADS, 0x21, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(L2_DBUS_BUSY, 0x22, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(L2_DBUS_BUSY_RD, 0x23, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(BUS_DRDY_CLOCKS, 0x62, P6F_ALL, 0x20),
|
||||
P6_EVDESCR(BUS_LOCK_CLOCKS, 0x63, P6F_ALL, 0x20),
|
||||
P6_EVDESCR(BUS_REQ_OUTSTANDING, 0x60, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(BUS_TRAN_BRD, 0x65, P6F_ALL, 0x20),
|
||||
P6_EVDESCR(BUS_TRAN_RFO, 0x66, P6F_ALL, 0x20),
|
||||
P6_EVDESCR(BUS_TRANS_WB, 0x67, P6F_ALL, 0x20),
|
||||
P6_EVDESCR(BUS_TRAN_IFETCH, 0x68, P6F_ALL, 0x20),
|
||||
P6_EVDESCR(BUS_TRAN_INVAL, 0x69, P6F_ALL, 0x20),
|
||||
P6_EVDESCR(BUS_TRAN_PWR, 0x6A, P6F_ALL, 0x20),
|
||||
P6_EVDESCR(BUS_TRANS_P, 0x6B, P6F_ALL, 0x20),
|
||||
P6_EVDESCR(BUS_TRANS_IO, 0x6C, P6F_ALL, 0x20),
|
||||
P6_EVDESCR(BUS_TRAN_DEF, 0x6D, P6F_ALL, 0x20),
|
||||
P6_EVDESCR(BUS_TRAN_BURST, 0x6E, P6F_ALL, 0x20),
|
||||
P6_EVDESCR(BUS_TRAN_ANY, 0x70, P6F_ALL, 0x20),
|
||||
P6_EVDESCR(BUS_TRAN_MEM, 0x6F, P6F_ALL, 0x20),
|
||||
P6_EVDESCR(BUS_DATA_RCV, 0x64, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(BUS_BNR_DRV, 0x61, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(BUS_HIT_DRV, 0x7A, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(BUS_HITM_DRV, 0x7B, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(BUS_SNOOP_STALL, 0x7E, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(FLOPS, 0xC1, P6F_ALL_CPUS | P6F_CTR0, 0x00),
|
||||
P6_EVDESCR(FP_COMPS_OPS_EXE, 0x10, P6F_ALL_CPUS | P6F_CTR0, 0x00),
|
||||
P6_EVDESCR(FP_ASSIST, 0x11, P6F_ALL_CPUS | P6F_CTR1, 0x00),
|
||||
P6_EVDESCR(MUL, 0x12, P6F_ALL_CPUS | P6F_CTR1, 0x00),
|
||||
P6_EVDESCR(DIV, 0x13, P6F_ALL_CPUS | P6F_CTR1, 0x00),
|
||||
P6_EVDESCR(CYCLES_DIV_BUSY, 0x14, P6F_ALL_CPUS | P6F_CTR0, 0x00),
|
||||
P6_EVDESCR(LD_BLOCKS, 0x03, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(SB_DRAINS, 0x04, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(MISALIGN_MEM_REF, 0x05, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(EMON_KNI_PREF_DISPATCHED, 0x07, P6F_PIII | P6F_ALL_CTRS, 0x03),
|
||||
P6_EVDESCR(EMON_KNI_PREF_MISS, 0x4B, P6F_PIII | P6F_ALL_CTRS, 0x03),
|
||||
P6_EVDESCR(INST_RETIRED, 0xC0, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(UOPS_RETIRED, 0xC2, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(INST_DECODED, 0xD0, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(EMON_KNI_INST_RETIRED, 0xD8, P6F_PIII | P6F_ALL_CTRS, 0x01),
|
||||
P6_EVDESCR(EMON_KNI_COMP_INST_RET, 0xD9, P6F_PIII | P6F_ALL_CTRS, 0x01),
|
||||
P6_EVDESCR(HW_INT_RX, 0xC8, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(CYCLES_INT_MASKED, 0xC6, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(CYCLES_INT_PENDING_AND_MASKED, 0xC7, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(BR_INST_RETIRED, 0xC4, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(BR_MISS_PRED_RETIRED, 0xC5, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(BR_TAKEN_RETIRED, 0xC9, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(BR_MISS_PRED_TAKEN_RET, 0xCA, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(BR_INST_DECODED, 0xE0, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(BTB_MISSES, 0xE2, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(BR_BOGUS, 0xE4, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(BACLEARS, 0xE6, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(RESOURCE_STALLS, 0xA2, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(PARTIAL_RAT_STALLS, 0xD2, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(SEGMENT_REG_LOADS, 0x06, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(CPU_CLK_UNHALTED, 0x79, P6F_ALL, 0x00),
|
||||
P6_EVDESCR(MMX_INSTR_EXEC, 0xB0,
|
||||
P6F_ALL_CTRS | P6F_CL | P6F_PII, 0x00),
|
||||
P6_EVDESCR(MMX_SAT_INSTR_EXEC, 0xB1,
|
||||
P6F_ALL_CTRS | P6F_PII | P6F_PIII, 0x00),
|
||||
P6_EVDESCR(MMX_UOPS_EXEC, 0xB2,
|
||||
P6F_ALL_CTRS | P6F_PII | P6F_PIII, 0x0F),
|
||||
P6_EVDESCR(MMX_INSTR_TYPE_EXEC, 0xB3,
|
||||
P6F_ALL_CTRS | P6F_PII | P6F_PIII, 0x3F),
|
||||
P6_EVDESCR(FP_MMX_TRANS, 0xCC,
|
||||
P6F_ALL_CTRS | P6F_PII | P6F_PIII, 0x01),
|
||||
P6_EVDESCR(MMX_ASSIST, 0xCD,
|
||||
P6F_ALL_CTRS | P6F_PII | P6F_PIII, 0x00),
|
||||
P6_EVDESCR(MMX_INSTR_RET, 0xCE, P6F_ALL_CTRS | P6F_PII, 0x00),
|
||||
P6_EVDESCR(SEG_RENAME_STALLS, 0xD4,
|
||||
P6F_ALL_CTRS | P6F_PII | P6F_PIII, 0x0F),
|
||||
P6_EVDESCR(SEG_REG_RENAMES, 0xD5,
|
||||
P6F_ALL_CTRS | P6F_PII | P6F_PIII, 0x0F),
|
||||
P6_EVDESCR(RET_SEG_RENAMES, 0xD6,
|
||||
P6F_ALL_CTRS | P6F_PII | P6F_PIII, 0x00),
|
||||
P6_EVDESCR(EMON_EST_TRANS, 0x58, P6F_ALL_CTRS | P6F_PM, 0x02),
|
||||
P6_EVDESCR(EMON_THERMAL_TRIP, 0x59, P6F_ALL_CTRS | P6F_PM, 0x00),
|
||||
P6_EVDESCR(BR_INST_EXEC, 0x88, P6F_ALL_CTRS | P6F_PM, 0x00),
|
||||
P6_EVDESCR(BR_MISSP_EXEC, 0x89, P6F_ALL_CTRS | P6F_PM, 0x00),
|
||||
P6_EVDESCR(BR_BAC_MISSP_EXEC, 0x8A, P6F_ALL_CTRS | P6F_PM, 0x00),
|
||||
P6_EVDESCR(BR_CND_EXEC, 0x8B, P6F_ALL_CTRS | P6F_PM, 0x00),
|
||||
P6_EVDESCR(BR_CND_MISSP_EXEC, 0x8C, P6F_ALL_CTRS | P6F_PM, 0x00),
|
||||
P6_EVDESCR(BR_IND_EXEC, 0x8D, P6F_ALL_CTRS | P6F_PM, 0x00),
|
||||
P6_EVDESCR(BR_IND_MISSP_EXEC, 0x8E, P6F_ALL_CTRS | P6F_PM, 0x00),
|
||||
P6_EVDESCR(BR_RET_EXEC, 0x8F, P6F_ALL_CTRS | P6F_PM, 0x00),
|
||||
P6_EVDESCR(BR_RET_MISSP_EXEC, 0x90, P6F_ALL_CTRS | P6F_PM, 0x00),
|
||||
P6_EVDESCR(BR_RET_BAC_MISSP_EXEC, 0x91, P6F_ALL_CTRS | P6F_PM, 0x00),
|
||||
P6_EVDESCR(BR_CALL_EXEC, 0x92, P6F_ALL_CTRS | P6F_PM, 0x00),
|
||||
P6_EVDESCR(BR_CALL_MISSP_EXEC, 0x93, P6F_ALL_CTRS | P6F_PM, 0x00),
|
||||
P6_EVDESCR(BR_IND_CALL_EXEC, 0x94, P6F_ALL_CTRS | P6F_PM, 0x00),
|
||||
P6_EVDESCR(EMON_SIMD_INSTR_RETIRED, 0xCE, P6F_ALL_CTRS | P6F_PM, 0x00),
|
||||
P6_EVDESCR(EMON_SYNCH_UOPS, 0xD3, P6F_ALL_CTRS | P6F_PM, 0x00),
|
||||
P6_EVDESCR(EMON_ESP_UOPS, 0xD7, P6F_ALL_CTRS | P6F_PM, 0x00),
|
||||
P6_EVDESCR(EMON_FUSED_UOPS_RET, 0xDA, P6F_ALL_CTRS | P6F_PM, 0x03),
|
||||
P6_EVDESCR(EMON_UNFUSION, 0xDB, P6F_ALL_CTRS | P6F_PM, 0x00),
|
||||
P6_EVDESCR(EMON_PREF_RQSTS_UP, 0xF0, P6F_ALL_CTRS | P6F_PM, 0x00),
|
||||
P6_EVDESCR(EMON_PREF_RQSTS_DN, 0xD8, P6F_ALL_CTRS | P6F_PM, 0x00),
|
||||
P6_EVDESCR(EMON_SSE_SSE2_INST_RETIRED, 0xD8, P6F_ALL_CTRS | P6F_PM, 0x03),
|
||||
P6_EVDESCR(EMON_SSE_SSE2_COMP_INST_RETIRED, 0xD9, P6F_ALL_CTRS | P6F_PM, 0x03)
|
||||
|
||||
#undef P6_EVDESCR
|
||||
};
|
||||
|
||||
#define P6_NEVENTS (PMC_EV_P6_LAST - PMC_EV_P6_FIRST + 1)
|
||||
|
||||
static const struct p6_event_descr *
|
||||
p6_find_event(enum pmc_event ev)
|
||||
{
|
||||
int n;
|
||||
|
||||
for (n = 0; n < P6_NEVENTS; n++)
|
||||
if (p6_events[n].pm_event == ev)
|
||||
break;
|
||||
if (n == P6_NEVENTS)
|
||||
return NULL;
|
||||
return &p6_events[n];
|
||||
}
|
||||
|
||||
/*
|
||||
* Per-CPU data structure for P6 class CPUs
|
||||
*
|
||||
* [common stuff]
|
||||
* [3 struct pmc_hw pointers]
|
||||
* [3 struct pmc_hw structures]
|
||||
*/
|
||||
|
||||
struct p6_cpu {
|
||||
struct pmc_cpu pc_common;
|
||||
struct pmc_hw *pc_hwpmcs[P6_NPMCS];
|
||||
struct pmc_hw pc_p6pmcs[P6_NPMCS];
|
||||
};
|
||||
|
||||
static int
|
||||
p6_init(int cpu)
|
||||
{
|
||||
int n;
|
||||
struct p6_cpu *pcs;
|
||||
struct pmc_hw *phw;
|
||||
|
||||
KASSERT(cpu >= 0 && cpu < mp_ncpus,
|
||||
("[p6,%d] bad cpu %d", __LINE__, cpu));
|
||||
|
||||
PMCDBG(MDP,INI,0,"p6-init cpu=%d", cpu);
|
||||
|
||||
MALLOC(pcs, struct p6_cpu *, sizeof(struct p6_cpu), M_PMC,
|
||||
M_WAITOK|M_ZERO);
|
||||
|
||||
if (pcs == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
phw = pcs->pc_p6pmcs;
|
||||
|
||||
for (n = 0; n < P6_NPMCS; n++, phw++) {
|
||||
phw->phw_state = PMC_PHW_FLAG_IS_ENABLED |
|
||||
PMC_PHW_CPU_TO_STATE(cpu) | PMC_PHW_INDEX_TO_STATE(n);
|
||||
phw->phw_pmc = NULL;
|
||||
pcs->pc_hwpmcs[n] = phw;
|
||||
}
|
||||
|
||||
/* Mark the TSC as shareable */
|
||||
pcs->pc_hwpmcs[0]->phw_state |= PMC_PHW_FLAG_IS_SHAREABLE;
|
||||
|
||||
pmc_pcpu[cpu] = (struct pmc_cpu *) pcs;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
p6_cleanup(int cpu)
|
||||
{
|
||||
struct pmc_cpu *pcs;
|
||||
|
||||
KASSERT(cpu >= 0 && cpu < mp_ncpus,
|
||||
("[p6,%d] bad cpu %d", __LINE__, cpu));
|
||||
|
||||
PMCDBG(MDP,INI,0,"p6-cleanup cpu=%d", cpu);
|
||||
|
||||
if ((pcs = pmc_pcpu[cpu]) != NULL)
|
||||
FREE(pcs, M_PMC);
|
||||
pmc_pcpu[cpu] = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
p6_switch_in(struct pmc_cpu *pc)
|
||||
{
|
||||
(void) pc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
p6_switch_out(struct pmc_cpu *pc)
|
||||
{
|
||||
(void) pc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
p6_read_pmc(int cpu, int ri, pmc_value_t *v)
|
||||
{
|
||||
struct pmc_hw *phw;
|
||||
struct pmc *pm;
|
||||
struct p6pmc_descr *pd;
|
||||
pmc_value_t tmp;
|
||||
|
||||
phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
|
||||
pm = phw->phw_pmc;
|
||||
pd = &p6_pmcdesc[ri];
|
||||
|
||||
KASSERT(pm,
|
||||
("[p6,%d] cpu %d ri %d pmc not configured", __LINE__, cpu, ri));
|
||||
|
||||
if (pd->pm_descr.pd_class == PMC_CLASS_TSC)
|
||||
return 0;
|
||||
|
||||
tmp = rdmsr(pd->pm_pmc_msr) & P6_PERFCTR_MASK;
|
||||
if (PMC_IS_SAMPLING_MODE(pm->pm_mode))
|
||||
*v = -tmp;
|
||||
else
|
||||
*v = tmp;
|
||||
|
||||
PMCDBG(MDP,REA,1, "p6-read cpu=%d ri=%d msr=0x%x -> v=%jx", cpu, ri,
|
||||
pd->pm_pmc_msr, *v);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
p6_write_pmc(int cpu, int ri, pmc_value_t v)
|
||||
{
|
||||
struct pmc_hw *phw;
|
||||
struct pmc *pm;
|
||||
struct p6pmc_descr *pd;
|
||||
|
||||
phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
|
||||
pm = phw->phw_pmc;
|
||||
pd = &p6_pmcdesc[ri];
|
||||
|
||||
KASSERT(pm,
|
||||
("[p6,%d] cpu %d ri %d pmc not configured", __LINE__, cpu, ri));
|
||||
|
||||
if (pd->pm_descr.pd_class == PMC_CLASS_TSC)
|
||||
return 0;
|
||||
|
||||
PMCDBG(MDP,WRI,1, "p6-write cpu=%d ri=%d msr=0x%x v=%jx", cpu, ri,
|
||||
pd->pm_pmc_msr, v);
|
||||
|
||||
if (PMC_IS_SAMPLING_MODE(pm->pm_mode))
|
||||
v = -v;
|
||||
|
||||
wrmsr(pd->pm_pmc_msr, v & P6_PERFCTR_MASK);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
p6_config_pmc(int cpu, int ri, struct pmc *pm)
|
||||
{
|
||||
struct pmc_hw *phw;
|
||||
|
||||
PMCDBG(MDP,CFG,1, "p6-config cpu=%d ri=%d pm=%p", cpu, ri, pm);
|
||||
|
||||
phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
|
||||
phw->phw_pmc = pm;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* A pmc may be allocated to a given row index if:
|
||||
* - the event is valid for this CPU
|
||||
* - the event is valid for this counter index
|
||||
*/
|
||||
|
||||
static int
|
||||
p6_allocate_pmc(int cpu, int ri, struct pmc *pm,
|
||||
const struct pmc_op_pmcallocate *a)
|
||||
{
|
||||
uint32_t allowed_unitmask, caps, config, unitmask;
|
||||
const struct p6pmc_descr *pd;
|
||||
const struct p6_event_descr *pevent;
|
||||
enum pmc_event ev;
|
||||
|
||||
(void) cpu;
|
||||
|
||||
KASSERT(cpu >= 0 && cpu < mp_ncpus,
|
||||
("[p4,%d] illegal CPU %d", __LINE__, cpu));
|
||||
KASSERT(ri >= 0 && ri < P6_NPMCS,
|
||||
("[p4,%d] illegal row-index value %d", __LINE__, ri));
|
||||
|
||||
pd = &p6_pmcdesc[ri];
|
||||
|
||||
PMCDBG(MDP,ALL,1, "p6-allocate ri=%d class=%d pmccaps=0x%x "
|
||||
"reqcaps=0x%x", ri, pd->pm_descr.pd_class, pd->pm_descr.pd_caps,
|
||||
pm->pm_caps);
|
||||
|
||||
/* check class */
|
||||
if (pd->pm_descr.pd_class != pm->pm_class)
|
||||
return EINVAL;
|
||||
|
||||
/* check requested capabilities */
|
||||
caps = a->pm_caps;
|
||||
if ((pd->pm_descr.pd_caps & caps) != caps)
|
||||
return EPERM;
|
||||
|
||||
if (pd->pm_descr.pd_class == PMC_CLASS_TSC) {
|
||||
/* TSC's are always allocated in system-wide counting mode */
|
||||
if (a->pm_ev != PMC_EV_TSC_TSC ||
|
||||
a->pm_mode != PMC_MODE_SC)
|
||||
return EINVAL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* P6 class events
|
||||
*/
|
||||
|
||||
ev = pm->pm_event;
|
||||
|
||||
if (ev < PMC_EV_P6_FIRST || ev > PMC_EV_P6_LAST)
|
||||
return EINVAL;
|
||||
|
||||
if ((pevent = p6_find_event(ev)) == NULL)
|
||||
return ESRCH;
|
||||
|
||||
if (!P6_EVENT_VALID_FOR_CPU(pevent, p6_cputype) ||
|
||||
!P6_EVENT_VALID_FOR_CTR(pevent, (ri-1)))
|
||||
return EINVAL;
|
||||
|
||||
/* For certain events, Pentium M differs from the stock P6 */
|
||||
allowed_unitmask = 0;
|
||||
if (p6_cputype == PMC_CPU_INTEL_PM) {
|
||||
if (ev == PMC_EV_P6_L2_LD || ev == PMC_EV_P6_L2_LINES_IN ||
|
||||
ev == PMC_EV_P6_L2_LINES_OUT)
|
||||
allowed_unitmask = P6_EVSEL_TO_UMASK(0x3F);
|
||||
else if (ev == PMC_EV_P6_L2_M_LINES_OUTM)
|
||||
allowed_unitmask = P6_EVSEL_TO_UMASK(0x30);
|
||||
} else
|
||||
allowed_unitmask = P6_EVSEL_TO_UMASK(pevent->pm_unitmask);
|
||||
|
||||
unitmask = a->pm_p6_config & P6_EVSEL_UMASK_MASK;
|
||||
if (unitmask & ~allowed_unitmask) /* disallow reserved bits */
|
||||
return EINVAL;
|
||||
|
||||
if (ev == PMC_EV_P6_MMX_UOPS_EXEC) /* hardcoded mask */
|
||||
unitmask = P6_EVSEL_TO_UMASK(0x0F);
|
||||
|
||||
config = 0;
|
||||
|
||||
config |= P6_EVSEL_EVENT_SELECT(pevent->pm_evsel);
|
||||
|
||||
if (unitmask & (caps & PMC_CAP_QUALIFIER))
|
||||
config |= unitmask;
|
||||
|
||||
if (caps & PMC_CAP_THRESHOLD)
|
||||
config |= a->pm_p6_config & P6_EVSEL_CMASK_MASK;
|
||||
|
||||
/* set at least one of the 'usr' or 'os' caps */
|
||||
if (caps & PMC_CAP_USER)
|
||||
config |= P6_EVSEL_USR;
|
||||
if (caps & PMC_CAP_SYSTEM)
|
||||
config |= P6_EVSEL_OS;
|
||||
if ((caps & (PMC_CAP_USER|PMC_CAP_SYSTEM)) == 0)
|
||||
config |= (P6_EVSEL_USR|P6_EVSEL_OS);
|
||||
|
||||
if (caps & PMC_CAP_EDGE)
|
||||
config |= P6_EVSEL_E;
|
||||
if (caps & PMC_CAP_INVERT)
|
||||
config |= P6_EVSEL_INV;
|
||||
if (caps & PMC_CAP_INTERRUPT)
|
||||
config |= P6_EVSEL_INT;
|
||||
|
||||
pm->pm_md.pm_p6.pm_p6_evsel = config;
|
||||
|
||||
PMCDBG(MDP,ALL,2, "p6-allocate config=0x%x", config);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
p6_release_pmc(int cpu, int ri, struct pmc *pm)
|
||||
{
|
||||
struct pmc_hw *phw;
|
||||
|
||||
(void) pm;
|
||||
|
||||
PMCDBG(MDP,REL,1, "p6-release cpu=%d ri=%d pm=%p", cpu, ri, pm);
|
||||
|
||||
KASSERT(cpu >= 0 && cpu < mp_ncpus,
|
||||
("[p6,%d] illegal CPU value %d", __LINE__, cpu));
|
||||
KASSERT(ri >= 0 && ri < P6_NPMCS,
|
||||
("[p6,%d] illegal row-index %d", __LINE__, ri));
|
||||
|
||||
phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
|
||||
|
||||
KASSERT(phw->phw_pmc == NULL,
|
||||
("[p6,%d] PHW pmc %p != pmc %p", __LINE__, phw->phw_pmc, pm));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
p6_start_pmc(int cpu, int ri)
|
||||
{
|
||||
uint32_t config;
|
||||
struct pmc *pm;
|
||||
struct pmc_hw *phw;
|
||||
const struct p6pmc_descr *pd;
|
||||
|
||||
KASSERT(cpu >= 0 && cpu < mp_ncpus,
|
||||
("[p6,%d] illegal CPU value %d", __LINE__, cpu));
|
||||
KASSERT(ri >= 0 && ri < P6_NPMCS,
|
||||
("[p6,%d] illegal row-index %d", __LINE__, ri));
|
||||
|
||||
phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
|
||||
pm = phw->phw_pmc;
|
||||
pd = &p6_pmcdesc[ri];
|
||||
|
||||
KASSERT(pm,
|
||||
("[p6,%d] starting cpu%d,ri%d with no pmc configured",
|
||||
__LINE__, cpu, ri));
|
||||
|
||||
PMCDBG(MDP,STA,1, "p6-start cpu=%d ri=%d", cpu, ri);
|
||||
|
||||
if (pd->pm_descr.pd_class == PMC_CLASS_TSC)
|
||||
return 0; /* TSC are always running */
|
||||
|
||||
KASSERT(pd->pm_descr.pd_class == PMC_CLASS_P6,
|
||||
("[p6,%d] unknown PMC class %d", __LINE__,
|
||||
pd->pm_descr.pd_class));
|
||||
|
||||
config = pm->pm_md.pm_p6.pm_p6_evsel;
|
||||
|
||||
PMCDBG(MDP,STA,2, "p6-start/2 cpu=%d ri=%d evselmsr=0x%x config=0x%x",
|
||||
cpu, ri, pd->pm_evsel_msr, config);
|
||||
|
||||
if (pd->pm_evsel_msr == P6_MSR_EVSEL0) /* CTR 0 */
|
||||
wrmsr(pd->pm_evsel_msr, config | P6_EVSEL_EN);
|
||||
else { /* CTR1 shares the enable bit CTR 0 */
|
||||
wrmsr(pd->pm_evsel_msr, config);
|
||||
wrmsr(P6_MSR_EVSEL0, rdmsr(P6_MSR_EVSEL0) | P6_EVSEL_EN);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
p6_stop_pmc(int cpu, int ri)
|
||||
{
|
||||
uint32_t config;
|
||||
struct pmc *pm;
|
||||
struct pmc_hw *phw;
|
||||
struct p6pmc_descr *pd;
|
||||
|
||||
KASSERT(cpu >= 0 && cpu < mp_ncpus,
|
||||
("[p6,%d] illegal cpu value %d", __LINE__, cpu));
|
||||
KASSERT(ri >= 0 && ri < P6_NPMCS,
|
||||
("[p6,%d] illegal row index %d", __LINE__, ri));
|
||||
|
||||
phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
|
||||
pm = phw->phw_pmc;
|
||||
pd = &p6_pmcdesc[ri];
|
||||
|
||||
KASSERT(pm,
|
||||
("[p6,%d] cpu%d ri%d no configured PMC to stop", __LINE__,
|
||||
cpu, ri));
|
||||
|
||||
if (pd->pm_descr.pd_class == PMC_CLASS_TSC)
|
||||
return 0;
|
||||
|
||||
KASSERT(pd->pm_descr.pd_class == PMC_CLASS_P6,
|
||||
("[p6,%d] unknown PMC class %d", __LINE__,
|
||||
pd->pm_descr.pd_class));
|
||||
|
||||
PMCDBG(MDP,STO,1, "p6-stop cpu=%d ri=%d", cpu, ri);
|
||||
|
||||
/*
|
||||
* If CTR0 is being turned off but CTR1 is active, we need
|
||||
* leave CTR0's EN field set. If CTR1 is being stopped, it
|
||||
* suffices to zero its EVSEL register.
|
||||
*/
|
||||
|
||||
if (ri == 1 &&
|
||||
pmc_pcpu[cpu]->pc_hwpmcs[2]->phw_pmc != NULL)
|
||||
config = P6_EVSEL_EN;
|
||||
else
|
||||
config = 0;
|
||||
wrmsr(pd->pm_evsel_msr, config);
|
||||
|
||||
PMCDBG(MDP,STO,2, "p6-stop/2 cpu=%d ri=%d config=0x%x", cpu, ri,
|
||||
config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
p6_intr(int cpu, uintptr_t eip)
|
||||
{
|
||||
(void) cpu;
|
||||
(void) eip;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
p6_describe(int cpu, int ri, struct pmc_info *pi,
|
||||
struct pmc **ppmc)
|
||||
{
|
||||
int error;
|
||||
size_t copied;
|
||||
struct pmc_hw *phw;
|
||||
struct p6pmc_descr *pd;
|
||||
|
||||
phw = pmc_pcpu[cpu]->pc_hwpmcs[ri];
|
||||
pd = &p6_pmcdesc[ri];
|
||||
|
||||
if ((error = copystr(pd->pm_descr.pd_name, pi->pm_name,
|
||||
PMC_NAME_MAX, &copied)) != 0)
|
||||
return error;
|
||||
|
||||
pi->pm_class = pd->pm_descr.pd_class;
|
||||
pi->pm_caps = pd->pm_descr.pd_caps;
|
||||
pi->pm_width = pd->pm_descr.pd_width;
|
||||
|
||||
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
|
||||
p6_get_msr(int ri, uint32_t *msr)
|
||||
{
|
||||
KASSERT(ri >= 0 && ri < P6_NPMCS,
|
||||
("[p6,%d ri %d out of range", __LINE__, ri));
|
||||
|
||||
*msr = p6_pmcdesc[ri].pm_pmc_msr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pmc_initialize_p6(struct pmc_mdep *pmc_mdep)
|
||||
{
|
||||
KASSERT(strcmp(cpu_vendor, "GenuineIntel") == 0,
|
||||
("[p6,%d] Initializing non-intel processor", __LINE__));
|
||||
|
||||
PMCDBG(MDP,INI,1, "%s", "p6-initialize");
|
||||
|
||||
switch (pmc_mdep->pmd_cputype) {
|
||||
|
||||
/*
|
||||
* P6 Family Processors
|
||||
*/
|
||||
|
||||
case PMC_CPU_INTEL_P6:
|
||||
case PMC_CPU_INTEL_CL:
|
||||
case PMC_CPU_INTEL_PII:
|
||||
case PMC_CPU_INTEL_PIII:
|
||||
case PMC_CPU_INTEL_PM:
|
||||
|
||||
p6_cputype = pmc_mdep->pmd_cputype;
|
||||
|
||||
pmc_mdep->pmd_npmc = P6_NPMCS;
|
||||
pmc_mdep->pmd_classes[1] = PMC_CLASS_P6;
|
||||
pmc_mdep->pmd_nclasspmcs[1] = 2;
|
||||
|
||||
pmc_mdep->pmd_init = p6_init;
|
||||
pmc_mdep->pmd_cleanup = p6_cleanup;
|
||||
pmc_mdep->pmd_switch_in = p6_switch_in;
|
||||
pmc_mdep->pmd_switch_out = p6_switch_out;
|
||||
pmc_mdep->pmd_read_pmc = p6_read_pmc;
|
||||
pmc_mdep->pmd_write_pmc = p6_write_pmc;
|
||||
pmc_mdep->pmd_config_pmc = p6_config_pmc;
|
||||
pmc_mdep->pmd_allocate_pmc = p6_allocate_pmc;
|
||||
pmc_mdep->pmd_release_pmc = p6_release_pmc;
|
||||
pmc_mdep->pmd_start_pmc = p6_start_pmc;
|
||||
pmc_mdep->pmd_stop_pmc = p6_stop_pmc;
|
||||
pmc_mdep->pmd_intr = p6_intr;
|
||||
pmc_mdep->pmd_describe = p6_describe;
|
||||
pmc_mdep->pmd_get_msr = p6_get_msr; /* i386 */
|
||||
|
||||
break;
|
||||
default:
|
||||
KASSERT(0,("[p6,%d] Unknown CPU type", __LINE__));
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user