@@ -315,6 +315,7 @@ static int pstate_init_perf(struct amd_cpudata *cpudata)
315315 WRITE_ONCE (cpudata -> nominal_perf , AMD_CPPC_NOMINAL_PERF (cap1 ));
316316 WRITE_ONCE (cpudata -> lowest_nonlinear_perf , AMD_CPPC_LOWNONLIN_PERF (cap1 ));
317317 WRITE_ONCE (cpudata -> lowest_perf , AMD_CPPC_LOWEST_PERF (cap1 ));
318+ WRITE_ONCE (cpudata -> prefcore_ranking , AMD_CPPC_HIGHEST_PERF (cap1 ));
318319 WRITE_ONCE (cpudata -> min_limit_perf , AMD_CPPC_LOWEST_PERF (cap1 ));
319320 return 0 ;
320321}
@@ -339,6 +340,7 @@ static int cppc_init_perf(struct amd_cpudata *cpudata)
339340 WRITE_ONCE (cpudata -> lowest_nonlinear_perf ,
340341 cppc_perf .lowest_nonlinear_perf );
341342 WRITE_ONCE (cpudata -> lowest_perf , cppc_perf .lowest_perf );
343+ WRITE_ONCE (cpudata -> prefcore_ranking , cppc_perf .highest_perf );
342344 WRITE_ONCE (cpudata -> min_limit_perf , cppc_perf .lowest_perf );
343345
344346 if (cppc_state == AMD_PSTATE_ACTIVE )
@@ -785,6 +787,40 @@ static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata)
785787 schedule_work (& sched_prefcore_work );
786788}
787789
790+ static void amd_pstate_update_limits (unsigned int cpu )
791+ {
792+ struct cpufreq_policy * policy = cpufreq_cpu_get (cpu );
793+ struct amd_cpudata * cpudata = policy -> driver_data ;
794+ u32 prev_high = 0 , cur_high = 0 ;
795+ int ret ;
796+ bool highest_perf_changed = false;
797+
798+ mutex_lock (& amd_pstate_driver_lock );
799+ if ((!amd_pstate_prefcore ) || (!cpudata -> hw_prefcore ))
800+ goto free_cpufreq_put ;
801+
802+ ret = amd_pstate_get_highest_perf (cpu , & cur_high );
803+ if (ret )
804+ goto free_cpufreq_put ;
805+
806+ prev_high = READ_ONCE (cpudata -> prefcore_ranking );
807+ if (prev_high != cur_high ) {
808+ highest_perf_changed = true;
809+ WRITE_ONCE (cpudata -> prefcore_ranking , cur_high );
810+
811+ if (cur_high < CPPC_MAX_PERF )
812+ sched_set_itmt_core_prio ((int )cur_high , cpu );
813+ }
814+
815+ free_cpufreq_put :
816+ cpufreq_cpu_put (policy );
817+
818+ if (!highest_perf_changed )
819+ cpufreq_update_policy (cpu );
820+
821+ mutex_unlock (& amd_pstate_driver_lock );
822+ }
823+
788824static int amd_pstate_cpu_init (struct cpufreq_policy * policy )
789825{
790826 int min_freq , max_freq , nominal_freq , lowest_nonlinear_freq , ret ;
@@ -958,6 +994,17 @@ static ssize_t show_amd_pstate_highest_perf(struct cpufreq_policy *policy,
958994 return sysfs_emit (buf , "%u\n" , perf );
959995}
960996
997+ static ssize_t show_amd_pstate_prefcore_ranking (struct cpufreq_policy * policy ,
998+ char * buf )
999+ {
1000+ u32 perf ;
1001+ struct amd_cpudata * cpudata = policy -> driver_data ;
1002+
1003+ perf = READ_ONCE (cpudata -> prefcore_ranking );
1004+
1005+ return sysfs_emit (buf , "%u\n" , perf );
1006+ }
1007+
9611008static ssize_t show_amd_pstate_hw_prefcore (struct cpufreq_policy * policy ,
9621009 char * buf )
9631010{
@@ -1176,6 +1223,7 @@ cpufreq_freq_attr_ro(amd_pstate_max_freq);
11761223cpufreq_freq_attr_ro (amd_pstate_lowest_nonlinear_freq );
11771224
11781225cpufreq_freq_attr_ro (amd_pstate_highest_perf );
1226+ cpufreq_freq_attr_ro (amd_pstate_prefcore_ranking );
11791227cpufreq_freq_attr_ro (amd_pstate_hw_prefcore );
11801228cpufreq_freq_attr_rw (energy_performance_preference );
11811229cpufreq_freq_attr_ro (energy_performance_available_preferences );
@@ -1186,6 +1234,7 @@ static struct freq_attr *amd_pstate_attr[] = {
11861234 & amd_pstate_max_freq ,
11871235 & amd_pstate_lowest_nonlinear_freq ,
11881236 & amd_pstate_highest_perf ,
1237+ & amd_pstate_prefcore_ranking ,
11891238 & amd_pstate_hw_prefcore ,
11901239 NULL ,
11911240};
@@ -1194,6 +1243,7 @@ static struct freq_attr *amd_pstate_epp_attr[] = {
11941243 & amd_pstate_max_freq ,
11951244 & amd_pstate_lowest_nonlinear_freq ,
11961245 & amd_pstate_highest_perf ,
1246+ & amd_pstate_prefcore_ranking ,
11971247 & amd_pstate_hw_prefcore ,
11981248 & energy_performance_preference ,
11991249 & energy_performance_available_preferences ,
@@ -1537,6 +1587,7 @@ static struct cpufreq_driver amd_pstate_driver = {
15371587 .suspend = amd_pstate_cpu_suspend ,
15381588 .resume = amd_pstate_cpu_resume ,
15391589 .set_boost = amd_pstate_set_boost ,
1590+ .update_limits = amd_pstate_update_limits ,
15401591 .name = "amd-pstate" ,
15411592 .attr = amd_pstate_attr ,
15421593};
@@ -1551,6 +1602,7 @@ static struct cpufreq_driver amd_pstate_epp_driver = {
15511602 .online = amd_pstate_epp_cpu_online ,
15521603 .suspend = amd_pstate_epp_suspend ,
15531604 .resume = amd_pstate_epp_resume ,
1605+ .update_limits = amd_pstate_update_limits ,
15541606 .name = "amd-pstate-epp" ,
15551607 .attr = amd_pstate_epp_attr ,
15561608};
0 commit comments