13#ifndef __L4UTIL_PERFORM_H
14#define __L4UTIL_PERFORM_H
23#ifndef CONFIG_PERFORM_ONLY_PROTOTYPES
25#if ! (defined CPU_PENTIUM ^ defined CPU_P6 ^ defined CPU_K7)
27#error You must define your target architecture.
28#error Define EITHER CPU_PENTIUM for Intel Pentium or CPU_P6 for Intel PPro/PII/PIII.
40static inline void l4_i586_wrmsr(
unsigned reg,
unsigned long long*val){
41 unsigned long dummyeax, dummyecx, dummyedx;
44 ".byte 0xf; .byte 0x30\n"
45 :
"=a" (dummyeax),
"=d" (dummyedx),
"=c" (dummyecx)
46 :
"2" (reg),
"0" (*(unsigned *)val),
"1" (*((unsigned *)val+1))
55static inline void l4_i586_rdmsr(
unsigned reg,
unsigned long long*val){
59 ".byte 0xf; .byte 0x32\n"
60 :
"=a" (*(
unsigned *)val),
"=d" (*((
unsigned *)val+1)),
"=c" (dummy)
77l4_i586_reset_event_counter(
void){
78 asm volatile(
"xor %%rax, %%rax\n"
84 : : :
"cx",
"ax",
"dx"
89l4_i586_read_event_counter_long(
long long *counter0,
long long *counter1)
97 "mov %%rax, (%%rbx)\n"
98 "mov %%rdx, 4(%%rbx)\n"
101 "mov %%rax, (%%rsi)\n"
102 "mov %%rdx, 4(%%rsi)\n"
104 :
"b" (counter0),
"S" (counter1)
110l4_i586_read_event_counter(
int *counter0,
int *counter1)
112 asm volatile(
"push %%rdx \n"
113 ".byte 0x0f, 0x30 \n"
114 "mov $0x12, %%rcx \n"
115 ".byte 0x0f, 0x32 \n"
116 "mov %%rax, %%rbx \n"
117 "movl $0x13, %%rcx \n"
120 :
"=b" (*counter0),
"=a" (*counter1)
121 :
"1" (0),
"c" (0x11)
126l4_i586_select_event(
int event0,
int event1)
128 asm volatile(
".byte 0x0f, 0x30\n"
131 "a" (event0 + (event1 << 16)),
137#define P5_RD_MISS 0x003
138#define P5_WR_MISS 0x008
139#define P5_RW_MISS 0x029
140#define P5_EX_MISS 0x00e
142#define P5_D_WBACK 0x006
144#define P5_RW_TLB 0x002
145#define P5_EX_TLB 0x00d
147#define P5_A_STALL 0x01f
148#define P5_W_STALL 0x019
149#define P5_R_STALL 0x01a
150#define P5_X_STALL 0x01b
152#define P5_AGI_STALL 0x01f
154#define P5_PIPLINE_FLUSH 0x015
156#define P5_NON_CACHE_RD 0x01e
157#define P5_NCACHE_REFS 0x01e
158#define P5_LOCKED_BUS 0x01c
160#define P5_MEM2PIPE 0x009
161#define P5_BANK_CONF 0x00a
164#define P5_INSTRS_EX 0x016
165#define P5_INSTRS_EX_V 0x017
168#define P5_CNT_NOTHING (0x00 << 6)
169#define P5_CNT_EVENT_PL0 (0x01 << 6)
170#define P5_CNT_EVENT_PL3 (0x02 << 6)
171#define P5_CNT_EVENT (0x03 << 6)
172#define P5_CNT_CLOCKS_PL0 (0x05 << 6)
173#define P5_CNT_CLOCKS_PL3 (0x06 << 6)
174#define P5_CNT_CLOCKS (0x07 << 6)
229#define P6_DATA_MEM_REFS 0x43
230#define P6_DCU_LINES_IN 0x45
231#define P6_DCU_M_LINES_IN 0x46
232#define P6_DCU_M_LINES_OUT 0x47
233#define P6_DCU_MISS_OUTSTANDING 0x48
236#define P6_IFU_IFETCH 0x80
237#define P6_IFU_IFETCH_MISS 0x81
238#define P6_ITLB_MISS 0x85
239#define P6_IFU_MEM_STALL 0x86
240#define P6_ILD_STALL 0x87
243#define P6_L2_IFETCH 0x28
246#define P6_L2_LINES_IN 0x24
247#define P6_L2_LINES_OUT 0x26
248#define P6_L2_M_LINES_INM 0x25
249#define P6_L2_M_LINES_OUTM 0x27
250#define P6_L2_RQSTS 0x2e
251#define P6_L2_ADS 0x21
252#define P6_L2_DBUS_BUSY 0x22
253#define P6_L2_DBUS_BUSY_RD 0x23
256#define P6_BUS_DRDY_CLOCKS 0x62
257#define P6_BUS_LOCK_CLOCKS 0x63
258#define P6_BUS_REQ_OUTSTANDING 0x60
259#define P6_BUS_TRAN_BRD 0x65
260#define P6_BUS_TRAN_RFO 0x66
261#define P6_BUS_TRAN_WB 0x67
262#define P6_BUS_TRAN_IFETCH 0x68
263#define P6_BUS_TRAN_INVAL 0x69
264#define P6_BUS_TRAN_PWR 0x6a
265#define P6_BUS_TRANS_P 0x6b
266#define P6_BUS_TRANS_IO 0x6c
267#define P6_BUS_TRAN_DEF 0x6d
268#define P6_BUS_TRAN_BURST 0x6e
269#define P6_BUS_TRAN_ANY 0x70
270#define P6_BUS_TRAN_MEM 0x6f
271#define P6_BUS_DATA_RCV 0x64
272#define P6_BUS_BNR_DRV 0x61
273#define P6_BUS_HIT_DRV 0x7a
274#define P6_BUS_HITM_DRV 0x7b
275#define P6_BUS_SNOOP_STALL 0x7e
279#define P6_FP_COMP_OPS 0x10
280#define P6_FP_ASSIST 0x11
283#define P6_CYCLES_DIV_BUSY 0x14
286#define P6_LD_BLOCKS 0x03
287#define P6_SB_DRAINS 0x04
288#define P6_MISALING_MEM_REF 0x05
291#define P6_INST_RETIRED 0xc0
292#define P6_UOPS_RETIRED 0xc2
293#define P6_INST_DECODER 0xd0
296#define P6_HW_INT_RX 0xc8
297#define P6_CYCLES_INT_MASKED 0xc6
298#define P6_CYCLES_INT_PENDING_AND_MASKED 0xc7
301#define P6_BR_INST_RETIRED 0xc4
302#define P6_BR_MISS_PRED_RETIRED 0xc5
303#define P6_BR_TAKEN_RETIRED 0xc9
304#define P6_BR_MISS_PRED_TAKEN_RET 0xca
305#define P6_BR_INST_DECODED 0xe0
306#define P6_BTB_MISSES 0xe2
307#define P6_BR_BOGUS 0xe4
308#define P6_BACLEARS 0xe6
311#define P6_RESOURCE_STALLS 0xa2
312#define P6_PARTIAL_RAT_STALLS 0xd2
315#define P6_SEGMENT_REG_LOADS 0x06
318#define P6_CPU_CLK_UNHALTED 0x79
321#define P6_UNIT_M 0x0800
322#define P6_UNIT_E 0x0400
323#define P6_UNIT_S 0x0200
324#define P6_UNIT_I 0x0100
325#define P6_UNIT_MESI 0x0f00
327#define P6_UNIT_SELF 0x0000
328#define P6_UNIT_ANY 0x2000
339#define P6CNT_U 0x010000
340#define P6CNT_K 0x020000
341#define P6CNT_E 0x040000
342#define P6CNT_PC 0x080000
343#define P6CNT_IE 0x100000
344#define P6CNT_F 0x200000
345#define P6CNT_EN 0x400000
346#define P6CNT_IV 0x800000
363#define MSR_P6_EVNTSEL0 0x186
364#define MSR_P6_EVNTSEL1 0x187
365#define MSR_P6_PERFCTR0 0xc1
366#define MSR_P6_PERFCTR1 0xc2
374#define l4_i686_rdpmc(cntr, res_p) \
376 "mov %2, %%rcx # put counter number in \n\
377 .byte 0xf; .byte 0x33 # RDPMC instruction \n\
378 mov %%rdx, %1 # High order 32 bits \n\
379 mov %%rax, %0 # Low order 32 bits" \
380 : "=g" (*(int *)(res_p)), "=g" (*(((int *)res_p)+1)) \
382 : "ecx", "eax", "edx")
384static inline l4_uint32_t l4_i686_rdpmc_32(
int cntr){
387 __asm__ __volatile__(
388 ".byte 0xf; .byte 0x33 # RDPMC instruction"
391 :
"rcx",
"rax",
"rdx");
395static inline void l4_i686_select_perfctr_event(
int counter,
396 unsigned long long val){
397 l4_i586_wrmsr(MSR_P6_EVNTSEL0+counter, &val);
400static inline void l4_i686_select_perfctr0_event(
long long *val){
402 "mov $MSR_P6_EVNTSEL0, %%rcx\n"
403 "mov (%%rbx), %%rax\n"
404 "mov 4(%%rbx), %%rdx\n"
410 :
"ax",
"cx",
"dx",
"bx"
418#define K7CNT_U 0x010000
419#define K7CNT_K 0x020000
420#define K7CNT_E 0x040000
421#define K7CNT_PC 0x080000
422#define K7CNT_IE 0x100000
423#define K7CNT_F 0x200000
424#define K7CNT_EN 0x400000
425#define K7CNT_IV 0x800000
427#define MSR_K7_EVNTSEL0 0xC0010000
428#define MSR_K7_EVNTSEL1 0xC0010001
429#define MSR_K7_EVNTSEL2 0xC0010002
430#define MSR_K7_EVNTSEL3 0xC0010003
431#define MSR_K7_PERFCTR0 0xC0010004
432#define MSR_K7_PERFCTR1 0xC0010005
433#define MSR_K7_PERFCTR2 0xC0010006
434#define MSR_K7_PERFCTR3 0xC0010007
L4 compiler related defines.
unsigned int l4_uint32_t
Unsigned 32bit value.
#define __END_DECLS
End section with C types and functions.
#define __BEGIN_DECLS
Start section with C types and functions.
Common L4 ABI Data Types.