[PATCH] cpufreq-stats driver updates

Changes to the cpufreq stats driver:
* Changes the way P-state transition table looks in /sysfs providing more
clear output
* Changes the time unit in the output from HZ to clock_t

Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
Signed-off-by: Dave Jones <davej@redhat.com>

authored by

Venkatesh Pallipadi and committed by
Dave Jones
58f1df25 f94ea640

+30 -17
+30 -17
drivers/cpufreq/cpufreq_stats.c
··· 19 19 #include <linux/percpu.h> 20 20 #include <linux/kobject.h> 21 21 #include <linux/spinlock.h> 22 + #include <asm/cputime.h> 22 23 23 24 static spinlock_t cpufreq_stats_lock; 24 25 ··· 30 29 .show = _show,\ 31 30 }; 32 31 33 - static unsigned long 34 - delta_time(unsigned long old, unsigned long new) 35 - { 36 - return (old > new) ? (old - new): (new + ~old + 1); 37 - } 38 - 39 32 struct cpufreq_stats { 40 33 unsigned int cpu; 41 34 unsigned int total_trans; 42 - unsigned long long last_time; 35 + unsigned long long last_time; 43 36 unsigned int max_state; 44 37 unsigned int state_num; 45 38 unsigned int last_index; 46 - unsigned long long *time_in_state; 39 + cputime64_t *time_in_state; 47 40 unsigned int *freq_table; 48 41 #ifdef CONFIG_CPU_FREQ_STAT_DETAILS 49 42 unsigned int *trans_table; ··· 55 60 cpufreq_stats_update (unsigned int cpu) 56 61 { 57 62 struct cpufreq_stats *stat; 63 + unsigned long long cur_time; 64 + 65 + cur_time = get_jiffies_64(); 58 66 spin_lock(&cpufreq_stats_lock); 59 67 stat = cpufreq_stats_table[cpu]; 60 68 if (stat->time_in_state) 61 - stat->time_in_state[stat->last_index] += 62 - delta_time(stat->last_time, jiffies); 63 - stat->last_time = jiffies; 69 + stat->time_in_state[stat->last_index] = 70 + cputime64_add(stat->time_in_state[stat->last_index], 71 + cputime_sub(cur_time, stat->last_time)); 72 + stat->last_time = cur_time; 64 73 spin_unlock(&cpufreq_stats_lock); 65 74 return 0; 66 75 } ··· 89 90 return 0; 90 91 cpufreq_stats_update(stat->cpu); 91 92 for (i = 0; i < stat->state_num; i++) { 92 - len += sprintf(buf + len, "%u %llu\n", 93 - stat->freq_table[i], stat->time_in_state[i]); 93 + len += sprintf(buf + len, "%u %llu\n", stat->freq_table[i], 94 + (unsigned long long)cputime64_to_clock_t(stat->time_in_state[i])); 94 95 } 95 96 return len; 96 97 } ··· 106 107 if(!stat) 107 108 return 0; 108 109 cpufreq_stats_update(stat->cpu); 110 + len += snprintf(buf + len, PAGE_SIZE - len, " From : To\n"); 111 + len += snprintf(buf + len, PAGE_SIZE - len, " : "); 109 112 for (i = 0; i < stat->state_num; i++) { 110 113 if (len >= PAGE_SIZE) 111 114 break; 112 - len += snprintf(buf + len, PAGE_SIZE - len, "%9u:\t", 115 + len += snprintf(buf + len, PAGE_SIZE - len, "%9u ", 116 + stat->freq_table[i]); 117 + } 118 + if (len >= PAGE_SIZE) 119 + return len; 120 + 121 + len += snprintf(buf + len, PAGE_SIZE - len, "\n"); 122 + 123 + for (i = 0; i < stat->state_num; i++) { 124 + if (len >= PAGE_SIZE) 125 + break; 126 + 127 + len += snprintf(buf + len, PAGE_SIZE - len, "%9u: ", 113 128 stat->freq_table[i]); 114 129 115 130 for (j = 0; j < stat->state_num; j++) { 116 131 if (len >= PAGE_SIZE) 117 132 break; 118 - len += snprintf(buf + len, PAGE_SIZE - len, "%u\t", 133 + len += snprintf(buf + len, PAGE_SIZE - len, "%9u ", 119 134 stat->trans_table[i*stat->max_state+j]); 120 135 } 121 136 len += snprintf(buf + len, PAGE_SIZE - len, "\n"); ··· 210 197 count++; 211 198 } 212 199 213 - alloc_size = count * sizeof(int) + count * sizeof(long long); 200 + alloc_size = count * sizeof(int) + count * sizeof(cputime64_t); 214 201 215 202 #ifdef CONFIG_CPU_FREQ_STAT_DETAILS 216 203 alloc_size += count * count * sizeof(int); ··· 237 224 } 238 225 stat->state_num = j; 239 226 spin_lock(&cpufreq_stats_lock); 240 - stat->last_time = jiffies; 227 + stat->last_time = get_jiffies_64(); 241 228 stat->last_index = freq_table_get_index(stat, policy->cur); 242 229 spin_unlock(&cpufreq_stats_lock); 243 230 cpufreq_cpu_put(data);