@@ -25,9 +25,6 @@ struct sugov_policy {
2525 unsigned int next_freq ;
2626 unsigned int cached_raw_freq ;
2727
28- /* max CPU capacity, which is equal for all CPUs in freq. domain */
29- unsigned long max ;
30-
3128 /* The next fields are only needed if fast switch cannot be used: */
3229 struct irq_work irq_work ;
3330 struct kthread_work work ;
@@ -51,6 +48,7 @@ struct sugov_cpu {
5148
5249 unsigned long util ;
5350 unsigned long bw_dl ;
51+ unsigned long max ;
5452
5553 /* The field below is for single-CPU policies only: */
5654#ifdef CONFIG_NO_HZ_COMMON
@@ -160,6 +158,7 @@ static void sugov_get_util(struct sugov_cpu *sg_cpu)
160158{
161159 struct rq * rq = cpu_rq (sg_cpu -> cpu );
162160
161+ sg_cpu -> max = arch_scale_cpu_capacity (sg_cpu -> cpu );
163162 sg_cpu -> bw_dl = cpu_bw_dl (rq );
164163 sg_cpu -> util = effective_cpu_util (sg_cpu -> cpu , cpu_util_cfs (sg_cpu -> cpu ),
165164 FREQUENCY_UTIL , NULL );
@@ -254,7 +253,6 @@ static void sugov_iowait_boost(struct sugov_cpu *sg_cpu, u64 time,
254253 */
255254static void sugov_iowait_apply (struct sugov_cpu * sg_cpu , u64 time )
256255{
257- struct sugov_policy * sg_policy = sg_cpu -> sg_policy ;
258256 unsigned long boost ;
259257
260258 /* No boost currently required */
@@ -282,8 +280,7 @@ static void sugov_iowait_apply(struct sugov_cpu *sg_cpu, u64 time)
282280 * sg_cpu->util is already in capacity scale; convert iowait_boost
283281 * into the same scale so we can compare.
284282 */
285- boost = sg_cpu -> iowait_boost * sg_policy -> max ;
286- boost >>= SCHED_CAPACITY_SHIFT ;
283+ boost = (sg_cpu -> iowait_boost * sg_cpu -> max ) >> SCHED_CAPACITY_SHIFT ;
287284 boost = uclamp_rq_util_with (cpu_rq (sg_cpu -> cpu ), boost , NULL );
288285 if (sg_cpu -> util < boost )
289286 sg_cpu -> util = boost ;
@@ -340,7 +337,7 @@ static void sugov_update_single_freq(struct update_util_data *hook, u64 time,
340337 if (!sugov_update_single_common (sg_cpu , time , flags ))
341338 return ;
342339
343- next_f = get_next_freq (sg_policy , sg_cpu -> util , sg_policy -> max );
340+ next_f = get_next_freq (sg_policy , sg_cpu -> util , sg_cpu -> max );
344341 /*
345342 * Do not reduce the frequency if the CPU has not been idle
346343 * recently, as the reduction is likely to be premature then.
@@ -376,7 +373,6 @@ static void sugov_update_single_perf(struct update_util_data *hook, u64 time,
376373 unsigned int flags )
377374{
378375 struct sugov_cpu * sg_cpu = container_of (hook , struct sugov_cpu , update_util );
379- struct sugov_policy * sg_policy = sg_cpu -> sg_policy ;
380376 unsigned long prev_util = sg_cpu -> util ;
381377
382378 /*
@@ -403,8 +399,7 @@ static void sugov_update_single_perf(struct update_util_data *hook, u64 time,
403399 sg_cpu -> util = prev_util ;
404400
405401 cpufreq_driver_adjust_perf (sg_cpu -> cpu , map_util_perf (sg_cpu -> bw_dl ),
406- map_util_perf (sg_cpu -> util ),
407- sg_policy -> max );
402+ map_util_perf (sg_cpu -> util ), sg_cpu -> max );
408403
409404 sg_cpu -> sg_policy -> last_freq_update_time = time ;
410405}
@@ -413,19 +408,25 @@ static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time)
413408{
414409 struct sugov_policy * sg_policy = sg_cpu -> sg_policy ;
415410 struct cpufreq_policy * policy = sg_policy -> policy ;
416- unsigned long util = 0 ;
411+ unsigned long util = 0 , max = 1 ;
417412 unsigned int j ;
418413
419414 for_each_cpu (j , policy -> cpus ) {
420415 struct sugov_cpu * j_sg_cpu = & per_cpu (sugov_cpu , j );
416+ unsigned long j_util , j_max ;
421417
422418 sugov_get_util (j_sg_cpu );
423419 sugov_iowait_apply (j_sg_cpu , time );
420+ j_util = j_sg_cpu -> util ;
421+ j_max = j_sg_cpu -> max ;
424422
425- util = max (j_sg_cpu -> util , util );
423+ if (j_util * max > j_max * util ) {
424+ util = j_util ;
425+ max = j_max ;
426+ }
426427 }
427428
428- return get_next_freq (sg_policy , util , sg_policy -> max );
429+ return get_next_freq (sg_policy , util , max );
429430}
430431
431432static void
@@ -751,15 +752,14 @@ static int sugov_start(struct cpufreq_policy *policy)
751752{
752753 struct sugov_policy * sg_policy = policy -> governor_data ;
753754 void (* uu )(struct update_util_data * data , u64 time , unsigned int flags );
754- unsigned int cpu = cpumask_first ( policy -> cpus ) ;
755+ unsigned int cpu ;
755756
756757 sg_policy -> freq_update_delay_ns = sg_policy -> tunables -> rate_limit_us * NSEC_PER_USEC ;
757758 sg_policy -> last_freq_update_time = 0 ;
758759 sg_policy -> next_freq = 0 ;
759760 sg_policy -> work_in_progress = false;
760761 sg_policy -> limits_changed = false;
761762 sg_policy -> cached_raw_freq = 0 ;
762- sg_policy -> max = arch_scale_cpu_capacity (cpu );
763763
764764 sg_policy -> need_freq_update = cpufreq_driver_test_flags (CPUFREQ_NEED_UPDATE_LIMITS );
765765
0 commit comments