power_allocator.txt 10 KB

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