Skip to content

Commit 8354eb9

Browse files
Vincent Donnefortrafaeljw
authored andcommitted
PM: EM: Allow skipping inefficient states
The new performance domain flag EM_PERF_DOMAIN_SKIP_INEFFICIENCIES allows to not take into account inefficient states when estimating energy consumption. This intends to let the Energy Model know that CPUFreq itself will skip inefficiencies and such states don't need to be part of the estimation anymore. Signed-off-by: Vincent Donnefort <[email protected]> Reviewed-by: Lukasz Luba <[email protected]> Acked-by: Viresh Kumar <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 88f7a89 commit 8354eb9

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

include/linux/energy_model.h

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ struct em_perf_domain {
6464
*
6565
* EM_PERF_DOMAIN_MILLIWATTS: The power values are in milli-Watts or some
6666
* other scale.
67+
*
68+
* EM_PERF_DOMAIN_SKIP_INEFFICIENCIES: Skip inefficient states when estimating
69+
* energy consumption.
6770
*/
6871
#define EM_PERF_DOMAIN_MILLIWATTS BIT(0)
72+
#define EM_PERF_DOMAIN_SKIP_INEFFICIENCIES BIT(1)
6973

7074
#define em_span_cpus(em) (to_cpumask((em)->cpus))
7175

@@ -120,6 +124,37 @@ int em_dev_register_perf_domain(struct device *dev, unsigned int nr_states,
120124
bool milliwatts);
121125
void em_dev_unregister_perf_domain(struct device *dev);
122126

127+
/**
128+
* em_pd_get_efficient_state() - Get an efficient performance state from the EM
129+
* @pd : Performance domain for which we want an efficient frequency
130+
* @freq : Frequency to map with the EM
131+
*
132+
* It is called from the scheduler code quite frequently and as a consequence
133+
* doesn't implement any check.
134+
*
135+
* Return: An efficient performance state, high enough to meet @freq
136+
* requirement.
137+
*/
138+
static inline
139+
struct em_perf_state *em_pd_get_efficient_state(struct em_perf_domain *pd,
140+
unsigned long freq)
141+
{
142+
struct em_perf_state *ps;
143+
int i;
144+
145+
for (i = 0; i < pd->nr_perf_states; i++) {
146+
ps = &pd->table[i];
147+
if (ps->frequency >= freq) {
148+
if (pd->flags & EM_PERF_DOMAIN_SKIP_INEFFICIENCIES &&
149+
ps->flags & EM_PERF_STATE_INEFFICIENT)
150+
continue;
151+
break;
152+
}
153+
}
154+
155+
return ps;
156+
}
157+
123158
/**
124159
* em_cpu_energy() - Estimates the energy consumed by the CPUs of a
125160
* performance domain
@@ -142,7 +177,7 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd,
142177
{
143178
unsigned long freq, scale_cpu;
144179
struct em_perf_state *ps;
145-
int i, cpu;
180+
int cpu;
146181

147182
if (!sum_util)
148183
return 0;
@@ -167,11 +202,7 @@ static inline unsigned long em_cpu_energy(struct em_perf_domain *pd,
167202
* Find the lowest performance state of the Energy Model above the
168203
* requested frequency.
169204
*/
170-
for (i = 0; i < pd->nr_perf_states; i++) {
171-
ps = &pd->table[i];
172-
if (ps->frequency >= freq)
173-
break;
174-
}
205+
ps = em_pd_get_efficient_state(pd, freq);
175206

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

kernel/power/energy_model.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ static int em_debug_units_show(struct seq_file *s, void *unused)
6565
}
6666
DEFINE_SHOW_ATTRIBUTE(em_debug_units);
6767

68+
static int em_debug_skip_inefficiencies_show(struct seq_file *s, void *unused)
69+
{
70+
struct em_perf_domain *pd = s->private;
71+
int enabled = (pd->flags & EM_PERF_DOMAIN_SKIP_INEFFICIENCIES) ? 1 : 0;
72+
73+
seq_printf(s, "%d\n", enabled);
74+
75+
return 0;
76+
}
77+
DEFINE_SHOW_ATTRIBUTE(em_debug_skip_inefficiencies);
78+
6879
static void em_debug_create_pd(struct device *dev)
6980
{
7081
struct dentry *d;
@@ -78,6 +89,8 @@ static void em_debug_create_pd(struct device *dev)
7889
&em_debug_cpus_fops);
7990

8091
debugfs_create_file("units", 0444, d, dev->em_pd, &em_debug_units_fops);
92+
debugfs_create_file("skip-inefficiencies", 0444, d, dev->em_pd,
93+
&em_debug_skip_inefficiencies_fops);
8194

8295
/* Create a sub-directory for each performance state */
8396
for (i = 0; i < dev->em_pd->nr_perf_states; i++)

0 commit comments

Comments
 (0)