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