Lines Matching +full:crystal +full:- +full:26 +full:m +full:- +full:en

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)
75 * 1. built-in only, the sysfs counters are not here -- we learn of those at run-time
77 * matching on them for --show and --hide.
82 * Usually truncated to 7 characters, but also handles 18 columns for raw 64-bit counters
234 #define BIC_Pkgpc9 (1ULL << 26)
404 int crystal_freq; /* Crystal clock to use when not available from CPUID.15 */
419 …bool has_per_core_rapl; /* Indicates cores energy collection is per-core, not per-package. AMD spe…
1086 /* MSRs that are not yet in the kernel-provided header. */
1166 .perf_name = "energy-pkg",
1179 .perf_name = "energy-pkg",
1192 .perf_name = "energy-cores",
1205 .perf_name = "energy-ram",
1218 .perf_name = "energy-gpu",
1270 .perf_name = "energy-psys",
1334 .perf_name = "c1-residency",
1344 .perf_name = "c3-residency",
1354 .perf_name = "c6-residency",
1364 .perf_name = "c7-residency",
1374 .perf_name = "c2-residency",
1384 .perf_name = "c3-residency",
1394 .perf_name = "c6-residency",
1404 .perf_name = "c7-residency",
1414 .perf_name = "c8-residency",
1424 .perf_name = "c9-residency",
1434 .perf_name = "c10-residency",
1558 /* BIC-like metadata */
1567 return (p->msb - p->lsb) + 1; in pmt_counter_get_width()
1574 …new_mem = (struct pmt_domain_info *)reallocarray(pcounter->domains, new_size, sizeof(*pcounter->do… in pmt_counter_resize_()
1581 const size_t num_new_domains = new_size - pcounter->num_domains; in pmt_counter_resize_()
1583 memset(&new_mem[pcounter->num_domains], 0, num_new_domains * sizeof(*pcounter->domains)); in pmt_counter_resize_()
1585 pcounter->num_domains = new_size; in pmt_counter_resize_()
1586 pcounter->domains = new_mem; in pmt_counter_resize_()
1599 new_size = MAX(new_size, pcounter->num_domains * 2); in pmt_counter_resize()
1630 unsigned long long mc6_us; /* duplicate as per-core for now, even though per module */
1714 /* get_msr_sum() = sum + (get_msr() - last) */
1732 if (platform->rapl_msrs & RAPL_AMD_F17H) in idx_to_offset()
1756 offset = -1; in idx_to_offset()
1789 idx = -1; in offset_to_idx()
1798 return platform->rapl_msrs & (RAPL_PKG | RAPL_AMD_F17H); in idx_valid()
1800 return platform->rapl_msrs & RAPL_DRAM; in idx_valid()
1802 return platform->rapl_msrs & RAPL_CORE_ENERGY_STATUS; in idx_valid()
1804 return platform->rapl_msrs & RAPL_GFX; in idx_valid()
1806 return platform->rapl_msrs & RAPL_PKG_PERF_STATUS; in idx_valid()
1808 return platform->rapl_msrs & RAPL_DRAM_PERF_STATUS; in idx_valid()
1810 return platform->rapl_msrs & RAPL_PSYS; in idx_valid()
1846 if (p->msr_num != 0) { in free_msr_counters_()
1847 *pp = p->next; in free_msr_counters_()
1855 pp = &p->next; in free_msr_counters_()
1867 sys.added_thread_counters -= free_msr_counters_(&sys.tp); in free_sys_msr_counters()
1870 sys.added_core_counters -= free_msr_counters_(&sys.cp); in free_sys_msr_counters()
1873 sys.added_package_counters -= free_msr_counters_(&sys.pp); in free_sys_msr_counters()
1891 int logical_node_id; /* 0-based count within the package */
1939 * skip non-present cpus
1956 if (cpu_is_not_allowed(t->cpu_id)) in for_all_cpus()
1976 return ((int)t->cpu_id == c->base_cpu || c->base_cpu < 0); in is_cpu_first_thread_in_core()
1983 return ((int)t->cpu_id == p->base_cpu || p->base_cpu < 0); in is_cpu_first_core_in_package()
1995 if (sched_setaffinity(0, cpu_affinity_setsize, cpu_affinity_set) == -1) in cpu_migrate()
1996 return -1; in cpu_migrate()
2014 err(-1, "%s open failed, try chown or chmod +r /dev/cpu/*/msr, " in get_msr_fd()
2015 "or run with --no-msr, or run as root", pathname); in get_msr_fd()
2042 const pid_t pid = -1; in open_perf_counter()
2066 …_count_percpu[cpu] = open_perf_counter(cpu, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, -1, 0); in get_instr_count_fd()
2080 err(-1, "cpu%d: msr offset 0x%llx read failed", cpu, (unsigned long long)offset); in get_msr()
2103 switch (pc->scope) { in cpu_to_domain()
2124 * HIDE_LIST - hide this list of counters, show the rest [default]
2125 * SHOW_LIST - show this list of counters, hide the rest
2132 "Usage: turbostat [OPTIONS][(--interval seconds) | COMMAND ...]\n" in help()
2136 "If no COMMAND is specified, turbostat wakes every 5-seconds\n" in help()
2138 " -a, --add add a counter\n" in help()
2139 " eg. --add msr0x10,u64,cpu,delta,MY_TSC\n" in help()
2140 " eg. --add perf/cstate_pkg/c2-residency,package,delta,percent,perfPC2\n" in help()
2141 " eg. --add pmt,name=XTAL,type=raw,domain=package0,offset=0,lsb=0,msb=63,guid=0x1a067102\n" in help()
2142 " -c, --cpu cpu-set limit output to summary plus cpu-set:\n" in help()
2143 " {core | package | j,k,l..m,n-p }\n" in help()
2144 " -d, --debug displays usec, Time_Of_Day_Seconds and more debugging\n" in help()
2146 " -D, --Dump displays the raw counter values\n" in help()
2147 " -e, --enable [all | column]\n" in help()
2149 " -H, --hide [column|column,column,...]\n" in help()
2151 " -i, --interval sec.subsec\n" in help()
2152 " Override default 5-second measurement interval\n" in help()
2153 " -J, --Joules displays energy in Joules instead of Watts\n" in help()
2154 " -l, --list list column headers only\n" in help()
2155 " -M, --no-msr Disable all uses of the MSR driver\n" in help()
2156 " -P, --no-perf Disable all uses of the perf API\n" in help()
2157 " -n, --num_iterations num\n" in help()
2159 " -N, --header_iterations num\n" in help()
2161 " -o, --out file\n" in help()
2163 " -q, --quiet skip decoding system configuration header\n" in help()
2164 " -s, --show [column|column,column,...]\n" in help()
2166 " -S, --Summary\n" in help()
2167 " limits output to 1-line system summary per interval\n" in help()
2168 " -T, --TCC temperature\n" in help()
2171 " -h, --help print this help message\n" in help()
2172 " -v, --version print version information\n" "\n" "For more help, run \"man turbostat\"\n"); in help()
2223 fprintf(stderr, "More than max %d un-recognized --add options '%s'\n", in bic_lookup()
2233 fprintf(stderr, "More than max %d un-recognized --skip options '%s'\n", in bic_lookup()
2296 for (mp = sys.tp; mp; mp = mp->next) { in print_header()
2298 if (mp->format == FORMAT_RAW) { in print_header()
2299 if (mp->width == 64) in print_header()
2300 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), mp->name); in print_header()
2302 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), mp->name); in print_header()
2304 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in print_header()
2305 outp += sprintf(outp, "%s%8s", (printed++ ? delim : ""), mp->name); in print_header()
2307 outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), mp->name); in print_header()
2311 for (pp = sys.perf_tp; pp; pp = pp->next) { in print_header()
2313 if (pp->format == FORMAT_RAW) { in print_header()
2314 if (pp->width == 64) in print_header()
2315 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), pp->name); in print_header()
2317 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), pp->name); in print_header()
2319 if ((pp->type == COUNTER_ITEMS) && sums_need_wide_columns) in print_header()
2320 outp += sprintf(outp, "%s%8s", (printed++ ? delim : ""), pp->name); in print_header()
2322 outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), pp->name); in print_header()
2328 switch (ppmt->type) { in print_header()
2331 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), ppmt->name); in print_header()
2333 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), ppmt->name); in print_header()
2338 outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), ppmt->name); in print_header()
2342 ppmt = ppmt->next; in print_header()
2363 if (platform->rapl_msrs && !rapl_joules) { in print_header()
2364 if (DO_BIC(BIC_CorWatt) && platform->has_per_core_rapl) in print_header()
2366 } else if (platform->rapl_msrs && rapl_joules) { in print_header()
2367 if (DO_BIC(BIC_Cor_J) && platform->has_per_core_rapl) in print_header()
2371 for (mp = sys.cp; mp; mp = mp->next) { in print_header()
2372 if (mp->format == FORMAT_RAW) { in print_header()
2373 if (mp->width == 64) in print_header()
2374 outp += sprintf(outp, "%s%18.18s", delim, mp->name); in print_header()
2376 outp += sprintf(outp, "%s%10.10s", delim, mp->name); in print_header()
2378 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in print_header()
2379 outp += sprintf(outp, "%s%8s", delim, mp->name); in print_header()
2381 outp += sprintf(outp, "%s%s", delim, mp->name); in print_header()
2385 for (pp = sys.perf_cp; pp; pp = pp->next) { in print_header()
2387 if (pp->format == FORMAT_RAW) { in print_header()
2388 if (pp->width == 64) in print_header()
2389 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), pp->name); in print_header()
2391 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), pp->name); in print_header()
2393 if ((pp->type == COUNTER_ITEMS) && sums_need_wide_columns) in print_header()
2394 outp += sprintf(outp, "%s%8s", (printed++ ? delim : ""), pp->name); in print_header()
2396 outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), pp->name); in print_header()
2402 switch (ppmt->type) { in print_header()
2405 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), ppmt->name); in print_header()
2407 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), ppmt->name); in print_header()
2412 outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), ppmt->name); in print_header()
2416 ppmt = ppmt->next; in print_header()
2470 if (platform->rapl_msrs && !rapl_joules) { in print_header()
2473 if (DO_BIC(BIC_CorWatt) && !platform->has_per_core_rapl) in print_header()
2483 } else if (platform->rapl_msrs && rapl_joules) { in print_header()
2486 if (DO_BIC(BIC_Cor_J) && !platform->has_per_core_rapl) in print_header()
2500 for (mp = sys.pp; mp; mp = mp->next) { in print_header()
2501 if (mp->format == FORMAT_RAW) { in print_header()
2502 if (mp->width == 64) in print_header()
2503 outp += sprintf(outp, "%s%18.18s", delim, mp->name); in print_header()
2504 else if (mp->width == 32) in print_header()
2505 outp += sprintf(outp, "%s%10.10s", delim, mp->name); in print_header()
2507 outp += sprintf(outp, "%s%7.7s", delim, mp->name); in print_header()
2509 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in print_header()
2510 outp += sprintf(outp, "%s%8s", delim, mp->name); in print_header()
2512 outp += sprintf(outp, "%s%7.7s", delim, mp->name); in print_header()
2516 for (pp = sys.perf_pp; pp; pp = pp->next) { in print_header()
2518 if (pp->format == FORMAT_RAW) { in print_header()
2519 if (pp->width == 64) in print_header()
2520 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), pp->name); in print_header()
2522 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), pp->name); in print_header()
2524 if ((pp->type == COUNTER_ITEMS) && sums_need_wide_columns) in print_header()
2525 outp += sprintf(outp, "%s%8s", (printed++ ? delim : ""), pp->name); in print_header()
2527 outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), pp->name); in print_header()
2533 switch (ppmt->type) { in print_header()
2536 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), ppmt->name); in print_header()
2538 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), ppmt->name); in print_header()
2543 outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), ppmt->name); in print_header()
2547 ppmt = ppmt->next; in print_header()
2567 outp += sprintf(outp, "CPU: %d flags 0x%x\n", t->cpu_id, t->flags); in dump_counters()
2568 outp += sprintf(outp, "TSC: %016llX\n", t->tsc); in dump_counters()
2569 outp += sprintf(outp, "aperf: %016llX\n", t->aperf); in dump_counters()
2570 outp += sprintf(outp, "mperf: %016llX\n", t->mperf); in dump_counters()
2571 outp += sprintf(outp, "c1: %016llX\n", t->c1); in dump_counters()
2574 outp += sprintf(outp, "IPC: %lld\n", t->instr_count); in dump_counters()
2577 outp += sprintf(outp, "IRQ: %lld\n", t->irq_count); in dump_counters()
2579 outp += sprintf(outp, "SMI: %d\n", t->smi_count); in dump_counters()
2581 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in dump_counters()
2583 sprintf(outp, "tADDED [%d] %8s msr0x%x: %08llX %s\n", i, mp->name, mp->msr_num, in dump_counters()
2584 t->counter[i], mp->sp->path); in dump_counters()
2589 outp += sprintf(outp, "core: %d\n", c->core_id); in dump_counters()
2590 outp += sprintf(outp, "c3: %016llX\n", c->c3); in dump_counters()
2591 outp += sprintf(outp, "c6: %016llX\n", c->c6); in dump_counters()
2592 outp += sprintf(outp, "c7: %016llX\n", c->c7); in dump_counters()
2593 outp += sprintf(outp, "DTS: %dC\n", c->core_temp_c); in dump_counters()
2594 outp += sprintf(outp, "cpu_throt_count: %016llX\n", c->core_throt_cnt); in dump_counters()
2596 const unsigned long long energy_value = c->core_energy.raw_value * c->core_energy.scale; in dump_counters()
2597 const double energy_scale = c->core_energy.scale; in dump_counters()
2599 if (c->core_energy.unit == RAPL_UNIT_JOULES) in dump_counters()
2602 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in dump_counters()
2604 sprintf(outp, "cADDED [%d] %8s msr0x%x: %08llX %s\n", i, mp->name, mp->msr_num, in dump_counters()
2605 c->counter[i], mp->sp->path); in dump_counters()
2607 outp += sprintf(outp, "mc6_us: %016llX\n", c->mc6_us); in dump_counters()
2611 outp += sprintf(outp, "package: %d\n", p->package_id); in dump_counters()
2613 outp += sprintf(outp, "Weighted cores: %016llX\n", p->pkg_wtd_core_c0); in dump_counters()
2614 outp += sprintf(outp, "Any cores: %016llX\n", p->pkg_any_core_c0); in dump_counters()
2615 outp += sprintf(outp, "Any GFX: %016llX\n", p->pkg_any_gfxe_c0); in dump_counters()
2616 outp += sprintf(outp, "CPU + GFX: %016llX\n", p->pkg_both_core_gfxe_c0); in dump_counters()
2618 outp += sprintf(outp, "pc2: %016llX\n", p->pc2); in dump_counters()
2620 outp += sprintf(outp, "pc3: %016llX\n", p->pc3); in dump_counters()
2622 outp += sprintf(outp, "pc6: %016llX\n", p->pc6); in dump_counters()
2624 outp += sprintf(outp, "pc7: %016llX\n", p->pc7); in dump_counters()
2625 outp += sprintf(outp, "pc8: %016llX\n", p->pc8); in dump_counters()
2626 outp += sprintf(outp, "pc9: %016llX\n", p->pc9); in dump_counters()
2627 outp += sprintf(outp, "pc10: %016llX\n", p->pc10); in dump_counters()
2628 outp += sprintf(outp, "cpu_lpi: %016llX\n", p->cpu_lpi); in dump_counters()
2629 outp += sprintf(outp, "sys_lpi: %016llX\n", p->sys_lpi); in dump_counters()
2630 outp += sprintf(outp, "Joules PKG: %0llX\n", p->energy_pkg.raw_value); in dump_counters()
2631 outp += sprintf(outp, "Joules COR: %0llX\n", p->energy_cores.raw_value); in dump_counters()
2632 outp += sprintf(outp, "Joules GFX: %0llX\n", p->energy_gfx.raw_value); in dump_counters()
2633 outp += sprintf(outp, "Joules RAM: %0llX\n", p->energy_dram.raw_value); in dump_counters()
2634 outp += sprintf(outp, "Joules PSYS: %0llX\n", pplat_cnt->energy_psys.raw_value); in dump_counters()
2635 outp += sprintf(outp, "Throttle PKG: %0llX\n", p->rapl_pkg_perf_status.raw_value); in dump_counters()
2636 outp += sprintf(outp, "Throttle RAM: %0llX\n", p->rapl_dram_perf_status.raw_value); in dump_counters()
2637 outp += sprintf(outp, "PTM: %dC\n", p->pkg_temp_c); in dump_counters()
2639 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in dump_counters()
2641 sprintf(outp, "pADDED [%d] %8s msr0x%x: %08llX %s\n", i, mp->name, mp->msr_num, in dump_counters()
2642 p->counter[i], mp->sp->path); in dump_counters()
2659 assert(c->unit == RAPL_UNIT_JOULES); in rapl_counter_get_value()
2661 const double scaled = c->raw_value * c->scale; in rapl_counter_get_value()
2698 /*if not summary line and --cpu is used */ in format_counters()
2699 …if ((t != &average.threads) && (cpu_subset && !CPU_ISSET_S(t->cpu_id, cpu_subset_size, cpu_subset)… in format_counters()
2706 timersub(&t->tv_end, &t->tv_begin, &tv); in format_counters()
2712 outp += sprintf(outp, "%10ld.%06ld\t", t->tv_end.tv_sec, t->tv_end.tv_usec); in format_counters()
2714 interval_float = t->tv_delta.tv_sec + t->tv_delta.tv_usec / 1000000.0; in format_counters()
2716 tsc = t->tsc * tsc_tweak; in format_counters()
2721 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2723 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2725 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2727 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2729 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2731 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2733 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2737 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->package_id); in format_counters()
2739 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2743 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), cpus[t->cpu_id].die_id); in format_counters()
2745 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2750 (printed++ ? delim : ""), cpus[t->cpu_id].physical_node_id); in format_counters()
2752 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2756 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), c->core_id); in format_counters()
2758 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2761 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->cpu_id); in format_counters()
2763 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->apic_id); in format_counters()
2765 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->x2apic_id); in format_counters()
2769 …outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), 1.0 / units * t->aperf / interval_float); in format_counters()
2772 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->mperf / tsc); in format_counters()
2777 sprintf(outp, "%s%.0f", (printed++ ? delim : ""), base_hz / units * t->aperf / t->mperf); in format_counters()
2780 tsc / units * t->aperf / t->mperf / interval_float); in format_counters()
2784 outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), 1.0 * t->tsc / units / interval_float); in format_counters()
2787 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 1.0 * t->instr_count / t->aperf); in format_counters()
2792 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), t->irq_count); in format_counters()
2794 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->irq_count); in format_counters()
2799 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->smi_count); in format_counters()
2802 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in format_counters()
2803 if (mp->format == FORMAT_RAW) { in format_counters()
2804 if (mp->width == 32) in format_counters()
2806 sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int)t->counter[i]); in format_counters()
2808 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), t->counter[i]); in format_counters()
2809 } else if (mp->format == FORMAT_DELTA) { in format_counters()
2810 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in format_counters()
2811 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), t->counter[i]); in format_counters()
2813 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->counter[i]); in format_counters()
2814 } else if (mp->format == FORMAT_PERCENT) { in format_counters()
2815 if (mp->type == COUNTER_USEC) in format_counters()
2818 t->counter[i] / interval_float / 10000); in format_counters()
2820 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->counter[i] / tsc); in format_counters()
2825 for (i = 0, pp = sys.perf_tp; pp; ++i, pp = pp->next) { in format_counters()
2826 if (pp->format == FORMAT_RAW) { in format_counters()
2827 if (pp->width == 32) in format_counters()
2830 (unsigned int)t->perf_counter[i]); in format_counters()
2832 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), t->perf_counter[i]); in format_counters()
2833 } else if (pp->format == FORMAT_DELTA) { in format_counters()
2834 if ((pp->type == COUNTER_ITEMS) && sums_need_wide_columns) in format_counters()
2835 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), t->perf_counter[i]); in format_counters()
2837 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->perf_counter[i]); in format_counters()
2838 } else if (pp->format == FORMAT_PERCENT) { in format_counters()
2839 if (pp->type == COUNTER_USEC) in format_counters()
2842 t->perf_counter[i] / interval_float / 10000); in format_counters()
2845 sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->perf_counter[i] / tsc); in format_counters()
2849 for (i = 0, ppmt = sys.pmt_tp; ppmt; i++, ppmt = ppmt->next) { in format_counters()
2850 const unsigned long value_raw = t->pmt_counter[i]; in format_counters()
2852 switch (ppmt->type) { in format_counters()
2856 (unsigned int)t->pmt_counter[i]); in format_counters()
2858 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), t->pmt_counter[i]); in format_counters()
2870 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->c1 / tsc); in format_counters()
2872 /* print per-core data only for 1st thread in core */ in format_counters()
2877 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c3 / tsc); in format_counters()
2879 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c6 / tsc); in format_counters()
2881 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c7 / tsc); in format_counters()
2885 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->mc6_us / tsc); in format_counters()
2888 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), c->core_temp_c); in format_counters()
2892 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), c->core_throt_cnt); in format_counters()
2894 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in format_counters()
2895 if (mp->format == FORMAT_RAW) { in format_counters()
2896 if (mp->width == 32) in format_counters()
2898 sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int)c->counter[i]); in format_counters()
2900 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), c->counter[i]); in format_counters()
2901 } else if (mp->format == FORMAT_DELTA) { in format_counters()
2902 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in format_counters()
2903 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), c->counter[i]); in format_counters()
2905 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), c->counter[i]); in format_counters()
2906 } else if (mp->format == FORMAT_PERCENT) { in format_counters()
2907 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->counter[i] / tsc); in format_counters()
2911 for (i = 0, pp = sys.perf_cp; pp; i++, pp = pp->next) { in format_counters()
2912 if (pp->format == FORMAT_RAW) { in format_counters()
2913 if (pp->width == 32) in format_counters()
2916 (unsigned int)c->perf_counter[i]); in format_counters()
2918 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), c->perf_counter[i]); in format_counters()
2919 } else if (pp->format == FORMAT_DELTA) { in format_counters()
2920 if ((pp->type == COUNTER_ITEMS) && sums_need_wide_columns) in format_counters()
2921 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), c->perf_counter[i]); in format_counters()
2923 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), c->perf_counter[i]); in format_counters()
2924 } else if (pp->format == FORMAT_PERCENT) { in format_counters()
2925 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->perf_counter[i] / tsc); in format_counters()
2929 for (i = 0, ppmt = sys.pmt_cp; ppmt; i++, ppmt = ppmt->next) { in format_counters()
2930 const unsigned long value_raw = c->pmt_counter[i]; in format_counters()
2932 switch (ppmt->type) { in format_counters()
2936 (unsigned int)c->pmt_counter[i]); in format_counters()
2938 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), c->pmt_counter[i]); in format_counters()
2950 if (DO_BIC(BIC_CorWatt) && platform->has_per_core_rapl) in format_counters()
2953 rapl_counter_get_value(&c->core_energy, RAPL_UNIT_WATTS, interval_float)); in format_counters()
2954 if (DO_BIC(BIC_Cor_J) && platform->has_per_core_rapl) in format_counters()
2956 rapl_counter_get_value(&c->core_energy, RAPL_UNIT_JOULES, interval_float)); in format_counters()
2958 /* print per-package data only for 1st core in package */ in format_counters()
2964 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->pkg_temp_c); in format_counters()
2968 if (p->gfx_rc6_ms == -1) { /* detect GFX counter reset */ in format_counters()
2972 p->gfx_rc6_ms / 10.0 / interval_float); in format_counters()
2978 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->gfx_mhz); in format_counters()
2982 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->gfx_act_mhz); in format_counters()
2986 if (p->sam_mc6_ms == -1) { /* detect GFX counter reset */ in format_counters()
2990 p->sam_mc6_ms / 10.0 / interval_float); in format_counters()
2996 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->sam_mhz); in format_counters()
3000 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->sam_act_mhz); in format_counters()
3004 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_wtd_core_c0 / tsc); in format_counters()
3006 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_any_core_c0 / tsc); in format_counters()
3008 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_any_gfxe_c0 / tsc); in format_counters()
3010 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_both_core_gfxe_c0 / tsc); in format_counters()
3013 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc2 / tsc); in format_counters()
3015 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc3 / tsc); in format_counters()
3017 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc6 / tsc); in format_counters()
3019 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc7 / tsc); in format_counters()
3021 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc8 / tsc); in format_counters()
3023 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc9 / tsc); in format_counters()
3025 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc10 / tsc); in format_counters()
3029 …sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->die_c6 / crystal_hz / interval_float); in format_counters()
3032 if (p->cpu_lpi >= 0) in format_counters()
3035 100.0 * p->cpu_lpi / 1000000.0 / interval_float); in format_counters()
3040 if (p->sys_lpi >= 0) in format_counters()
3043 100.0 * p->sys_lpi / 1000000.0 / interval_float); in format_counters()
3051 rapl_counter_get_value(&p->energy_pkg, RAPL_UNIT_WATTS, interval_float)); in format_counters()
3052 if (DO_BIC(BIC_CorWatt) && !platform->has_per_core_rapl) in format_counters()
3055 rapl_counter_get_value(&p->energy_cores, RAPL_UNIT_WATTS, interval_float)); in format_counters()
3059 rapl_counter_get_value(&p->energy_gfx, RAPL_UNIT_WATTS, interval_float)); in format_counters()
3063 rapl_counter_get_value(&p->energy_dram, RAPL_UNIT_WATTS, interval_float)); in format_counters()
3066 rapl_counter_get_value(&p->energy_pkg, RAPL_UNIT_JOULES, interval_float)); in format_counters()
3067 if (DO_BIC(BIC_Cor_J) && !platform->has_per_core_rapl) in format_counters()
3069 rapl_counter_get_value(&p->energy_cores, RAPL_UNIT_JOULES, interval_float)); in format_counters()
3072 rapl_counter_get_value(&p->energy_gfx, RAPL_UNIT_JOULES, interval_float)); in format_counters()
3075 rapl_counter_get_value(&p->energy_dram, RAPL_UNIT_JOULES, interval_float)); in format_counters()
3079 rapl_counter_get_value(&p->rapl_pkg_perf_status, RAPL_UNIT_WATTS, interval_float)); in format_counters()
3083 rapl_counter_get_value(&p->rapl_dram_perf_status, RAPL_UNIT_WATTS, interval_float)); in format_counters()
3086 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->uncore_mhz); in format_counters()
3088 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in format_counters()
3089 if (mp->format == FORMAT_RAW) { in format_counters()
3090 if (mp->width == 32) in format_counters()
3092 sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int)p->counter[i]); in format_counters()
3094 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), p->counter[i]); in format_counters()
3095 } else if (mp->format == FORMAT_DELTA) { in format_counters()
3096 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in format_counters()
3097 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), p->counter[i]); in format_counters()
3099 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), p->counter[i]); in format_counters()
3100 } else if (mp->format == FORMAT_PERCENT) { in format_counters()
3101 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->counter[i] / tsc); in format_counters()
3102 } else if (mp->type == COUNTER_K2M) in format_counters()
3103 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), (unsigned int)p->counter[i] / 1000); in format_counters()
3106 for (i = 0, pp = sys.perf_pp; pp; i++, pp = pp->next) { in format_counters()
3107 if (pp->format == FORMAT_RAW) { in format_counters()
3108 if (pp->width == 32) in format_counters()
3111 (unsigned int)p->perf_counter[i]); in format_counters()
3113 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), p->perf_counter[i]); in format_counters()
3114 } else if (pp->format == FORMAT_DELTA) { in format_counters()
3115 if ((pp->type == COUNTER_ITEMS) && sums_need_wide_columns) in format_counters()
3116 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), p->perf_counter[i]); in format_counters()
3118 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), p->perf_counter[i]); in format_counters()
3119 } else if (pp->format == FORMAT_PERCENT) { in format_counters()
3120 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->perf_counter[i] / tsc); in format_counters()
3121 } else if (pp->type == COUNTER_K2M) { in format_counters()
3123 sprintf(outp, "%s%d", (printed++ ? delim : ""), (unsigned int)p->perf_counter[i] / 1000); in format_counters()
3127 for (i = 0, ppmt = sys.pmt_pp; ppmt; i++, ppmt = ppmt->next) { in format_counters()
3128 const unsigned long value_raw = p->pmt_counter[i]; in format_counters()
3130 switch (ppmt->type) { in format_counters()
3134 (unsigned int)p->pmt_counter[i]); in format_counters()
3136 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), p->pmt_counter[i]); in format_counters()
3148 rapl_counter_get_value(&pplat_cnt->energy_psys, RAPL_UNIT_WATTS, interval_float)); in format_counters()
3151 rapl_counter_get_value(&pplat_cnt->energy_psys, RAPL_UNIT_JOULES, interval_float)); in format_counters()
3154 if (*(outp - 1) != '\n') in format_counters()
3200 old = ((((unsigned long long)new << 32) - ((unsigned long long)old << 32)) >> 32);
3210 old->pkg_wtd_core_c0 = new->pkg_wtd_core_c0 - old->pkg_wtd_core_c0; in delta_package()
3212 old->pkg_any_core_c0 = new->pkg_any_core_c0 - old->pkg_any_core_c0; in delta_package()
3214 old->pkg_any_gfxe_c0 = new->pkg_any_gfxe_c0 - old->pkg_any_gfxe_c0; in delta_package()
3216 old->pkg_both_core_gfxe_c0 = new->pkg_both_core_gfxe_c0 - old->pkg_both_core_gfxe_c0; in delta_package()
3218 old->pc2 = new->pc2 - old->pc2; in delta_package()
3220 old->pc3 = new->pc3 - old->pc3; in delta_package()
3222 old->pc6 = new->pc6 - old->pc6; in delta_package()
3224 old->pc7 = new->pc7 - old->pc7; in delta_package()
3225 old->pc8 = new->pc8 - old->pc8; in delta_package()
3226 old->pc9 = new->pc9 - old->pc9; in delta_package()
3227 old->pc10 = new->pc10 - old->pc10; in delta_package()
3228 old->die_c6 = new->die_c6 - old->die_c6; in delta_package()
3229 old->cpu_lpi = new->cpu_lpi - old->cpu_lpi; in delta_package()
3230 old->sys_lpi = new->sys_lpi - old->sys_lpi; in delta_package()
3231 old->pkg_temp_c = new->pkg_temp_c; in delta_package()
3234 if (old->gfx_rc6_ms > new->gfx_rc6_ms) in delta_package()
3235 old->gfx_rc6_ms = -1; in delta_package()
3237 old->gfx_rc6_ms = new->gfx_rc6_ms - old->gfx_rc6_ms; in delta_package()
3239 old->uncore_mhz = new->uncore_mhz; in delta_package()
3240 old->gfx_mhz = new->gfx_mhz; in delta_package()
3241 old->gfx_act_mhz = new->gfx_act_mhz; in delta_package()
3244 if (old->sam_mc6_ms > new->sam_mc6_ms) in delta_package()
3245 old->sam_mc6_ms = -1; in delta_package()
3247 old->sam_mc6_ms = new->sam_mc6_ms - old->sam_mc6_ms; in delta_package()
3249 old->sam_mhz = new->sam_mhz; in delta_package()
3250 old->sam_act_mhz = new->sam_act_mhz; in delta_package()
3252 old->energy_pkg.raw_value = new->energy_pkg.raw_value - old->energy_pkg.raw_value; in delta_package()
3253 old->energy_cores.raw_value = new->energy_cores.raw_value - old->energy_cores.raw_value; in delta_package()
3254 old->energy_gfx.raw_value = new->energy_gfx.raw_value - old->energy_gfx.raw_value; in delta_package()
3255 old->energy_dram.raw_value = new->energy_dram.raw_value - old->energy_dram.raw_value; in delta_package()
3256 …old->rapl_pkg_perf_status.raw_value = new->rapl_pkg_perf_status.raw_value - old->rapl_pkg_perf_sta… in delta_package()
3257 old->rapl_dram_perf_status.raw_value = in delta_package()
3258 new->rapl_dram_perf_status.raw_value - old->rapl_dram_perf_status.raw_value; in delta_package()
3260 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in delta_package()
3261 if (mp->format == FORMAT_RAW) in delta_package()
3262 old->counter[i] = new->counter[i]; in delta_package()
3263 else if (mp->format == FORMAT_AVERAGE) in delta_package()
3264 old->counter[i] = new->counter[i]; in delta_package()
3266 old->counter[i] = new->counter[i] - old->counter[i]; in delta_package()
3269 for (i = 0, pp = sys.perf_pp; pp; i++, pp = pp->next) { in delta_package()
3270 if (pp->format == FORMAT_RAW) in delta_package()
3271 old->perf_counter[i] = new->perf_counter[i]; in delta_package()
3272 else if (pp->format == FORMAT_AVERAGE) in delta_package()
3273 old->perf_counter[i] = new->perf_counter[i]; in delta_package()
3275 old->perf_counter[i] = new->perf_counter[i] - old->perf_counter[i]; in delta_package()
3278 for (i = 0, ppmt = sys.pmt_pp; ppmt; i++, ppmt = ppmt->next) { in delta_package()
3279 if (ppmt->format == FORMAT_RAW) in delta_package()
3280 old->pmt_counter[i] = new->pmt_counter[i]; in delta_package()
3282 old->pmt_counter[i] = new->pmt_counter[i] - old->pmt_counter[i]; in delta_package()
3295 old->c3 = new->c3 - old->c3; in delta_core()
3296 old->c6 = new->c6 - old->c6; in delta_core()
3297 old->c7 = new->c7 - old->c7; in delta_core()
3298 old->core_temp_c = new->core_temp_c; in delta_core()
3299 old->core_throt_cnt = new->core_throt_cnt; in delta_core()
3300 old->mc6_us = new->mc6_us - old->mc6_us; in delta_core()
3302 DELTA_WRAP32(new->core_energy.raw_value, old->core_energy.raw_value); in delta_core()
3304 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in delta_core()
3305 if (mp->format == FORMAT_RAW) in delta_core()
3306 old->counter[i] = new->counter[i]; in delta_core()
3308 old->counter[i] = new->counter[i] - old->counter[i]; in delta_core()
3311 for (i = 0, pp = sys.perf_cp; pp; i++, pp = pp->next) { in delta_core()
3312 if (pp->format == FORMAT_RAW) in delta_core()
3313 old->perf_counter[i] = new->perf_counter[i]; in delta_core()
3315 old->perf_counter[i] = new->perf_counter[i] - old->perf_counter[i]; in delta_core()
3318 for (i = 0, ppmt = sys.pmt_cp; ppmt; i++, ppmt = ppmt->next) { in delta_core()
3319 if (ppmt->format == FORMAT_RAW) in delta_core()
3320 old->pmt_counter[i] = new->pmt_counter[i]; in delta_core()
3322 old->pmt_counter[i] = new->pmt_counter[i] - old->pmt_counter[i]; in delta_core()
3328 if (!DO_BIC(BIC_CPU_c1) || platform->has_msr_core_c1_res) in soft_c1_residency_display()
3335 * old = new - old
3346 new->apic_id = old->apic_id; in delta_thread()
3348 new->x2apic_id = old->x2apic_id; in delta_thread()
3353 * over-write old w/ new so we can print end of interval values in delta_thread()
3356 timersub(&new->tv_begin, &old->tv_begin, &old->tv_delta); in delta_thread()
3357 old->tv_begin = new->tv_begin; in delta_thread()
3358 old->tv_end = new->tv_end; in delta_thread()
3360 old->tsc = new->tsc - old->tsc; in delta_thread()
3363 if (old->tsc < (1000 * 1000)) in delta_thread()
3364 errx(-3, "Insanely slow TSC rate, TSC stops in idle?\n" in delta_thread()
3365 "You can disable all c-states by booting with \"idle=poll\"\n" in delta_thread()
3368 old->c1 = new->c1 - old->c1; in delta_thread()
3372 if ((new->aperf > old->aperf) && (new->mperf > old->mperf)) { in delta_thread()
3373 old->aperf = new->aperf - old->aperf; in delta_thread()
3374 old->mperf = new->mperf - old->mperf; in delta_thread()
3376 return -1; in delta_thread()
3380 if (platform->has_msr_core_c1_res) { in delta_thread()
3388 * it is possible for mperf's non-halted cycles + idle states in delta_thread()
3391 if ((old->mperf + core_delta->c3 + core_delta->c6 + core_delta->c7) > (old->tsc * tsc_tweak)) in delta_thread()
3392 old->c1 = 0; in delta_thread()
3395 old->c1 = (old->tsc * tsc_tweak) - old->mperf - core_delta->c3 in delta_thread()
3396 - core_delta->c6 - core_delta->c7; in delta_thread()
3400 if (old->mperf == 0) { in delta_thread()
3402 fprintf(outf, "cpu%d MPERF 0!\n", old->cpu_id); in delta_thread()
3403 old->mperf = 1; /* divide by 0 protection */ in delta_thread()
3407 old->instr_count = new->instr_count - old->instr_count; in delta_thread()
3410 old->irq_count = new->irq_count - old->irq_count; in delta_thread()
3413 old->smi_count = new->smi_count - old->smi_count; in delta_thread()
3415 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in delta_thread()
3416 if (mp->format == FORMAT_RAW) in delta_thread()
3417 old->counter[i] = new->counter[i]; in delta_thread()
3419 old->counter[i] = new->counter[i] - old->counter[i]; in delta_thread()
3422 for (i = 0, pp = sys.perf_tp; pp; i++, pp = pp->next) { in delta_thread()
3423 if (pp->format == FORMAT_RAW) in delta_thread()
3424 old->perf_counter[i] = new->perf_counter[i]; in delta_thread()
3426 old->perf_counter[i] = new->perf_counter[i] - old->perf_counter[i]; in delta_thread()
3429 for (i = 0, ppmt = sys.pmt_tp; ppmt; i++, ppmt = ppmt->next) { in delta_thread()
3430 if (ppmt->format == FORMAT_RAW) in delta_thread()
3431 old->pmt_counter[i] = new->pmt_counter[i]; in delta_thread()
3433 old->pmt_counter[i] = new->pmt_counter[i] - old->pmt_counter[i]; in delta_thread()
3462 old->energy_psys.raw_value = new->energy_psys.raw_value - old->energy_psys.raw_value; in delta_platform()
3467 c->raw_value = 0; in rapl_counter_clear()
3468 c->scale = 0.0; in rapl_counter_clear()
3469 c->unit = RAPL_UNIT_INVALID; in rapl_counter_clear()
3477 t->tv_begin.tv_sec = 0; in clear_counters()
3478 t->tv_begin.tv_usec = 0; in clear_counters()
3479 t->tv_end.tv_sec = 0; in clear_counters()
3480 t->tv_end.tv_usec = 0; in clear_counters()
3481 t->tv_delta.tv_sec = 0; in clear_counters()
3482 t->tv_delta.tv_usec = 0; in clear_counters()
3484 t->tsc = 0; in clear_counters()
3485 t->aperf = 0; in clear_counters()
3486 t->mperf = 0; in clear_counters()
3487 t->c1 = 0; in clear_counters()
3489 t->instr_count = 0; in clear_counters()
3491 t->irq_count = 0; in clear_counters()
3492 t->smi_count = 0; in clear_counters()
3494 c->c3 = 0; in clear_counters()
3495 c->c6 = 0; in clear_counters()
3496 c->c7 = 0; in clear_counters()
3497 c->mc6_us = 0; in clear_counters()
3498 c->core_temp_c = 0; in clear_counters()
3499 rapl_counter_clear(&c->core_energy); in clear_counters()
3500 c->core_throt_cnt = 0; in clear_counters()
3502 p->pkg_wtd_core_c0 = 0; in clear_counters()
3503 p->pkg_any_core_c0 = 0; in clear_counters()
3504 p->pkg_any_gfxe_c0 = 0; in clear_counters()
3505 p->pkg_both_core_gfxe_c0 = 0; in clear_counters()
3507 p->pc2 = 0; in clear_counters()
3509 p->pc3 = 0; in clear_counters()
3511 p->pc6 = 0; in clear_counters()
3513 p->pc7 = 0; in clear_counters()
3514 p->pc8 = 0; in clear_counters()
3515 p->pc9 = 0; in clear_counters()
3516 p->pc10 = 0; in clear_counters()
3517 p->die_c6 = 0; in clear_counters()
3518 p->cpu_lpi = 0; in clear_counters()
3519 p->sys_lpi = 0; in clear_counters()
3521 rapl_counter_clear(&p->energy_pkg); in clear_counters()
3522 rapl_counter_clear(&p->energy_dram); in clear_counters()
3523 rapl_counter_clear(&p->energy_cores); in clear_counters()
3524 rapl_counter_clear(&p->energy_gfx); in clear_counters()
3525 rapl_counter_clear(&p->rapl_pkg_perf_status); in clear_counters()
3526 rapl_counter_clear(&p->rapl_dram_perf_status); in clear_counters()
3527 p->pkg_temp_c = 0; in clear_counters()
3529 p->gfx_rc6_ms = 0; in clear_counters()
3530 p->uncore_mhz = 0; in clear_counters()
3531 p->gfx_mhz = 0; in clear_counters()
3532 p->gfx_act_mhz = 0; in clear_counters()
3533 p->sam_mc6_ms = 0; in clear_counters()
3534 p->sam_mhz = 0; in clear_counters()
3535 p->sam_act_mhz = 0; in clear_counters()
3536 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) in clear_counters()
3537 t->counter[i] = 0; in clear_counters()
3539 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) in clear_counters()
3540 c->counter[i] = 0; in clear_counters()
3542 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) in clear_counters()
3543 p->counter[i] = 0; in clear_counters()
3545 memset(&t->perf_counter[0], 0, sizeof(t->perf_counter)); in clear_counters()
3546 memset(&c->perf_counter[0], 0, sizeof(c->perf_counter)); in clear_counters()
3547 memset(&p->perf_counter[0], 0, sizeof(p->perf_counter)); in clear_counters()
3549 memset(&t->pmt_counter[0], 0, ARRAY_SIZE(t->pmt_counter)); in clear_counters()
3550 memset(&c->pmt_counter[0], 0, ARRAY_SIZE(c->pmt_counter)); in clear_counters()
3551 memset(&p->pmt_counter[0], 0, ARRAY_SIZE(p->pmt_counter)); in clear_counters()
3557 if (dst->unit == RAPL_UNIT_INVALID) { in rapl_counter_accumulate()
3558 dst->unit = src->unit; in rapl_counter_accumulate()
3559 dst->scale = src->scale; in rapl_counter_accumulate()
3562 assert(dst->unit == src->unit); in rapl_counter_accumulate()
3563 assert(dst->scale == src->scale); in rapl_counter_accumulate()
3565 dst->raw_value += src->raw_value; in rapl_counter_accumulate()
3575 /* copy un-changing apic_id's */ in sum_counters()
3577 average.threads.apic_id = t->apic_id; in sum_counters()
3579 average.threads.x2apic_id = t->x2apic_id; in sum_counters()
3583 average.threads.tv_begin = t->tv_begin; in sum_counters()
3586 average.threads.tv_end = t->tv_end; in sum_counters()
3588 average.threads.tsc += t->tsc; in sum_counters()
3589 average.threads.aperf += t->aperf; in sum_counters()
3590 average.threads.mperf += t->mperf; in sum_counters()
3591 average.threads.c1 += t->c1; in sum_counters()
3593 average.threads.instr_count += t->instr_count; in sum_counters()
3595 average.threads.irq_count += t->irq_count; in sum_counters()
3596 average.threads.smi_count += t->smi_count; in sum_counters()
3598 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in sum_counters()
3599 if (mp->format == FORMAT_RAW) in sum_counters()
3601 average.threads.counter[i] += t->counter[i]; in sum_counters()
3604 for (i = 0, pp = sys.perf_tp; pp; i++, pp = pp->next) { in sum_counters()
3605 if (pp->format == FORMAT_RAW) in sum_counters()
3607 average.threads.perf_counter[i] += t->perf_counter[i]; in sum_counters()
3610 for (i = 0, ppmt = sys.pmt_tp; ppmt; i++, ppmt = ppmt->next) { in sum_counters()
3611 average.threads.pmt_counter[i] += t->pmt_counter[i]; in sum_counters()
3614 /* sum per-core values only for 1st thread in core */ in sum_counters()
3618 average.cores.c3 += c->c3; in sum_counters()
3619 average.cores.c6 += c->c6; in sum_counters()
3620 average.cores.c7 += c->c7; in sum_counters()
3621 average.cores.mc6_us += c->mc6_us; in sum_counters()
3623 average.cores.core_temp_c = MAX(average.cores.core_temp_c, c->core_temp_c); in sum_counters()
3624 average.cores.core_throt_cnt = MAX(average.cores.core_throt_cnt, c->core_throt_cnt); in sum_counters()
3626 rapl_counter_accumulate(&average.cores.core_energy, &c->core_energy); in sum_counters()
3628 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in sum_counters()
3629 if (mp->format == FORMAT_RAW) in sum_counters()
3631 average.cores.counter[i] += c->counter[i]; in sum_counters()
3634 for (i = 0, pp = sys.perf_cp; pp; i++, pp = pp->next) { in sum_counters()
3635 if (pp->format == FORMAT_RAW) in sum_counters()
3637 average.cores.perf_counter[i] += c->perf_counter[i]; in sum_counters()
3640 for (i = 0, ppmt = sys.pmt_cp; ppmt; i++, ppmt = ppmt->next) { in sum_counters()
3641 average.cores.pmt_counter[i] += c->pmt_counter[i]; in sum_counters()
3644 /* sum per-pkg values only for 1st core in pkg */ in sum_counters()
3649 average.packages.pkg_wtd_core_c0 += p->pkg_wtd_core_c0; in sum_counters()
3651 average.packages.pkg_any_core_c0 += p->pkg_any_core_c0; in sum_counters()
3653 average.packages.pkg_any_gfxe_c0 += p->pkg_any_gfxe_c0; in sum_counters()
3655 average.packages.pkg_both_core_gfxe_c0 += p->pkg_both_core_gfxe_c0; in sum_counters()
3657 average.packages.pc2 += p->pc2; in sum_counters()
3659 average.packages.pc3 += p->pc3; in sum_counters()
3661 average.packages.pc6 += p->pc6; in sum_counters()
3663 average.packages.pc7 += p->pc7; in sum_counters()
3664 average.packages.pc8 += p->pc8; in sum_counters()
3665 average.packages.pc9 += p->pc9; in sum_counters()
3666 average.packages.pc10 += p->pc10; in sum_counters()
3667 average.packages.die_c6 += p->die_c6; in sum_counters()
3669 average.packages.cpu_lpi = p->cpu_lpi; in sum_counters()
3670 average.packages.sys_lpi = p->sys_lpi; in sum_counters()
3672 rapl_counter_accumulate(&average.packages.energy_pkg, &p->energy_pkg); in sum_counters()
3673 rapl_counter_accumulate(&average.packages.energy_dram, &p->energy_dram); in sum_counters()
3674 rapl_counter_accumulate(&average.packages.energy_cores, &p->energy_cores); in sum_counters()
3675 rapl_counter_accumulate(&average.packages.energy_gfx, &p->energy_gfx); in sum_counters()
3677 average.packages.gfx_rc6_ms = p->gfx_rc6_ms; in sum_counters()
3678 average.packages.uncore_mhz = p->uncore_mhz; in sum_counters()
3679 average.packages.gfx_mhz = p->gfx_mhz; in sum_counters()
3680 average.packages.gfx_act_mhz = p->gfx_act_mhz; in sum_counters()
3681 average.packages.sam_mc6_ms = p->sam_mc6_ms; in sum_counters()
3682 average.packages.sam_mhz = p->sam_mhz; in sum_counters()
3683 average.packages.sam_act_mhz = p->sam_act_mhz; in sum_counters()
3685 average.packages.pkg_temp_c = MAX(average.packages.pkg_temp_c, p->pkg_temp_c); in sum_counters()
3687 rapl_counter_accumulate(&average.packages.rapl_pkg_perf_status, &p->rapl_pkg_perf_status); in sum_counters()
3688 rapl_counter_accumulate(&average.packages.rapl_dram_perf_status, &p->rapl_dram_perf_status); in sum_counters()
3690 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in sum_counters()
3691 if ((mp->format == FORMAT_RAW) && (topo.num_packages == 0)) in sum_counters()
3692 average.packages.counter[i] = p->counter[i]; in sum_counters()
3694 average.packages.counter[i] += p->counter[i]; in sum_counters()
3697 for (i = 0, pp = sys.perf_pp; pp; i++, pp = pp->next) { in sum_counters()
3698 if ((pp->format == FORMAT_RAW) && (topo.num_packages == 0)) in sum_counters()
3699 average.packages.perf_counter[i] = p->perf_counter[i]; in sum_counters()
3701 average.packages.perf_counter[i] += p->perf_counter[i]; in sum_counters()
3704 for (i = 0, ppmt = sys.pmt_pp; ppmt; i++, ppmt = ppmt->next) { in sum_counters()
3705 average.packages.pmt_counter[i] += p->pmt_counter[i]; in sum_counters()
3765 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in compute_average()
3766 if (mp->format == FORMAT_RAW) in compute_average()
3768 if (mp->type == COUNTER_ITEMS) { in compute_average()
3775 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in compute_average()
3776 if (mp->format == FORMAT_RAW) in compute_average()
3778 if (mp->type == COUNTER_ITEMS) { in compute_average()
3784 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in compute_average()
3785 if (mp->format == FORMAT_RAW) in compute_average()
3787 if (mp->type == COUNTER_ITEMS) { in compute_average()
3794 for (i = 0, pp = sys.perf_tp; pp; i++, pp = pp->next) { in compute_average()
3795 if (pp->format == FORMAT_RAW) in compute_average()
3797 if (pp->type == COUNTER_ITEMS) { in compute_average()
3804 for (i = 0, pp = sys.perf_cp; pp; i++, pp = pp->next) { in compute_average()
3805 if (pp->format == FORMAT_RAW) in compute_average()
3807 if (pp->type == COUNTER_ITEMS) { in compute_average()
3813 for (i = 0, pp = sys.perf_pp; pp; i++, pp = pp->next) { in compute_average()
3814 if (pp->format == FORMAT_RAW) in compute_average()
3816 if (pp->type == COUNTER_ITEMS) { in compute_average()
3823 for (i = 0, ppmt = sys.pmt_tp; ppmt; i++, ppmt = ppmt->next) { in compute_average()
3826 for (i = 0, ppmt = sys.pmt_cp; ppmt; i++, ppmt = ppmt->next) { in compute_average()
3829 for (i = 0, ppmt = sys.pmt_pp; ppmt; i++, ppmt = ppmt->next) { in compute_average()
3879 if (mp->msr_num != 0) { in get_mp()
3881 if (get_msr(cpu, mp->msr_num, counterp)) in get_mp()
3882 return -1; in get_mp()
3886 if (mp->flags & SYSFS_PERCPU) { in get_mp()
3887 sprintf(path, "/sys/devices/system/cpu/cpu%d/%s", cpu, mp->sp->path); in get_mp()
3927 int ret, epb = -1; in get_epb()
3946 return -1; in get_epb()
3961 t->apic_id = (ebx >> 24) & 0xff; in get_apic_id()
3983 t->x2apic_id = eax; in get_apic_id()
3995 t->x2apic_id = edx; in get_apic_id()
3997 if (debug && (t->apic_id != (t->x2apic_id & 0xff))) in get_apic_id()
3998 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()
4011 return -1; in get_core_throt_cnt()
4015 return -1; in get_core_throt_cnt()
4031 int ret = -1; in read_perf_counter_info()
4034 if (fdmt == -1) { in read_perf_counter_info()
4037 ret = -1; in read_perf_counter_info()
4041 bytes_read = read(fdmt, buf, sizeof(buf) - 1); in read_perf_counter_info()
4045 ret = -1; in read_perf_counter_info()
4054 ret = -1; in read_perf_counter_info()
4072 v = -1; in read_perf_counter_info_n()
4098 unsigned int ret = -1; in read_perf_config()
4104 return -1; in read_perf_config()
4175 if (rci->source[i] == COUNTER_SOURCE_PERF) in rapl_counter_info_count_perf()
4186 if (cci->source[i] == COUNTER_SOURCE_PERF) in cstate_counter_info_count_perf()
4194 if (rci->source[idx] == COUNTER_SOURCE_NONE) in write_rapl_counter()
4197 rc->raw_value = rci->data[idx]; in write_rapl_counter()
4198 rc->unit = rci->unit[idx]; in write_rapl_counter()
4199 rc->scale = rci->scale[idx]; in write_rapl_counter()
4219 if (rci->fd_perf != -1) { in get_rapl_counters()
4222 const ssize_t actual_read_size = read(rci->fd_perf, &perf_data[0], sizeof(perf_data)); in get_rapl_counters()
4225 err(-1, "%s: failed to read perf_data (%zu %zu)", __func__, expected_read_size, in get_rapl_counters()
4230 switch (rci->source[i]) { in get_rapl_counters()
4232 rci->data[i] = 0; in get_rapl_counters()
4237 assert(rci->fd_perf != -1); in get_rapl_counters()
4241 i, perf_data[pi], rci->scale[i], perf_data[pi] * rci->scale[i]); in get_rapl_counters()
4243 rci->data[i] = perf_data[pi]; in get_rapl_counters()
4253 if (rci->flags[i] & RAPL_COUNTER_FLAG_USE_MSR_SUM) { in get_rapl_counters()
4254 if (get_msr_sum(cpu, rci->msr[i], &rci->data[i])) in get_rapl_counters()
4255 return -13 - i; in get_rapl_counters()
4257 if (get_msr(cpu, rci->msr[i], &rci->data[i])) in get_rapl_counters()
4258 return -13 - i; in get_rapl_counters()
4261 rci->data[i] &= rci->msr_mask[i]; in get_rapl_counters()
4262 if (rci->msr_shift[i] >= 0) in get_rapl_counters()
4263 rci->data[i] >>= abs(rci->msr_shift[i]); in get_rapl_counters()
4265 rci->data[i] <<= abs(rci->msr_shift[i]); in get_rapl_counters()
4272 write_rapl_counter(&p->energy_pkg, rci, RAPL_RCI_INDEX_ENERGY_PKG); in get_rapl_counters()
4273 write_rapl_counter(&p->energy_cores, rci, RAPL_RCI_INDEX_ENERGY_CORES); in get_rapl_counters()
4274 write_rapl_counter(&p->energy_dram, rci, RAPL_RCI_INDEX_DRAM); in get_rapl_counters()
4275 write_rapl_counter(&p->energy_gfx, rci, RAPL_RCI_INDEX_GFX); in get_rapl_counters()
4276 write_rapl_counter(&p->rapl_pkg_perf_status, rci, RAPL_RCI_INDEX_PKG_PERF_STATUS); in get_rapl_counters()
4277 write_rapl_counter(&p->rapl_dram_perf_status, rci, RAPL_RCI_INDEX_DRAM_PERF_STATUS); in get_rapl_counters()
4278 write_rapl_counter(&c->core_energy, rci, RAPL_RCI_INDEX_CORE_ENERGY); in get_rapl_counters()
4279 write_rapl_counter(&pplat_cnt->energy_psys, rci, RAPL_RCI_INDEX_ENERGY_PLATFORM); in get_rapl_counters()
4287 if (sp->id == id) in find_sysfs_path_by_id()
4288 return (sp->path); in find_sysfs_path_by_id()
4289 sp = sp->next; in find_sysfs_path_by_id()
4327 if (cci->fd_perf_core != -1) { in get_cstate_counters()
4331 actual_read_size_core = read(cci->fd_perf_core, &perf_data_core[0], sizeof(perf_data_core)); in get_cstate_counters()
4334 err(-1, "%s: read perf %s: %ld", __func__, "core", actual_read_size_core); in get_cstate_counters()
4337 if (cci->fd_perf_pkg != -1) { in get_cstate_counters()
4341 actual_read_size_pkg = read(cci->fd_perf_pkg, &perf_data_pkg[0], sizeof(perf_data_pkg)); in get_cstate_counters()
4344 err(-1, "%s: read perf %s: %ld", __func__, "pkg", actual_read_size_pkg); in get_cstate_counters()
4350 …err(-1, "%s: failed to read perf_data (%zu %zu)", __func__, expected_read_size, actual_read_size_t… in get_cstate_counters()
4370 switch (cci->source[i]) { in get_cstate_counters()
4376 assert(cci->fd_perf_core != -1 || cci->fd_perf_pkg != -1); in get_cstate_counters()
4381 cci->data[i] = perf_data[pi]; in get_cstate_counters()
4388 if (get_msr(cpu, cci->msr[i], &cci->data[i])) in get_cstate_counters()
4389 return -13 - i; in get_cstate_counters()
4392 fprintf(stderr, "cstate via %s0x%llx %u: %llu\n", "msr", cci->msr[i], i, cci->data[i]); in get_cstate_counters()
4406 if (cci->source[index] != COUNTER_SOURCE_NONE) \ in get_cstate_counters()
4407 out_counter = cci->data[index]; \ in get_cstate_counters()
4412 PERF_COUNTER_WRITE_DATA(t->c1, CCSTATE_RCI_INDEX_C1_RESIDENCY); in get_cstate_counters()
4413 PERF_COUNTER_WRITE_DATA(c->c3, CCSTATE_RCI_INDEX_C3_RESIDENCY); in get_cstate_counters()
4414 PERF_COUNTER_WRITE_DATA(c->c6, CCSTATE_RCI_INDEX_C6_RESIDENCY); in get_cstate_counters()
4415 PERF_COUNTER_WRITE_DATA(c->c7, CCSTATE_RCI_INDEX_C7_RESIDENCY); in get_cstate_counters()
4417 PERF_COUNTER_WRITE_DATA(p->pc2, PCSTATE_RCI_INDEX_C2_RESIDENCY); in get_cstate_counters()
4418 PERF_COUNTER_WRITE_DATA(p->pc3, PCSTATE_RCI_INDEX_C3_RESIDENCY); in get_cstate_counters()
4419 PERF_COUNTER_WRITE_DATA(p->pc6, PCSTATE_RCI_INDEX_C6_RESIDENCY); in get_cstate_counters()
4420 PERF_COUNTER_WRITE_DATA(p->pc7, PCSTATE_RCI_INDEX_C7_RESIDENCY); in get_cstate_counters()
4421 PERF_COUNTER_WRITE_DATA(p->pc8, PCSTATE_RCI_INDEX_C8_RESIDENCY); in get_cstate_counters()
4422 PERF_COUNTER_WRITE_DATA(p->pc9, PCSTATE_RCI_INDEX_C9_RESIDENCY); in get_cstate_counters()
4423 PERF_COUNTER_WRITE_DATA(p->pc10, PCSTATE_RCI_INDEX_C10_RESIDENCY); in get_cstate_counters()
4435 if (mci->source[i] == COUNTER_SOURCE_PERF) in msr_counter_info_count_perf()
4456 ZERO_ARRAY(mci->data); in get_smi_aperf_mperf()
4458 if (mci->fd_perf != -1) { in get_smi_aperf_mperf()
4461 const ssize_t actual_read_size = read(mci->fd_perf, &perf_data[0], sizeof(perf_data)); in get_smi_aperf_mperf()
4464 err(-1, "%s: failed to read perf_data (%zu %zu)", __func__, expected_read_size, in get_smi_aperf_mperf()
4469 switch (mci->source[i]) { in get_smi_aperf_mperf()
4475 assert(mci->fd_perf != -1); in get_smi_aperf_mperf()
4480 mci->data[i] = perf_data[pi]; in get_smi_aperf_mperf()
4488 if (get_msr(cpu, mci->msr[i], &mci->data[i])) in get_smi_aperf_mperf()
4489 return -2 - i; in get_smi_aperf_mperf()
4491 mci->data[i] &= mci->msr_mask[i]; in get_smi_aperf_mperf()
4494 fprintf(stderr, "Reading msr counter via msr at %u: %llu\n", i, mci->data[i]); in get_smi_aperf_mperf()
4501 t->aperf = mci->data[MSR_RCI_INDEX_APERF]; in get_smi_aperf_mperf()
4502 t->mperf = mci->data[MSR_RCI_INDEX_MPERF]; in get_smi_aperf_mperf()
4503 t->smi_count = mci->data[MSR_RCI_INDEX_SMI]; in get_smi_aperf_mperf()
4514 for (size_t i = 0; pp; ++i, pp = pp->next) { in perf_counter_info_read_values()
4516 assert(domain < pp->num_domains); in perf_counter_info_read_values()
4518 fd_counter = pp->fd_perf_per_domain[domain]; in perf_counter_info_read_values()
4520 if (fd_counter == -1) in perf_counter_info_read_values()
4527 out[i] = value * pp->scale; in perf_counter_info_read_values()
4540 mask = ((1 << (msb + 1)) - 1); in pmt_gen_value_mask()
4542 mask -= (1 << lsb) - 1; in pmt_gen_value_mask()
4549 assert(domain_id < ppmt->num_domains); in pmt_read_counter()
4551 const unsigned long *pmmio = ppmt->domains[domain_id].pcounter; in pmt_read_counter()
4553 const unsigned long value_mask = pmt_gen_value_mask(ppmt->lsb, ppmt->msb); in pmt_read_counter()
4554 const unsigned long value_shift = ppmt->lsb; in pmt_read_counter()
4566 int cpu = t->cpu_id; in get_counters()
4575 return -1; in get_counters()
4578 gettimeofday(&t->tv_begin, (struct timezone *)NULL); in get_counters()
4583 t->tsc = rdtsc(); /* we are running on local CPU of interest */ in get_counters()
4588 if (read(get_instr_count_fd(cpu), &t->instr_count, sizeof(long long)) != sizeof(long long)) in get_counters()
4589 return -4; in get_counters()
4592 t->irq_count = irqs_per_cpu[cpu]; in get_counters()
4596 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in get_counters()
4597 if (get_mp(cpu, mp, &t->counter[i], mp->sp->path)) in get_counters()
4598 return -10; in get_counters()
4601 if (perf_counter_info_read_values(sys.perf_tp, cpu, t->perf_counter, MAX_ADDED_THREAD_COUNTERS)) in get_counters()
4602 return -10; in get_counters()
4604 for (i = 0, pp = sys.pmt_tp; pp; i++, pp = pp->next) in get_counters()
4605 t->pmt_counter[i] = pmt_read_counter(pp, t->cpu_id); in get_counters()
4611 if (platform->has_per_core_rapl) { in get_counters()
4612 status = get_rapl_counters(cpu, c->core_id, c, p); in get_counters()
4617 if (DO_BIC(BIC_CPU_c7) && t->is_atom) { in get_counters()
4624 c->c6 -= c->c7; in get_counters()
4628 if (get_msr(cpu, MSR_MODULE_C6_RES_MS, &c->mc6_us)) in get_counters()
4629 return -8; in get_counters()
4633 return -9; in get_counters()
4634 c->core_temp_c = tj_max - ((msr >> 16) & 0x7F); in get_counters()
4638 get_core_throt_cnt(cpu, &c->core_throt_cnt); in get_counters()
4640 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in get_counters()
4641 if (get_mp(cpu, mp, &c->counter[i], mp->sp->path)) in get_counters()
4642 return -10; in get_counters()
4645 if (perf_counter_info_read_values(sys.perf_cp, cpu, c->perf_counter, MAX_ADDED_CORE_COUNTERS)) in get_counters()
4646 return -10; in get_counters()
4648 for (i = 0, pp = sys.pmt_cp; pp; i++, pp = pp->next) in get_counters()
4649 c->pmt_counter[i] = pmt_read_counter(pp, c->core_id); in get_counters()
4656 if (get_msr(cpu, MSR_PKG_WEIGHTED_CORE_C0_RES, &p->pkg_wtd_core_c0)) in get_counters()
4657 return -10; in get_counters()
4660 if (get_msr(cpu, MSR_PKG_ANY_CORE_C0_RES, &p->pkg_any_core_c0)) in get_counters()
4661 return -11; in get_counters()
4664 if (get_msr(cpu, MSR_PKG_ANY_GFXE_C0_RES, &p->pkg_any_gfxe_c0)) in get_counters()
4665 return -12; in get_counters()
4668 if (get_msr(cpu, MSR_PKG_BOTH_CORE_GFXE_C0_RES, &p->pkg_both_core_gfxe_c0)) in get_counters()
4669 return -13; in get_counters()
4673 p->cpu_lpi = cpuidle_cur_cpu_lpi_us; in get_counters()
4675 p->sys_lpi = cpuidle_cur_sys_lpi_us; in get_counters()
4677 if (!platform->has_per_core_rapl) { in get_counters()
4678 status = get_rapl_counters(cpu, p->package_id, c, p); in get_counters()
4685 return -17; in get_counters()
4686 p->pkg_temp_c = tj_max - ((msr >> 16) & 0x7F); in get_counters()
4690 p->uncore_mhz = get_legacy_uncore_mhz(p->package_id); in get_counters()
4693 p->gfx_rc6_ms = gfx_info[GFX_rc6].val_ull; in get_counters()
4696 p->gfx_mhz = gfx_info[GFX_MHz].val; in get_counters()
4699 p->gfx_act_mhz = gfx_info[GFX_ACTMHz].val; in get_counters()
4702 p->sam_mc6_ms = gfx_info[SAM_mc6].val_ull; in get_counters()
4705 p->sam_mhz = gfx_info[SAM_MHz].val; in get_counters()
4708 p->sam_act_mhz = gfx_info[SAM_ACTMHz].val; in get_counters()
4710 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in get_counters()
4713 if (mp->msr_num == 0) { in get_counters()
4714 path = find_sysfs_path_by_id(mp->sp, p->package_id); in get_counters()
4716 warnx("%s: package_id %d not found", __func__, p->package_id); in get_counters()
4717 return -10; in get_counters()
4720 if (get_mp(cpu, mp, &p->counter[i], path)) in get_counters()
4721 return -10; in get_counters()
4724 if (perf_counter_info_read_values(sys.perf_pp, cpu, p->perf_counter, MAX_ADDED_PACKAGE_COUNTERS)) in get_counters()
4725 return -10; in get_counters()
4727 for (i = 0, pp = sys.pmt_pp; pp; i++, pp = pp->next) in get_counters()
4728 p->pmt_counter[i] = pmt_read_counter(pp, p->package_id); in get_counters()
4731 gettimeofday(&t->tv_end, (struct timezone *)NULL); in get_counters()
4791 if (!platform->has_nhm_msrs || no_msr) in probe_cst_limit()
4794 switch (platform->cst_limit) { in probe_cst_limit()
4835 if (!platform->has_nhm_msrs || no_msr) in dump_platform_info()
4853 if (!platform->has_nhm_msrs || no_msr) in dump_power_ctl()
4857 fprintf(outf, "cpu%d: MSR_IA32_POWER_CTL: 0x%08llx (C1E auto-promotion: %sabled)\n", in dump_power_ctl()
4858 base_cpu, msr, msr & 0x2 ? "EN" : "DIS"); in dump_power_ctl()
4860 /* C-state Pre-wake Disable (CSTATE_PREWAKE_DISABLE) */ in dump_power_ctl()
4861 if (platform->has_cst_prewake_bit) in dump_power_ctl()
4862 fprintf(outf, "C-state Pre-wake: %sabled\n", msr & 0x40000000 ? "DIS" : "EN"); in dump_power_ctl()
4938 if (platform->trl_msrs & TRL_CORECOUNT) { in dump_turbo_ratio_limits()
4945 for (shift = 56; shift >= 0; shift -= 8) { in dump_turbo_ratio_limits()
5014 * [0] -- Reserved in dump_knl_turbo_ratio_limits()
5015 * [7:1] -- Base value of number of active cores of bucket 1. in dump_knl_turbo_ratio_limits()
5016 * [15:8] -- Base value of freq ratio of bucket 1. in dump_knl_turbo_ratio_limits()
5017 * [20:16] -- +ve delta of number of active cores of bucket 2. in dump_knl_turbo_ratio_limits()
5020 * [23:21] -- Negative delta of freq ratio of bucket 2. in dump_knl_turbo_ratio_limits()
5022 * freq ratio of bucket 1 - delta in dump_knl_turbo_ratio_limits()
5023 * [28:24]-- +ve delta of number of active cores of bucket 3. in dump_knl_turbo_ratio_limits()
5024 * [31:29]-- -ve delta of freq ratio of bucket 3. in dump_knl_turbo_ratio_limits()
5025 * [36:32]-- +ve delta of number of active cores of bucket 4. in dump_knl_turbo_ratio_limits()
5026 * [39:37]-- -ve delta of freq ratio of bucket 4. in dump_knl_turbo_ratio_limits()
5027 * [44:40]-- +ve delta of number of active cores of bucket 5. in dump_knl_turbo_ratio_limits()
5028 * [47:45]-- -ve delta of freq ratio of bucket 5. in dump_knl_turbo_ratio_limits()
5029 * [52:48]-- +ve delta of number of active cores of bucket 6. in dump_knl_turbo_ratio_limits()
5030 * [55:53]-- -ve delta of freq ratio of bucket 6. in dump_knl_turbo_ratio_limits()
5031 * [60:56]-- +ve delta of number of active cores of bucket 7. in dump_knl_turbo_ratio_limits()
5032 * [63:61]-- -ve delta of freq ratio of bucket 7. in dump_knl_turbo_ratio_limits()
5044 ratio[b_nr + 1] = ratio[b_nr] - delta_ratio; in dump_knl_turbo_ratio_limits()
5048 for (i = buckets_no - 1; i >= 0; i--) in dump_knl_turbo_ratio_limits()
5049 if (i > 0 ? ratio[i] != ratio[i - 1] : 1) in dump_knl_turbo_ratio_limits()
5059 if (!platform->has_nhm_msrs || no_msr) in dump_cst_cfg()
5066 fprintf(outf, " (%s%s%s%s%slocked, pkg-cstate-limit=%d (%s)", in dump_cst_cfg()
5067 (msr & SNB_C3_AUTO_UNDEMOTE) ? "UNdemote-C3, " : "", in dump_cst_cfg()
5068 (msr & SNB_C1_AUTO_UNDEMOTE) ? "UNdemote-C1, " : "", in dump_cst_cfg()
5069 (msr & NHM_C3_AUTO_DEMOTE) ? "demote-C3, " : "", in dump_cst_cfg()
5070 (msr & NHM_C1_AUTO_DEMOTE) ? "demote-C1, " : "", in dump_cst_cfg()
5074 if (platform->has_cst_auto_convension) { in dump_cst_cfg()
5075 …fprintf(outf, ", automatic c-state conversion=%s", (msr & AUTOMATIC_CSTATE_CONVERSION) ? "on" : "o… in dump_cst_cfg()
5131 if (!platform->has_irtl_msrs || no_msr) in print_irtl()
5134 if (platform->supported_cstates & PC3) { in print_irtl()
5141 if (platform->supported_cstates & PC6) { in print_irtl()
5148 if (platform->supported_cstates & PC7) { in print_irtl()
5155 if (platform->supported_cstates & PC8) { in print_irtl()
5162 if (platform->supported_cstates & PC9) { in print_irtl()
5169 if (platform->supported_cstates & PC10) { in print_irtl()
5215 if (ccstate_counter_info[counter_id].fd_perf_core != -1) in free_fd_cstate()
5218 if (ccstate_counter_info[counter_id].fd_perf_pkg != -1) in free_fd_cstate()
5233 if (msr_counter_info[cpu].fd_perf != -1) in free_fd_msr()
5250 if (rapl_counter_info_perdomain[domain_id].fd_perf != -1) in free_fd_rapl_percpu()
5264 if (!pp->fd_perf_per_domain) in free_fd_added_perf_counters_()
5268 for (size_t domain = 0; domain < pp->num_domains; ++domain) { in free_fd_added_perf_counters_()
5269 if (pp->fd_perf_per_domain[domain] != -1) { in free_fd_added_perf_counters_()
5270 close(pp->fd_perf_per_domain[domain]); in free_fd_added_perf_counters_()
5271 pp->fd_perf_per_domain[domain] = -1; in free_fd_added_perf_counters_()
5275 free(pp->fd_perf_per_domain); in free_fd_added_perf_counters_()
5276 pp->fd_perf_per_domain = NULL; in free_fd_added_perf_counters_()
5278 pp = pp->next; in free_fd_added_perf_counters_()
5401 cpus[cpu].logical_node_id = -1; in set_node_data()
5410 if (cpus[cpu].logical_node_id != -1) in set_node_data()
5439 int cpu = thiscpu->logical_cpu_id; in get_physical_node_id()
5449 return -1; in get_physical_node_id()
5459 if (*next == '-') /* no negative cpu numbers */ in parse_cpu_str()
5479 if (*next == '-') { in parse_cpu_str()
5514 int cpu = thiscpu->logical_cpu_id; in get_thread_siblings()
5519 thiscpu->put_ids = CPU_ALLOC((topo.max_cpu_num + 1)); in get_thread_siblings()
5520 if (thiscpu->thread_id < 0) in get_thread_siblings()
5521 thiscpu->thread_id = thread_id++; in get_thread_siblings()
5522 if (!thiscpu->put_ids) in get_thread_siblings()
5523 return -1; in get_thread_siblings()
5526 CPU_ZERO_S(size, thiscpu->put_ids); in get_thread_siblings()
5533 return -1; in get_thread_siblings()
5536 offset -= BITMASK_SIZE; in get_thread_siblings()
5543 if (sib_core == thiscpu->physical_core_id) { in get_thread_siblings()
5544 CPU_SET_S(so, size, thiscpu->put_ids); in get_thread_siblings()
5553 return CPU_COUNT_S(size, thiscpu->put_ids); in get_thread_siblings()
5558 * skip non-present cpus
5579 if (cpu_is_not_allowed(t->cpu_id)) in for_all_cpus_2()
5688 fprintf(outf, "turbostat: re-initialized with num_cpus %d, allowed_cpus %d\n", topo.num_cpus, in re_initialize()
5709 topo.max_cpu_num--; /* 0 based */ in set_max_cpu_num()
5732 cpus[cpu].thread_id = -1; in init_thread_id()
5754 return -1; in set_cpu_hybrid_type()
5854 return -EINVAL; in snapshot_graphics()
5876 return -1; in snapshot_cpu_lpi_us()
5901 return -1; in snapshot_sys_lpi_us()
6027 /* get_msr_sum() = sum + (get_msr() - last) */ in get_msr_sum()
6044 int cpu = t->cpu_id; in update_msr_sum()
6100 if (timer_create(CLOCK_REALTIME, &sev, &timerid) == -1) { in msr_sum_record()
6116 if (timer_settime(timerid, 0, &its, NULL) == -1) { in msr_sum_record()
6131 * return value < -20 on failure
6140 if (errno && (original_priority == -1)) in set_my_sched_priority()
6141 return -21; in set_my_sched_priority()
6145 return -21; in set_my_sched_priority()
6150 return -21; in set_my_sched_priority()
6166 * ignore on error - we probably don't have permission to set it, but in turbostat_loop()
6169 set_my_sched_priority(-20); in turbostat_loop()
6177 if (retval < -1) { in turbostat_loop()
6179 } else if (retval == -1) { in turbostat_loop()
6203 if (retval < -1) { in turbostat_loop()
6205 } else if (retval == -1) { in turbostat_loop()
6227 if (retval < -1) { in turbostat_loop()
6229 } else if (retval == -1) { in turbostat_loop()
6290 if (cap_free(caps) == -1) in check_for_cap_sys_rawio()
6291 err(-6, "cap_free\n"); in check_for_cap_sys_rawio()
6315 … "\tRun as root to enable them or use %s to disable the access explicitly", pathname, "--no-msr"); in check_msr_permission()
6325 if (!platform->has_nhm_msrs || no_msr) in probe_bclk()
6328 if (platform->bclk_freq == BCLK_100MHZ) in probe_bclk()
6330 else if (platform->bclk_freq == BCLK_133MHZ) in probe_bclk()
6332 else if (platform->bclk_freq == BCLK_SLV) in probe_bclk()
6343 if (platform->enable_tsc_tweak) in probe_bclk()
6365 if (!platform->has_nhm_msrs || no_msr) in dump_turbo_ratio_info()
6368 if (platform->trl_msrs & TRL_LIMIT2) in dump_turbo_ratio_info()
6371 if (platform->trl_msrs & TRL_LIMIT1) in dump_turbo_ratio_info()
6374 if (platform->trl_msrs & TRL_BASE) { in dump_turbo_ratio_info()
6381 if (platform->trl_msrs & TRL_ATOM) in dump_turbo_ratio_info()
6384 if (platform->trl_msrs & TRL_KNL) in dump_turbo_ratio_info()
6387 if (platform->has_config_tdp) in dump_turbo_ratio_info()
6394 int retval = -1; in read_sysfs_int()
6400 return (-1); in read_sysfs_int()
6452 fprintf(outf, "Uncore Frequency package%d die%d: %d - %d MHz ", i, j, k / 1000, l / 1000); in probe_intel_uncore_frequency_legacy()
6458 fprintf(outf, "(%d - %d MHz)", k / 1000, l / 1000); in probe_intel_uncore_frequency_legacy()
6482 uncore_max_id -= 1; in probe_intel_uncore_frequency_cluster()
6486 for (i = uncore_max_id; i >= 0; --i) { in probe_intel_uncore_frequency_cluster()
6517 …fprintf(outf, "Uncore Frequency package%d domain%d cluster%d: %d - %d MHz ", package_id, domain_id, in probe_intel_uncore_frequency_cluster()
6524 fprintf(outf, "(%d - %d MHz)", k / 1000, l / 1000); in probe_intel_uncore_frequency_cluster()
6573 if (!strncmp(buf, "gt0-rc", strlen("gt0-rc"))) in probe_graphics()
6575 else if (!strncmp(buf, "gt0-mc", strlen("gt0-mc"))) in probe_graphics()
6680 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ in dump_sysfs_cstate_config()
6681 sp = strchr(name_buf, '-'); in dump_sysfs_cstate_config()
6766 cpu = t->cpu_id; in print_epb()
6768 /* EPB is per-package */ in print_epb()
6774 return -1; in print_epb()
6818 cpu = t->cpu_id; in print_hwp()
6820 /* MSR_HWP_CAPABILITIES is per-package */ in print_hwp()
6826 return -1; in print_hwp()
6832 fprintf(outf, "cpu%d: MSR_PM_ENABLE: 0x%08llx (%sHWP)\n", cpu, msr, (msr & (1 << 0)) ? "" : "No-"); in print_hwp()
6878 cpu, msr, ((msr) & 0x1) ? "EN" : "Dis", ((msr) & 0x2) ? "EN" : "Dis"); in print_hwp()
6885 cpu, msr, ((msr) & 0x1) ? "" : "No-", ((msr) & 0x4) ? "" : "No-"); in print_hwp()
6904 cpu = t->cpu_id; in print_perf_limit()
6906 /* per-package */ in print_perf_limit()
6912 return -1; in print_perf_limit()
6915 if (platform->plr_msrs & PLR_CORE) { in print_perf_limit()
6927 (msr & 1 << 6) ? "VR-Therm, " : "", in print_perf_limit()
6928 (msr & 1 << 5) ? "Auto-HWP, " : "", in print_perf_limit()
6938 (msr & 1 << 26) ? "PkgPwrL1, " : "", in print_perf_limit()
6941 (msr & 1 << 22) ? "VR-Therm, " : "", in print_perf_limit()
6942 (msr & 1 << 21) ? "Auto-HWP, " : "", in print_perf_limit()
6948 if (platform->plr_msrs & PLR_GFX) { in print_perf_limit()
6955 (msr & 1 << 6) ? "VR-Therm, " : "", in print_perf_limit()
6963 (msr & 1 << 22) ? "VR-Therm, " : "", in print_perf_limit()
6966 (msr & 1 << 26) ? "PkgPwrL1, " : "", (msr & 1 << 27) ? "PkgPwrL2, " : ""); in print_perf_limit()
6968 if (platform->plr_msrs & PLR_RING) { in print_perf_limit()
6974 (msr & 1 << 6) ? "VR-Therm, " : "", in print_perf_limit()
6980 (msr & 1 << 22) ? "VR-Therm, " : "", in print_perf_limit()
6982 (msr & 1 << 26) ? "PkgPwrL1, " : "", (msr & 1 << 27) ? "PkgPwrL2, " : ""); in print_perf_limit()
6992 if (platform->rapl_quirk_tdp) in get_quirk_tdp()
6993 return platform->rapl_quirk_tdp; in get_quirk_tdp()
7002 if (platform->rapl_msrs & RAPL_PKG_POWER_INFO) in get_tdp_intel()
7026 if (!(platform->rapl_msrs & RAPL_PKG_PERF_STATUS)) in rapl_probe_intel()
7028 if (!(platform->rapl_msrs & RAPL_DRAM_PERF_STATUS)) in rapl_probe_intel()
7036 if (platform->has_rapl_divisor) in rapl_probe_intel()
7041 if (platform->has_fixed_rapl_unit) in rapl_probe_intel()
7074 rapl_time_units = ldexp(1.0, -(msr >> 16 & 0xf)); in rapl_probe_amd()
7075 rapl_energy_units = ldexp(1.0, -(msr >> 8 & 0x1f)); in rapl_probe_amd()
7076 rapl_power_units = ldexp(1.0, -(msr & 0xf)); in rapl_probe_amd()
7089 ((msr >> 15) & 1) ? "EN" : "DIS", in print_power_limit_msr()
7092 (((msr >> 16) & 1) ? "EN" : "DIS")); in print_power_limit_msr()
7106 if (!platform->rapl_msrs) in print_rapl()
7113 cpu = t->cpu_id; in print_rapl()
7116 return -1; in print_rapl()
7119 if (platform->rapl_msrs & RAPL_AMD_F17H) { in print_rapl()
7122 return -1; in print_rapl()
7126 return -1; in print_rapl()
7132 if (platform->rapl_msrs & RAPL_PKG_POWER_INFO) { in print_rapl()
7135 return -5; in print_rapl()
7137 fprintf(outf, "cpu%d: MSR_PKG_POWER_INFO: 0x%08llx (%.0f W TDP, RAPL %.0f - %.0f W, %f sec.)\n", in print_rapl()
7145 if (platform->rapl_msrs & RAPL_PKG) { in print_rapl()
7148 return -9; in print_rapl()
7156 ((msr >> 47) & 1) ? "EN" : "DIS", in print_rapl()
7159 ((msr >> 48) & 1) ? "EN" : "DIS"); in print_rapl()
7162 return -9; in print_rapl()
7169 if (platform->rapl_msrs & RAPL_DRAM_POWER_INFO) { in print_rapl()
7171 return -6; in print_rapl()
7173 fprintf(outf, "cpu%d: MSR_DRAM_POWER_INFO,: 0x%08llx (%.0f W TDP, RAPL %.0f - %.0f W, %f sec.)\n", in print_rapl()
7180 if (platform->rapl_msrs & RAPL_DRAM) { in print_rapl()
7182 return -9; in print_rapl()
7188 if (platform->rapl_msrs & RAPL_CORE_POLICY) { in print_rapl()
7190 return -7; in print_rapl()
7194 if (platform->rapl_msrs & RAPL_CORE_POWER_LIMIT) { in print_rapl()
7196 return -9; in print_rapl()
7201 if (platform->rapl_msrs & RAPL_GFX) { in print_rapl()
7203 return -8; in print_rapl()
7208 return -9; in print_rapl()
7223 if (!platform->rapl_msrs || no_msr) in probe_rapl()
7243 * but also allow cmdline over-ride with -T.
7245 * Several MSR temperature values are in units of degrees-C
7262 /* this is a per-package concept */ in set_temperature_target()
7266 cpu = t->cpu_id; in set_temperature_target()
7269 return -1; in set_temperature_target()
7279 if (!platform->has_nhm_msrs || no_msr) in set_temperature_target()
7288 int bits = platform->tcc_offset_bits; in set_temperature_target()
7295 tcc_offset = (msr >> 24) & GENMASK(bits - 1, 0); in set_temperature_target()
7296 fprintf(outf, "cpu%d: MSR_IA32_TEMPERATURE_TARGET: 0x%08llx (%d C) (%d default - %d offset)\n", in set_temperature_target()
7297 cpu, msr, tcc_default - tcc_offset, tcc_default, tcc_offset); in set_temperature_target()
7312 fprintf(outf, "cpu%d: Guessing tjMax %d C, Please use -T to specify\n", cpu, tj_max); in set_temperature_target()
7332 cpu = t->cpu_id; in print_thermal()
7334 /* DTS is per-core, no need to print for each thread */ in print_thermal()
7340 return -1; in print_thermal()
7348 fprintf(outf, "cpu%d: MSR_IA32_PACKAGE_THERM_STATUS: 0x%08llx (%d C)\n", cpu, msr, tj_max - dts); in print_thermal()
7356 cpu, msr, tj_max - dts, tj_max - dts2); in print_thermal()
7367 fprintf(outf, "cpu%d: MSR_IA32_THERM_STATUS: 0x%08llx (%d C +/- %d)\n", in print_thermal()
7368 cpu, msr, tj_max - dts, resolution); in print_thermal()
7376 cpu, msr, tj_max - dts, tj_max - dts2); in print_thermal()
7407 if (cpu_migrate(t->cpu_id)) { in get_cpu_type()
7408 fprintf(outf, "Could not migrate to CPU %d\n", t->cpu_id); in get_cpu_type()
7409 return -1; in get_cpu_type()
7418 t->is_atom = true; in get_cpu_type()
7431 base_cpu, msr, msr & FEAT_CTL_LOCKED ? "" : "UN-", msr & (1 << 18) ? "SGX" : ""); in decode_feature_control_msr()
7447 msr & MSR_IA32_MISC_ENABLE_TM1 ? "" : "No-", in decode_misc_enable_msr()
7448 msr & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP ? "" : "No-", in decode_misc_enable_msr()
7449 msr & MSR_IA32_MISC_ENABLE_MWAIT ? "" : "No-", in decode_misc_enable_msr()
7450 msr & MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE ? "No-" : "", in decode_misc_enable_msr()
7451 msr & MSR_IA32_MISC_ENABLE_TURBO_DISABLE ? "No-" : ""); in decode_misc_enable_msr()
7461 if (!platform->has_msr_misc_feature_control) in decode_misc_feature_control()
7466 …"cpu%d: MSR_MISC_FEATURE_CONTROL: 0x%08llx (%sL2-Prefetch %sL2-Prefetch-pair %sL1-Prefetch %sL1-IP in decode_misc_feature_control()
7467 base_cpu, msr, msr & (0 << 0) ? "No-" : "", msr & (1 << 0) ? "No-" : "", in decode_misc_feature_control()
7468 msr & (2 << 0) ? "No-" : "", msr & (3 << 0) ? "No-" : ""); in decode_misc_feature_control()
7485 if (!platform->has_msr_misc_pwr_mgmt) in decode_misc_pwr_mgmt_msr()
7489 …fprintf(outf, "cpu%d: MSR_MISC_PWR_MGMT: 0x%08llx (%sable-EIST_Coordination %sable-EPB %sable-OOB)… in decode_misc_pwr_mgmt_msr()
7491 msr & (1 << 0) ? "DIS" : "EN", msr & (1 << 1) ? "EN" : "DIS", msr & (1 << 8) ? "EN" : "DIS"); in decode_misc_pwr_mgmt_msr()
7507 if (!platform->has_msr_c6_demotion_policy_config) in decode_c6_demotion_policy_msr()
7511 fprintf(outf, "cpu%d: MSR_CC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-CC6-Demotion)\n", in decode_c6_demotion_policy_msr()
7512 base_cpu, msr, msr & (1 << 0) ? "EN" : "DIS"); in decode_c6_demotion_policy_msr()
7515 fprintf(outf, "cpu%d: MSR_MC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-MC6-Demotion)\n", in decode_c6_demotion_policy_msr()
7516 base_cpu, msr, msr & (1 << 0) ? "EN" : "DIS"); in decode_c6_demotion_policy_msr()
7552 fd = open_perf_counter(base_cpu, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, -1, 0); in has_instr_count_access()
7553 has_access = fd != -1; in has_instr_count_access()
7555 if (fd != -1) in has_instr_count_access()
7561 "instructions retired perf counter", "--no-perf"); in has_instr_count_access()
7570 return -1; in add_rapl_perf_counter_()
7572 const double scale = read_perf_scale(cai->perf_subsys, cai->perf_name); in add_rapl_perf_counter_()
7575 return -1; in add_rapl_perf_counter_()
7577 const enum rapl_unit unit = read_perf_rapl_unit(cai->perf_subsys, cai->perf_name); in add_rapl_perf_counter_()
7580 return -1; in add_rapl_perf_counter_()
7582 const unsigned int rapl_type = read_perf_type(cai->perf_subsys); in add_rapl_perf_counter_()
7583 const unsigned int rapl_energy_pkg_config = read_perf_config(cai->perf_subsys, cai->perf_name); in add_rapl_perf_counter_()
7586 open_perf_counter(cpu, rapl_type, rapl_energy_pkg_config, rci->fd_perf, PERF_FORMAT_GROUP); in add_rapl_perf_counter_()
7587 if (fd_counter == -1) in add_rapl_perf_counter_()
7588 return -1; in add_rapl_perf_counter_()
7591 if (rci->fd_perf == -1) in add_rapl_perf_counter_()
7592 rci->fd_perf = fd_counter; in add_rapl_perf_counter_()
7611 * Linux-perf manages the HW instructions-retired counter
7622 err(-1, "calloc fd_instr_count_percpu"); in linux_perf_init()
7628 …const unsigned int num_domains = (platform->has_per_core_rapl ? topo.max_core_id : topo.max_packag… in rapl_perf_init()
7633 err(-1, "calloc rapl_counter_info_percpu"); in rapl_perf_init()
7642 rci->fd_perf = -1; in rapl_perf_init()
7644 rci->data[i] = 0; in rapl_perf_init()
7645 rci->source[i] = COUNTER_SOURCE_NONE; in rapl_perf_init()
7670 platform->has_per_core_rapl ? cpus[cpu].physical_core_id : cpus[cpu].physical_package_id; in rapl_perf_init()
7679 if ((cai->flags & RAPL_COUNTER_FLAG_PLATFORM_COUNTER) && (cpu != base_cpu)) in rapl_perf_init()
7685 if (BIC_IS_ENABLED(cai->bic) && (platform->rapl_msrs & cai->feature_mask)) { in rapl_perf_init()
7688 if (!no_perf && cai->perf_name in rapl_perf_init()
7689 && add_rapl_perf_counter(cpu, rci, cai, &scale, &unit) != -1) { in rapl_perf_init()
7690 rci->source[cai->rci_index] = COUNTER_SOURCE_PERF; in rapl_perf_init()
7691 rci->scale[cai->rci_index] = scale * cai->compat_scale; in rapl_perf_init()
7692 rci->unit[cai->rci_index] = unit; in rapl_perf_init()
7693 rci->flags[cai->rci_index] = cai->flags; in rapl_perf_init()
7696 } else if (!no_msr && cai->msr && probe_msr(cpu, cai->msr) == 0) { in rapl_perf_init()
7697 rci->source[cai->rci_index] = COUNTER_SOURCE_MSR; in rapl_perf_init()
7698 rci->msr[cai->rci_index] = cai->msr; in rapl_perf_init()
7699 rci->msr_mask[cai->rci_index] = cai->msr_mask; in rapl_perf_init()
7700 rci->msr_shift[cai->rci_index] = cai->msr_shift; in rapl_perf_init()
7701 rci->unit[cai->rci_index] = RAPL_UNIT_JOULES; in rapl_perf_init()
7702 rci->scale[cai->rci_index] = *cai->platform_rapl_msr_scale * cai->compat_scale; in rapl_perf_init()
7703 rci->flags[cai->rci_index] = cai->flags; in rapl_perf_init()
7707 if (rci->source[cai->rci_index] != COUNTER_SOURCE_NONE) in rapl_perf_init()
7713 BIC_PRESENT(cai->bic); in rapl_perf_init()
7729 return &cci->fd_perf_core; in get_cstate_perf_group_fd()
7732 return &cci->fd_perf_pkg; in get_cstate_perf_group_fd()
7740 return -1; in add_cstate_perf_counter_()
7742 int *pfd_group = get_cstate_perf_group_fd(cci, cai->perf_subsys); in add_cstate_perf_counter_()
7745 return -1; in add_cstate_perf_counter_()
7747 const unsigned int type = read_perf_type(cai->perf_subsys); in add_cstate_perf_counter_()
7748 const unsigned int config = read_perf_config(cai->perf_subsys, cai->perf_name); in add_cstate_perf_counter_()
7752 if (fd_counter == -1) in add_cstate_perf_counter_()
7753 return -1; in add_cstate_perf_counter_()
7756 if (*pfd_group == -1) in add_cstate_perf_counter_()
7775 return -1; in add_msr_perf_counter_()
7777 const unsigned int type = read_perf_type(cai->perf_subsys); in add_msr_perf_counter_()
7778 const unsigned int config = read_perf_config(cai->perf_subsys, cai->perf_name); in add_msr_perf_counter_()
7780 const int fd_counter = open_perf_counter(cpu, type, config, cci->fd_perf, PERF_FORMAT_GROUP); in add_msr_perf_counter_()
7782 if (fd_counter == -1) in add_msr_perf_counter_()
7783 return -1; in add_msr_perf_counter_()
7786 if (cci->fd_perf == -1) in add_msr_perf_counter_()
7787 cci->fd_perf = fd_counter; in add_msr_perf_counter_()
7797 …fprintf(stderr, "%s: %s/%s: %d (cpu: %d)\n", __func__, cai->perf_subsys, cai->perf_name, ret, cpu); in add_msr_perf_counter()
7812 msr_counter_info[cpu].fd_perf = -1; in msr_perf_init_()
7818 cai->present = false; in msr_perf_init_()
7827 if (cai->needed) { in msr_perf_init_()
7829 if (!no_perf && cai->perf_name && add_msr_perf_counter(cpu, cci, cai) != -1) { in msr_perf_init_()
7830 cci->source[cai->rci_index] = COUNTER_SOURCE_PERF; in msr_perf_init_()
7831 cai->present = true; in msr_perf_init_()
7834 } else if (!no_msr && cai->msr && probe_msr(cpu, cai->msr) == 0) { in msr_perf_init_()
7835 cci->source[cai->rci_index] = COUNTER_SOURCE_MSR; in msr_perf_init_()
7836 cci->msr[cai->rci_index] = cai->msr; in msr_perf_init_()
7837 cci->msr_mask[cai->rci_index] = cai->msr_mask; in msr_perf_init_()
7838 cai->present = true; in msr_perf_init_()
7849 const bool need_soft_c1 = (!platform->has_msr_core_c1_res) && (platform->supported_cstates & CC1); in msr_perf_init()
7903 ccstate_counter_info[cpu].fd_perf_core = -1; in cstate_perf_init_()
7904 ccstate_counter_info[cpu].fd_perf_pkg = -1; in cstate_perf_init_()
7927 const bool per_thread = cai->flags & CSTATE_COUNTER_FLAG_COLLECT_PER_THREAD; in cstate_perf_init_()
7928 const bool per_core = cai->flags & CSTATE_COUNTER_FLAG_COLLECT_PER_CORE; in cstate_perf_init_()
7936 const bool counter_needed = BIC_IS_ENABLED(cai->bic) || in cstate_perf_init_()
7937 (soft_c1 && (cai->flags & CSTATE_COUNTER_FLAG_SOFT_C1_DEPENDENCY)); in cstate_perf_init_()
7938 const bool counter_supported = (platform->supported_cstates & cai->feature_mask); in cstate_perf_init_()
7942 if (!no_perf && cai->perf_name && add_cstate_perf_counter(cpu, cci, cai) != -1) { in cstate_perf_init_()
7944 cci->source[cai->rci_index] = COUNTER_SOURCE_PERF; in cstate_perf_init_()
7947 } else if (!no_msr && cai->msr && pkg_cstate_limit >= cai->pkg_cstate_limit in cstate_perf_init_()
7948 && probe_msr(cpu, cai->msr) == 0) { in cstate_perf_init_()
7949 cci->source[cai->rci_index] = COUNTER_SOURCE_MSR; in cstate_perf_init_()
7950 cci->msr[cai->rci_index] = cai->msr; in cstate_perf_init_()
7954 if (cci->source[cai->rci_index] != COUNTER_SOURCE_NONE) { in cstate_perf_init_()
7963 BIC_PRESENT(cai->bic); in cstate_perf_init_()
7976 const bool soft_c1 = !platform->has_msr_core_c1_res && has_amperf_access() in cstate_perf_init()
7977 && platform->supported_cstates & CC1; in cstate_perf_init()
7989 if (platform->has_msr_module_c6_res_ms) in probe_cstates()
7992 if (platform->has_ext_cst_msrs && !no_msr) { in probe_cstates()
8104 ecx_flags & (1 << 0) ? "SSE3" : "-", in process_cpuid()
8105 ecx_flags & (1 << 3) ? "MONITOR" : "-", in process_cpuid()
8106 ecx_flags & (1 << 6) ? "SMX" : "-", in process_cpuid()
8107 ecx_flags & (1 << 7) ? "EIST" : "-", in process_cpuid()
8108 ecx_flags & (1 << 8) ? "TM2" : "-", in process_cpuid()
8109 edx_flags & (1 << 4) ? "TSC" : "-", in process_cpuid()
8110 edx_flags & (1 << 5) ? "MSR" : "-", in process_cpuid()
8111 edx_flags & (1 << 22) ? "ACPI-TM" : "-", in process_cpuid()
8112 edx_flags & (1 << 28) ? "HT" : "-", edx_flags & (1 << 29) ? "TM" : "-"); in process_cpuid()
8123 * Non-Stop TSC is advertised by CPUID.EAX=0x80000007: EDX.bit8 in process_cpuid()
8154 has_aperf ? "" : "No-", in process_cpuid()
8155 has_turbo ? "" : "No-", in process_cpuid()
8156 do_dts ? "" : "No-", in process_cpuid()
8157 do_ptm ? "" : "No-", in process_cpuid()
8158 has_hwp ? "" : "No-", in process_cpuid()
8159 has_hwp_notify ? "" : "No-", in process_cpuid()
8160 has_hwp_activity_window ? "" : "No-", in process_cpuid()
8161 has_hwp_epp ? "" : "No-", has_hwp_pkg ? "" : "No-", has_epb ? "" : "No-"); in process_cpuid()
8177 fprintf(outf, "CPUID(7): %sSGX %sHybrid\n", has_sgx ? "" : "No-", is_hybrid ? "" : "No-"); in process_cpuid()
8188 * CPUID 15H TSC/Crystal ratio, possibly Crystal Hz in process_cpuid()
8199 crystal_hz = platform->crystal_freq; in process_cpuid()
8224 if (platform->enable_tsc_tweak) in process_cpuid()
8233 aperf_mperf_multiplier = platform->need_perf_multiplier ? 1024 : 1; in process_cpuid()
8244 if (platform->has_msr_knl_core_c6_residency && cai->msr == MSR_CORE_C6_RESIDENCY) in counter_info_init()
8245 cai->msr = MSR_KNL_CORE_C6_RESIDENCY; in counter_info_init()
8247 if (!platform->has_msr_core_c1_res && cai->msr == MSR_CORE_C1_RES) in counter_info_init()
8248 cai->msr = 0; in counter_info_init()
8250 if (platform->has_msr_atom_pkg_c6_residency && cai->msr == MSR_PKG_C6_RESIDENCY) in counter_info_init()
8251 cai->msr = MSR_ATOM_PKG_C6_RESIDENCY; in counter_info_init()
8276 if (platform->has_nhm_msrs && !no_msr) in probe_pm_features()
8289 if (isdigit(dirp->d_name[0])) in dir_filter()
8380 err(-ENODEV, "No valid cpus found"); in topology_probe()
8494 (*t)[i].cpu_id = -1; in allocate_counters()
8501 (*c)[i].core_id = -1; in allocate_counters()
8502 (*c)[i].base_cpu = -1; in allocate_counters()
8511 (*p)[i].base_cpu = -1; in allocate_counters()
8534 /* Workaround for systems where physical_node_id==-1 in init_counter()
8535 * and logical_node_id==(-1 - topo.num_cpus) in init_counter()
8544 t->cpu_id = cpu_id; in init_counter()
8546 if (c->base_cpu < 0) in init_counter()
8547 c->base_cpu = t->cpu_id; in init_counter()
8548 if (p->base_cpu < 0) in init_counter()
8549 p->base_cpu = t->cpu_id; in init_counter()
8552 c->core_id = core_id; in init_counter()
8553 p->package_id = pkg_id; in init_counter()
8568 err(-1, "calloc output buffer"); in allocate_output_buffer()
8575 err(-1, "calloc fd_percpu"); in allocate_fd_percpu()
8582 err(-1, "calloc %d", topo.num_cpus); in allocate_irq_buffers()
8586 err(-1, "calloc %d", topo.max_cpu_num + 1); in allocate_irq_buffers()
8592 if ((int)t->cpu_id == c->base_cpu) in update_topo()
8594 if ((int)t->cpu_id == p->base_cpu) in update_topo()
8632 err(-ENODEV, "No valid cpus found"); in set_base_cpu()
8665 * -1: doesn't have separate perf device for p and e core in perf_has_hybrid_devices()
8676 cached = -1; in perf_has_hybrid_devices()
8681 cached = -1; in perf_has_hybrid_devices()
8706 switch (pinfo->scope) { in added_perf_counters_init_()
8721 pinfo->fd_perf_per_domain = calloc(num_domains, sizeof(*pinfo->fd_perf_per_domain)); in added_perf_counters_init_()
8722 if (!pinfo->fd_perf_per_domain) in added_perf_counters_init_()
8726 pinfo->fd_perf_per_domain[i] = -1; in added_perf_counters_init_()
8728 pinfo->num_domains = num_domains; in added_perf_counters_init_()
8729 pinfo->scale = 1.0; in added_perf_counters_init_()
8755 const char *perf_device = pinfo->device; in added_perf_counters_init_()
8773 if (perf_type == (unsigned int)-1) { in added_perf_counters_init_()
8775 __func__, perf_device, pinfo->event, "type"); in added_perf_counters_init_()
8779 perf_config = read_perf_config(perf_device, pinfo->event); in added_perf_counters_init_()
8780 if (perf_config == (unsigned int)-1) { in added_perf_counters_init_()
8782 __func__, perf_device, pinfo->event, "config"); in added_perf_counters_init_()
8787 perf_scale = read_perf_scale(perf_device, pinfo->event); in added_perf_counters_init_()
8791 fd_perf = open_perf_counter(cpu, perf_type, perf_config, -1, 0); in added_perf_counters_init_()
8792 if (fd_perf == -1) { in added_perf_counters_init_()
8794 __func__, perf_device, pinfo->event, cpu); in added_perf_counters_init_()
8799 pinfo->fd_perf_per_domain[next_domain] = fd_perf; in added_perf_counters_init_()
8800 pinfo->scale = perf_scale; in added_perf_counters_init_()
8804 perf_device, pinfo->event, cpu, pinfo->fd_perf_per_domain[next_domain]); in added_perf_counters_init_()
8807 pinfo = pinfo->next; in added_perf_counters_init_()
8834 if (fd_telem_info == -1) in parse_telem_info_file()
8835 return -1; in parse_telem_info_file()
8840 return -1; in parse_telem_info_file()
8845 return -1; in parse_telem_info_file()
8867 if (stat(SYSFS_TELEM_PATH, &st) == -1) in pmt_mmio_open()
8880 if (strcmp(entry->d_name, ".") == 0) in pmt_mmio_open()
8883 if (strcmp(entry->d_name, "..") == 0) in pmt_mmio_open()
8886 if (sscanf(entry->d_name, "telem%u", &telem_idx) != 1) in pmt_mmio_open()
8889 if (fstatat(dirfd(dirp), entry->d_name, &st, 0) == -1) { in pmt_mmio_open()
8896 fd_telem_dir = openat(dirfd(dirp), entry->d_name, O_RDONLY); in pmt_mmio_open()
8897 if (fd_telem_dir == -1) { in pmt_mmio_open()
8924 if (fd_pmt == -1) in pmt_mmio_open()
8941 ret->guid = guid; in pmt_mmio_open()
8942 ret->mmio_base = mmio; in pmt_mmio_open()
8943 ret->pmt_offset = offset; in pmt_mmio_open()
8944 ret->size = size; in pmt_mmio_open()
8946 ret->next = pmt_mmios; in pmt_mmio_open()
8966 if (pmmio->guid == guid) in pmt_mmio_find()
8969 pmmio = pmmio->next; in pmt_mmio_find()
8980 ret = (char *)pmmio->mmio_base; in pmt_get_counter_pointer()
8985 * - we might have to apply the offset first. in pmt_get_counter_pointer()
8987 ret += pmmio->pmt_offset; in pmt_get_counter_pointer()
9014 if (strcmp(pcounter->name, name) == 0) in pmt_find_counter()
9017 pcounter = pcounter->next; in pmt_find_counter()
9040 if (domain_id >= pcounter->num_domains) in pmt_counter_add_domain()
9043 assert(pcounter->domains); in pmt_counter_add_domain()
9044 assert(domain_id < pcounter->num_domains); in pmt_counter_add_domain()
9046 pcounter->domains[domain_id].pcounter = pmmio; in pmt_counter_add_domain()
9079 if (offset >= mmio->size) { in pmt_add_counter()
9081 fprintf(stderr, "%s: offset %u outside of PMT MMIO size %u\n", __func__, offset, mmio->size); in pmt_add_counter()
9095 strncpy(pcounter->name, name, ARRAY_SIZE(pcounter->name) - 1); in pmt_add_counter()
9096 pcounter->type = type; in pmt_add_counter()
9097 pcounter->scope = scope; in pmt_add_counter()
9098 pcounter->lsb = lsb; in pmt_add_counter()
9099 pcounter->msb = msb; in pmt_add_counter()
9100 pcounter->format = format; in pmt_add_counter()
9102 conflict += pcounter->type != type; in pmt_add_counter()
9103 conflict += pcounter->scope != scope; in pmt_add_counter()
9104 conflict += pcounter->lsb != lsb; in pmt_add_counter()
9105 conflict += pcounter->msb != msb; in pmt_add_counter()
9106 conflict += pcounter->format != format; in pmt_add_counter()
9118 pcounter->next = *pmt_root; in pmt_add_counter()
9153 if (BIC_IS_ENABLED(BIC_IPC) && has_aperf_access && get_instr_count_fd(base_cpu) != -1) in turbostat_init()
9160 if (platform->enable_tsc_tweak && !has_base_hz) { in turbostat_init()
9186 if (child_pid == -1) in fork_it()
9191 if (waitpid(child_pid, &status, 0) == -1) in fork_it()
9199 * because re-starting is problematic when forking in fork_it()
9239 fprintf(outf, "turbostat version 2024.11.30 - Len Brown <lenb@kernel.org>\n"); in print_version()
9255 ret = fread(bootcmd, sizeof(char), COMMAND_LINE_SIZE - 1, fp); in print_bootcmd()
9269 for (mp = head; mp; mp = mp->next) { in find_msrp_by_name()
9271 fprintf(stderr, "%s: %s %s\n", __func__, name, mp->name); in find_msrp_by_name()
9272 if (!strncmp(name, mp->name, strlen(mp->name))) in find_msrp_by_name()
9285 errx(1, "Requested MSR counter 0x%x, but in --no-msr mode", msr_num); in add_counter()
9302 return -1; in add_counter()
9314 return -1; in add_counter()
9326 return -1; in add_counter()
9331 return -1; in add_counter()
9337 err(-1, "calloc msr_counter"); in add_counter()
9339 msrp->msr_num = msr_num; in add_counter()
9340 strncpy(msrp->name, name, NAME_BYTES - 1); in add_counter()
9341 msrp->width = width; in add_counter()
9342 msrp->type = type; in add_counter()
9343 msrp->format = format; in add_counter()
9344 msrp->flags = flags; in add_counter()
9348 msrp->next = sys.tp; in add_counter()
9352 msrp->next = sys.cp; in add_counter()
9356 msrp->next = sys.pp; in add_counter()
9370 strncpy(sp->path, path, PATH_BYTES - 1); in add_counter()
9371 sp->id = id; in add_counter()
9372 sp->next = msrp->sp; in add_counter()
9373 msrp->sp = sp; in add_counter()
9399 strncpy(pinfo->device, perf_device, ARRAY_SIZE(pinfo->device) - 1); in make_perf_counter_info()
9400 strncpy(pinfo->event, perf_event, ARRAY_SIZE(pinfo->event) - 1); in make_perf_counter_info()
9402 strncpy(pinfo->name, name, ARRAY_SIZE(pinfo->name) - 1); in make_perf_counter_info()
9403 pinfo->width = width; in make_perf_counter_info()
9404 pinfo->scope = scope; in make_perf_counter_info()
9405 pinfo->type = type; in make_perf_counter_info()
9406 pinfo->format = format; in make_perf_counter_info()
9420 return -1; in add_perf_counter()
9427 return -1; in add_perf_counter()
9434 return -1; in add_perf_counter()
9442 return -1; in add_perf_counter()
9446 pinfo->next = sys.perf_tp; in add_perf_counter()
9452 pinfo->next = sys.perf_cp; in add_perf_counter()
9458 pinfo->next = sys.perf_pp; in add_perf_counter()
9467 __func__, pinfo->device, pinfo->event, pinfo->name, pinfo->scope); in add_perf_counter()
9564 fprintf(stderr, "--add: (msrDDD | msr0xXXX | /path_to_counter | perf/device/event ) required\n"); in parse_add_command_msr()
9568 /* Test for non-empty perf_device and perf_event */ in parse_add_command_msr()
9814 for (state = 10; state >= 0; --state) { in probe_sysfs()
9823 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ in probe_sysfs()
9824 sp = strchr(name_buf, '-'); in probe_sysfs()
9845 for (state = 10; state >= 0; --state) { in probe_sysfs()
9853 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ in probe_sysfs()
9854 sp = strchr(name_buf, '-'); in probe_sysfs()
9877 * 1,2,4..6,8-10 and set bits in cpu_subset
9909 fprintf(stderr, "\"--cpu %s\" malformed\n", optarg); in parse_cpu_command()
9911 exit(-1); in parse_cpu_command()
9929 { "hide", required_argument, 0, 'H' }, // meh, -h taken by --help in cmdline()
9934 { "no-msr", no_argument, 0, 'M' }, in cmdline()
9935 { "no-perf", no_argument, 0, 'P' }, in cmdline()
9947 * like adding the MSR counter with --add and at the same time using --no-msr. in cmdline()
9949 while ((opt = getopt_long_only(argc, argv, "+MPn:", long_options, &option_index)) != -1) { in cmdline()
9951 case 'M': in cmdline()
9963 …pt = getopt_long_only(argc, argv, "+C:c:Dde:hi:Jn:o:qMST:v", long_options, &option_index)) != -1) { in cmdline()
9981 /* --enable specified counter */ in cmdline()
9990 * --hide: do not show those specified in cmdline()
10009 interval_tv.tv_usec = (interval - interval_tv.tv_sec) * 1000000; in cmdline()
10010 interval_ts.tv_nsec = (interval - interval_ts.tv_sec) * 1000000000; in cmdline()
10027 case 'M': in cmdline()
10049 * --show: show only those specified in cmdline()
10098 if (ret == -1) in main()
10136 if (argc - optind) in main()