1d69e8502SGarrett Wollman /* 2d69e8502SGarrett Wollman * Copyright 1996 Massachusetts Institute of Technology 3d69e8502SGarrett Wollman * 4d69e8502SGarrett Wollman * Permission to use, copy, modify, and distribute this software and 5d69e8502SGarrett Wollman * its documentation for any purpose and without fee is hereby 6d69e8502SGarrett Wollman * granted, provided that both the above copyright notice and this 7d69e8502SGarrett Wollman * permission notice appear in all copies, that both the above 8d69e8502SGarrett Wollman * copyright notice and this permission notice appear in all 9d69e8502SGarrett Wollman * supporting documentation, and that the name of M.I.T. not be used 10d69e8502SGarrett Wollman * in advertising or publicity pertaining to distribution of the 11d69e8502SGarrett Wollman * software without specific, written prior permission. M.I.T. makes 12d69e8502SGarrett Wollman * no representations about the suitability of this software for any 13d69e8502SGarrett Wollman * purpose. It is provided "as is" without express or implied 14d69e8502SGarrett Wollman * warranty. 15d69e8502SGarrett Wollman * 16d69e8502SGarrett Wollman * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS 17d69e8502SGarrett Wollman * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, 18d69e8502SGarrett Wollman * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19d69e8502SGarrett Wollman * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 20d69e8502SGarrett Wollman * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21d69e8502SGarrett Wollman * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22d69e8502SGarrett Wollman * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 23d69e8502SGarrett Wollman * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24d69e8502SGarrett Wollman * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25d69e8502SGarrett Wollman * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 26d69e8502SGarrett Wollman * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27d69e8502SGarrett Wollman * SUCH DAMAGE. 28d69e8502SGarrett Wollman * 29c3aac50fSPeter Wemm * $FreeBSD$ 30d69e8502SGarrett Wollman */ 31d69e8502SGarrett Wollman 32d69e8502SGarrett Wollman /* 33d69e8502SGarrett Wollman * Interface to performance-monitoring counters for Intel Pentium and 34d69e8502SGarrett Wollman * Pentium Pro CPUs. 35d69e8502SGarrett Wollman */ 36d69e8502SGarrett Wollman 37d69e8502SGarrett Wollman #ifndef _MACHINE_PERFMON_H_ 38ebedb5adSBruce Evans #define _MACHINE_PERFMON_H_ 39d69e8502SGarrett Wollman 40664a31e4SPeter Wemm #ifndef _KERNEL 41ebedb5adSBruce Evans #include <sys/types.h> 42d69e8502SGarrett Wollman #endif 43ebedb5adSBruce Evans #include <sys/ioccom.h> 44d69e8502SGarrett Wollman 45d69e8502SGarrett Wollman #define NPMC 2 46d69e8502SGarrett Wollman 47d69e8502SGarrett Wollman #define PMIOSETUP _IOW('5', 1, struct pmc) 48d69e8502SGarrett Wollman #define PMIOGET _IOWR('5', 7, struct pmc) 49d69e8502SGarrett Wollman #define PMIOSTART _IOW('5', 2, int) 50d69e8502SGarrett Wollman #define PMIOSTOP _IOW('5', 3, int) 51d69e8502SGarrett Wollman #define PMIOREAD _IOWR('5', 4, struct pmc_data) 52d69e8502SGarrett Wollman #define PMIORESET _IOW('5', 5, int) 53d69e8502SGarrett Wollman #define PMIOTSTAMP _IOR('5', 6, struct pmc_tstamp) 54d69e8502SGarrett Wollman 55d69e8502SGarrett Wollman struct pmc { 56d69e8502SGarrett Wollman int pmc_num; 57d69e8502SGarrett Wollman union { 58d69e8502SGarrett Wollman struct { 59d69e8502SGarrett Wollman unsigned char pmcus_event; 60d69e8502SGarrett Wollman unsigned char pmcus_unit; 61d69e8502SGarrett Wollman unsigned char pmcus_flags; 62d69e8502SGarrett Wollman unsigned char pmcus_mask; 63d69e8502SGarrett Wollman } pmcu_s; 64d69e8502SGarrett Wollman unsigned int pmcu_val; 65d69e8502SGarrett Wollman } pmc_pmcu; 66d69e8502SGarrett Wollman }; 67d69e8502SGarrett Wollman 68d69e8502SGarrett Wollman #define PMC_ALL (-1) 69d69e8502SGarrett Wollman 70d69e8502SGarrett Wollman #define pmc_event pmc_pmcu.pmcu_s.pmcus_event 71d69e8502SGarrett Wollman #define pmc_unit pmc_pmcu.pmcu_s.pmcus_unit 72d69e8502SGarrett Wollman #define pmc_flags pmc_pmcu.pmcu_s.pmcus_flags 73d69e8502SGarrett Wollman #define pmc_mask pmc_pmcu.pmcu_s.pmcus_mask 74d69e8502SGarrett Wollman #define pmc_val pmc_pmcu.pmcu_val 75d69e8502SGarrett Wollman 76d69e8502SGarrett Wollman #define PMCF_USR 0x01 /* count events in user mode */ 77d69e8502SGarrett Wollman #define PMCF_OS 0x02 /* count events in kernel mode */ 78d69e8502SGarrett Wollman #define PMCF_E 0x04 /* use edge-detection mode */ 79d69e8502SGarrett Wollman #define PMCF_PC 0x08 /* PMx output pin control */ 80d69e8502SGarrett Wollman #define PMCF_INT 0x10 /* APIC interrupt enable (do not use) */ 81d69e8502SGarrett Wollman #define PMCF_EN 0x40 /* enable counters */ 82d69e8502SGarrett Wollman #define PMCF_INV 0x80 /* invert counter mask comparison */ 83d69e8502SGarrett Wollman 84d69e8502SGarrett Wollman #define PMCF_SYS_FLAGS (PMCF_INT | PMCF_EN) /* user cannot set */ 85d69e8502SGarrett Wollman 86d69e8502SGarrett Wollman struct pmc_data { 87d69e8502SGarrett Wollman int pmcd_num; 88d69e8502SGarrett Wollman quad_t pmcd_value; 89d69e8502SGarrett Wollman }; 90d69e8502SGarrett Wollman 91d69e8502SGarrett Wollman struct pmc_tstamp { 92d69e8502SGarrett Wollman int pmct_rate; 93d69e8502SGarrett Wollman quad_t pmct_value; 94d69e8502SGarrett Wollman }; 95d69e8502SGarrett Wollman 96664a31e4SPeter Wemm #ifndef _KERNEL 97d69e8502SGarrett Wollman 98d69e8502SGarrett Wollman #define _PATH_PERFMON "/dev/perfmon" 99d69e8502SGarrett Wollman 100d69e8502SGarrett Wollman #else 101d69e8502SGarrett Wollman 102d69e8502SGarrett Wollman /* 103d69e8502SGarrett Wollman * Intra-kernel interface to performance monitoring counters 104d69e8502SGarrett Wollman */ 105b63dc6adSAlfred Perlstein void perfmon_init(void); 106b63dc6adSAlfred Perlstein int perfmon_avail(void); 107b63dc6adSAlfred Perlstein int perfmon_setup(int, unsigned int); 108b63dc6adSAlfred Perlstein int perfmon_get(int, unsigned int *); 109b63dc6adSAlfred Perlstein int perfmon_fini(int); 110b63dc6adSAlfred Perlstein int perfmon_start(int); 111b63dc6adSAlfred Perlstein int perfmon_stop(int); 112b63dc6adSAlfred Perlstein int perfmon_read(int, quad_t *); 113b63dc6adSAlfred Perlstein int perfmon_reset(int); 114d69e8502SGarrett Wollman 115664a31e4SPeter Wemm #endif /* _KERNEL */ 116d69e8502SGarrett Wollman 117d69e8502SGarrett Wollman /* 118d69e8502SGarrett Wollman * Pentium Pro performance counters, from Appendix B. 119d69e8502SGarrett Wollman */ 120d69e8502SGarrett Wollman /* Data Cache Unit */ 121d69e8502SGarrett Wollman #define PMC6_DATA_MEM_REFS 0x43 122d69e8502SGarrett Wollman #define PMC6_DCU_LINES_IN 0x45 123d69e8502SGarrett Wollman #define PMC6_DCU_M_LINES_IN 0x46 124d69e8502SGarrett Wollman #define PMC6_DCU_M_LINES_OUT 0x47 125d69e8502SGarrett Wollman #define PMC6_DCU_MISS_OUTSTANDING 0x48 126d69e8502SGarrett Wollman 127d69e8502SGarrett Wollman /* Instruction Fetch Unit */ 128d69e8502SGarrett Wollman #define PMC6_IFU_IFETCH 0x80 129d69e8502SGarrett Wollman #define PMC6_IFU_IFETCH_MISS 0x81 130d69e8502SGarrett Wollman #define PMC6_ITLB_MISS 0x85 131d69e8502SGarrett Wollman #define PMC6_IFU_MEM_STALL 0x86 132d69e8502SGarrett Wollman #define PMC6_ILD_STALL 0x87 133d69e8502SGarrett Wollman 134d69e8502SGarrett Wollman /* L2 Cache */ 135d69e8502SGarrett Wollman #define PMC6_L2_IFETCH 0x28 /* MESI */ 136d69e8502SGarrett Wollman #define PMC6_L2_LD 0x29 /* MESI */ 137d69e8502SGarrett Wollman #define PMC6_L2_ST 0x2a /* MESI */ 138d69e8502SGarrett Wollman #define PMC6_L2_LINES_IN 0x24 139d69e8502SGarrett Wollman #define PMC6_L2_LINES_OUT 0x26 140d69e8502SGarrett Wollman #define PMC6_L2_M_LINES_INM 0x25 141d69e8502SGarrett Wollman #define PMC6_L2_M_LINES_OUTM 0x27 142d69e8502SGarrett Wollman #define PMC6_L2_RQSTS 0x2e /* MESI */ 143d69e8502SGarrett Wollman #define PMC6_L2_ADS 0x21 144d69e8502SGarrett Wollman #define PMC6_L2_DBUS_BUSY 0x22 145d69e8502SGarrett Wollman #define PMC6_L2_DBUS_BUSY_RD 0x23 146d69e8502SGarrett Wollman 147d69e8502SGarrett Wollman /* External Bus Logic */ 148d69e8502SGarrett Wollman #define PMC6_BUS_DRDY_CLOCKS 0x62 149d69e8502SGarrett Wollman #define PMC6_BUS_LOCK_CLOCKS 0x63 150d69e8502SGarrett Wollman #define PMC6_BUS_REQ_OUTSTANDING 0x60 151d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_BRD 0x65 152d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_RFO 0x66 153d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_WB 0x67 154d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_IFETCH 0x68 155d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_INVAL 0x69 156d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_PWR 0x6a 157d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_P 0x6b 158d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_IO 0x6c 159d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_DEF 0x6d 160d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_BURST 0x6e 161d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_ANY 0x70 162d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_MEM 0x6f 163d69e8502SGarrett Wollman #define PMC6_BUS_DATA_RCV 0x64 164d69e8502SGarrett Wollman #define PMC6_BUS_BNR_DRV 0x61 165d69e8502SGarrett Wollman #define PMC6_BUS_HIT_DRV 0x7a 166d69e8502SGarrett Wollman #define PMC6_BUS_HITM_DRV 0x7b 167d69e8502SGarrett Wollman #define PMC6_BUS_SNOOP_STALL 0x7e 168d69e8502SGarrett Wollman 169d69e8502SGarrett Wollman /* Floating Point Unit */ 170d69e8502SGarrett Wollman #define PMC6_FLOPS 0xc1 /* counter 0 only */ 171d69e8502SGarrett Wollman #define PMC6_FP_COMP_OPS_EXE 0x10 /* counter 0 only */ 172d69e8502SGarrett Wollman #define PMC6_FP_ASSIST 0x11 /* counter 1 only */ 173d69e8502SGarrett Wollman #define PMC6_MUL 0x12 /* counter 1 only */ 174d69e8502SGarrett Wollman #define PMC6_DIV 0x13 /* counter 1 only */ 175d69e8502SGarrett Wollman #define PMC6_CYCLES_DIV_BUSY 0x14 /* counter 0 only */ 176d69e8502SGarrett Wollman 177d69e8502SGarrett Wollman /* Memory Ordering */ 178d69e8502SGarrett Wollman #define PMC6_LD_BLOCKS 0x03 179d69e8502SGarrett Wollman #define PMC6_SB_DRAINS 0x04 180d69e8502SGarrett Wollman #define PMC6_MISALIGN_MEM_REF 0x05 181d69e8502SGarrett Wollman 182d69e8502SGarrett Wollman /* Instruction Decoding and Retirement */ 183d69e8502SGarrett Wollman #define PMC6_INST_RETIRED 0xc0 184d69e8502SGarrett Wollman #define PMC6_UOPS_RETIRED 0xc2 185d69e8502SGarrett Wollman #define PMC6_INST_DECODER 0xd0 /* (sic) */ 186d69e8502SGarrett Wollman 187d69e8502SGarrett Wollman /* Interrupts */ 188d69e8502SGarrett Wollman #define PMC6_HW_INT_RX 0xc8 189d69e8502SGarrett Wollman #define PMC6_CYCLES_INT_MASKED 0xc6 190d69e8502SGarrett Wollman #define PMC6_CYCLES_INT_PENDING_AND_MASKED 0xc7 191d69e8502SGarrett Wollman 192d69e8502SGarrett Wollman /* Branches */ 193d69e8502SGarrett Wollman #define PMC6_BR_INST_RETIRED 0xc4 194d69e8502SGarrett Wollman #define PMC6_BR_MISS_PRED_RETIRED 0xc5 195d69e8502SGarrett Wollman #define PMC6_BR_TAKEN_RETIRED 0xc9 196d69e8502SGarrett Wollman #define PMC6_BR_MISS_PRED_TAKEN_RET 0xca 197d69e8502SGarrett Wollman #define PMC6_BR_INST_DECODED 0xe0 198d69e8502SGarrett Wollman #define PMC6_BTB_MISSES 0xe2 199d69e8502SGarrett Wollman #define PMC6_BR_BOGUS 0xe4 200d69e8502SGarrett Wollman #define PMC6_BACLEARS 0xe6 201d69e8502SGarrett Wollman 202d69e8502SGarrett Wollman /* Stalls */ 203d69e8502SGarrett Wollman #define PMC6_RESOURCE_STALLS 0xa2 204d69e8502SGarrett Wollman #define PMC6_PARTIAL_RAT_STALLS 0xd2 205d69e8502SGarrett Wollman 206d69e8502SGarrett Wollman /* Segment Register Loads */ 207d69e8502SGarrett Wollman #define PMC6_SEGMENT_REG_LOADS 0x06 208d69e8502SGarrett Wollman 209d69e8502SGarrett Wollman /* Clocks */ 210d69e8502SGarrett Wollman #define PMC6_CPU_CLK_UNHALTED 0x79 211d69e8502SGarrett Wollman 212d69e8502SGarrett Wollman /* 213d69e8502SGarrett Wollman * Pentium Performance Counters 214d69e8502SGarrett Wollman * This list comes from the Harvard people, not Intel. 215d69e8502SGarrett Wollman */ 216d69e8502SGarrett Wollman #define PMC5_DATA_READ 0 217d69e8502SGarrett Wollman #define PMC5_DATA_WRITE 1 218d69e8502SGarrett Wollman #define PMC5_DATA_TLB_MISS 2 219d69e8502SGarrett Wollman #define PMC5_DATA_READ_MISS 3 220d69e8502SGarrett Wollman #define PMC5_DATA_WRITE_MISS 4 221d69e8502SGarrett Wollman #define PMC5_WRITE_M_E 5 222d69e8502SGarrett Wollman #define PMC5_DATA_LINES_WBACK 6 223d69e8502SGarrett Wollman #define PMC5_DATA_CACHE_SNOOP 7 224d69e8502SGarrett Wollman #define PMC5_DATA_CACHE_SNOOP_HIT 8 225d69e8502SGarrett Wollman #define PMC5_MEM_ACCESS_BOTH 9 226d69e8502SGarrett Wollman #define PMC5_BANK_CONFLICTS 10 227d69e8502SGarrett Wollman #define PMC5_MISALIGNED_DATA 11 228d69e8502SGarrett Wollman #define PMC5_INST_READ 12 229d69e8502SGarrett Wollman #define PMC5_INST_TLB_MISS 13 230d69e8502SGarrett Wollman #define PMC5_INST_CACHE_MISS 14 231d69e8502SGarrett Wollman #define PMC5_SEGMENT_REG_LOAD 15 232d69e8502SGarrett Wollman #define PMC5_BRANCHES 18 233d69e8502SGarrett Wollman #define PMC5_BTB_HITS 19 234d69e8502SGarrett Wollman #define PMC5_BRANCH_TAKEN 20 235d69e8502SGarrett Wollman #define PMC5_PIPELINE_FLUSH 21 236d69e8502SGarrett Wollman #define PMC5_INST_EXECUTED 22 237d69e8502SGarrett Wollman #define PMC5_INST_EXECUTED_V 23 238d69e8502SGarrett Wollman #define PMC5_BUS_UTILIZATION 24 239d69e8502SGarrett Wollman #define PMC5_WRITE_BACKUP_STALL 25 240d69e8502SGarrett Wollman #define PMC5_DATA_READ_STALL 26 241d69e8502SGarrett Wollman #define PMC5_WRITE_E_M_STALL 27 242d69e8502SGarrett Wollman #define PMC5_LOCKED_BUS 28 243d69e8502SGarrett Wollman #define PMC5_IO_CYCLE 29 244d69e8502SGarrett Wollman #define PMC5_NONCACHE_MEMORY 30 245d69e8502SGarrett Wollman #define PMC5_ADDR_GEN_INTERLOCK 31 246d69e8502SGarrett Wollman #define PMC5_FLOPS 34 247d69e8502SGarrett Wollman #define PMC5_BP0_MATCH 35 248d69e8502SGarrett Wollman #define PMC5_BP1_MATCH 36 249d69e8502SGarrett Wollman #define PMC5_BP2_MATCH 37 250d69e8502SGarrett Wollman #define PMC5_BP3_MATCH 38 251d69e8502SGarrett Wollman #define PMC5_HW_INTR 39 252d69e8502SGarrett Wollman #define PMC5_DATA_RW 40 253d69e8502SGarrett Wollman #define PMC5_DATA_RW_MISS 41 254d69e8502SGarrett Wollman 255ebedb5adSBruce Evans #endif /* !_MACHINE_PERFMON_H_ */ 256