Lines Matching +full:operating +full:- +full:range +full:- +full:celsius
1 // SPDX-License-Identifier: GPL-2.0-only
3 * turbostat -- show CPU frequency and C-state residency
19 #define VFM_MODEL_MASK GENMASK(VFM_FAMILY_BIT - 1, VFM_MODEL_BIT)
20 #define VFM_FAMILY_MASK GENMASK(VFM_VENDOR_BIT - 1, VFM_FAMILY_BIT)
21 #define VFM_VENDOR_MASK GENMASK(VFM_RSVD_BIT - 1, VFM_VENDOR_BIT)
72 * 1. built-in only, the sysfs counters are not here -- we learn of those at run-time
74 * matching on them for --show and --hide.
79 * Usually truncated to 7 characters, but also handles 18 columns for raw 64-bit counters
410 …bool has_per_core_rapl; /* Indicates cores energy collection is per-core, not per-package. AMD spe…
1071 /* MSRs that are not yet in the kernel-provided header. */
1141 …double compat_scale; /* Some counters require constant scaling to be in the same range as other, s…
1149 .perf_name = "energy-pkg",
1162 .perf_name = "energy-pkg",
1175 .perf_name = "energy-cores",
1188 .perf_name = "energy-ram",
1201 .perf_name = "energy-gpu",
1304 .perf_name = "c1-residency",
1314 .perf_name = "c3-residency",
1324 .perf_name = "c6-residency",
1334 .perf_name = "c7-residency",
1344 .perf_name = "c2-residency",
1354 .perf_name = "c3-residency",
1364 .perf_name = "c6-residency",
1374 .perf_name = "c7-residency",
1384 .perf_name = "c8-residency",
1394 .perf_name = "c9-residency",
1404 .perf_name = "c10-residency",
1528 /* BIC-like metadata */
1537 return (p->msb - p->lsb) + 1; in pmt_counter_get_width()
1544 …new_mem = (struct pmt_domain_info *)reallocarray(pcounter->domains, new_size, sizeof(*pcounter->do… in pmt_counter_resize_()
1551 const size_t num_new_domains = new_size - pcounter->num_domains; in pmt_counter_resize_()
1553 memset(&new_mem[pcounter->num_domains], 0, num_new_domains * sizeof(*pcounter->domains)); in pmt_counter_resize_()
1555 pcounter->num_domains = new_size; in pmt_counter_resize_()
1556 pcounter->domains = new_mem; in pmt_counter_resize_()
1569 new_size = MAX(new_size, pcounter->num_domains * 2); in pmt_counter_resize()
1600 unsigned long long mc6_us; /* duplicate as per-core for now, even though per module */
1683 /* get_msr_sum() = sum + (get_msr() - last) */
1701 if (platform->rapl_msrs & RAPL_AMD_F17H) in idx_to_offset()
1722 offset = -1; in idx_to_offset()
1752 idx = -1; in offset_to_idx()
1761 return platform->rapl_msrs & (RAPL_PKG | RAPL_AMD_F17H); in idx_valid()
1763 return platform->rapl_msrs & RAPL_DRAM; in idx_valid()
1765 return platform->rapl_msrs & RAPL_CORE_ENERGY_STATUS; in idx_valid()
1767 return platform->rapl_msrs & RAPL_GFX; in idx_valid()
1769 return platform->rapl_msrs & RAPL_PKG_PERF_STATUS; in idx_valid()
1771 return platform->rapl_msrs & RAPL_DRAM_PERF_STATUS; in idx_valid()
1807 if (p->msr_num != 0) { in free_msr_counters_()
1808 *pp = p->next; in free_msr_counters_()
1816 pp = &p->next; in free_msr_counters_()
1828 sys.added_thread_counters -= free_msr_counters_(&sys.tp); in free_sys_msr_counters()
1831 sys.added_core_counters -= free_msr_counters_(&sys.cp); in free_sys_msr_counters()
1834 sys.added_package_counters -= free_msr_counters_(&sys.pp); in free_sys_msr_counters()
1848 int logical_node_id; /* 0-based count within the package */
1895 * skip non-present cpus
1912 if (cpu_is_not_allowed(t->cpu_id)) in for_all_cpus()
1932 return ((int)t->cpu_id == c->base_cpu || c->base_cpu < 0); in is_cpu_first_thread_in_core()
1939 return ((int)t->cpu_id == p->base_cpu || p->base_cpu < 0); in is_cpu_first_core_in_package()
1951 if (sched_setaffinity(0, cpu_affinity_setsize, cpu_affinity_set) == -1) in cpu_migrate()
1952 return -1; in cpu_migrate()
1970 err(-1, "%s open failed, try chown or chmod +r /dev/cpu/*/msr, " in get_msr_fd()
1971 "or run with --no-msr, or run as root", pathname); in get_msr_fd()
1998 const pid_t pid = -1; in open_perf_counter()
2022 …_count_percpu[cpu] = open_perf_counter(cpu, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, -1, 0); in get_instr_count_fd()
2036 err(-1, "cpu%d: msr offset 0x%llx read failed", cpu, (unsigned long long)offset); in get_msr()
2059 switch (pc->scope) { in cpu_to_domain()
2080 * HIDE_LIST - hide this list of counters, show the rest [default]
2081 * SHOW_LIST - show this list of counters, hide the rest
2088 "Usage: turbostat [OPTIONS][(--interval seconds) | COMMAND ...]\n" in help()
2092 "If no COMMAND is specified, turbostat wakes every 5-seconds\n" in help()
2094 " -a, --add add a counter\n" in help()
2095 " eg. --add msr0x10,u64,cpu,delta,MY_TSC\n" in help()
2096 " eg. --add perf/cstate_pkg/c2-residency,package,delta,percent,perfPC2\n" in help()
2097 " eg. --add pmt,name=XTAL,type=raw,domain=package0,offset=0,lsb=0,msb=63,guid=0x1a067102\n" in help()
2098 " -c, --cpu cpu-set limit output to summary plus cpu-set:\n" in help()
2099 " {core | package | j,k,l..m,n-p }\n" in help()
2100 " -d, --debug displays usec, Time_Of_Day_Seconds and more debugging\n" in help()
2102 " -D, --Dump displays the raw counter values\n" in help()
2103 " -e, --enable [all | column]\n" in help()
2105 " -H, --hide [column|column,column,...]\n" in help()
2107 " -i, --interval sec.subsec\n" in help()
2108 " Override default 5-second measurement interval\n" in help()
2109 " -J, --Joules displays energy in Joules instead of Watts\n" in help()
2110 " -l, --list list column headers only\n" in help()
2111 " -M, --no-msr Disable all uses of the MSR driver\n" in help()
2112 " -P, --no-perf Disable all uses of the perf API\n" in help()
2113 " -n, --num_iterations num\n" in help()
2115 " -N, --header_iterations num\n" in help()
2117 " -o, --out file\n" in help()
2119 " -q, --quiet skip decoding system configuration header\n" in help()
2120 " -s, --show [column|column,column,...]\n" in help()
2122 " -S, --Summary\n" in help()
2123 " limits output to 1-line system summary per interval\n" in help()
2124 " -T, --TCC temperature\n" in help()
2126 " degrees Celsius\n" in help()
2127 " -h, --help print this help message\n" in help()
2128 " -v, --version print version information\n" "\n" "For more help, run \"man turbostat\"\n"); in help()
2179 fprintf(stderr, "More than max %d un-recognized --add options '%s'\n", in bic_lookup()
2189 fprintf(stderr, "More than max %d un-recognized --skip options '%s'\n", in bic_lookup()
2252 for (mp = sys.tp; mp; mp = mp->next) { in print_header()
2254 if (mp->format == FORMAT_RAW) { in print_header()
2255 if (mp->width == 64) in print_header()
2256 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), mp->name); in print_header()
2258 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), mp->name); in print_header()
2260 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in print_header()
2261 outp += sprintf(outp, "%s%8s", (printed++ ? delim : ""), mp->name); in print_header()
2263 outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), mp->name); in print_header()
2267 for (pp = sys.perf_tp; pp; pp = pp->next) { in print_header()
2269 if (pp->format == FORMAT_RAW) { in print_header()
2270 if (pp->width == 64) in print_header()
2271 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), pp->name); in print_header()
2273 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), pp->name); in print_header()
2275 if ((pp->type == COUNTER_ITEMS) && sums_need_wide_columns) in print_header()
2276 outp += sprintf(outp, "%s%8s", (printed++ ? delim : ""), pp->name); in print_header()
2278 outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), pp->name); in print_header()
2284 switch (ppmt->type) { in print_header()
2287 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), ppmt->name); in print_header()
2289 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), ppmt->name); in print_header()
2294 outp += sprintf(outp, "%s%s", delim, ppmt->name); in print_header()
2298 ppmt = ppmt->next; in print_header()
2319 if (platform->rapl_msrs && !rapl_joules) { in print_header()
2320 if (DO_BIC(BIC_CorWatt) && platform->has_per_core_rapl) in print_header()
2322 } else if (platform->rapl_msrs && rapl_joules) { in print_header()
2323 if (DO_BIC(BIC_Cor_J) && platform->has_per_core_rapl) in print_header()
2327 for (mp = sys.cp; mp; mp = mp->next) { in print_header()
2328 if (mp->format == FORMAT_RAW) { in print_header()
2329 if (mp->width == 64) in print_header()
2330 outp += sprintf(outp, "%s%18.18s", delim, mp->name); in print_header()
2332 outp += sprintf(outp, "%s%10.10s", delim, mp->name); in print_header()
2334 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in print_header()
2335 outp += sprintf(outp, "%s%8s", delim, mp->name); in print_header()
2337 outp += sprintf(outp, "%s%s", delim, mp->name); in print_header()
2341 for (pp = sys.perf_cp; pp; pp = pp->next) { in print_header()
2343 if (pp->format == FORMAT_RAW) { in print_header()
2344 if (pp->width == 64) in print_header()
2345 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), pp->name); in print_header()
2347 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), pp->name); in print_header()
2349 if ((pp->type == COUNTER_ITEMS) && sums_need_wide_columns) in print_header()
2350 outp += sprintf(outp, "%s%8s", (printed++ ? delim : ""), pp->name); in print_header()
2352 outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), pp->name); in print_header()
2358 switch (ppmt->type) { in print_header()
2361 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), ppmt->name); in print_header()
2363 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), ppmt->name); in print_header()
2368 outp += sprintf(outp, "%s%s", delim, ppmt->name); in print_header()
2372 ppmt = ppmt->next; in print_header()
2426 if (platform->rapl_msrs && !rapl_joules) { in print_header()
2429 if (DO_BIC(BIC_CorWatt) && !platform->has_per_core_rapl) in print_header()
2439 } else if (platform->rapl_msrs && rapl_joules) { in print_header()
2442 if (DO_BIC(BIC_Cor_J) && !platform->has_per_core_rapl) in print_header()
2456 for (mp = sys.pp; mp; mp = mp->next) { in print_header()
2457 if (mp->format == FORMAT_RAW) { in print_header()
2458 if (mp->width == 64) in print_header()
2459 outp += sprintf(outp, "%s%18.18s", delim, mp->name); in print_header()
2460 else if (mp->width == 32) in print_header()
2461 outp += sprintf(outp, "%s%10.10s", delim, mp->name); in print_header()
2463 outp += sprintf(outp, "%s%7.7s", delim, mp->name); in print_header()
2465 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in print_header()
2466 outp += sprintf(outp, "%s%8s", delim, mp->name); in print_header()
2468 outp += sprintf(outp, "%s%7.7s", delim, mp->name); in print_header()
2472 for (pp = sys.perf_pp; pp; pp = pp->next) { in print_header()
2474 if (pp->format == FORMAT_RAW) { in print_header()
2475 if (pp->width == 64) in print_header()
2476 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), pp->name); in print_header()
2478 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), pp->name); in print_header()
2480 if ((pp->type == COUNTER_ITEMS) && sums_need_wide_columns) in print_header()
2481 outp += sprintf(outp, "%s%8s", (printed++ ? delim : ""), pp->name); in print_header()
2483 outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), pp->name); in print_header()
2489 switch (ppmt->type) { in print_header()
2492 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), ppmt->name); in print_header()
2494 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), ppmt->name); in print_header()
2499 outp += sprintf(outp, "%s%s", delim, ppmt->name); in print_header()
2503 ppmt = ppmt->next; in print_header()
2517 outp += sprintf(outp, "CPU: %d flags 0x%x\n", t->cpu_id, t->flags); in dump_counters()
2518 outp += sprintf(outp, "TSC: %016llX\n", t->tsc); in dump_counters()
2519 outp += sprintf(outp, "aperf: %016llX\n", t->aperf); in dump_counters()
2520 outp += sprintf(outp, "mperf: %016llX\n", t->mperf); in dump_counters()
2521 outp += sprintf(outp, "c1: %016llX\n", t->c1); in dump_counters()
2524 outp += sprintf(outp, "IPC: %lld\n", t->instr_count); in dump_counters()
2527 outp += sprintf(outp, "IRQ: %lld\n", t->irq_count); in dump_counters()
2529 outp += sprintf(outp, "SMI: %d\n", t->smi_count); in dump_counters()
2531 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in dump_counters()
2533 sprintf(outp, "tADDED [%d] %8s msr0x%x: %08llX %s\n", i, mp->name, mp->msr_num, in dump_counters()
2534 t->counter[i], mp->sp->path); in dump_counters()
2539 outp += sprintf(outp, "core: %d\n", c->core_id); in dump_counters()
2540 outp += sprintf(outp, "c3: %016llX\n", c->c3); in dump_counters()
2541 outp += sprintf(outp, "c6: %016llX\n", c->c6); in dump_counters()
2542 outp += sprintf(outp, "c7: %016llX\n", c->c7); in dump_counters()
2543 outp += sprintf(outp, "DTS: %dC\n", c->core_temp_c); in dump_counters()
2544 outp += sprintf(outp, "cpu_throt_count: %016llX\n", c->core_throt_cnt); in dump_counters()
2546 const unsigned long long energy_value = c->core_energy.raw_value * c->core_energy.scale; in dump_counters()
2547 const double energy_scale = c->core_energy.scale; in dump_counters()
2549 if (c->core_energy.unit == RAPL_UNIT_JOULES) in dump_counters()
2552 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in dump_counters()
2554 sprintf(outp, "cADDED [%d] %8s msr0x%x: %08llX %s\n", i, mp->name, mp->msr_num, in dump_counters()
2555 c->counter[i], mp->sp->path); in dump_counters()
2557 outp += sprintf(outp, "mc6_us: %016llX\n", c->mc6_us); in dump_counters()
2561 outp += sprintf(outp, "package: %d\n", p->package_id); in dump_counters()
2563 outp += sprintf(outp, "Weighted cores: %016llX\n", p->pkg_wtd_core_c0); in dump_counters()
2564 outp += sprintf(outp, "Any cores: %016llX\n", p->pkg_any_core_c0); in dump_counters()
2565 outp += sprintf(outp, "Any GFX: %016llX\n", p->pkg_any_gfxe_c0); in dump_counters()
2566 outp += sprintf(outp, "CPU + GFX: %016llX\n", p->pkg_both_core_gfxe_c0); in dump_counters()
2568 outp += sprintf(outp, "pc2: %016llX\n", p->pc2); in dump_counters()
2570 outp += sprintf(outp, "pc3: %016llX\n", p->pc3); in dump_counters()
2572 outp += sprintf(outp, "pc6: %016llX\n", p->pc6); in dump_counters()
2574 outp += sprintf(outp, "pc7: %016llX\n", p->pc7); in dump_counters()
2575 outp += sprintf(outp, "pc8: %016llX\n", p->pc8); in dump_counters()
2576 outp += sprintf(outp, "pc9: %016llX\n", p->pc9); in dump_counters()
2577 outp += sprintf(outp, "pc10: %016llX\n", p->pc10); in dump_counters()
2578 outp += sprintf(outp, "cpu_lpi: %016llX\n", p->cpu_lpi); in dump_counters()
2579 outp += sprintf(outp, "sys_lpi: %016llX\n", p->sys_lpi); in dump_counters()
2580 outp += sprintf(outp, "Joules PKG: %0llX\n", p->energy_pkg.raw_value); in dump_counters()
2581 outp += sprintf(outp, "Joules COR: %0llX\n", p->energy_cores.raw_value); in dump_counters()
2582 outp += sprintf(outp, "Joules GFX: %0llX\n", p->energy_gfx.raw_value); in dump_counters()
2583 outp += sprintf(outp, "Joules RAM: %0llX\n", p->energy_dram.raw_value); in dump_counters()
2584 outp += sprintf(outp, "Throttle PKG: %0llX\n", p->rapl_pkg_perf_status.raw_value); in dump_counters()
2585 outp += sprintf(outp, "Throttle RAM: %0llX\n", p->rapl_dram_perf_status.raw_value); in dump_counters()
2586 outp += sprintf(outp, "PTM: %dC\n", p->pkg_temp_c); in dump_counters()
2588 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in dump_counters()
2590 sprintf(outp, "pADDED [%d] %8s msr0x%x: %08llX %s\n", i, mp->name, mp->msr_num, in dump_counters()
2591 p->counter[i], mp->sp->path); in dump_counters()
2608 assert(c->unit == RAPL_UNIT_JOULES); in rapl_counter_get_value()
2610 const double scaled = c->raw_value * c->scale; in rapl_counter_get_value()
2639 /*if not summary line and --cpu is used */ in format_counters()
2640 …if ((t != &average.threads) && (cpu_subset && !CPU_ISSET_S(t->cpu_id, cpu_subset_size, cpu_subset)… in format_counters()
2647 timersub(&t->tv_end, &t->tv_begin, &tv); in format_counters()
2653 outp += sprintf(outp, "%10ld.%06ld\t", t->tv_end.tv_sec, t->tv_end.tv_usec); in format_counters()
2655 interval_float = t->tv_delta.tv_sec + t->tv_delta.tv_usec / 1000000.0; in format_counters()
2657 tsc = t->tsc * tsc_tweak; in format_counters()
2662 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2664 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2666 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2668 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2670 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2672 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2674 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2678 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->package_id); in format_counters()
2680 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2684 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), cpus[t->cpu_id].die_id); in format_counters()
2686 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2691 (printed++ ? delim : ""), cpus[t->cpu_id].physical_node_id); in format_counters()
2693 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2697 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), c->core_id); in format_counters()
2699 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2702 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->cpu_id); in format_counters()
2704 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->apic_id); in format_counters()
2706 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->x2apic_id); in format_counters()
2710 …outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), 1.0 / units * t->aperf / interval_float); in format_counters()
2713 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->mperf / tsc); in format_counters()
2718 sprintf(outp, "%s%.0f", (printed++ ? delim : ""), base_hz / units * t->aperf / t->mperf); in format_counters()
2721 tsc / units * t->aperf / t->mperf / interval_float); in format_counters()
2725 outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), 1.0 * t->tsc / units / interval_float); in format_counters()
2728 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 1.0 * t->instr_count / t->aperf); in format_counters()
2733 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), t->irq_count); in format_counters()
2735 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->irq_count); in format_counters()
2740 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->smi_count); in format_counters()
2743 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in format_counters()
2744 if (mp->format == FORMAT_RAW) { in format_counters()
2745 if (mp->width == 32) in format_counters()
2747 sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int)t->counter[i]); in format_counters()
2749 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), t->counter[i]); in format_counters()
2750 } else if (mp->format == FORMAT_DELTA) { in format_counters()
2751 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in format_counters()
2752 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), t->counter[i]); in format_counters()
2754 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->counter[i]); in format_counters()
2755 } else if (mp->format == FORMAT_PERCENT) { in format_counters()
2756 if (mp->type == COUNTER_USEC) in format_counters()
2759 t->counter[i] / interval_float / 10000); in format_counters()
2761 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->counter[i] / tsc); in format_counters()
2766 for (i = 0, pp = sys.perf_tp; pp; ++i, pp = pp->next) { in format_counters()
2767 if (pp->format == FORMAT_RAW) { in format_counters()
2768 if (pp->width == 32) in format_counters()
2771 (unsigned int)t->perf_counter[i]); in format_counters()
2773 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), t->perf_counter[i]); in format_counters()
2774 } else if (pp->format == FORMAT_DELTA) { in format_counters()
2775 if ((pp->type == COUNTER_ITEMS) && sums_need_wide_columns) in format_counters()
2776 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), t->perf_counter[i]); in format_counters()
2778 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->perf_counter[i]); in format_counters()
2779 } else if (pp->format == FORMAT_PERCENT) { in format_counters()
2780 if (pp->type == COUNTER_USEC) in format_counters()
2783 t->perf_counter[i] / interval_float / 10000); in format_counters()
2786 sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->perf_counter[i] / tsc); in format_counters()
2790 for (i = 0, ppmt = sys.pmt_tp; ppmt; i++, ppmt = ppmt->next) { in format_counters()
2791 switch (ppmt->type) { in format_counters()
2795 (unsigned int)t->pmt_counter[i]); in format_counters()
2797 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), t->pmt_counter[i]); in format_counters()
2802 const unsigned long value_raw = t->pmt_counter[i]; in format_counters()
2812 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->c1 / tsc); in format_counters()
2814 /* print per-core data only for 1st thread in core */ in format_counters()
2819 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c3 / tsc); in format_counters()
2821 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c6 / tsc); in format_counters()
2823 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c7 / tsc); in format_counters()
2827 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->mc6_us / tsc); in format_counters()
2830 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), c->core_temp_c); in format_counters()
2834 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), c->core_throt_cnt); in format_counters()
2836 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in format_counters()
2837 if (mp->format == FORMAT_RAW) { in format_counters()
2838 if (mp->width == 32) in format_counters()
2840 sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int)c->counter[i]); in format_counters()
2842 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), c->counter[i]); in format_counters()
2843 } else if (mp->format == FORMAT_DELTA) { in format_counters()
2844 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in format_counters()
2845 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), c->counter[i]); in format_counters()
2847 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), c->counter[i]); in format_counters()
2848 } else if (mp->format == FORMAT_PERCENT) { in format_counters()
2849 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->counter[i] / tsc); in format_counters()
2853 for (i = 0, pp = sys.perf_cp; pp; i++, pp = pp->next) { in format_counters()
2854 if (pp->format == FORMAT_RAW) { in format_counters()
2855 if (pp->width == 32) in format_counters()
2858 (unsigned int)c->perf_counter[i]); in format_counters()
2860 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), c->perf_counter[i]); in format_counters()
2861 } else if (pp->format == FORMAT_DELTA) { in format_counters()
2862 if ((pp->type == COUNTER_ITEMS) && sums_need_wide_columns) in format_counters()
2863 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), c->perf_counter[i]); in format_counters()
2865 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), c->perf_counter[i]); in format_counters()
2866 } else if (pp->format == FORMAT_PERCENT) { in format_counters()
2867 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->perf_counter[i] / tsc); in format_counters()
2871 for (i = 0, ppmt = sys.pmt_cp; ppmt; i++, ppmt = ppmt->next) { in format_counters()
2872 switch (ppmt->type) { in format_counters()
2876 (unsigned int)c->pmt_counter[i]); in format_counters()
2878 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), c->pmt_counter[i]); in format_counters()
2883 const unsigned long value_raw = c->pmt_counter[i]; in format_counters()
2893 if (DO_BIC(BIC_CorWatt) && platform->has_per_core_rapl) in format_counters()
2896 rapl_counter_get_value(&c->core_energy, RAPL_UNIT_WATTS, interval_float)); in format_counters()
2897 if (DO_BIC(BIC_Cor_J) && platform->has_per_core_rapl) in format_counters()
2899 rapl_counter_get_value(&c->core_energy, RAPL_UNIT_JOULES, interval_float)); in format_counters()
2901 /* print per-package data only for 1st core in package */ in format_counters()
2907 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->pkg_temp_c); in format_counters()
2911 if (p->gfx_rc6_ms == -1) { /* detect GFX counter reset */ in format_counters()
2915 p->gfx_rc6_ms / 10.0 / interval_float); in format_counters()
2921 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->gfx_mhz); in format_counters()
2925 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->gfx_act_mhz); in format_counters()
2929 if (p->sam_mc6_ms == -1) { /* detect GFX counter reset */ in format_counters()
2933 p->sam_mc6_ms / 10.0 / interval_float); in format_counters()
2939 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->sam_mhz); in format_counters()
2943 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->sam_act_mhz); in format_counters()
2947 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_wtd_core_c0 / tsc); in format_counters()
2949 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_any_core_c0 / tsc); in format_counters()
2951 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_any_gfxe_c0 / tsc); in format_counters()
2953 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_both_core_gfxe_c0 / tsc); in format_counters()
2956 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc2 / tsc); in format_counters()
2958 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc3 / tsc); in format_counters()
2960 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc6 / tsc); in format_counters()
2962 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc7 / tsc); in format_counters()
2964 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc8 / tsc); in format_counters()
2966 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc9 / tsc); in format_counters()
2968 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc10 / tsc); in format_counters()
2972 …sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->die_c6 / crystal_hz / interval_float); in format_counters()
2975 if (p->cpu_lpi >= 0) in format_counters()
2978 100.0 * p->cpu_lpi / 1000000.0 / interval_float); in format_counters()
2983 if (p->sys_lpi >= 0) in format_counters()
2986 100.0 * p->sys_lpi / 1000000.0 / interval_float); in format_counters()
2994 rapl_counter_get_value(&p->energy_pkg, RAPL_UNIT_WATTS, interval_float)); in format_counters()
2995 if (DO_BIC(BIC_CorWatt) && !platform->has_per_core_rapl) in format_counters()
2998 rapl_counter_get_value(&p->energy_cores, RAPL_UNIT_WATTS, interval_float)); in format_counters()
3002 rapl_counter_get_value(&p->energy_gfx, RAPL_UNIT_WATTS, interval_float)); in format_counters()
3006 rapl_counter_get_value(&p->energy_dram, RAPL_UNIT_WATTS, interval_float)); in format_counters()
3009 rapl_counter_get_value(&p->energy_pkg, RAPL_UNIT_JOULES, interval_float)); in format_counters()
3010 if (DO_BIC(BIC_Cor_J) && !platform->has_per_core_rapl) in format_counters()
3012 rapl_counter_get_value(&p->energy_cores, RAPL_UNIT_JOULES, interval_float)); in format_counters()
3015 rapl_counter_get_value(&p->energy_gfx, RAPL_UNIT_JOULES, interval_float)); in format_counters()
3018 rapl_counter_get_value(&p->energy_dram, RAPL_UNIT_JOULES, interval_float)); in format_counters()
3022 rapl_counter_get_value(&p->rapl_pkg_perf_status, RAPL_UNIT_WATTS, interval_float)); in format_counters()
3026 rapl_counter_get_value(&p->rapl_dram_perf_status, RAPL_UNIT_WATTS, interval_float)); in format_counters()
3029 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->uncore_mhz); in format_counters()
3031 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in format_counters()
3032 if (mp->format == FORMAT_RAW) { in format_counters()
3033 if (mp->width == 32) in format_counters()
3035 sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int)p->counter[i]); in format_counters()
3037 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), p->counter[i]); in format_counters()
3038 } else if (mp->format == FORMAT_DELTA) { in format_counters()
3039 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in format_counters()
3040 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), p->counter[i]); in format_counters()
3042 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), p->counter[i]); in format_counters()
3043 } else if (mp->format == FORMAT_PERCENT) { in format_counters()
3044 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->counter[i] / tsc); in format_counters()
3045 } else if (mp->type == COUNTER_K2M) in format_counters()
3046 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), (unsigned int)p->counter[i] / 1000); in format_counters()
3049 for (i = 0, pp = sys.perf_pp; pp; i++, pp = pp->next) { in format_counters()
3050 if (pp->format == FORMAT_RAW) { in format_counters()
3051 if (pp->width == 32) in format_counters()
3054 (unsigned int)p->perf_counter[i]); in format_counters()
3056 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), p->perf_counter[i]); in format_counters()
3057 } else if (pp->format == FORMAT_DELTA) { in format_counters()
3058 if ((pp->type == COUNTER_ITEMS) && sums_need_wide_columns) in format_counters()
3059 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), p->perf_counter[i]); in format_counters()
3061 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), p->perf_counter[i]); in format_counters()
3062 } else if (pp->format == FORMAT_PERCENT) { in format_counters()
3063 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->perf_counter[i] / tsc); in format_counters()
3064 } else if (pp->type == COUNTER_K2M) { in format_counters()
3066 sprintf(outp, "%s%d", (printed++ ? delim : ""), (unsigned int)p->perf_counter[i] / 1000); in format_counters()
3070 for (i = 0, ppmt = sys.pmt_pp; ppmt; i++, ppmt = ppmt->next) { in format_counters()
3071 switch (ppmt->type) { in format_counters()
3075 (unsigned int)p->pmt_counter[i]); in format_counters()
3077 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), p->pmt_counter[i]); in format_counters()
3082 const unsigned long value_raw = p->pmt_counter[i]; in format_counters()
3091 if (*(outp - 1) != '\n') in format_counters()
3137 old = ((((unsigned long long)new << 32) - ((unsigned long long)old << 32)) >> 32);
3147 old->pkg_wtd_core_c0 = new->pkg_wtd_core_c0 - old->pkg_wtd_core_c0; in delta_package()
3149 old->pkg_any_core_c0 = new->pkg_any_core_c0 - old->pkg_any_core_c0; in delta_package()
3151 old->pkg_any_gfxe_c0 = new->pkg_any_gfxe_c0 - old->pkg_any_gfxe_c0; in delta_package()
3153 old->pkg_both_core_gfxe_c0 = new->pkg_both_core_gfxe_c0 - old->pkg_both_core_gfxe_c0; in delta_package()
3155 old->pc2 = new->pc2 - old->pc2; in delta_package()
3157 old->pc3 = new->pc3 - old->pc3; in delta_package()
3159 old->pc6 = new->pc6 - old->pc6; in delta_package()
3161 old->pc7 = new->pc7 - old->pc7; in delta_package()
3162 old->pc8 = new->pc8 - old->pc8; in delta_package()
3163 old->pc9 = new->pc9 - old->pc9; in delta_package()
3164 old->pc10 = new->pc10 - old->pc10; in delta_package()
3165 old->die_c6 = new->die_c6 - old->die_c6; in delta_package()
3166 old->cpu_lpi = new->cpu_lpi - old->cpu_lpi; in delta_package()
3167 old->sys_lpi = new->sys_lpi - old->sys_lpi; in delta_package()
3168 old->pkg_temp_c = new->pkg_temp_c; in delta_package()
3171 if (old->gfx_rc6_ms > new->gfx_rc6_ms) in delta_package()
3172 old->gfx_rc6_ms = -1; in delta_package()
3174 old->gfx_rc6_ms = new->gfx_rc6_ms - old->gfx_rc6_ms; in delta_package()
3176 old->uncore_mhz = new->uncore_mhz; in delta_package()
3177 old->gfx_mhz = new->gfx_mhz; in delta_package()
3178 old->gfx_act_mhz = new->gfx_act_mhz; in delta_package()
3181 if (old->sam_mc6_ms > new->sam_mc6_ms) in delta_package()
3182 old->sam_mc6_ms = -1; in delta_package()
3184 old->sam_mc6_ms = new->sam_mc6_ms - old->sam_mc6_ms; in delta_package()
3186 old->sam_mhz = new->sam_mhz; in delta_package()
3187 old->sam_act_mhz = new->sam_act_mhz; in delta_package()
3189 old->energy_pkg.raw_value = new->energy_pkg.raw_value - old->energy_pkg.raw_value; in delta_package()
3190 old->energy_cores.raw_value = new->energy_cores.raw_value - old->energy_cores.raw_value; in delta_package()
3191 old->energy_gfx.raw_value = new->energy_gfx.raw_value - old->energy_gfx.raw_value; in delta_package()
3192 old->energy_dram.raw_value = new->energy_dram.raw_value - old->energy_dram.raw_value; in delta_package()
3193 …old->rapl_pkg_perf_status.raw_value = new->rapl_pkg_perf_status.raw_value - old->rapl_pkg_perf_sta… in delta_package()
3194 old->rapl_dram_perf_status.raw_value = in delta_package()
3195 new->rapl_dram_perf_status.raw_value - old->rapl_dram_perf_status.raw_value; in delta_package()
3197 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in delta_package()
3198 if (mp->format == FORMAT_RAW) in delta_package()
3199 old->counter[i] = new->counter[i]; in delta_package()
3200 else if (mp->format == FORMAT_AVERAGE) in delta_package()
3201 old->counter[i] = new->counter[i]; in delta_package()
3203 old->counter[i] = new->counter[i] - old->counter[i]; in delta_package()
3206 for (i = 0, pp = sys.perf_pp; pp; i++, pp = pp->next) { in delta_package()
3207 if (pp->format == FORMAT_RAW) in delta_package()
3208 old->perf_counter[i] = new->perf_counter[i]; in delta_package()
3209 else if (pp->format == FORMAT_AVERAGE) in delta_package()
3210 old->perf_counter[i] = new->perf_counter[i]; in delta_package()
3212 old->perf_counter[i] = new->perf_counter[i] - old->perf_counter[i]; in delta_package()
3215 for (i = 0, ppmt = sys.pmt_pp; ppmt; i++, ppmt = ppmt->next) { in delta_package()
3216 if (ppmt->format == FORMAT_RAW) in delta_package()
3217 old->pmt_counter[i] = new->pmt_counter[i]; in delta_package()
3219 old->pmt_counter[i] = new->pmt_counter[i] - old->pmt_counter[i]; in delta_package()
3232 old->c3 = new->c3 - old->c3; in delta_core()
3233 old->c6 = new->c6 - old->c6; in delta_core()
3234 old->c7 = new->c7 - old->c7; in delta_core()
3235 old->core_temp_c = new->core_temp_c; in delta_core()
3236 old->core_throt_cnt = new->core_throt_cnt; in delta_core()
3237 old->mc6_us = new->mc6_us - old->mc6_us; in delta_core()
3239 DELTA_WRAP32(new->core_energy.raw_value, old->core_energy.raw_value); in delta_core()
3241 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in delta_core()
3242 if (mp->format == FORMAT_RAW) in delta_core()
3243 old->counter[i] = new->counter[i]; in delta_core()
3245 old->counter[i] = new->counter[i] - old->counter[i]; in delta_core()
3248 for (i = 0, pp = sys.perf_cp; pp; i++, pp = pp->next) { in delta_core()
3249 if (pp->format == FORMAT_RAW) in delta_core()
3250 old->perf_counter[i] = new->perf_counter[i]; in delta_core()
3252 old->perf_counter[i] = new->perf_counter[i] - old->perf_counter[i]; in delta_core()
3255 for (i = 0, ppmt = sys.pmt_cp; ppmt; i++, ppmt = ppmt->next) { in delta_core()
3256 if (ppmt->format == FORMAT_RAW) in delta_core()
3257 old->pmt_counter[i] = new->pmt_counter[i]; in delta_core()
3259 old->pmt_counter[i] = new->pmt_counter[i] - old->pmt_counter[i]; in delta_core()
3265 if (!DO_BIC(BIC_CPU_c1) || platform->has_msr_core_c1_res) in soft_c1_residency_display()
3272 * old = new - old
3283 new->apic_id = old->apic_id; in delta_thread()
3285 new->x2apic_id = old->x2apic_id; in delta_thread()
3290 * over-write old w/ new so we can print end of interval values in delta_thread()
3293 timersub(&new->tv_begin, &old->tv_begin, &old->tv_delta); in delta_thread()
3294 old->tv_begin = new->tv_begin; in delta_thread()
3295 old->tv_end = new->tv_end; in delta_thread()
3297 old->tsc = new->tsc - old->tsc; in delta_thread()
3300 if (old->tsc < (1000 * 1000)) in delta_thread()
3301 errx(-3, "Insanely slow TSC rate, TSC stops in idle?\n" in delta_thread()
3302 "You can disable all c-states by booting with \"idle=poll\"\n" in delta_thread()
3305 old->c1 = new->c1 - old->c1; in delta_thread()
3309 if ((new->aperf > old->aperf) && (new->mperf > old->mperf)) { in delta_thread()
3310 old->aperf = new->aperf - old->aperf; in delta_thread()
3311 old->mperf = new->mperf - old->mperf; in delta_thread()
3313 return -1; in delta_thread()
3317 if (platform->has_msr_core_c1_res) { in delta_thread()
3325 * it is possible for mperf's non-halted cycles + idle states in delta_thread()
3328 if ((old->mperf + core_delta->c3 + core_delta->c6 + core_delta->c7) > (old->tsc * tsc_tweak)) in delta_thread()
3329 old->c1 = 0; in delta_thread()
3332 old->c1 = (old->tsc * tsc_tweak) - old->mperf - core_delta->c3 in delta_thread()
3333 - core_delta->c6 - core_delta->c7; in delta_thread()
3337 if (old->mperf == 0) { in delta_thread()
3339 fprintf(outf, "cpu%d MPERF 0!\n", old->cpu_id); in delta_thread()
3340 old->mperf = 1; /* divide by 0 protection */ in delta_thread()
3344 old->instr_count = new->instr_count - old->instr_count; in delta_thread()
3347 old->irq_count = new->irq_count - old->irq_count; in delta_thread()
3350 old->smi_count = new->smi_count - old->smi_count; in delta_thread()
3352 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in delta_thread()
3353 if (mp->format == FORMAT_RAW) in delta_thread()
3354 old->counter[i] = new->counter[i]; in delta_thread()
3356 old->counter[i] = new->counter[i] - old->counter[i]; in delta_thread()
3359 for (i = 0, pp = sys.perf_tp; pp; i++, pp = pp->next) { in delta_thread()
3360 if (pp->format == FORMAT_RAW) in delta_thread()
3361 old->perf_counter[i] = new->perf_counter[i]; in delta_thread()
3363 old->perf_counter[i] = new->perf_counter[i] - old->perf_counter[i]; in delta_thread()
3366 for (i = 0, ppmt = sys.pmt_tp; ppmt; i++, ppmt = ppmt->next) { in delta_thread()
3367 if (ppmt->format == FORMAT_RAW) in delta_thread()
3368 old->pmt_counter[i] = new->pmt_counter[i]; in delta_thread()
3370 old->pmt_counter[i] = new->pmt_counter[i] - old->pmt_counter[i]; in delta_thread()
3399 c->raw_value = 0; in rapl_counter_clear()
3400 c->scale = 0.0; in rapl_counter_clear()
3401 c->unit = RAPL_UNIT_INVALID; in rapl_counter_clear()
3409 t->tv_begin.tv_sec = 0; in clear_counters()
3410 t->tv_begin.tv_usec = 0; in clear_counters()
3411 t->tv_end.tv_sec = 0; in clear_counters()
3412 t->tv_end.tv_usec = 0; in clear_counters()
3413 t->tv_delta.tv_sec = 0; in clear_counters()
3414 t->tv_delta.tv_usec = 0; in clear_counters()
3416 t->tsc = 0; in clear_counters()
3417 t->aperf = 0; in clear_counters()
3418 t->mperf = 0; in clear_counters()
3419 t->c1 = 0; in clear_counters()
3421 t->instr_count = 0; in clear_counters()
3423 t->irq_count = 0; in clear_counters()
3424 t->smi_count = 0; in clear_counters()
3426 c->c3 = 0; in clear_counters()
3427 c->c6 = 0; in clear_counters()
3428 c->c7 = 0; in clear_counters()
3429 c->mc6_us = 0; in clear_counters()
3430 c->core_temp_c = 0; in clear_counters()
3431 rapl_counter_clear(&c->core_energy); in clear_counters()
3432 c->core_throt_cnt = 0; in clear_counters()
3434 p->pkg_wtd_core_c0 = 0; in clear_counters()
3435 p->pkg_any_core_c0 = 0; in clear_counters()
3436 p->pkg_any_gfxe_c0 = 0; in clear_counters()
3437 p->pkg_both_core_gfxe_c0 = 0; in clear_counters()
3439 p->pc2 = 0; in clear_counters()
3441 p->pc3 = 0; in clear_counters()
3443 p->pc6 = 0; in clear_counters()
3445 p->pc7 = 0; in clear_counters()
3446 p->pc8 = 0; in clear_counters()
3447 p->pc9 = 0; in clear_counters()
3448 p->pc10 = 0; in clear_counters()
3449 p->die_c6 = 0; in clear_counters()
3450 p->cpu_lpi = 0; in clear_counters()
3451 p->sys_lpi = 0; in clear_counters()
3453 rapl_counter_clear(&p->energy_pkg); in clear_counters()
3454 rapl_counter_clear(&p->energy_dram); in clear_counters()
3455 rapl_counter_clear(&p->energy_cores); in clear_counters()
3456 rapl_counter_clear(&p->energy_gfx); in clear_counters()
3457 rapl_counter_clear(&p->rapl_pkg_perf_status); in clear_counters()
3458 rapl_counter_clear(&p->rapl_dram_perf_status); in clear_counters()
3459 p->pkg_temp_c = 0; in clear_counters()
3461 p->gfx_rc6_ms = 0; in clear_counters()
3462 p->uncore_mhz = 0; in clear_counters()
3463 p->gfx_mhz = 0; in clear_counters()
3464 p->gfx_act_mhz = 0; in clear_counters()
3465 p->sam_mc6_ms = 0; in clear_counters()
3466 p->sam_mhz = 0; in clear_counters()
3467 p->sam_act_mhz = 0; in clear_counters()
3468 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) in clear_counters()
3469 t->counter[i] = 0; in clear_counters()
3471 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) in clear_counters()
3472 c->counter[i] = 0; in clear_counters()
3474 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) in clear_counters()
3475 p->counter[i] = 0; in clear_counters()
3477 memset(&t->perf_counter[0], 0, sizeof(t->perf_counter)); in clear_counters()
3478 memset(&c->perf_counter[0], 0, sizeof(c->perf_counter)); in clear_counters()
3479 memset(&p->perf_counter[0], 0, sizeof(p->perf_counter)); in clear_counters()
3481 memset(&t->pmt_counter[0], 0, ARRAY_SIZE(t->pmt_counter)); in clear_counters()
3482 memset(&c->pmt_counter[0], 0, ARRAY_SIZE(c->pmt_counter)); in clear_counters()
3483 memset(&p->pmt_counter[0], 0, ARRAY_SIZE(p->pmt_counter)); in clear_counters()
3489 if (dst->unit == RAPL_UNIT_INVALID) { in rapl_counter_accumulate()
3490 dst->unit = src->unit; in rapl_counter_accumulate()
3491 dst->scale = src->scale; in rapl_counter_accumulate()
3494 assert(dst->unit == src->unit); in rapl_counter_accumulate()
3495 assert(dst->scale == src->scale); in rapl_counter_accumulate()
3497 dst->raw_value += src->raw_value; in rapl_counter_accumulate()
3507 /* copy un-changing apic_id's */ in sum_counters()
3509 average.threads.apic_id = t->apic_id; in sum_counters()
3511 average.threads.x2apic_id = t->x2apic_id; in sum_counters()
3515 average.threads.tv_begin = t->tv_begin; in sum_counters()
3518 average.threads.tv_end = t->tv_end; in sum_counters()
3520 average.threads.tsc += t->tsc; in sum_counters()
3521 average.threads.aperf += t->aperf; in sum_counters()
3522 average.threads.mperf += t->mperf; in sum_counters()
3523 average.threads.c1 += t->c1; in sum_counters()
3525 average.threads.instr_count += t->instr_count; in sum_counters()
3527 average.threads.irq_count += t->irq_count; in sum_counters()
3528 average.threads.smi_count += t->smi_count; in sum_counters()
3530 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in sum_counters()
3531 if (mp->format == FORMAT_RAW) in sum_counters()
3533 average.threads.counter[i] += t->counter[i]; in sum_counters()
3536 for (i = 0, pp = sys.perf_tp; pp; i++, pp = pp->next) { in sum_counters()
3537 if (pp->format == FORMAT_RAW) in sum_counters()
3539 average.threads.perf_counter[i] += t->perf_counter[i]; in sum_counters()
3542 for (i = 0, ppmt = sys.pmt_tp; ppmt; i++, ppmt = ppmt->next) { in sum_counters()
3543 average.threads.pmt_counter[i] += t->pmt_counter[i]; in sum_counters()
3546 /* sum per-core values only for 1st thread in core */ in sum_counters()
3550 average.cores.c3 += c->c3; in sum_counters()
3551 average.cores.c6 += c->c6; in sum_counters()
3552 average.cores.c7 += c->c7; in sum_counters()
3553 average.cores.mc6_us += c->mc6_us; in sum_counters()
3555 average.cores.core_temp_c = MAX(average.cores.core_temp_c, c->core_temp_c); in sum_counters()
3556 average.cores.core_throt_cnt = MAX(average.cores.core_throt_cnt, c->core_throt_cnt); in sum_counters()
3558 rapl_counter_accumulate(&average.cores.core_energy, &c->core_energy); in sum_counters()
3560 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in sum_counters()
3561 if (mp->format == FORMAT_RAW) in sum_counters()
3563 average.cores.counter[i] += c->counter[i]; in sum_counters()
3566 for (i = 0, pp = sys.perf_cp; pp; i++, pp = pp->next) { in sum_counters()
3567 if (pp->format == FORMAT_RAW) in sum_counters()
3569 average.cores.perf_counter[i] += c->perf_counter[i]; in sum_counters()
3572 for (i = 0, ppmt = sys.pmt_cp; ppmt; i++, ppmt = ppmt->next) { in sum_counters()
3573 average.cores.pmt_counter[i] += c->pmt_counter[i]; in sum_counters()
3576 /* sum per-pkg values only for 1st core in pkg */ in sum_counters()
3581 average.packages.pkg_wtd_core_c0 += p->pkg_wtd_core_c0; in sum_counters()
3583 average.packages.pkg_any_core_c0 += p->pkg_any_core_c0; in sum_counters()
3585 average.packages.pkg_any_gfxe_c0 += p->pkg_any_gfxe_c0; in sum_counters()
3587 average.packages.pkg_both_core_gfxe_c0 += p->pkg_both_core_gfxe_c0; in sum_counters()
3589 average.packages.pc2 += p->pc2; in sum_counters()
3591 average.packages.pc3 += p->pc3; in sum_counters()
3593 average.packages.pc6 += p->pc6; in sum_counters()
3595 average.packages.pc7 += p->pc7; in sum_counters()
3596 average.packages.pc8 += p->pc8; in sum_counters()
3597 average.packages.pc9 += p->pc9; in sum_counters()
3598 average.packages.pc10 += p->pc10; in sum_counters()
3599 average.packages.die_c6 += p->die_c6; in sum_counters()
3601 average.packages.cpu_lpi = p->cpu_lpi; in sum_counters()
3602 average.packages.sys_lpi = p->sys_lpi; in sum_counters()
3604 rapl_counter_accumulate(&average.packages.energy_pkg, &p->energy_pkg); in sum_counters()
3605 rapl_counter_accumulate(&average.packages.energy_dram, &p->energy_dram); in sum_counters()
3606 rapl_counter_accumulate(&average.packages.energy_cores, &p->energy_cores); in sum_counters()
3607 rapl_counter_accumulate(&average.packages.energy_gfx, &p->energy_gfx); in sum_counters()
3609 average.packages.gfx_rc6_ms = p->gfx_rc6_ms; in sum_counters()
3610 average.packages.uncore_mhz = p->uncore_mhz; in sum_counters()
3611 average.packages.gfx_mhz = p->gfx_mhz; in sum_counters()
3612 average.packages.gfx_act_mhz = p->gfx_act_mhz; in sum_counters()
3613 average.packages.sam_mc6_ms = p->sam_mc6_ms; in sum_counters()
3614 average.packages.sam_mhz = p->sam_mhz; in sum_counters()
3615 average.packages.sam_act_mhz = p->sam_act_mhz; in sum_counters()
3617 average.packages.pkg_temp_c = MAX(average.packages.pkg_temp_c, p->pkg_temp_c); in sum_counters()
3619 rapl_counter_accumulate(&average.packages.rapl_pkg_perf_status, &p->rapl_pkg_perf_status); in sum_counters()
3620 rapl_counter_accumulate(&average.packages.rapl_dram_perf_status, &p->rapl_dram_perf_status); in sum_counters()
3622 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in sum_counters()
3623 if ((mp->format == FORMAT_RAW) && (topo.num_packages == 0)) in sum_counters()
3624 average.packages.counter[i] = p->counter[i]; in sum_counters()
3626 average.packages.counter[i] += p->counter[i]; in sum_counters()
3629 for (i = 0, pp = sys.perf_pp; pp; i++, pp = pp->next) { in sum_counters()
3630 if ((pp->format == FORMAT_RAW) && (topo.num_packages == 0)) in sum_counters()
3631 average.packages.perf_counter[i] = p->perf_counter[i]; in sum_counters()
3633 average.packages.perf_counter[i] += p->perf_counter[i]; in sum_counters()
3636 for (i = 0, ppmt = sys.pmt_pp; ppmt; i++, ppmt = ppmt->next) { in sum_counters()
3637 average.packages.pmt_counter[i] += p->pmt_counter[i]; in sum_counters()
3697 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in compute_average()
3698 if (mp->format == FORMAT_RAW) in compute_average()
3700 if (mp->type == COUNTER_ITEMS) { in compute_average()
3707 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in compute_average()
3708 if (mp->format == FORMAT_RAW) in compute_average()
3710 if (mp->type == COUNTER_ITEMS) { in compute_average()
3716 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in compute_average()
3717 if (mp->format == FORMAT_RAW) in compute_average()
3719 if (mp->type == COUNTER_ITEMS) { in compute_average()
3726 for (i = 0, pp = sys.perf_tp; pp; i++, pp = pp->next) { in compute_average()
3727 if (pp->format == FORMAT_RAW) in compute_average()
3729 if (pp->type == COUNTER_ITEMS) { in compute_average()
3736 for (i = 0, pp = sys.perf_cp; pp; i++, pp = pp->next) { in compute_average()
3737 if (pp->format == FORMAT_RAW) in compute_average()
3739 if (pp->type == COUNTER_ITEMS) { in compute_average()
3745 for (i = 0, pp = sys.perf_pp; pp; i++, pp = pp->next) { in compute_average()
3746 if (pp->format == FORMAT_RAW) in compute_average()
3748 if (pp->type == COUNTER_ITEMS) { in compute_average()
3755 for (i = 0, ppmt = sys.pmt_tp; ppmt; i++, ppmt = ppmt->next) { in compute_average()
3758 for (i = 0, ppmt = sys.pmt_cp; ppmt; i++, ppmt = ppmt->next) { in compute_average()
3761 for (i = 0, ppmt = sys.pmt_pp; ppmt; i++, ppmt = ppmt->next) { in compute_average()
3811 if (mp->msr_num != 0) { in get_mp()
3813 if (get_msr(cpu, mp->msr_num, counterp)) in get_mp()
3814 return -1; in get_mp()
3818 if (mp->flags & SYSFS_PERCPU) { in get_mp()
3819 sprintf(path, "/sys/devices/system/cpu/cpu%d/%s", cpu, mp->sp->path); in get_mp()
3859 int ret, epb = -1; in get_epb()
3878 return -1; in get_epb()
3893 t->apic_id = (ebx >> 24) & 0xff; in get_apic_id()
3915 t->x2apic_id = eax; in get_apic_id()
3927 t->x2apic_id = edx; in get_apic_id()
3929 if (debug && (t->apic_id != (t->x2apic_id & 0xff))) in get_apic_id()
3930 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()
3943 return -1; in get_core_throt_cnt()
3947 return -1; in get_core_throt_cnt()
3963 int ret = -1; in read_perf_counter_info()
3966 if (fdmt == -1) { in read_perf_counter_info()
3969 ret = -1; in read_perf_counter_info()
3973 bytes_read = read(fdmt, buf, sizeof(buf) - 1); in read_perf_counter_info()
3977 ret = -1; in read_perf_counter_info()
3986 ret = -1; in read_perf_counter_info()
4004 v = -1; in read_perf_counter_info_n()
4030 unsigned int ret = -1; in read_perf_config()
4036 return -1; in read_perf_config()
4107 if (rci->source[i] == COUNTER_SOURCE_PERF) in rapl_counter_info_count_perf()
4118 if (cci->source[i] == COUNTER_SOURCE_PERF) in cstate_counter_info_count_perf()
4126 rc->raw_value = rci->data[idx]; in write_rapl_counter()
4127 rc->unit = rci->unit[idx]; in write_rapl_counter()
4128 rc->scale = rci->scale[idx]; in write_rapl_counter()
4147 if (rci->fd_perf != -1) { in get_rapl_counters()
4150 const ssize_t actual_read_size = read(rci->fd_perf, &perf_data[0], sizeof(perf_data)); in get_rapl_counters()
4153 err(-1, "%s: failed to read perf_data (%zu %zu)", __func__, expected_read_size, in get_rapl_counters()
4158 switch (rci->source[i]) { in get_rapl_counters()
4164 assert(rci->fd_perf != -1); in get_rapl_counters()
4168 i, perf_data[pi], rci->scale[i], perf_data[pi] * rci->scale[i]); in get_rapl_counters()
4170 rci->data[i] = perf_data[pi]; in get_rapl_counters()
4180 if (rci->flags[i] & RAPL_COUNTER_FLAG_USE_MSR_SUM) { in get_rapl_counters()
4181 if (get_msr_sum(cpu, rci->msr[i], &rci->data[i])) in get_rapl_counters()
4182 return -13 - i; in get_rapl_counters()
4184 if (get_msr(cpu, rci->msr[i], &rci->data[i])) in get_rapl_counters()
4185 return -13 - i; in get_rapl_counters()
4188 rci->data[i] &= rci->msr_mask[i]; in get_rapl_counters()
4189 if (rci->msr_shift[i] >= 0) in get_rapl_counters()
4190 rci->data[i] >>= abs(rci->msr_shift[i]); in get_rapl_counters()
4192 rci->data[i] <<= abs(rci->msr_shift[i]); in get_rapl_counters()
4199 write_rapl_counter(&p->energy_pkg, rci, RAPL_RCI_INDEX_ENERGY_PKG); in get_rapl_counters()
4200 write_rapl_counter(&p->energy_cores, rci, RAPL_RCI_INDEX_ENERGY_CORES); in get_rapl_counters()
4201 write_rapl_counter(&p->energy_dram, rci, RAPL_RCI_INDEX_DRAM); in get_rapl_counters()
4202 write_rapl_counter(&p->energy_gfx, rci, RAPL_RCI_INDEX_GFX); in get_rapl_counters()
4203 write_rapl_counter(&p->rapl_pkg_perf_status, rci, RAPL_RCI_INDEX_PKG_PERF_STATUS); in get_rapl_counters()
4204 write_rapl_counter(&p->rapl_dram_perf_status, rci, RAPL_RCI_INDEX_DRAM_PERF_STATUS); in get_rapl_counters()
4205 write_rapl_counter(&c->core_energy, rci, RAPL_RCI_INDEX_CORE_ENERGY); in get_rapl_counters()
4213 if (sp->id == id) in find_sysfs_path_by_id()
4214 return (sp->path); in find_sysfs_path_by_id()
4215 sp = sp->next; in find_sysfs_path_by_id()
4253 if (cci->fd_perf_core != -1) { in get_cstate_counters()
4257 actual_read_size_core = read(cci->fd_perf_core, &perf_data_core[0], sizeof(perf_data_core)); in get_cstate_counters()
4260 err(-1, "%s: read perf %s: %ld", __func__, "core", actual_read_size_core); in get_cstate_counters()
4263 if (cci->fd_perf_pkg != -1) { in get_cstate_counters()
4267 actual_read_size_pkg = read(cci->fd_perf_pkg, &perf_data_pkg[0], sizeof(perf_data_pkg)); in get_cstate_counters()
4270 err(-1, "%s: read perf %s: %ld", __func__, "pkg", actual_read_size_pkg); in get_cstate_counters()
4276 …err(-1, "%s: failed to read perf_data (%zu %zu)", __func__, expected_read_size, actual_read_size_t… in get_cstate_counters()
4296 switch (cci->source[i]) { in get_cstate_counters()
4302 assert(cci->fd_perf_core != -1 || cci->fd_perf_pkg != -1); in get_cstate_counters()
4307 cci->data[i] = perf_data[pi]; in get_cstate_counters()
4314 if (get_msr(cpu, cci->msr[i], &cci->data[i])) in get_cstate_counters()
4315 return -13 - i; in get_cstate_counters()
4318 fprintf(stderr, "cstate via %s0x%llx %u: %llu\n", "msr", cci->msr[i], i, cci->data[i]); in get_cstate_counters()
4332 if (cci->source[index] != COUNTER_SOURCE_NONE) \ in get_cstate_counters()
4333 out_counter = cci->data[index]; \ in get_cstate_counters()
4338 PERF_COUNTER_WRITE_DATA(t->c1, CCSTATE_RCI_INDEX_C1_RESIDENCY); in get_cstate_counters()
4339 PERF_COUNTER_WRITE_DATA(c->c3, CCSTATE_RCI_INDEX_C3_RESIDENCY); in get_cstate_counters()
4340 PERF_COUNTER_WRITE_DATA(c->c6, CCSTATE_RCI_INDEX_C6_RESIDENCY); in get_cstate_counters()
4341 PERF_COUNTER_WRITE_DATA(c->c7, CCSTATE_RCI_INDEX_C7_RESIDENCY); in get_cstate_counters()
4343 PERF_COUNTER_WRITE_DATA(p->pc2, PCSTATE_RCI_INDEX_C2_RESIDENCY); in get_cstate_counters()
4344 PERF_COUNTER_WRITE_DATA(p->pc3, PCSTATE_RCI_INDEX_C3_RESIDENCY); in get_cstate_counters()
4345 PERF_COUNTER_WRITE_DATA(p->pc6, PCSTATE_RCI_INDEX_C6_RESIDENCY); in get_cstate_counters()
4346 PERF_COUNTER_WRITE_DATA(p->pc7, PCSTATE_RCI_INDEX_C7_RESIDENCY); in get_cstate_counters()
4347 PERF_COUNTER_WRITE_DATA(p->pc8, PCSTATE_RCI_INDEX_C8_RESIDENCY); in get_cstate_counters()
4348 PERF_COUNTER_WRITE_DATA(p->pc9, PCSTATE_RCI_INDEX_C9_RESIDENCY); in get_cstate_counters()
4349 PERF_COUNTER_WRITE_DATA(p->pc10, PCSTATE_RCI_INDEX_C10_RESIDENCY); in get_cstate_counters()
4361 if (mci->source[i] == COUNTER_SOURCE_PERF) in msr_counter_info_count_perf()
4382 ZERO_ARRAY(mci->data); in get_smi_aperf_mperf()
4384 if (mci->fd_perf != -1) { in get_smi_aperf_mperf()
4387 const ssize_t actual_read_size = read(mci->fd_perf, &perf_data[0], sizeof(perf_data)); in get_smi_aperf_mperf()
4390 err(-1, "%s: failed to read perf_data (%zu %zu)", __func__, expected_read_size, in get_smi_aperf_mperf()
4395 switch (mci->source[i]) { in get_smi_aperf_mperf()
4401 assert(mci->fd_perf != -1); in get_smi_aperf_mperf()
4406 mci->data[i] = perf_data[pi]; in get_smi_aperf_mperf()
4414 if (get_msr(cpu, mci->msr[i], &mci->data[i])) in get_smi_aperf_mperf()
4415 return -2 - i; in get_smi_aperf_mperf()
4417 mci->data[i] &= mci->msr_mask[i]; in get_smi_aperf_mperf()
4420 fprintf(stderr, "Reading msr counter via msr at %u: %llu\n", i, mci->data[i]); in get_smi_aperf_mperf()
4427 t->aperf = mci->data[MSR_RCI_INDEX_APERF]; in get_smi_aperf_mperf()
4428 t->mperf = mci->data[MSR_RCI_INDEX_MPERF]; in get_smi_aperf_mperf()
4429 t->smi_count = mci->data[MSR_RCI_INDEX_SMI]; in get_smi_aperf_mperf()
4440 for (size_t i = 0; pp; ++i, pp = pp->next) { in perf_counter_info_read_values()
4442 assert(domain < pp->num_domains); in perf_counter_info_read_values()
4444 fd_counter = pp->fd_perf_per_domain[domain]; in perf_counter_info_read_values()
4446 if (fd_counter == -1) in perf_counter_info_read_values()
4453 out[i] = value * pp->scale; in perf_counter_info_read_values()
4466 mask = ((1 << (msb + 1)) - 1); in pmt_gen_value_mask()
4468 mask -= (1 << lsb) - 1; in pmt_gen_value_mask()
4475 assert(domain_id < ppmt->num_domains); in pmt_read_counter()
4477 const unsigned long *pmmio = ppmt->domains[domain_id].pcounter; in pmt_read_counter()
4479 const unsigned long value_mask = pmt_gen_value_mask(ppmt->lsb, ppmt->msb); in pmt_read_counter()
4480 const unsigned long value_shift = ppmt->lsb; in pmt_read_counter()
4492 int cpu = t->cpu_id; in get_counters()
4501 return -1; in get_counters()
4504 gettimeofday(&t->tv_begin, (struct timezone *)NULL); in get_counters()
4509 t->tsc = rdtsc(); /* we are running on local CPU of interest */ in get_counters()
4514 if (read(get_instr_count_fd(cpu), &t->instr_count, sizeof(long long)) != sizeof(long long)) in get_counters()
4515 return -4; in get_counters()
4518 t->irq_count = irqs_per_cpu[cpu]; in get_counters()
4522 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in get_counters()
4523 if (get_mp(cpu, mp, &t->counter[i], mp->sp->path)) in get_counters()
4524 return -10; in get_counters()
4527 if (perf_counter_info_read_values(sys.perf_tp, cpu, t->perf_counter, MAX_ADDED_THREAD_COUNTERS)) in get_counters()
4528 return -10; in get_counters()
4530 for (i = 0, pp = sys.pmt_tp; pp; i++, pp = pp->next) in get_counters()
4531 t->pmt_counter[i] = pmt_read_counter(pp, t->cpu_id); in get_counters()
4537 if (platform->has_per_core_rapl) { in get_counters()
4538 status = get_rapl_counters(cpu, c->core_id, c, p); in get_counters()
4543 if (DO_BIC(BIC_CPU_c7) && t->is_atom) { in get_counters()
4550 c->c6 -= c->c7; in get_counters()
4554 if (get_msr(cpu, MSR_MODULE_C6_RES_MS, &c->mc6_us)) in get_counters()
4555 return -8; in get_counters()
4559 return -9; in get_counters()
4560 c->core_temp_c = tj_max - ((msr >> 16) & 0x7F); in get_counters()
4564 get_core_throt_cnt(cpu, &c->core_throt_cnt); in get_counters()
4566 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in get_counters()
4567 if (get_mp(cpu, mp, &c->counter[i], mp->sp->path)) in get_counters()
4568 return -10; in get_counters()
4571 if (perf_counter_info_read_values(sys.perf_cp, cpu, c->perf_counter, MAX_ADDED_CORE_COUNTERS)) in get_counters()
4572 return -10; in get_counters()
4574 for (i = 0, pp = sys.pmt_cp; pp; i++, pp = pp->next) in get_counters()
4575 c->pmt_counter[i] = pmt_read_counter(pp, c->core_id); in get_counters()
4582 if (get_msr(cpu, MSR_PKG_WEIGHTED_CORE_C0_RES, &p->pkg_wtd_core_c0)) in get_counters()
4583 return -10; in get_counters()
4586 if (get_msr(cpu, MSR_PKG_ANY_CORE_C0_RES, &p->pkg_any_core_c0)) in get_counters()
4587 return -11; in get_counters()
4590 if (get_msr(cpu, MSR_PKG_ANY_GFXE_C0_RES, &p->pkg_any_gfxe_c0)) in get_counters()
4591 return -12; in get_counters()
4594 if (get_msr(cpu, MSR_PKG_BOTH_CORE_GFXE_C0_RES, &p->pkg_both_core_gfxe_c0)) in get_counters()
4595 return -13; in get_counters()
4599 p->cpu_lpi = cpuidle_cur_cpu_lpi_us; in get_counters()
4601 p->sys_lpi = cpuidle_cur_sys_lpi_us; in get_counters()
4603 if (!platform->has_per_core_rapl) { in get_counters()
4604 status = get_rapl_counters(cpu, p->package_id, c, p); in get_counters()
4611 return -17; in get_counters()
4612 p->pkg_temp_c = tj_max - ((msr >> 16) & 0x7F); in get_counters()
4616 p->uncore_mhz = get_legacy_uncore_mhz(p->package_id); in get_counters()
4619 p->gfx_rc6_ms = gfx_info[GFX_rc6].val_ull; in get_counters()
4622 p->gfx_mhz = gfx_info[GFX_MHz].val; in get_counters()
4625 p->gfx_act_mhz = gfx_info[GFX_ACTMHz].val; in get_counters()
4628 p->sam_mc6_ms = gfx_info[SAM_mc6].val_ull; in get_counters()
4631 p->sam_mhz = gfx_info[SAM_MHz].val; in get_counters()
4634 p->sam_act_mhz = gfx_info[SAM_ACTMHz].val; in get_counters()
4636 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in get_counters()
4639 if (mp->msr_num == 0) { in get_counters()
4640 path = find_sysfs_path_by_id(mp->sp, p->package_id); in get_counters()
4642 warnx("%s: package_id %d not found", __func__, p->package_id); in get_counters()
4643 return -10; in get_counters()
4646 if (get_mp(cpu, mp, &p->counter[i], path)) in get_counters()
4647 return -10; in get_counters()
4650 if (perf_counter_info_read_values(sys.perf_pp, cpu, p->perf_counter, MAX_ADDED_PACKAGE_COUNTERS)) in get_counters()
4651 return -10; in get_counters()
4653 for (i = 0, pp = sys.pmt_pp; pp; i++, pp = pp->next) in get_counters()
4654 p->pmt_counter[i] = pmt_read_counter(pp, p->package_id); in get_counters()
4657 gettimeofday(&t->tv_end, (struct timezone *)NULL); in get_counters()
4717 if (!platform->has_nhm_msrs || no_msr) in probe_cst_limit()
4720 switch (platform->cst_limit) { in probe_cst_limit()
4761 if (!platform->has_nhm_msrs || no_msr) in dump_platform_info()
4779 if (!platform->has_nhm_msrs || no_msr) in dump_power_ctl()
4783 fprintf(outf, "cpu%d: MSR_IA32_POWER_CTL: 0x%08llx (C1E auto-promotion: %sabled)\n", in dump_power_ctl()
4786 /* C-state Pre-wake Disable (CSTATE_PREWAKE_DISABLE) */ in dump_power_ctl()
4787 if (platform->has_cst_prewake_bit) in dump_power_ctl()
4788 fprintf(outf, "C-state Pre-wake: %sabled\n", msr & 0x40000000 ? "DIS" : "EN"); in dump_power_ctl()
4864 if (platform->trl_msrs & TRL_CORECOUNT) { in dump_turbo_ratio_limits()
4871 for (shift = 56; shift >= 0; shift -= 8) { in dump_turbo_ratio_limits()
4894 fprintf(outf, "%d * %.1f = %.1f MHz minimum operating frequency\n", ratio, bclk, ratio * bclk); in dump_atom_turbo_ratio_limits()
4940 * [0] -- Reserved in dump_knl_turbo_ratio_limits()
4941 * [7:1] -- Base value of number of active cores of bucket 1. in dump_knl_turbo_ratio_limits()
4942 * [15:8] -- Base value of freq ratio of bucket 1. in dump_knl_turbo_ratio_limits()
4943 * [20:16] -- +ve delta of number of active cores of bucket 2. in dump_knl_turbo_ratio_limits()
4946 * [23:21] -- Negative delta of freq ratio of bucket 2. in dump_knl_turbo_ratio_limits()
4948 * freq ratio of bucket 1 - delta in dump_knl_turbo_ratio_limits()
4949 * [28:24]-- +ve delta of number of active cores of bucket 3. in dump_knl_turbo_ratio_limits()
4950 * [31:29]-- -ve delta of freq ratio of bucket 3. in dump_knl_turbo_ratio_limits()
4951 * [36:32]-- +ve delta of number of active cores of bucket 4. in dump_knl_turbo_ratio_limits()
4952 * [39:37]-- -ve delta of freq ratio of bucket 4. in dump_knl_turbo_ratio_limits()
4953 * [44:40]-- +ve delta of number of active cores of bucket 5. in dump_knl_turbo_ratio_limits()
4954 * [47:45]-- -ve delta of freq ratio of bucket 5. in dump_knl_turbo_ratio_limits()
4955 * [52:48]-- +ve delta of number of active cores of bucket 6. in dump_knl_turbo_ratio_limits()
4956 * [55:53]-- -ve delta of freq ratio of bucket 6. in dump_knl_turbo_ratio_limits()
4957 * [60:56]-- +ve delta of number of active cores of bucket 7. in dump_knl_turbo_ratio_limits()
4958 * [63:61]-- -ve delta of freq ratio of bucket 7. in dump_knl_turbo_ratio_limits()
4970 ratio[b_nr + 1] = ratio[b_nr] - delta_ratio; in dump_knl_turbo_ratio_limits()
4974 for (i = buckets_no - 1; i >= 0; i--) in dump_knl_turbo_ratio_limits()
4975 if (i > 0 ? ratio[i] != ratio[i - 1] : 1) in dump_knl_turbo_ratio_limits()
4985 if (!platform->has_nhm_msrs || no_msr) in dump_cst_cfg()
4992 fprintf(outf, " (%s%s%s%s%slocked, pkg-cstate-limit=%d (%s)", in dump_cst_cfg()
4993 (msr & SNB_C3_AUTO_UNDEMOTE) ? "UNdemote-C3, " : "", in dump_cst_cfg()
4994 (msr & SNB_C1_AUTO_UNDEMOTE) ? "UNdemote-C1, " : "", in dump_cst_cfg()
4995 (msr & NHM_C3_AUTO_DEMOTE) ? "demote-C3, " : "", in dump_cst_cfg()
4996 (msr & NHM_C1_AUTO_DEMOTE) ? "demote-C1, " : "", in dump_cst_cfg()
5000 if (platform->has_cst_auto_convension) { in dump_cst_cfg()
5001 …fprintf(outf, ", automatic c-state conversion=%s", (msr & AUTOMATIC_CSTATE_CONVERSION) ? "on" : "o… in dump_cst_cfg()
5057 if (!platform->has_irtl_msrs || no_msr) in print_irtl()
5060 if (platform->supported_cstates & PC3) { in print_irtl()
5067 if (platform->supported_cstates & PC6) { in print_irtl()
5074 if (platform->supported_cstates & PC7) { in print_irtl()
5081 if (platform->supported_cstates & PC8) { in print_irtl()
5088 if (platform->supported_cstates & PC9) { in print_irtl()
5095 if (platform->supported_cstates & PC10) { in print_irtl()
5141 if (ccstate_counter_info[counter_id].fd_perf_core != -1) in free_fd_cstate()
5144 if (ccstate_counter_info[counter_id].fd_perf_pkg != -1) in free_fd_cstate()
5159 if (msr_counter_info[cpu].fd_perf != -1) in free_fd_msr()
5176 if (rapl_counter_info_perdomain[domain_id].fd_perf != -1) in free_fd_rapl_percpu()
5190 if (!pp->fd_perf_per_domain) in free_fd_added_perf_counters_()
5194 for (size_t domain = 0; domain < pp->num_domains; ++domain) { in free_fd_added_perf_counters_()
5195 if (pp->fd_perf_per_domain[domain] != -1) { in free_fd_added_perf_counters_()
5196 close(pp->fd_perf_per_domain[domain]); in free_fd_added_perf_counters_()
5197 pp->fd_perf_per_domain[domain] = -1; in free_fd_added_perf_counters_()
5201 free(pp->fd_perf_per_domain); in free_fd_added_perf_counters_()
5202 pp->fd_perf_per_domain = NULL; in free_fd_added_perf_counters_()
5204 pp = pp->next; in free_fd_added_perf_counters_()
5327 cpus[cpu].logical_node_id = -1; in set_node_data()
5336 if (cpus[cpu].logical_node_id != -1) in set_node_data()
5365 int cpu = thiscpu->logical_cpu_id; in get_physical_node_id()
5375 return -1; in get_physical_node_id()
5385 if (*next == '-') /* no negative cpu numbers */ in parse_cpu_str()
5402 if (*next == '-') { in parse_cpu_str()
5403 next += 1; /* start range */ in parse_cpu_str()
5407 next += 1; /* start range */ in parse_cpu_str()
5437 int cpu = thiscpu->logical_cpu_id; in get_thread_siblings()
5442 thiscpu->put_ids = CPU_ALLOC((topo.max_cpu_num + 1)); in get_thread_siblings()
5443 if (thiscpu->thread_id < 0) in get_thread_siblings()
5444 thiscpu->thread_id = thread_id++; in get_thread_siblings()
5445 if (!thiscpu->put_ids) in get_thread_siblings()
5446 return -1; in get_thread_siblings()
5449 CPU_ZERO_S(size, thiscpu->put_ids); in get_thread_siblings()
5456 return -1; in get_thread_siblings()
5459 offset -= BITMASK_SIZE; in get_thread_siblings()
5466 if (sib_core == thiscpu->physical_core_id) { in get_thread_siblings()
5467 CPU_SET_S(so, size, thiscpu->put_ids); in get_thread_siblings()
5476 return CPU_COUNT_S(size, thiscpu->put_ids); in get_thread_siblings()
5481 * skip non-present cpus
5502 if (cpu_is_not_allowed(t->cpu_id)) in for_all_cpus_2()
5611 fprintf(outf, "turbostat: re-initialized with num_cpus %d, allowed_cpus %d\n", topo.num_cpus, in re_initialize()
5632 topo.max_cpu_num--; /* 0 based */ in set_max_cpu_num()
5655 cpus[cpu].thread_id = -1; in init_thread_id()
5758 return -EINVAL; in snapshot_graphics()
5780 return -1; in snapshot_cpu_lpi_us()
5805 return -1; in snapshot_sys_lpi_us()
5931 /* get_msr_sum() = sum + (get_msr() - last) */ in get_msr_sum()
5948 int cpu = t->cpu_id; in update_msr_sum()
6004 if (timer_create(CLOCK_REALTIME, &sev, &timerid) == -1) { in msr_sum_record()
6020 if (timer_settime(timerid, 0, &its, NULL) == -1) { in msr_sum_record()
6035 * return value < -20 on failure
6044 if (errno && (original_priority == -1)) in set_my_sched_priority()
6045 return -21; in set_my_sched_priority()
6049 return -21; in set_my_sched_priority()
6054 return -21; in set_my_sched_priority()
6070 * ignore on error - we probably don't have permission to set it, but in turbostat_loop()
6073 set_my_sched_priority(-20); in turbostat_loop()
6081 if (retval < -1) { in turbostat_loop()
6083 } else if (retval == -1) { in turbostat_loop()
6107 if (retval < -1) { in turbostat_loop()
6109 } else if (retval == -1) { in turbostat_loop()
6130 if (retval < -1) { in turbostat_loop()
6132 } else if (retval == -1) { in turbostat_loop()
6192 if (cap_free(caps) == -1) in check_for_cap_sys_rawio()
6193 err(-6, "cap_free\n"); in check_for_cap_sys_rawio()
6217 … "\tRun as root to enable them or use %s to disable the access explicitly", pathname, "--no-msr"); in check_msr_permission()
6227 if (!platform->has_nhm_msrs || no_msr) in probe_bclk()
6230 if (platform->bclk_freq == BCLK_100MHZ) in probe_bclk()
6232 else if (platform->bclk_freq == BCLK_133MHZ) in probe_bclk()
6234 else if (platform->bclk_freq == BCLK_SLV) in probe_bclk()
6245 if (platform->enable_tsc_tweak) in probe_bclk()
6267 if (!platform->has_nhm_msrs || no_msr) in dump_turbo_ratio_info()
6270 if (platform->trl_msrs & TRL_LIMIT2) in dump_turbo_ratio_info()
6273 if (platform->trl_msrs & TRL_LIMIT1) in dump_turbo_ratio_info()
6276 if (platform->trl_msrs & TRL_BASE) { in dump_turbo_ratio_info()
6283 if (platform->trl_msrs & TRL_ATOM) in dump_turbo_ratio_info()
6286 if (platform->trl_msrs & TRL_KNL) in dump_turbo_ratio_info()
6289 if (platform->has_config_tdp) in dump_turbo_ratio_info()
6296 int retval = -1; in read_sysfs_int()
6302 return (-1); in read_sysfs_int()
6354 fprintf(outf, "Uncore Frequency package%d die%d: %d - %d MHz ", i, j, k / 1000, l / 1000); in probe_intel_uncore_frequency_legacy()
6360 fprintf(outf, "(%d - %d MHz)", k / 1000, l / 1000); in probe_intel_uncore_frequency_legacy()
6384 uncore_max_id -= 1; in probe_intel_uncore_frequency_cluster()
6388 for (i = uncore_max_id; i >= 0; --i) { in probe_intel_uncore_frequency_cluster()
6419 …fprintf(outf, "Uncore Frequency package%d domain%d cluster%d: %d - %d MHz ", package_id, domain_id, in probe_intel_uncore_frequency_cluster()
6426 fprintf(outf, "(%d - %d MHz)", k / 1000, l / 1000); in probe_intel_uncore_frequency_cluster()
6464 if (!strncmp(buf, "gt0-rc", strlen("gt0-rc"))) in probe_graphics()
6466 else if (!strncmp(buf, "gt0-mc", strlen("gt0-mc"))) in probe_graphics()
6576 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ in dump_sysfs_cstate_config()
6577 sp = strchr(name_buf, '-'); in dump_sysfs_cstate_config()
6662 cpu = t->cpu_id; in print_epb()
6664 /* EPB is per-package */ in print_epb()
6670 return -1; in print_epb()
6714 cpu = t->cpu_id; in print_hwp()
6716 /* MSR_HWP_CAPABILITIES is per-package */ in print_hwp()
6722 return -1; in print_hwp()
6728 fprintf(outf, "cpu%d: MSR_PM_ENABLE: 0x%08llx (%sHWP)\n", cpu, msr, (msr & (1 << 0)) ? "" : "No-"); in print_hwp()
6781 cpu, msr, ((msr) & 0x1) ? "" : "No-", ((msr) & 0x4) ? "" : "No-"); in print_hwp()
6800 cpu = t->cpu_id; in print_perf_limit()
6802 /* per-package */ in print_perf_limit()
6808 return -1; in print_perf_limit()
6811 if (platform->plr_msrs & PLR_CORE) { in print_perf_limit()
6823 (msr & 1 << 6) ? "VR-Therm, " : "", in print_perf_limit()
6824 (msr & 1 << 5) ? "Auto-HWP, " : "", in print_perf_limit()
6837 (msr & 1 << 22) ? "VR-Therm, " : "", in print_perf_limit()
6838 (msr & 1 << 21) ? "Auto-HWP, " : "", in print_perf_limit()
6844 if (platform->plr_msrs & PLR_GFX) { in print_perf_limit()
6851 (msr & 1 << 6) ? "VR-Therm, " : "", in print_perf_limit()
6859 (msr & 1 << 22) ? "VR-Therm, " : "", in print_perf_limit()
6864 if (platform->plr_msrs & PLR_RING) { in print_perf_limit()
6870 (msr & 1 << 6) ? "VR-Therm, " : "", in print_perf_limit()
6876 (msr & 1 << 22) ? "VR-Therm, " : "", in print_perf_limit()
6888 if (platform->rapl_quirk_tdp) in get_quirk_tdp()
6889 return platform->rapl_quirk_tdp; in get_quirk_tdp()
6898 if (platform->rapl_msrs & RAPL_PKG_POWER_INFO) in get_tdp_intel()
6922 if (!(platform->rapl_msrs & RAPL_PKG_PERF_STATUS)) in rapl_probe_intel()
6924 if (!(platform->rapl_msrs & RAPL_DRAM_PERF_STATUS)) in rapl_probe_intel()
6932 if (platform->has_rapl_divisor) in rapl_probe_intel()
6937 if (platform->has_fixed_rapl_unit) in rapl_probe_intel()
6952 …fprintf(outf, "RAPL: %.0f sec. Joule Counter Range, at %.0f Watts\n", rapl_joule_counter_range, td… in rapl_probe_intel()
6970 rapl_time_units = ldexp(1.0, -(msr >> 16 & 0xf)); in rapl_probe_amd()
6971 rapl_energy_units = ldexp(1.0, -(msr >> 8 & 0x1f)); in rapl_probe_amd()
6972 rapl_power_units = ldexp(1.0, -(msr & 0xf)); in rapl_probe_amd()
6978 …fprintf(outf, "RAPL: %.0f sec. Joule Counter Range, at %.0f Watts\n", rapl_joule_counter_range, td… in rapl_probe_amd()
7002 if (!platform->rapl_msrs) in print_rapl()
7009 cpu = t->cpu_id; in print_rapl()
7012 return -1; in print_rapl()
7015 if (platform->rapl_msrs & RAPL_AMD_F17H) { in print_rapl()
7018 return -1; in print_rapl()
7022 return -1; in print_rapl()
7028 if (platform->rapl_msrs & RAPL_PKG_POWER_INFO) { in print_rapl()
7031 return -5; in print_rapl()
7033 fprintf(outf, "cpu%d: MSR_PKG_POWER_INFO: 0x%08llx (%.0f W TDP, RAPL %.0f - %.0f W, %f sec.)\n", in print_rapl()
7041 if (platform->rapl_msrs & RAPL_PKG) { in print_rapl()
7044 return -9; in print_rapl()
7058 return -9; in print_rapl()
7065 if (platform->rapl_msrs & RAPL_DRAM_POWER_INFO) { in print_rapl()
7067 return -6; in print_rapl()
7069 fprintf(outf, "cpu%d: MSR_DRAM_POWER_INFO,: 0x%08llx (%.0f W TDP, RAPL %.0f - %.0f W, %f sec.)\n", in print_rapl()
7076 if (platform->rapl_msrs & RAPL_DRAM) { in print_rapl()
7078 return -9; in print_rapl()
7084 if (platform->rapl_msrs & RAPL_CORE_POLICY) { in print_rapl()
7086 return -7; in print_rapl()
7090 if (platform->rapl_msrs & RAPL_CORE_POWER_LIMIT) { in print_rapl()
7092 return -9; in print_rapl()
7097 if (platform->rapl_msrs & RAPL_GFX) { in print_rapl()
7099 return -8; in print_rapl()
7104 return -9; in print_rapl()
7119 if (!platform->rapl_msrs || no_msr) in probe_rapl()
7139 * but also allow cmdline over-ride with -T.
7141 * Several MSR temperature values are in units of degrees-C
7158 /* this is a per-package concept */ in set_temperature_target()
7162 cpu = t->cpu_id; in set_temperature_target()
7165 return -1; in set_temperature_target()
7175 if (!platform->has_nhm_msrs || no_msr) in set_temperature_target()
7184 int bits = platform->tcc_offset_bits; in set_temperature_target()
7191 tcc_offset = (msr >> 24) & GENMASK(bits - 1, 0); in set_temperature_target()
7192 fprintf(outf, "cpu%d: MSR_IA32_TEMPERATURE_TARGET: 0x%08llx (%d C) (%d default - %d offset)\n", in set_temperature_target()
7193 cpu, msr, tcc_default - tcc_offset, tcc_default, tcc_offset); in set_temperature_target()
7208 fprintf(outf, "cpu%d: Guessing tjMax %d C, Please use -T to specify\n", cpu, tj_max); in set_temperature_target()
7228 cpu = t->cpu_id; in print_thermal()
7230 /* DTS is per-core, no need to print for each thread */ in print_thermal()
7236 return -1; in print_thermal()
7244 fprintf(outf, "cpu%d: MSR_IA32_PACKAGE_THERM_STATUS: 0x%08llx (%d C)\n", cpu, msr, tj_max - dts); in print_thermal()
7252 cpu, msr, tj_max - dts, tj_max - dts2); in print_thermal()
7263 fprintf(outf, "cpu%d: MSR_IA32_THERM_STATUS: 0x%08llx (%d C +/- %d)\n", in print_thermal()
7264 cpu, msr, tj_max - dts, resolution); in print_thermal()
7272 cpu, msr, tj_max - dts, tj_max - dts2); in print_thermal()
7303 if (cpu_migrate(t->cpu_id)) { in get_cpu_type()
7304 fprintf(outf, "Could not migrate to CPU %d\n", t->cpu_id); in get_cpu_type()
7305 return -1; in get_cpu_type()
7314 t->is_atom = true; in get_cpu_type()
7327 base_cpu, msr, msr & FEAT_CTL_LOCKED ? "" : "UN-", msr & (1 << 18) ? "SGX" : ""); in decode_feature_control_msr()
7343 msr & MSR_IA32_MISC_ENABLE_TM1 ? "" : "No-", in decode_misc_enable_msr()
7344 msr & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP ? "" : "No-", in decode_misc_enable_msr()
7345 msr & MSR_IA32_MISC_ENABLE_MWAIT ? "" : "No-", in decode_misc_enable_msr()
7346 msr & MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE ? "No-" : "", in decode_misc_enable_msr()
7347 msr & MSR_IA32_MISC_ENABLE_TURBO_DISABLE ? "No-" : ""); in decode_misc_enable_msr()
7357 if (!platform->has_msr_misc_feature_control) in decode_misc_feature_control()
7362 …"cpu%d: MSR_MISC_FEATURE_CONTROL: 0x%08llx (%sL2-Prefetch %sL2-Prefetch-pair %sL1-Prefetch %sL1-IP… in decode_misc_feature_control()
7363 base_cpu, msr, msr & (0 << 0) ? "No-" : "", msr & (1 << 0) ? "No-" : "", in decode_misc_feature_control()
7364 msr & (2 << 0) ? "No-" : "", msr & (3 << 0) ? "No-" : ""); in decode_misc_feature_control()
7381 if (!platform->has_msr_misc_pwr_mgmt) in decode_misc_pwr_mgmt_msr()
7385 …fprintf(outf, "cpu%d: MSR_MISC_PWR_MGMT: 0x%08llx (%sable-EIST_Coordination %sable-EPB %sable-OOB)… in decode_misc_pwr_mgmt_msr()
7403 if (!platform->has_msr_c6_demotion_policy_config) in decode_c6_demotion_policy_msr()
7407 fprintf(outf, "cpu%d: MSR_CC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-CC6-Demotion)\n", in decode_c6_demotion_policy_msr()
7411 fprintf(outf, "cpu%d: MSR_MC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-MC6-Demotion)\n", in decode_c6_demotion_policy_msr()
7448 fd = open_perf_counter(base_cpu, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, -1, 0); in has_instr_count_access()
7449 has_access = fd != -1; in has_instr_count_access()
7451 if (fd != -1) in has_instr_count_access()
7457 "instructions retired perf counter", "--no-perf"); in has_instr_count_access()
7466 return -1; in add_rapl_perf_counter_()
7468 const double scale = read_perf_scale(cai->perf_subsys, cai->perf_name); in add_rapl_perf_counter_()
7471 return -1; in add_rapl_perf_counter_()
7473 const enum rapl_unit unit = read_perf_rapl_unit(cai->perf_subsys, cai->perf_name); in add_rapl_perf_counter_()
7476 return -1; in add_rapl_perf_counter_()
7478 const unsigned int rapl_type = read_perf_type(cai->perf_subsys); in add_rapl_perf_counter_()
7479 const unsigned int rapl_energy_pkg_config = read_perf_config(cai->perf_subsys, cai->perf_name); in add_rapl_perf_counter_()
7482 open_perf_counter(cpu, rapl_type, rapl_energy_pkg_config, rci->fd_perf, PERF_FORMAT_GROUP); in add_rapl_perf_counter_()
7483 if (fd_counter == -1) in add_rapl_perf_counter_()
7484 return -1; in add_rapl_perf_counter_()
7487 if (rci->fd_perf == -1) in add_rapl_perf_counter_()
7488 rci->fd_perf = fd_counter; in add_rapl_perf_counter_()
7507 * Linux-perf manages the HW instructions-retired counter
7518 err(-1, "calloc fd_instr_count_percpu"); in linux_perf_init()
7524 …const unsigned int num_domains = (platform->has_per_core_rapl ? topo.max_core_id : topo.max_packag… in rapl_perf_init()
7529 err(-1, "calloc rapl_counter_info_percpu"); in rapl_perf_init()
7538 rci->fd_perf = -1; in rapl_perf_init()
7540 rci->data[i] = 0; in rapl_perf_init()
7541 rci->source[i] = COUNTER_SOURCE_NONE; in rapl_perf_init()
7566 platform->has_per_core_rapl ? cpus[cpu].physical_core_id : cpus[cpu].physical_package_id; in rapl_perf_init()
7578 if (BIC_IS_ENABLED(cai->bic) && (platform->rapl_msrs & cai->feature_mask)) { in rapl_perf_init()
7581 if (!no_perf && cai->perf_name in rapl_perf_init()
7582 && add_rapl_perf_counter(cpu, rci, cai, &scale, &unit) != -1) { in rapl_perf_init()
7583 rci->source[cai->rci_index] = COUNTER_SOURCE_PERF; in rapl_perf_init()
7584 rci->scale[cai->rci_index] = scale * cai->compat_scale; in rapl_perf_init()
7585 rci->unit[cai->rci_index] = unit; in rapl_perf_init()
7586 rci->flags[cai->rci_index] = cai->flags; in rapl_perf_init()
7589 } else if (!no_msr && cai->msr && probe_msr(cpu, cai->msr) == 0) { in rapl_perf_init()
7590 rci->source[cai->rci_index] = COUNTER_SOURCE_MSR; in rapl_perf_init()
7591 rci->msr[cai->rci_index] = cai->msr; in rapl_perf_init()
7592 rci->msr_mask[cai->rci_index] = cai->msr_mask; in rapl_perf_init()
7593 rci->msr_shift[cai->rci_index] = cai->msr_shift; in rapl_perf_init()
7594 rci->unit[cai->rci_index] = RAPL_UNIT_JOULES; in rapl_perf_init()
7595 rci->scale[cai->rci_index] = *cai->platform_rapl_msr_scale * cai->compat_scale; in rapl_perf_init()
7596 rci->flags[cai->rci_index] = cai->flags; in rapl_perf_init()
7600 if (rci->source[cai->rci_index] != COUNTER_SOURCE_NONE) in rapl_perf_init()
7606 BIC_PRESENT(cai->bic); in rapl_perf_init()
7622 return &cci->fd_perf_core; in get_cstate_perf_group_fd()
7625 return &cci->fd_perf_pkg; in get_cstate_perf_group_fd()
7633 return -1; in add_cstate_perf_counter_()
7635 int *pfd_group = get_cstate_perf_group_fd(cci, cai->perf_subsys); in add_cstate_perf_counter_()
7638 return -1; in add_cstate_perf_counter_()
7640 const unsigned int type = read_perf_type(cai->perf_subsys); in add_cstate_perf_counter_()
7641 const unsigned int config = read_perf_config(cai->perf_subsys, cai->perf_name); in add_cstate_perf_counter_()
7645 if (fd_counter == -1) in add_cstate_perf_counter_()
7646 return -1; in add_cstate_perf_counter_()
7649 if (*pfd_group == -1) in add_cstate_perf_counter_()
7668 return -1; in add_msr_perf_counter_()
7670 const unsigned int type = read_perf_type(cai->perf_subsys); in add_msr_perf_counter_()
7671 const unsigned int config = read_perf_config(cai->perf_subsys, cai->perf_name); in add_msr_perf_counter_()
7673 const int fd_counter = open_perf_counter(cpu, type, config, cci->fd_perf, PERF_FORMAT_GROUP); in add_msr_perf_counter_()
7675 if (fd_counter == -1) in add_msr_perf_counter_()
7676 return -1; in add_msr_perf_counter_()
7679 if (cci->fd_perf == -1) in add_msr_perf_counter_()
7680 cci->fd_perf = fd_counter; in add_msr_perf_counter_()
7690 …fprintf(stderr, "%s: %s/%s: %d (cpu: %d)\n", __func__, cai->perf_subsys, cai->perf_name, ret, cpu); in add_msr_perf_counter()
7705 msr_counter_info[cpu].fd_perf = -1; in msr_perf_init_()
7711 cai->present = false; in msr_perf_init_()
7720 if (cai->needed) { in msr_perf_init_()
7722 if (!no_perf && cai->perf_name && add_msr_perf_counter(cpu, cci, cai) != -1) { in msr_perf_init_()
7723 cci->source[cai->rci_index] = COUNTER_SOURCE_PERF; in msr_perf_init_()
7724 cai->present = true; in msr_perf_init_()
7727 } else if (!no_msr && cai->msr && probe_msr(cpu, cai->msr) == 0) { in msr_perf_init_()
7728 cci->source[cai->rci_index] = COUNTER_SOURCE_MSR; in msr_perf_init_()
7729 cci->msr[cai->rci_index] = cai->msr; in msr_perf_init_()
7730 cci->msr_mask[cai->rci_index] = cai->msr_mask; in msr_perf_init_()
7731 cai->present = true; in msr_perf_init_()
7742 const bool need_soft_c1 = (!platform->has_msr_core_c1_res) && (platform->supported_cstates & CC1); in msr_perf_init()
7796 ccstate_counter_info[cpu].fd_perf_core = -1; in cstate_perf_init_()
7797 ccstate_counter_info[cpu].fd_perf_pkg = -1; in cstate_perf_init_()
7820 const bool per_thread = cai->flags & CSTATE_COUNTER_FLAG_COLLECT_PER_THREAD; in cstate_perf_init_()
7821 const bool per_core = cai->flags & CSTATE_COUNTER_FLAG_COLLECT_PER_CORE; in cstate_perf_init_()
7829 const bool counter_needed = BIC_IS_ENABLED(cai->bic) || in cstate_perf_init_()
7830 (soft_c1 && (cai->flags & CSTATE_COUNTER_FLAG_SOFT_C1_DEPENDENCY)); in cstate_perf_init_()
7831 const bool counter_supported = (platform->supported_cstates & cai->feature_mask); in cstate_perf_init_()
7835 if (!no_perf && cai->perf_name && add_cstate_perf_counter(cpu, cci, cai) != -1) { in cstate_perf_init_()
7837 cci->source[cai->rci_index] = COUNTER_SOURCE_PERF; in cstate_perf_init_()
7840 } else if (!no_msr && cai->msr && pkg_cstate_limit >= cai->pkg_cstate_limit in cstate_perf_init_()
7841 && probe_msr(cpu, cai->msr) == 0) { in cstate_perf_init_()
7842 cci->source[cai->rci_index] = COUNTER_SOURCE_MSR; in cstate_perf_init_()
7843 cci->msr[cai->rci_index] = cai->msr; in cstate_perf_init_()
7847 if (cci->source[cai->rci_index] != COUNTER_SOURCE_NONE) { in cstate_perf_init_()
7856 BIC_PRESENT(cai->bic); in cstate_perf_init_()
7869 const bool soft_c1 = !platform->has_msr_core_c1_res && has_amperf_access() in cstate_perf_init()
7870 && platform->supported_cstates & CC1; in cstate_perf_init()
7882 if (platform->has_msr_module_c6_res_ms) in probe_cstates()
7885 if (platform->has_ext_cst_msrs && !no_msr) { in probe_cstates()
7997 ecx_flags & (1 << 0) ? "SSE3" : "-", in process_cpuid()
7998 ecx_flags & (1 << 3) ? "MONITOR" : "-", in process_cpuid()
7999 ecx_flags & (1 << 6) ? "SMX" : "-", in process_cpuid()
8000 ecx_flags & (1 << 7) ? "EIST" : "-", in process_cpuid()
8001 ecx_flags & (1 << 8) ? "TM2" : "-", in process_cpuid()
8002 edx_flags & (1 << 4) ? "TSC" : "-", in process_cpuid()
8003 edx_flags & (1 << 5) ? "MSR" : "-", in process_cpuid()
8004 edx_flags & (1 << 22) ? "ACPI-TM" : "-", in process_cpuid()
8005 edx_flags & (1 << 28) ? "HT" : "-", edx_flags & (1 << 29) ? "TM" : "-"); in process_cpuid()
8016 * Non-Stop TSC is advertised by CPUID.EAX=0x80000007: EDX.bit8 in process_cpuid()
8047 has_aperf ? "" : "No-", in process_cpuid()
8048 has_turbo ? "" : "No-", in process_cpuid()
8049 do_dts ? "" : "No-", in process_cpuid()
8050 do_ptm ? "" : "No-", in process_cpuid()
8051 has_hwp ? "" : "No-", in process_cpuid()
8052 has_hwp_notify ? "" : "No-", in process_cpuid()
8053 has_hwp_activity_window ? "" : "No-", in process_cpuid()
8054 has_hwp_epp ? "" : "No-", has_hwp_pkg ? "" : "No-", has_epb ? "" : "No-"); in process_cpuid()
8070 fprintf(outf, "CPUID(7): %sSGX %sHybrid\n", has_sgx ? "" : "No-", is_hybrid ? "" : "No-"); in process_cpuid()
8092 crystal_hz = platform->crystal_freq; in process_cpuid()
8117 if (platform->enable_tsc_tweak) in process_cpuid()
8126 aperf_mperf_multiplier = platform->need_perf_multiplier ? 1024 : 1; in process_cpuid()
8137 if (platform->has_msr_knl_core_c6_residency && cai->msr == MSR_CORE_C6_RESIDENCY) in counter_info_init()
8138 cai->msr = MSR_KNL_CORE_C6_RESIDENCY; in counter_info_init()
8140 if (!platform->has_msr_core_c1_res && cai->msr == MSR_CORE_C1_RES) in counter_info_init()
8141 cai->msr = 0; in counter_info_init()
8143 if (platform->has_msr_atom_pkg_c6_residency && cai->msr == MSR_PKG_C6_RESIDENCY) in counter_info_init()
8144 cai->msr = MSR_ATOM_PKG_C6_RESIDENCY; in counter_info_init()
8169 if (platform->has_nhm_msrs && !no_msr) in probe_pm_features()
8182 if (isdigit(dirp->d_name[0])) in dir_filter()
8273 err(-ENODEV, "No valid cpus found"); in topology_probe()
8385 (*t)[i].cpu_id = -1; in allocate_counters()
8392 (*c)[i].core_id = -1; in allocate_counters()
8393 (*c)[i].base_cpu = -1; in allocate_counters()
8402 (*p)[i].base_cpu = -1; in allocate_counters()
8425 /* Workaround for systems where physical_node_id==-1 in init_counter()
8426 * and logical_node_id==(-1 - topo.num_cpus) in init_counter()
8435 t->cpu_id = cpu_id; in init_counter()
8437 if (c->base_cpu < 0) in init_counter()
8438 c->base_cpu = t->cpu_id; in init_counter()
8439 if (p->base_cpu < 0) in init_counter()
8440 p->base_cpu = t->cpu_id; in init_counter()
8443 c->core_id = core_id; in init_counter()
8444 p->package_id = pkg_id; in init_counter()
8459 err(-1, "calloc output buffer"); in allocate_output_buffer()
8466 err(-1, "calloc fd_percpu"); in allocate_fd_percpu()
8473 err(-1, "calloc %d", topo.num_cpus); in allocate_irq_buffers()
8477 err(-1, "calloc %d", topo.max_cpu_num + 1); in allocate_irq_buffers()
8483 if ((int)t->cpu_id == c->base_cpu) in update_topo()
8485 if ((int)t->cpu_id == p->base_cpu) in update_topo()
8523 err(-ENODEV, "No valid cpus found"); in set_base_cpu()
8568 switch (pinfo->scope) { in added_perf_counters_init_()
8583 pinfo->fd_perf_per_domain = calloc(num_domains, sizeof(*pinfo->fd_perf_per_domain)); in added_perf_counters_init_()
8584 if (!pinfo->fd_perf_per_domain) in added_perf_counters_init_()
8588 pinfo->fd_perf_per_domain[i] = -1; in added_perf_counters_init_()
8590 pinfo->num_domains = num_domains; in added_perf_counters_init_()
8591 pinfo->scale = 1.0; in added_perf_counters_init_()
8607 perf_type = read_perf_type(pinfo->device); in added_perf_counters_init_()
8608 if (perf_type == (unsigned int)-1) { in added_perf_counters_init_()
8610 __func__, pinfo->device, pinfo->event, "type"); in added_perf_counters_init_()
8614 perf_config = read_perf_config(pinfo->device, pinfo->event); in added_perf_counters_init_()
8615 if (perf_config == (unsigned int)-1) { in added_perf_counters_init_()
8617 __func__, pinfo->device, pinfo->event, "config"); in added_perf_counters_init_()
8622 perf_scale = read_perf_scale(pinfo->device, pinfo->event); in added_perf_counters_init_()
8626 fd_perf = open_perf_counter(cpu, perf_type, perf_config, -1, 0); in added_perf_counters_init_()
8627 if (fd_perf == -1) { in added_perf_counters_init_()
8629 __func__, pinfo->device, pinfo->event, cpu); in added_perf_counters_init_()
8634 pinfo->fd_perf_per_domain[next_domain] = fd_perf; in added_perf_counters_init_()
8635 pinfo->scale = perf_scale; in added_perf_counters_init_()
8639 pinfo->device, pinfo->event, cpu, pinfo->fd_perf_per_domain[next_domain]); in added_perf_counters_init_()
8642 pinfo = pinfo->next; in added_perf_counters_init_()
8669 if (fd_telem_info == -1) in parse_telem_info_file()
8670 return -1; in parse_telem_info_file()
8675 return -1; in parse_telem_info_file()
8680 return -1; in parse_telem_info_file()
8702 if (stat(SYSFS_TELEM_PATH, &st) == -1) in pmt_mmio_open()
8715 if (strcmp(entry->d_name, ".") == 0) in pmt_mmio_open()
8718 if (strcmp(entry->d_name, "..") == 0) in pmt_mmio_open()
8721 if (sscanf(entry->d_name, "telem%u", &telem_idx) != 1) in pmt_mmio_open()
8724 if (fstatat(dirfd(dirp), entry->d_name, &st, 0) == -1) { in pmt_mmio_open()
8731 fd_telem_dir = openat(dirfd(dirp), entry->d_name, O_RDONLY); in pmt_mmio_open()
8732 if (fd_telem_dir == -1) { in pmt_mmio_open()
8759 if (fd_pmt == -1) in pmt_mmio_open()
8776 ret->guid = guid; in pmt_mmio_open()
8777 ret->mmio_base = mmio; in pmt_mmio_open()
8778 ret->pmt_offset = offset; in pmt_mmio_open()
8779 ret->size = size; in pmt_mmio_open()
8781 ret->next = pmt_mmios; in pmt_mmio_open()
8801 if (pmmio->guid == guid) in pmt_mmio_find()
8804 pmmio = pmmio->next; in pmt_mmio_find()
8815 ret = (char *)pmmio->mmio_base; in pmt_get_counter_pointer()
8820 * - we might have to apply the offset first. in pmt_get_counter_pointer()
8822 ret += pmmio->pmt_offset; in pmt_get_counter_pointer()
8849 if (strcmp(pcounter->name, name) == 0) in pmt_find_counter()
8852 pcounter = pcounter->next; in pmt_find_counter()
8875 if (domain_id >= pcounter->num_domains) in pmt_counter_add_domain()
8878 assert(pcounter->domains); in pmt_counter_add_domain()
8879 assert(domain_id < pcounter->num_domains); in pmt_counter_add_domain()
8881 pcounter->domains[domain_id].pcounter = pmmio; in pmt_counter_add_domain()
8914 if (offset >= mmio->size) { in pmt_add_counter()
8916 fprintf(stderr, "%s: offset %u outside of PMT MMIO size %u\n", __func__, offset, mmio->size); in pmt_add_counter()
8930 strncpy(pcounter->name, name, ARRAY_SIZE(pcounter->name) - 1); in pmt_add_counter()
8931 pcounter->type = type; in pmt_add_counter()
8932 pcounter->scope = scope; in pmt_add_counter()
8933 pcounter->lsb = lsb; in pmt_add_counter()
8934 pcounter->msb = msb; in pmt_add_counter()
8935 pcounter->format = format; in pmt_add_counter()
8937 conflict += pcounter->type != type; in pmt_add_counter()
8938 conflict += pcounter->scope != scope; in pmt_add_counter()
8939 conflict += pcounter->lsb != lsb; in pmt_add_counter()
8940 conflict += pcounter->msb != msb; in pmt_add_counter()
8941 conflict += pcounter->format != format; in pmt_add_counter()
8953 pcounter->next = *pmt_root; in pmt_add_counter()
8988 if (BIC_IS_ENABLED(BIC_IPC) && has_aperf_access && get_instr_count_fd(base_cpu) != -1) in turbostat_init()
8995 if (platform->enable_tsc_tweak && !has_base_hz) { in turbostat_init()
9021 if (child_pid == -1) in fork_it()
9026 if (waitpid(child_pid, &status, 0) == -1) in fork_it()
9034 * because re-starting is problematic when forking in fork_it()
9074 fprintf(outf, "turbostat version 2024.07.26 - Len Brown <lenb@kernel.org>\n"); in print_version()
9090 ret = fread(bootcmd, sizeof(char), COMMAND_LINE_SIZE - 1, fp); in print_bootcmd()
9104 for (mp = head; mp; mp = mp->next) { in find_msrp_by_name()
9106 fprintf(stderr, "%s: %s %s\n", __func__, name, mp->name); in find_msrp_by_name()
9107 if (!strncmp(name, mp->name, strlen(mp->name))) in find_msrp_by_name()
9120 errx(1, "Requested MSR counter 0x%x, but in --no-msr mode", msr_num); in add_counter()
9137 return -1; in add_counter()
9149 return -1; in add_counter()
9161 return -1; in add_counter()
9166 return -1; in add_counter()
9172 err(-1, "calloc msr_counter"); in add_counter()
9174 msrp->msr_num = msr_num; in add_counter()
9175 strncpy(msrp->name, name, NAME_BYTES - 1); in add_counter()
9176 msrp->width = width; in add_counter()
9177 msrp->type = type; in add_counter()
9178 msrp->format = format; in add_counter()
9179 msrp->flags = flags; in add_counter()
9183 msrp->next = sys.tp; in add_counter()
9187 msrp->next = sys.cp; in add_counter()
9191 msrp->next = sys.pp; in add_counter()
9205 strncpy(sp->path, path, PATH_BYTES - 1); in add_counter()
9206 sp->id = id; in add_counter()
9207 sp->next = msrp->sp; in add_counter()
9208 msrp->sp = sp; in add_counter()
9234 strncpy(pinfo->device, perf_device, ARRAY_SIZE(pinfo->device) - 1); in make_perf_counter_info()
9235 strncpy(pinfo->event, perf_event, ARRAY_SIZE(pinfo->event) - 1); in make_perf_counter_info()
9237 strncpy(pinfo->name, name, ARRAY_SIZE(pinfo->name) - 1); in make_perf_counter_info()
9238 pinfo->width = width; in make_perf_counter_info()
9239 pinfo->scope = scope; in make_perf_counter_info()
9240 pinfo->type = type; in make_perf_counter_info()
9241 pinfo->format = format; in make_perf_counter_info()
9255 return -1; in add_perf_counter()
9262 return -1; in add_perf_counter()
9269 return -1; in add_perf_counter()
9277 return -1; in add_perf_counter()
9281 pinfo->next = sys.perf_tp; in add_perf_counter()
9287 pinfo->next = sys.perf_cp; in add_perf_counter()
9293 pinfo->next = sys.perf_pp; in add_perf_counter()
9302 __func__, pinfo->device, pinfo->event, pinfo->name, pinfo->scope); in add_perf_counter()
9399 fprintf(stderr, "--add: (msrDDD | msr0xXXX | /path_to_counter | perf/device/event ) required\n"); in parse_add_command_msr()
9403 /* Test for non-empty perf_device and perf_event */ in parse_add_command_msr()
9649 for (state = 10; state >= 0; --state) { in probe_sysfs()
9658 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ in probe_sysfs()
9659 sp = strchr(name_buf, '-'); in probe_sysfs()
9680 for (state = 10; state >= 0; --state) { in probe_sysfs()
9688 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ in probe_sysfs()
9689 sp = strchr(name_buf, '-'); in probe_sysfs()
9712 * 1,2,4..6,8-10 and set bits in cpu_subset
9744 fprintf(stderr, "\"--cpu %s\" malformed\n", optarg); in parse_cpu_command()
9746 exit(-1); in parse_cpu_command()
9764 { "hide", required_argument, 0, 'H' }, // meh, -h taken by --help in cmdline()
9769 { "no-msr", no_argument, 0, 'M' }, in cmdline()
9770 { "no-perf", no_argument, 0, 'P' }, in cmdline()
9782 * like adding the MSR counter with --add and at the same time using --no-msr. in cmdline()
9784 while ((opt = getopt_long_only(argc, argv, "MPn:", long_options, &option_index)) != -1) { in cmdline()
9798 …pt = getopt_long_only(argc, argv, "+C:c:Dde:hi:Jn:o:qMST:v", long_options, &option_index)) != -1) { in cmdline()
9810 /* --enable specified counter */ in cmdline()
9819 * --hide: do not show those specified in cmdline()
9838 interval_tv.tv_usec = (interval - interval_tv.tv_sec) * 1000000; in cmdline()
9839 interval_ts.tv_nsec = (interval - interval_ts.tv_sec) * 1000000000; in cmdline()
9878 * --show: show only those specified in cmdline()
9927 if (ret == -1) in main()
9965 if (argc - optind) in main()