Skip to content

Commit 1bc138c

Browse files
lukaszluba-armrafaeljw
authored andcommitted
PM / EM: add support for other devices than CPUs in Energy Model
Add support for other devices than CPUs. The registration function does not require a valid cpumask pointer and is ready to handle new devices. Some of the internal structures has been reorganized in order to keep consistent view (like removing per_cpu pd pointers). Signed-off-by: Lukasz Luba <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent d0351cc commit 1bc138c

File tree

3 files changed

+194
-84
lines changed

3 files changed

+194
-84
lines changed

include/linux/device.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define _DEVICE_H_
1414

1515
#include <linux/dev_printk.h>
16+
#include <linux/energy_model.h>
1617
#include <linux/ioport.h>
1718
#include <linux/kobject.h>
1819
#include <linux/klist.h>
@@ -559,6 +560,10 @@ struct device {
559560
struct dev_pm_info power;
560561
struct dev_pm_domain *pm_domain;
561562

563+
#ifdef CONFIG_ENERGY_MODEL
564+
struct em_perf_domain *em_pd;
565+
#endif
566+
562567
#ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN
563568
struct irq_domain *msi_domain;
564569
#endif

include/linux/energy_model.h

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
/**
1414
* em_perf_state - Performance state of a performance domain
15-
* @frequency: The CPU frequency in KHz, for consistency with CPUFreq
16-
* @power: The power consumed by 1 CPU at this level, in milli-watts
15+
* @frequency: The frequency in KHz, for consistency with CPUFreq
16+
* @power: The power consumed at this level, in milli-watts (by 1 CPU or
17+
by a registered device). It can be a total power: static and
18+
dynamic.
1719
* @cost: The cost coefficient associated with this level, used during
1820
* energy calculation. Equal to: power * max_frequency / frequency
1921
*/
@@ -27,12 +29,16 @@ struct em_perf_state {
2729
* em_perf_domain - Performance domain
2830
* @table: List of performance states, in ascending order
2931
* @nr_perf_states: Number of performance states
30-
* @cpus: Cpumask covering the CPUs of the domain
32+
* @cpus: Cpumask covering the CPUs of the domain. It's here
33+
* for performance reasons to avoid potential cache
34+
* misses during energy calculations in the scheduler
35+
* and simplifies allocating/freeing that memory region.
3136
*
32-
* A "performance domain" represents a group of CPUs whose performance is
33-
* scaled together. All CPUs of a performance domain must have the same
34-
* micro-architecture. Performance domains often have a 1-to-1 mapping with
35-
* CPUFreq policies.
37+
* In case of CPU device, a "performance domain" represents a group of CPUs
38+
* whose performance is scaled together. All CPUs of a performance domain
39+
* must have the same micro-architecture. Performance domains often have
40+
* a 1-to-1 mapping with CPUFreq policies. In case of other devices the @cpus
41+
* field is unused.
3642
*/
3743
struct em_perf_domain {
3844
struct em_perf_state *table;
@@ -71,10 +77,12 @@ struct em_data_callback {
7177
#define EM_DATA_CB(_active_power_cb) { .active_power = &_active_power_cb }
7278

7379
struct em_perf_domain *em_cpu_get(int cpu);
80+
struct em_perf_domain *em_pd_get(struct device *dev);
7481
int em_register_perf_domain(cpumask_t *span, unsigned int nr_states,
7582
struct em_data_callback *cb);
7683
int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states,
7784
struct em_data_callback *cb, cpumask_t *span);
85+
void em_dev_unregister_perf_domain(struct device *dev);
7886

7987
/**
8088
* em_pd_energy() - Estimates the energy consumed by the CPUs of a perf. domain
@@ -184,10 +192,17 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states,
184192
{
185193
return -EINVAL;
186194
}
195+
static inline void em_dev_unregister_perf_domain(struct device *dev)
196+
{
197+
}
187198
static inline struct em_perf_domain *em_cpu_get(int cpu)
188199
{
189200
return NULL;
190201
}
202+
static inline struct em_perf_domain *em_pd_get(struct device *dev)
203+
{
204+
return NULL;
205+
}
191206
static inline unsigned long em_pd_energy(struct em_perf_domain *pd,
192207
unsigned long max_util, unsigned long sum_util)
193208
{

0 commit comments

Comments
 (0)