aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDominik Brodowski <linux@dominikbrodowski.net>2011-04-19 13:58:59 -0400
committerDominik Brodowski <linux@dominikbrodowski.net>2011-07-29 12:35:38 -0400
commitb510b54127a4d4112a9a3f200339719bcb463c15 (patch)
tree172dda3d580231b00b92b19ed41766ec18693739 /tools
parent6c2b8185517fea46bdb1e4e70c7005901fcc89ab (diff)
cpupowerutils: idle_monitor - ConfigStyle bugfixes
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Diffstat (limited to 'tools')
-rw-r--r--tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c20
-rw-r--r--tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c65
-rw-r--r--tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c64
-rw-r--r--tools/power/cpupower/utils/idle_monitor/mperf_monitor.c33
-rw-r--r--tools/power/cpupower/utils/idle_monitor/nhm_idle.c30
-rw-r--r--tools/power/cpupower/utils/idle_monitor/snb_idle.c31
6 files changed, 128 insertions, 115 deletions
diff --git a/tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c b/tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c
index 3de94322dfb8..202e555988be 100644
--- a/tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c
+++ b/tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c
@@ -104,7 +104,7 @@ static int amd_fam14h_get_pci_info(struct cstate *state,
104 unsigned int *enable_bit, 104 unsigned int *enable_bit,
105 unsigned int cpu) 105 unsigned int cpu)
106{ 106{
107 switch(state->id) { 107 switch (state->id) {
108 case NON_PC0: 108 case NON_PC0:
109 *enable_bit = PCI_NON_PC0_ENABLE_BIT; 109 *enable_bit = PCI_NON_PC0_ENABLE_BIT;
110 *pci_offset = PCI_NON_PC0_OFFSET; 110 *pci_offset = PCI_NON_PC0_OFFSET;
@@ -177,7 +177,7 @@ static int amd_fam14h_disable(cstate_t *state, unsigned int cpu)
177 /* was the bit whether NBP1 got entered set? */ 177 /* was the bit whether NBP1 got entered set? */
178 nbp1_entered = (val & (1 << PCI_NBP1_ACTIVE_BIT)) | 178 nbp1_entered = (val & (1 << PCI_NBP1_ACTIVE_BIT)) |
179 (val & (1 << PCI_NBP1_ENTERED_BIT)); 179 (val & (1 << PCI_NBP1_ENTERED_BIT));
180 180
181 dprint("NBP1 was %sentered - 0x%x - enable_bit: " 181 dprint("NBP1 was %sentered - 0x%x - enable_bit: "
182 "%d - pci_offset: 0x%x\n", 182 "%d - pci_offset: 0x%x\n",
183 nbp1_entered ? "" : "not ", 183 nbp1_entered ? "" : "not ",
@@ -214,7 +214,7 @@ static int fam14h_get_count_percent(unsigned int id, double *percent,
214 unsigned int cpu) 214 unsigned int cpu)
215{ 215{
216 unsigned long diff; 216 unsigned long diff;
217 217
218 if (id >= AMD_FAM14H_STATE_NUM) 218 if (id >= AMD_FAM14H_STATE_NUM)
219 return -1; 219 return -1;
220 /* residency count in 80ns -> divide through 12.5 to get us residency */ 220 /* residency count in 80ns -> divide through 12.5 to get us residency */
@@ -236,9 +236,8 @@ static int amd_fam14h_start(void)
236 int num, cpu; 236 int num, cpu;
237 clock_gettime(CLOCK_REALTIME, &start_time); 237 clock_gettime(CLOCK_REALTIME, &start_time);
238 for (num = 0; num < AMD_FAM14H_STATE_NUM; num++) { 238 for (num = 0; num < AMD_FAM14H_STATE_NUM; num++) {
239 for (cpu = 0; cpu < cpu_count; cpu++) { 239 for (cpu = 0; cpu < cpu_count; cpu++)
240 amd_fam14h_init(&amd_fam14h_cstates[num], cpu); 240 amd_fam14h_init(&amd_fam14h_cstates[num], cpu);
241 }
242 } 241 }
243#ifdef DEBUG 242#ifdef DEBUG
244 clock_gettime(CLOCK_REALTIME, &dbg_time); 243 clock_gettime(CLOCK_REALTIME, &dbg_time);
@@ -257,9 +256,8 @@ static int amd_fam14h_stop(void)
257 clock_gettime(CLOCK_REALTIME, &end_time); 256 clock_gettime(CLOCK_REALTIME, &end_time);
258 257
259 for (num = 0; num < AMD_FAM14H_STATE_NUM; num++) { 258 for (num = 0; num < AMD_FAM14H_STATE_NUM; num++) {
260 for (cpu = 0; cpu < cpu_count; cpu++) { 259 for (cpu = 0; cpu < cpu_count; cpu++)
261 amd_fam14h_disable(&amd_fam14h_cstates[num], cpu); 260 amd_fam14h_disable(&amd_fam14h_cstates[num], cpu);
262 }
263 } 261 }
264#ifdef DEBUG 262#ifdef DEBUG
265 clock_gettime(CLOCK_REALTIME, &dbg_time); 263 clock_gettime(CLOCK_REALTIME, &dbg_time);
@@ -281,8 +279,8 @@ static int is_nbp1_capable(void)
281 return val & (1 << 31); 279 return val & (1 << 31);
282} 280}
283 281
284struct cpuidle_monitor* amd_fam14h_register(void) { 282struct cpuidle_monitor *amd_fam14h_register(void)
285 283{
286 int num; 284 int num;
287 285
288 if (cpupower_cpu_info.vendor != X86_VENDOR_AMD) 286 if (cpupower_cpu_info.vendor != X86_VENDOR_AMD)
@@ -299,9 +297,9 @@ struct cpuidle_monitor* amd_fam14h_register(void) {
299 297
300 /* We do not alloc for nbp1 machine wide counter */ 298 /* We do not alloc for nbp1 machine wide counter */
301 for (num = 0; num < AMD_FAM14H_STATE_NUM - 1; num++) { 299 for (num = 0; num < AMD_FAM14H_STATE_NUM - 1; num++) {
302 previous_count[num] = calloc (cpu_count, 300 previous_count[num] = calloc(cpu_count,
303 sizeof(unsigned long long)); 301 sizeof(unsigned long long));
304 current_count[num] = calloc (cpu_count, 302 current_count[num] = calloc(cpu_count,
305 sizeof(unsigned long long)); 303 sizeof(unsigned long long));
306 } 304 }
307 305
diff --git a/tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c b/tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c
index 63f6d670517b..d048b96a6155 100644
--- a/tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c
+++ b/tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c
@@ -36,10 +36,10 @@ static int cpuidle_get_count_percent(unsigned int id, double *percent,
36 *percent = 0.0; 36 *percent = 0.0;
37 else 37 else
38 *percent = ((100.0 * statediff) / timediff); 38 *percent = ((100.0 * statediff) / timediff);
39 39
40 dprint("%s: - timediff: %llu - statediff: %llu - percent: %f (%u)\n", 40 dprint("%s: - timediff: %llu - statediff: %llu - percent: %f (%u)\n",
41 cpuidle_cstates[id].name, timediff, statediff, *percent, cpu); 41 cpuidle_cstates[id].name, timediff, statediff, *percent, cpu);
42 42
43 return 0; 43 return 0;
44} 44}
45 45
@@ -55,7 +55,6 @@ static int cpuidle_start(void)
55 dprint("CPU %d - State: %d - Val: %llu\n", 55 dprint("CPU %d - State: %d - Val: %llu\n",
56 cpu, state, previous_count[cpu][state]); 56 cpu, state, previous_count[cpu][state]);
57 } 57 }
58
59 }; 58 };
60 return 0; 59 return 0;
61} 60}
@@ -83,40 +82,51 @@ void fix_up_intel_idle_driver_name(char *tmp, int num)
83{ 82{
84 /* fix up cpuidle name for intel idle driver */ 83 /* fix up cpuidle name for intel idle driver */
85 if (!strncmp(tmp, "NHM-", 4)) { 84 if (!strncmp(tmp, "NHM-", 4)) {
86 switch(num) { 85 switch (num) {
87 case 1: strcpy(tmp, "C1"); 86 case 1:
87 strcpy(tmp, "C1");
88 break; 88 break;
89 case 2: strcpy(tmp, "C3"); 89 case 2:
90 strcpy(tmp, "C3");
90 break; 91 break;
91 case 3: strcpy(tmp, "C6"); 92 case 3:
93 strcpy(tmp, "C6");
92 break; 94 break;
93 } 95 }
94 } else if (!strncmp(tmp, "SNB-", 4)) { 96 } else if (!strncmp(tmp, "SNB-", 4)) {
95 switch(num) { 97 switch (num) {
96 case 1: strcpy(tmp, "C1"); 98 case 1:
99 strcpy(tmp, "C1");
97 break; 100 break;
98 case 2: strcpy(tmp, "C3"); 101 case 2:
102 strcpy(tmp, "C3");
99 break; 103 break;
100 case 3: strcpy(tmp, "C6"); 104 case 3:
105 strcpy(tmp, "C6");
101 break; 106 break;
102 case 4: strcpy(tmp, "C7"); 107 case 4:
108 strcpy(tmp, "C7");
103 break; 109 break;
104 } 110 }
105 } else if (!strncmp(tmp, "ATM-", 4)) { 111 } else if (!strncmp(tmp, "ATM-", 4)) {
106 switch(num) { 112 switch (num) {
107 case 1: strcpy(tmp, "C1"); 113 case 1:
114 strcpy(tmp, "C1");
108 break; 115 break;
109 case 2: strcpy(tmp, "C2"); 116 case 2:
117 strcpy(tmp, "C2");
110 break; 118 break;
111 case 3: strcpy(tmp, "C4"); 119 case 3:
120 strcpy(tmp, "C4");
112 break; 121 break;
113 case 4: strcpy(tmp, "C6"); 122 case 4:
123 strcpy(tmp, "C6");
114 break; 124 break;
115 } 125 }
116 } 126 }
117} 127}
118 128
119static struct cpuidle_monitor* cpuidle_register(void) 129static struct cpuidle_monitor *cpuidle_register(void)
120{ 130{
121 int num; 131 int num;
122 char *tmp; 132 char *tmp;
@@ -127,7 +137,7 @@ static struct cpuidle_monitor* cpuidle_register(void)
127 if (cpuidle_sysfs_monitor.hw_states_num == 0) 137 if (cpuidle_sysfs_monitor.hw_states_num == 0)
128 return NULL; 138 return NULL;
129 139
130 for (num = 0; num < cpuidle_sysfs_monitor.hw_states_num; num ++) { 140 for (num = 0; num < cpuidle_sysfs_monitor.hw_states_num; num++) {
131 tmp = sysfs_get_idlestate_name(0, num); 141 tmp = sysfs_get_idlestate_name(0, num);
132 if (tmp == NULL) 142 if (tmp == NULL)
133 continue; 143 continue;
@@ -144,17 +154,18 @@ static struct cpuidle_monitor* cpuidle_register(void)
144 154
145 cpuidle_cstates[num].range = RANGE_THREAD; 155 cpuidle_cstates[num].range = RANGE_THREAD;
146 cpuidle_cstates[num].id = num; 156 cpuidle_cstates[num].id = num;
147 cpuidle_cstates[num].get_count_percent = cpuidle_get_count_percent; 157 cpuidle_cstates[num].get_count_percent =
148 }; 158 cpuidle_get_count_percent;
159 };
149 160
150 /* Free this at program termination */ 161 /* Free this at program termination */
151 previous_count = malloc(sizeof (long long*) * cpu_count); 162 previous_count = malloc(sizeof(long long *) * cpu_count);
152 current_count = malloc(sizeof (long long*) * cpu_count); 163 current_count = malloc(sizeof(long long *) * cpu_count);
153 for (num = 0; num < cpu_count; num++) { 164 for (num = 0; num < cpu_count; num++) {
154 previous_count[num] = malloc (sizeof(long long) * 165 previous_count[num] = malloc(sizeof(long long) *
155 cpuidle_sysfs_monitor.hw_states_num); 166 cpuidle_sysfs_monitor.hw_states_num);
156 current_count[num] = malloc (sizeof(long long) * 167 current_count[num] = malloc(sizeof(long long) *
157 cpuidle_sysfs_monitor.hw_states_num); 168 cpuidle_sysfs_monitor.hw_states_num);
158 } 169 }
159 170
160 cpuidle_sysfs_monitor.name_len = strlen(cpuidle_sysfs_monitor.name); 171 cpuidle_sysfs_monitor.name_len = strlen(cpuidle_sysfs_monitor.name);
diff --git a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c
index 3e96e79de3c2..ba4bf068380d 100644
--- a/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c
+++ b/tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c
@@ -24,7 +24,7 @@
24 24
25/* Define pointers to all monitors. */ 25/* Define pointers to all monitors. */
26#define DEF(x) & x ## _monitor , 26#define DEF(x) & x ## _monitor ,
27struct cpuidle_monitor * all_monitors[] = { 27struct cpuidle_monitor *all_monitors[] = {
28#include "idle_monitors.def" 28#include "idle_monitors.def"
290 290
30}; 30};
@@ -76,19 +76,19 @@ void print_n_spaces(int n)
76 int x; 76 int x;
77 for (x = 0; x < n; x++) 77 for (x = 0; x < n; x++)
78 printf(" "); 78 printf(" ");
79} 79}
80 80
81/* size of s must be at least n + 1 */ 81/* size of s must be at least n + 1 */
82int fill_string_with_spaces(char *s, int n) 82int fill_string_with_spaces(char *s, int n)
83{ 83{
84 int len = strlen(s); 84 int len = strlen(s);
85 if (len > n) 85 if (len > n)
86 return -1; 86 return -1;
87 for (; len < n; len++) 87 for (; len < n; len++)
88 s[len] = ' '; 88 s[len] = ' ';
89 s[len] = '\0'; 89 s[len] = '\0';
90 return 0; 90 return 0;
91} 91}
92 92
93void print_header(int topology_depth) 93void print_header(int topology_depth)
94{ 94{
@@ -107,7 +107,7 @@ void print_header(int topology_depth)
107 - 1; 107 - 1;
108 if (mon != 0) { 108 if (mon != 0) {
109 printf("|| "); 109 printf("|| ");
110 need_len --; 110 need_len--;
111 } 111 }
112 sprintf(buf, "%s", monitors[mon]->name); 112 sprintf(buf, "%s", monitors[mon]->name);
113 fill_string_with_spaces(buf, need_len); 113 fill_string_with_spaces(buf, need_len);
@@ -169,26 +169,24 @@ void print_results(int topology_depth, int cpu)
169 if (s.get_count_percent) { 169 if (s.get_count_percent) {
170 ret = s.get_count_percent(s.id, &percent, 170 ret = s.get_count_percent(s.id, &percent,
171 cpu_top.core_info[cpu].cpu); 171 cpu_top.core_info[cpu].cpu);
172 if (ret) { 172 if (ret)
173 printf("******"); 173 printf("******");
174 } else if (percent >= 100.0) 174 else if (percent >= 100.0)
175 printf("%6.1f", percent); 175 printf("%6.1f", percent);
176 else 176 else
177 printf("%6.2f", percent); 177 printf("%6.2f", percent);
178 } 178 } else if (s.get_count) {
179 else if (s.get_count) {
180 ret = s.get_count(s.id, &result, 179 ret = s.get_count(s.id, &result,
181 cpu_top.core_info[cpu].cpu); 180 cpu_top.core_info[cpu].cpu);
182 if (ret) { 181 if (ret)
183 printf("******"); 182 printf("******");
184 } else 183 else
185 printf("%6llu", result); 184 printf("%6llu", result);
186 } 185 } else {
187 else {
188 printf(_("Monitor %s, Counter %s has no count " 186 printf(_("Monitor %s, Counter %s has no count "
189 "function. Implementation error\n"), 187 "function. Implementation error\n"),
190 monitors[mon]->name, s.name); 188 monitors[mon]->name, s.name);
191 exit (EXIT_FAILURE); 189 exit(EXIT_FAILURE);
192 } 190 }
193 } 191 }
194 } 192 }
@@ -211,7 +209,7 @@ void print_results(int topology_depth, int cpu)
211 * Monitors get sorted in the same order the user passes them 209 * Monitors get sorted in the same order the user passes them
212*/ 210*/
213 211
214static void parse_monitor_param(char* param) 212static void parse_monitor_param(char *param)
215{ 213{
216 unsigned int num; 214 unsigned int num;
217 int mon, hits = 0; 215 int mon, hits = 0;
@@ -219,7 +217,7 @@ static void parse_monitor_param(char* param)
219 struct cpuidle_monitor *tmp_mons[MONITORS_MAX]; 217 struct cpuidle_monitor *tmp_mons[MONITORS_MAX];
220 218
221 219
222 for (mon = 0; mon < MONITORS_MAX;mon++, tmp = NULL) { 220 for (mon = 0; mon < MONITORS_MAX; mon++, tmp = NULL) {
223 token = strtok(tmp, ","); 221 token = strtok(tmp, ",");
224 if (token == NULL) 222 if (token == NULL)
225 break; 223 break;
@@ -235,7 +233,7 @@ static void parse_monitor_param(char* param)
235 tmp_mons[hits] = monitors[num]; 233 tmp_mons[hits] = monitors[num];
236 hits++; 234 hits++;
237 } 235 }
238 } 236 }
239 } 237 }
240 if (hits == 0) { 238 if (hits == 0) {
241 printf(_("No matching monitor found in %s, " 239 printf(_("No matching monitor found in %s, "
@@ -244,20 +242,23 @@ static void parse_monitor_param(char* param)
244 exit(EXIT_FAILURE); 242 exit(EXIT_FAILURE);
245 } 243 }
246 /* Override detected/registerd monitors array with requested one */ 244 /* Override detected/registerd monitors array with requested one */
247 memcpy(monitors, tmp_mons, sizeof(struct cpuidle_monitor*) * MONITORS_MAX); 245 memcpy(monitors, tmp_mons,
246 sizeof(struct cpuidle_monitor *) * MONITORS_MAX);
248 avail_monitors = hits; 247 avail_monitors = hits;
249} 248}
250 249
251void list_monitors(void) { 250void list_monitors(void)
251{
252 unsigned int mon; 252 unsigned int mon;
253 int state; 253 int state;
254 cstate_t s; 254 cstate_t s;
255 255
256 for (mon = 0; mon < avail_monitors; mon++) { 256 for (mon = 0; mon < avail_monitors; mon++) {
257 printf(_("Monitor \"%s\" (%d states) - Might overflow after %u " 257 printf(_("Monitor \"%s\" (%d states) - Might overflow after %u "
258 "s\n"), monitors[mon]->name, monitors[mon]->hw_states_num, 258 "s\n"),
259 monitors[mon]->overflow_s); 259 monitors[mon]->name, monitors[mon]->hw_states_num,
260 260 monitors[mon]->overflow_s);
261
261 for (state = 0; state < monitors[mon]->hw_states_num; state++) { 262 for (state = 0; state < monitors[mon]->hw_states_num; state++) {
262 s = monitors[mon]->hw_states[state]; 263 s = monitors[mon]->hw_states[state];
263 /* 264 /*
@@ -308,7 +309,8 @@ int fork_it(char **argv)
308 timediff = timespec_diff_us(start, end); 309 timediff = timespec_diff_us(start, end);
309 if (WIFEXITED(status)) 310 if (WIFEXITED(status))
310 printf(_("%s took %.5f seconds and exited with status %d\n"), 311 printf(_("%s took %.5f seconds and exited with status %d\n"),
311 argv[0], timediff / (1000.0 * 1000), WEXITSTATUS(status)); 312 argv[0], timediff / (1000.0 * 1000),
313 WEXITSTATUS(status));
312 return 0; 314 return 0;
313} 315}
314 316
@@ -322,9 +324,9 @@ int do_interval_measure(int i)
322 monitors[num]->start(); 324 monitors[num]->start();
323 } 325 }
324 sleep(i); 326 sleep(i);
325 for (num = 0; num < avail_monitors; num++) { 327 for (num = 0; num < avail_monitors; num++)
326 monitors[num]->stop(); 328 monitors[num]->stop();
327 } 329
328 return 0; 330 return 0;
329} 331}
330 332
@@ -384,7 +386,7 @@ int cmd_monitor(int argc, char **argv)
384 } 386 }
385 387
386 dprint("System has up to %d CPU cores\n", cpu_count); 388 dprint("System has up to %d CPU cores\n", cpu_count);
387 389
388 for (num = 0; all_monitors[num]; num++) { 390 for (num = 0; all_monitors[num]; num++) {
389 dprint("Try to register: %s\n", all_monitors[num]->name); 391 dprint("Try to register: %s\n", all_monitors[num]->name);
390 test_mon = all_monitors[num]->do_register(); 392 test_mon = all_monitors[num]->do_register();
@@ -438,9 +440,9 @@ int cmd_monitor(int argc, char **argv)
438 print_results(1, cpu); 440 print_results(1, cpu);
439 } 441 }
440 442
441 for (num = 0; num < avail_monitors; num++) { 443 for (num = 0; num < avail_monitors; num++)
442 monitors[num]->unregister(); 444 monitors[num]->unregister();
443 } 445
444 cpu_topology_release(cpu_top); 446 cpu_topology_release(cpu_top);
445 return 0; 447 return 0;
446} 448}
diff --git a/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c b/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c
index f8545e40e232..63ca87a05e5f 100644
--- a/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c
+++ b/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c
@@ -79,7 +79,7 @@ static int mperf_init_stats(unsigned int cpu)
79 ret |= read_msr(cpu, MSR_MPERF, &val); 79 ret |= read_msr(cpu, MSR_MPERF, &val);
80 mperf_previous_count[cpu] = val; 80 mperf_previous_count[cpu] = val;
81 is_valid[cpu] = !ret; 81 is_valid[cpu] = !ret;
82 82
83 return 0; 83 return 0;
84} 84}
85 85
@@ -93,7 +93,7 @@ static int mperf_measure_stats(unsigned int cpu)
93 ret |= read_msr(cpu, MSR_MPERF, &val); 93 ret |= read_msr(cpu, MSR_MPERF, &val);
94 mperf_current_count[cpu] = val; 94 mperf_current_count[cpu] = val;
95 is_valid[cpu] = !ret; 95 is_valid[cpu] = !ret;
96 96
97 return 0; 97 return 0;
98} 98}
99 99
@@ -145,14 +145,14 @@ static int mperf_get_count_percent(unsigned int id, double *percent,
145 if (id == Cx) 145 if (id == Cx)
146 *percent = 100.0 - *percent; 146 *percent = 100.0 - *percent;
147 147
148 dprint("%s: previous: %llu - current: %llu - (%u)\n", mperf_cstates[id].name, 148 dprint("%s: previous: %llu - current: %llu - (%u)\n",
149 mperf_diff, aperf_diff, cpu); 149 mperf_cstates[id].name, mperf_diff, aperf_diff, cpu);
150 dprint("%s: %f\n", mperf_cstates[id].name, *percent); 150 dprint("%s: %f\n", mperf_cstates[id].name, *percent);
151 return 0; 151 return 0;
152} 152}
153 153
154static int mperf_get_count_freq(unsigned int id, unsigned long long *count, 154static int mperf_get_count_freq(unsigned int id, unsigned long long *count,
155 unsigned int cpu) 155 unsigned int cpu)
156{ 156{
157 unsigned long long aperf_diff, mperf_diff; 157 unsigned long long aperf_diff, mperf_diff;
158 158
@@ -206,8 +206,8 @@ static int mperf_stop(void)
206 206
207struct cpuidle_monitor mperf_monitor; 207struct cpuidle_monitor mperf_monitor;
208 208
209struct cpuidle_monitor* mperf_register(void) { 209struct cpuidle_monitor *mperf_register(void)
210 210{
211 unsigned long min; 211 unsigned long min;
212 212
213 if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_APERF)) 213 if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_APERF))
@@ -221,21 +221,18 @@ struct cpuidle_monitor* mperf_register(void) {
221 } 221 }
222 222
223 /* Free this at program termination */ 223 /* Free this at program termination */
224 is_valid = calloc(cpu_count, sizeof (int)); 224 is_valid = calloc(cpu_count, sizeof(int));
225 mperf_previous_count = calloc (cpu_count, 225 mperf_previous_count = calloc(cpu_count, sizeof(unsigned long long));
226 sizeof(unsigned long long)); 226 aperf_previous_count = calloc(cpu_count, sizeof(unsigned long long));
227 aperf_previous_count = calloc (cpu_count, 227 mperf_current_count = calloc(cpu_count, sizeof(unsigned long long));
228 sizeof(unsigned long long)); 228 aperf_current_count = calloc(cpu_count, sizeof(unsigned long long));
229 mperf_current_count = calloc (cpu_count, 229
230 sizeof(unsigned long long));
231 aperf_current_count = calloc (cpu_count,
232 sizeof(unsigned long long));
233
234 mperf_monitor.name_len = strlen(mperf_monitor.name); 230 mperf_monitor.name_len = strlen(mperf_monitor.name);
235 return &mperf_monitor; 231 return &mperf_monitor;
236} 232}
237 233
238void mperf_unregister(void) { 234void mperf_unregister(void)
235{
239 free(mperf_previous_count); 236 free(mperf_previous_count);
240 free(aperf_previous_count); 237 free(aperf_previous_count);
241 free(mperf_current_count); 238 free(mperf_current_count);
diff --git a/tools/power/cpupower/utils/idle_monitor/nhm_idle.c b/tools/power/cpupower/utils/idle_monitor/nhm_idle.c
index 6424b6dd3fa5..d2a91dd0d563 100644
--- a/tools/power/cpupower/utils/idle_monitor/nhm_idle.c
+++ b/tools/power/cpupower/utils/idle_monitor/nhm_idle.c
@@ -69,11 +69,12 @@ static unsigned long long *current_count[NHM_CSTATE_COUNT];
69/* valid flag for all CPUs. If a MSR read failed it will be zero */ 69/* valid flag for all CPUs. If a MSR read failed it will be zero */
70static int *is_valid; 70static int *is_valid;
71 71
72static int nhm_get_count(enum intel_nhm_id id, unsigned long long *val, unsigned int cpu) 72static int nhm_get_count(enum intel_nhm_id id, unsigned long long *val,
73 unsigned int cpu)
73{ 74{
74 int msr; 75 int msr;
75 76
76 switch(id) { 77 switch (id) {
77 case C3: 78 case C3:
78 msr = MSR_CORE_C3_RESIDENCY; 79 msr = MSR_CORE_C3_RESIDENCY;
79 break; 80 break;
@@ -106,12 +107,13 @@ static int nhm_get_count_percent(unsigned int id, double *percent,
106 if (!is_valid[cpu]) 107 if (!is_valid[cpu])
107 return -1; 108 return -1;
108 109
109 *percent = (100.0 * (current_count[id][cpu] - previous_count[id][cpu])) / 110 *percent = (100.0 *
111 (current_count[id][cpu] - previous_count[id][cpu])) /
110 (tsc_at_measure_end - tsc_at_measure_start); 112 (tsc_at_measure_end - tsc_at_measure_start);
111 113
112 dprint("%s: previous: %llu - current: %llu - (%u)\n", nhm_cstates[id].name, 114 dprint("%s: previous: %llu - current: %llu - (%u)\n",
113 previous_count[id][cpu], current_count[id][cpu], 115 nhm_cstates[id].name, previous_count[id][cpu],
114 cpu); 116 current_count[id][cpu], cpu);
115 117
116 dprint("%s: tsc_diff: %llu - count_diff: %llu - percent: %2.f (%u)\n", 118 dprint("%s: tsc_diff: %llu - count_diff: %llu - percent: %2.f (%u)\n",
117 nhm_cstates[id].name, 119 nhm_cstates[id].name,
@@ -162,7 +164,8 @@ static int nhm_stop(void)
162 164
163struct cpuidle_monitor intel_nhm_monitor; 165struct cpuidle_monitor intel_nhm_monitor;
164 166
165struct cpuidle_monitor* intel_nhm_register(void) { 167struct cpuidle_monitor *intel_nhm_register(void)
168{
166 int num; 169 int num;
167 170
168 if (cpupower_cpu_info.vendor != X86_VENDOR_INTEL) 171 if (cpupower_cpu_info.vendor != X86_VENDOR_INTEL)
@@ -175,19 +178,20 @@ struct cpuidle_monitor* intel_nhm_register(void) {
175 return NULL; 178 return NULL;
176 179
177 /* Free this at program termination */ 180 /* Free this at program termination */
178 is_valid = calloc(cpu_count, sizeof (int)); 181 is_valid = calloc(cpu_count, sizeof(int));
179 for (num = 0; num < NHM_CSTATE_COUNT; num++) { 182 for (num = 0; num < NHM_CSTATE_COUNT; num++) {
180 previous_count[num] = calloc (cpu_count, 183 previous_count[num] = calloc(cpu_count,
181 sizeof(unsigned long long)); 184 sizeof(unsigned long long));
182 current_count[num] = calloc (cpu_count, 185 current_count[num] = calloc(cpu_count,
183 sizeof(unsigned long long)); 186 sizeof(unsigned long long));
184 } 187 }
185 188
186 intel_nhm_monitor.name_len = strlen(intel_nhm_monitor.name); 189 intel_nhm_monitor.name_len = strlen(intel_nhm_monitor.name);
187 return &intel_nhm_monitor; 190 return &intel_nhm_monitor;
188} 191}
189 192
190void intel_nhm_unregister(void) { 193void intel_nhm_unregister(void)
194{
191 int num; 195 int num;
192 196
193 for (num = 0; num < NHM_CSTATE_COUNT; num++) { 197 for (num = 0; num < NHM_CSTATE_COUNT; num++) {
diff --git a/tools/power/cpupower/utils/idle_monitor/snb_idle.c b/tools/power/cpupower/utils/idle_monitor/snb_idle.c
index 8cc80a5b530c..a1bc07cd53e1 100644
--- a/tools/power/cpupower/utils/idle_monitor/snb_idle.c
+++ b/tools/power/cpupower/utils/idle_monitor/snb_idle.c
@@ -58,11 +58,12 @@ static unsigned long long *current_count[SNB_CSTATE_COUNT];
58/* valid flag for all CPUs. If a MSR read failed it will be zero */ 58/* valid flag for all CPUs. If a MSR read failed it will be zero */
59static int *is_valid; 59static int *is_valid;
60 60
61static int snb_get_count(enum intel_snb_id id, unsigned long long *val, unsigned int cpu) 61static int snb_get_count(enum intel_snb_id id, unsigned long long *val,
62 unsigned int cpu)
62{ 63{
63 int msr; 64 int msr;
64 65
65 switch(id) { 66 switch (id) {
66 case C7: 67 case C7:
67 msr = MSR_CORE_C7_RESIDENCY; 68 msr = MSR_CORE_C7_RESIDENCY;
68 break; 69 break;
@@ -91,18 +92,18 @@ static int snb_get_count_percent(unsigned int id, double *percent,
91 if (!is_valid[cpu]) 92 if (!is_valid[cpu])
92 return -1; 93 return -1;
93 94
94 *percent = (100.0 * (current_count[id][cpu] - previous_count[id][cpu])) / 95 *percent = (100.0 *
96 (current_count[id][cpu] - previous_count[id][cpu])) /
95 (tsc_at_measure_end - tsc_at_measure_start); 97 (tsc_at_measure_end - tsc_at_measure_start);
96 98
97 dprint("%s: previous: %llu - current: %llu - (%u)\n", snb_cstates[id].name, 99 dprint("%s: previous: %llu - current: %llu - (%u)\n",
98 previous_count[id][cpu], current_count[id][cpu], 100 snb_cstates[id].name, previous_count[id][cpu],
99 cpu); 101 current_count[id][cpu], cpu);
100 102
101 dprint("%s: tsc_diff: %llu - count_diff: %llu - percent: %2.f (%u)\n", 103 dprint("%s: tsc_diff: %llu - count_diff: %llu - percent: %2.f (%u)\n",
102 snb_cstates[id].name, 104 snb_cstates[id].name,
103 (unsigned long long) tsc_at_measure_end - tsc_at_measure_start, 105 (unsigned long long) tsc_at_measure_end - tsc_at_measure_start,
104 current_count[id][cpu] 106 current_count[id][cpu] - previous_count[id][cpu],
105 - previous_count[id][cpu],
106 *percent, cpu); 107 *percent, cpu);
107 108
108 return 0; 109 return 0;
@@ -141,8 +142,8 @@ static int snb_stop(void)
141 142
142struct cpuidle_monitor intel_snb_monitor; 143struct cpuidle_monitor intel_snb_monitor;
143 144
144static struct cpuidle_monitor* snb_register(void) { 145static struct cpuidle_monitor *snb_register(void)
145 146{
146 int num; 147 int num;
147 148
148 if (cpupower_cpu_info.vendor != X86_VENDOR_INTEL 149 if (cpupower_cpu_info.vendor != X86_VENDOR_INTEL
@@ -153,12 +154,12 @@ static struct cpuidle_monitor* snb_register(void) {
153 && cpupower_cpu_info.model != 0x2D) 154 && cpupower_cpu_info.model != 0x2D)
154 return NULL; 155 return NULL;
155 156
156 is_valid = calloc(cpu_count, sizeof (int)); 157 is_valid = calloc(cpu_count, sizeof(int));
157 for (num = 0; num < SNB_CSTATE_COUNT; num++) { 158 for (num = 0; num < SNB_CSTATE_COUNT; num++) {
158 previous_count[num] = calloc (cpu_count, 159 previous_count[num] = calloc(cpu_count,
159 sizeof(unsigned long long)); 160 sizeof(unsigned long long));
160 current_count[num] = calloc (cpu_count, 161 current_count[num] = calloc(cpu_count,
161 sizeof(unsigned long long)); 162 sizeof(unsigned long long));
162 } 163 }
163 intel_snb_monitor.name_len = strlen(intel_snb_monitor.name); 164 intel_snb_monitor.name_len = strlen(intel_snb_monitor.name);
164 return &intel_snb_monitor; 165 return &intel_snb_monitor;