Lines Matching +full:ecx +full:- +full:1000
1 // SPDX-License-Identifier: GPL-2.0-only
3 * turbostat -- show CPU frequency and C-state residency
44 * 1. built-in only, the sysfs counters are not here -- we learn of those at run-time
46 * matching on them for --show and --hide.
51 * Usually truncated to 7 characters, but also handles 18 columns for raw 64-bit counters
318 /* Indicates cores energy collection is per-core,
319 * not per-package. */
327 /* MSRs that are not yet in the kernel-provided header. */
369 unsigned long long mc6_us; /* duplicate as per-core for now, even though per module */
443 /* get_msr_sum() = sum + (get_msr() - last) */
482 offset = -1; in idx_to_offset()
512 idx = -1; in offset_to_idx()
557 int logical_node_id; /* 0-based count within the package */
594 * skip non-present cpus
612 if (cpu_is_not_present(t->cpu_id)) in for_all_cpus()
632 if (sched_setaffinity(0, cpu_affinity_setsize, cpu_affinity_set) == -1) in cpu_migrate()
633 return -1; in cpu_migrate()
651 err(-1, "%s open failed, try chown or chmod +r /dev/cpu/*/msr, or run as root", pathname); in get_msr_fd()
674 fd = perf_event_open(&pea, -1, cpu_num, -1, 0); in perf_instr_count_open()
675 if (fd == -1) { in perf_instr_count_open()
700 err(-1, "cpu%d: msr offset 0x%llx read failed", cpu, (unsigned long long)offset); in get_msr()
712 * HIDE_LIST - hide this list of counters, show the rest [default]
713 * SHOW_LIST - show this list of counters, hide the rest
720 "Usage: turbostat [OPTIONS][(--interval seconds) | COMMAND ...]\n" in help()
724 "If no COMMAND is specified, turbostat wakes every 5-seconds\n" in help()
726 " -a, --add add a counter\n" in help()
727 " eg. --add msr0x10,u64,cpu,delta,MY_TSC\n" in help()
728 " -c, --cpu cpu-set limit output to summary plus cpu-set:\n" in help()
729 " {core | package | j,k,l..m,n-p }\n" in help()
730 " -d, --debug displays usec, Time_Of_Day_Seconds and more debugging\n" in help()
731 " -D, --Dump displays the raw counter values\n" in help()
732 " -e, --enable [all | column]\n" in help()
734 " -H, --hide [column|column,column,...]\n" in help()
736 " -i, --interval sec.subsec\n" in help()
737 " Override default 5-second measurement interval\n" in help()
738 " -J, --Joules displays energy in Joules instead of Watts\n" in help()
739 " -l, --list list column headers only\n" in help()
740 " -n, --num_iterations num\n" in help()
742 " -N, --header_iterations num\n" in help()
744 " -o, --out file\n" in help()
746 " -q, --quiet skip decoding system configuration header\n" in help()
747 " -s, --show [column|column,column,...]\n" in help()
749 " -S, --Summary\n" in help()
750 " limits output to 1-line system summary per interval\n" in help()
751 " -T, --TCC temperature\n" in help()
754 " -h, --help print this help message\n" in help()
755 " -v, --version print version information\n" "\n" "For more help, run \"man turbostat\"\n"); in help()
806 fprintf(stderr, "More than max %d un-recognized --add options '%s'\n", in bic_lookup()
816 fprintf(stderr, "More than max %d un-recognized --skip options '%s'\n", in bic_lookup()
877 for (mp = sys.tp; mp; mp = mp->next) { in print_header()
879 if (mp->format == FORMAT_RAW) { in print_header()
880 if (mp->width == 64) in print_header()
881 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), mp->name); in print_header()
883 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), mp->name); in print_header()
885 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in print_header()
886 outp += sprintf(outp, "%s%8s", (printed++ ? delim : ""), mp->name); in print_header()
888 outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), mp->name); in print_header()
918 for (mp = sys.cp; mp; mp = mp->next) { in print_header()
919 if (mp->format == FORMAT_RAW) { in print_header()
920 if (mp->width == 64) in print_header()
921 outp += sprintf(outp, "%s%18.18s", delim, mp->name); in print_header()
923 outp += sprintf(outp, "%s%10.10s", delim, mp->name); in print_header()
925 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in print_header()
926 outp += sprintf(outp, "%s%8s", delim, mp->name); in print_header()
928 outp += sprintf(outp, "%s%s", delim, mp->name); in print_header()
1002 for (mp = sys.pp; mp; mp = mp->next) { in print_header()
1003 if (mp->format == FORMAT_RAW) { in print_header()
1004 if (mp->width == 64) in print_header()
1005 outp += sprintf(outp, "%s%18.18s", delim, mp->name); in print_header()
1007 outp += sprintf(outp, "%s%10.10s", delim, mp->name); in print_header()
1009 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in print_header()
1010 outp += sprintf(outp, "%s%8s", delim, mp->name); in print_header()
1012 outp += sprintf(outp, "%s%s", delim, mp->name); in print_header()
1027 outp += sprintf(outp, "CPU: %d flags 0x%x\n", t->cpu_id, t->flags); in dump_counters()
1028 outp += sprintf(outp, "TSC: %016llX\n", t->tsc); in dump_counters()
1029 outp += sprintf(outp, "aperf: %016llX\n", t->aperf); in dump_counters()
1030 outp += sprintf(outp, "mperf: %016llX\n", t->mperf); in dump_counters()
1031 outp += sprintf(outp, "c1: %016llX\n", t->c1); in dump_counters()
1034 outp += sprintf(outp, "IPC: %lld\n", t->instr_count); in dump_counters()
1037 outp += sprintf(outp, "IRQ: %lld\n", t->irq_count); in dump_counters()
1039 outp += sprintf(outp, "SMI: %d\n", t->smi_count); in dump_counters()
1041 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in dump_counters()
1042 outp += sprintf(outp, "tADDED [%d] msr0x%x: %08llX\n", i, mp->msr_num, t->counter[i]); in dump_counters()
1047 outp += sprintf(outp, "core: %d\n", c->core_id); in dump_counters()
1048 outp += sprintf(outp, "c3: %016llX\n", c->c3); in dump_counters()
1049 outp += sprintf(outp, "c6: %016llX\n", c->c6); in dump_counters()
1050 outp += sprintf(outp, "c7: %016llX\n", c->c7); in dump_counters()
1051 outp += sprintf(outp, "DTS: %dC\n", c->core_temp_c); in dump_counters()
1052 outp += sprintf(outp, "cpu_throt_count: %016llX\n", c->core_throt_cnt); in dump_counters()
1053 outp += sprintf(outp, "Joules: %0X\n", c->core_energy); in dump_counters()
1055 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in dump_counters()
1056 outp += sprintf(outp, "cADDED [%d] msr0x%x: %08llX\n", i, mp->msr_num, c->counter[i]); in dump_counters()
1058 outp += sprintf(outp, "mc6_us: %016llX\n", c->mc6_us); in dump_counters()
1062 outp += sprintf(outp, "package: %d\n", p->package_id); in dump_counters()
1064 outp += sprintf(outp, "Weighted cores: %016llX\n", p->pkg_wtd_core_c0); in dump_counters()
1065 outp += sprintf(outp, "Any cores: %016llX\n", p->pkg_any_core_c0); in dump_counters()
1066 outp += sprintf(outp, "Any GFX: %016llX\n", p->pkg_any_gfxe_c0); in dump_counters()
1067 outp += sprintf(outp, "CPU + GFX: %016llX\n", p->pkg_both_core_gfxe_c0); in dump_counters()
1069 outp += sprintf(outp, "pc2: %016llX\n", p->pc2); in dump_counters()
1071 outp += sprintf(outp, "pc3: %016llX\n", p->pc3); in dump_counters()
1073 outp += sprintf(outp, "pc6: %016llX\n", p->pc6); in dump_counters()
1075 outp += sprintf(outp, "pc7: %016llX\n", p->pc7); in dump_counters()
1076 outp += sprintf(outp, "pc8: %016llX\n", p->pc8); in dump_counters()
1077 outp += sprintf(outp, "pc9: %016llX\n", p->pc9); in dump_counters()
1078 outp += sprintf(outp, "pc10: %016llX\n", p->pc10); in dump_counters()
1079 outp += sprintf(outp, "cpu_lpi: %016llX\n", p->cpu_lpi); in dump_counters()
1080 outp += sprintf(outp, "sys_lpi: %016llX\n", p->sys_lpi); in dump_counters()
1081 outp += sprintf(outp, "Joules PKG: %0llX\n", p->energy_pkg); in dump_counters()
1082 outp += sprintf(outp, "Joules COR: %0llX\n", p->energy_cores); in dump_counters()
1083 outp += sprintf(outp, "Joules GFX: %0llX\n", p->energy_gfx); in dump_counters()
1084 outp += sprintf(outp, "Joules RAM: %0llX\n", p->energy_dram); in dump_counters()
1085 outp += sprintf(outp, "Throttle PKG: %0llX\n", p->rapl_pkg_perf_status); in dump_counters()
1086 outp += sprintf(outp, "Throttle RAM: %0llX\n", p->rapl_dram_perf_status); in dump_counters()
1087 outp += sprintf(outp, "PTM: %dC\n", p->pkg_temp_c); in dump_counters()
1089 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in dump_counters()
1090 outp += sprintf(outp, "pADDED [%d] msr0x%x: %08llX\n", i, mp->msr_num, p->counter[i]); in dump_counters()
1112 if (show_core_only && !(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) in format_counters()
1116 if (show_pkg_only && !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) in format_counters()
1119 /*if not summary line and --cpu is used */ in format_counters()
1120 …if ((t != &average.threads) && (cpu_subset && !CPU_ISSET_S(t->cpu_id, cpu_subset_size, cpu_subset)… in format_counters()
1127 timersub(&t->tv_end, &t->tv_begin, &tv); in format_counters()
1133 outp += sprintf(outp, "%10ld.%06ld\t", t->tv_end.tv_sec, t->tv_end.tv_usec); in format_counters()
1135 interval_float = t->tv_delta.tv_sec + t->tv_delta.tv_usec / 1000000.0; in format_counters()
1137 tsc = t->tsc * tsc_tweak; in format_counters()
1142 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
1144 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
1146 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
1148 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
1150 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
1152 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
1154 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
1158 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->package_id); in format_counters()
1160 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
1164 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), cpus[t->cpu_id].die_id); in format_counters()
1166 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
1171 (printed++ ? delim : ""), cpus[t->cpu_id].physical_node_id); in format_counters()
1173 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
1177 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), c->core_id); in format_counters()
1179 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
1182 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->cpu_id); in format_counters()
1184 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->apic_id); in format_counters()
1186 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->x2apic_id); in format_counters()
1190 …outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), 1.0 / units * t->aperf / interval_float); in format_counters()
1193 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->mperf / tsc); in format_counters()
1198 sprintf(outp, "%s%.0f", (printed++ ? delim : ""), base_hz / units * t->aperf / t->mperf); in format_counters()
1201 tsc / units * t->aperf / t->mperf / interval_float); in format_counters()
1205 outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), 1.0 * t->tsc / units / interval_float); in format_counters()
1208 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 1.0 * t->instr_count / t->aperf); in format_counters()
1213 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), t->irq_count); in format_counters()
1215 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->irq_count); in format_counters()
1220 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->smi_count); in format_counters()
1223 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in format_counters()
1224 if (mp->format == FORMAT_RAW) { in format_counters()
1225 if (mp->width == 32) in format_counters()
1227 sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int)t->counter[i]); in format_counters()
1229 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), t->counter[i]); in format_counters()
1230 } else if (mp->format == FORMAT_DELTA) { in format_counters()
1231 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in format_counters()
1232 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), t->counter[i]); in format_counters()
1234 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->counter[i]); in format_counters()
1235 } else if (mp->format == FORMAT_PERCENT) { in format_counters()
1236 if (mp->type == COUNTER_USEC) in format_counters()
1239 t->counter[i] / interval_float / 10000); in format_counters()
1241 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->counter[i] / tsc); in format_counters()
1247 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->c1 / tsc); in format_counters()
1249 /* print per-core data only for 1st thread in core */ in format_counters()
1250 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) in format_counters()
1254 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c3 / tsc); in format_counters()
1256 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c6 / tsc); in format_counters()
1258 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c7 / tsc); in format_counters()
1262 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->mc6_us / tsc); in format_counters()
1265 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), c->core_temp_c); in format_counters()
1269 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), c->core_throt_cnt); in format_counters()
1271 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in format_counters()
1272 if (mp->format == FORMAT_RAW) { in format_counters()
1273 if (mp->width == 32) in format_counters()
1275 sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int)c->counter[i]); in format_counters()
1277 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), c->counter[i]); in format_counters()
1278 } else if (mp->format == FORMAT_DELTA) { in format_counters()
1279 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in format_counters()
1280 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), c->counter[i]); in format_counters()
1282 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), c->counter[i]); in format_counters()
1283 } else if (mp->format == FORMAT_PERCENT) { in format_counters()
1284 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->counter[i] / tsc); in format_counters()
1292 …sprintf(outp, fmt8, (printed++ ? delim : ""), c->core_energy * rapl_energy_units / interval_float); in format_counters()
1294 outp += sprintf(outp, fmt8, (printed++ ? delim : ""), c->core_energy * rapl_energy_units); in format_counters()
1296 /* print per-package data only for 1st core in package */ in format_counters()
1297 if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) in format_counters()
1302 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->pkg_temp_c); in format_counters()
1306 if (p->gfx_rc6_ms == -1) { /* detect GFX counter reset */ in format_counters()
1310 p->gfx_rc6_ms / 10.0 / interval_float); in format_counters()
1316 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->gfx_mhz); in format_counters()
1320 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->gfx_act_mhz); in format_counters()
1324 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_wtd_core_c0 / tsc); in format_counters()
1326 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_any_core_c0 / tsc); in format_counters()
1328 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_any_gfxe_c0 / tsc); in format_counters()
1330 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_both_core_gfxe_c0 / tsc); in format_counters()
1333 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc2 / tsc); in format_counters()
1335 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc3 / tsc); in format_counters()
1337 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc6 / tsc); in format_counters()
1339 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc7 / tsc); in format_counters()
1341 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc8 / tsc); in format_counters()
1343 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc9 / tsc); in format_counters()
1345 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc10 / tsc); in format_counters()
1349 …sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->cpu_lpi / 1000000.0 / interval_float); in format_counters()
1352 …sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->sys_lpi / 1000000.0 / interval_float); in format_counters()
1356 … sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_pkg * rapl_energy_units / interval_float); in format_counters()
1360 …sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_cores * rapl_energy_units / interval_float… in format_counters()
1363 … sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_gfx * rapl_energy_units / interval_float); in format_counters()
1367 p->energy_dram * rapl_dram_energy_units / interval_float); in format_counters()
1369 outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_pkg * rapl_energy_units); in format_counters()
1371 outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_cores * rapl_energy_units); in format_counters()
1373 outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_gfx * rapl_energy_units); in format_counters()
1375 outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_dram * rapl_dram_energy_units); in format_counters()
1379 100.0 * p->rapl_pkg_perf_status * rapl_time_units / interval_float); in format_counters()
1383 100.0 * p->rapl_dram_perf_status * rapl_time_units / interval_float); in format_counters()
1386 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->uncore_mhz); in format_counters()
1388 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in format_counters()
1389 if (mp->format == FORMAT_RAW) { in format_counters()
1390 if (mp->width == 32) in format_counters()
1392 sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int)p->counter[i]); in format_counters()
1394 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), p->counter[i]); in format_counters()
1395 } else if (mp->format == FORMAT_DELTA) { in format_counters()
1396 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in format_counters()
1397 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), p->counter[i]); in format_counters()
1399 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), p->counter[i]); in format_counters()
1400 } else if (mp->format == FORMAT_PERCENT) { in format_counters()
1401 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->counter[i] / tsc); in format_counters()
1406 if (*(outp - 1) != '\n') in format_counters()
1452 old = ((((unsigned long long)new << 32) - ((unsigned long long)old << 32)) >> 32);
1460 old->pkg_wtd_core_c0 = new->pkg_wtd_core_c0 - old->pkg_wtd_core_c0; in delta_package()
1462 old->pkg_any_core_c0 = new->pkg_any_core_c0 - old->pkg_any_core_c0; in delta_package()
1464 old->pkg_any_gfxe_c0 = new->pkg_any_gfxe_c0 - old->pkg_any_gfxe_c0; in delta_package()
1466 old->pkg_both_core_gfxe_c0 = new->pkg_both_core_gfxe_c0 - old->pkg_both_core_gfxe_c0; in delta_package()
1468 old->pc2 = new->pc2 - old->pc2; in delta_package()
1470 old->pc3 = new->pc3 - old->pc3; in delta_package()
1472 old->pc6 = new->pc6 - old->pc6; in delta_package()
1474 old->pc7 = new->pc7 - old->pc7; in delta_package()
1475 old->pc8 = new->pc8 - old->pc8; in delta_package()
1476 old->pc9 = new->pc9 - old->pc9; in delta_package()
1477 old->pc10 = new->pc10 - old->pc10; in delta_package()
1478 old->cpu_lpi = new->cpu_lpi - old->cpu_lpi; in delta_package()
1479 old->sys_lpi = new->sys_lpi - old->sys_lpi; in delta_package()
1480 old->pkg_temp_c = new->pkg_temp_c; in delta_package()
1483 if (old->gfx_rc6_ms > new->gfx_rc6_ms) in delta_package()
1484 old->gfx_rc6_ms = -1; in delta_package()
1486 old->gfx_rc6_ms = new->gfx_rc6_ms - old->gfx_rc6_ms; in delta_package()
1488 old->uncore_mhz = new->uncore_mhz; in delta_package()
1489 old->gfx_mhz = new->gfx_mhz; in delta_package()
1490 old->gfx_act_mhz = new->gfx_act_mhz; in delta_package()
1492 old->energy_pkg = new->energy_pkg - old->energy_pkg; in delta_package()
1493 old->energy_cores = new->energy_cores - old->energy_cores; in delta_package()
1494 old->energy_gfx = new->energy_gfx - old->energy_gfx; in delta_package()
1495 old->energy_dram = new->energy_dram - old->energy_dram; in delta_package()
1496 old->rapl_pkg_perf_status = new->rapl_pkg_perf_status - old->rapl_pkg_perf_status; in delta_package()
1497 old->rapl_dram_perf_status = new->rapl_dram_perf_status - old->rapl_dram_perf_status; in delta_package()
1499 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in delta_package()
1500 if (mp->format == FORMAT_RAW) in delta_package()
1501 old->counter[i] = new->counter[i]; in delta_package()
1503 old->counter[i] = new->counter[i] - old->counter[i]; in delta_package()
1514 old->c3 = new->c3 - old->c3; in delta_core()
1515 old->c6 = new->c6 - old->c6; in delta_core()
1516 old->c7 = new->c7 - old->c7; in delta_core()
1517 old->core_temp_c = new->core_temp_c; in delta_core()
1518 old->core_throt_cnt = new->core_throt_cnt; in delta_core()
1519 old->mc6_us = new->mc6_us - old->mc6_us; in delta_core()
1521 DELTA_WRAP32(new->core_energy, old->core_energy); in delta_core()
1523 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in delta_core()
1524 if (mp->format == FORMAT_RAW) in delta_core()
1525 old->counter[i] = new->counter[i]; in delta_core()
1527 old->counter[i] = new->counter[i] - old->counter[i]; in delta_core()
1540 * old = new - old
1549 new->apic_id = old->apic_id; in delta_thread()
1551 new->x2apic_id = old->x2apic_id; in delta_thread()
1556 * over-write old w/ new so we can print end of interval values in delta_thread()
1559 timersub(&new->tv_begin, &old->tv_begin, &old->tv_delta); in delta_thread()
1560 old->tv_begin = new->tv_begin; in delta_thread()
1561 old->tv_end = new->tv_end; in delta_thread()
1563 old->tsc = new->tsc - old->tsc; in delta_thread()
1566 if (old->tsc < (1000 * 1000)) in delta_thread()
1567 errx(-3, "Insanely slow TSC rate, TSC stops in idle?\n" in delta_thread()
1568 "You can disable all c-states by booting with \"idle=poll\"\n" in delta_thread()
1571 old->c1 = new->c1 - old->c1; in delta_thread()
1574 if ((new->aperf > old->aperf) && (new->mperf > old->mperf)) { in delta_thread()
1575 old->aperf = new->aperf - old->aperf; in delta_thread()
1576 old->mperf = new->mperf - old->mperf; in delta_thread()
1578 return -1; in delta_thread()
1590 * it is possible for mperf's non-halted cycles + idle states in delta_thread()
1593 if ((old->mperf + core_delta->c3 + core_delta->c6 + core_delta->c7) > (old->tsc * tsc_tweak)) in delta_thread()
1594 old->c1 = 0; in delta_thread()
1597 old->c1 = (old->tsc * tsc_tweak) - old->mperf - core_delta->c3 in delta_thread()
1598 - core_delta->c6 - core_delta->c7; in delta_thread()
1602 if (old->mperf == 0) { in delta_thread()
1604 fprintf(outf, "cpu%d MPERF 0!\n", old->cpu_id); in delta_thread()
1605 old->mperf = 1; /* divide by 0 protection */ in delta_thread()
1609 old->instr_count = new->instr_count - old->instr_count; in delta_thread()
1612 old->irq_count = new->irq_count - old->irq_count; in delta_thread()
1615 old->smi_count = new->smi_count - old->smi_count; in delta_thread()
1617 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in delta_thread()
1618 if (mp->format == FORMAT_RAW) in delta_thread()
1619 old->counter[i] = new->counter[i]; in delta_thread()
1621 old->counter[i] = new->counter[i] - old->counter[i]; in delta_thread()
1632 if (t->flags & CPU_IS_FIRST_THREAD_IN_CORE) in delta_cpu()
1641 if (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE) in delta_cpu()
1652 t->tv_begin.tv_sec = 0; in clear_counters()
1653 t->tv_begin.tv_usec = 0; in clear_counters()
1654 t->tv_end.tv_sec = 0; in clear_counters()
1655 t->tv_end.tv_usec = 0; in clear_counters()
1656 t->tv_delta.tv_sec = 0; in clear_counters()
1657 t->tv_delta.tv_usec = 0; in clear_counters()
1659 t->tsc = 0; in clear_counters()
1660 t->aperf = 0; in clear_counters()
1661 t->mperf = 0; in clear_counters()
1662 t->c1 = 0; in clear_counters()
1664 t->instr_count = 0; in clear_counters()
1666 t->irq_count = 0; in clear_counters()
1667 t->smi_count = 0; in clear_counters()
1670 t->flags = CPU_IS_FIRST_THREAD_IN_CORE | CPU_IS_FIRST_CORE_IN_PACKAGE; in clear_counters()
1672 c->c3 = 0; in clear_counters()
1673 c->c6 = 0; in clear_counters()
1674 c->c7 = 0; in clear_counters()
1675 c->mc6_us = 0; in clear_counters()
1676 c->core_temp_c = 0; in clear_counters()
1677 c->core_energy = 0; in clear_counters()
1678 c->core_throt_cnt = 0; in clear_counters()
1680 p->pkg_wtd_core_c0 = 0; in clear_counters()
1681 p->pkg_any_core_c0 = 0; in clear_counters()
1682 p->pkg_any_gfxe_c0 = 0; in clear_counters()
1683 p->pkg_both_core_gfxe_c0 = 0; in clear_counters()
1685 p->pc2 = 0; in clear_counters()
1687 p->pc3 = 0; in clear_counters()
1689 p->pc6 = 0; in clear_counters()
1691 p->pc7 = 0; in clear_counters()
1692 p->pc8 = 0; in clear_counters()
1693 p->pc9 = 0; in clear_counters()
1694 p->pc10 = 0; in clear_counters()
1695 p->cpu_lpi = 0; in clear_counters()
1696 p->sys_lpi = 0; in clear_counters()
1698 p->energy_pkg = 0; in clear_counters()
1699 p->energy_dram = 0; in clear_counters()
1700 p->energy_cores = 0; in clear_counters()
1701 p->energy_gfx = 0; in clear_counters()
1702 p->rapl_pkg_perf_status = 0; in clear_counters()
1703 p->rapl_dram_perf_status = 0; in clear_counters()
1704 p->pkg_temp_c = 0; in clear_counters()
1706 p->gfx_rc6_ms = 0; in clear_counters()
1707 p->uncore_mhz = 0; in clear_counters()
1708 p->gfx_mhz = 0; in clear_counters()
1709 p->gfx_act_mhz = 0; in clear_counters()
1710 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) in clear_counters()
1711 t->counter[i] = 0; in clear_counters()
1713 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) in clear_counters()
1714 c->counter[i] = 0; in clear_counters()
1716 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) in clear_counters()
1717 p->counter[i] = 0; in clear_counters()
1725 /* copy un-changing apic_id's */ in sum_counters()
1727 average.threads.apic_id = t->apic_id; in sum_counters()
1729 average.threads.x2apic_id = t->x2apic_id; in sum_counters()
1733 average.threads.tv_begin = t->tv_begin; in sum_counters()
1736 average.threads.tv_end = t->tv_end; in sum_counters()
1738 average.threads.tsc += t->tsc; in sum_counters()
1739 average.threads.aperf += t->aperf; in sum_counters()
1740 average.threads.mperf += t->mperf; in sum_counters()
1741 average.threads.c1 += t->c1; in sum_counters()
1743 average.threads.instr_count += t->instr_count; in sum_counters()
1745 average.threads.irq_count += t->irq_count; in sum_counters()
1746 average.threads.smi_count += t->smi_count; in sum_counters()
1748 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in sum_counters()
1749 if (mp->format == FORMAT_RAW) in sum_counters()
1751 average.threads.counter[i] += t->counter[i]; in sum_counters()
1754 /* sum per-core values only for 1st thread in core */ in sum_counters()
1755 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) in sum_counters()
1758 average.cores.c3 += c->c3; in sum_counters()
1759 average.cores.c6 += c->c6; in sum_counters()
1760 average.cores.c7 += c->c7; in sum_counters()
1761 average.cores.mc6_us += c->mc6_us; in sum_counters()
1763 average.cores.core_temp_c = MAX(average.cores.core_temp_c, c->core_temp_c); in sum_counters()
1764 average.cores.core_throt_cnt = MAX(average.cores.core_throt_cnt, c->core_throt_cnt); in sum_counters()
1766 average.cores.core_energy += c->core_energy; in sum_counters()
1768 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in sum_counters()
1769 if (mp->format == FORMAT_RAW) in sum_counters()
1771 average.cores.counter[i] += c->counter[i]; in sum_counters()
1774 /* sum per-pkg values only for 1st core in pkg */ in sum_counters()
1775 if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) in sum_counters()
1779 average.packages.pkg_wtd_core_c0 += p->pkg_wtd_core_c0; in sum_counters()
1781 average.packages.pkg_any_core_c0 += p->pkg_any_core_c0; in sum_counters()
1783 average.packages.pkg_any_gfxe_c0 += p->pkg_any_gfxe_c0; in sum_counters()
1785 average.packages.pkg_both_core_gfxe_c0 += p->pkg_both_core_gfxe_c0; in sum_counters()
1787 average.packages.pc2 += p->pc2; in sum_counters()
1789 average.packages.pc3 += p->pc3; in sum_counters()
1791 average.packages.pc6 += p->pc6; in sum_counters()
1793 average.packages.pc7 += p->pc7; in sum_counters()
1794 average.packages.pc8 += p->pc8; in sum_counters()
1795 average.packages.pc9 += p->pc9; in sum_counters()
1796 average.packages.pc10 += p->pc10; in sum_counters()
1798 average.packages.cpu_lpi = p->cpu_lpi; in sum_counters()
1799 average.packages.sys_lpi = p->sys_lpi; in sum_counters()
1801 average.packages.energy_pkg += p->energy_pkg; in sum_counters()
1802 average.packages.energy_dram += p->energy_dram; in sum_counters()
1803 average.packages.energy_cores += p->energy_cores; in sum_counters()
1804 average.packages.energy_gfx += p->energy_gfx; in sum_counters()
1806 average.packages.gfx_rc6_ms = p->gfx_rc6_ms; in sum_counters()
1807 average.packages.uncore_mhz = p->uncore_mhz; in sum_counters()
1808 average.packages.gfx_mhz = p->gfx_mhz; in sum_counters()
1809 average.packages.gfx_act_mhz = p->gfx_act_mhz; in sum_counters()
1811 average.packages.pkg_temp_c = MAX(average.packages.pkg_temp_c, p->pkg_temp_c); in sum_counters()
1813 average.packages.rapl_pkg_perf_status += p->rapl_pkg_perf_status; in sum_counters()
1814 average.packages.rapl_dram_perf_status += p->rapl_dram_perf_status; in sum_counters()
1816 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in sum_counters()
1817 if ((mp->format == FORMAT_RAW) && (topo.num_packages == 0)) in sum_counters()
1818 average.packages.counter[i] = p->counter[i]; in sum_counters()
1820 average.packages.counter[i] += p->counter[i]; in sum_counters()
1876 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in compute_average()
1877 if (mp->format == FORMAT_RAW) in compute_average()
1879 if (mp->type == COUNTER_ITEMS) { in compute_average()
1886 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in compute_average()
1887 if (mp->format == FORMAT_RAW) in compute_average()
1889 if (mp->type == COUNTER_ITEMS) { in compute_average()
1895 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in compute_average()
1896 if (mp->format == FORMAT_RAW) in compute_average()
1898 if (mp->type == COUNTER_ITEMS) { in compute_average()
1951 if (mp->msr_num != 0) { in get_mp()
1952 if (get_msr(cpu, mp->msr_num, counterp)) in get_mp()
1953 return -1; in get_mp()
1957 if (mp->flags & SYSFS_PERCPU) { in get_mp()
1958 sprintf(path, "/sys/devices/system/cpu/cpu%d/%s", cpu, mp->path); in get_mp()
1962 *counterp = snapshot_sysfs_counter(mp->path); in get_mp()
1976 return (snapshot_sysfs_counter(path) / 1000); in get_uncore_mhz()
1983 int ret, epb = -1; in get_epb()
2008 unsigned int eax, ebx, ecx, edx; in get_apic_id() local
2011 eax = ebx = ecx = edx = 0; in get_apic_id()
2012 __cpuid(1, eax, ebx, ecx, edx); in get_apic_id()
2014 t->apic_id = (ebx >> 24) & 0xff; in get_apic_id()
2026 eax = ebx = ecx = edx = 0; in get_apic_id()
2027 __cpuid(0x80000001, eax, ebx, ecx, edx); in get_apic_id()
2028 topology_extensions = ecx & (1 << 22); in get_apic_id()
2033 eax = ebx = ecx = edx = 0; in get_apic_id()
2034 __cpuid(0x8000001e, eax, ebx, ecx, edx); in get_apic_id()
2036 t->x2apic_id = eax; in get_apic_id()
2046 ecx = 0; in get_apic_id()
2047 __cpuid(0xb, eax, ebx, ecx, edx); in get_apic_id()
2048 t->x2apic_id = edx; in get_apic_id()
2050 if (debug && (t->apic_id != (t->x2apic_id & 0xff))) in get_apic_id()
2051 fprintf(outf, "cpu%d: BIOS BUG: apic 0x%x x2apic 0x%x\n", t->cpu_id, t->apic_id, t->x2apic_id); in get_apic_id()
2064 return -1; in get_core_throt_cnt()
2068 return -1; in get_core_throt_cnt()
2081 int cpu = t->cpu_id; in get_counters()
2089 return -1; in get_counters()
2092 gettimeofday(&t->tv_begin, (struct timezone *)NULL); in get_counters()
2097 t->tsc = rdtsc(); /* we are running on local CPU of interest */ in get_counters()
2109 * varies by a large amount, we re-read them. in get_counters()
2117 if (get_msr(cpu, MSR_IA32_APERF, &t->aperf)) in get_counters()
2118 return -3; in get_counters()
2120 t->tsc = rdtsc(); /* re-read close to APERF */ in get_counters()
2122 tsc_before = t->tsc; in get_counters()
2124 if (get_msr(cpu, MSR_IA32_APERF, &t->aperf)) in get_counters()
2125 return -3; in get_counters()
2129 if (get_msr(cpu, MSR_IA32_MPERF, &t->mperf)) in get_counters()
2130 return -4; in get_counters()
2134 aperf_time = tsc_between - tsc_before; in get_counters()
2135 mperf_time = tsc_after - tsc_between; in get_counters()
2150 t->aperf = t->aperf * aperf_mperf_multiplier; in get_counters()
2151 t->mperf = t->mperf * aperf_mperf_multiplier; in get_counters()
2155 if (read(get_instr_count_fd(cpu), &t->instr_count, sizeof(long long)) != sizeof(long long)) in get_counters()
2156 return -4; in get_counters()
2159 t->irq_count = irqs_per_cpu[cpu]; in get_counters()
2162 return -5; in get_counters()
2163 t->smi_count = msr & 0xFFFFFFFF; in get_counters()
2166 if (get_msr(cpu, MSR_CORE_C1_RES, &t->c1)) in get_counters()
2167 return -6; in get_counters()
2170 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in get_counters()
2171 if (get_mp(cpu, mp, &t->counter[i])) in get_counters()
2172 return -10; in get_counters()
2176 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) in get_counters()
2180 if (get_msr(cpu, MSR_CORE_C3_RESIDENCY, &c->c3)) in get_counters()
2181 return -6; in get_counters()
2185 if (get_msr(cpu, MSR_CORE_C6_RESIDENCY, &c->c6)) in get_counters()
2186 return -7; in get_counters()
2188 if (get_msr(cpu, MSR_KNL_CORE_C6_RESIDENCY, &c->c6)) in get_counters()
2189 return -7; in get_counters()
2193 if (get_msr(cpu, MSR_CORE_C7_RESIDENCY, &c->c7)) in get_counters()
2194 return -8; in get_counters()
2195 else if (t->is_atom) { in get_counters()
2202 c->c6 -= c->c7; in get_counters()
2207 if (get_msr(cpu, MSR_MODULE_C6_RES_MS, &c->mc6_us)) in get_counters()
2208 return -8; in get_counters()
2212 return -9; in get_counters()
2213 c->core_temp_c = tj_max - ((msr >> 16) & 0x7F); in get_counters()
2217 get_core_throt_cnt(cpu, &c->core_throt_cnt); in get_counters()
2221 return -14; in get_counters()
2222 c->core_energy = msr & 0xFFFFFFFF; in get_counters()
2225 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in get_counters()
2226 if (get_mp(cpu, mp, &c->counter[i])) in get_counters()
2227 return -10; in get_counters()
2231 if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) in get_counters()
2235 if (get_msr(cpu, MSR_PKG_WEIGHTED_CORE_C0_RES, &p->pkg_wtd_core_c0)) in get_counters()
2236 return -10; in get_counters()
2239 if (get_msr(cpu, MSR_PKG_ANY_CORE_C0_RES, &p->pkg_any_core_c0)) in get_counters()
2240 return -11; in get_counters()
2243 if (get_msr(cpu, MSR_PKG_ANY_GFXE_C0_RES, &p->pkg_any_gfxe_c0)) in get_counters()
2244 return -12; in get_counters()
2247 if (get_msr(cpu, MSR_PKG_BOTH_CORE_GFXE_C0_RES, &p->pkg_both_core_gfxe_c0)) in get_counters()
2248 return -13; in get_counters()
2251 if (get_msr(cpu, MSR_PKG_C3_RESIDENCY, &p->pc3)) in get_counters()
2252 return -9; in get_counters()
2255 if (get_msr(cpu, MSR_ATOM_PKG_C6_RESIDENCY, &p->pc6)) in get_counters()
2256 return -10; in get_counters()
2258 if (get_msr(cpu, MSR_PKG_C6_RESIDENCY, &p->pc6)) in get_counters()
2259 return -10; in get_counters()
2264 if (get_msr(cpu, MSR_PKG_C2_RESIDENCY, &p->pc2)) in get_counters()
2265 return -11; in get_counters()
2267 if (get_msr(cpu, MSR_PKG_C7_RESIDENCY, &p->pc7)) in get_counters()
2268 return -12; in get_counters()
2270 if (get_msr(cpu, MSR_PKG_C8_RESIDENCY, &p->pc8)) in get_counters()
2271 return -13; in get_counters()
2273 if (get_msr(cpu, MSR_PKG_C9_RESIDENCY, &p->pc9)) in get_counters()
2274 return -13; in get_counters()
2276 if (get_msr(cpu, MSR_PKG_C10_RESIDENCY, &p->pc10)) in get_counters()
2277 return -13; in get_counters()
2280 p->cpu_lpi = cpuidle_cur_cpu_lpi_us; in get_counters()
2282 p->sys_lpi = cpuidle_cur_sys_lpi_us; in get_counters()
2286 return -13; in get_counters()
2287 p->energy_pkg = msr; in get_counters()
2291 return -14; in get_counters()
2292 p->energy_cores = msr; in get_counters()
2296 return -15; in get_counters()
2297 p->energy_dram = msr; in get_counters()
2301 return -16; in get_counters()
2302 p->energy_gfx = msr; in get_counters()
2306 return -16; in get_counters()
2307 p->rapl_pkg_perf_status = msr; in get_counters()
2311 return -16; in get_counters()
2312 p->rapl_dram_perf_status = msr; in get_counters()
2316 return -13; in get_counters()
2317 p->energy_pkg = msr; in get_counters()
2321 return -17; in get_counters()
2322 p->pkg_temp_c = tj_max - ((msr >> 16) & 0x7F); in get_counters()
2326 p->gfx_rc6_ms = gfx_cur_rc6_ms; in get_counters()
2330 p->uncore_mhz = get_uncore_mhz(p->package_id, 0); in get_counters()
2333 p->gfx_mhz = gfx_cur_mhz; in get_counters()
2336 p->gfx_act_mhz = gfx_act_mhz; in get_counters()
2338 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in get_counters()
2339 if (get_mp(cpu, mp, &p->counter[i])) in get_counters()
2340 return -10; in get_counters()
2343 gettimeofday(&t->tv_end, (struct timezone *)NULL); in get_counters()
2444 fprintf(outf, "cpu%d: MSR_IA32_POWER_CTL: 0x%08llx (C1E auto-promotion: %sabled)\n", in dump_nhm_platform_info()
2447 /* C-state Pre-wake Disable (CSTATE_PREWAKE_DISABLE) */ in dump_nhm_platform_info()
2449 fprintf(outf, "C-state Pre-wake: %sabled\n", msr & 0x40000000 ? "DIS" : "EN"); in dump_nhm_platform_info()
2554 for (shift = 56; shift >= 0; shift -= 8) { in dump_turbo_ratio_limits()
2623 * [0] -- Reserved in dump_knl_turbo_ratio_limits()
2624 * [7:1] -- Base value of number of active cores of bucket 1. in dump_knl_turbo_ratio_limits()
2625 * [15:8] -- Base value of freq ratio of bucket 1. in dump_knl_turbo_ratio_limits()
2626 * [20:16] -- +ve delta of number of active cores of bucket 2. in dump_knl_turbo_ratio_limits()
2629 * [23:21] -- Negative delta of freq ratio of bucket 2. in dump_knl_turbo_ratio_limits()
2631 * freq ratio of bucket 1 - delta in dump_knl_turbo_ratio_limits()
2632 * [28:24]-- +ve delta of number of active cores of bucket 3. in dump_knl_turbo_ratio_limits()
2633 * [31:29]-- -ve delta of freq ratio of bucket 3. in dump_knl_turbo_ratio_limits()
2634 * [36:32]-- +ve delta of number of active cores of bucket 4. in dump_knl_turbo_ratio_limits()
2635 * [39:37]-- -ve delta of freq ratio of bucket 4. in dump_knl_turbo_ratio_limits()
2636 * [44:40]-- +ve delta of number of active cores of bucket 5. in dump_knl_turbo_ratio_limits()
2637 * [47:45]-- -ve delta of freq ratio of bucket 5. in dump_knl_turbo_ratio_limits()
2638 * [52:48]-- +ve delta of number of active cores of bucket 6. in dump_knl_turbo_ratio_limits()
2639 * [55:53]-- -ve delta of freq ratio of bucket 6. in dump_knl_turbo_ratio_limits()
2640 * [60:56]-- +ve delta of number of active cores of bucket 7. in dump_knl_turbo_ratio_limits()
2641 * [63:61]-- -ve delta of freq ratio of bucket 7. in dump_knl_turbo_ratio_limits()
2653 ratio[b_nr + 1] = ratio[b_nr] - delta_ratio; in dump_knl_turbo_ratio_limits()
2657 for (i = buckets_no - 1; i >= 0; i--) in dump_knl_turbo_ratio_limits()
2658 if (i > 0 ? ratio[i] != ratio[i - 1] : 1) in dump_knl_turbo_ratio_limits()
2672 fprintf(outf, " (%s%s%s%s%slocked, pkg-cstate-limit=%d (%s)", in dump_nhm_cst_cfg()
2673 (msr & SNB_C3_AUTO_UNDEMOTE) ? "UNdemote-C3, " : "", in dump_nhm_cst_cfg()
2674 (msr & SNB_C1_AUTO_UNDEMOTE) ? "UNdemote-C1, " : "", in dump_nhm_cst_cfg()
2675 (msr & NHM_C3_AUTO_DEMOTE) ? "demote-C3, " : "", in dump_nhm_cst_cfg()
2676 (msr & NHM_C1_AUTO_DEMOTE) ? "demote-C1, " : "", in dump_nhm_cst_cfg()
2681 …fprintf(outf, ", automatic c-state conversion=%s", (msr & AUTOMATIC_CSTATE_CONVERSION) ? "on" : "o… in dump_nhm_cst_cfg()
2883 cpus[cpu].logical_node_id = -1; in set_node_data()
2892 if (cpus[cpu].logical_node_id != -1) in set_node_data()
2921 int cpu = thiscpu->logical_cpu_id; in get_physical_node_id()
2931 return -1; in get_physical_node_id()
2940 int cpu = thiscpu->logical_cpu_id; in get_thread_siblings()
2945 thiscpu->put_ids = CPU_ALLOC((topo.max_cpu_num + 1)); in get_thread_siblings()
2946 if (thiscpu->thread_id < 0) in get_thread_siblings()
2947 thiscpu->thread_id = thread_id++; in get_thread_siblings()
2948 if (!thiscpu->put_ids) in get_thread_siblings()
2949 return -1; in get_thread_siblings()
2952 CPU_ZERO_S(size, thiscpu->put_ids); in get_thread_siblings()
2959 return -1; in get_thread_siblings()
2962 offset -= BITMASK_SIZE; in get_thread_siblings()
2969 if (sib_core == thiscpu->physical_core_id) { in get_thread_siblings()
2970 CPU_SET_S(so, size, thiscpu->put_ids); in get_thread_siblings()
2979 return CPU_COUNT_S(size, thiscpu->put_ids); in get_thread_siblings()
2984 * skip non-present cpus
3005 if (cpu_is_not_present(t->cpu_id)) in for_all_cpus_2()
3061 fprintf(outf, "turbostat: re-initialized with num_cpus %d\n", topo.num_cpus); in re_initialize()
3081 topo.max_cpu_num--; /* 0 based */ in set_max_cpu_num()
3104 cpus[cpu].thread_id = -1; in init_thread_id()
3267 return -1; in snapshot_cpu_lpi_us()
3292 return -1; in snapshot_sys_lpi_us()
3390 rest.tv_nsec = (tout.tv_usec % 1000000) * 1000; in do_sleep()
3407 /* get_msr_sum() = sum + (get_msr() - last) */ in get_msr_sum()
3424 int cpu = t->cpu_id; in update_msr_sum()
3478 if (timer_create(CLOCK_REALTIME, &sev, &timerid) == -1) { in msr_sum_record()
3494 if (timer_settime(timerid, 0, &its, NULL) == -1) { in msr_sum_record()
3517 if (errno && (original_priority == -1)) in set_my_sched_priority()
3543 set_my_sched_priority(-20); in turbostat_loop()
3551 if (retval < -1) { in turbostat_loop()
3553 } else if (retval == -1) { in turbostat_loop()
3573 if (retval < -1) { in turbostat_loop()
3575 } else if (retval == -1) { in turbostat_loop()
3596 if (retval < -1) { in turbostat_loop()
3598 } else if (retval == -1) { in turbostat_loop()
3626 err(-5, "no /dev/cpu/0/msr, Try \"# modprobe msr\" "); in check_dev_msr()
3641 err(-6, "cap_get_proc\n"); in check_for_cap_sys_rawio()
3644 err(-6, "cap_get\n"); in check_for_cap_sys_rawio()
3651 if (cap_free(caps) == -1) in check_for_cap_sys_rawio()
3652 err(-6, "cap_free\n"); in check_for_cap_sys_rawio()
3678 exit(-6); in check_permissions()
3715 case INTEL_FAM6_NEHALEM: /* Core i7 and i5 Processor - Clarksfield, Lynnfield, Jasper Forest */ in probe_nhm_msrs()
3716 case INTEL_FAM6_NEHALEM_EX: /* Nehalem-EX Xeon - Beckton */ in probe_nhm_msrs()
3924 /* Nehalem compatible, but do not include turbo-ratio limit support */ in has_turbo_ratio_limit()
3925 case INTEL_FAM6_NEHALEM_EX: /* Nehalem-EX Xeon - Beckton */ in has_turbo_ratio_limit()
3926 case INTEL_FAM6_XEON_PHI_KNL: /* PHI - Knights Landing (different MSR definition) */ in has_turbo_ratio_limit()
4126 int retval = -1; in read_sysfs_int()
4132 return (-1); in read_sysfs_int()
4186 fprintf(outf, "Uncore Frequency pkg%d die%d: %d - %d MHz ", i, j, k / 1000, l / 1000); in intel_uncore_frequency_probe()
4196 fprintf(outf, "(%d - %d MHz)\n", k / 1000, l / 1000); in intel_uncore_frequency_probe()
4228 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ in dump_sysfs_cstate_config()
4229 sp = strchr(name_buf, '-'); in dump_sysfs_cstate_config()
4314 cpu = t->cpu_id; in print_epb()
4316 /* EPB is per-package */ in print_epb()
4317 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) in print_epb()
4322 return -1; in print_epb()
4363 cpu = t->cpu_id; in print_hwp()
4365 /* MSR_HWP_CAPABILITIES is per-package */ in print_hwp()
4366 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) in print_hwp()
4371 return -1; in print_hwp()
4377 fprintf(outf, "cpu%d: MSR_PM_ENABLE: 0x%08llx (%sHWP)\n", cpu, msr, (msr & (1 << 0)) ? "" : "No-"); in print_hwp()
4430 cpu, msr, ((msr) & 0x1) ? "" : "No-", ((msr) & 0x4) ? "" : "No-"); in print_hwp()
4446 cpu = t->cpu_id; in print_perf_limit()
4448 /* per-package */ in print_perf_limit()
4449 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) in print_perf_limit()
4454 return -1; in print_perf_limit()
4469 (msr & 1 << 6) ? "VR-Therm, " : "", in print_perf_limit()
4470 (msr & 1 << 5) ? "Auto-HWP, " : "", in print_perf_limit()
4483 (msr & 1 << 22) ? "VR-Therm, " : "", in print_perf_limit()
4484 (msr & 1 << 21) ? "Auto-HWP, " : "", in print_perf_limit()
4497 (msr & 1 << 6) ? "VR-Therm, " : "", in print_perf_limit()
4505 (msr & 1 << 22) ? "VR-Therm, " : "", in print_perf_limit()
4516 (msr & 1 << 6) ? "VR-Therm, " : "", in print_perf_limit()
4522 (msr & 1 << 22) ? "VR-Therm, " : "", in print_perf_limit()
4559 * Energy units are either hard-coded, or come from RAPL Energy Unit MSR.
4751 unsigned int eax, ebx, ecx, edx; in rapl_probe_amd() local
4758 __cpuid(0x80000007, eax, ebx, ecx, edx); in rapl_probe_amd()
4778 rapl_time_units = ldexp(1.0, -(msr >> 16 & 0xf)); in rapl_probe_amd()
4779 rapl_energy_units = ldexp(1.0, -(msr >> 8 & 0x1f)); in rapl_probe_amd()
4780 rapl_power_units = ldexp(1.0, -(msr & 0xf)); in rapl_probe_amd()
4854 cpu = t->cpu_id; in print_thermal()
4856 /* DTS is per-core, no need to print for each thread */ in print_thermal()
4857 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) in print_thermal()
4862 return -1; in print_thermal()
4865 if (do_ptm && (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) { in print_thermal()
4870 fprintf(outf, "cpu%d: MSR_IA32_PACKAGE_THERM_STATUS: 0x%08llx (%d C)\n", cpu, msr, tj_max - dts); in print_thermal()
4878 cpu, msr, tj_max - dts, tj_max - dts2); in print_thermal()
4889 fprintf(outf, "cpu%d: MSR_IA32_THERM_STATUS: 0x%08llx (%d C +/- %d)\n", in print_thermal()
4890 cpu, msr, tj_max - dts, resolution); in print_thermal()
4898 cpu, msr, tj_max - dts, tj_max - dts2); in print_thermal()
4929 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) in print_rapl()
4932 cpu = t->cpu_id; in print_rapl()
4935 return -1; in print_rapl()
4941 return -1; in print_rapl()
4945 return -1; in print_rapl()
4954 return -5; in print_rapl()
4956 fprintf(outf, "cpu%d: MSR_PKG_POWER_INFO: 0x%08llx (%.0f W TDP, RAPL %.0f - %.0f W, %f sec.)\n", in print_rapl()
4967 return -9; in print_rapl()
4981 return -9; in print_rapl()
4990 return -6; in print_rapl()
4992 fprintf(outf, "cpu%d: MSR_DRAM_POWER_INFO,: 0x%08llx (%.0f W TDP, RAPL %.0f - %.0f W, %f sec.)\n", in print_rapl()
5001 return -9; in print_rapl()
5009 return -7; in print_rapl()
5015 return -9; in print_rapl()
5022 return -8; in print_rapl()
5027 return -9; in print_rapl()
5226 unsigned int eax, ebx, ecx, edx; in get_cpu_type() local
5234 if (cpu_migrate(t->cpu_id)) { in get_cpu_type()
5235 fprintf(outf, "Could not migrate to CPU %d\n", t->cpu_id); in get_cpu_type()
5236 return -1; in get_cpu_type()
5242 __cpuid(0x1a, eax, ebx, ecx, edx); in get_cpu_type()
5245 t->is_atom = true; in get_cpu_type()
5255 * but also allow cmdline over-ride with -T.
5257 * Several MSR temperature values are in units of degrees-C
5274 /* this is a per-package concept */ in set_temperature_target()
5275 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) in set_temperature_target()
5278 cpu = t->cpu_id; in set_temperature_target()
5281 return -1; in set_temperature_target()
5303 fprintf(outf, "cpu%d: MSR_IA32_TEMPERATURE_TARGET: 0x%08llx (%d C) (%d default - %d offset)\n", in set_temperature_target()
5304 cpu, msr, tcc_default - tcc_offset, tcc_default, tcc_offset); in set_temperature_target()
5308 fprintf(outf, "cpu%d: MSR_IA32_TEMPERATURE_TARGET: 0x%08llx (%d C) (%d default - %d offset)\n", in set_temperature_target()
5309 cpu, msr, tcc_default - tcc_offset, tcc_default, tcc_offset); in set_temperature_target()
5326 fprintf(outf, "cpu%d: Guessing tjMax %d C, Please use -T to specify\n", cpu, tj_max); in set_temperature_target()
5337 base_cpu, msr, msr & FEAT_CTL_LOCKED ? "" : "UN-", msr & (1 << 18) ? "SGX" : ""); in decode_feature_control_msr()
5350 msr & MSR_IA32_MISC_ENABLE_TM1 ? "" : "No-", in decode_misc_enable_msr()
5351 msr & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP ? "" : "No-", in decode_misc_enable_msr()
5352 msr & MSR_IA32_MISC_ENABLE_MWAIT ? "" : "No-", in decode_misc_enable_msr()
5353 msr & MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE ? "No-" : "", in decode_misc_enable_msr()
5354 msr & MSR_IA32_MISC_ENABLE_TURBO_DISABLE ? "No-" : ""); in decode_misc_enable_msr()
5366 …"cpu%d: MSR_MISC_FEATURE_CONTROL: 0x%08llx (%sL2-Prefetch %sL2-Prefetch-pair %sL1-Prefetch %sL1-IP… in decode_misc_feature_control()
5367 base_cpu, msr, msr & (0 << 0) ? "No-" : "", msr & (1 << 0) ? "No-" : "", in decode_misc_feature_control()
5368 msr & (2 << 0) ? "No-" : "", msr & (3 << 0) ? "No-" : ""); in decode_misc_feature_control()
5389 …fprintf(outf, "cpu%d: MSR_MISC_PWR_MGMT: 0x%08llx (%sable-EIST_Coordination %sable-EPB %sable-OOB)… in decode_misc_pwr_mgmt_msr()
5405 fprintf(outf, "cpu%d: MSR_CC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-CC6-Demotion)\n", in decode_c6_demotion_policy_msr()
5409 fprintf(outf, "cpu%d: MSR_MC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-MC6-Demotion)\n", in decode_c6_demotion_policy_msr()
5420 case INTEL_FAM6_NEHALEM_EP: /* Core i7, Xeon 5500 series - Bloomfield, Gainstown NHM-EP */ in intel_model_duplicates()
5421 case INTEL_FAM6_NEHALEM: /* Core i7 and i5 Processor - Clarksfield, Lynnfield, Jasper Forest */ in intel_model_duplicates()
5422 case 0x1F: /* Core i7 and i5 Processor - Nehalem */ in intel_model_duplicates()
5423 case INTEL_FAM6_WESTMERE: /* Westmere Client - Clarkdale, Arrandale */ in intel_model_duplicates()
5424 case INTEL_FAM6_WESTMERE_EP: /* Westmere EP - Gulftown */ in intel_model_duplicates()
5427 case INTEL_FAM6_NEHALEM_EX: /* Nehalem-EX Xeon - Beckton */ in intel_model_duplicates()
5428 case INTEL_FAM6_WESTMERE_EX: /* Westmere-EX Xeon - Eagleton */ in intel_model_duplicates()
5435 case INTEL_FAM6_BROADWELL_D: /* BDX-DE */ in intel_model_duplicates()
5500 * Linux-perf manages the HW instructions-retired counter
5513 err(-1, "calloc fd_instr_count_percpu"); in linux_perf_init()
5520 unsigned int eax, ebx, ecx, edx; in process_cpuid() local
5525 eax = ebx = ecx = edx = 0; in process_cpuid()
5527 __cpuid(0, max_level, ebx, ecx, edx); in process_cpuid()
5529 if (ebx == 0x756e6547 && ecx == 0x6c65746e && edx == 0x49656e69) in process_cpuid()
5531 else if (ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65) in process_cpuid()
5533 else if (ebx == 0x6f677948 && ecx == 0x656e6975 && edx == 0x6e65476e) in process_cpuid()
5538 (char *)&ebx, (char *)&edx, (char *)&ecx, max_level); in process_cpuid()
5540 __cpuid(1, fms, ebx, ecx, edx); in process_cpuid()
5548 ecx_flags = ecx; in process_cpuid()
5561 ebx = ecx = edx = 0; in process_cpuid()
5562 __cpuid(0x80000000, max_extended_level, ebx, ecx, edx); in process_cpuid()
5573 ecx_flags & (1 << 0) ? "SSE3" : "-", in process_cpuid()
5574 ecx_flags & (1 << 3) ? "MONITOR" : "-", in process_cpuid()
5575 ecx_flags & (1 << 6) ? "SMX" : "-", in process_cpuid()
5576 ecx_flags & (1 << 7) ? "EIST" : "-", in process_cpuid()
5577 ecx_flags & (1 << 8) ? "TM2" : "-", in process_cpuid()
5578 edx_flags & (1 << 4) ? "TSC" : "-", in process_cpuid()
5579 edx_flags & (1 << 5) ? "MSR" : "-", in process_cpuid()
5580 edx_flags & (1 << 22) ? "ACPI-TM" : "-", in process_cpuid()
5581 edx_flags & (1 << 28) ? "HT" : "-", edx_flags & (1 << 29) ? "TM" : "-"); in process_cpuid()
5594 * Non-Stop TSC is advertised by CPUID.EAX=0x80000007: EDX.bit8 in process_cpuid()
5597 __cpuid(0x80000007, eax, ebx, ecx, edx); in process_cpuid()
5602 * APERF/MPERF is advertised by CPUID.EAX=0x6: ECX.bit0 in process_cpuid()
5606 __cpuid(0x6, eax, ebx, ecx, edx); in process_cpuid()
5607 has_aperf = ecx & (1 << 0); in process_cpuid()
5625 has_epb = ecx & (1 << 3); in process_cpuid()
5630 has_aperf ? "" : "No-", in process_cpuid()
5631 has_turbo ? "" : "No-", in process_cpuid()
5632 do_dts ? "" : "No-", in process_cpuid()
5633 do_ptm ? "" : "No-", in process_cpuid()
5634 has_hwp ? "" : "No-", in process_cpuid()
5635 has_hwp_notify ? "" : "No-", in process_cpuid()
5636 has_hwp_activity_window ? "" : "No-", in process_cpuid()
5637 has_hwp_epp ? "" : "No-", has_hwp_pkg ? "" : "No-", has_epb ? "" : "No-"); in process_cpuid()
5645 ecx = 0; in process_cpuid()
5647 __cpuid_count(0x7, 0, eax, ebx, ecx, edx); in process_cpuid()
5653 fprintf(outf, "CPUID(7): %sSGX %sHybrid\n", has_sgx ? "" : "No-", is_hybrid ? "" : "No-"); in process_cpuid()
5864 if (isdigit(dirp->d_name[0])) in dir_filter()
6017 (*t)[i].cpu_id = -1; in allocate_counters()
6024 (*c)[i].core_id = -1; in allocate_counters()
6053 /* Workaround for systems where physical_node_id==-1 in init_counter()
6054 * and logical_node_id==(-1 - topo.num_cpus) in init_counter()
6063 t->cpu_id = cpu_id; in init_counter()
6065 t->flags |= CPU_IS_FIRST_THREAD_IN_CORE; in init_counter()
6067 t->flags |= CPU_IS_FIRST_CORE_IN_PACKAGE; in init_counter()
6070 c->core_id = core_id; in init_counter()
6071 p->package_id = pkg_id; in init_counter()
6086 err(-1, "calloc output buffer"); in allocate_output_buffer()
6093 err(-1, "calloc fd_percpu"); in allocate_fd_percpu()
6100 err(-1, "calloc %d", topo.num_cpus); in allocate_irq_buffers()
6104 err(-1, "calloc %d", topo.max_cpu_num + 1); in allocate_irq_buffers()
6122 err(-ENODEV, "No valid cpus found"); in set_base_cpu()
6174 /* clear affinity side-effect of get_counters() */ in fork_it()
6186 if (child_pid == -1) in fork_it()
6191 if (waitpid(child_pid, &status, 0) == -1) in fork_it()
6199 * because re-starting is problematic when forking in fork_it()
6239 fprintf(outf, "turbostat version 2023.03.17 - Len Brown <lenb@kernel.org>\n"); in print_version()
6255 ret = fread(bootcmd, sizeof(char), COMMAND_LINE_SIZE - 1, fp); in print_bootcmd()
6277 msrp->msr_num = msr_num; in add_counter()
6278 strncpy(msrp->name, name, NAME_BYTES - 1); in add_counter()
6280 strncpy(msrp->path, path, PATH_BYTES - 1); in add_counter()
6281 msrp->width = width; in add_counter()
6282 msrp->type = type; in add_counter()
6283 msrp->format = format; in add_counter()
6284 msrp->flags = flags; in add_counter()
6289 msrp->next = sys.tp; in add_counter()
6294 exit(-1); in add_counter()
6299 msrp->next = sys.cp; in add_counter()
6304 exit(-1); in add_counter()
6309 msrp->next = sys.pp; in add_counter()
6314 exit(-1); in add_counter()
6406 fprintf(stderr, "--add: (msrDDD | msr0xXXX | /path_to_counter ) required\n"); in parse_add_command()
6455 for (state = 10; state >= 0; --state) { in probe_sysfs()
6464 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ in probe_sysfs()
6465 sp = strchr(name_buf, '-'); in probe_sysfs()
6486 for (state = 10; state >= 0; --state) { in probe_sysfs()
6494 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ in probe_sysfs()
6495 sp = strchr(name_buf, '-'); in probe_sysfs()
6518 * 1,2,4..6,8-10 and set bits in cpu_subset
6551 if (*next == '-') /* no negative cpu numbers */ in parse_cpu_command()
6568 if (*next == '-') { in parse_cpu_command()
6597 fprintf(stderr, "\"--cpu %s\" malformed\n", optarg); in parse_cpu_command()
6599 exit(-1); in parse_cpu_command()
6617 { "hide", required_argument, 0, 'H' }, // meh, -h taken by --help in cmdline()
6631 …opt = getopt_long_only(argc, argv, "+C:c:Dde:hi:Jn:o:qST:v", long_options, &option_index)) != -1) { in cmdline()
6643 /* --enable specified counter */ in cmdline()
6652 * --hide: do not show those specified in cmdline()
6671 interval_tv.tv_usec = (interval - interval_tv.tv_sec) * 1000000; in cmdline()
6672 interval_ts.tv_nsec = (interval - interval_ts.tv_sec) * 1000000000; in cmdline()
6707 * --show: show only those specified in cmdline()
6780 if (argc - optind) in main()