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 <qperret@google.com>
Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
Lukasz Luba 2020-05-27 10:58:49 +01:00 committed by Rafael J. Wysocki
parent 7d9895c7fb
commit d0351cc3b0
4 changed files with 18 additions and 26 deletions

View File

@ -103,17 +103,12 @@ scmi_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
} }
static int __maybe_unused static int __maybe_unused
scmi_get_cpu_power(unsigned long *power, unsigned long *KHz, int cpu) scmi_get_cpu_power(unsigned long *power, unsigned long *KHz,
struct device *cpu_dev)
{ {
struct device *cpu_dev = get_cpu_device(cpu);
unsigned long Hz; unsigned long Hz;
int ret, domain; int ret, domain;
if (!cpu_dev) {
pr_err("failed to get cpu%d device\n", cpu);
return -ENODEV;
}
domain = handle->perf_ops->device_domain_id(cpu_dev); domain = handle->perf_ops->device_domain_id(cpu_dev);
if (domain < 0) if (domain < 0)
return domain; return domain;
@ -200,7 +195,7 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
policy->fast_switch_possible = true; policy->fast_switch_possible = true;
em_register_perf_domain(policy->cpus, nr_opp, &em_cb); em_dev_register_perf_domain(cpu_dev, nr_opp, &em_cb, policy->cpus);
return 0; return 0;

View File

@ -1216,9 +1216,8 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_of_node);
* calculation failed because of missing parameters, 0 otherwise. * calculation failed because of missing parameters, 0 otherwise.
*/ */
static int __maybe_unused _get_cpu_power(unsigned long *mW, unsigned long *kHz, static int __maybe_unused _get_cpu_power(unsigned long *mW, unsigned long *kHz,
int cpu) struct device *cpu_dev)
{ {
struct device *cpu_dev;
struct dev_pm_opp *opp; struct dev_pm_opp *opp;
struct device_node *np; struct device_node *np;
unsigned long mV, Hz; unsigned long mV, Hz;
@ -1226,10 +1225,6 @@ static int __maybe_unused _get_cpu_power(unsigned long *mW, unsigned long *kHz,
u64 tmp; u64 tmp;
int ret; int ret;
cpu_dev = get_cpu_device(cpu);
if (!cpu_dev)
return -ENODEV;
np = of_node_get(cpu_dev->of_node); np = of_node_get(cpu_dev->of_node);
if (!np) if (!np)
return -EINVAL; return -EINVAL;
@ -1297,6 +1292,6 @@ void dev_pm_opp_of_register_em(struct cpumask *cpus)
if (ret || !cap) if (ret || !cap)
return; return;
em_register_perf_domain(cpus, nr_opp, &em_cb); em_dev_register_perf_domain(cpu_dev, nr_opp, &em_cb, cpus);
} }
EXPORT_SYMBOL_GPL(dev_pm_opp_of_register_em); EXPORT_SYMBOL_GPL(dev_pm_opp_of_register_em);

View File

@ -48,24 +48,25 @@ struct em_perf_domain {
struct em_data_callback { struct em_data_callback {
/** /**
* active_power() - Provide power at the next performance state of * active_power() - Provide power at the next performance state of
* a CPU * a device
* @power : Active power at the performance state in mW * @power : Active power at the performance state in mW
* (modified) * (modified)
* @freq : Frequency at the performance state in kHz * @freq : Frequency at the performance state in kHz
* (modified) * (modified)
* @cpu : CPU for which we do this operation * @dev : Device for which we do this operation (can be a CPU)
* *
* active_power() must find the lowest performance state of 'cpu' above * active_power() must find the lowest performance state of 'dev' above
* 'freq' and update 'power' and 'freq' to the matching active power * 'freq' and update 'power' and 'freq' to the matching active power
* and frequency. * and frequency.
* *
* The power is the one of a single CPU in the domain, expressed in * In case of CPUs, the power is the one of a single CPU in the domain,
* milli-watts. It is expected to fit in the [0, EM_MAX_POWER] * expressed in milli-watts. It is expected to fit in the
* range. * [0, EM_MAX_POWER] range.
* *
* Return 0 on success. * Return 0 on success.
*/ */
int (*active_power)(unsigned long *power, unsigned long *freq, int cpu); int (*active_power)(unsigned long *power, unsigned long *freq,
struct device *dev);
}; };
#define EM_DATA_CB(_active_power_cb) { .active_power = &_active_power_cb } #define EM_DATA_CB(_active_power_cb) { .active_power = &_active_power_cb }

View File

@ -78,8 +78,9 @@ core_initcall(em_debug_init);
#else /* CONFIG_DEBUG_FS */ #else /* CONFIG_DEBUG_FS */
static void em_debug_create_pd(struct em_perf_domain *pd, int cpu) {} static void em_debug_create_pd(struct em_perf_domain *pd, int cpu) {}
#endif #endif
static struct em_perf_domain *em_create_pd(cpumask_t *span, int nr_states, static struct em_perf_domain *
struct em_data_callback *cb) em_create_pd(struct device *dev, int nr_states, struct em_data_callback *cb,
cpumask_t *span)
{ {
unsigned long opp_eff, prev_opp_eff = ULONG_MAX; unsigned long opp_eff, prev_opp_eff = ULONG_MAX;
unsigned long power, freq, prev_freq = 0; 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,
* lowest performance state of 'cpu' above 'freq' and updates * lowest performance state of 'cpu' above 'freq' and updates
* 'power' and 'freq' accordingly. * 'power' and 'freq' accordingly.
*/ */
ret = cb->active_power(&power, &freq, cpu); ret = cb->active_power(&power, &freq, dev);
if (ret) { if (ret) {
pr_err("pd%d: invalid perf. state: %d\n", cpu, ret); pr_err("pd%d: invalid perf. state: %d\n", cpu, ret);
goto free_ps_table; goto free_ps_table;
@ -237,7 +238,7 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states,
} }
/* Create the performance domain and add it to the Energy Model. */ /* Create the performance domain and add it to the Energy Model. */
pd = em_create_pd(span, nr_states, cb); pd = em_create_pd(dev, nr_states, cb, span);
if (!pd) { if (!pd) {
ret = -EINVAL; ret = -EINVAL;
goto unlock; goto unlock;