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