← Documents Documentation/scheduler/sched-energy.rst GitHub 원문 ↗

Linux 6.18.37 · Scheduler

Energy Aware Scheduling

Energy Model, performance domain, root domain과 utilization 신호를 이용해 EAS가 task 배치 후보의 에너지를 비교하는 과정을 설명합니다.

Source pathDocumentation/scheduler/sched-energy.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

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

1. 요약·해설

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

EAS가 해결하려는 문제

sched-energy.rst:1-67

Energy Aware Scheduling은 비대칭 CPU 시스템에서 task를 어느 CPU에 둘지 결정할 때 처리 용량과 예상 에너지를 함께 비교합니다. 단순히 가장 한가한 CPU를 고르면 작은 task가 big CPU를 깨우거나 performance domain의 주파수를 올려 시스템 전체 에너지가 증가할 수 있습니다.

EAS는 CFS wake-up placement 경로에서 사용되며 과부하 상태에서는 일반 load balancing으로 돌아갑니다. 따라서 EAS는 항상 적용되는 별도 scheduler가 아니라 특정 조건에서 CFS의 CPU 선택을 보강하는 정책입니다.

Performance domain과 root domain

sched-energy.rst:68-127
하드웨어 주파수 공유 범위와 scheduler balancing 범위
CPU0-1CPU2-3CPU4-7
01 PD0: little clusterPD4: mid clusterPD8: big cluster
02 RD1 balancing spanRD1 balancing spanRD2 balancing span

performance domain은 같은 주파수 상태를 공유하는 CPU 집합이고 root domain은 scheduler가 admission과 balancing에 사용하는 CPU 집합입니다. 두 경계는 반드시 일치하지 않습니다.

Energy Model의 performance domain은 한 CPU의 부하가 같은 domain의 다른 CPU 주파수와 전력에도 영향을 준다는 사실을 표현합니다. EAS는 후보 CPU 하나만 계산하지 않고 그 CPU가 속한 domain의 합산 utilization과 선택될 performance state를 계산합니다.

후보 CPU별 에너지 추정

sched-energy.rst:128-277
비대칭 CPU의 capacity와 energy cost 예
CPU 종류util 170util 341util 512최대 capacity
Little낮은 OPP / 50중간 OPP / 150높은 OPP / 300512
Big낮은 OPP / 400낮은 OPP / 400중간 OPP / 8001024
배치 원칙task가 little CPU capacity 안에 들어오면 little cluster가 유리할 가능성이 높지만, cluster의 기존 부하 때문에 OPP가 상승하면 다른 후보가 더 저렴할 수 있습니다.

표의 수치는 개념 예입니다. 실제 비용은 Energy Model performance state와 domain utilization에서 계산합니다.

wake-up task를 각 후보 CPU에 더한 가상 utilization을 만들고, 모든 performance domain에 대해 필요한 frequency와 energy cost를 계산합니다. 후보 배치의 총 에너지 차이가 migration 비용과 정책상 margin을 넘어설 때 더 효율적인 CPU를 선택합니다.

util_avg 200인 task P의 세 가지 배치 후보
CPU0 LittleCPU1 LittleCPU2 BigCPU3 Big
01 현재 400 + P 200현재 100현재 600현재 500
02 Case 1: 200100 + P 200600500
03 Case 2: 200100600500 + P 200

prev_cpu에 그대로 두는 경우, Little CPU1으로 옮기는 경우, Big CPU3으로 옮기는 경우의 performance-domain 부하를 나란히 비교합니다.

후보 배치별 Energy Model 계산 결과
후보Little domain OPPBig domain OPP총 energy판정
P → CPU1341 capacity / 150 power768 capacity / 800 power1364최저 비용
P → CPU3341 capacity / 150 power768 capacity / 800 power1485Big domain 부하 증가
P → CPU0 유지512 capacity / 300 power768 capacity / 800 power1437Little OPP 상승
선택CPU1 배치는 task P가 Little capacity 안에 들어가면서도 CPU0의 기존 부하를 낮춰 세 후보 중 총 energy가 가장 작습니다.

각 CPU의 utilization을 domain OPP power에 비례 배분한 원문 계산을 후보별 총합으로 정리했습니다.

utilization은 capacity scale로 정규화되어야 합니다. CPU frequency invariance와 micro-architecture capacity invariance가 맞지 않으면 같은 숫자가 CPU마다 다른 실제 작업량을 뜻하게 되어 에너지 비교가 왜곡됩니다.

