xref: /rk3399_ARM-atf/docs/perf/performance-monitoring-unit.rst (revision 601964294796f2b78f38c3f85cfaeb5885e06f19)
1*62c9be71SPetre-Ionut TudorPerformance Monitoring Unit
2*62c9be71SPetre-Ionut Tudor===========================
3*62c9be71SPetre-Ionut Tudor
4*62c9be71SPetre-Ionut TudorThe Performance Monitoring Unit (PMU) allows recording of architectural and
5*62c9be71SPetre-Ionut Tudormicroarchitectural events for profiling purposes.
6*62c9be71SPetre-Ionut Tudor
7*62c9be71SPetre-Ionut TudorThis document gives an overview of the PMU counter configuration to assist with
8*62c9be71SPetre-Ionut Tudorimplementation and to complement the PMU security guidelines given in the
9*62c9be71SPetre-Ionut Tudor:ref:`Secure Development Guidelines` document.
10*62c9be71SPetre-Ionut Tudor
11*62c9be71SPetre-Ionut Tudor.. note::
12*62c9be71SPetre-Ionut Tudor   This section applies to Armv8-A implementations which have version 3
13*62c9be71SPetre-Ionut Tudor   of the Performance Monitors Extension (PMUv3).
14*62c9be71SPetre-Ionut Tudor
15*62c9be71SPetre-Ionut TudorPMU Counters
16*62c9be71SPetre-Ionut Tudor------------
17*62c9be71SPetre-Ionut Tudor
18*62c9be71SPetre-Ionut TudorThe PMU makes 32 counters available at all privilege levels:
19*62c9be71SPetre-Ionut Tudor
20*62c9be71SPetre-Ionut Tudor-  31 programmable event counters: ``PMEVCNTR<n>``, where ``n`` is ``0`` to
21*62c9be71SPetre-Ionut Tudor   ``30``.
22*62c9be71SPetre-Ionut Tudor-  A dedicated cycle counter: ``PMCCNTR``.
23*62c9be71SPetre-Ionut Tudor
24*62c9be71SPetre-Ionut TudorArchitectural mappings
25*62c9be71SPetre-Ionut Tudor~~~~~~~~~~~~~~~~~~~~~~
26*62c9be71SPetre-Ionut Tudor
27*62c9be71SPetre-Ionut Tudor+--------------+---------+----------------------------+
28*62c9be71SPetre-Ionut Tudor| Counters     | State   | System Register Name       |
29*62c9be71SPetre-Ionut Tudor+==============+=========+============================+
30*62c9be71SPetre-Ionut Tudor|              | AArch64 | ``PMEVCNTR<n>_EL0[63*:0]`` |
31*62c9be71SPetre-Ionut Tudor| Programmable +---------+----------------------------+
32*62c9be71SPetre-Ionut Tudor|              | AArch32 | ``PMEVCNTR<n>[31:0]``      |
33*62c9be71SPetre-Ionut Tudor+--------------+---------+----------------------------+
34*62c9be71SPetre-Ionut Tudor|              | AArch64 | ``PMCCNTR_EL0[63:0]``      |
35*62c9be71SPetre-Ionut Tudor| Cycle        +---------+----------------------------+
36*62c9be71SPetre-Ionut Tudor|              | AArch32 | ``PMCCNTR[63:0]``          |
37*62c9be71SPetre-Ionut Tudor+--------------+---------+----------------------------+
38*62c9be71SPetre-Ionut Tudor
39*62c9be71SPetre-Ionut Tudor.. note::
40*62c9be71SPetre-Ionut Tudor   Bits [63:32] are only available if ARMv8.5-PMU is implemented. Refer to the
41*62c9be71SPetre-Ionut Tudor   `Arm ARM`_ for a detailed description of ARMv8.5-PMU features.
42*62c9be71SPetre-Ionut Tudor
43*62c9be71SPetre-Ionut TudorConfiguring the PMU for counting events
44*62c9be71SPetre-Ionut Tudor---------------------------------------
45*62c9be71SPetre-Ionut Tudor
46*62c9be71SPetre-Ionut TudorEach programmable counter has an associated register, ``PMEVTYPER<n>`` which
47*62c9be71SPetre-Ionut Tudorconfigures it. The cycle counter has the ``PMCCFILTR_EL0`` register, which has
48*62c9be71SPetre-Ionut Tudoran identical function and bit field layout as ``PMEVTYPER<n>``. In addition,
49*62c9be71SPetre-Ionut Tudorthe counters are enabled (permitted to increment) via the ``PMCNTENSET`` and
50*62c9be71SPetre-Ionut Tudor``PMCR`` registers. These can be accessed at all privilege levels.
51*62c9be71SPetre-Ionut Tudor
52*62c9be71SPetre-Ionut TudorArchitectural mappings
53*62c9be71SPetre-Ionut Tudor~~~~~~~~~~~~~~~~~~~~~~
54*62c9be71SPetre-Ionut Tudor
55*62c9be71SPetre-Ionut Tudor+-----------------------------+------------------------+
56*62c9be71SPetre-Ionut Tudor| AArch64                     | AArch32                |
57*62c9be71SPetre-Ionut Tudor+=============================+========================+
58*62c9be71SPetre-Ionut Tudor| ``PMEVTYPER<n>_EL0[63*:0]`` | ``PMEVTYPER<n>[31:0]`` |
59*62c9be71SPetre-Ionut Tudor+-----------------------------+------------------------+
60*62c9be71SPetre-Ionut Tudor| ``PMCCFILTR_EL0[63*:0]``    | ``PMCCFILTR[31:0]``    |
61*62c9be71SPetre-Ionut Tudor+-----------------------------+------------------------+
62*62c9be71SPetre-Ionut Tudor| ``PMCNTENSET_EL0[63*:0]``   | ``PMCNTENSET[31:0]``   |
63*62c9be71SPetre-Ionut Tudor+-----------------------------+------------------------+
64*62c9be71SPetre-Ionut Tudor| ``PMCR_EL0[63*:0]``         | ``PMCR[31:0]``         |
65*62c9be71SPetre-Ionut Tudor+-----------------------------+------------------------+
66*62c9be71SPetre-Ionut Tudor
67*62c9be71SPetre-Ionut Tudor.. note::
68*62c9be71SPetre-Ionut Tudor   Bits [63:32] are reserved.
69*62c9be71SPetre-Ionut Tudor
70*62c9be71SPetre-Ionut TudorRelevant register fields
71*62c9be71SPetre-Ionut Tudor~~~~~~~~~~~~~~~~~~~~~~~~
72*62c9be71SPetre-Ionut Tudor
73*62c9be71SPetre-Ionut TudorFor ``PMEVTYPER<n>_EL0``/``PMEVTYPER<n>`` and ``PMCCFILTR_EL0/PMCCFILTR``, the
74*62c9be71SPetre-Ionut Tudormost important fields are:
75*62c9be71SPetre-Ionut Tudor
76*62c9be71SPetre-Ionut Tudor-  ``P``:
77*62c9be71SPetre-Ionut Tudor
78*62c9be71SPetre-Ionut Tudor   -  Bit 31.
79*62c9be71SPetre-Ionut Tudor   -  If set to ``0``, will increment the associated ``PMEVCNTR<n>`` at EL1.
80*62c9be71SPetre-Ionut Tudor
81*62c9be71SPetre-Ionut Tudor-  ``NSK``:
82*62c9be71SPetre-Ionut Tudor
83*62c9be71SPetre-Ionut Tudor   -  Bit 29.
84*62c9be71SPetre-Ionut Tudor   -  If equal to the ``P`` bit it enables the associated ``PMEVCNTR<n>`` at
85*62c9be71SPetre-Ionut Tudor      Non-secure EL1.
86*62c9be71SPetre-Ionut Tudor   -  Reserved if EL3 not implemented.
87*62c9be71SPetre-Ionut Tudor
88*62c9be71SPetre-Ionut Tudor-  ``NSH``:
89*62c9be71SPetre-Ionut Tudor
90*62c9be71SPetre-Ionut Tudor   -  Bit 27.
91*62c9be71SPetre-Ionut Tudor   -  If set to ``1``, will increment the associated ``PMEVCNTR<n>`` at EL2.
92*62c9be71SPetre-Ionut Tudor   -  Reserved if EL2 not implemented.
93*62c9be71SPetre-Ionut Tudor
94*62c9be71SPetre-Ionut Tudor-  ``SH``:
95*62c9be71SPetre-Ionut Tudor
96*62c9be71SPetre-Ionut Tudor   -  Bit 24.
97*62c9be71SPetre-Ionut Tudor   -  If different to the ``NSH`` bit it enables the associated ``PMEVCNTR<n>``
98*62c9be71SPetre-Ionut Tudor      at Secure EL2.
99*62c9be71SPetre-Ionut Tudor   -  Reserved if Secure EL2 not implemented.
100*62c9be71SPetre-Ionut Tudor
101*62c9be71SPetre-Ionut Tudor-  ``M``:
102*62c9be71SPetre-Ionut Tudor
103*62c9be71SPetre-Ionut Tudor   -  Bit 26.
104*62c9be71SPetre-Ionut Tudor   -  If equal to the ``P`` bit it enables the associated ``PMEVCNTR<n>`` at
105*62c9be71SPetre-Ionut Tudor      EL3.
106*62c9be71SPetre-Ionut Tudor
107*62c9be71SPetre-Ionut Tudor-  ``evtCount[15:10]``:
108*62c9be71SPetre-Ionut Tudor
109*62c9be71SPetre-Ionut Tudor   -  Extension to ``evtCount[9:0]``. Reserved unless ARMv8.1-PMU implemented.
110*62c9be71SPetre-Ionut Tudor
111*62c9be71SPetre-Ionut Tudor-  ``evtCount[9:0]``:
112*62c9be71SPetre-Ionut Tudor
113*62c9be71SPetre-Ionut Tudor   -  The event number that the associated ``PMEVCNTR<n>`` will count.
114*62c9be71SPetre-Ionut Tudor
115*62c9be71SPetre-Ionut TudorFor ``PMCNTENSET_EL0``/``PMCNTENSET``, the most important fields are:
116*62c9be71SPetre-Ionut Tudor
117*62c9be71SPetre-Ionut Tudor-  ``P[30:0]``:
118*62c9be71SPetre-Ionut Tudor
119*62c9be71SPetre-Ionut Tudor   -  Setting bit ``P[n]`` to ``1`` enables counter ``PMEVCNTR<n>``.
120*62c9be71SPetre-Ionut Tudor   -  The effects of ``PMEVTYPER<n>`` are applied on top of this.
121*62c9be71SPetre-Ionut Tudor      In other words, the counter will not increment at any privilege level or
122*62c9be71SPetre-Ionut Tudor      security state unless it is enabled here.
123*62c9be71SPetre-Ionut Tudor
124*62c9be71SPetre-Ionut Tudor-  ``C``:
125*62c9be71SPetre-Ionut Tudor
126*62c9be71SPetre-Ionut Tudor   -  Bit 31.
127*62c9be71SPetre-Ionut Tudor   -  If set to ``1`` enables the cycle counter ``PMCCNTR``.
128*62c9be71SPetre-Ionut Tudor
129*62c9be71SPetre-Ionut TudorFor ``PMCR``/``PMCR_EL0``, the most important fields are:
130*62c9be71SPetre-Ionut Tudor
131*62c9be71SPetre-Ionut Tudor-  ``DP``:
132*62c9be71SPetre-Ionut Tudor
133*62c9be71SPetre-Ionut Tudor   -  Bit 5.
134*62c9be71SPetre-Ionut Tudor   -  If set to ``1`` it disables the cycle counter ``PMCCNTR`` where event
135*62c9be71SPetre-Ionut Tudor      counting (by ``PMEVCNTR<n>``) is prohibited (e.g. EL2 and the Secure
136*62c9be71SPetre-Ionut Tudor      world).
137*62c9be71SPetre-Ionut Tudor   -  If set to ``0``, ``PMCCNTR`` will not be affected by this bit and
138*62c9be71SPetre-Ionut Tudor      therefore will be able to count where the programmable counters are
139*62c9be71SPetre-Ionut Tudor      prohibited.
140*62c9be71SPetre-Ionut Tudor
141*62c9be71SPetre-Ionut Tudor-  ``E``:
142*62c9be71SPetre-Ionut Tudor
143*62c9be71SPetre-Ionut Tudor   -  Bit 0.
144*62c9be71SPetre-Ionut Tudor   -  Enables/disables counting altogether.
145*62c9be71SPetre-Ionut Tudor   -  The effects of ``PMCNTENSET`` and ``PMCR.DP`` are applied on top of this.
146*62c9be71SPetre-Ionut Tudor      In other words, if this bit is ``0`` then no counters will increment
147*62c9be71SPetre-Ionut Tudor      regardless of how the other PMU system registers or bit fields are
148*62c9be71SPetre-Ionut Tudor      configured.
149*62c9be71SPetre-Ionut Tudor
150*62c9be71SPetre-Ionut Tudor.. rubric:: References
151*62c9be71SPetre-Ionut Tudor
152*62c9be71SPetre-Ionut Tudor-  `Arm ARM`_
153*62c9be71SPetre-Ionut Tudor
154*62c9be71SPetre-Ionut Tudor--------------
155*62c9be71SPetre-Ionut Tudor
156*62c9be71SPetre-Ionut Tudor*Copyright (c) 2019-2020, Arm Limited and Contributors. All rights reserved.*
157*62c9be71SPetre-Ionut Tudor
158*62c9be71SPetre-Ionut Tudor.. _Arm ARM: https://developer.arm.com/docs/ddi0487/latest
159