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 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux

Pull turbostat updates from Len Brown.

* 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux:
tools/power turbostat: introduce -s to dump counters
tools/power turbostat: remove unused command line option
turbostat: Add option to report joules consumed per sample
turbostat: run on HSX
turbostat: Add a .gitignore to ignore the compiled turbostat binary
turbostat: Clean up error handling; disambiguate error messages; use err and errx
turbostat: Factor out common function to open file and exit on failure
turbostat: Add a helper to parse a single int out of a file
turbostat: Check return value of fscanf
turbostat: Use GCC's CPUID functions to support PIC
turbostat: Don't attempt to printf an off_t with %zx
turbostat: Don't put unprocessed uapi headers in the include path

+244 -200
+1
tools/power/x86/turbostat/.gitignore
··· 1 + turbostat
+1 -1
tools/power/x86/turbostat/Makefile
··· 5 5 6 6 turbostat : turbostat.c 7 7 CFLAGS += -Wall 8 - CFLAGS += -I../../../../arch/x86/include/uapi/ 8 + CFLAGS += -DMSRHEADER='"../../../../arch/x86/include/uapi/asm/msr-index.h"' 9 9 10 10 %: %.c 11 11 @mkdir -p $(BUILD_OUTPUT)
+242 -199
tools/power/x86/turbostat/turbostat.c
··· 20 20 */ 21 21 22 22 #define _GNU_SOURCE 23 - #include <asm/msr.h> 23 + #include MSRHEADER 24 + #include <stdarg.h> 24 25 #include <stdio.h> 26 + #include <err.h> 25 27 #include <unistd.h> 26 28 #include <sys/types.h> 27 29 #include <sys/wait.h> ··· 37 35 #include <string.h> 38 36 #include <ctype.h> 39 37 #include <sched.h> 38 + #include <cpuid.h> 40 39 41 40 char *proc_stat = "/proc/stat"; 42 41 unsigned int interval_sec = 5; /* set with -i interval_sec */ 43 42 unsigned int verbose; /* set with -v */ 44 43 unsigned int rapl_verbose; /* set with -R */ 44 + unsigned int rapl_joules; /* set with -J */ 45 45 unsigned int thermal_verbose; /* set with -T */ 46 - unsigned int summary_only; /* set with -s */ 46 + unsigned int summary_only; /* set with -S */ 47 + unsigned int dump_only; /* set with -s */ 47 48 unsigned int skip_c0; 48 49 unsigned int skip_c1; 49 50 unsigned int do_nhm_cstates; ··· 82 77 double rapl_power_units, rapl_energy_units, rapl_time_units; 83 78 double rapl_joule_counter_range; 84 79 85 - #define RAPL_PKG (1 << 0) 86 - #define RAPL_CORES (1 << 1) 87 - #define RAPL_GFX (1 << 2) 88 - #define RAPL_DRAM (1 << 3) 89 - #define RAPL_PKG_PERF_STATUS (1 << 4) 90 - #define RAPL_DRAM_PERF_STATUS (1 << 5) 91 - #define RAPL_PKG_POWER_INFO (1 << 6) 92 - #define RAPL_CORE_POLICY (1 << 7) 80 + #define RAPL_PKG (1 << 0) 81 + /* 0x610 MSR_PKG_POWER_LIMIT */ 82 + /* 0x611 MSR_PKG_ENERGY_STATUS */ 83 + #define RAPL_PKG_PERF_STATUS (1 << 1) 84 + /* 0x613 MSR_PKG_PERF_STATUS */ 85 + #define RAPL_PKG_POWER_INFO (1 << 2) 86 + /* 0x614 MSR_PKG_POWER_INFO */ 87 + 88 + #define RAPL_DRAM (1 << 3) 89 + /* 0x618 MSR_DRAM_POWER_LIMIT */ 90 + /* 0x619 MSR_DRAM_ENERGY_STATUS */ 91 + /* 0x61c MSR_DRAM_POWER_INFO */ 92 + #define RAPL_DRAM_PERF_STATUS (1 << 4) 93 + /* 0x61b MSR_DRAM_PERF_STATUS */ 94 + 95 + #define RAPL_CORES (1 << 5) 96 + /* 0x638 MSR_PP0_POWER_LIMIT */ 97 + /* 0x639 MSR_PP0_ENERGY_STATUS */ 98 + #define RAPL_CORE_POLICY (1 << 6) 99 + /* 0x63a MSR_PP0_POLICY */ 100 + 101 + 102 + #define RAPL_GFX (1 << 7) 103 + /* 0x640 MSR_PP1_POWER_LIMIT */ 104 + /* 0x641 MSR_PP1_ENERGY_STATUS */ 105 + /* 0x642 MSR_PP1_POLICY */ 93 106 #define TJMAX_DEFAULT 100 94 107 95 108 #define MAX(a, b) ((a) > (b) ? (a) : (b)) ··· 257 234 close(fd); 258 235 259 236 if (retval != sizeof *msr) { 260 - fprintf(stderr, "%s offset 0x%zx read failed\n", pathname, offset); 237 + fprintf(stderr, "%s offset 0x%llx read failed\n", pathname, (unsigned long long)offset); 261 238 return -1; 262 239 } 263 240 ··· 319 296 outp += sprintf(outp, " %%pc10"); 320 297 } 321 298 322 - if (do_rapl & RAPL_PKG) 323 - outp += sprintf(outp, " Pkg_W"); 324 - if (do_rapl & RAPL_CORES) 325 - outp += sprintf(outp, " Cor_W"); 326 - if (do_rapl & RAPL_GFX) 327 - outp += sprintf(outp, " GFX_W"); 328 - if (do_rapl & RAPL_DRAM) 329 - outp += sprintf(outp, " RAM_W"); 330 - if (do_rapl & RAPL_PKG_PERF_STATUS) 331 - outp += sprintf(outp, " PKG_%%"); 332 - if (do_rapl & RAPL_DRAM_PERF_STATUS) 333 - outp += sprintf(outp, " RAM_%%"); 299 + if (do_rapl && !rapl_joules) { 300 + if (do_rapl & RAPL_PKG) 301 + outp += sprintf(outp, " Pkg_W"); 302 + if (do_rapl & RAPL_CORES) 303 + outp += sprintf(outp, " Cor_W"); 304 + if (do_rapl & RAPL_GFX) 305 + outp += sprintf(outp, " GFX_W"); 306 + if (do_rapl & RAPL_DRAM) 307 + outp += sprintf(outp, " RAM_W"); 308 + if (do_rapl & RAPL_PKG_PERF_STATUS) 309 + outp += sprintf(outp, " PKG_%%"); 310 + if (do_rapl & RAPL_DRAM_PERF_STATUS) 311 + outp += sprintf(outp, " RAM_%%"); 312 + } else { 313 + if (do_rapl & RAPL_PKG) 314 + outp += sprintf(outp, " Pkg_J"); 315 + if (do_rapl & RAPL_CORES) 316 + outp += sprintf(outp, " Cor_J"); 317 + if (do_rapl & RAPL_GFX) 318 + outp += sprintf(outp, " GFX_J"); 319 + if (do_rapl & RAPL_DRAM) 320 + outp += sprintf(outp, " RAM_W"); 321 + if (do_rapl & RAPL_PKG_PERF_STATUS) 322 + outp += sprintf(outp, " PKG_%%"); 323 + if (do_rapl & RAPL_DRAM_PERF_STATUS) 324 + outp += sprintf(outp, " RAM_%%"); 325 + outp += sprintf(outp, " time"); 334 326 327 + } 335 328 outp += sprintf(outp, "\n"); 336 329 } 337 330 338 331 int dump_counters(struct thread_data *t, struct core_data *c, 339 332 struct pkg_data *p) 340 333 { 341 - fprintf(stderr, "t %p, c %p, p %p\n", t, c, p); 334 + outp += sprintf(outp, "t %p, c %p, p %p\n", t, c, p); 342 335 343 336 if (t) { 344 - fprintf(stderr, "CPU: %d flags 0x%x\n", t->cpu_id, t->flags); 345 - fprintf(stderr, "TSC: %016llX\n", t->tsc); 346 - fprintf(stderr, "aperf: %016llX\n", t->aperf); 347 - fprintf(stderr, "mperf: %016llX\n", t->mperf); 348 - fprintf(stderr, "c1: %016llX\n", t->c1); 349 - fprintf(stderr, "msr0x%x: %08llX\n", 337 + outp += sprintf(outp, "CPU: %d flags 0x%x\n", 338 + t->cpu_id, t->flags); 339 + outp += sprintf(outp, "TSC: %016llX\n", t->tsc); 340 + outp += sprintf(outp, "aperf: %016llX\n", t->aperf); 341 + outp += sprintf(outp, "mperf: %016llX\n", t->mperf); 342 + outp += sprintf(outp, "c1: %016llX\n", t->c1); 343 + outp += sprintf(outp, "msr0x%x: %08llX\n", 350 344 extra_delta_offset32, t->extra_delta32); 351 - fprintf(stderr, "msr0x%x: %016llX\n", 345 + outp += sprintf(outp, "msr0x%x: %016llX\n", 352 346 extra_delta_offset64, t->extra_delta64); 353 - fprintf(stderr, "msr0x%x: %08llX\n", 347 + outp += sprintf(outp, "msr0x%x: %08llX\n", 354 348 extra_msr_offset32, t->extra_msr32); 355 - fprintf(stderr, "msr0x%x: %016llX\n", 349 + outp += sprintf(outp, "msr0x%x: %016llX\n", 356 350 extra_msr_offset64, t->extra_msr64); 357 351 if (do_smi) 358 - fprintf(stderr, "SMI: %08X\n", t->smi_count); 352 + outp += sprintf(outp, "SMI: %08X\n", t->smi_count); 359 353 } 360 354 361 355 if (c) { 362 - fprintf(stderr, "core: %d\n", c->core_id); 363 - fprintf(stderr, "c3: %016llX\n", c->c3); 364 - fprintf(stderr, "c6: %016llX\n", c->c6); 365 - fprintf(stderr, "c7: %016llX\n", c->c7); 366 - fprintf(stderr, "DTS: %dC\n", c->core_temp_c); 356 + outp += sprintf(outp, "core: %d\n", c->core_id); 357 + outp += sprintf(outp, "c3: %016llX\n", c->c3); 358 + outp += sprintf(outp, "c6: %016llX\n", c->c6); 359 + outp += sprintf(outp, "c7: %016llX\n", c->c7); 360 + outp += sprintf(outp, "DTS: %dC\n", c->core_temp_c); 367 361 } 368 362 369 363 if (p) { 370 - fprintf(stderr, "package: %d\n", p->package_id); 371 - fprintf(stderr, "pc2: %016llX\n", p->pc2); 372 - fprintf(stderr, "pc3: %016llX\n", p->pc3); 373 - fprintf(stderr, "pc6: %016llX\n", p->pc6); 374 - fprintf(stderr, "pc7: %016llX\n", p->pc7); 375 - fprintf(stderr, "pc8: %016llX\n", p->pc8); 376 - fprintf(stderr, "pc9: %016llX\n", p->pc9); 377 - fprintf(stderr, "pc10: %016llX\n", p->pc10); 378 - fprintf(stderr, "Joules PKG: %0X\n", p->energy_pkg); 379 - fprintf(stderr, "Joules COR: %0X\n", p->energy_cores); 380 - fprintf(stderr, "Joules GFX: %0X\n", p->energy_gfx); 381 - fprintf(stderr, "Joules RAM: %0X\n", p->energy_dram); 382 - fprintf(stderr, "Throttle PKG: %0X\n", p->rapl_pkg_perf_status); 383 - fprintf(stderr, "Throttle RAM: %0X\n", p->rapl_dram_perf_status); 384 - fprintf(stderr, "PTM: %dC\n", p->pkg_temp_c); 364 + outp += sprintf(outp, "package: %d\n", p->package_id); 365 + outp += sprintf(outp, "pc2: %016llX\n", p->pc2); 366 + outp += sprintf(outp, "pc3: %016llX\n", p->pc3); 367 + outp += sprintf(outp, "pc6: %016llX\n", p->pc6); 368 + outp += sprintf(outp, "pc7: %016llX\n", p->pc7); 369 + outp += sprintf(outp, "pc8: %016llX\n", p->pc8); 370 + outp += sprintf(outp, "pc9: %016llX\n", p->pc9); 371 + outp += sprintf(outp, "pc10: %016llX\n", p->pc10); 372 + outp += sprintf(outp, "Joules PKG: %0X\n", p->energy_pkg); 373 + outp += sprintf(outp, "Joules COR: %0X\n", p->energy_cores); 374 + outp += sprintf(outp, "Joules GFX: %0X\n", p->energy_gfx); 375 + outp += sprintf(outp, "Joules RAM: %0X\n", p->energy_dram); 376 + outp += sprintf(outp, "Throttle PKG: %0X\n", 377 + p->rapl_pkg_perf_status); 378 + outp += sprintf(outp, "Throttle RAM: %0X\n", 379 + p->rapl_dram_perf_status); 380 + outp += sprintf(outp, "PTM: %dC\n", p->pkg_temp_c); 385 381 } 382 + 383 + outp += sprintf(outp, "\n"); 384 + 386 385 return 0; 387 386 } 388 387 ··· 572 527 fmt6 = " %4.0f**"; 573 528 } 574 529 575 - if (do_rapl & RAPL_PKG) 576 - outp += sprintf(outp, fmt6, p->energy_pkg * rapl_energy_units / interval_float); 577 - if (do_rapl & RAPL_CORES) 578 - outp += sprintf(outp, fmt6, p->energy_cores * rapl_energy_units / interval_float); 579 - if (do_rapl & RAPL_GFX) 580 - outp += sprintf(outp, fmt5, p->energy_gfx * rapl_energy_units / interval_float); 581 - if (do_rapl & RAPL_DRAM) 582 - outp += sprintf(outp, fmt5, p->energy_dram * rapl_energy_units / interval_float); 583 - if (do_rapl & RAPL_PKG_PERF_STATUS ) 584 - outp += sprintf(outp, fmt5, 100.0 * p->rapl_pkg_perf_status * rapl_time_units / interval_float); 585 - if (do_rapl & RAPL_DRAM_PERF_STATUS ) 586 - outp += sprintf(outp, fmt5, 100.0 * p->rapl_dram_perf_status * rapl_time_units / interval_float); 530 + if (do_rapl && !rapl_joules) { 531 + if (do_rapl & RAPL_PKG) 532 + outp += sprintf(outp, fmt6, p->energy_pkg * rapl_energy_units / interval_float); 533 + if (do_rapl & RAPL_CORES) 534 + outp += sprintf(outp, fmt6, p->energy_cores * rapl_energy_units / interval_float); 535 + if (do_rapl & RAPL_GFX) 536 + outp += sprintf(outp, fmt5, p->energy_gfx * rapl_energy_units / interval_float); 537 + if (do_rapl & RAPL_DRAM) 538 + outp += sprintf(outp, fmt5, p->energy_dram * rapl_energy_units / interval_float); 539 + if (do_rapl & RAPL_PKG_PERF_STATUS) 540 + outp += sprintf(outp, fmt5, 100.0 * p->rapl_pkg_perf_status * rapl_time_units / interval_float); 541 + if (do_rapl & RAPL_DRAM_PERF_STATUS) 542 + outp += sprintf(outp, fmt5, 100.0 * p->rapl_dram_perf_status * rapl_time_units / interval_float); 543 + } else { 544 + if (do_rapl & RAPL_PKG) 545 + outp += sprintf(outp, fmt6, 546 + p->energy_pkg * rapl_energy_units); 547 + if (do_rapl & RAPL_CORES) 548 + outp += sprintf(outp, fmt6, 549 + p->energy_cores * rapl_energy_units); 550 + if (do_rapl & RAPL_GFX) 551 + outp += sprintf(outp, fmt5, 552 + p->energy_gfx * rapl_energy_units); 553 + if (do_rapl & RAPL_DRAM) 554 + outp += sprintf(outp, fmt5, 555 + p->energy_dram * rapl_energy_units); 556 + if (do_rapl & RAPL_PKG_PERF_STATUS) 557 + outp += sprintf(outp, fmt5, 100.0 * p->rapl_pkg_perf_status * rapl_time_units / interval_float); 558 + if (do_rapl & RAPL_DRAM_PERF_STATUS) 559 + outp += sprintf(outp, fmt5, 100.0 * p->rapl_dram_perf_status * rapl_time_units / interval_float); 560 + outp += sprintf(outp, fmt5, interval_float); 587 561 562 + } 588 563 done: 589 564 outp += sprintf(outp, "\n"); 590 565 ··· 687 622 old->tsc = new->tsc - old->tsc; 688 623 689 624 /* check for TSC < 1 Mcycles over interval */ 690 - if (old->tsc < (1000 * 1000)) { 691 - fprintf(stderr, "Insanely slow TSC rate, TSC stops in idle?\n"); 692 - fprintf(stderr, "You can disable all c-states by booting with \"idle=poll\"\n"); 693 - fprintf(stderr, "or just the deep ones with \"processor.max_cstate=1\"\n"); 694 - exit(-3); 695 - } 625 + if (old->tsc < (1000 * 1000)) 626 + errx(-3, "Insanely slow TSC rate, TSC stops in idle?\n" 627 + "You can disable all c-states by booting with \"idle=poll\"\n" 628 + "or just the deep ones with \"processor.max_cstate=1\""); 696 629 697 630 old->c1 = new->c1 - old->c1; 698 631 ··· 1236 1173 } 1237 1174 1238 1175 /* 1176 + * Open a file, and exit on failure 1177 + */ 1178 + FILE *fopen_or_die(const char *path, const char *mode) 1179 + { 1180 + FILE *filep = fopen(path, "r"); 1181 + if (!filep) 1182 + err(1, "%s: open failed", path); 1183 + return filep; 1184 + } 1185 + 1186 + /* 1187 + * Parse a file containing a single int. 1188 + */ 1189 + int parse_int_file(const char *fmt, ...) 1190 + { 1191 + va_list args; 1192 + char path[PATH_MAX]; 1193 + FILE *filep; 1194 + int value; 1195 + 1196 + va_start(args, fmt); 1197 + vsnprintf(path, sizeof(path), fmt, args); 1198 + va_end(args); 1199 + filep = fopen_or_die(path, "r"); 1200 + if (fscanf(filep, "%d", &value) != 1) 1201 + err(1, "%s: failed to parse number from file", path); 1202 + fclose(filep); 1203 + return value; 1204 + } 1205 + 1206 + /* 1239 1207 * cpu_is_first_sibling_in_core(cpu) 1240 1208 * return 1 if given CPU is 1st HT sibling in the core 1241 1209 */ 1242 1210 int cpu_is_first_sibling_in_core(int cpu) 1243 1211 { 1244 - char path[64]; 1245 - FILE *filep; 1246 - int first_cpu; 1247 - 1248 - sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu); 1249 - filep = fopen(path, "r"); 1250 - if (filep == NULL) { 1251 - perror(path); 1252 - exit(1); 1253 - } 1254 - fscanf(filep, "%d", &first_cpu); 1255 - fclose(filep); 1256 - return (cpu == first_cpu); 1212 + return cpu == parse_int_file("/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu); 1257 1213 } 1258 1214 1259 1215 /* ··· 1281 1199 */ 1282 1200 int cpu_is_first_core_in_package(int cpu) 1283 1201 { 1284 - char path[64]; 1285 - FILE *filep; 1286 - int first_cpu; 1287 - 1288 - sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/core_siblings_list", cpu); 1289 - filep = fopen(path, "r"); 1290 - if (filep == NULL) { 1291 - perror(path); 1292 - exit(1); 1293 - } 1294 - fscanf(filep, "%d", &first_cpu); 1295 - fclose(filep); 1296 - return (cpu == first_cpu); 1202 + return cpu == parse_int_file("/sys/devices/system/cpu/cpu%d/topology/core_siblings_list", cpu); 1297 1203 } 1298 1204 1299 1205 int get_physical_package_id(int cpu) 1300 1206 { 1301 - char path[80]; 1302 - FILE *filep; 1303 - int pkg; 1304 - 1305 - sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/physical_package_id", cpu); 1306 - filep = fopen(path, "r"); 1307 - if (filep == NULL) { 1308 - perror(path); 1309 - exit(1); 1310 - } 1311 - fscanf(filep, "%d", &pkg); 1312 - fclose(filep); 1313 - return pkg; 1207 + return parse_int_file("/sys/devices/system/cpu/cpu%d/topology/physical_package_id", cpu); 1314 1208 } 1315 1209 1316 1210 int get_core_id(int cpu) 1317 1211 { 1318 - char path[80]; 1319 - FILE *filep; 1320 - int core; 1321 - 1322 - sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/core_id", cpu); 1323 - filep = fopen(path, "r"); 1324 - if (filep == NULL) { 1325 - perror(path); 1326 - exit(1); 1327 - } 1328 - fscanf(filep, "%d", &core); 1329 - fclose(filep); 1330 - return core; 1212 + return parse_int_file("/sys/devices/system/cpu/cpu%d/topology/core_id", cpu); 1331 1213 } 1332 1214 1333 1215 int get_num_ht_siblings(int cpu) ··· 1303 1257 char character; 1304 1258 1305 1259 sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu); 1306 - filep = fopen(path, "r"); 1307 - if (filep == NULL) { 1308 - perror(path); 1309 - exit(1); 1310 - } 1260 + filep = fopen_or_die(path, "r"); 1311 1261 /* 1312 1262 * file format: 1313 1263 * if a pair of number with a character between: 2 siblings (eg. 1-2, or 1,4) ··· 1373 1331 int cpu_num; 1374 1332 int retval; 1375 1333 1376 - fp = fopen(proc_stat, "r"); 1377 - if (fp == NULL) { 1378 - perror(proc_stat); 1379 - exit(1); 1380 - } 1334 + fp = fopen_or_die(proc_stat, "r"); 1381 1335 1382 1336 retval = fscanf(fp, "cpu %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n"); 1383 - if (retval != 0) { 1384 - perror("/proc/stat format"); 1385 - exit(1); 1386 - } 1337 + if (retval != 0) 1338 + err(1, "%s: failed to parse format", proc_stat); 1387 1339 1388 1340 while (1) { 1389 1341 retval = fscanf(fp, "cpu%u %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n", &cpu_num); ··· 1481 1445 { 1482 1446 struct stat sb; 1483 1447 1484 - if (stat("/dev/cpu/0/msr", &sb)) { 1485 - fprintf(stderr, "no /dev/cpu/0/msr\n"); 1486 - fprintf(stderr, "Try \"# modprobe msr\"\n"); 1487 - exit(-5); 1488 - } 1448 + if (stat("/dev/cpu/0/msr", &sb)) 1449 + err(-5, "no /dev/cpu/0/msr\n" 1450 + "Try \"# modprobe msr\""); 1489 1451 } 1490 1452 1491 1453 void check_super_user() 1492 1454 { 1493 - if (getuid() != 0) { 1494 - fprintf(stderr, "must be root\n"); 1495 - exit(-6); 1496 - } 1455 + if (getuid() != 0) 1456 + errx(-6, "must be root"); 1497 1457 } 1498 1458 1499 1459 int has_nehalem_turbo_ratio_limit(unsigned int family, unsigned int model) ··· 1511 1479 case 0x3A: /* IVB */ 1512 1480 case 0x3E: /* IVB Xeon */ 1513 1481 case 0x3C: /* HSW */ 1514 - case 0x3F: /* HSW */ 1482 + case 0x3F: /* HSX */ 1515 1483 case 0x45: /* HSW */ 1516 1484 case 0x46: /* HSW */ 1517 1485 case 0x37: /* BYT */ ··· 1627 1595 case 0x2A: 1628 1596 case 0x3A: 1629 1597 case 0x3C: /* HSW */ 1630 - case 0x3F: /* HSW */ 1631 1598 case 0x45: /* HSW */ 1632 1599 case 0x46: /* HSW */ 1633 1600 do_rapl = RAPL_PKG | RAPL_CORES | RAPL_CORE_POLICY | RAPL_GFX | RAPL_PKG_POWER_INFO; 1601 + break; 1602 + case 0x3F: /* HSX */ 1603 + do_rapl = RAPL_PKG | RAPL_DRAM | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_PKG_POWER_INFO; 1634 1604 break; 1635 1605 case 0x2D: 1636 1606 case 0x3E: ··· 2012 1978 2013 1979 eax = ebx = ecx = edx = 0; 2014 1980 2015 - asm("cpuid" : "=a" (max_level), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (0)); 1981 + __get_cpuid(0, &max_level, &ebx, &ecx, &edx); 2016 1982 2017 1983 if (ebx == 0x756e6547 && edx == 0x49656e69 && ecx == 0x6c65746e) 2018 1984 genuine_intel = 1; ··· 2021 1987 fprintf(stderr, "CPUID(0): %.4s%.4s%.4s ", 2022 1988 (char *)&ebx, (char *)&edx, (char *)&ecx); 2023 1989 2024 - asm("cpuid" : "=a" (fms), "=c" (ecx), "=d" (edx) : "a" (1) : "ebx"); 1990 + __get_cpuid(1, &fms, &ebx, &ecx, &edx); 2025 1991 family = (fms >> 8) & 0xf; 2026 1992 model = (fms >> 4) & 0xf; 2027 1993 stepping = fms & 0xf; ··· 2032 1998 fprintf(stderr, "%d CPUID levels; family:model:stepping 0x%x:%x:%x (%d:%d:%d)\n", 2033 1999 max_level, family, model, stepping, family, model, stepping); 2034 2000 2035 - if (!(edx & (1 << 5))) { 2036 - fprintf(stderr, "CPUID: no MSR\n"); 2037 - exit(1); 2038 - } 2001 + if (!(edx & (1 << 5))) 2002 + errx(1, "CPUID: no MSR"); 2039 2003 2040 2004 /* 2041 2005 * check max extended function levels of CPUID. ··· 2041 2009 * This check is valid for both Intel and AMD. 2042 2010 */ 2043 2011 ebx = ecx = edx = 0; 2044 - asm("cpuid" : "=a" (max_level), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (0x80000000)); 2012 + __get_cpuid(0x80000000, &max_level, &ebx, &ecx, &edx); 2045 2013 2046 - if (max_level < 0x80000007) { 2047 - fprintf(stderr, "CPUID: no invariant TSC (max_level 0x%x)\n", max_level); 2048 - exit(1); 2049 - } 2014 + if (max_level < 0x80000007) 2015 + errx(1, "CPUID: no invariant TSC (max_level 0x%x)", max_level); 2050 2016 2051 2017 /* 2052 2018 * Non-Stop TSC is advertised by CPUID.EAX=0x80000007: EDX.bit8 2053 2019 * this check is valid for both Intel and AMD 2054 2020 */ 2055 - asm("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (0x80000007)); 2021 + __get_cpuid(0x80000007, &eax, &ebx, &ecx, &edx); 2056 2022 has_invariant_tsc = edx & (1 << 8); 2057 2023 2058 - if (!has_invariant_tsc) { 2059 - fprintf(stderr, "No invariant TSC\n"); 2060 - exit(1); 2061 - } 2024 + if (!has_invariant_tsc) 2025 + errx(1, "No invariant TSC"); 2062 2026 2063 2027 /* 2064 2028 * APERF/MPERF is advertised by CPUID.EAX=0x6: ECX.bit0 2065 2029 * this check is valid for both Intel and AMD 2066 2030 */ 2067 2031 2068 - asm("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (0x6)); 2032 + __get_cpuid(0x6, &eax, &ebx, &ecx, &edx); 2069 2033 has_aperf = ecx & (1 << 0); 2070 2034 do_dts = eax & (1 << 0); 2071 2035 do_ptm = eax & (1 << 6); ··· 2075 2047 has_epb ? ", EPB": ""); 2076 2048 2077 2049 if (!has_aperf) 2078 - exit(-1); 2050 + errx(-1, "No APERF"); 2079 2051 2080 2052 do_nehalem_platform_info = genuine_intel && has_invariant_tsc; 2081 2053 do_nhm_cstates = genuine_intel; /* all Intel w/ non-stop TSC have NHM counters */ ··· 2095 2067 2096 2068 void usage() 2097 2069 { 2098 - fprintf(stderr, "%s: [-v][-R][-T][-p|-P|-S][-c MSR# | -s]][-C MSR#][-m MSR#][-M MSR#][-i interval_sec | command ...]\n", 2099 - progname); 2100 - exit(1); 2070 + errx(1, "%s: [-v][-R][-T][-p|-P|-S][-c MSR#][-C MSR#][-m MSR#][-M MSR#][-i interval_sec | command ...]\n", 2071 + progname); 2101 2072 } 2102 2073 2103 2074 ··· 2139 2112 fprintf(stderr, "num_cpus %d max_cpu_num %d\n", topo.num_cpus, topo.max_cpu_num); 2140 2113 2141 2114 cpus = calloc(1, (topo.max_cpu_num + 1) * sizeof(struct cpu_topology)); 2142 - if (cpus == NULL) { 2143 - perror("calloc cpus"); 2144 - exit(1); 2145 - } 2115 + if (cpus == NULL) 2116 + err(1, "calloc cpus"); 2146 2117 2147 2118 /* 2148 2119 * Allocate and initialize cpu_present_set 2149 2120 */ 2150 2121 cpu_present_set = CPU_ALLOC((topo.max_cpu_num + 1)); 2151 - if (cpu_present_set == NULL) { 2152 - perror("CPU_ALLOC"); 2153 - exit(3); 2154 - } 2122 + if (cpu_present_set == NULL) 2123 + err(3, "CPU_ALLOC"); 2155 2124 cpu_present_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); 2156 2125 CPU_ZERO_S(cpu_present_setsize, cpu_present_set); 2157 2126 for_all_proc_cpus(mark_cpu_present); ··· 2156 2133 * Allocate and initialize cpu_affinity_set 2157 2134 */ 2158 2135 cpu_affinity_set = CPU_ALLOC((topo.max_cpu_num + 1)); 2159 - if (cpu_affinity_set == NULL) { 2160 - perror("CPU_ALLOC"); 2161 - exit(3); 2162 - } 2136 + if (cpu_affinity_set == NULL) 2137 + err(3, "CPU_ALLOC"); 2163 2138 cpu_affinity_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); 2164 2139 CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); 2165 2140 ··· 2241 2220 2242 2221 return; 2243 2222 error: 2244 - perror("calloc counters"); 2245 - exit(1); 2223 + err(1, "calloc counters"); 2246 2224 } 2247 2225 /* 2248 2226 * init_counter() ··· 2296 2276 2297 2277 void allocate_output_buffer() 2298 2278 { 2299 - output_buffer = calloc(1, (1 + topo.num_cpus) * 256); 2279 + output_buffer = calloc(1, (1 + topo.num_cpus) * 1024); 2300 2280 outp = output_buffer; 2301 - if (outp == NULL) { 2302 - perror("calloc"); 2303 - exit(-1); 2304 - } 2281 + if (outp == NULL) 2282 + err(-1, "calloc output buffer"); 2305 2283 } 2306 2284 2307 2285 void setup_all_buffers(void) ··· 2310 2292 allocate_output_buffer(); 2311 2293 for_all_proc_cpus(initialize_counters); 2312 2294 } 2295 + 2313 2296 void turbostat_init() 2314 2297 { 2315 2298 check_cpuid(); ··· 2354 2335 } else { 2355 2336 2356 2337 /* parent */ 2357 - if (child_pid == -1) { 2358 - perror("fork"); 2359 - exit(1); 2360 - } 2338 + if (child_pid == -1) 2339 + err(1, "fork"); 2361 2340 2362 2341 signal(SIGINT, SIG_IGN); 2363 2342 signal(SIGQUIT, SIG_IGN); 2364 - if (waitpid(child_pid, &status, 0) == -1) { 2365 - perror("wait"); 2366 - exit(status); 2367 - } 2343 + if (waitpid(child_pid, &status, 0) == -1) 2344 + err(status, "waitpid"); 2368 2345 } 2369 2346 /* 2370 2347 * n.b. fork_it() does not check for errors from for_all_cpus() ··· 2379 2364 return status; 2380 2365 } 2381 2366 2367 + int get_and_dump_counters(void) 2368 + { 2369 + int status; 2370 + 2371 + status = for_all_cpus(get_counters, ODD_COUNTERS); 2372 + if (status) 2373 + return status; 2374 + 2375 + status = for_all_cpus(dump_counters, ODD_COUNTERS); 2376 + if (status) 2377 + return status; 2378 + 2379 + flush_stdout(); 2380 + 2381 + return status; 2382 + } 2383 + 2382 2384 void cmdline(int argc, char **argv) 2383 2385 { 2384 2386 int opt; 2385 2387 2386 2388 progname = argv[0]; 2387 2389 2388 - while ((opt = getopt(argc, argv, "+pPSvi:sc:sC:m:M:RT:")) != -1) { 2390 + while ((opt = getopt(argc, argv, "+pPsSvi:c:C:m:M:RJT:")) != -1) { 2389 2391 switch (opt) { 2390 2392 case 'p': 2391 2393 show_core_only++; 2392 2394 break; 2393 2395 case 'P': 2394 2396 show_pkg_only++; 2397 + break; 2398 + case 's': 2399 + dump_only++; 2395 2400 break; 2396 2401 case 'S': 2397 2402 summary_only++; ··· 2440 2405 case 'T': 2441 2406 tcc_activation_temp_override = atoi(optarg); 2442 2407 break; 2408 + case 'J': 2409 + rapl_joules++; 2410 + break; 2411 + 2443 2412 default: 2444 2413 usage(); 2445 2414 } ··· 2455 2416 cmdline(argc, argv); 2456 2417 2457 2418 if (verbose) 2458 - fprintf(stderr, "turbostat v3.5 April 26, 2013" 2419 + fprintf(stderr, "turbostat v3.6 Dec 2, 2013" 2459 2420 " - Len Brown <lenb@kernel.org>\n"); 2460 2421 2461 2422 turbostat_init(); 2423 + 2424 + /* dump counters and exit */ 2425 + if (dump_only) 2426 + return get_and_dump_counters(); 2462 2427 2463 2428 /* 2464 2429 * if any params left, it must be a command to fork