Skip to content

Commit ca0fc87

Browse files
lukaszluba-armrafaeljw
authored andcommitted
PM: EM: Introduce runtime modifiable table
The new runtime table can be populated with a new power data to better reflect the actual efficiency of the device e.g. CPU. The power can vary over time e.g. due to the SoC temperature change. Higher temperature can increase power values. For longer running scenarios, such as game or camera, when also other devices are used (e.g. GPU, ISP) the CPU power can change. The new EM framework is able to addresses this issue and change the EM data at runtime safely. Reviewed-by: Dietmar Eggemann <[email protected]> Tested-by: Dietmar Eggemann <[email protected]> Signed-off-by: Lukasz Luba <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 8552d68 commit ca0fc87

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

include/linux/energy_model.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,20 @@ struct em_perf_state {
3636
*/
3737
#define EM_PERF_STATE_INEFFICIENT BIT(0)
3838

39+
/**
40+
* struct em_perf_table - Performance states table
41+
* @rcu: RCU used for safe access and destruction
42+
* @state: List of performance states, in ascending order
43+
*/
44+
struct em_perf_table {
45+
struct rcu_head rcu;
46+
struct em_perf_state state[];
47+
};
48+
3949
/**
4050
* struct em_perf_domain - Performance domain
4151
* @table: List of performance states, in ascending order
52+
* @em_table: Pointer to the runtime modifiable em_perf_table
4253
* @nr_perf_states: Number of performance states
4354
* @flags: See "em_perf_domain flags"
4455
* @cpus: Cpumask covering the CPUs of the domain. It's here
@@ -54,6 +65,7 @@ struct em_perf_state {
5465
*/
5566
struct em_perf_domain {
5667
struct em_perf_state *table;
68+
struct em_perf_table __rcu *em_table;
5769
int nr_perf_states;
5870
unsigned long flags;
5971
unsigned long cpus[];

kernel/power/energy_model.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
*/
2424
static DEFINE_MUTEX(em_pd_mutex);
2525

26+
static void em_cpufreq_update_efficiencies(struct device *dev,
27+
struct em_perf_state *table);
28+
2629
static bool _is_cpu_device(struct device *dev)
2730
{
2831
return (dev->bus == &cpu_subsys);
@@ -103,6 +106,31 @@ static void em_debug_create_pd(struct device *dev) {}
103106
static void em_debug_remove_pd(struct device *dev) {}
104107
#endif
105108

109+
static void em_destroy_table_rcu(struct rcu_head *rp)
110+
{
111+
struct em_perf_table __rcu *table;
112+
113+
table = container_of(rp, struct em_perf_table, rcu);
114+
kfree(table);
115+
}
116+
117+
static void em_free_table(struct em_perf_table __rcu *table)
118+
{
119+
call_rcu(&table->rcu, em_destroy_table_rcu);
120+
}
121+
122+
static struct em_perf_table __rcu *
123+
em_allocate_table(struct em_perf_domain *pd)
124+
{
125+
struct em_perf_table __rcu *table;
126+
int table_size;
127+
128+
table_size = sizeof(struct em_perf_state) * pd->nr_perf_states;
129+
130+
table = kzalloc(sizeof(*table) + table_size, GFP_KERNEL);
131+
return table;
132+
}
133+
106134
static int em_compute_costs(struct device *dev, struct em_perf_state *table,
107135
struct em_data_callback *cb, int nr_states,
108136
unsigned long flags)
@@ -153,6 +181,24 @@ static int em_allocate_perf_table(struct em_perf_domain *pd,
153181
return 0;
154182
}
155183

184+
static int em_create_runtime_table(struct em_perf_domain *pd)
185+
{
186+
struct em_perf_table __rcu *table;
187+
int table_size;
188+
189+
table = em_allocate_table(pd);
190+
if (!table)
191+
return -ENOMEM;
192+
193+
/* Initialize runtime table with existing data */
194+
table_size = sizeof(struct em_perf_state) * pd->nr_perf_states;
195+
memcpy(table->state, pd->table, table_size);
196+
197+
rcu_assign_pointer(pd->em_table, table);
198+
199+
return 0;
200+
}
201+
156202
static int em_create_perf_table(struct device *dev, struct em_perf_domain *pd,
157203
struct em_perf_state *table,
158204
struct em_data_callback *cb,
@@ -245,6 +291,10 @@ static int em_create_pd(struct device *dev, int nr_states,
245291
if (ret)
246292
goto free_pd_table;
247293

294+
ret = em_create_runtime_table(pd);
295+
if (ret)
296+
goto free_pd_table;
297+
248298
if (_is_cpu_device(dev))
249299
for_each_cpu(cpu, cpus) {
250300
cpu_dev = get_cpu_device(cpu);
@@ -461,6 +511,9 @@ void em_dev_unregister_perf_domain(struct device *dev)
461511
em_debug_remove_pd(dev);
462512

463513
kfree(dev->em_pd->table);
514+
515+
em_free_table(dev->em_pd->em_table);
516+
464517
kfree(dev->em_pd);
465518
dev->em_pd = NULL;
466519
mutex_unlock(&em_pd_mutex);

0 commit comments

Comments
 (0)