← Documents Documentation/arch/arm64/amu.rst GitHub 원문 ↗

Linux 6.18.37 · Architecture

Activity Monitors Unit (AMU) extension in AArch64 Linux

ARMv8.4 AMUv1의 고정·보조 64-bit counter, firmware 책임, system register, userspace와 KVM guest 접근 제한을 설명합니다.

Source pathDocumentation/arch/arm64/amu.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

amu.rst:1-119

AMU는 각 CPU에 system-management용 activity counter를 제공합니다. Linux는 AMU 지원 CPU와 미지원 CPU가 섞여도 동작하지만, 실제 counter enable·exception-level 접근·CPU off 전후 보존은 firmware가 책임져야 합니다.

AMUv1 고정 counter
Counter측정 대상
CORECPU frequency에 따른 cycle
CONST고정 system clock cycle
INST_RETArchitecturally executed instruction
MEM_STALLLast-level cache miss에 따른 dispatch stall
확장 공간Architected counter 최대 16개와 auxiliary counter 최대 16개를 수용합니다.
ResetCold reset에서 모든 counter가 0이 됩니다.

네 counter는 모두 64-bit이며 WFI/WFE 동안 증가하지 않습니다.

AMU 접근 책임 분담
EL3/EL2 firmwareRegister access 허용Counter enableCPU off save/restoreEL1 Linux
EL0 userspaceAMUSERENR_EL0 trap접근 차단
KVM guest EL0/EL1UNDEFINED exception접근 차단

Firmware가 상위 exception level에서 접근과 상태를 준비한 뒤 kernel이 system register를 사용합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

AMU 지원 개요

1-14

문서 제목은 `Activity Monitors Unit (AMU) extension in AArch64 Linux`입니다. 작성자는 Ionela Voinescu `<[email protected]>`, 날짜는 `2019-09-10`입니다.

이 문서는 AArch64 Linux가 Activity Monitors Unit을 지원하는 방식을 간략히 설명합니다.

아키텍처 개요

15-48

Activity Monitors extension은 ARMv8.4 CPU architecture에서 도입된 선택적 extension입니다. 각 CPU에 구현되는 AMU는 system management용 performance counter를 제공합니다. AMU extension은 counter register에 접근하는 system register interface와 선택적인 외부 memory-mapped interface를 지원합니다.

Activity Monitors architecture version 1은 아키텍처가 고정해 정의한 64-bit event counter 네 개로 이루어진 counter group을 구현합니다.

Counter증가 조건
CPU cycle counterCPU frequency에 맞춰 증가합니다.
Constant counterSystem clock의 고정 frequency에 맞춰 증가합니다.
Instructions retired아키텍처 관점에서 실행이 완료된 instruction마다 증가합니다.
Memory stall cycles같은 clock domain의 last-level cache miss 때문에 instruction dispatch가 정지한 cycle을 셉니다.

CPU가 WFI 또는 WFE 상태일 때는 이 counter들이 증가하지 않습니다.

Activity Monitors architecture에는 최대 16개의 architected event counter를 위한 공간이 있습니다. 향후 architecture version은 이 공간에 architected event counter를 더 구현할 수 있습니다.

Version 1은 여기에 더해 최대 16개의 보조 64-bit event counter로 이루어진 counter group도 구현합니다. Cold reset이 발생하면 모든 counter는 0으로 reset됩니다.

기본 커널·펌웨어 지원

49-82

Kernel은 Activity Monitors extension을 지원하는 CPU와 지원하지 않는 CPU가 섞인 시스템에서도 안전하게 실행됩니다. 따라서 `CONFIG_ARM64_AMU_EXTN`을 선택하면 capability를 조건 없이 활성화해, 늦게 들어오는 secondary CPU나 hotplug CPU도 이 기능을 감지하고 사용할 수 있게 합니다.

어떤 CPU에서 기능을 감지하면 extension의 가용성을 표시하지만, 이는 counter가 올바르게 동작한다는 보장이 아니라 extension이 존재한다는 뜻일 뿐입니다.

더 높은 exception level에서 실행되는 firmware, 예를 들어 arm-tf는 다음 지원을 제공해야 합니다.

  • 낮은 exception level인 EL2와 EL1이 AMU register에 접근할 수 있게 합니다.
  • Counter를 활성화합니다. 활성화하지 않으면 읽은 값은 0입니다.
  • CPU를 `off` power state에 넣기 전과 다시 올린 뒤에 counter를 save/restore합니다.

이 기능을 켠 kernel이 손상된 firmware로 boot하면 counter register 접근 중 panic이나 lockup이 발생할 수 있습니다. 이런 증상이 없더라도 register read 값이 실제 상황을 올바르게 반영하지 않을 수 있으며, 가장 흔하게는 counter가 활성화되지 않아 0으로 읽힙니다.

Firmware가 적절히 지원하지 않는다면 `CONFIG_ARM64_AMU_EXTN`을 끄는 것이 가장 좋습니다. 보안상의 이유로 이 설정을 꺼도 `AMUSERENR_EL0` 설정을 우회하지 않으므로 EL0(userspace)의 접근은 EL1(kernel)으로 trap됩니다. 따라서 firmware는 AMU register 접근이 EL2/EL3에서 trap되지 않도록 여전히 보장해야 합니다.

AMUv1 system register

83-96

AMUv1의 고정 counter는 다음 system register 정의로 접근합니다.

  • `SYS_AMEVCNTR0_CORE_EL0`
  • `SYS_AMEVCNTR0_CONST_EL0`
  • `SYS_AMEVCNTR0_INST_RET_EL0`
  • `SYS_AMEVCNTR0_MEM_STALL_EL0`

Platform별 보조 counter는 `SYS_AMEVCNTR1_EL0(n)`으로 접근하며 `n`의 범위는 0부터 15까지입니다. 자세한 정의는 `arch/arm64/include/asm/sysreg.h`에 있습니다.

Userspace 접근

97-108

현재 userspace의 AMU register 접근은 다음 이유로 비활성화됩니다.

  • 보안: secure mode에서 실행된 code에 관한 정보를 노출할 수 있습니다.
  • 목적: AMU counter는 system management용입니다.

또한 이 기능의 존재 여부는 userspace에 공개되지 않습니다.

가상화

109-119

현재 KVM guest에서는 userspace(EL0)와 kernelspace(EL1)의 AMU register 접근을 모두 비활성화합니다. 다른 guest나 host가 실행한 code에 관한 정보를 노출할 수 있기 때문입니다.

AMU register에 접근하려는 모든 시도에는 `UNDEFINED` exception을 guest에 주입합니다.