Lines Matching +full:ecx +full:- +full:1000

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
98 #define ROUND_UP_TO_PAGE_SIZE(n) (((n) + 0x1000UL-1UL) & ~(0x1000UL-1UL))
433 …bool has_per_core_rapl; /* Indicates cores energy collection is per-core, not per-package. AMD spe…
1080 unsigned int eax, ebx, ecx, edx; in probe_platform_features() local
1082 __cpuid(0x80000007, eax, ebx, ecx, edx); in probe_platform_features()
1118 /* MSRs that are not yet in the kernel-provided header. */
1198 .perf_name = "energy-pkg",
1211 .perf_name = "energy-pkg",
1224 .perf_name = "energy-cores",
1237 .perf_name = "energy-ram",
1250 .perf_name = "energy-gpu",
1302 .perf_name = "energy-psys",
1366 .perf_name = "c1-residency",
1376 .perf_name = "c3-residency",
1386 .perf_name = "c6-residency",
1396 .perf_name = "c7-residency",
1406 .perf_name = "c2-residency",
1416 .perf_name = "c3-residency",
1426 .perf_name = "c6-residency",
1436 .perf_name = "c7-residency",
1446 .perf_name = "c8-residency",
1456 .perf_name = "c9-residency",
1466 .perf_name = "c10-residency",
1602 /* BIC-like metadata */
1624 return sscanf(e->d_name, "telem%u", &dummy); in pmt_telemdir_filter()
1631 sscanf((*a)->d_name, "telem%u", &aidx); in pmt_telemdir_sort()
1632 sscanf((*b)->d_name, "telem%u", &bidx); in pmt_telemdir_sort()
1641 if (!iter->dir) in pmt_diriter_next()
1644 if (iter->current_name_idx >= iter->num_names) in pmt_diriter_next()
1647 ret = iter->namelist[iter->current_name_idx]; in pmt_diriter_next()
1648 ++iter->current_name_idx; in pmt_diriter_next()
1655 int num_names = iter->num_names; in pmt_diriter_begin()
1657 if (!iter->dir) { in pmt_diriter_begin()
1658 iter->dir = opendir(pmt_root_path); in pmt_diriter_begin()
1659 if (iter->dir == NULL) in pmt_diriter_begin()
1662 num_names = scandir(pmt_root_path, &iter->namelist, pmt_telemdir_filter, pmt_telemdir_sort); in pmt_diriter_begin()
1663 if (num_names == -1) in pmt_diriter_begin()
1667 iter->current_name_idx = 0; in pmt_diriter_begin()
1668 iter->num_names = num_names; in pmt_diriter_begin()
1680 if (iter->namelist) { in pmt_diriter_remove()
1681 for (unsigned int i = 0; i < iter->num_names; i++) { in pmt_diriter_remove()
1682 free(iter->namelist[i]); in pmt_diriter_remove()
1683 iter->namelist[i] = NULL; in pmt_diriter_remove()
1687 free(iter->namelist); in pmt_diriter_remove()
1688 iter->namelist = NULL; in pmt_diriter_remove()
1689 iter->num_names = 0; in pmt_diriter_remove()
1690 iter->current_name_idx = 0; in pmt_diriter_remove()
1692 closedir(iter->dir); in pmt_diriter_remove()
1693 iter->dir = NULL; in pmt_diriter_remove()
1698 return (p->msb - p->lsb) + 1; in pmt_counter_get_width()
1705 …new_mem = (struct pmt_domain_info *)reallocarray(pcounter->domains, new_size, sizeof(*pcounter->do… in pmt_counter_resize_()
1712 const size_t num_new_domains = new_size - pcounter->num_domains; in pmt_counter_resize_()
1714 memset(&new_mem[pcounter->num_domains], 0, num_new_domains * sizeof(*pcounter->domains)); in pmt_counter_resize_()
1716 pcounter->num_domains = new_size; in pmt_counter_resize_()
1717 pcounter->domains = new_mem; in pmt_counter_resize_()
1730 new_size = MAX(new_size, pcounter->num_domains * 2); in pmt_counter_resize()
1762 unsigned long long mc6_us; /* duplicate as per-core for now, even though per module */
1846 /* get_msr_sum() = sum + (get_msr() - last) */
1864 if (platform->rapl_msrs & RAPL_AMD_F17H) in idx_to_offset()
1888 offset = -1; in idx_to_offset()
1921 idx = -1; in offset_to_idx()
1930 return platform->rapl_msrs & (RAPL_PKG | RAPL_AMD_F17H); in idx_valid()
1932 return platform->rapl_msrs & RAPL_DRAM; in idx_valid()
1934 return platform->rapl_msrs & RAPL_CORE_ENERGY_STATUS; in idx_valid()
1936 return platform->rapl_msrs & RAPL_GFX; in idx_valid()
1938 return platform->rapl_msrs & RAPL_PKG_PERF_STATUS; in idx_valid()
1940 return platform->rapl_msrs & RAPL_DRAM_PERF_STATUS; in idx_valid()
1942 return platform->rapl_msrs & RAPL_PSYS; in idx_valid()
1978 if (p->msr_num != 0) { in free_msr_counters_()
1979 *pp = p->next; in free_msr_counters_()
1987 pp = &p->next; in free_msr_counters_()
1999 sys.added_thread_counters -= free_msr_counters_(&sys.tp); in free_sys_msr_counters()
2002 sys.added_core_counters -= free_msr_counters_(&sys.cp); in free_sys_msr_counters()
2005 sys.added_package_counters -= free_msr_counters_(&sys.pp); in free_sys_msr_counters()
2023 int logical_node_id; /* 0-based count within the package */
2072 * skip non-present cpus
2091 if (cpu_is_not_allowed(t->cpu_id)) in for_all_cpus()
2109 return ((int)t->cpu_id == c->base_cpu || c->base_cpu < 0); in is_cpu_first_thread_in_core()
2116 return ((int)t->cpu_id == p->base_cpu || p->base_cpu < 0); in is_cpu_first_core_in_package()
2128 if (sched_setaffinity(0, cpu_affinity_setsize, cpu_affinity_set) == -1) in cpu_migrate()
2129 return -1; in cpu_migrate()
2147 err(-1, "%s open failed, try chown or chmod +r /dev/cpu/*/msr, " in get_msr_fd()
2148 "or run with --no-msr, or run as root", pathname); in get_msr_fd()
2175 const pid_t pid = -1; in open_perf_counter()
2199 …_count_percpu[cpu] = open_perf_counter(cpu, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, -1, 0); in get_instr_count_fd()
2213 err(-1, "cpu%d: msr offset 0x%llx read failed", cpu, (unsigned long long)offset); in get_msr()
2249 switch (pc->scope) { in cpu_to_domain()
2270 * HIDE_LIST - hide this list of counters, show the rest [default]
2271 * SHOW_LIST - show this list of counters, hide the rest
2278 "Usage: turbostat [OPTIONS][(--interval seconds) | COMMAND ...]\n" in help()
2282 "If no COMMAND is specified, turbostat wakes every 5-seconds\n" in help()
2284 " -a, --add counter\n" in help()
2286 " eg. --add msr0x10,u64,cpu,delta,MY_TSC\n" in help()
2287 " eg. --add perf/cstate_pkg/c2-residency,package,delta,percent,perfPC2\n" in help()
2288 " eg. --add pmt,name=XTAL,type=raw,domain=package0,offset=0,lsb=0,msb=63,guid=0x1a067102\n" in help()
2289 " -c, --cpu cpu-set\n" in help()
2290 " limit output to summary plus cpu-set:\n" in help()
2291 " {core | package | j,k,l..m,n-p }\n" in help()
2292 " -d, --debug\n" in help()
2295 " -D, --Dump\n" in help()
2297 " -e, --enable [all | column]\n" in help()
2299 " -f, --force\n" in help()
2301 " -H, --hide [column | column,column,...]\n" in help()
2303 " -i, --interval sec.subsec\n" in help()
2304 " override default 5-second measurement interval\n" in help()
2305 " -J, --Joules\n" in help()
2307 " -l, --list\n" in help()
2309 " -M, --no-msr\n" in help()
2311 " -P, --no-perf\n" in help()
2313 " -n, --num_iterations num\n" in help()
2315 " -N, --header_iterations num\n" in help()
2317 " -o, --out file\n" in help()
2319 " -q, --quiet\n" in help()
2321 " -s, --show [column | column,column,...]\n" in help()
2323 " -S, --Summary\n" in help()
2324 " limits output to 1-line system summary per interval\n" in help()
2325 " -T, --TCC temperature\n" in help()
2328 " -h, --help\n" in help()
2330 " -v, --version\n" in help()
2392 fprintf(stderr, "More than max %d un-recognized --add options '%s'\n", in bic_lookup()
2402 fprintf(stderr, "More than max %d un-recognized --skip options '%s'\n", in bic_lookup()
2471 for (mp = sys.tp; mp; mp = mp->next) { in print_header()
2473 if (mp->format == FORMAT_RAW) { in print_header()
2474 if (mp->width == 64) in print_header()
2475 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), mp->name); in print_header()
2477 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), mp->name); in print_header()
2479 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in print_header()
2480 outp += sprintf(outp, "%s%8s", (printed++ ? delim : ""), mp->name); in print_header()
2482 outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), mp->name); in print_header()
2486 for (pp = sys.perf_tp; pp; pp = pp->next) { in print_header()
2488 if (pp->format == FORMAT_RAW) { in print_header()
2489 if (pp->width == 64) in print_header()
2490 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), pp->name); in print_header()
2492 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), pp->name); in print_header()
2494 if ((pp->type == COUNTER_ITEMS) && sums_need_wide_columns) in print_header()
2495 outp += sprintf(outp, "%s%8s", (printed++ ? delim : ""), pp->name); in print_header()
2497 outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), pp->name); in print_header()
2503 switch (ppmt->type) { in print_header()
2506 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), ppmt->name); in print_header()
2508 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), ppmt->name); in print_header()
2514 outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), ppmt->name); in print_header()
2518 ppmt = ppmt->next; in print_header()
2539 if (platform->rapl_msrs && !rapl_joules) { in print_header()
2540 if (DO_BIC(BIC_CorWatt) && platform->has_per_core_rapl) in print_header()
2542 } else if (platform->rapl_msrs && rapl_joules) { in print_header()
2543 if (DO_BIC(BIC_Cor_J) && platform->has_per_core_rapl) in print_header()
2547 for (mp = sys.cp; mp; mp = mp->next) { in print_header()
2548 if (mp->format == FORMAT_RAW) { in print_header()
2549 if (mp->width == 64) in print_header()
2550 outp += sprintf(outp, "%s%18.18s", delim, mp->name); in print_header()
2552 outp += sprintf(outp, "%s%10.10s", delim, mp->name); in print_header()
2554 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in print_header()
2555 outp += sprintf(outp, "%s%8s", delim, mp->name); in print_header()
2557 outp += sprintf(outp, "%s%s", delim, mp->name); in print_header()
2561 for (pp = sys.perf_cp; pp; pp = pp->next) { in print_header()
2563 if (pp->format == FORMAT_RAW) { in print_header()
2564 if (pp->width == 64) in print_header()
2565 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), pp->name); in print_header()
2567 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), pp->name); in print_header()
2569 if ((pp->type == COUNTER_ITEMS) && sums_need_wide_columns) in print_header()
2570 outp += sprintf(outp, "%s%8s", (printed++ ? delim : ""), pp->name); in print_header()
2572 outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), pp->name); in print_header()
2578 switch (ppmt->type) { in print_header()
2581 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), ppmt->name); in print_header()
2583 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), ppmt->name); in print_header()
2589 outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), ppmt->name); in print_header()
2593 ppmt = ppmt->next; in print_header()
2647 if (platform->rapl_msrs && !rapl_joules) { in print_header()
2650 if (DO_BIC(BIC_CorWatt) && !platform->has_per_core_rapl) in print_header()
2660 } else if (platform->rapl_msrs && rapl_joules) { in print_header()
2663 if (DO_BIC(BIC_Cor_J) && !platform->has_per_core_rapl) in print_header()
2677 for (mp = sys.pp; mp; mp = mp->next) { in print_header()
2678 if (mp->format == FORMAT_RAW) { in print_header()
2679 if (mp->width == 64) in print_header()
2680 outp += sprintf(outp, "%s%18.18s", delim, mp->name); in print_header()
2681 else if (mp->width == 32) in print_header()
2682 outp += sprintf(outp, "%s%10.10s", delim, mp->name); in print_header()
2684 outp += sprintf(outp, "%s%7.7s", delim, mp->name); in print_header()
2686 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in print_header()
2687 outp += sprintf(outp, "%s%8s", delim, mp->name); in print_header()
2689 outp += sprintf(outp, "%s%7.7s", delim, mp->name); in print_header()
2693 for (pp = sys.perf_pp; pp; pp = pp->next) { in print_header()
2695 if (pp->format == FORMAT_RAW) { in print_header()
2696 if (pp->width == 64) in print_header()
2697 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), pp->name); in print_header()
2699 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), pp->name); in print_header()
2701 if ((pp->type == COUNTER_ITEMS) && sums_need_wide_columns) in print_header()
2702 outp += sprintf(outp, "%s%8s", (printed++ ? delim : ""), pp->name); in print_header()
2704 outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), pp->name); in print_header()
2710 switch (ppmt->type) { in print_header()
2713 outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), ppmt->name); in print_header()
2715 outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), ppmt->name); in print_header()
2721 outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), ppmt->name); in print_header()
2725 ppmt = ppmt->next; in print_header()
2745 outp += sprintf(outp, "CPU: %d flags 0x%x\n", t->cpu_id, t->flags); in dump_counters()
2746 outp += sprintf(outp, "TSC: %016llX\n", t->tsc); in dump_counters()
2747 outp += sprintf(outp, "aperf: %016llX\n", t->aperf); in dump_counters()
2748 outp += sprintf(outp, "mperf: %016llX\n", t->mperf); in dump_counters()
2749 outp += sprintf(outp, "c1: %016llX\n", t->c1); in dump_counters()
2752 outp += sprintf(outp, "IPC: %lld\n", t->instr_count); in dump_counters()
2755 outp += sprintf(outp, "IRQ: %lld\n", t->irq_count); in dump_counters()
2757 outp += sprintf(outp, "IRQ: %lld\n", t->nmi_count); in dump_counters()
2759 outp += sprintf(outp, "SMI: %d\n", t->smi_count); in dump_counters()
2761 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in dump_counters()
2763 sprintf(outp, "tADDED [%d] %8s msr0x%x: %08llX %s\n", i, mp->name, mp->msr_num, in dump_counters()
2764 t->counter[i], mp->sp->path); in dump_counters()
2769 outp += sprintf(outp, "core: %d\n", c->core_id); in dump_counters()
2770 outp += sprintf(outp, "c3: %016llX\n", c->c3); in dump_counters()
2771 outp += sprintf(outp, "c6: %016llX\n", c->c6); in dump_counters()
2772 outp += sprintf(outp, "c7: %016llX\n", c->c7); in dump_counters()
2773 outp += sprintf(outp, "DTS: %dC\n", c->core_temp_c); in dump_counters()
2774 outp += sprintf(outp, "cpu_throt_count: %016llX\n", c->core_throt_cnt); in dump_counters()
2776 const unsigned long long energy_value = c->core_energy.raw_value * c->core_energy.scale; in dump_counters()
2777 const double energy_scale = c->core_energy.scale; in dump_counters()
2779 if (c->core_energy.unit == RAPL_UNIT_JOULES) in dump_counters()
2782 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in dump_counters()
2784 sprintf(outp, "cADDED [%d] %8s msr0x%x: %08llX %s\n", i, mp->name, mp->msr_num, in dump_counters()
2785 c->counter[i], mp->sp->path); in dump_counters()
2787 outp += sprintf(outp, "mc6_us: %016llX\n", c->mc6_us); in dump_counters()
2791 outp += sprintf(outp, "package: %d\n", p->package_id); in dump_counters()
2793 outp += sprintf(outp, "Weighted cores: %016llX\n", p->pkg_wtd_core_c0); in dump_counters()
2794 outp += sprintf(outp, "Any cores: %016llX\n", p->pkg_any_core_c0); in dump_counters()
2795 outp += sprintf(outp, "Any GFX: %016llX\n", p->pkg_any_gfxe_c0); in dump_counters()
2796 outp += sprintf(outp, "CPU + GFX: %016llX\n", p->pkg_both_core_gfxe_c0); in dump_counters()
2798 outp += sprintf(outp, "pc2: %016llX\n", p->pc2); in dump_counters()
2800 outp += sprintf(outp, "pc3: %016llX\n", p->pc3); in dump_counters()
2802 outp += sprintf(outp, "pc6: %016llX\n", p->pc6); in dump_counters()
2804 outp += sprintf(outp, "pc7: %016llX\n", p->pc7); in dump_counters()
2805 outp += sprintf(outp, "pc8: %016llX\n", p->pc8); in dump_counters()
2806 outp += sprintf(outp, "pc9: %016llX\n", p->pc9); in dump_counters()
2807 outp += sprintf(outp, "pc10: %016llX\n", p->pc10); in dump_counters()
2808 outp += sprintf(outp, "cpu_lpi: %016llX\n", p->cpu_lpi); in dump_counters()
2809 outp += sprintf(outp, "sys_lpi: %016llX\n", p->sys_lpi); in dump_counters()
2810 outp += sprintf(outp, "Joules PKG: %0llX\n", p->energy_pkg.raw_value); in dump_counters()
2811 outp += sprintf(outp, "Joules COR: %0llX\n", p->energy_cores.raw_value); in dump_counters()
2812 outp += sprintf(outp, "Joules GFX: %0llX\n", p->energy_gfx.raw_value); in dump_counters()
2813 outp += sprintf(outp, "Joules RAM: %0llX\n", p->energy_dram.raw_value); in dump_counters()
2814 outp += sprintf(outp, "Joules PSYS: %0llX\n", pplat_cnt->energy_psys.raw_value); in dump_counters()
2815 outp += sprintf(outp, "Throttle PKG: %0llX\n", p->rapl_pkg_perf_status.raw_value); in dump_counters()
2816 outp += sprintf(outp, "Throttle RAM: %0llX\n", p->rapl_dram_perf_status.raw_value); in dump_counters()
2817 outp += sprintf(outp, "PTM: %dC\n", p->pkg_temp_c); in dump_counters()
2819 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in dump_counters()
2821 sprintf(outp, "pADDED [%d] %8s msr0x%x: %08llX %s\n", i, mp->name, mp->msr_num, in dump_counters()
2822 p->counter[i], mp->sp->path); in dump_counters()
2839 assert(c->unit == RAPL_UNIT_JOULES); in rapl_counter_get_value()
2841 const double scaled = c->raw_value * c->scale; in rapl_counter_get_value()
2878 /*if not summary line and --cpu is used */ in format_counters()
2879 …if ((t != &average.threads) && (cpu_subset && !CPU_ISSET_S(t->cpu_id, cpu_subset_size, cpu_subset)… in format_counters()
2886 timersub(&t->tv_end, &t->tv_begin, &tv); in format_counters()
2892 outp += sprintf(outp, "%10ld.%06ld\t", t->tv_end.tv_sec, t->tv_end.tv_usec); in format_counters()
2894 interval_float = t->tv_delta.tv_sec + t->tv_delta.tv_usec / 1000000.0; in format_counters()
2896 tsc = t->tsc * tsc_tweak; in format_counters()
2901 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2903 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2905 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2907 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2909 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2911 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2913 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2917 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->package_id); in format_counters()
2919 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2923 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), cpus[t->cpu_id].die_id); in format_counters()
2925 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2930 (printed++ ? delim : ""), cpus[t->cpu_id].physical_node_id); in format_counters()
2932 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2936 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), c->core_id); in format_counters()
2938 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); in format_counters()
2941 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->cpu_id); in format_counters()
2943 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->apic_id); in format_counters()
2945 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->x2apic_id); in format_counters()
2949 …outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), 1.0 / units * t->aperf / interval_float); in format_counters()
2952 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->mperf / tsc); in format_counters()
2957 sprintf(outp, "%s%.0f", (printed++ ? delim : ""), base_hz / units * t->aperf / t->mperf); in format_counters()
2960 tsc / units * t->aperf / t->mperf / interval_float); in format_counters()
2964 outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), 1.0 * t->tsc / units / interval_float); in format_counters()
2967 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 1.0 * t->instr_count / t->aperf); in format_counters()
2972 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), t->irq_count); in format_counters()
2974 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->irq_count); in format_counters()
2980 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), t->nmi_count); in format_counters()
2982 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->nmi_count); in format_counters()
2987 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->smi_count); in format_counters()
2990 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in format_counters()
2991 if (mp->format == FORMAT_RAW) { in format_counters()
2992 if (mp->width == 32) in format_counters()
2994 sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int)t->counter[i]); in format_counters()
2996 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), t->counter[i]); in format_counters()
2997 } else if (mp->format == FORMAT_DELTA) { in format_counters()
2998 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in format_counters()
2999 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), t->counter[i]); in format_counters()
3001 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->counter[i]); in format_counters()
3002 } else if (mp->format == FORMAT_PERCENT) { in format_counters()
3003 if (mp->type == COUNTER_USEC) in format_counters()
3006 t->counter[i] / interval_float / 10000); in format_counters()
3008 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->counter[i] / tsc); in format_counters()
3013 for (i = 0, pp = sys.perf_tp; pp; ++i, pp = pp->next) { in format_counters()
3014 if (pp->format == FORMAT_RAW) { in format_counters()
3015 if (pp->width == 32) in format_counters()
3018 (unsigned int)t->perf_counter[i]); in format_counters()
3020 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), t->perf_counter[i]); in format_counters()
3021 } else if (pp->format == FORMAT_DELTA) { in format_counters()
3022 if ((pp->type == COUNTER_ITEMS) && sums_need_wide_columns) in format_counters()
3023 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), t->perf_counter[i]); in format_counters()
3025 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->perf_counter[i]); in format_counters()
3026 } else if (pp->format == FORMAT_PERCENT) { in format_counters()
3027 if (pp->type == COUNTER_USEC) in format_counters()
3030 t->perf_counter[i] / interval_float / 10000); in format_counters()
3033 sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->perf_counter[i] / tsc); in format_counters()
3037 for (i = 0, ppmt = sys.pmt_tp; ppmt; i++, ppmt = ppmt->next) { in format_counters()
3038 const unsigned long value_raw = t->pmt_counter[i]; in format_counters()
3040 switch (ppmt->type) { in format_counters()
3044 (unsigned int)t->pmt_counter[i]); in format_counters()
3046 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), t->pmt_counter[i]); in format_counters()
3063 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->c1 / tsc); in format_counters()
3065 /* print per-core data only for 1st thread in core */ in format_counters()
3070 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c3 / tsc); in format_counters()
3072 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c6 / tsc); in format_counters()
3074 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c7 / tsc); in format_counters()
3078 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->mc6_us / tsc); in format_counters()
3081 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), c->core_temp_c); in format_counters()
3085 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), c->core_throt_cnt); in format_counters()
3087 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in format_counters()
3088 if (mp->format == FORMAT_RAW) { in format_counters()
3089 if (mp->width == 32) in format_counters()
3091 sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int)c->counter[i]); in format_counters()
3093 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), c->counter[i]); in format_counters()
3094 } else if (mp->format == FORMAT_DELTA) { in format_counters()
3095 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in format_counters()
3096 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), c->counter[i]); in format_counters()
3098 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), c->counter[i]); in format_counters()
3099 } else if (mp->format == FORMAT_PERCENT) { in format_counters()
3100 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->counter[i] / tsc); in format_counters()
3104 for (i = 0, pp = sys.perf_cp; pp; i++, pp = pp->next) { in format_counters()
3105 if (pp->format == FORMAT_RAW) { in format_counters()
3106 if (pp->width == 32) in format_counters()
3109 (unsigned int)c->perf_counter[i]); in format_counters()
3111 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), c->perf_counter[i]); in format_counters()
3112 } else if (pp->format == FORMAT_DELTA) { in format_counters()
3113 if ((pp->type == COUNTER_ITEMS) && sums_need_wide_columns) in format_counters()
3114 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), c->perf_counter[i]); in format_counters()
3116 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), c->perf_counter[i]); in format_counters()
3117 } else if (pp->format == FORMAT_PERCENT) { in format_counters()
3118 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->perf_counter[i] / tsc); in format_counters()
3122 for (i = 0, ppmt = sys.pmt_cp; ppmt; i++, ppmt = ppmt->next) { in format_counters()
3123 const unsigned long value_raw = c->pmt_counter[i]; in format_counters()
3125 switch (ppmt->type) { in format_counters()
3129 (unsigned int)c->pmt_counter[i]); in format_counters()
3131 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), c->pmt_counter[i]); in format_counters()
3148 if (DO_BIC(BIC_CorWatt) && platform->has_per_core_rapl) in format_counters()
3151 rapl_counter_get_value(&c->core_energy, RAPL_UNIT_WATTS, interval_float)); in format_counters()
3152 if (DO_BIC(BIC_Cor_J) && platform->has_per_core_rapl) in format_counters()
3154 rapl_counter_get_value(&c->core_energy, RAPL_UNIT_JOULES, interval_float)); in format_counters()
3156 /* print per-package data only for 1st core in package */ in format_counters()
3162 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->pkg_temp_c); in format_counters()
3166 if (p->gfx_rc6_ms == -1) { /* detect GFX counter reset */ in format_counters()
3170 p->gfx_rc6_ms / 10.0 / interval_float); in format_counters()
3176 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->gfx_mhz); in format_counters()
3180 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->gfx_act_mhz); in format_counters()
3184 if (p->sam_mc6_ms == -1) { /* detect GFX counter reset */ in format_counters()
3188 p->sam_mc6_ms / 10.0 / interval_float); in format_counters()
3194 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->sam_mhz); in format_counters()
3198 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->sam_act_mhz); in format_counters()
3202 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_wtd_core_c0 / tsc); in format_counters()
3204 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_any_core_c0 / tsc); in format_counters()
3206 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_any_gfxe_c0 / tsc); in format_counters()
3208 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_both_core_gfxe_c0 / tsc); in format_counters()
3211 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc2 / tsc); in format_counters()
3213 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc3 / tsc); in format_counters()
3215 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc6 / tsc); in format_counters()
3217 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc7 / tsc); in format_counters()
3219 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc8 / tsc); in format_counters()
3221 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc9 / tsc); in format_counters()
3223 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc10 / tsc); in format_counters()
3227 …sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->die_c6 / crystal_hz / interval_float); in format_counters()
3230 if (p->cpu_lpi >= 0) in format_counters()
3233 100.0 * p->cpu_lpi / 1000000.0 / interval_float); in format_counters()
3238 if (p->sys_lpi >= 0) in format_counters()
3241 100.0 * p->sys_lpi / 1000000.0 / interval_float); in format_counters()
3249 rapl_counter_get_value(&p->energy_pkg, RAPL_UNIT_WATTS, interval_float)); in format_counters()
3250 if (DO_BIC(BIC_CorWatt) && !platform->has_per_core_rapl) in format_counters()
3253 rapl_counter_get_value(&p->energy_cores, RAPL_UNIT_WATTS, interval_float)); in format_counters()
3257 rapl_counter_get_value(&p->energy_gfx, RAPL_UNIT_WATTS, interval_float)); in format_counters()
3261 rapl_counter_get_value(&p->energy_dram, RAPL_UNIT_WATTS, interval_float)); in format_counters()
3264 rapl_counter_get_value(&p->energy_pkg, RAPL_UNIT_JOULES, interval_float)); in format_counters()
3265 if (DO_BIC(BIC_Cor_J) && !platform->has_per_core_rapl) in format_counters()
3267 rapl_counter_get_value(&p->energy_cores, RAPL_UNIT_JOULES, interval_float)); in format_counters()
3270 rapl_counter_get_value(&p->energy_gfx, RAPL_UNIT_JOULES, interval_float)); in format_counters()
3273 rapl_counter_get_value(&p->energy_dram, RAPL_UNIT_JOULES, interval_float)); in format_counters()
3277 rapl_counter_get_value(&p->rapl_pkg_perf_status, RAPL_UNIT_WATTS, interval_float)); in format_counters()
3281 rapl_counter_get_value(&p->rapl_dram_perf_status, RAPL_UNIT_WATTS, interval_float)); in format_counters()
3284 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->uncore_mhz); in format_counters()
3286 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in format_counters()
3287 if (mp->format == FORMAT_RAW) { in format_counters()
3288 if (mp->width == 32) in format_counters()
3290 sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int)p->counter[i]); in format_counters()
3292 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), p->counter[i]); in format_counters()
3293 } else if (mp->format == FORMAT_DELTA) { in format_counters()
3294 if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) in format_counters()
3295 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), p->counter[i]); in format_counters()
3297 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), p->counter[i]); in format_counters()
3298 } else if (mp->format == FORMAT_PERCENT) { in format_counters()
3299 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->counter[i] / tsc); in format_counters()
3300 } else if (mp->type == COUNTER_K2M) in format_counters()
3301 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), (unsigned int)p->counter[i] / 1000); in format_counters()
3304 for (i = 0, pp = sys.perf_pp; pp; i++, pp = pp->next) { in format_counters()
3305 if (pp->format == FORMAT_RAW) { in format_counters()
3306 if (pp->width == 32) in format_counters()
3309 (unsigned int)p->perf_counter[i]); in format_counters()
3311 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), p->perf_counter[i]); in format_counters()
3312 } else if (pp->format == FORMAT_DELTA) { in format_counters()
3313 if ((pp->type == COUNTER_ITEMS) && sums_need_wide_columns) in format_counters()
3314 outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), p->perf_counter[i]); in format_counters()
3316 outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), p->perf_counter[i]); in format_counters()
3317 } else if (pp->format == FORMAT_PERCENT) { in format_counters()
3318 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->perf_counter[i] / tsc); in format_counters()
3319 } else if (pp->type == COUNTER_K2M) { in format_counters()
3321 sprintf(outp, "%s%d", (printed++ ? delim : ""), (unsigned int)p->perf_counter[i] / 1000); in format_counters()
3325 for (i = 0, ppmt = sys.pmt_pp; ppmt; i++, ppmt = ppmt->next) { in format_counters()
3326 const unsigned long value_raw = p->pmt_counter[i]; in format_counters()
3328 switch (ppmt->type) { in format_counters()
3332 (unsigned int)p->pmt_counter[i]); in format_counters()
3334 outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), p->pmt_counter[i]); in format_counters()
3351 rapl_counter_get_value(&pplat_cnt->energy_psys, RAPL_UNIT_WATTS, interval_float)); in format_counters()
3354 rapl_counter_get_value(&pplat_cnt->energy_psys, RAPL_UNIT_JOULES, interval_float)); in format_counters()
3357 if (*(outp - 1) != '\n') in format_counters()
3403 old = ((((unsigned long long)new << 32) - ((unsigned long long)old << 32)) >> 32);
3413 old->pkg_wtd_core_c0 = new->pkg_wtd_core_c0 - old->pkg_wtd_core_c0; in delta_package()
3415 old->pkg_any_core_c0 = new->pkg_any_core_c0 - old->pkg_any_core_c0; in delta_package()
3417 old->pkg_any_gfxe_c0 = new->pkg_any_gfxe_c0 - old->pkg_any_gfxe_c0; in delta_package()
3419 old->pkg_both_core_gfxe_c0 = new->pkg_both_core_gfxe_c0 - old->pkg_both_core_gfxe_c0; in delta_package()
3421 old->pc2 = new->pc2 - old->pc2; in delta_package()
3423 old->pc3 = new->pc3 - old->pc3; in delta_package()
3425 old->pc6 = new->pc6 - old->pc6; in delta_package()
3427 old->pc7 = new->pc7 - old->pc7; in delta_package()
3428 old->pc8 = new->pc8 - old->pc8; in delta_package()
3429 old->pc9 = new->pc9 - old->pc9; in delta_package()
3430 old->pc10 = new->pc10 - old->pc10; in delta_package()
3431 old->die_c6 = new->die_c6 - old->die_c6; in delta_package()
3432 old->cpu_lpi = new->cpu_lpi - old->cpu_lpi; in delta_package()
3433 old->sys_lpi = new->sys_lpi - old->sys_lpi; in delta_package()
3434 old->pkg_temp_c = new->pkg_temp_c; in delta_package()
3437 if (old->gfx_rc6_ms > new->gfx_rc6_ms) in delta_package()
3438 old->gfx_rc6_ms = -1; in delta_package()
3440 old->gfx_rc6_ms = new->gfx_rc6_ms - old->gfx_rc6_ms; in delta_package()
3442 old->uncore_mhz = new->uncore_mhz; in delta_package()
3443 old->gfx_mhz = new->gfx_mhz; in delta_package()
3444 old->gfx_act_mhz = new->gfx_act_mhz; in delta_package()
3447 if (old->sam_mc6_ms > new->sam_mc6_ms) in delta_package()
3448 old->sam_mc6_ms = -1; in delta_package()
3450 old->sam_mc6_ms = new->sam_mc6_ms - old->sam_mc6_ms; in delta_package()
3452 old->sam_mhz = new->sam_mhz; in delta_package()
3453 old->sam_act_mhz = new->sam_act_mhz; in delta_package()
3455 old->energy_pkg.raw_value = new->energy_pkg.raw_value - old->energy_pkg.raw_value; in delta_package()
3456 old->energy_cores.raw_value = new->energy_cores.raw_value - old->energy_cores.raw_value; in delta_package()
3457 old->energy_gfx.raw_value = new->energy_gfx.raw_value - old->energy_gfx.raw_value; in delta_package()
3458 old->energy_dram.raw_value = new->energy_dram.raw_value - old->energy_dram.raw_value; in delta_package()
3459 …old->rapl_pkg_perf_status.raw_value = new->rapl_pkg_perf_status.raw_value - old->rapl_pkg_perf_sta… in delta_package()
3460 old->rapl_dram_perf_status.raw_value = in delta_package()
3461 new->rapl_dram_perf_status.raw_value - old->rapl_dram_perf_status.raw_value; in delta_package()
3463 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in delta_package()
3464 if (mp->format == FORMAT_RAW) in delta_package()
3465 old->counter[i] = new->counter[i]; in delta_package()
3466 else if (mp->format == FORMAT_AVERAGE) in delta_package()
3467 old->counter[i] = new->counter[i]; in delta_package()
3469 old->counter[i] = new->counter[i] - old->counter[i]; in delta_package()
3472 for (i = 0, pp = sys.perf_pp; pp; i++, pp = pp->next) { in delta_package()
3473 if (pp->format == FORMAT_RAW) in delta_package()
3474 old->perf_counter[i] = new->perf_counter[i]; in delta_package()
3475 else if (pp->format == FORMAT_AVERAGE) in delta_package()
3476 old->perf_counter[i] = new->perf_counter[i]; in delta_package()
3478 old->perf_counter[i] = new->perf_counter[i] - old->perf_counter[i]; in delta_package()
3481 for (i = 0, ppmt = sys.pmt_pp; ppmt; i++, ppmt = ppmt->next) { in delta_package()
3482 if (ppmt->format == FORMAT_RAW) in delta_package()
3483 old->pmt_counter[i] = new->pmt_counter[i]; in delta_package()
3485 old->pmt_counter[i] = new->pmt_counter[i] - old->pmt_counter[i]; in delta_package()
3498 old->c3 = new->c3 - old->c3; in delta_core()
3499 old->c6 = new->c6 - old->c6; in delta_core()
3500 old->c7 = new->c7 - old->c7; in delta_core()
3501 old->core_temp_c = new->core_temp_c; in delta_core()
3502 old->core_throt_cnt = new->core_throt_cnt - old->core_throt_cnt; in delta_core()
3503 old->mc6_us = new->mc6_us - old->mc6_us; in delta_core()
3505 DELTA_WRAP32(new->core_energy.raw_value, old->core_energy.raw_value); in delta_core()
3507 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in delta_core()
3508 if (mp->format == FORMAT_RAW) in delta_core()
3509 old->counter[i] = new->counter[i]; in delta_core()
3511 old->counter[i] = new->counter[i] - old->counter[i]; in delta_core()
3514 for (i = 0, pp = sys.perf_cp; pp; i++, pp = pp->next) { in delta_core()
3515 if (pp->format == FORMAT_RAW) in delta_core()
3516 old->perf_counter[i] = new->perf_counter[i]; in delta_core()
3518 old->perf_counter[i] = new->perf_counter[i] - old->perf_counter[i]; in delta_core()
3521 for (i = 0, ppmt = sys.pmt_cp; ppmt; i++, ppmt = ppmt->next) { in delta_core()
3522 if (ppmt->format == FORMAT_RAW) in delta_core()
3523 old->pmt_counter[i] = new->pmt_counter[i]; in delta_core()
3525 old->pmt_counter[i] = new->pmt_counter[i] - old->pmt_counter[i]; in delta_core()
3531 if (!DO_BIC(BIC_CPU_c1) || platform->has_msr_core_c1_res) in soft_c1_residency_display()
3538 * old = new - old
3549 new->apic_id = old->apic_id; in delta_thread()
3551 new->x2apic_id = old->x2apic_id; in delta_thread()
3556 * over-write old w/ new so we can print end of interval values in delta_thread()
3559 timersub(&new->tv_begin, &old->tv_begin, &old->tv_delta); in delta_thread()
3560 old->tv_begin = new->tv_begin; in delta_thread()
3561 old->tv_end = new->tv_end; in delta_thread()
3563 old->tsc = new->tsc - old->tsc; in delta_thread()
3566 if (old->tsc < (1000 * 1000)) in delta_thread()
3567 errx(-3, "Insanely slow TSC rate, TSC stops in idle?\n" in delta_thread()
3568 "You can disable all c-states by booting with \"idle=poll\"\n" in delta_thread()
3571 old->c1 = new->c1 - old->c1; in delta_thread()
3575 if ((new->aperf > old->aperf) && (new->mperf > old->mperf)) { in delta_thread()
3576 old->aperf = new->aperf - old->aperf; in delta_thread()
3577 old->mperf = new->mperf - old->mperf; in delta_thread()
3579 return -1; in delta_thread()
3583 if (platform->has_msr_core_c1_res) { in delta_thread()
3591 * it is possible for mperf's non-halted cycles + idle states in delta_thread()
3594 if ((old->mperf + core_delta->c3 + core_delta->c6 + core_delta->c7) > (old->tsc * tsc_tweak)) in delta_thread()
3595 old->c1 = 0; in delta_thread()
3598 old->c1 = (old->tsc * tsc_tweak) - old->mperf - core_delta->c3 in delta_thread()
3599 - core_delta->c6 - core_delta->c7; in delta_thread()
3603 if (old->mperf == 0) { in delta_thread()
3605 fprintf(outf, "cpu%d MPERF 0!\n", old->cpu_id); in delta_thread()
3606 old->mperf = 1; /* divide by 0 protection */ in delta_thread()
3610 old->instr_count = new->instr_count - old->instr_count; in delta_thread()
3613 old->irq_count = new->irq_count - old->irq_count; in delta_thread()
3616 old->nmi_count = new->nmi_count - old->nmi_count; in delta_thread()
3619 old->smi_count = new->smi_count - old->smi_count; in delta_thread()
3621 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in delta_thread()
3622 if (mp->format == FORMAT_RAW) in delta_thread()
3623 old->counter[i] = new->counter[i]; in delta_thread()
3625 old->counter[i] = new->counter[i] - old->counter[i]; in delta_thread()
3628 for (i = 0, pp = sys.perf_tp; pp; i++, pp = pp->next) { in delta_thread()
3629 if (pp->format == FORMAT_RAW) in delta_thread()
3630 old->perf_counter[i] = new->perf_counter[i]; in delta_thread()
3632 old->perf_counter[i] = new->perf_counter[i] - old->perf_counter[i]; in delta_thread()
3635 for (i = 0, ppmt = sys.pmt_tp; ppmt; i++, ppmt = ppmt->next) { in delta_thread()
3636 if (ppmt->format == FORMAT_RAW) in delta_thread()
3637 old->pmt_counter[i] = new->pmt_counter[i]; in delta_thread()
3639 old->pmt_counter[i] = new->pmt_counter[i] - old->pmt_counter[i]; in delta_thread()
3666 old->energy_psys.raw_value = new->energy_psys.raw_value - old->energy_psys.raw_value; in delta_platform()
3671 c->raw_value = 0; in rapl_counter_clear()
3672 c->scale = 0.0; in rapl_counter_clear()
3673 c->unit = RAPL_UNIT_INVALID; in rapl_counter_clear()
3681 t->tv_begin.tv_sec = 0; in clear_counters()
3682 t->tv_begin.tv_usec = 0; in clear_counters()
3683 t->tv_end.tv_sec = 0; in clear_counters()
3684 t->tv_end.tv_usec = 0; in clear_counters()
3685 t->tv_delta.tv_sec = 0; in clear_counters()
3686 t->tv_delta.tv_usec = 0; in clear_counters()
3688 t->tsc = 0; in clear_counters()
3689 t->aperf = 0; in clear_counters()
3690 t->mperf = 0; in clear_counters()
3691 t->c1 = 0; in clear_counters()
3693 t->instr_count = 0; in clear_counters()
3695 t->irq_count = 0; in clear_counters()
3696 t->nmi_count = 0; in clear_counters()
3697 t->smi_count = 0; in clear_counters()
3699 c->c3 = 0; in clear_counters()
3700 c->c6 = 0; in clear_counters()
3701 c->c7 = 0; in clear_counters()
3702 c->mc6_us = 0; in clear_counters()
3703 c->core_temp_c = 0; in clear_counters()
3704 rapl_counter_clear(&c->core_energy); in clear_counters()
3705 c->core_throt_cnt = 0; in clear_counters()
3707 p->pkg_wtd_core_c0 = 0; in clear_counters()
3708 p->pkg_any_core_c0 = 0; in clear_counters()
3709 p->pkg_any_gfxe_c0 = 0; in clear_counters()
3710 p->pkg_both_core_gfxe_c0 = 0; in clear_counters()
3712 p->pc2 = 0; in clear_counters()
3714 p->pc3 = 0; in clear_counters()
3716 p->pc6 = 0; in clear_counters()
3718 p->pc7 = 0; in clear_counters()
3719 p->pc8 = 0; in clear_counters()
3720 p->pc9 = 0; in clear_counters()
3721 p->pc10 = 0; in clear_counters()
3722 p->die_c6 = 0; in clear_counters()
3723 p->cpu_lpi = 0; in clear_counters()
3724 p->sys_lpi = 0; in clear_counters()
3726 rapl_counter_clear(&p->energy_pkg); in clear_counters()
3727 rapl_counter_clear(&p->energy_dram); in clear_counters()
3728 rapl_counter_clear(&p->energy_cores); in clear_counters()
3729 rapl_counter_clear(&p->energy_gfx); in clear_counters()
3730 rapl_counter_clear(&p->rapl_pkg_perf_status); in clear_counters()
3731 rapl_counter_clear(&p->rapl_dram_perf_status); in clear_counters()
3732 p->pkg_temp_c = 0; in clear_counters()
3734 p->gfx_rc6_ms = 0; in clear_counters()
3735 p->uncore_mhz = 0; in clear_counters()
3736 p->gfx_mhz = 0; in clear_counters()
3737 p->gfx_act_mhz = 0; in clear_counters()
3738 p->sam_mc6_ms = 0; in clear_counters()
3739 p->sam_mhz = 0; in clear_counters()
3740 p->sam_act_mhz = 0; in clear_counters()
3741 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) in clear_counters()
3742 t->counter[i] = 0; in clear_counters()
3744 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) in clear_counters()
3745 c->counter[i] = 0; in clear_counters()
3747 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) in clear_counters()
3748 p->counter[i] = 0; in clear_counters()
3750 memset(&t->perf_counter[0], 0, sizeof(t->perf_counter)); in clear_counters()
3751 memset(&c->perf_counter[0], 0, sizeof(c->perf_counter)); in clear_counters()
3752 memset(&p->perf_counter[0], 0, sizeof(p->perf_counter)); in clear_counters()
3754 memset(&t->pmt_counter[0], 0, ARRAY_SIZE(t->pmt_counter)); in clear_counters()
3755 memset(&c->pmt_counter[0], 0, ARRAY_SIZE(c->pmt_counter)); in clear_counters()
3756 memset(&p->pmt_counter[0], 0, ARRAY_SIZE(p->pmt_counter)); in clear_counters()
3762 if (dst->unit == RAPL_UNIT_INVALID) { in rapl_counter_accumulate()
3763 dst->unit = src->unit; in rapl_counter_accumulate()
3764 dst->scale = src->scale; in rapl_counter_accumulate()
3767 assert(dst->unit == src->unit); in rapl_counter_accumulate()
3768 assert(dst->scale == src->scale); in rapl_counter_accumulate()
3770 dst->raw_value += src->raw_value; in rapl_counter_accumulate()
3780 /* copy un-changing apic_id's */ in sum_counters()
3782 average.threads.apic_id = t->apic_id; in sum_counters()
3784 average.threads.x2apic_id = t->x2apic_id; in sum_counters()
3791 average.threads.tv_end = t->tv_end; in sum_counters()
3793 average.threads.tsc += t->tsc; in sum_counters()
3794 average.threads.aperf += t->aperf; in sum_counters()
3795 average.threads.mperf += t->mperf; in sum_counters()
3796 average.threads.c1 += t->c1; in sum_counters()
3798 average.threads.instr_count += t->instr_count; in sum_counters()
3800 average.threads.irq_count += t->irq_count; in sum_counters()
3801 average.threads.nmi_count += t->nmi_count; in sum_counters()
3802 average.threads.smi_count += t->smi_count; in sum_counters()
3804 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in sum_counters()
3805 if (mp->format == FORMAT_RAW) in sum_counters()
3807 average.threads.counter[i] += t->counter[i]; in sum_counters()
3810 for (i = 0, pp = sys.perf_tp; pp; i++, pp = pp->next) { in sum_counters()
3811 if (pp->format == FORMAT_RAW) in sum_counters()
3813 average.threads.perf_counter[i] += t->perf_counter[i]; in sum_counters()
3816 for (i = 0, ppmt = sys.pmt_tp; ppmt; i++, ppmt = ppmt->next) { in sum_counters()
3817 average.threads.pmt_counter[i] += t->pmt_counter[i]; in sum_counters()
3820 /* sum per-core values only for 1st thread in core */ in sum_counters()
3824 average.cores.c3 += c->c3; in sum_counters()
3825 average.cores.c6 += c->c6; in sum_counters()
3826 average.cores.c7 += c->c7; in sum_counters()
3827 average.cores.mc6_us += c->mc6_us; in sum_counters()
3829 average.cores.core_temp_c = MAX(average.cores.core_temp_c, c->core_temp_c); in sum_counters()
3830 average.cores.core_throt_cnt = MAX(average.cores.core_throt_cnt, c->core_throt_cnt); in sum_counters()
3832 rapl_counter_accumulate(&average.cores.core_energy, &c->core_energy); in sum_counters()
3834 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in sum_counters()
3835 if (mp->format == FORMAT_RAW) in sum_counters()
3837 average.cores.counter[i] += c->counter[i]; in sum_counters()
3840 for (i = 0, pp = sys.perf_cp; pp; i++, pp = pp->next) { in sum_counters()
3841 if (pp->format == FORMAT_RAW) in sum_counters()
3843 average.cores.perf_counter[i] += c->perf_counter[i]; in sum_counters()
3846 for (i = 0, ppmt = sys.pmt_cp; ppmt; i++, ppmt = ppmt->next) { in sum_counters()
3847 average.cores.pmt_counter[i] += c->pmt_counter[i]; in sum_counters()
3850 /* sum per-pkg values only for 1st core in pkg */ in sum_counters()
3855 average.packages.pkg_wtd_core_c0 += p->pkg_wtd_core_c0; in sum_counters()
3857 average.packages.pkg_any_core_c0 += p->pkg_any_core_c0; in sum_counters()
3859 average.packages.pkg_any_gfxe_c0 += p->pkg_any_gfxe_c0; in sum_counters()
3861 average.packages.pkg_both_core_gfxe_c0 += p->pkg_both_core_gfxe_c0; in sum_counters()
3863 average.packages.pc2 += p->pc2; in sum_counters()
3865 average.packages.pc3 += p->pc3; in sum_counters()
3867 average.packages.pc6 += p->pc6; in sum_counters()
3869 average.packages.pc7 += p->pc7; in sum_counters()
3870 average.packages.pc8 += p->pc8; in sum_counters()
3871 average.packages.pc9 += p->pc9; in sum_counters()
3872 average.packages.pc10 += p->pc10; in sum_counters()
3873 average.packages.die_c6 += p->die_c6; in sum_counters()
3875 average.packages.cpu_lpi = p->cpu_lpi; in sum_counters()
3876 average.packages.sys_lpi = p->sys_lpi; in sum_counters()
3878 rapl_counter_accumulate(&average.packages.energy_pkg, &p->energy_pkg); in sum_counters()
3879 rapl_counter_accumulate(&average.packages.energy_dram, &p->energy_dram); in sum_counters()
3880 rapl_counter_accumulate(&average.packages.energy_cores, &p->energy_cores); in sum_counters()
3881 rapl_counter_accumulate(&average.packages.energy_gfx, &p->energy_gfx); in sum_counters()
3883 average.packages.gfx_rc6_ms = p->gfx_rc6_ms; in sum_counters()
3884 average.packages.uncore_mhz = p->uncore_mhz; in sum_counters()
3885 average.packages.gfx_mhz = p->gfx_mhz; in sum_counters()
3886 average.packages.gfx_act_mhz = p->gfx_act_mhz; in sum_counters()
3887 average.packages.sam_mc6_ms = p->sam_mc6_ms; in sum_counters()
3888 average.packages.sam_mhz = p->sam_mhz; in sum_counters()
3889 average.packages.sam_act_mhz = p->sam_act_mhz; in sum_counters()
3891 average.packages.pkg_temp_c = MAX(average.packages.pkg_temp_c, p->pkg_temp_c); in sum_counters()
3893 rapl_counter_accumulate(&average.packages.rapl_pkg_perf_status, &p->rapl_pkg_perf_status); in sum_counters()
3894 rapl_counter_accumulate(&average.packages.rapl_dram_perf_status, &p->rapl_dram_perf_status); in sum_counters()
3896 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in sum_counters()
3897 if ((mp->format == FORMAT_RAW) && (topo.num_packages == 0)) in sum_counters()
3898 average.packages.counter[i] = p->counter[i]; in sum_counters()
3900 average.packages.counter[i] += p->counter[i]; in sum_counters()
3903 for (i = 0, pp = sys.perf_pp; pp; i++, pp = pp->next) { in sum_counters()
3904 if ((pp->format == FORMAT_RAW) && (topo.num_packages == 0)) in sum_counters()
3905 average.packages.perf_counter[i] = p->perf_counter[i]; in sum_counters()
3907 average.packages.perf_counter[i] += p->perf_counter[i]; in sum_counters()
3910 for (i = 0, ppmt = sys.pmt_pp; ppmt; i++, ppmt = ppmt->next) { in sum_counters()
3911 average.packages.pmt_counter[i] += p->pmt_counter[i]; in sum_counters()
3974 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in compute_average()
3975 if (mp->format == FORMAT_RAW) in compute_average()
3977 if (mp->type == COUNTER_ITEMS) { in compute_average()
3984 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in compute_average()
3985 if (mp->format == FORMAT_RAW) in compute_average()
3987 if (mp->type == COUNTER_ITEMS) { in compute_average()
3993 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in compute_average()
3994 if (mp->format == FORMAT_RAW) in compute_average()
3996 if (mp->type == COUNTER_ITEMS) { in compute_average()
4003 for (i = 0, pp = sys.perf_tp; pp; i++, pp = pp->next) { in compute_average()
4004 if (pp->format == FORMAT_RAW) in compute_average()
4006 if (pp->type == COUNTER_ITEMS) { in compute_average()
4013 for (i = 0, pp = sys.perf_cp; pp; i++, pp = pp->next) { in compute_average()
4014 if (pp->format == FORMAT_RAW) in compute_average()
4016 if (pp->type == COUNTER_ITEMS) { in compute_average()
4022 for (i = 0, pp = sys.perf_pp; pp; i++, pp = pp->next) { in compute_average()
4023 if (pp->format == FORMAT_RAW) in compute_average()
4025 if (pp->type == COUNTER_ITEMS) { in compute_average()
4032 for (i = 0, ppmt = sys.pmt_tp; ppmt; i++, ppmt = ppmt->next) { in compute_average()
4035 for (i = 0, ppmt = sys.pmt_cp; ppmt; i++, ppmt = ppmt->next) { in compute_average()
4038 for (i = 0, ppmt = sys.pmt_pp; ppmt; i++, ppmt = ppmt->next) { in compute_average()
4088 if (mp->msr_num != 0) { in get_mp()
4090 if (get_msr(cpu, mp->msr_num, counterp)) in get_mp()
4091 return -1; in get_mp()
4095 if (mp->flags & SYSFS_PERCPU) { in get_mp()
4096 sprintf(path, "/sys/devices/system/cpu/cpu%d/%s", cpu, mp->sp->path); in get_mp()
4122 return (snapshot_sysfs_counter(path) / 1000); in get_legacy_uncore_mhz()
4136 int ret, epb = -1; in get_epb()
4155 return -1; in get_epb()
4164 unsigned int eax, ebx, ecx, edx; in get_apic_id() local
4167 eax = ebx = ecx = edx = 0; in get_apic_id()
4168 __cpuid(1, eax, ebx, ecx, edx); in get_apic_id()
4170 t->apic_id = (ebx >> 24) & 0xff; in get_apic_id()
4182 eax = ebx = ecx = edx = 0; in get_apic_id()
4183 __cpuid(0x80000001, eax, ebx, ecx, edx); in get_apic_id()
4184 topology_extensions = ecx & (1 << 22); in get_apic_id()
4189 eax = ebx = ecx = edx = 0; in get_apic_id()
4190 __cpuid(0x8000001e, eax, ebx, ecx, edx); in get_apic_id()
4192 t->x2apic_id = eax; in get_apic_id()
4202 ecx = 0; in get_apic_id()
4203 __cpuid(0xb, eax, ebx, ecx, edx); in get_apic_id()
4204 t->x2apic_id = edx; in get_apic_id()
4206 if (debug && (t->apic_id != (t->x2apic_id & 0xff))) in get_apic_id()
4207 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()
4220 return -1; in get_core_throt_cnt()
4224 return -1; in get_core_throt_cnt()
4240 int ret = -1; in read_perf_counter_info()
4243 if (fdmt == -1) { in read_perf_counter_info()
4246 ret = -1; in read_perf_counter_info()
4250 bytes_read = read(fdmt, buf, sizeof(buf) - 1); in read_perf_counter_info()
4254 ret = -1; in read_perf_counter_info()
4263 ret = -1; in read_perf_counter_info()
4281 v = -1; in read_perf_counter_info_n()
4307 unsigned int ret = -1; in read_perf_config()
4313 return -1; in read_perf_config()
4384 if (rci->source[i] == COUNTER_SOURCE_PERF) in rapl_counter_info_count_perf()
4395 if (cci->source[i] == COUNTER_SOURCE_PERF) in cstate_counter_info_count_perf()
4403 if (rci->source[idx] == COUNTER_SOURCE_NONE) in write_rapl_counter()
4406 rc->raw_value = rci->data[idx]; in write_rapl_counter()
4407 rc->unit = rci->unit[idx]; in write_rapl_counter()
4408 rc->scale = rci->scale[idx]; in write_rapl_counter()
4428 if (rci->fd_perf != -1) { in get_rapl_counters()
4431 const ssize_t actual_read_size = read(rci->fd_perf, &perf_data[0], sizeof(perf_data)); in get_rapl_counters()
4434 err(-1, "%s: failed to read perf_data (%zu %zu)", __func__, expected_read_size, in get_rapl_counters()
4439 switch (rci->source[i]) { in get_rapl_counters()
4441 rci->data[i] = 0; in get_rapl_counters()
4446 assert(rci->fd_perf != -1); in get_rapl_counters()
4450 i, perf_data[pi], rci->scale[i], perf_data[pi] * rci->scale[i]); in get_rapl_counters()
4452 rci->data[i] = perf_data[pi]; in get_rapl_counters()
4462 if (rci->flags[i] & RAPL_COUNTER_FLAG_USE_MSR_SUM) { in get_rapl_counters()
4463 if (get_msr_sum(cpu, rci->msr[i], &rci->data[i])) in get_rapl_counters()
4464 return -13 - i; in get_rapl_counters()
4466 if (get_msr(cpu, rci->msr[i], &rci->data[i])) in get_rapl_counters()
4467 return -13 - i; in get_rapl_counters()
4470 rci->data[i] &= rci->msr_mask[i]; in get_rapl_counters()
4471 if (rci->msr_shift[i] >= 0) in get_rapl_counters()
4472 rci->data[i] >>= abs(rci->msr_shift[i]); in get_rapl_counters()
4474 rci->data[i] <<= abs(rci->msr_shift[i]); in get_rapl_counters()
4481 write_rapl_counter(&p->energy_pkg, rci, RAPL_RCI_INDEX_ENERGY_PKG); in get_rapl_counters()
4482 write_rapl_counter(&p->energy_cores, rci, RAPL_RCI_INDEX_ENERGY_CORES); in get_rapl_counters()
4483 write_rapl_counter(&p->energy_dram, rci, RAPL_RCI_INDEX_DRAM); in get_rapl_counters()
4484 write_rapl_counter(&p->energy_gfx, rci, RAPL_RCI_INDEX_GFX); in get_rapl_counters()
4485 write_rapl_counter(&p->rapl_pkg_perf_status, rci, RAPL_RCI_INDEX_PKG_PERF_STATUS); in get_rapl_counters()
4486 write_rapl_counter(&p->rapl_dram_perf_status, rci, RAPL_RCI_INDEX_DRAM_PERF_STATUS); in get_rapl_counters()
4487 write_rapl_counter(&c->core_energy, rci, RAPL_RCI_INDEX_CORE_ENERGY); in get_rapl_counters()
4488 write_rapl_counter(&pplat_cnt->energy_psys, rci, RAPL_RCI_INDEX_ENERGY_PLATFORM); in get_rapl_counters()
4496 if (sp->id == id) in find_sysfs_path_by_id()
4497 return (sp->path); in find_sysfs_path_by_id()
4498 sp = sp->next; in find_sysfs_path_by_id()
4536 if (cci->fd_perf_core != -1) { in get_cstate_counters()
4540 actual_read_size_core = read(cci->fd_perf_core, &perf_data_core[0], sizeof(perf_data_core)); in get_cstate_counters()
4543 err(-1, "%s: read perf %s: %ld", __func__, "core", actual_read_size_core); in get_cstate_counters()
4546 if (cci->fd_perf_pkg != -1) { in get_cstate_counters()
4550 actual_read_size_pkg = read(cci->fd_perf_pkg, &perf_data_pkg[0], sizeof(perf_data_pkg)); in get_cstate_counters()
4553 err(-1, "%s: read perf %s: %ld", __func__, "pkg", actual_read_size_pkg); in get_cstate_counters()
4559 …err(-1, "%s: failed to read perf_data (%zu %zu)", __func__, expected_read_size, actual_read_size_t… in get_cstate_counters()
4579 switch (cci->source[i]) { in get_cstate_counters()
4585 assert(cci->fd_perf_core != -1 || cci->fd_perf_pkg != -1); in get_cstate_counters()
4590 cci->data[i] = perf_data[pi]; in get_cstate_counters()
4597 if (get_msr(cpu, cci->msr[i], &cci->data[i])) in get_cstate_counters()
4598 return -13 - i; in get_cstate_counters()
4601 fprintf(stderr, "cstate via %s0x%llx %u: %llu\n", "msr", cci->msr[i], i, cci->data[i]); in get_cstate_counters()
4615 if (cci->source[index] != COUNTER_SOURCE_NONE) \ in get_cstate_counters()
4616 out_counter = cci->data[index]; \ in get_cstate_counters()
4621 PERF_COUNTER_WRITE_DATA(t->c1, CCSTATE_RCI_INDEX_C1_RESIDENCY); in get_cstate_counters()
4622 PERF_COUNTER_WRITE_DATA(c->c3, CCSTATE_RCI_INDEX_C3_RESIDENCY); in get_cstate_counters()
4623 PERF_COUNTER_WRITE_DATA(c->c6, CCSTATE_RCI_INDEX_C6_RESIDENCY); in get_cstate_counters()
4624 PERF_COUNTER_WRITE_DATA(c->c7, CCSTATE_RCI_INDEX_C7_RESIDENCY); in get_cstate_counters()
4626 PERF_COUNTER_WRITE_DATA(p->pc2, PCSTATE_RCI_INDEX_C2_RESIDENCY); in get_cstate_counters()
4627 PERF_COUNTER_WRITE_DATA(p->pc3, PCSTATE_RCI_INDEX_C3_RESIDENCY); in get_cstate_counters()
4628 PERF_COUNTER_WRITE_DATA(p->pc6, PCSTATE_RCI_INDEX_C6_RESIDENCY); in get_cstate_counters()
4629 PERF_COUNTER_WRITE_DATA(p->pc7, PCSTATE_RCI_INDEX_C7_RESIDENCY); in get_cstate_counters()
4630 PERF_COUNTER_WRITE_DATA(p->pc8, PCSTATE_RCI_INDEX_C8_RESIDENCY); in get_cstate_counters()
4631 PERF_COUNTER_WRITE_DATA(p->pc9, PCSTATE_RCI_INDEX_C9_RESIDENCY); in get_cstate_counters()
4632 PERF_COUNTER_WRITE_DATA(p->pc10, PCSTATE_RCI_INDEX_C10_RESIDENCY); in get_cstate_counters()
4644 if (mci->source[i] == COUNTER_SOURCE_PERF) in msr_counter_info_count_perf()
4665 ZERO_ARRAY(mci->data); in get_smi_aperf_mperf()
4667 if (mci->fd_perf != -1) { in get_smi_aperf_mperf()
4670 const ssize_t actual_read_size = read(mci->fd_perf, &perf_data[0], sizeof(perf_data)); in get_smi_aperf_mperf()
4673 err(-1, "%s: failed to read perf_data (%zu %zu)", __func__, expected_read_size, in get_smi_aperf_mperf()
4678 switch (mci->source[i]) { in get_smi_aperf_mperf()
4684 assert(mci->fd_perf != -1); in get_smi_aperf_mperf()
4689 mci->data[i] = perf_data[pi]; in get_smi_aperf_mperf()
4697 if (get_msr(cpu, mci->msr[i], &mci->data[i])) in get_smi_aperf_mperf()
4698 return -2 - i; in get_smi_aperf_mperf()
4700 mci->data[i] &= mci->msr_mask[i]; in get_smi_aperf_mperf()
4703 fprintf(stderr, "Reading msr counter via msr at %u: %llu\n", i, mci->data[i]); in get_smi_aperf_mperf()
4710 t->aperf = mci->data[MSR_RCI_INDEX_APERF]; in get_smi_aperf_mperf()
4711 t->mperf = mci->data[MSR_RCI_INDEX_MPERF]; in get_smi_aperf_mperf()
4712 t->smi_count = mci->data[MSR_RCI_INDEX_SMI]; in get_smi_aperf_mperf()
4723 for (size_t i = 0; pp; ++i, pp = pp->next) { in perf_counter_info_read_values()
4725 assert(domain < pp->num_domains); in perf_counter_info_read_values()
4727 fd_counter = pp->fd_perf_per_domain[domain]; in perf_counter_info_read_values()
4729 if (fd_counter == -1) in perf_counter_info_read_values()
4736 out[i] = value * pp->scale; in perf_counter_info_read_values()
4749 mask = ((1 << (msb + 1)) - 1); in pmt_gen_value_mask()
4751 mask -= (1 << lsb) - 1; in pmt_gen_value_mask()
4758 if (domain_id >= ppmt->num_domains) in pmt_read_counter()
4761 const unsigned long *pmmio = ppmt->domains[domain_id].pcounter; in pmt_read_counter()
4763 const unsigned long value_mask = pmt_gen_value_mask(ppmt->lsb, ppmt->msb); in pmt_read_counter()
4764 const unsigned long value_shift = ppmt->lsb; in pmt_read_counter()
4776 int cpu = t->cpu_id; in get_counters()
4785 return -1; in get_counters()
4788 gettimeofday(&t->tv_begin, (struct timezone *)NULL); in get_counters()
4793 t->tsc = rdtsc(); /* we are running on local CPU of interest */ in get_counters()
4798 if (read(get_instr_count_fd(cpu), &t->instr_count, sizeof(long long)) != sizeof(long long)) in get_counters()
4799 return -4; in get_counters()
4802 t->irq_count = irqs_per_cpu[cpu]; in get_counters()
4804 t->nmi_count = nmi_per_cpu[cpu]; in get_counters()
4808 for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { in get_counters()
4809 if (get_mp(cpu, mp, &t->counter[i], mp->sp->path)) in get_counters()
4810 return -10; in get_counters()
4813 if (perf_counter_info_read_values(sys.perf_tp, cpu, t->perf_counter, MAX_ADDED_THREAD_COUNTERS)) in get_counters()
4814 return -10; in get_counters()
4816 for (i = 0, pp = sys.pmt_tp; pp; i++, pp = pp->next) in get_counters()
4817 t->pmt_counter[i] = pmt_read_counter(pp, t->cpu_id); in get_counters()
4823 if (platform->has_per_core_rapl) { in get_counters()
4824 status = get_rapl_counters(cpu, c->core_id, c, p); in get_counters()
4829 if (DO_BIC(BIC_CPU_c7) && t->is_atom) { in get_counters()
4836 c->c6 -= c->c7; in get_counters()
4840 if (get_msr(cpu, MSR_MODULE_C6_RES_MS, &c->mc6_us)) in get_counters()
4841 return -8; in get_counters()
4845 return -9; in get_counters()
4846 c->core_temp_c = tj_max - ((msr >> 16) & 0x7F); in get_counters()
4850 get_core_throt_cnt(cpu, &c->core_throt_cnt); in get_counters()
4852 for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { in get_counters()
4853 if (get_mp(cpu, mp, &c->counter[i], mp->sp->path)) in get_counters()
4854 return -10; in get_counters()
4857 if (perf_counter_info_read_values(sys.perf_cp, cpu, c->perf_counter, MAX_ADDED_CORE_COUNTERS)) in get_counters()
4858 return -10; in get_counters()
4860 for (i = 0, pp = sys.pmt_cp; pp; i++, pp = pp->next) in get_counters()
4861 c->pmt_counter[i] = pmt_read_counter(pp, c->core_id); in get_counters()
4868 if (get_msr(cpu, MSR_PKG_WEIGHTED_CORE_C0_RES, &p->pkg_wtd_core_c0)) in get_counters()
4869 return -10; in get_counters()
4872 if (get_msr(cpu, MSR_PKG_ANY_CORE_C0_RES, &p->pkg_any_core_c0)) in get_counters()
4873 return -11; in get_counters()
4876 if (get_msr(cpu, MSR_PKG_ANY_GFXE_C0_RES, &p->pkg_any_gfxe_c0)) in get_counters()
4877 return -12; in get_counters()
4880 if (get_msr(cpu, MSR_PKG_BOTH_CORE_GFXE_C0_RES, &p->pkg_both_core_gfxe_c0)) in get_counters()
4881 return -13; in get_counters()
4885 p->cpu_lpi = cpuidle_cur_cpu_lpi_us; in get_counters()
4887 p->sys_lpi = cpuidle_cur_sys_lpi_us; in get_counters()
4889 if (!platform->has_per_core_rapl) { in get_counters()
4890 status = get_rapl_counters(cpu, p->package_id, c, p); in get_counters()
4897 return -17; in get_counters()
4898 p->pkg_temp_c = tj_max - ((msr >> 16) & 0x7F); in get_counters()
4902 p->uncore_mhz = get_legacy_uncore_mhz(p->package_id); in get_counters()
4905 p->gfx_rc6_ms = gfx_info[GFX_rc6].val_ull; in get_counters()
4908 p->gfx_mhz = gfx_info[GFX_MHz].val; in get_counters()
4911 p->gfx_act_mhz = gfx_info[GFX_ACTMHz].val; in get_counters()
4914 p->sam_mc6_ms = gfx_info[SAM_mc6].val_ull; in get_counters()
4917 p->sam_mhz = gfx_info[SAM_MHz].val; in get_counters()
4920 p->sam_act_mhz = gfx_info[SAM_ACTMHz].val; in get_counters()
4922 for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { in get_counters()
4925 if (mp->msr_num == 0) { in get_counters()
4926 path = find_sysfs_path_by_id(mp->sp, p->package_id); in get_counters()
4928 warnx("%s: package_id %d not found", __func__, p->package_id); in get_counters()
4929 return -10; in get_counters()
4932 if (get_mp(cpu, mp, &p->counter[i], path)) in get_counters()
4933 return -10; in get_counters()
4936 if (perf_counter_info_read_values(sys.perf_pp, cpu, p->perf_counter, MAX_ADDED_PACKAGE_COUNTERS)) in get_counters()
4937 return -10; in get_counters()
4939 for (i = 0, pp = sys.pmt_pp; pp; i++, pp = pp->next) in get_counters()
4940 p->pmt_counter[i] = pmt_read_counter(pp, p->package_id); in get_counters()
4943 gettimeofday(&t->tv_end, (struct timezone *)NULL); in get_counters()
5003 if (!platform->has_nhm_msrs || no_msr) in probe_cst_limit()
5006 switch (platform->cst_limit) { in probe_cst_limit()
5047 if (!platform->has_nhm_msrs || no_msr) in dump_platform_info()
5065 if (!platform->has_nhm_msrs || no_msr) in dump_power_ctl()
5069 fprintf(outf, "cpu%d: MSR_IA32_POWER_CTL: 0x%08llx (C1E auto-promotion: %sabled)\n", in dump_power_ctl()
5072 /* C-state Pre-wake Disable (CSTATE_PREWAKE_DISABLE) */ in dump_power_ctl()
5073 if (platform->has_cst_prewake_bit) in dump_power_ctl()
5074 fprintf(outf, "C-state Pre-wake: %sabled\n", msr & 0x40000000 ? "DIS" : "EN"); in dump_power_ctl()
5150 if (platform->trl_msrs & TRL_CORECOUNT) { in dump_turbo_ratio_limits()
5157 for (shift = 56; shift >= 0; shift -= 8) { in dump_turbo_ratio_limits()
5226 * [0] -- Reserved in dump_knl_turbo_ratio_limits()
5227 * [7:1] -- Base value of number of active cores of bucket 1. in dump_knl_turbo_ratio_limits()
5228 * [15:8] -- Base value of freq ratio of bucket 1. in dump_knl_turbo_ratio_limits()
5229 * [20:16] -- +ve delta of number of active cores of bucket 2. in dump_knl_turbo_ratio_limits()
5232 * [23:21] -- Negative delta of freq ratio of bucket 2. in dump_knl_turbo_ratio_limits()
5234 * freq ratio of bucket 1 - delta in dump_knl_turbo_ratio_limits()
5235 * [28:24]-- +ve delta of number of active cores of bucket 3. in dump_knl_turbo_ratio_limits()
5236 * [31:29]-- -ve delta of freq ratio of bucket 3. in dump_knl_turbo_ratio_limits()
5237 * [36:32]-- +ve delta of number of active cores of bucket 4. in dump_knl_turbo_ratio_limits()
5238 * [39:37]-- -ve delta of freq ratio of bucket 4. in dump_knl_turbo_ratio_limits()
5239 * [44:40]-- +ve delta of number of active cores of bucket 5. in dump_knl_turbo_ratio_limits()
5240 * [47:45]-- -ve delta of freq ratio of bucket 5. in dump_knl_turbo_ratio_limits()
5241 * [52:48]-- +ve delta of number of active cores of bucket 6. in dump_knl_turbo_ratio_limits()
5242 * [55:53]-- -ve delta of freq ratio of bucket 6. in dump_knl_turbo_ratio_limits()
5243 * [60:56]-- +ve delta of number of active cores of bucket 7. in dump_knl_turbo_ratio_limits()
5244 * [63:61]-- -ve delta of freq ratio of bucket 7. in dump_knl_turbo_ratio_limits()
5256 ratio[b_nr + 1] = ratio[b_nr] - delta_ratio; in dump_knl_turbo_ratio_limits()
5260 for (i = buckets_no - 1; i >= 0; i--) in dump_knl_turbo_ratio_limits()
5261 if (i > 0 ? ratio[i] != ratio[i - 1] : 1) in dump_knl_turbo_ratio_limits()
5271 if (!platform->has_nhm_msrs || no_msr) in dump_cst_cfg()
5278 fprintf(outf, " (%s%s%s%s%slocked, pkg-cstate-limit=%d (%s)", in dump_cst_cfg()
5279 (msr & SNB_C3_AUTO_UNDEMOTE) ? "UNdemote-C3, " : "", in dump_cst_cfg()
5280 (msr & SNB_C1_AUTO_UNDEMOTE) ? "UNdemote-C1, " : "", in dump_cst_cfg()
5281 (msr & NHM_C3_AUTO_DEMOTE) ? "demote-C3, " : "", in dump_cst_cfg()
5282 (msr & NHM_C1_AUTO_DEMOTE) ? "demote-C1, " : "", in dump_cst_cfg()
5286 if (platform->has_cst_auto_convension) { in dump_cst_cfg()
5287 …fprintf(outf, ", automatic c-state conversion=%s", (msr & AUTOMATIC_CSTATE_CONVERSION) ? "on" : "o… in dump_cst_cfg()
5343 if (!platform->has_irtl_msrs || no_msr) in print_irtl()
5346 if (platform->supported_cstates & PC3) { in print_irtl()
5353 if (platform->supported_cstates & PC6) { in print_irtl()
5360 if (platform->supported_cstates & PC7) { in print_irtl()
5367 if (platform->supported_cstates & PC8) { in print_irtl()
5374 if (platform->supported_cstates & PC9) { in print_irtl()
5381 if (platform->supported_cstates & PC10) { in print_irtl()
5427 if (ccstate_counter_info[counter_id].fd_perf_core != -1) in free_fd_cstate()
5430 if (ccstate_counter_info[counter_id].fd_perf_pkg != -1) in free_fd_cstate()
5445 if (msr_counter_info[cpu].fd_perf != -1) in free_fd_msr()
5462 if (rapl_counter_info_perdomain[domain_id].fd_perf != -1) in free_fd_rapl_percpu()
5476 if (!pp->fd_perf_per_domain) in free_fd_added_perf_counters_()
5480 for (size_t domain = 0; domain < pp->num_domains; ++domain) { in free_fd_added_perf_counters_()
5481 if (pp->fd_perf_per_domain[domain] != -1) { in free_fd_added_perf_counters_()
5482 close(pp->fd_perf_per_domain[domain]); in free_fd_added_perf_counters_()
5483 pp->fd_perf_per_domain[domain] = -1; in free_fd_added_perf_counters_()
5487 free(pp->fd_perf_per_domain); in free_fd_added_perf_counters_()
5488 pp->fd_perf_per_domain = NULL; in free_fd_added_perf_counters_()
5490 pp = pp->next; in free_fd_added_perf_counters_()
5614 cpus[cpu].logical_node_id = -1; in set_node_data()
5623 if (cpus[cpu].logical_node_id != -1) in set_node_data()
5652 int cpu = thiscpu->logical_cpu_id; in get_physical_node_id()
5662 return -1; in get_physical_node_id()
5672 if (*next == '-') /* no negative cpu numbers */ in parse_cpu_str()
5692 if (*next == '-') { in parse_cpu_str()
5727 int cpu = thiscpu->logical_cpu_id; in get_thread_siblings()
5732 thiscpu->put_ids = CPU_ALLOC((topo.max_cpu_num + 1)); in get_thread_siblings()
5733 if (thiscpu->thread_id < 0) in get_thread_siblings()
5734 thiscpu->thread_id = thread_id++; in get_thread_siblings()
5735 if (!thiscpu->put_ids) in get_thread_siblings()
5736 return -1; in get_thread_siblings()
5739 CPU_ZERO_S(size, thiscpu->put_ids); in get_thread_siblings()
5746 return -1; in get_thread_siblings()
5749 offset -= BITMASK_SIZE; in get_thread_siblings()
5756 if (sib_core == thiscpu->physical_core_id) { in get_thread_siblings()
5757 CPU_SET_S(so, size, thiscpu->put_ids); in get_thread_siblings()
5766 return CPU_COUNT_S(size, thiscpu->put_ids); in get_thread_siblings()
5771 * skip non-present cpus
5794 if (cpu_is_not_allowed(t->cpu_id)) in for_all_cpus_2()
5901 fprintf(outf, "turbostat: re-initialized with num_cpus %d, allowed_cpus %d\n", topo.num_cpus, in re_initialize()
5922 topo.max_cpu_num--; /* 0 based */ in set_max_cpu_num()
5945 cpus[cpu].thread_id = -1; in init_thread_id()
5951 unsigned int eax, ebx, ecx, edx; in set_my_cpu_type() local
5954 __cpuid(0, max_level, ebx, ecx, edx); in set_my_cpu_type()
5959 __cpuid(CPUID_LEAF_MODEL_ID, eax, ebx, ecx, edx); in set_my_cpu_type()
5967 return -1; in set_cpu_hybrid_type()
6074 return -EINVAL; in snapshot_graphics()
6096 return -1; in snapshot_cpu_lpi_us()
6121 return -1; in snapshot_sys_lpi_us()
6230 rest.tv_nsec = (tout.tv_usec % 1000000) * 1000; in do_sleep()
6249 /* get_msr_sum() = sum + (get_msr() - last) */ in get_msr_sum()
6266 int cpu = t->cpu_id; in update_msr_sum()
6322 if (timer_create(CLOCK_REALTIME, &sev, &timerid) == -1) { in msr_sum_record()
6338 if (timer_settime(timerid, 0, &its, NULL) == -1) { in msr_sum_record()
6353 * return value < -20 on failure
6362 if (errno && (original_priority == -1)) in set_my_sched_priority()
6363 return -21; in set_my_sched_priority()
6367 return -21; in set_my_sched_priority()
6372 return -21; in set_my_sched_priority()
6388 * ignore on error - we probably don't have permission to set it, but in turbostat_loop()
6391 set_my_sched_priority(-20); in turbostat_loop()
6399 if (retval < -1) { in turbostat_loop()
6401 } else if (retval == -1) { in turbostat_loop()
6425 if (retval < -1) { in turbostat_loop()
6427 } else if (retval == -1) { in turbostat_loop()
6449 if (retval < -1) { in turbostat_loop()
6451 } else if (retval == -1) { in turbostat_loop()
6512 if (cap_free(caps) == -1) in check_for_cap_sys_rawio()
6513 err(-6, "cap_free\n"); in check_for_cap_sys_rawio()
6537 … "\tRun as root to enable them or use %s to disable the access explicitly", pathname, "--no-msr"); in check_msr_permission()
6547 if (!platform->has_nhm_msrs || no_msr) in probe_bclk()
6550 if (platform->bclk_freq == BCLK_100MHZ) in probe_bclk()
6552 else if (platform->bclk_freq == BCLK_133MHZ) in probe_bclk()
6554 else if (platform->bclk_freq == BCLK_SLV) in probe_bclk()
6565 if (platform->enable_tsc_tweak) in probe_bclk()
6587 if (!platform->has_nhm_msrs || no_msr) in dump_turbo_ratio_info()
6590 if (platform->trl_msrs & TRL_LIMIT2) in dump_turbo_ratio_info()
6593 if (platform->trl_msrs & TRL_LIMIT1) in dump_turbo_ratio_info()
6596 if (platform->trl_msrs & TRL_BASE) { in dump_turbo_ratio_info()
6603 if (platform->trl_msrs & TRL_ATOM) in dump_turbo_ratio_info()
6606 if (platform->trl_msrs & TRL_KNL) in dump_turbo_ratio_info()
6609 if (platform->has_config_tdp) in dump_turbo_ratio_info()
6616 int retval = -1; in read_sysfs_int()
6622 return (-1); in read_sysfs_int()
6674 fprintf(outf, "Uncore Frequency package%d die%d: %d - %d MHz ", i, j, k / 1000, l / 1000); in probe_intel_uncore_frequency_legacy()
6680 fprintf(outf, "(%d - %d MHz)", k / 1000, l / 1000); in probe_intel_uncore_frequency_legacy()
6684 fprintf(outf, " %d MHz\n", k / 1000); in probe_intel_uncore_frequency_legacy()
6704 uncore_max_id -= 1; in probe_intel_uncore_frequency_cluster()
6708 for (i = uncore_max_id; i >= 0; --i) { in probe_intel_uncore_frequency_cluster()
6732 * and reported -- So it is effectively (enabled & present). in probe_intel_uncore_frequency_cluster()
6737 * This allows "--show/--hide UncMHz" to be effective for in probe_intel_uncore_frequency_cluster()
6750 …fprintf(outf, "Uncore Frequency package%d domain%d cluster%d: %d - %d MHz ", package_id, domain_id, in probe_intel_uncore_frequency_cluster()
6751 cluster_id, k / 1000, l / 1000); in probe_intel_uncore_frequency_cluster()
6757 fprintf(outf, "(%d - %d MHz)", k / 1000, l / 1000); in probe_intel_uncore_frequency_cluster()
6761 fprintf(outf, " %d MHz\n", k / 1000); in probe_intel_uncore_frequency_cluster()
6806 if (!strncmp(buf, "gt0-rc", strlen("gt0-rc"))) in probe_graphics()
6808 else if (!strncmp(buf, "gt0-mc", strlen("gt0-mc"))) in probe_graphics()
6913 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ in dump_sysfs_cstate_config()
6914 sp = strchr(name_buf, '-'); in dump_sysfs_cstate_config()
6999 cpu = t->cpu_id; in print_epb()
7001 /* EPB is per-package */ in print_epb()
7007 return -1; in print_epb()
7051 cpu = t->cpu_id; in print_hwp()
7053 /* MSR_HWP_CAPABILITIES is per-package */ in print_hwp()
7059 return -1; in print_hwp()
7065 fprintf(outf, "cpu%d: MSR_PM_ENABLE: 0x%08llx (%sHWP)\n", cpu, msr, (msr & (1 << 0)) ? "" : "No-"); in print_hwp()
7118 cpu, msr, ((msr) & 0x1) ? "" : "No-", ((msr) & 0x4) ? "" : "No-"); in print_hwp()
7137 cpu = t->cpu_id; in print_perf_limit()
7139 /* per-package */ in print_perf_limit()
7145 return -1; in print_perf_limit()
7148 if (platform->plr_msrs & PLR_CORE) { in print_perf_limit()
7160 (msr & 1 << 6) ? "VR-Therm, " : "", in print_perf_limit()
7161 (msr & 1 << 5) ? "Auto-HWP, " : "", in print_perf_limit()
7174 (msr & 1 << 22) ? "VR-Therm, " : "", in print_perf_limit()
7175 (msr & 1 << 21) ? "Auto-HWP, " : "", in print_perf_limit()
7181 if (platform->plr_msrs & PLR_GFX) { in print_perf_limit()
7188 (msr & 1 << 6) ? "VR-Therm, " : "", in print_perf_limit()
7196 (msr & 1 << 22) ? "VR-Therm, " : "", in print_perf_limit()
7201 if (platform->plr_msrs & PLR_RING) { in print_perf_limit()
7207 (msr & 1 << 6) ? "VR-Therm, " : "", in print_perf_limit()
7213 (msr & 1 << 22) ? "VR-Therm, " : "", in print_perf_limit()
7225 if (platform->rapl_quirk_tdp) in get_quirk_tdp()
7226 return platform->rapl_quirk_tdp; in get_quirk_tdp()
7235 if (platform->rapl_msrs & RAPL_PKG_POWER_INFO) in get_tdp_intel()
7259 if (!(platform->rapl_msrs & RAPL_PKG_PERF_STATUS)) in rapl_probe_intel()
7261 if (!(platform->rapl_msrs & RAPL_DRAM_PERF_STATUS)) in rapl_probe_intel()
7269 if (platform->has_rapl_divisor) in rapl_probe_intel()
7274 if (platform->has_fixed_rapl_unit) in rapl_probe_intel()
7279 if (platform->has_fixed_rapl_psys_unit) in rapl_probe_intel()
7312 rapl_time_units = ldexp(1.0, -(msr >> 16 & 0xf)); in rapl_probe_amd()
7313 rapl_energy_units = ldexp(1.0, -(msr >> 8 & 0x1f)); in rapl_probe_amd()
7314 rapl_power_units = ldexp(1.0, -(msr & 0xf)); in rapl_probe_amd()
7344 if (!platform->rapl_msrs) in print_rapl()
7351 cpu = t->cpu_id; in print_rapl()
7354 return -1; in print_rapl()
7357 if (platform->rapl_msrs & RAPL_AMD_F17H) { in print_rapl()
7360 return -1; in print_rapl()
7364 return -1; in print_rapl()
7370 if (platform->rapl_msrs & RAPL_PKG_POWER_INFO) { in print_rapl()
7373 return -5; in print_rapl()
7375 fprintf(outf, "cpu%d: MSR_PKG_POWER_INFO: 0x%08llx (%.0f W TDP, RAPL %.0f - %.0f W, %f sec.)\n", in print_rapl()
7383 if (platform->rapl_msrs & RAPL_PKG) { in print_rapl()
7386 return -9; in print_rapl()
7400 return -9; in print_rapl()
7407 if (platform->rapl_msrs & RAPL_DRAM_POWER_INFO) { in print_rapl()
7409 return -6; in print_rapl()
7411 fprintf(outf, "cpu%d: MSR_DRAM_POWER_INFO,: 0x%08llx (%.0f W TDP, RAPL %.0f - %.0f W, %f sec.)\n", in print_rapl()
7418 if (platform->rapl_msrs & RAPL_DRAM) { in print_rapl()
7420 return -9; in print_rapl()
7426 if (platform->rapl_msrs & RAPL_CORE_POLICY) { in print_rapl()
7428 return -7; in print_rapl()
7432 if (platform->rapl_msrs & RAPL_CORE_POWER_LIMIT) { in print_rapl()
7434 return -9; in print_rapl()
7439 if (platform->rapl_msrs & RAPL_GFX) { in print_rapl()
7441 return -8; in print_rapl()
7446 return -9; in print_rapl()
7461 if (!platform->rapl_msrs || no_msr) in probe_rapl()
7481 * but also allow cmdline over-ride with -T.
7483 * Several MSR temperature values are in units of degrees-C
7500 /* this is a per-package concept */ in set_temperature_target()
7504 cpu = t->cpu_id; in set_temperature_target()
7507 return -1; in set_temperature_target()
7517 if (!platform->has_nhm_msrs || no_msr) in set_temperature_target()
7526 int bits = platform->tcc_offset_bits; in set_temperature_target()
7533 tcc_offset = (msr >> 24) & GENMASK(bits - 1, 0); in set_temperature_target()
7534 fprintf(outf, "cpu%d: MSR_IA32_TEMPERATURE_TARGET: 0x%08llx (%d C) (%d default - %d offset)\n", in set_temperature_target()
7535 cpu, msr, tcc_default - tcc_offset, tcc_default, tcc_offset); in set_temperature_target()
7550 fprintf(outf, "cpu%d: Guessing tjMax %d C, Please use -T to specify\n", cpu, tj_max); in set_temperature_target()
7570 cpu = t->cpu_id; in print_thermal()
7572 /* DTS is per-core, no need to print for each thread */ in print_thermal()
7578 return -1; in print_thermal()
7586 fprintf(outf, "cpu%d: MSR_IA32_PACKAGE_THERM_STATUS: 0x%08llx (%d C)\n", cpu, msr, tj_max - dts); in print_thermal()
7594 cpu, msr, tj_max - dts, tj_max - dts2); in print_thermal()
7605 fprintf(outf, "cpu%d: MSR_IA32_THERM_STATUS: 0x%08llx (%d C +/- %d)\n", in print_thermal()
7606 cpu, msr, tj_max - dts, resolution); in print_thermal()
7614 cpu, msr, tj_max - dts, tj_max - dts2); in print_thermal()
7637 unsigned int eax, ebx, ecx, edx; in get_cpu_type() local
7645 if (cpu_migrate(t->cpu_id)) { in get_cpu_type()
7646 fprintf(outf, "Could not migrate to CPU %d\n", t->cpu_id); in get_cpu_type()
7647 return -1; in get_cpu_type()
7653 __cpuid(0x1a, eax, ebx, ecx, edx); in get_cpu_type()
7656 t->is_atom = true; in get_cpu_type()
7669 base_cpu, msr, msr & FEAT_CTL_LOCKED ? "" : "UN-", msr & (1 << 18) ? "SGX" : ""); in decode_feature_control_msr()
7685 msr & MSR_IA32_MISC_ENABLE_TM1 ? "" : "No-", in decode_misc_enable_msr()
7686 msr & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP ? "" : "No-", in decode_misc_enable_msr()
7687 msr & MSR_IA32_MISC_ENABLE_MWAIT ? "" : "No-", in decode_misc_enable_msr()
7688 msr & MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE ? "No-" : "", in decode_misc_enable_msr()
7689 msr & MSR_IA32_MISC_ENABLE_TURBO_DISABLE ? "No-" : ""); in decode_misc_enable_msr()
7699 if (!platform->has_msr_misc_feature_control) in decode_misc_feature_control()
7704 …"cpu%d: MSR_MISC_FEATURE_CONTROL: 0x%08llx (%sL2-Prefetch %sL2-Prefetch-pair %sL1-Prefetch %sL1-IP in decode_misc_feature_control()
7705 base_cpu, msr, msr & (0 << 0) ? "No-" : "", msr & (1 << 0) ? "No-" : "", in decode_misc_feature_control()
7706 msr & (2 << 0) ? "No-" : "", msr & (3 << 0) ? "No-" : ""); in decode_misc_feature_control()
7723 if (!platform->has_msr_misc_pwr_mgmt) in decode_misc_pwr_mgmt_msr()
7727 …fprintf(outf, "cpu%d: MSR_MISC_PWR_MGMT: 0x%08llx (%sable-EIST_Coordination %sable-EPB %sable-OOB)… in decode_misc_pwr_mgmt_msr()
7745 if (!platform->has_msr_c6_demotion_policy_config) in decode_c6_demotion_policy_msr()
7749 fprintf(outf, "cpu%d: MSR_CC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-CC6-Demotion)\n", in decode_c6_demotion_policy_msr()
7753 fprintf(outf, "cpu%d: MSR_MC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-MC6-Demotion)\n", in decode_c6_demotion_policy_msr()
7790 fd = open_perf_counter(base_cpu, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, -1, 0); in has_instr_count_access()
7791 has_access = fd != -1; in has_instr_count_access()
7793 if (fd != -1) in has_instr_count_access()
7799 "instructions retired perf counter", "--no-perf"); in has_instr_count_access()
7808 return -1; in add_rapl_perf_counter_()
7810 const double scale = read_perf_scale(cai->perf_subsys, cai->perf_name); in add_rapl_perf_counter_()
7813 return -1; in add_rapl_perf_counter_()
7815 const enum rapl_unit unit = read_perf_rapl_unit(cai->perf_subsys, cai->perf_name); in add_rapl_perf_counter_()
7818 return -1; in add_rapl_perf_counter_()
7820 const unsigned int rapl_type = read_perf_type(cai->perf_subsys); in add_rapl_perf_counter_()
7821 const unsigned int rapl_energy_pkg_config = read_perf_config(cai->perf_subsys, cai->perf_name); in add_rapl_perf_counter_()
7824 open_perf_counter(cpu, rapl_type, rapl_energy_pkg_config, rci->fd_perf, PERF_FORMAT_GROUP); in add_rapl_perf_counter_()
7825 if (fd_counter == -1) in add_rapl_perf_counter_()
7826 return -1; in add_rapl_perf_counter_()
7829 if (rci->fd_perf == -1) in add_rapl_perf_counter_()
7830 rci->fd_perf = fd_counter; in add_rapl_perf_counter_()
7849 * Linux-perf manages the HW instructions-retired counter
7860 err(-1, "calloc fd_instr_count_percpu"); in linux_perf_init()
7866 …const unsigned int num_domains = (platform->has_per_core_rapl ? topo.max_core_id : topo.max_packag… in rapl_perf_init()
7871 err(-1, "calloc rapl_counter_info_percpu"); in rapl_perf_init()
7880 rci->fd_perf = -1; in rapl_perf_init()
7882 rci->data[i] = 0; in rapl_perf_init()
7883 rci->source[i] = COUNTER_SOURCE_NONE; in rapl_perf_init()
7908 platform->has_per_core_rapl ? cpus[cpu].physical_core_id : cpus[cpu].physical_package_id; in rapl_perf_init()
7917 if ((cai->flags & RAPL_COUNTER_FLAG_PLATFORM_COUNTER) && (cpu != base_cpu)) in rapl_perf_init()
7923 if (BIC_IS_ENABLED(cai->bic) && (platform->rapl_msrs & cai->feature_mask)) { in rapl_perf_init()
7926 if (!no_perf && cai->perf_name in rapl_perf_init()
7927 && add_rapl_perf_counter(cpu, rci, cai, &scale, &unit) != -1) { in rapl_perf_init()
7928 rci->source[cai->rci_index] = COUNTER_SOURCE_PERF; in rapl_perf_init()
7929 rci->scale[cai->rci_index] = scale * cai->compat_scale; in rapl_perf_init()
7930 rci->unit[cai->rci_index] = unit; in rapl_perf_init()
7931 rci->flags[cai->rci_index] = cai->flags; in rapl_perf_init()
7934 } else if (!no_msr && cai->msr && probe_rapl_msr(cpu, cai->msr, cai->rci_index) == 0) { in rapl_perf_init()
7935 rci->source[cai->rci_index] = COUNTER_SOURCE_MSR; in rapl_perf_init()
7936 rci->msr[cai->rci_index] = cai->msr; in rapl_perf_init()
7937 rci->msr_mask[cai->rci_index] = cai->msr_mask; in rapl_perf_init()
7938 rci->msr_shift[cai->rci_index] = cai->msr_shift; in rapl_perf_init()
7939 rci->unit[cai->rci_index] = RAPL_UNIT_JOULES; in rapl_perf_init()
7940 rci->scale[cai->rci_index] = *cai->platform_rapl_msr_scale * cai->compat_scale; in rapl_perf_init()
7941 rci->flags[cai->rci_index] = cai->flags; in rapl_perf_init()
7945 if (rci->source[cai->rci_index] != COUNTER_SOURCE_NONE) in rapl_perf_init()
7951 BIC_PRESENT(cai->bic); in rapl_perf_init()
7967 return &cci->fd_perf_core; in get_cstate_perf_group_fd()
7970 return &cci->fd_perf_pkg; in get_cstate_perf_group_fd()
7978 return -1; in add_cstate_perf_counter_()
7980 int *pfd_group = get_cstate_perf_group_fd(cci, cai->perf_subsys); in add_cstate_perf_counter_()
7983 return -1; in add_cstate_perf_counter_()
7985 const unsigned int type = read_perf_type(cai->perf_subsys); in add_cstate_perf_counter_()
7986 const unsigned int config = read_perf_config(cai->perf_subsys, cai->perf_name); in add_cstate_perf_counter_()
7990 if (fd_counter == -1) in add_cstate_perf_counter_()
7991 return -1; in add_cstate_perf_counter_()
7994 if (*pfd_group == -1) in add_cstate_perf_counter_()
8013 return -1; in add_msr_perf_counter_()
8015 const unsigned int type = read_perf_type(cai->perf_subsys); in add_msr_perf_counter_()
8016 const unsigned int config = read_perf_config(cai->perf_subsys, cai->perf_name); in add_msr_perf_counter_()
8018 const int fd_counter = open_perf_counter(cpu, type, config, cci->fd_perf, PERF_FORMAT_GROUP); in add_msr_perf_counter_()
8020 if (fd_counter == -1) in add_msr_perf_counter_()
8021 return -1; in add_msr_perf_counter_()
8024 if (cci->fd_perf == -1) in add_msr_perf_counter_()
8025 cci->fd_perf = fd_counter; in add_msr_perf_counter_()
8035 …fprintf(stderr, "%s: %s/%s: %d (cpu: %d)\n", __func__, cai->perf_subsys, cai->perf_name, ret, cpu); in add_msr_perf_counter()
8050 msr_counter_info[cpu].fd_perf = -1; in msr_perf_init_()
8056 cai->present = false; in msr_perf_init_()
8065 if (cai->needed) { in msr_perf_init_()
8067 if (!no_perf && cai->perf_name && add_msr_perf_counter(cpu, cci, cai) != -1) { in msr_perf_init_()
8068 cci->source[cai->rci_index] = COUNTER_SOURCE_PERF; in msr_perf_init_()
8069 cai->present = true; in msr_perf_init_()
8072 } else if (!no_msr && cai->msr && probe_rapl_msr(cpu, cai->msr, cai->rci_index) == 0) { in msr_perf_init_()
8073 cci->source[cai->rci_index] = COUNTER_SOURCE_MSR; in msr_perf_init_()
8074 cci->msr[cai->rci_index] = cai->msr; in msr_perf_init_()
8075 cci->msr_mask[cai->rci_index] = cai->msr_mask; in msr_perf_init_()
8076 cai->present = true; in msr_perf_init_()
8087 const bool need_soft_c1 = (!platform->has_msr_core_c1_res) && (platform->supported_cstates & CC1); in msr_perf_init()
8141 ccstate_counter_info[cpu].fd_perf_core = -1; in cstate_perf_init_()
8142 ccstate_counter_info[cpu].fd_perf_pkg = -1; in cstate_perf_init_()
8165 const bool per_thread = cai->flags & CSTATE_COUNTER_FLAG_COLLECT_PER_THREAD; in cstate_perf_init_()
8166 const bool per_core = cai->flags & CSTATE_COUNTER_FLAG_COLLECT_PER_CORE; in cstate_perf_init_()
8174 const bool counter_needed = BIC_IS_ENABLED(cai->bic) || in cstate_perf_init_()
8175 (soft_c1 && (cai->flags & CSTATE_COUNTER_FLAG_SOFT_C1_DEPENDENCY)); in cstate_perf_init_()
8176 const bool counter_supported = (platform->supported_cstates & cai->feature_mask); in cstate_perf_init_()
8180 if (!no_perf && cai->perf_name && add_cstate_perf_counter(cpu, cci, cai) != -1) { in cstate_perf_init_()
8182 cci->source[cai->rci_index] = COUNTER_SOURCE_PERF; in cstate_perf_init_()
8185 } else if (!no_msr && cai->msr && pkg_cstate_limit >= cai->pkg_cstate_limit in cstate_perf_init_()
8186 && probe_rapl_msr(cpu, cai->msr, cai->rci_index) == 0) { in cstate_perf_init_()
8187 cci->source[cai->rci_index] = COUNTER_SOURCE_MSR; in cstate_perf_init_()
8188 cci->msr[cai->rci_index] = cai->msr; in cstate_perf_init_()
8192 if (cci->source[cai->rci_index] != COUNTER_SOURCE_NONE) { in cstate_perf_init_()
8201 BIC_PRESENT(cai->bic); in cstate_perf_init_()
8214 const bool soft_c1 = !platform->has_msr_core_c1_res && has_amperf_access() in cstate_perf_init()
8215 && platform->supported_cstates & CC1; in cstate_perf_init()
8227 if (platform->has_msr_module_c6_res_ms) in probe_cstates()
8230 if (platform->has_ext_cst_msrs && !no_msr) { in probe_cstates()
8287 unsigned int eax, ebx, ecx, edx; in process_cpuid() local
8292 eax = ebx = ecx = edx = 0; in process_cpuid()
8294 __cpuid(0, max_level, ebx, ecx, edx); in process_cpuid()
8296 if (ebx == 0x756e6547 && ecx == 0x6c65746e && edx == 0x49656e69) in process_cpuid()
8298 else if (ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65) in process_cpuid()
8300 else if (ebx == 0x6f677948 && ecx == 0x656e6975 && edx == 0x6e65476e) in process_cpuid()
8305 (char *)&ebx, (char *)&edx, (char *)&ecx, max_level); in process_cpuid()
8307 __cpuid(1, fms, ebx, ecx, edx); in process_cpuid()
8315 ecx_flags = ecx; in process_cpuid()
8330 ebx = ecx = edx = 0; in process_cpuid()
8331 __cpuid(0x80000000, max_extended_level, ebx, ecx, edx); in process_cpuid()
8342 ecx_flags & (1 << 0) ? "SSE3" : "-", in process_cpuid()
8343 ecx_flags & (1 << 3) ? "MONITOR" : "-", in process_cpuid()
8344 ecx_flags & (1 << 6) ? "SMX" : "-", in process_cpuid()
8345 ecx_flags & (1 << 7) ? "EIST" : "-", in process_cpuid()
8346 ecx_flags & (1 << 8) ? "TM2" : "-", in process_cpuid()
8347 edx_flags & (1 << 4) ? "TSC" : "-", in process_cpuid()
8348 edx_flags & (1 << 5) ? "MSR" : "-", in process_cpuid()
8349 edx_flags & (1 << 22) ? "ACPI-TM" : "-", in process_cpuid()
8350 edx_flags & (1 << 28) ? "HT" : "-", edx_flags & (1 << 29) ? "TM" : "-"); in process_cpuid()
8361 * Non-Stop TSC is advertised by CPUID.EAX=0x80000007: EDX.bit8 in process_cpuid()
8364 __cpuid(0x80000007, eax, ebx, ecx, edx); in process_cpuid()
8369 * APERF/MPERF is advertised by CPUID.EAX=0x6: ECX.bit0 in process_cpuid()
8373 __cpuid(0x6, eax, ebx, ecx, edx); in process_cpuid()
8374 has_aperf = ecx & (1 << 0); in process_cpuid()
8387 has_epb = ecx & (1 << 3); in process_cpuid()
8392 has_aperf ? "" : "No-", in process_cpuid()
8393 has_turbo ? "" : "No-", in process_cpuid()
8394 do_dts ? "" : "No-", in process_cpuid()
8395 do_ptm ? "" : "No-", in process_cpuid()
8396 has_hwp ? "" : "No-", in process_cpuid()
8397 has_hwp_notify ? "" : "No-", in process_cpuid()
8398 has_hwp_activity_window ? "" : "No-", in process_cpuid()
8399 has_hwp_epp ? "" : "No-", has_hwp_pkg ? "" : "No-", has_epb ? "" : "No-"); in process_cpuid()
8407 ecx = 0; in process_cpuid()
8409 __cpuid_count(0x7, 0, eax, ebx, ecx, edx); in process_cpuid()
8415 fprintf(outf, "CPUID(7): %sSGX %sHybrid\n", has_sgx ? "" : "No-", is_hybrid ? "" : "No-"); in process_cpuid()
8437 crystal_hz = platform->crystal_freq; in process_cpuid()
8462 if (platform->enable_tsc_tweak) in process_cpuid()
8471 aperf_mperf_multiplier = platform->need_perf_multiplier ? 1024 : 1; in process_cpuid()
8483 if (platform->has_msr_knl_core_c6_residency && cai->msr == MSR_CORE_C6_RESIDENCY) in counter_info_init()
8484 cai->msr = MSR_KNL_CORE_C6_RESIDENCY; in counter_info_init()
8486 if (!platform->has_msr_core_c1_res && cai->msr == MSR_CORE_C1_RES) in counter_info_init()
8487 cai->msr = 0; in counter_info_init()
8489 if (platform->has_msr_atom_pkg_c6_residency && cai->msr == MSR_PKG_C6_RESIDENCY) in counter_info_init()
8490 cai->msr = MSR_ATOM_PKG_C6_RESIDENCY; in counter_info_init()
8515 if (platform->has_nhm_msrs && !no_msr) in probe_pm_features()
8528 if (isdigit(dirp->d_name[0])) in dir_filter()
8544 return -1; in initialize_cpu_possible_set()
8558 return -1; in initialize_cpu_possible_set()
8656 err(-ENODEV, "No valid cpus found"); in topology_probe()
8770 (*t)[i].cpu_id = -1; in allocate_counters()
8777 (*c)[i].core_id = -1; in allocate_counters()
8778 (*c)[i].base_cpu = -1; in allocate_counters()
8787 (*p)[i].base_cpu = -1; in allocate_counters()
8810 /* Workaround for systems where physical_node_id==-1 in init_counter()
8811 * and logical_node_id==(-1 - topo.num_cpus) in init_counter()
8820 t->cpu_id = cpu_id; in init_counter()
8822 if (c->base_cpu < 0) in init_counter()
8823 c->base_cpu = t->cpu_id; in init_counter()
8824 if (p->base_cpu < 0) in init_counter()
8825 p->base_cpu = t->cpu_id; in init_counter()
8828 c->core_id = core_id; in init_counter()
8829 p->package_id = pkg_id; in init_counter()
8844 err(-1, "calloc output buffer"); in allocate_output_buffer()
8851 err(-1, "calloc fd_percpu"); in allocate_fd_percpu()
8858 err(-1, "calloc %d", topo.num_cpus); in allocate_irq_buffers()
8862 err(-1, "calloc %d IRQ", topo.max_cpu_num + 1); in allocate_irq_buffers()
8866 err(-1, "calloc %d NMI", topo.max_cpu_num + 1); in allocate_irq_buffers()
8872 if ((int)t->cpu_id == c->base_cpu) in update_topo()
8874 if ((int)t->cpu_id == p->base_cpu) in update_topo()
8912 err(-ENODEV, "No valid cpus found"); in set_base_cpu()
8945 * -1: doesn't have separate perf device for p and e core in perf_has_hybrid_devices()
8956 cached = -1; in perf_has_hybrid_devices()
8961 cached = -1; in perf_has_hybrid_devices()
8986 switch (pinfo->scope) { in added_perf_counters_init_()
9001 pinfo->fd_perf_per_domain = calloc(num_domains, sizeof(*pinfo->fd_perf_per_domain)); in added_perf_counters_init_()
9002 if (!pinfo->fd_perf_per_domain) in added_perf_counters_init_()
9006 pinfo->fd_perf_per_domain[i] = -1; in added_perf_counters_init_()
9008 pinfo->num_domains = num_domains; in added_perf_counters_init_()
9009 pinfo->scale = 1.0; in added_perf_counters_init_()
9035 const char *perf_device = pinfo->device; in added_perf_counters_init_()
9053 if (perf_type == (unsigned int)-1) { in added_perf_counters_init_()
9055 __func__, perf_device, pinfo->event, "type"); in added_perf_counters_init_()
9059 perf_config = read_perf_config(perf_device, pinfo->event); in added_perf_counters_init_()
9060 if (perf_config == (unsigned int)-1) { in added_perf_counters_init_()
9062 __func__, perf_device, pinfo->event, "config"); in added_perf_counters_init_()
9067 perf_scale = read_perf_scale(perf_device, pinfo->event); in added_perf_counters_init_()
9071 fd_perf = open_perf_counter(cpu, perf_type, perf_config, -1, 0); in added_perf_counters_init_()
9072 if (fd_perf == -1) { in added_perf_counters_init_()
9074 __func__, perf_device, pinfo->event, cpu); in added_perf_counters_init_()
9079 pinfo->fd_perf_per_domain[next_domain] = fd_perf; in added_perf_counters_init_()
9080 pinfo->scale = perf_scale; in added_perf_counters_init_()
9084 perf_device, pinfo->event, cpu, pinfo->fd_perf_per_domain[next_domain]); in added_perf_counters_init_()
9087 pinfo = pinfo->next; in added_perf_counters_init_()
9114 if (fd_telem_info == -1) in parse_telem_info_file()
9115 return -1; in parse_telem_info_file()
9120 return -1; in parse_telem_info_file()
9125 return -1; in parse_telem_info_file()
9147 if (stat(SYSFS_TELEM_PATH, &st) == -1) in pmt_mmio_open()
9158 if (fstatat(dirfd(pmt_iter.dir), entry->d_name, &st, 0) == -1) in pmt_mmio_open()
9164 fd_telem_dir = openat(dirfd(pmt_iter.dir), entry->d_name, O_RDONLY); in pmt_mmio_open()
9165 if (fd_telem_dir == -1) in pmt_mmio_open()
9191 if (fd_pmt == -1) in pmt_mmio_open()
9213 new_pmt->guid = guid; in pmt_mmio_open()
9214 new_pmt->mmio_base = mmio; in pmt_mmio_open()
9215 new_pmt->pmt_offset = offset; in pmt_mmio_open()
9216 new_pmt->size = size; in pmt_mmio_open()
9217 new_pmt->next = pmt_mmios; in pmt_mmio_open()
9220 last->next = new_pmt; in pmt_mmio_open()
9249 if (pmmio->guid == guid) in pmt_mmio_find()
9252 pmmio = pmmio->next; in pmt_mmio_find()
9263 ret = (char *)pmmio->mmio_base; in pmt_get_counter_pointer()
9268 * - we might have to apply the offset first. in pmt_get_counter_pointer()
9270 ret += pmmio->pmt_offset; in pmt_get_counter_pointer()
9287 ret = ret->next; in pmt_add_guid()
9288 --seq; in pmt_add_guid()
9302 if (strcmp(pcounter->name, name) == 0) in pmt_find_counter()
9305 pcounter = pcounter->next; in pmt_find_counter()
9328 if (domain_id >= pcounter->num_domains) in pmt_counter_add_domain()
9331 assert(pcounter->domains); in pmt_counter_add_domain()
9332 assert(domain_id < pcounter->num_domains); in pmt_counter_add_domain()
9334 pcounter->domains[domain_id].pcounter = pmmio; in pmt_counter_add_domain()
9367 if (offset >= mmio->size) { in pmt_add_counter()
9369 fprintf(stderr, "%s: offset %u outside of PMT MMIO size %u\n", __func__, offset, mmio->size); in pmt_add_counter()
9383 strncpy(pcounter->name, name, ARRAY_SIZE(pcounter->name) - 1); in pmt_add_counter()
9384 pcounter->type = type; in pmt_add_counter()
9385 pcounter->scope = scope; in pmt_add_counter()
9386 pcounter->lsb = lsb; in pmt_add_counter()
9387 pcounter->msb = msb; in pmt_add_counter()
9388 pcounter->format = format; in pmt_add_counter()
9390 conflict += pcounter->type != type; in pmt_add_counter()
9391 conflict += pcounter->scope != scope; in pmt_add_counter()
9392 conflict += pcounter->lsb != lsb; in pmt_add_counter()
9393 conflict += pcounter->msb != msb; in pmt_add_counter()
9394 conflict += pcounter->format != format; in pmt_add_counter()
9406 pcounter->next = *pmt_root; in pmt_add_counter()
9499 if (BIC_IS_ENABLED(BIC_IPC) && has_aperf_access && get_instr_count_fd(base_cpu) != -1) in turbostat_init()
9506 if (platform->enable_tsc_tweak && !has_base_hz) { in turbostat_init()
9545 if (child_pid == -1) in fork_it()
9550 if (waitpid(child_pid, &status, 0) == -1) in fork_it()
9558 * because re-starting is problematic when forking in fork_it()
9597 fprintf(outf, "turbostat version 2025.04.06 - Len Brown <lenb@kernel.org>\n"); in print_version()
9613 ret = fread(bootcmd, sizeof(char), COMMAND_LINE_SIZE - 1, fp); in print_bootcmd()
9627 for (mp = head; mp; mp = mp->next) { in find_msrp_by_name()
9629 fprintf(stderr, "%s: %s %s\n", __func__, name, mp->name); in find_msrp_by_name()
9630 if (!strcmp(name, mp->name)) in find_msrp_by_name()
9643 errx(1, "Requested MSR counter 0x%x, but in --no-msr mode", msr_num); in add_counter()
9660 return -1; in add_counter()
9672 return -1; in add_counter()
9684 return -1; in add_counter()
9689 return -1; in add_counter()
9695 err(-1, "calloc msr_counter"); in add_counter()
9697 msrp->msr_num = msr_num; in add_counter()
9698 strncpy(msrp->name, name, NAME_BYTES - 1); in add_counter()
9699 msrp->width = width; in add_counter()
9700 msrp->type = type; in add_counter()
9701 msrp->format = format; in add_counter()
9702 msrp->flags = flags; in add_counter()
9706 msrp->next = sys.tp; in add_counter()
9710 msrp->next = sys.cp; in add_counter()
9714 msrp->next = sys.pp; in add_counter()
9728 strncpy(sp->path, path, PATH_BYTES - 1); in add_counter()
9729 sp->id = id; in add_counter()
9730 sp->next = msrp->sp; in add_counter()
9731 msrp->sp = sp; in add_counter()
9757 strncpy(pinfo->device, perf_device, ARRAY_SIZE(pinfo->device) - 1); in make_perf_counter_info()
9758 strncpy(pinfo->event, perf_event, ARRAY_SIZE(pinfo->event) - 1); in make_perf_counter_info()
9760 strncpy(pinfo->name, name, ARRAY_SIZE(pinfo->name) - 1); in make_perf_counter_info()
9761 pinfo->width = width; in make_perf_counter_info()
9762 pinfo->scope = scope; in make_perf_counter_info()
9763 pinfo->type = type; in make_perf_counter_info()
9764 pinfo->format = format; in make_perf_counter_info()
9778 return -1; in add_perf_counter()
9785 return -1; in add_perf_counter()
9792 return -1; in add_perf_counter()
9800 return -1; in add_perf_counter()
9804 pinfo->next = sys.perf_tp; in add_perf_counter()
9810 pinfo->next = sys.perf_cp; in add_perf_counter()
9816 pinfo->next = sys.perf_pp; in add_perf_counter()
9825 __func__, pinfo->device, pinfo->event, pinfo->name, pinfo->scope); in add_perf_counter()
9922 fprintf(stderr, "--add: (msrDDD | msr0xXXX | /path_to_counter | perf/device/event) required\n"); in parse_add_command_msr()
9926 /* Test for non-empty perf_device and perf_event */ in parse_add_command_msr()
9965 int fd_telem_dir = -1; in pmt_parse_from_path()
9969 int ret = -1; in pmt_parse_from_path()
9972 if (fd_target_dir == -1) { in pmt_parse_from_path()
9973 return -1; in pmt_parse_from_path()
9976 if (fstat(fd_target_dir, &target_stat) == -1) { in pmt_parse_from_path()
9993 fd_telem_dir = openat(dirfd(pmt_iter.dir), dirname->d_name, O_RDONLY | O_DIRECTORY); in pmt_parse_from_path()
9994 if (fd_telem_dir == -1) in pmt_parse_from_path()
10002 if (fstat(fd_telem_dir, &stat) == -1) { in pmt_parse_from_path()
10004 dirname->d_name, strerror(errno)); in pmt_parse_from_path()
10026 fd_telem_dir = -1; in pmt_parse_from_path()
10031 if (fd_telem_dir != -1) in pmt_parse_from_path()
10289 for (state = 10; state >= 0; --state) { in probe_cpuidle_residency()
10298 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ in probe_cpuidle_residency()
10299 sp = strchr(name_buf, '-'); in probe_cpuidle_residency()
10338 for (state = 10; state >= 0; --state) { in probe_cpuidle_counts()
10356 /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ in probe_cpuidle_counts()
10357 sp = strchr(name_buf, '-'); in probe_cpuidle_counts()
10386 *sp = '-'; in probe_cpuidle_counts()
10396 * 1,2,4..6,8-10 and set bits in cpu_subset
10428 fprintf(stderr, "\"--cpu %s\" malformed\n", optarg); in parse_cpu_command()
10430 exit(-1); in parse_cpu_command()
10449 { "hide", required_argument, 0, 'H' }, // meh, -h taken by --help in cmdline()
10454 { "no-msr", no_argument, 0, 'M' }, in cmdline()
10455 { "no-perf", no_argument, 0, 'P' }, in cmdline()
10467 * like adding the MSR counter with --add and at the same time using --no-msr. in cmdline()
10469 while ((opt = getopt_long_only(argc, argv, "+MPn:", long_options, &option_index)) != -1) { in cmdline()
10483 …pt = getopt_long_only(argc, argv, "+C:c:Dde:hi:Jn:o:qMST:v", long_options, &option_index)) != -1) { in cmdline()
10501 /* --enable specified counter */ in cmdline()
10513 * --hide: do not show those specified in cmdline()
10532 interval_tv.tv_usec = (interval - interval_tv.tv_sec) * 1000000; in cmdline()
10533 interval_ts.tv_nsec = (interval - interval_ts.tv_sec) * 1000000000; in cmdline()
10572 * --show: show only those specified in cmdline()
10621 if (ret == -1) in main()
10660 if (argc - optind) in main()