1
2
3
4
5
6
7
8
9
10
11
12 #ifndef _I386_PCTR_H_
13 #define _I386_PCTR_H_
14
15 #include <sys/ioccom.h>
16
17 typedef u_quad_t pctrval;
18
19 #define PCTR_NUM 2
20
21 struct pctrst {
22 u_int pctr_fn[PCTR_NUM];
23 pctrval pctr_tsc;
24 pctrval pctr_hwc[PCTR_NUM];
25 pctrval pctr_idl;
26 };
27
28
29 #define P5CTR_K 0x40
30 #define P5CTR_U 0x80
31 #define P5CTR_C 0x100
32
33 #define P6CTR_U 0x010000
34 #define P6CTR_K 0x020000
35 #define P6CTR_E 0x040000
36 #define P6CTR_EN 0x400000
37 #define P6CTR_I 0x800000
38
39
40 #define P6CTR_UM_M 0x0800
41 #define P6CTR_UM_E 0x0400
42 #define P6CTR_UM_S 0x0200
43 #define P6CTR_UM_I 0x0100
44 #define P6CTR_UM_MESI (P6CTR_UM_M|P6CTR_UM_E|P6CTR_UM_S|P6CTR_UM_I)
45 #define P6CTR_UM_A 0x2000
46
47 #define P6CTR_CM_SHIFT 24
48
49
50 #define PCIOCRD _IOR('c', 1, struct pctrst)
51 #define PCIOCS0 _IOW('c', 8, unsigned int)
52 #define PCIOCS1 _IOW('c', 9, unsigned int)
53
54 #define _PATH_PCTR "/dev/pctr"
55
56 #define rdtsc() \
57 ({ \
58 pctrval v; \
59 __asm __volatile ("rdtsc" : "=A" (v)); \
60 v; \
61 })
62
63
64 #define rdpmc(ctr) \
65 ({ \
66 pctrval v; \
67 __asm __volatile ("rdpmc\n" \
68 "\tandl $0xff, %%edx" \
69 : "=A" (v) : "c" (ctr)); \
70 v; \
71 })
72
73 #ifdef _KERNEL
74
75 #define rdmsr(msr) \
76 ({ \
77 pctrval v; \
78 __asm __volatile ("rdmsr" : "=A" (v) : "c" (msr)); \
79 v; \
80 })
81
82 #define wrmsr(msr, v) \
83 __asm __volatile ("wrmsr" :: "A" ((u_quad_t) (v)), "c" (msr));
84
85 #endif
86 #endif