26
26
#include <linux/uaccess.h>
27
27
28
28
#include <acpi/processor.h>
29
+ #include <acpi/cppc_acpi.h>
29
30
30
31
#include <asm/msr.h>
31
32
#include <asm/processor.h>
@@ -53,6 +54,7 @@ struct acpi_cpufreq_data {
53
54
unsigned int resume ;
54
55
unsigned int cpu_feature ;
55
56
unsigned int acpi_perf_cpu ;
57
+ unsigned int first_perf_state ;
56
58
cpumask_var_t freqdomain_cpus ;
57
59
void (* cpu_freq_write )(struct acpi_pct_register * reg , u32 val );
58
60
u32 (* cpu_freq_read )(struct acpi_pct_register * reg );
@@ -221,10 +223,10 @@ static unsigned extract_msr(struct cpufreq_policy *policy, u32 msr)
221
223
222
224
perf = to_perf_data (data );
223
225
224
- cpufreq_for_each_entry (pos , policy -> freq_table )
226
+ cpufreq_for_each_entry (pos , policy -> freq_table + data -> first_perf_state )
225
227
if (msr == perf -> states [pos -> driver_data ].status )
226
228
return pos -> frequency ;
227
- return policy -> freq_table [0 ].frequency ;
229
+ return policy -> freq_table [data -> first_perf_state ].frequency ;
228
230
}
229
231
230
232
static unsigned extract_freq (struct cpufreq_policy * policy , u32 val )
@@ -363,6 +365,7 @@ static unsigned int get_cur_freq_on_cpu(unsigned int cpu)
363
365
struct cpufreq_policy * policy ;
364
366
unsigned int freq ;
365
367
unsigned int cached_freq ;
368
+ unsigned int state ;
366
369
367
370
pr_debug ("%s (%d)\n" , __func__ , cpu );
368
371
@@ -374,7 +377,11 @@ static unsigned int get_cur_freq_on_cpu(unsigned int cpu)
374
377
if (unlikely (!data || !policy -> freq_table ))
375
378
return 0 ;
376
379
377
- cached_freq = policy -> freq_table [to_perf_data (data )-> state ].frequency ;
380
+ state = to_perf_data (data )-> state ;
381
+ if (state < data -> first_perf_state )
382
+ state = data -> first_perf_state ;
383
+
384
+ cached_freq = policy -> freq_table [state ].frequency ;
378
385
freq = extract_freq (policy , get_cur_val (cpumask_of (cpu ), data ));
379
386
if (freq != cached_freq ) {
380
387
/*
@@ -628,16 +635,54 @@ static int acpi_cpufreq_blacklist(struct cpuinfo_x86 *c)
628
635
}
629
636
#endif
630
637
638
+ #ifdef CONFIG_ACPI_CPPC_LIB
639
+ static u64 get_max_boost_ratio (unsigned int cpu )
640
+ {
641
+ struct cppc_perf_caps perf_caps ;
642
+ u64 highest_perf , nominal_perf ;
643
+ int ret ;
644
+
645
+ if (acpi_pstate_strict )
646
+ return 0 ;
647
+
648
+ ret = cppc_get_perf_caps (cpu , & perf_caps );
649
+ if (ret ) {
650
+ pr_debug ("CPU%d: Unable to get performance capabilities (%d)\n" ,
651
+ cpu , ret );
652
+ return 0 ;
653
+ }
654
+
655
+ highest_perf = perf_caps .highest_perf ;
656
+ nominal_perf = perf_caps .nominal_perf ;
657
+
658
+ if (!highest_perf || !nominal_perf ) {
659
+ pr_debug ("CPU%d: highest or nominal performance missing\n" , cpu );
660
+ return 0 ;
661
+ }
662
+
663
+ if (highest_perf < nominal_perf ) {
664
+ pr_debug ("CPU%d: nominal performance above highest\n" , cpu );
665
+ return 0 ;
666
+ }
667
+
668
+ return div_u64 (highest_perf << SCHED_CAPACITY_SHIFT , nominal_perf );
669
+ }
670
+ #else
671
+ static inline u64 get_max_boost_ratio (unsigned int cpu ) { return 0 ; }
672
+ #endif
673
+
631
674
static int acpi_cpufreq_cpu_init (struct cpufreq_policy * policy )
632
675
{
633
- unsigned int i ;
634
- unsigned int valid_states = 0 ;
635
- unsigned int cpu = policy -> cpu ;
676
+ struct cpufreq_frequency_table * freq_table ;
677
+ struct acpi_processor_performance * perf ;
636
678
struct acpi_cpufreq_data * data ;
679
+ unsigned int cpu = policy -> cpu ;
680
+ struct cpuinfo_x86 * c = & cpu_data (cpu );
681
+ unsigned int valid_states = 0 ;
637
682
unsigned int result = 0 ;
638
- struct cpuinfo_x86 * c = & cpu_data ( policy -> cpu ) ;
639
- struct acpi_processor_performance * perf ;
640
- struct cpufreq_frequency_table * freq_table ;
683
+ unsigned int state_count ;
684
+ u64 max_boost_ratio ;
685
+ unsigned int i ;
641
686
#ifdef CONFIG_SMP
642
687
static int blacklisted ;
643
688
#endif
@@ -750,8 +795,28 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
750
795
goto err_unreg ;
751
796
}
752
797
753
- freq_table = kcalloc (perf -> state_count + 1 , sizeof (* freq_table ),
754
- GFP_KERNEL );
798
+ state_count = perf -> state_count + 1 ;
799
+
800
+ max_boost_ratio = get_max_boost_ratio (cpu );
801
+ if (max_boost_ratio ) {
802
+ /*
803
+ * Make a room for one more entry to represent the highest
804
+ * available "boost" frequency.
805
+ */
806
+ state_count ++ ;
807
+ valid_states ++ ;
808
+ data -> first_perf_state = valid_states ;
809
+ } else {
810
+ /*
811
+ * If the maximum "boost" frequency is unknown, ask the arch
812
+ * scale-invariance code to use the "nominal" performance for
813
+ * CPU utilization scaling so as to prevent the schedutil
814
+ * governor from selecting inadequate CPU frequencies.
815
+ */
816
+ arch_set_max_freq_ratio (true);
817
+ }
818
+
819
+ freq_table = kcalloc (state_count , sizeof (* freq_table ), GFP_KERNEL );
755
820
if (!freq_table ) {
756
821
result = - ENOMEM ;
757
822
goto err_unreg ;
@@ -785,6 +850,30 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
785
850
valid_states ++ ;
786
851
}
787
852
freq_table [valid_states ].frequency = CPUFREQ_TABLE_END ;
853
+
854
+ if (max_boost_ratio ) {
855
+ unsigned int state = data -> first_perf_state ;
856
+ unsigned int freq = freq_table [state ].frequency ;
857
+
858
+ /*
859
+ * Because the loop above sorts the freq_table entries in the
860
+ * descending order, freq is the maximum frequency in the table.
861
+ * Assume that it corresponds to the CPPC nominal frequency and
862
+ * use it to populate the frequency field of the extra "boost"
863
+ * frequency entry.
864
+ */
865
+ freq_table [0 ].frequency = freq * max_boost_ratio >> SCHED_CAPACITY_SHIFT ;
866
+ /*
867
+ * The purpose of the extra "boost" frequency entry is to make
868
+ * the rest of cpufreq aware of the real maximum frequency, but
869
+ * the way to request it is the same as for the first_perf_state
870
+ * entry that is expected to cover the entire range of "boost"
871
+ * frequencies of the CPU, so copy the driver_data value from
872
+ * that entry.
873
+ */
874
+ freq_table [0 ].driver_data = freq_table [state ].driver_data ;
875
+ }
876
+
788
877
policy -> freq_table = freq_table ;
789
878
perf -> state = 0 ;
790
879
@@ -858,8 +947,10 @@ static void acpi_cpufreq_cpu_ready(struct cpufreq_policy *policy)
858
947
{
859
948
struct acpi_processor_performance * perf = per_cpu_ptr (acpi_perf_data ,
860
949
policy -> cpu );
950
+ struct acpi_cpufreq_data * data = policy -> driver_data ;
951
+ unsigned int freq = policy -> freq_table [data -> first_perf_state ].frequency ;
861
952
862
- if (perf -> states [0 ].core_frequency * 1000 != policy -> cpuinfo . max_freq )
953
+ if (perf -> states [0 ].core_frequency * 1000 != freq )
863
954
pr_warn (FW_WARN "P-state 0 is not max freq\n" );
864
955
}
865
956
0 commit comments