]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
cpufreq: preserve freq_table_sorted across suspend/hibernate
authorZihuan Zhang <zhangzihuan@kylinos.cn>
Sat, 11 Oct 2025 07:24:20 +0000 (15:24 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 20 Oct 2025 19:01:35 +0000 (21:01 +0200)
During S3/S4 suspend and resume, cpufreq policies are not freed or
recreated; the freq_table and policy structure remain intact. However,
set_freq_table_sorted() currently resets policy->freq_table_sorted to
UNSORTED unconditionally, which is unnecessary since the table order
does not change across suspend/resume.

This patch adds a check to skip validation if policy->freq_table_sorted
is already ASCENDING or DESCENDING. This avoids unnecessary traversal
of the frequency table on S3/S4 resume or repeated online events,
reducing overhead while preserving correctness.

Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn>
Link: https://patch.msgid.link/20251011072420.11495-1-zhangzihuan@kylinos.cn
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpufreq/cpufreq.c

index 852e024facc3cb5469db24242e61104d8d6ccb09..4a27f6cb07d38044a26b8f285d129ebd21a44928 100644 (file)
@@ -1421,9 +1421,12 @@ static int cpufreq_policy_online(struct cpufreq_policy *policy,
                 * If there is a problem with its frequency table, take it
                 * offline and drop it.
                 */
-               ret = cpufreq_table_validate_and_sort(policy);
-               if (ret)
-                       goto out_offline_policy;
+               if (policy->freq_table_sorted != CPUFREQ_TABLE_SORTED_ASCENDING &&
+                   policy->freq_table_sorted != CPUFREQ_TABLE_SORTED_DESCENDING) {
+                       ret = cpufreq_table_validate_and_sort(policy);
+                       if (ret)
+                               goto out_offline_policy;
+               }
 
                /* related_cpus should at least include policy->cpus. */
                cpumask_copy(policy->related_cpus, policy->cpus);