When collecting stats, if a frequency doesn't match the table, go through
the table again with both the search frequency and table values shifted
left by 10 bits.

Signed-off-by: Mark Langsdorf <[email protected]>
Cc: MyungJoo Ham <[email protected]>
---
Changes from v3, v2
        None
Changes from v1:
        Implemented a simple round-up algorithm instead of the over/under
method that could cause errors on Intel processors with boost mode.

 drivers/cpufreq/cpufreq_stats.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index 3998316..30aee36 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -161,6 +161,9 @@ static int freq_table_get_index(struct cpufreq_stats *stat, 
unsigned int freq)
        for (index = 0; index < stat->max_state; index++)
                if (stat->freq_table[index] == freq)
                        return index;
+       for (index = 0; index < stat->max_state; index++)
+               if ((stat->freq_table[index] >> 10) == (freq >> 10))
+                       return index;
        return -1;
 }
 
@@ -251,6 +254,8 @@ static int cpufreq_stats_create_table(struct cpufreq_policy 
*policy,
        spin_lock(&cpufreq_stats_lock);
        stat->last_time = get_jiffies_64();
        stat->last_index = freq_table_get_index(stat, policy->cur);
+       if (stat->last_index > stat->max_state)
+               stat->last_index = stat->max_state - 1;
        spin_unlock(&cpufreq_stats_lock);
        cpufreq_cpu_put(data);
        return 0;
-- 
1.7.11.7

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to