Skip to content

Commit 4654e9f

Browse files
wkarnyrafaeljw
authored andcommitted
amd-pstate: Fix amd_pstate mode switch
amd_pstate mode can be changed by writing the mode name to the `status` sysfs. But some combinations are not working. Fix this issue by taking care of the edge cases. Before the fix the mode change combination test fails: #./pst_test.sh Test passed: from: disable, to Test passed: from: disable, to disable Test failed: 1, From mode: disable, to mode: passive Test failed: 1, From mode: disable, to mode: active Test failed: 1, From mode: passive, to mode: active Test passed: from: passive, to disable Test failed: 1, From mode: passive, to mode: passive Test failed: 1, From mode: passive, to mode: active Test failed: 1, From mode: active, to mode: active Test passed: from: active, to disable Test failed: 1, From mode: active, to mode: passive Test failed: 1, From mode: active, to mode: active After the fix test passes: #./pst_test.sh Test passed: from: disable, to Test passed: from: disable, to disable Test passed: from: disable, to passive Test passed: from: disable, to active Test passed: from: passive, to active Test passed: from: passive, to disable Test passed: from: passive, to passive Test passed: from: passive, to active Test passed: from: active, to active Test passed: from: active, to disable Test passed: from: active, to passive Test passed: from: active, to active Fixes: abd61c0 ("cpufreq: amd-pstate: add driver working mode switch support") Acked-by: Huang Rui <[email protected]> Reviewed-by: Alexey Kardashevskiy <[email protected]> Signed-off-by: Wyes Karny <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 09a9639 commit 4654e9f

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

drivers/cpufreq/amd-pstate.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -840,33 +840,31 @@ static int amd_pstate_update_status(const char *buf, size_t size)
840840

841841
switch(mode_idx) {
842842
case AMD_PSTATE_DISABLE:
843-
if (!current_pstate_driver)
844-
return -EINVAL;
845-
if (cppc_state == AMD_PSTATE_ACTIVE)
846-
return -EBUSY;
847-
cpufreq_unregister_driver(current_pstate_driver);
848-
amd_pstate_driver_cleanup();
843+
if (current_pstate_driver) {
844+
cpufreq_unregister_driver(current_pstate_driver);
845+
amd_pstate_driver_cleanup();
846+
}
849847
break;
850848
case AMD_PSTATE_PASSIVE:
851849
if (current_pstate_driver) {
852850
if (current_pstate_driver == &amd_pstate_driver)
853851
return 0;
854852
cpufreq_unregister_driver(current_pstate_driver);
855-
cppc_state = AMD_PSTATE_PASSIVE;
856-
current_pstate_driver = &amd_pstate_driver;
857853
}
858854

855+
current_pstate_driver = &amd_pstate_driver;
856+
cppc_state = AMD_PSTATE_PASSIVE;
859857
ret = cpufreq_register_driver(current_pstate_driver);
860858
break;
861859
case AMD_PSTATE_ACTIVE:
862860
if (current_pstate_driver) {
863861
if (current_pstate_driver == &amd_pstate_epp_driver)
864862
return 0;
865863
cpufreq_unregister_driver(current_pstate_driver);
866-
current_pstate_driver = &amd_pstate_epp_driver;
867-
cppc_state = AMD_PSTATE_ACTIVE;
868864
}
869865

866+
current_pstate_driver = &amd_pstate_epp_driver;
867+
cppc_state = AMD_PSTATE_ACTIVE;
870868
ret = cpufreq_register_driver(current_pstate_driver);
871869
break;
872870
default:

0 commit comments

Comments
 (0)