pmc_mdep.h (1fa7f10bac396ef8fe623f3845b7d9280e078abd) | pmc_mdep.h (ebccf1e3a6b11b97cbf5f813dd76636e892a9035) |
---|---|
1/*- | 1/*- |
2 * Copyright (c) 2003-2008 Joseph Koshy 3 * Copyright (c) 2007 The FreeBSD Foundation | 2 * Copyright (c) 2003, Joseph Koshy |
4 * All rights reserved. 5 * | 3 * All rights reserved. 4 * |
6 * Portions of this software were developed by A. Joseph Koshy under 7 * sponsorship from the FreeBSD Foundation and Google, Inc. 8 * | |
9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. --- 13 unchanged lines hidden (view full) --- 30 * $FreeBSD$ 31 */ 32 33/* Machine dependent interfaces */ 34 35#ifndef _MACHINE_PMC_MDEP_H 36#define _MACHINE_PMC_MDEP_H 1 37 | 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. --- 13 unchanged lines hidden (view full) --- 26 * $FreeBSD$ 27 */ 28 29/* Machine dependent interfaces */ 30 31#ifndef _MACHINE_PMC_MDEP_H 32#define _MACHINE_PMC_MDEP_H 1 33 |
38#ifdef _KERNEL 39struct pmc_mdep; 40#endif | 34#include <sys/pmc.h> |
41 | 35 |
42#include <dev/hwpmc/hwpmc_amd.h> 43#include <dev/hwpmc/hwpmc_core.h> 44#include <dev/hwpmc/hwpmc_piv.h> 45#include <dev/hwpmc/hwpmc_tsc.h> 46#include <dev/hwpmc/hwpmc_uncore.h> | 36/* AMD K7 PMCs */ |
47 | 37 |
48/* 49 * Intel processors implementing V2 and later of the Intel performance 50 * measurement architecture have PMCs of the following classes: TSC, 51 * IAF, IAP, UCF and UCP. 52 */ 53#define PMC_MDEP_CLASS_INDEX_TSC 0 54#define PMC_MDEP_CLASS_INDEX_K8 1 55#define PMC_MDEP_CLASS_INDEX_P4 1 56#define PMC_MDEP_CLASS_INDEX_IAP 1 57#define PMC_MDEP_CLASS_INDEX_IAF 2 58#define PMC_MDEP_CLASS_INDEX_UCP 3 59#define PMC_MDEP_CLASS_INDEX_UCF 4 | 38#define K8_NPMCS 5 /* 1 TSC + 4 PMCs */ |
60 | 39 |
61/* 62 * On the amd64 platform we support the following PMCs. 63 * 64 * TSC The timestamp counter 65 * K8 AMD Athlon64 and Opteron PMCs in 64 bit mode. 66 * PIV Intel P4/HTT and P4/EMT64 67 * IAP Intel Core/Core2/Atom CPUs in 64 bits mode. 68 * IAF Intel fixed-function PMCs in Core2 and later CPUs. 69 * UCP Intel Uncore programmable PMCs. 70 * UCF Intel Uncore fixed-function PMCs. 71 */ | 40#define K8_PMC_COUNTERMASK 0xFF000000 41#define K8_PMC_TO_COUNTER(x) (((x) << 24) & K8_PMC_COUNTERMASK) 42#define K8_PMC_INVERT (1 << 23) 43#define K8_PMC_ENABLE (1 << 22) 44#define K8_PMC_INT (1 << 20) 45#define K8_PMC_PC (1 << 19) 46#define K8_PMC_EDGE (1 << 18) 47#define K8_PMC_OS (1 << 17) 48#define K8_PMC_USR (1 << 16) |
72 | 49 |
73union pmc_md_op_pmcallocate { 74 struct pmc_md_amd_op_pmcallocate pm_amd; 75 struct pmc_md_iaf_op_pmcallocate pm_iaf; 76 struct pmc_md_iap_op_pmcallocate pm_iap; 77 struct pmc_md_ucf_op_pmcallocate pm_ucf; 78 struct pmc_md_ucp_op_pmcallocate pm_ucp; 79 struct pmc_md_p4_op_pmcallocate pm_p4; 80 uint64_t __pad[4]; 81}; | 50#define K8_PMC_UNITMASK_M 0x10 51#define K8_PMC_UNITMASK_O 0x08 52#define K8_PMC_UNITMASK_E 0x04 53#define K8_PMC_UNITMASK_S 0x02 54#define K8_PMC_UNITMASK_I 0x01 55#define K8_PMC_UNITMASK_MOESI 0x1F |
82 | 56 |
83/* Logging */ 84#define PMCLOG_READADDR PMCLOG_READ64 85#define PMCLOG_EMITADDR PMCLOG_EMIT64 | 57#define K8_PMC_UNITMASK 0xFF00 58#define K8_PMC_EVENTMASK 0x00FF 59#define K8_PMC_TO_UNITMASK(x) (((x) << 8) & K8_PMC_UNITMASK) 60#define K8_PMC_TO_EVENTMASK(x) ((x) & 0xFF) 61#define K8_VALID_BITS (K8_PMC_COUNTERMASK | K8_PMC_INVERT | \ 62 K8_PMC_ENABLE | K8_PMC_INT | K8_PMC_PC | K8_PMC_EDGE | K8_PMC_OS | \ 63 K8_PMC_USR | K8_PMC_UNITMASK | K8_PMC_EVENTMASK) |
86 | 64 |
87#ifdef _KERNEL | 65#ifdef _KERNEL |
88 | 66 |
89union pmc_md_pmc { 90 struct pmc_md_amd_pmc pm_amd; 91 struct pmc_md_iaf_pmc pm_iaf; 92 struct pmc_md_iap_pmc pm_iap; 93 struct pmc_md_ucf_pmc pm_ucf; 94 struct pmc_md_ucp_pmc pm_ucp; 95 struct pmc_md_p4_pmc pm_p4; 96}; 97 98#define PMC_TRAPFRAME_TO_PC(TF) ((TF)->tf_rip) 99#define PMC_TRAPFRAME_TO_FP(TF) ((TF)->tf_rbp) 100#define PMC_TRAPFRAME_TO_USER_SP(TF) ((TF)->tf_rsp) 101#define PMC_TRAPFRAME_TO_KERNEL_SP(TF) ((TF)->tf_rsp) 102 103#define PMC_AT_FUNCTION_PROLOGUE_PUSH_BP(I) \ 104 (((I) & 0xffffffff) == 0xe5894855) /* pushq %rbp; movq %rsp,%rbp */ 105#define PMC_AT_FUNCTION_PROLOGUE_MOV_SP_BP(I) \ 106 (((I) & 0x00ffffff) == 0x00e58948) /* movq %rsp,%rbp */ 107#define PMC_AT_FUNCTION_EPILOGUE_RET(I) \ 108 (((I) & 0xFF) == 0xC3) /* ret */ 109 110#define PMC_IN_TRAP_HANDLER(PC) \ 111 ((PC) >= (uintptr_t) start_exceptions && \ 112 (PC) < (uintptr_t) end_exceptions) 113 114#define PMC_IN_KERNEL_STACK(S,START,END) \ 115 ((S) >= (START) && (S) < (END)) 116#define PMC_IN_KERNEL(va) (((va) >= DMAP_MIN_ADDRESS && \ 117 (va) < DMAP_MAX_ADDRESS) || ((va) >= VM_MIN_KERNEL_ADDRESS && \ 118 (va) < VM_MAX_KERNEL_ADDRESS)) 119 120#define PMC_IN_USERSPACE(va) ((va) <= VM_MAXUSER_ADDRESS) 121 | |
122/* 123 * Prototypes 124 */ 125 | 67/* 68 * Prototypes 69 */ 70 |
126void start_exceptions(void), end_exceptions(void); 127 | 71#if defined(__amd64__) |
128struct pmc_mdep *pmc_amd_initialize(void); | 72struct pmc_mdep *pmc_amd_initialize(void); |
129void pmc_amd_finalize(struct pmc_mdep *_md); 130struct pmc_mdep *pmc_intel_initialize(void); 131void pmc_intel_finalize(struct pmc_mdep *_md); | 73#endif /* defined(__i386__) */ |
132 133#endif /* _KERNEL */ 134#endif /* _MACHINE_PMC_MDEP_H */ | 74 75#endif /* _KERNEL */ 76#endif /* _MACHINE_PMC_MDEP_H */ |