Over-utilization과 fallback

sched-energy.rst:278-316

root domain의 가용 capacity에 비해 utilization이 너무 높아지면 에너지 최소화보다 처리량과 latency 보장이 우선입니다. scheduler는 overutilized 표시를 세우고 EAS의 세밀한 energy comparison 대신 일반 load balancing을 사용합니다.

EAS 활성 조건

sched-energy.rst:317-405
  • CPU capacity가 서로 다른 asymmetric topology여야 합니다.
  • CPU performance domain을 설명하는 Energy Model이 등록되어야 합니다.
  • Energy Model 계산 복잡도가 scheduler hot path에서 감당 가능한 수준이어야 합니다.
  • cpufreq governor로 schedutil을 사용해 scheduler utilization과 DVFS 결정을 연결해야 합니다.
  • frequency와 CPU capacity에 대해 scale-invariant utilization 신호가 제공되어야 합니다.
  • SMT topology는 현재 EAS 가정과 충돌할 수 있으므로 지원 조건을 별도로 확인해야 합니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 =======================
2 Energy Aware Scheduling
3 =======================
4
5 1. Introduction
6 ---------------
7
8 Energy Aware Scheduling (or EAS) gives the scheduler the ability to predict
9 the impact of its decisions on the energy consumed by CPUs. EAS relies on an
10 Energy Model (EM) of the CPUs to select an energy efficient CPU for each task,
11 with a minimal impact on throughput. This document aims at providing an
12 introduction on how EAS works, what are the main design decisions behind it, and
13 details what is needed to get it to run.
14
15 Before going any further, please note that at the time of writing::
16
17 /!\ EAS does not support platforms with symmetric CPU topologies /!\
18
19 EAS operates only on heterogeneous CPU topologies (such as Arm big.LITTLE)
20 because this is where the potential for saving energy through scheduling is
21 the highest.
22
23 The actual EM used by EAS is _not_ maintained by the scheduler, but by a
24 dedicated framework. For details about this framework and what it provides,
25 please refer to its documentation (see Documentation/power/energy-model.rst).
26
27
28 2. Background and Terminology
29 -----------------------------
30
31 To make it clear from the start:
32 - energy = [joule] (resource like a battery on powered devices)
33 - power = energy/time = [joule/second] = [watt]
34
35 The goal of EAS is to minimize energy, while still getting the job done. That
36 is, we want to maximize::
37
38 performance [inst/s]
39 --------------------
40 power [W]
41
42 which is equivalent to minimizing::
43
44 energy [J]
45 -----------
46 instruction
47
48 while still getting 'good' performance. It is essentially an alternative
49 optimization objective to the current performance-only objective for the
50 scheduler. This alternative considers two objectives: energy-efficiency and
51 performance.
52
53 The idea behind introducing an EM is to allow the scheduler to evaluate the
54 implications of its decisions rather than blindly applying energy-saving
55 techniques that may have positive effects only on some platforms. At the same
56 time, the EM must be as simple as possible to minimize the scheduler latency
57 impact.
58
59 In short, EAS changes the way CFS tasks are assigned to CPUs. When it is time
60 for the scheduler to decide where a task should run (during wake-up), the EM
61 is used to break the tie between several good CPU candidates and pick the one
62 that is predicted to yield the best energy consumption without harming the
63 system's throughput. The predictions made by EAS rely on specific elements of
64 knowledge about the platform's topology, which include the 'capacity' of CPUs,
65 and their respective energy costs.
66
67
68 3. Topology information
69 -----------------------
70
71 EAS (as well as the rest of the scheduler) uses the notion of 'capacity' to
72 differentiate CPUs with different computing throughput. The 'capacity' of a CPU
73 represents the amount of work it can absorb when running at its highest
74 frequency compared to the most capable CPU of the system. Capacity values are
75 normalized in a 1024 range, and are comparable with the utilization signals of
76 tasks and CPUs computed by the Per-Entity Load Tracking (PELT) mechanism. Thanks
77 to capacity and utilization values, EAS is able to estimate how big/busy a
78 task/CPU is, and to take this into consideration when evaluating performance vs
79 energy trade-offs. The capacity of CPUs is provided via arch-specific code
80 through the arch_scale_cpu_capacity() callback.
81
82 The rest of platform knowledge used by EAS is directly read from the Energy
83 Model (EM) framework. The EM of a platform is composed of a power cost table
84 per 'performance domain' in the system (see Documentation/power/energy-model.rst
85 for further details about performance domains).
86
87 The scheduler manages references to the EM objects in the topology code when the
88 scheduling domains are built, or re-built. For each root domain (rd), the
89 scheduler maintains a singly linked list of all performance domains intersecting
90 the current rd->span. Each node in the list contains a pointer to a struct
91 em_perf_domain as provided by the EM framework.
92
93 The lists are attached to the root domains in order to cope with exclusive
94 cpuset configurations. Since the boundaries of exclusive cpusets do not
95 necessarily match those of performance domains, the lists of different root
96 domains can contain duplicate elements.
97
98 Example 1.
99 Let us consider a platform with 12 CPUs, split in 3 performance domains
100 (pd0, pd4 and pd8), organized as follows::
101
102 CPUs: 0 1 2 3 4 5 6 7 8 9 10 11
103 PDs: |--pd0--|--pd4--|---pd8---|
104 RDs: |----rd1----|-----rd2-----|
105
106 Now, consider that userspace decided to split the system with two
107 exclusive cpusets, hence creating two independent root domains, each
108 containing 6 CPUs. The two root domains are denoted rd1 and rd2 in the
109 above figure. Since pd4 intersects with both rd1 and rd2, it will be
110 present in the linked list '->pd' attached to each of them:
111
112 * rd1->pd: pd0 -> pd4
113 * rd2->pd: pd4 -> pd8
114
115 Please note that the scheduler will create two duplicate list nodes for
116 pd4 (one for each list). However, both just hold a pointer to the same
117 shared data structure of the EM framework.
118
119 Since the access to these lists can happen concurrently with hotplug and other
120 things, they are protected by RCU, like the rest of topology structures
121 manipulated by the scheduler.
122
123 EAS also maintains a static key (sched_energy_present) which is enabled when at
124 least one root domain meets all conditions for EAS to start. Those conditions
125 are summarized in Section 6.
126
127
128 4. Energy-Aware task placement
129 ------------------------------
130
131 EAS overrides the CFS task wake-up balancing code. It uses the EM of the
132 platform and the PELT signals to choose an energy-efficient target CPU during
133 wake-up balance. When EAS is enabled, select_task_rq_fair() calls
134 find_energy_efficient_cpu() to do the placement decision. This function looks
135 for the CPU with the highest spare capacity (CPU capacity - CPU utilization) in
136 each performance domain since it is the one which will allow us to keep the
137 frequency the lowest. Then, the function checks if placing the task there could
138 save energy compared to leaving it on prev_cpu, i.e. the CPU where the task ran
139 in its previous activation.
140
141 find_energy_efficient_cpu() uses compute_energy() to estimate what will be the
142 energy consumed by the system if the waking task was migrated. compute_energy()
143 looks at the current utilization landscape of the CPUs and adjusts it to
144 'simulate' the task migration. The EM framework provides the em_pd_energy() API
145 which computes the expected energy consumption of each performance domain for
146 the given utilization landscape.
147
148 An example of energy-optimized task placement decision is detailed below.
149
150 Example 2.
151 Let us consider a (fake) platform with 2 independent performance domains
152 composed of two CPUs each. CPU0 and CPU1 are little CPUs; CPU2 and CPU3
153 are big.
154
155 The scheduler must decide where to place a task P whose util_avg = 200
156 and prev_cpu = 0.
157
158 The current utilization landscape of the CPUs is depicted on the graph
159 below. CPUs 0-3 have a util_avg of 400, 100, 600 and 500 respectively
160 Each performance domain has three Operating Performance Points (OPPs).
161 The CPU capacity and power cost associated with each OPP is listed in
162 the Energy Model table. The util_avg of P is shown on the figures
163 below as 'PP'::
164
165 CPU util.
166 1024 - - - - - - - Energy Model
167 +-----------+-------------+
168 | Little | Big |
169 768 ============= +-----+-----+------+------+
170 | Cap | Pwr | Cap | Pwr |
171 +-----+-----+------+------+
172 512 =========== - ##- - - - - | 170 | 50 | 512 | 400 |
173 ## ## | 341 | 150 | 768 | 800 |
174 341 -PP - - - - ## ## | 512 | 300 | 1024 | 1700 |
175 PP ## ## +-----+-----+------+------+
176 170 -## - - - - ## ##
177 ## ## ## ##
178 ------------ -------------
179 CPU0 CPU1 CPU2 CPU3
180
181 Current OPP: ===== Other OPP: - - - util_avg (100 each): ##
182
183
184 find_energy_efficient_cpu() will first look for the CPUs with the
185 maximum spare capacity in the two performance domains. In this example,
186 CPU1 and CPU3. Then it will estimate the energy of the system if P was
187 placed on either of them, and check if that would save some energy
188 compared to leaving P on CPU0. EAS assumes that OPPs follow utilization
189 (which is coherent with the behaviour of the schedutil CPUFreq
190 governor, see Section 6. for more details on this topic).
191
192 **Case 1. P is migrated to CPU1**::
193
194 1024 - - - - - - -
195
196 Energy calculation:
197 768 ============= * CPU0: 200 / 341 * 150 = 88
198 * CPU1: 300 / 341 * 150 = 131
199 * CPU2: 600 / 768 * 800 = 625
200 512 - - - - - - - ##- - - - - * CPU3: 500 / 768 * 800 = 520
201 ## ## => total_energy = 1364
202 341 =========== ## ##
203 PP ## ##
204 170 -## - - PP- ## ##
205 ## ## ## ##
206 ------------ -------------
207 CPU0 CPU1 CPU2 CPU3
208
209
210 **Case 2. P is migrated to CPU3**::
211
212 1024 - - - - - - -
213
214 Energy calculation:
215 768 ============= * CPU0: 200 / 341 * 150 = 88
216 * CPU1: 100 / 341 * 150 = 43
217 PP * CPU2: 600 / 768 * 800 = 625
218 512 - - - - - - - ##- - -PP - * CPU3: 700 / 768 * 800 = 729
219 ## ## => total_energy = 1485
220 341 =========== ## ##
221 ## ##
222 170 -## - - - - ## ##
223 ## ## ## ##
224 ------------ -------------
225 CPU0 CPU1 CPU2 CPU3
226
227
228 **Case 3. P stays on prev_cpu / CPU 0**::
229
230 1024 - - - - - - -
231
232 Energy calculation:
233 768 ============= * CPU0: 400 / 512 * 300 = 234
234 * CPU1: 100 / 512 * 300 = 58
235 * CPU2: 600 / 768 * 800 = 625
236 512 =========== - ##- - - - - * CPU3: 500 / 768 * 800 = 520
237 ## ## => total_energy = 1437
238 341 -PP - - - - ## ##
239 PP ## ##
240 170 -## - - - - ## ##
241 ## ## ## ##
242 ------------ -------------
243 CPU0 CPU1 CPU2 CPU3
244
245
246 From these calculations, the Case 1 has the lowest total energy. So CPU 1
247 is be the best candidate from an energy-efficiency standpoint.
248
249 Big CPUs are generally more power hungry than the little ones and are thus used
250 mainly when a task doesn't fit the littles. However, little CPUs aren't always
251 necessarily more energy-efficient than big CPUs. For some systems, the high OPPs
252 of the little CPUs can be less energy-efficient than the lowest OPPs of the
253 bigs, for example. So, if the little CPUs happen to have enough utilization at
254 a specific point in time, a small task waking up at that moment could be better
255 of executing on the big side in order to save energy, even though it would fit
256 on the little side.
257
258 And even in the case where all OPPs of the big CPUs are less energy-efficient
259 than those of the little, using the big CPUs for a small task might still, under
260 specific conditions, save energy. Indeed, placing a task on a little CPU can
261 result in raising the OPP of the entire performance domain, and that will
262 increase the cost of the tasks already running there. If the waking task is
263 placed on a big CPU, its own execution cost might be higher than if it was
264 running on a little, but it won't impact the other tasks of the little CPUs
265 which will keep running at a lower OPP. So, when considering the total energy
266 consumed by CPUs, the extra cost of running that one task on a big core can be
267 smaller than the cost of raising the OPP on the little CPUs for all the other
268 tasks.
269
270 The examples above would be nearly impossible to get right in a generic way, and
271 for all platforms, without knowing the cost of running at different OPPs on all
272 CPUs of the system. Thanks to its EM-based design, EAS should cope with them
273 correctly without too many troubles. However, in order to ensure a minimal
274 impact on throughput for high-utilization scenarios, EAS also implements another
275 mechanism called 'over-utilization'.
276
277
278 5. Over-utilization
279 -------------------
280
281 From a general standpoint, the use-cases where EAS can help the most are those
282 involving a light/medium CPU utilization. Whenever long CPU-bound tasks are
283 being run, they will require all of the available CPU capacity, and there isn't
284 much that can be done by the scheduler to save energy without severely harming
285 throughput. In order to avoid hurting performance with EAS, CPUs are flagged as
286 'over-utilized' as soon as they are used at more than 80% of their compute
287 capacity. As long as no CPUs are over-utilized in a root domain, load balancing
288 is disabled and EAS overridess the wake-up balancing code. EAS is likely to load
289 the most energy efficient CPUs of the system more than the others if that can be
290 done without harming throughput. So, the load-balancer is disabled to prevent
291 it from breaking the energy-efficient task placement found by EAS. It is safe to
292 do so when the system isn't overutilized since being below the 80% tipping point
293 implies that:
294
295 a. there is some idle time on all CPUs, so the utilization signals used by
296 EAS are likely to accurately represent the 'size' of the various tasks
297 in the system;
298 b. all tasks should already be provided with enough CPU capacity,
299 regardless of their nice values;
300 c. since there is spare capacity all tasks must be blocking/sleeping
301 regularly and balancing at wake-up is sufficient.
302
303 As soon as one CPU goes above the 80% tipping point, at least one of the three
304 assumptions above becomes incorrect. In this scenario, the 'overutilized' flag
305 is raised for the entire root domain, EAS is disabled, and the load-balancer is
306 re-enabled. By doing so, the scheduler falls back onto load-based algorithms for
307 wake-up and load balance under CPU-bound conditions. This provides a better
308 respect of the nice values of tasks.
309
310 Since the notion of overutilization largely relies on detecting whether or not
311 there is some idle time in the system, the CPU capacity 'stolen' by higher
312 (than CFS) scheduling classes (as well as IRQ) must be taken into account. As
313 such, the detection of overutilization accounts for the capacity used not only
314 by CFS tasks, but also by the other scheduling classes and IRQ.
315
316
317 6. Dependencies and requirements for EAS
318 ----------------------------------------
319
320 Energy Aware Scheduling depends on the CPUs of the system having specific
321 hardware properties and on other features of the kernel being enabled. This
322 section lists these dependencies and provides hints as to how they can be met.
323
324
325 6.1 - Asymmetric CPU topology
326 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
327
328
329 As mentioned in the introduction, EAS is only supported on platforms with
330 asymmetric CPU topologies for now. This requirement is checked at run-time by
331 looking for the presence of the SD_ASYM_CPUCAPACITY_FULL flag when the scheduling
332 domains are built.
333
334 See Documentation/scheduler/sched-capacity.rst for requirements to be met for this
335 flag to be set in the sched_domain hierarchy.
336
337 Please note that EAS is not fundamentally incompatible with SMP, but no
338 significant savings on SMP platforms have been observed yet. This restriction
339 could be amended in the future if proven otherwise.
340
341
342 6.2 - Energy Model presence
343 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
344
345 EAS uses the EM of a platform to estimate the impact of scheduling decisions on
346 energy. So, your platform must provide power cost tables to the EM framework in
347 order to make EAS start. To do so, please refer to documentation of the
348 independent EM framework in Documentation/power/energy-model.rst.
349
350 Please also note that the scheduling domains need to be re-built after the
351 EM has been registered in order to start EAS.
352
353 EAS uses the EM to make a forecasting decision on energy usage and thus it is
354 more focused on the difference when checking possible options for task
355 placement. For EAS it doesn't matter whether the EM power values are expressed
356 in milli-Watts or in an 'abstract scale'.
357
358
359 6.3 - Energy Model complexity
360 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
361
362 EAS does not impose any complexity limit on the number of PDs/OPPs/CPUs but
363 restricts the number of CPUs to EM_MAX_NUM_CPUS to prevent overflows during
364 the energy estimation.
365
366
367 6.4 - Schedutil governor
368 ^^^^^^^^^^^^^^^^^^^^^^^^
369
370 EAS tries to predict at which OPP will the CPUs be running in the close future
371 in order to estimate their energy consumption. To do so, it is assumed that OPPs
372 of CPUs follow their utilization.
373
374 Although it is very difficult to provide hard guarantees regarding the accuracy
375 of this assumption in practice (because the hardware might not do what it is
376 told to do, for example), schedutil as opposed to other CPUFreq governors at
377 least _requests_ frequencies calculated using the utilization signals.
378 Consequently, the only sane governor to use together with EAS is schedutil,
379 because it is the only one providing some degree of consistency between
380 frequency requests and energy predictions.
381
382 Using EAS with any other governor than schedutil is not supported.
383
384
385 6.5 Scale-invariant utilization signals
386 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
387
388 In order to make accurate prediction across CPUs and for all performance
389 states, EAS needs frequency-invariant and CPU-invariant PELT signals. These can
390 be obtained using the architecture-defined arch_scale{cpu,freq}_capacity()
391 callbacks.
392
393 Using EAS on a platform that doesn't implement these two callbacks is not
394 supported.
395
396
397 6.6 Multithreading (SMT)
398 ^^^^^^^^^^^^^^^^^^^^^^^^
399
400 EAS in its current form is SMT unaware and is not able to leverage
401 multithreaded hardware to save energy. EAS considers threads as independent
402 CPUs, which can actually be counter-productive for both performance and energy.
403
404 EAS on SMT is not supported.
405

