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 tag 'pm-5.1-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm

Pull power management fixes from Rafael Wysocki:
"These fix up the intel_pstate driver after recent changes to prevent
it from printing pointless messages and update the turbostat utility
(mostly fixes and new hardware support).

Specifics:

- Make intel_pstate only load on Intel processors and prevent it from
printing pointless failure messages (Borislav Petkov).

- Update the turbostat utility:
* Assorted fixes (Ben Hutchings, Len Brown, Prarit Bhargava).
* Support for AMD Fam 17h (Zen) RAPL and package power (Calvin
Walton).
* Support for Intel Icelake and for systems with more than one die
per package (Len Brown).
* Cleanups (Len Brown)"

* tag 'pm-5.1-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm:
cpufreq/intel_pstate: Load only on Intel hardware
tools/power turbostat: update version number
tools/power turbostat: Warn on bad ACPI LPIT data
tools/power turbostat: Add checks for failure of fgets() and fscanf()
tools/power turbostat: Also read package power on AMD F17h (Zen)
tools/power turbostat: Add support for AMD Fam 17h (Zen) RAPL
tools/power turbostat: Do not display an error on systems without a cpufreq driver
tools/power turbostat: Add Die column
tools/power turbostat: Add Icelake support
tools/power turbostat: Cleanup CNL-specific code
tools/power turbostat: Cleanup CC3-skip code
tools/power turbostat: Restore ability to execute in topology-order

