Skip to content

Commit 95fad7f

Browse files
committed
cpufreq/amd-pstate: Drop boost_state variable
Currently boost_state is cached for every processor in cpudata structure and driver boost state is set for every processor. Both of these aren't necessary as the driver only needs to set once and the policy stores whether boost is enabled. Move the driver boost setting to registration and adjust all references to cached value to pull from the policy instead. Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com> Link: https://lore.kernel.org/r/20241209185248.16301-16-mario.limonciello@amd.com Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
1 parent f9a378f commit 95fad7f

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

drivers/cpufreq/amd-pstate.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,10 @@ static int shmem_set_epp(struct amd_cpudata *cpudata, u32 epp)
316316
return ret;
317317
}
318318

319-
static int amd_pstate_set_energy_pref_index(struct amd_cpudata *cpudata,
320-
int pref_index)
319+
static int amd_pstate_set_energy_pref_index(struct cpufreq_policy *policy,
320+
int pref_index)
321321
{
322+
struct amd_cpudata *cpudata = policy->driver_data;
322323
int epp;
323324

324325
if (!pref_index)
@@ -336,7 +337,7 @@ static int amd_pstate_set_energy_pref_index(struct amd_cpudata *cpudata,
336337
epp,
337338
FIELD_GET(AMD_CPPC_MIN_PERF_MASK, cpudata->cppc_req_cached),
338339
FIELD_GET(AMD_CPPC_MAX_PERF_MASK, cpudata->cppc_req_cached),
339-
cpudata->boost_state);
340+
policy->boost_enabled);
340341
}
341342

342343
return amd_pstate_set_epp(cpudata, epp);
@@ -746,7 +747,6 @@ static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state)
746747
guard(mutex)(&amd_pstate_driver_lock);
747748

748749
ret = amd_pstate_cpu_boost_update(policy, state);
749-
WRITE_ONCE(cpudata->boost_state, !ret ? state : false);
750750
policy->boost_enabled = !ret ? state : false;
751751
refresh_frequency_limits(policy);
752752

@@ -768,9 +768,6 @@ static int amd_pstate_init_boost_support(struct amd_cpudata *cpudata)
768768
goto exit_err;
769769
}
770770

771-
/* at least one CPU supports CPB, even if others fail later on to set up */
772-
current_pstate_driver->boost_enabled = true;
773-
774771
ret = rdmsrl_on_cpu(cpudata->cpu, MSR_K7_HWCR, &boost_val);
775772
if (ret) {
776773
pr_err_once("failed to read initial CPU boost state!\n");
@@ -1176,7 +1173,6 @@ static ssize_t show_energy_performance_available_preferences(
11761173
static ssize_t store_energy_performance_preference(
11771174
struct cpufreq_policy *policy, const char *buf, size_t count)
11781175
{
1179-
struct amd_cpudata *cpudata = policy->driver_data;
11801176
char str_preference[21];
11811177
ssize_t ret;
11821178

@@ -1190,7 +1186,7 @@ static ssize_t store_energy_performance_preference(
11901186

11911187
guard(mutex)(&amd_pstate_limits_lock);
11921188

1193-
ret = amd_pstate_set_energy_pref_index(cpudata, ret);
1189+
ret = amd_pstate_set_energy_pref_index(policy, ret);
11941190

11951191
return ret ? ret : count;
11961192
}
@@ -1265,6 +1261,9 @@ static int amd_pstate_register_driver(int mode)
12651261
return ret;
12661262
}
12671263

1264+
/* at least one CPU supports CPB */
1265+
current_pstate_driver->boost_enabled = cpu_feature_enabled(X86_FEATURE_CPB);
1266+
12681267
ret = cpufreq_register_driver(current_pstate_driver);
12691268
if (ret) {
12701269
amd_pstate_driver_cleanup();
@@ -1604,8 +1603,9 @@ static int amd_pstate_epp_set_policy(struct cpufreq_policy *policy)
16041603
return 0;
16051604
}
16061605

1607-
static int amd_pstate_epp_reenable(struct amd_cpudata *cpudata)
1606+
static int amd_pstate_epp_reenable(struct cpufreq_policy *policy)
16081607
{
1608+
struct amd_cpudata *cpudata = policy->driver_data;
16091609
u64 max_perf;
16101610
int ret;
16111611

@@ -1619,7 +1619,7 @@ static int amd_pstate_epp_reenable(struct amd_cpudata *cpudata)
16191619
trace_amd_pstate_epp_perf(cpudata->cpu, cpudata->highest_perf,
16201620
cpudata->epp_cached,
16211621
FIELD_GET(AMD_CPPC_MIN_PERF_MASK, cpudata->cppc_req_cached),
1622-
max_perf, cpudata->boost_state);
1622+
max_perf, policy->boost_enabled);
16231623
}
16241624

16251625
return amd_pstate_update_perf(cpudata, 0, 0, max_perf, cpudata->epp_cached, false);
@@ -1632,7 +1632,7 @@ static int amd_pstate_epp_cpu_online(struct cpufreq_policy *policy)
16321632

16331633
pr_debug("AMD CPU Core %d going online\n", cpudata->cpu);
16341634

1635-
ret = amd_pstate_epp_reenable(cpudata);
1635+
ret = amd_pstate_epp_reenable(policy);
16361636
if (ret)
16371637
return ret;
16381638
cpudata->suspended = false;
@@ -1690,7 +1690,7 @@ static int amd_pstate_epp_resume(struct cpufreq_policy *policy)
16901690
guard(mutex)(&amd_pstate_limits_lock);
16911691

16921692
/* enable amd pstate from suspend state*/
1693-
amd_pstate_epp_reenable(cpudata);
1693+
amd_pstate_epp_reenable(policy);
16941694

16951695
cpudata->suspended = false;
16961696
}

drivers/cpufreq/amd-pstate.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ struct amd_cpudata {
9898
u64 cppc_cap1_cached;
9999
bool suspended;
100100
s16 epp_default;
101-
bool boost_state;
102101
};
103102

104103
/*

0 commit comments

Comments
 (0)