3. 한국어 전문 번역

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

EAS의 목적과 지원 범위

1-27

Energy Aware Scheduling(EAS)은 scheduler가 task placement 결정이 CPU energy 소비에 미칠 영향을 예측하게 한다. CPU Energy Model(EM)을 이용해 throughput 손실을 최소화하면서 각 task가 실행될 energy-efficient CPU를 선택한다.

문서 작성 시점의 EAS는 symmetric CPU topology를 지원하지 않는다. scheduling으로 energy를 절약할 가능성이 큰 Arm big.LITTLE 같은 heterogeneous topology에서만 동작한다.

EAS가 사용하는 EM은 scheduler가 직접 유지하지 않고 독립 Energy Model framework가 제공한다. power/energy-model 문서에서 performance domain과 power cost table 등록 방식을 확인할 수 있다.

energy, power와 최적화 목표

28-67

energy는 joule로 측정하는 유한 자원이고, power는 단위 시간당 energy인 joule/second 또는 watt다. EAS는 필요한 작업을 완료하면서 총 energy를 최소화한다.

maximize: performance [instructions/s] / power [W]

same objective: minimize energy [J] / instruction

기존 performance-only scheduler 목표에 energy efficiency를 추가한 다목적 최적화다. EM이 없으면 특정 platform에서만 이득인 절전 기법을 scheduler가 맹목적으로 적용할 수 있다. 반대로 EM이 너무 복잡하면 wakeup latency를 늘리므로 필요한 차이를 예측할 만큼 단순해야 한다.

