diff options
author | Peter Boonstoppel <pboonstoppel@nvidia.com> | 2011-08-18 15:24:12 -0700 |
---|---|---|
committer | Niket Sirsi <nsirsi@nvidia.com> | 2011-08-22 17:45:47 -0700 |
commit | f4a2d50cfa45dfd8c3dc71d8190ad2802bec4329 (patch) | |
tree | 24baf67ec29063b8a38c7790aa040af8ff4aa683 | |
parent | 8be8be6967e1a11193ae63e00ab07ee2000a6ba1 (diff) |
cpufreq: stats: snap freq to next lower freq when not in table
When cpu runs at frequency not in cpufreq table (because of other
frequency governing mechanisms), bill time spent at that frequency to
next lower frequency in cpufreq stats table.
Change-Id: I9cfda4e7a223ca3f773f1adb145d242483209799
Reviewed-on: http://git-master/r/47929
Reviewed-by: Peter Boonstoppel <pboonstoppel@nvidia.com>
Tested-by: Peter Boonstoppel <pboonstoppel@nvidia.com>
Tested-by: Diwakar Tundlam <dtundlam@nvidia.com>
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>
Reviewed-by: Scott Williams <scwilliams@nvidia.com>
-rw-r--r-- | drivers/cpufreq/cpufreq_stats.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index f47a549ce03a..8aebde517c22 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c @@ -159,10 +159,10 @@ static struct attribute_group stats_attr_group = { static int freq_table_get_index(struct cpufreq_stats *stat, unsigned int freq) { int index; - for (index = 0; index < stat->max_state; index++) - if (stat->freq_table[index] == freq) - return index; - return -1; + for (index = 0; index < stat->state_num; index++) + if (stat->freq_table[index] > freq) + break; + return index - 1; /* below lowest freq in table: return -1 */ } static void cpufreq_stats_free_table(unsigned int cpu) @@ -183,7 +183,7 @@ static void cpufreq_stats_free_table(unsigned int cpu) static int cpufreq_stats_create_table(struct cpufreq_policy *policy, struct cpufreq_frequency_table *table) { - unsigned int i, j, count = 0, ret = 0; + unsigned int i, j, k, l, count = 0, ret = 0; struct cpufreq_stats *stat; struct cpufreq_policy *data; unsigned int alloc_size; @@ -235,8 +235,16 @@ static int cpufreq_stats_create_table(struct cpufreq_policy *policy, unsigned int freq = table[i].frequency; if (freq == CPUFREQ_ENTRY_INVALID) continue; - if (freq_table_get_index(stat, freq) == -1) - stat->freq_table[j++] = freq; + + /* Insert in sorted stat->freq_table */ + for (k = 0; k < j && stat->freq_table[k] < freq; k++) + ; + if (stat->freq_table[k] == freq) + continue; + for (l = j; l > k; l--) + stat->freq_table[l] = stat->freq_table[l - 1]; + stat->freq_table[k] = freq; + j++; } stat->state_num = j; spin_lock(&cpufreq_stats_lock); |