performance-monitoring-unit.rst 5.0 KB

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