EAS는 CFS task가 wakeup할 때 여러 성능상 적합한 CPU candidate 사이의 tie를 energy 예측으로 푼다. throughput을 해치지 않는 후보 중 예상 energy가 가장 낮은 CPU를 고르며, platform별 CPU capacity와 energy cost를 입력으로 사용한다.

capacity, performance domain과 root domain

68-127

CPU capacity는 system에서 가장 강한 CPU가 최고 frequency로 처리할 수 있는 양을 1024로 정규화한 상대 throughput이다. task와 CPU utilization은 PELT가 같은 1024 scale로 계산하므로 capacity와 직접 비교해 task 크기와 CPU 여유를 판단할 수 있다. architecture는 arch_scale_cpu_capacity() callback으로 값을 제공한다.

나머지 platform 정보는 EM framework의 performance domain별 power cost table에서 읽는다. scheduler가 scheduling domain을 build 또는 rebuild할 때 각 root domain(rd)의 span과 교차하는 모든 performance domain을 singly linked list로 보관하며, node는 EM의 struct em_perf_domain을 가리킨다.

exclusive cpuset 경계와 performance domain 경계는 일치하지 않을 수 있다. 12 CPU가 pd0={0-3}, pd4={4-7}, pd8={8-11}이고 root domain이 rd1={0-5}, rd2={6-11}이면 pd4가 두 rd와 모두 교차한다.

