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