]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/libsrc/standalone_v4_1/src/xpm_counter.h
Add back Zynq demo - this time using SDK V14.2.
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo_bsp / ps7_cortexa9_0 / libsrc / standalone_v4_1 / src / xpm_counter.h
1 /******************************************************************************
2 *
3 * (c) Copyright 2011-13  Xilinx, Inc. All rights reserved.
4 *
5 * This file contains confidential and proprietary information of Xilinx, Inc.
6 * and is protected under U.S. and international copyright and other
7 * intellectual property laws.
8 *
9 * DISCLAIMER
10 * This disclaimer is not a license and does not grant any rights to the
11 * materials distributed herewith. Except as otherwise provided in a valid
12 * license issued to you by Xilinx, and to the maximum extent permitted by
13 * applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL
14 * FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS,
15 * IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
16 * MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE;
17 * and (2) Xilinx shall not be liable (whether in contract or tort, including
18 * negligence, or under any other theory of liability) for any loss or damage
19 * of any kind or nature related to, arising under or in connection with these
20 * materials, including for any direct, or any indirect, special, incidental,
21 * or consequential loss or damage (including loss of data, profits, goodwill,
22 * or any type of loss or damage suffered as a result of any action brought by
23 * a third party) even if such damage or loss was reasonably foreseeable or
24 * Xilinx had been advised of the possibility of the same.
25 *
26 * CRITICAL APPLICATIONS
27 * Xilinx products are not designed or intended to be fail-safe, or for use in
28 * any application requiring fail-safe performance, such as life-support or
29 * safety devices or systems, Class III medical devices, nuclear facilities,
30 * applications related to the deployment of airbags, or any other applications
31 * that could lead to death, personal injury, or severe property or
32 * environmental damage (individually and collectively, "Critical
33 * Applications"). Customer assumes the sole risk and liability of any use of
34 * Xilinx products in Critical Applications, subject only to applicable laws
35 * and regulations governing limitations on product liability.
36 *
37 * THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE
38 * AT ALL TIMES.
39 *
40 ******************************************************************************/
41 /*****************************************************************************/
42 /**
43 *
44 * @file xpm_counter.h
45 *
46 * This header file contains APIs for configuring and controlling the Cortex-A9
47 * Performance Monitor Events.
48 * Cortex-A9 Performance Monitor has 6 event counters which can be used to
49 * count a variety of events described in Coretx-A9 TRM. This file defines
50 * configurations, where value configures the event counters to count a
51 * set of events.
52 *
53 * Xpm_SetEvents can be used to set the event counters to count a set of events
54 * and Xpm_GetEventCounters can be used to read the counter values.
55 *
56 * @note
57 *
58 * This file doesn't handle the Cortex-A9 cycle counter, as the cycle counter is
59 * being used for time keeping.
60 *
61 * <pre>
62 * MODIFICATION HISTORY:
63 *
64 * Ver   Who  Date     Changes
65 * ----- ---- -------- -----------------------------------------------
66 * 1.00a sdm  07/11/11 First release
67 * </pre>
68 *
69 ******************************************************************************/
70
71 #ifndef XPMCOUNTER_H /* prevent circular inclusions */
72 #define XPMCOUNTER_H /* by using protection macros */
73
74 /***************************** Include Files ********************************/
75
76 #include <stdint.h>
77 #include "xpseudo_asm.h"
78 #include "xil_types.h"
79
80 #ifdef __cplusplus
81 extern "C" {
82 #endif /* __cplusplus */
83
84 /************************** Constant Definitions ****************************/
85
86 /* Number of performance counters */
87 #define XPM_CTRCOUNT 6
88
89 /* The following constants define the Cortex-A9 Performance Monitor Events */
90
91 /*
92  * Software increment. The register is incremented only on writes to the
93  * Software Increment Register
94  */
95 #define XPM_EVENT_SOFTINCR 0x00
96
97 /*
98  * Instruction fetch that causes a refill at (at least) the lowest level(s) of
99  * instruction or unified cache. Includes the speculative linefills in the
100  * count
101  */
102 #define XPM_EVENT_INSRFETCH_CACHEREFILL 0x01
103
104 /*
105  * Instruction fetch that causes a TLB refill at (at least) the lowest level of
106  * TLB. Includes the speculative requests in the count
107  */
108 #define XPM_EVENT_INSTRFECT_TLBREFILL 0x02
109
110 /*
111  * Data read or write operation that causes a refill at (at least) the lowest
112  * level(s)of data or unified cache. Counts the number of allocations performed
113  * in the Data Cache due to a read or a write
114  */
115 #define XPM_EVENT_DATA_CACHEREFILL 0x03
116
117 /*
118  * Data read or write operation that causes a cache access at (at least) the
119  * lowest level(s) of data or unified cache. This includes speculative reads
120  */
121 #define XPM_EVENT_DATA_CACHEACCESS 0x04
122
123 /*
124  * Data read or write operation that causes a TLB refill at (at least) the
125  * lowest level of TLB. This does not include micro TLB misses due to PLD, PLI,
126  * CP15 Cache operation by MVA and CP15 VA to PA operations
127  */
128 #define XPM_EVENT_DATA_TLBREFILL 0x05
129
130 /*
131  * Data read architecturally executed. Counts the number of data read
132  * instructions accepted by the Load Store Unit. This includes counting the
133  * speculative and aborted LDR/LDM, as well as the reads due to the SWP
134  * instructions
135  */
136 #define XPM_EVENT_DATA_READS 0x06
137
138 /*
139  * Data write architecturally executed. Counts the number of data write
140  * instructions accepted by the Load Store Unit. This includes counting the
141  * speculative and aborted STR/STM, as well as the writes due to the SWP
142  * instructions
143  */
144 #define XPM_EVENT_DATA_WRITE 0x07
145
146 /* Exception taken. Counts the number of exceptions architecturally taken.*/
147 #define XPM_EVENT_EXCEPTION 0x09
148
149 /* Exception return architecturally executed.*/
150 #define XPM_EVENT_EXCEPRETURN 0x0A
151
152 /*
153  * Change to ContextID retired. Counts the number of instructions
154  * architecturally executed writing into the ContextID Register
155  */
156 #define XPM_EVENT_CHANGECONTEXT 0x0B
157
158 /*
159  * Software change of PC, except by an exception, architecturally executed.
160  * Count the number of PC changes architecturally executed, excluding the PC
161  * changes due to taken exceptions
162  */
163 #define XPM_EVENT_SW_CHANGEPC 0x0C
164
165 /*
166  * Immediate branch architecturally executed (taken or not taken). This includes
167  * the branches which are flushed due to a previous load/store which aborts
168  * late
169  */
170 #define XPM_EVENT_IMMEDBRANCH 0x0D
171
172 /*
173  * Unaligned access architecturally executed. Counts the number of aborted
174  * unaligned accessed architecturally executed, and the number of not-aborted
175  * unaligned accesses, including the speculative ones
176  */
177 #define XPM_EVENT_UNALIGNEDACCESS 0x0F
178
179 /*
180  * Branch mispredicted/not predicted. Counts the number of mispredicted or
181  * not-predicted branches executed. This includes the branches which are flushed
182  * due to a previous load/store which aborts late
183  */
184 #define XPM_EVENT_BRANCHMISS 0x10
185
186 /*
187  * Counts clock cycles when the Cortex-A9 processor is not in WFE/WFI. This
188  * event is not exported on the PMUEVENT bus
189  */
190 #define XPM_EVENT_CLOCKCYCLES 0x11
191
192 /*
193  * Branches or other change in program flow that could have been predicted by
194  * the branch prediction resources of the processor. This includes the branches
195  * which are flushed due to a previous load/store which aborts late
196  */
197 #define XPM_EVENT_BRANCHPREDICT 0x12
198
199 /*
200  * Java bytecode execute. Counts the number of Java bytecodes being decoded,
201  * including speculative ones
202  */
203 #define XPM_EVENT_JAVABYTECODE 0x40
204
205 /*
206  * Software Java bytecode executed. Counts the number of software java bytecodes
207  * being decoded, including speculative ones
208  */
209 #define XPM_EVENT_SWJAVABYTECODE 0x41
210
211 /*
212  * Jazelle backward branches executed. Counts the number of Jazelle taken
213  * branches being executed. This includes the branches which are flushed due
214  * to a previous load/store which aborts late
215  */
216 #define XPM_EVENT_JAVABACKBRANCH 0x42
217
218 /*
219  * Coherent linefill miss Counts the number of coherent linefill requests
220  * performed by the Cortex-A9 processor which also miss in all the other
221  * Cortex-A9 processors, meaning that the request is sent to the external
222  * memory
223  */
224 #define XPM_EVENT_COHERLINEMISS 0x50
225
226 /*
227  * Coherent linefill hit. Counts the number of coherent linefill requests
228  * performed by the Cortex-A9 processor which hit in another Cortex-A9
229  * processor, meaning that the linefill data is fetched directly from the
230  * relevant Cortex-A9 cache
231  */
232 #define XPM_EVENT_COHERLINEHIT 0x51
233
234 /*
235  * Instruction cache dependent stall cycles. Counts the number of cycles where
236  * the processor is ready to accept new instructions, but does not receive any
237  * due to the instruction side not being able to provide any and the
238  * instruction cache is currently performing at least one linefill
239  */
240 #define XPM_EVENT_INSTRSTALL 0x60
241
242 /*
243  * Data cache dependent stall cycles. Counts the number of cycles where the core
244  * has some instructions that it cannot issue to any pipeline, and the Load
245  * Store unit has at least one pending linefill request, and no pending
246  */
247 #define XPM_EVENT_DATASTALL 0x61
248
249 /*
250  * Main TLB miss stall cycles. Counts the number of cycles where the processor
251  * is stalled waiting for the completion of translation table walks from the
252  * main TLB. The processor stalls can be due to the instruction side not being
253  * able to provide the instructions, or to the data side not being able to
254  * provide the necessary data, due to them waiting for the main TLB translation
255  * table walk to complete
256  */
257 #define XPM_EVENT_MAINTLBSTALL 0x62
258
259 /*
260  * Counts the number of STREX instructions architecturally executed and
261  * passed
262  */
263 #define XPM_EVENT_STREXPASS 0x63
264
265 /*
266  * Counts the number of STREX instructions architecturally executed and
267  * failed
268  */
269 #define XPM_EVENT_STREXFAIL 0x64
270
271 /*
272  * Data eviction. Counts the number of eviction requests due to a linefill in
273  * the data cache
274  */
275 #define XPM_EVENT_DATAEVICT 0x65
276
277 /*
278  * Counts the number of cycles where the issue stage does not dispatch any
279  * instruction because it is empty or cannot dispatch any instructions
280  */
281 #define XPM_EVENT_NODISPATCH 0x66
282
283 /*
284  * Counts the number of cycles where the issue stage is empty
285  */
286 #define XPM_EVENT_ISSUEEMPTY 0x67
287
288 /*
289  * Counts the number of instructions going through the Register Renaming stage.
290  * This number is an approximate number of the total number of instructions
291  * speculatively executed, and even more approximate of the total number of
292  * instructions architecturally executed. The approximation depends mainly on
293  * the branch misprediction rate.
294  * The renaming stage can handle two instructions in the same cycle so the event
295  * is two bits long:
296  *    - b00 no instructions renamed
297  *    - b01 one instruction renamed
298  *    - b10 two instructions renamed
299  */
300 #define XPM_EVENT_INSTRRENAME 0x68
301
302 /*
303  * Counts the number of procedure returns whose condition codes do not fail,
304  * excluding all returns from exception. This count includes procedure returns
305  * which are flushed due to a previous load/store which aborts late.
306  * Only the following instructions are reported:
307  * - BX R14
308  * - MOV PC LR
309  * - POP {..,pc}
310  * - LDR pc,[sp],#offset
311  * The following instructions are not reported:
312  * - LDMIA R9!,{..,PC} (ThumbEE state only)
313  * - LDR PC,[R9],#offset (ThumbEE state only)
314  * - BX R0 (Rm != R14)
315  * - MOV PC,R0 (Rm != R14)
316  * - LDM SP,{...,PC} (writeback not specified)
317  * - LDR PC,[SP,#offset] (wrong addressing mode)
318  */
319 #define XPM_EVENT_PREDICTFUNCRET 0x6E
320
321 /*
322  * Counts the number of instructions being executed in the main execution
323  * pipeline of the processor, the multiply pipeline and arithmetic logic unit
324  * pipeline. The counted instructions are still speculative
325  */
326 #define XPM_EVENT_MAINEXEC 0x70
327
328 /*
329  * Counts the number of instructions being executed in the processor second
330  * execution pipeline (ALU). The counted instructions are still speculative
331  */
332 #define XPM_EVENT_SECEXEC 0x71
333
334 /*
335  * Counts the number of instructions being executed in the Load/Store unit. The
336  * counted instructions are still speculative
337  */
338 #define XPM_EVENT_LDRSTR 0x72
339
340 /*
341  * Counts the number of Floating-point instructions going through the Register
342  * Rename stage. Instructions are still speculative in this stage.
343  *Two floating-point instructions can be renamed in the same cycle so the event
344  * is two bitslong:
345  *0b00 no floating-point instruction renamed
346  *0b01 one floating-point instruction renamed
347  *0b10 two floating-point instructions renamed
348  */
349 #define XPM_EVENT_FLOATRENAME 0x73
350
351 /*
352  * Counts the number of Neon instructions going through the Register Rename
353  * stage.Instructions are still speculative in this stage.
354  * Two NEON instructions can be renamed in the same cycle so the event is two
355  * bits long:
356  *0b00 no NEON instruction renamed
357  *0b01 one NEON instruction renamed
358  *0b10 two NEON instructions renamed
359  */
360 #define XPM_EVENT_NEONRENAME 0x74
361
362 /*
363  * Counts the number of cycles where the processor is stalled because PLD slots
364  * are all full
365  */
366 #define XPM_EVENT_PLDSTALL 0x80
367
368 /*
369  * Counts the number of cycles when the processor is stalled and the data side
370  * is stalled too because it is full and executing writes to the external
371  * memory
372  */
373 #define XPM_EVENT_WRITESTALL 0x81
374
375 /*
376  * Counts the number of stall cycles due to main TLB misses on requests issued
377  * by the instruction side
378  */
379 #define XPM_EVENT_INSTRTLBSTALL 0x82
380
381 /*
382  * Counts the number of stall cycles due to main TLB misses on requests issued
383  * by the data side
384  */
385 #define XPM_EVENT_DATATLBSTALL 0x83
386
387 /*
388  * Counts the number of stall cycles due to micro TLB misses on the instruction
389  * side. This event does not include main TLB miss stall cycles that are already
390  * counted in the corresponding main TLB event
391  */
392 #define XPM_EVENT_INSTR_uTLBSTALL 0x84
393
394 /*
395  * Counts the number of stall cycles due to micro TLB misses on the data side.
396  * This event does not include main TLB miss stall cycles that are already
397  * counted in the corresponding main TLB event
398  */
399 #define XPM_EVENT_DATA_uTLBSTALL 0x85
400
401 /*
402  * Counts the number of stall cycles because of the execution of a DMB memory
403  * barrier. This includes all DMB instructions being executed, even
404  * speculatively
405  */
406 #define XPM_EVENT_DMB_STALL 0x86
407
408 /*
409  * Counts the number of cycles during which the integer core clock is enabled
410  */
411 #define XPM_EVENT_INT_CLKEN 0x8A
412
413 /*
414  * Counts the number of cycles during which the Data Engine clock is enabled
415  */
416 #define XPM_EVENT_DE_CLKEN 0x8B
417
418 /*
419  * Counts the number of ISB instructions architecturally executed
420  */
421 #define XPM_EVENT_INSTRISB 0x90
422
423 /*
424  * Counts the number of DSB instructions architecturally executed
425  */
426 #define XPM_EVENT_INSTRDSB 0x91
427
428 /*
429  * Counts the number of DMB instructions speculatively executed
430  */
431 #define XPM_EVENT_INSTRDMB 0x92
432
433 /*
434  * Counts the number of external interrupts executed by the processor
435  */
436 #define XPM_EVENT_EXTINT 0x93
437
438 /*
439  * PLE cache line request completed
440  */
441 #define XPM_EVENT_PLE_LRC 0xA0
442
443 /*
444  * PLE cache line request skipped
445  */
446 #define XPM_EVENT_PLE_LRS 0xA1
447
448 /*
449  * PLE FIFO flush
450  */
451 #define XPM_EVENT_PLE_FLUSH 0xA2
452
453 /*
454  * PLE request complete
455  */
456 #define XPM_EVENT_PLE_CMPL 0xA3
457
458 /*
459  * PLE FIFO overflow
460  */
461 #define XPM_EVENT_PLE_OVFL 0xA4
462
463 /*
464  * PLE request programmed
465  */
466 #define XPM_EVENT_PLE_PROG 0xA5
467
468 /*
469  * The following constants define the configurations for Cortex-A9 Performance
470  * Monitor Events. Each configuration configures the event counters for a set
471  * of events.
472  * -----------------------------------------------
473  * Config               PmCtr0... PmCtr5
474  * -----------------------------------------------
475  * XPM_CNTRCFG1         { XPM_EVENT_SOFTINCR,
476  *                        XPM_EVENT_INSRFETCH_CACHEREFILL,
477  *                        XPM_EVENT_INSTRFECT_TLBREFILL,
478  *                        XPM_EVENT_DATA_CACHEREFILL,
479  *                        XPM_EVENT_DATA_CACHEACCESS,
480  *                        XPM_EVENT_DATA_TLBREFILL }
481  *
482  * XPM_CNTRCFG2         { XPM_EVENT_DATA_READS,
483  *                        XPM_EVENT_DATA_WRITE,
484  *                        XPM_EVENT_EXCEPTION,
485  *                        XPM_EVENT_EXCEPRETURN,
486  *                        XPM_EVENT_CHANGECONTEXT,
487  *                        XPM_EVENT_SW_CHANGEPC }
488  *
489  * XPM_CNTRCFG3         { XPM_EVENT_IMMEDBRANCH,
490  *                        XPM_EVENT_UNALIGNEDACCESS,
491  *                        XPM_EVENT_BRANCHMISS,
492  *                        XPM_EVENT_CLOCKCYCLES,
493  *                        XPM_EVENT_BRANCHPREDICT,
494  *                        XPM_EVENT_JAVABYTECODE }
495  *
496  * XPM_CNTRCFG4         { XPM_EVENT_SWJAVABYTECODE,
497  *                        XPM_EVENT_JAVABACKBRANCH,
498  *                        XPM_EVENT_COHERLINEMISS,
499  *                        XPM_EVENT_COHERLINEHIT,
500  *                        XPM_EVENT_INSTRSTALL,
501  *                        XPM_EVENT_DATASTALL }
502  *
503  * XPM_CNTRCFG5         { XPM_EVENT_MAINTLBSTALL,
504  *                        XPM_EVENT_STREXPASS,
505  *                        XPM_EVENT_STREXFAIL,
506  *                        XPM_EVENT_DATAEVICT,
507  *                        XPM_EVENT_NODISPATCH,
508  *                        XPM_EVENT_ISSUEEMPTY }
509  *
510  * XPM_CNTRCFG6         { XPM_EVENT_INSTRRENAME,
511  *                        XPM_EVENT_PREDICTFUNCRET,
512  *                        XPM_EVENT_MAINEXEC,
513  *                        XPM_EVENT_SECEXEC,
514  *                        XPM_EVENT_LDRSTR,
515  *                        XPM_EVENT_FLOATRENAME }
516  *
517  * XPM_CNTRCFG7         { XPM_EVENT_NEONRENAME,
518  *                        XPM_EVENT_PLDSTALL,
519  *                        XPM_EVENT_WRITESTALL,
520  *                        XPM_EVENT_INSTRTLBSTALL,
521  *                        XPM_EVENT_DATATLBSTALL,
522  *                        XPM_EVENT_INSTR_uTLBSTALL }
523  *
524  * XPM_CNTRCFG8         { XPM_EVENT_DATA_uTLBSTALL,
525  *                        XPM_EVENT_DMB_STALL,
526  *                        XPM_EVENT_INT_CLKEN,
527  *                        XPM_EVENT_DE_CLKEN,
528  *                        XPM_EVENT_INSTRISB,
529  *                        XPM_EVENT_INSTRDSB }
530  *
531  * XPM_CNTRCFG9         { XPM_EVENT_INSTRDMB,
532  *                        XPM_EVENT_EXTINT,
533  *                        XPM_EVENT_PLE_LRC,
534  *                        XPM_EVENT_PLE_LRS,
535  *                        XPM_EVENT_PLE_FLUSH,
536  *                        XPM_EVENT_PLE_CMPL }
537  *
538  * XPM_CNTRCFG10        { XPM_EVENT_PLE_OVFL,
539  *                        XPM_EVENT_PLE_PROG,
540  *                        XPM_EVENT_PLE_LRC,
541  *                        XPM_EVENT_PLE_LRS,
542  *                        XPM_EVENT_PLE_FLUSH,
543  *                        XPM_EVENT_PLE_CMPL }
544  *
545  * XPM_CNTRCFG11        { XPM_EVENT_DATASTALL,
546  *                        XPM_EVENT_INSRFETCH_CACHEREFILL,
547  *                        XPM_EVENT_INSTRFECT_TLBREFILL,
548  *                        XPM_EVENT_DATA_CACHEREFILL,
549  *                        XPM_EVENT_DATA_CACHEACCESS,
550  *                        XPM_EVENT_DATA_TLBREFILL }
551  */
552 #define XPM_CNTRCFG1    0
553 #define XPM_CNTRCFG2    1
554 #define XPM_CNTRCFG3    2
555 #define XPM_CNTRCFG4    3
556 #define XPM_CNTRCFG5    4
557 #define XPM_CNTRCFG6    5
558 #define XPM_CNTRCFG7    6
559 #define XPM_CNTRCFG8    7
560 #define XPM_CNTRCFG9    8
561 #define XPM_CNTRCFG10   9
562 #define XPM_CNTRCFG11   10
563
564 /**************************** Type Definitions ******************************/
565
566 /***************** Macros (Inline Functions) Definitions ********************/
567
568 /************************** Variable Definitions ****************************/
569
570 /************************** Function Prototypes *****************************/
571
572 /* Interface fuctions to access perfromance counters from abstraction layer */
573 void Xpm_SetEvents(int PmcrCfg);
574 void Xpm_GetEventCounters(u32 *PmCtrValue);
575
576 #ifdef __cplusplus
577 }
578 #endif
579
580 #endif