amu.rst 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. .. _amu_index:
  2. =======================================================
  3. Activity Monitors Unit (AMU) extension in AArch64 Linux
  4. =======================================================
  5. Author: Ionela Voinescu <[email protected]>
  6. Date: 2019-09-10
  7. This document briefly describes the provision of Activity Monitors Unit
  8. support in AArch64 Linux.
  9. Architecture overview
  10. ---------------------
  11. The activity monitors extension is an optional extension introduced by the
  12. ARMv8.4 CPU architecture.
  13. The activity monitors unit, implemented in each CPU, provides performance
  14. counters intended for system management use. The AMU extension provides a
  15. system register interface to the counter registers and also supports an
  16. optional external memory-mapped interface.
  17. Version 1 of the Activity Monitors architecture implements a counter group
  18. of four fixed and architecturally defined 64-bit event counters.
  19. - CPU cycle counter: increments at the frequency of the CPU.
  20. - Constant counter: increments at the fixed frequency of the system
  21. clock.
  22. - Instructions retired: increments with every architecturally executed
  23. instruction.
  24. - Memory stall cycles: counts instruction dispatch stall cycles caused by
  25. misses in the last level cache within the clock domain.
  26. When in WFI or WFE these counters do not increment.
  27. The Activity Monitors architecture provides space for up to 16 architected
  28. event counters. Future versions of the architecture may use this space to
  29. implement additional architected event counters.
  30. Additionally, version 1 implements a counter group of up to 16 auxiliary
  31. 64-bit event counters.
  32. On cold reset all counters reset to 0.
  33. Basic support
  34. -------------
  35. The kernel can safely run a mix of CPUs with and without support for the
  36. activity monitors extension. Therefore, when CONFIG_ARM64_AMU_EXTN is
  37. selected we unconditionally enable the capability to allow any late CPU
  38. (secondary or hotplugged) to detect and use the feature.
  39. When the feature is detected on a CPU, we flag the availability of the
  40. feature but this does not guarantee the correct functionality of the
  41. counters, only the presence of the extension.
  42. Firmware (code running at higher exception levels, e.g. arm-tf) support is
  43. needed to:
  44. - Enable access for lower exception levels (EL2 and EL1) to the AMU
  45. registers.
  46. - Enable the counters. If not enabled these will read as 0.
  47. - Save/restore the counters before/after the CPU is being put/brought up
  48. from the 'off' power state.
  49. When using kernels that have this feature enabled but boot with broken
  50. firmware the user may experience panics or lockups when accessing the
  51. counter registers. Even if these symptoms are not observed, the values
  52. returned by the register reads might not correctly reflect reality. Most
  53. commonly, the counters will read as 0, indicating that they are not
  54. enabled.
  55. If proper support is not provided in firmware it's best to disable
  56. CONFIG_ARM64_AMU_EXTN. To be noted that for security reasons, this does not
  57. bypass the setting of AMUSERENR_EL0 to trap accesses from EL0 (userspace) to
  58. EL1 (kernel). Therefore, firmware should still ensure accesses to AMU registers
  59. are not trapped in EL2/EL3.
  60. The fixed counters of AMUv1 are accessible though the following system
  61. register definitions:
  62. - SYS_AMEVCNTR0_CORE_EL0
  63. - SYS_AMEVCNTR0_CONST_EL0
  64. - SYS_AMEVCNTR0_INST_RET_EL0
  65. - SYS_AMEVCNTR0_MEM_STALL_EL0
  66. Auxiliary platform specific counters can be accessed using
  67. SYS_AMEVCNTR1_EL0(n), where n is a value between 0 and 15.
  68. Details can be found in: arch/arm64/include/asm/sysreg.h.
  69. Userspace access
  70. ----------------
  71. Currently, access from userspace to the AMU registers is disabled due to:
  72. - Security reasons: they might expose information about code executed in
  73. secure mode.
  74. - Purpose: AMU counters are intended for system management use.
  75. Also, the presence of the feature is not visible to userspace.
  76. Virtualization
  77. --------------
  78. Currently, access from userspace (EL0) and kernelspace (EL1) on the KVM
  79. guest side is disabled due to:
  80. - Security reasons: they might expose information about code executed
  81. by other guests or the host.
  82. Any attempt to access the AMU registers will result in an UNDEFINED
  83. exception being injected into the guest.