Many drivers keep frequencies in frequency table in ascending
or descending order. When governor tries to change to policy->min
or policy->max respectively then the cpufreq_frequency_table_target
could return on first iteration. This will save some iteration cycles.
So, break out early when a frequency in cpufreq_frequency_table
equals to target one.
Testing this during kernel compilation using ondemand governor
with a frequency table in ascending order, the
cpufreq_frequency_table_target returned early on the first
iteration at about 30% of times called.
Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
                i = pos - table;
                if ((freq < policy->min) || (freq > policy->max))
                        continue;
+               if (freq == target_freq) {
+                       optimal.driver_data = i;
+                       break;
+               }
                switch (relation) {
                case CPUFREQ_RELATION_H:
-                       if (freq <= target_freq) {
+                       if (freq < target_freq) {
                                if (freq >= optimal.frequency) {
                                        optimal.frequency = freq;
                                        optimal.driver_data = i;
                        }
                        break;
                case CPUFREQ_RELATION_L:
-                       if (freq >= target_freq) {
+                       if (freq > target_freq) {
                                if (freq <= optimal.frequency) {
                                        optimal.frequency = freq;
                                        optimal.driver_data = i;