You've already forked linux-apfs
mirror of
https://github.com/linux-apfs/linux-apfs.git
synced 2026-05-01 15:00:59 -07:00
cpufreq: Handle sorted frequency tables more efficiently
cpufreq drivers aren't required to provide a sorted frequency table today, and even the ones which provide a sorted table aren't handled efficiently by cpufreq core. This patch adds infrastructure to verify if the freq-table provided by the drivers is sorted or not, and use efficient helpers if they are sorted. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
committed by
Rafael J. Wysocki
parent
8d540ea792
commit
da0c6dc00c
@@ -113,9 +113,9 @@ int cpufreq_generic_frequency_table_verify(struct cpufreq_policy *policy)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(cpufreq_generic_frequency_table_verify);
|
||||
|
||||
int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
|
||||
unsigned int target_freq,
|
||||
unsigned int relation)
|
||||
int cpufreq_table_index_unsorted(struct cpufreq_policy *policy,
|
||||
unsigned int target_freq,
|
||||
unsigned int relation)
|
||||
{
|
||||
struct cpufreq_frequency_table optimal = {
|
||||
.driver_data = ~0,
|
||||
@@ -205,7 +205,7 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
|
||||
table[index].frequency);
|
||||
return index;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(cpufreq_frequency_table_target);
|
||||
EXPORT_SYMBOL_GPL(cpufreq_table_index_unsorted);
|
||||
|
||||
int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy,
|
||||
unsigned int freq)
|
||||
@@ -297,15 +297,72 @@ struct freq_attr *cpufreq_generic_attr[] = {
|
||||
};
|
||||
EXPORT_SYMBOL_GPL(cpufreq_generic_attr);
|
||||
|
||||
static int set_freq_table_sorted(struct cpufreq_policy *policy)
|
||||
{
|
||||
struct cpufreq_frequency_table *pos, *table = policy->freq_table;
|
||||
struct cpufreq_frequency_table *prev = NULL;
|
||||
int ascending = 0;
|
||||
|
||||
policy->freq_table_sorted = CPUFREQ_TABLE_UNSORTED;
|
||||
|
||||
cpufreq_for_each_valid_entry(pos, table) {
|
||||
if (!prev) {
|
||||
prev = pos;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pos->frequency == prev->frequency) {
|
||||
pr_warn("Duplicate freq-table entries: %u\n",
|
||||
pos->frequency);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Frequency increased from prev to pos */
|
||||
if (pos->frequency > prev->frequency) {
|
||||
/* But frequency was decreasing earlier */
|
||||
if (ascending < 0) {
|
||||
pr_debug("Freq table is unsorted\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ascending++;
|
||||
} else {
|
||||
/* Frequency decreased from prev to pos */
|
||||
|
||||
/* But frequency was increasing earlier */
|
||||
if (ascending > 0) {
|
||||
pr_debug("Freq table is unsorted\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ascending--;
|
||||
}
|
||||
|
||||
prev = pos;
|
||||
}
|
||||
|
||||
if (ascending > 0)
|
||||
policy->freq_table_sorted = CPUFREQ_TABLE_SORTED_ASCENDING;
|
||||
else
|
||||
policy->freq_table_sorted = CPUFREQ_TABLE_SORTED_DESCENDING;
|
||||
|
||||
pr_debug("Freq table is sorted in %s order\n",
|
||||
ascending > 0 ? "ascending" : "descending");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cpufreq_table_validate_and_show(struct cpufreq_policy *policy,
|
||||
struct cpufreq_frequency_table *table)
|
||||
{
|
||||
int ret = cpufreq_frequency_table_cpuinfo(policy, table);
|
||||
int ret;
|
||||
|
||||
if (!ret)
|
||||
policy->freq_table = table;
|
||||
ret = cpufreq_frequency_table_cpuinfo(policy, table);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return ret;
|
||||
policy->freq_table = table;
|
||||
return set_freq_table_sorted(policy);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(cpufreq_table_validate_and_show);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user