power_allocator.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. =================================
  2. Power allocator governor tunables
  3. =================================
  4. Trip points
  5. -----------
  6. The governor works optimally with the following two passive trip points:
  7. 1. "switch on" trip point: temperature above which the governor
  8. control loop starts operating. This is the first passive trip
  9. point of the thermal zone.
  10. 2. "desired temperature" trip point: it should be higher than the
  11. "switch on" trip point. This the target temperature the governor
  12. is controlling for. This is the last passive trip point of the
  13. thermal zone.
  14. PID Controller
  15. --------------
  16. The power allocator governor implements a
  17. Proportional-Integral-Derivative controller (PID controller) with
  18. temperature as the control input and power as the controlled output:
  19. P_max = k_p * e + k_i * err_integral + k_d * diff_err + sustainable_power
  20. where
  21. - e = desired_temperature - current_temperature
  22. - err_integral is the sum of previous errors
  23. - diff_err = e - previous_error
  24. It is similar to the one depicted below::
  25. k_d
  26. |
  27. current_temp |
  28. | v
  29. | +----------+ +---+
  30. | +----->| diff_err |-->| X |------+
  31. | | +----------+ +---+ |
  32. | | | tdp actor
  33. | | k_i | | get_requested_power()
  34. | | | | | | |
  35. | | | | | | | ...
  36. v | v v v v v
  37. +---+ | +-------+ +---+ +---+ +---+ +----------+
  38. | S |-----+----->| sum e |----->| X |--->| S |-->| S |-->|power |
  39. +---+ | +-------+ +---+ +---+ +---+ |allocation|
  40. ^ | ^ +----------+
  41. | | | | |
  42. | | +---+ | | |
  43. | +------->| X |-------------------+ v v
  44. | +---+ granted performance
  45. desired_temperature ^
  46. |
  47. |
  48. k_po/k_pu
  49. Sustainable power
  50. -----------------
  51. An estimate of the sustainable dissipatable power (in mW) should be
  52. provided while registering the thermal zone. This estimates the
  53. sustained power that can be dissipated at the desired control
  54. temperature. This is the maximum sustained power for allocation at
  55. the desired maximum temperature. The actual sustained power can vary
  56. for a number of reasons. The closed loop controller will take care of
  57. variations such as environmental conditions, and some factors related
  58. to the speed-grade of the silicon. `sustainable_power` is therefore
  59. simply an estimate, and may be tuned to affect the aggressiveness of
  60. the thermal ramp. For reference, the sustainable power of a 4" phone
  61. is typically 2000mW, while on a 10" tablet is around 4500mW (may vary
  62. depending on screen size). It is possible to have the power value
  63. expressed in an abstract scale. The sustained power should be aligned
  64. to the scale used by the related cooling devices.
  65. If you are using device tree, do add it as a property of the
  66. thermal-zone. For example::
  67. thermal-zones {
  68. soc_thermal {
  69. polling-delay = <1000>;
  70. polling-delay-passive = <100>;
  71. sustainable-power = <2500>;
  72. ...
  73. Instead, if the thermal zone is registered from the platform code, pass a
  74. `thermal_zone_params` that has a `sustainable_power`. If no
  75. `thermal_zone_params` were being passed, then something like below
  76. will suffice::
  77. static const struct thermal_zone_params tz_params = {
  78. .sustainable_power = 3500,
  79. };
  80. and then pass `tz_params` as the 5th parameter to
  81. `thermal_zone_device_register()`
  82. k_po and k_pu
  83. -------------
  84. The implementation of the PID controller in the power allocator
  85. thermal governor allows the configuration of two proportional term
  86. constants: `k_po` and `k_pu`. `k_po` is the proportional term
  87. constant during temperature overshoot periods (current temperature is
  88. above "desired temperature" trip point). Conversely, `k_pu` is the
  89. proportional term constant during temperature undershoot periods
  90. (current temperature below "desired temperature" trip point).
  91. These controls are intended as the primary mechanism for configuring
  92. the permitted thermal "ramp" of the system. For instance, a lower
  93. `k_pu` value will provide a slower ramp, at the cost of capping
  94. available capacity at a low temperature. On the other hand, a high
  95. value of `k_pu` will result in the governor granting very high power
  96. while temperature is low, and may lead to temperature overshooting.
  97. The default value for `k_pu` is::
  98. 2 * sustainable_power / (desired_temperature - switch_on_temp)
  99. This means that at `switch_on_temp` the output of the controller's
  100. proportional term will be 2 * `sustainable_power`. The default value
  101. for `k_po` is::
  102. sustainable_power / (desired_temperature - switch_on_temp)
  103. Focusing on the proportional and feed forward values of the PID
  104. controller equation we have::
  105. P_max = k_p * e + sustainable_power
  106. The proportional term is proportional to the difference between the
  107. desired temperature and the current one. When the current temperature
  108. is the desired one, then the proportional component is zero and
  109. `P_max` = `sustainable_power`. That is, the system should operate in
  110. thermal equilibrium under constant load. `sustainable_power` is only
  111. an estimate, which is the reason for closed-loop control such as this.
  112. Expanding `k_pu` we get::
  113. P_max = 2 * sustainable_power * (T_set - T) / (T_set - T_on) +
  114. sustainable_power
  115. where:
  116. - T_set is the desired temperature
  117. - T is the current temperature
  118. - T_on is the switch on temperature
  119. When the current temperature is the switch_on temperature, the above
  120. formula becomes::
  121. P_max = 2 * sustainable_power * (T_set - T_on) / (T_set - T_on) +
  122. sustainable_power = 2 * sustainable_power + sustainable_power =
  123. 3 * sustainable_power
  124. Therefore, the proportional term alone linearly decreases power from
  125. 3 * `sustainable_power` to `sustainable_power` as the temperature
  126. rises from the switch on temperature to the desired temperature.
  127. k_i and integral_cutoff
  128. -----------------------
  129. `k_i` configures the PID loop's integral term constant. This term
  130. allows the PID controller to compensate for long term drift and for
  131. the quantized nature of the output control: cooling devices can't set
  132. the exact power that the governor requests. When the temperature
  133. error is below `integral_cutoff`, errors are accumulated in the
  134. integral term. This term is then multiplied by `k_i` and the result
  135. added to the output of the controller. Typically `k_i` is set low (1
  136. or 2) and `integral_cutoff` is 0.
  137. k_d
  138. ---
  139. `k_d` configures the PID loop's derivative term constant. It's
  140. recommended to leave it as the default: 0.
  141. Cooling device power API
  142. ========================
  143. Cooling devices controlled by this governor must supply the additional
  144. "power" API in their `cooling_device_ops`. It consists on three ops:
  145. 1. ::
  146. int get_requested_power(struct thermal_cooling_device *cdev,
  147. struct thermal_zone_device *tz, u32 *power);
  148. @cdev:
  149. The `struct thermal_cooling_device` pointer
  150. @tz:
  151. thermal zone in which we are currently operating
  152. @power:
  153. pointer in which to store the calculated power
  154. `get_requested_power()` calculates the power requested by the device
  155. in milliwatts and stores it in @power . It should return 0 on
  156. success, -E* on failure. This is currently used by the power
  157. allocator governor to calculate how much power to give to each cooling
  158. device.
  159. 2. ::
  160. int state2power(struct thermal_cooling_device *cdev, struct
  161. thermal_zone_device *tz, unsigned long state,
  162. u32 *power);
  163. @cdev:
  164. The `struct thermal_cooling_device` pointer
  165. @tz:
  166. thermal zone in which we are currently operating
  167. @state:
  168. A cooling device state
  169. @power:
  170. pointer in which to store the equivalent power
  171. Convert cooling device state @state into power consumption in
  172. milliwatts and store it in @power. It should return 0 on success, -E*
  173. on failure. This is currently used by thermal core to calculate the
  174. maximum power that an actor can consume.
  175. 3. ::
  176. int power2state(struct thermal_cooling_device *cdev, u32 power,
  177. unsigned long *state);
  178. @cdev:
  179. The `struct thermal_cooling_device` pointer
  180. @power:
  181. power in milliwatts
  182. @state:
  183. pointer in which to store the resulting state
  184. Calculate a cooling device state that would make the device consume at
  185. most @power mW and store it in @state. It should return 0 on success,
  186. -E* on failure. This is currently used by the thermal core to convert
  187. a given power set by the power allocator governor to a state that the
  188. cooling device can set. It is a function because this conversion may
  189. depend on external factors that may change so this function should the
  190. best conversion given "current circumstances".
  191. Cooling device weights
  192. ----------------------
  193. Weights are a mechanism to bias the allocation among cooling
  194. devices. They express the relative power efficiency of different
  195. cooling devices. Higher weight can be used to express higher power
  196. efficiency. Weighting is relative such that if each cooling device
  197. has a weight of one they are considered equal. This is particularly
  198. useful in heterogeneous systems where two cooling devices may perform
  199. the same kind of compute, but with different efficiency. For example,
  200. a system with two different types of processors.
  201. If the thermal zone is registered using
  202. `thermal_zone_device_register()` (i.e., platform code), then weights
  203. are passed as part of the thermal zone's `thermal_bind_parameters`.
  204. If the platform is registered using device tree, then they are passed
  205. as the `contribution` property of each map in the `cooling-maps` node.
  206. Limitations of the power allocator governor
  207. ===========================================
  208. The power allocator governor's PID controller works best if there is a
  209. periodic tick. If you have a driver that calls
  210. `thermal_zone_device_update()` (or anything that ends up calling the
  211. governor's `throttle()` function) repetitively, the governor response
  212. won't be very good. Note that this is not particular to this
  213. governor, step-wise will also misbehave if you call its throttle()
  214. faster than the normal thermal framework tick (due to interrupts for
  215. example) as it will overreact.
  216. Energy Model requirements
  217. =========================
  218. Another important thing is the consistent scale of the power values
  219. provided by the cooling devices. All of the cooling devices in a single
  220. thermal zone should have power values reported either in milli-Watts
  221. or scaled to the same 'abstract scale'.