Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'turbostat' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux

Pull turbostat updates from Len Brown.

* 'turbostat' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux:
tools/power turbostat: remove obsolete -M, -m, -C, -c options
tools/power turbostat: Make extensible via the --add parameter
tools/power turbostat: Denverton uses a 25 MHz crystal, not 19.2 MHz
tools/power turbostat: line up headers when -M is used
tools/power turbostat: fix SKX PKG_CSTATE_LIMIT decoding
tools/power turbostat: Support Knights Mill (KNM)
tools/power turbostat: Display HWP OOB status
tools/power turbostat: fix Denverton BCLK
tools/power turbostat: use intel-family.h model strings
tools/power/turbostat: Add Denverton RAPL support
tools/power/turbostat: Add Denverton support
tools/power/turbostat: split core MSR support into status + limit
tools/power turbostat: fix error case overflow read of slm_freq_table[]
tools/power turbostat: Allocate correct amount of fd and irq entries
tools/power turbostat: switch to tab delimited output
tools/power turbostat: Gracefully handle ACPI S3
tools/power turbostat: tidy up output on Joule counter overflow

+677 -375
+1
tools/power/x86/turbostat/Makefile
··· 10 10 turbostat : turbostat.c 11 11 CFLAGS += -Wall 12 12 CFLAGS += -DMSRHEADER='"../../../../arch/x86/include/asm/msr-index.h"' 13 + CFLAGS += -DINTEL_FAMILY_HEADER='"../../../../arch/x86/include/asm/intel-family.h"' 13 14 14 15 %: %.c 15 16 @mkdir -p $(BUILD_OUTPUT)
+20 -6
tools/power/x86/turbostat/turbostat.8
··· 25 25 .SS Options 26 26 Options can be specified with a single or double '-', and only as much of the option 27 27 name as necessary to disambiguate it from others is necessary. Note that options are case-sensitive. 28 - \fB--Counter MSR#\fP shows the delta of the specified 64-bit MSR counter. 29 28 .PP 30 - \fB--counter MSR#\fP shows the delta of the specified 32-bit MSR counter. 29 + \fB--add attributes\fP add column with counter having specified 'attributes'. The 'location' attribute is required, all others are optional. 30 + .nf 31 + location: {\fBmsrDDD\fP | \fBmsr0xXXX\fP} 32 + msrDDD is a decimal offset, eg. msr16 33 + msr0xXXX is a hex offset, eg. msr0x10 34 + 35 + scope: {\fBcpu\fP | \fBcore\fP | \fBpackage\fP} 36 + sample and print the counter for every cpu, core, or package. 37 + default: cpu 38 + 39 + size: {\fBu32\fP | \fBu64\fP } 40 + MSRs are read as 64-bits, u32 truncates the displayed value to 32-bits. 41 + default: u64 42 + 43 + format: {\fBraw\fP | \fBdelta\fP | \fBpercent\fP} 44 + 'raw' shows the MSR contents in hex. 45 + 'delta' shows the difference in values during the measurement interval. 46 + 'percent' shows the delta as a percentage of the cycles elapsed. 47 + default: delta 48 + .fi 31 49 .PP 32 50 \fB--Dump\fP displays the raw counter values. 33 51 .PP ··· 60 42 \fB--help\fP displays usage for the most common parameters. 61 43 .PP 62 44 \fB--Joules\fP displays energy in Joules, rather than dividing Joules by time to print power in Watts. 63 - .PP 64 - \fB--MSR MSR#\fP shows the specified 64-bit MSR value. 65 - .PP 66 - \fB--msr MSR#\fP shows the specified 32-bit MSR value. 67 45 .PP 68 46 \fB--Package\fP limits output to the system summary plus the 1st thread in each Package. 69 47 .PP
+656 -369
tools/power/x86/turbostat/turbostat.c
··· 21 21 22 22 #define _GNU_SOURCE 23 23 #include MSRHEADER 24 + #include INTEL_FAMILY_HEADER 24 25 #include <stdarg.h> 25 26 #include <stdio.h> 26 27 #include <err.h> ··· 52 51 unsigned int rapl_joules; 53 52 unsigned int summary_only; 54 53 unsigned int dump_only; 55 - unsigned int skip_c0; 56 - unsigned int skip_c1; 57 54 unsigned int do_nhm_cstates; 58 55 unsigned int do_snb_cstates; 59 56 unsigned int do_knl_cstates; ··· 71 72 unsigned int genuine_intel; 72 73 unsigned int has_invariant_tsc; 73 74 unsigned int do_nhm_platform_info; 74 - unsigned int extra_msr_offset32; 75 - unsigned int extra_msr_offset64; 76 - unsigned int extra_delta_offset32; 77 - unsigned int extra_delta_offset64; 78 75 unsigned int aperf_mperf_multiplier = 1; 79 76 int do_irq = 1; 80 77 int do_smi; ··· 126 131 #define RAPL_DRAM_POWER_INFO (1 << 5) 127 132 /* 0x61c MSR_DRAM_POWER_INFO */ 128 133 129 - #define RAPL_CORES (1 << 6) 134 + #define RAPL_CORES_POWER_LIMIT (1 << 6) 130 135 /* 0x638 MSR_PP0_POWER_LIMIT */ 131 - /* 0x639 MSR_PP0_ENERGY_STATUS */ 132 136 #define RAPL_CORE_POLICY (1 << 7) 133 137 /* 0x63a MSR_PP0_POLICY */ 134 138 ··· 135 141 /* 0x640 MSR_PP1_POWER_LIMIT */ 136 142 /* 0x641 MSR_PP1_ENERGY_STATUS */ 137 143 /* 0x642 MSR_PP1_POLICY */ 144 + 145 + #define RAPL_CORES_ENERGY_STATUS (1 << 9) 146 + /* 0x639 MSR_PP0_ENERGY_STATUS */ 147 + #define RAPL_CORES (RAPL_CORES_ENERGY_STATUS | RAPL_CORES_POWER_LIMIT) 138 148 #define TJMAX_DEFAULT 100 139 149 140 150 #define MAX(a, b) ((a) > (b) ? (a) : (b)) 141 151 142 - int aperf_mperf_unstable; 152 + /* 153 + * buffer size used by sscanf() for added column names 154 + * Usually truncated to 7 characters, but also handles 18 columns for raw 64-bit counters 155 + */ 156 + #define NAME_BYTES 20 157 + 143 158 int backwards_count; 144 159 char *progname; 145 160 ··· 160 157 unsigned long long aperf; 161 158 unsigned long long mperf; 162 159 unsigned long long c1; 163 - unsigned long long extra_msr64; 164 - unsigned long long extra_delta64; 165 - unsigned long long extra_msr32; 166 - unsigned long long extra_delta32; 167 160 unsigned int irq_count; 168 161 unsigned int smi_count; 169 162 unsigned int cpu_id; 170 163 unsigned int flags; 171 164 #define CPU_IS_FIRST_THREAD_IN_CORE 0x2 172 165 #define CPU_IS_FIRST_CORE_IN_PACKAGE 0x4 166 + unsigned long long counter[1]; 173 167 } *thread_even, *thread_odd; 174 168 175 169 struct core_data { ··· 175 175 unsigned long long c7; 176 176 unsigned int core_temp_c; 177 177 unsigned int core_id; 178 + unsigned long long counter[1]; 178 179 } *core_even, *core_odd; 179 180 180 181 struct pkg_data { ··· 200 199 unsigned int rapl_pkg_perf_status; /* MSR_PKG_PERF_STATUS */ 201 200 unsigned int rapl_dram_perf_status; /* MSR_DRAM_PERF_STATUS */ 202 201 unsigned int pkg_temp_c; 203 - 202 + unsigned long long counter[1]; 204 203 } *package_even, *package_odd; 205 204 206 205 #define ODD_COUNTERS thread_odd, core_odd, package_odd ··· 214 213 (core_base + (pkg_no) * topo.num_cores_per_pkg + (core_no)) 215 214 #define GET_PKG(pkg_base, pkg_no) (pkg_base + pkg_no) 216 215 216 + enum counter_scope {SCOPE_CPU, SCOPE_CORE, SCOPE_PACKAGE}; 217 + enum counter_type {COUNTER_CYCLES, COUNTER_SECONDS}; 218 + enum counter_format {FORMAT_RAW, FORMAT_DELTA, FORMAT_PERCENT}; 219 + 220 + struct msr_counter { 221 + unsigned int msr_num; 222 + char name[NAME_BYTES]; 223 + unsigned int width; 224 + enum counter_type type; 225 + enum counter_format format; 226 + struct msr_counter *next; 227 + }; 228 + 229 + struct sys_counters { 230 + unsigned int thread_counter_bytes; 231 + unsigned int core_counter_bytes; 232 + unsigned int package_counter_bytes; 233 + struct msr_counter *tp; 234 + struct msr_counter *cp; 235 + struct msr_counter *pp; 236 + } sys; 237 + 217 238 struct system_summary { 218 239 struct thread_data threads; 219 240 struct core_data cores; 220 241 struct pkg_data packages; 221 - } sum, average; 242 + } average; 222 243 223 244 224 245 struct topo_params { ··· 342 319 /* 343 320 * Example Format w/ field column widths: 344 321 * 345 - * Package Core CPU Avg_MHz Bzy_MHz TSC_MHz IRQ SMI Busy% CPU_%c1 CPU_%c3 CPU_%c6 CPU_%c7 CoreTmp PkgTmp GFXMHz Pkg%pc2 Pkg%pc3 Pkg%pc6 Pkg%pc7 PkgWatt CorWatt GFXWatt 322 + * Package Core CPU Avg_MHz Bzy_MHz TSC_MHz IRQ SMI Busy% CPU_%c1 CPU_%c3 CPU_%c6 CPU_%c7 ThreadC CoreTmp CoreCnt PkgTmp GFXMHz Pkg%pc2 Pkg%pc3 Pkg%pc6 Pkg%pc7 PkgWatt CorWatt GFXWatt PkgCnt 346 323 * 12345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678 347 324 */ 348 325 349 326 void print_header(void) 350 327 { 351 - if (show_pkg) 352 - outp += sprintf(outp, " Package"); 353 - if (show_core) 354 - outp += sprintf(outp, " Core"); 355 - if (show_cpu) 356 - outp += sprintf(outp, " CPU"); 357 - if (has_aperf) 358 - outp += sprintf(outp, " Avg_MHz"); 359 - if (has_aperf) 360 - outp += sprintf(outp, " Busy%%"); 361 - if (has_aperf) 362 - outp += sprintf(outp, " Bzy_MHz"); 363 - outp += sprintf(outp, " TSC_MHz"); 328 + struct msr_counter *mp; 364 329 365 - if (extra_delta_offset32) 366 - outp += sprintf(outp, " count 0x%03X", extra_delta_offset32); 367 - if (extra_delta_offset64) 368 - outp += sprintf(outp, " COUNT 0x%03X", extra_delta_offset64); 369 - if (extra_msr_offset32) 370 - outp += sprintf(outp, " MSR 0x%03X", extra_msr_offset32); 371 - if (extra_msr_offset64) 372 - outp += sprintf(outp, " MSR 0x%03X", extra_msr_offset64); 330 + if (show_pkg) 331 + outp += sprintf(outp, "\tPackage"); 332 + if (show_core) 333 + outp += sprintf(outp, "\tCore"); 334 + if (show_cpu) 335 + outp += sprintf(outp, "\tCPU"); 336 + if (has_aperf) 337 + outp += sprintf(outp, "\tAvg_MHz"); 338 + if (has_aperf) 339 + outp += sprintf(outp, "\tBusy%%"); 340 + if (has_aperf) 341 + outp += sprintf(outp, "\tBzy_MHz"); 342 + outp += sprintf(outp, "\tTSC_MHz"); 373 343 374 344 if (!debug) 375 345 goto done; 376 346 377 347 if (do_irq) 378 - outp += sprintf(outp, " IRQ"); 348 + outp += sprintf(outp, "\tIRQ"); 379 349 if (do_smi) 380 - outp += sprintf(outp, " SMI"); 350 + outp += sprintf(outp, "\tSMI"); 381 351 382 352 if (do_nhm_cstates) 383 - outp += sprintf(outp, " CPU%%c1"); 353 + outp += sprintf(outp, "\tCPU%%c1"); 384 354 if (do_nhm_cstates && !do_slm_cstates && !do_knl_cstates) 385 - outp += sprintf(outp, " CPU%%c3"); 355 + outp += sprintf(outp, "\tCPU%%c3"); 386 356 if (do_nhm_cstates) 387 - outp += sprintf(outp, " CPU%%c6"); 357 + outp += sprintf(outp, "\tCPU%%c6"); 388 358 if (do_snb_cstates) 389 - outp += sprintf(outp, " CPU%%c7"); 359 + outp += sprintf(outp, "\tCPU%%c7"); 360 + 361 + for (mp = sys.tp; mp; mp = mp->next) { 362 + if (mp->format == FORMAT_RAW) { 363 + if (mp->width == 64) 364 + outp += sprintf(outp, "\t%18.18s", mp->name); 365 + else 366 + outp += sprintf(outp, "\t%10.10s", mp->name); 367 + } else { 368 + outp += sprintf(outp, "\t%-7.7s", mp->name); 369 + } 370 + } 390 371 391 372 if (do_dts) 392 - outp += sprintf(outp, " CoreTmp"); 373 + outp += sprintf(outp, "\tCoreTmp"); 374 + 375 + for (mp = sys.cp; mp; mp = mp->next) { 376 + if (mp->format == FORMAT_RAW) { 377 + if (mp->width == 64) 378 + outp += sprintf(outp, "\t%18.18s", mp->name); 379 + else 380 + outp += sprintf(outp, "\t%10.10s", mp->name); 381 + } else { 382 + outp += sprintf(outp, "\t%-7.7s", mp->name); 383 + } 384 + } 385 + 393 386 if (do_ptm) 394 - outp += sprintf(outp, " PkgTmp"); 387 + outp += sprintf(outp, "\tPkgTmp"); 395 388 396 389 if (do_gfx_rc6_ms) 397 - outp += sprintf(outp, " GFX%%rc6"); 390 + outp += sprintf(outp, "\tGFX%%rc6"); 398 391 399 392 if (do_gfx_mhz) 400 - outp += sprintf(outp, " GFXMHz"); 393 + outp += sprintf(outp, "\tGFXMHz"); 401 394 402 395 if (do_skl_residency) { 403 - outp += sprintf(outp, " Totl%%C0"); 404 - outp += sprintf(outp, " Any%%C0"); 405 - outp += sprintf(outp, " GFX%%C0"); 406 - outp += sprintf(outp, " CPUGFX%%"); 396 + outp += sprintf(outp, "\tTotl%%C0"); 397 + outp += sprintf(outp, "\tAny%%C0"); 398 + outp += sprintf(outp, "\tGFX%%C0"); 399 + outp += sprintf(outp, "\tCPUGFX%%"); 407 400 } 408 401 409 402 if (do_pc2) 410 - outp += sprintf(outp, " Pkg%%pc2"); 403 + outp += sprintf(outp, "\tPkg%%pc2"); 411 404 if (do_pc3) 412 - outp += sprintf(outp, " Pkg%%pc3"); 405 + outp += sprintf(outp, "\tPkg%%pc3"); 413 406 if (do_pc6) 414 - outp += sprintf(outp, " Pkg%%pc6"); 407 + outp += sprintf(outp, "\tPkg%%pc6"); 415 408 if (do_pc7) 416 - outp += sprintf(outp, " Pkg%%pc7"); 409 + outp += sprintf(outp, "\tPkg%%pc7"); 417 410 if (do_c8_c9_c10) { 418 - outp += sprintf(outp, " Pkg%%pc8"); 419 - outp += sprintf(outp, " Pkg%%pc9"); 420 - outp += sprintf(outp, " Pk%%pc10"); 411 + outp += sprintf(outp, "\tPkg%%pc8"); 412 + outp += sprintf(outp, "\tPkg%%pc9"); 413 + outp += sprintf(outp, "\tPk%%pc10"); 421 414 } 422 415 423 416 if (do_rapl && !rapl_joules) { 424 417 if (do_rapl & RAPL_PKG) 425 - outp += sprintf(outp, " PkgWatt"); 426 - if (do_rapl & RAPL_CORES) 427 - outp += sprintf(outp, " CorWatt"); 418 + outp += sprintf(outp, "\tPkgWatt"); 419 + if (do_rapl & RAPL_CORES_ENERGY_STATUS) 420 + outp += sprintf(outp, "\tCorWatt"); 428 421 if (do_rapl & RAPL_GFX) 429 - outp += sprintf(outp, " GFXWatt"); 422 + outp += sprintf(outp, "\tGFXWatt"); 430 423 if (do_rapl & RAPL_DRAM) 431 - outp += sprintf(outp, " RAMWatt"); 424 + outp += sprintf(outp, "\tRAMWatt"); 432 425 if (do_rapl & RAPL_PKG_PERF_STATUS) 433 - outp += sprintf(outp, " PKG_%%"); 426 + outp += sprintf(outp, "\tPKG_%%"); 434 427 if (do_rapl & RAPL_DRAM_PERF_STATUS) 435 - outp += sprintf(outp, " RAM_%%"); 428 + outp += sprintf(outp, "\tRAM_%%"); 436 429 } else if (do_rapl && rapl_joules) { 437 430 if (do_rapl & RAPL_PKG) 438 - outp += sprintf(outp, " Pkg_J"); 439 - if (do_rapl & RAPL_CORES) 440 - outp += sprintf(outp, " Cor_J"); 431 + outp += sprintf(outp, "\tPkg_J"); 432 + if (do_rapl & RAPL_CORES_ENERGY_STATUS) 433 + outp += sprintf(outp, "\tCor_J"); 441 434 if (do_rapl & RAPL_GFX) 442 - outp += sprintf(outp, " GFX_J"); 435 + outp += sprintf(outp, "\tGFX_J"); 443 436 if (do_rapl & RAPL_DRAM) 444 - outp += sprintf(outp, " RAM_J"); 437 + outp += sprintf(outp, "\tRAM_J"); 445 438 if (do_rapl & RAPL_PKG_PERF_STATUS) 446 - outp += sprintf(outp, " PKG_%%"); 439 + outp += sprintf(outp, "\tPKG_%%"); 447 440 if (do_rapl & RAPL_DRAM_PERF_STATUS) 448 - outp += sprintf(outp, " RAM_%%"); 449 - outp += sprintf(outp, " time"); 450 - 441 + outp += sprintf(outp, "\tRAM_%%"); 451 442 } 452 - done: 443 + for (mp = sys.pp; mp; mp = mp->next) { 444 + if (mp->format == FORMAT_RAW) { 445 + if (mp->width == 64) 446 + outp += sprintf(outp, "\t%18.18s", mp->name); 447 + else 448 + outp += sprintf(outp, "\t%10.10s", mp->name); 449 + } else { 450 + outp += sprintf(outp, "\t%-7.7s", mp->name); 451 + } 452 + } 453 + 454 + done: 453 455 outp += sprintf(outp, "\n"); 454 456 } 455 457 456 458 int dump_counters(struct thread_data *t, struct core_data *c, 457 459 struct pkg_data *p) 458 460 { 461 + int i; 462 + struct msr_counter *mp; 463 + 459 464 outp += sprintf(outp, "t %p, c %p, p %p\n", t, c, p); 460 465 461 466 if (t) { ··· 493 442 outp += sprintf(outp, "aperf: %016llX\n", t->aperf); 494 443 outp += sprintf(outp, "mperf: %016llX\n", t->mperf); 495 444 outp += sprintf(outp, "c1: %016llX\n", t->c1); 496 - outp += sprintf(outp, "msr0x%x: %08llX\n", 497 - extra_delta_offset32, t->extra_delta32); 498 - outp += sprintf(outp, "msr0x%x: %016llX\n", 499 - extra_delta_offset64, t->extra_delta64); 500 - outp += sprintf(outp, "msr0x%x: %08llX\n", 501 - extra_msr_offset32, t->extra_msr32); 502 - outp += sprintf(outp, "msr0x%x: %016llX\n", 503 - extra_msr_offset64, t->extra_msr64); 445 + 504 446 if (do_irq) 505 447 outp += sprintf(outp, "IRQ: %08X\n", t->irq_count); 506 448 if (do_smi) 507 449 outp += sprintf(outp, "SMI: %08X\n", t->smi_count); 450 + 451 + for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { 452 + outp += sprintf(outp, "tADDED [%d] msr0x%x: %08llX\n", 453 + i, mp->msr_num, t->counter[i]); 454 + } 508 455 } 509 456 510 457 if (c) { ··· 511 462 outp += sprintf(outp, "c6: %016llX\n", c->c6); 512 463 outp += sprintf(outp, "c7: %016llX\n", c->c7); 513 464 outp += sprintf(outp, "DTS: %dC\n", c->core_temp_c); 465 + 466 + for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { 467 + outp += sprintf(outp, "cADDED [%d] msr0x%x: %08llX\n", 468 + i, mp->msr_num, c->counter[i]); 469 + } 514 470 } 515 471 516 472 if (p) { ··· 545 491 outp += sprintf(outp, "Throttle RAM: %0X\n", 546 492 p->rapl_dram_perf_status); 547 493 outp += sprintf(outp, "PTM: %dC\n", p->pkg_temp_c); 494 + 495 + for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { 496 + outp += sprintf(outp, "pADDED [%d] msr0x%x: %08llX\n", 497 + i, mp->msr_num, p->counter[i]); 498 + } 548 499 } 549 500 550 501 outp += sprintf(outp, "\n"); ··· 565 506 { 566 507 double interval_float; 567 508 char *fmt8; 509 + int i; 510 + struct msr_counter *mp; 568 511 569 512 /* if showing only 1st thread in core and this isn't one, bail out */ 570 513 if (show_core_only && !(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) ··· 581 520 /* topo columns, print blanks on 1st (average) line */ 582 521 if (t == &average.threads) { 583 522 if (show_pkg) 584 - outp += sprintf(outp, " -"); 523 + outp += sprintf(outp, "\t-"); 585 524 if (show_core) 586 - outp += sprintf(outp, " -"); 525 + outp += sprintf(outp, "\t-"); 587 526 if (show_cpu) 588 - outp += sprintf(outp, " -"); 527 + outp += sprintf(outp, "\t-"); 589 528 } else { 590 529 if (show_pkg) { 591 530 if (p) 592 - outp += sprintf(outp, "%8d", p->package_id); 531 + outp += sprintf(outp, "\t%d", p->package_id); 593 532 else 594 - outp += sprintf(outp, " -"); 533 + outp += sprintf(outp, "\t-"); 595 534 } 596 535 if (show_core) { 597 536 if (c) 598 - outp += sprintf(outp, "%8d", c->core_id); 537 + outp += sprintf(outp, "\t%d", c->core_id); 599 538 else 600 - outp += sprintf(outp, " -"); 539 + outp += sprintf(outp, "\t-"); 601 540 } 602 541 if (show_cpu) 603 - outp += sprintf(outp, "%8d", t->cpu_id); 542 + outp += sprintf(outp, "\t%d", t->cpu_id); 604 543 } 605 544 606 545 /* Avg_MHz */ 607 546 if (has_aperf) 608 - outp += sprintf(outp, "%8.0f", 547 + outp += sprintf(outp, "\t%.0f", 609 548 1.0 / units * t->aperf / interval_float); 610 549 611 550 /* Busy% */ 612 - if (has_aperf) { 613 - if (!skip_c0) 614 - outp += sprintf(outp, "%8.2f", 100.0 * t->mperf/t->tsc/tsc_tweak); 615 - else 616 - outp += sprintf(outp, "********"); 617 - } 551 + if (has_aperf) 552 + outp += sprintf(outp, "\t%.2f", 100.0 * t->mperf/t->tsc/tsc_tweak); 618 553 619 554 /* Bzy_MHz */ 620 555 if (has_aperf) { 621 556 if (has_base_hz) 622 - outp += sprintf(outp, "%8.0f", base_hz / units * t->aperf / t->mperf); 557 + outp += sprintf(outp, "\t%.0f", base_hz / units * t->aperf / t->mperf); 623 558 else 624 - outp += sprintf(outp, "%8.0f", 559 + outp += sprintf(outp, "\t%.0f", 625 560 1.0 * t->tsc / units * t->aperf / t->mperf / interval_float); 626 561 } 627 562 628 563 /* TSC_MHz */ 629 - outp += sprintf(outp, "%8.0f", 1.0 * t->tsc/units/interval_float); 630 - 631 - /* delta */ 632 - if (extra_delta_offset32) 633 - outp += sprintf(outp, " %11llu", t->extra_delta32); 634 - 635 - /* DELTA */ 636 - if (extra_delta_offset64) 637 - outp += sprintf(outp, " %11llu", t->extra_delta64); 638 - /* msr */ 639 - if (extra_msr_offset32) 640 - outp += sprintf(outp, " 0x%08llx", t->extra_msr32); 641 - 642 - /* MSR */ 643 - if (extra_msr_offset64) 644 - outp += sprintf(outp, " 0x%016llx", t->extra_msr64); 564 + outp += sprintf(outp, "\t%.0f", 1.0 * t->tsc/units/interval_float); 645 565 646 566 if (!debug) 647 567 goto done; 648 568 649 569 /* IRQ */ 650 570 if (do_irq) 651 - outp += sprintf(outp, "%8d", t->irq_count); 571 + outp += sprintf(outp, "\t%d", t->irq_count); 652 572 653 573 /* SMI */ 654 574 if (do_smi) 655 - outp += sprintf(outp, "%8d", t->smi_count); 575 + outp += sprintf(outp, "\t%d", t->smi_count); 656 576 657 - if (do_nhm_cstates) { 658 - if (!skip_c1) 659 - outp += sprintf(outp, "%8.2f", 100.0 * t->c1/t->tsc); 660 - else 661 - outp += sprintf(outp, "********"); 662 - } 577 + if (do_nhm_cstates) 578 + outp += sprintf(outp, "\t%.2f", 100.0 * t->c1/t->tsc); 663 579 664 580 /* print per-core data only for 1st thread in core */ 665 581 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) 666 582 goto done; 667 583 668 584 if (do_nhm_cstates && !do_slm_cstates && !do_knl_cstates) 669 - outp += sprintf(outp, "%8.2f", 100.0 * c->c3/t->tsc); 585 + outp += sprintf(outp, "\t%.2f", 100.0 * c->c3/t->tsc); 670 586 if (do_nhm_cstates) 671 - outp += sprintf(outp, "%8.2f", 100.0 * c->c6/t->tsc); 587 + outp += sprintf(outp, "\t%.2f", 100.0 * c->c6/t->tsc); 672 588 if (do_snb_cstates) 673 - outp += sprintf(outp, "%8.2f", 100.0 * c->c7/t->tsc); 589 + outp += sprintf(outp, "\t%.2f", 100.0 * c->c7/t->tsc); 590 + 591 + for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { 592 + if (mp->format == FORMAT_RAW) { 593 + if (mp->width == 32) 594 + outp += sprintf(outp, "\t0x%08lx", (unsigned long) t->counter[i]); 595 + else 596 + outp += sprintf(outp, "\t0x%016llx", t->counter[i]); 597 + } else if (mp->format == FORMAT_DELTA) { 598 + outp += sprintf(outp, "\t%8lld", t->counter[i]); 599 + } else if (mp->format == FORMAT_PERCENT) { 600 + outp += sprintf(outp, "\t%.2f", 100.0 * t->counter[i]/t->tsc); 601 + } 602 + } 603 + 674 604 675 605 if (do_dts) 676 - outp += sprintf(outp, "%8d", c->core_temp_c); 606 + outp += sprintf(outp, "\t%d", c->core_temp_c); 607 + 608 + for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { 609 + if (mp->format == FORMAT_RAW) { 610 + if (mp->width == 32) 611 + outp += sprintf(outp, "\t0x%08lx", (unsigned long) c->counter[i]); 612 + else 613 + outp += sprintf(outp, "\t0x%016llx", c->counter[i]); 614 + } else if (mp->format == FORMAT_DELTA) { 615 + outp += sprintf(outp, "\t%8lld", c->counter[i]); 616 + } else if (mp->format == FORMAT_PERCENT) { 617 + outp += sprintf(outp, "\t%.2f", 100.0 * c->counter[i]/t->tsc); 618 + } 619 + } 677 620 678 621 /* print per-package data only for 1st core in package */ 679 622 if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) ··· 685 620 686 621 /* PkgTmp */ 687 622 if (do_ptm) 688 - outp += sprintf(outp, "%8d", p->pkg_temp_c); 623 + outp += sprintf(outp, "\t%d", p->pkg_temp_c); 689 624 690 625 /* GFXrc6 */ 691 626 if (do_gfx_rc6_ms) { 692 - if (p->gfx_rc6_ms == -1) { /* detect counter reset */ 693 - outp += sprintf(outp, " ***.**"); 627 + if (p->gfx_rc6_ms == -1) { /* detect GFX counter reset */ 628 + outp += sprintf(outp, "\t**.**"); 694 629 } else { 695 - outp += sprintf(outp, "%8.2f", 630 + outp += sprintf(outp, "\t%.2f", 696 631 p->gfx_rc6_ms / 10.0 / interval_float); 697 632 } 698 633 } 699 634 700 635 /* GFXMHz */ 701 636 if (do_gfx_mhz) 702 - outp += sprintf(outp, "%8d", p->gfx_mhz); 637 + outp += sprintf(outp, "\t%d", p->gfx_mhz); 703 638 704 639 /* Totl%C0, Any%C0 GFX%C0 CPUGFX% */ 705 640 if (do_skl_residency) { 706 - outp += sprintf(outp, "%8.2f", 100.0 * p->pkg_wtd_core_c0/t->tsc); 707 - outp += sprintf(outp, "%8.2f", 100.0 * p->pkg_any_core_c0/t->tsc); 708 - outp += sprintf(outp, "%8.2f", 100.0 * p->pkg_any_gfxe_c0/t->tsc); 709 - outp += sprintf(outp, "%8.2f", 100.0 * p->pkg_both_core_gfxe_c0/t->tsc); 641 + outp += sprintf(outp, "\t%.2f", 100.0 * p->pkg_wtd_core_c0/t->tsc); 642 + outp += sprintf(outp, "\t%.2f", 100.0 * p->pkg_any_core_c0/t->tsc); 643 + outp += sprintf(outp, "\t%.2f", 100.0 * p->pkg_any_gfxe_c0/t->tsc); 644 + outp += sprintf(outp, "\t%.2f", 100.0 * p->pkg_both_core_gfxe_c0/t->tsc); 710 645 } 711 646 712 647 if (do_pc2) 713 - outp += sprintf(outp, "%8.2f", 100.0 * p->pc2/t->tsc); 648 + outp += sprintf(outp, "\t%.2f", 100.0 * p->pc2/t->tsc); 714 649 if (do_pc3) 715 - outp += sprintf(outp, "%8.2f", 100.0 * p->pc3/t->tsc); 650 + outp += sprintf(outp, "\t%.2f", 100.0 * p->pc3/t->tsc); 716 651 if (do_pc6) 717 - outp += sprintf(outp, "%8.2f", 100.0 * p->pc6/t->tsc); 652 + outp += sprintf(outp, "\t%.2f", 100.0 * p->pc6/t->tsc); 718 653 if (do_pc7) 719 - outp += sprintf(outp, "%8.2f", 100.0 * p->pc7/t->tsc); 654 + outp += sprintf(outp, "\t%.2f", 100.0 * p->pc7/t->tsc); 720 655 if (do_c8_c9_c10) { 721 - outp += sprintf(outp, "%8.2f", 100.0 * p->pc8/t->tsc); 722 - outp += sprintf(outp, "%8.2f", 100.0 * p->pc9/t->tsc); 723 - outp += sprintf(outp, "%8.2f", 100.0 * p->pc10/t->tsc); 656 + outp += sprintf(outp, "\t%.2f", 100.0 * p->pc8/t->tsc); 657 + outp += sprintf(outp, "\t%.2f", 100.0 * p->pc9/t->tsc); 658 + outp += sprintf(outp, "\t%.2f", 100.0 * p->pc10/t->tsc); 724 659 } 725 660 726 661 /* ··· 728 663 * indicate that results are suspect by printing "**" in fraction place. 729 664 */ 730 665 if (interval_float < rapl_joule_counter_range) 731 - fmt8 = "%8.2f"; 666 + fmt8 = "\t%.2f"; 732 667 else 733 - fmt8 = " %6.0f**"; 668 + fmt8 = "%6.0f**"; 734 669 735 670 if (do_rapl && !rapl_joules) { 736 671 if (do_rapl & RAPL_PKG) 737 672 outp += sprintf(outp, fmt8, p->energy_pkg * rapl_energy_units / interval_float); 738 - if (do_rapl & RAPL_CORES) 673 + if (do_rapl & RAPL_CORES_ENERGY_STATUS) 739 674 outp += sprintf(outp, fmt8, p->energy_cores * rapl_energy_units / interval_float); 740 675 if (do_rapl & RAPL_GFX) 741 676 outp += sprintf(outp, fmt8, p->energy_gfx * rapl_energy_units / interval_float); ··· 762 697 outp += sprintf(outp, fmt8, 100.0 * p->rapl_pkg_perf_status * rapl_time_units / interval_float); 763 698 if (do_rapl & RAPL_DRAM_PERF_STATUS) 764 699 outp += sprintf(outp, fmt8, 100.0 * p->rapl_dram_perf_status * rapl_time_units / interval_float); 765 - 766 - outp += sprintf(outp, fmt8, interval_float); 767 700 } 701 + for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { 702 + if (mp->format == FORMAT_RAW) { 703 + if (mp->width == 32) 704 + outp += sprintf(outp, "\t0x%08lx", (unsigned long) p->counter[i]); 705 + else 706 + outp += sprintf(outp, "\t0x%016llx", p->counter[i]); 707 + } else if (mp->format == FORMAT_DELTA) { 708 + outp += sprintf(outp, "\t%8lld", p->counter[i]); 709 + } else if (mp->format == FORMAT_PERCENT) { 710 + outp += sprintf(outp, "\t%.2f", 100.0 * p->counter[i]/t->tsc); 711 + } 712 + } 713 + 768 714 done: 769 715 outp += sprintf(outp, "\n"); 770 716 ··· 828 752 old = 0x100000000 + new - old; \ 829 753 } 830 754 831 - void 755 + int 832 756 delta_package(struct pkg_data *new, struct pkg_data *old) 833 757 { 758 + int i; 759 + struct msr_counter *mp; 834 760 835 761 if (do_skl_residency) { 836 762 old->pkg_wtd_core_c0 = new->pkg_wtd_core_c0 - old->pkg_wtd_core_c0; ··· 866 788 DELTA_WRAP32(new->energy_dram, old->energy_dram); 867 789 DELTA_WRAP32(new->rapl_pkg_perf_status, old->rapl_pkg_perf_status); 868 790 DELTA_WRAP32(new->rapl_dram_perf_status, old->rapl_dram_perf_status); 791 + 792 + for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { 793 + if (mp->format == FORMAT_RAW) 794 + old->counter[i] = new->counter[i]; 795 + else 796 + old->counter[i] = new->counter[i] - old->counter[i]; 797 + } 798 + 799 + return 0; 869 800 } 870 801 871 802 void 872 803 delta_core(struct core_data *new, struct core_data *old) 873 804 { 805 + int i; 806 + struct msr_counter *mp; 807 + 874 808 old->c3 = new->c3 - old->c3; 875 809 old->c6 = new->c6 - old->c6; 876 810 old->c7 = new->c7 - old->c7; 877 811 old->core_temp_c = new->core_temp_c; 812 + 813 + for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { 814 + if (mp->format == FORMAT_RAW) 815 + old->counter[i] = new->counter[i]; 816 + else 817 + old->counter[i] = new->counter[i] - old->counter[i]; 818 + } 878 819 } 879 820 880 821 /* 881 822 * old = new - old 882 823 */ 883 - void 824 + int 884 825 delta_thread(struct thread_data *new, struct thread_data *old, 885 826 struct core_data *core_delta) 886 827 { 828 + int i; 829 + struct msr_counter *mp; 830 + 887 831 old->tsc = new->tsc - old->tsc; 888 832 889 833 /* check for TSC < 1 Mcycles over interval */ ··· 921 821 old->aperf = new->aperf - old->aperf; 922 822 old->mperf = new->mperf - old->mperf; 923 823 } else { 924 - 925 - if (!aperf_mperf_unstable) { 926 - fprintf(outf, "%s: APERF or MPERF went backwards *\n", progname); 927 - fprintf(outf, "* Frequency results do not cover entire interval *\n"); 928 - fprintf(outf, "* fix this by running Linux-2.6.30 or later *\n"); 929 - 930 - aperf_mperf_unstable = 1; 931 - } 932 - /* 933 - * mperf delta is likely a huge "positive" number 934 - * can not use it for calculating c0 time 935 - */ 936 - skip_c0 = 1; 937 - skip_c1 = 1; 824 + return -1; 938 825 } 939 826 } 940 827 ··· 952 865 old->mperf = 1; /* divide by 0 protection */ 953 866 } 954 867 955 - old->extra_delta32 = new->extra_delta32 - old->extra_delta32; 956 - old->extra_delta32 &= 0xFFFFFFFF; 957 - 958 - old->extra_delta64 = new->extra_delta64 - old->extra_delta64; 959 - 960 - /* 961 - * Extra MSR is just a snapshot, simply copy latest w/o subtracting 962 - */ 963 - old->extra_msr32 = new->extra_msr32; 964 - old->extra_msr64 = new->extra_msr64; 965 - 966 868 if (do_irq) 967 869 old->irq_count = new->irq_count - old->irq_count; 968 870 969 871 if (do_smi) 970 872 old->smi_count = new->smi_count - old->smi_count; 873 + 874 + for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { 875 + if (mp->format == FORMAT_RAW) 876 + old->counter[i] = new->counter[i]; 877 + else 878 + old->counter[i] = new->counter[i] - old->counter[i]; 879 + } 880 + return 0; 971 881 } 972 882 973 883 int delta_cpu(struct thread_data *t, struct core_data *c, 974 884 struct pkg_data *p, struct thread_data *t2, 975 885 struct core_data *c2, struct pkg_data *p2) 976 886 { 887 + int retval = 0; 888 + 977 889 /* calculate core delta only for 1st thread in core */ 978 890 if (t->flags & CPU_IS_FIRST_THREAD_IN_CORE) 979 891 delta_core(c, c2); 980 892 981 893 /* always calculate thread delta */ 982 - delta_thread(t, t2, c2); /* c2 is core delta */ 894 + retval = delta_thread(t, t2, c2); /* c2 is core delta */ 895 + if (retval) 896 + return retval; 983 897 984 898 /* calculate package delta only for 1st core in package */ 985 899 if (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE) 986 - delta_package(p, p2); 900 + retval = delta_package(p, p2); 987 901 988 - return 0; 902 + return retval; 989 903 } 990 904 991 905 void clear_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) 992 906 { 907 + int i; 908 + struct msr_counter *mp; 909 + 993 910 t->tsc = 0; 994 911 t->aperf = 0; 995 912 t->mperf = 0; 996 913 t->c1 = 0; 997 - 998 - t->extra_delta32 = 0; 999 - t->extra_delta64 = 0; 1000 914 1001 915 t->irq_count = 0; 1002 916 t->smi_count = 0; ··· 1036 948 1037 949 p->gfx_rc6_ms = 0; 1038 950 p->gfx_mhz = 0; 951 + 952 + for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) 953 + t->counter[i] = 0; 954 + 955 + for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) 956 + c->counter[i] = 0; 957 + 958 + for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) 959 + p->counter[i] = 0; 1039 960 } 1040 961 int sum_counters(struct thread_data *t, struct core_data *c, 1041 962 struct pkg_data *p) 1042 963 { 964 + int i; 965 + struct msr_counter *mp; 966 + 1043 967 average.threads.tsc += t->tsc; 1044 968 average.threads.aperf += t->aperf; 1045 969 average.threads.mperf += t->mperf; 1046 970 average.threads.c1 += t->c1; 1047 971 1048 - average.threads.extra_delta32 += t->extra_delta32; 1049 - average.threads.extra_delta64 += t->extra_delta64; 1050 - 1051 972 average.threads.irq_count += t->irq_count; 1052 973 average.threads.smi_count += t->smi_count; 974 + 975 + for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { 976 + if (mp->format == FORMAT_RAW) 977 + continue; 978 + average.threads.counter[i] += t->counter[i]; 979 + } 1053 980 1054 981 /* sum per-core values only for 1st thread in core */ 1055 982 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) ··· 1075 972 average.cores.c7 += c->c7; 1076 973 1077 974 average.cores.core_temp_c = MAX(average.cores.core_temp_c, c->core_temp_c); 975 + 976 + for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { 977 + if (mp->format == FORMAT_RAW) 978 + continue; 979 + average.cores.counter[i] += c->counter[i]; 980 + } 1078 981 1079 982 /* sum per-pkg values only for 1st core in pkg */ 1080 983 if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) ··· 1116 1007 1117 1008 average.packages.rapl_pkg_perf_status += p->rapl_pkg_perf_status; 1118 1009 average.packages.rapl_dram_perf_status += p->rapl_dram_perf_status; 1010 + 1011 + for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { 1012 + if (mp->format == FORMAT_RAW) 1013 + continue; 1014 + average.packages.counter[i] += p->counter[i]; 1015 + } 1119 1016 return 0; 1120 1017 } 1121 1018 /* ··· 1131 1016 void compute_average(struct thread_data *t, struct core_data *c, 1132 1017 struct pkg_data *p) 1133 1018 { 1019 + int i; 1020 + struct msr_counter *mp; 1021 + 1134 1022 clear_counters(&average.threads, &average.cores, &average.packages); 1135 1023 1136 1024 for_all_cpus(sum_counters, t, c, p); ··· 1142 1024 average.threads.aperf /= topo.num_cpus; 1143 1025 average.threads.mperf /= topo.num_cpus; 1144 1026 average.threads.c1 /= topo.num_cpus; 1145 - 1146 - average.threads.extra_delta32 /= topo.num_cpus; 1147 - average.threads.extra_delta32 &= 0xFFFFFFFF; 1148 - 1149 - average.threads.extra_delta64 /= topo.num_cpus; 1150 1027 1151 1028 average.cores.c3 /= topo.num_cores; 1152 1029 average.cores.c6 /= topo.num_cores; ··· 1165 1052 average.packages.pc8 /= topo.num_packages; 1166 1053 average.packages.pc9 /= topo.num_packages; 1167 1054 average.packages.pc10 /= topo.num_packages; 1055 + 1056 + for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { 1057 + if (mp->format == FORMAT_RAW) 1058 + continue; 1059 + average.threads.counter[i] /= topo.num_cpus; 1060 + } 1061 + for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { 1062 + if (mp->format == FORMAT_RAW) 1063 + continue; 1064 + average.cores.counter[i] /= topo.num_cores; 1065 + } 1066 + for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { 1067 + if (mp->format == FORMAT_RAW) 1068 + continue; 1069 + average.packages.counter[i] /= topo.num_packages; 1070 + } 1168 1071 } 1169 1072 1170 1073 static unsigned long long rdtsc(void) ··· 1202 1073 int cpu = t->cpu_id; 1203 1074 unsigned long long msr; 1204 1075 int aperf_mperf_retry_count = 0; 1076 + struct msr_counter *mp; 1077 + int i; 1205 1078 1206 1079 if (cpu_migrate(cpu)) { 1207 1080 fprintf(outf, "Could not migrate to CPU %d\n", cpu); ··· 1276 1145 return -5; 1277 1146 t->smi_count = msr & 0xFFFFFFFF; 1278 1147 } 1279 - if (extra_delta_offset32) { 1280 - if (get_msr(cpu, extra_delta_offset32, &msr)) 1281 - return -5; 1282 - t->extra_delta32 = msr & 0xFFFFFFFF; 1283 - } 1284 - 1285 - if (extra_delta_offset64) 1286 - if (get_msr(cpu, extra_delta_offset64, &t->extra_delta64)) 1287 - return -5; 1288 - 1289 - if (extra_msr_offset32) { 1290 - if (get_msr(cpu, extra_msr_offset32, &msr)) 1291 - return -5; 1292 - t->extra_msr32 = msr & 0xFFFFFFFF; 1293 - } 1294 - 1295 - if (extra_msr_offset64) 1296 - if (get_msr(cpu, extra_msr_offset64, &t->extra_msr64)) 1297 - return -5; 1298 1148 1299 1149 if (use_c1_residency_msr) { 1300 1150 if (get_msr(cpu, MSR_CORE_C1_RES, &t->c1)) 1301 1151 return -6; 1302 1152 } 1153 + 1154 + for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { 1155 + if (get_msr(cpu, mp->msr_num, &t->counter[i])) 1156 + return -10; 1157 + } 1158 + 1303 1159 1304 1160 /* collect core counters only for 1st thread in core */ 1305 1161 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) ··· 1315 1197 c->core_temp_c = tcc_activation_temp - ((msr >> 16) & 0x7F); 1316 1198 } 1317 1199 1200 + for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { 1201 + if (get_msr(cpu, mp->msr_num, &c->counter[i])) 1202 + return -10; 1203 + } 1318 1204 1319 1205 /* collect package counters only for 1st core in package */ 1320 1206 if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) ··· 1359 1237 return -13; 1360 1238 p->energy_pkg = msr & 0xFFFFFFFF; 1361 1239 } 1362 - if (do_rapl & RAPL_CORES) { 1240 + if (do_rapl & RAPL_CORES_ENERGY_STATUS) { 1363 1241 if (get_msr(cpu, MSR_PP0_ENERGY_STATUS, &msr)) 1364 1242 return -14; 1365 1243 p->energy_cores = msr & 0xFFFFFFFF; ··· 1395 1273 1396 1274 if (do_gfx_mhz) 1397 1275 p->gfx_mhz = gfx_cur_mhz; 1276 + 1277 + for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { 1278 + if (get_msr(cpu, mp->msr_num, &p->counter[i])) 1279 + return -10; 1280 + } 1398 1281 1399 1282 return 0; 1400 1283 } ··· 1437 1310 int amt_pkg_cstate_limits[16] = {PCL__0, PCL__1, PCL__2, PCLRSV, PCLRSV, PCLRSV, PCL__6, PCL__7, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; 1438 1311 int phi_pkg_cstate_limits[16] = {PCL__0, PCL__2, PCL_6N, PCL_6R, PCLRSV, PCLRSV, PCLRSV, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; 1439 1312 int bxt_pkg_cstate_limits[16] = {PCL__0, PCL__2, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; 1313 + int skx_pkg_cstate_limits[16] = {PCL__0, PCL__2, PCL_6N, PCL_6R, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; 1440 1314 1441 1315 1442 1316 static void ··· 1766 1638 { 1767 1639 int i; 1768 1640 1769 - for (i = 0; i < topo.max_cpu_num; ++i) { 1641 + for (i = 0; i < topo.max_cpu_num + 1; ++i) { 1770 1642 if (fd_percpu[i] != 0) 1771 1643 close(fd_percpu[i]); 1772 1644 } ··· 2199 2071 } 2200 2072 gettimeofday(&tv_odd, (struct timezone *)NULL); 2201 2073 timersub(&tv_odd, &tv_even, &tv_delta); 2202 - for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS); 2074 + if (for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS)) { 2075 + re_initialize(); 2076 + goto restart; 2077 + } 2203 2078 compute_average(EVEN_COUNTERS); 2204 2079 format_all_counters(EVEN_COUNTERS); 2205 2080 flush_output_stdout(); ··· 2218 2087 } 2219 2088 gettimeofday(&tv_even, (struct timezone *)NULL); 2220 2089 timersub(&tv_even, &tv_odd, &tv_delta); 2221 - for_all_cpus_2(delta_cpu, EVEN_COUNTERS, ODD_COUNTERS); 2090 + if (for_all_cpus_2(delta_cpu, EVEN_COUNTERS, ODD_COUNTERS)) { 2091 + re_initialize(); 2092 + goto restart; 2093 + } 2222 2094 compute_average(ODD_COUNTERS); 2223 2095 format_all_counters(ODD_COUNTERS); 2224 2096 flush_output_stdout(); ··· 2308 2174 bclk = discover_bclk(family, model); 2309 2175 2310 2176 switch (model) { 2311 - case 0x1A: /* Core i7, Xeon 5500 series - Bloomfield, Gainstown NHM-EP */ 2312 - case 0x1E: /* Core i7 and i5 Processor - Clarksfield, Lynnfield, Jasper Forest */ 2177 + case INTEL_FAM6_NEHALEM_EP: /* Core i7, Xeon 5500 series - Bloomfield, Gainstown NHM-EP */ 2178 + case INTEL_FAM6_NEHALEM: /* Core i7 and i5 Processor - Clarksfield, Lynnfield, Jasper Forest */ 2313 2179 case 0x1F: /* Core i7 and i5 Processor - Nehalem */ 2314 - case 0x25: /* Westmere Client - Clarkdale, Arrandale */ 2315 - case 0x2C: /* Westmere EP - Gulftown */ 2316 - case 0x2E: /* Nehalem-EX Xeon - Beckton */ 2317 - case 0x2F: /* Westmere-EX Xeon - Eagleton */ 2180 + case INTEL_FAM6_WESTMERE: /* Westmere Client - Clarkdale, Arrandale */ 2181 + case INTEL_FAM6_WESTMERE_EP: /* Westmere EP - Gulftown */ 2182 + case INTEL_FAM6_NEHALEM_EX: /* Nehalem-EX Xeon - Beckton */ 2183 + case INTEL_FAM6_WESTMERE_EX: /* Westmere-EX Xeon - Eagleton */ 2318 2184 pkg_cstate_limits = nhm_pkg_cstate_limits; 2319 2185 break; 2320 - case 0x2A: /* SNB */ 2321 - case 0x2D: /* SNB Xeon */ 2322 - case 0x3A: /* IVB */ 2323 - case 0x3E: /* IVB Xeon */ 2186 + case INTEL_FAM6_SANDYBRIDGE: /* SNB */ 2187 + case INTEL_FAM6_SANDYBRIDGE_X: /* SNB Xeon */ 2188 + case INTEL_FAM6_IVYBRIDGE: /* IVB */ 2189 + case INTEL_FAM6_IVYBRIDGE_X: /* IVB Xeon */ 2324 2190 pkg_cstate_limits = snb_pkg_cstate_limits; 2325 2191 break; 2326 - case 0x3C: /* HSW */ 2327 - case 0x3F: /* HSX */ 2328 - case 0x45: /* HSW */ 2329 - case 0x46: /* HSW */ 2330 - case 0x3D: /* BDW */ 2331 - case 0x47: /* BDW */ 2332 - case 0x4F: /* BDX */ 2333 - case 0x56: /* BDX-DE */ 2334 - case 0x4E: /* SKL */ 2335 - case 0x5E: /* SKL */ 2336 - case 0x8E: /* KBL */ 2337 - case 0x9E: /* KBL */ 2338 - case 0x55: /* SKX */ 2192 + case INTEL_FAM6_HASWELL_CORE: /* HSW */ 2193 + case INTEL_FAM6_HASWELL_X: /* HSX */ 2194 + case INTEL_FAM6_HASWELL_ULT: /* HSW */ 2195 + case INTEL_FAM6_HASWELL_GT3E: /* HSW */ 2196 + case INTEL_FAM6_BROADWELL_CORE: /* BDW */ 2197 + case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ 2198 + case INTEL_FAM6_BROADWELL_X: /* BDX */ 2199 + case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ 2200 + case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ 2201 + case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ 2202 + case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ 2203 + case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ 2339 2204 pkg_cstate_limits = hsw_pkg_cstate_limits; 2340 2205 break; 2341 - case 0x37: /* BYT */ 2342 - case 0x4D: /* AVN */ 2206 + case INTEL_FAM6_SKYLAKE_X: /* SKX */ 2207 + pkg_cstate_limits = skx_pkg_cstate_limits; 2208 + break; 2209 + case INTEL_FAM6_ATOM_SILVERMONT1: /* BYT */ 2210 + case INTEL_FAM6_ATOM_SILVERMONT2: /* AVN */ 2343 2211 pkg_cstate_limits = slv_pkg_cstate_limits; 2344 2212 break; 2345 - case 0x4C: /* AMT */ 2213 + case INTEL_FAM6_ATOM_AIRMONT: /* AMT */ 2346 2214 pkg_cstate_limits = amt_pkg_cstate_limits; 2347 2215 break; 2348 - case 0x57: /* PHI */ 2216 + case INTEL_FAM6_XEON_PHI_KNL: /* PHI */ 2217 + case INTEL_FAM6_XEON_PHI_KNM: 2349 2218 pkg_cstate_limits = phi_pkg_cstate_limits; 2350 2219 break; 2351 - case 0x5C: /* BXT */ 2220 + case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ 2221 + case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ 2352 2222 pkg_cstate_limits = bxt_pkg_cstate_limits; 2353 2223 break; 2354 2224 default: ··· 2372 2234 { 2373 2235 switch (model) { 2374 2236 /* Nehalem compatible, but do not include turbo-ratio limit support */ 2375 - case 0x2E: /* Nehalem-EX Xeon - Beckton */ 2376 - case 0x2F: /* Westmere-EX Xeon - Eagleton */ 2377 - case 0x57: /* PHI - Knights Landing (different MSR definition) */ 2237 + case INTEL_FAM6_NEHALEM_EX: /* Nehalem-EX Xeon - Beckton */ 2238 + case INTEL_FAM6_WESTMERE_EX: /* Westmere-EX Xeon - Eagleton */ 2239 + case INTEL_FAM6_XEON_PHI_KNL: /* PHI - Knights Landing (different MSR definition) */ 2240 + case INTEL_FAM6_XEON_PHI_KNM: 2378 2241 return 0; 2379 2242 default: 2380 2243 return 1; ··· 2390 2251 return 0; 2391 2252 2392 2253 switch (model) { 2393 - case 0x3E: /* IVB Xeon */ 2394 - case 0x3F: /* HSW Xeon */ 2254 + case INTEL_FAM6_IVYBRIDGE_X: /* IVB Xeon */ 2255 + case INTEL_FAM6_HASWELL_X: /* HSW Xeon */ 2395 2256 return 1; 2396 2257 default: 2397 2258 return 0; ··· 2406 2267 return 0; 2407 2268 2408 2269 switch (model) { 2409 - case 0x3F: /* HSW Xeon */ 2270 + case INTEL_FAM6_HASWELL_X: /* HSW Xeon */ 2410 2271 return 1; 2411 2272 default: 2412 2273 return 0; ··· 2422 2283 return 0; 2423 2284 2424 2285 switch (model) { 2425 - case 0x57: /* Knights Landing */ 2286 + case INTEL_FAM6_XEON_PHI_KNL: /* Knights Landing */ 2287 + case INTEL_FAM6_XEON_PHI_KNM: 2426 2288 return 1; 2427 2289 default: 2428 2290 return 0; ··· 2438 2298 return 0; 2439 2299 2440 2300 switch (model) { 2441 - case 0x3A: /* IVB */ 2442 - case 0x3C: /* HSW */ 2443 - case 0x3F: /* HSX */ 2444 - case 0x45: /* HSW */ 2445 - case 0x46: /* HSW */ 2446 - case 0x3D: /* BDW */ 2447 - case 0x47: /* BDW */ 2448 - case 0x4F: /* BDX */ 2449 - case 0x56: /* BDX-DE */ 2450 - case 0x4E: /* SKL */ 2451 - case 0x5E: /* SKL */ 2452 - case 0x8E: /* KBL */ 2453 - case 0x9E: /* KBL */ 2454 - case 0x55: /* SKX */ 2301 + case INTEL_FAM6_IVYBRIDGE: /* IVB */ 2302 + case INTEL_FAM6_HASWELL_CORE: /* HSW */ 2303 + case INTEL_FAM6_HASWELL_X: /* HSX */ 2304 + case INTEL_FAM6_HASWELL_ULT: /* HSW */ 2305 + case INTEL_FAM6_HASWELL_GT3E: /* HSW */ 2306 + case INTEL_FAM6_BROADWELL_CORE: /* BDW */ 2307 + case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ 2308 + case INTEL_FAM6_BROADWELL_X: /* BDX */ 2309 + case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ 2310 + case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ 2311 + case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ 2312 + case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ 2313 + case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ 2314 + case INTEL_FAM6_SKYLAKE_X: /* SKX */ 2455 2315 2456 - case 0x57: /* Knights Landing */ 2316 + case INTEL_FAM6_XEON_PHI_KNL: /* Knights Landing */ 2317 + case INTEL_FAM6_XEON_PHI_KNM: 2457 2318 return 1; 2458 2319 default: 2459 2320 return 0; ··· 2734 2593 return ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units; 2735 2594 2736 2595 switch (model) { 2737 - case 0x37: 2738 - case 0x4D: 2596 + case INTEL_FAM6_ATOM_SILVERMONT1: 2597 + case INTEL_FAM6_ATOM_SILVERMONT2: 2739 2598 return 30.0; 2740 2599 default: 2741 2600 return 135.0; ··· 2752 2611 /* only called for genuine_intel, family 6 */ 2753 2612 2754 2613 switch (model) { 2755 - case 0x3F: /* HSX */ 2756 - case 0x4F: /* BDX */ 2757 - case 0x56: /* BDX-DE */ 2758 - case 0x57: /* KNL */ 2614 + case INTEL_FAM6_HASWELL_X: /* HSX */ 2615 + case INTEL_FAM6_BROADWELL_X: /* BDX */ 2616 + case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ 2617 + case INTEL_FAM6_XEON_PHI_KNL: /* KNL */ 2618 + case INTEL_FAM6_XEON_PHI_KNM: 2759 2619 return (rapl_dram_energy_units = 15.3 / 1000000); 2760 2620 default: 2761 2621 return (rapl_energy_units); ··· 2782 2640 return; 2783 2641 2784 2642 switch (model) { 2785 - case 0x2A: 2786 - case 0x3A: 2787 - case 0x3C: /* HSW */ 2788 - case 0x45: /* HSW */ 2789 - case 0x46: /* HSW */ 2790 - case 0x3D: /* BDW */ 2791 - case 0x47: /* BDW */ 2643 + case INTEL_FAM6_SANDYBRIDGE: 2644 + case INTEL_FAM6_IVYBRIDGE: 2645 + case INTEL_FAM6_HASWELL_CORE: /* HSW */ 2646 + case INTEL_FAM6_HASWELL_ULT: /* HSW */ 2647 + case INTEL_FAM6_HASWELL_GT3E: /* HSW */ 2648 + case INTEL_FAM6_BROADWELL_CORE: /* BDW */ 2649 + case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ 2792 2650 do_rapl = RAPL_PKG | RAPL_CORES | RAPL_CORE_POLICY | RAPL_GFX | RAPL_PKG_POWER_INFO; 2793 2651 break; 2794 - case 0x5C: /* BXT */ 2652 + case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ 2795 2653 do_rapl = RAPL_PKG | RAPL_PKG_POWER_INFO; 2796 2654 break; 2797 - case 0x4E: /* SKL */ 2798 - case 0x5E: /* SKL */ 2799 - case 0x8E: /* KBL */ 2800 - case 0x9E: /* KBL */ 2655 + case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ 2656 + case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ 2657 + case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ 2658 + case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ 2801 2659 do_rapl = RAPL_PKG | RAPL_DRAM | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_PKG_POWER_INFO; 2802 2660 break; 2803 - case 0x3F: /* HSX */ 2804 - case 0x4F: /* BDX */ 2805 - case 0x56: /* BDX-DE */ 2806 - case 0x55: /* SKX */ 2807 - case 0x57: /* KNL */ 2661 + case INTEL_FAM6_HASWELL_X: /* HSX */ 2662 + case INTEL_FAM6_BROADWELL_X: /* BDX */ 2663 + case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ 2664 + case INTEL_FAM6_SKYLAKE_X: /* SKX */ 2665 + case INTEL_FAM6_XEON_PHI_KNL: /* KNL */ 2666 + case INTEL_FAM6_XEON_PHI_KNM: 2808 2667 do_rapl = RAPL_PKG | RAPL_DRAM | RAPL_DRAM_POWER_INFO | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_PKG_POWER_INFO; 2809 2668 break; 2810 - case 0x2D: 2811 - case 0x3E: 2669 + case INTEL_FAM6_SANDYBRIDGE_X: 2670 + case INTEL_FAM6_IVYBRIDGE_X: 2812 2671 do_rapl = RAPL_PKG | RAPL_CORES | RAPL_CORE_POLICY | RAPL_DRAM | RAPL_DRAM_POWER_INFO | RAPL_PKG_PERF_STATUS | RAPL_DRAM_PERF_STATUS | RAPL_PKG_POWER_INFO; 2813 2672 break; 2814 - case 0x37: /* BYT */ 2815 - case 0x4D: /* AVN */ 2816 - do_rapl = RAPL_PKG | RAPL_CORES ; 2673 + case INTEL_FAM6_ATOM_SILVERMONT1: /* BYT */ 2674 + case INTEL_FAM6_ATOM_SILVERMONT2: /* AVN */ 2675 + do_rapl = RAPL_PKG | RAPL_CORES; 2676 + break; 2677 + case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ 2678 + do_rapl = RAPL_PKG | RAPL_DRAM | RAPL_DRAM_POWER_INFO | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_PKG_POWER_INFO | RAPL_CORES_ENERGY_STATUS; 2817 2679 break; 2818 2680 default: 2819 2681 return; ··· 2828 2682 return; 2829 2683 2830 2684 rapl_power_units = 1.0 / (1 << (msr & 0xF)); 2831 - if (model == 0x37) 2685 + if (model == INTEL_FAM6_ATOM_SILVERMONT1) 2832 2686 rapl_energy_units = 1.0 * (1 << (msr >> 8 & 0x1F)) / 1000000; 2833 2687 else 2834 2688 rapl_energy_units = 1.0 / (1 << (msr >> 8 & 0x1F)); ··· 2859 2713 return; 2860 2714 2861 2715 switch (model) { 2862 - case 0x3C: /* HSW */ 2863 - case 0x45: /* HSW */ 2864 - case 0x46: /* HSW */ 2716 + case INTEL_FAM6_HASWELL_CORE: /* HSW */ 2717 + case INTEL_FAM6_HASWELL_ULT: /* HSW */ 2718 + case INTEL_FAM6_HASWELL_GT3E: /* HSW */ 2865 2719 do_gfx_perf_limit_reasons = 1; 2866 - case 0x3F: /* HSX */ 2720 + case INTEL_FAM6_HASWELL_X: /* HSX */ 2867 2721 do_core_perf_limit_reasons = 1; 2868 2722 do_ring_perf_limit_reasons = 1; 2869 2723 default: ··· 2883 2737 cpu = t->cpu_id; 2884 2738 2885 2739 /* DTS is per-core, no need to print for each thread */ 2886 - if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) 2740 + if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) 2887 2741 return 0; 2888 2742 2889 2743 if (cpu_migrate(cpu)) { ··· 3032 2886 fprintf(outf, "cpu%d: MSR_PP0_POLICY: %lld\n", cpu, msr & 0xF); 3033 2887 } 3034 2888 } 3035 - if (do_rapl & RAPL_CORES) { 2889 + if (do_rapl & RAPL_CORES_POWER_LIMIT) { 3036 2890 if (debug) { 3037 - 3038 2891 if (get_msr(cpu, MSR_PP0_POWER_LIMIT, &msr)) 3039 2892 return -9; 3040 2893 fprintf(outf, "cpu%d: MSR_PP0_POWER_LIMIT: 0x%08llx (%slocked)\n", ··· 3072 2927 return 0; 3073 2928 3074 2929 switch (model) { 3075 - case 0x2A: 3076 - case 0x2D: 3077 - case 0x3A: /* IVB */ 3078 - case 0x3E: /* IVB Xeon */ 3079 - case 0x3C: /* HSW */ 3080 - case 0x3F: /* HSW */ 3081 - case 0x45: /* HSW */ 3082 - case 0x46: /* HSW */ 3083 - case 0x3D: /* BDW */ 3084 - case 0x47: /* BDW */ 3085 - case 0x4F: /* BDX */ 3086 - case 0x56: /* BDX-DE */ 3087 - case 0x4E: /* SKL */ 3088 - case 0x5E: /* SKL */ 3089 - case 0x8E: /* KBL */ 3090 - case 0x9E: /* KBL */ 3091 - case 0x55: /* SKX */ 3092 - case 0x5C: /* BXT */ 2930 + case INTEL_FAM6_SANDYBRIDGE: 2931 + case INTEL_FAM6_SANDYBRIDGE_X: 2932 + case INTEL_FAM6_IVYBRIDGE: /* IVB */ 2933 + case INTEL_FAM6_IVYBRIDGE_X: /* IVB Xeon */ 2934 + case INTEL_FAM6_HASWELL_CORE: /* HSW */ 2935 + case INTEL_FAM6_HASWELL_X: /* HSW */ 2936 + case INTEL_FAM6_HASWELL_ULT: /* HSW */ 2937 + case INTEL_FAM6_HASWELL_GT3E: /* HSW */ 2938 + case INTEL_FAM6_BROADWELL_CORE: /* BDW */ 2939 + case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ 2940 + case INTEL_FAM6_BROADWELL_X: /* BDX */ 2941 + case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ 2942 + case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ 2943 + case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ 2944 + case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ 2945 + case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ 2946 + case INTEL_FAM6_SKYLAKE_X: /* SKX */ 2947 + case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ 2948 + case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ 3093 2949 return 1; 3094 2950 } 3095 2951 return 0; ··· 3114 2968 return 0; 3115 2969 3116 2970 switch (model) { 3117 - case 0x45: /* HSW */ 3118 - case 0x3D: /* BDW */ 3119 - case 0x4E: /* SKL */ 3120 - case 0x5E: /* SKL */ 3121 - case 0x8E: /* KBL */ 3122 - case 0x9E: /* KBL */ 3123 - case 0x5C: /* BXT */ 2971 + case INTEL_FAM6_HASWELL_ULT: /* HSW */ 2972 + case INTEL_FAM6_BROADWELL_CORE: /* BDW */ 2973 + case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ 2974 + case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ 2975 + case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ 2976 + case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ 2977 + case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ 3124 2978 return 1; 3125 2979 } 3126 2980 return 0; ··· 3140 2994 return 0; 3141 2995 3142 2996 switch (model) { 3143 - case 0x4E: /* SKL */ 3144 - case 0x5E: /* SKL */ 3145 - case 0x8E: /* KBL */ 3146 - case 0x9E: /* KBL */ 2997 + case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ 2998 + case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ 2999 + case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ 3000 + case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ 3147 3001 return 1; 3148 3002 } 3149 3003 return 0; ··· 3156 3010 if (!genuine_intel) 3157 3011 return 0; 3158 3012 switch (model) { 3159 - case 0x37: /* BYT */ 3160 - case 0x4D: /* AVN */ 3013 + case INTEL_FAM6_ATOM_SILVERMONT1: /* BYT */ 3014 + case INTEL_FAM6_ATOM_SILVERMONT2: /* AVN */ 3161 3015 return 1; 3162 3016 } 3163 3017 return 0; ··· 3168 3022 if (!genuine_intel) 3169 3023 return 0; 3170 3024 switch (model) { 3171 - case 0x57: /* KNL */ 3025 + case INTEL_FAM6_XEON_PHI_KNL: /* KNL */ 3026 + case INTEL_FAM6_XEON_PHI_KNM: 3172 3027 return 1; 3173 3028 } 3174 3029 return 0; ··· 3197 3050 i = msr & 0xf; 3198 3051 if (i >= SLM_BCLK_FREQS) { 3199 3052 fprintf(outf, "SLM BCLK[%d] invalid\n", i); 3200 - msr = 3; 3053 + i = 3; 3201 3054 } 3202 3055 freq = slm_freq_table[i]; 3203 3056 ··· 3321 3174 return; 3322 3175 3323 3176 if (!get_msr(base_cpu, MSR_MISC_PWR_MGMT, &msr)) 3324 - fprintf(outf, "cpu%d: MSR_MISC_PWR_MGMT: 0x%08llx (%sable-EIST_Coordination %sable-EPB)\n", 3177 + fprintf(outf, "cpu%d: MSR_MISC_PWR_MGMT: 0x%08llx (%sable-EIST_Coordination %sable-EPB %sable-OOB)\n", 3325 3178 base_cpu, msr, 3326 3179 msr & (1 << 0) ? "DIS" : "EN", 3327 - msr & (1 << 1) ? "EN" : "DIS"); 3180 + msr & (1 << 1) ? "EN" : "DIS", 3181 + msr & (1 << 8) ? "EN" : "DIS"); 3328 3182 } 3329 3183 3330 3184 void process_cpuid() ··· 3451 3303 3452 3304 if (crystal_hz == 0) 3453 3305 switch(model) { 3454 - case 0x4E: /* SKL */ 3455 - case 0x5E: /* SKL */ 3456 - case 0x8E: /* KBL */ 3457 - case 0x9E: /* KBL */ 3306 + case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ 3307 + case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ 3308 + case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ 3309 + case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ 3458 3310 crystal_hz = 24000000; /* 24.0 MHz */ 3459 3311 break; 3460 - case 0x55: /* SKX */ 3312 + case INTEL_FAM6_SKYLAKE_X: /* SKX */ 3313 + case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ 3461 3314 crystal_hz = 25000000; /* 25.0 MHz */ 3462 3315 break; 3463 - case 0x5C: /* BXT */ 3316 + case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ 3464 3317 crystal_hz = 19200000; /* 19.2 MHz */ 3465 3318 break; 3466 3319 default: ··· 3534 3385 "when COMMAND completes.\n" 3535 3386 "If no COMMAND is specified, turbostat wakes every 5-seconds\n" 3536 3387 "to print statistics, until interrupted.\n" 3388 + "--add add a counter\n" 3389 + " eg. --add msr0x10,u64,cpu,delta,MY_TSC\n" 3537 3390 "--debug run in \"debug\" mode\n" 3538 3391 "--interval sec Override default 5-second measurement interval\n" 3539 3392 "--help print this help message\n" 3540 - "--counter msr print 32-bit counter at address \"msr\"\n" 3541 - "--Counter msr print 64-bit Counter at address \"msr\"\n" 3542 3393 "--out file create or truncate \"file\" for all output\n" 3543 - "--msr msr print 32-bit value at address \"msr\"\n" 3544 - "--MSR msr print 64-bit Value at address \"msr\"\n" 3545 3394 "--version print version information\n" 3546 3395 "\n" 3547 3396 "For more help, run \"man turbostat\"\n"); ··· 3662 3515 int i; 3663 3516 3664 3517 *t = calloc(topo.num_threads_per_core * topo.num_cores_per_pkg * 3665 - topo.num_packages, sizeof(struct thread_data)); 3518 + topo.num_packages, sizeof(struct thread_data) + sys.thread_counter_bytes); 3666 3519 if (*t == NULL) 3667 3520 goto error; 3668 3521 ··· 3671 3524 (*t)[i].cpu_id = -1; 3672 3525 3673 3526 *c = calloc(topo.num_cores_per_pkg * topo.num_packages, 3674 - sizeof(struct core_data)); 3527 + sizeof(struct core_data) + sys.core_counter_bytes); 3675 3528 if (*c == NULL) 3676 3529 goto error; 3677 3530 3678 3531 for (i = 0; i < topo.num_cores_per_pkg * topo.num_packages; i++) 3679 3532 (*c)[i].core_id = -1; 3680 3533 3681 - *p = calloc(topo.num_packages, sizeof(struct pkg_data)); 3534 + *p = calloc(topo.num_packages, sizeof(struct pkg_data) + sys.package_counter_bytes); 3682 3535 if (*p == NULL) 3683 3536 goto error; 3684 3537 ··· 3745 3598 } 3746 3599 void allocate_fd_percpu(void) 3747 3600 { 3748 - fd_percpu = calloc(topo.max_cpu_num, sizeof(int)); 3601 + fd_percpu = calloc(topo.max_cpu_num + 1, sizeof(int)); 3749 3602 if (fd_percpu == NULL) 3750 3603 err(-1, "calloc fd_percpu"); 3751 3604 } ··· 3755 3608 if (irq_column_2_cpu == NULL) 3756 3609 err(-1, "calloc %d", topo.num_cpus); 3757 3610 3758 - irqs_per_cpu = calloc(topo.max_cpu_num, sizeof(int)); 3611 + irqs_per_cpu = calloc(topo.max_cpu_num + 1, sizeof(int)); 3759 3612 if (irqs_per_cpu == NULL) 3760 - err(-1, "calloc %d", topo.max_cpu_num); 3613 + err(-1, "calloc %d", topo.max_cpu_num + 1); 3761 3614 } 3762 3615 void setup_all_buffers(void) 3763 3616 { ··· 3844 3697 for_all_cpus(get_counters, ODD_COUNTERS); 3845 3698 gettimeofday(&tv_odd, (struct timezone *)NULL); 3846 3699 timersub(&tv_odd, &tv_even, &tv_delta); 3847 - for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS); 3848 - compute_average(EVEN_COUNTERS); 3849 - format_all_counters(EVEN_COUNTERS); 3700 + if (for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS)) 3701 + fprintf(outf, "%s: Counter reset detected\n", progname); 3702 + else { 3703 + compute_average(EVEN_COUNTERS); 3704 + format_all_counters(EVEN_COUNTERS); 3705 + } 3850 3706 3851 3707 fprintf(outf, "%.6f sec\n", tv_delta.tv_sec + tv_delta.tv_usec/1000000.0); 3852 3708 ··· 3876 3726 } 3877 3727 3878 3728 void print_version() { 3879 - fprintf(outf, "turbostat version 4.12 5 Apr 2016" 3729 + fprintf(outf, "turbostat version 4.16 24 Dec 2016" 3880 3730 " - Len Brown <lenb@kernel.org>\n"); 3881 3731 } 3882 3732 3733 + int add_counter(unsigned int msr_num, char *name, unsigned int width, 3734 + enum counter_scope scope, enum counter_type type, 3735 + enum counter_format format) 3736 + { 3737 + struct msr_counter *msrp; 3738 + 3739 + msrp = calloc(1, sizeof(struct msr_counter)); 3740 + if (msrp == NULL) { 3741 + perror("calloc"); 3742 + exit(1); 3743 + } 3744 + 3745 + msrp->msr_num = msr_num; 3746 + strncpy(msrp->name, name, NAME_BYTES); 3747 + msrp->width = width; 3748 + msrp->type = type; 3749 + msrp->format = format; 3750 + 3751 + switch (scope) { 3752 + 3753 + case SCOPE_CPU: 3754 + sys.thread_counter_bytes += 64; 3755 + msrp->next = sys.tp; 3756 + sys.tp = msrp; 3757 + sys.thread_counter_bytes += sizeof(unsigned long long); 3758 + break; 3759 + 3760 + case SCOPE_CORE: 3761 + sys.core_counter_bytes += 64; 3762 + msrp->next = sys.cp; 3763 + sys.cp = msrp; 3764 + sys.core_counter_bytes += sizeof(unsigned long long); 3765 + break; 3766 + 3767 + case SCOPE_PACKAGE: 3768 + sys.package_counter_bytes += 64; 3769 + msrp->next = sys.pp; 3770 + sys.pp = msrp; 3771 + sys.package_counter_bytes += sizeof(unsigned long long); 3772 + break; 3773 + } 3774 + 3775 + return 0; 3776 + } 3777 + 3778 + void parse_add_command(char *add_command) 3779 + { 3780 + int msr_num = 0; 3781 + char name_buffer[NAME_BYTES]; 3782 + int width = 64; 3783 + int fail = 0; 3784 + enum counter_scope scope = SCOPE_CPU; 3785 + enum counter_type type = COUNTER_CYCLES; 3786 + enum counter_format format = FORMAT_DELTA; 3787 + 3788 + while (add_command) { 3789 + 3790 + if (sscanf(add_command, "msr0x%x", &msr_num) == 1) 3791 + goto next; 3792 + 3793 + if (sscanf(add_command, "msr%d", &msr_num) == 1) 3794 + goto next; 3795 + 3796 + if (sscanf(add_command, "u%d", &width) == 1) { 3797 + if ((width == 32) || (width == 64)) 3798 + goto next; 3799 + width = 64; 3800 + } 3801 + if (!strncmp(add_command, "cpu", strlen("cpu"))) { 3802 + scope = SCOPE_CPU; 3803 + goto next; 3804 + } 3805 + if (!strncmp(add_command, "core", strlen("core"))) { 3806 + scope = SCOPE_CORE; 3807 + goto next; 3808 + } 3809 + if (!strncmp(add_command, "package", strlen("package"))) { 3810 + scope = SCOPE_PACKAGE; 3811 + goto next; 3812 + } 3813 + if (!strncmp(add_command, "cycles", strlen("cycles"))) { 3814 + type = COUNTER_CYCLES; 3815 + goto next; 3816 + } 3817 + if (!strncmp(add_command, "seconds", strlen("seconds"))) { 3818 + type = COUNTER_SECONDS; 3819 + goto next; 3820 + } 3821 + if (!strncmp(add_command, "raw", strlen("raw"))) { 3822 + format = FORMAT_RAW; 3823 + goto next; 3824 + } 3825 + if (!strncmp(add_command, "delta", strlen("delta"))) { 3826 + format = FORMAT_DELTA; 3827 + goto next; 3828 + } 3829 + if (!strncmp(add_command, "percent", strlen("percent"))) { 3830 + format = FORMAT_PERCENT; 3831 + goto next; 3832 + } 3833 + 3834 + if (sscanf(add_command, "%18s,%*s", name_buffer) == 1) { /* 18 < NAME_BYTES */ 3835 + char *eos; 3836 + 3837 + eos = strchr(name_buffer, ','); 3838 + if (eos) 3839 + *eos = '\0'; 3840 + goto next; 3841 + } 3842 + 3843 + next: 3844 + add_command = strchr(add_command, ','); 3845 + if (add_command) 3846 + add_command++; 3847 + 3848 + } 3849 + if (msr_num == 0) { 3850 + fprintf(stderr, "--add: (msrDDD | msr0xXXX) required\n"); 3851 + fail++; 3852 + } 3853 + 3854 + /* generate default column header */ 3855 + if (*name_buffer == '\0') { 3856 + if (format == FORMAT_RAW) { 3857 + if (width == 32) 3858 + sprintf(name_buffer, "msr%d", msr_num); 3859 + else 3860 + sprintf(name_buffer, "MSR%d", msr_num); 3861 + } else if (format == FORMAT_DELTA) { 3862 + if (width == 32) 3863 + sprintf(name_buffer, "cnt%d", msr_num); 3864 + else 3865 + sprintf(name_buffer, "CNT%d", msr_num); 3866 + } else if (format == FORMAT_PERCENT) { 3867 + if (width == 32) 3868 + sprintf(name_buffer, "msr%d%%", msr_num); 3869 + else 3870 + sprintf(name_buffer, "MSR%d%%", msr_num); 3871 + } 3872 + } 3873 + 3874 + if (add_counter(msr_num, name_buffer, width, scope, type, format)) 3875 + fail++; 3876 + 3877 + if (fail) { 3878 + help(); 3879 + exit(1); 3880 + } 3881 + } 3883 3882 void cmdline(int argc, char **argv) 3884 3883 { 3885 3884 int opt; 3886 3885 int option_index = 0; 3887 3886 static struct option long_options[] = { 3888 - {"Counter", required_argument, 0, 'C'}, 3889 - {"counter", required_argument, 0, 'c'}, 3887 + {"add", required_argument, 0, 'a'}, 3890 3888 {"Dump", no_argument, 0, 'D'}, 3891 3889 {"debug", no_argument, 0, 'd'}, 3892 3890 {"interval", required_argument, 0, 'i'}, 3893 3891 {"help", no_argument, 0, 'h'}, 3894 3892 {"Joules", no_argument, 0, 'J'}, 3895 - {"MSR", required_argument, 0, 'M'}, 3896 - {"msr", required_argument, 0, 'm'}, 3897 3893 {"out", required_argument, 0, 'o'}, 3898 3894 {"Package", no_argument, 0, 'p'}, 3899 3895 {"processor", no_argument, 0, 'p'}, ··· 4054 3758 while ((opt = getopt_long_only(argc, argv, "+C:c:Ddhi:JM:m:o:PpST:v", 4055 3759 long_options, &option_index)) != -1) { 4056 3760 switch (opt) { 4057 - case 'C': 4058 - sscanf(optarg, "%x", &extra_delta_offset64); 4059 - break; 4060 - case 'c': 4061 - sscanf(optarg, "%x", &extra_delta_offset32); 3761 + case 'a': 3762 + parse_add_command(optarg); 4062 3763 break; 4063 3764 case 'D': 4064 3765 dump_only++; ··· 4083 3790 break; 4084 3791 case 'J': 4085 3792 rapl_joules++; 4086 - break; 4087 - case 'M': 4088 - sscanf(optarg, "%x", &extra_msr_offset64); 4089 - break; 4090 - case 'm': 4091 - sscanf(optarg, "%x", &extra_msr_offset32); 4092 3793 break; 4093 3794 case 'o': 4094 3795 outf = fopen_or_die(optarg, "w");