History

OPP: refactor dev_pm_opp_of_register_em() and update related drivers

The Energy Model framework supports not only CPU devices. Drop the CPU specific interface with cpumask and add struct device. Add also a return value, user might use it. This new interface provides easy way to create a simple Energy Model, which then might be used by e.g. thermal subsystem.

Lukasz Luba committed 6 years ago

Commit 0e0ffa81 parent 7b7570a9 files · +65 −35Browse files

Unified · Split

9 files
  1. drivers/cpufreq/cpufreq-dt.c +1 −1
  2. drivers/cpufreq/imx6q-cpufreq.c +1 −1
  3. drivers/cpufreq/mediatek-cpufreq.c +1 −1
  4. drivers/cpufreq/omap-cpufreq.c +1 −1
  5. drivers/cpufreq/qcom-cpufreq-hw.c +1 −1
  6. drivers/cpufreq/scpi-cpufreq.c +1 −1
  7. drivers/cpufreq/vexpress-spc-cpufreq.c +1 −1
  8. drivers/opp/of.c +45 −26
  9. include/linux/pm_opp.h +13 −2
drivers/cpufreq/cpufreq-dt.c+1−1
@@ -279,7 +279,7 @@ static int cpufreq_init(struct cpufreq_policy *policy) · 278 unmodified lines
279 policy->cpuinfo.transition_latency = transition_latency;279 policy->cpuinfo.transition_latency = transition_latency;
280 policy->dvfs_possible_from_any_cpu = true;280 policy->dvfs_possible_from_any_cpu = true;
281 281
282 dev_pm_opp_of_register_em(policy->cpus);282 dev_pm_opp_of_register_em(cpu_dev, policy->cpus);
283 283
284 return 0;284 return 0;
285 285
drivers/cpufreq/imx6q-cpufreq.c+1−1
@@ -193,7 +193,7 @@ static int imx6q_cpufreq_init(struct cpufreq_policy *policy) · 192 unmodified lines
193 policy->clk = clks[ARM].clk;193 policy->clk = clks[ARM].clk;
194 cpufreq_generic_init(policy, freq_table, transition_latency);194 cpufreq_generic_init(policy, freq_table, transition_latency);
195 policy->suspend_freq = max_freq;195 policy->suspend_freq = max_freq;
196 dev_pm_opp_of_register_em(policy->cpus);196 dev_pm_opp_of_register_em(cpu_dev, policy->cpus);
197 197
198 return 0;198 return 0;
199}199}
drivers/cpufreq/mediatek-cpufreq.c+1−1
@@ -448,7 +448,7 @@ static int mtk_cpufreq_init(struct cpufreq_policy *policy) · 447 unmodified lines
448 policy->driver_data = info;448 policy->driver_data = info;
449 policy->clk = info->cpu_clk;449 policy->clk = info->cpu_clk;
450 450
451 dev_pm_opp_of_register_em(policy->cpus);451 dev_pm_opp_of_register_em(info->cpu_dev, policy->cpus);
452 452
453 return 0;453 return 0;
454}454}
drivers/cpufreq/omap-cpufreq.c+1−1
@@ -131,7 +131,7 @@ static int omap_cpu_init(struct cpufreq_policy *policy) · 130 unmodified lines
131 131
132 /* FIXME: what's the actual transition time? */132 /* FIXME: what's the actual transition time? */
133 cpufreq_generic_init(policy, freq_table, 300 * 1000);133 cpufreq_generic_init(policy, freq_table, 300 * 1000);
134 dev_pm_opp_of_register_em(policy->cpus);134 dev_pm_opp_of_register_em(mpu_dev, policy->cpus);
135 135
136 return 0;136 return 0;
137}137}
drivers/cpufreq/qcom-cpufreq-hw.c+1−1
@@ -238,7 +238,7 @@ static int qcom_cpufreq_hw_cpu_init(struct cpufreq_policy *policy) · 237 unmodified lines
238 goto error;238 goto error;
239 }239 }
240 240
241 dev_pm_opp_of_register_em(policy->cpus);241 dev_pm_opp_of_register_em(cpu_dev, policy->cpus);
242 242
243 policy->fast_switch_possible = true;243 policy->fast_switch_possible = true;
244 244
drivers/cpufreq/scpi-cpufreq.c+1−1
@@ -167,7 +167,7 @@ static int scpi_cpufreq_init(struct cpufreq_policy *policy) · 166 unmodified lines
167 167
168 policy->fast_switch_possible = false;168 policy->fast_switch_possible = false;
169 169
170 dev_pm_opp_of_register_em(policy->cpus);170 dev_pm_opp_of_register_em(cpu_dev, policy->cpus);
171 171
172 return 0;172 return 0;
173 173
drivers/cpufreq/vexpress-spc-cpufreq.c+1−1
@@ -450,7 +450,7 @@ static int ve_spc_cpufreq_init(struct cpufreq_policy *policy) · 449 unmodified lines
450 policy->freq_table = freq_table[cur_cluster];450 policy->freq_table = freq_table[cur_cluster];
451 policy->cpuinfo.transition_latency = 1000000; /* 1 ms */451 policy->cpuinfo.transition_latency = 1000000; /* 1 ms */
452 452
453 dev_pm_opp_of_register_em(policy->cpus);453 dev_pm_opp_of_register_em(cpu_dev, policy->cpus);
454 454
455 if (is_bL_switching_enabled())455 if (is_bL_switching_enabled())
456 per_cpu(cpu_last_req_freq, policy->cpu) =456 per_cpu(cpu_last_req_freq, policy->cpu) =
drivers/opp/of.c+45−26
@@ -1205,18 +1205,18 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_of_node); · 1204 unmodified lines
1205 1205
1206/*1206/*
1207 * Callback function provided to the Energy Model framework upon registration.1207 * Callback function provided to the Energy Model framework upon registration.
1208 * This computes the power estimated by @CPU at @kHz if it is the frequency1208 * This computes the power estimated by @dev at @kHz if it is the frequency
1209 * of an existing OPP, or at the frequency of the first OPP above @kHz otherwise1209 * of an existing OPP, or at the frequency of the first OPP above @kHz otherwise
1210 * (see dev_pm_opp_find_freq_ceil()). This function updates @kHz to the ceiled1210 * (see dev_pm_opp_find_freq_ceil()). This function updates @kHz to the ceiled
1211 * frequency and @mW to the associated power. The power is estimated as1211 * frequency and @mW to the associated power. The power is estimated as
1212 * P = C * V^2 * f with C being the CPU's capacitance and V and f respectively1212 * P = C * V^2 * f with C being the device's capacitance and V and f
1213 * the voltage and frequency of the OPP.1213 * respectively the voltage and frequency of the OPP.
1214 *1214 *
1215 * Returns -ENODEV if the CPU device cannot be found, -EINVAL if the power1215 * Returns -EINVAL if the power calculation failed because of missing
1216 * calculation failed because of missing parameters, 0 otherwise.1216 * parameters, 0 otherwise.
1217 */1217 */
1218static int __maybe_unused _get_cpu_power(unsigned long *mW, unsigned long *kHz,1218static int __maybe_unused _get_power(unsigned long *mW, unsigned long *kHz,
1219 struct device *cpu_dev)1219 struct device *dev)
1220{1220{
1221 struct dev_pm_opp *opp;1221 struct dev_pm_opp *opp;
1222 struct device_node *np;1222 struct device_node *np;
@@ -1225,7 +1225,7 @@ static int __maybe_unused _get_cpu_power(unsigned long *mW, unsigned long *kHz, · 2 unmodified lines
1225 u64 tmp;1225 u64 tmp;
1226 int ret;1226 int ret;
1227 1227
1228 np = of_node_get(cpu_dev->of_node);1228 np = of_node_get(dev->of_node);
1229 if (!np)1229 if (!np)
1230 return -EINVAL;1230 return -EINVAL;
1231 1231
@@ -1235,7 +1235,7 @@ static int __maybe_unused _get_cpu_power(unsigned long *mW, unsigned long *kHz, · 3 unmodified lines
1235 return -EINVAL;1235 return -EINVAL;
1236 1236
1237 Hz = *kHz * 1000;1237 Hz = *kHz * 1000;
1238 opp = dev_pm_opp_find_freq_ceil(cpu_dev, &Hz);1238 opp = dev_pm_opp_find_freq_ceil(dev, &Hz);
1239 if (IS_ERR(opp))1239 if (IS_ERR(opp))
1240 return -EINVAL;1240 return -EINVAL;
1241 1241
@@ -1255,30 +1255,38 @@ static int __maybe_unused _get_cpu_power(unsigned long *mW, unsigned long *kHz, · 13 unmodified lines
1255 1255
1256/**1256/**
1257 * dev_pm_opp_of_register_em() - Attempt to register an Energy Model1257 * dev_pm_opp_of_register_em() - Attempt to register an Energy Model
1258 * @cpus : CPUs for which an Energy Model has to be registered1258 * @dev : Device for which an Energy Model has to be registered
1259 * @cpus : CPUs for which an Energy Model has to be registered. For
1260 * other type of devices it should be set to NULL.
1259 *1261 *
1260 * This checks whether the "dynamic-power-coefficient" devicetree property has1262 * This checks whether the "dynamic-power-coefficient" devicetree property has
1261 * been specified, and tries to register an Energy Model with it if it has.1263 * been specified, and tries to register an Energy Model with it if it has.
1264 * Having this property means the voltages are known for OPPs and the EM
1265 * might be calculated.
1262 */1266 */
1263void dev_pm_opp_of_register_em(struct cpumask *cpus)1267int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus)
1264{1268{
1265 struct em_data_callback em_cb = EM_DATA_CB(_get_cpu_power);1269 struct em_data_callback em_cb = EM_DATA_CB(_get_power);
1266 int ret, nr_opp, cpu = cpumask_first(cpus);
1267 struct device *cpu_dev;
1268 struct device_node *np;1270 struct device_node *np;
1271 int ret, nr_opp;
1269 u32 cap;1272 u32 cap;
1270 1273
1271 cpu_dev = get_cpu_device(cpu);1274 if (IS_ERR_OR_NULL(dev)) {
1272 if (!cpu_dev)1275 ret = -EINVAL;
1273 return;1276 goto failed;
1277 }
1274 1278
1275 nr_opp = dev_pm_opp_get_opp_count(cpu_dev);1279 nr_opp = dev_pm_opp_get_opp_count(dev);
1276 if (nr_opp <= 0)1280 if (nr_opp <= 0) {
1277 return;1281 ret = -EINVAL;
1282 goto failed;
1283 }
1278 1284
1279 np = of_node_get(cpu_dev->of_node);1285 np = of_node_get(dev->of_node);
1280 if (!np)1286 if (!np) {
1281 return;1287 ret = -EINVAL;
1288 goto failed;
1289 }
1282 1290
1283 /*1291 /*
1284 * Register an EM only if the 'dynamic-power-coefficient' property is1292 * Register an EM only if the 'dynamic-power-coefficient' property is
@@ -1289,9 +1297,20 @@ void dev_pm_opp_of_register_em(struct cpumask *cpus) · 4 unmodified lines
1289 */1297 */
1290 ret = of_property_read_u32(np, "dynamic-power-coefficient", &cap);1298 ret = of_property_read_u32(np, "dynamic-power-coefficient", &cap);
1291 of_node_put(np);1299 of_node_put(np);
1292 if (ret || !cap)1300 if (ret || !cap) {
1293 return;1301 dev_dbg(dev, "Couldn't find proper 'dynamic-power-coefficient' in DT\n");
1302 ret = -EINVAL;
1303 goto failed;
1304 }
1294 1305
1295 em_dev_register_perf_domain(cpu_dev, nr_opp, &em_cb, cpus);1306 ret = em_dev_register_perf_domain(dev, nr_opp, &em_cb, cpus);
1307 if (ret)
1308 goto failed;
1309
1310 return 0;
1311
1312failed:
1313 dev_dbg(dev, "Couldn't register Energy Model %d\n", ret);
1314 return ret;
1296}1315}
1297EXPORT_SYMBOL_GPL(dev_pm_opp_of_register_em);1316EXPORT_SYMBOL_GPL(dev_pm_opp_of_register_em);
include/linux/pm_opp.h+13−2
@@ -11,6 +11,7 @@ · 10 unmodified lines
11#ifndef __LINUX_OPP_H__11#ifndef __LINUX_OPP_H__
12#define __LINUX_OPP_H__12#define __LINUX_OPP_H__
13 13
14#include <linux/energy_model.h>
14#include <linux/err.h>15#include <linux/err.h>
15#include <linux/notifier.h>16#include <linux/notifier.h>
16 17
@@ -373,7 +374,11 @@ struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev); · 356 unmodified lines
373struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);374struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
374int of_get_required_opp_performance_state(struct device_node *np, int index);375int of_get_required_opp_performance_state(struct device_node *np, int index);
375int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table);376int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table);
376void dev_pm_opp_of_register_em(struct cpumask *cpus);377int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus);
378static inline void dev_pm_opp_of_unregister_em(struct device *dev)
379{
380 em_dev_unregister_perf_domain(dev);
381}
377#else382#else
378static inline int dev_pm_opp_of_add_table(struct device *dev)383static inline int dev_pm_opp_of_add_table(struct device *dev)
379{384{
@@ -413,7 +418,13 @@ static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp) · 33 unmodified lines
413 return NULL;418 return NULL;
414}419}
415 420
416static inline void dev_pm_opp_of_register_em(struct cpumask *cpus)421static inline int dev_pm_opp_of_register_em(struct device *dev,
422 struct cpumask *cpus)
423{
424 return -ENOTSUPP;
425}
426
427static inline void dev_pm_opp_of_unregister_em(struct device *dev)
417{428{
418}429}
419 430