L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
perform.h
Go to the documentation of this file.
1
7/*
8 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
9 * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
10 * economic rights: Technische Universität Dresden (Germany)
11 * License: see LICENSE.spdx (in this directory or the directories above)
12 */
13#ifndef __L4UTIL_PERFORM_H
14#define __L4UTIL_PERFORM_H
15
16#include <l4/sys/types.h>
17#include <l4/sys/compiler.h>
18
20
21extern const char*strp6pmc_event(l4_uint32_t event);
22
23#ifndef CONFIG_PERFORM_ONLY_PROTOTYPES
24
25#if ! (defined CPU_PENTIUM ^ defined CPU_P6 ^ defined CPU_K7)
26
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.
29
30#else
31
32/* P5/P6/K7 section */
33
34/* Makros for access to model specific registers (MSR) */
35
36/* Write the 64-Bit Model Specific Register. First argument is the register,
37 second the 64-Bit value. This can only be called at priviledge level 0.
38 With L4, the kernel emulates the WRMSR when calling in PL 3.
39 */
40static inline void l4_i586_wrmsr(unsigned reg,unsigned long long*val){
41 unsigned long dummyeax, dummyecx, dummyedx;
42
43 asm volatile(
44 ".byte 0xf; .byte 0x30\n" /* wrmsr */
45 : "=a" (dummyeax), "=d" (dummyedx), "=c" (dummyecx)
46 : "2" (reg), "0" (*(unsigned *)val), "1" (*((unsigned *)val+1))
47 );
48}
49
50/* Read the 64-Bit Model Specific Register. First argument is the register,
51 second the address to a 64-Bit value. This can only be called at
52 priviledge level 0. With L4, the kernel emulates the RDMSR when calling
53 in PL 3.
54 */
55static inline void l4_i586_rdmsr(unsigned reg,unsigned long long*val){
56 unsigned dummy;
57
58 asm volatile(
59 ".byte 0xf; .byte 0x32\n" /* rdmsr */
60 : "=a" (*(unsigned *)val), "=d" (*((unsigned *)val+1)), "=c" (dummy)
61 : "2" (reg)
62 );
63}
64
65
66#ifdef CPU_PENTIUM
67/* Pentium section */
68
69/* functions and events defined here are only usable at Pentium
70 Processors. P6 architecture does NOT support this kind of measuring and
71 these events. P6 architecture has its own counters and its own events.
72 See P6-section for details. */
73
74/* from l4linux/arch/l4-i386/include/perform.h */
75
76static inline void
77l4_i586_reset_event_counter(void){
78 asm volatile("xor %%rax, %%rax\n"
79 "xor %%rdx, %%rdx\n"
80 "mov $0x12, %%rcx\n"
81 ".byte 0x0f, 0x30\n"
82 "movl $0x13, %%rcx\n"
83 ".byte 0x0f, 0x30\n"
84 : : : "cx", "ax", "dx"
85 );
86};
87
88static inline void
89l4_i586_read_event_counter_long(long long *counter0, long long *counter1)
90{
91 asm volatile(
92 /* "movl $0, %%eax\n"
93 "movl $0x11, %%ecx\n"
94 ".byte 0x0f, 0x30\n" *//* stop event counting */
95 "mov $0x12, %%rcx\n"
96 ".byte 0x0f, 0x32\n"
97 "mov %%rax, (%%rbx)\n"
98 "mov %%rdx, 4(%%rbx)\n"
99 "mov $0x13, %%ecx\n"
100 ".byte 0x0f, 0x32\n"
101 "mov %%rax, (%%rsi)\n"
102 "mov %%rdx, 4(%%rsi)\n"
103 : /* no output */
104 : "b" (counter0), "S" (counter1)
105 : "ax", "cx", "dx"
106 );
107}
108
109static inline void
110l4_i586_read_event_counter(int *counter0, int *counter1)
111{
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"
118 ".byte 0x0f, 0x32\n"
119 "popl %%edx\n"
120 : "=b" (*counter0), "=a" (*counter1)
121 : "1" (0), "c" (0x11)
122 );
123}
124
125static inline void
126l4_i586_select_event(int event0, int event1)
127{
128 asm volatile(".byte 0x0f, 0x30\n"
129 :
130 :
131 "a" (event0 + (event1 << 16)),
132 "d" (0),
133 "c" (0x11)
134 );
135};
136
137#define P5_RD_MISS 0x003 /* 000011B */
138#define P5_WR_MISS 0x008 /* 000100B */
139#define P5_RW_MISS 0x029 /* 101001B */
140#define P5_EX_MISS 0x00e /* 001110B */
141
142#define P5_D_WBACK 0x006 /* 000110B */
143
144#define P5_RW_TLB 0x002 /* 00010B */
145#define P5_EX_TLB 0x00d /* 01101B */
146
147#define P5_A_STALL 0x01f /* 11111B */
148#define P5_W_STALL 0x019 /* 11001B */
149#define P5_R_STALL 0x01a /* 11010B */
150#define P5_X_STALL 0x01b /* 11011B */
151
152#define P5_AGI_STALL 0x01f /* 11111B */
153
154#define P5_PIPLINE_FLUSH 0x015 /* 10101B */
155
156#define P5_NON_CACHE_RD 0x01e /* 11110B */
157#define P5_NCACHE_REFS 0x01e /* 11110B */
158#define P5_LOCKED_BUS 0x01c /* 11100B */
159
160#define P5_MEM2PIPE 0x009 /* 01001B */
161#define P5_BANK_CONF 0x00a /* 01010B */
162
163
164#define P5_INSTRS_EX 0x016 /* 10110B */
165#define P5_INSTRS_EX_V 0x017 /* 10111B */
166
167
168#define P5_CNT_NOTHING (0x00 << 6) /* 00B << 6 */
169#define P5_CNT_EVENT_PL0 (0x01 << 6) /* 01B << 6 */
170#define P5_CNT_EVENT_PL3 (0x02 << 6) /* 10B << 6 */
171#define P5_CNT_EVENT (0x03 << 6) /* 11B << 6 */
172#define P5_CNT_CLOCKS_PL0 (0x05 << 6) /* 101B << 6 */
173#define P5_CNT_CLOCKS_PL3 (0x06 << 6) /* 110B << 6 */
174#define P5_CNT_CLOCKS (0x07 << 6) /* 111B << 6 */
175
176
177#else
178#if defined CPU_P6
179/* PPro/PII/PIII section */
180
181/*-
182 * Copyright (c) 1997 The President and Fellows of Harvard College.
183 * All rights reserved.
184 * Copyright (c) 1997 Aaron B. Brown.
185 *
186 * Redistribution and use in source and binary forms, with or without
187 * modification, are permitted provided that the following conditions
188 * are met:
189 * 1. Redistributions of source code must retain the above copyright
190 * notice, this list of conditions and the following disclaimer.
191 * 2. Redistributions in binary form must reproduce the above copyright
192 * notice, this list of conditions and the following disclaimer in the
193 * documentation and/or other materials provided with the distribution.
194 * 3. All advertising materials mentioning features or use of this software
195 * must display the following acknowledgement:
196 * This product includes software developed by Harvard University
197 * and its contributors.
198 * 4. Neither the name of the University nor the names of its contributors
199 * may be used to endorse or promote products derived from this software
200 * without specific prior written permission.
201 *
202 * THIS SOFTWARE IS PROVIDED BY HARVARD AND CONTRIBUTORS ``AS IS'' AND
203 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
204 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
205 * ARE DISCLAIMED. IN NO EVENT SHALL HARVARD UNIVERSITY OR CONTRIBUTORS BE
206 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
207 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
208 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
209 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
210 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
211 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
212 * POSSIBILITY OF SUCH DAMAGE.
213 */
214
215/*********************************************************************
216 ** Symbolic names for counter numbers (used in select_p6counter()) **
217 *********************************************************************
218 *
219 * These correspond in order to the Pentium Pro counters. Add new counters at
220 * the end. These agree with the mneumonics in the Pentium Pro Family
221 * Developer's Manual, vol 3.
222 *
223 * Those events marked with a $ require a MESI unit field; those marked with
224 * a @ require a self/any unit field. Those marked with a 0 are only supported
225 * in counter 0; those marked with 1 are only supported in counter 1.
226 */
227
228/* Data cache unit */
229#define P6_DATA_MEM_REFS 0x43 /* total memory refs */
230#define P6_DCU_LINES_IN 0x45 /* all lines allocated in cache unit */
231#define P6_DCU_M_LINES_IN 0x46 /* M lines allocated in cache unit */
232#define P6_DCU_M_LINES_OUT 0x47 /* M lines evicted from cache */
233#define P6_DCU_MISS_OUTSTANDING 0x48 /* #cycles a miss is outstanding */
234
235/* Instruction fetch unit */
236#define P6_IFU_IFETCH 0x80 /* instruction fetches */
237#define P6_IFU_IFETCH_MISS 0x81 /* instruction fetch misses */
238#define P6_ITLB_MISS 0x85 /* ITLB misses */
239#define P6_IFU_MEM_STALL 0x86 /* number of cycles IFU is stalled */
240#define P6_ILD_STALL 0x87 /* #stalls in instr length decode */
241
242/* L2 Cache */
243#define P6_L2_IFETCH 0x28 /* ($) l2 ifetches */
244#define P6_L2_LD 0x29 /* ($) l2 data loads */
245#define P6_L2_ST 0x2a /* ($) l2 data stores */
246#define P6_L2_LINES_IN 0x24 /* lines allocated in l2 */
247#define P6_L2_LINES_OUT 0x26 /* lines removed from l2 */
248#define P6_L2_M_LINES_INM 0x25 /* modified lines allocated in L2 */
249#define P6_L2_M_LINES_OUTM 0x27 /* modified lines removed from L2 */
250#define P6_L2_RQSTS 0x2e /* ($) number of l2 requests */
251#define P6_L2_ADS 0x21 /* number of l2 addr strobes */
252#define P6_L2_DBUS_BUSY 0x22 /* number of data bus busy cycles */
253#define P6_L2_DBUS_BUSY_RD 0x23 /* #bus cycles xferring l2->cpu */
254
255/* External bus logic */
256#define P6_BUS_DRDY_CLOCKS 0x62 /* (@) #clocks DRDY is asserted */
257#define P6_BUS_LOCK_CLOCKS 0x63 /* (@) #clocks LOCK is asserted */
258#define P6_BUS_REQ_OUTSTANDING 0x60 /* #bus requests outstanding */
259#define P6_BUS_TRAN_BRD 0x65 /* (@) bus burst read txns */
260#define P6_BUS_TRAN_RFO 0x66 /* (@) bus read for ownership txns */
261#define P6_BUS_TRAN_WB 0x67 /* (@) bus writeback txns */
262#define P6_BUS_TRAN_IFETCH 0x68 /* (@) bus instr fetch txns */
263#define P6_BUS_TRAN_INVAL 0x69 /* (@) bus invalidate txns */
264#define P6_BUS_TRAN_PWR 0x6a /* (@) bus partial write txns */
265#define P6_BUS_TRANS_P 0x6b /* (@) bus partial txns */
266#define P6_BUS_TRANS_IO 0x6c /* (@) bus I/O txns */
267#define P6_BUS_TRAN_DEF 0x6d /* (@) bus deferred txns */
268#define P6_BUS_TRAN_BURST 0x6e /* (@) bus burst txns */
269#define P6_BUS_TRAN_ANY 0x70 /* (@) total bus txns */
270#define P6_BUS_TRAN_MEM 0x6f /* (@) total memory txns */
271#define P6_BUS_DATA_RCV 0x64 /* #busclocks CPU is receiving data */
272#define P6_BUS_BNR_DRV 0x61 /* #busclocks CPU is driving BNR pin */
273#define P6_BUS_HIT_DRV 0x7a /* #busclocks CPU is driving HIT pin */
274#define P6_BUS_HITM_DRV 0x7b /* #busclocks CPU is driving HITM pin*/
275#define P6_BUS_SNOOP_STALL 0x7e /* #clkcycles bus is snoop-stalled */
276
277/* FPU */
278#define P6_FLOPS 0xc1 /* (0) number of FP ops retired */
279#define P6_FP_COMP_OPS 0x10 /* (0) computational FPOPS exec'd */
280#define P6_FP_ASSIST 0x11 /* (1) FP excep's handled in ucode */
281#define P6_MUL 0x12 /* (1) number of FP multiplies */
282#define P6_DIV 0x13 /* (1) number of FP divides */
283#define P6_CYCLES_DIV_BUSY 0x14 /* (0) number of cycles divider busy */
284
285/* Memory ordering */
286#define P6_LD_BLOCKS 0x03 /* number of store buffer blocks */
287#define P6_SB_DRAINS 0x04 /* # of store buffer drain cycles */
288#define P6_MISALING_MEM_REF 0x05 /* # misaligned data memory refs */
289
290/* Instruction decoding and retirement */
291#define P6_INST_RETIRED 0xc0 /* number of instrs retired */
292#define P6_UOPS_RETIRED 0xc2 /* number of micro-ops retired */
293#define P6_INST_DECODER 0xd0 /* number of instructions decoded */
294
295/* Interrupts */
296#define P6_HW_INT_RX 0xc8 /* number of hardware interrupts */
297#define P6_CYCLES_INT_MASKED 0xc6 /* number of cycles hardints masked */
298#define P6_CYCLES_INT_PENDING_AND_MASKED 0xc7 /* #cycles masked but pending */
299
300/* Branches */
301#define P6_BR_INST_RETIRED 0xc4 /* number of branch instrs retired */
302#define P6_BR_MISS_PRED_RETIRED 0xc5 /* number of mispred'd brs retired */
303#define P6_BR_TAKEN_RETIRED 0xc9 /* number of taken branches retired */
304#define P6_BR_MISS_PRED_TAKEN_RET 0xca /* #taken mispredictions br's retired*/
305#define P6_BR_INST_DECODED 0xe0 /* number of branch instrs decoded */
306#define P6_BTB_MISSES 0xe2 /* # of branches that missed in BTB */
307#define P6_BR_BOGUS 0xe4 /* number of bogus branches */
308#define P6_BACLEARS 0xe6 /* # times BACLEAR is asserted */
309
310/* Stalls */
311#define P6_RESOURCE_STALLS 0xa2 /* # resource-related stall cycles */
312#define P6_PARTIAL_RAT_STALLS 0xd2 /* # cycles/events for partial stalls*/
313
314/* Segment register loads */
315#define P6_SEGMENT_REG_LOADS 0x06 /* number of segment register loads */
316
317/* Clocks */
318#define P6_CPU_CLK_UNHALTED 0x79 /* #clocks CPU is not halted */
319
320/* Unit field tags */
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
326
327#define P6_UNIT_SELF 0x0000
328#define P6_UNIT_ANY 0x2000
329
330/****************************************************************************
331 ** Flag bit definitions (used for the 'flag' field in select_p6counter()) **
332 ****************************************************************************
333 *
334 * The driver accepts fully-formed counter specifications from user-level.
335 * The following flags are mneumonics for the bits that get set in the
336 * PerfEvtSel0 and PerfEvtSel1 MSR's
337 *
338 */
339#define P6CNT_U 0x010000 /* Monitor user-level events */
340#define P6CNT_K 0x020000 /* Monitor kernel-level events */
341#define P6CNT_E 0x040000 /* Edge detect: count state transitions */
342#define P6CNT_PC 0x080000 /* Pin control: ?? */
343#define P6CNT_IE 0x100000 /* Int enable: enable interrupt on overflow */
344#define P6CNT_F 0x200000 /* Freeze counter (handled in software) */
345#define P6CNT_EN 0x400000 /* enable counters (in PerfEvtSel0) */
346#define P6CNT_IV 0x800000 /* Invert counter mask comparison result */
347
348/*****************************
349 ** Miscellaneous constants **
350 *****************************
351 *
352 * Number of Pentium Pro programable hardware counters.
353 */
354#define NUM_P6HWC 2
355
356/*****************************************************************************
357*
358* End of Copyright by Harvard College
359*
360*****************************************************************************/
361
362
363#define MSR_P6_EVNTSEL0 0x186
364#define MSR_P6_EVNTSEL1 0x187
365#define MSR_P6_PERFCTR0 0xc1
366#define MSR_P6_PERFCTR1 0xc2
367
368/* P6-specific Makros to manipulate and read counters */
369
370/* Read the 40 bit performance monitoring counter. This requires
371 the PCE-flag in CR4 to be set. Otherwise GP0 is raised. Works only
372 at P6.
373 */
374#define l4_i686_rdpmc(cntr, res_p) \
375 __asm __volatile( \
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)) \
381 : "g" (cntr) \
382 : "ecx", "eax", "edx")
383
384static inline l4_uint32_t l4_i686_rdpmc_32(int cntr){
385 l4_uint32_t x;
386
387 __asm__ __volatile__(
388 ".byte 0xf; .byte 0x33 # RDPMC instruction"
389 : "=a" (x)
390 : "c" (cntr)
391 : "rcx", "rax", "rdx");
392 return x;
393}
394
395static inline void l4_i686_select_perfctr_event(int counter,
396 unsigned long long val){
397 l4_i586_wrmsr(MSR_P6_EVNTSEL0+counter, &val);
398}
399
400static inline void l4_i686_select_perfctr0_event(long long *val){
401 asm volatile(
402 "mov $MSR_P6_EVNTSEL0, %%rcx\n"
403 "mov (%%rbx), %%rax\n"
404 "mov 4(%%rbx), %%rdx\n"
405 //".byte 0xcc, 0xeb, 0x01, 0x21\n"
406 ".byte 0x0f, 0x30\n" // wrmsr
407 //".byte 0xcc, 0xeb, 0x01, 0x21\n"
408 : /* no output */
409 : "b" (val)
410 : "ax", "cx", "dx", "bx"
411 );
412
413}
414
415/* end of P6 section */
416#else
417
418#define K7CNT_U 0x010000 /* Monitor user-level events */
419#define K7CNT_K 0x020000 /* Monitor kernel-level events */
420#define K7CNT_E 0x040000 /* Edge detect: count state transitions */
421#define K7CNT_PC 0x080000 /* Pin control: ?? */
422#define K7CNT_IE 0x100000 /* Int enable: enable interrupt on overflow */
423#define K7CNT_F 0x200000 /* Freeze counter (handled in software) */
424#define K7CNT_EN 0x400000 /* enable counters (in PerfEvtSel0) */
425#define K7CNT_IV 0x800000 /* Invert counter mask comparison result */
426
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
435
436#endif
437
438#endif
439
440/* end of P5/P6/K7 section*/
441#endif
442
443/* end of not only lib-prototypes section */
444#endif
445
447
448#endif
L4 compiler related defines.
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition l4int.h:29
#define __END_DECLS
End section with C types and functions.
Definition compiler.h:167
#define __BEGIN_DECLS
Start section with C types and functions.
Definition compiler.h:164
Common L4 ABI Data Types.