Skip to content

Commit 4af191d

Browse files
committed
Merge branches 'pm-cpufreq' and 'pm-cpuidle'
Merge cpufreq and cpuidle updates for 6.5-rc1: - Prevent cpufreq drivers that provide the ->adjust_perf() callback without a ->fast_switch() one which is used as a fallback from the former in some cases (Wyes Karny). - Fix some issues related to the AMD P-state cpufreq driver (Mario Limonciello, Wyes Karny). - Fix the energy_performance_preference attribute handling in the intel_pstate driver in passive mode (Tero Kristo). - Clean up the intel_idle driver, make it work with VM guests that cannot use the MWAIT instruction and address the case in which the host may enter a deep idle state when the guest is idle (Arjan van de Ven). * pm-cpufreq: cpufreq: intel_pstate: Fix energy_performance_preference for passive cpufreq: amd-pstate: Add a kernel config option to set default mode cpufreq: amd-pstate: Set a fallback policy based on preferred_profile ACPI: CPPC: Add definition for undefined FADT preferred PM profile value cpufreq: amd-pstate: Set default governor to schedutil cpufreq: amd-pstate: Make amd-pstate EPP driver name hyphenated cpufreq: amd-pstate: Write CPPC enable bit per-socket cpufreq: Fail driver register if it has adjust_perf without fast_switch * pm-cpuidle: intel_idle: Add a "Long HLT" C1 state for the VM guest mode intel_idle: Add support for using intel_idle in a VM guest using just hlt intel_idle: clean up the (new) state_update_enter_method function intel_idle: refactor state->enter manipulation into its own function
3 parents 5d83a2b + 03f44ff + 0fac214 commit 4af191d

File tree

9 files changed

+341
-57
lines changed

9 files changed

+341
-57
lines changed

drivers/cpufreq/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ choice
3838
prompt "Default CPUFreq governor"
3939
default CPU_FREQ_DEFAULT_GOV_USERSPACE if ARM_SA1110_CPUFREQ
4040
default CPU_FREQ_DEFAULT_GOV_SCHEDUTIL if ARM64 || ARM
41-
default CPU_FREQ_DEFAULT_GOV_SCHEDUTIL if X86_INTEL_PSTATE && SMP
41+
default CPU_FREQ_DEFAULT_GOV_SCHEDUTIL if (X86_INTEL_PSTATE || X86_AMD_PSTATE) && SMP
4242
default CPU_FREQ_DEFAULT_GOV_PERFORMANCE
4343
help
4444
This option sets which CPUFreq governor shall be loaded at

drivers/cpufreq/Kconfig.x86

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,23 @@ config X86_AMD_PSTATE
5151

5252
If in doubt, say N.
5353

54+
config X86_AMD_PSTATE_DEFAULT_MODE
55+
int "AMD Processor P-State default mode"
56+
depends on X86_AMD_PSTATE
57+
default 3 if X86_AMD_PSTATE
58+
range 1 4
59+
help
60+
Select the default mode the amd-pstate driver will use on
61+
supported hardware.
62+
The value set has the following meanings:
63+
1 -> Disabled
64+
2 -> Passive
65+
3 -> Active (EPP)
66+
4 -> Guided
67+
68+
For details, take a look at:
69+
<file:Documentation/admin-guide/pm/amd-pstate.rst>.
70+
5471
config X86_AMD_PSTATE_UT
5572
tristate "selftest for AMD Processor P-State driver"
5673
depends on X86 && ACPI_PROCESSOR

drivers/cpufreq/amd-pstate.c

Lines changed: 102 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
static struct cpufreq_driver *current_pstate_driver;
6363
static struct cpufreq_driver amd_pstate_driver;
6464
static struct cpufreq_driver amd_pstate_epp_driver;
65-
static int cppc_state = AMD_PSTATE_DISABLE;
65+
static int cppc_state = AMD_PSTATE_UNDEFINED;
66+
static bool cppc_enabled;
6667

