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