turbostat.c (7483d45f0aee3afc0646d185cabd4af9f6cab58c) | turbostat.c (e23da0370f80834e971142e50253f5b79be83631) |
---|---|
1/* 2 * turbostat -- show CPU frequency and C-state residency 3 * on modern Intel turbo-capable processors. 4 * | 1/* 2 * turbostat -- show CPU frequency and C-state residency 3 * on modern Intel turbo-capable processors. 4 * |
5 * Copyright (c) 2010, Intel Corporation. | 5 * Copyright (c) 2012 Intel Corporation. |
6 * Len Brown <len.brown@intel.com> 7 * 8 * This program is free software; you can redistribute it and/or modify it 9 * under the terms and conditions of the GNU General Public License, 10 * version 2, as published by the Free Software Foundation. 11 * 12 * This program is distributed in the hope it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or --- 30 unchanged lines hidden (view full) --- 44#define MSR_PKG_C7_RESIDENCY 0x3FA /* SNB only */ 45#define MSR_CORE_C3_RESIDENCY 0x3FC 46#define MSR_CORE_C6_RESIDENCY 0x3FD 47#define MSR_CORE_C7_RESIDENCY 0x3FE /* SNB only */ 48 49char *proc_stat = "/proc/stat"; 50unsigned int interval_sec = 5; /* set with -i interval_sec */ 51unsigned int verbose; /* set with -v */ | 6 * Len Brown <len.brown@intel.com> 7 * 8 * This program is free software; you can redistribute it and/or modify it 9 * under the terms and conditions of the GNU General Public License, 10 * version 2, as published by the Free Software Foundation. 11 * 12 * This program is distributed in the hope it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or --- 30 unchanged lines hidden (view full) --- 44#define MSR_PKG_C7_RESIDENCY 0x3FA /* SNB only */ 45#define MSR_CORE_C3_RESIDENCY 0x3FC 46#define MSR_CORE_C6_RESIDENCY 0x3FD 47#define MSR_CORE_C7_RESIDENCY 0x3FE /* SNB only */ 48 49char *proc_stat = "/proc/stat"; 50unsigned int interval_sec = 5; /* set with -i interval_sec */ 51unsigned int verbose; /* set with -v */ |
52unsigned int summary_only; /* set with -s */ |
|
52unsigned int skip_c0; 53unsigned int skip_c1; 54unsigned int do_nhm_cstates; 55unsigned int do_snb_cstates; 56unsigned int has_aperf; 57unsigned int units = 1000000000; /* Ghz etc */ 58unsigned int genuine_intel; 59unsigned int has_invariant_tsc; --- 64 unchanged lines hidden (view full) --- 124 close(fd); 125 return msr; 126} 127 128void print_header(void) 129{ 130 if (show_pkg) 131 fprintf(stderr, "pk"); | 53unsigned int skip_c0; 54unsigned int skip_c1; 55unsigned int do_nhm_cstates; 56unsigned int do_snb_cstates; 57unsigned int has_aperf; 58unsigned int units = 1000000000; /* Ghz etc */ 59unsigned int genuine_intel; 60unsigned int has_invariant_tsc; --- 64 unchanged lines hidden (view full) --- 125 close(fd); 126 return msr; 127} 128 129void print_header(void) 130{ 131 if (show_pkg) 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) 135 fprintf(stderr, " CPU"); | 137 if (show_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"); 141 if (do_nhm_cstates) 142 fprintf(stderr, " %%c1"); 143 if (do_nhm_cstates) 144 fprintf(stderr, " %%c3"); 145 if (do_nhm_cstates) 146 fprintf(stderr, " %%c6"); 147 if (do_snb_cstates) 148 fprintf(stderr, " %%c7"); 149 if (do_snb_cstates) | 145 fprintf(stderr, " TSC"); 146 if (do_nhm_cstates) 147 fprintf(stderr, " %%c1"); 148 if (do_nhm_cstates) 149 fprintf(stderr, " %%c3"); 150 if (do_nhm_cstates) 151 fprintf(stderr, " %%c6"); 152 if (do_snb_cstates) 153 fprintf(stderr, " %%c7"); 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) 158 fprintf(stderr, " MSR 0x%x ", extra_msr_offset); 159 160 putc('\n', stderr); 161} 162 163void dump_cnt(struct counters *cnt) 164{ --- 17 unchanged lines hidden (view full) --- 182void dump_list(struct counters *cnt) 183{ 184 printf("dump_list 0x%p\n", cnt); 185 186 for (; cnt; cnt = cnt->next) 187 dump_cnt(cnt); 188} 189 | 162 if (extra_msr_offset) 163 fprintf(stderr, " MSR 0x%x ", extra_msr_offset); 164 165 putc('\n', stderr); 166} 167 168void dump_cnt(struct counters *cnt) 169{ --- 17 unchanged lines hidden (view full) --- 187void dump_list(struct counters *cnt) 188{ 189 printf("dump_list 0x%p\n", cnt); 190 191 for (; cnt; cnt = cnt->next) 192 dump_cnt(cnt); 193} 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 */ |
|
190void print_cnt(struct counters *p) 191{ 192 double interval_float; 193 194 interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0; 195 196 /* topology columns, print blanks on 1st (average) line */ 197 if (p == cnt_average) { 198 if (show_pkg) | 204void print_cnt(struct counters *p) 205{ 206 double interval_float; 207 208 interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0; 209 210 /* topology columns, print blanks on 1st (average) line */ 211 if (p == cnt_average) { 212 if (show_pkg) |
213 fprintf(stderr, " "); 214 if (show_pkg && show_core) |
|
199 fprintf(stderr, " "); 200 if (show_core) | 215 fprintf(stderr, " "); 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 { 205 if (show_pkg) | 220 } else { 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 } 212 213 /* %c0 */ 214 if (do_nhm_cstates) { | 229 } 230 231 /* %c0 */ 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 } 220 221 /* GHz */ 222 if (has_aperf) { 223 if (!aperf_mperf_unstable) { | 239 } 240 241 /* GHz */ 242 if (has_aperf) { 243 if (!aperf_mperf_unstable) { |
224 fprintf(stderr, "%5.2f", | 244 fprintf(stderr, " %3.2f", |
225 1.0 * p->tsc / units * p->aperf / 226 p->mperf / interval_float); 227 } else { 228 if (p->aperf > p->tsc || p->mperf > p->tsc) { | 245 1.0 * p->tsc / units * p->aperf / 246 p->mperf / interval_float); 247 } else { 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 / 233 units * p->aperf / 234 p->mperf / interval_float); 235 } 236 } 237 } 238 239 /* TSC */ 240 fprintf(stderr, "%5.2f", 1.0 * p->tsc/units/interval_float); 241 242 if (do_nhm_cstates) { 243 if (!skip_c1) | 252 1.0 * p->tsc / 253 units * p->aperf / 254 p->mperf / interval_float); 255 } 256 } 257 } 258 259 /* TSC */ 260 fprintf(stderr, "%5.2f", 1.0 * p->tsc/units/interval_float); 261 262 if (do_nhm_cstates) { 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 246 fprintf(stderr, " ****"); 247 } 248 if (do_nhm_cstates) 249 fprintf(stderr, " %6.2f", 100.0 * p->c3/p->tsc); 250 if (do_nhm_cstates) 251 fprintf(stderr, " %6.2f", 100.0 * p->c6/p->tsc); 252 if (do_snb_cstates) 253 fprintf(stderr, " %6.2f", 100.0 * p->c7/p->tsc); 254 if (do_snb_cstates) | 265 else 266 fprintf(stderr, " ****"); 267 } 268 if (do_nhm_cstates) 269 fprintf(stderr, " %6.2f", 100.0 * p->c3/p->tsc); 270 if (do_nhm_cstates) 271 fprintf(stderr, " %6.2f", 100.0 * p->c6/p->tsc); 272 if (do_snb_cstates) 273 fprintf(stderr, " %6.2f", 100.0 * p->c7/p->tsc); 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) 263 fprintf(stderr, " 0x%016llx", p->extra_msr); 264 putc('\n', stderr); 265} 266 267void print_counters(struct counters *counters) 268{ 269 struct counters *cnt; | 282 if (extra_msr_offset) 283 fprintf(stderr, " 0x%016llx", p->extra_msr); 284 putc('\n', stderr); 285} 286 287void print_counters(struct counters *counters) 288{ 289 struct counters *cnt; |
290 static int printed; |
|
270 | 291 |
271 print_header(); | |
272 | 292 |
293 if (!printed || !summary_only) 294 print_header(); 295 |
|
273 if (num_cpus > 1) 274 print_cnt(cnt_average); 275 | 296 if (num_cpus > 1) 297 print_cnt(cnt_average); 298 |
299 printed = 1; 300 301 if (summary_only) 302 return; 303 |
|
276 for (cnt = counters; cnt != NULL; cnt = cnt->next) 277 print_cnt(cnt); 278 279} 280 281#define SUBTRACT_COUNTER(after, before, delta) (delta = (after - before), (before > after)) 282 283int compute_delta(struct counters *after, --- 268 unchanged lines hidden (view full) --- 552 * list was empty 553 */ 554 if (*list == NULL) { 555 new->next = *list; 556 *list = new; 557 return; 558 } 559 | 304 for (cnt = counters; cnt != NULL; cnt = cnt->next) 305 print_cnt(cnt); 306 307} 308 309#define SUBTRACT_COUNTER(after, before, delta) (delta = (after - before), (before > after)) 310 311int compute_delta(struct counters *after, --- 268 unchanged lines hidden (view full) --- 580 * list was empty 581 */ 582 if (*list == NULL) { 583 new->next = *list; 584 *list = new; 585 return; 586 } 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 562 /* 563 * insert on front of list. 564 * It is sorted by ascending package#, core#, cpu# 565 */ 566 if (((*list)->pkg > new->pkg) || 567 (((*list)->pkg == new->pkg) && ((*list)->core > new->core)) || 568 (((*list)->pkg == new->pkg) && ((*list)->core == new->core) && ((*list)->cpu > new->cpu))) { 569 new->next = *list; 570 *list = new; 571 return; 572 } 573 574 prev = *list; 575 576 while (prev->next && (prev->next->pkg < new->pkg)) { 577 prev = prev->next; | 590 591 /* 592 * insert on front of list. 593 * It is sorted by ascending package#, core#, cpu# 594 */ 595 if (((*list)->pkg > new->pkg) || 596 (((*list)->pkg == new->pkg) && ((*list)->core > new->core)) || 597 (((*list)->pkg == new->pkg) && ((*list)->core == new->core) && ((*list)->cpu > new->cpu))) { 598 new->next = *list; 599 *list = new; 600 return; 601 } 602 603 prev = *list; 604 605 while (prev->next && (prev->next->pkg < new->pkg)) { 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 } 580 581 while (prev->next && (prev->next->pkg == new->pkg) 582 && (prev->next->core < new->core)) { 583 prev = prev->next; | 609 } 610 611 while (prev->next && (prev->next->pkg == new->pkg) 612 && (prev->next->core < new->core)) { 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 } 586 587 while (prev->next && (prev->next->pkg == new->pkg) 588 && (prev->next->core == new->core) 589 && (prev->next->cpu < new->cpu)) { 590 prev = prev->next; 591 } 592 --- 407 unchanged lines hidden (view full) --- 1000} 1001 1002void cmdline(int argc, char **argv) 1003{ 1004 int opt; 1005 1006 progname = argv[0]; 1007 | 616 } 617 618 while (prev->next && (prev->next->pkg == new->pkg) 619 && (prev->next->core == new->core) 620 && (prev->next->cpu < new->cpu)) { 621 prev = prev->next; 622 } 623 --- 407 unchanged lines hidden (view full) --- 1031} 1032 1033void cmdline(int argc, char **argv) 1034{ 1035 int opt; 1036 1037 progname = argv[0]; 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': 1011 verbose++; 1012 break; 1013 case 'i': 1014 interval_sec = atoi(optarg); 1015 break; 1016 case 'M': 1017 sscanf(optarg, "%x", &extra_msr_offset); --- 31 unchanged lines hidden --- | 1044 case 'v': 1045 verbose++; 1046 break; 1047 case 'i': 1048 interval_sec = atoi(optarg); 1049 break; 1050 case 'M': 1051 sscanf(optarg, "%x", &extra_msr_offset); --- 31 unchanged lines hidden --- |