Skip to content

Commit 8f8b42c

Browse files
Perry Yuansuperm1
authored andcommitted
cpufreq: amd-pstate: optimize the initial frequency values verification
To enhance the debugging capability of the driver loading failure for broken CPPC ACPI tables, it can optimize the expression by moving the verification of `min_freq`, `nominal_freq`, and other dependency values to the `amd_pstate_init_freq()` function where they are initialized. If any of these values are incorrect, the `amd-pstate` driver will not be registered. By ensuring that these values are correct before they are used, it will facilitate the debugging process when encountering driver loading failures due to faulty CPPC ACPI tables from BIOS Signed-off-by: Perry Yuan <[email protected]> Acked-by: Gautham R. Shenoy <[email protected]> Acked-by: Mario Limonciello <[email protected]> Link: https://lore.kernel.org/r/f9793f8451c1832e34cc9dc35f89c653b39cfe38.1718811234.git.perry.yuan@amd.com Signed-off-by: Mario Limonciello <[email protected]>
1 parent fc6e083 commit 8f8b42c

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

drivers/cpufreq/amd-pstate.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,24 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata)
924924
WRITE_ONCE(cpudata->nominal_freq, nominal_freq);
925925
WRITE_ONCE(cpudata->max_freq, max_freq);
926926

927+
/**
928+
* Below values need to be initialized correctly, otherwise driver will fail to load
929+
* max_freq is calculated according to (nominal_freq * highest_perf)/nominal_perf
930+
* lowest_nonlinear_freq is a value between [min_freq, nominal_freq]
931+
* Check _CPC in ACPI table objects if any values are incorrect
932+
*/
933+
if (min_freq <= 0 || max_freq <= 0 || nominal_freq <= 0 || min_freq > max_freq) {
934+
pr_err("min_freq(%d) or max_freq(%d) or nominal_freq(%d) value is incorrect\n",
935+
min_freq, max_freq, nominal_freq * 1000);
936+
return -EINVAL;
937+
}
938+
939+
if (lowest_nonlinear_freq <= min_freq || lowest_nonlinear_freq > nominal_freq * 1000) {
940+
pr_err("lowest_nonlinear_freq(%d) value is out of range [min_freq(%d), nominal_freq(%d)]\n",
941+
lowest_nonlinear_freq, min_freq, nominal_freq * 1000);
942+
return -EINVAL;
943+
}
944+
927945
return 0;
928946
}
929947

@@ -962,15 +980,6 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
962980
max_freq = READ_ONCE(cpudata->max_freq);
963981
nominal_freq = READ_ONCE(cpudata->nominal_freq);
964982

965-
if (min_freq <= 0 || max_freq <= 0 ||
966-
nominal_freq <= 0 || min_freq > max_freq) {
967-
dev_err(dev,
968-
"min_freq(%d) or max_freq(%d) or nominal_freq (%d) value is incorrect, check _CPC in ACPI tables\n",
969-
min_freq, max_freq, nominal_freq);
970-
ret = -EINVAL;
971-
goto free_cpudata1;
972-
}
973-
974983
policy->cpuinfo.transition_latency = amd_pstate_get_transition_latency(policy->cpu);
975984
policy->transition_delay_us = amd_pstate_get_transition_delay_us(policy->cpu);
976985

@@ -1423,14 +1432,6 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
14231432
min_freq = READ_ONCE(cpudata->min_freq);
14241433
max_freq = READ_ONCE(cpudata->max_freq);
14251434
nominal_freq = READ_ONCE(cpudata->nominal_freq);
1426-
if (min_freq <= 0 || max_freq <= 0 ||
1427-
nominal_freq <= 0 || min_freq > max_freq) {
1428-
dev_err(dev,
1429-
"min_freq(%d) or max_freq(%d) or nominal_freq(%d) value is incorrect, check _CPC in ACPI tables\n",
1430-
min_freq, max_freq, nominal_freq);
1431-
ret = -EINVAL;
1432-
goto free_cpudata1;
1433-
}
14341435

14351436
policy->cpuinfo.min_freq = min_freq;
14361437
policy->cpuinfo.max_freq = max_freq;

0 commit comments

Comments
 (0)