Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1431892
| From | Francesco Lavra <francescolavra.fl@gmail.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH V5 1/2] cpufreq: Handle sorted frequency tables more efficiently |
| Date | 2016-06-27 12:20 +0200 |
| Message-ID | <rOBO2-7lH-11@gated-at.bofh.it> (permalink) |
| References | <rOwlk-3O5-13@gated-at.bofh.it> <rOwuZ-3Rt-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Hi,
On 06/27/2016 06:29 AM, Viresh Kumar wrote:
> 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.
<snip>
> @@ -610,6 +617,227 @@ int cpufreq_boost_trigger_state(int state);
> int cpufreq_boost_enabled(void);
> int cpufreq_enable_boost_support(void);
> bool policy_has_boost_freq(struct cpufreq_policy *policy);
> +
> +/* Find lowest freq at or above target in a table in ascending order */
> +static inline int cpufreq_table_find_index_al(struct cpufreq_policy *policy,
> + unsigned int target_freq)
> +{
> + struct cpufreq_frequency_table *table = policy->freq_table;
> + unsigned int freq;
> + int i, best = -1;
> +
> + for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {
> + freq = table[i].frequency;
> +
> + if (freq >= target_freq)
> + return i;
> +
> + best = i;
> + }
> +
> + return best;
> +}
> +
> +/* Find lowest freq at or above target in a table in descending order */
> +static inline int cpufreq_table_find_index_dl(struct cpufreq_policy *policy,
> + unsigned int target_freq)
> +{
> + struct cpufreq_frequency_table *table = policy->freq_table;
> + unsigned int freq;
> + int i, best = -1;
> +
> + for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {
> + freq = table[i].frequency;
> +
> + if (freq == target_freq)
> + return i;
> +
> + if (freq > target_freq) {
> + best = i;
> + continue;
> + }
> +
> + /* No freq found below target_freq */
"below" should be "above"
> +/* Find closest freq to target in a table in ascending order */
> +static inline int cpufreq_table_find_index_ac(struct cpufreq_policy *policy,
> + unsigned int target_freq)
> +{
> + struct cpufreq_frequency_table *table = policy->freq_table;
> + unsigned int freq;
> + int i, best = -1;
> +
> + for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {
> + freq = table[i].frequency;
> +
> + if (freq == target_freq)
> + return i;
> +
> + if (freq < target_freq) {
> + best = i;
> + continue;
> + }
> +
> + /* No freq found below target_freq */
> + if (best == -1)
> + return i;
> +
> + /* Choose the closest freq */
> + if (target_freq - table[best].frequency > freq - target_freq)
> + return i;
> +
> + return best;
> + }
> +
> + return best;
> +}
> +
> +/* Find closest freq to target in a table in descending order */
> +static inline int cpufreq_table_find_index_dc(struct cpufreq_policy *policy,
> + unsigned int target_freq)
> +{
> + struct cpufreq_frequency_table *table = policy->freq_table;
> + unsigned int freq;
> + int i, best = -1;
> +
> + for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {
> + freq = table[i].frequency;
> +
> + if (freq == target_freq)
> + return i;
> +
> + if (freq > target_freq) {
> + best = i;
> + continue;
> + }
> +
> + /* No freq found below target_freq */
"below" should be "above"
> + if (best == -1)
> + return i;
> +
> + /* Choose the closest freq */
> + if (target_freq - table[best].frequency > freq - target_freq)
Here, table[best].frequency > target_freq, and freq < and target_freq,
so you should reverse the sign of both sides of the inequation:
if (table[best].frequency - target_freq > target_freq - freq)
> + return i;
> +
> + return best;
> + }
> +
> + return best;
> +}
Regards,
Francesco
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH V5 0/2] cpufreq: Sorted policy->freq_table Viresh Kumar <viresh.kumar@linaro.org> - 2016-06-27 06:30 +0200
[PATCH V5 2/2] cpufreq: Reuse new freq-table helpers Viresh Kumar <viresh.kumar@linaro.org> - 2016-06-27 06:40 +0200
Re: [PATCH V5 2/2] cpufreq: Reuse new freq-table helpers "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2016-07-07 15:30 +0200
[PATCH V5 1/2] cpufreq: Handle sorted frequency tables more efficiently Viresh Kumar <viresh.kumar@linaro.org> - 2016-06-27 06:40 +0200
Re: [PATCH V5 1/2] cpufreq: Handle sorted frequency tables more efficiently Francesco Lavra <francescolavra.fl@gmail.com> - 2016-06-27 12:20 +0200
[PATCH V6 1/2] cpufreq: Handle sorted frequency tables more efficiently Viresh Kumar <viresh.kumar@linaro.org> - 2016-06-27 12:40 +0200
Re: [PATCH V6 1/2] cpufreq: Handle sorted frequency tables more efficiently "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2016-07-07 15:30 +0200
Re: [PATCH V5 0/2] cpufreq: Sorted policy->freq_table Viresh Kumar <viresh.kumar@linaro.org> - 2016-07-07 17:40 +0200
csiph-web