root domainCPU span연결된 EM PD list
rd1CPU 0-5pd0 → pd4
rd2CPU 6-11pd4 → pd8

pd4 list node는 rd마다 별도로 생기지만 두 node가 가리키는 struct em_perf_domain은 같은 EM object다. hotplug과 topology 변경이 list 접근과 동시에 일어날 수 있어 다른 scheduler topology와 마찬가지로 RCU로 보호한다.

sched_energy_present static key는 root domain 하나 이상이 EAS 시작 조건을 모두 만족할 때 활성화된다.

PD 경계와 exclusive cpuset 경계의 교차
CPU/PDrd1: CPU0-5rd2: CPU6-11
01 pd0: CPU0-3rd1->pd node
02 pd4: CPU4-7rd1->pd node → shared pd4shared pd4 ← rd2->pd node
03 pd8: CPU8-11rd2->pd node

pd4는 두 root domain에 걸치므로 list node는 중복되지만 EM data는 공유한다.

energy-aware wakeup placement

128-277

EAS가 켜지면 CFS wakeup balancing의 select_task_rq_fair()가 find_energy_efficient_cpu()를 호출한다. 각 performance domain에서 spare capacity=capacity-utilization이 가장 큰 CPU를 candidate로 선택한다. domain의 최대 utilization이 낮아져 더 낮은 OPP를 유지할 가능성이 가장 큰 CPU이기 때문이다.

그 다음 waking task를 candidate로 옮긴 경우와 이전 activation의 prev_cpu에 남긴 경우를 비교한다. compute_energy()가 현재 CPU utilization landscape에 task migration을 가상 반영하고, em_pd_energy()가 각 performance domain의 예상 energy를 계산한다.

find_energy_efficient_cpu() 결정
CFS task wakeup각 PD에서 capacity-util 최대 CPU 선택task가 capacity에 맞는지 확인candidate placement utilization simulationem_pd_energy()로 PD energy 합산prev_cpu 유지 비용과 비교energy가 가장 낮고 throughput을 해치지 않는 CPU 선택

성능상 맞지 않는 CPU를 먼저 제외하고, domain별 여유가 가장 큰 후보만 EM으로 비교한다.

예제 platform은 CPU0-1 little PD와 CPU2-3 big PD로 구성된다. waking task P는 util_avg=200이고 prev_cpu=CPU0다. 현재 CPU utilization은 각각 400, 100, 600, 500이다.

PDOPP capacity/power 1OPP capacity/power 2OPP capacity/power 3
Little CPU0-1170 / 50341 / 150512 / 300
Big CPU2-3512 / 400768 / 8001024 / 1700
CPU현재 utilPD 내 spare가 큰 후보P 배치 전 상태
CPU0 little400아니오prev_cpu
CPU1 little100little candidate
CPU2 big600아니오실행 중
CPU3 big500big candidate

EAS는 utilization에 맞춰 OPP가 선택된다고 가정하며 이는 schedutil CPUFreq governor의 동작과 일치한다. CPU1에 P를 두면 little PD 최대 util은 300이 되어 capacity 341 OPP를 쓰고, big PD는 capacity 768 OPP를 쓴다.

caseCPU별 energy 계산total energy
1: P → CPU1CPU0 200/341*150=88; CPU1 300/341*150=131; CPU2 600/768*800=625; CPU3 500/768*800=5201364
2: P → CPU3CPU0 200/341*150=88; CPU1 100/341*150=43; CPU2 600/768*800=625; CPU3 700/768*800=7291485
3: P → prev CPU0CPU0 400/512*300=234; CPU1 100/512*300=58; CPU2 600/768*800=625; CPU3 500/768*800=5201437

case 1의 total energy 1364가 가장 낮아 CPU1이 선택된다. 원문 표에서는 migration 뒤 CPU0 util을 200으로 표시한다. 이는 waking P의 200을 이전 CPU utilization에서 빼고 candidate에 더해 simulation한다는 의미다.

big CPU가 보통 더 많은 power를 쓰므로 task가 little capacity에 맞지 않을 때 주로 사용하지만, 모든 상황에서 little이 더 energy-efficient한 것은 아니다. little의 높은 OPP가 big의 낮은 OPP보다 나쁠 수 있다.

big의 모든 OPP 효율이 더 낮아도 small task를 big에 두는 편이 system total energy를 줄일 수 있다. little에 task를 더해 domain 전체 OPP가 올라가면 이미 그 domain에서 실행 중인 모든 task 비용이 증가한다. big에서 waking task 하나가 추가로 쓰는 비용이 little domain 전체 OPP 상승 비용보다 작을 수 있다.

이런 platform별 trade-off를 일반 scheduler heuristic만으로 정확히 풀기 어렵기 때문에 EM이 필요하다. 다만 utilization이 매우 높을 때 energy placement가 throughput을 해치지 않도록 over-utilization mechanism을 별도로 사용한다.

over-utilization과 load balancer 전환

278-316

