Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

cpufreq/amd-pstate: Cache the max frequency in cpudata

The value of maximum frequency is fixed and never changes. Doing
calculations every time based off of perf is unnecessary.

Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
Link: https://lore.kernel.org/r/20260326193620.649441-1-mario.limonciello@amd.com
Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>

+11 -18
+9 -18
drivers/cpufreq/amd-pstate.c
··· 826 826 static int amd_pstate_cpu_boost_update(struct cpufreq_policy *policy, bool on) 827 827 { 828 828 struct amd_cpudata *cpudata = policy->driver_data; 829 - union perf_cached perf = READ_ONCE(cpudata->perf); 830 - u32 nominal_freq, max_freq; 829 + u32 nominal_freq; 831 830 int ret = 0; 832 831 833 832 nominal_freq = READ_ONCE(cpudata->nominal_freq); 834 - max_freq = perf_to_freq(perf, cpudata->nominal_freq, perf.highest_perf); 835 833 836 834 if (on) 837 - policy->cpuinfo.max_freq = max_freq; 835 + policy->cpuinfo.max_freq = cpudata->max_freq; 838 836 else if (policy->cpuinfo.max_freq > nominal_freq) 839 837 policy->cpuinfo.max_freq = nominal_freq; 840 838 ··· 1019 1021 1020 1022 WRITE_ONCE(cpudata->nominal_freq, nominal_freq); 1021 1023 1024 + /* max_freq is calculated according to (nominal_freq * highest_perf)/nominal_perf */ 1022 1025 max_freq = perf_to_freq(perf, nominal_freq, perf.highest_perf); 1026 + WRITE_ONCE(cpudata->max_freq, max_freq); 1027 + 1023 1028 lowest_nonlinear_freq = perf_to_freq(perf, nominal_freq, perf.lowest_nonlinear_perf); 1024 1029 WRITE_ONCE(cpudata->lowest_nonlinear_freq, lowest_nonlinear_freq); 1025 1030 1026 1031 /** 1027 1032 * Below values need to be initialized correctly, otherwise driver will fail to load 1028 - * max_freq is calculated according to (nominal_freq * highest_perf)/nominal_perf 1029 1033 * lowest_nonlinear_freq is a value between [min_freq, nominal_freq] 1030 1034 * Check _CPC in ACPI table objects if any values are incorrect 1031 1035 */ ··· 1090 1090 policy->cpuinfo.min_freq = policy->min = perf_to_freq(perf, 1091 1091 cpudata->nominal_freq, 1092 1092 perf.lowest_perf); 1093 - policy->cpuinfo.max_freq = policy->max = perf_to_freq(perf, 1094 - cpudata->nominal_freq, 1095 - perf.highest_perf); 1093 + policy->cpuinfo.max_freq = policy->max = cpudata->max_freq; 1096 1094 1097 1095 policy->driver_data = cpudata; 1098 1096 ret = amd_pstate_cppc_enable(policy); ··· 1165 1167 static ssize_t show_amd_pstate_max_freq(struct cpufreq_policy *policy, 1166 1168 char *buf) 1167 1169 { 1168 - struct amd_cpudata *cpudata; 1169 - union perf_cached perf; 1170 + struct amd_cpudata *cpudata = policy->driver_data; 1170 1171 1171 - cpudata = policy->driver_data; 1172 - perf = READ_ONCE(cpudata->perf); 1173 - 1174 - return sysfs_emit(buf, "%u\n", 1175 - perf_to_freq(perf, cpudata->nominal_freq, perf.highest_perf)); 1172 + return sysfs_emit(buf, "%u\n", cpudata->max_freq); 1176 1173 } 1177 1174 1178 1175 static ssize_t show_amd_pstate_lowest_nonlinear_freq(struct cpufreq_policy *policy, ··· 1695 1702 policy->cpuinfo.min_freq = policy->min = perf_to_freq(perf, 1696 1703 cpudata->nominal_freq, 1697 1704 perf.lowest_perf); 1698 - policy->cpuinfo.max_freq = policy->max = perf_to_freq(perf, 1699 - cpudata->nominal_freq, 1700 - perf.highest_perf); 1705 + policy->cpuinfo.max_freq = policy->max = cpudata->max_freq; 1701 1706 policy->driver_data = cpudata; 1702 1707 1703 1708 ret = amd_pstate_cppc_enable(policy);
+2
drivers/cpufreq/amd-pstate.h
··· 73 73 * @min_limit_freq: Cached value of policy->min (in khz) 74 74 * @max_limit_freq: Cached value of policy->max (in khz) 75 75 * @nominal_freq: the frequency (in khz) that mapped to nominal_perf 76 + * @max_freq: in ideal conditions the maximum frequency (in khz) possible frequency 76 77 * @lowest_nonlinear_freq: the frequency (in khz) that mapped to lowest_nonlinear_perf 77 78 * @floor_freq: Cached value of the user requested floor_freq 78 79 * @cur: Difference of Aperf/Mperf/tsc count between last and current sample ··· 104 103 u32 min_limit_freq; 105 104 u32 max_limit_freq; 106 105 u32 nominal_freq; 106 + u32 max_freq; 107 107 u32 lowest_nonlinear_freq; 108 108 u32 floor_freq; 109 109