@@ -87,6 +87,7 @@ static int devfreq_cooling_set_cur_state(struct thermal_cooling_device *cdev,
8787 struct devfreq_cooling_device * dfc = cdev -> devdata ;
8888 struct devfreq * df = dfc -> devfreq ;
8989 struct device * dev = df -> dev .parent ;
90+ struct em_perf_state * table ;
9091 unsigned long freq ;
9192 int perf_idx ;
9293
@@ -100,7 +101,11 @@ static int devfreq_cooling_set_cur_state(struct thermal_cooling_device *cdev,
100101
101102 if (dfc -> em_pd ) {
102103 perf_idx = dfc -> max_state - state ;
103- freq = dfc -> em_pd -> table [perf_idx ].frequency * 1000 ;
104+
105+ rcu_read_lock ();
106+ table = em_perf_state_from_pd (dfc -> em_pd );
107+ freq = table [perf_idx ].frequency * 1000 ;
108+ rcu_read_unlock ();
104109 } else {
105110 freq = dfc -> freq_table [state ];
106111 }
@@ -123,14 +128,21 @@ static int devfreq_cooling_set_cur_state(struct thermal_cooling_device *cdev,
123128 */
124129static int get_perf_idx (struct em_perf_domain * em_pd , unsigned long freq )
125130{
126- int i ;
131+ struct em_perf_state * table ;
132+ int i , idx = - EINVAL ;
127133
134+ rcu_read_lock ();
135+ table = em_perf_state_from_pd (em_pd );
128136 for (i = 0 ; i < em_pd -> nr_perf_states ; i ++ ) {
129- if (em_pd -> table [i ].frequency == freq )
130- return i ;
137+ if (table [i ].frequency != freq )
138+ continue ;
139+
140+ idx = i ;
141+ break ;
131142 }
143+ rcu_read_unlock ();
132144
133- return - EINVAL ;
145+ return idx ;
134146}
135147
136148static unsigned long get_voltage (struct devfreq * df , unsigned long freq )
@@ -181,6 +193,7 @@ static int devfreq_cooling_get_requested_power(struct thermal_cooling_device *cd
181193 struct devfreq_cooling_device * dfc = cdev -> devdata ;
182194 struct devfreq * df = dfc -> devfreq ;
183195 struct devfreq_dev_status status ;
196+ struct em_perf_state * table ;
184197 unsigned long state ;
185198 unsigned long freq ;
186199 unsigned long voltage ;
@@ -204,7 +217,11 @@ static int devfreq_cooling_get_requested_power(struct thermal_cooling_device *cd
204217 state = dfc -> capped_state ;
205218
206219 /* Convert EM power into milli-Watts first */
207- dfc -> res_util = dfc -> em_pd -> table [state ].power ;
220+ rcu_read_lock ();
221+ table = em_perf_state_from_pd (dfc -> em_pd );
222+ dfc -> res_util = table [state ].power ;
223+ rcu_read_unlock ();
224+
208225 dfc -> res_util /= MICROWATT_PER_MILLIWATT ;
209226
210227 dfc -> res_util *= SCALE_ERROR_MITIGATION ;
@@ -225,7 +242,11 @@ static int devfreq_cooling_get_requested_power(struct thermal_cooling_device *cd
225242 _normalize_load (& status );
226243
227244 /* Convert EM power into milli-Watts first */
228- * power = dfc -> em_pd -> table [perf_idx ].power ;
245+ rcu_read_lock ();
246+ table = em_perf_state_from_pd (dfc -> em_pd );
247+ * power = table [perf_idx ].power ;
248+ rcu_read_unlock ();
249+
229250 * power /= MICROWATT_PER_MILLIWATT ;
230251 /* Scale power for utilization */
231252 * power *= status .busy_time ;
@@ -245,13 +266,19 @@ static int devfreq_cooling_state2power(struct thermal_cooling_device *cdev,
245266 unsigned long state , u32 * power )
246267{
247268 struct devfreq_cooling_device * dfc = cdev -> devdata ;
269+ struct em_perf_state * table ;
248270 int perf_idx ;
249271
250272 if (state > dfc -> max_state )
251273 return - EINVAL ;
252274
253275 perf_idx = dfc -> max_state - state ;
254- * power = dfc -> em_pd -> table [perf_idx ].power ;
276+
277+ rcu_read_lock ();
278+ table = em_perf_state_from_pd (dfc -> em_pd );
279+ * power = table [perf_idx ].power ;
280+ rcu_read_unlock ();
281+
255282 * power /= MICROWATT_PER_MILLIWATT ;
256283
257284 return 0 ;
@@ -264,6 +291,7 @@ static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev,
264291 struct devfreq * df = dfc -> devfreq ;
265292 struct devfreq_dev_status status ;
266293 unsigned long freq , em_power_mw ;
294+ struct em_perf_state * table ;
267295 s32 est_power ;
268296 int i ;
269297
@@ -288,13 +316,16 @@ static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev,
288316 * Find the first cooling state that is within the power
289317 * budget. The EM power table is sorted ascending.
290318 */
319+ rcu_read_lock ();
320+ table = em_perf_state_from_pd (dfc -> em_pd );
291321 for (i = dfc -> max_state ; i > 0 ; i -- ) {
292322 /* Convert EM power to milli-Watts to make safe comparison */
293- em_power_mw = dfc -> em_pd -> table [i ].power ;
323+ em_power_mw = table [i ].power ;
294324 em_power_mw /= MICROWATT_PER_MILLIWATT ;
295325 if (est_power >= em_power_mw )
296326 break ;
297327 }
328+ rcu_read_unlock ();
298329
299330 * state = dfc -> max_state - i ;
300331 dfc -> capped_state = * state ;
0 commit comments