Skip to content

Commit d0351cc

Browse files
lukaszluba-armrafaeljw
authored andcommitted
PM / EM: update callback structure and add device pointer
The Energy Model framework is going to support devices other that CPUs. In order to make this happen change the callback function and add pointer to a device as an argument. Update the related users to use new function and new callback from the Energy Model. Acked-by: Quentin Perret <[email protected]> Signed-off-by: Lukasz Luba <[email protected]> Acked-by: Daniel Lezcano <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 7d9895c commit d0351cc

File tree

4 files changed

+18
-26
lines changed

4 files changed

+18
-26
lines changed

drivers/cpufreq/scmi-cpufreq.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,12 @@ scmi_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
103103
}
104104

105105
static int __maybe_unused
106-
scmi_get_cpu_power(unsigned long *power, unsigned long *KHz, int cpu)
106+
scmi_get_cpu_power(unsigned long *power, unsigned long *KHz,
107+
struct device *cpu_dev)
107108
{
108-
struct device *cpu_dev = get_cpu_device(cpu);
109109
unsigned long Hz;
110110
int ret, domain;
111111

112-
if (!cpu_dev) {
113-
pr_err("failed to get cpu%d device\n", cpu);
114-
return -ENODEV;
115-
}
116-
117112
domain = handle->perf_ops->device_domain_id(cpu_dev);
118113
if (domain < 0)
119114
return domain;
@@ -200,7 +195,7 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
200195

201196
policy->fast_switch_possible = true;
202197

203-
em_register_perf_domain(policy->cpus, nr_opp, &em_cb);
198+
em_dev_register_perf_domain(cpu_dev, nr_opp, &em_cb, policy->cpus);
204199

205200
return 0;
206201

drivers/opp/of.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,20 +1216,15 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_of_node);
12161216
* calculation failed because of missing parameters, 0 otherwise.
12171217
*/
12181218
static int __maybe_unused _get_cpu_power(unsigned long *mW, unsigned long *kHz,
1219-
int cpu)
1219+
struct device *cpu_dev)
12201220
{
1221-
struct device *cpu_dev;
12221221
struct dev_pm_opp *opp;
12231222
struct device_node *np;
12241223
unsigned long mV, Hz;
12251224
u32 cap;
12261225
u64 tmp;
12271226
int ret;
12281227

1229-
cpu_dev = get_cpu_device(cpu);
1230-
if (!cpu_dev)
1231-
return -ENODEV;
1232-
12331228
np = of_node_get(cpu_dev->of_node);
12341229
if (!np)
12351230
return -EINVAL;
@@ -1297,6 +1292,6 @@ void dev_pm_opp_of_register_em(struct cpumask *cpus)
12971292
if (ret || !cap)
12981293
return;
12991294

1300-
em_register_perf_domain(cpus, nr_opp, &em_cb);
1295+
em_dev_register_perf_domain(cpu_dev, nr_opp, &em_cb, cpus);
13011296
}
13021297
EXPORT_SYMBOL_GPL(dev_pm_opp_of_register_em);

include/linux/energy_model.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,25 @@ struct em_perf_domain {
4848
struct em_data_callback {
4949
/**
5050
* active_power() - Provide power at the next performance state of
51-
* a CPU
51+
* a device
5252
* @power : Active power at the performance state in mW
5353
* (modified)
5454
* @freq : Frequency at the performance state in kHz
5555
* (modified)
56-
* @cpu : CPU for which we do this operation
56+
* @dev : Device for which we do this operation (can be a CPU)
5757
*
58-
* active_power() must find the lowest performance state of 'cpu' above
58+
* active_power() must find the lowest performance state of 'dev' above
5959
* 'freq' and update 'power' and 'freq' to the matching active power
6060
* and frequency.
6161
*
62-
* The power is the one of a single CPU in the domain, expressed in
63-
* milli-watts. It is expected to fit in the [0, EM_MAX_POWER]
64-
* range.
62+
* In case of CPUs, the power is the one of a single CPU in the domain,
63+
* expressed in milli-watts. It is expected to fit in the
64+
* [0, EM_MAX_POWER] range.
6565
*
6666
* Return 0 on success.
6767
*/
68-
int (*active_power)(unsigned long *power, unsigned long *freq, int cpu);
68+
int (*active_power)(unsigned long *power, unsigned long *freq,
69+
struct device *dev);
6970
};
7071
#define EM_DATA_CB(_active_power_cb) { .active_power = &_active_power_cb }
7172

kernel/power/energy_model.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ core_initcall(em_debug_init);
7878
#else /* CONFIG_DEBUG_FS */
7979
static void em_debug_create_pd(struct em_perf_domain *pd, int cpu) {}
8080
#endif
81-
static struct em_perf_domain *em_create_pd(cpumask_t *span, int nr_states,
82-
struct em_data_callback *cb)
81+
static struct em_perf_domain *
82+
em_create_pd(struct device *dev, int nr_states, struct em_data_callback *cb,
83+
cpumask_t *span)
8384
{
8485
unsigned long opp_eff, prev_opp_eff = ULONG_MAX;
8586
unsigned long power, freq, prev_freq = 0;
@@ -106,7 +107,7 @@ static struct em_perf_domain *em_create_pd(cpumask_t *span, int nr_states,
106107
* lowest performance state of 'cpu' above 'freq' and updates
107108
* 'power' and 'freq' accordingly.
108109
*/
109-
ret = cb->active_power(&power, &freq, cpu);
110+
ret = cb->active_power(&power, &freq, dev);
110111
if (ret) {
111112
pr_err("pd%d: invalid perf. state: %d\n", cpu, ret);
112113
goto free_ps_table;
@@ -237,7 +238,7 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states,
237238
}
238239

239240
/* Create the performance domain and add it to the Energy Model. */
240-
pd = em_create_pd(span, nr_states, cb);
241+
pd = em_create_pd(dev, nr_states, cb, span);
241242
if (!pd) {
242243
ret = -EINVAL;
243244
goto unlock;

0 commit comments

Comments
 (0)