@@ -91,48 +91,62 @@ struct cpufreq_cooling_device {
91
91
static unsigned long get_level (struct cpufreq_cooling_device * cpufreq_cdev ,
92
92
unsigned int freq )
93
93
{
94
+ struct em_perf_state * table ;
94
95
int i ;
95
96
97
+ rcu_read_lock ();
98
+ table = em_perf_state_from_pd (cpufreq_cdev -> em );
96
99
for (i = cpufreq_cdev -> max_level - 1 ; i >= 0 ; i -- ) {
97
- if (freq > cpufreq_cdev -> em -> table [i ].frequency )
100
+ if (freq > table [i ].frequency )
98
101
break ;
99
102
}
103
+ rcu_read_unlock ();
100
104
101
105
return cpufreq_cdev -> max_level - i - 1 ;
102
106
}
103
107
104
108
static u32 cpu_freq_to_power (struct cpufreq_cooling_device * cpufreq_cdev ,
105
109
u32 freq )
106
110
{
111
+ struct em_perf_state * table ;
107
112
unsigned long power_mw ;
108
113
int i ;
109
114
115
+ rcu_read_lock ();
116
+ table = em_perf_state_from_pd (cpufreq_cdev -> em );
110
117
for (i = cpufreq_cdev -> max_level - 1 ; i >= 0 ; i -- ) {
111
- if (freq > cpufreq_cdev -> em -> table [i ].frequency )
118
+ if (freq > table [i ].frequency )
112
119
break ;
113
120
}
114
121
115
- power_mw = cpufreq_cdev -> em -> table [i + 1 ].power ;
122
+ power_mw = table [i + 1 ].power ;
116
123
power_mw /= MICROWATT_PER_MILLIWATT ;
124
+ rcu_read_unlock ();
117
125
118
126
return power_mw ;
119
127
}
120
128
121
129
static u32 cpu_power_to_freq (struct cpufreq_cooling_device * cpufreq_cdev ,
122
130
u32 power )
123
131
{
132
+ struct em_perf_state * table ;
124
133
unsigned long em_power_mw ;
134
+ u32 freq ;
125
135
int i ;
126
136
137
+ rcu_read_lock ();
138
+ table = em_perf_state_from_pd (cpufreq_cdev -> em );
127
139
for (i = cpufreq_cdev -> max_level ; i > 0 ; i -- ) {
128
140
/* Convert EM power to milli-Watts to make safe comparison */
129
- em_power_mw = cpufreq_cdev -> em -> table [i ].power ;
141
+ em_power_mw = table [i ].power ;
130
142
em_power_mw /= MICROWATT_PER_MILLIWATT ;
131
143
if (power >= em_power_mw )
132
144
break ;
133
145
}
146
+ freq = table [i ].frequency ;
147
+ rcu_read_unlock ();
134
148
135
- return cpufreq_cdev -> em -> table [ i ]. frequency ;
149
+ return freq ;
136
150
}
137
151
138
152
/**
@@ -262,8 +276,9 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev,
262
276
static int cpufreq_state2power (struct thermal_cooling_device * cdev ,
263
277
unsigned long state , u32 * power )
264
278
{
265
- unsigned int freq , num_cpus , idx ;
266
279
struct cpufreq_cooling_device * cpufreq_cdev = cdev -> devdata ;
280
+ unsigned int freq , num_cpus , idx ;
281
+ struct em_perf_state * table ;
267
282
268
283
/* Request state should be less than max_level */
269
284
if (state > cpufreq_cdev -> max_level )
@@ -272,7 +287,12 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev,
272
287
num_cpus = cpumask_weight (cpufreq_cdev -> policy -> cpus );
273
288
274
289
idx = cpufreq_cdev -> max_level - state ;
275
- freq = cpufreq_cdev -> em -> table [idx ].frequency ;
290
+
291
+ rcu_read_lock ();
292
+ table = em_perf_state_from_pd (cpufreq_cdev -> em );
293
+ freq = table [idx ].frequency ;
294
+ rcu_read_unlock ();
295
+
276
296
* power = cpu_freq_to_power (cpufreq_cdev , freq ) * num_cpus ;
277
297
278
298
return 0 ;
@@ -378,8 +398,17 @@ static unsigned int get_state_freq(struct cpufreq_cooling_device *cpufreq_cdev,
378
398
#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
379
399
/* Use the Energy Model table if available */
380
400
if (cpufreq_cdev -> em ) {
401
+ struct em_perf_state * table ;
402
+ unsigned int freq ;
403
+
381
404
idx = cpufreq_cdev -> max_level - state ;
382
- return cpufreq_cdev -> em -> table [idx ].frequency ;
405
+
406
+ rcu_read_lock ();
407
+ table = em_perf_state_from_pd (cpufreq_cdev -> em );
408
+ freq = table [idx ].frequency ;
409
+ rcu_read_unlock ();
410
+
411
+ return freq ;
383
412
}
384
413
#endif
385
414
0 commit comments