Skip to content

Commit ed95716

Browse files
Liao Changrafaeljw
authored andcommitted
cpufreq: stats: Improve the performance of cpufreq_stats_create_table()
In the worst case, the freq_table of policy data is not sorted and contains duplicate frequencies, this means that it needs to iterate through the entire freq_table of policy to ensure each frequency is unique in the freq_table of stats data, this has a time complexity of O(N^2), where N is the number of frequencies in the freq_table of policy. However, if the policy.freq_table is already sorted and contains no duplicate frequencies, it can reduce the time complexity of creating stats.freq_table to O(N), the 'freq_table_sorted' field of policy data can be used to indicate whether the policy.freq_table is sorted. Signed-off-by: Liao Chang <liaochang1@huawei.com> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Reviewed-by: Dhruva Gole <d-gole@ti.com> [ rjw: Fix typo in changelog, remove redundant parens ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 706a741 commit ed95716

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/cpufreq/cpufreq_stats.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ void cpufreq_stats_create_table(struct cpufreq_policy *policy)
243243

244244
/* Find valid-unique entries */
245245
cpufreq_for_each_valid_entry(pos, policy->freq_table)
246-
if (freq_table_get_index(stats, pos->frequency) == -1)
246+
if (policy->freq_table_sorted != CPUFREQ_TABLE_UNSORTED ||
247+
freq_table_get_index(stats, pos->frequency) == -1)
247248
stats->freq_table[i++] = pos->frequency;
248249

249250
stats->state_num = i;

0 commit comments

Comments
 (0)