Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/cpufreq/cpufreq_stats.c |
| 3 | * |
| 4 | * Copyright (C) 2003-2004 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>. |
Dave Jones | 0a829c5 | 2009-01-18 01:49:04 -0500 | [diff] [blame] | 5 | * (C) 2004 Zou Nan hai <nanhai.zou@intel.com>. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/cpu.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/cpufreq.h> |
Paul Gortmaker | 5c720d37 | 2011-05-27 13:23:32 -0400 | [diff] [blame] | 14 | #include <linux/module.h> |
Viresh Kumar | 5ff0a26 | 2013-08-06 22:53:03 +0530 | [diff] [blame] | 15 | #include <linux/slab.h> |
Frederic Weisbecker | bfc3f02 | 2014-03-05 16:33:42 +0100 | [diff] [blame] | 16 | #include <linux/cputime.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
Rafael J. Wysocki | 1aefc75 | 2016-05-31 22:14:44 +0200 | [diff] [blame] | 18 | static DEFINE_SPINLOCK(cpufreq_stats_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | struct cpufreq_stats { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | unsigned int total_trans; |
Viresh Kumar | bb176f7 | 2013-06-19 14:19:33 +0530 | [diff] [blame] | 22 | unsigned long long last_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | unsigned int max_state; |
| 24 | unsigned int state_num; |
| 25 | unsigned int last_index; |
Viresh Kumar | 1e7586a | 2012-10-26 00:51:21 +0200 | [diff] [blame] | 26 | u64 *time_in_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | unsigned int *freq_table; |
| 28 | #ifdef CONFIG_CPU_FREQ_STAT_DETAILS |
| 29 | unsigned int *trans_table; |
| 30 | #endif |
| 31 | }; |
| 32 | |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 33 | static int cpufreq_stats_update(struct cpufreq_stats *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { |
Viresh Kumar | 9531347 | 2015-01-06 21:09:03 +0530 | [diff] [blame] | 35 | unsigned long long cur_time = get_jiffies_64(); |
Venkatesh Pallipadi | 58f1df2 | 2005-05-25 14:46:50 -0700 | [diff] [blame] | 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | spin_lock(&cpufreq_stats_lock); |
Viresh Kumar | c960f9b | 2015-01-06 21:09:12 +0530 | [diff] [blame] | 38 | stats->time_in_state[stats->last_index] += cur_time - stats->last_time; |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 39 | stats->last_time = cur_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | spin_unlock(&cpufreq_stats_lock); |
| 41 | return 0; |
| 42 | } |
| 43 | |
Markus Mayer | ee7930e | 2016-11-07 10:02:23 -0800 | [diff] [blame] | 44 | static void cpufreq_stats_clear_table(struct cpufreq_stats *stats) |
| 45 | { |
| 46 | unsigned int count = stats->max_state; |
| 47 | |
| 48 | memset(stats->time_in_state, 0, count * sizeof(u64)); |
| 49 | #ifdef CONFIG_CPU_FREQ_STAT_DETAILS |
| 50 | memset(stats->trans_table, 0, count * count * sizeof(int)); |
| 51 | #endif |
| 52 | stats->last_time = get_jiffies_64(); |
| 53 | stats->total_trans = 0; |
| 54 | } |
| 55 | |
Dave Jones | 0a829c5 | 2009-01-18 01:49:04 -0500 | [diff] [blame] | 56 | static ssize_t show_total_trans(struct cpufreq_policy *policy, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
Viresh Kumar | a9aaf29 | 2015-01-13 11:34:00 +0530 | [diff] [blame] | 58 | return sprintf(buf, "%d\n", policy->stats->total_trans); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Dave Jones | 0a829c5 | 2009-01-18 01:49:04 -0500 | [diff] [blame] | 61 | static ssize_t show_time_in_state(struct cpufreq_policy *policy, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 63 | struct cpufreq_stats *stats = policy->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | ssize_t len = 0; |
| 65 | int i; |
Viresh Kumar | a9aaf29 | 2015-01-13 11:34:00 +0530 | [diff] [blame] | 66 | |
Rafael J. Wysocki | 1aefc75 | 2016-05-31 22:14:44 +0200 | [diff] [blame] | 67 | if (policy->fast_switch_enabled) |
| 68 | return 0; |
| 69 | |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 70 | cpufreq_stats_update(stats); |
| 71 | for (i = 0; i < stats->state_num; i++) { |
| 72 | len += sprintf(buf + len, "%u %llu\n", stats->freq_table[i], |
Dave Jones | 0a829c5 | 2009-01-18 01:49:04 -0500 | [diff] [blame] | 73 | (unsigned long long) |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 74 | jiffies_64_to_clock_t(stats->time_in_state[i])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } |
| 76 | return len; |
| 77 | } |
| 78 | |
Markus Mayer | ee7930e | 2016-11-07 10:02:23 -0800 | [diff] [blame] | 79 | static ssize_t store_reset(struct cpufreq_policy *policy, const char *buf, |
| 80 | size_t count) |
| 81 | { |
| 82 | /* We don't care what is written to the attribute. */ |
| 83 | cpufreq_stats_clear_table(policy->stats); |
| 84 | return count; |
| 85 | } |
| 86 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | #ifdef CONFIG_CPU_FREQ_STAT_DETAILS |
Dave Jones | 0a829c5 | 2009-01-18 01:49:04 -0500 | [diff] [blame] | 88 | static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 90 | struct cpufreq_stats *stats = policy->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | ssize_t len = 0; |
| 92 | int i, j; |
| 93 | |
Rafael J. Wysocki | 1aefc75 | 2016-05-31 22:14:44 +0200 | [diff] [blame] | 94 | if (policy->fast_switch_enabled) |
| 95 | return 0; |
| 96 | |
Venkatesh Pallipadi | 58f1df2 | 2005-05-25 14:46:50 -0700 | [diff] [blame] | 97 | len += snprintf(buf + len, PAGE_SIZE - len, " From : To\n"); |
| 98 | len += snprintf(buf + len, PAGE_SIZE - len, " : "); |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 99 | for (i = 0; i < stats->state_num; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | if (len >= PAGE_SIZE) |
| 101 | break; |
Venkatesh Pallipadi | 58f1df2 | 2005-05-25 14:46:50 -0700 | [diff] [blame] | 102 | len += snprintf(buf + len, PAGE_SIZE - len, "%9u ", |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 103 | stats->freq_table[i]); |
Venkatesh Pallipadi | 58f1df2 | 2005-05-25 14:46:50 -0700 | [diff] [blame] | 104 | } |
| 105 | if (len >= PAGE_SIZE) |
Cesar Eduardo Barros | 25aca34 | 2008-02-16 08:41:25 -0200 | [diff] [blame] | 106 | return PAGE_SIZE; |
Venkatesh Pallipadi | 58f1df2 | 2005-05-25 14:46:50 -0700 | [diff] [blame] | 107 | |
| 108 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 109 | |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 110 | for (i = 0; i < stats->state_num; i++) { |
Venkatesh Pallipadi | 58f1df2 | 2005-05-25 14:46:50 -0700 | [diff] [blame] | 111 | if (len >= PAGE_SIZE) |
| 112 | break; |
| 113 | |
| 114 | len += snprintf(buf + len, PAGE_SIZE - len, "%9u: ", |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 115 | stats->freq_table[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 117 | for (j = 0; j < stats->state_num; j++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | if (len >= PAGE_SIZE) |
| 119 | break; |
Venkatesh Pallipadi | 58f1df2 | 2005-05-25 14:46:50 -0700 | [diff] [blame] | 120 | len += snprintf(buf + len, PAGE_SIZE - len, "%9u ", |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 121 | stats->trans_table[i*stats->max_state+j]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } |
Cesar Eduardo Barros | 25aca34 | 2008-02-16 08:41:25 -0200 | [diff] [blame] | 123 | if (len >= PAGE_SIZE) |
| 124 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); |
| 126 | } |
Cesar Eduardo Barros | 25aca34 | 2008-02-16 08:41:25 -0200 | [diff] [blame] | 127 | if (len >= PAGE_SIZE) |
| 128 | return PAGE_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | return len; |
| 130 | } |
Viresh Kumar | df18e50 | 2013-02-04 11:38:52 +0000 | [diff] [blame] | 131 | cpufreq_freq_attr_ro(trans_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | #endif |
| 133 | |
Viresh Kumar | df18e50 | 2013-02-04 11:38:52 +0000 | [diff] [blame] | 134 | cpufreq_freq_attr_ro(total_trans); |
| 135 | cpufreq_freq_attr_ro(time_in_state); |
Markus Mayer | ee7930e | 2016-11-07 10:02:23 -0800 | [diff] [blame] | 136 | cpufreq_freq_attr_wo(reset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | static struct attribute *default_attrs[] = { |
Viresh Kumar | df18e50 | 2013-02-04 11:38:52 +0000 | [diff] [blame] | 139 | &total_trans.attr, |
| 140 | &time_in_state.attr, |
Markus Mayer | ee7930e | 2016-11-07 10:02:23 -0800 | [diff] [blame] | 141 | &reset.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | #ifdef CONFIG_CPU_FREQ_STAT_DETAILS |
Viresh Kumar | df18e50 | 2013-02-04 11:38:52 +0000 | [diff] [blame] | 143 | &trans_table.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | #endif |
| 145 | NULL |
| 146 | }; |
| 147 | static struct attribute_group stats_attr_group = { |
| 148 | .attrs = default_attrs, |
| 149 | .name = "stats" |
| 150 | }; |
| 151 | |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 152 | static int freq_table_get_index(struct cpufreq_stats *stats, unsigned int freq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | { |
| 154 | int index; |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 155 | for (index = 0; index < stats->max_state; index++) |
| 156 | if (stats->freq_table[index] == freq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | return index; |
| 158 | return -1; |
| 159 | } |
| 160 | |
Rafael J. Wysocki | 1aefc75 | 2016-05-31 22:14:44 +0200 | [diff] [blame] | 161 | void cpufreq_stats_free_table(struct cpufreq_policy *policy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | { |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 163 | struct cpufreq_stats *stats = policy->stats; |
Viresh Kumar | b8eed8a | 2013-01-14 13:23:03 +0000 | [diff] [blame] | 164 | |
Viresh Kumar | a9aaf29 | 2015-01-13 11:34:00 +0530 | [diff] [blame] | 165 | /* Already freed */ |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 166 | if (!stats) |
Viresh Kumar | 2d13594 | 2014-01-07 07:10:12 +0530 | [diff] [blame] | 167 | return; |
| 168 | |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 169 | pr_debug("%s: Free stats table\n", __func__); |
Viresh Kumar | 2d13594 | 2014-01-07 07:10:12 +0530 | [diff] [blame] | 170 | |
| 171 | sysfs_remove_group(&policy->kobj, &stats_attr_group); |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 172 | kfree(stats->time_in_state); |
| 173 | kfree(stats); |
Viresh Kumar | a9aaf29 | 2015-01-13 11:34:00 +0530 | [diff] [blame] | 174 | policy->stats = NULL; |
steven finney | 98586ed | 2011-05-02 11:29:17 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Rafael J. Wysocki | 1aefc75 | 2016-05-31 22:14:44 +0200 | [diff] [blame] | 177 | void cpufreq_stats_create_table(struct cpufreq_policy *policy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | { |
Viresh Kumar | a685c6d | 2015-01-06 21:09:11 +0530 | [diff] [blame] | 179 | unsigned int i = 0, count = 0, ret = -ENOMEM; |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 180 | struct cpufreq_stats *stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | unsigned int alloc_size; |
Stratos Karafotis | 041526f | 2014-04-25 23:15:38 +0300 | [diff] [blame] | 182 | struct cpufreq_frequency_table *pos, *table; |
Saravana Kannan | ad4c230 | 2014-02-27 17:58:36 -0800 | [diff] [blame] | 183 | |
Viresh Kumar | a685c6d | 2015-01-06 21:09:11 +0530 | [diff] [blame] | 184 | /* We need cpufreq table for creating stats table */ |
Viresh Kumar | f8bfc11 | 2016-06-03 10:58:47 +0530 | [diff] [blame] | 185 | table = policy->freq_table; |
Saravana Kannan | ad4c230 | 2014-02-27 17:58:36 -0800 | [diff] [blame] | 186 | if (unlikely(!table)) |
Rafael J. Wysocki | 1aefc75 | 2016-05-31 22:14:44 +0200 | [diff] [blame] | 187 | return; |
Saravana Kannan | ad4c230 | 2014-02-27 17:58:36 -0800 | [diff] [blame] | 188 | |
Viresh Kumar | b8c6744 | 2015-01-06 21:09:01 +0530 | [diff] [blame] | 189 | /* stats already initialized */ |
Viresh Kumar | a9aaf29 | 2015-01-13 11:34:00 +0530 | [diff] [blame] | 190 | if (policy->stats) |
Rafael J. Wysocki | 1aefc75 | 2016-05-31 22:14:44 +0200 | [diff] [blame] | 191 | return; |
Viresh Kumar | b8c6744 | 2015-01-06 21:09:01 +0530 | [diff] [blame] | 192 | |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 193 | stats = kzalloc(sizeof(*stats), GFP_KERNEL); |
Viresh Kumar | a685c6d | 2015-01-06 21:09:11 +0530 | [diff] [blame] | 194 | if (!stats) |
Rafael J. Wysocki | 1aefc75 | 2016-05-31 22:14:44 +0200 | [diff] [blame] | 195 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
Viresh Kumar | a685c6d | 2015-01-06 21:09:11 +0530 | [diff] [blame] | 197 | /* Find total allocation size */ |
Stratos Karafotis | 041526f | 2014-04-25 23:15:38 +0300 | [diff] [blame] | 198 | cpufreq_for_each_valid_entry(pos, table) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Viresh Kumar | 1e7586a | 2012-10-26 00:51:21 +0200 | [diff] [blame] | 201 | alloc_size = count * sizeof(int) + count * sizeof(u64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | #ifdef CONFIG_CPU_FREQ_STAT_DETAILS |
| 204 | alloc_size += count * count * sizeof(int); |
| 205 | #endif |
Viresh Kumar | a685c6d | 2015-01-06 21:09:11 +0530 | [diff] [blame] | 206 | |
| 207 | /* Allocate memory for time_in_state/freq_table/trans_table in one go */ |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 208 | stats->time_in_state = kzalloc(alloc_size, GFP_KERNEL); |
Viresh Kumar | a685c6d | 2015-01-06 21:09:11 +0530 | [diff] [blame] | 209 | if (!stats->time_in_state) |
| 210 | goto free_stat; |
| 211 | |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 212 | stats->freq_table = (unsigned int *)(stats->time_in_state + count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
| 214 | #ifdef CONFIG_CPU_FREQ_STAT_DETAILS |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 215 | stats->trans_table = stats->freq_table + count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | #endif |
Viresh Kumar | a685c6d | 2015-01-06 21:09:11 +0530 | [diff] [blame] | 217 | |
| 218 | stats->max_state = count; |
| 219 | |
| 220 | /* Find valid-unique entries */ |
Stratos Karafotis | 041526f | 2014-04-25 23:15:38 +0300 | [diff] [blame] | 221 | cpufreq_for_each_valid_entry(pos, table) |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 222 | if (freq_table_get_index(stats, pos->frequency) == -1) |
| 223 | stats->freq_table[i++] = pos->frequency; |
Viresh Kumar | a685c6d | 2015-01-06 21:09:11 +0530 | [diff] [blame] | 224 | |
Viresh Kumar | 490285c | 2015-01-06 21:09:15 +0530 | [diff] [blame] | 225 | stats->state_num = i; |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 226 | stats->last_time = get_jiffies_64(); |
| 227 | stats->last_index = freq_table_get_index(stats, policy->cur); |
Viresh Kumar | a685c6d | 2015-01-06 21:09:11 +0530 | [diff] [blame] | 228 | |
| 229 | policy->stats = stats; |
| 230 | ret = sysfs_create_group(&policy->kobj, &stats_attr_group); |
| 231 | if (!ret) |
Rafael J. Wysocki | 1aefc75 | 2016-05-31 22:14:44 +0200 | [diff] [blame] | 232 | return; |
Viresh Kumar | a685c6d | 2015-01-06 21:09:11 +0530 | [diff] [blame] | 233 | |
| 234 | /* We failed, release resources */ |
Viresh Kumar | a9aaf29 | 2015-01-13 11:34:00 +0530 | [diff] [blame] | 235 | policy->stats = NULL; |
Viresh Kumar | a685c6d | 2015-01-06 21:09:11 +0530 | [diff] [blame] | 236 | kfree(stats->time_in_state); |
| 237 | free_stat: |
| 238 | kfree(stats); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Rafael J. Wysocki | 1aefc75 | 2016-05-31 22:14:44 +0200 | [diff] [blame] | 241 | void cpufreq_stats_record_transition(struct cpufreq_policy *policy, |
| 242 | unsigned int new_freq) |
Viresh Kumar | b3f9ff8 | 2014-01-07 07:10:13 +0530 | [diff] [blame] | 243 | { |
Rafael J. Wysocki | 1aefc75 | 2016-05-31 22:14:44 +0200 | [diff] [blame] | 244 | struct cpufreq_stats *stats = policy->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | int old_index, new_index; |
| 246 | |
Rafael J. Wysocki | 1aefc75 | 2016-05-31 22:14:44 +0200 | [diff] [blame] | 247 | if (!stats) { |
Viresh Kumar | a9aaf29 | 2015-01-13 11:34:00 +0530 | [diff] [blame] | 248 | pr_debug("%s: No stats found\n", __func__); |
Rafael J. Wysocki | 1aefc75 | 2016-05-31 22:14:44 +0200 | [diff] [blame] | 249 | return; |
Viresh Kumar | a9aaf29 | 2015-01-13 11:34:00 +0530 | [diff] [blame] | 250 | } |
| 251 | |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 252 | old_index = stats->last_index; |
Rafael J. Wysocki | 1aefc75 | 2016-05-31 22:14:44 +0200 | [diff] [blame] | 253 | new_index = freq_table_get_index(stats, new_freq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 255 | /* We can't do stats->time_in_state[-1]= .. */ |
Rafael J. Wysocki | 1aefc75 | 2016-05-31 22:14:44 +0200 | [diff] [blame] | 256 | if (old_index == -1 || new_index == -1 || old_index == new_index) |
| 257 | return; |
Venkatesh Pallipadi | 8edc59d9 | 2006-12-19 12:58:55 -0800 | [diff] [blame] | 258 | |
Viresh Kumar | e734769 | 2015-01-06 21:09:14 +0530 | [diff] [blame] | 259 | cpufreq_stats_update(stats); |
| 260 | |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 261 | stats->last_index = new_index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | #ifdef CONFIG_CPU_FREQ_STAT_DETAILS |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 263 | stats->trans_table[old_index * stats->max_state + new_index]++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | #endif |
Viresh Kumar | 5094160 | 2015-01-06 21:09:07 +0530 | [diff] [blame] | 265 | stats->total_trans++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | } |