xref: /openbmc/linux/Documentation/power/powercap/powercap.rst (revision 4b4193256c8d3bc3a5397b5cd9494c2ad386317d)
1151f4e2bSMauro Carvalho Chehab=======================
2151f4e2bSMauro Carvalho ChehabPower Capping Framework
3151f4e2bSMauro Carvalho Chehab=======================
4151f4e2bSMauro Carvalho Chehab
5151f4e2bSMauro Carvalho ChehabThe power capping framework provides a consistent interface between the kernel
6151f4e2bSMauro Carvalho Chehaband the user space that allows power capping drivers to expose the settings to
7151f4e2bSMauro Carvalho Chehabuser space in a uniform way.
8151f4e2bSMauro Carvalho Chehab
9151f4e2bSMauro Carvalho ChehabTerminology
10151f4e2bSMauro Carvalho Chehab===========
11151f4e2bSMauro Carvalho Chehab
12151f4e2bSMauro Carvalho ChehabThe framework exposes power capping devices to user space via sysfs in the
13151f4e2bSMauro Carvalho Chehabform of a tree of objects. The objects at the root level of the tree represent
14151f4e2bSMauro Carvalho Chehab'control types', which correspond to different methods of power capping.  For
15151f4e2bSMauro Carvalho Chehabexample, the intel-rapl control type represents the Intel "Running Average
16151f4e2bSMauro Carvalho ChehabPower Limit" (RAPL) technology, whereas the 'idle-injection' control type
17151f4e2bSMauro Carvalho Chehabcorresponds to the use of idle injection for controlling power.
18151f4e2bSMauro Carvalho Chehab
19151f4e2bSMauro Carvalho ChehabPower zones represent different parts of the system, which can be controlled and
20151f4e2bSMauro Carvalho Chehabmonitored using the power capping method determined by the control type the
21151f4e2bSMauro Carvalho Chehabgiven zone belongs to. They each contain attributes for monitoring power, as
22151f4e2bSMauro Carvalho Chehabwell as controls represented in the form of power constraints.  If the parts of
23151f4e2bSMauro Carvalho Chehabthe system represented by different power zones are hierarchical (that is, one
24151f4e2bSMauro Carvalho Chehabbigger part consists of multiple smaller parts that each have their own power
25151f4e2bSMauro Carvalho Chehabcontrols), those power zones may also be organized in a hierarchy with one
26151f4e2bSMauro Carvalho Chehabparent power zone containing multiple subzones and so on to reflect the power
27151f4e2bSMauro Carvalho Chehabcontrol topology of the system.  In that case, it is possible to apply power
28151f4e2bSMauro Carvalho Chehabcapping to a set of devices together using the parent power zone and if more
29151f4e2bSMauro Carvalho Chehabfine grained control is required, it can be applied through the subzones.
30151f4e2bSMauro Carvalho Chehab
31151f4e2bSMauro Carvalho Chehab
32151f4e2bSMauro Carvalho ChehabExample sysfs interface tree::
33151f4e2bSMauro Carvalho Chehab
34151f4e2bSMauro Carvalho Chehab  /sys/devices/virtual/powercap
35151f4e2bSMauro Carvalho Chehab  └──intel-rapl
36151f4e2bSMauro Carvalho Chehab      ├──intel-rapl:0
37151f4e2bSMauro Carvalho Chehab      │   ├──constraint_0_name
38151f4e2bSMauro Carvalho Chehab      │   ├──constraint_0_power_limit_uw
39151f4e2bSMauro Carvalho Chehab      │   ├──constraint_0_time_window_us
40151f4e2bSMauro Carvalho Chehab      │   ├──constraint_1_name
41151f4e2bSMauro Carvalho Chehab      │   ├──constraint_1_power_limit_uw
42151f4e2bSMauro Carvalho Chehab      │   ├──constraint_1_time_window_us
43151f4e2bSMauro Carvalho Chehab      │   ├──device -> ../../intel-rapl
44151f4e2bSMauro Carvalho Chehab      │   ├──energy_uj
45151f4e2bSMauro Carvalho Chehab      │   ├──intel-rapl:0:0
46151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_0_name
47151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_0_power_limit_uw
48151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_0_time_window_us
49151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_1_name
50151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_1_power_limit_uw
51151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_1_time_window_us
52151f4e2bSMauro Carvalho Chehab      │   │   ├──device -> ../../intel-rapl:0
53151f4e2bSMauro Carvalho Chehab      │   │   ├──energy_uj
54151f4e2bSMauro Carvalho Chehab      │   │   ├──max_energy_range_uj
55151f4e2bSMauro Carvalho Chehab      │   │   ├──name
56151f4e2bSMauro Carvalho Chehab      │   │   ├──enabled
57151f4e2bSMauro Carvalho Chehab      │   │   ├──power
58151f4e2bSMauro Carvalho Chehab      │   │   │   ├──async
59151f4e2bSMauro Carvalho Chehab      │   │   │   []
60151f4e2bSMauro Carvalho Chehab      │   │   ├──subsystem -> ../../../../../../class/power_cap
61151f4e2bSMauro Carvalho Chehab      │   │   └──uevent
62151f4e2bSMauro Carvalho Chehab      │   ├──intel-rapl:0:1
63151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_0_name
64151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_0_power_limit_uw
65151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_0_time_window_us
66151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_1_name
67151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_1_power_limit_uw
68151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_1_time_window_us
69151f4e2bSMauro Carvalho Chehab      │   │   ├──device -> ../../intel-rapl:0
70151f4e2bSMauro Carvalho Chehab      │   │   ├──energy_uj
71151f4e2bSMauro Carvalho Chehab      │   │   ├──max_energy_range_uj
72151f4e2bSMauro Carvalho Chehab      │   │   ├──name
73151f4e2bSMauro Carvalho Chehab      │   │   ├──enabled
74151f4e2bSMauro Carvalho Chehab      │   │   ├──power
75151f4e2bSMauro Carvalho Chehab      │   │   │   ├──async
76151f4e2bSMauro Carvalho Chehab      │   │   │   []
77151f4e2bSMauro Carvalho Chehab      │   │   ├──subsystem -> ../../../../../../class/power_cap
78151f4e2bSMauro Carvalho Chehab      │   │   └──uevent
79151f4e2bSMauro Carvalho Chehab      │   ├──max_energy_range_uj
80151f4e2bSMauro Carvalho Chehab      │   ├──max_power_range_uw
81151f4e2bSMauro Carvalho Chehab      │   ├──name
82151f4e2bSMauro Carvalho Chehab      │   ├──enabled
83151f4e2bSMauro Carvalho Chehab      │   ├──power
84151f4e2bSMauro Carvalho Chehab      │   │   ├──async
85151f4e2bSMauro Carvalho Chehab      │   │   []
86151f4e2bSMauro Carvalho Chehab      │   ├──subsystem -> ../../../../../class/power_cap
87151f4e2bSMauro Carvalho Chehab      │   ├──enabled
88151f4e2bSMauro Carvalho Chehab      │   ├──uevent
89151f4e2bSMauro Carvalho Chehab      ├──intel-rapl:1
90151f4e2bSMauro Carvalho Chehab      │   ├──constraint_0_name
91151f4e2bSMauro Carvalho Chehab      │   ├──constraint_0_power_limit_uw
92151f4e2bSMauro Carvalho Chehab      │   ├──constraint_0_time_window_us
93151f4e2bSMauro Carvalho Chehab      │   ├──constraint_1_name
94151f4e2bSMauro Carvalho Chehab      │   ├──constraint_1_power_limit_uw
95151f4e2bSMauro Carvalho Chehab      │   ├──constraint_1_time_window_us
96151f4e2bSMauro Carvalho Chehab      │   ├──device -> ../../intel-rapl
97151f4e2bSMauro Carvalho Chehab      │   ├──energy_uj
98151f4e2bSMauro Carvalho Chehab      │   ├──intel-rapl:1:0
99151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_0_name
100151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_0_power_limit_uw
101151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_0_time_window_us
102151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_1_name
103151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_1_power_limit_uw
104151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_1_time_window_us
105151f4e2bSMauro Carvalho Chehab      │   │   ├──device -> ../../intel-rapl:1
106151f4e2bSMauro Carvalho Chehab      │   │   ├──energy_uj
107151f4e2bSMauro Carvalho Chehab      │   │   ├──max_energy_range_uj
108151f4e2bSMauro Carvalho Chehab      │   │   ├──name
109151f4e2bSMauro Carvalho Chehab      │   │   ├──enabled
110151f4e2bSMauro Carvalho Chehab      │   │   ├──power
111151f4e2bSMauro Carvalho Chehab      │   │   │   ├──async
112151f4e2bSMauro Carvalho Chehab      │   │   │   []
113151f4e2bSMauro Carvalho Chehab      │   │   ├──subsystem -> ../../../../../../class/power_cap
114151f4e2bSMauro Carvalho Chehab      │   │   └──uevent
115151f4e2bSMauro Carvalho Chehab      │   ├──intel-rapl:1:1
116151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_0_name
117151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_0_power_limit_uw
118151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_0_time_window_us
119151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_1_name
120151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_1_power_limit_uw
121151f4e2bSMauro Carvalho Chehab      │   │   ├──constraint_1_time_window_us
122151f4e2bSMauro Carvalho Chehab      │   │   ├──device -> ../../intel-rapl:1
123151f4e2bSMauro Carvalho Chehab      │   │   ├──energy_uj
124151f4e2bSMauro Carvalho Chehab      │   │   ├──max_energy_range_uj
125151f4e2bSMauro Carvalho Chehab      │   │   ├──name
126151f4e2bSMauro Carvalho Chehab      │   │   ├──enabled
127151f4e2bSMauro Carvalho Chehab      │   │   ├──power
128151f4e2bSMauro Carvalho Chehab      │   │   │   ├──async
129151f4e2bSMauro Carvalho Chehab      │   │   │   []
130151f4e2bSMauro Carvalho Chehab      │   │   ├──subsystem -> ../../../../../../class/power_cap
131151f4e2bSMauro Carvalho Chehab      │   │   └──uevent
132151f4e2bSMauro Carvalho Chehab      │   ├──max_energy_range_uj
133151f4e2bSMauro Carvalho Chehab      │   ├──max_power_range_uw
134151f4e2bSMauro Carvalho Chehab      │   ├──name
135151f4e2bSMauro Carvalho Chehab      │   ├──enabled
136151f4e2bSMauro Carvalho Chehab      │   ├──power
137151f4e2bSMauro Carvalho Chehab      │   │   ├──async
138151f4e2bSMauro Carvalho Chehab      │   │   []
139151f4e2bSMauro Carvalho Chehab      │   ├──subsystem -> ../../../../../class/power_cap
140151f4e2bSMauro Carvalho Chehab      │   ├──uevent
141151f4e2bSMauro Carvalho Chehab      ├──power
142151f4e2bSMauro Carvalho Chehab      │   ├──async
143151f4e2bSMauro Carvalho Chehab      │   []
144151f4e2bSMauro Carvalho Chehab      ├──subsystem -> ../../../../class/power_cap
145151f4e2bSMauro Carvalho Chehab      ├──enabled
146151f4e2bSMauro Carvalho Chehab      └──uevent
147151f4e2bSMauro Carvalho Chehab
148151f4e2bSMauro Carvalho ChehabThe above example illustrates a case in which the Intel RAPL technology,
149151f4e2bSMauro Carvalho Chehabavailable in Intel® IA-64 and IA-32 Processor Architectures, is used. There is one
150151f4e2bSMauro Carvalho Chehabcontrol type called intel-rapl which contains two power zones, intel-rapl:0 and
151151f4e2bSMauro Carvalho Chehabintel-rapl:1, representing CPU packages.  Each of these power zones contains
152151f4e2bSMauro Carvalho Chehabtwo subzones, intel-rapl:j:0 and intel-rapl:j:1 (j = 0, 1), representing the
153151f4e2bSMauro Carvalho Chehab"core" and the "uncore" parts of the given CPU package, respectively.  All of
154151f4e2bSMauro Carvalho Chehabthe zones and subzones contain energy monitoring attributes (energy_uj,
155151f4e2bSMauro Carvalho Chehabmax_energy_range_uj) and constraint attributes (constraint_*) allowing controls
156151f4e2bSMauro Carvalho Chehabto be applied (the constraints in the 'package' power zones apply to the whole
157151f4e2bSMauro Carvalho ChehabCPU packages and the subzone constraints only apply to the respective parts of
158151f4e2bSMauro Carvalho Chehabthe given package individually). Since Intel RAPL doesn't provide instantaneous
159151f4e2bSMauro Carvalho Chehabpower value, there is no power_uw attribute.
160151f4e2bSMauro Carvalho Chehab
161151f4e2bSMauro Carvalho ChehabIn addition to that, each power zone contains a name attribute, allowing the
162151f4e2bSMauro Carvalho Chehabpart of the system represented by that zone to be identified.
163151f4e2bSMauro Carvalho ChehabFor example::
164151f4e2bSMauro Carvalho Chehab
165151f4e2bSMauro Carvalho Chehab	cat /sys/class/power_cap/intel-rapl/intel-rapl:0/name
166151f4e2bSMauro Carvalho Chehab
167151f4e2bSMauro Carvalho Chehabpackage-0
168151f4e2bSMauro Carvalho Chehab---------
169151f4e2bSMauro Carvalho Chehab
170*8365a898SSumeet PawnikarDepending on different power zones, the Intel RAPL technology allows
171*8365a898SSumeet Pawnikarone or multiple constraints like short term, long term and peak power,
172*8365a898SSumeet Pawnikarwith different time windows to be applied to each power zone.
173*8365a898SSumeet PawnikarAll the zones contain attributes representing the constraint names,
174*8365a898SSumeet Pawnikarpower limits and the sizes of the time windows. Note that time window
175*8365a898SSumeet Pawnikaris not applicable to peak power. Here, constraint_j_* attributes
176*8365a898SSumeet Pawnikarcorrespond to the jth constraint (j = 0,1,2).
177151f4e2bSMauro Carvalho Chehab
178151f4e2bSMauro Carvalho ChehabFor example::
179151f4e2bSMauro Carvalho Chehab
180151f4e2bSMauro Carvalho Chehab	constraint_0_name
181151f4e2bSMauro Carvalho Chehab	constraint_0_power_limit_uw
182151f4e2bSMauro Carvalho Chehab	constraint_0_time_window_us
183151f4e2bSMauro Carvalho Chehab	constraint_1_name
184151f4e2bSMauro Carvalho Chehab	constraint_1_power_limit_uw
185151f4e2bSMauro Carvalho Chehab	constraint_1_time_window_us
186*8365a898SSumeet Pawnikar	constraint_2_name
187*8365a898SSumeet Pawnikar	constraint_2_power_limit_uw
188*8365a898SSumeet Pawnikar	constraint_2_time_window_us
189151f4e2bSMauro Carvalho Chehab
190151f4e2bSMauro Carvalho ChehabPower Zone Attributes
191151f4e2bSMauro Carvalho Chehab=====================
192151f4e2bSMauro Carvalho Chehab
193151f4e2bSMauro Carvalho ChehabMonitoring attributes
194151f4e2bSMauro Carvalho Chehab---------------------
195151f4e2bSMauro Carvalho Chehab
196151f4e2bSMauro Carvalho Chehabenergy_uj (rw)
197151f4e2bSMauro Carvalho Chehab	Current energy counter in micro joules. Write "0" to reset.
198151f4e2bSMauro Carvalho Chehab	If the counter can not be reset, then this attribute is read only.
199151f4e2bSMauro Carvalho Chehab
200151f4e2bSMauro Carvalho Chehabmax_energy_range_uj (ro)
201151f4e2bSMauro Carvalho Chehab	Range of the above energy counter in micro-joules.
202151f4e2bSMauro Carvalho Chehab
203151f4e2bSMauro Carvalho Chehabpower_uw (ro)
204151f4e2bSMauro Carvalho Chehab	Current power in micro watts.
205151f4e2bSMauro Carvalho Chehab
206151f4e2bSMauro Carvalho Chehabmax_power_range_uw (ro)
207151f4e2bSMauro Carvalho Chehab	Range of the above power value in micro-watts.
208151f4e2bSMauro Carvalho Chehab
209151f4e2bSMauro Carvalho Chehabname (ro)
210151f4e2bSMauro Carvalho Chehab	Name of this power zone.
211151f4e2bSMauro Carvalho Chehab
212151f4e2bSMauro Carvalho ChehabIt is possible that some domains have both power ranges and energy counter ranges;
213151f4e2bSMauro Carvalho Chehabhowever, only one is mandatory.
214151f4e2bSMauro Carvalho Chehab
215151f4e2bSMauro Carvalho ChehabConstraints
216151f4e2bSMauro Carvalho Chehab-----------
217151f4e2bSMauro Carvalho Chehab
218151f4e2bSMauro Carvalho Chehabconstraint_X_power_limit_uw (rw)
219151f4e2bSMauro Carvalho Chehab	Power limit in micro watts, which should be applicable for the
220151f4e2bSMauro Carvalho Chehab	time window specified by "constraint_X_time_window_us".
221151f4e2bSMauro Carvalho Chehab
222151f4e2bSMauro Carvalho Chehabconstraint_X_time_window_us (rw)
223151f4e2bSMauro Carvalho Chehab	Time window in micro seconds.
224151f4e2bSMauro Carvalho Chehab
225151f4e2bSMauro Carvalho Chehabconstraint_X_name (ro)
226151f4e2bSMauro Carvalho Chehab	An optional name of the constraint
227151f4e2bSMauro Carvalho Chehab
228151f4e2bSMauro Carvalho Chehabconstraint_X_max_power_uw(ro)
229151f4e2bSMauro Carvalho Chehab	Maximum allowed power in micro watts.
230151f4e2bSMauro Carvalho Chehab
231151f4e2bSMauro Carvalho Chehabconstraint_X_min_power_uw(ro)
232151f4e2bSMauro Carvalho Chehab	Minimum allowed power in micro watts.
233151f4e2bSMauro Carvalho Chehab
234151f4e2bSMauro Carvalho Chehabconstraint_X_max_time_window_us(ro)
235151f4e2bSMauro Carvalho Chehab	Maximum allowed time window in micro seconds.
236151f4e2bSMauro Carvalho Chehab
237151f4e2bSMauro Carvalho Chehabconstraint_X_min_time_window_us(ro)
238151f4e2bSMauro Carvalho Chehab	Minimum allowed time window in micro seconds.
239151f4e2bSMauro Carvalho Chehab
240151f4e2bSMauro Carvalho ChehabExcept power_limit_uw and time_window_us other fields are optional.
241151f4e2bSMauro Carvalho Chehab
242151f4e2bSMauro Carvalho ChehabCommon zone and control type attributes
243151f4e2bSMauro Carvalho Chehab---------------------------------------
244151f4e2bSMauro Carvalho Chehab
245151f4e2bSMauro Carvalho Chehabenabled (rw): Enable/Disable controls at zone level or for all zones using
246151f4e2bSMauro Carvalho Chehaba control type.
247151f4e2bSMauro Carvalho Chehab
248151f4e2bSMauro Carvalho ChehabPower Cap Client Driver Interface
249151f4e2bSMauro Carvalho Chehab=================================
250151f4e2bSMauro Carvalho Chehab
251151f4e2bSMauro Carvalho ChehabThe API summary:
252151f4e2bSMauro Carvalho Chehab
253151f4e2bSMauro Carvalho ChehabCall powercap_register_control_type() to register control type object.
254151f4e2bSMauro Carvalho ChehabCall powercap_register_zone() to register a power zone (under a given
255151f4e2bSMauro Carvalho Chehabcontrol type), either as a top-level power zone or as a subzone of another
256151f4e2bSMauro Carvalho Chehabpower zone registered earlier.
257151f4e2bSMauro Carvalho ChehabThe number of constraints in a power zone and the corresponding callbacks have
258151f4e2bSMauro Carvalho Chehabto be defined prior to calling powercap_register_zone() to register that zone.
259151f4e2bSMauro Carvalho Chehab
260151f4e2bSMauro Carvalho ChehabTo Free a power zone call powercap_unregister_zone().
261151f4e2bSMauro Carvalho ChehabTo free a control type object call powercap_unregister_control_type().
262151f4e2bSMauro Carvalho ChehabDetailed API can be generated using kernel-doc on include/linux/powercap.h.
263