2019-06-04 16:11:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* linux/drivers/cpufreq/freq_table.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 - 2003 Dominik Brodowski
|
|
|
|
*/
|
|
|
|
|
2012-10-23 07:29:03 +08:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/cpufreq.h>
|
2013-08-07 01:23:03 +08:00
|
|
|
#include <linux/module.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* FREQUENCY TABLE HELPERS *
|
|
|
|
*********************************************************************/
|
|
|
|
|
2015-07-29 18:53:09 +08:00
|
|
|
bool policy_has_boost_freq(struct cpufreq_policy *policy)
|
|
|
|
{
|
|
|
|
struct cpufreq_frequency_table *pos, *table = policy->freq_table;
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
cpufreq_for_each_valid_entry(pos, table)
|
|
|
|
if (pos->flags & CPUFREQ_BOOST_FREQ)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(policy_has_boost_freq);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
|
|
|
|
struct cpufreq_frequency_table *table)
|
|
|
|
{
|
2014-04-26 04:15:38 +08:00
|
|
|
struct cpufreq_frequency_table *pos;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int min_freq = ~0;
|
|
|
|
unsigned int max_freq = 0;
|
2014-04-26 04:15:38 +08:00
|
|
|
unsigned int freq;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-04-26 04:15:38 +08:00
|
|
|
cpufreq_for_each_valid_entry(pos, table) {
|
|
|
|
freq = pos->frequency;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-12-20 22:24:49 +08:00
|
|
|
if (!cpufreq_boost_enabled()
|
2014-04-26 04:15:38 +08:00
|
|
|
&& (pos->flags & CPUFREQ_BOOST_FREQ))
|
2013-12-20 22:24:49 +08:00
|
|
|
continue;
|
|
|
|
|
2014-04-26 04:15:38 +08:00
|
|
|
pr_debug("table entry %u: %u kHz\n", (int)(pos - table), freq);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (freq < min_freq)
|
|
|
|
min_freq = freq;
|
|
|
|
if (freq > max_freq)
|
|
|
|
max_freq = freq;
|
|
|
|
}
|
|
|
|
|
|
|
|
policy->min = policy->cpuinfo.min_freq = min_freq;
|
|
|
|
policy->max = policy->cpuinfo.max_freq = max_freq;
|
|
|
|
|
|
|
|
if (policy->min == ~0)
|
|
|
|
return -EINVAL;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
cpufreq: Avoid creating excessively large stack frames
In the process of modifying a cpufreq policy, the cpufreq core makes
a copy of it including all of the internals which is stored on the
CPU stack. Because struct cpufreq_policy is relatively large, this
may cause the size of the stack frame to exceed the 2 KB limit and
so the GCC complains when -Wframe-larger-than= is used.
In fact, it is not necessary to copy the entire policy structure
in order to modify it, however.
First, because cpufreq_set_policy() obtains the min and max policy
limits from frequency QoS now, it is not necessary to pass the limits
to it from the callers. The only things that need to be passed to it
from there are the new governor pointer or (if there is a built-in
governor in the driver) the "policy" value representing the governor
choice. They both can be passed as individual arguments, though, so
make cpufreq_set_policy() take them this way and rework its callers
accordingly. This avoids making copies of cpufreq policies in the
callers of cpufreq_set_policy().
Second, cpufreq_set_policy() still needs to pass the new policy
data to the ->verify() callback of the cpufreq driver whose task
is to sanitize the min and max policy limits. It still does not
need to make a full copy of struct cpufreq_policy for this purpose,
but it needs to pass a few items from it to the driver in case they
are needed (different drivers have different needs in that respect
and all of them have to be covered). For this reason, introduce
struct cpufreq_policy_data to hold copies of the members of
struct cpufreq_policy used by the existing ->verify() driver
callbacks and pass a pointer to a temporary structure of that
type to ->verify() (instead of passing a pointer to full struct
cpufreq_policy to it).
While at it, notice that intel_pstate and longrun don't really need
to verify the "policy" value in struct cpufreq_policy, so drop those
check from them to avoid copying "policy" into struct
cpufreq_policy_data (which allows it to be slightly smaller).
Also while at it fix up white space in a couple of places and make
cpufreq_set_policy() static (as it can be so).
Fixes: 3000ce3c52f8 ("cpufreq: Use per-policy frequency QoS")
Link: https://lore.kernel.org/linux-pm/CAMuHMdX6-jb1W8uC2_237m8ctCpsnGp=JCxqt8pCWVqNXHmkVg@mail.gmail.com
Reported-by: kbuild test robot <lkp@intel.com>
Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: 5.4+ <stable@vger.kernel.org> # 5.4+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
2020-01-27 06:40:11 +08:00
|
|
|
int cpufreq_frequency_table_verify(struct cpufreq_policy_data *policy,
|
2005-04-17 06:20:36 +08:00
|
|
|
struct cpufreq_frequency_table *table)
|
|
|
|
{
|
2014-04-26 04:15:38 +08:00
|
|
|
struct cpufreq_frequency_table *pos;
|
|
|
|
unsigned int freq, next_larger = ~0;
|
2013-10-02 16:43:15 +08:00
|
|
|
bool found = false;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-03-27 21:04:46 +08:00
|
|
|
pr_debug("request for verification of policy (%u - %u kHz) for cpu %u\n",
|
2006-10-26 18:50:58 +08:00
|
|
|
policy->min, policy->max, policy->cpu);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-10-02 16:43:19 +08:00
|
|
|
cpufreq_verify_within_cpu_limits(policy);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-04-26 04:15:38 +08:00
|
|
|
cpufreq_for_each_valid_entry(pos, table) {
|
|
|
|
freq = pos->frequency;
|
|
|
|
|
2013-10-02 16:43:15 +08:00
|
|
|
if ((freq >= policy->min) && (freq <= policy->max)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((next_larger > freq) && (freq > policy->max))
|
2005-04-17 06:20:36 +08:00
|
|
|
next_larger = freq;
|
|
|
|
}
|
|
|
|
|
2013-10-02 16:43:15 +08:00
|
|
|
if (!found) {
|
2005-04-17 06:20:36 +08:00
|
|
|
policy->max = next_larger;
|
2013-10-02 16:43:19 +08:00
|
|
|
cpufreq_verify_within_cpu_limits(policy);
|
2013-10-02 16:43:15 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-03-27 21:04:46 +08:00
|
|
|
pr_debug("verification lead to (%u - %u kHz) for cpu %u\n",
|
2006-10-26 18:50:58 +08:00
|
|
|
policy->min, policy->max, policy->cpu);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(cpufreq_frequency_table_verify);
|
|
|
|
|
2013-10-03 22:57:55 +08:00
|
|
|
/*
|
2014-03-10 17:23:33 +08:00
|
|
|
* Generic routine to verify policy & frequency table, requires driver to set
|
|
|
|
* policy->freq_table prior to it.
|
2013-10-03 22:57:55 +08:00
|
|
|
*/
|
cpufreq: Avoid creating excessively large stack frames
In the process of modifying a cpufreq policy, the cpufreq core makes
a copy of it including all of the internals which is stored on the
CPU stack. Because struct cpufreq_policy is relatively large, this
may cause the size of the stack frame to exceed the 2 KB limit and
so the GCC complains when -Wframe-larger-than= is used.
In fact, it is not necessary to copy the entire policy structure
in order to modify it, however.
First, because cpufreq_set_policy() obtains the min and max policy
limits from frequency QoS now, it is not necessary to pass the limits
to it from the callers. The only things that need to be passed to it
from there are the new governor pointer or (if there is a built-in
governor in the driver) the "policy" value representing the governor
choice. They both can be passed as individual arguments, though, so
make cpufreq_set_policy() take them this way and rework its callers
accordingly. This avoids making copies of cpufreq policies in the
callers of cpufreq_set_policy().
Second, cpufreq_set_policy() still needs to pass the new policy
data to the ->verify() callback of the cpufreq driver whose task
is to sanitize the min and max policy limits. It still does not
need to make a full copy of struct cpufreq_policy for this purpose,
but it needs to pass a few items from it to the driver in case they
are needed (different drivers have different needs in that respect
and all of them have to be covered). For this reason, introduce
struct cpufreq_policy_data to hold copies of the members of
struct cpufreq_policy used by the existing ->verify() driver
callbacks and pass a pointer to a temporary structure of that
type to ->verify() (instead of passing a pointer to full struct
cpufreq_policy to it).
While at it, notice that intel_pstate and longrun don't really need
to verify the "policy" value in struct cpufreq_policy, so drop those
check from them to avoid copying "policy" into struct
cpufreq_policy_data (which allows it to be slightly smaller).
Also while at it fix up white space in a couple of places and make
cpufreq_set_policy() static (as it can be so).
Fixes: 3000ce3c52f8 ("cpufreq: Use per-policy frequency QoS")
Link: https://lore.kernel.org/linux-pm/CAMuHMdX6-jb1W8uC2_237m8ctCpsnGp=JCxqt8pCWVqNXHmkVg@mail.gmail.com
Reported-by: kbuild test robot <lkp@intel.com>
Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: 5.4+ <stable@vger.kernel.org> # 5.4+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
2020-01-27 06:40:11 +08:00
|
|
|
int cpufreq_generic_frequency_table_verify(struct cpufreq_policy_data *policy)
|
2013-10-03 22:57:55 +08:00
|
|
|
{
|
2016-06-03 13:28:47 +08:00
|
|
|
if (!policy->freq_table)
|
2013-10-03 22:57:55 +08:00
|
|
|
return -ENODEV;
|
|
|
|
|
2016-06-03 13:28:47 +08:00
|
|
|
return cpufreq_frequency_table_verify(policy, policy->freq_table);
|
2013-10-03 22:57:55 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(cpufreq_generic_frequency_table_verify);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-06-27 18:34:07 +08:00
|
|
|
int cpufreq_table_index_unsorted(struct cpufreq_policy *policy,
|
|
|
|
unsigned int target_freq,
|
|
|
|
unsigned int relation)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-05-31 06:09:31 +08:00
|
|
|
struct cpufreq_frequency_table optimal = {
|
2013-03-30 18:55:15 +08:00
|
|
|
.driver_data = ~0,
|
2006-05-31 06:09:31 +08:00
|
|
|
.frequency = 0,
|
|
|
|
};
|
|
|
|
struct cpufreq_frequency_table suboptimal = {
|
2013-03-30 18:55:15 +08:00
|
|
|
.driver_data = ~0,
|
2006-05-31 06:09:31 +08:00
|
|
|
.frequency = 0,
|
|
|
|
};
|
2014-04-26 04:15:38 +08:00
|
|
|
struct cpufreq_frequency_table *pos;
|
2016-06-03 13:28:49 +08:00
|
|
|
struct cpufreq_frequency_table *table = policy->freq_table;
|
2014-07-01 00:59:33 +08:00
|
|
|
unsigned int freq, diff, i = 0;
|
2016-06-03 13:28:51 +08:00
|
|
|
int index;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-03-27 21:04:46 +08:00
|
|
|
pr_debug("request for target %u kHz (relation: %u) for cpu %u\n",
|
2006-10-26 18:50:58 +08:00
|
|
|
target_freq, relation, policy->cpu);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
switch (relation) {
|
|
|
|
case CPUFREQ_RELATION_H:
|
|
|
|
suboptimal.frequency = ~0;
|
|
|
|
break;
|
|
|
|
case CPUFREQ_RELATION_L:
|
2014-07-01 00:59:33 +08:00
|
|
|
case CPUFREQ_RELATION_C:
|
2005-04-17 06:20:36 +08:00
|
|
|
optimal.frequency = ~0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-01-30 13:42:37 +08:00
|
|
|
cpufreq_for_each_valid_entry_idx(pos, table, i) {
|
2014-04-26 04:15:38 +08:00
|
|
|
freq = pos->frequency;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((freq < policy->min) || (freq > policy->max))
|
|
|
|
continue;
|
2014-05-15 02:05:52 +08:00
|
|
|
if (freq == target_freq) {
|
|
|
|
optimal.driver_data = i;
|
|
|
|
break;
|
|
|
|
}
|
2009-01-18 14:56:41 +08:00
|
|
|
switch (relation) {
|
2005-04-17 06:20:36 +08:00
|
|
|
case CPUFREQ_RELATION_H:
|
2014-05-15 02:05:52 +08:00
|
|
|
if (freq < target_freq) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (freq >= optimal.frequency) {
|
|
|
|
optimal.frequency = freq;
|
2013-03-30 18:55:15 +08:00
|
|
|
optimal.driver_data = i;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (freq <= suboptimal.frequency) {
|
|
|
|
suboptimal.frequency = freq;
|
2013-03-30 18:55:15 +08:00
|
|
|
suboptimal.driver_data = i;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CPUFREQ_RELATION_L:
|
2014-05-15 02:05:52 +08:00
|
|
|
if (freq > target_freq) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (freq <= optimal.frequency) {
|
|
|
|
optimal.frequency = freq;
|
2013-03-30 18:55:15 +08:00
|
|
|
optimal.driver_data = i;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (freq >= suboptimal.frequency) {
|
|
|
|
suboptimal.frequency = freq;
|
2013-03-30 18:55:15 +08:00
|
|
|
suboptimal.driver_data = i;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-07-01 00:59:33 +08:00
|
|
|
case CPUFREQ_RELATION_C:
|
|
|
|
diff = abs(freq - target_freq);
|
|
|
|
if (diff < optimal.frequency ||
|
|
|
|
(diff == optimal.frequency &&
|
|
|
|
freq > table[optimal.driver_data].frequency)) {
|
|
|
|
optimal.frequency = diff;
|
|
|
|
optimal.driver_data = i;
|
|
|
|
}
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2013-03-30 18:55:15 +08:00
|
|
|
if (optimal.driver_data > i) {
|
2016-06-03 13:28:51 +08:00
|
|
|
if (suboptimal.driver_data > i) {
|
|
|
|
WARN(1, "Invalid frequency table: %d\n", policy->cpu);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-06-03 13:28:51 +08:00
|
|
|
index = suboptimal.driver_data;
|
|
|
|
} else
|
|
|
|
index = optimal.driver_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-06-03 13:28:51 +08:00
|
|
|
pr_debug("target index is %u, freq is:%u kHz\n", index,
|
|
|
|
table[index].frequency);
|
|
|
|
return index;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2016-06-27 18:34:07 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpufreq_table_index_unsorted);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-12-03 13:50:46 +08:00
|
|
|
int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy,
|
|
|
|
unsigned int freq)
|
|
|
|
{
|
2016-06-03 13:28:47 +08:00
|
|
|
struct cpufreq_frequency_table *pos, *table = policy->freq_table;
|
2018-01-30 13:42:37 +08:00
|
|
|
int idx;
|
2013-12-03 13:50:46 +08:00
|
|
|
|
|
|
|
if (unlikely(!table)) {
|
|
|
|
pr_debug("%s: Unable to find frequency table\n", __func__);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2018-01-30 13:42:37 +08:00
|
|
|
cpufreq_for_each_valid_entry_idx(pos, table, idx)
|
2014-04-26 04:15:38 +08:00
|
|
|
if (pos->frequency == freq)
|
2018-01-30 13:42:37 +08:00
|
|
|
return idx;
|
2013-12-03 13:50:46 +08:00
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(cpufreq_frequency_table_get_index);
|
|
|
|
|
2020-07-15 16:26:22 +08:00
|
|
|
/*
|
2007-11-22 06:52:15 +08:00
|
|
|
* show_available_freqs - show available frequencies for the specified CPU
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2013-12-20 22:24:49 +08:00
|
|
|
static ssize_t show_available_freqs(struct cpufreq_policy *policy, char *buf,
|
|
|
|
bool show_boost)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
ssize_t count = 0;
|
2014-04-26 04:15:38 +08:00
|
|
|
struct cpufreq_frequency_table *pos, *table = policy->freq_table;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-03-10 17:23:33 +08:00
|
|
|
if (!table)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENODEV;
|
|
|
|
|
2014-04-26 04:15:38 +08:00
|
|
|
cpufreq_for_each_valid_entry(pos, table) {
|
2013-12-20 22:24:49 +08:00
|
|
|
/*
|
|
|
|
* show_boost = true and driver_data = BOOST freq
|
|
|
|
* display BOOST freqs
|
|
|
|
*
|
|
|
|
* show_boost = false and driver_data = BOOST freq
|
|
|
|
* show_boost = true and driver_data != BOOST freq
|
|
|
|
* continue - do not display anything
|
|
|
|
*
|
|
|
|
* show_boost = false and driver_data != BOOST freq
|
|
|
|
* display NON BOOST freqs
|
|
|
|
*/
|
2014-04-26 04:15:38 +08:00
|
|
|
if (show_boost ^ (pos->flags & CPUFREQ_BOOST_FREQ))
|
2013-12-20 22:24:49 +08:00
|
|
|
continue;
|
|
|
|
|
2014-04-26 04:15:38 +08:00
|
|
|
count += sprintf(&buf[count], "%d ", pos->frequency);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
count += sprintf(&buf[count], "\n");
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-12-20 22:24:49 +08:00
|
|
|
#define cpufreq_attr_available_freq(_name) \
|
|
|
|
struct freq_attr cpufreq_freq_attr_##_name##_freqs = \
|
|
|
|
__ATTR_RO(_name##_frequencies)
|
|
|
|
|
2020-07-15 16:26:22 +08:00
|
|
|
/*
|
2013-12-20 22:24:49 +08:00
|
|
|
* show_scaling_available_frequencies - show available normal frequencies for
|
|
|
|
* the specified CPU
|
|
|
|
*/
|
|
|
|
static ssize_t scaling_available_frequencies_show(struct cpufreq_policy *policy,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
return show_available_freqs(policy, buf, false);
|
|
|
|
}
|
|
|
|
cpufreq_attr_available_freq(scaling_available);
|
2005-04-17 06:20:36 +08:00
|
|
|
EXPORT_SYMBOL_GPL(cpufreq_freq_attr_scaling_available_freqs);
|
|
|
|
|
2020-07-15 16:26:22 +08:00
|
|
|
/*
|
2013-12-20 22:24:49 +08:00
|
|
|
* show_available_boost_freqs - show available boost frequencies for
|
|
|
|
* the specified CPU
|
|
|
|
*/
|
|
|
|
static ssize_t scaling_boost_frequencies_show(struct cpufreq_policy *policy,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
return show_available_freqs(policy, buf, true);
|
|
|
|
}
|
|
|
|
cpufreq_attr_available_freq(scaling_boost);
|
|
|
|
EXPORT_SYMBOL_GPL(cpufreq_freq_attr_scaling_boost_freqs);
|
|
|
|
|
2013-10-03 22:57:55 +08:00
|
|
|
struct freq_attr *cpufreq_generic_attr[] = {
|
|
|
|
&cpufreq_freq_attr_scaling_available_freqs,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(cpufreq_generic_attr);
|
|
|
|
|
2016-06-27 18:34:07 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-02-22 13:59:44 +08:00
|
|
|
int cpufreq_table_validate_and_sort(struct cpufreq_policy *policy)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!policy->freq_table)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = cpufreq_frequency_table_cpuinfo(policy, policy->freq_table);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return set_freq_table_sorted(policy);
|
|
|
|
}
|
|
|
|
|
2009-01-18 14:56:41 +08:00
|
|
|
MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>");
|
|
|
|
MODULE_DESCRIPTION("CPUfreq frequency table helpers");
|
|
|
|
MODULE_LICENSE("GPL");
|