turbostat.c (3316f99a9f1b68c578c57e76792bd19da1c7d423) | turbostat.c (8173c336989c1a12290cd023969df2775b2df34d) |
---|---|
1/* 2 * turbostat -- show CPU frequency and C-state residency 3 * on modern Intel and AMD processors. 4 * 5 * Copyright (c) 2013 Intel Corporation. 6 * Len Brown <len.brown@intel.com> 7 * 8 * This program is free software; you can redistribute it and/or modify it --- 2629 unchanged lines hidden (view full) --- 2638 size = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); 2639 CPU_ZERO_S(size, thiscpu->put_ids); 2640 2641 sprintf(path, 2642 "/sys/devices/system/cpu/cpu%d/topology/thread_siblings", cpu); 2643 filep = fopen_or_die(path, "r"); 2644 do { 2645 offset -= BITMASK_SIZE; | 1/* 2 * turbostat -- show CPU frequency and C-state residency 3 * on modern Intel and AMD processors. 4 * 5 * Copyright (c) 2013 Intel Corporation. 6 * Len Brown <len.brown@intel.com> 7 * 8 * This program is free software; you can redistribute it and/or modify it --- 2629 unchanged lines hidden (view full) --- 2638 size = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); 2639 CPU_ZERO_S(size, thiscpu->put_ids); 2640 2641 sprintf(path, 2642 "/sys/devices/system/cpu/cpu%d/topology/thread_siblings", cpu); 2643 filep = fopen_or_die(path, "r"); 2644 do { 2645 offset -= BITMASK_SIZE; |
2646 fscanf(filep, "%lx%c", &map, &character); | 2646 if (fscanf(filep, "%lx%c", &map, &character) != 2) 2647 err(1, "%s: failed to parse file", path); |
2647 for (shift = 0; shift < BITMASK_SIZE; shift++) { 2648 if ((map >> shift) & 0x1) { 2649 so = shift + offset; 2650 sib_core = get_core_id(so); 2651 if (sib_core == thiscpu->physical_core_id) { 2652 CPU_SET_S(so, size, thiscpu->put_ids); 2653 if ((so != cpu) && 2654 (cpus[so].thread_id < 0)) --- 815 unchanged lines hidden (view full) --- 3470 3471 for (state = 0; state < 10; ++state) { 3472 3473 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", 3474 base_cpu, state); 3475 input = fopen(path, "r"); 3476 if (input == NULL) 3477 continue; | 2648 for (shift = 0; shift < BITMASK_SIZE; shift++) { 2649 if ((map >> shift) & 0x1) { 2650 so = shift + offset; 2651 sib_core = get_core_id(so); 2652 if (sib_core == thiscpu->physical_core_id) { 2653 CPU_SET_S(so, size, thiscpu->put_ids); 2654 if ((so != cpu) && 2655 (cpus[so].thread_id < 0)) --- 815 unchanged lines hidden (view full) --- 3471 3472 for (state = 0; state < 10; ++state) { 3473 3474 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", 3475 base_cpu, state); 3476 input = fopen(path, "r"); 3477 if (input == NULL) 3478 continue; |
3478 fgets(name_buf, sizeof(name_buf), input); | 3479 if (!fgets(name_buf, sizeof(name_buf), input)) 3480 err(1, "%s: failed to read file", path); |
3479 3480 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ 3481 sp = strchr(name_buf, '-'); 3482 if (!sp) 3483 sp = strchrnul(name_buf, '\n'); 3484 *sp = '\0'; | 3481 3482 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ 3483 sp = strchr(name_buf, '-'); 3484 if (!sp) 3485 sp = strchrnul(name_buf, '\n'); 3486 *sp = '\0'; |
3485 | |
3486 fclose(input); 3487 3488 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/desc", 3489 base_cpu, state); 3490 input = fopen(path, "r"); 3491 if (input == NULL) 3492 continue; | 3487 fclose(input); 3488 3489 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/desc", 3490 base_cpu, state); 3491 input = fopen(path, "r"); 3492 if (input == NULL) 3493 continue; |
3493 fgets(desc, sizeof(desc), input); | 3494 if (!fgets(desc, sizeof(desc), input)) 3495 err(1, "%s: failed to read file", path); |
3494 3495 fprintf(outf, "cpu%d: %s: %s", base_cpu, name_buf, desc); 3496 fclose(input); 3497 } 3498} 3499static void 3500dump_sysfs_pstate_config(void) 3501{ --- 5 unchanged lines hidden (view full) --- 3507 3508 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_driver", 3509 base_cpu); 3510 input = fopen(path, "r"); 3511 if (input == NULL) { 3512 fprintf(outf, "NSFOD %s\n", path); 3513 return; 3514 } | 3496 3497 fprintf(outf, "cpu%d: %s: %s", base_cpu, name_buf, desc); 3498 fclose(input); 3499 } 3500} 3501static void 3502dump_sysfs_pstate_config(void) 3503{ --- 5 unchanged lines hidden (view full) --- 3509 3510 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_driver", 3511 base_cpu); 3512 input = fopen(path, "r"); 3513 if (input == NULL) { 3514 fprintf(outf, "NSFOD %s\n", path); 3515 return; 3516 } |
3515 fgets(driver_buf, sizeof(driver_buf), input); | 3517 if (!fgets(driver_buf, sizeof(driver_buf), input)) 3518 err(1, "%s: failed to read file", path); |
3516 fclose(input); 3517 3518 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", 3519 base_cpu); 3520 input = fopen(path, "r"); 3521 if (input == NULL) { 3522 fprintf(outf, "NSFOD %s\n", path); 3523 return; 3524 } | 3519 fclose(input); 3520 3521 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", 3522 base_cpu); 3523 input = fopen(path, "r"); 3524 if (input == NULL) { 3525 fprintf(outf, "NSFOD %s\n", path); 3526 return; 3527 } |
3525 fgets(governor_buf, sizeof(governor_buf), input); | 3528 if (!fgets(governor_buf, sizeof(governor_buf), input)) 3529 err(1, "%s: failed to read file", path); |
3526 fclose(input); 3527 3528 fprintf(outf, "cpu%d: cpufreq driver: %s", base_cpu, driver_buf); 3529 fprintf(outf, "cpu%d: cpufreq governor: %s", base_cpu, governor_buf); 3530 3531 sprintf(path, "/sys/devices/system/cpu/cpufreq/boost"); 3532 input = fopen(path, "r"); 3533 if (input != NULL) { | 3530 fclose(input); 3531 3532 fprintf(outf, "cpu%d: cpufreq driver: %s", base_cpu, driver_buf); 3533 fprintf(outf, "cpu%d: cpufreq governor: %s", base_cpu, governor_buf); 3534 3535 sprintf(path, "/sys/devices/system/cpu/cpufreq/boost"); 3536 input = fopen(path, "r"); 3537 if (input != NULL) { |
3534 fscanf(input, "%d", &turbo); | 3538 if (fscanf(input, "%d", &turbo) != 1) 3539 err(1, "%s: failed to parse number from file", path); |
3535 fprintf(outf, "cpufreq boost: %d\n", turbo); 3536 fclose(input); 3537 } 3538 3539 sprintf(path, "/sys/devices/system/cpu/intel_pstate/no_turbo"); 3540 input = fopen(path, "r"); 3541 if (input != NULL) { | 3540 fprintf(outf, "cpufreq boost: %d\n", turbo); 3541 fclose(input); 3542 } 3543 3544 sprintf(path, "/sys/devices/system/cpu/intel_pstate/no_turbo"); 3545 input = fopen(path, "r"); 3546 if (input != NULL) { |
3542 fscanf(input, "%d", &turbo); | 3547 if (fscanf(input, "%d", &turbo) != 1) 3548 err(1, "%s: failed to parse number from file", path); |
3543 fprintf(outf, "cpufreq intel_pstate no_turbo: %d\n", turbo); 3544 fclose(input); 3545 } 3546} 3547 3548 3549/* 3550 * print_epb() --- 1908 unchanged lines hidden (view full) --- 5459 5460 for (state = 10; state >= 0; --state) { 5461 5462 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", 5463 base_cpu, state); 5464 input = fopen(path, "r"); 5465 if (input == NULL) 5466 continue; | 3549 fprintf(outf, "cpufreq intel_pstate no_turbo: %d\n", turbo); 3550 fclose(input); 3551 } 3552} 3553 3554 3555/* 3556 * print_epb() --- 1908 unchanged lines hidden (view full) --- 5465 5466 for (state = 10; state >= 0; --state) { 5467 5468 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", 5469 base_cpu, state); 5470 input = fopen(path, "r"); 5471 if (input == NULL) 5472 continue; |
5467 fgets(name_buf, sizeof(name_buf), input); | 5473 if (!fgets(name_buf, sizeof(name_buf), input)) 5474 err(1, "%s: failed to read file", path); |
5468 5469 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ 5470 sp = strchr(name_buf, '-'); 5471 if (!sp) 5472 sp = strchrnul(name_buf, '\n'); 5473 *sp = '%'; 5474 *(sp + 1) = '\0'; 5475 --- 10 unchanged lines hidden (view full) --- 5486 5487 for (state = 10; state >= 0; --state) { 5488 5489 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", 5490 base_cpu, state); 5491 input = fopen(path, "r"); 5492 if (input == NULL) 5493 continue; | 5475 5476 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ 5477 sp = strchr(name_buf, '-'); 5478 if (!sp) 5479 sp = strchrnul(name_buf, '\n'); 5480 *sp = '%'; 5481 *(sp + 1) = '\0'; 5482 --- 10 unchanged lines hidden (view full) --- 5493 5494 for (state = 10; state >= 0; --state) { 5495 5496 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", 5497 base_cpu, state); 5498 input = fopen(path, "r"); 5499 if (input == NULL) 5500 continue; |
5494 fgets(name_buf, sizeof(name_buf), input); | 5501 if (!fgets(name_buf, sizeof(name_buf), input)) 5502 err(1, "%s: failed to read file", path); |
5495 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ 5496 sp = strchr(name_buf, '-'); 5497 if (!sp) 5498 sp = strchrnul(name_buf, '\n'); 5499 *sp = '\0'; 5500 fclose(input); 5501 5502 sprintf(path, "cpuidle/state%d/usage", state); --- 253 unchanged lines hidden --- | 5503 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ 5504 sp = strchr(name_buf, '-'); 5505 if (!sp) 5506 sp = strchrnul(name_buf, '\n'); 5507 *sp = '\0'; 5508 fclose(input); 5509 5510 sprintf(path, "cpuidle/state%d/usage", state); --- 253 unchanged lines hidden --- |