Skip to content

Commit c88ad30

Browse files
superm1rafaeljw
authored andcommitted
cpufreq: amd-pstate: Add a kernel config option to set default mode
Users are having more success with amd-pstate since the introduction of EPP and Guided modes. To expose the driver to more users by default introduce a kernel configuration option for setting the default mode. Users can use an integer to map out which default mode they want to use in lieu of a kernel command line option. This will default to EPP, but only if: 1) The CPU supports an MSR. 2) The system profile is identified 3) The system profile is identified as a non-server by the FADT. Link: https://gitlab.freedesktop.org/hadess/power-profiles-daemon/-/merge_requests/121 Acked-by: Huang Rui <[email protected]> Reviewed-by: Gautham R. Shenoy <[email protected]> Co-developed-by: Perry Yuan <[email protected]> Signed-off-by: Perry Yuan <[email protected]> Signed-off-by: Mario Limonciello <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 32f80b9 commit c88ad30

File tree

3 files changed

+68
-26
lines changed

3 files changed

+68
-26
lines changed

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: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
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;
6666
static bool cppc_enabled;
6767

6868
/*
@@ -1410,22 +1410,32 @@ static struct cpufreq_driver amd_pstate_epp_driver = {
14101410
.attr = amd_pstate_epp_attr,
14111411
};
14121412

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+
14131432
static int __init amd_pstate_init(void)
14141433
{
14151434
struct device *dev_root;
14161435
int ret;
14171436

14181437
if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
14191438
return -ENODEV;
1420-
/*
1421-
* by default the pstate driver is disabled to load
1422-
* enable the amd_pstate passive mode driver explicitly
1423-
* with amd_pstate=passive or other modes in kernel command line
1424-
*/
1425-
if (cppc_state == AMD_PSTATE_DISABLE) {
1426-
pr_info("driver load is disabled, boot with specific mode to enable this\n");
1427-
return -ENODEV;
1428-
}
14291439

14301440
if (!acpi_cpc_valid()) {
14311441
pr_warn_once("the _CPC object is not present in SBIOS or ACPI disabled\n");
@@ -1436,6 +1446,33 @@ static int __init amd_pstate_init(void)
14361446
if (cpufreq_get_current_driver())
14371447
return -EEXIST;
14381448

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+
14391476
/* capability check */
14401477
if (boot_cpu_has(X86_FEATURE_CPPC)) {
14411478
pr_debug("AMD CPPC MSR based functionality is supported\n");
@@ -1488,21 +1525,7 @@ static int __init amd_pstate_param(char *str)
14881525
size = strlen(str);
14891526
mode_idx = get_mode_idx_from_str(str, size);
14901527

1491-
if (mode_idx >= AMD_PSTATE_DISABLE && mode_idx < AMD_PSTATE_MAX) {
1492-
cppc_state = mode_idx;
1493-
if (cppc_state == AMD_PSTATE_DISABLE)
1494-
pr_info("driver is explicitly disabled\n");
1495-
1496-
if (cppc_state == AMD_PSTATE_ACTIVE)
1497-
current_pstate_driver = &amd_pstate_epp_driver;
1498-
1499-
if (cppc_state == AMD_PSTATE_PASSIVE || cppc_state == AMD_PSTATE_GUIDED)
1500-
current_pstate_driver = &amd_pstate_driver;
1501-
1502-
return 0;
1503-
}
1504-
1505-
return -EINVAL;
1528+
return amd_pstate_set_driver(mode_idx);
15061529
}
15071530
early_param("amd_pstate", amd_pstate_param);
15081531

include/linux/amd-pstate.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,16 @@ struct amd_cpudata {
9494
* enum amd_pstate_mode - driver working mode of amd pstate
9595
*/
9696
enum amd_pstate_mode {
97-
AMD_PSTATE_DISABLE = 0,
97+
AMD_PSTATE_UNDEFINED = 0,
98+
AMD_PSTATE_DISABLE,
9899
AMD_PSTATE_PASSIVE,
99100
AMD_PSTATE_ACTIVE,
100101
AMD_PSTATE_GUIDED,
101102
AMD_PSTATE_MAX,
102103
};
103104

104105
static const char * const amd_pstate_mode_string[] = {
106+
[AMD_PSTATE_UNDEFINED] = "undefined",
105107
[AMD_PSTATE_DISABLE] = "disable",
106108
[AMD_PSTATE_PASSIVE] = "passive",
107109
[AMD_PSTATE_ACTIVE] = "active",

0 commit comments

Comments
 (0)