cpufreq/amd-pstate: Do not fail init when auto_sel cannot be written
Subsystems (3)
PATCH 1/1 cpufreq/amd-pstate: Do not fail init when auto_sel cannot be written
Since commit 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems"), shmem_init_perf() programs AUTONOMOUS_SELECTION_ENABLE unconditionally, including in active mode.
On platforms implementing CPPC v2 and below, _CPC reports Autonomous Selection Enable as a plain integer rather than as a register descriptor. Such a field is a read-only capability flag: cppc_get_reg_val() reads it back successfully (the firmware reports it as enabled), while cppc_set_reg_val() rejects the write with -EOPNOTSUPP because the entry is not an ACPI_TYPE_BUFFER.
shmem_init_perf() propagates that error, so every amd_pstate_epp_cpu_init() fails, cpufreq_register_driver() ends up with an empty policy list and returns -ENODEV, and amd-pstate refuses to load at all:
amd_pstate: failed to set auto_sel, ret: -95
amd_pstate: Failed to initialize CPU 0: -95
...
amd_pstate: failed to register with return -19
Failing to write auto_sel is not fatal: the register is either already enabled, as reported by the cppc_get_auto_sel() call right above, or not writable at all, and active mode worked in both cases before the offending commit. Downgrade the failure to a warning and let initialization continue, matching how the cppc_get_auto_sel() failure is handled.
--- drivers/cpufreq/amd-pstate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/amd-pstate.c +1 -1
@@ -538,5 +538,5 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)if (ret)pr_warn ("failed to set auto_sel, ret: %d\n" , ret); -return ret; +return 0 ; }
K Prateek Nayak
reviewerHello Wentao,
Quoted 10 lines · Wentao Guan
Since commit
9dfd13f80c85("cpufreq/amd-pstate: Toggleauto_selin active mode on shared memory systems"),shmem_init_perf()programsAUTONOMOUS_SELECTION_ENABLEunconditionally, including in active mode.On platforms implementing CPPC v2 and below,
_CPCreports Autonomous Selection Enable as a plain integer rather than as a register descriptor. Such a field is a read-only capability flag:cppc_get_reg_val()reads it back successfully (the firmware reports it as enabled), whilecppc_set_reg_val()rejects the write with-EOPNOTSUPPbecause the entry is not anACPI_TYPE_BUFFER.
Ah! So it is one of those platforms that fall into:
Platforms that exclusively support Autonomous Selection must populate this field as an Integer with a value of 1.
as per the ACPI spec.
Quoted 10 lines
shmem_init_perf()propagates that error, so everyamd_pstate_epp_cpu_init()fails,cpufreq_register_driver()ends up with an empty policy list and returns-ENODEV, and amd-pstate refuses to load at all:
amd_pstate: failed to setauto_sel, ret: -95
amd_pstate: Failed to initialize CPU 0: -95
...
amd_pstate: failed to register with return -19
Quoted 5 lines
Failing to write
auto_selis not fatal: the register is either already enabled, as reported by thecppc_get_auto_sel()call right above, or not writable at all, and active mode worked in both cases before the offending commit. Downgrade the failure to a warning and let initialization continue, matching how thecppc_get_auto_sel()failure is handled.
Can't we just skip cppc_set_auto_sel() if the auto_sel is already at the desired value? Something like:
(Completely untested)
drivers/cpufreq/amd-pstate.c +3 -0
@@ -524,6 +524,9 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)return 0 ; } +if ((cppc_state !=AMD_PSTATE_PASSIVE ) == auto_sel) +return 0 ; + ret =cppc_set_auto_sel (cpudata->cpu, (cppc_state ==AMD_PSTATE_PASSIVE ) ?0 :1 );
---
That way we fail for passive mode switch which will operate under incorrectly assumptions since these platform only supports autonomous modes.
Thoughts?
Quoted 20 lines
Fixes 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems")Tested-by LFRon <[email protected]>Signed-off-by Wentao Guan <[email protected]>--- drivers/cpufreq/amd-pstate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/cpufreq/amd-pstate.c +1
-1@@ -538,5 +538,5 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)if (ret)pr_warn ("failed to set auto_sel, ret: %d\n" , ret); -return ret; +return 0 ; }
Signature · 2 lines
Thanks and Regards, Prateek
Hi,
Quoted 56 lines · Wentao Guan
Quoted 10 lines
Since commit
9dfd13f80c85("cpufreq/amd-pstate: Toggleauto_selin active mode on shared memory systems"),shmem_init_perf()programsAUTONOMOUS_SELECTION_ENABLEunconditionally, including in active mode.On platforms implementing CPPC v2 and below,
_CPCreports Autonomous Selection Enable as a plain integer rather than as a register descriptor. Such a field is a read-only capability flag:cppc_get_reg_val()reads it back successfully (the firmware reports it as enabled), whilecppc_set_reg_val()rejects the write with-EOPNOTSUPPbecause the entry is not anACPI_TYPE_BUFFER.Ah! So it is one of those platforms that fall into:
Platforms that exclusively support Autonomous Selection must populate this field as an Integer with a value of 1.
as per the ACPI spec.
Quoted 10 lines
shmem_init_perf()propagates that error, so everyamd_pstate_epp_cpu_init()fails,cpufreq_register_driver()ends up with an empty policy list and returns-ENODEV, and amd-pstate refuses to load at all:
amd_pstate: failed to setauto_sel, ret: -95
amd_pstate: Failed to initialize CPU 0: -95
...
amd_pstate: failed to register with return -19Quoted 5 lines
Failing to write
auto_selis not fatal: the register is either already enabled, as reported by thecppc_get_auto_sel()call right above, or not writable at all, and active mode worked in both cases before the offending commit. Downgrade the failure to a warning and let initialization continue, matching how thecppc_get_auto_sel()failure is handled.Can't we just skip
cppc_set_auto_sel()if theauto_selis already at the desired value? Something like:(Completely untested)
drivers/cpufreq/amd-pstate.c +3
-1@@ -524,6 +524,9 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)return 0 ; } +if ((cppc_state !=AMD_PSTATE_PASSIVE ) == auto_sel) +return 0 ; + ret =cppc_set_auto_sel (cpudata->cpu, (cppc_state ==AMD_PSTATE_PASSIVE ) ?0 :1 ); ---
Quoted 5 lines
That way we fail for passive mode switch which will operate under incorrectly assumptions since these platform only supports autonomous modes.
Thoughts?
Thanks for your review, full agree with your suggested patch. I will send v2 after be tested later.
BRs
Wentao Guan
PATCH v2 1/1 cpufreq/amd-pstate: Skip auto_sel write when it already matches the mode
In reply to K Prateek NayakSince commit 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems"), shmem_init_perf() programs AUTONOMOUS_SELECTION_ENABLE unconditionally, including in active mode.
Platforms that exclusively support autonomous selection report this field as an Integer of 1, as required by the ACPI specification, instead of as a register descriptor. cppc_get_reg_val() reads such a field back successfully, but cppc_set_reg_val() rejects the write with -EOPNOTSUPP because the entry is not an ACPI_TYPE_BUFFER.
shmem_init_perf() propagates that error, so every amd_pstate_epp_cpu_init() fails, cpufreq_register_driver() ends up with an empty policy list and returns -ENODEV, and amd-pstate refuses to load at all:
amd_pstate: failed to set auto_sel, ret: -95
amd_pstate: Failed to initialize CPU 0: -95
...
amd_pstate: failed to register with return -19
Skip the write when the register already holds the value the requested mode needs. Active and guided mode are fixed on these platforms, which report auto_sel as 1, while passive mode still fails to load on a platform that cannot disable autonomous selection, exactly as it did before the offending commit.
---
changelog v2:
Accecpt and tested the K Prateek Nayak reviews.
v1 link:
https://lore.kernel.org/stable/[email protected]/#R
---
--- drivers/cpufreq/amd-pstate.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/cpufreq/amd-pstate.c +3 -0
@@ -535,6 +535,9 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)return 0 ; } +if ((cppc_state !=AMD_PSTATE_PASSIVE ) == auto_sel) +return 0 ; + ret =cppc_set_auto_sel (cpudata->cpu, (cppc_state ==AMD_PSTATE_PASSIVE ) ?0 :1 );
Signature · 1 line
2.30.2
Re: [PATCH v2] cpufreq/amd-pstate: Skip auto_sel write when it already matches the mode
Hello Wentao,
Quoted 25 lines · Wentao Guan
Since commit
9dfd13f80c85("cpufreq/amd-pstate: Toggleauto_selin active mode on shared memory systems"),shmem_init_perf()programsAUTONOMOUS_SELECTION_ENABLEunconditionally, including in active mode.Platforms that exclusively support autonomous selection report this field as an Integer of 1, as required by the ACPI specification, instead of as a register descriptor.
cppc_get_reg_val()reads such a field back successfully, butcppc_set_reg_val()rejects the write with-EOPNOTSUPPbecause the entry is not anACPI_TYPE_BUFFER.
shmem_init_perf()propagates that error, so everyamd_pstate_epp_cpu_init()fails,cpufreq_register_driver()ends up with an empty policy list and returns-ENODEV, and amd-pstate refuses to load at all:
amd_pstate: failed to setauto_sel, ret: -95
amd_pstate: Failed to initialize CPU 0: -95
...
amd_pstate: failed to register with return -19Skip the write when the register already holds the value the requested mode needs. Active and guided mode are fixed on these platforms, which report
auto_selas 1, while passive mode still fails to load on a platform that cannot disable autonomous selection, exactly as it did before the offending commit.
Quoted 4 lines
Fixes 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems")Tested-by LFRon <[email protected]>Signed-off-by K Prateek Nayak <[email protected]>
You can flip that to:
You did all the hard work to find, debug, and test it!
Quoted 16 lines
Signed-off-by Wentao Guan <[email protected]>---
changelog v2:
Accecpt and tested the K Prateek Nayak reviews.
v1 link:
https://lore.kernel.org/stable/[email protected]/#R
------ drivers/cpufreq/amd-pstate.c | 3 +++ 1 file changed, 3 insertions(+)drivers/cpufreq/amd-pstate.c +0
-0
drivers/cpufreq/amd-pstate.c static int shmem_init_perf(struct amd_cpudata *cpudata) · line 542
Quoted 8 lines
drivers/cpufreq/amd-pstate.c +3
-0@@ -535,6 +535,9 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)return 0 ; } +if ((cppc_state !=AMD_PSTATE_PASSIVE ) == auto_sel) +return 0 ; + ret =cppc_set_auto_sel (cpudata->cpu, (cppc_state ==AMD_PSTATE_PASSIVE ) ?0 :1 );
nit. Now that we arrive here only to flip the autosel value, you can just do:
cppc_set_auto_sel(cpudata->cpu, !auto_sel)
... and remove that ternary op.
Signature · 2 lines
Thanks and Regards, Prateek
PATCH v3 1/1 cpufreq/amd-pstate: Skip auto_sel write when it already matches the mode
Since commit 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems"), shmem_init_perf() programs AUTONOMOUS_SELECTION_ENABLE unconditionally, including in active mode.
Platforms that exclusively support autonomous selection report this field as an Integer of 1, as required by the ACPI specification, instead of as a register descriptor. cppc_get_reg_val() reads such a field back successfully, but cppc_set_reg_val() rejects the write with -EOPNOTSUPP because the entry is not an ACPI_TYPE_BUFFER.
shmem_init_perf() propagates that error, so every amd_pstate_epp_cpu_init() fails, cpufreq_register_driver() ends up with an empty policy list and returns -ENODEV, and amd-pstate refuses to load at all:
amd_pstate: failed to set auto_sel, ret: -95
amd_pstate: Failed to initialize CPU 0: -95
...
amd_pstate: failed to register with return -19
Skip the write when the register already holds the value the requested mode needs. Active and guided mode are fixed on these platforms, which report auto_sel as 1, while passive mode still fails to load on a platform that cannot disable autonomous selection, exactly as it did before the offending commit.
---
changelog v3:
Include the K Prateek Nayak reviews to remove that ternary op base on current condition now have.
v2 link:
https://lore.kernel.org/stable/[email protected]/#R
changelog v2:
Accecpt and tested the K Prateek Nayak reviews.
v1 link:
https://lore.kernel.org/stable/[email protected]/#R
---
--- drivers/cpufreq/amd-pstate.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/cpufreq/amd-pstate.c +4 -2
@@ -532,8 +532,10 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)return 0 ; } - ret =cppc_set_auto_sel (cpudata->cpu, - (cppc_state ==AMD_PSTATE_PASSIVE ) ?0 :1 ); +if ((cppc_state !=AMD_PSTATE_PASSIVE ) == auto_sel) +return 0 ; + + ret =cppc_set_auto_sel (cpudata->cpu, !auto_sel);if (ret)pr_warn ("failed to set auto_sel, ret: %d\n" , ret);
Signature · 1 line
2.30.2
Re: [PATCH v3] cpufreq/amd-pstate: Skip auto_sel write when it already matches the mode
Hi,
Quoted 65 lines
Since commit
9dfd13f80c85("cpufreq/amd-pstate: Toggleauto_selin active mode on shared memory systems"),shmem_init_perf()programsAUTONOMOUS_SELECTION_ENABLEunconditionally, including in active mode.Platforms that exclusively support autonomous selection report this field as an Integer of 1, as required by the ACPI specification, instead of as a register descriptor.
cppc_get_reg_val()reads such a field back successfully, butcppc_set_reg_val()rejects the write with-EOPNOTSUPPbecause the entry is not anACPI_TYPE_BUFFER.
shmem_init_perf()propagates that error, so everyamd_pstate_epp_cpu_init()fails,cpufreq_register_driver()ends up with an empty policy list and returns-ENODEV, and amd-pstate refuses to load at all:
amd_pstate: failed to setauto_sel, ret: -95
amd_pstate: Failed to initialize CPU 0: -95
...
amd_pstate: failed to register with return -19Skip the write when the register already holds the value the requested mode needs. Active and guided mode are fixed on these platforms, which report
auto_selas 1, while passive mode still fails to load on a platform that cannot disable autonomous selection, exactly as it did before the offending commit.Fixes 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems")Reviewed-by K Prateek Nayak <[email protected]>Tested-by K Prateek Nayak <[email protected]>Tested-by LFRon <[email protected]>Signed-off-by Wentao Guan <[email protected]>---
changelog v3:
Include the K Prateek Nayak reviews to remove that ternary op base on current condition now have.v2 link:
https://lore.kernel.org/stable/[email protected]/#R
changelog v2:
Accecpt and tested the K Prateek Nayak reviews.
v1 link:
https://lore.kernel.org/stable/[email protected]/#R
---
---drivers/cpufreq/amd-pstate.c| 6 ++++--1 file changed, 4 insertions(+), 2 deletions(-)drivers/cpufreq/amd-pstate.c +4
-3@@ -532,8 +532,10 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)return 0 ; } - ret =cppc_set_auto_sel (cpudata->cpu, - (cppc_state ==AMD_PSTATE_PASSIVE ) ?0 :1 ); +if ((cppc_state !=AMD_PSTATE_PASSIVE ) == auto_sel) +return 0 ; + + ret =cppc_set_auto_sel (cpudata->cpu, !auto_sel);if (ret)pr_warn ("failed to set auto_sel, ret: %d\n" , ret); --
Quoted 1 line
2.30.2
Ping? Nearly a month passed, anything update?
BRs
Wentao Guan
K Prateek Nayak
reviewerRe: [PATCH v3] cpufreq/amd-pstate: Skip auto_sel write when it already matches the mode
Hello Wentao,
Quoted 64 lines · Wentao Guan
Hi,
Quoted 62 lines
Since commit
9dfd13f80c85("cpufreq/amd-pstate: Toggleauto_selin active mode on shared memory systems"),shmem_init_perf()programsAUTONOMOUS_SELECTION_ENABLEunconditionally, including in active mode.Platforms that exclusively support autonomous selection report this field as an Integer of 1, as required by the ACPI specification, instead of as a register descriptor.
cppc_get_reg_val()reads such a field back successfully, butcppc_set_reg_val()rejects the write with-EOPNOTSUPPbecause the entry is not anACPI_TYPE_BUFFER.
shmem_init_perf()propagates that error, so everyamd_pstate_epp_cpu_init()fails,cpufreq_register_driver()ends up with an empty policy list and returns-ENODEV, and amd-pstate refuses to load at all:
amd_pstate: failed to setauto_sel, ret: -95
amd_pstate: Failed to initialize CPU 0: -95
...
amd_pstate: failed to register with return -19Skip the write when the register already holds the value the requested mode needs. Active and guided mode are fixed on these platforms, which report
auto_selas 1, while passive mode still fails to load on a platform that cannot disable autonomous selection, exactly as it did before the offending commit.Fixes 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems")Reviewed-by K Prateek Nayak <[email protected]>Tested-by K Prateek Nayak <[email protected]>Tested-by LFRon <[email protected]>Signed-off-by Wentao Guan <[email protected]>---
changelog v3:
Include the K Prateek Nayak reviews to remove that ternary op base on current condition now have.v2 link:
https://lore.kernel.org/stable/[email protected]/#R
changelog v2:
Accecpt and tested the K Prateek Nayak reviews.
v1 link:
https://lore.kernel.org/stable/[email protected]/#R
---
---drivers/cpufreq/amd-pstate.c| 6 ++++--1 file changed, 4 insertions(+), 2 deletions(-)drivers/cpufreq/amd-pstate.c +4
-2@@ -532,8 +532,10 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)return 0 ; } - ret =cppc_set_auto_sel (cpudata->cpu, - (cppc_state ==AMD_PSTATE_PASSIVE ) ?0 :1 ); +if ((cppc_state !=AMD_PSTATE_PASSIVE ) == auto_sel) +return 0 ; + + ret =cppc_set_auto_sel (cpudata->cpu, !auto_sel);
Quoted 6 lines
Quoted 4 lines
drivers/cpufreq/amd-pstate.c +0
-1if (ret)pr_warn ("failed to set auto_sel, ret: %d\n" , ret); --2.30.2
Ping? Nearly a month passed, anything update?
On a similar issue here
https://lore.kernel.org/all/[email protected]/
Mario had recently pointed out that this might be a BIOS issue on systems that may have MSR interface but running an old BIOS that does not advertise the CPUID bit.
Could you please share your system details here and check if you are running the latest BIOS from your vendor?
Signature · 2 lines
Thanks and Regards, Prateek
Re: [PATCH v3] cpufreq/amd-pstate: Skip auto_sel write when it already matches the mode
Hi,
Quoted 72 lines · Wentao Guan
Quoted 64 lines
Hi,
Quoted 62 lines
Since commit
9dfd13f80c85("cpufreq/amd-pstate: Toggleauto_selin active mode on shared memory systems"),shmem_init_perf()programsAUTONOMOUS_SELECTION_ENABLEunconditionally, including in active mode.Platforms that exclusively support autonomous selection report this field as an Integer of 1, as required by the ACPI specification, instead of as a register descriptor.
cppc_get_reg_val()reads such a field back successfully, butcppc_set_reg_val()rejects the write with-EOPNOTSUPPbecause the entry is not anACPI_TYPE_BUFFER.
shmem_init_perf()propagates that error, so everyamd_pstate_epp_cpu_init()fails,cpufreq_register_driver()ends up with an empty policy list and returns-ENODEV, and amd-pstate refuses to load at all:
amd_pstate: failed to setauto_sel, ret: -95
amd_pstate: Failed to initialize CPU 0: -95
...
amd_pstate: failed to register with return -19Skip the write when the register already holds the value the requested mode needs. Active and guided mode are fixed on these platforms, which report
auto_selas 1, while passive mode still fails to load on a platform that cannot disable autonomous selection, exactly as it did before the offending commit.Fixes 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems")Reviewed-by K Prateek Nayak <[email protected]>Tested-by K Prateek Nayak <[email protected]>Tested-by LFRon <[email protected]>Signed-off-by Wentao Guan <[email protected]>---
changelog v3:
Include the K Prateek Nayak reviews to remove that ternary op base on current condition now have.v2 link:
https://lore.kernel.org/stable/[email protected]/#R
changelog v2:
Accecpt and tested the K Prateek Nayak reviews.
v1 link:
https://lore.kernel.org/stable/[email protected]/#R
---
---drivers/cpufreq/amd-pstate.c| 6 ++++--1 file changed, 4 insertions(+), 2 deletions(-)drivers/cpufreq/amd-pstate.c +4
-2@@ -532,8 +532,10 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)return 0 ; } - ret =cppc_set_auto_sel (cpudata->cpu, - (cppc_state ==AMD_PSTATE_PASSIVE ) ?0 :1 ); +if ((cppc_state !=AMD_PSTATE_PASSIVE ) == auto_sel) +return 0 ; + + ret =cppc_set_auto_sel (cpudata->cpu, !auto_sel);Quoted 6 lines
Quoted 4 lines
drivers/cpufreq/amd-pstate.c +0
-1if (ret)pr_warn ("failed to set auto_sel, ret: %d\n" , ret); --2.30.2
Ping? Nearly a month passed, anything update?
Quoted 5 lines
On a similar issue here
https://lore.kernel.org/all/[email protected]/
Mario had recently pointed out that this might be a BIOS issue on systems that may have MSR interface but running an old BIOS that does not advertise the CPUID bit.
Seem same issue.
Quoted 3 lines
Could you please share your system details here and check if you are running the latest BIOS from your vendor?
Emmm, the user report that dmesg showed running on this laptop:
DMI: METAPHYUNI MetamechBook01/MetamechBook01, BIOS AHP958_V00.01_T015A5ME1 02/22/2024 which vendor not ship new BIOS,
but it is verified in AMD Advantage: https://www.amd.com/en/gaming/laptops/advantage-premium.html ...
He also helped me to test the kernel patch.
BRs
Wentao Guan