xref: /OK3568_Linux_fs/kernel/Documentation/power/powercap/dtpm.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun==========================================
4*4882a593SmuzhiyunDynamic Thermal Power Management framework
5*4882a593Smuzhiyun==========================================
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunOn the embedded world, the complexity of the SoC leads to an
8*4882a593Smuzhiyunincreasing number of hotspots which need to be monitored and mitigated
9*4882a593Smuzhiyunas a whole in order to prevent the temperature to go above the
10*4882a593Smuzhiyunnormative and legally stated 'skin temperature'.
11*4882a593Smuzhiyun
12*4882a593SmuzhiyunAnother aspect is to sustain the performance for a given power budget,
13*4882a593Smuzhiyunfor example virtual reality where the user can feel dizziness if the
14*4882a593Smuzhiyunperformance is capped while a big CPU is processing something else. Or
15*4882a593Smuzhiyunreduce the battery charging because the dissipated power is too high
16*4882a593Smuzhiyuncompared with the power consumed by other devices.
17*4882a593Smuzhiyun
18*4882a593SmuzhiyunThe user space is the most adequate place to dynamically act on the
19*4882a593Smuzhiyundifferent devices by limiting their power given an application
20*4882a593Smuzhiyunprofile: it has the knowledge of the platform.
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunThe Dynamic Thermal Power Management (DTPM) is a technique acting on
23*4882a593Smuzhiyunthe device power by limiting and/or balancing a power budget among
24*4882a593Smuzhiyundifferent devices.
25*4882a593Smuzhiyun
26*4882a593SmuzhiyunThe DTPM framework provides an unified interface to act on the
27*4882a593Smuzhiyundevice power.
28*4882a593Smuzhiyun
29*4882a593SmuzhiyunOverview
30*4882a593Smuzhiyun========
31*4882a593Smuzhiyun
32*4882a593SmuzhiyunThe DTPM framework relies on the powercap framework to create the
33*4882a593Smuzhiyunpowercap entries in the sysfs directory and implement the backend
34*4882a593Smuzhiyundriver to do the connection with the power manageable device.
35*4882a593Smuzhiyun
36*4882a593SmuzhiyunThe DTPM is a tree representation describing the power constraints
37*4882a593Smuzhiyunshared between devices, not their physical positions.
38*4882a593Smuzhiyun
39*4882a593SmuzhiyunThe nodes of the tree are a virtual description aggregating the power
40*4882a593Smuzhiyuncharacteristics of the children nodes and their power limitations.
41*4882a593Smuzhiyun
42*4882a593SmuzhiyunThe leaves of the tree are the real power manageable devices.
43*4882a593Smuzhiyun
44*4882a593SmuzhiyunFor instance::
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun  SoC
47*4882a593Smuzhiyun   |
48*4882a593Smuzhiyun   `-- pkg
49*4882a593Smuzhiyun	|
50*4882a593Smuzhiyun	|-- pd0 (cpu0-3)
51*4882a593Smuzhiyun	|
52*4882a593Smuzhiyun	`-- pd1 (cpu4-5)
53*4882a593Smuzhiyun
54*4882a593SmuzhiyunThe pkg power will be the sum of pd0 and pd1 power numbers::
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun  SoC (400mW - 3100mW)
57*4882a593Smuzhiyun   |
58*4882a593Smuzhiyun   `-- pkg (400mW - 3100mW)
59*4882a593Smuzhiyun	|
60*4882a593Smuzhiyun	|-- pd0 (100mW - 700mW)
61*4882a593Smuzhiyun	|
62*4882a593Smuzhiyun	`-- pd1 (300mW - 2400mW)
63*4882a593Smuzhiyun
64*4882a593SmuzhiyunWhen the nodes are inserted in the tree, their power characteristics are propagated to the parents::
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun  SoC (600mW - 5900mW)
67*4882a593Smuzhiyun   |
68*4882a593Smuzhiyun   |-- pkg (400mW - 3100mW)
69*4882a593Smuzhiyun   |    |
70*4882a593Smuzhiyun   |    |-- pd0 (100mW - 700mW)
71*4882a593Smuzhiyun   |    |
72*4882a593Smuzhiyun   |    `-- pd1 (300mW - 2400mW)
73*4882a593Smuzhiyun   |
74*4882a593Smuzhiyun   `-- pd2 (200mW - 2800mW)
75*4882a593Smuzhiyun
76*4882a593SmuzhiyunEach node have a weight on a 2^10 basis reflecting the percentage of power consumption along the siblings::
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun  SoC (w=1024)
79*4882a593Smuzhiyun   |
80*4882a593Smuzhiyun   |-- pkg (w=538)
81*4882a593Smuzhiyun   |    |
82*4882a593Smuzhiyun   |    |-- pd0 (w=231)
83*4882a593Smuzhiyun   |    |
84*4882a593Smuzhiyun   |    `-- pd1 (w=794)
85*4882a593Smuzhiyun   |
86*4882a593Smuzhiyun   `-- pd2 (w=486)
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun   Note the sum of weights at the same level are equal to 1024.
89*4882a593Smuzhiyun
90*4882a593SmuzhiyunWhen a power limitation is applied to a node, then it is distributed along the children given their weights. For example, if we set a power limitation of 3200mW at the 'SoC' root node, the resulting tree will be::
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun  SoC (w=1024) <--- power_limit = 3200mW
93*4882a593Smuzhiyun   |
94*4882a593Smuzhiyun   |-- pkg (w=538) --> power_limit = 1681mW
95*4882a593Smuzhiyun   |    |
96*4882a593Smuzhiyun   |    |-- pd0 (w=231) --> power_limit = 378mW
97*4882a593Smuzhiyun   |    |
98*4882a593Smuzhiyun   |    `-- pd1 (w=794) --> power_limit = 1303mW
99*4882a593Smuzhiyun   |
100*4882a593Smuzhiyun   `-- pd2 (w=486) --> power_limit = 1519mW
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun
103*4882a593SmuzhiyunFlat description
104*4882a593Smuzhiyun----------------
105*4882a593Smuzhiyun
106*4882a593SmuzhiyunA root node is created and it is the parent of all the nodes. This
107*4882a593Smuzhiyundescription is the simplest one and it is supposed to give to user
108*4882a593Smuzhiyunspace a flat representation of all the devices supporting the power
109*4882a593Smuzhiyunlimitation without any power limitation distribution.
110*4882a593Smuzhiyun
111*4882a593SmuzhiyunHierarchical description
112*4882a593Smuzhiyun------------------------
113*4882a593Smuzhiyun
114*4882a593SmuzhiyunThe different devices supporting the power limitation are represented
115*4882a593Smuzhiyunhierarchically. There is one root node, all intermediate nodes are
116*4882a593Smuzhiyungrouping the child nodes which can be intermediate nodes also or real
117*4882a593Smuzhiyundevices.
118*4882a593Smuzhiyun
119*4882a593SmuzhiyunThe intermediate nodes aggregate the power information and allows to
120*4882a593Smuzhiyunset the power limit given the weight of the nodes.
121*4882a593Smuzhiyun
122*4882a593SmuzhiyunUser space API
123*4882a593Smuzhiyun==============
124*4882a593Smuzhiyun
125*4882a593SmuzhiyunAs stated in the overview, the DTPM framework is built on top of the
126*4882a593Smuzhiyunpowercap framework. Thus the sysfs interface is the same, please refer
127*4882a593Smuzhiyunto the powercap documentation for further details.
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun * power_uw: Instantaneous power consumption. If the node is an
130*4882a593Smuzhiyun   intermediate node, then the power consumption will be the sum of all
131*4882a593Smuzhiyun   children power consumption.
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun * max_power_range_uw: The power range resulting of the maximum power
134*4882a593Smuzhiyun   minus the minimum power.
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun * name: The name of the node. This is implementation dependent. Even
137*4882a593Smuzhiyun   if it is not recommended for the user space, several nodes can have
138*4882a593Smuzhiyun   the same name.
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun * constraint_X_name: The name of the constraint.
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun * constraint_X_max_power_uw: The maximum power limit to be applicable
143*4882a593Smuzhiyun   to the node.
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun * constraint_X_power_limit_uw: The power limit to be applied to the
146*4882a593Smuzhiyun   node. If the value contained in constraint_X_max_power_uw is set,
147*4882a593Smuzhiyun   the constraint will be removed.
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun * constraint_X_time_window_us: The meaning of this file will depend
150*4882a593Smuzhiyun   on the constraint number.
151*4882a593Smuzhiyun
152*4882a593SmuzhiyunConstraints
153*4882a593Smuzhiyun-----------
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun * Constraint 0: The power limitation is immediately applied, without
156*4882a593Smuzhiyun   limitation in time.
157*4882a593Smuzhiyun
158*4882a593SmuzhiyunKernel API
159*4882a593Smuzhiyun==========
160*4882a593Smuzhiyun
161*4882a593SmuzhiyunOverview
162*4882a593Smuzhiyun--------
163*4882a593Smuzhiyun
164*4882a593SmuzhiyunThe DTPM framework has no power limiting backend support. It is
165*4882a593Smuzhiyungeneric and provides a set of API to let the different drivers to
166*4882a593Smuzhiyunimplement the backend part for the power limitation and create the
167*4882a593Smuzhiyunpower constraints tree.
168*4882a593Smuzhiyun
169*4882a593SmuzhiyunIt is up to the platform to provide the initialization function to
170*4882a593Smuzhiyunallocate and link the different nodes of the tree.
171*4882a593Smuzhiyun
172*4882a593SmuzhiyunA special macro has the role of declaring a node and the corresponding
173*4882a593Smuzhiyuninitialization function via a description structure. This one contains
174*4882a593Smuzhiyunan optional parent field allowing to hook different devices to an
175*4882a593Smuzhiyunalready existing tree at boot time.
176*4882a593Smuzhiyun
177*4882a593SmuzhiyunFor instance::
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun	struct dtpm_descr my_descr = {
180*4882a593Smuzhiyun		.name = "my_name",
181*4882a593Smuzhiyun		.init = my_init_func,
182*4882a593Smuzhiyun	};
183*4882a593Smuzhiyun
184*4882a593Smuzhiyun	DTPM_DECLARE(my_descr);
185*4882a593Smuzhiyun
186*4882a593SmuzhiyunThe nodes of the DTPM tree are described with dtpm structure. The
187*4882a593Smuzhiyunsteps to add a new power limitable device is done in three steps:
188*4882a593Smuzhiyun
189*4882a593Smuzhiyun * Allocate the dtpm node
190*4882a593Smuzhiyun * Set the power number of the dtpm node
191*4882a593Smuzhiyun * Register the dtpm node
192*4882a593Smuzhiyun
193*4882a593SmuzhiyunThe registration of the dtpm node is done with the powercap
194*4882a593Smuzhiyunops. Basically, it must implements the callbacks to get and set the
195*4882a593Smuzhiyunpower and the limit.
196*4882a593Smuzhiyun
197*4882a593SmuzhiyunAlternatively, if the node to be inserted is an intermediate one, then
198*4882a593Smuzhiyuna simple function to insert it as a future parent is available.
199*4882a593Smuzhiyun
200*4882a593SmuzhiyunIf a device has its power characteristics changing, then the tree must
201*4882a593Smuzhiyunbe updated with the new power numbers and weights.
202*4882a593Smuzhiyun
203*4882a593SmuzhiyunNomenclature
204*4882a593Smuzhiyun------------
205*4882a593Smuzhiyun
206*4882a593Smuzhiyun * dtpm_alloc() : Allocate and initialize a dtpm structure
207*4882a593Smuzhiyun
208*4882a593Smuzhiyun * dtpm_register() : Add the dtpm node to the tree
209*4882a593Smuzhiyun
210*4882a593Smuzhiyun * dtpm_unregister() : Remove the dtpm node from the tree
211*4882a593Smuzhiyun
212*4882a593Smuzhiyun * dtpm_update_power() : Update the power characteristics of the dtpm node
213