Skip to content

Commit d87e402

Browse files
kudureranganathsuperm1
authored andcommitted
cpufreq/amd-pstate: Enable ITMT support after initializing core rankings
When working on dynamic ITMT priority support, it was observed that "asym_prefer_cpu" on AMD systems supporting Preferred Core ranking was always set to the first CPU in the sched group when the system boots up despite another CPU in the group having a higher ITMT ranking. "asym_prefer_cpu" is cached when the sched domain hierarchy is constructed. On AMD systems that support Preferred Core rankings, sched domains are rebuilt when ITMT support is enabled for the first time from amd_pstate*_cpu_init(). Since amd_pstate*_cpu_init() is called to initialize the cpudata for each CPU, the ITMT support is enabled after the first CPU initializes its asym priority but this is too early since other CPUs have not yet initialized their asym priorities and the sched domain is rebuilt only once when the support is toggled on for the first time. Initialize the asym priorities first in amd_pstate*_cpu_init() and then enable ITMT support later in amd_pstate_register_driver() to ensure all CPUs have correctly initialized their asym priorities before sched domain hierarchy is rebuilt. Clear the ITMT support when the amd-pstate driver unregisters since core rankings cannot be trusted unless the update_limits() callback is operational. Remove the delayed work mechanism now that ITMT support is only toggled from the driver init path which is outside the cpuhp critical section. Fixes: f3a0523 ("cpufreq: amd-pstate: Enable amd-pstate preferred core support") Signed-off-by: K Prateek Nayak <kprateek.nayak@amd.com> Reviewed-by: Mario Limonciello <mario.limonciello@amd.com> Link: https://lore.kernel.org/r/20250411081439.27652-1-kprateek.nayak@amd.com Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
1 parent 56a49e1 commit d87e402

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

drivers/cpufreq/amd-pstate.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -794,16 +794,6 @@ static void amd_perf_ctl_reset(unsigned int cpu)
794794
wrmsrl_on_cpu(cpu, MSR_AMD_PERF_CTL, 0);
795795
}
796796

797-
/*
798-
* Set amd-pstate preferred core enable can't be done directly from cpufreq callbacks
799-
* due to locking, so queue the work for later.
800-
*/
801-
static void amd_pstste_sched_prefcore_workfn(struct work_struct *work)
802-
{
803-
sched_set_itmt_support();
804-
}
805-
static DECLARE_WORK(sched_prefcore_work, amd_pstste_sched_prefcore_workfn);
806-
807797
#define CPPC_MAX_PERF U8_MAX
808798

809799
static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata)
@@ -814,14 +804,8 @@ static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata)
814804

815805
cpudata->hw_prefcore = true;
816806

817-
/*
818-
* The priorities can be set regardless of whether or not
819-
* sched_set_itmt_support(true) has been called and it is valid to
820-
* update them at any time after it has been called.
821-
*/
807+
/* Priorities must be initialized before ITMT support can be toggled on. */
822808
sched_set_itmt_core_prio((int)READ_ONCE(cpudata->prefcore_ranking), cpudata->cpu);
823-
824-
schedule_work(&sched_prefcore_work);
825809
}
826810

827811
static void amd_pstate_update_limits(unsigned int cpu)
@@ -1196,6 +1180,9 @@ static ssize_t show_energy_performance_preference(
11961180

11971181
static void amd_pstate_driver_cleanup(void)
11981182
{
1183+
if (amd_pstate_prefcore)
1184+
sched_clear_itmt_support();
1185+
11991186
cppc_state = AMD_PSTATE_DISABLE;
12001187
current_pstate_driver = NULL;
12011188
}
@@ -1238,6 +1225,10 @@ static int amd_pstate_register_driver(int mode)
12381225
return ret;
12391226
}
12401227

1228+
/* Enable ITMT support once all CPUs have initialized their asym priorities. */
1229+
if (amd_pstate_prefcore)
1230+
sched_set_itmt_support();
1231+
12411232
return 0;
12421233
}
12431234

0 commit comments

Comments
 (0)