@@ -529,6 +529,30 @@ static int intel_pstate_cppc_get_scaling(int cpu)
529
529
}
530
530
#endif /* CONFIG_ACPI_CPPC_LIB */
531
531
532
+ static int intel_pstate_freq_to_hwp_rel (struct cpudata * cpu , int freq ,
533
+ unsigned int relation )
534
+ {
535
+ if (freq == cpu -> pstate .turbo_freq )
536
+ return cpu -> pstate .turbo_pstate ;
537
+
538
+ if (freq == cpu -> pstate .max_freq )
539
+ return cpu -> pstate .max_pstate ;
540
+
541
+ switch (relation ) {
542
+ case CPUFREQ_RELATION_H :
543
+ return freq / cpu -> pstate .scaling ;
544
+ case CPUFREQ_RELATION_C :
545
+ return DIV_ROUND_CLOSEST (freq , cpu -> pstate .scaling );
546
+ }
547
+
548
+ return DIV_ROUND_UP (freq , cpu -> pstate .scaling );
549
+ }
550
+
551
+ static int intel_pstate_freq_to_hwp (struct cpudata * cpu , int freq )
552
+ {
553
+ return intel_pstate_freq_to_hwp_rel (cpu , freq , CPUFREQ_RELATION_L );
554
+ }
555
+
532
556
/**
533
557
* intel_pstate_hybrid_hwp_adjust - Calibrate HWP performance levels.
534
558
* @cpu: Target CPU.
@@ -546,6 +570,7 @@ static void intel_pstate_hybrid_hwp_adjust(struct cpudata *cpu)
546
570
int perf_ctl_scaling = cpu -> pstate .perf_ctl_scaling ;
547
571
int perf_ctl_turbo = pstate_funcs .get_turbo (cpu -> cpu );
548
572
int scaling = cpu -> pstate .scaling ;
573
+ int freq ;
549
574
550
575
pr_debug ("CPU%d: perf_ctl_max_phys = %d\n" , cpu -> cpu , perf_ctl_max_phys );
551
576
pr_debug ("CPU%d: perf_ctl_turbo = %d\n" , cpu -> cpu , perf_ctl_turbo );
@@ -559,16 +584,16 @@ static void intel_pstate_hybrid_hwp_adjust(struct cpudata *cpu)
559
584
cpu -> pstate .max_freq = rounddown (cpu -> pstate .max_pstate * scaling ,
560
585
perf_ctl_scaling );
561
586
562
- cpu -> pstate .max_pstate_physical =
563
- DIV_ROUND_UP (perf_ctl_max_phys * perf_ctl_scaling ,
564
- scaling );
587
+ freq = perf_ctl_max_phys * perf_ctl_scaling ;
588
+ cpu -> pstate .max_pstate_physical = intel_pstate_freq_to_hwp (cpu , freq );
565
589
566
- cpu -> pstate .min_freq = cpu -> pstate .min_pstate * perf_ctl_scaling ;
590
+ freq = cpu -> pstate .min_pstate * perf_ctl_scaling ;
591
+ cpu -> pstate .min_freq = freq ;
567
592
/*
568
593
* Cast the min P-state value retrieved via pstate_funcs.get_min() to
569
594
* the effective range of HWP performance levels.
570
595
*/
571
- cpu -> pstate .min_pstate = DIV_ROUND_UP (cpu -> pstate . min_freq , scaling );
596
+ cpu -> pstate .min_pstate = intel_pstate_freq_to_hwp (cpu , freq );
572
597
}
573
598
574
599
static inline void update_turbo_state (void )
@@ -2528,13 +2553,12 @@ static void intel_pstate_update_perf_limits(struct cpudata *cpu,
2528
2553
* abstract values to represent performance rather than pure ratios.
2529
2554
*/
2530
2555
if (hwp_active && cpu -> pstate .scaling != perf_ctl_scaling ) {
2531
- int scaling = cpu -> pstate .scaling ;
2532
2556
int freq ;
2533
2557
2534
2558
freq = max_policy_perf * perf_ctl_scaling ;
2535
- max_policy_perf = DIV_ROUND_UP ( freq , scaling );
2559
+ max_policy_perf = intel_pstate_freq_to_hwp ( cpu , freq );
2536
2560
freq = min_policy_perf * perf_ctl_scaling ;
2537
- min_policy_perf = DIV_ROUND_UP ( freq , scaling );
2561
+ min_policy_perf = intel_pstate_freq_to_hwp ( cpu , freq );
2538
2562
}
2539
2563
2540
2564
pr_debug ("cpu:%d min_policy_perf:%d max_policy_perf:%d\n" ,
@@ -2908,18 +2932,7 @@ static int intel_cpufreq_target(struct cpufreq_policy *policy,
2908
2932
2909
2933
cpufreq_freq_transition_begin (policy , & freqs );
2910
2934
2911
- switch (relation ) {
2912
- case CPUFREQ_RELATION_L :
2913
- target_pstate = DIV_ROUND_UP (freqs .new , cpu -> pstate .scaling );
2914
- break ;
2915
- case CPUFREQ_RELATION_H :
2916
- target_pstate = freqs .new / cpu -> pstate .scaling ;
2917
- break ;
2918
- default :
2919
- target_pstate = DIV_ROUND_CLOSEST (freqs .new , cpu -> pstate .scaling );
2920
- break ;
2921
- }
2922
-
2935
+ target_pstate = intel_pstate_freq_to_hwp_rel (cpu , freqs .new , relation );
2923
2936
target_pstate = intel_cpufreq_update_pstate (policy , target_pstate , false);
2924
2937
2925
2938
freqs .new = target_pstate * cpu -> pstate .scaling ;
@@ -2937,7 +2950,7 @@ static unsigned int intel_cpufreq_fast_switch(struct cpufreq_policy *policy,
2937
2950
2938
2951
update_turbo_state ();
2939
2952
2940
- target_pstate = DIV_ROUND_UP ( target_freq , cpu -> pstate . scaling );
2953
+ target_pstate = intel_pstate_freq_to_hwp ( cpu , target_freq );
2941
2954
2942
2955
target_pstate = intel_cpufreq_update_pstate (policy , target_pstate , true);
2943
2956
0 commit comments