@@ -91,48 +91,62 @@ struct cpufreq_cooling_device {
9191static unsigned long get_level (struct cpufreq_cooling_device * cpufreq_cdev ,
9292 unsigned int freq )
9393{
94+ struct em_perf_state * table ;
9495 int i ;
9596
97+ rcu_read_lock ();
98+ table = em_perf_state_from_pd (cpufreq_cdev -> em );
9699 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 )
98101 break ;
99102 }
103+ rcu_read_unlock ();
100104
101105 return cpufreq_cdev -> max_level - i - 1 ;
102106}
103107
104108static u32 cpu_freq_to_power (struct cpufreq_cooling_device * cpufreq_cdev ,
105109 u32 freq )
106110{
111+ struct em_perf_state * table ;
107112 unsigned long power_mw ;
108113 int i ;
109114
115+ rcu_read_lock ();
116+ table = em_perf_state_from_pd (cpufreq_cdev -> em );
110117 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 )
112119 break ;
113120 }
114121
115- power_mw = cpufreq_cdev -> em -> table [i + 1 ].power ;
122+ power_mw = table [i + 1 ].power ;
116123 power_mw /= MICROWATT_PER_MILLIWATT ;
124+ rcu_read_unlock ();
117125
118126 return power_mw ;
119127}
120128
121129static u32 cpu_power_to_freq (struct cpufreq_cooling_device * cpufreq_cdev ,
122130 u32 power )
123131{
132+ struct em_perf_state * table ;
124133 unsigned long em_power_mw ;
134+ u32 freq ;
125135 int i ;
126136
137+ rcu_read_lock ();
138+ table = em_perf_state_from_pd (cpufreq_cdev -> em );
127139 for (i = cpufreq_cdev -> max_level ; i > 0 ; i -- ) {
128140 /* 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 ;
130142 em_power_mw /= MICROWATT_PER_MILLIWATT ;
131143 if (power >= em_power_mw )
132144 break ;
133145 }
146+ freq = table [i ].frequency ;
147+ rcu_read_unlock ();
134148
135- return cpufreq_cdev -> em -> table [ i ]. frequency ;
149+ return freq ;
136150}
137151
138152/**
@@ -262,8 +276,9 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev,
262276static int cpufreq_state2power (struct thermal_cooling_device * cdev ,
263277 unsigned long state , u32 * power )
264278{
265- unsigned int freq , num_cpus , idx ;
266279 struct cpufreq_cooling_device * cpufreq_cdev = cdev -> devdata ;
280+ unsigned int freq , num_cpus , idx ;
281+ struct em_perf_state * table ;
267282
268283 /* Request state should be less than max_level */
269284 if (state > cpufreq_cdev -> max_level )
@@ -272,7 +287,12 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev,
272287 num_cpus = cpumask_weight (cpufreq_cdev -> policy -> cpus );
273288
274289 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+
276296 * power = cpu_freq_to_power (cpufreq_cdev , freq ) * num_cpus ;
277297
278298 return 0 ;
@@ -378,8 +398,17 @@ static unsigned int get_state_freq(struct cpufreq_cooling_device *cpufreq_cdev,
378398#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
379399 /* Use the Energy Model table if available */
380400 if (cpufreq_cdev -> em ) {
401+ struct em_perf_state * table ;
402+ unsigned int freq ;
403+
381404 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 ;
383412 }
384413#endif
385414
0 commit comments