cpu-cooling-api.txt 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. CPU cooling APIs How To
  2. ===================================
  3. Written by Amit Daniel Kachhap <amit.kachhap@linaro.org>
  4. Updated: 6 Jan 2015
  5. Copyright (c) 2012 Samsung Electronics Co., Ltd(http://www.samsung.com)
  6. 0. Introduction
  7. The generic cpu cooling(freq clipping) provides registration/unregistration APIs
  8. to the caller. The binding of the cooling devices to the trip point is left for
  9. the user. The registration APIs returns the cooling device pointer.
  10. 1. cpu cooling APIs
  11. 1.1 cpufreq registration/unregistration APIs
  12. 1.1.1 struct thermal_cooling_device *cpufreq_cooling_register(
  13. struct cpumask *clip_cpus)
  14. This interface function registers the cpufreq cooling device with the name
  15. "thermal-cpufreq-%x". This api can support multiple instances of cpufreq
  16. cooling devices.
  17. clip_cpus: cpumask of cpus where the frequency constraints will happen.
  18. 1.1.2 struct thermal_cooling_device *of_cpufreq_cooling_register(
  19. struct device_node *np, const struct cpumask *clip_cpus)
  20. This interface function registers the cpufreq cooling device with
  21. the name "thermal-cpufreq-%x" linking it with a device tree node, in
  22. order to bind it via the thermal DT code. This api can support multiple
  23. instances of cpufreq cooling devices.
  24. np: pointer to the cooling device device tree node
  25. clip_cpus: cpumask of cpus where the frequency constraints will happen.
  26. 1.1.3 struct thermal_cooling_device *cpufreq_power_cooling_register(
  27. const struct cpumask *clip_cpus, u32 capacitance,
  28. get_static_t plat_static_func)
  29. Similar to cpufreq_cooling_register, this function registers a cpufreq
  30. cooling device. Using this function, the cooling device will
  31. implement the power extensions by using a simple cpu power model. The
  32. cpus must have registered their OPPs using the OPP library.
  33. The additional parameters are needed for the power model (See 2. Power
  34. models). "capacitance" is the dynamic power coefficient (See 2.1
  35. Dynamic power). "plat_static_func" is a function to calculate the
  36. static power consumed by these cpus (See 2.2 Static power).
  37. 1.1.4 struct thermal_cooling_device *of_cpufreq_power_cooling_register(
  38. struct device_node *np, const struct cpumask *clip_cpus, u32 capacitance,
  39. get_static_t plat_static_func)
  40. Similar to cpufreq_power_cooling_register, this function register a
  41. cpufreq cooling device with power extensions using the device tree
  42. information supplied by the np parameter.
  43. 1.1.5 void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
  44. This interface function unregisters the "thermal-cpufreq-%x" cooling device.
  45. cdev: Cooling device pointer which has to be unregistered.
  46. 2. Power models
  47. The power API registration functions provide a simple power model for
  48. CPUs. The current power is calculated as dynamic + (optionally)
  49. static power. This power model requires that the operating-points of
  50. the CPUs are registered using the kernel's opp library and the
  51. `cpufreq_frequency_table` is assigned to the `struct device` of the
  52. cpu. If you are using CONFIG_CPUFREQ_DT then the
  53. `cpufreq_frequency_table` should already be assigned to the cpu
  54. device.
  55. The `plat_static_func` parameter of `cpufreq_power_cooling_register()`
  56. and `of_cpufreq_power_cooling_register()` is optional. If you don't
  57. provide it, only dynamic power will be considered.
  58. 2.1 Dynamic power
  59. The dynamic power consumption of a processor depends on many factors.
  60. For a given processor implementation the primary factors are:
  61. - The time the processor spends running, consuming dynamic power, as
  62. compared to the time in idle states where dynamic consumption is
  63. negligible. Herein we refer to this as 'utilisation'.
  64. - The voltage and frequency levels as a result of DVFS. The DVFS
  65. level is a dominant factor governing power consumption.
  66. - In running time the 'execution' behaviour (instruction types, memory
  67. access patterns and so forth) causes, in most cases, a second order
  68. variation. In pathological cases this variation can be significant,
  69. but typically it is of a much lesser impact than the factors above.
  70. A high level dynamic power consumption model may then be represented as:
  71. Pdyn = f(run) * Voltage^2 * Frequency * Utilisation
  72. f(run) here represents the described execution behaviour and its
  73. result has a units of Watts/Hz/Volt^2 (this often expressed in
  74. mW/MHz/uVolt^2)
  75. The detailed behaviour for f(run) could be modelled on-line. However,
  76. in practice, such an on-line model has dependencies on a number of
  77. implementation specific processor support and characterisation
  78. factors. Therefore, in initial implementation that contribution is
  79. represented as a constant coefficient. This is a simplification
  80. consistent with the relative contribution to overall power variation.
  81. In this simplified representation our model becomes:
  82. Pdyn = Capacitance * Voltage^2 * Frequency * Utilisation
  83. Where `capacitance` is a constant that represents an indicative
  84. running time dynamic power coefficient in fundamental units of
  85. mW/MHz/uVolt^2. Typical values for mobile CPUs might lie in range
  86. from 100 to 500. For reference, the approximate values for the SoC in
  87. ARM's Juno Development Platform are 530 for the Cortex-A57 cluster and
  88. 140 for the Cortex-A53 cluster.
  89. 2.2 Static power
  90. Static leakage power consumption depends on a number of factors. For a
  91. given circuit implementation the primary factors are:
  92. - Time the circuit spends in each 'power state'
  93. - Temperature
  94. - Operating voltage
  95. - Process grade
  96. The time the circuit spends in each 'power state' for a given
  97. evaluation period at first order means OFF or ON. However,
  98. 'retention' states can also be supported that reduce power during
  99. inactive periods without loss of context.
  100. Note: The visibility of state entries to the OS can vary, according to
  101. platform specifics, and this can then impact the accuracy of a model
  102. based on OS state information alone. It might be possible in some
  103. cases to extract more accurate information from system resources.
  104. The temperature, operating voltage and process 'grade' (slow to fast)
  105. of the circuit are all significant factors in static leakage power
  106. consumption. All of these have complex relationships to static power.
  107. Circuit implementation specific factors include the chosen silicon
  108. process as well as the type, number and size of transistors in both
  109. the logic gates and any RAM elements included.
  110. The static power consumption modelling must take into account the
  111. power managed regions that are implemented. Taking the example of an
  112. ARM processor cluster, the modelling would take into account whether
  113. each CPU can be powered OFF separately or if only a single power
  114. region is implemented for the complete cluster.
  115. In one view, there are others, a static power consumption model can
  116. then start from a set of reference values for each power managed
  117. region (e.g. CPU, Cluster/L2) in each state (e.g. ON, OFF) at an
  118. arbitrary process grade, voltage and temperature point. These values
  119. are then scaled for all of the following: the time in each state, the
  120. process grade, the current temperature and the operating voltage.
  121. However, since both implementation specific and complex relationships
  122. dominate the estimate, the appropriate interface to the model from the
  123. cpu cooling device is to provide a function callback that calculates
  124. the static power in this platform. When registering the cpu cooling
  125. device pass a function pointer that follows the `get_static_t`
  126. prototype:
  127. int plat_get_static(cpumask_t *cpumask, int interval,
  128. unsigned long voltage, u32 &power);
  129. `cpumask` is the cpumask of the cpus involved in the calculation.
  130. `voltage` is the voltage at which they are operating. The function
  131. should calculate the average static power for the last `interval`
  132. milliseconds. It returns 0 on success, -E* on error. If it
  133. succeeds, it should store the static power in `power`. Reading the
  134. temperature of the cpus described by `cpumask` is left for
  135. plat_get_static() to do as the platform knows best which thermal
  136. sensor is closest to the cpu.
  137. If `plat_static_func` is NULL, static power is considered to be
  138. negligible for this platform and only dynamic power is considered.
  139. The platform specific callback can then use any combination of tables
  140. and/or equations to permute the estimated value. Process grade
  141. information is not passed to the model since access to such data, from
  142. on-chip measurement capability or manufacture time data, is platform
  143. specific.
  144. Note: the significance of static power for CPUs in comparison to
  145. dynamic power is highly dependent on implementation. Given the
  146. potential complexity in implementation, the importance and accuracy of
  147. its inclusion when using cpu cooling devices should be assessed on a
  148. case by case basis.