186cb007fSWarner Losh /*- 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 */ 29d69e8502SGarrett Wollman 30d69e8502SGarrett Wollman /* 31d69e8502SGarrett Wollman * Interface to performance-monitoring counters for Intel Pentium and 32d69e8502SGarrett Wollman * Pentium Pro CPUs. 33d69e8502SGarrett Wollman */ 34d69e8502SGarrett Wollman 35d69e8502SGarrett Wollman #ifndef _MACHINE_PERFMON_H_ 36ebedb5adSBruce Evans #define _MACHINE_PERFMON_H_ 37d69e8502SGarrett Wollman 38664a31e4SPeter Wemm #ifndef _KERNEL 39ebedb5adSBruce Evans #include <sys/types.h> 40d69e8502SGarrett Wollman #endif 41ebedb5adSBruce Evans #include <sys/ioccom.h> 42d69e8502SGarrett Wollman 43d69e8502SGarrett Wollman #define NPMC 2 44d69e8502SGarrett Wollman 45d69e8502SGarrett Wollman #define PMIOSETUP _IOW('5', 1, struct pmc) 46d69e8502SGarrett Wollman #define PMIOGET _IOWR('5', 7, struct pmc) 47d69e8502SGarrett Wollman #define PMIOSTART _IOW('5', 2, int) 48d69e8502SGarrett Wollman #define PMIOSTOP _IOW('5', 3, int) 49d69e8502SGarrett Wollman #define PMIOREAD _IOWR('5', 4, struct pmc_data) 50d69e8502SGarrett Wollman #define PMIORESET _IOW('5', 5, int) 51d69e8502SGarrett Wollman #define PMIOTSTAMP _IOR('5', 6, struct pmc_tstamp) 52d69e8502SGarrett Wollman 53d69e8502SGarrett Wollman struct pmc { 54d69e8502SGarrett Wollman int pmc_num; 55d69e8502SGarrett Wollman union { 56d69e8502SGarrett Wollman struct { 57d69e8502SGarrett Wollman unsigned char pmcus_event; 58d69e8502SGarrett Wollman unsigned char pmcus_unit; 59d69e8502SGarrett Wollman unsigned char pmcus_flags; 60d69e8502SGarrett Wollman unsigned char pmcus_mask; 61d69e8502SGarrett Wollman } pmcu_s; 62d69e8502SGarrett Wollman unsigned int pmcu_val; 63d69e8502SGarrett Wollman } pmc_pmcu; 64d69e8502SGarrett Wollman }; 65d69e8502SGarrett Wollman 66d69e8502SGarrett Wollman #define PMC_ALL (-1) 67d69e8502SGarrett Wollman 68d69e8502SGarrett Wollman #define pmc_event pmc_pmcu.pmcu_s.pmcus_event 69d69e8502SGarrett Wollman #define pmc_unit pmc_pmcu.pmcu_s.pmcus_unit 70d69e8502SGarrett Wollman #define pmc_flags pmc_pmcu.pmcu_s.pmcus_flags 71d69e8502SGarrett Wollman #define pmc_mask pmc_pmcu.pmcu_s.pmcus_mask 72d69e8502SGarrett Wollman #define pmc_val pmc_pmcu.pmcu_val 73d69e8502SGarrett Wollman 74d69e8502SGarrett Wollman #define PMCF_USR 0x01 /* count events in user mode */ 75d69e8502SGarrett Wollman #define PMCF_OS 0x02 /* count events in kernel mode */ 76d69e8502SGarrett Wollman #define PMCF_E 0x04 /* use edge-detection mode */ 77d69e8502SGarrett Wollman #define PMCF_PC 0x08 /* PMx output pin control */ 78d69e8502SGarrett Wollman #define PMCF_INT 0x10 /* APIC interrupt enable (do not use) */ 79d69e8502SGarrett Wollman #define PMCF_EN 0x40 /* enable counters */ 80d69e8502SGarrett Wollman #define PMCF_INV 0x80 /* invert counter mask comparison */ 81d69e8502SGarrett Wollman 82d69e8502SGarrett Wollman #define PMCF_SYS_FLAGS (PMCF_INT | PMCF_EN) /* user cannot set */ 83d69e8502SGarrett Wollman 84d69e8502SGarrett Wollman struct pmc_data { 85d69e8502SGarrett Wollman int pmcd_num; 86d69e8502SGarrett Wollman quad_t pmcd_value; 87d69e8502SGarrett Wollman }; 88d69e8502SGarrett Wollman 89d69e8502SGarrett Wollman struct pmc_tstamp { 90d69e8502SGarrett Wollman int pmct_rate; 91d69e8502SGarrett Wollman quad_t pmct_value; 92d69e8502SGarrett Wollman }; 93d69e8502SGarrett Wollman 94664a31e4SPeter Wemm #ifndef _KERNEL 95d69e8502SGarrett Wollman 96d69e8502SGarrett Wollman #define _PATH_PERFMON "/dev/perfmon" 97d69e8502SGarrett Wollman 98d69e8502SGarrett Wollman #else 99d69e8502SGarrett Wollman 100d69e8502SGarrett Wollman /* 101d69e8502SGarrett Wollman * Intra-kernel interface to performance monitoring counters 102d69e8502SGarrett Wollman */ 103b63dc6adSAlfred Perlstein void perfmon_init(void); 104b63dc6adSAlfred Perlstein int perfmon_avail(void); 105b63dc6adSAlfred Perlstein int perfmon_setup(int, unsigned int); 106b63dc6adSAlfred Perlstein int perfmon_get(int, unsigned int *); 107b63dc6adSAlfred Perlstein int perfmon_fini(int); 108b63dc6adSAlfred Perlstein int perfmon_start(int); 109b63dc6adSAlfred Perlstein int perfmon_stop(int); 110b63dc6adSAlfred Perlstein int perfmon_read(int, quad_t *); 111b63dc6adSAlfred Perlstein int perfmon_reset(int); 112d69e8502SGarrett Wollman 113664a31e4SPeter Wemm #endif /* _KERNEL */ 114d69e8502SGarrett Wollman 115d69e8502SGarrett Wollman /* 116d69e8502SGarrett Wollman * Pentium Pro performance counters, from Appendix B. 117d69e8502SGarrett Wollman */ 118d69e8502SGarrett Wollman /* Data Cache Unit */ 119d69e8502SGarrett Wollman #define PMC6_DATA_MEM_REFS 0x43 120d69e8502SGarrett Wollman #define PMC6_DCU_LINES_IN 0x45 121d69e8502SGarrett Wollman #define PMC6_DCU_M_LINES_IN 0x46 122d69e8502SGarrett Wollman #define PMC6_DCU_M_LINES_OUT 0x47 123d69e8502SGarrett Wollman #define PMC6_DCU_MISS_OUTSTANDING 0x48 124d69e8502SGarrett Wollman 125d69e8502SGarrett Wollman /* Instruction Fetch Unit */ 126d69e8502SGarrett Wollman #define PMC6_IFU_IFETCH 0x80 127d69e8502SGarrett Wollman #define PMC6_IFU_IFETCH_MISS 0x81 128d69e8502SGarrett Wollman #define PMC6_ITLB_MISS 0x85 129d69e8502SGarrett Wollman #define PMC6_IFU_MEM_STALL 0x86 130d69e8502SGarrett Wollman #define PMC6_ILD_STALL 0x87 131d69e8502SGarrett Wollman 132d69e8502SGarrett Wollman /* L2 Cache */ 133d69e8502SGarrett Wollman #define PMC6_L2_IFETCH 0x28 /* MESI */ 134d69e8502SGarrett Wollman #define PMC6_L2_LD 0x29 /* MESI */ 135d69e8502SGarrett Wollman #define PMC6_L2_ST 0x2a /* MESI */ 136d69e8502SGarrett Wollman #define PMC6_L2_LINES_IN 0x24 137d69e8502SGarrett Wollman #define PMC6_L2_LINES_OUT 0x26 138d69e8502SGarrett Wollman #define PMC6_L2_M_LINES_INM 0x25 139d69e8502SGarrett Wollman #define PMC6_L2_M_LINES_OUTM 0x27 140d69e8502SGarrett Wollman #define PMC6_L2_RQSTS 0x2e /* MESI */ 141d69e8502SGarrett Wollman #define PMC6_L2_ADS 0x21 142d69e8502SGarrett Wollman #define PMC6_L2_DBUS_BUSY 0x22 143d69e8502SGarrett Wollman #define PMC6_L2_DBUS_BUSY_RD 0x23 144d69e8502SGarrett Wollman 145d69e8502SGarrett Wollman /* External Bus Logic */ 146d69e8502SGarrett Wollman #define PMC6_BUS_DRDY_CLOCKS 0x62 147d69e8502SGarrett Wollman #define PMC6_BUS_LOCK_CLOCKS 0x63 148d69e8502SGarrett Wollman #define PMC6_BUS_REQ_OUTSTANDING 0x60 149d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_BRD 0x65 150d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_RFO 0x66 151d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_WB 0x67 152d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_IFETCH 0x68 153d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_INVAL 0x69 154d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_PWR 0x6a 155d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_P 0x6b 156d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_IO 0x6c 157d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_DEF 0x6d 158d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_BURST 0x6e 159d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_ANY 0x70 160d69e8502SGarrett Wollman #define PMC6_BUS_TRAN_MEM 0x6f 161d69e8502SGarrett Wollman #define PMC6_BUS_DATA_RCV 0x64 162d69e8502SGarrett Wollman #define PMC6_BUS_BNR_DRV 0x61 163d69e8502SGarrett Wollman #define PMC6_BUS_HIT_DRV 0x7a 164d69e8502SGarrett Wollman #define PMC6_BUS_HITM_DRV 0x7b 165d69e8502SGarrett Wollman #define PMC6_BUS_SNOOP_STALL 0x7e 166d69e8502SGarrett Wollman 167d69e8502SGarrett Wollman /* Floating Point Unit */ 168d69e8502SGarrett Wollman #define PMC6_FLOPS 0xc1 /* counter 0 only */ 169d69e8502SGarrett Wollman #define PMC6_FP_COMP_OPS_EXE 0x10 /* counter 0 only */ 170d69e8502SGarrett Wollman #define PMC6_FP_ASSIST 0x11 /* counter 1 only */ 171d69e8502SGarrett Wollman #define PMC6_MUL 0x12 /* counter 1 only */ 172d69e8502SGarrett Wollman #define PMC6_DIV 0x13 /* counter 1 only */ 173d69e8502SGarrett Wollman #define PMC6_CYCLES_DIV_BUSY 0x14 /* counter 0 only */ 174d69e8502SGarrett Wollman 175d69e8502SGarrett Wollman /* Memory Ordering */ 176d69e8502SGarrett Wollman #define PMC6_LD_BLOCKS 0x03 177d69e8502SGarrett Wollman #define PMC6_SB_DRAINS 0x04 178d69e8502SGarrett Wollman #define PMC6_MISALIGN_MEM_REF 0x05 179d69e8502SGarrett Wollman 180d69e8502SGarrett Wollman /* Instruction Decoding and Retirement */ 181d69e8502SGarrett Wollman #define PMC6_INST_RETIRED 0xc0 182d69e8502SGarrett Wollman #define PMC6_UOPS_RETIRED 0xc2 183d69e8502SGarrett Wollman #define PMC6_INST_DECODER 0xd0 /* (sic) */ 184d69e8502SGarrett Wollman 185d69e8502SGarrett Wollman /* Interrupts */ 186d69e8502SGarrett Wollman #define PMC6_HW_INT_RX 0xc8 187d69e8502SGarrett Wollman #define PMC6_CYCLES_INT_MASKED 0xc6 188d69e8502SGarrett Wollman #define PMC6_CYCLES_INT_PENDING_AND_MASKED 0xc7 189d69e8502SGarrett Wollman 190d69e8502SGarrett Wollman /* Branches */ 191d69e8502SGarrett Wollman #define PMC6_BR_INST_RETIRED 0xc4 192d69e8502SGarrett Wollman #define PMC6_BR_MISS_PRED_RETIRED 0xc5 193d69e8502SGarrett Wollman #define PMC6_BR_TAKEN_RETIRED 0xc9 194d69e8502SGarrett Wollman #define PMC6_BR_MISS_PRED_TAKEN_RET 0xca 195d69e8502SGarrett Wollman #define PMC6_BR_INST_DECODED 0xe0 196d69e8502SGarrett Wollman #define PMC6_BTB_MISSES 0xe2 197d69e8502SGarrett Wollman #define PMC6_BR_BOGUS 0xe4 198d69e8502SGarrett Wollman #define PMC6_BACLEARS 0xe6 199d69e8502SGarrett Wollman 200d69e8502SGarrett Wollman /* Stalls */ 201d69e8502SGarrett Wollman #define PMC6_RESOURCE_STALLS 0xa2 202d69e8502SGarrett Wollman #define PMC6_PARTIAL_RAT_STALLS 0xd2 203d69e8502SGarrett Wollman 204d69e8502SGarrett Wollman /* Segment Register Loads */ 205d69e8502SGarrett Wollman #define PMC6_SEGMENT_REG_LOADS 0x06 206d69e8502SGarrett Wollman 207d69e8502SGarrett Wollman /* Clocks */ 208d69e8502SGarrett Wollman #define PMC6_CPU_CLK_UNHALTED 0x79 209d69e8502SGarrett Wollman 210d69e8502SGarrett Wollman /* 211d69e8502SGarrett Wollman * Pentium Performance Counters 212d69e8502SGarrett Wollman * This list comes from the Harvard people, not Intel. 213d69e8502SGarrett Wollman */ 214d69e8502SGarrett Wollman #define PMC5_DATA_READ 0 215d69e8502SGarrett Wollman #define PMC5_DATA_WRITE 1 216d69e8502SGarrett Wollman #define PMC5_DATA_TLB_MISS 2 217d69e8502SGarrett Wollman #define PMC5_DATA_READ_MISS 3 218d69e8502SGarrett Wollman #define PMC5_DATA_WRITE_MISS 4 219d69e8502SGarrett Wollman #define PMC5_WRITE_M_E 5 220d69e8502SGarrett Wollman #define PMC5_DATA_LINES_WBACK 6 221d69e8502SGarrett Wollman #define PMC5_DATA_CACHE_SNOOP 7 222d69e8502SGarrett Wollman #define PMC5_DATA_CACHE_SNOOP_HIT 8 223d69e8502SGarrett Wollman #define PMC5_MEM_ACCESS_BOTH 9 224d69e8502SGarrett Wollman #define PMC5_BANK_CONFLICTS 10 225d69e8502SGarrett Wollman #define PMC5_MISALIGNED_DATA 11 226d69e8502SGarrett Wollman #define PMC5_INST_READ 12 227d69e8502SGarrett Wollman #define PMC5_INST_TLB_MISS 13 228d69e8502SGarrett Wollman #define PMC5_INST_CACHE_MISS 14 229d69e8502SGarrett Wollman #define PMC5_SEGMENT_REG_LOAD 15 230d69e8502SGarrett Wollman #define PMC5_BRANCHES 18 231d69e8502SGarrett Wollman #define PMC5_BTB_HITS 19 232d69e8502SGarrett Wollman #define PMC5_BRANCH_TAKEN 20 233d69e8502SGarrett Wollman #define PMC5_PIPELINE_FLUSH 21 234d69e8502SGarrett Wollman #define PMC5_INST_EXECUTED 22 235d69e8502SGarrett Wollman #define PMC5_INST_EXECUTED_V 23 236d69e8502SGarrett Wollman #define PMC5_BUS_UTILIZATION 24 237d69e8502SGarrett Wollman #define PMC5_WRITE_BACKUP_STALL 25 238d69e8502SGarrett Wollman #define PMC5_DATA_READ_STALL 26 239d69e8502SGarrett Wollman #define PMC5_WRITE_E_M_STALL 27 240d69e8502SGarrett Wollman #define PMC5_LOCKED_BUS 28 241d69e8502SGarrett Wollman #define PMC5_IO_CYCLE 29 242d69e8502SGarrett Wollman #define PMC5_NONCACHE_MEMORY 30 243d69e8502SGarrett Wollman #define PMC5_ADDR_GEN_INTERLOCK 31 244d69e8502SGarrett Wollman #define PMC5_FLOPS 34 245d69e8502SGarrett Wollman #define PMC5_BP0_MATCH 35 246d69e8502SGarrett Wollman #define PMC5_BP1_MATCH 36 247d69e8502SGarrett Wollman #define PMC5_BP2_MATCH 37 248d69e8502SGarrett Wollman #define PMC5_BP3_MATCH 38 249d69e8502SGarrett Wollman #define PMC5_HW_INTR 39 250d69e8502SGarrett Wollman #define PMC5_DATA_RW 40 251d69e8502SGarrett Wollman #define PMC5_DATA_RW_MISS 41 252d69e8502SGarrett Wollman 253ebedb5adSBruce Evans #endif /* !_MACHINE_PERFMON_H_ */ 254