162306a36Sopenharmony_ci=======================
262306a36Sopenharmony_ciCPU cooling APIs How To
362306a36Sopenharmony_ci=======================
462306a36Sopenharmony_ci
562306a36Sopenharmony_ciWritten by Amit Daniel Kachhap <amit.kachhap@linaro.org>
662306a36Sopenharmony_ci
762306a36Sopenharmony_ciUpdated: 6 Jan 2015
862306a36Sopenharmony_ci
962306a36Sopenharmony_ciCopyright (c)  2012 Samsung Electronics Co., Ltd(http://www.samsung.com)
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci0. Introduction
1262306a36Sopenharmony_ci===============
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ciThe generic cpu cooling(freq clipping) provides registration/unregistration APIs
1562306a36Sopenharmony_cito the caller. The binding of the cooling devices to the trip point is left for
1662306a36Sopenharmony_cithe user. The registration APIs returns the cooling device pointer.
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci1. cpu cooling APIs
1962306a36Sopenharmony_ci===================
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci1.1 cpufreq registration/unregistration APIs
2262306a36Sopenharmony_ci--------------------------------------------
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci    ::
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci	struct thermal_cooling_device
2762306a36Sopenharmony_ci	*cpufreq_cooling_register(struct cpumask *clip_cpus)
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci    This interface function registers the cpufreq cooling device with the name
3062306a36Sopenharmony_ci    "thermal-cpufreq-%x". This api can support multiple instances of cpufreq
3162306a36Sopenharmony_ci    cooling devices.
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci   clip_cpus:
3462306a36Sopenharmony_ci	cpumask of cpus where the frequency constraints will happen.
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci    ::
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci	struct thermal_cooling_device
3962306a36Sopenharmony_ci	*of_cpufreq_cooling_register(struct cpufreq_policy *policy)
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci    This interface function registers the cpufreq cooling device with
4262306a36Sopenharmony_ci    the name "thermal-cpufreq-%x" linking it with a device tree node, in
4362306a36Sopenharmony_ci    order to bind it via the thermal DT code. This api can support multiple
4462306a36Sopenharmony_ci    instances of cpufreq cooling devices.
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci    policy:
4762306a36Sopenharmony_ci	CPUFreq policy.
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci    ::
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci	void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci    This interface function unregisters the "thermal-cpufreq-%x" cooling device.
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci    cdev: Cooling device pointer which has to be unregistered.
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci2. Power models
5962306a36Sopenharmony_ci===============
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ciThe power API registration functions provide a simple power model for
6262306a36Sopenharmony_ciCPUs.  The current power is calculated as dynamic power (static power isn't
6362306a36Sopenharmony_cisupported currently).  This power model requires that the operating-points of
6462306a36Sopenharmony_cithe CPUs are registered using the kernel's opp library and the
6562306a36Sopenharmony_ci`cpufreq_frequency_table` is assigned to the `struct device` of the
6662306a36Sopenharmony_cicpu.  If you are using CONFIG_CPUFREQ_DT then the
6762306a36Sopenharmony_ci`cpufreq_frequency_table` should already be assigned to the cpu
6862306a36Sopenharmony_cidevice.
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ciThe dynamic power consumption of a processor depends on many factors.
7162306a36Sopenharmony_ciFor a given processor implementation the primary factors are:
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci- The time the processor spends running, consuming dynamic power, as
7462306a36Sopenharmony_ci  compared to the time in idle states where dynamic consumption is
7562306a36Sopenharmony_ci  negligible.  Herein we refer to this as 'utilisation'.
7662306a36Sopenharmony_ci- The voltage and frequency levels as a result of DVFS.  The DVFS
7762306a36Sopenharmony_ci  level is a dominant factor governing power consumption.
7862306a36Sopenharmony_ci- In running time the 'execution' behaviour (instruction types, memory
7962306a36Sopenharmony_ci  access patterns and so forth) causes, in most cases, a second order
8062306a36Sopenharmony_ci  variation.  In pathological cases this variation can be significant,
8162306a36Sopenharmony_ci  but typically it is of a much lesser impact than the factors above.
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ciA high level dynamic power consumption model may then be represented as::
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci	Pdyn = f(run) * Voltage^2 * Frequency * Utilisation
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_cif(run) here represents the described execution behaviour and its
8862306a36Sopenharmony_ciresult has a units of Watts/Hz/Volt^2 (this often expressed in
8962306a36Sopenharmony_cimW/MHz/uVolt^2)
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ciThe detailed behaviour for f(run) could be modelled on-line.  However,
9262306a36Sopenharmony_ciin practice, such an on-line model has dependencies on a number of
9362306a36Sopenharmony_ciimplementation specific processor support and characterisation
9462306a36Sopenharmony_cifactors.  Therefore, in initial implementation that contribution is
9562306a36Sopenharmony_cirepresented as a constant coefficient.  This is a simplification
9662306a36Sopenharmony_ciconsistent with the relative contribution to overall power variation.
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ciIn this simplified representation our model becomes::
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci	Pdyn = Capacitance * Voltage^2 * Frequency * Utilisation
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ciWhere `capacitance` is a constant that represents an indicative
10362306a36Sopenharmony_cirunning time dynamic power coefficient in fundamental units of
10462306a36Sopenharmony_cimW/MHz/uVolt^2.  Typical values for mobile CPUs might lie in range
10562306a36Sopenharmony_cifrom 100 to 500.  For reference, the approximate values for the SoC in
10662306a36Sopenharmony_ciARM's Juno Development Platform are 530 for the Cortex-A57 cluster and
10762306a36Sopenharmony_ci140 for the Cortex-A53 cluster.
108