Skip to content

Commit 36c5014

Browse files
wkarnyrafaeljw
authored andcommitted
cpufreq: amd-pstate: optimize driver working mode selection in amd_pstate_param()
The amd-pstate driver may support multiple working modes. Introduce a variable to keep track of which mode is currently enabled. Here we use cppc_state var to indicate which mode is enabled. This change will help to simplify the the amd_pstate_param() to choose which mode used for the following driver registration. Acked-by: Huang Rui <ray.huang@amd.com> Reviewed-by: Mario Limonciello <mario.limonciello@amd.com> Tested-by: Wyes Karny <wyes.karny@amd.com> Signed-off-by: Perry Yuan <perry.yuan@amd.com> Signed-off-by: Wyes Karny <wyes.karny@amd.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent e22abc6 commit 36c5014

2 files changed

Lines changed: 46 additions & 10 deletions

File tree

drivers/cpufreq/amd-pstate.c

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,18 @@
6060
* module parameter to be able to enable it manually for debugging.
6161
*/
6262
static struct cpufreq_driver amd_pstate_driver;
63-
static int cppc_load __initdata;
63+
static int cppc_state = AMD_PSTATE_DISABLE;
64+
65+
static inline int get_mode_idx_from_str(const char *str, size_t size)
66+
{
67+
int i;
68+
69+
for (i=0; i < AMD_PSTATE_MAX; i++) {
70+
if (!strncmp(str, amd_pstate_mode_string[i], size))
71+
return i;
72+
}
73+
return -EINVAL;
74+
}
6475

6576
static inline int pstate_enable(bool enable)
6677
{
@@ -626,10 +637,10 @@ static int __init amd_pstate_init(void)
626637
/*
627638
* by default the pstate driver is disabled to load
628639
* enable the amd_pstate passive mode driver explicitly
629-
* with amd_pstate=passive in kernel command line
640+
* with amd_pstate=passive or other modes in kernel command line
630641
*/
631-
if (!cppc_load) {
632-
pr_debug("driver load is disabled, boot with amd_pstate=passive to enable this\n");
642+
if (cppc_state == AMD_PSTATE_DISABLE) {
643+
pr_debug("driver load is disabled, boot with specific mode to enable this\n");
633644
return -ENODEV;
634645
}
635646

@@ -671,16 +682,24 @@ device_initcall(amd_pstate_init);
671682

672683
static int __init amd_pstate_param(char *str)
673684
{
685+
size_t size;
686+
int mode_idx;
687+
674688
if (!str)
675689
return -EINVAL;
676690

677-
if (!strcmp(str, "disable")) {
678-
cppc_load = 0;
679-
pr_info("driver is explicitly disabled\n");
680-
} else if (!strcmp(str, "passive"))
681-
cppc_load = 1;
691+
size = strlen(str);
692+
mode_idx = get_mode_idx_from_str(str, size);
682693

683-
return 0;
694+
if (mode_idx >= AMD_PSTATE_DISABLE && mode_idx < AMD_PSTATE_MAX) {
695+
cppc_state = mode_idx;
696+
if (cppc_state == AMD_PSTATE_DISABLE)
697+
pr_info("driver is explicitly disabled\n");
698+
699+
return 0;
700+
}
701+
702+
return -EINVAL;
684703
}
685704
early_param("amd_pstate", amd_pstate_param);
686705

include/linux/amd-pstate.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,21 @@ struct amd_cpudata {
7474
bool boost_supported;
7575
};
7676

77+
/*
78+
* enum amd_pstate_mode - driver working mode of amd pstate
79+
*/
80+
enum amd_pstate_mode {
81+
AMD_PSTATE_DISABLE = 0,
82+
AMD_PSTATE_PASSIVE,
83+
AMD_PSTATE_ACTIVE,
84+
AMD_PSTATE_MAX,
85+
};
86+
87+
static const char * const amd_pstate_mode_string[] = {
88+
[AMD_PSTATE_DISABLE] = "disable",
89+
[AMD_PSTATE_PASSIVE] = "passive",
90+
[AMD_PSTATE_ACTIVE] = "active",
91+
NULL,
92+
};
93+
7794
#endif /* _LINUX_AMD_PSTATE_H */

0 commit comments

Comments
 (0)