6768
/*
6869
* AMD Energy Preference Performance (EPP)
@@ -228,14 +229,38 @@ static int amd_pstate_set_energy_pref_index(struct amd_cpudata *cpudata,
228229

229230
static inline int pstate_enable(bool enable)
230231
{
231-
return wrmsrl_safe(MSR_AMD_CPPC_ENABLE, enable);
232+
int ret, cpu;
233+
unsigned long logical_proc_id_mask = 0;
234+
235+
if (enable == cppc_enabled)
236+
return 0;
237+
238+
for_each_present_cpu(cpu) {
239+
unsigned long logical_id = topology_logical_die_id(cpu);
240+
241+
if (test_bit(logical_id, &logical_proc_id_mask))
242+
continue;
243+
244+
set_bit(logical_id, &logical_proc_id_mask);
245+
246+
ret = wrmsrl_safe_on_cpu(cpu, MSR_AMD_CPPC_ENABLE,
247+
enable);
248+
if (ret)
249+
return ret;
250+
}
251+
252+
cppc_enabled = enable;
253+
return 0;
232254
}
233255

234256
static int cppc_enable(bool enable)
235257
{
236258
int cpu, ret = 0;
237259
struct cppc_perf_ctrls perf_ctrls;
238260

261+
if (enable == cppc_enabled)
262+
return 0;
263+
239264
for_each_present_cpu(cpu) {
240265
ret = cppc_set_enable(cpu, enable);
241266
if (ret)
@@ -251,6 +276,7 @@ static int cppc_enable(bool enable)
251276
}
252277
}
253278

279+
cppc_enabled = enable;
254280
return ret;
255281
}
256282

@@ -1045,6 +1071,26 @@ static const struct attribute_group amd_pstate_global_attr_group = {
10451071
.attrs = pstate_global_attributes,
10461072
};
10471073

1074+
static bool amd_pstate_acpi_pm_profile_server(void)
1075+
{
1076+
switch (acpi_gbl_FADT.preferred_profile) {
1077+
case PM_ENTERPRISE_SERVER:
1078+
case PM_SOHO_SERVER:
1079+
case PM_PERFORMANCE_SERVER:
1080+
return true;
1081+
}
1082+
return false;
1083+
}
1084+
1085+
static bool amd_pstate_acpi_pm_profile_undefined(void)
1086+
{
1087+
if (acpi_gbl_FADT.preferred_profile == PM_UNSPECIFIED)
1088+
return true;
1089+
if (acpi_gbl_FADT.preferred_profile >= NR_PM_PROFILES)
1090+
return true;
1091+
return false;
1092+
}
1093+
10481094
static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
10491095
{
10501096
int min_freq, max_freq, nominal_freq, lowest_nonlinear_freq, ret;
@@ -1102,10 +1148,14 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
11021148
policy->max = policy->cpuinfo.max_freq;
11031149

11041150
/*
1105-
* Set the policy to powersave to provide a valid fallback value in case
1151+
* Set the policy to provide a valid fallback value in case
11061152
* the default cpufreq governor is neither powersave nor performance.
11071153
*/
1108-
policy->policy = CPUFREQ_POLICY_POWERSAVE;
1154+
if (amd_pstate_acpi_pm_profile_server() ||
1155+
amd_pstate_acpi_pm_profile_undefined())
1156+
policy->policy = CPUFREQ_POLICY_PERFORMANCE;
1157+
else
1158+
policy->policy = CPUFREQ_POLICY_POWERSAVE;
11091159

11101160
if (boot_cpu_has(X86_FEATURE_CPPC)) {
11111161
ret = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, &value);
@@ -1356,26 +1406,36 @@ static struct cpufreq_driver amd_pstate_epp_driver = {
13561406
.online = amd_pstate_epp_cpu_online,
13571407
.suspend = amd_pstate_epp_suspend,
13581408
.resume = amd_pstate_epp_resume,
1359-
.name = "amd_pstate_epp",
1409+
.name = "amd-pstate-epp",
13601410
.attr = amd_pstate_epp_attr,
13611411
};
13621412

