@@ -42,6 +42,7 @@ static u64 set_pd_power_limit(struct dtpm *dtpm, u64 power_limit)
4242{
4343 struct dtpm_cpu * dtpm_cpu = to_dtpm_cpu (dtpm );
4444 struct em_perf_domain * pd = em_cpu_get (dtpm_cpu -> cpu );
45+ struct em_perf_state * table ;
4546 struct cpumask cpus ;
4647 unsigned long freq ;
4748 u64 power ;
@@ -50,20 +51,22 @@ static u64 set_pd_power_limit(struct dtpm *dtpm, u64 power_limit)
5051 cpumask_and (& cpus , cpu_online_mask , to_cpumask (pd -> cpus ));
5152 nr_cpus = cpumask_weight (& cpus );
5253
54+ rcu_read_lock ();
55+ table = em_perf_state_from_pd (pd );
5356 for (i = 0 ; i < pd -> nr_perf_states ; i ++ ) {
5457
55- power = pd -> table [i ].power * nr_cpus ;
58+ power = table [i ].power * nr_cpus ;
5659
5760 if (power > power_limit )
5861 break ;
5962 }
6063
61- freq = pd -> table [i - 1 ].frequency ;
64+ freq = table [i - 1 ].frequency ;
65+ power_limit = table [i - 1 ].power * nr_cpus ;
66+ rcu_read_unlock ();
6267
6368 freq_qos_update_request (& dtpm_cpu -> qos_req , freq );
6469
65- power_limit = pd -> table [i - 1 ].power * nr_cpus ;
66-
6770 return power_limit ;
6871}
6972
@@ -87,9 +90,11 @@ static u64 scale_pd_power_uw(struct cpumask *pd_mask, u64 power)
8790static u64 get_pd_power_uw (struct dtpm * dtpm )
8891{
8992 struct dtpm_cpu * dtpm_cpu = to_dtpm_cpu (dtpm );
93+ struct em_perf_state * table ;
9094 struct em_perf_domain * pd ;
9195 struct cpumask * pd_mask ;
9296 unsigned long freq ;
97+ u64 power = 0 ;
9398 int i ;
9499
95100 pd = em_cpu_get (dtpm_cpu -> cpu );
@@ -98,33 +103,43 @@ static u64 get_pd_power_uw(struct dtpm *dtpm)
98103
99104 freq = cpufreq_quick_get (dtpm_cpu -> cpu );
100105
106+ rcu_read_lock ();
107+ table = em_perf_state_from_pd (pd );
101108 for (i = 0 ; i < pd -> nr_perf_states ; i ++ ) {
102109
103- if (pd -> table [i ].frequency < freq )
110+ if (table [i ].frequency < freq )
104111 continue ;
105112
106- return scale_pd_power_uw (pd_mask , pd -> table [i ].power );
113+ power = scale_pd_power_uw (pd_mask , table [i ].power );
114+ break ;
107115 }
116+ rcu_read_unlock ();
108117
109- return 0 ;
118+ return power ;
110119}
111120
112121static int update_pd_power_uw (struct dtpm * dtpm )
113122{
114123 struct dtpm_cpu * dtpm_cpu = to_dtpm_cpu (dtpm );
115124 struct em_perf_domain * em = em_cpu_get (dtpm_cpu -> cpu );
125+ struct em_perf_state * table ;
116126 struct cpumask cpus ;
117127 int nr_cpus ;
118128
119129 cpumask_and (& cpus , cpu_online_mask , to_cpumask (em -> cpus ));
120130 nr_cpus = cpumask_weight (& cpus );
121131
122- dtpm -> power_min = em -> table [0 ].power ;
132+ rcu_read_lock ();
133+ table = em_perf_state_from_pd (em );
134+
135+ dtpm -> power_min = table [0 ].power ;
123136 dtpm -> power_min *= nr_cpus ;
124137
125- dtpm -> power_max = em -> table [em -> nr_perf_states - 1 ].power ;
138+ dtpm -> power_max = table [em -> nr_perf_states - 1 ].power ;
126139 dtpm -> power_max *= nr_cpus ;
127140
141+ rcu_read_unlock ();
142+
128143 return 0 ;
129144}
130145
@@ -180,6 +195,7 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent)
180195{
181196 struct dtpm_cpu * dtpm_cpu ;
182197 struct cpufreq_policy * policy ;
198+ struct em_perf_state * table ;
183199 struct em_perf_domain * pd ;
184200 char name [CPUFREQ_NAME_LEN ];
185201 int ret = - ENOMEM ;
@@ -216,9 +232,12 @@ static int __dtpm_cpu_setup(int cpu, struct dtpm *parent)
216232 if (ret )
217233 goto out_kfree_dtpm_cpu ;
218234
235+ rcu_read_lock ();
236+ table = em_perf_state_from_pd (pd );
219237 ret = freq_qos_add_request (& policy -> constraints ,
220238 & dtpm_cpu -> qos_req , FREQ_QOS_MAX ,
221- pd -> table [pd -> nr_perf_states - 1 ].frequency );
239+ table [pd -> nr_perf_states - 1 ].frequency );
240+ rcu_read_unlock ();
222241 if (ret )
223242 goto out_dtpm_unregister ;
224243
0 commit comments