Skip to content

Commit 521b512

Browse files
lukaszluba-armrafaeljw
authored andcommitted
PM / EM: change naming convention from 'capacity' to 'performance'
The Energy Model uses concept of performance domain and capacity states in order to calculate power used by CPUs. Change naming convention from capacity to performance state would enable wider usage in future, e.g. upcoming support for other devices other than CPUs. 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 4877846 commit 521b512

File tree

4 files changed

+84
-78
lines changed

4 files changed

+84
-78
lines changed

drivers/thermal/cpufreq_cooling.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,18 +333,18 @@ static inline bool em_is_sane(struct cpufreq_cooling_device *cpufreq_cdev,
333333
return false;
334334

335335
policy = cpufreq_cdev->policy;
336-
if (!cpumask_equal(policy->related_cpus, to_cpumask(em->cpus))) {
336+
if (!cpumask_equal(policy->related_cpus, em_span_cpus(em))) {
337337
pr_err("The span of pd %*pbl is misaligned with cpufreq policy %*pbl\n",
338-
cpumask_pr_args(to_cpumask(em->cpus)),
338+
cpumask_pr_args(em_span_cpus(em)),
339339
cpumask_pr_args(policy->related_cpus));
340340
return false;
341341
}
342342

343343
nr_levels = cpufreq_cdev->max_level + 1;
344-
if (em->nr_cap_states != nr_levels) {
345-
pr_err("The number of cap states in pd %*pbl (%u) doesn't match the number of cooling levels (%u)\n",
346-
cpumask_pr_args(to_cpumask(em->cpus)),
347-
em->nr_cap_states, nr_levels);
344+
if (em_pd_nr_perf_states(em) != nr_levels) {
345+
pr_err("The number of performance states in pd %*pbl (%u) doesn't match the number of cooling levels (%u)\n",
346+
cpumask_pr_args(em_span_cpus(em)),
347+
em_pd_nr_perf_states(em), nr_levels);
348348
return false;
349349
}
350350

include/linux/energy_model.h

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@
1010
#include <linux/types.h>
1111

1212
/**
13-
* em_cap_state - Capacity state of a performance domain
13+
* em_perf_state - Performance state of a performance domain
1414
* @frequency: The CPU frequency in KHz, for consistency with CPUFreq
1515
* @power: The power consumed by 1 CPU at this level, in milli-watts
1616
* @cost: The cost coefficient associated with this level, used during
1717
* energy calculation. Equal to: power * max_frequency / frequency
1818
*/
19-
struct em_cap_state {
19+
struct em_perf_state {
2020
unsigned long frequency;
2121
unsigned long power;
2222
unsigned long cost;
2323
};
2424

2525
/**
2626
* em_perf_domain - Performance domain
27-
* @table: List of capacity states, in ascending order
28-
* @nr_cap_states: Number of capacity states
27+
* @table: List of performance states, in ascending order
28+
* @nr_perf_states: Number of performance states
2929
* @cpus: Cpumask covering the CPUs of the domain
3030
*
3131
* A "performance domain" represents a group of CPUs whose performance is
@@ -34,22 +34,27 @@ struct em_cap_state {
3434
* CPUFreq policies.
3535
*/
3636
struct em_perf_domain {
37-
struct em_cap_state *table;
38-
int nr_cap_states;
37+
struct em_perf_state *table;
38+
int nr_perf_states;
3939
unsigned long cpus[];
4040
};
4141

42+
#define em_span_cpus(em) (to_cpumask((em)->cpus))
43+
4244
#ifdef CONFIG_ENERGY_MODEL
4345
#define EM_CPU_MAX_POWER 0xFFFF
4446

4547
struct em_data_callback {
4648
/**
47-
* active_power() - Provide power at the next capacity state of a CPU
48-
* @power : Active power at the capacity state in mW (modified)
49-
* @freq : Frequency at the capacity state in kHz (modified)
49+
* active_power() - Provide power at the next performance state of
50+
* a CPU
51+
* @power : Active power at the performance state in mW
52+
* (modified)
53+
* @freq : Frequency at the performance state in kHz
54+
* (modified)
5055
* @cpu : CPU for which we do this operation
5156
*
52-
* active_power() must find the lowest capacity state of 'cpu' above
57+
* active_power() must find the lowest performance state of 'cpu' above
5358
* 'freq' and update 'power' and 'freq' to the matching active power
5459
* and frequency.
5560
*
@@ -80,46 +85,46 @@ static inline unsigned long em_pd_energy(struct em_perf_domain *pd,
8085
unsigned long max_util, unsigned long sum_util)
8186
{
8287
unsigned long freq, scale_cpu;
83-
struct em_cap_state *cs;
88+
struct em_perf_state *ps;
8489
int i, cpu;
8590

8691
/*
87-
* In order to predict the capacity state, map the utilization of the
88-
* most utilized CPU of the performance domain to a requested frequency,
89-
* like schedutil.
92+
* In order to predict the performance state, map the utilization of
93+
* the most utilized CPU of the performance domain to a requested
94+
* frequency, like schedutil.
9095
*/
9196
cpu = cpumask_first(to_cpumask(pd->cpus));
9297
scale_cpu = arch_scale_cpu_capacity(cpu);
93-
cs = &pd->table[pd->nr_cap_states - 1];
94-
freq = map_util_freq(max_util, cs->frequency, scale_cpu);
98+
ps = &pd->table[pd->nr_perf_states - 1];
99+
freq = map_util_freq(max_util, ps->frequency, scale_cpu);
95100

96101
/*
97-
* Find the lowest capacity state of the Energy Model above the
102+
* Find the lowest performance state of the Energy Model above the
98103
* requested frequency.
99104
*/
100-
for (i = 0; i < pd->nr_cap_states; i++) {
101-
cs = &pd->table[i];
102-
if (cs->frequency >= freq)
105+
for (i = 0; i < pd->nr_perf_states; i++) {
106+
ps = &pd->table[i];
107+
if (ps->frequency >= freq)
103108
break;
104109
}
105110

106111
/*
107-
* The capacity of a CPU in the domain at that capacity state (cs)
112+
* The capacity of a CPU in the domain at the performance state (ps)
108113
* can be computed as:
109114
*
110-
* cs->freq * scale_cpu
111-
* cs->cap = -------------------- (1)
115+
* ps->freq * scale_cpu
116+
* ps->cap = -------------------- (1)
112117
* cpu_max_freq
113118
*
114119
* So, ignoring the costs of idle states (which are not available in
115-
* the EM), the energy consumed by this CPU at that capacity state is
116-
* estimated as:
120+
* the EM), the energy consumed by this CPU at that performance state
121+
* is estimated as:
117122
*
118-
* cs->power * cpu_util
123+
* ps->power * cpu_util
119124
* cpu_nrg = -------------------- (2)
120-
* cs->cap
125+
* ps->cap
121126
*
122-
* since 'cpu_util / cs->cap' represents its percentage of busy time.
127+
* since 'cpu_util / ps->cap' represents its percentage of busy time.
123128
*
124129
* NOTE: Although the result of this computation actually is in
125130
* units of power, it can be manipulated as an energy value
@@ -129,34 +134,35 @@ static inline unsigned long em_pd_energy(struct em_perf_domain *pd,
129134
* By injecting (1) in (2), 'cpu_nrg' can be re-expressed as a product
130135
* of two terms:
131136
*
132-
* cs->power * cpu_max_freq cpu_util
137+
* ps->power * cpu_max_freq cpu_util
133138
* cpu_nrg = ------------------------ * --------- (3)
134-
* cs->freq scale_cpu
139+
* ps->freq scale_cpu
135140
*
136-
* The first term is static, and is stored in the em_cap_state struct
137-
* as 'cs->cost'.
141+
* The first term is static, and is stored in the em_perf_state struct
142+
* as 'ps->cost'.
138143
*
139144
* Since all CPUs of the domain have the same micro-architecture, they
140-
* share the same 'cs->cost', and the same CPU capacity. Hence, the
145+
* share the same 'ps->cost', and the same CPU capacity. Hence, the
141146
* total energy of the domain (which is the simple sum of the energy of
142147
* all of its CPUs) can be factorized as:
143148
*
144-
* cs->cost * \Sum cpu_util
149+
* ps->cost * \Sum cpu_util
145150
* pd_nrg = ------------------------ (4)
146151
* scale_cpu
147152
*/
148-
return cs->cost * sum_util / scale_cpu;
153+
return ps->cost * sum_util / scale_cpu;
149154
}
150155

151156
/**
152-
* em_pd_nr_cap_states() - Get the number of capacity states of a perf. domain
157+
* em_pd_nr_perf_states() - Get the number of performance states of a perf.
158+
* domain
153159
* @pd : performance domain for which this must be done
154160
*
155-
* Return: the number of capacity states in the performance domain table
161+
* Return: the number of performance states in the performance domain table
156162
*/
157-
static inline int em_pd_nr_cap_states(struct em_perf_domain *pd)
163+
static inline int em_pd_nr_perf_states(struct em_perf_domain *pd)
158164
{
159-
return pd->nr_cap_states;
165+
return pd->nr_perf_states;
160166
}
161167

162168
#else
@@ -177,7 +183,7 @@ static inline unsigned long em_pd_energy(struct em_perf_domain *pd,
177183
{
178184
return 0;
179185
}
180-
static inline int em_pd_nr_cap_states(struct em_perf_domain *pd)
186+
static inline int em_pd_nr_perf_states(struct em_perf_domain *pd)
181187
{
182188
return 0;
183189
}

kernel/power/energy_model.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ static DEFINE_MUTEX(em_pd_mutex);
2727
#ifdef CONFIG_DEBUG_FS
2828
static struct dentry *rootdir;
2929

30-
static void em_debug_create_cs(struct em_cap_state *cs, struct dentry *pd)
30+
static void em_debug_create_ps(struct em_perf_state *ps, struct dentry *pd)
3131
{
3232
struct dentry *d;
3333
char name[24];
3434

35-
snprintf(name, sizeof(name), "cs:%lu", cs->frequency);
35+
snprintf(name, sizeof(name), "ps:%lu", ps->frequency);
3636

37-
/* Create per-cs directory */
37+
/* Create per-ps directory */
3838
d = debugfs_create_dir(name, pd);
39-
debugfs_create_ulong("frequency", 0444, d, &cs->frequency);
40-
debugfs_create_ulong("power", 0444, d, &cs->power);
41-
debugfs_create_ulong("cost", 0444, d, &cs->cost);
39+
debugfs_create_ulong("frequency", 0444, d, &ps->frequency);
40+
debugfs_create_ulong("power", 0444, d, &ps->power);
41+
debugfs_create_ulong("cost", 0444, d, &ps->cost);
4242
}
4343

4444
static int em_debug_cpus_show(struct seq_file *s, void *unused)
@@ -62,9 +62,9 @@ static void em_debug_create_pd(struct em_perf_domain *pd, int cpu)
6262

6363
debugfs_create_file("cpus", 0444, d, pd->cpus, &em_debug_cpus_fops);
6464

65-
/* Create a sub-directory for each capacity state */
66-
for (i = 0; i < pd->nr_cap_states; i++)
67-
em_debug_create_cs(&pd->table[i], d);
65+
/* Create a sub-directory for each performance state */
66+
for (i = 0; i < pd->nr_perf_states; i++)
67+
em_debug_create_ps(&pd->table[i], d);
6868
}
6969

7070
static int __init em_debug_init(void)
@@ -84,7 +84,7 @@ static struct em_perf_domain *em_create_pd(cpumask_t *span, int nr_states,
8484
unsigned long opp_eff, prev_opp_eff = ULONG_MAX;
8585
unsigned long power, freq, prev_freq = 0;
8686
int i, ret, cpu = cpumask_first(span);
87-
struct em_cap_state *table;
87+
struct em_perf_state *table;
8888
struct em_perf_domain *pd;
8989
u64 fmax;
9090

@@ -99,26 +99,26 @@ static struct em_perf_domain *em_create_pd(cpumask_t *span, int nr_states,
9999
if (!table)
100100
goto free_pd;
101101

102-
/* Build the list of capacity states for this performance domain */
102+
/* Build the list of performance states for this performance domain */
103103
for (i = 0, freq = 0; i < nr_states; i++, freq++) {
104104
/*
105105
* active_power() is a driver callback which ceils 'freq' to
106-
* lowest capacity state of 'cpu' above 'freq' and updates
106+
* lowest performance state of 'cpu' above 'freq' and updates
107107
* 'power' and 'freq' accordingly.
108108
*/
109109
ret = cb->active_power(&power, &freq, cpu);
110110
if (ret) {
111-
pr_err("pd%d: invalid cap. state: %d\n", cpu, ret);
112-
goto free_cs_table;
111+
pr_err("pd%d: invalid perf. state: %d\n", cpu, ret);
112+
goto free_ps_table;
113113
}
114114

115115
/*
116116
* We expect the driver callback to increase the frequency for
117-
* higher capacity states.
117+
* higher performance states.
118118
*/
119119
if (freq <= prev_freq) {
120120
pr_err("pd%d: non-increasing freq: %lu\n", cpu, freq);
121-
goto free_cs_table;
121+
goto free_ps_table;
122122
}
123123

124124
/*
@@ -127,7 +127,7 @@ static struct em_perf_domain *em_create_pd(cpumask_t *span, int nr_states,
127127
*/
128128
if (!power || power > EM_CPU_MAX_POWER) {
129129
pr_err("pd%d: invalid power: %lu\n", cpu, power);
130-
goto free_cs_table;
130+
goto free_ps_table;
131131
}
132132

133133
table[i].power = power;
@@ -141,27 +141,27 @@ static struct em_perf_domain *em_create_pd(cpumask_t *span, int nr_states,
141141
*/
142142
opp_eff = freq / power;
143143
if (opp_eff >= prev_opp_eff)
144-
pr_warn("pd%d: hertz/watts ratio non-monotonically decreasing: em_cap_state %d >= em_cap_state%d\n",
144+
pr_warn("pd%d: hertz/watts ratio non-monotonically decreasing: em_perf_state %d >= em_perf_state%d\n",
145145
cpu, i, i - 1);
146146
prev_opp_eff = opp_eff;
147147
}
148148

149-
/* Compute the cost of each capacity_state. */
149+
/* Compute the cost of each performance state. */
150150
fmax = (u64) table[nr_states - 1].frequency;
151151
for (i = 0; i < nr_states; i++) {
152152
table[i].cost = div64_u64(fmax * table[i].power,
153153
table[i].frequency);
154154
}
155155

156156
pd->table = table;
157-
pd->nr_cap_states = nr_states;
157+
pd->nr_perf_states = nr_states;
158158
cpumask_copy(to_cpumask(pd->cpus), span);
159159

160160
em_debug_create_pd(pd, cpu);
161161

162162
return pd;
163163

164-
free_cs_table:
164+
free_ps_table:
165165
kfree(table);
166166
free_pd:
167167
kfree(pd);
@@ -185,7 +185,7 @@ EXPORT_SYMBOL_GPL(em_cpu_get);
185185
/**
186186
* em_register_perf_domain() - Register the Energy Model of a performance domain
187187
* @span : Mask of CPUs in the performance domain
188-
* @nr_states : Number of capacity states to register
188+
* @nr_states : Number of performance states to register
189189
* @cb : Callback functions providing the data of the Energy Model
190190
*
191191
* Create Energy Model tables for a performance domain using the callbacks

0 commit comments

Comments
 (0)