1413+
static int __init amd_pstate_set_driver(int mode_idx)
1414+
{
1415+
if (mode_idx >= AMD_PSTATE_DISABLE && mode_idx < AMD_PSTATE_MAX) {
1416+
cppc_state = mode_idx;
1417+
if (cppc_state == AMD_PSTATE_DISABLE)
1418+
pr_info("driver is explicitly disabled\n");
1419+
1420+
if (cppc_state == AMD_PSTATE_ACTIVE)
1421+
current_pstate_driver = &amd_pstate_epp_driver;
1422+
1423+
if (cppc_state == AMD_PSTATE_PASSIVE || cppc_state == AMD_PSTATE_GUIDED)
1424+
current_pstate_driver = &amd_pstate_driver;
1425+
1426+
return 0;
1427+
}
1428+
1429+
return -EINVAL;
1430+
}
1431+
13631432
static int __init amd_pstate_init(void)
13641433
{
13651434
struct device *dev_root;
13661435
int ret;
13671436

13681437
if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
13691438
return -ENODEV;
1370-
/*
1371-
* by default the pstate driver is disabled to load
1372-
* enable the amd_pstate passive mode driver explicitly
1373-
* with amd_pstate=passive or other modes in kernel command line
1374-
*/
1375-
if (cppc_state == AMD_PSTATE_DISABLE) {
1376-
pr_info("driver load is disabled, boot with specific mode to enable this\n");
1377-
return -ENODEV;
1378-
}
13791439

13801440
if (!acpi_cpc_valid()) {
13811441
pr_warn_once("the _CPC object is not present in SBIOS or ACPI disabled\n");
@@ -1386,6 +1446,33 @@ static int __init amd_pstate_init(void)
13861446
if (cpufreq_get_current_driver())
13871447
return -EEXIST;
13881448

1449+
switch (cppc_state) {
1450+
case AMD_PSTATE_UNDEFINED:
1451+
/* Disable on the following configs by default:
1452+
* 1. Undefined platforms
1453+
* 2. Server platforms
1454+
* 3. Shared memory designs
1455+
*/
1456+
if (amd_pstate_acpi_pm_profile_undefined() ||
1457+
amd_pstate_acpi_pm_profile_server() ||
1458+
!boot_cpu_has(X86_FEATURE_CPPC)) {
1459+
pr_info("driver load is disabled, boot with specific mode to enable this\n");
1460+
return -ENODEV;
1461+
}
1462+
ret = amd_pstate_set_driver(CONFIG_X86_AMD_PSTATE_DEFAULT_MODE);
1463+
if (ret)
1464+
return ret;
1465+
break;
1466+
case AMD_PSTATE_DISABLE:
1467+
return -ENODEV;
1468+
case AMD_PSTATE_PASSIVE:
1469+
case AMD_PSTATE_ACTIVE:
1470+
case AMD_PSTATE_GUIDED:
1471+
break;
1472+
default:
1473+
return -EINVAL;
1474+
}
1475+
13891476
/* capability check */
13901477
if (boot_cpu_has(X86_FEATURE_CPPC)) {
13911478
pr_debug("AMD CPPC MSR based functionality is supported\n");
@@ -1438,21 +1525,7 @@ static int __init amd_pstate_param(char *str)
14381525
size = strlen(str);
14391526
mode_idx = get_mode_idx_from_str(str, size);
14401527

1441-
if (mode_idx >= AMD_PSTATE_DISABLE && mode_idx < AMD_PSTATE_MAX) {
1442-
cppc_state = mode_idx;
1443-
if (cppc_state == AMD_PSTATE_DISABLE)
1444-
pr_info("driver is explicitly disabled\n");
1445-
1446-
if (cppc_state == AMD_PSTATE_ACTIVE)
1447-
current_pstate_driver = &amd_pstate_epp_driver;
1448-
1449-
if (cppc_state == AMD_PSTATE_PASSIVE || cppc_state == AMD_PSTATE_GUIDED)
1450-
current_pstate_driver = &amd_pstate_driver;
1451-
1452-
return 0;
1453-
}
1454-
1455-
return -EINVAL;
1528+
return amd_pstate_set_driver(mode_idx);
14561529
}
14571530
early_param("amd_pstate", amd_pstate_param);
14581531

drivers/cpufreq/cpufreq.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2828,7 +2828,8 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
28282828
(driver_data->setpolicy && (driver_data->target_index ||
28292829
driver_data->target)) ||
28302830
(!driver_data->get_intermediate != !driver_data->target_intermediate) ||
2831-
(!driver_data->online != !driver_data->offline))
2831+
(!driver_data->online != !driver_data->offline) ||
2832+
(driver_data->adjust_perf && !driver_data->fast_switch))
28322833
return -EINVAL;
28332834

28342835
pr_debug("trying to register driver %s\n", driver_data->name);

drivers/cpufreq/intel_pstate.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,8 @@ static ssize_t store_energy_performance_preference(
824824
err = cpufreq_start_governor(policy);
825825
if (!ret)
826826
ret = err;
827+
} else {
828+
ret = 0;
827829
}
828830
}
829831

0 commit comments

Comments
 (0)