diff options
Diffstat (limited to 'tools/power/x86/turbostat/turbostat.c')
-rw-r--r-- | tools/power/x86/turbostat/turbostat.c | 90 |
1 files changed, 62 insertions, 28 deletions
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 310d3dd5e547..6436d54378c7 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * turbostat -- show CPU frequency and C-state residency | 2 | * turbostat -- show CPU frequency and C-state residency |
3 | * on modern Intel turbo-capable processors. | 3 | * on modern Intel turbo-capable processors. |
4 | * | 4 | * |
5 | * Copyright (c) 2010, Intel Corporation. | 5 | * Copyright (c) 2012 Intel Corporation. |
6 | * Len Brown <len.brown@intel.com> | 6 | * Len Brown <len.brown@intel.com> |
7 | * | 7 | * |
8 | * This program is free software; you can redistribute it and/or modify it | 8 | * This program is free software; you can redistribute it and/or modify it |
@@ -49,6 +49,7 @@ | |||
49 | char *proc_stat = "/proc/stat"; | 49 | char *proc_stat = "/proc/stat"; |
50 | unsigned int interval_sec = 5; /* set with -i interval_sec */ | 50 | unsigned int interval_sec = 5; /* set with -i interval_sec */ |
51 | unsigned int verbose; /* set with -v */ | 51 | unsigned int verbose; /* set with -v */ |
52 | unsigned int summary_only; /* set with -s */ | ||
52 | unsigned int skip_c0; | 53 | unsigned int skip_c0; |
53 | unsigned int skip_c1; | 54 | unsigned int skip_c1; |
54 | unsigned int do_nhm_cstates; | 55 | unsigned int do_nhm_cstates; |
@@ -129,14 +130,18 @@ void print_header(void) | |||
129 | { | 130 | { |
130 | if (show_pkg) | 131 | if (show_pkg) |
131 | fprintf(stderr, "pk"); | 132 | fprintf(stderr, "pk"); |
133 | if (show_pkg) | ||
134 | fprintf(stderr, " "); | ||
132 | if (show_core) | 135 | if (show_core) |
133 | fprintf(stderr, " cr"); | 136 | fprintf(stderr, "cor"); |
134 | if (show_cpu) | 137 | if (show_cpu) |
135 | fprintf(stderr, " CPU"); | 138 | fprintf(stderr, " CPU"); |
139 | if (show_pkg || show_core || show_cpu) | ||
140 | fprintf(stderr, " "); | ||
136 | if (do_nhm_cstates) | 141 | if (do_nhm_cstates) |
137 | fprintf(stderr, " %%c0 "); | 142 | fprintf(stderr, " %%c0"); |
138 | if (has_aperf) | 143 | if (has_aperf) |
139 | fprintf(stderr, " GHz"); | 144 | fprintf(stderr, " GHz"); |
140 | fprintf(stderr, " TSC"); | 145 | fprintf(stderr, " TSC"); |
141 | if (do_nhm_cstates) | 146 | if (do_nhm_cstates) |
142 | fprintf(stderr, " %%c1"); | 147 | fprintf(stderr, " %%c1"); |
@@ -147,13 +152,13 @@ void print_header(void) | |||
147 | if (do_snb_cstates) | 152 | if (do_snb_cstates) |
148 | fprintf(stderr, " %%c7"); | 153 | fprintf(stderr, " %%c7"); |
149 | if (do_snb_cstates) | 154 | if (do_snb_cstates) |
150 | fprintf(stderr, " %%pc2"); | 155 | fprintf(stderr, " %%pc2"); |
151 | if (do_nhm_cstates) | 156 | if (do_nhm_cstates) |
152 | fprintf(stderr, " %%pc3"); | 157 | fprintf(stderr, " %%pc3"); |
153 | if (do_nhm_cstates) | 158 | if (do_nhm_cstates) |
154 | fprintf(stderr, " %%pc6"); | 159 | fprintf(stderr, " %%pc6"); |
155 | if (do_snb_cstates) | 160 | if (do_snb_cstates) |
156 | fprintf(stderr, " %%pc7"); | 161 | fprintf(stderr, " %%pc7"); |
157 | if (extra_msr_offset) | 162 | if (extra_msr_offset) |
158 | fprintf(stderr, " MSR 0x%x ", extra_msr_offset); | 163 | fprintf(stderr, " MSR 0x%x ", extra_msr_offset); |
159 | 164 | ||
@@ -187,6 +192,15 @@ void dump_list(struct counters *cnt) | |||
187 | dump_cnt(cnt); | 192 | dump_cnt(cnt); |
188 | } | 193 | } |
189 | 194 | ||
195 | /* | ||
196 | * column formatting convention & formats | ||
197 | * package: "pk" 2 columns %2d | ||
198 | * core: "cor" 3 columns %3d | ||
199 | * CPU: "CPU" 3 columns %3d | ||
200 | * GHz: "GHz" 3 columns %3.2 | ||
201 | * TSC: "TSC" 3 columns %3.2 | ||
202 | * percentage " %pc3" %6.2 | ||
203 | */ | ||
190 | void print_cnt(struct counters *p) | 204 | void print_cnt(struct counters *p) |
191 | { | 205 | { |
192 | double interval_float; | 206 | double interval_float; |
@@ -196,39 +210,45 @@ void print_cnt(struct counters *p) | |||
196 | /* topology columns, print blanks on 1st (average) line */ | 210 | /* topology columns, print blanks on 1st (average) line */ |
197 | if (p == cnt_average) { | 211 | if (p == cnt_average) { |
198 | if (show_pkg) | 212 | if (show_pkg) |
213 | fprintf(stderr, " "); | ||
214 | if (show_pkg && show_core) | ||
199 | fprintf(stderr, " "); | 215 | fprintf(stderr, " "); |
200 | if (show_core) | 216 | if (show_core) |
201 | fprintf(stderr, " "); | 217 | fprintf(stderr, " "); |
202 | if (show_cpu) | 218 | if (show_cpu) |
203 | fprintf(stderr, " "); | 219 | fprintf(stderr, " " " "); |
204 | } else { | 220 | } else { |
205 | if (show_pkg) | 221 | if (show_pkg) |
206 | fprintf(stderr, "%d", p->pkg); | 222 | fprintf(stderr, "%2d", p->pkg); |
223 | if (show_pkg && show_core) | ||
224 | fprintf(stderr, " "); | ||
207 | if (show_core) | 225 | if (show_core) |
208 | fprintf(stderr, "%4d", p->core); | 226 | fprintf(stderr, "%3d", p->core); |
209 | if (show_cpu) | 227 | if (show_cpu) |
210 | fprintf(stderr, "%4d", p->cpu); | 228 | fprintf(stderr, " %3d", p->cpu); |
211 | } | 229 | } |
212 | 230 | ||
213 | /* %c0 */ | 231 | /* %c0 */ |
214 | if (do_nhm_cstates) { | 232 | if (do_nhm_cstates) { |
233 | if (show_pkg || show_core || show_cpu) | ||
234 | fprintf(stderr, " "); | ||
215 | if (!skip_c0) | 235 | if (!skip_c0) |
216 | fprintf(stderr, "%7.2f", 100.0 * p->mperf/p->tsc); | 236 | fprintf(stderr, "%6.2f", 100.0 * p->mperf/p->tsc); |
217 | else | 237 | else |
218 | fprintf(stderr, " ****"); | 238 | fprintf(stderr, " ****"); |
219 | } | 239 | } |
220 | 240 | ||
221 | /* GHz */ | 241 | /* GHz */ |
222 | if (has_aperf) { | 242 | if (has_aperf) { |
223 | if (!aperf_mperf_unstable) { | 243 | if (!aperf_mperf_unstable) { |
224 | fprintf(stderr, "%5.2f", | 244 | fprintf(stderr, " %3.2f", |
225 | 1.0 * p->tsc / units * p->aperf / | 245 | 1.0 * p->tsc / units * p->aperf / |
226 | p->mperf / interval_float); | 246 | p->mperf / interval_float); |
227 | } else { | 247 | } else { |
228 | if (p->aperf > p->tsc || p->mperf > p->tsc) { | 248 | if (p->aperf > p->tsc || p->mperf > p->tsc) { |
229 | fprintf(stderr, " ****"); | 249 | fprintf(stderr, " ***"); |
230 | } else { | 250 | } else { |
231 | fprintf(stderr, "%4.1f*", | 251 | fprintf(stderr, "%3.1f*", |
232 | 1.0 * p->tsc / | 252 | 1.0 * p->tsc / |
233 | units * p->aperf / | 253 | units * p->aperf / |
234 | p->mperf / interval_float); | 254 | p->mperf / interval_float); |
@@ -241,7 +261,7 @@ void print_cnt(struct counters *p) | |||
241 | 261 | ||
242 | if (do_nhm_cstates) { | 262 | if (do_nhm_cstates) { |
243 | if (!skip_c1) | 263 | if (!skip_c1) |
244 | fprintf(stderr, "%7.2f", 100.0 * p->c1/p->tsc); | 264 | fprintf(stderr, " %6.2f", 100.0 * p->c1/p->tsc); |
245 | else | 265 | else |
246 | fprintf(stderr, " ****"); | 266 | fprintf(stderr, " ****"); |
247 | } | 267 | } |
@@ -252,13 +272,13 @@ void print_cnt(struct counters *p) | |||
252 | if (do_snb_cstates) | 272 | if (do_snb_cstates) |
253 | fprintf(stderr, " %6.2f", 100.0 * p->c7/p->tsc); | 273 | fprintf(stderr, " %6.2f", 100.0 * p->c7/p->tsc); |
254 | if (do_snb_cstates) | 274 | if (do_snb_cstates) |
255 | fprintf(stderr, " %5.2f", 100.0 * p->pc2/p->tsc); | 275 | fprintf(stderr, " %6.2f", 100.0 * p->pc2/p->tsc); |
256 | if (do_nhm_cstates) | 276 | if (do_nhm_cstates) |
257 | fprintf(stderr, " %5.2f", 100.0 * p->pc3/p->tsc); | 277 | fprintf(stderr, " %6.2f", 100.0 * p->pc3/p->tsc); |
258 | if (do_nhm_cstates) | 278 | if (do_nhm_cstates) |
259 | fprintf(stderr, " %5.2f", 100.0 * p->pc6/p->tsc); | 279 | fprintf(stderr, " %6.2f", 100.0 * p->pc6/p->tsc); |
260 | if (do_snb_cstates) | 280 | if (do_snb_cstates) |
261 | fprintf(stderr, " %5.2f", 100.0 * p->pc7/p->tsc); | 281 | fprintf(stderr, " %6.2f", 100.0 * p->pc7/p->tsc); |
262 | if (extra_msr_offset) | 282 | if (extra_msr_offset) |
263 | fprintf(stderr, " 0x%016llx", p->extra_msr); | 283 | fprintf(stderr, " 0x%016llx", p->extra_msr); |
264 | putc('\n', stderr); | 284 | putc('\n', stderr); |
@@ -267,12 +287,20 @@ void print_cnt(struct counters *p) | |||
267 | void print_counters(struct counters *counters) | 287 | void print_counters(struct counters *counters) |
268 | { | 288 | { |
269 | struct counters *cnt; | 289 | struct counters *cnt; |
290 | static int printed; | ||
270 | 291 | ||
271 | print_header(); | 292 | |
293 | if (!printed || !summary_only) | ||
294 | print_header(); | ||
272 | 295 | ||
273 | if (num_cpus > 1) | 296 | if (num_cpus > 1) |
274 | print_cnt(cnt_average); | 297 | print_cnt(cnt_average); |
275 | 298 | ||
299 | printed = 1; | ||
300 | |||
301 | if (summary_only) | ||
302 | return; | ||
303 | |||
276 | for (cnt = counters; cnt != NULL; cnt = cnt->next) | 304 | for (cnt = counters; cnt != NULL; cnt = cnt->next) |
277 | print_cnt(cnt); | 305 | print_cnt(cnt); |
278 | 306 | ||
@@ -557,7 +585,8 @@ void insert_counters(struct counters **list, | |||
557 | return; | 585 | return; |
558 | } | 586 | } |
559 | 587 | ||
560 | show_cpu = 1; /* there is more than one CPU */ | 588 | if (!summary_only) |
589 | show_cpu = 1; /* there is more than one CPU */ | ||
561 | 590 | ||
562 | /* | 591 | /* |
563 | * insert on front of list. | 592 | * insert on front of list. |
@@ -575,13 +604,15 @@ void insert_counters(struct counters **list, | |||
575 | 604 | ||
576 | while (prev->next && (prev->next->pkg < new->pkg)) { | 605 | while (prev->next && (prev->next->pkg < new->pkg)) { |
577 | prev = prev->next; | 606 | prev = prev->next; |
578 | show_pkg = 1; /* there is more than 1 package */ | 607 | if (!summary_only) |
608 | show_pkg = 1; /* there is more than 1 package */ | ||
579 | } | 609 | } |
580 | 610 | ||
581 | while (prev->next && (prev->next->pkg == new->pkg) | 611 | while (prev->next && (prev->next->pkg == new->pkg) |
582 | && (prev->next->core < new->core)) { | 612 | && (prev->next->core < new->core)) { |
583 | prev = prev->next; | 613 | prev = prev->next; |
584 | show_core = 1; /* there is more than 1 core */ | 614 | if (!summary_only) |
615 | show_core = 1; /* there is more than 1 core */ | ||
585 | } | 616 | } |
586 | 617 | ||
587 | while (prev->next && (prev->next->pkg == new->pkg) | 618 | while (prev->next && (prev->next->pkg == new->pkg) |
@@ -1005,8 +1036,11 @@ void cmdline(int argc, char **argv) | |||
1005 | 1036 | ||
1006 | progname = argv[0]; | 1037 | progname = argv[0]; |
1007 | 1038 | ||
1008 | while ((opt = getopt(argc, argv, "+vi:M:")) != -1) { | 1039 | while ((opt = getopt(argc, argv, "+svi:M:")) != -1) { |
1009 | switch (opt) { | 1040 | switch (opt) { |
1041 | case 's': | ||
1042 | summary_only++; | ||
1043 | break; | ||
1010 | case 'v': | 1044 | case 'v': |
1011 | verbose++; | 1045 | verbose++; |
1012 | break; | 1046 | break; |