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