Skip to content

Commit a3c7877

Browse files
lukaszluba-armrafaeljw
authored andcommitted
PM: EM: Refactor em_pd_get_efficient_state() to be more flexible
The Energy Model (EM) is going to support runtime modification. There are going to be 2 EM tables which store information. This patch aims to prepare the code to be generic and use one of the tables. The function will no longer get a pointer to 'struct em_perf_domain' (the EM) but instead a pointer to 'struct em_perf_state' (which is one of the EM's tables). Prepare em_pd_get_efficient_state() for the upcoming changes and make it possible to be re-used. Return an index for the best performance state for a given EM table. The function arguments that are introduced should allow to work on different performance state arrays. The caller of em_pd_get_efficient_state() should be able to use the index either on the default or the modifiable EM table. Reviewed-by: Daniel Lezcano <[email protected]> Reviewed-by: Hongyan Xia <[email protected]> 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 99907d6 commit a3c7877

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

include/linux/energy_model.h

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,33 +175,35 @@ void em_dev_unregister_perf_domain(struct device *dev);
175175

176176
/**
177177
* em_pd_get_efficient_state() - Get an efficient performance state from the EM
178-
* @pd : Performance domain for which we want an efficient frequency
179-
* @freq : Frequency to map with the EM
178+
* @table: List of performance states, in ascending order
179+
* @nr_perf_states: Number of performance states
180+
* @freq: Frequency to map with the EM
181+
* @pd_flags: Performance Domain flags
180182
*
181183
* It is called from the scheduler code quite frequently and as a consequence
182184
* doesn't implement any check.
183185
*
184-
* Return: An efficient performance state, high enough to meet @freq
186+
* Return: An efficient performance state id, high enough to meet @freq
185187
* requirement.
186188
*/
187-
static inline
188-
struct em_perf_state *em_pd_get_efficient_state(struct em_perf_domain *pd,
189-
unsigned long freq)
189+
static inline int
190+
em_pd_get_efficient_state(struct em_perf_state *table, int nr_perf_states,
191+
unsigned long freq, unsigned long pd_flags)
190192
{
191193
struct em_perf_state *ps;
192194
int i;
193195

194-
for (i = 0; i < pd->nr_perf_states; i++) {
195-
ps = &pd->table[i];
196+
for (i = 0; i < nr_perf_states; i++) {
197+
ps = &table[i];
196198
if (ps->frequency >= freq) {
197-
if (pd->flags & EM_PERF_DOMAIN_SKIP_INEFFICIENCIES &&
199+
if (pd_flags & EM_PERF_DOMAIN_SKIP_INEFFICIENCIES &&
198200
ps->flags & EM_PERF_STATE_INEFFICIENT)
199201
continue;
200-
break;
202+
return i;
201203
}
202204
}
203205

204-
return ps;
206+
return nr_perf_states - 1;
205207
}
206208

207209
/**
@@ -226,7 +228,7 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd,
226228
{
227229
unsigned long freq, ref_freq, scale_cpu;
228230
struct em_perf_state *ps;
229-
int cpu;
231+
int cpu, i;
230232

231233
if (!sum_util)
232234
return 0;
@@ -250,7 +252,9 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd,
250252
* Find the lowest performance state of the Energy Model above the
251253
* requested frequency.
252254
*/
253-
ps = em_pd_get_efficient_state(pd, freq);
255+
i = em_pd_get_efficient_state(pd->table, pd->nr_perf_states, freq,
256+
pd->flags);
257+
ps = &pd->table[i];
254258

255259
/*
256260
* The capacity of a CPU in the domain at the performance state (ps)

0 commit comments

Comments
 (0)