^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) =======================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) CPU cooling APIs How To
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) =======================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) Written by Amit Daniel Kachhap <amit.kachhap@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) Updated: 6 Jan 2015
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) Copyright (c) 2012 Samsung Electronics Co., Ltd(http://www.samsung.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) 0. Introduction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) ===============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) The generic cpu cooling(freq clipping) provides registration/unregistration APIs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) to the caller. The binding of the cooling devices to the trip point is left for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) the user. The registration APIs returns the cooling device pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 1. cpu cooling APIs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) ===================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 1.1 cpufreq registration/unregistration APIs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) --------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct thermal_cooling_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) *cpufreq_cooling_register(struct cpumask *clip_cpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) This interface function registers the cpufreq cooling device with the name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) "thermal-cpufreq-%x". This api can support multiple instances of cpufreq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) cooling devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) clip_cpus:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) cpumask of cpus where the frequency constraints will happen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct thermal_cooling_device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) *of_cpufreq_cooling_register(struct cpufreq_policy *policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) This interface function registers the cpufreq cooling device with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) the name "thermal-cpufreq-%x" linking it with a device tree node, in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) order to bind it via the thermal DT code. This api can support multiple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) instances of cpufreq cooling devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) policy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) CPUFreq policy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) This interface function unregisters the "thermal-cpufreq-%x" cooling device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) cdev: Cooling device pointer which has to be unregistered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 2. Power models
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) ===============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) The power API registration functions provide a simple power model for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) CPUs. The current power is calculated as dynamic power (static power isn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) supported currently). This power model requires that the operating-points of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) the CPUs are registered using the kernel's opp library and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) `cpufreq_frequency_table` is assigned to the `struct device` of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) cpu. If you are using CONFIG_CPUFREQ_DT then the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) `cpufreq_frequency_table` should already be assigned to the cpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) The dynamic power consumption of a processor depends on many factors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) For a given processor implementation the primary factors are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) - The time the processor spends running, consuming dynamic power, as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) compared to the time in idle states where dynamic consumption is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) negligible. Herein we refer to this as 'utilisation'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) - The voltage and frequency levels as a result of DVFS. The DVFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) level is a dominant factor governing power consumption.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) - In running time the 'execution' behaviour (instruction types, memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) access patterns and so forth) causes, in most cases, a second order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) variation. In pathological cases this variation can be significant,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) but typically it is of a much lesser impact than the factors above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) A high level dynamic power consumption model may then be represented as::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) Pdyn = f(run) * Voltage^2 * Frequency * Utilisation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) f(run) here represents the described execution behaviour and its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) result has a units of Watts/Hz/Volt^2 (this often expressed in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) mW/MHz/uVolt^2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) The detailed behaviour for f(run) could be modelled on-line. However,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) in practice, such an on-line model has dependencies on a number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) implementation specific processor support and characterisation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) factors. Therefore, in initial implementation that contribution is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) represented as a constant coefficient. This is a simplification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) consistent with the relative contribution to overall power variation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) In this simplified representation our model becomes::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) Pdyn = Capacitance * Voltage^2 * Frequency * Utilisation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) Where `capacitance` is a constant that represents an indicative
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) running time dynamic power coefficient in fundamental units of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) mW/MHz/uVolt^2. Typical values for mobile CPUs might lie in range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) from 100 to 500. For reference, the approximate values for the SoC in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) ARM's Juno Development Platform are 530 for the Cortex-A57 cluster and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 140 for the Cortex-A53 cluster.