Skip to content

Commit 7d9895c

Browse files
lukaszluba-armrafaeljw
authored andcommitted
PM / EM: introduce em_dev_register_perf_domain function
Add now function in the Energy Model framework which is going to support new devices. This function will help in transition and make it smoother. For now it still checks if the cpumask is a valid pointer, which will be removed later when the new structures and infrastructure will be ready. Acked-by: Daniel Lezcano <[email protected]> Acked-by: Quentin Perret <[email protected]> Signed-off-by: Lukasz Luba <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 521b512 commit 7d9895c

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

include/linux/energy_model.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#ifndef _LINUX_ENERGY_MODEL_H
33
#define _LINUX_ENERGY_MODEL_H
44
#include <linux/cpumask.h>
5+
#include <linux/device.h>
56
#include <linux/jump_label.h>
67
#include <linux/kobject.h>
78
#include <linux/rcupdate.h>
@@ -42,7 +43,7 @@ struct em_perf_domain {
4243
#define em_span_cpus(em) (to_cpumask((em)->cpus))
4344

4445
#ifdef CONFIG_ENERGY_MODEL
45-
#define EM_CPU_MAX_POWER 0xFFFF
46+
#define EM_MAX_POWER 0xFFFF
4647

4748
struct em_data_callback {
4849
/**
@@ -59,7 +60,7 @@ struct em_data_callback {
5960
* and frequency.
6061
*
6162
* The power is the one of a single CPU in the domain, expressed in
62-
* milli-watts. It is expected to fit in the [0, EM_CPU_MAX_POWER]
63+
* milli-watts. It is expected to fit in the [0, EM_MAX_POWER]
6364
* range.
6465
*
6566
* Return 0 on success.
@@ -71,6 +72,8 @@ struct em_data_callback {
7172
struct em_perf_domain *em_cpu_get(int cpu);
7273
int em_register_perf_domain(cpumask_t *span, unsigned int nr_states,
7374
struct em_data_callback *cb);
75+
int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states,
76+
struct em_data_callback *cb, cpumask_t *span);
7477

7578
/**
7679
* em_pd_energy() - Estimates the energy consumed by the CPUs of a perf. domain
@@ -174,6 +177,12 @@ static inline int em_register_perf_domain(cpumask_t *span,
174177
{
175178
return -EINVAL;
176179
}
180+
static inline
181+
int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states,
182+
struct em_data_callback *cb, cpumask_t *span)
183+
{
184+
return -EINVAL;
185+
}
177186
static inline struct em_perf_domain *em_cpu_get(int cpu)
178187
{
179188
return NULL;

kernel/power/energy_model.c

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static struct em_perf_domain *em_create_pd(cpumask_t *span, int nr_states,
125125
* The power returned by active_state() is expected to be
126126
* positive, in milli-watts and to fit into 16 bits.
127127
*/
128-
if (!power || power > EM_CPU_MAX_POWER) {
128+
if (!power || power > EM_MAX_POWER) {
129129
pr_err("pd%d: invalid power: %lu\n", cpu, power);
130130
goto free_ps_table;
131131
}
@@ -183,10 +183,13 @@ struct em_perf_domain *em_cpu_get(int cpu)
183183
EXPORT_SYMBOL_GPL(em_cpu_get);
184184

185185
/**
186-
* em_register_perf_domain() - Register the Energy Model of a performance domain
187-
* @span : Mask of CPUs in the performance domain
186+
* em_dev_register_perf_domain() - Register the Energy Model (EM) for a device
187+
* @dev : Device for which the EM is to register
188188
* @nr_states : Number of performance states to register
189189
* @cb : Callback functions providing the data of the Energy Model
190+
* @span : Pointer to cpumask_t, which in case of a CPU device is
191+
* obligatory. It can be taken from i.e. 'policy->cpus'. For other
192+
* type of devices this should be set to NULL.
190193
*
191194
* Create Energy Model tables for a performance domain using the callbacks
192195
* defined in cb.
@@ -196,14 +199,14 @@ EXPORT_SYMBOL_GPL(em_cpu_get);
196199
*
197200
* Return 0 on success
198201
*/
199-
int em_register_perf_domain(cpumask_t *span, unsigned int nr_states,
200-
struct em_data_callback *cb)
202+
int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states,
203+
struct em_data_callback *cb, cpumask_t *span)
201204
{
202205
unsigned long cap, prev_cap = 0;
203206
struct em_perf_domain *pd;
204207
int cpu, ret = 0;
205208

206-
if (!span || !nr_states || !cb)
209+
if (!dev || !span || !nr_states || !cb)
207210
return -EINVAL;
208211

209212
/*
@@ -255,4 +258,29 @@ int em_register_perf_domain(cpumask_t *span, unsigned int nr_states,
255258

256259
return ret;
257260
}
261+
EXPORT_SYMBOL_GPL(em_dev_register_perf_domain);
262+
263+
/**
264+
* em_register_perf_domain() - Register the Energy Model of a performance domain
265+
* @span : Mask of CPUs in the performance domain
266+
* @nr_states : Number of capacity states to register
267+
* @cb : Callback functions providing the data of the Energy Model
268+
*
269+
* Create Energy Model tables for a performance domain using the callbacks
270+
* defined in cb.
271+
*
272+
* If multiple clients register the same performance domain, all but the first
273+
* registration will be ignored.
274+
*
275+
* Return 0 on success
276+
*/
277+
int em_register_perf_domain(cpumask_t *span, unsigned int nr_states,
278+
struct em_data_callback *cb)
279+
{
280+
struct device *cpu_dev;
281+
282+
cpu_dev = get_cpu_device(cpumask_first(span));
283+
284+
return em_dev_register_perf_domain(cpu_dev, nr_states, cb, span);
285+
}
258286
EXPORT_SYMBOL_GPL(em_register_perf_domain);

0 commit comments

Comments
 (0)