energy-model.rst (d704aa0d44ade12660d4d7220b2a8d785b7b4247) energy-model.rst (08374410a5ea3ff2fa9a87edd7d7ab15375b1c31)
1.. SPDX-License-Identifier: GPL-2.0
2
3=======================
4Energy Model of devices
5=======================
6
71. Overview
8-----------

--- 70 unchanged lines hidden (view full) ---

79^^^^^^^^^^^^^^^^^^
80
81CONFIG_ENERGY_MODEL must be enabled to use the EM framework.
82
83
842.2 Registration of performance domains
85^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
86
1.. SPDX-License-Identifier: GPL-2.0
2
3=======================
4Energy Model of devices
5=======================
6
71. Overview
8-----------

--- 70 unchanged lines hidden (view full) ---

79^^^^^^^^^^^^^^^^^^
80
81CONFIG_ENERGY_MODEL must be enabled to use the EM framework.
82
83
842.2 Registration of performance domains
85^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
86
87Registration of 'advanced' EM
88~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89
90The 'advanced' EM gets it's name due to the fact that the driver is allowed
91to provide more precised power model. It's not limited to some implemented math
92formula in the framework (like it's in 'simple' EM case). It can better reflect
93the real power measurements performed for each performance state. Thus, this
94registration method should be preferred in case considering EM static power
95(leakage) is important.
96
87Drivers are expected to register performance domains into the EM framework by
88calling the following API::
89
90 int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states,
91 struct em_data_callback *cb, cpumask_t *cpus, bool milliwatts);
92
93Drivers must provide a callback function returning <frequency, power> tuples
94for each performance state. The callback function provided by the driver is free
95to fetch data from any relevant location (DT, firmware, ...), and by any mean
96deemed necessary. Only for CPU devices, drivers must specify the CPUs of the
97performance domains using cpumask. For other devices than CPUs the last
98argument must be set to NULL.
99The last argument 'milliwatts' is important to set with correct value. Kernel
100subsystems which use EM might rely on this flag to check if all EM devices use
101the same scale. If there are different scales, these subsystems might decide
102to: return warning/error, stop working or panic.
103See Section 3. for an example of driver implementing this
104callback, or Section 2.4 for further documentation on this API
105
97Drivers are expected to register performance domains into the EM framework by
98calling the following API::
99
100 int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states,
101 struct em_data_callback *cb, cpumask_t *cpus, bool milliwatts);
102
103Drivers must provide a callback function returning <frequency, power> tuples
104for each performance state. The callback function provided by the driver is free
105to fetch data from any relevant location (DT, firmware, ...), and by any mean
106deemed necessary. Only for CPU devices, drivers must specify the CPUs of the
107performance domains using cpumask. For other devices than CPUs the last
108argument must be set to NULL.
109The last argument 'milliwatts' is important to set with correct value. Kernel
110subsystems which use EM might rely on this flag to check if all EM devices use
111the same scale. If there are different scales, these subsystems might decide
112to: return warning/error, stop working or panic.
113See Section 3. for an example of driver implementing this
114callback, or Section 2.4 for further documentation on this API
115
116Registration of 'simple' EM
117~~~~~~~~~~~~~~~~~~~~~~~~~~~
106
118
119The 'simple' EM is registered using the framework helper function
120cpufreq_register_em_with_opp(). It implements a power model which is tight to
121math formula::
122
123 Power = C * V^2 * f
124
125The EM which is registered using this method might not reflect correctly the
126physics of a real device, e.g. when static power (leakage) is important.
127
128
1072.3 Accessing performance domains
108^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
109
110There are two API functions which provide the access to the energy model:
111em_cpu_get() which takes CPU id as an argument and em_pd_get() with device
112pointer as an argument. It depends on the subsystem which interface it is
113going to use, but in case of CPU devices both functions return the same
114performance domain.

--- 78 unchanged lines hidden ---
1292.3 Accessing performance domains
130^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
131
132There are two API functions which provide the access to the energy model:
133em_cpu_get() which takes CPU id as an argument and em_pd_get() with device
134pointer as an argument. It depends on the subsystem which interface it is
135going to use, but in case of CPU devices both functions return the same
136performance domain.

--- 78 unchanged lines hidden ---