+223 -59
+4 -1
drivers/cpufreq/intel_pstate.c
··· 2596 2596 const struct x86_cpu_id *id; 2597 2597 int rc; 2598 2598 2599 + if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) 2600 + return -ENODEV; 2601 + 2599 2602 if (no_load) 2600 2603 return -ENODEV; 2601 2604 ··· 2614 2611 } else { 2615 2612 id = x86_match_cpu(intel_pstate_cpu_ids); 2616 2613 if (!id) { 2617 - pr_info("CPU ID not supported\n"); 2614 + pr_info("CPU model not supported\n"); 2618 2615 return -ENODEV; 2619 2616 } 2620 2617
+219 -58
tools/power/x86/turbostat/turbostat.c
··· 44 44 #include <cpuid.h> 45 45 #include <linux/capability.h> 46 46 #include <errno.h> 47 + #include <math.h> 47 48 48 49 char *proc_stat = "/proc/stat"; 49 50 FILE *outf; ··· 64 63 unsigned int do_snb_cstates; 65 64 unsigned int do_knl_cstates; 66 65 unsigned int do_slm_cstates; 67 - unsigned int do_cnl_cstates; 68 66 unsigned int use_c1_residency_msr; 69 67 unsigned int has_aperf; 70 68 unsigned int has_epb; ··· 141 141 142 142 #define RAPL_CORES_ENERGY_STATUS (1 << 9) 143 143 /* 0x639 MSR_PP0_ENERGY_STATUS */ 144 + #define RAPL_PER_CORE_ENERGY (1 << 10) 145 + /* Indicates cores energy collection is per-core, 146 + * not per-package. */ 147 + #define RAPL_AMD_F17H (1 << 11) 148 + /* 0xc0010299 MSR_RAPL_PWR_UNIT */ 149 + /* 0xc001029a MSR_CORE_ENERGY_STAT */ 150 + /* 0xc001029b MSR_PKG_ENERGY_STAT */ 144 151 #define RAPL_CORES (RAPL_CORES_ENERGY_STATUS | RAPL_CORES_POWER_LIMIT) 145 152 #define TJMAX_DEFAULT 100 153 + 154 + /* MSRs that are not yet in the kernel-provided header. */ 155 + #define MSR_RAPL_PWR_UNIT 0xc0010299 156 + #define MSR_CORE_ENERGY_STAT 0xc001029a 157 + #define MSR_PKG_ENERGY_STAT 0xc001029b 146 158 147 159 #define MAX(a, b) ((a) > (b) ? (a) : (b)) 148 160 ··· 199 187 unsigned long long c7; 200 188 unsigned long long mc6_us; /* duplicate as per-core for now, even though per module */ 201 189 unsigned int core_temp_c; 190 + unsigned int core_energy; /* MSR_CORE_ENERGY_STAT */ 202 191 unsigned int core_id; 203 192 unsigned long long counter[MAX_ADDED_COUNTERS]; 204 193 } *core_even, *core_odd; ··· 286 273 287 274 struct cpu_topology { 288 275 int physical_package_id; 276 + int die_id; 289 277 int logical_cpu_id; 290 278 int physical_node_id; 291 279 int logical_node_id; /* 0-based count within the package */ ··· 297 283 298 284 struct topo_params { 299 285 int num_packages; 286 + int num_die; 300 287 int num_cpus; 301 288 int num_cores; 302 289 int max_cpu_num; ··· 329 314 int retval, pkg_no, core_no, thread_no, node_no; 330 315 331 316 for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { 332 - for (core_no = 0; core_no < topo.cores_per_node; ++core_no) { 333 - for (node_no = 0; node_no < topo.nodes_per_pkg; 334 - node_no++) { 317 + for (node_no = 0; node_no < topo.nodes_per_pkg; node_no++) { 318 + for (core_no = 0; core_no < topo.cores_per_node; ++core_no) { 335 319 for (thread_no = 0; thread_no < 336 320 topo.threads_per_core; ++thread_no) { 337 321 struct thread_data *t; ··· 456 442 { 0x0, "CPU" }, 457 443 { 0x0, "APIC" }, 458 444 { 0x0, "X2APIC" }, 445 + { 0x0, "Die" }, 459 446 }; 460 447 461 448 #define MAX_BIC (sizeof(bic) / sizeof(struct msr_counter)) ··· 510 495 #define BIC_CPU (1ULL << 47) 511 496 #define BIC_APIC (1ULL << 48) 512 497 #define BIC_X2APIC (1ULL << 49) 498 + #define BIC_Die (1ULL << 50) 513 499 514 500 #define BIC_DISABLED_BY_DEFAULT (BIC_USEC | BIC_TOD | BIC_APIC | BIC_X2APIC) 515 501 ··· 637 621 outp += sprintf(outp, "%sTime_Of_Day_Seconds", (printed++ ? delim : "")); 638 622 if (DO_BIC(BIC_Package)) 639 623 outp += sprintf(outp, "%sPackage", (printed++ ? delim : "")); 624 + if (DO_BIC(BIC_Die)) 625 + outp += sprintf(outp, "%sDie", (printed++ ? delim : "")); 640 626 if (DO_BIC(BIC_Node)) 641 627 outp += sprintf(outp, "%sNode", (printed++ ? delim : "")); 642 628 if (DO_BIC(BIC_Core)) ··· 685 667 686 668 if (DO_BIC(BIC_CPU_c1)) 687 669 outp += sprintf(outp, "%sCPU%%c1", (printed++ ? delim : "")); 688 - if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates && !do_cnl_cstates) 670 + if (DO_BIC(BIC_CPU_c3)) 689 671 outp += sprintf(outp, "%sCPU%%c3", (printed++ ? delim : "")); 690 672 if (DO_BIC(BIC_CPU_c6)) 691 673 outp += sprintf(outp, "%sCPU%%c6", (printed++ ? delim : "")); ··· 697 679 698 680 if (DO_BIC(BIC_CoreTmp)) 699 681 outp += sprintf(outp, "%sCoreTmp", (printed++ ? delim : "")); 682 + 683 + if (do_rapl && !rapl_joules) { 684 + if (DO_BIC(BIC_CorWatt) && (do_rapl & RAPL_PER_CORE_ENERGY)) 685 + outp += sprintf(outp, "%sCorWatt", (printed++ ? delim : "")); 686 + } else if (do_rapl && rapl_joules) { 687 + if (DO_BIC(BIC_Cor_J) && (do_rapl & RAPL_PER_CORE_ENERGY)) 688 + outp += sprintf(outp, "%sCor_J", (printed++ ? delim : "")); 689 + } 700 690 701 691 for (mp = sys.cp; mp; mp = mp->next) { 702 692 if (mp->format == FORMAT_RAW) { ··· 760 734 if (do_rapl && !rapl_joules) { 761 735 if (DO_BIC(BIC_PkgWatt)) 762 736 outp += sprintf(outp, "%sPkgWatt", (printed++ ? delim : "")); 763 - if (DO_BIC(BIC_CorWatt)) 737 + if (DO_BIC(BIC_CorWatt) && !(do_rapl & RAPL_PER_CORE_ENERGY)) 764 738 outp += sprintf(outp, "%sCorWatt", (printed++ ? delim : "")); 765 739 if (DO_BIC(BIC_GFXWatt)) 766 740 outp += sprintf(outp, "%sGFXWatt", (printed++ ? delim : "")); ··· 773 747 } else if (do_rapl && rapl_joules) { 774 748 if (DO_BIC(BIC_Pkg_J)) 775 749 outp += sprintf(outp, "%sPkg_J", (printed++ ? delim : "")); 776 - if (DO_BIC(BIC_Cor_J)) 750 + if (DO_BIC(BIC_Cor_J) && !(do_rapl & RAPL_PER_CORE_ENERGY)) 777 751 outp += sprintf(outp, "%sCor_J", (printed++ ? delim : "")); 778 752 if (DO_BIC(BIC_GFX_J)) 779 753 outp += sprintf(outp, "%sGFX_J", (printed++ ? delim : "")); ··· 834 808 outp += sprintf(outp, "c6: %016llX\n", c->c6); 835 809 outp += sprintf(outp, "c7: %016llX\n", c->c7); 836 810 outp += sprintf(outp, "DTS: %dC\n", c->core_temp_c); 811 + outp += sprintf(outp, "Joules: %0X\n", c->core_energy); 837 812 838 813 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { 839 814 outp += sprintf(outp, "cADDED [%d] msr0x%x: %08llX\n", ··· 931 904 if (t == &average.threads) { 932 905 if (DO_BIC(BIC_Package)) 933 906 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); 907 + if (DO_BIC(BIC_Die)) 908 + outp += sprintf(outp, "%s-", (printed++ ? delim : "")); 934 909 if (DO_BIC(BIC_Node)) 935 910 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); 936 911 if (DO_BIC(BIC_Core)) ··· 947 918 if (DO_BIC(BIC_Package)) { 948 919 if (p) 949 920 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->package_id); 921 + else 922 + outp += sprintf(outp, "%s-", (printed++ ? delim : "")); 923 + } 924 + if (DO_BIC(BIC_Die)) { 925 + if (c) 926 + outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), cpus[t->cpu_id].die_id); 950 927 else 951 928 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); 952 929 } ··· 1038 1003 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) 1039 1004 goto done; 1040 1005 1041 - if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates && !do_cnl_cstates) 1006 + if (DO_BIC(BIC_CPU_c3)) 1042 1007 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c3/tsc); 1043 1008 if (DO_BIC(BIC_CPU_c6)) 1044 1009 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c6/tsc); ··· 1067 1032 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->counter[i]/tsc); 1068 1033 } 1069 1034 } 1035 + 1036 + /* 1037 + * If measurement interval exceeds minimum RAPL Joule Counter range, 1038 + * indicate that results are suspect by printing "**" in fraction place. 1039 + */ 1040 + if (interval_float < rapl_joule_counter_range) 1041 + fmt8 = "%s%.2f"; 1042 + else 1043 + fmt8 = "%6.0f**"; 1044 + 1045 + if (DO_BIC(BIC_CorWatt) && (do_rapl & RAPL_PER_CORE_ENERGY)) 1046 + outp += sprintf(outp, fmt8, (printed++ ? delim : ""), c->core_energy * rapl_energy_units / interval_float); 1047 + if (DO_BIC(BIC_Cor_J) && (do_rapl & RAPL_PER_CORE_ENERGY)) 1048 + outp += sprintf(outp, fmt8, (printed++ ? delim : ""), c->core_energy * rapl_energy_units); 1070 1049 1071 1050 /* print per-package data only for 1st core in package */ 1072 1051 if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) ··· 1134 1085 if (DO_BIC(BIC_SYS_LPI)) 1135 1086 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->sys_lpi / 1000000.0 / interval_float); 1136 1087 1137 - /* 1138 - * If measurement interval exceeds minimum RAPL Joule Counter range, 1139 - * indicate that results are suspect by printing "**" in fraction place. 1140 - */ 1141 - if (interval_float < rapl_joule_counter_range) 1142 - fmt8 = "%s%.2f"; 1143 - else 1144 - fmt8 = "%6.0f**"; 1145 - 1146 1088 if (DO_BIC(BIC_PkgWatt)) 1147 1089 outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_pkg * rapl_energy_units / interval_float); 1148 - if (DO_BIC(BIC_CorWatt)) 1090 + if (DO_BIC(BIC_CorWatt) && !(do_rapl & RAPL_PER_CORE_ENERGY)) 1149 1091 outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_cores * rapl_energy_units / interval_float); 1150 1092 if (DO_BIC(BIC_GFXWatt)) 1151 1093 outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_gfx * rapl_energy_units / interval_float); ··· 1144 1104 outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_dram * rapl_dram_energy_units / interval_float); 1145 1105 if (DO_BIC(BIC_Pkg_J)) 1146 1106 outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_pkg * rapl_energy_units); 1147 - if (DO_BIC(BIC_Cor_J)) 1107 + if (DO_BIC(BIC_Cor_J) && !(do_rapl & RAPL_PER_CORE_ENERGY)) 1148 1108 outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_cores * rapl_energy_units); 1149 1109 if (DO_BIC(BIC_GFX_J)) 1150 1110 outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_gfx * rapl_energy_units); ··· 1289 1249 old->core_temp_c = new->core_temp_c; 1290 1250 old->mc6_us = new->mc6_us - old->mc6_us; 1291 1251 1252 + DELTA_WRAP32(new->core_energy, old->core_energy); 1253 + 1292 1254 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { 1293 1255 if (mp->format == FORMAT_RAW) 1294 1256 old->counter[i] = new->counter[i]; ··· 1433 1391 c->c7 = 0; 1434 1392 c->mc6_us = 0; 1435 1393 c->core_temp_c = 0; 1394 + c->core_energy = 0; 1436 1395 1437 1396 p->pkg_wtd_core_c0 = 0; 1438 1397 p->pkg_any_core_c0 = 0; ··· 1515 1472 average.cores.mc6_us += c->mc6_us; 1516 1473 1517 1474 average.cores.core_temp_c = MAX(average.cores.core_temp_c, c->core_temp_c); 1475 + 1476 + average.cores.core_energy += c->core_energy; 1518 1477 1519 1478 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { 1520 1479 if (mp->format == FORMAT_RAW) ··· 1863 1818 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) 1864 1819 goto done; 1865 1820 1866 - if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates && !do_cnl_cstates) { 1821 + if (DO_BIC(BIC_CPU_c3)) { 1867 1822 if (get_msr(cpu, MSR_CORE_C3_RESIDENCY, &c->c3)) 1868 1823 return -6; 1869 1824 } ··· 1888 1843 if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr)) 1889 1844 return -9; 1890 1845 c->core_temp_c = tcc_activation_temp - ((msr >> 16) & 0x7F); 1846 + } 1847 + 1848 + if (do_rapl & RAPL_AMD_F17H) { 1849 + if (get_msr(cpu, MSR_CORE_ENERGY_STAT, &msr)) 1850 + return -14; 1851 + c->core_energy = msr & 0xFFFFFFFF; 1891 1852 } 1892 1853 1893 1854 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { ··· 1984 1933 if (get_msr(cpu, MSR_DRAM_PERF_STATUS, &msr)) 1985 1934 return -16; 1986 1935 p->rapl_dram_perf_status = msr & 0xFFFFFFFF; 1936 + } 1937 + if (do_rapl & RAPL_AMD_F17H) { 1938 + if (get_msr(cpu, MSR_PKG_ENERGY_STAT, &msr)) 1939 + return -13; 1940 + p->energy_pkg = msr & 0xFFFFFFFF; 1987 1941 } 1988 1942 if (DO_BIC(BIC_PkgTmp)) { 1989 1943 if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr)) ··· 2512 2456 2513 2457 /* 2514 2458 * Parse a file containing a single int. 2459 + * Return 0 if file can not be opened 2460 + * Exit if file can be opened, but can not be parsed 2515 2461 */ 2516 2462 int parse_int_file(const char *fmt, ...) 2517 2463 { ··· 2525 2467 va_start(args, fmt); 2526 2468 vsnprintf(path, sizeof(path), fmt, args); 2527 2469 va_end(args); 2528 - filep = fopen_or_die(path, "r"); 2470 + filep = fopen(path, "r"); 2471 + if (!filep) 2472 + return 0; 2529 2473 if (fscanf(filep, "%d", &value) != 1) 2530 2474 err(1, "%s: failed to parse number from file", path); 2531 2475 fclose(filep); ··· 2546 2486 int get_physical_package_id(int cpu) 2547 2487 { 2548 2488 return parse_int_file("/sys/devices/system/cpu/cpu%d/topology/physical_package_id", cpu); 2489 + } 2490 + 2491 + int get_die_id(int cpu) 2492 + { 2493 + return parse_int_file("/sys/devices/system/cpu/cpu%d/topology/die_id", cpu); 2549 2494 } 2550 2495 2551 2496 int get_core_id(int cpu) ··· 2643 2578 filep = fopen_or_die(path, "r"); 2644 2579 do { 2645 2580 offset -= BITMASK_SIZE; 2646 - fscanf(filep, "%lx%c", &map, &character); 2581 + if (fscanf(filep, "%lx%c", &map, &character) != 2) 2582 + err(1, "%s: failed to parse file", path); 2647 2583 for (shift = 0; shift < BITMASK_SIZE; shift++) { 2648 2584 if ((map >> shift) & 0x1) { 2649 2585 so = shift + offset; ··· 2921 2855 fp = fopen_or_die("/sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us", "r"); 2922 2856 2923 2857 retval = fscanf(fp, "%lld", &cpuidle_cur_cpu_lpi_us); 2924 - if (retval != 1) 2925 - err(1, "CPU LPI"); 2858 + if (retval != 1) { 2859 + fprintf(stderr, "Disabling Low Power Idle CPU output\n"); 2860 + BIC_NOT_PRESENT(BIC_CPU_LPI); 2861 + return -1; 2862 + } 2926 2863 2927 2864 fclose(fp); 2928 2865 ··· 2947 2878 fp = fopen_or_die("/sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us", "r"); 2948 2879 2949 2880 retval = fscanf(fp, "%lld", &cpuidle_cur_sys_lpi_us); 2950 - if (retval != 1) 2951 - err(1, "SYS LPI"); 2952 - 2881 + if (retval != 1) { 2882 + fprintf(stderr, "Disabling Low Power Idle System output\n"); 2883 + BIC_NOT_PRESENT(BIC_SYS_LPI); 2884 + return -1; 2885 + } 2953 2886 fclose(fp); 2954 2887 2955 2888 return 0; ··· 3481 3410 input = fopen(path, "r"); 3482 3411 if (input == NULL) 3483 3412 continue; 3484 - fgets(name_buf, sizeof(name_buf), input); 3413 + if (!fgets(name_buf, sizeof(name_buf), input)) 3414 + err(1, "%s: failed to read file", path); 3485 3415 3486 3416 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ 3487 3417 sp = strchr(name_buf, '-'); 3488 3418 if (!sp) 3489 3419 sp = strchrnul(name_buf, '\n'); 3490 3420 *sp = '\0'; 3491 - 3492 3421 fclose(input); 3493 3422 3494 3423 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/desc", ··· 3496 3425 input = fopen(path, "r"); 3497 3426 if (input == NULL) 3498 3427 continue; 3499 - fgets(desc, sizeof(desc), input); 3428 + if (!fgets(desc, sizeof(desc), input)) 3429 + err(1, "%s: failed to read file", path); 3500 3430 3501 3431 fprintf(outf, "cpu%d: %s: %s", base_cpu, name_buf, desc); 3502 3432 fclose(input); ··· 3516 3444 base_cpu); 3517 3445 input = fopen(path, "r"); 3518 3446 if (input == NULL) { 3519 - fprintf(stderr, "NSFOD %s\n", path); 3447 + fprintf(outf, "NSFOD %s\n", path); 3520 3448 return; 3521 3449 } 3522 - fgets(driver_buf, sizeof(driver_buf), input); 3450 + if (!fgets(driver_buf, sizeof(driver_buf), input)) 3451 + err(1, "%s: failed to read file", path); 3523 3452 fclose(input); 3524 3453 3525 3454 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", 3526 3455 base_cpu); 3527 3456 input = fopen(path, "r"); 3528 3457 if (input == NULL) { 3529 - fprintf(stderr, "NSFOD %s\n", path); 3458 + fprintf(outf, "NSFOD %s\n", path); 3530 3459 return; 3531 3460 } 3532 - fgets(governor_buf, sizeof(governor_buf), input); 3461 + if (!fgets(governor_buf, sizeof(governor_buf), input)) 3462 + err(1, "%s: failed to read file", path); 3533 3463 fclose(input); 3534 3464 3535 3465 fprintf(outf, "cpu%d: cpufreq driver: %s", base_cpu, driver_buf); ··· 3540 3466 sprintf(path, "/sys/devices/system/cpu/cpufreq/boost"); 3541 3467 input = fopen(path, "r"); 3542 3468 if (input != NULL) { 3543 - fscanf(input, "%d", &turbo); 3469 + if (fscanf(input, "%d", &turbo) != 1) 3470 + err(1, "%s: failed to parse number from file", path); 3544 3471 fprintf(outf, "cpufreq boost: %d\n", turbo); 3545 3472 fclose(input); 3546 3473 } ··· 3549 3474 sprintf(path, "/sys/devices/system/cpu/intel_pstate/no_turbo"); 3550 3475 input = fopen(path, "r"); 3551 3476 if (input != NULL) { 3552 - fscanf(input, "%d", &turbo); 3477 + if (fscanf(input, "%d", &turbo) != 1) 3478 + err(1, "%s: failed to parse number from file", path); 3553 3479 fprintf(outf, "cpufreq intel_pstate no_turbo: %d\n", turbo); 3554 3480 fclose(input); 3555 3481 } ··· 3794 3718 #define RAPL_POWER_GRANULARITY 0x7FFF /* 15 bit power granularity */ 3795 3719 #define RAPL_TIME_GRANULARITY 0x3F /* 6 bit time granularity */ 3796 3720 3797 - double get_tdp(unsigned int model) 3721 + double get_tdp_intel(unsigned int model) 3798 3722 { 3799 3723 unsigned long long msr; 3800 3724 ··· 3808 3732 return 30.0; 3809 3733 default: 3810 3734 return 135.0; 3735 + } 3736 + } 3737 + 3738 + double get_tdp_amd(unsigned int family) 3739 + { 3740 + switch (family) { 3741 + case 0x17: 3742 + default: 3743 + /* This is the max stock TDP of HEDT/Server Fam17h chips */ 3744 + return 250.0; 3811 3745 } 3812 3746 } 3813 3747 ··· 3840 3754 } 3841 3755 } 3842 3756 3843 - 3844 - /* 3845 - * rapl_probe() 3846 - * 3847 - * sets do_rapl, rapl_power_units, rapl_energy_units, rapl_time_units 3848 - */ 3849 - void rapl_probe(unsigned int family, unsigned int model) 3757 + void rapl_probe_intel(unsigned int family, unsigned int model) 3850 3758 { 3851 3759 unsigned long long msr; 3852 3760 unsigned int time_unit; 3853 3761 double tdp; 3854 - 3855 - if (!genuine_intel) 3856 - return; 3857 3762 3858 3763 if (family != 6) 3859 3764 return; ··· 3969 3892 3970 3893 rapl_time_units = 1.0 / (1 << (time_unit)); 3971 3894 3972 - tdp = get_tdp(model); 3895 + tdp = get_tdp_intel(model); 3973 3896 3974 3897 rapl_joule_counter_range = 0xFFFFFFFF * rapl_energy_units / tdp; 3975 3898 if (!quiet) 3976 3899 fprintf(outf, "RAPL: %.0f sec. Joule Counter Range, at %.0f Watts\n", rapl_joule_counter_range, tdp); 3900 + } 3977 3901 3978 - return; 3902 + void rapl_probe_amd(unsigned int family, unsigned int model) 3903 + { 3904 + unsigned long long msr; 3905 + unsigned int eax, ebx, ecx, edx; 3906 + unsigned int has_rapl = 0; 3907 + double tdp; 3908 + 3909 + if (max_extended_level >= 0x80000007) { 3910 + __cpuid(0x80000007, eax, ebx, ecx, edx); 3911 + /* RAPL (Fam 17h) */ 3912 + has_rapl = edx & (1 << 14); 3913 + } 3914 + 3915 + if (!has_rapl) 3916 + return; 3917 + 3918 + switch (family) { 3919 + case 0x17: /* Zen, Zen+ */ 3920 + do_rapl = RAPL_AMD_F17H | RAPL_PER_CORE_ENERGY; 3921 + if (rapl_joules) { 3922 + BIC_PRESENT(BIC_Pkg_J); 3923 + BIC_PRESENT(BIC_Cor_J); 3924 + } else { 3925 + BIC_PRESENT(BIC_PkgWatt); 3926 + BIC_PRESENT(BIC_CorWatt); 3927 + } 3928 + break; 3929 + default: 3930 + return; 3931 + } 3932 + 3933 + if (get_msr(base_cpu, MSR_RAPL_PWR_UNIT, &msr)) 3934 + return; 3935 + 3936 + rapl_time_units = ldexp(1.0, -(msr >> 16 & 0xf)); 3937 + rapl_energy_units = ldexp(1.0, -(msr >> 8 & 0x1f)); 3938 + rapl_power_units = ldexp(1.0, -(msr & 0xf)); 3939 + 3940 + tdp = get_tdp_amd(model); 3941 + 3942 + rapl_joule_counter_range = 0xFFFFFFFF * rapl_energy_units / tdp; 3943 + if (!quiet) 3944 + fprintf(outf, "RAPL: %.0f sec. Joule Counter Range, at %.0f Watts\n", rapl_joule_counter_range, tdp); 3945 + } 3946 + 3947 + /* 3948 + * rapl_probe() 3949 + * 3950 + * sets do_rapl, rapl_power_units, rapl_energy_units, rapl_time_units 3951 + */ 3952 + void rapl_probe(unsigned int family, unsigned int model) 3953 + { 3954 + if (genuine_intel) 3955 + rapl_probe_intel(family, model); 3956 + if (authentic_amd) 3957 + rapl_probe_amd(family, model); 3979 3958 } 3980 3959 3981 3960 void perf_limit_reasons_probe(unsigned int family, unsigned int model) ··· 4136 4003 int print_rapl(struct thread_data *t, struct core_data *c, struct pkg_data *p) 4137 4004 { 4138 4005 unsigned long long msr; 4006 + const char *msr_name; 4139 4007 int cpu; 4140 4008 4141 4009 if (!do_rapl) ··· 4152 4018 return -1; 4153 4019 } 4154 4020 4155 - if (get_msr(cpu, MSR_RAPL_POWER_UNIT, &msr)) 4156 - return -1; 4021 + if (do_rapl & RAPL_AMD_F17H) { 4022 + msr_name = "MSR_RAPL_PWR_UNIT"; 4023 + if (get_msr(cpu, MSR_RAPL_PWR_UNIT, &msr)) 4024 + return -1; 4025 + } else { 4026 + msr_name = "MSR_RAPL_POWER_UNIT"; 4027 + if (get_msr(cpu, MSR_RAPL_POWER_UNIT, &msr)) 4028 + return -1; 4029 + } 4157 4030 4158 - fprintf(outf, "cpu%d: MSR_RAPL_POWER_UNIT: 0x%08llx (%f Watts, %f Joules, %f sec.)\n", cpu, msr, 4031 + fprintf(outf, "cpu%d: %s: 0x%08llx (%f Watts, %f Joules, %f sec.)\n", cpu, msr_name, msr, 4159 4032 rapl_power_units, rapl_energy_units, rapl_time_units); 4160 4033 4161 4034 if (do_rapl & RAPL_PKG_POWER_INFO) { ··· 4592 4451 case INTEL_FAM6_KABYLAKE_MOBILE: 4593 4452 case INTEL_FAM6_KABYLAKE_DESKTOP: 4594 4453 return INTEL_FAM6_SKYLAKE_MOBILE; 4454 + 4455 + case INTEL_FAM6_ICELAKE_MOBILE: 4456 + return INTEL_FAM6_CANNONLAKE_MOBILE; 4595 4457 } 4596 4458 return model; 4597 4459 } ··· 4846 4702 } 4847 4703 do_slm_cstates = is_slm(family, model); 4848 4704 do_knl_cstates = is_knl(family, model); 4849 - do_cnl_cstates = is_cnl(family, model); 4705 + 4706 + if (do_slm_cstates || do_knl_cstates || is_cnl(family, model)) 4707 + BIC_NOT_PRESENT(BIC_CPU_c3); 4850 4708 4851 4709 if (!quiet) 4852 4710 decode_misc_pwr_mgmt_msr(); ··· 4915 4769 int i; 4916 4770 int max_core_id = 0; 4917 4771 int max_package_id = 0; 4772 + int max_die_id = 0; 4918 4773 int max_siblings = 0; 4919 4774 4920 4775 /* Initialize num_cpus, max_cpu_num */ ··· 4982 4835 if (cpus[i].physical_package_id > max_package_id) 4983 4836 max_package_id = cpus[i].physical_package_id; 4984 4837 4838 + /* get die information */ 4839 + cpus[i].die_id = get_die_id(i); 4840 + if (cpus[i].die_id > max_die_id) 4841 + max_die_id = cpus[i].die_id; 4842 + 4985 4843 /* get numa node information */ 4986 4844 cpus[i].physical_node_id = get_physical_node_id(&cpus[i]); 4987 4845 if (cpus[i].physical_node_id > topo.max_node_num) ··· 5012 4860 if (!summary_only && topo.cores_per_node > 1) 5013 4861 BIC_PRESENT(BIC_Core); 5014 4862 4863 + topo.num_die = max_die_id + 1; 4864 + if (debug > 1) 4865 + fprintf(outf, "max_die_id %d, sizing for %d die\n", 4866 + max_die_id, topo.num_die); 4867 + if (!summary_only && topo.num_die > 1) 4868 + BIC_PRESENT(BIC_Die); 4869 + 5015 4870 topo.num_packages = max_package_id + 1; 5016 4871 if (debug > 1) 5017 4872 fprintf(outf, "max_package_id %d, sizing for %d packages\n", ··· 5043 4884 if (cpu_is_not_present(i)) 5044 4885 continue; 5045 4886 fprintf(outf, 5046 - "cpu %d pkg %d node %d lnode %d core %d thread %d\n", 5047 - i, cpus[i].physical_package_id, 4887 + "cpu %d pkg %d die %d node %d lnode %d core %d thread %d\n", 4888 + i, cpus[i].physical_package_id, cpus[i].die_id, 5048 4889 cpus[i].physical_node_id, 5049 4890 cpus[i].logical_node_id, 5050 4891 cpus[i].physical_core_id, ··· 5281 5122 } 5282 5123 5283 5124 void print_version() { 5284 - fprintf(outf, "turbostat version 18.07.27" 5125 + fprintf(outf, "turbostat version 19.03.20" 5285 5126 " - Len Brown <lenb@kernel.org>\n"); 5286 5127 } 5287 5128 ··· 5478 5319 input = fopen(path, "r"); 5479 5320 if (input == NULL) 5480 5321 continue; 5481 - fgets(name_buf, sizeof(name_buf), input); 5322 + if (!fgets(name_buf, sizeof(name_buf), input)) 5323 + err(1, "%s: failed to read file", path); 5482 5324 5483 5325 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ 5484 5326 sp = strchr(name_buf, '-'); ··· 5506 5346 input = fopen(path, "r"); 5507 5347 if (input == NULL) 5508 5348 continue; 5509 - fgets(name_buf, sizeof(name_buf), input); 5349 + if (!fgets(name_buf, sizeof(name_buf), input)) 5350 + err(1, "%s: failed to read file", path); 5510 5351 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ 5511 5352 sp = strchr(name_buf, '-'); 5512 5353 if (!sp)