EAS의 이득은 CPU utilization이 가볍거나 중간 정도일 때 가장 크다. 긴 CPU-bound task가 전체 capacity를 요구하면 throughput을 크게 낮추지 않고 절약할 energy가 거의 없다.

CPU 사용량이 compute capacity의 80%를 넘으면 over-utilized로 판단한다. root domain에 over-utilized CPU가 하나도 없으면 일반 load balancing을 끄고 EAS가 wakeup balancing을 대체한다. EAS는 energy-efficient CPU에 의도적으로 task를 더 모을 수 있으므로 일반 balancer가 그 배치를 다시 흩뜨리지 않게 한다.

  • 모든 CPU가 80% 아래면 idle time이 있어 PELT utilization이 task 크기를 비교적 정확히 나타낸다.
  • 모든 task가 nice 값과 무관하게 필요한 CPU capacity를 이미 받을 수 있다.
  • spare capacity가 있으므로 task가 주기적으로 block/sleep하고 wakeup 시점 balancing만으로 충분하다.

CPU 하나라도 80%를 넘으면 가정 중 적어도 하나가 깨진다. root domain 전체에 overutilized flag를 세우고 EAS를 끄며 load balancer를 다시 켠다. CPU-bound 조건에서는 load 기반 wakeup과 periodic balancing이 task nice 값을 더 잘 반영한다.

over-utilization은 system에 idle time이 있는지 판단하는 개념이므로 CFS보다 높은 scheduling class와 IRQ가 가져간 CPU capacity도 포함한다. CFS task utilization만 보고 spare를 계산하면 실제로 사용할 수 없는 capacity를 있다고 오판할 수 있다.

EAS와 load balancing mode 전환
모든 CPU util <= 80%sched_energy_present 조건 충족EAS wakeup placement일반 load balancer 억제
어느 CPU util > 80%root domain overutilizedEAS disableload-based balancing 재활성화

root domain의 CPU 하나가 capacity 80%를 넘는 순간 throughput 중심 알고리즘으로 돌아간다.

EAS 활성화 조건

317-404

EAS는 hardware topology와 kernel 기능이 특정 조건을 만족해야 시작한다. scheduler domain build 시 SD_ASYM_CPUCAPACITY_FULL flag를 찾아 asymmetric CPU topology인지 확인한다. EAS가 본질적으로 SMP와 양립할 수 없는 것은 아니지만 symmetric platform에서 의미 있는 절감이 관측되지 않아 현재 지원하지 않는다.

platform은 EM framework에 power cost table을 등록해야 한다. EM 등록 뒤 scheduling domain을 rebuild해야 EAS가 시작된다. EAS는 placement 후보 사이 energy 차이만 비교하므로 power 값은 milli-watt 같은 실제 단위여도 되고 일관된 abstract scale이어도 된다.

performance domain, OPP와 CPU 수의 알고리즘 복잡도에 별도 제한을 두지는 않지만 energy 계산 overflow를 막기 위해 CPU 수를 EM_MAX_NUM_CPUS로 제한한다.

EAS는 가까운 미래 CPU OPP가 utilization을 따라간다고 가정한다. hardware가 frequency request를 정확히 따르지 않을 수 있어 완전한 보장은 어렵지만, schedutil은 PELT utilization으로 frequency를 요청하므로 energy prediction과 일관성을 제공하는 유일하게 지원되는 governor다. 다른 CPUFreq governor와 EAS 조합은 지원하지 않는다.

서로 다른 CPU와 모든 performance state를 비교하려면 PELT signal이 frequency-invariant이고 CPU-invariant여야 한다. architecture가 arch_scale_cpu_capacity()와 arch_scale_freq_capacity() callback을 구현해야 하며, 둘 중 하나라도 없으면 EAS를 지원하지 않는다.

현재 EAS는 SMT를 인식하지 못하고 hardware thread를 독립 CPU로 취급한다. 이 모델은 performance와 energy 모두에 역효과를 낼 수 있으므로 SMT platform에서는 지원하지 않는다.

요구 조건검사 또는 제공 요소
Asymmetric topologySD_ASYM_CPUCAPACITY_FULL
Energy Modelperformance domain별 power cost table, 등록 뒤 sched domain rebuild
CPUFreq governorschedutil
Scale invariancearch_scale_cpu_capacity(), arch_scale_freq_capacity()
CPU 수EM_MAX_NUM_CPUS 이하
SMT지원하지 않음