Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1 | /* |
| 2 | * turbostat -- show CPU frequency and C-state residency |
| 3 | * on modern Intel turbo-capable processors. |
| 4 | * |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 5 | * Copyright (c) 2013 Intel Corporation. |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 6 | * Len Brown <len.brown@intel.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms and conditions of the GNU General Public License, |
| 10 | * version 2, as published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | */ |
| 21 | |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 22 | #define _GNU_SOURCE |
Josh Triplett | b731f31 | 2013-08-20 17:20:12 -0700 | [diff] [blame] | 23 | #include MSRHEADER |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 24 | #include INTEL_FAMILY_HEADER |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 25 | #include <stdarg.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 26 | #include <stdio.h> |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 27 | #include <err.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 28 | #include <unistd.h> |
| 29 | #include <sys/types.h> |
| 30 | #include <sys/wait.h> |
| 31 | #include <sys/stat.h> |
| 32 | #include <sys/resource.h> |
| 33 | #include <fcntl.h> |
| 34 | #include <signal.h> |
| 35 | #include <sys/time.h> |
| 36 | #include <stdlib.h> |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 37 | #include <getopt.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 38 | #include <dirent.h> |
| 39 | #include <string.h> |
| 40 | #include <ctype.h> |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 41 | #include <sched.h> |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 42 | #include <time.h> |
Josh Triplett | 2b92865 | 2013-08-20 17:20:14 -0700 | [diff] [blame] | 43 | #include <cpuid.h> |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 44 | #include <linux/capability.h> |
| 45 | #include <errno.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 46 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 47 | char *proc_stat = "/proc/stat"; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 48 | FILE *outf; |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 49 | int *fd_percpu; |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 50 | struct timespec interval_ts = {5, 0}; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 51 | unsigned int debug; |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 52 | unsigned int quiet; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 53 | unsigned int sums_need_wide_columns; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 54 | unsigned int rapl_joules; |
| 55 | unsigned int summary_only; |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 56 | unsigned int list_header_only; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 57 | unsigned int dump_only; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 58 | unsigned int do_snb_cstates; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 59 | unsigned int do_knl_cstates; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 60 | unsigned int do_skl_residency; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 61 | unsigned int do_slm_cstates; |
| 62 | unsigned int use_c1_residency_msr; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 63 | unsigned int has_aperf; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 64 | unsigned int has_epb; |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 65 | unsigned int do_irtl_snb; |
| 66 | unsigned int do_irtl_hsw; |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 67 | unsigned int units = 1000000; /* MHz etc */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 68 | unsigned int genuine_intel; |
| 69 | unsigned int has_invariant_tsc; |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 70 | unsigned int do_nhm_platform_info; |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 71 | unsigned int no_MSR_MISC_PWR_MGMT; |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 72 | unsigned int aperf_mperf_multiplier = 1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 73 | double bclk; |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 74 | double base_hz; |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 75 | unsigned int has_base_hz; |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 76 | double tsc_tweak = 1.0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 77 | unsigned int show_pkg_only; |
| 78 | unsigned int show_core_only; |
| 79 | char *output_buffer, *outp; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 80 | unsigned int do_rapl; |
| 81 | unsigned int do_dts; |
| 82 | unsigned int do_ptm; |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 83 | unsigned long long gfx_cur_rc6_ms; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 84 | unsigned int gfx_cur_mhz; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 85 | unsigned int tcc_activation_temp; |
| 86 | unsigned int tcc_activation_temp_override; |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 87 | double rapl_power_units, rapl_time_units; |
| 88 | double rapl_dram_energy_units, rapl_energy_units; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 89 | double rapl_joule_counter_range; |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 90 | unsigned int do_core_perf_limit_reasons; |
| 91 | unsigned int do_gfx_perf_limit_reasons; |
| 92 | unsigned int do_ring_perf_limit_reasons; |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 93 | unsigned int crystal_hz; |
| 94 | unsigned long long tsc_hz; |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 95 | int base_cpu; |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 96 | double discover_bclk(unsigned int family, unsigned int model); |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 97 | unsigned int has_hwp; /* IA32_PM_ENABLE, IA32_HWP_CAPABILITIES */ |
| 98 | /* IA32_HWP_REQUEST, IA32_HWP_STATUS */ |
| 99 | unsigned int has_hwp_notify; /* IA32_HWP_INTERRUPT */ |
| 100 | unsigned int has_hwp_activity_window; /* IA32_HWP_REQUEST[bits 41:32] */ |
| 101 | unsigned int has_hwp_epp; /* IA32_HWP_REQUEST[bits 31:24] */ |
| 102 | unsigned int has_hwp_pkg; /* IA32_HWP_REQUEST_PKG */ |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 103 | unsigned int has_misc_feature_control; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 104 | |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 105 | #define RAPL_PKG (1 << 0) |
| 106 | /* 0x610 MSR_PKG_POWER_LIMIT */ |
| 107 | /* 0x611 MSR_PKG_ENERGY_STATUS */ |
| 108 | #define RAPL_PKG_PERF_STATUS (1 << 1) |
| 109 | /* 0x613 MSR_PKG_PERF_STATUS */ |
| 110 | #define RAPL_PKG_POWER_INFO (1 << 2) |
| 111 | /* 0x614 MSR_PKG_POWER_INFO */ |
| 112 | |
| 113 | #define RAPL_DRAM (1 << 3) |
| 114 | /* 0x618 MSR_DRAM_POWER_LIMIT */ |
| 115 | /* 0x619 MSR_DRAM_ENERGY_STATUS */ |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 116 | #define RAPL_DRAM_PERF_STATUS (1 << 4) |
| 117 | /* 0x61b MSR_DRAM_PERF_STATUS */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 118 | #define RAPL_DRAM_POWER_INFO (1 << 5) |
| 119 | /* 0x61c MSR_DRAM_POWER_INFO */ |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 120 | |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 121 | #define RAPL_CORES_POWER_LIMIT (1 << 6) |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 122 | /* 0x638 MSR_PP0_POWER_LIMIT */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 123 | #define RAPL_CORE_POLICY (1 << 7) |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 124 | /* 0x63a MSR_PP0_POLICY */ |
| 125 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 126 | #define RAPL_GFX (1 << 8) |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 127 | /* 0x640 MSR_PP1_POWER_LIMIT */ |
| 128 | /* 0x641 MSR_PP1_ENERGY_STATUS */ |
| 129 | /* 0x642 MSR_PP1_POLICY */ |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 130 | |
| 131 | #define RAPL_CORES_ENERGY_STATUS (1 << 9) |
| 132 | /* 0x639 MSR_PP0_ENERGY_STATUS */ |
| 133 | #define RAPL_CORES (RAPL_CORES_ENERGY_STATUS | RAPL_CORES_POWER_LIMIT) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 134 | #define TJMAX_DEFAULT 100 |
| 135 | |
| 136 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 137 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 138 | /* |
| 139 | * buffer size used by sscanf() for added column names |
| 140 | * Usually truncated to 7 characters, but also handles 18 columns for raw 64-bit counters |
| 141 | */ |
| 142 | #define NAME_BYTES 20 |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 143 | #define PATH_BYTES 128 |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 144 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 145 | int backwards_count; |
| 146 | char *progname; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 147 | |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 148 | #define CPU_SUBSET_MAXCPUS 1024 /* need to use before probe... */ |
| 149 | cpu_set_t *cpu_present_set, *cpu_affinity_set, *cpu_subset; |
| 150 | size_t cpu_present_setsize, cpu_affinity_setsize, cpu_subset_size; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 151 | #define MAX_ADDED_COUNTERS 16 |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 152 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 153 | struct thread_data { |
| 154 | unsigned long long tsc; |
| 155 | unsigned long long aperf; |
| 156 | unsigned long long mperf; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 157 | unsigned long long c1; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 158 | unsigned long long irq_count; |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 159 | unsigned int smi_count; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 160 | unsigned int cpu_id; |
| 161 | unsigned int flags; |
| 162 | #define CPU_IS_FIRST_THREAD_IN_CORE 0x2 |
| 163 | #define CPU_IS_FIRST_CORE_IN_PACKAGE 0x4 |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 164 | unsigned long long counter[MAX_ADDED_COUNTERS]; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 165 | } *thread_even, *thread_odd; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 166 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 167 | struct core_data { |
| 168 | unsigned long long c3; |
| 169 | unsigned long long c6; |
| 170 | unsigned long long c7; |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 171 | unsigned long long mc6_us; /* duplicate as per-core for now, even though per module */ |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 172 | unsigned int core_temp_c; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 173 | unsigned int core_id; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 174 | unsigned long long counter[MAX_ADDED_COUNTERS]; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 175 | } *core_even, *core_odd; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 176 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 177 | struct pkg_data { |
| 178 | unsigned long long pc2; |
| 179 | unsigned long long pc3; |
| 180 | unsigned long long pc6; |
| 181 | unsigned long long pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 182 | unsigned long long pc8; |
| 183 | unsigned long long pc9; |
| 184 | unsigned long long pc10; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 185 | unsigned long long pkg_wtd_core_c0; |
| 186 | unsigned long long pkg_any_core_c0; |
| 187 | unsigned long long pkg_any_gfxe_c0; |
| 188 | unsigned long long pkg_both_core_gfxe_c0; |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 189 | long long gfx_rc6_ms; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 190 | unsigned int gfx_mhz; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 191 | unsigned int package_id; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 192 | unsigned int energy_pkg; /* MSR_PKG_ENERGY_STATUS */ |
| 193 | unsigned int energy_dram; /* MSR_DRAM_ENERGY_STATUS */ |
| 194 | unsigned int energy_cores; /* MSR_PP0_ENERGY_STATUS */ |
| 195 | unsigned int energy_gfx; /* MSR_PP1_ENERGY_STATUS */ |
| 196 | unsigned int rapl_pkg_perf_status; /* MSR_PKG_PERF_STATUS */ |
| 197 | unsigned int rapl_dram_perf_status; /* MSR_DRAM_PERF_STATUS */ |
| 198 | unsigned int pkg_temp_c; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 199 | unsigned long long counter[MAX_ADDED_COUNTERS]; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 200 | } *package_even, *package_odd; |
| 201 | |
| 202 | #define ODD_COUNTERS thread_odd, core_odd, package_odd |
| 203 | #define EVEN_COUNTERS thread_even, core_even, package_even |
| 204 | |
| 205 | #define GET_THREAD(thread_base, thread_no, core_no, pkg_no) \ |
| 206 | (thread_base + (pkg_no) * topo.num_cores_per_pkg * \ |
| 207 | topo.num_threads_per_core + \ |
| 208 | (core_no) * topo.num_threads_per_core + (thread_no)) |
| 209 | #define GET_CORE(core_base, core_no, pkg_no) \ |
| 210 | (core_base + (pkg_no) * topo.num_cores_per_pkg + (core_no)) |
| 211 | #define GET_PKG(pkg_base, pkg_no) (pkg_base + pkg_no) |
| 212 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 213 | enum counter_scope {SCOPE_CPU, SCOPE_CORE, SCOPE_PACKAGE}; |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 214 | enum counter_type {COUNTER_ITEMS, COUNTER_CYCLES, COUNTER_SECONDS, COUNTER_USEC}; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 215 | enum counter_format {FORMAT_RAW, FORMAT_DELTA, FORMAT_PERCENT}; |
| 216 | |
| 217 | struct msr_counter { |
| 218 | unsigned int msr_num; |
| 219 | char name[NAME_BYTES]; |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 220 | char path[PATH_BYTES]; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 221 | unsigned int width; |
| 222 | enum counter_type type; |
| 223 | enum counter_format format; |
| 224 | struct msr_counter *next; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 225 | unsigned int flags; |
| 226 | #define FLAGS_HIDE (1 << 0) |
| 227 | #define FLAGS_SHOW (1 << 1) |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 228 | #define SYSFS_PERCPU (1 << 1) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 229 | }; |
| 230 | |
| 231 | struct sys_counters { |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 232 | unsigned int added_thread_counters; |
| 233 | unsigned int added_core_counters; |
| 234 | unsigned int added_package_counters; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 235 | struct msr_counter *tp; |
| 236 | struct msr_counter *cp; |
| 237 | struct msr_counter *pp; |
| 238 | } sys; |
| 239 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 240 | struct system_summary { |
| 241 | struct thread_data threads; |
| 242 | struct core_data cores; |
| 243 | struct pkg_data packages; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 244 | } average; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 245 | |
| 246 | |
| 247 | struct topo_params { |
| 248 | int num_packages; |
| 249 | int num_cpus; |
| 250 | int num_cores; |
| 251 | int max_cpu_num; |
| 252 | int num_cores_per_pkg; |
| 253 | int num_threads_per_core; |
| 254 | } topo; |
| 255 | |
| 256 | struct timeval tv_even, tv_odd, tv_delta; |
| 257 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 258 | int *irq_column_2_cpu; /* /proc/interrupts column numbers */ |
| 259 | int *irqs_per_cpu; /* indexed by cpu_num */ |
| 260 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 261 | void setup_all_buffers(void); |
| 262 | |
| 263 | int cpu_is_not_present(int cpu) |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 264 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 265 | return !CPU_ISSET_S(cpu, cpu_present_setsize, cpu_present_set); |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 266 | } |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 267 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 268 | * run func(thread, core, package) in topology order |
| 269 | * skip non-present cpus |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 270 | */ |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 271 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 272 | int for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg_data *), |
| 273 | struct thread_data *thread_base, struct core_data *core_base, struct pkg_data *pkg_base) |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 274 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 275 | int retval, pkg_no, core_no, thread_no; |
| 276 | |
| 277 | for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { |
| 278 | for (core_no = 0; core_no < topo.num_cores_per_pkg; ++core_no) { |
| 279 | for (thread_no = 0; thread_no < |
| 280 | topo.num_threads_per_core; ++thread_no) { |
| 281 | struct thread_data *t; |
| 282 | struct core_data *c; |
| 283 | struct pkg_data *p; |
| 284 | |
| 285 | t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); |
| 286 | |
| 287 | if (cpu_is_not_present(t->cpu_id)) |
| 288 | continue; |
| 289 | |
| 290 | c = GET_CORE(core_base, core_no, pkg_no); |
| 291 | p = GET_PKG(pkg_base, pkg_no); |
| 292 | |
| 293 | retval = func(t, c, p); |
| 294 | if (retval) |
| 295 | return retval; |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | return 0; |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | int cpu_migrate(int cpu) |
| 303 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 304 | CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); |
| 305 | CPU_SET_S(cpu, cpu_affinity_setsize, cpu_affinity_set); |
| 306 | if (sched_setaffinity(0, cpu_affinity_setsize, cpu_affinity_set) == -1) |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 307 | return -1; |
| 308 | else |
| 309 | return 0; |
| 310 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 311 | int get_msr_fd(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 312 | { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 313 | char pathname[32]; |
| 314 | int fd; |
| 315 | |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 316 | fd = fd_percpu[cpu]; |
| 317 | |
| 318 | if (fd) |
| 319 | return fd; |
| 320 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 321 | sprintf(pathname, "/dev/cpu/%d/msr", cpu); |
| 322 | fd = open(pathname, O_RDONLY); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 323 | if (fd < 0) |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 324 | err(-1, "%s open failed, try chown or chmod +r /dev/cpu/*/msr, or run as root", pathname); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 325 | |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 326 | fd_percpu[cpu] = fd; |
| 327 | |
| 328 | return fd; |
| 329 | } |
| 330 | |
| 331 | int get_msr(int cpu, off_t offset, unsigned long long *msr) |
| 332 | { |
| 333 | ssize_t retval; |
| 334 | |
| 335 | retval = pread(get_msr_fd(cpu), msr, sizeof(*msr), offset); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 336 | |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 337 | if (retval != sizeof *msr) |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 338 | err(-1, "cpu%d: msr offset 0x%llx read failed", cpu, (unsigned long long)offset); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 339 | |
| 340 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 341 | } |
| 342 | |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 343 | /* |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 344 | * Each string in this array is compared in --show and --hide cmdline. |
| 345 | * Thus, strings that are proper sub-sets must follow their more specific peers. |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 346 | */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 347 | struct msr_counter bic[] = { |
| 348 | { 0x0, "Package" }, |
| 349 | { 0x0, "Avg_MHz" }, |
| 350 | { 0x0, "Bzy_MHz" }, |
| 351 | { 0x0, "TSC_MHz" }, |
| 352 | { 0x0, "IRQ" }, |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 353 | { 0x0, "SMI", "", 32, 0, FORMAT_DELTA, NULL}, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 354 | { 0x0, "Busy%" }, |
| 355 | { 0x0, "CPU%c1" }, |
| 356 | { 0x0, "CPU%c3" }, |
| 357 | { 0x0, "CPU%c6" }, |
| 358 | { 0x0, "CPU%c7" }, |
| 359 | { 0x0, "ThreadC" }, |
| 360 | { 0x0, "CoreTmp" }, |
| 361 | { 0x0, "CoreCnt" }, |
| 362 | { 0x0, "PkgTmp" }, |
| 363 | { 0x0, "GFX%rc6" }, |
| 364 | { 0x0, "GFXMHz" }, |
| 365 | { 0x0, "Pkg%pc2" }, |
| 366 | { 0x0, "Pkg%pc3" }, |
| 367 | { 0x0, "Pkg%pc6" }, |
| 368 | { 0x0, "Pkg%pc7" }, |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 369 | { 0x0, "Pkg%pc8" }, |
| 370 | { 0x0, "Pkg%pc9" }, |
| 371 | { 0x0, "Pkg%pc10" }, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 372 | { 0x0, "PkgWatt" }, |
| 373 | { 0x0, "CorWatt" }, |
| 374 | { 0x0, "GFXWatt" }, |
| 375 | { 0x0, "PkgCnt" }, |
| 376 | { 0x0, "RAMWatt" }, |
| 377 | { 0x0, "PKG_%" }, |
| 378 | { 0x0, "RAM_%" }, |
| 379 | { 0x0, "Pkg_J" }, |
| 380 | { 0x0, "Cor_J" }, |
| 381 | { 0x0, "GFX_J" }, |
| 382 | { 0x0, "RAM_J" }, |
| 383 | { 0x0, "Core" }, |
| 384 | { 0x0, "CPU" }, |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 385 | { 0x0, "Mod%c6" }, |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 386 | { 0x0, "sysfs" }, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 387 | }; |
| 388 | |
| 389 | #define MAX_BIC (sizeof(bic) / sizeof(struct msr_counter)) |
| 390 | #define BIC_Package (1ULL << 0) |
| 391 | #define BIC_Avg_MHz (1ULL << 1) |
| 392 | #define BIC_Bzy_MHz (1ULL << 2) |
| 393 | #define BIC_TSC_MHz (1ULL << 3) |
| 394 | #define BIC_IRQ (1ULL << 4) |
| 395 | #define BIC_SMI (1ULL << 5) |
| 396 | #define BIC_Busy (1ULL << 6) |
| 397 | #define BIC_CPU_c1 (1ULL << 7) |
| 398 | #define BIC_CPU_c3 (1ULL << 8) |
| 399 | #define BIC_CPU_c6 (1ULL << 9) |
| 400 | #define BIC_CPU_c7 (1ULL << 10) |
| 401 | #define BIC_ThreadC (1ULL << 11) |
| 402 | #define BIC_CoreTmp (1ULL << 12) |
| 403 | #define BIC_CoreCnt (1ULL << 13) |
| 404 | #define BIC_PkgTmp (1ULL << 14) |
| 405 | #define BIC_GFX_rc6 (1ULL << 15) |
| 406 | #define BIC_GFXMHz (1ULL << 16) |
| 407 | #define BIC_Pkgpc2 (1ULL << 17) |
| 408 | #define BIC_Pkgpc3 (1ULL << 18) |
| 409 | #define BIC_Pkgpc6 (1ULL << 19) |
| 410 | #define BIC_Pkgpc7 (1ULL << 20) |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 411 | #define BIC_Pkgpc8 (1ULL << 21) |
| 412 | #define BIC_Pkgpc9 (1ULL << 22) |
| 413 | #define BIC_Pkgpc10 (1ULL << 23) |
| 414 | #define BIC_PkgWatt (1ULL << 24) |
| 415 | #define BIC_CorWatt (1ULL << 25) |
| 416 | #define BIC_GFXWatt (1ULL << 26) |
| 417 | #define BIC_PkgCnt (1ULL << 27) |
| 418 | #define BIC_RAMWatt (1ULL << 28) |
| 419 | #define BIC_PKG__ (1ULL << 29) |
| 420 | #define BIC_RAM__ (1ULL << 30) |
| 421 | #define BIC_Pkg_J (1ULL << 31) |
| 422 | #define BIC_Cor_J (1ULL << 32) |
| 423 | #define BIC_GFX_J (1ULL << 33) |
| 424 | #define BIC_RAM_J (1ULL << 34) |
| 425 | #define BIC_Core (1ULL << 35) |
| 426 | #define BIC_CPU (1ULL << 36) |
| 427 | #define BIC_Mod_c6 (1ULL << 37) |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 428 | #define BIC_sysfs (1ULL << 38) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 429 | |
| 430 | unsigned long long bic_enabled = 0xFFFFFFFFFFFFFFFFULL; |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 431 | unsigned long long bic_present = BIC_sysfs; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 432 | |
| 433 | #define DO_BIC(COUNTER_NAME) (bic_enabled & bic_present & COUNTER_NAME) |
| 434 | #define BIC_PRESENT(COUNTER_BIT) (bic_present |= COUNTER_BIT) |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 435 | #define BIC_NOT_PRESENT(COUNTER_BIT) (bic_present &= ~COUNTER_BIT) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 436 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 437 | #define MAX_DEFERRED 16 |
| 438 | char *deferred_skip_names[MAX_DEFERRED]; |
| 439 | int deferred_skip_index; |
| 440 | |
| 441 | /* |
| 442 | * HIDE_LIST - hide this list of counters, show the rest [default] |
| 443 | * SHOW_LIST - show this list of counters, hide the rest |
| 444 | */ |
| 445 | enum show_hide_mode { SHOW_LIST, HIDE_LIST } global_show_hide_mode = HIDE_LIST; |
| 446 | |
| 447 | void help(void) |
| 448 | { |
| 449 | fprintf(outf, |
| 450 | "Usage: turbostat [OPTIONS][(--interval seconds) | COMMAND ...]\n" |
| 451 | "\n" |
| 452 | "Turbostat forks the specified COMMAND and prints statistics\n" |
| 453 | "when COMMAND completes.\n" |
| 454 | "If no COMMAND is specified, turbostat wakes every 5-seconds\n" |
| 455 | "to print statistics, until interrupted.\n" |
| 456 | "--add add a counter\n" |
| 457 | " eg. --add msr0x10,u64,cpu,delta,MY_TSC\n" |
| 458 | "--cpu cpu-set limit output to summary plus cpu-set:\n" |
| 459 | " {core | package | j,k,l..m,n-p }\n" |
| 460 | "--quiet skip decoding system configuration header\n" |
| 461 | "--interval sec Override default 5-second measurement interval\n" |
| 462 | "--help print this help message\n" |
| 463 | "--list list column headers only\n" |
| 464 | "--out file create or truncate \"file\" for all output\n" |
| 465 | "--version print version information\n" |
| 466 | "\n" |
| 467 | "For more help, run \"man turbostat\"\n"); |
| 468 | } |
| 469 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 470 | /* |
| 471 | * bic_lookup |
| 472 | * for all the strings in comma separate name_list, |
| 473 | * set the approprate bit in return value. |
| 474 | */ |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 475 | unsigned long long bic_lookup(char *name_list, enum show_hide_mode mode) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 476 | { |
| 477 | int i; |
| 478 | unsigned long long retval = 0; |
| 479 | |
| 480 | while (name_list) { |
| 481 | char *comma; |
| 482 | |
| 483 | comma = strchr(name_list, ','); |
| 484 | |
| 485 | if (comma) |
| 486 | *comma = '\0'; |
| 487 | |
| 488 | for (i = 0; i < MAX_BIC; ++i) { |
| 489 | if (!strcmp(name_list, bic[i].name)) { |
| 490 | retval |= (1ULL << i); |
| 491 | break; |
| 492 | } |
| 493 | } |
| 494 | if (i == MAX_BIC) { |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 495 | if (mode == SHOW_LIST) { |
| 496 | fprintf(stderr, "Invalid counter name: %s\n", name_list); |
| 497 | exit(-1); |
| 498 | } |
| 499 | deferred_skip_names[deferred_skip_index++] = name_list; |
| 500 | if (debug) |
| 501 | fprintf(stderr, "deferred \"%s\"\n", name_list); |
| 502 | if (deferred_skip_index >= MAX_DEFERRED) { |
| 503 | fprintf(stderr, "More than max %d un-recognized --skip options '%s'\n", |
| 504 | MAX_DEFERRED, name_list); |
| 505 | help(); |
| 506 | exit(1); |
| 507 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | name_list = comma; |
| 511 | if (name_list) |
| 512 | name_list++; |
| 513 | |
| 514 | } |
| 515 | return retval; |
| 516 | } |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 517 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 518 | |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 519 | void print_header(char *delim) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 520 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 521 | struct msr_counter *mp; |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 522 | int printed = 0; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 523 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 524 | if (DO_BIC(BIC_Package)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 525 | outp += sprintf(outp, "%sPackage", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 526 | if (DO_BIC(BIC_Core)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 527 | outp += sprintf(outp, "%sCore", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 528 | if (DO_BIC(BIC_CPU)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 529 | outp += sprintf(outp, "%sCPU", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 530 | if (DO_BIC(BIC_Avg_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 531 | outp += sprintf(outp, "%sAvg_MHz", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 532 | if (DO_BIC(BIC_Busy)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 533 | outp += sprintf(outp, "%sBusy%%", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 534 | if (DO_BIC(BIC_Bzy_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 535 | outp += sprintf(outp, "%sBzy_MHz", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 536 | if (DO_BIC(BIC_TSC_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 537 | outp += sprintf(outp, "%sTSC_MHz", (printed++ ? delim : "")); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 538 | |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 539 | if (DO_BIC(BIC_IRQ)) { |
| 540 | if (sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 541 | outp += sprintf(outp, "%s IRQ", (printed++ ? delim : "")); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 542 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 543 | outp += sprintf(outp, "%sIRQ", (printed++ ? delim : "")); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 544 | } |
| 545 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 546 | if (DO_BIC(BIC_SMI)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 547 | outp += sprintf(outp, "%sSMI", (printed++ ? delim : "")); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 548 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 549 | for (mp = sys.tp; mp; mp = mp->next) { |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 550 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 551 | if (mp->format == FORMAT_RAW) { |
| 552 | if (mp->width == 64) |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 553 | outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 554 | else |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 555 | outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 556 | } else { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 557 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 558 | outp += sprintf(outp, "%s%8s", (printed++ ? delim : ""), mp->name); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 559 | else |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 560 | outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 564 | if (DO_BIC(BIC_CPU_c1)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 565 | outp += sprintf(outp, "%sCPU%%c1", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 566 | if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 567 | outp += sprintf(outp, "%sCPU%%c3", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 568 | if (DO_BIC(BIC_CPU_c6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 569 | outp += sprintf(outp, "%sCPU%%c6", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 570 | if (DO_BIC(BIC_CPU_c7)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 571 | outp += sprintf(outp, "%sCPU%%c7", (printed++ ? delim : "")); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 572 | |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 573 | if (DO_BIC(BIC_Mod_c6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 574 | outp += sprintf(outp, "%sMod%%c6", (printed++ ? delim : "")); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 575 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 576 | if (DO_BIC(BIC_CoreTmp)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 577 | outp += sprintf(outp, "%sCoreTmp", (printed++ ? delim : "")); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 578 | |
| 579 | for (mp = sys.cp; mp; mp = mp->next) { |
| 580 | if (mp->format == FORMAT_RAW) { |
| 581 | if (mp->width == 64) |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 582 | outp += sprintf(outp, "%s%18.18s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 583 | else |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 584 | outp += sprintf(outp, "%s%10.10s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 585 | } else { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 586 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
| 587 | outp += sprintf(outp, "%s%8s", delim, mp->name); |
| 588 | else |
| 589 | outp += sprintf(outp, "%s%s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 590 | } |
| 591 | } |
| 592 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 593 | if (DO_BIC(BIC_PkgTmp)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 594 | outp += sprintf(outp, "%sPkgTmp", (printed++ ? delim : "")); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 595 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 596 | if (DO_BIC(BIC_GFX_rc6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 597 | outp += sprintf(outp, "%sGFX%%rc6", (printed++ ? delim : "")); |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 598 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 599 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 600 | outp += sprintf(outp, "%sGFXMHz", (printed++ ? delim : "")); |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 601 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 602 | if (do_skl_residency) { |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 603 | outp += sprintf(outp, "%sTotl%%C0", (printed++ ? delim : "")); |
| 604 | outp += sprintf(outp, "%sAny%%C0", (printed++ ? delim : "")); |
| 605 | outp += sprintf(outp, "%sGFX%%C0", (printed++ ? delim : "")); |
| 606 | outp += sprintf(outp, "%sCPUGFX%%", (printed++ ? delim : "")); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 607 | } |
| 608 | |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 609 | if (DO_BIC(BIC_Pkgpc2)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 610 | outp += sprintf(outp, "%sPkg%%pc2", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 611 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 612 | outp += sprintf(outp, "%sPkg%%pc3", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 613 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 614 | outp += sprintf(outp, "%sPkg%%pc6", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 615 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 616 | outp += sprintf(outp, "%sPkg%%pc7", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 617 | if (DO_BIC(BIC_Pkgpc8)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 618 | outp += sprintf(outp, "%sPkg%%pc8", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 619 | if (DO_BIC(BIC_Pkgpc9)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 620 | outp += sprintf(outp, "%sPkg%%pc9", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 621 | if (DO_BIC(BIC_Pkgpc10)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 622 | outp += sprintf(outp, "%sPk%%pc10", (printed++ ? delim : "")); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 623 | |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 624 | if (do_rapl && !rapl_joules) { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 625 | if (DO_BIC(BIC_PkgWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 626 | outp += sprintf(outp, "%sPkgWatt", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 627 | if (DO_BIC(BIC_CorWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 628 | outp += sprintf(outp, "%sCorWatt", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 629 | if (DO_BIC(BIC_GFXWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 630 | outp += sprintf(outp, "%sGFXWatt", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 631 | if (DO_BIC(BIC_RAMWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 632 | outp += sprintf(outp, "%sRAMWatt", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 633 | if (DO_BIC(BIC_PKG__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 634 | outp += sprintf(outp, "%sPKG_%%", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 635 | if (DO_BIC(BIC_RAM__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 636 | outp += sprintf(outp, "%sRAM_%%", (printed++ ? delim : "")); |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 637 | } else if (do_rapl && rapl_joules) { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 638 | if (DO_BIC(BIC_Pkg_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 639 | outp += sprintf(outp, "%sPkg_J", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 640 | if (DO_BIC(BIC_Cor_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 641 | outp += sprintf(outp, "%sCor_J", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 642 | if (DO_BIC(BIC_GFX_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 643 | outp += sprintf(outp, "%sGFX_J", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 644 | if (DO_BIC(BIC_RAM_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 645 | outp += sprintf(outp, "%sRAM_J", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 646 | if (DO_BIC(BIC_PKG__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 647 | outp += sprintf(outp, "%sPKG_%%", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 648 | if (DO_BIC(BIC_RAM__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 649 | outp += sprintf(outp, "%sRAM_%%", (printed++ ? delim : "")); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 650 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 651 | for (mp = sys.pp; mp; mp = mp->next) { |
| 652 | if (mp->format == FORMAT_RAW) { |
| 653 | if (mp->width == 64) |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 654 | outp += sprintf(outp, "%s%18.18s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 655 | else |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 656 | outp += sprintf(outp, "%s%10.10s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 657 | } else { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 658 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
| 659 | outp += sprintf(outp, "%s%8s", delim, mp->name); |
| 660 | else |
| 661 | outp += sprintf(outp, "%s%s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 665 | outp += sprintf(outp, "\n"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 666 | } |
| 667 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 668 | int dump_counters(struct thread_data *t, struct core_data *c, |
| 669 | struct pkg_data *p) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 670 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 671 | int i; |
| 672 | struct msr_counter *mp; |
| 673 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 674 | outp += sprintf(outp, "t %p, c %p, p %p\n", t, c, p); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 675 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 676 | if (t) { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 677 | outp += sprintf(outp, "CPU: %d flags 0x%x\n", |
| 678 | t->cpu_id, t->flags); |
| 679 | outp += sprintf(outp, "TSC: %016llX\n", t->tsc); |
| 680 | outp += sprintf(outp, "aperf: %016llX\n", t->aperf); |
| 681 | outp += sprintf(outp, "mperf: %016llX\n", t->mperf); |
| 682 | outp += sprintf(outp, "c1: %016llX\n", t->c1); |
Len Brown | 6886fee | 2016-12-24 15:18:37 -0500 | [diff] [blame] | 683 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 684 | if (DO_BIC(BIC_IRQ)) |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 685 | outp += sprintf(outp, "IRQ: %lld\n", t->irq_count); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 686 | if (DO_BIC(BIC_SMI)) |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 687 | outp += sprintf(outp, "SMI: %d\n", t->smi_count); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 688 | |
| 689 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 690 | outp += sprintf(outp, "tADDED [%d] msr0x%x: %08llX\n", |
| 691 | i, mp->msr_num, t->counter[i]); |
| 692 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 693 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 694 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 695 | if (c) { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 696 | outp += sprintf(outp, "core: %d\n", c->core_id); |
| 697 | outp += sprintf(outp, "c3: %016llX\n", c->c3); |
| 698 | outp += sprintf(outp, "c6: %016llX\n", c->c6); |
| 699 | outp += sprintf(outp, "c7: %016llX\n", c->c7); |
| 700 | outp += sprintf(outp, "DTS: %dC\n", c->core_temp_c); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 701 | |
| 702 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 703 | outp += sprintf(outp, "cADDED [%d] msr0x%x: %08llX\n", |
| 704 | i, mp->msr_num, c->counter[i]); |
| 705 | } |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 706 | outp += sprintf(outp, "mc6_us: %016llX\n", c->mc6_us); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | if (p) { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 710 | outp += sprintf(outp, "package: %d\n", p->package_id); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 711 | |
| 712 | outp += sprintf(outp, "Weighted cores: %016llX\n", p->pkg_wtd_core_c0); |
| 713 | outp += sprintf(outp, "Any cores: %016llX\n", p->pkg_any_core_c0); |
| 714 | outp += sprintf(outp, "Any GFX: %016llX\n", p->pkg_any_gfxe_c0); |
| 715 | outp += sprintf(outp, "CPU + GFX: %016llX\n", p->pkg_both_core_gfxe_c0); |
| 716 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 717 | outp += sprintf(outp, "pc2: %016llX\n", p->pc2); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 718 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 719 | outp += sprintf(outp, "pc3: %016llX\n", p->pc3); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 720 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 721 | outp += sprintf(outp, "pc6: %016llX\n", p->pc6); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 722 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 723 | outp += sprintf(outp, "pc7: %016llX\n", p->pc7); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 724 | outp += sprintf(outp, "pc8: %016llX\n", p->pc8); |
| 725 | outp += sprintf(outp, "pc9: %016llX\n", p->pc9); |
| 726 | outp += sprintf(outp, "pc10: %016llX\n", p->pc10); |
| 727 | outp += sprintf(outp, "Joules PKG: %0X\n", p->energy_pkg); |
| 728 | outp += sprintf(outp, "Joules COR: %0X\n", p->energy_cores); |
| 729 | outp += sprintf(outp, "Joules GFX: %0X\n", p->energy_gfx); |
| 730 | outp += sprintf(outp, "Joules RAM: %0X\n", p->energy_dram); |
| 731 | outp += sprintf(outp, "Throttle PKG: %0X\n", |
| 732 | p->rapl_pkg_perf_status); |
| 733 | outp += sprintf(outp, "Throttle RAM: %0X\n", |
| 734 | p->rapl_dram_perf_status); |
| 735 | outp += sprintf(outp, "PTM: %dC\n", p->pkg_temp_c); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 736 | |
| 737 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 738 | outp += sprintf(outp, "pADDED [%d] msr0x%x: %08llX\n", |
| 739 | i, mp->msr_num, p->counter[i]); |
| 740 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 741 | } |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 742 | |
| 743 | outp += sprintf(outp, "\n"); |
| 744 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 745 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 746 | } |
| 747 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 748 | /* |
| 749 | * column formatting convention & formats |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 750 | */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 751 | int format_counters(struct thread_data *t, struct core_data *c, |
| 752 | struct pkg_data *p) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 753 | { |
Len Brown | 008d396e | 2017-02-10 00:29:51 -0500 | [diff] [blame] | 754 | double interval_float, tsc; |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 755 | char *fmt8; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 756 | int i; |
| 757 | struct msr_counter *mp; |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 758 | char *delim = "\t"; |
| 759 | int printed = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 760 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 761 | /* if showing only 1st thread in core and this isn't one, bail out */ |
| 762 | if (show_core_only && !(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 763 | return 0; |
| 764 | |
| 765 | /* if showing only 1st thread in pkg and this isn't one, bail out */ |
| 766 | if (show_pkg_only && !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 767 | return 0; |
| 768 | |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 769 | /*if not summary line and --cpu is used */ |
| 770 | if ((t != &average.threads) && |
| 771 | (cpu_subset && !CPU_ISSET_S(t->cpu_id, cpu_subset_size, cpu_subset))) |
| 772 | return 0; |
| 773 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 774 | interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0; |
| 775 | |
Len Brown | 008d396e | 2017-02-10 00:29:51 -0500 | [diff] [blame] | 776 | tsc = t->tsc * tsc_tweak; |
| 777 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 778 | /* topo columns, print blanks on 1st (average) line */ |
| 779 | if (t == &average.threads) { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 780 | if (DO_BIC(BIC_Package)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 781 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 782 | if (DO_BIC(BIC_Core)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 783 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 784 | if (DO_BIC(BIC_CPU)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 785 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 786 | } else { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 787 | if (DO_BIC(BIC_Package)) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 788 | if (p) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 789 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->package_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 790 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 791 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 792 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 793 | if (DO_BIC(BIC_Core)) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 794 | if (c) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 795 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), c->core_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 796 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 797 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 798 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 799 | if (DO_BIC(BIC_CPU)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 800 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->cpu_id); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 801 | } |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 802 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 803 | if (DO_BIC(BIC_Avg_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 804 | outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 805 | 1.0 / units * t->aperf / interval_float); |
| 806 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 807 | if (DO_BIC(BIC_Busy)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 808 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->mperf/tsc); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 809 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 810 | if (DO_BIC(BIC_Bzy_MHz)) { |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 811 | if (has_base_hz) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 812 | outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), base_hz / units * t->aperf / t->mperf); |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 813 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 814 | outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), |
Len Brown | 008d396e | 2017-02-10 00:29:51 -0500 | [diff] [blame] | 815 | tsc / units * t->aperf / t->mperf / interval_float); |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 816 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 817 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 818 | if (DO_BIC(BIC_TSC_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 819 | outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), 1.0 * t->tsc/units/interval_float); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 820 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 821 | /* IRQ */ |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 822 | if (DO_BIC(BIC_IRQ)) { |
| 823 | if (sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 824 | outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), t->irq_count); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 825 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 826 | outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->irq_count); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 827 | } |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 828 | |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 829 | /* SMI */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 830 | if (DO_BIC(BIC_SMI)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 831 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->smi_count); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 832 | |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 833 | /* Added counters */ |
| 834 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 835 | if (mp->format == FORMAT_RAW) { |
| 836 | if (mp->width == 32) |
Len Brown | 5f3aea5 | 2017-02-23 18:10:27 -0500 | [diff] [blame] | 837 | outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int) t->counter[i]); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 838 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 839 | outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), t->counter[i]); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 840 | } else if (mp->format == FORMAT_DELTA) { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 841 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 842 | outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), t->counter[i]); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 843 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 844 | outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->counter[i]); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 845 | } else if (mp->format == FORMAT_PERCENT) { |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 846 | if (mp->type == COUNTER_USEC) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 847 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), t->counter[i]/interval_float/10000); |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 848 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 849 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->counter[i]/tsc); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 850 | } |
| 851 | } |
| 852 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 853 | /* C1 */ |
| 854 | if (DO_BIC(BIC_CPU_c1)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 855 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->c1/tsc); |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 856 | |
| 857 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 858 | /* print per-core data only for 1st thread in core */ |
| 859 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 860 | goto done; |
| 861 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 862 | if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 863 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c3/tsc); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 864 | if (DO_BIC(BIC_CPU_c6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 865 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c6/tsc); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 866 | if (DO_BIC(BIC_CPU_c7)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 867 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c7/tsc); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 868 | |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 869 | /* Mod%c6 */ |
| 870 | if (DO_BIC(BIC_Mod_c6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 871 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->mc6_us / tsc); |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 872 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 873 | if (DO_BIC(BIC_CoreTmp)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 874 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), c->core_temp_c); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 875 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 876 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 877 | if (mp->format == FORMAT_RAW) { |
| 878 | if (mp->width == 32) |
Len Brown | 5f3aea5 | 2017-02-23 18:10:27 -0500 | [diff] [blame] | 879 | outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int) c->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 880 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 881 | outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), c->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 882 | } else if (mp->format == FORMAT_DELTA) { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 883 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 884 | outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), c->counter[i]); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 885 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 886 | outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), c->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 887 | } else if (mp->format == FORMAT_PERCENT) { |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 888 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->counter[i]/tsc); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 889 | } |
| 890 | } |
| 891 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 892 | /* print per-package data only for 1st core in package */ |
| 893 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 894 | goto done; |
| 895 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 896 | /* PkgTmp */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 897 | if (DO_BIC(BIC_PkgTmp)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 898 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->pkg_temp_c); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 899 | |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 900 | /* GFXrc6 */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 901 | if (DO_BIC(BIC_GFX_rc6)) { |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 902 | if (p->gfx_rc6_ms == -1) { /* detect GFX counter reset */ |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 903 | outp += sprintf(outp, "%s**.**", (printed++ ? delim : "")); |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 904 | } else { |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 905 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 906 | p->gfx_rc6_ms / 10.0 / interval_float); |
| 907 | } |
| 908 | } |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 909 | |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 910 | /* GFXMHz */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 911 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 912 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->gfx_mhz); |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 913 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 914 | /* Totl%C0, Any%C0 GFX%C0 CPUGFX% */ |
| 915 | if (do_skl_residency) { |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 916 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_wtd_core_c0/tsc); |
| 917 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_any_core_c0/tsc); |
| 918 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_any_gfxe_c0/tsc); |
| 919 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_both_core_gfxe_c0/tsc); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 920 | } |
| 921 | |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 922 | if (DO_BIC(BIC_Pkgpc2)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 923 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc2/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 924 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 925 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc3/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 926 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 927 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc6/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 928 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 929 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc7/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 930 | if (DO_BIC(BIC_Pkgpc8)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 931 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc8/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 932 | if (DO_BIC(BIC_Pkgpc9)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 933 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc9/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 934 | if (DO_BIC(BIC_Pkgpc10)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 935 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc10/tsc); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 936 | |
| 937 | /* |
| 938 | * If measurement interval exceeds minimum RAPL Joule Counter range, |
| 939 | * indicate that results are suspect by printing "**" in fraction place. |
| 940 | */ |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 941 | if (interval_float < rapl_joule_counter_range) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 942 | fmt8 = "%s%.2f"; |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 943 | else |
Len Brown | e975db5 | 2016-04-06 23:56:02 -0400 | [diff] [blame] | 944 | fmt8 = "%6.0f**"; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 945 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 946 | if (DO_BIC(BIC_PkgWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 947 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_pkg * rapl_energy_units / interval_float); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 948 | if (DO_BIC(BIC_CorWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 949 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_cores * rapl_energy_units / interval_float); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 950 | if (DO_BIC(BIC_GFXWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 951 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_gfx * rapl_energy_units / interval_float); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 952 | if (DO_BIC(BIC_RAMWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 953 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_dram * rapl_dram_energy_units / interval_float); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 954 | if (DO_BIC(BIC_Pkg_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 955 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_pkg * rapl_energy_units); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 956 | if (DO_BIC(BIC_Cor_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 957 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_cores * rapl_energy_units); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 958 | if (DO_BIC(BIC_GFX_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 959 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_gfx * rapl_energy_units); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 960 | if (DO_BIC(BIC_RAM_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 961 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_dram * rapl_dram_energy_units); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 962 | if (DO_BIC(BIC_PKG__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 963 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), 100.0 * p->rapl_pkg_perf_status * rapl_time_units / interval_float); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 964 | if (DO_BIC(BIC_RAM__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 965 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), 100.0 * p->rapl_dram_perf_status * rapl_time_units / interval_float); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 966 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 967 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 968 | if (mp->format == FORMAT_RAW) { |
| 969 | if (mp->width == 32) |
Len Brown | 5f3aea5 | 2017-02-23 18:10:27 -0500 | [diff] [blame] | 970 | outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int) p->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 971 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 972 | outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), p->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 973 | } else if (mp->format == FORMAT_DELTA) { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 974 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 975 | outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), p->counter[i]); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 976 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 977 | outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), p->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 978 | } else if (mp->format == FORMAT_PERCENT) { |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 979 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->counter[i]/tsc); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 980 | } |
| 981 | } |
| 982 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 983 | done: |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 984 | outp += sprintf(outp, "\n"); |
| 985 | |
| 986 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 987 | } |
| 988 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 989 | void flush_output_stdout(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 990 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 991 | FILE *filep; |
| 992 | |
| 993 | if (outf == stderr) |
| 994 | filep = stdout; |
| 995 | else |
| 996 | filep = outf; |
| 997 | |
| 998 | fputs(output_buffer, filep); |
| 999 | fflush(filep); |
| 1000 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1001 | outp = output_buffer; |
| 1002 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1003 | void flush_output_stderr(void) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1004 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1005 | fputs(output_buffer, outf); |
| 1006 | fflush(outf); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1007 | outp = output_buffer; |
| 1008 | } |
| 1009 | void format_all_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 1010 | { |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 1011 | static int printed; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1012 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 1013 | if (!printed || !summary_only) |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 1014 | print_header("\t"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1015 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1016 | if (topo.num_cpus > 1) |
| 1017 | format_counters(&average.threads, &average.cores, |
| 1018 | &average.packages); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1019 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 1020 | printed = 1; |
| 1021 | |
| 1022 | if (summary_only) |
| 1023 | return; |
| 1024 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1025 | for_all_cpus(format_counters, t, c, p); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1026 | } |
| 1027 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1028 | #define DELTA_WRAP32(new, old) \ |
| 1029 | if (new > old) { \ |
| 1030 | old = new - old; \ |
| 1031 | } else { \ |
| 1032 | old = 0x100000000 + new - old; \ |
| 1033 | } |
| 1034 | |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1035 | int |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1036 | delta_package(struct pkg_data *new, struct pkg_data *old) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1037 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1038 | int i; |
| 1039 | struct msr_counter *mp; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1040 | |
| 1041 | if (do_skl_residency) { |
| 1042 | old->pkg_wtd_core_c0 = new->pkg_wtd_core_c0 - old->pkg_wtd_core_c0; |
| 1043 | old->pkg_any_core_c0 = new->pkg_any_core_c0 - old->pkg_any_core_c0; |
| 1044 | old->pkg_any_gfxe_c0 = new->pkg_any_gfxe_c0 - old->pkg_any_gfxe_c0; |
| 1045 | old->pkg_both_core_gfxe_c0 = new->pkg_both_core_gfxe_c0 - old->pkg_both_core_gfxe_c0; |
| 1046 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1047 | old->pc2 = new->pc2 - old->pc2; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1048 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1049 | old->pc3 = new->pc3 - old->pc3; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1050 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1051 | old->pc6 = new->pc6 - old->pc6; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1052 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1053 | old->pc7 = new->pc7 - old->pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1054 | old->pc8 = new->pc8 - old->pc8; |
| 1055 | old->pc9 = new->pc9 - old->pc9; |
| 1056 | old->pc10 = new->pc10 - old->pc10; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1057 | old->pkg_temp_c = new->pkg_temp_c; |
| 1058 | |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 1059 | /* flag an error when rc6 counter resets/wraps */ |
| 1060 | if (old->gfx_rc6_ms > new->gfx_rc6_ms) |
| 1061 | old->gfx_rc6_ms = -1; |
| 1062 | else |
| 1063 | old->gfx_rc6_ms = new->gfx_rc6_ms - old->gfx_rc6_ms; |
| 1064 | |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1065 | old->gfx_mhz = new->gfx_mhz; |
| 1066 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1067 | DELTA_WRAP32(new->energy_pkg, old->energy_pkg); |
| 1068 | DELTA_WRAP32(new->energy_cores, old->energy_cores); |
| 1069 | DELTA_WRAP32(new->energy_gfx, old->energy_gfx); |
| 1070 | DELTA_WRAP32(new->energy_dram, old->energy_dram); |
| 1071 | DELTA_WRAP32(new->rapl_pkg_perf_status, old->rapl_pkg_perf_status); |
| 1072 | DELTA_WRAP32(new->rapl_dram_perf_status, old->rapl_dram_perf_status); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1073 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1074 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1075 | if (mp->format == FORMAT_RAW) |
| 1076 | old->counter[i] = new->counter[i]; |
| 1077 | else |
| 1078 | old->counter[i] = new->counter[i] - old->counter[i]; |
| 1079 | } |
| 1080 | |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1081 | return 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1082 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1083 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1084 | void |
| 1085 | delta_core(struct core_data *new, struct core_data *old) |
| 1086 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1087 | int i; |
| 1088 | struct msr_counter *mp; |
| 1089 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1090 | old->c3 = new->c3 - old->c3; |
| 1091 | old->c6 = new->c6 - old->c6; |
| 1092 | old->c7 = new->c7 - old->c7; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1093 | old->core_temp_c = new->core_temp_c; |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1094 | old->mc6_us = new->mc6_us - old->mc6_us; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1095 | |
| 1096 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 1097 | if (mp->format == FORMAT_RAW) |
| 1098 | old->counter[i] = new->counter[i]; |
| 1099 | else |
| 1100 | old->counter[i] = new->counter[i] - old->counter[i]; |
| 1101 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1102 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1103 | |
Len Brown | c3ae331 | 2012-06-13 21:31:46 -0400 | [diff] [blame] | 1104 | /* |
| 1105 | * old = new - old |
| 1106 | */ |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1107 | int |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1108 | delta_thread(struct thread_data *new, struct thread_data *old, |
| 1109 | struct core_data *core_delta) |
| 1110 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1111 | int i; |
| 1112 | struct msr_counter *mp; |
| 1113 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1114 | old->tsc = new->tsc - old->tsc; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1115 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1116 | /* check for TSC < 1 Mcycles over interval */ |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 1117 | if (old->tsc < (1000 * 1000)) |
| 1118 | errx(-3, "Insanely slow TSC rate, TSC stops in idle?\n" |
| 1119 | "You can disable all c-states by booting with \"idle=poll\"\n" |
| 1120 | "or just the deep ones with \"processor.max_cstate=1\""); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1121 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1122 | old->c1 = new->c1 - old->c1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1123 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1124 | if (DO_BIC(BIC_Avg_MHz) || DO_BIC(BIC_Busy) || DO_BIC(BIC_Bzy_MHz)) { |
Len Brown | a729617 | 2015-01-23 01:33:58 -0500 | [diff] [blame] | 1125 | if ((new->aperf > old->aperf) && (new->mperf > old->mperf)) { |
| 1126 | old->aperf = new->aperf - old->aperf; |
| 1127 | old->mperf = new->mperf - old->mperf; |
| 1128 | } else { |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1129 | return -1; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1130 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1131 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1132 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1133 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1134 | if (use_c1_residency_msr) { |
| 1135 | /* |
| 1136 | * Some models have a dedicated C1 residency MSR, |
| 1137 | * which should be more accurate than the derivation below. |
| 1138 | */ |
| 1139 | } else { |
| 1140 | /* |
| 1141 | * As counter collection is not atomic, |
| 1142 | * it is possible for mperf's non-halted cycles + idle states |
| 1143 | * to exceed TSC's all cycles: show c1 = 0% in that case. |
| 1144 | */ |
| 1145 | if ((old->mperf + core_delta->c3 + core_delta->c6 + core_delta->c7) > old->tsc) |
| 1146 | old->c1 = 0; |
| 1147 | else { |
| 1148 | /* normal case, derive c1 */ |
Len Brown | 008d396e | 2017-02-10 00:29:51 -0500 | [diff] [blame] | 1149 | old->c1 = (old->tsc * tsc_tweak) - old->mperf - core_delta->c3 |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1150 | - core_delta->c6 - core_delta->c7; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1151 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1152 | } |
Len Brown | c3ae331 | 2012-06-13 21:31:46 -0400 | [diff] [blame] | 1153 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1154 | if (old->mperf == 0) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1155 | if (debug > 1) |
| 1156 | fprintf(outf, "cpu%d MPERF 0!\n", old->cpu_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1157 | old->mperf = 1; /* divide by 0 protection */ |
| 1158 | } |
| 1159 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1160 | if (DO_BIC(BIC_IRQ)) |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1161 | old->irq_count = new->irq_count - old->irq_count; |
| 1162 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1163 | if (DO_BIC(BIC_SMI)) |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 1164 | old->smi_count = new->smi_count - old->smi_count; |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1165 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1166 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 1167 | if (mp->format == FORMAT_RAW) |
| 1168 | old->counter[i] = new->counter[i]; |
| 1169 | else |
| 1170 | old->counter[i] = new->counter[i] - old->counter[i]; |
| 1171 | } |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1172 | return 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | int delta_cpu(struct thread_data *t, struct core_data *c, |
| 1176 | struct pkg_data *p, struct thread_data *t2, |
| 1177 | struct core_data *c2, struct pkg_data *p2) |
| 1178 | { |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1179 | int retval = 0; |
| 1180 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1181 | /* calculate core delta only for 1st thread in core */ |
| 1182 | if (t->flags & CPU_IS_FIRST_THREAD_IN_CORE) |
| 1183 | delta_core(c, c2); |
| 1184 | |
| 1185 | /* always calculate thread delta */ |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1186 | retval = delta_thread(t, t2, c2); /* c2 is core delta */ |
| 1187 | if (retval) |
| 1188 | return retval; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1189 | |
| 1190 | /* calculate package delta only for 1st core in package */ |
| 1191 | if (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE) |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1192 | retval = delta_package(p, p2); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1193 | |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1194 | return retval; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | void clear_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 1198 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1199 | int i; |
| 1200 | struct msr_counter *mp; |
| 1201 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1202 | t->tsc = 0; |
| 1203 | t->aperf = 0; |
| 1204 | t->mperf = 0; |
| 1205 | t->c1 = 0; |
| 1206 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1207 | t->irq_count = 0; |
| 1208 | t->smi_count = 0; |
| 1209 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1210 | /* tells format_counters to dump all fields from this set */ |
| 1211 | t->flags = CPU_IS_FIRST_THREAD_IN_CORE | CPU_IS_FIRST_CORE_IN_PACKAGE; |
| 1212 | |
| 1213 | c->c3 = 0; |
| 1214 | c->c6 = 0; |
| 1215 | c->c7 = 0; |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1216 | c->mc6_us = 0; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1217 | c->core_temp_c = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1218 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1219 | p->pkg_wtd_core_c0 = 0; |
| 1220 | p->pkg_any_core_c0 = 0; |
| 1221 | p->pkg_any_gfxe_c0 = 0; |
| 1222 | p->pkg_both_core_gfxe_c0 = 0; |
| 1223 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1224 | p->pc2 = 0; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1225 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1226 | p->pc3 = 0; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1227 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1228 | p->pc6 = 0; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1229 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1230 | p->pc7 = 0; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1231 | p->pc8 = 0; |
| 1232 | p->pc9 = 0; |
| 1233 | p->pc10 = 0; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1234 | |
| 1235 | p->energy_pkg = 0; |
| 1236 | p->energy_dram = 0; |
| 1237 | p->energy_cores = 0; |
| 1238 | p->energy_gfx = 0; |
| 1239 | p->rapl_pkg_perf_status = 0; |
| 1240 | p->rapl_dram_perf_status = 0; |
| 1241 | p->pkg_temp_c = 0; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1242 | |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1243 | p->gfx_rc6_ms = 0; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1244 | p->gfx_mhz = 0; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1245 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) |
| 1246 | t->counter[i] = 0; |
| 1247 | |
| 1248 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) |
| 1249 | c->counter[i] = 0; |
| 1250 | |
| 1251 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) |
| 1252 | p->counter[i] = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1253 | } |
| 1254 | int sum_counters(struct thread_data *t, struct core_data *c, |
| 1255 | struct pkg_data *p) |
| 1256 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1257 | int i; |
| 1258 | struct msr_counter *mp; |
| 1259 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1260 | average.threads.tsc += t->tsc; |
| 1261 | average.threads.aperf += t->aperf; |
| 1262 | average.threads.mperf += t->mperf; |
| 1263 | average.threads.c1 += t->c1; |
| 1264 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1265 | average.threads.irq_count += t->irq_count; |
| 1266 | average.threads.smi_count += t->smi_count; |
| 1267 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1268 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 1269 | if (mp->format == FORMAT_RAW) |
| 1270 | continue; |
| 1271 | average.threads.counter[i] += t->counter[i]; |
| 1272 | } |
| 1273 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1274 | /* sum per-core values only for 1st thread in core */ |
| 1275 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 1276 | return 0; |
| 1277 | |
| 1278 | average.cores.c3 += c->c3; |
| 1279 | average.cores.c6 += c->c6; |
| 1280 | average.cores.c7 += c->c7; |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1281 | average.cores.mc6_us += c->mc6_us; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1282 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1283 | average.cores.core_temp_c = MAX(average.cores.core_temp_c, c->core_temp_c); |
| 1284 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1285 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 1286 | if (mp->format == FORMAT_RAW) |
| 1287 | continue; |
| 1288 | average.cores.counter[i] += c->counter[i]; |
| 1289 | } |
| 1290 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1291 | /* sum per-pkg values only for 1st core in pkg */ |
| 1292 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 1293 | return 0; |
| 1294 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1295 | if (do_skl_residency) { |
| 1296 | average.packages.pkg_wtd_core_c0 += p->pkg_wtd_core_c0; |
| 1297 | average.packages.pkg_any_core_c0 += p->pkg_any_core_c0; |
| 1298 | average.packages.pkg_any_gfxe_c0 += p->pkg_any_gfxe_c0; |
| 1299 | average.packages.pkg_both_core_gfxe_c0 += p->pkg_both_core_gfxe_c0; |
| 1300 | } |
| 1301 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1302 | average.packages.pc2 += p->pc2; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1303 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1304 | average.packages.pc3 += p->pc3; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1305 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1306 | average.packages.pc6 += p->pc6; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1307 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1308 | average.packages.pc7 += p->pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1309 | average.packages.pc8 += p->pc8; |
| 1310 | average.packages.pc9 += p->pc9; |
| 1311 | average.packages.pc10 += p->pc10; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1312 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1313 | average.packages.energy_pkg += p->energy_pkg; |
| 1314 | average.packages.energy_dram += p->energy_dram; |
| 1315 | average.packages.energy_cores += p->energy_cores; |
| 1316 | average.packages.energy_gfx += p->energy_gfx; |
| 1317 | |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1318 | average.packages.gfx_rc6_ms = p->gfx_rc6_ms; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1319 | average.packages.gfx_mhz = p->gfx_mhz; |
| 1320 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1321 | average.packages.pkg_temp_c = MAX(average.packages.pkg_temp_c, p->pkg_temp_c); |
| 1322 | |
| 1323 | average.packages.rapl_pkg_perf_status += p->rapl_pkg_perf_status; |
| 1324 | average.packages.rapl_dram_perf_status += p->rapl_dram_perf_status; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1325 | |
| 1326 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1327 | if (mp->format == FORMAT_RAW) |
| 1328 | continue; |
| 1329 | average.packages.counter[i] += p->counter[i]; |
| 1330 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1331 | return 0; |
| 1332 | } |
| 1333 | /* |
| 1334 | * sum the counters for all cpus in the system |
| 1335 | * compute the weighted average |
| 1336 | */ |
| 1337 | void compute_average(struct thread_data *t, struct core_data *c, |
| 1338 | struct pkg_data *p) |
| 1339 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1340 | int i; |
| 1341 | struct msr_counter *mp; |
| 1342 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1343 | clear_counters(&average.threads, &average.cores, &average.packages); |
| 1344 | |
| 1345 | for_all_cpus(sum_counters, t, c, p); |
| 1346 | |
| 1347 | average.threads.tsc /= topo.num_cpus; |
| 1348 | average.threads.aperf /= topo.num_cpus; |
| 1349 | average.threads.mperf /= topo.num_cpus; |
| 1350 | average.threads.c1 /= topo.num_cpus; |
| 1351 | |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1352 | if (average.threads.irq_count > 9999999) |
| 1353 | sums_need_wide_columns = 1; |
| 1354 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1355 | average.cores.c3 /= topo.num_cores; |
| 1356 | average.cores.c6 /= topo.num_cores; |
| 1357 | average.cores.c7 /= topo.num_cores; |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1358 | average.cores.mc6_us /= topo.num_cores; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1359 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1360 | if (do_skl_residency) { |
| 1361 | average.packages.pkg_wtd_core_c0 /= topo.num_packages; |
| 1362 | average.packages.pkg_any_core_c0 /= topo.num_packages; |
| 1363 | average.packages.pkg_any_gfxe_c0 /= topo.num_packages; |
| 1364 | average.packages.pkg_both_core_gfxe_c0 /= topo.num_packages; |
| 1365 | } |
| 1366 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1367 | average.packages.pc2 /= topo.num_packages; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1368 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1369 | average.packages.pc3 /= topo.num_packages; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1370 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1371 | average.packages.pc6 /= topo.num_packages; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1372 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1373 | average.packages.pc7 /= topo.num_packages; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1374 | |
| 1375 | average.packages.pc8 /= topo.num_packages; |
| 1376 | average.packages.pc9 /= topo.num_packages; |
| 1377 | average.packages.pc10 /= topo.num_packages; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1378 | |
| 1379 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 1380 | if (mp->format == FORMAT_RAW) |
| 1381 | continue; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1382 | if (mp->type == COUNTER_ITEMS) { |
| 1383 | if (average.threads.counter[i] > 9999999) |
| 1384 | sums_need_wide_columns = 1; |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 1385 | continue; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1386 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1387 | average.threads.counter[i] /= topo.num_cpus; |
| 1388 | } |
| 1389 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 1390 | if (mp->format == FORMAT_RAW) |
| 1391 | continue; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1392 | if (mp->type == COUNTER_ITEMS) { |
| 1393 | if (average.cores.counter[i] > 9999999) |
| 1394 | sums_need_wide_columns = 1; |
| 1395 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1396 | average.cores.counter[i] /= topo.num_cores; |
| 1397 | } |
| 1398 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1399 | if (mp->format == FORMAT_RAW) |
| 1400 | continue; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1401 | if (mp->type == COUNTER_ITEMS) { |
| 1402 | if (average.packages.counter[i] > 9999999) |
| 1403 | sums_need_wide_columns = 1; |
| 1404 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1405 | average.packages.counter[i] /= topo.num_packages; |
| 1406 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | static unsigned long long rdtsc(void) |
| 1410 | { |
| 1411 | unsigned int low, high; |
| 1412 | |
| 1413 | asm volatile("rdtsc" : "=a" (low), "=d" (high)); |
| 1414 | |
| 1415 | return low | ((unsigned long long)high) << 32; |
| 1416 | } |
| 1417 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1418 | /* |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1419 | * Open a file, and exit on failure |
| 1420 | */ |
| 1421 | FILE *fopen_or_die(const char *path, const char *mode) |
| 1422 | { |
| 1423 | FILE *filep = fopen(path, mode); |
| 1424 | |
| 1425 | if (!filep) |
| 1426 | err(1, "%s: open failed", path); |
| 1427 | return filep; |
| 1428 | } |
| 1429 | /* |
| 1430 | * snapshot_sysfs_counter() |
| 1431 | * |
| 1432 | * return snapshot of given counter |
| 1433 | */ |
| 1434 | unsigned long long snapshot_sysfs_counter(char *path) |
| 1435 | { |
| 1436 | FILE *fp; |
| 1437 | int retval; |
| 1438 | unsigned long long counter; |
| 1439 | |
| 1440 | fp = fopen_or_die(path, "r"); |
| 1441 | |
| 1442 | retval = fscanf(fp, "%lld", &counter); |
| 1443 | if (retval != 1) |
| 1444 | err(1, "snapshot_sysfs_counter(%s)", path); |
| 1445 | |
| 1446 | fclose(fp); |
| 1447 | |
| 1448 | return counter; |
| 1449 | } |
| 1450 | |
| 1451 | int get_mp(int cpu, struct msr_counter *mp, unsigned long long *counterp) |
| 1452 | { |
| 1453 | if (mp->msr_num != 0) { |
| 1454 | if (get_msr(cpu, mp->msr_num, counterp)) |
| 1455 | return -1; |
| 1456 | } else { |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 1457 | char path[128]; |
| 1458 | |
| 1459 | if (mp->flags & SYSFS_PERCPU) { |
| 1460 | sprintf(path, "/sys/devices/system/cpu/cpu%d/%s", |
| 1461 | cpu, mp->path); |
| 1462 | |
| 1463 | *counterp = snapshot_sysfs_counter(path); |
| 1464 | } else { |
| 1465 | *counterp = snapshot_sysfs_counter(mp->path); |
| 1466 | } |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | return 0; |
| 1470 | } |
| 1471 | |
| 1472 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1473 | * get_counters(...) |
| 1474 | * migrate to cpu |
| 1475 | * acquire and record local counters for that cpu |
| 1476 | */ |
| 1477 | int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 1478 | { |
| 1479 | int cpu = t->cpu_id; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1480 | unsigned long long msr; |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1481 | int aperf_mperf_retry_count = 0; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1482 | struct msr_counter *mp; |
| 1483 | int i; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1484 | |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 1485 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1486 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1487 | return -1; |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 1488 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1489 | |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1490 | retry: |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1491 | t->tsc = rdtsc(); /* we are running on local CPU of interest */ |
| 1492 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1493 | if (DO_BIC(BIC_Avg_MHz) || DO_BIC(BIC_Busy) || DO_BIC(BIC_Bzy_MHz)) { |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1494 | unsigned long long tsc_before, tsc_between, tsc_after, aperf_time, mperf_time; |
| 1495 | |
| 1496 | /* |
| 1497 | * The TSC, APERF and MPERF must be read together for |
| 1498 | * APERF/MPERF and MPERF/TSC to give accurate results. |
| 1499 | * |
| 1500 | * Unfortunately, APERF and MPERF are read by |
| 1501 | * individual system call, so delays may occur |
| 1502 | * between them. If the time to read them |
| 1503 | * varies by a large amount, we re-read them. |
| 1504 | */ |
| 1505 | |
| 1506 | /* |
| 1507 | * This initial dummy APERF read has been seen to |
| 1508 | * reduce jitter in the subsequent reads. |
| 1509 | */ |
| 1510 | |
Len Brown | 9c63a65 | 2012-10-31 01:29:52 -0400 | [diff] [blame] | 1511 | if (get_msr(cpu, MSR_IA32_APERF, &t->aperf)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1512 | return -3; |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1513 | |
| 1514 | t->tsc = rdtsc(); /* re-read close to APERF */ |
| 1515 | |
| 1516 | tsc_before = t->tsc; |
| 1517 | |
| 1518 | if (get_msr(cpu, MSR_IA32_APERF, &t->aperf)) |
| 1519 | return -3; |
| 1520 | |
| 1521 | tsc_between = rdtsc(); |
| 1522 | |
Len Brown | 9c63a65 | 2012-10-31 01:29:52 -0400 | [diff] [blame] | 1523 | if (get_msr(cpu, MSR_IA32_MPERF, &t->mperf)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1524 | return -4; |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1525 | |
| 1526 | tsc_after = rdtsc(); |
| 1527 | |
| 1528 | aperf_time = tsc_between - tsc_before; |
| 1529 | mperf_time = tsc_after - tsc_between; |
| 1530 | |
| 1531 | /* |
| 1532 | * If the system call latency to read APERF and MPERF |
| 1533 | * differ by more than 2x, then try again. |
| 1534 | */ |
| 1535 | if ((aperf_time > (2 * mperf_time)) || (mperf_time > (2 * aperf_time))) { |
| 1536 | aperf_mperf_retry_count++; |
| 1537 | if (aperf_mperf_retry_count < 5) |
| 1538 | goto retry; |
| 1539 | else |
| 1540 | warnx("cpu%d jitter %lld %lld", |
| 1541 | cpu, aperf_time, mperf_time); |
| 1542 | } |
| 1543 | aperf_mperf_retry_count = 0; |
| 1544 | |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 1545 | t->aperf = t->aperf * aperf_mperf_multiplier; |
| 1546 | t->mperf = t->mperf * aperf_mperf_multiplier; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1547 | } |
| 1548 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1549 | if (DO_BIC(BIC_IRQ)) |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1550 | t->irq_count = irqs_per_cpu[cpu]; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1551 | if (DO_BIC(BIC_SMI)) { |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 1552 | if (get_msr(cpu, MSR_SMI_COUNT, &msr)) |
| 1553 | return -5; |
| 1554 | t->smi_count = msr & 0xFFFFFFFF; |
| 1555 | } |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1556 | if (DO_BIC(BIC_CPU_c1) && use_c1_residency_msr) { |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1557 | if (get_msr(cpu, MSR_CORE_C1_RES, &t->c1)) |
| 1558 | return -6; |
| 1559 | } |
| 1560 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1561 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1562 | if (get_mp(cpu, mp, &t->counter[i])) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1563 | return -10; |
| 1564 | } |
| 1565 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1566 | /* collect core counters only for 1st thread in core */ |
| 1567 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 1568 | return 0; |
| 1569 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1570 | if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1571 | if (get_msr(cpu, MSR_CORE_C3_RESIDENCY, &c->c3)) |
| 1572 | return -6; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1573 | } |
| 1574 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1575 | if (DO_BIC(BIC_CPU_c6) && !do_knl_cstates) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1576 | if (get_msr(cpu, MSR_CORE_C6_RESIDENCY, &c->c6)) |
| 1577 | return -7; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1578 | } else if (do_knl_cstates) { |
| 1579 | if (get_msr(cpu, MSR_KNL_CORE_C6_RESIDENCY, &c->c6)) |
| 1580 | return -7; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1581 | } |
| 1582 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1583 | if (DO_BIC(BIC_CPU_c7)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1584 | if (get_msr(cpu, MSR_CORE_C7_RESIDENCY, &c->c7)) |
| 1585 | return -8; |
| 1586 | |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1587 | if (DO_BIC(BIC_Mod_c6)) |
| 1588 | if (get_msr(cpu, MSR_MODULE_C6_RES_MS, &c->mc6_us)) |
| 1589 | return -8; |
| 1590 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1591 | if (DO_BIC(BIC_CoreTmp)) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1592 | if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr)) |
| 1593 | return -9; |
| 1594 | c->core_temp_c = tcc_activation_temp - ((msr >> 16) & 0x7F); |
| 1595 | } |
| 1596 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1597 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1598 | if (get_mp(cpu, mp, &c->counter[i])) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1599 | return -10; |
| 1600 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1601 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1602 | /* collect package counters only for 1st core in package */ |
| 1603 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 1604 | return 0; |
| 1605 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1606 | if (do_skl_residency) { |
| 1607 | if (get_msr(cpu, MSR_PKG_WEIGHTED_CORE_C0_RES, &p->pkg_wtd_core_c0)) |
| 1608 | return -10; |
| 1609 | if (get_msr(cpu, MSR_PKG_ANY_CORE_C0_RES, &p->pkg_any_core_c0)) |
| 1610 | return -11; |
| 1611 | if (get_msr(cpu, MSR_PKG_ANY_GFXE_C0_RES, &p->pkg_any_gfxe_c0)) |
| 1612 | return -12; |
| 1613 | if (get_msr(cpu, MSR_PKG_BOTH_CORE_GFXE_C0_RES, &p->pkg_both_core_gfxe_c0)) |
| 1614 | return -13; |
| 1615 | } |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1616 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1617 | if (get_msr(cpu, MSR_PKG_C3_RESIDENCY, &p->pc3)) |
| 1618 | return -9; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1619 | if (DO_BIC(BIC_Pkgpc6)) { |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1620 | if (do_slm_cstates) { |
| 1621 | if (get_msr(cpu, MSR_ATOM_PKG_C6_RESIDENCY, &p->pc6)) |
| 1622 | return -10; |
| 1623 | } else { |
| 1624 | if (get_msr(cpu, MSR_PKG_C6_RESIDENCY, &p->pc6)) |
| 1625 | return -10; |
| 1626 | } |
| 1627 | } |
| 1628 | |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1629 | if (DO_BIC(BIC_Pkgpc2)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1630 | if (get_msr(cpu, MSR_PKG_C2_RESIDENCY, &p->pc2)) |
| 1631 | return -11; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1632 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1633 | if (get_msr(cpu, MSR_PKG_C7_RESIDENCY, &p->pc7)) |
| 1634 | return -12; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1635 | if (DO_BIC(BIC_Pkgpc8)) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1636 | if (get_msr(cpu, MSR_PKG_C8_RESIDENCY, &p->pc8)) |
| 1637 | return -13; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1638 | if (DO_BIC(BIC_Pkgpc9)) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1639 | if (get_msr(cpu, MSR_PKG_C9_RESIDENCY, &p->pc9)) |
| 1640 | return -13; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1641 | if (DO_BIC(BIC_Pkgpc10)) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1642 | if (get_msr(cpu, MSR_PKG_C10_RESIDENCY, &p->pc10)) |
| 1643 | return -13; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1644 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1645 | if (do_rapl & RAPL_PKG) { |
| 1646 | if (get_msr(cpu, MSR_PKG_ENERGY_STATUS, &msr)) |
| 1647 | return -13; |
| 1648 | p->energy_pkg = msr & 0xFFFFFFFF; |
| 1649 | } |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 1650 | if (do_rapl & RAPL_CORES_ENERGY_STATUS) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1651 | if (get_msr(cpu, MSR_PP0_ENERGY_STATUS, &msr)) |
| 1652 | return -14; |
| 1653 | p->energy_cores = msr & 0xFFFFFFFF; |
| 1654 | } |
| 1655 | if (do_rapl & RAPL_DRAM) { |
| 1656 | if (get_msr(cpu, MSR_DRAM_ENERGY_STATUS, &msr)) |
| 1657 | return -15; |
| 1658 | p->energy_dram = msr & 0xFFFFFFFF; |
| 1659 | } |
| 1660 | if (do_rapl & RAPL_GFX) { |
| 1661 | if (get_msr(cpu, MSR_PP1_ENERGY_STATUS, &msr)) |
| 1662 | return -16; |
| 1663 | p->energy_gfx = msr & 0xFFFFFFFF; |
| 1664 | } |
| 1665 | if (do_rapl & RAPL_PKG_PERF_STATUS) { |
| 1666 | if (get_msr(cpu, MSR_PKG_PERF_STATUS, &msr)) |
| 1667 | return -16; |
| 1668 | p->rapl_pkg_perf_status = msr & 0xFFFFFFFF; |
| 1669 | } |
| 1670 | if (do_rapl & RAPL_DRAM_PERF_STATUS) { |
| 1671 | if (get_msr(cpu, MSR_DRAM_PERF_STATUS, &msr)) |
| 1672 | return -16; |
| 1673 | p->rapl_dram_perf_status = msr & 0xFFFFFFFF; |
| 1674 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1675 | if (DO_BIC(BIC_PkgTmp)) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1676 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr)) |
| 1677 | return -17; |
| 1678 | p->pkg_temp_c = tcc_activation_temp - ((msr >> 16) & 0x7F); |
| 1679 | } |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1680 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1681 | if (DO_BIC(BIC_GFX_rc6)) |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1682 | p->gfx_rc6_ms = gfx_cur_rc6_ms; |
| 1683 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1684 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1685 | p->gfx_mhz = gfx_cur_mhz; |
| 1686 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1687 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1688 | if (get_mp(cpu, mp, &p->counter[i])) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1689 | return -10; |
| 1690 | } |
| 1691 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1692 | return 0; |
| 1693 | } |
| 1694 | |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1695 | /* |
| 1696 | * MSR_PKG_CST_CONFIG_CONTROL decoding for pkg_cstate_limit: |
| 1697 | * If you change the values, note they are used both in comparisons |
| 1698 | * (>= PCL__7) and to index pkg_cstate_limit_strings[]. |
| 1699 | */ |
| 1700 | |
| 1701 | #define PCLUKN 0 /* Unknown */ |
| 1702 | #define PCLRSV 1 /* Reserved */ |
| 1703 | #define PCL__0 2 /* PC0 */ |
| 1704 | #define PCL__1 3 /* PC1 */ |
| 1705 | #define PCL__2 4 /* PC2 */ |
| 1706 | #define PCL__3 5 /* PC3 */ |
| 1707 | #define PCL__4 6 /* PC4 */ |
| 1708 | #define PCL__6 7 /* PC6 */ |
| 1709 | #define PCL_6N 8 /* PC6 No Retention */ |
| 1710 | #define PCL_6R 9 /* PC6 Retention */ |
| 1711 | #define PCL__7 10 /* PC7 */ |
| 1712 | #define PCL_7S 11 /* PC7 Shrink */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1713 | #define PCL__8 12 /* PC8 */ |
| 1714 | #define PCL__9 13 /* PC9 */ |
| 1715 | #define PCLUNL 14 /* Unlimited */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1716 | |
| 1717 | int pkg_cstate_limit = PCLUKN; |
| 1718 | char *pkg_cstate_limit_strings[] = { "reserved", "unknown", "pc0", "pc1", "pc2", |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1719 | "pc3", "pc4", "pc6", "pc6n", "pc6r", "pc7", "pc7s", "pc8", "pc9", "unlimited"}; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1720 | |
Len Brown | e9257f5 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 1721 | int nhm_pkg_cstate_limits[16] = {PCL__0, PCL__1, PCL__3, PCL__6, PCL__7, PCLRSV, PCLRSV, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; |
| 1722 | int snb_pkg_cstate_limits[16] = {PCL__0, PCL__2, PCL_6N, PCL_6R, PCL__7, PCL_7S, PCLRSV, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; |
| 1723 | int hsw_pkg_cstate_limits[16] = {PCL__0, PCL__2, PCL__3, PCL__6, PCL__7, PCL_7S, PCL__8, PCL__9, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1724 | int slv_pkg_cstate_limits[16] = {PCL__0, PCL__1, PCLRSV, PCLRSV, PCL__4, PCLRSV, PCL__6, PCL__7, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCL__6, PCL__7}; |
Len Brown | f264288 | 2017-01-07 23:13:15 -0500 | [diff] [blame] | 1725 | int amt_pkg_cstate_limits[16] = {PCLUNL, PCL__1, PCL__2, PCLRSV, PCLRSV, PCLRSV, PCL__6, PCL__7, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; |
Len Brown | e9257f5 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 1726 | int phi_pkg_cstate_limits[16] = {PCL__0, PCL__2, PCL_6N, PCL_6R, PCLRSV, PCLRSV, PCLRSV, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; |
Len Brown | e4085d5 | 2016-04-06 17:15:56 -0400 | [diff] [blame] | 1727 | int bxt_pkg_cstate_limits[16] = {PCL__0, PCL__2, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; |
Len Brown | d8ebb44 | 2016-12-01 20:27:46 -0500 | [diff] [blame] | 1728 | int skx_pkg_cstate_limits[16] = {PCL__0, PCL__2, PCL_6N, PCL_6R, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1729 | |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 1730 | |
| 1731 | static void |
| 1732 | calculate_tsc_tweak() |
| 1733 | { |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 1734 | tsc_tweak = base_hz / tsc_hz; |
| 1735 | } |
| 1736 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1737 | static void |
| 1738 | dump_nhm_platform_info(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1739 | { |
| 1740 | unsigned long long msr; |
| 1741 | unsigned int ratio; |
| 1742 | |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 1743 | get_msr(base_cpu, MSR_PLATFORM_INFO, &msr); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1744 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1745 | fprintf(outf, "cpu%d: MSR_PLATFORM_INFO: 0x%08llx\n", base_cpu, msr); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1746 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1747 | ratio = (msr >> 40) & 0xFF; |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1748 | fprintf(outf, "%d * %.1f = %.1f MHz max efficiency frequency\n", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1749 | ratio, bclk, ratio * bclk); |
| 1750 | |
| 1751 | ratio = (msr >> 8) & 0xFF; |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1752 | fprintf(outf, "%d * %.1f = %.1f MHz base frequency\n", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1753 | ratio, bclk, ratio * bclk); |
| 1754 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1755 | get_msr(base_cpu, MSR_IA32_POWER_CTL, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1756 | fprintf(outf, "cpu%d: MSR_IA32_POWER_CTL: 0x%08llx (C1E auto-promotion: %sabled)\n", |
Len Brown | bfae205 | 2015-06-17 12:27:21 -0400 | [diff] [blame] | 1757 | base_cpu, msr, msr & 0x2 ? "EN" : "DIS"); |
Len Brown | 6792041 | 2013-01-31 15:22:15 -0500 | [diff] [blame] | 1758 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1759 | return; |
| 1760 | } |
| 1761 | |
| 1762 | static void |
| 1763 | dump_hsw_turbo_ratio_limits(void) |
| 1764 | { |
| 1765 | unsigned long long msr; |
| 1766 | unsigned int ratio; |
| 1767 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1768 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT2, &msr); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1769 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1770 | fprintf(outf, "cpu%d: MSR_TURBO_RATIO_LIMIT2: 0x%08llx\n", base_cpu, msr); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1771 | |
| 1772 | ratio = (msr >> 8) & 0xFF; |
| 1773 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1774 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 18 active cores\n", |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1775 | ratio, bclk, ratio * bclk); |
| 1776 | |
| 1777 | ratio = (msr >> 0) & 0xFF; |
| 1778 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1779 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 17 active cores\n", |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1780 | ratio, bclk, ratio * bclk); |
| 1781 | return; |
| 1782 | } |
| 1783 | |
| 1784 | static void |
| 1785 | dump_ivt_turbo_ratio_limits(void) |
| 1786 | { |
| 1787 | unsigned long long msr; |
| 1788 | unsigned int ratio; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1789 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1790 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT1, &msr); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1791 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1792 | fprintf(outf, "cpu%d: MSR_TURBO_RATIO_LIMIT1: 0x%08llx\n", base_cpu, msr); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1793 | |
| 1794 | ratio = (msr >> 56) & 0xFF; |
| 1795 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1796 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 16 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1797 | ratio, bclk, ratio * bclk); |
| 1798 | |
| 1799 | ratio = (msr >> 48) & 0xFF; |
| 1800 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1801 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 15 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1802 | ratio, bclk, ratio * bclk); |
| 1803 | |
| 1804 | ratio = (msr >> 40) & 0xFF; |
| 1805 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1806 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 14 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1807 | ratio, bclk, ratio * bclk); |
| 1808 | |
| 1809 | ratio = (msr >> 32) & 0xFF; |
| 1810 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1811 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 13 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1812 | ratio, bclk, ratio * bclk); |
| 1813 | |
| 1814 | ratio = (msr >> 24) & 0xFF; |
| 1815 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1816 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 12 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1817 | ratio, bclk, ratio * bclk); |
| 1818 | |
| 1819 | ratio = (msr >> 16) & 0xFF; |
| 1820 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1821 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 11 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1822 | ratio, bclk, ratio * bclk); |
| 1823 | |
| 1824 | ratio = (msr >> 8) & 0xFF; |
| 1825 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1826 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 10 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1827 | ratio, bclk, ratio * bclk); |
| 1828 | |
| 1829 | ratio = (msr >> 0) & 0xFF; |
| 1830 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1831 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 9 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1832 | ratio, bclk, ratio * bclk); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1833 | return; |
| 1834 | } |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1835 | int has_turbo_ratio_group_limits(int family, int model) |
| 1836 | { |
| 1837 | |
| 1838 | if (!genuine_intel) |
| 1839 | return 0; |
| 1840 | |
| 1841 | switch (model) { |
| 1842 | case INTEL_FAM6_ATOM_GOLDMONT: |
| 1843 | case INTEL_FAM6_SKYLAKE_X: |
| 1844 | case INTEL_FAM6_ATOM_DENVERTON: |
| 1845 | return 1; |
| 1846 | } |
| 1847 | return 0; |
| 1848 | } |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1849 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1850 | static void |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1851 | dump_turbo_ratio_limits(int family, int model) |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1852 | { |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1853 | unsigned long long msr, core_counts; |
| 1854 | unsigned int ratio, group_size; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1855 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1856 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1857 | fprintf(outf, "cpu%d: MSR_TURBO_RATIO_LIMIT: 0x%08llx\n", base_cpu, msr); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1858 | |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1859 | if (has_turbo_ratio_group_limits(family, model)) { |
| 1860 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT1, &core_counts); |
| 1861 | fprintf(outf, "cpu%d: MSR_TURBO_RATIO_LIMIT1: 0x%08llx\n", base_cpu, core_counts); |
| 1862 | } else { |
| 1863 | core_counts = 0x0807060504030201; |
| 1864 | } |
| 1865 | |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1866 | ratio = (msr >> 56) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1867 | group_size = (core_counts >> 56) & 0xFF; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1868 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1869 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 1870 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1871 | |
| 1872 | ratio = (msr >> 48) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1873 | group_size = (core_counts >> 48) & 0xFF; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1874 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1875 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 1876 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1877 | |
| 1878 | ratio = (msr >> 40) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1879 | group_size = (core_counts >> 40) & 0xFF; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1880 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1881 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 1882 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1883 | |
| 1884 | ratio = (msr >> 32) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1885 | group_size = (core_counts >> 32) & 0xFF; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1886 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1887 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 1888 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1889 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1890 | ratio = (msr >> 24) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1891 | group_size = (core_counts >> 24) & 0xFF; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1892 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1893 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 1894 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1895 | |
| 1896 | ratio = (msr >> 16) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1897 | group_size = (core_counts >> 16) & 0xFF; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1898 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1899 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 1900 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1901 | |
| 1902 | ratio = (msr >> 8) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1903 | group_size = (core_counts >> 8) & 0xFF; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1904 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1905 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 1906 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1907 | |
| 1908 | ratio = (msr >> 0) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1909 | group_size = (core_counts >> 0) & 0xFF; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1910 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1911 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 1912 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1913 | return; |
| 1914 | } |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 1915 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1916 | static void |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 1917 | dump_atom_turbo_ratio_limits(void) |
| 1918 | { |
| 1919 | unsigned long long msr; |
| 1920 | unsigned int ratio; |
| 1921 | |
| 1922 | get_msr(base_cpu, MSR_ATOM_CORE_RATIOS, &msr); |
| 1923 | fprintf(outf, "cpu%d: MSR_ATOM_CORE_RATIOS: 0x%08llx\n", base_cpu, msr & 0xFFFFFFFF); |
| 1924 | |
| 1925 | ratio = (msr >> 0) & 0x3F; |
| 1926 | if (ratio) |
| 1927 | fprintf(outf, "%d * %.1f = %.1f MHz minimum operating frequency\n", |
| 1928 | ratio, bclk, ratio * bclk); |
| 1929 | |
| 1930 | ratio = (msr >> 8) & 0x3F; |
| 1931 | if (ratio) |
| 1932 | fprintf(outf, "%d * %.1f = %.1f MHz low frequency mode (LFM)\n", |
| 1933 | ratio, bclk, ratio * bclk); |
| 1934 | |
| 1935 | ratio = (msr >> 16) & 0x3F; |
| 1936 | if (ratio) |
| 1937 | fprintf(outf, "%d * %.1f = %.1f MHz base frequency\n", |
| 1938 | ratio, bclk, ratio * bclk); |
| 1939 | |
| 1940 | get_msr(base_cpu, MSR_ATOM_CORE_TURBO_RATIOS, &msr); |
| 1941 | fprintf(outf, "cpu%d: MSR_ATOM_CORE_TURBO_RATIOS: 0x%08llx\n", base_cpu, msr & 0xFFFFFFFF); |
| 1942 | |
| 1943 | ratio = (msr >> 24) & 0x3F; |
| 1944 | if (ratio) |
| 1945 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 4 active cores\n", |
| 1946 | ratio, bclk, ratio * bclk); |
| 1947 | |
| 1948 | ratio = (msr >> 16) & 0x3F; |
| 1949 | if (ratio) |
| 1950 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 3 active cores\n", |
| 1951 | ratio, bclk, ratio * bclk); |
| 1952 | |
| 1953 | ratio = (msr >> 8) & 0x3F; |
| 1954 | if (ratio) |
| 1955 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 2 active cores\n", |
| 1956 | ratio, bclk, ratio * bclk); |
| 1957 | |
| 1958 | ratio = (msr >> 0) & 0x3F; |
| 1959 | if (ratio) |
| 1960 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 1 active core\n", |
| 1961 | ratio, bclk, ratio * bclk); |
| 1962 | } |
| 1963 | |
| 1964 | static void |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1965 | dump_knl_turbo_ratio_limits(void) |
| 1966 | { |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 1967 | const unsigned int buckets_no = 7; |
| 1968 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1969 | unsigned long long msr; |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 1970 | int delta_cores, delta_ratio; |
| 1971 | int i, b_nr; |
| 1972 | unsigned int cores[buckets_no]; |
| 1973 | unsigned int ratio[buckets_no]; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1974 | |
Srinivas Pandruvada | ebf5926 | 2016-07-06 16:07:56 -0700 | [diff] [blame] | 1975 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT, &msr); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1976 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1977 | fprintf(outf, "cpu%d: MSR_TURBO_RATIO_LIMIT: 0x%08llx\n", |
Len Brown | bfae205 | 2015-06-17 12:27:21 -0400 | [diff] [blame] | 1978 | base_cpu, msr); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1979 | |
| 1980 | /** |
| 1981 | * Turbo encoding in KNL is as follows: |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 1982 | * [0] -- Reserved |
| 1983 | * [7:1] -- Base value of number of active cores of bucket 1. |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1984 | * [15:8] -- Base value of freq ratio of bucket 1. |
| 1985 | * [20:16] -- +ve delta of number of active cores of bucket 2. |
| 1986 | * i.e. active cores of bucket 2 = |
| 1987 | * active cores of bucket 1 + delta |
| 1988 | * [23:21] -- Negative delta of freq ratio of bucket 2. |
| 1989 | * i.e. freq ratio of bucket 2 = |
| 1990 | * freq ratio of bucket 1 - delta |
| 1991 | * [28:24]-- +ve delta of number of active cores of bucket 3. |
| 1992 | * [31:29]-- -ve delta of freq ratio of bucket 3. |
| 1993 | * [36:32]-- +ve delta of number of active cores of bucket 4. |
| 1994 | * [39:37]-- -ve delta of freq ratio of bucket 4. |
| 1995 | * [44:40]-- +ve delta of number of active cores of bucket 5. |
| 1996 | * [47:45]-- -ve delta of freq ratio of bucket 5. |
| 1997 | * [52:48]-- +ve delta of number of active cores of bucket 6. |
| 1998 | * [55:53]-- -ve delta of freq ratio of bucket 6. |
| 1999 | * [60:56]-- +ve delta of number of active cores of bucket 7. |
| 2000 | * [63:61]-- -ve delta of freq ratio of bucket 7. |
| 2001 | */ |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2002 | |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2003 | b_nr = 0; |
| 2004 | cores[b_nr] = (msr & 0xFF) >> 1; |
| 2005 | ratio[b_nr] = (msr >> 8) & 0xFF; |
| 2006 | |
| 2007 | for (i = 16; i < 64; i += 8) { |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2008 | delta_cores = (msr >> i) & 0x1F; |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2009 | delta_ratio = (msr >> (i + 5)) & 0x7; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2010 | |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2011 | cores[b_nr + 1] = cores[b_nr] + delta_cores; |
| 2012 | ratio[b_nr + 1] = ratio[b_nr] - delta_ratio; |
| 2013 | b_nr++; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2014 | } |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2015 | |
| 2016 | for (i = buckets_no - 1; i >= 0; i--) |
| 2017 | if (i > 0 ? ratio[i] != ratio[i - 1] : 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2018 | fprintf(outf, |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 2019 | "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2020 | ratio[i], bclk, ratio[i] * bclk, cores[i]); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | static void |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2024 | dump_nhm_cst_cfg(void) |
| 2025 | { |
| 2026 | unsigned long long msr; |
| 2027 | |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 2028 | get_msr(base_cpu, MSR_PKG_CST_CONFIG_CONTROL, &msr); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2029 | |
| 2030 | #define SNB_C1_AUTO_UNDEMOTE (1UL << 27) |
| 2031 | #define SNB_C3_AUTO_UNDEMOTE (1UL << 28) |
| 2032 | |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 2033 | fprintf(outf, "cpu%d: MSR_PKG_CST_CONFIG_CONTROL: 0x%08llx", base_cpu, msr); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2034 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2035 | fprintf(outf, " (%s%s%s%s%slocked: pkg-cstate-limit=%d: %s)\n", |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2036 | (msr & SNB_C3_AUTO_UNDEMOTE) ? "UNdemote-C3, " : "", |
| 2037 | (msr & SNB_C1_AUTO_UNDEMOTE) ? "UNdemote-C1, " : "", |
| 2038 | (msr & NHM_C3_AUTO_DEMOTE) ? "demote-C3, " : "", |
| 2039 | (msr & NHM_C1_AUTO_DEMOTE) ? "demote-C1, " : "", |
| 2040 | (msr & (1 << 15)) ? "" : "UN", |
Len Brown | 6c34f16 | 2016-03-13 03:21:22 -0400 | [diff] [blame] | 2041 | (unsigned int)msr & 0xF, |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2042 | pkg_cstate_limit_strings[pkg_cstate_limit]); |
| 2043 | return; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2044 | } |
| 2045 | |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2046 | static void |
| 2047 | dump_config_tdp(void) |
| 2048 | { |
| 2049 | unsigned long long msr; |
| 2050 | |
| 2051 | get_msr(base_cpu, MSR_CONFIG_TDP_NOMINAL, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2052 | fprintf(outf, "cpu%d: MSR_CONFIG_TDP_NOMINAL: 0x%08llx", base_cpu, msr); |
Chen Yu | 685b535 | 2015-12-13 21:09:31 +0800 | [diff] [blame] | 2053 | fprintf(outf, " (base_ratio=%d)\n", (unsigned int)msr & 0xFF); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2054 | |
| 2055 | get_msr(base_cpu, MSR_CONFIG_TDP_LEVEL_1, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2056 | fprintf(outf, "cpu%d: MSR_CONFIG_TDP_LEVEL_1: 0x%08llx (", base_cpu, msr); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2057 | if (msr) { |
Chen Yu | 685b535 | 2015-12-13 21:09:31 +0800 | [diff] [blame] | 2058 | fprintf(outf, "PKG_MIN_PWR_LVL1=%d ", (unsigned int)(msr >> 48) & 0x7FFF); |
| 2059 | fprintf(outf, "PKG_MAX_PWR_LVL1=%d ", (unsigned int)(msr >> 32) & 0x7FFF); |
| 2060 | fprintf(outf, "LVL1_RATIO=%d ", (unsigned int)(msr >> 16) & 0xFF); |
| 2061 | fprintf(outf, "PKG_TDP_LVL1=%d", (unsigned int)(msr) & 0x7FFF); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2062 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2063 | fprintf(outf, ")\n"); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2064 | |
| 2065 | get_msr(base_cpu, MSR_CONFIG_TDP_LEVEL_2, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2066 | fprintf(outf, "cpu%d: MSR_CONFIG_TDP_LEVEL_2: 0x%08llx (", base_cpu, msr); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2067 | if (msr) { |
Chen Yu | 685b535 | 2015-12-13 21:09:31 +0800 | [diff] [blame] | 2068 | fprintf(outf, "PKG_MIN_PWR_LVL2=%d ", (unsigned int)(msr >> 48) & 0x7FFF); |
| 2069 | fprintf(outf, "PKG_MAX_PWR_LVL2=%d ", (unsigned int)(msr >> 32) & 0x7FFF); |
| 2070 | fprintf(outf, "LVL2_RATIO=%d ", (unsigned int)(msr >> 16) & 0xFF); |
| 2071 | fprintf(outf, "PKG_TDP_LVL2=%d", (unsigned int)(msr) & 0x7FFF); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2072 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2073 | fprintf(outf, ")\n"); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2074 | |
| 2075 | get_msr(base_cpu, MSR_CONFIG_TDP_CONTROL, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2076 | fprintf(outf, "cpu%d: MSR_CONFIG_TDP_CONTROL: 0x%08llx (", base_cpu, msr); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2077 | if ((msr) & 0x3) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2078 | fprintf(outf, "TDP_LEVEL=%d ", (unsigned int)(msr) & 0x3); |
| 2079 | fprintf(outf, " lock=%d", (unsigned int)(msr >> 31) & 1); |
| 2080 | fprintf(outf, ")\n"); |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2081 | |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2082 | get_msr(base_cpu, MSR_TURBO_ACTIVATION_RATIO, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2083 | fprintf(outf, "cpu%d: MSR_TURBO_ACTIVATION_RATIO: 0x%08llx (", base_cpu, msr); |
Chen Yu | 685b535 | 2015-12-13 21:09:31 +0800 | [diff] [blame] | 2084 | fprintf(outf, "MAX_NON_TURBO_RATIO=%d", (unsigned int)(msr) & 0xFF); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2085 | fprintf(outf, " lock=%d", (unsigned int)(msr >> 31) & 1); |
| 2086 | fprintf(outf, ")\n"); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2087 | } |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 2088 | |
| 2089 | unsigned int irtl_time_units[] = {1, 32, 1024, 32768, 1048576, 33554432, 0, 0 }; |
| 2090 | |
| 2091 | void print_irtl(void) |
| 2092 | { |
| 2093 | unsigned long long msr; |
| 2094 | |
| 2095 | get_msr(base_cpu, MSR_PKGC3_IRTL, &msr); |
| 2096 | fprintf(outf, "cpu%d: MSR_PKGC3_IRTL: 0x%08llx (", base_cpu, msr); |
| 2097 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2098 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2099 | |
| 2100 | get_msr(base_cpu, MSR_PKGC6_IRTL, &msr); |
| 2101 | fprintf(outf, "cpu%d: MSR_PKGC6_IRTL: 0x%08llx (", base_cpu, msr); |
| 2102 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2103 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2104 | |
| 2105 | get_msr(base_cpu, MSR_PKGC7_IRTL, &msr); |
| 2106 | fprintf(outf, "cpu%d: MSR_PKGC7_IRTL: 0x%08llx (", base_cpu, msr); |
| 2107 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2108 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2109 | |
| 2110 | if (!do_irtl_hsw) |
| 2111 | return; |
| 2112 | |
| 2113 | get_msr(base_cpu, MSR_PKGC8_IRTL, &msr); |
| 2114 | fprintf(outf, "cpu%d: MSR_PKGC8_IRTL: 0x%08llx (", base_cpu, msr); |
| 2115 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2116 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2117 | |
| 2118 | get_msr(base_cpu, MSR_PKGC9_IRTL, &msr); |
| 2119 | fprintf(outf, "cpu%d: MSR_PKGC9_IRTL: 0x%08llx (", base_cpu, msr); |
| 2120 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2121 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2122 | |
| 2123 | get_msr(base_cpu, MSR_PKGC10_IRTL, &msr); |
| 2124 | fprintf(outf, "cpu%d: MSR_PKGC10_IRTL: 0x%08llx (", base_cpu, msr); |
| 2125 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2126 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2127 | |
| 2128 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2129 | void free_fd_percpu(void) |
| 2130 | { |
| 2131 | int i; |
| 2132 | |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 2133 | for (i = 0; i < topo.max_cpu_num + 1; ++i) { |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2134 | if (fd_percpu[i] != 0) |
| 2135 | close(fd_percpu[i]); |
| 2136 | } |
| 2137 | |
| 2138 | free(fd_percpu); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2139 | } |
| 2140 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2141 | void free_all_buffers(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2142 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2143 | CPU_FREE(cpu_present_set); |
| 2144 | cpu_present_set = NULL; |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2145 | cpu_present_setsize = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2146 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2147 | CPU_FREE(cpu_affinity_set); |
| 2148 | cpu_affinity_set = NULL; |
| 2149 | cpu_affinity_setsize = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2150 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2151 | free(thread_even); |
| 2152 | free(core_even); |
| 2153 | free(package_even); |
| 2154 | |
| 2155 | thread_even = NULL; |
| 2156 | core_even = NULL; |
| 2157 | package_even = NULL; |
| 2158 | |
| 2159 | free(thread_odd); |
| 2160 | free(core_odd); |
| 2161 | free(package_odd); |
| 2162 | |
| 2163 | thread_odd = NULL; |
| 2164 | core_odd = NULL; |
| 2165 | package_odd = NULL; |
| 2166 | |
| 2167 | free(output_buffer); |
| 2168 | output_buffer = NULL; |
| 2169 | outp = NULL; |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2170 | |
| 2171 | free_fd_percpu(); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2172 | |
| 2173 | free(irq_column_2_cpu); |
| 2174 | free(irqs_per_cpu); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2175 | } |
| 2176 | |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 2177 | |
| 2178 | /* |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2179 | * Parse a file containing a single int. |
| 2180 | */ |
| 2181 | int parse_int_file(const char *fmt, ...) |
| 2182 | { |
| 2183 | va_list args; |
| 2184 | char path[PATH_MAX]; |
| 2185 | FILE *filep; |
| 2186 | int value; |
| 2187 | |
| 2188 | va_start(args, fmt); |
| 2189 | vsnprintf(path, sizeof(path), fmt, args); |
| 2190 | va_end(args); |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 2191 | filep = fopen_or_die(path, "r"); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 2192 | if (fscanf(filep, "%d", &value) != 1) |
| 2193 | err(1, "%s: failed to parse number from file", path); |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2194 | fclose(filep); |
| 2195 | return value; |
| 2196 | } |
| 2197 | |
| 2198 | /* |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2199 | * get_cpu_position_in_core(cpu) |
| 2200 | * return the position of the CPU among its HT siblings in the core |
| 2201 | * return -1 if the sibling is not in list |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2202 | */ |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2203 | int get_cpu_position_in_core(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2204 | { |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2205 | char path[64]; |
| 2206 | FILE *filep; |
| 2207 | int this_cpu; |
| 2208 | char character; |
| 2209 | int i; |
| 2210 | |
| 2211 | sprintf(path, |
| 2212 | "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", |
| 2213 | cpu); |
| 2214 | filep = fopen(path, "r"); |
| 2215 | if (filep == NULL) { |
| 2216 | perror(path); |
| 2217 | exit(1); |
| 2218 | } |
| 2219 | |
| 2220 | for (i = 0; i < topo.num_threads_per_core; i++) { |
| 2221 | fscanf(filep, "%d", &this_cpu); |
| 2222 | if (this_cpu == cpu) { |
| 2223 | fclose(filep); |
| 2224 | return i; |
| 2225 | } |
| 2226 | |
| 2227 | /* Account for no separator after last thread*/ |
| 2228 | if (i != (topo.num_threads_per_core - 1)) |
| 2229 | fscanf(filep, "%c", &character); |
| 2230 | } |
| 2231 | |
| 2232 | fclose(filep); |
| 2233 | return -1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2234 | } |
| 2235 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2236 | /* |
| 2237 | * cpu_is_first_core_in_package(cpu) |
| 2238 | * return 1 if given CPU is 1st core in package |
| 2239 | */ |
| 2240 | int cpu_is_first_core_in_package(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2241 | { |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2242 | return cpu == parse_int_file("/sys/devices/system/cpu/cpu%d/topology/core_siblings_list", cpu); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2243 | } |
| 2244 | |
| 2245 | int get_physical_package_id(int cpu) |
| 2246 | { |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2247 | return parse_int_file("/sys/devices/system/cpu/cpu%d/topology/physical_package_id", cpu); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2248 | } |
| 2249 | |
| 2250 | int get_core_id(int cpu) |
| 2251 | { |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2252 | return parse_int_file("/sys/devices/system/cpu/cpu%d/topology/core_id", cpu); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2253 | } |
| 2254 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2255 | int get_num_ht_siblings(int cpu) |
| 2256 | { |
| 2257 | char path[80]; |
| 2258 | FILE *filep; |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2259 | int sib1; |
| 2260 | int matches = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2261 | char character; |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2262 | char str[100]; |
| 2263 | char *ch; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2264 | |
| 2265 | sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu); |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 2266 | filep = fopen_or_die(path, "r"); |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2267 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2268 | /* |
| 2269 | * file format: |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2270 | * A ',' separated or '-' separated set of numbers |
| 2271 | * (eg 1-2 or 1,3,4,5) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2272 | */ |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2273 | fscanf(filep, "%d%c\n", &sib1, &character); |
| 2274 | fseek(filep, 0, SEEK_SET); |
| 2275 | fgets(str, 100, filep); |
| 2276 | ch = strchr(str, character); |
| 2277 | while (ch != NULL) { |
| 2278 | matches++; |
| 2279 | ch = strchr(ch+1, character); |
| 2280 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2281 | |
| 2282 | fclose(filep); |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2283 | return matches+1; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2284 | } |
| 2285 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2286 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2287 | * run func(thread, core, package) in topology order |
| 2288 | * skip non-present cpus |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2289 | */ |
| 2290 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2291 | int for_all_cpus_2(int (func)(struct thread_data *, struct core_data *, |
| 2292 | struct pkg_data *, struct thread_data *, struct core_data *, |
| 2293 | struct pkg_data *), struct thread_data *thread_base, |
| 2294 | struct core_data *core_base, struct pkg_data *pkg_base, |
| 2295 | struct thread_data *thread_base2, struct core_data *core_base2, |
| 2296 | struct pkg_data *pkg_base2) |
| 2297 | { |
| 2298 | int retval, pkg_no, core_no, thread_no; |
| 2299 | |
| 2300 | for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { |
| 2301 | for (core_no = 0; core_no < topo.num_cores_per_pkg; ++core_no) { |
| 2302 | for (thread_no = 0; thread_no < |
| 2303 | topo.num_threads_per_core; ++thread_no) { |
| 2304 | struct thread_data *t, *t2; |
| 2305 | struct core_data *c, *c2; |
| 2306 | struct pkg_data *p, *p2; |
| 2307 | |
| 2308 | t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); |
| 2309 | |
| 2310 | if (cpu_is_not_present(t->cpu_id)) |
| 2311 | continue; |
| 2312 | |
| 2313 | t2 = GET_THREAD(thread_base2, thread_no, core_no, pkg_no); |
| 2314 | |
| 2315 | c = GET_CORE(core_base, core_no, pkg_no); |
| 2316 | c2 = GET_CORE(core_base2, core_no, pkg_no); |
| 2317 | |
| 2318 | p = GET_PKG(pkg_base, pkg_no); |
| 2319 | p2 = GET_PKG(pkg_base2, pkg_no); |
| 2320 | |
| 2321 | retval = func(t, c, p, t2, c2, p2); |
| 2322 | if (retval) |
| 2323 | return retval; |
| 2324 | } |
| 2325 | } |
| 2326 | } |
| 2327 | return 0; |
| 2328 | } |
| 2329 | |
| 2330 | /* |
| 2331 | * run func(cpu) on every cpu in /proc/stat |
| 2332 | * return max_cpu number |
| 2333 | */ |
| 2334 | int for_all_proc_cpus(int (func)(int)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2335 | { |
| 2336 | FILE *fp; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2337 | int cpu_num; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2338 | int retval; |
| 2339 | |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 2340 | fp = fopen_or_die(proc_stat, "r"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2341 | |
| 2342 | retval = fscanf(fp, "cpu %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n"); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 2343 | if (retval != 0) |
| 2344 | err(1, "%s: failed to parse format", proc_stat); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2345 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2346 | while (1) { |
| 2347 | retval = fscanf(fp, "cpu%u %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n", &cpu_num); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2348 | if (retval != 1) |
| 2349 | break; |
| 2350 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2351 | retval = func(cpu_num); |
| 2352 | if (retval) { |
| 2353 | fclose(fp); |
| 2354 | return(retval); |
| 2355 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2356 | } |
| 2357 | fclose(fp); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2358 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | void re_initialize(void) |
| 2362 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2363 | free_all_buffers(); |
| 2364 | setup_all_buffers(); |
| 2365 | printf("turbostat: re-initialized with num_cpus %d\n", topo.num_cpus); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2366 | } |
| 2367 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2368 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2369 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2370 | * count_cpus() |
| 2371 | * remember the last one seen, it will be the max |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2372 | */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2373 | int count_cpus(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2374 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2375 | if (topo.max_cpu_num < cpu) |
| 2376 | topo.max_cpu_num = cpu; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2377 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2378 | topo.num_cpus += 1; |
| 2379 | return 0; |
| 2380 | } |
| 2381 | int mark_cpu_present(int cpu) |
| 2382 | { |
| 2383 | CPU_SET_S(cpu, cpu_present_setsize, cpu_present_set); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 2384 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2385 | } |
| 2386 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2387 | /* |
| 2388 | * snapshot_proc_interrupts() |
| 2389 | * |
| 2390 | * read and record summary of /proc/interrupts |
| 2391 | * |
| 2392 | * return 1 if config change requires a restart, else return 0 |
| 2393 | */ |
| 2394 | int snapshot_proc_interrupts(void) |
| 2395 | { |
| 2396 | static FILE *fp; |
| 2397 | int column, retval; |
| 2398 | |
| 2399 | if (fp == NULL) |
| 2400 | fp = fopen_or_die("/proc/interrupts", "r"); |
| 2401 | else |
| 2402 | rewind(fp); |
| 2403 | |
| 2404 | /* read 1st line of /proc/interrupts to get cpu* name for each column */ |
| 2405 | for (column = 0; column < topo.num_cpus; ++column) { |
| 2406 | int cpu_number; |
| 2407 | |
| 2408 | retval = fscanf(fp, " CPU%d", &cpu_number); |
| 2409 | if (retval != 1) |
| 2410 | break; |
| 2411 | |
| 2412 | if (cpu_number > topo.max_cpu_num) { |
| 2413 | warn("/proc/interrupts: cpu%d: > %d", cpu_number, topo.max_cpu_num); |
| 2414 | return 1; |
| 2415 | } |
| 2416 | |
| 2417 | irq_column_2_cpu[column] = cpu_number; |
| 2418 | irqs_per_cpu[cpu_number] = 0; |
| 2419 | } |
| 2420 | |
| 2421 | /* read /proc/interrupt count lines and sum up irqs per cpu */ |
| 2422 | while (1) { |
| 2423 | int column; |
| 2424 | char buf[64]; |
| 2425 | |
| 2426 | retval = fscanf(fp, " %s:", buf); /* flush irq# "N:" */ |
| 2427 | if (retval != 1) |
| 2428 | break; |
| 2429 | |
| 2430 | /* read the count per cpu */ |
| 2431 | for (column = 0; column < topo.num_cpus; ++column) { |
| 2432 | |
| 2433 | int cpu_number, irq_count; |
| 2434 | |
| 2435 | retval = fscanf(fp, " %d", &irq_count); |
| 2436 | if (retval != 1) |
| 2437 | break; |
| 2438 | |
| 2439 | cpu_number = irq_column_2_cpu[column]; |
| 2440 | irqs_per_cpu[cpu_number] += irq_count; |
| 2441 | |
| 2442 | } |
| 2443 | |
| 2444 | while (getc(fp) != '\n') |
| 2445 | ; /* flush interrupt description */ |
| 2446 | |
| 2447 | } |
| 2448 | return 0; |
| 2449 | } |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2450 | /* |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 2451 | * snapshot_gfx_rc6_ms() |
| 2452 | * |
| 2453 | * record snapshot of |
| 2454 | * /sys/class/drm/card0/power/rc6_residency_ms |
| 2455 | * |
| 2456 | * return 1 if config change requires a restart, else return 0 |
| 2457 | */ |
| 2458 | int snapshot_gfx_rc6_ms(void) |
| 2459 | { |
| 2460 | FILE *fp; |
| 2461 | int retval; |
| 2462 | |
| 2463 | fp = fopen_or_die("/sys/class/drm/card0/power/rc6_residency_ms", "r"); |
| 2464 | |
| 2465 | retval = fscanf(fp, "%lld", &gfx_cur_rc6_ms); |
| 2466 | if (retval != 1) |
| 2467 | err(1, "GFX rc6"); |
| 2468 | |
| 2469 | fclose(fp); |
| 2470 | |
| 2471 | return 0; |
| 2472 | } |
| 2473 | /* |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2474 | * snapshot_gfx_mhz() |
| 2475 | * |
| 2476 | * record snapshot of |
| 2477 | * /sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz |
| 2478 | * |
| 2479 | * return 1 if config change requires a restart, else return 0 |
| 2480 | */ |
| 2481 | int snapshot_gfx_mhz(void) |
| 2482 | { |
| 2483 | static FILE *fp; |
| 2484 | int retval; |
| 2485 | |
| 2486 | if (fp == NULL) |
| 2487 | fp = fopen_or_die("/sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz", "r"); |
Len Brown | 22048c5 | 2017-03-04 15:42:48 -0500 | [diff] [blame] | 2488 | else { |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2489 | rewind(fp); |
Len Brown | 22048c5 | 2017-03-04 15:42:48 -0500 | [diff] [blame] | 2490 | fflush(fp); |
| 2491 | } |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2492 | |
| 2493 | retval = fscanf(fp, "%d", &gfx_cur_mhz); |
| 2494 | if (retval != 1) |
| 2495 | err(1, "GFX MHz"); |
| 2496 | |
| 2497 | return 0; |
| 2498 | } |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2499 | |
| 2500 | /* |
| 2501 | * snapshot /proc and /sys files |
| 2502 | * |
| 2503 | * return 1 if configuration restart needed, else return 0 |
| 2504 | */ |
| 2505 | int snapshot_proc_sysfs_files(void) |
| 2506 | { |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 2507 | if (DO_BIC(BIC_IRQ)) |
| 2508 | if (snapshot_proc_interrupts()) |
| 2509 | return 1; |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2510 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 2511 | if (DO_BIC(BIC_GFX_rc6)) |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 2512 | snapshot_gfx_rc6_ms(); |
| 2513 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 2514 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2515 | snapshot_gfx_mhz(); |
| 2516 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2517 | return 0; |
| 2518 | } |
| 2519 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2520 | void turbostat_loop() |
| 2521 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2522 | int retval; |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 2523 | int restarted = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2524 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2525 | restart: |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 2526 | restarted++; |
| 2527 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2528 | snapshot_proc_sysfs_files(); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2529 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 2530 | if (retval < -1) { |
| 2531 | exit(retval); |
| 2532 | } else if (retval == -1) { |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 2533 | if (restarted > 1) { |
| 2534 | exit(retval); |
| 2535 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2536 | re_initialize(); |
| 2537 | goto restart; |
| 2538 | } |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 2539 | restarted = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2540 | gettimeofday(&tv_even, (struct timezone *)NULL); |
| 2541 | |
| 2542 | while (1) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2543 | if (for_all_proc_cpus(cpu_is_not_present)) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2544 | re_initialize(); |
| 2545 | goto restart; |
| 2546 | } |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 2547 | nanosleep(&interval_ts, NULL); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2548 | if (snapshot_proc_sysfs_files()) |
| 2549 | goto restart; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2550 | retval = for_all_cpus(get_counters, ODD_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 2551 | if (retval < -1) { |
| 2552 | exit(retval); |
| 2553 | } else if (retval == -1) { |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 2554 | re_initialize(); |
| 2555 | goto restart; |
| 2556 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2557 | gettimeofday(&tv_odd, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2558 | timersub(&tv_odd, &tv_even, &tv_delta); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 2559 | if (for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS)) { |
| 2560 | re_initialize(); |
| 2561 | goto restart; |
| 2562 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2563 | compute_average(EVEN_COUNTERS); |
| 2564 | format_all_counters(EVEN_COUNTERS); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2565 | flush_output_stdout(); |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 2566 | nanosleep(&interval_ts, NULL); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2567 | if (snapshot_proc_sysfs_files()) |
| 2568 | goto restart; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2569 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 2570 | if (retval < -1) { |
| 2571 | exit(retval); |
| 2572 | } else if (retval == -1) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2573 | re_initialize(); |
| 2574 | goto restart; |
| 2575 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2576 | gettimeofday(&tv_even, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2577 | timersub(&tv_even, &tv_odd, &tv_delta); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 2578 | if (for_all_cpus_2(delta_cpu, EVEN_COUNTERS, ODD_COUNTERS)) { |
| 2579 | re_initialize(); |
| 2580 | goto restart; |
| 2581 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2582 | compute_average(ODD_COUNTERS); |
| 2583 | format_all_counters(ODD_COUNTERS); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2584 | flush_output_stdout(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2585 | } |
| 2586 | } |
| 2587 | |
| 2588 | void check_dev_msr() |
| 2589 | { |
| 2590 | struct stat sb; |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2591 | char pathname[32]; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2592 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2593 | sprintf(pathname, "/dev/cpu/%d/msr", base_cpu); |
| 2594 | if (stat(pathname, &sb)) |
Len Brown | a21d38c | 2015-03-24 16:37:35 -0400 | [diff] [blame] | 2595 | if (system("/sbin/modprobe msr > /dev/null 2>&1")) |
| 2596 | err(-5, "no /dev/cpu/0/msr, Try \"# modprobe msr\" "); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2597 | } |
| 2598 | |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2599 | void check_permissions() |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2600 | { |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2601 | struct __user_cap_header_struct cap_header_data; |
| 2602 | cap_user_header_t cap_header = &cap_header_data; |
| 2603 | struct __user_cap_data_struct cap_data_data; |
| 2604 | cap_user_data_t cap_data = &cap_data_data; |
| 2605 | extern int capget(cap_user_header_t hdrp, cap_user_data_t datap); |
| 2606 | int do_exit = 0; |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2607 | char pathname[32]; |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2608 | |
| 2609 | /* check for CAP_SYS_RAWIO */ |
| 2610 | cap_header->pid = getpid(); |
| 2611 | cap_header->version = _LINUX_CAPABILITY_VERSION; |
| 2612 | if (capget(cap_header, cap_data) < 0) |
| 2613 | err(-6, "capget(2) failed"); |
| 2614 | |
| 2615 | if ((cap_data->effective & (1 << CAP_SYS_RAWIO)) == 0) { |
| 2616 | do_exit++; |
| 2617 | warnx("capget(CAP_SYS_RAWIO) failed," |
| 2618 | " try \"# setcap cap_sys_rawio=ep %s\"", progname); |
| 2619 | } |
| 2620 | |
| 2621 | /* test file permissions */ |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2622 | sprintf(pathname, "/dev/cpu/%d/msr", base_cpu); |
| 2623 | if (euidaccess(pathname, R_OK)) { |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2624 | do_exit++; |
| 2625 | warn("/dev/cpu/0/msr open failed, try chown or chmod +r /dev/cpu/*/msr"); |
| 2626 | } |
| 2627 | |
| 2628 | /* if all else fails, thell them to be root */ |
| 2629 | if (do_exit) |
| 2630 | if (getuid() != 0) |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2631 | warnx("... or simply run as root"); |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2632 | |
| 2633 | if (do_exit) |
| 2634 | exit(-6); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2635 | } |
| 2636 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2637 | /* |
| 2638 | * NHM adds support for additional MSRs: |
| 2639 | * |
| 2640 | * MSR_SMI_COUNT 0x00000034 |
| 2641 | * |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 2642 | * MSR_PLATFORM_INFO 0x000000ce |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 2643 | * MSR_PKG_CST_CONFIG_CONTROL 0x000000e2 |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2644 | * |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 2645 | * MSR_MISC_PWR_MGMT 0x000001aa |
| 2646 | * |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2647 | * MSR_PKG_C3_RESIDENCY 0x000003f8 |
| 2648 | * MSR_PKG_C6_RESIDENCY 0x000003f9 |
| 2649 | * MSR_CORE_C3_RESIDENCY 0x000003fc |
| 2650 | * MSR_CORE_C6_RESIDENCY 0x000003fd |
| 2651 | * |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2652 | * Side effect: |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 2653 | * sets global pkg_cstate_limit to decode MSR_PKG_CST_CONFIG_CONTROL |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 2654 | * sets has_misc_feature_control |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2655 | */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2656 | int probe_nhm_msrs(unsigned int family, unsigned int model) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2657 | { |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2658 | unsigned long long msr; |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 2659 | unsigned int base_ratio; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2660 | int *pkg_cstate_limits; |
| 2661 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2662 | if (!genuine_intel) |
| 2663 | return 0; |
| 2664 | |
| 2665 | if (family != 6) |
| 2666 | return 0; |
| 2667 | |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 2668 | bclk = discover_bclk(family, model); |
| 2669 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2670 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2671 | case INTEL_FAM6_NEHALEM_EP: /* Core i7, Xeon 5500 series - Bloomfield, Gainstown NHM-EP */ |
| 2672 | case INTEL_FAM6_NEHALEM: /* Core i7 and i5 Processor - Clarksfield, Lynnfield, Jasper Forest */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2673 | case 0x1F: /* Core i7 and i5 Processor - Nehalem */ |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2674 | case INTEL_FAM6_WESTMERE: /* Westmere Client - Clarkdale, Arrandale */ |
| 2675 | case INTEL_FAM6_WESTMERE_EP: /* Westmere EP - Gulftown */ |
| 2676 | case INTEL_FAM6_NEHALEM_EX: /* Nehalem-EX Xeon - Beckton */ |
| 2677 | case INTEL_FAM6_WESTMERE_EX: /* Westmere-EX Xeon - Eagleton */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2678 | pkg_cstate_limits = nhm_pkg_cstate_limits; |
| 2679 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2680 | case INTEL_FAM6_SANDYBRIDGE: /* SNB */ |
| 2681 | case INTEL_FAM6_SANDYBRIDGE_X: /* SNB Xeon */ |
| 2682 | case INTEL_FAM6_IVYBRIDGE: /* IVB */ |
| 2683 | case INTEL_FAM6_IVYBRIDGE_X: /* IVB Xeon */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2684 | pkg_cstate_limits = snb_pkg_cstate_limits; |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 2685 | has_misc_feature_control = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2686 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2687 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 2688 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 2689 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 2690 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 2691 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 2692 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
| 2693 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 2694 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 2695 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 2696 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 2697 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 2698 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2699 | pkg_cstate_limits = hsw_pkg_cstate_limits; |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 2700 | has_misc_feature_control = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2701 | break; |
Len Brown | d8ebb44 | 2016-12-01 20:27:46 -0500 | [diff] [blame] | 2702 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
| 2703 | pkg_cstate_limits = skx_pkg_cstate_limits; |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 2704 | has_misc_feature_control = 1; |
Len Brown | d8ebb44 | 2016-12-01 20:27:46 -0500 | [diff] [blame] | 2705 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2706 | case INTEL_FAM6_ATOM_SILVERMONT1: /* BYT */ |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 2707 | no_MSR_MISC_PWR_MGMT = 1; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2708 | case INTEL_FAM6_ATOM_SILVERMONT2: /* AVN */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2709 | pkg_cstate_limits = slv_pkg_cstate_limits; |
| 2710 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2711 | case INTEL_FAM6_ATOM_AIRMONT: /* AMT */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2712 | pkg_cstate_limits = amt_pkg_cstate_limits; |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 2713 | no_MSR_MISC_PWR_MGMT = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2714 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2715 | case INTEL_FAM6_XEON_PHI_KNL: /* PHI */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 2716 | case INTEL_FAM6_XEON_PHI_KNM: |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2717 | pkg_cstate_limits = phi_pkg_cstate_limits; |
| 2718 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2719 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | ac01ac1 | 2017-01-27 01:45:35 -0500 | [diff] [blame] | 2720 | case INTEL_FAM6_ATOM_GEMINI_LAKE: |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2721 | case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ |
Len Brown | e4085d5 | 2016-04-06 17:15:56 -0400 | [diff] [blame] | 2722 | pkg_cstate_limits = bxt_pkg_cstate_limits; |
| 2723 | break; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2724 | default: |
| 2725 | return 0; |
| 2726 | } |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 2727 | get_msr(base_cpu, MSR_PKG_CST_CONFIG_CONTROL, &msr); |
Len Brown | e9257f5 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 2728 | pkg_cstate_limit = pkg_cstate_limits[msr & 0xF]; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2729 | |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 2730 | get_msr(base_cpu, MSR_PLATFORM_INFO, &msr); |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 2731 | base_ratio = (msr >> 8) & 0xFF; |
| 2732 | |
| 2733 | base_hz = base_ratio * bclk * 1000000; |
| 2734 | has_base_hz = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2735 | return 1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2736 | } |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 2737 | /* |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 2738 | * SLV client has support for unique MSRs: |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 2739 | * |
| 2740 | * MSR_CC6_DEMOTION_POLICY_CONFIG |
| 2741 | * MSR_MC6_DEMOTION_POLICY_CONFIG |
| 2742 | */ |
| 2743 | |
| 2744 | int has_slv_msrs(unsigned int family, unsigned int model) |
| 2745 | { |
| 2746 | if (!genuine_intel) |
| 2747 | return 0; |
| 2748 | |
| 2749 | switch (model) { |
| 2750 | case INTEL_FAM6_ATOM_SILVERMONT1: |
| 2751 | case INTEL_FAM6_ATOM_MERRIFIELD: |
| 2752 | case INTEL_FAM6_ATOM_MOOREFIELD: |
| 2753 | return 1; |
| 2754 | } |
| 2755 | return 0; |
| 2756 | } |
Len Brown | 7170a37 | 2017-01-27 02:13:27 -0500 | [diff] [blame] | 2757 | int is_dnv(unsigned int family, unsigned int model) |
| 2758 | { |
| 2759 | |
| 2760 | if (!genuine_intel) |
| 2761 | return 0; |
| 2762 | |
| 2763 | switch (model) { |
| 2764 | case INTEL_FAM6_ATOM_DENVERTON: |
| 2765 | return 1; |
| 2766 | } |
| 2767 | return 0; |
| 2768 | } |
Len Brown | ade0eba | 2017-02-10 01:56:47 -0500 | [diff] [blame] | 2769 | int is_bdx(unsigned int family, unsigned int model) |
| 2770 | { |
| 2771 | |
| 2772 | if (!genuine_intel) |
| 2773 | return 0; |
| 2774 | |
| 2775 | switch (model) { |
| 2776 | case INTEL_FAM6_BROADWELL_X: |
| 2777 | case INTEL_FAM6_BROADWELL_XEON_D: |
| 2778 | return 1; |
| 2779 | } |
| 2780 | return 0; |
| 2781 | } |
Len Brown | 34c76197 | 2017-01-27 02:36:41 -0500 | [diff] [blame] | 2782 | int is_skx(unsigned int family, unsigned int model) |
| 2783 | { |
| 2784 | |
| 2785 | if (!genuine_intel) |
| 2786 | return 0; |
| 2787 | |
| 2788 | switch (model) { |
| 2789 | case INTEL_FAM6_SKYLAKE_X: |
| 2790 | return 1; |
| 2791 | } |
| 2792 | return 0; |
| 2793 | } |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 2794 | |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2795 | int has_turbo_ratio_limit(unsigned int family, unsigned int model) |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2796 | { |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 2797 | if (has_slv_msrs(family, model)) |
| 2798 | return 0; |
| 2799 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2800 | switch (model) { |
| 2801 | /* Nehalem compatible, but do not include turbo-ratio limit support */ |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2802 | case INTEL_FAM6_NEHALEM_EX: /* Nehalem-EX Xeon - Beckton */ |
| 2803 | case INTEL_FAM6_WESTMERE_EX: /* Westmere-EX Xeon - Eagleton */ |
| 2804 | case INTEL_FAM6_XEON_PHI_KNL: /* PHI - Knights Landing (different MSR definition) */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 2805 | case INTEL_FAM6_XEON_PHI_KNM: |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2806 | return 0; |
| 2807 | default: |
| 2808 | return 1; |
| 2809 | } |
| 2810 | } |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 2811 | int has_atom_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 2812 | { |
| 2813 | if (has_slv_msrs(family, model)) |
| 2814 | return 1; |
| 2815 | |
| 2816 | return 0; |
| 2817 | } |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2818 | int has_ivt_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 2819 | { |
| 2820 | if (!genuine_intel) |
| 2821 | return 0; |
| 2822 | |
| 2823 | if (family != 6) |
| 2824 | return 0; |
| 2825 | |
| 2826 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2827 | case INTEL_FAM6_IVYBRIDGE_X: /* IVB Xeon */ |
| 2828 | case INTEL_FAM6_HASWELL_X: /* HSW Xeon */ |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2829 | return 1; |
| 2830 | default: |
| 2831 | return 0; |
| 2832 | } |
| 2833 | } |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2834 | int has_hsw_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 2835 | { |
| 2836 | if (!genuine_intel) |
| 2837 | return 0; |
| 2838 | |
| 2839 | if (family != 6) |
| 2840 | return 0; |
| 2841 | |
| 2842 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2843 | case INTEL_FAM6_HASWELL_X: /* HSW Xeon */ |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2844 | return 1; |
| 2845 | default: |
| 2846 | return 0; |
| 2847 | } |
| 2848 | } |
| 2849 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2850 | int has_knl_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 2851 | { |
| 2852 | if (!genuine_intel) |
| 2853 | return 0; |
| 2854 | |
| 2855 | if (family != 6) |
| 2856 | return 0; |
| 2857 | |
| 2858 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2859 | case INTEL_FAM6_XEON_PHI_KNL: /* Knights Landing */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 2860 | case INTEL_FAM6_XEON_PHI_KNM: |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2861 | return 1; |
| 2862 | default: |
| 2863 | return 0; |
| 2864 | } |
| 2865 | } |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2866 | int has_glm_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 2867 | { |
| 2868 | if (!genuine_intel) |
| 2869 | return 0; |
| 2870 | |
| 2871 | if (family != 6) |
| 2872 | return 0; |
| 2873 | |
| 2874 | switch (model) { |
| 2875 | case INTEL_FAM6_ATOM_GOLDMONT: |
| 2876 | case INTEL_FAM6_SKYLAKE_X: |
| 2877 | return 1; |
| 2878 | default: |
| 2879 | return 0; |
| 2880 | } |
| 2881 | } |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2882 | int has_config_tdp(unsigned int family, unsigned int model) |
| 2883 | { |
| 2884 | if (!genuine_intel) |
| 2885 | return 0; |
| 2886 | |
| 2887 | if (family != 6) |
| 2888 | return 0; |
| 2889 | |
| 2890 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2891 | case INTEL_FAM6_IVYBRIDGE: /* IVB */ |
| 2892 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 2893 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 2894 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 2895 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 2896 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 2897 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
| 2898 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 2899 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 2900 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 2901 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 2902 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 2903 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
| 2904 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2905 | |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2906 | case INTEL_FAM6_XEON_PHI_KNL: /* Knights Landing */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 2907 | case INTEL_FAM6_XEON_PHI_KNM: |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2908 | return 1; |
| 2909 | default: |
| 2910 | return 0; |
| 2911 | } |
| 2912 | } |
| 2913 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2914 | static void |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 2915 | dump_cstate_pstate_config_info(unsigned int family, unsigned int model) |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2916 | { |
| 2917 | if (!do_nhm_platform_info) |
| 2918 | return; |
| 2919 | |
| 2920 | dump_nhm_platform_info(); |
| 2921 | |
| 2922 | if (has_hsw_turbo_ratio_limit(family, model)) |
| 2923 | dump_hsw_turbo_ratio_limits(); |
| 2924 | |
| 2925 | if (has_ivt_turbo_ratio_limit(family, model)) |
| 2926 | dump_ivt_turbo_ratio_limits(); |
| 2927 | |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2928 | if (has_turbo_ratio_limit(family, model)) |
| 2929 | dump_turbo_ratio_limits(family, model); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2930 | |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 2931 | if (has_atom_turbo_ratio_limit(family, model)) |
| 2932 | dump_atom_turbo_ratio_limits(); |
| 2933 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2934 | if (has_knl_turbo_ratio_limit(family, model)) |
| 2935 | dump_knl_turbo_ratio_limits(); |
| 2936 | |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2937 | if (has_config_tdp(family, model)) |
| 2938 | dump_config_tdp(); |
| 2939 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2940 | dump_nhm_cst_cfg(); |
| 2941 | } |
| 2942 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 2943 | static void |
| 2944 | dump_sysfs_cstate_config(void) |
| 2945 | { |
| 2946 | char path[64]; |
| 2947 | char name_buf[16]; |
| 2948 | char desc[64]; |
| 2949 | FILE *input; |
| 2950 | int state; |
| 2951 | char *sp; |
| 2952 | |
| 2953 | if (!DO_BIC(BIC_sysfs)) |
| 2954 | return; |
| 2955 | |
| 2956 | for (state = 0; state < 10; ++state) { |
| 2957 | |
| 2958 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", |
| 2959 | base_cpu, state); |
| 2960 | input = fopen(path, "r"); |
| 2961 | if (input == NULL) |
| 2962 | continue; |
| 2963 | fgets(name_buf, sizeof(name_buf), input); |
| 2964 | |
| 2965 | /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ |
| 2966 | sp = strchr(name_buf, '-'); |
| 2967 | if (!sp) |
| 2968 | sp = strchrnul(name_buf, '\n'); |
| 2969 | *sp = '\0'; |
| 2970 | |
| 2971 | fclose(input); |
| 2972 | |
| 2973 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/desc", |
| 2974 | base_cpu, state); |
| 2975 | input = fopen(path, "r"); |
| 2976 | if (input == NULL) |
| 2977 | continue; |
| 2978 | fgets(desc, sizeof(desc), input); |
| 2979 | |
| 2980 | fprintf(outf, "cpu%d: %s: %s", base_cpu, name_buf, desc); |
| 2981 | fclose(input); |
| 2982 | } |
| 2983 | } |
Len Brown | 7293fcc | 2017-02-22 00:11:12 -0500 | [diff] [blame] | 2984 | static void |
| 2985 | dump_sysfs_pstate_config(void) |
| 2986 | { |
| 2987 | char path[64]; |
| 2988 | char driver_buf[64]; |
| 2989 | char governor_buf[64]; |
| 2990 | FILE *input; |
| 2991 | int turbo; |
| 2992 | |
| 2993 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_driver", |
| 2994 | base_cpu); |
| 2995 | input = fopen(path, "r"); |
| 2996 | if (input == NULL) { |
| 2997 | fprintf(stderr, "NSFOD %s\n", path); |
| 2998 | return; |
| 2999 | } |
| 3000 | fgets(driver_buf, sizeof(driver_buf), input); |
| 3001 | fclose(input); |
| 3002 | |
| 3003 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", |
| 3004 | base_cpu); |
| 3005 | input = fopen(path, "r"); |
| 3006 | if (input == NULL) { |
| 3007 | fprintf(stderr, "NSFOD %s\n", path); |
| 3008 | return; |
| 3009 | } |
| 3010 | fgets(governor_buf, sizeof(governor_buf), input); |
| 3011 | fclose(input); |
| 3012 | |
| 3013 | fprintf(outf, "cpu%d: cpufreq driver: %s", base_cpu, driver_buf); |
| 3014 | fprintf(outf, "cpu%d: cpufreq governor: %s", base_cpu, governor_buf); |
| 3015 | |
| 3016 | sprintf(path, "/sys/devices/system/cpu/cpufreq/boost"); |
| 3017 | input = fopen(path, "r"); |
| 3018 | if (input != NULL) { |
| 3019 | fscanf(input, "%d", &turbo); |
| 3020 | fprintf(outf, "cpufreq boost: %d\n", turbo); |
| 3021 | fclose(input); |
| 3022 | } |
| 3023 | |
| 3024 | sprintf(path, "/sys/devices/system/cpu/intel_pstate/no_turbo"); |
| 3025 | input = fopen(path, "r"); |
| 3026 | if (input != NULL) { |
| 3027 | fscanf(input, "%d", &turbo); |
| 3028 | fprintf(outf, "cpufreq intel_pstate no_turbo: %d\n", turbo); |
| 3029 | fclose(input); |
| 3030 | } |
| 3031 | } |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 3032 | |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 3033 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3034 | /* |
| 3035 | * print_epb() |
| 3036 | * Decode the ENERGY_PERF_BIAS MSR |
| 3037 | */ |
| 3038 | int print_epb(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3039 | { |
| 3040 | unsigned long long msr; |
| 3041 | char *epb_string; |
| 3042 | int cpu; |
| 3043 | |
| 3044 | if (!has_epb) |
| 3045 | return 0; |
| 3046 | |
| 3047 | cpu = t->cpu_id; |
| 3048 | |
| 3049 | /* EPB is per-package */ |
| 3050 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3051 | return 0; |
| 3052 | |
| 3053 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3054 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3055 | return -1; |
| 3056 | } |
| 3057 | |
| 3058 | if (get_msr(cpu, MSR_IA32_ENERGY_PERF_BIAS, &msr)) |
| 3059 | return 0; |
| 3060 | |
Len Brown | e9be7dd | 2015-05-26 12:19:37 -0400 | [diff] [blame] | 3061 | switch (msr & 0xF) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3062 | case ENERGY_PERF_BIAS_PERFORMANCE: |
| 3063 | epb_string = "performance"; |
| 3064 | break; |
| 3065 | case ENERGY_PERF_BIAS_NORMAL: |
| 3066 | epb_string = "balanced"; |
| 3067 | break; |
| 3068 | case ENERGY_PERF_BIAS_POWERSAVE: |
| 3069 | epb_string = "powersave"; |
| 3070 | break; |
| 3071 | default: |
| 3072 | epb_string = "custom"; |
| 3073 | break; |
| 3074 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3075 | fprintf(outf, "cpu%d: MSR_IA32_ENERGY_PERF_BIAS: 0x%08llx (%s)\n", cpu, msr, epb_string); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3076 | |
| 3077 | return 0; |
| 3078 | } |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3079 | /* |
| 3080 | * print_hwp() |
| 3081 | * Decode the MSR_HWP_CAPABILITIES |
| 3082 | */ |
| 3083 | int print_hwp(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3084 | { |
| 3085 | unsigned long long msr; |
| 3086 | int cpu; |
| 3087 | |
| 3088 | if (!has_hwp) |
| 3089 | return 0; |
| 3090 | |
| 3091 | cpu = t->cpu_id; |
| 3092 | |
| 3093 | /* MSR_HWP_CAPABILITIES is per-package */ |
| 3094 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3095 | return 0; |
| 3096 | |
| 3097 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3098 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3099 | return -1; |
| 3100 | } |
| 3101 | |
| 3102 | if (get_msr(cpu, MSR_PM_ENABLE, &msr)) |
| 3103 | return 0; |
| 3104 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3105 | fprintf(outf, "cpu%d: MSR_PM_ENABLE: 0x%08llx (%sHWP)\n", |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3106 | cpu, msr, (msr & (1 << 0)) ? "" : "No-"); |
| 3107 | |
| 3108 | /* MSR_PM_ENABLE[1] == 1 if HWP is enabled and MSRs visible */ |
| 3109 | if ((msr & (1 << 0)) == 0) |
| 3110 | return 0; |
| 3111 | |
| 3112 | if (get_msr(cpu, MSR_HWP_CAPABILITIES, &msr)) |
| 3113 | return 0; |
| 3114 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3115 | fprintf(outf, "cpu%d: MSR_HWP_CAPABILITIES: 0x%08llx " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3116 | "(high 0x%x guar 0x%x eff 0x%x low 0x%x)\n", |
| 3117 | cpu, msr, |
| 3118 | (unsigned int)HWP_HIGHEST_PERF(msr), |
| 3119 | (unsigned int)HWP_GUARANTEED_PERF(msr), |
| 3120 | (unsigned int)HWP_MOSTEFFICIENT_PERF(msr), |
| 3121 | (unsigned int)HWP_LOWEST_PERF(msr)); |
| 3122 | |
| 3123 | if (get_msr(cpu, MSR_HWP_REQUEST, &msr)) |
| 3124 | return 0; |
| 3125 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3126 | fprintf(outf, "cpu%d: MSR_HWP_REQUEST: 0x%08llx " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3127 | "(min 0x%x max 0x%x des 0x%x epp 0x%x window 0x%x pkg 0x%x)\n", |
| 3128 | cpu, msr, |
| 3129 | (unsigned int)(((msr) >> 0) & 0xff), |
| 3130 | (unsigned int)(((msr) >> 8) & 0xff), |
| 3131 | (unsigned int)(((msr) >> 16) & 0xff), |
| 3132 | (unsigned int)(((msr) >> 24) & 0xff), |
| 3133 | (unsigned int)(((msr) >> 32) & 0xff3), |
| 3134 | (unsigned int)(((msr) >> 42) & 0x1)); |
| 3135 | |
| 3136 | if (has_hwp_pkg) { |
| 3137 | if (get_msr(cpu, MSR_HWP_REQUEST_PKG, &msr)) |
| 3138 | return 0; |
| 3139 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3140 | fprintf(outf, "cpu%d: MSR_HWP_REQUEST_PKG: 0x%08llx " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3141 | "(min 0x%x max 0x%x des 0x%x epp 0x%x window 0x%x)\n", |
| 3142 | cpu, msr, |
| 3143 | (unsigned int)(((msr) >> 0) & 0xff), |
| 3144 | (unsigned int)(((msr) >> 8) & 0xff), |
| 3145 | (unsigned int)(((msr) >> 16) & 0xff), |
| 3146 | (unsigned int)(((msr) >> 24) & 0xff), |
| 3147 | (unsigned int)(((msr) >> 32) & 0xff3)); |
| 3148 | } |
| 3149 | if (has_hwp_notify) { |
| 3150 | if (get_msr(cpu, MSR_HWP_INTERRUPT, &msr)) |
| 3151 | return 0; |
| 3152 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3153 | fprintf(outf, "cpu%d: MSR_HWP_INTERRUPT: 0x%08llx " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3154 | "(%s_Guaranteed_Perf_Change, %s_Excursion_Min)\n", |
| 3155 | cpu, msr, |
| 3156 | ((msr) & 0x1) ? "EN" : "Dis", |
| 3157 | ((msr) & 0x2) ? "EN" : "Dis"); |
| 3158 | } |
| 3159 | if (get_msr(cpu, MSR_HWP_STATUS, &msr)) |
| 3160 | return 0; |
| 3161 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3162 | fprintf(outf, "cpu%d: MSR_HWP_STATUS: 0x%08llx " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3163 | "(%sGuaranteed_Perf_Change, %sExcursion_Min)\n", |
| 3164 | cpu, msr, |
| 3165 | ((msr) & 0x1) ? "" : "No-", |
| 3166 | ((msr) & 0x2) ? "" : "No-"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3167 | |
| 3168 | return 0; |
| 3169 | } |
| 3170 | |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3171 | /* |
| 3172 | * print_perf_limit() |
| 3173 | */ |
| 3174 | int print_perf_limit(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3175 | { |
| 3176 | unsigned long long msr; |
| 3177 | int cpu; |
| 3178 | |
| 3179 | cpu = t->cpu_id; |
| 3180 | |
| 3181 | /* per-package */ |
| 3182 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3183 | return 0; |
| 3184 | |
| 3185 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3186 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3187 | return -1; |
| 3188 | } |
| 3189 | |
| 3190 | if (do_core_perf_limit_reasons) { |
| 3191 | get_msr(cpu, MSR_CORE_PERF_LIMIT_REASONS, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3192 | fprintf(outf, "cpu%d: MSR_CORE_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr); |
| 3193 | fprintf(outf, " (Active: %s%s%s%s%s%s%s%s%s%s%s%s%s%s)", |
Len Brown | e33cbe8 | 2015-03-13 16:30:57 -0400 | [diff] [blame] | 3194 | (msr & 1 << 15) ? "bit15, " : "", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3195 | (msr & 1 << 14) ? "bit14, " : "", |
Len Brown | e33cbe8 | 2015-03-13 16:30:57 -0400 | [diff] [blame] | 3196 | (msr & 1 << 13) ? "Transitions, " : "", |
| 3197 | (msr & 1 << 12) ? "MultiCoreTurbo, " : "", |
| 3198 | (msr & 1 << 11) ? "PkgPwrL2, " : "", |
| 3199 | (msr & 1 << 10) ? "PkgPwrL1, " : "", |
| 3200 | (msr & 1 << 9) ? "CorePwr, " : "", |
| 3201 | (msr & 1 << 8) ? "Amps, " : "", |
| 3202 | (msr & 1 << 6) ? "VR-Therm, " : "", |
| 3203 | (msr & 1 << 5) ? "Auto-HWP, " : "", |
| 3204 | (msr & 1 << 4) ? "Graphics, " : "", |
| 3205 | (msr & 1 << 2) ? "bit2, " : "", |
| 3206 | (msr & 1 << 1) ? "ThermStatus, " : "", |
| 3207 | (msr & 1 << 0) ? "PROCHOT, " : ""); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3208 | fprintf(outf, " (Logged: %s%s%s%s%s%s%s%s%s%s%s%s%s%s)\n", |
Len Brown | e33cbe8 | 2015-03-13 16:30:57 -0400 | [diff] [blame] | 3209 | (msr & 1 << 31) ? "bit31, " : "", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3210 | (msr & 1 << 30) ? "bit30, " : "", |
Len Brown | e33cbe8 | 2015-03-13 16:30:57 -0400 | [diff] [blame] | 3211 | (msr & 1 << 29) ? "Transitions, " : "", |
| 3212 | (msr & 1 << 28) ? "MultiCoreTurbo, " : "", |
| 3213 | (msr & 1 << 27) ? "PkgPwrL2, " : "", |
| 3214 | (msr & 1 << 26) ? "PkgPwrL1, " : "", |
| 3215 | (msr & 1 << 25) ? "CorePwr, " : "", |
| 3216 | (msr & 1 << 24) ? "Amps, " : "", |
| 3217 | (msr & 1 << 22) ? "VR-Therm, " : "", |
| 3218 | (msr & 1 << 21) ? "Auto-HWP, " : "", |
| 3219 | (msr & 1 << 20) ? "Graphics, " : "", |
| 3220 | (msr & 1 << 18) ? "bit18, " : "", |
| 3221 | (msr & 1 << 17) ? "ThermStatus, " : "", |
| 3222 | (msr & 1 << 16) ? "PROCHOT, " : ""); |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3223 | |
| 3224 | } |
| 3225 | if (do_gfx_perf_limit_reasons) { |
| 3226 | get_msr(cpu, MSR_GFX_PERF_LIMIT_REASONS, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3227 | fprintf(outf, "cpu%d: MSR_GFX_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr); |
| 3228 | fprintf(outf, " (Active: %s%s%s%s%s%s%s%s)", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3229 | (msr & 1 << 0) ? "PROCHOT, " : "", |
| 3230 | (msr & 1 << 1) ? "ThermStatus, " : "", |
| 3231 | (msr & 1 << 4) ? "Graphics, " : "", |
| 3232 | (msr & 1 << 6) ? "VR-Therm, " : "", |
| 3233 | (msr & 1 << 8) ? "Amps, " : "", |
| 3234 | (msr & 1 << 9) ? "GFXPwr, " : "", |
| 3235 | (msr & 1 << 10) ? "PkgPwrL1, " : "", |
| 3236 | (msr & 1 << 11) ? "PkgPwrL2, " : ""); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3237 | fprintf(outf, " (Logged: %s%s%s%s%s%s%s%s)\n", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3238 | (msr & 1 << 16) ? "PROCHOT, " : "", |
| 3239 | (msr & 1 << 17) ? "ThermStatus, " : "", |
| 3240 | (msr & 1 << 20) ? "Graphics, " : "", |
| 3241 | (msr & 1 << 22) ? "VR-Therm, " : "", |
| 3242 | (msr & 1 << 24) ? "Amps, " : "", |
| 3243 | (msr & 1 << 25) ? "GFXPwr, " : "", |
| 3244 | (msr & 1 << 26) ? "PkgPwrL1, " : "", |
| 3245 | (msr & 1 << 27) ? "PkgPwrL2, " : ""); |
| 3246 | } |
| 3247 | if (do_ring_perf_limit_reasons) { |
| 3248 | get_msr(cpu, MSR_RING_PERF_LIMIT_REASONS, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3249 | fprintf(outf, "cpu%d: MSR_RING_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr); |
| 3250 | fprintf(outf, " (Active: %s%s%s%s%s%s)", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3251 | (msr & 1 << 0) ? "PROCHOT, " : "", |
| 3252 | (msr & 1 << 1) ? "ThermStatus, " : "", |
| 3253 | (msr & 1 << 6) ? "VR-Therm, " : "", |
| 3254 | (msr & 1 << 8) ? "Amps, " : "", |
| 3255 | (msr & 1 << 10) ? "PkgPwrL1, " : "", |
| 3256 | (msr & 1 << 11) ? "PkgPwrL2, " : ""); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3257 | fprintf(outf, " (Logged: %s%s%s%s%s%s)\n", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3258 | (msr & 1 << 16) ? "PROCHOT, " : "", |
| 3259 | (msr & 1 << 17) ? "ThermStatus, " : "", |
| 3260 | (msr & 1 << 22) ? "VR-Therm, " : "", |
| 3261 | (msr & 1 << 24) ? "Amps, " : "", |
| 3262 | (msr & 1 << 26) ? "PkgPwrL1, " : "", |
| 3263 | (msr & 1 << 27) ? "PkgPwrL2, " : ""); |
| 3264 | } |
| 3265 | return 0; |
| 3266 | } |
| 3267 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3268 | #define RAPL_POWER_GRANULARITY 0x7FFF /* 15 bit power granularity */ |
| 3269 | #define RAPL_TIME_GRANULARITY 0x3F /* 6 bit time granularity */ |
| 3270 | |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 3271 | double get_tdp(unsigned int model) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3272 | { |
| 3273 | unsigned long long msr; |
| 3274 | |
| 3275 | if (do_rapl & RAPL_PKG_POWER_INFO) |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3276 | if (!get_msr(base_cpu, MSR_PKG_POWER_INFO, &msr)) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3277 | return ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units; |
| 3278 | |
| 3279 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3280 | case INTEL_FAM6_ATOM_SILVERMONT1: |
| 3281 | case INTEL_FAM6_ATOM_SILVERMONT2: |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3282 | return 30.0; |
| 3283 | default: |
| 3284 | return 135.0; |
| 3285 | } |
| 3286 | } |
| 3287 | |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 3288 | /* |
| 3289 | * rapl_dram_energy_units_probe() |
| 3290 | * Energy units are either hard-coded, or come from RAPL Energy Unit MSR. |
| 3291 | */ |
| 3292 | static double |
| 3293 | rapl_dram_energy_units_probe(int model, double rapl_energy_units) |
| 3294 | { |
| 3295 | /* only called for genuine_intel, family 6 */ |
| 3296 | |
| 3297 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3298 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 3299 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 3300 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 3301 | case INTEL_FAM6_XEON_PHI_KNL: /* KNL */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 3302 | case INTEL_FAM6_XEON_PHI_KNM: |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 3303 | return (rapl_dram_energy_units = 15.3 / 1000000); |
| 3304 | default: |
| 3305 | return (rapl_energy_units); |
| 3306 | } |
| 3307 | } |
| 3308 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3309 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3310 | /* |
| 3311 | * rapl_probe() |
| 3312 | * |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3313 | * sets do_rapl, rapl_power_units, rapl_energy_units, rapl_time_units |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3314 | */ |
| 3315 | void rapl_probe(unsigned int family, unsigned int model) |
| 3316 | { |
| 3317 | unsigned long long msr; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3318 | unsigned int time_unit; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3319 | double tdp; |
| 3320 | |
| 3321 | if (!genuine_intel) |
| 3322 | return; |
| 3323 | |
| 3324 | if (family != 6) |
| 3325 | return; |
| 3326 | |
| 3327 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3328 | case INTEL_FAM6_SANDYBRIDGE: |
| 3329 | case INTEL_FAM6_IVYBRIDGE: |
| 3330 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 3331 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 3332 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 3333 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 3334 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3335 | do_rapl = RAPL_PKG | RAPL_CORES | RAPL_CORE_POLICY | RAPL_GFX | RAPL_PKG_POWER_INFO; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3336 | if (rapl_joules) { |
| 3337 | BIC_PRESENT(BIC_Pkg_J); |
| 3338 | BIC_PRESENT(BIC_Cor_J); |
| 3339 | BIC_PRESENT(BIC_GFX_J); |
| 3340 | } else { |
| 3341 | BIC_PRESENT(BIC_PkgWatt); |
| 3342 | BIC_PRESENT(BIC_CorWatt); |
| 3343 | BIC_PRESENT(BIC_GFXWatt); |
| 3344 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3345 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3346 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | ac01ac1 | 2017-01-27 01:45:35 -0500 | [diff] [blame] | 3347 | case INTEL_FAM6_ATOM_GEMINI_LAKE: |
Len Brown | e4085d5 | 2016-04-06 17:15:56 -0400 | [diff] [blame] | 3348 | do_rapl = RAPL_PKG | RAPL_PKG_POWER_INFO; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3349 | if (rapl_joules) |
| 3350 | BIC_PRESENT(BIC_Pkg_J); |
| 3351 | else |
| 3352 | BIC_PRESENT(BIC_PkgWatt); |
Len Brown | e4085d5 | 2016-04-06 17:15:56 -0400 | [diff] [blame] | 3353 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3354 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 3355 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 3356 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 3357 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Len Brown | 8182492 | 2017-03-04 17:23:07 -0500 | [diff] [blame^] | 3358 | do_rapl = RAPL_PKG | RAPL_CORES | RAPL_CORE_POLICY | RAPL_DRAM | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_GFX | RAPL_PKG_POWER_INFO; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3359 | BIC_PRESENT(BIC_PKG__); |
| 3360 | BIC_PRESENT(BIC_RAM__); |
| 3361 | if (rapl_joules) { |
| 3362 | BIC_PRESENT(BIC_Pkg_J); |
| 3363 | BIC_PRESENT(BIC_Cor_J); |
| 3364 | BIC_PRESENT(BIC_RAM_J); |
Len Brown | 8182492 | 2017-03-04 17:23:07 -0500 | [diff] [blame^] | 3365 | BIC_PRESENT(BIC_GFX_J); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3366 | } else { |
| 3367 | BIC_PRESENT(BIC_PkgWatt); |
| 3368 | BIC_PRESENT(BIC_CorWatt); |
| 3369 | BIC_PRESENT(BIC_RAMWatt); |
Len Brown | 8182492 | 2017-03-04 17:23:07 -0500 | [diff] [blame^] | 3370 | BIC_PRESENT(BIC_GFXWatt); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3371 | } |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3372 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3373 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 3374 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 3375 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 3376 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
| 3377 | case INTEL_FAM6_XEON_PHI_KNL: /* KNL */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 3378 | case INTEL_FAM6_XEON_PHI_KNM: |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3379 | do_rapl = RAPL_PKG | RAPL_DRAM | RAPL_DRAM_POWER_INFO | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_PKG_POWER_INFO; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3380 | BIC_PRESENT(BIC_PKG__); |
| 3381 | BIC_PRESENT(BIC_RAM__); |
| 3382 | if (rapl_joules) { |
| 3383 | BIC_PRESENT(BIC_Pkg_J); |
| 3384 | BIC_PRESENT(BIC_RAM_J); |
| 3385 | } else { |
| 3386 | BIC_PRESENT(BIC_PkgWatt); |
| 3387 | BIC_PRESENT(BIC_RAMWatt); |
| 3388 | } |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 3389 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3390 | case INTEL_FAM6_SANDYBRIDGE_X: |
| 3391 | case INTEL_FAM6_IVYBRIDGE_X: |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3392 | do_rapl = RAPL_PKG | RAPL_CORES | RAPL_CORE_POLICY | RAPL_DRAM | RAPL_DRAM_POWER_INFO | RAPL_PKG_PERF_STATUS | RAPL_DRAM_PERF_STATUS | RAPL_PKG_POWER_INFO; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3393 | BIC_PRESENT(BIC_PKG__); |
| 3394 | BIC_PRESENT(BIC_RAM__); |
| 3395 | if (rapl_joules) { |
| 3396 | BIC_PRESENT(BIC_Pkg_J); |
| 3397 | BIC_PRESENT(BIC_Cor_J); |
| 3398 | BIC_PRESENT(BIC_RAM_J); |
| 3399 | } else { |
| 3400 | BIC_PRESENT(BIC_PkgWatt); |
| 3401 | BIC_PRESENT(BIC_CorWatt); |
| 3402 | BIC_PRESENT(BIC_RAMWatt); |
| 3403 | } |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3404 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3405 | case INTEL_FAM6_ATOM_SILVERMONT1: /* BYT */ |
| 3406 | case INTEL_FAM6_ATOM_SILVERMONT2: /* AVN */ |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 3407 | do_rapl = RAPL_PKG | RAPL_CORES; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3408 | if (rapl_joules) { |
| 3409 | BIC_PRESENT(BIC_Pkg_J); |
| 3410 | BIC_PRESENT(BIC_Cor_J); |
| 3411 | } else { |
| 3412 | BIC_PRESENT(BIC_PkgWatt); |
| 3413 | BIC_PRESENT(BIC_CorWatt); |
| 3414 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3415 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3416 | case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ |
Jacob Pan | 0f64490 | 2016-06-16 09:48:22 -0700 | [diff] [blame] | 3417 | do_rapl = RAPL_PKG | RAPL_DRAM | RAPL_DRAM_POWER_INFO | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_PKG_POWER_INFO | RAPL_CORES_ENERGY_STATUS; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3418 | BIC_PRESENT(BIC_PKG__); |
| 3419 | BIC_PRESENT(BIC_RAM__); |
| 3420 | if (rapl_joules) { |
| 3421 | BIC_PRESENT(BIC_Pkg_J); |
| 3422 | BIC_PRESENT(BIC_Cor_J); |
| 3423 | BIC_PRESENT(BIC_RAM_J); |
| 3424 | } else { |
| 3425 | BIC_PRESENT(BIC_PkgWatt); |
| 3426 | BIC_PRESENT(BIC_CorWatt); |
| 3427 | BIC_PRESENT(BIC_RAMWatt); |
| 3428 | } |
Jacob Pan | 0f64490 | 2016-06-16 09:48:22 -0700 | [diff] [blame] | 3429 | break; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3430 | default: |
| 3431 | return; |
| 3432 | } |
| 3433 | |
| 3434 | /* units on package 0, verify later other packages match */ |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3435 | if (get_msr(base_cpu, MSR_RAPL_POWER_UNIT, &msr)) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3436 | return; |
| 3437 | |
| 3438 | rapl_power_units = 1.0 / (1 << (msr & 0xF)); |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3439 | if (model == INTEL_FAM6_ATOM_SILVERMONT1) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3440 | rapl_energy_units = 1.0 * (1 << (msr >> 8 & 0x1F)) / 1000000; |
| 3441 | else |
| 3442 | rapl_energy_units = 1.0 / (1 << (msr >> 8 & 0x1F)); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3443 | |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 3444 | rapl_dram_energy_units = rapl_dram_energy_units_probe(model, rapl_energy_units); |
| 3445 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3446 | time_unit = msr >> 16 & 0xF; |
| 3447 | if (time_unit == 0) |
| 3448 | time_unit = 0xA; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3449 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3450 | rapl_time_units = 1.0 / (1 << (time_unit)); |
| 3451 | |
| 3452 | tdp = get_tdp(model); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3453 | |
| 3454 | rapl_joule_counter_range = 0xFFFFFFFF * rapl_energy_units / tdp; |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3455 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3456 | fprintf(outf, "RAPL: %.0f sec. Joule Counter Range, at %.0f Watts\n", rapl_joule_counter_range, tdp); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3457 | |
| 3458 | return; |
| 3459 | } |
| 3460 | |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 3461 | void perf_limit_reasons_probe(unsigned int family, unsigned int model) |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3462 | { |
| 3463 | if (!genuine_intel) |
| 3464 | return; |
| 3465 | |
| 3466 | if (family != 6) |
| 3467 | return; |
| 3468 | |
| 3469 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3470 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 3471 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 3472 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3473 | do_gfx_perf_limit_reasons = 1; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3474 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3475 | do_core_perf_limit_reasons = 1; |
| 3476 | do_ring_perf_limit_reasons = 1; |
| 3477 | default: |
| 3478 | return; |
| 3479 | } |
| 3480 | } |
| 3481 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3482 | int print_thermal(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3483 | { |
| 3484 | unsigned long long msr; |
| 3485 | unsigned int dts; |
| 3486 | int cpu; |
| 3487 | |
| 3488 | if (!(do_dts || do_ptm)) |
| 3489 | return 0; |
| 3490 | |
| 3491 | cpu = t->cpu_id; |
| 3492 | |
| 3493 | /* DTS is per-core, no need to print for each thread */ |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 3494 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3495 | return 0; |
| 3496 | |
| 3497 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3498 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3499 | return -1; |
| 3500 | } |
| 3501 | |
| 3502 | if (do_ptm && (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) { |
| 3503 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr)) |
| 3504 | return 0; |
| 3505 | |
| 3506 | dts = (msr >> 16) & 0x7F; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3507 | fprintf(outf, "cpu%d: MSR_IA32_PACKAGE_THERM_STATUS: 0x%08llx (%d C)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3508 | cpu, msr, tcc_activation_temp - dts); |
| 3509 | |
| 3510 | #ifdef THERM_DEBUG |
| 3511 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, &msr)) |
| 3512 | return 0; |
| 3513 | |
| 3514 | dts = (msr >> 16) & 0x7F; |
| 3515 | dts2 = (msr >> 8) & 0x7F; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3516 | fprintf(outf, "cpu%d: MSR_IA32_PACKAGE_THERM_INTERRUPT: 0x%08llx (%d C, %d C)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3517 | cpu, msr, tcc_activation_temp - dts, tcc_activation_temp - dts2); |
| 3518 | #endif |
| 3519 | } |
| 3520 | |
| 3521 | |
| 3522 | if (do_dts) { |
| 3523 | unsigned int resolution; |
| 3524 | |
| 3525 | if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr)) |
| 3526 | return 0; |
| 3527 | |
| 3528 | dts = (msr >> 16) & 0x7F; |
| 3529 | resolution = (msr >> 27) & 0xF; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3530 | fprintf(outf, "cpu%d: MSR_IA32_THERM_STATUS: 0x%08llx (%d C +/- %d)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3531 | cpu, msr, tcc_activation_temp - dts, resolution); |
| 3532 | |
| 3533 | #ifdef THERM_DEBUG |
| 3534 | if (get_msr(cpu, MSR_IA32_THERM_INTERRUPT, &msr)) |
| 3535 | return 0; |
| 3536 | |
| 3537 | dts = (msr >> 16) & 0x7F; |
| 3538 | dts2 = (msr >> 8) & 0x7F; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3539 | fprintf(outf, "cpu%d: MSR_IA32_THERM_INTERRUPT: 0x%08llx (%d C, %d C)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3540 | cpu, msr, tcc_activation_temp - dts, tcc_activation_temp - dts2); |
| 3541 | #endif |
| 3542 | } |
| 3543 | |
| 3544 | return 0; |
| 3545 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 3546 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3547 | void print_power_limit_msr(int cpu, unsigned long long msr, char *label) |
| 3548 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3549 | fprintf(outf, "cpu%d: %s: %sabled (%f Watts, %f sec, clamp %sabled)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3550 | cpu, label, |
| 3551 | ((msr >> 15) & 1) ? "EN" : "DIS", |
| 3552 | ((msr >> 0) & 0x7FFF) * rapl_power_units, |
| 3553 | (1.0 + (((msr >> 22) & 0x3)/4.0)) * (1 << ((msr >> 17) & 0x1F)) * rapl_time_units, |
| 3554 | (((msr >> 16) & 1) ? "EN" : "DIS")); |
| 3555 | |
| 3556 | return; |
| 3557 | } |
| 3558 | |
| 3559 | int print_rapl(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3560 | { |
| 3561 | unsigned long long msr; |
| 3562 | int cpu; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3563 | |
| 3564 | if (!do_rapl) |
| 3565 | return 0; |
| 3566 | |
| 3567 | /* RAPL counters are per package, so print only for 1st thread/package */ |
| 3568 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3569 | return 0; |
| 3570 | |
| 3571 | cpu = t->cpu_id; |
| 3572 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3573 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3574 | return -1; |
| 3575 | } |
| 3576 | |
| 3577 | if (get_msr(cpu, MSR_RAPL_POWER_UNIT, &msr)) |
| 3578 | return -1; |
| 3579 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3580 | fprintf(outf, "cpu%d: MSR_RAPL_POWER_UNIT: 0x%08llx (%f Watts, %f Joules, %f sec.)\n", cpu, msr, |
| 3581 | rapl_power_units, rapl_energy_units, rapl_time_units); |
| 3582 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3583 | if (do_rapl & RAPL_PKG_POWER_INFO) { |
| 3584 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3585 | if (get_msr(cpu, MSR_PKG_POWER_INFO, &msr)) |
| 3586 | return -5; |
| 3587 | |
| 3588 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3589 | fprintf(outf, "cpu%d: MSR_PKG_POWER_INFO: 0x%08llx (%.0f W TDP, RAPL %.0f - %.0f W, %f sec.)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3590 | cpu, msr, |
| 3591 | ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3592 | ((msr >> 16) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3593 | ((msr >> 32) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3594 | ((msr >> 48) & RAPL_TIME_GRANULARITY) * rapl_time_units); |
| 3595 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3596 | } |
| 3597 | if (do_rapl & RAPL_PKG) { |
| 3598 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3599 | if (get_msr(cpu, MSR_PKG_POWER_LIMIT, &msr)) |
| 3600 | return -9; |
| 3601 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3602 | fprintf(outf, "cpu%d: MSR_PKG_POWER_LIMIT: 0x%08llx (%slocked)\n", |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3603 | cpu, msr, (msr >> 63) & 1 ? "" : "UN"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3604 | |
| 3605 | print_power_limit_msr(cpu, msr, "PKG Limit #1"); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3606 | fprintf(outf, "cpu%d: PKG Limit #2: %sabled (%f Watts, %f* sec, clamp %sabled)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3607 | cpu, |
| 3608 | ((msr >> 47) & 1) ? "EN" : "DIS", |
| 3609 | ((msr >> 32) & 0x7FFF) * rapl_power_units, |
| 3610 | (1.0 + (((msr >> 54) & 0x3)/4.0)) * (1 << ((msr >> 49) & 0x1F)) * rapl_time_units, |
| 3611 | ((msr >> 48) & 1) ? "EN" : "DIS"); |
| 3612 | } |
| 3613 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3614 | if (do_rapl & RAPL_DRAM_POWER_INFO) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3615 | if (get_msr(cpu, MSR_DRAM_POWER_INFO, &msr)) |
| 3616 | return -6; |
| 3617 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3618 | fprintf(outf, "cpu%d: MSR_DRAM_POWER_INFO,: 0x%08llx (%.0f W TDP, RAPL %.0f - %.0f W, %f sec.)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3619 | cpu, msr, |
| 3620 | ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3621 | ((msr >> 16) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3622 | ((msr >> 32) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3623 | ((msr >> 48) & RAPL_TIME_GRANULARITY) * rapl_time_units); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3624 | } |
| 3625 | if (do_rapl & RAPL_DRAM) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3626 | if (get_msr(cpu, MSR_DRAM_POWER_LIMIT, &msr)) |
| 3627 | return -9; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3628 | fprintf(outf, "cpu%d: MSR_DRAM_POWER_LIMIT: 0x%08llx (%slocked)\n", |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3629 | cpu, msr, (msr >> 31) & 1 ? "" : "UN"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3630 | |
| 3631 | print_power_limit_msr(cpu, msr, "DRAM Limit"); |
| 3632 | } |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3633 | if (do_rapl & RAPL_CORE_POLICY) { |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3634 | if (get_msr(cpu, MSR_PP0_POLICY, &msr)) |
| 3635 | return -7; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3636 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3637 | fprintf(outf, "cpu%d: MSR_PP0_POLICY: %lld\n", cpu, msr & 0xF); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3638 | } |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 3639 | if (do_rapl & RAPL_CORES_POWER_LIMIT) { |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3640 | if (get_msr(cpu, MSR_PP0_POWER_LIMIT, &msr)) |
| 3641 | return -9; |
| 3642 | fprintf(outf, "cpu%d: MSR_PP0_POWER_LIMIT: 0x%08llx (%slocked)\n", |
| 3643 | cpu, msr, (msr >> 31) & 1 ? "" : "UN"); |
| 3644 | print_power_limit_msr(cpu, msr, "Cores Limit"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3645 | } |
| 3646 | if (do_rapl & RAPL_GFX) { |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3647 | if (get_msr(cpu, MSR_PP1_POLICY, &msr)) |
| 3648 | return -8; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3649 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3650 | fprintf(outf, "cpu%d: MSR_PP1_POLICY: %lld\n", cpu, msr & 0xF); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3651 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3652 | if (get_msr(cpu, MSR_PP1_POWER_LIMIT, &msr)) |
| 3653 | return -9; |
| 3654 | fprintf(outf, "cpu%d: MSR_PP1_POWER_LIMIT: 0x%08llx (%slocked)\n", |
| 3655 | cpu, msr, (msr >> 31) & 1 ? "" : "UN"); |
| 3656 | print_power_limit_msr(cpu, msr, "GFX Limit"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3657 | } |
| 3658 | return 0; |
| 3659 | } |
| 3660 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3661 | /* |
| 3662 | * SNB adds support for additional MSRs: |
| 3663 | * |
| 3664 | * MSR_PKG_C7_RESIDENCY 0x000003fa |
| 3665 | * MSR_CORE_C7_RESIDENCY 0x000003fe |
| 3666 | * MSR_PKG_C2_RESIDENCY 0x0000060d |
| 3667 | */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3668 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3669 | int has_snb_msrs(unsigned int family, unsigned int model) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3670 | { |
| 3671 | if (!genuine_intel) |
| 3672 | return 0; |
| 3673 | |
| 3674 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3675 | case INTEL_FAM6_SANDYBRIDGE: |
| 3676 | case INTEL_FAM6_SANDYBRIDGE_X: |
| 3677 | case INTEL_FAM6_IVYBRIDGE: /* IVB */ |
| 3678 | case INTEL_FAM6_IVYBRIDGE_X: /* IVB Xeon */ |
| 3679 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 3680 | case INTEL_FAM6_HASWELL_X: /* HSW */ |
| 3681 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 3682 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 3683 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 3684 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
| 3685 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 3686 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 3687 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 3688 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 3689 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 3690 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
| 3691 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
| 3692 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | ac01ac1 | 2017-01-27 01:45:35 -0500 | [diff] [blame] | 3693 | case INTEL_FAM6_ATOM_GEMINI_LAKE: |
Xiaolong Wang | 5bbac26 | 2016-09-30 17:53:40 +0800 | [diff] [blame] | 3694 | case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3695 | return 1; |
| 3696 | } |
| 3697 | return 0; |
| 3698 | } |
| 3699 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3700 | /* |
| 3701 | * HSW adds support for additional MSRs: |
| 3702 | * |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 3703 | * MSR_PKG_C8_RESIDENCY 0x00000630 |
| 3704 | * MSR_PKG_C9_RESIDENCY 0x00000631 |
| 3705 | * MSR_PKG_C10_RESIDENCY 0x00000632 |
| 3706 | * |
| 3707 | * MSR_PKGC8_IRTL 0x00000633 |
| 3708 | * MSR_PKGC9_IRTL 0x00000634 |
| 3709 | * MSR_PKGC10_IRTL 0x00000635 |
| 3710 | * |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3711 | */ |
| 3712 | int has_hsw_msrs(unsigned int family, unsigned int model) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 3713 | { |
| 3714 | if (!genuine_intel) |
| 3715 | return 0; |
| 3716 | |
| 3717 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3718 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 3719 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 3720 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 3721 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 3722 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 3723 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
| 3724 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | ac01ac1 | 2017-01-27 01:45:35 -0500 | [diff] [blame] | 3725 | case INTEL_FAM6_ATOM_GEMINI_LAKE: |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 3726 | return 1; |
| 3727 | } |
| 3728 | return 0; |
| 3729 | } |
| 3730 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3731 | /* |
| 3732 | * SKL adds support for additional MSRS: |
| 3733 | * |
| 3734 | * MSR_PKG_WEIGHTED_CORE_C0_RES 0x00000658 |
| 3735 | * MSR_PKG_ANY_CORE_C0_RES 0x00000659 |
| 3736 | * MSR_PKG_ANY_GFXE_C0_RES 0x0000065A |
| 3737 | * MSR_PKG_BOTH_CORE_GFXE_C0_RES 0x0000065B |
| 3738 | */ |
| 3739 | int has_skl_msrs(unsigned int family, unsigned int model) |
| 3740 | { |
| 3741 | if (!genuine_intel) |
| 3742 | return 0; |
| 3743 | |
| 3744 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3745 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 3746 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 3747 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 3748 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3749 | return 1; |
| 3750 | } |
| 3751 | return 0; |
| 3752 | } |
| 3753 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3754 | int is_slm(unsigned int family, unsigned int model) |
| 3755 | { |
| 3756 | if (!genuine_intel) |
| 3757 | return 0; |
| 3758 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3759 | case INTEL_FAM6_ATOM_SILVERMONT1: /* BYT */ |
| 3760 | case INTEL_FAM6_ATOM_SILVERMONT2: /* AVN */ |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3761 | return 1; |
| 3762 | } |
| 3763 | return 0; |
| 3764 | } |
| 3765 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 3766 | int is_knl(unsigned int family, unsigned int model) |
| 3767 | { |
| 3768 | if (!genuine_intel) |
| 3769 | return 0; |
| 3770 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3771 | case INTEL_FAM6_XEON_PHI_KNL: /* KNL */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 3772 | case INTEL_FAM6_XEON_PHI_KNM: |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 3773 | return 1; |
| 3774 | } |
| 3775 | return 0; |
| 3776 | } |
| 3777 | |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 3778 | unsigned int get_aperf_mperf_multiplier(unsigned int family, unsigned int model) |
| 3779 | { |
| 3780 | if (is_knl(family, model)) |
| 3781 | return 1024; |
| 3782 | return 1; |
| 3783 | } |
| 3784 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3785 | #define SLM_BCLK_FREQS 5 |
| 3786 | double slm_freq_table[SLM_BCLK_FREQS] = { 83.3, 100.0, 133.3, 116.7, 80.0}; |
| 3787 | |
| 3788 | double slm_bclk(void) |
| 3789 | { |
| 3790 | unsigned long long msr = 3; |
| 3791 | unsigned int i; |
| 3792 | double freq; |
| 3793 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3794 | if (get_msr(base_cpu, MSR_FSB_FREQ, &msr)) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3795 | fprintf(outf, "SLM BCLK: unknown\n"); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3796 | |
| 3797 | i = msr & 0xf; |
| 3798 | if (i >= SLM_BCLK_FREQS) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3799 | fprintf(outf, "SLM BCLK[%d] invalid\n", i); |
Colin Ian King | 0a91e55 | 2016-04-25 13:03:15 +0100 | [diff] [blame] | 3800 | i = 3; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3801 | } |
| 3802 | freq = slm_freq_table[i]; |
| 3803 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3804 | if (!quiet) |
Len Brown | 8f6196c | 2017-01-07 22:40:23 -0500 | [diff] [blame] | 3805 | fprintf(outf, "SLM BCLK: %.1f Mhz\n", freq); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3806 | |
| 3807 | return freq; |
| 3808 | } |
| 3809 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3810 | double discover_bclk(unsigned int family, unsigned int model) |
| 3811 | { |
Chrzaniuk, Hubert | 121b48b | 2016-02-10 16:35:17 +0100 | [diff] [blame] | 3812 | if (has_snb_msrs(family, model) || is_knl(family, model)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3813 | return 100.00; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3814 | else if (is_slm(family, model)) |
| 3815 | return slm_bclk(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3816 | else |
| 3817 | return 133.33; |
| 3818 | } |
| 3819 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3820 | /* |
| 3821 | * MSR_IA32_TEMPERATURE_TARGET indicates the temperature where |
| 3822 | * the Thermal Control Circuit (TCC) activates. |
| 3823 | * This is usually equal to tjMax. |
| 3824 | * |
| 3825 | * Older processors do not have this MSR, so there we guess, |
| 3826 | * but also allow cmdline over-ride with -T. |
| 3827 | * |
| 3828 | * Several MSR temperature values are in units of degrees-C |
| 3829 | * below this value, including the Digital Thermal Sensor (DTS), |
| 3830 | * Package Thermal Management Sensor (PTM), and thermal event thresholds. |
| 3831 | */ |
| 3832 | int set_temperature_target(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3833 | { |
| 3834 | unsigned long long msr; |
| 3835 | unsigned int target_c_local; |
| 3836 | int cpu; |
| 3837 | |
| 3838 | /* tcc_activation_temp is used only for dts or ptm */ |
| 3839 | if (!(do_dts || do_ptm)) |
| 3840 | return 0; |
| 3841 | |
| 3842 | /* this is a per-package concept */ |
| 3843 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3844 | return 0; |
| 3845 | |
| 3846 | cpu = t->cpu_id; |
| 3847 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3848 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3849 | return -1; |
| 3850 | } |
| 3851 | |
| 3852 | if (tcc_activation_temp_override != 0) { |
| 3853 | tcc_activation_temp = tcc_activation_temp_override; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3854 | fprintf(outf, "cpu%d: Using cmdline TCC Target (%d C)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3855 | cpu, tcc_activation_temp); |
| 3856 | return 0; |
| 3857 | } |
| 3858 | |
| 3859 | /* Temperature Target MSR is Nehalem and newer only */ |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3860 | if (!do_nhm_platform_info) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3861 | goto guess; |
| 3862 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3863 | if (get_msr(base_cpu, MSR_IA32_TEMPERATURE_TARGET, &msr)) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3864 | goto guess; |
| 3865 | |
Jean Delvare | 3482124 | 2014-05-01 11:40:19 +0200 | [diff] [blame] | 3866 | target_c_local = (msr >> 16) & 0xFF; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3867 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3868 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3869 | fprintf(outf, "cpu%d: MSR_IA32_TEMPERATURE_TARGET: 0x%08llx (%d C)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3870 | cpu, msr, target_c_local); |
| 3871 | |
Jean Delvare | 3482124 | 2014-05-01 11:40:19 +0200 | [diff] [blame] | 3872 | if (!target_c_local) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3873 | goto guess; |
| 3874 | |
| 3875 | tcc_activation_temp = target_c_local; |
| 3876 | |
| 3877 | return 0; |
| 3878 | |
| 3879 | guess: |
| 3880 | tcc_activation_temp = TJMAX_DEFAULT; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3881 | fprintf(outf, "cpu%d: Guessing tjMax %d C, Please use -T to specify\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3882 | cpu, tcc_activation_temp); |
| 3883 | |
| 3884 | return 0; |
| 3885 | } |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 3886 | |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 3887 | void decode_feature_control_msr(void) |
| 3888 | { |
| 3889 | unsigned long long msr; |
| 3890 | |
| 3891 | if (!get_msr(base_cpu, MSR_IA32_FEATURE_CONTROL, &msr)) |
| 3892 | fprintf(outf, "cpu%d: MSR_IA32_FEATURE_CONTROL: 0x%08llx (%sLocked %s)\n", |
| 3893 | base_cpu, msr, |
| 3894 | msr & FEATURE_CONTROL_LOCKED ? "" : "UN-", |
| 3895 | msr & (1 << 18) ? "SGX" : ""); |
| 3896 | } |
| 3897 | |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 3898 | void decode_misc_enable_msr(void) |
| 3899 | { |
| 3900 | unsigned long long msr; |
| 3901 | |
| 3902 | if (!get_msr(base_cpu, MSR_IA32_MISC_ENABLE, &msr)) |
Len Brown | e651262 | 2017-01-11 23:17:24 -0500 | [diff] [blame] | 3903 | fprintf(outf, "cpu%d: MSR_IA32_MISC_ENABLE: 0x%08llx (%sTCC %sEIST %sMWAIT %sPREFETCH %sTURBO)\n", |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 3904 | base_cpu, msr, |
Len Brown | e651262 | 2017-01-11 23:17:24 -0500 | [diff] [blame] | 3905 | msr & MSR_IA32_MISC_ENABLE_TM1 ? "" : "No-", |
| 3906 | msr & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP ? "" : "No-", |
| 3907 | msr & MSR_IA32_MISC_ENABLE_MWAIT ? "No-" : "", |
| 3908 | msr & MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE ? "No-" : "", |
| 3909 | msr & MSR_IA32_MISC_ENABLE_TURBO_DISABLE ? "No-" : ""); |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 3910 | } |
| 3911 | |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 3912 | void decode_misc_feature_control(void) |
| 3913 | { |
| 3914 | unsigned long long msr; |
| 3915 | |
| 3916 | if (!has_misc_feature_control) |
| 3917 | return; |
| 3918 | |
| 3919 | if (!get_msr(base_cpu, MSR_MISC_FEATURE_CONTROL, &msr)) |
| 3920 | fprintf(outf, "cpu%d: MSR_MISC_FEATURE_CONTROL: 0x%08llx (%sL2-Prefetch %sL2-Prefetch-pair %sL1-Prefetch %sL1-IP-Prefetch)\n", |
| 3921 | base_cpu, msr, |
| 3922 | msr & (0 << 0) ? "No-" : "", |
| 3923 | msr & (1 << 0) ? "No-" : "", |
| 3924 | msr & (2 << 0) ? "No-" : "", |
| 3925 | msr & (3 << 0) ? "No-" : ""); |
| 3926 | } |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 3927 | /* |
| 3928 | * Decode MSR_MISC_PWR_MGMT |
| 3929 | * |
| 3930 | * Decode the bits according to the Nehalem documentation |
| 3931 | * bit[0] seems to continue to have same meaning going forward |
| 3932 | * bit[1] less so... |
| 3933 | */ |
| 3934 | void decode_misc_pwr_mgmt_msr(void) |
| 3935 | { |
| 3936 | unsigned long long msr; |
| 3937 | |
| 3938 | if (!do_nhm_platform_info) |
| 3939 | return; |
| 3940 | |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 3941 | if (no_MSR_MISC_PWR_MGMT) |
| 3942 | return; |
| 3943 | |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 3944 | if (!get_msr(base_cpu, MSR_MISC_PWR_MGMT, &msr)) |
Srinivas Pandruvada | ddadb8a | 2016-11-11 14:29:48 -0800 | [diff] [blame] | 3945 | fprintf(outf, "cpu%d: MSR_MISC_PWR_MGMT: 0x%08llx (%sable-EIST_Coordination %sable-EPB %sable-OOB)\n", |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 3946 | base_cpu, msr, |
| 3947 | msr & (1 << 0) ? "DIS" : "EN", |
Srinivas Pandruvada | ddadb8a | 2016-11-11 14:29:48 -0800 | [diff] [blame] | 3948 | msr & (1 << 1) ? "EN" : "DIS", |
| 3949 | msr & (1 << 8) ? "EN" : "DIS"); |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 3950 | } |
Len Brown | 71616c8 | 2017-01-07 22:37:48 -0500 | [diff] [blame] | 3951 | /* |
| 3952 | * Decode MSR_CC6_DEMOTION_POLICY_CONFIG, MSR_MC6_DEMOTION_POLICY_CONFIG |
| 3953 | * |
| 3954 | * This MSRs are present on Silvermont processors, |
| 3955 | * Intel Atom processor E3000 series (Baytrail), and friends. |
| 3956 | */ |
| 3957 | void decode_c6_demotion_policy_msr(void) |
| 3958 | { |
| 3959 | unsigned long long msr; |
| 3960 | |
| 3961 | if (!get_msr(base_cpu, MSR_CC6_DEMOTION_POLICY_CONFIG, &msr)) |
| 3962 | fprintf(outf, "cpu%d: MSR_CC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-CC6-Demotion)\n", |
| 3963 | base_cpu, msr, msr & (1 << 0) ? "EN" : "DIS"); |
| 3964 | |
| 3965 | if (!get_msr(base_cpu, MSR_MC6_DEMOTION_POLICY_CONFIG, &msr)) |
| 3966 | fprintf(outf, "cpu%d: MSR_MC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-MC6-Demotion)\n", |
| 3967 | base_cpu, msr, msr & (1 << 0) ? "EN" : "DIS"); |
| 3968 | } |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3969 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3970 | void process_cpuid() |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3971 | { |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 3972 | unsigned int eax, ebx, ecx, edx, max_level, max_extended_level; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3973 | unsigned int fms, family, model, stepping; |
Len Brown | b3a34e9 | 2017-01-21 00:50:08 -0500 | [diff] [blame] | 3974 | unsigned int has_turbo; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3975 | |
| 3976 | eax = ebx = ecx = edx = 0; |
| 3977 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 3978 | __cpuid(0, max_level, ebx, ecx, edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3979 | |
| 3980 | if (ebx == 0x756e6547 && edx == 0x49656e69 && ecx == 0x6c65746e) |
| 3981 | genuine_intel = 1; |
| 3982 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3983 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3984 | fprintf(outf, "CPUID(0): %.4s%.4s%.4s ", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3985 | (char *)&ebx, (char *)&edx, (char *)&ecx); |
| 3986 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 3987 | __cpuid(1, fms, ebx, ecx, edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3988 | family = (fms >> 8) & 0xf; |
| 3989 | model = (fms >> 4) & 0xf; |
| 3990 | stepping = fms & 0xf; |
| 3991 | if (family == 6 || family == 0xf) |
| 3992 | model += ((fms >> 16) & 0xf) << 4; |
| 3993 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3994 | if (!quiet) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3995 | fprintf(outf, "%d CPUID levels; family:model:stepping 0x%x:%x:%x (%d:%d:%d)\n", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3996 | max_level, family, model, stepping, family, model, stepping); |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 3997 | fprintf(outf, "CPUID(1): %s %s %s %s %s %s %s %s %s\n", |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 3998 | ecx & (1 << 0) ? "SSE3" : "-", |
| 3999 | ecx & (1 << 3) ? "MONITOR" : "-", |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 4000 | ecx & (1 << 6) ? "SMX" : "-", |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4001 | ecx & (1 << 7) ? "EIST" : "-", |
| 4002 | ecx & (1 << 8) ? "TM2" : "-", |
| 4003 | edx & (1 << 4) ? "TSC" : "-", |
| 4004 | edx & (1 << 5) ? "MSR" : "-", |
| 4005 | edx & (1 << 22) ? "ACPI-TM" : "-", |
| 4006 | edx & (1 << 29) ? "TM" : "-"); |
| 4007 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4008 | |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4009 | if (!(edx & (1 << 5))) |
| 4010 | errx(1, "CPUID: no MSR"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4011 | |
| 4012 | /* |
| 4013 | * check max extended function levels of CPUID. |
| 4014 | * This is needed to check for invariant TSC. |
| 4015 | * This check is valid for both Intel and AMD. |
| 4016 | */ |
| 4017 | ebx = ecx = edx = 0; |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4018 | __cpuid(0x80000000, max_extended_level, ebx, ecx, edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4019 | |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 4020 | if (max_extended_level >= 0x80000007) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4021 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4022 | /* |
| 4023 | * Non-Stop TSC is advertised by CPUID.EAX=0x80000007: EDX.bit8 |
| 4024 | * this check is valid for both Intel and AMD |
| 4025 | */ |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4026 | __cpuid(0x80000007, eax, ebx, ecx, edx); |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4027 | has_invariant_tsc = edx & (1 << 8); |
| 4028 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4029 | |
| 4030 | /* |
| 4031 | * APERF/MPERF is advertised by CPUID.EAX=0x6: ECX.bit0 |
| 4032 | * this check is valid for both Intel and AMD |
| 4033 | */ |
| 4034 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4035 | __cpuid(0x6, eax, ebx, ecx, edx); |
Thomas Renninger | 8209e05 | 2011-01-21 15:11:19 +0100 | [diff] [blame] | 4036 | has_aperf = ecx & (1 << 0); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4037 | if (has_aperf) { |
| 4038 | BIC_PRESENT(BIC_Avg_MHz); |
| 4039 | BIC_PRESENT(BIC_Busy); |
| 4040 | BIC_PRESENT(BIC_Bzy_MHz); |
| 4041 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4042 | do_dts = eax & (1 << 0); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4043 | if (do_dts) |
| 4044 | BIC_PRESENT(BIC_CoreTmp); |
Len Brown | b3a34e9 | 2017-01-21 00:50:08 -0500 | [diff] [blame] | 4045 | has_turbo = eax & (1 << 1); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4046 | do_ptm = eax & (1 << 6); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4047 | if (do_ptm) |
| 4048 | BIC_PRESENT(BIC_PkgTmp); |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4049 | has_hwp = eax & (1 << 7); |
| 4050 | has_hwp_notify = eax & (1 << 8); |
| 4051 | has_hwp_activity_window = eax & (1 << 9); |
| 4052 | has_hwp_epp = eax & (1 << 10); |
| 4053 | has_hwp_pkg = eax & (1 << 11); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4054 | has_epb = ecx & (1 << 3); |
| 4055 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4056 | if (!quiet) |
Len Brown | b3a34e9 | 2017-01-21 00:50:08 -0500 | [diff] [blame] | 4057 | fprintf(outf, "CPUID(6): %sAPERF, %sTURBO, %sDTS, %sPTM, %sHWP, " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4058 | "%sHWPnotify, %sHWPwindow, %sHWPepp, %sHWPpkg, %sEPB\n", |
| 4059 | has_aperf ? "" : "No-", |
Len Brown | b3a34e9 | 2017-01-21 00:50:08 -0500 | [diff] [blame] | 4060 | has_turbo ? "" : "No-", |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4061 | do_dts ? "" : "No-", |
| 4062 | do_ptm ? "" : "No-", |
| 4063 | has_hwp ? "" : "No-", |
| 4064 | has_hwp_notify ? "" : "No-", |
| 4065 | has_hwp_activity_window ? "" : "No-", |
| 4066 | has_hwp_epp ? "" : "No-", |
| 4067 | has_hwp_pkg ? "" : "No-", |
| 4068 | has_epb ? "" : "No-"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4069 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4070 | if (!quiet) |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4071 | decode_misc_enable_msr(); |
| 4072 | |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 4073 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4074 | if (max_level >= 0x7 && !quiet) { |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 4075 | int has_sgx; |
| 4076 | |
| 4077 | ecx = 0; |
| 4078 | |
| 4079 | __cpuid_count(0x7, 0, eax, ebx, ecx, edx); |
| 4080 | |
| 4081 | has_sgx = ebx & (1 << 2); |
| 4082 | fprintf(outf, "CPUID(7): %sSGX\n", has_sgx ? "" : "No-"); |
| 4083 | |
| 4084 | if (has_sgx) |
| 4085 | decode_feature_control_msr(); |
| 4086 | } |
| 4087 | |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 4088 | if (max_level >= 0x15) { |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4089 | unsigned int eax_crystal; |
| 4090 | unsigned int ebx_tsc; |
| 4091 | |
| 4092 | /* |
| 4093 | * CPUID 15H TSC/Crystal ratio, possibly Crystal Hz |
| 4094 | */ |
| 4095 | eax_crystal = ebx_tsc = crystal_hz = edx = 0; |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4096 | __cpuid(0x15, eax_crystal, ebx_tsc, crystal_hz, edx); |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4097 | |
| 4098 | if (ebx_tsc != 0) { |
| 4099 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4100 | if (!quiet && (ebx != 0)) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4101 | fprintf(outf, "CPUID(0x15): eax_crystal: %d ebx_tsc: %d ecx_crystal_hz: %d\n", |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4102 | eax_crystal, ebx_tsc, crystal_hz); |
| 4103 | |
| 4104 | if (crystal_hz == 0) |
| 4105 | switch(model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4106 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 4107 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 4108 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 4109 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Len Brown | e8efbc8 | 2016-04-06 17:15:57 -0400 | [diff] [blame] | 4110 | crystal_hz = 24000000; /* 24.0 MHz */ |
| 4111 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4112 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
Len Brown | 7268d40 | 2016-12-01 23:10:39 -0500 | [diff] [blame] | 4113 | case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ |
Len Brown | ec53e59 | 2016-04-06 17:15:58 -0400 | [diff] [blame] | 4114 | crystal_hz = 25000000; /* 25.0 MHz */ |
| 4115 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4116 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | ac01ac1 | 2017-01-27 01:45:35 -0500 | [diff] [blame] | 4117 | case INTEL_FAM6_ATOM_GEMINI_LAKE: |
Len Brown | e8efbc8 | 2016-04-06 17:15:57 -0400 | [diff] [blame] | 4118 | crystal_hz = 19200000; /* 19.2 MHz */ |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4119 | break; |
| 4120 | default: |
| 4121 | crystal_hz = 0; |
| 4122 | } |
| 4123 | |
| 4124 | if (crystal_hz) { |
| 4125 | tsc_hz = (unsigned long long) crystal_hz * ebx_tsc / eax_crystal; |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4126 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4127 | fprintf(outf, "TSC: %lld MHz (%d Hz * %d / %d / 1000000)\n", |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4128 | tsc_hz / 1000000, crystal_hz, ebx_tsc, eax_crystal); |
| 4129 | } |
| 4130 | } |
| 4131 | } |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 4132 | if (max_level >= 0x16) { |
| 4133 | unsigned int base_mhz, max_mhz, bus_mhz, edx; |
| 4134 | |
| 4135 | /* |
| 4136 | * CPUID 16H Base MHz, Max MHz, Bus MHz |
| 4137 | */ |
| 4138 | base_mhz = max_mhz = bus_mhz = edx = 0; |
| 4139 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4140 | __cpuid(0x16, base_mhz, max_mhz, bus_mhz, edx); |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4141 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4142 | fprintf(outf, "CPUID(0x16): base_mhz: %d max_mhz: %d bus_mhz: %d\n", |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 4143 | base_mhz, max_mhz, bus_mhz); |
| 4144 | } |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4145 | |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 4146 | if (has_aperf) |
| 4147 | aperf_mperf_multiplier = get_aperf_mperf_multiplier(family, model); |
| 4148 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4149 | BIC_PRESENT(BIC_IRQ); |
| 4150 | BIC_PRESENT(BIC_TSC_MHz); |
| 4151 | |
| 4152 | if (probe_nhm_msrs(family, model)) { |
| 4153 | do_nhm_platform_info = 1; |
| 4154 | BIC_PRESENT(BIC_CPU_c1); |
| 4155 | BIC_PRESENT(BIC_CPU_c3); |
| 4156 | BIC_PRESENT(BIC_CPU_c6); |
| 4157 | BIC_PRESENT(BIC_SMI); |
| 4158 | } |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4159 | do_snb_cstates = has_snb_msrs(family, model); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4160 | |
| 4161 | if (do_snb_cstates) |
| 4162 | BIC_PRESENT(BIC_CPU_c7); |
| 4163 | |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 4164 | do_irtl_snb = has_snb_msrs(family, model); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4165 | if (do_snb_cstates && (pkg_cstate_limit >= PCL__2)) |
| 4166 | BIC_PRESENT(BIC_Pkgpc2); |
| 4167 | if (pkg_cstate_limit >= PCL__3) |
| 4168 | BIC_PRESENT(BIC_Pkgpc3); |
| 4169 | if (pkg_cstate_limit >= PCL__6) |
| 4170 | BIC_PRESENT(BIC_Pkgpc6); |
| 4171 | if (do_snb_cstates && (pkg_cstate_limit >= PCL__7)) |
| 4172 | BIC_PRESENT(BIC_Pkgpc7); |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 4173 | if (has_slv_msrs(family, model)) { |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4174 | BIC_NOT_PRESENT(BIC_Pkgpc2); |
| 4175 | BIC_NOT_PRESENT(BIC_Pkgpc3); |
| 4176 | BIC_PRESENT(BIC_Pkgpc6); |
| 4177 | BIC_NOT_PRESENT(BIC_Pkgpc7); |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 4178 | BIC_PRESENT(BIC_Mod_c6); |
| 4179 | use_c1_residency_msr = 1; |
| 4180 | } |
Len Brown | 7170a37 | 2017-01-27 02:13:27 -0500 | [diff] [blame] | 4181 | if (is_dnv(family, model)) { |
| 4182 | BIC_PRESENT(BIC_CPU_c1); |
| 4183 | BIC_NOT_PRESENT(BIC_CPU_c3); |
| 4184 | BIC_NOT_PRESENT(BIC_Pkgpc3); |
| 4185 | BIC_NOT_PRESENT(BIC_CPU_c7); |
| 4186 | BIC_NOT_PRESENT(BIC_Pkgpc7); |
| 4187 | use_c1_residency_msr = 1; |
| 4188 | } |
Len Brown | 34c76197 | 2017-01-27 02:36:41 -0500 | [diff] [blame] | 4189 | if (is_skx(family, model)) { |
| 4190 | BIC_NOT_PRESENT(BIC_CPU_c3); |
| 4191 | BIC_NOT_PRESENT(BIC_Pkgpc3); |
| 4192 | BIC_NOT_PRESENT(BIC_CPU_c7); |
| 4193 | BIC_NOT_PRESENT(BIC_Pkgpc7); |
| 4194 | } |
Len Brown | ade0eba | 2017-02-10 01:56:47 -0500 | [diff] [blame] | 4195 | if (is_bdx(family, model)) { |
| 4196 | BIC_NOT_PRESENT(BIC_CPU_c7); |
| 4197 | BIC_NOT_PRESENT(BIC_Pkgpc7); |
| 4198 | } |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4199 | if (has_hsw_msrs(family, model)) { |
| 4200 | BIC_PRESENT(BIC_Pkgpc8); |
| 4201 | BIC_PRESENT(BIC_Pkgpc9); |
| 4202 | BIC_PRESENT(BIC_Pkgpc10); |
| 4203 | } |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 4204 | do_irtl_hsw = has_hsw_msrs(family, model); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 4205 | do_skl_residency = has_skl_msrs(family, model); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4206 | do_slm_cstates = is_slm(family, model); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 4207 | do_knl_cstates = is_knl(family, model); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4208 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4209 | if (!quiet) |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 4210 | decode_misc_pwr_mgmt_msr(); |
| 4211 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4212 | if (!quiet && has_slv_msrs(family, model)) |
Len Brown | 71616c8 | 2017-01-07 22:37:48 -0500 | [diff] [blame] | 4213 | decode_c6_demotion_policy_msr(); |
| 4214 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4215 | rapl_probe(family, model); |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 4216 | perf_limit_reasons_probe(family, model); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4217 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4218 | if (!quiet) |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 4219 | dump_cstate_pstate_config_info(family, model); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 4220 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4221 | if (!quiet) |
| 4222 | dump_sysfs_cstate_config(); |
Len Brown | 7293fcc | 2017-02-22 00:11:12 -0500 | [diff] [blame] | 4223 | if (!quiet) |
| 4224 | dump_sysfs_pstate_config(); |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4225 | |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 4226 | if (has_skl_msrs(family, model)) |
| 4227 | calculate_tsc_tweak(); |
| 4228 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4229 | if (!access("/sys/class/drm/card0/power/rc6_residency_ms", R_OK)) |
| 4230 | BIC_PRESENT(BIC_GFX_rc6); |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 4231 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4232 | if (!access("/sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz", R_OK)) |
| 4233 | BIC_PRESENT(BIC_GFXMHz); |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 4234 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4235 | if (!quiet) |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 4236 | decode_misc_feature_control(); |
| 4237 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4238 | return; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4239 | } |
| 4240 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4241 | |
| 4242 | /* |
| 4243 | * in /dev/cpu/ return success for names that are numbers |
| 4244 | * ie. filter out ".", "..", "microcode". |
| 4245 | */ |
| 4246 | int dir_filter(const struct dirent *dirp) |
| 4247 | { |
| 4248 | if (isdigit(dirp->d_name[0])) |
| 4249 | return 1; |
| 4250 | else |
| 4251 | return 0; |
| 4252 | } |
| 4253 | |
| 4254 | int open_dev_cpu_msr(int dummy1) |
| 4255 | { |
| 4256 | return 0; |
| 4257 | } |
| 4258 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4259 | void topology_probe() |
| 4260 | { |
| 4261 | int i; |
| 4262 | int max_core_id = 0; |
| 4263 | int max_package_id = 0; |
| 4264 | int max_siblings = 0; |
| 4265 | struct cpu_topology { |
| 4266 | int core_id; |
| 4267 | int physical_package_id; |
| 4268 | } *cpus; |
| 4269 | |
| 4270 | /* Initialize num_cpus, max_cpu_num */ |
| 4271 | topo.num_cpus = 0; |
| 4272 | topo.max_cpu_num = 0; |
| 4273 | for_all_proc_cpus(count_cpus); |
| 4274 | if (!summary_only && topo.num_cpus > 1) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4275 | BIC_PRESENT(BIC_CPU); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4276 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4277 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4278 | fprintf(outf, "num_cpus %d max_cpu_num %d\n", topo.num_cpus, topo.max_cpu_num); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4279 | |
| 4280 | cpus = calloc(1, (topo.max_cpu_num + 1) * sizeof(struct cpu_topology)); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4281 | if (cpus == NULL) |
| 4282 | err(1, "calloc cpus"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4283 | |
| 4284 | /* |
| 4285 | * Allocate and initialize cpu_present_set |
| 4286 | */ |
| 4287 | cpu_present_set = CPU_ALLOC((topo.max_cpu_num + 1)); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4288 | if (cpu_present_set == NULL) |
| 4289 | err(3, "CPU_ALLOC"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4290 | cpu_present_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); |
| 4291 | CPU_ZERO_S(cpu_present_setsize, cpu_present_set); |
| 4292 | for_all_proc_cpus(mark_cpu_present); |
| 4293 | |
| 4294 | /* |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 4295 | * Validate that all cpus in cpu_subset are also in cpu_present_set |
| 4296 | */ |
| 4297 | for (i = 0; i < CPU_SUBSET_MAXCPUS; ++i) { |
| 4298 | if (CPU_ISSET_S(i, cpu_subset_size, cpu_subset)) |
| 4299 | if (!CPU_ISSET_S(i, cpu_present_setsize, cpu_present_set)) |
| 4300 | err(1, "cpu%d not present", i); |
| 4301 | } |
| 4302 | |
| 4303 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4304 | * Allocate and initialize cpu_affinity_set |
| 4305 | */ |
| 4306 | cpu_affinity_set = CPU_ALLOC((topo.max_cpu_num + 1)); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4307 | if (cpu_affinity_set == NULL) |
| 4308 | err(3, "CPU_ALLOC"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4309 | cpu_affinity_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); |
| 4310 | CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); |
| 4311 | |
| 4312 | |
| 4313 | /* |
| 4314 | * For online cpus |
| 4315 | * find max_core_id, max_package_id |
| 4316 | */ |
| 4317 | for (i = 0; i <= topo.max_cpu_num; ++i) { |
| 4318 | int siblings; |
| 4319 | |
| 4320 | if (cpu_is_not_present(i)) { |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4321 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4322 | fprintf(outf, "cpu%d NOT PRESENT\n", i); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4323 | continue; |
| 4324 | } |
| 4325 | cpus[i].core_id = get_core_id(i); |
| 4326 | if (cpus[i].core_id > max_core_id) |
| 4327 | max_core_id = cpus[i].core_id; |
| 4328 | |
| 4329 | cpus[i].physical_package_id = get_physical_package_id(i); |
| 4330 | if (cpus[i].physical_package_id > max_package_id) |
| 4331 | max_package_id = cpus[i].physical_package_id; |
| 4332 | |
| 4333 | siblings = get_num_ht_siblings(i); |
| 4334 | if (siblings > max_siblings) |
| 4335 | max_siblings = siblings; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4336 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4337 | fprintf(outf, "cpu %d pkg %d core %d\n", |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4338 | i, cpus[i].physical_package_id, cpus[i].core_id); |
| 4339 | } |
| 4340 | topo.num_cores_per_pkg = max_core_id + 1; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4341 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4342 | fprintf(outf, "max_core_id %d, sizing for %d cores per package\n", |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4343 | max_core_id, topo.num_cores_per_pkg); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4344 | if (!summary_only && topo.num_cores_per_pkg > 1) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4345 | BIC_PRESENT(BIC_Core); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4346 | |
| 4347 | topo.num_packages = max_package_id + 1; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4348 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4349 | fprintf(outf, "max_package_id %d, sizing for %d packages\n", |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4350 | max_package_id, topo.num_packages); |
Len Brown | 7da6e3e | 2017-02-21 23:43:41 -0500 | [diff] [blame] | 4351 | if (!summary_only && topo.num_packages > 1) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4352 | BIC_PRESENT(BIC_Package); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4353 | |
| 4354 | topo.num_threads_per_core = max_siblings; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4355 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4356 | fprintf(outf, "max_siblings %d\n", max_siblings); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4357 | |
| 4358 | free(cpus); |
| 4359 | } |
| 4360 | |
| 4361 | void |
| 4362 | allocate_counters(struct thread_data **t, struct core_data **c, struct pkg_data **p) |
| 4363 | { |
| 4364 | int i; |
| 4365 | |
| 4366 | *t = calloc(topo.num_threads_per_core * topo.num_cores_per_pkg * |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4367 | topo.num_packages, sizeof(struct thread_data)); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4368 | if (*t == NULL) |
| 4369 | goto error; |
| 4370 | |
| 4371 | for (i = 0; i < topo.num_threads_per_core * |
| 4372 | topo.num_cores_per_pkg * topo.num_packages; i++) |
| 4373 | (*t)[i].cpu_id = -1; |
| 4374 | |
| 4375 | *c = calloc(topo.num_cores_per_pkg * topo.num_packages, |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4376 | sizeof(struct core_data)); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4377 | if (*c == NULL) |
| 4378 | goto error; |
| 4379 | |
| 4380 | for (i = 0; i < topo.num_cores_per_pkg * topo.num_packages; i++) |
| 4381 | (*c)[i].core_id = -1; |
| 4382 | |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4383 | *p = calloc(topo.num_packages, sizeof(struct pkg_data)); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4384 | if (*p == NULL) |
| 4385 | goto error; |
| 4386 | |
| 4387 | for (i = 0; i < topo.num_packages; i++) |
| 4388 | (*p)[i].package_id = i; |
| 4389 | |
| 4390 | return; |
| 4391 | error: |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4392 | err(1, "calloc counters"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4393 | } |
| 4394 | /* |
| 4395 | * init_counter() |
| 4396 | * |
| 4397 | * set cpu_id, core_num, pkg_num |
| 4398 | * set FIRST_THREAD_IN_CORE and FIRST_CORE_IN_PACKAGE |
| 4399 | * |
| 4400 | * increment topo.num_cores when 1st core in pkg seen |
| 4401 | */ |
| 4402 | void init_counter(struct thread_data *thread_base, struct core_data *core_base, |
| 4403 | struct pkg_data *pkg_base, int thread_num, int core_num, |
| 4404 | int pkg_num, int cpu_id) |
| 4405 | { |
| 4406 | struct thread_data *t; |
| 4407 | struct core_data *c; |
| 4408 | struct pkg_data *p; |
| 4409 | |
| 4410 | t = GET_THREAD(thread_base, thread_num, core_num, pkg_num); |
| 4411 | c = GET_CORE(core_base, core_num, pkg_num); |
| 4412 | p = GET_PKG(pkg_base, pkg_num); |
| 4413 | |
| 4414 | t->cpu_id = cpu_id; |
| 4415 | if (thread_num == 0) { |
| 4416 | t->flags |= CPU_IS_FIRST_THREAD_IN_CORE; |
| 4417 | if (cpu_is_first_core_in_package(cpu_id)) |
| 4418 | t->flags |= CPU_IS_FIRST_CORE_IN_PACKAGE; |
| 4419 | } |
| 4420 | |
| 4421 | c->core_id = core_num; |
| 4422 | p->package_id = pkg_num; |
| 4423 | } |
| 4424 | |
| 4425 | |
| 4426 | int initialize_counters(int cpu_id) |
| 4427 | { |
| 4428 | int my_thread_id, my_core_id, my_package_id; |
| 4429 | |
| 4430 | my_package_id = get_physical_package_id(cpu_id); |
| 4431 | my_core_id = get_core_id(cpu_id); |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 4432 | my_thread_id = get_cpu_position_in_core(cpu_id); |
| 4433 | if (!my_thread_id) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4434 | topo.num_cores++; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4435 | |
| 4436 | init_counter(EVEN_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id); |
| 4437 | init_counter(ODD_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id); |
| 4438 | return 0; |
| 4439 | } |
| 4440 | |
| 4441 | void allocate_output_buffer() |
| 4442 | { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4443 | output_buffer = calloc(1, (1 + topo.num_cpus) * 1024); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4444 | outp = output_buffer; |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4445 | if (outp == NULL) |
| 4446 | err(-1, "calloc output buffer"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4447 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 4448 | void allocate_fd_percpu(void) |
| 4449 | { |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 4450 | fd_percpu = calloc(topo.max_cpu_num + 1, sizeof(int)); |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 4451 | if (fd_percpu == NULL) |
| 4452 | err(-1, "calloc fd_percpu"); |
| 4453 | } |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 4454 | void allocate_irq_buffers(void) |
| 4455 | { |
| 4456 | irq_column_2_cpu = calloc(topo.num_cpus, sizeof(int)); |
| 4457 | if (irq_column_2_cpu == NULL) |
| 4458 | err(-1, "calloc %d", topo.num_cpus); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4459 | |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 4460 | irqs_per_cpu = calloc(topo.max_cpu_num + 1, sizeof(int)); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 4461 | if (irqs_per_cpu == NULL) |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 4462 | err(-1, "calloc %d", topo.max_cpu_num + 1); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 4463 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4464 | void setup_all_buffers(void) |
| 4465 | { |
| 4466 | topology_probe(); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 4467 | allocate_irq_buffers(); |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 4468 | allocate_fd_percpu(); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4469 | allocate_counters(&thread_even, &core_even, &package_even); |
| 4470 | allocate_counters(&thread_odd, &core_odd, &package_odd); |
| 4471 | allocate_output_buffer(); |
| 4472 | for_all_proc_cpus(initialize_counters); |
| 4473 | } |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4474 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 4475 | void set_base_cpu(void) |
| 4476 | { |
| 4477 | base_cpu = sched_getcpu(); |
| 4478 | if (base_cpu < 0) |
| 4479 | err(-ENODEV, "No valid cpus found"); |
| 4480 | |
| 4481 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4482 | fprintf(outf, "base_cpu = %d\n", base_cpu); |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 4483 | } |
| 4484 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4485 | void turbostat_init() |
| 4486 | { |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 4487 | setup_all_buffers(); |
| 4488 | set_base_cpu(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4489 | check_dev_msr(); |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 4490 | check_permissions(); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 4491 | process_cpuid(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4492 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4493 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4494 | if (!quiet) |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4495 | for_all_cpus(print_hwp, ODD_COUNTERS); |
| 4496 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4497 | if (!quiet) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4498 | for_all_cpus(print_epb, ODD_COUNTERS); |
| 4499 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4500 | if (!quiet) |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 4501 | for_all_cpus(print_perf_limit, ODD_COUNTERS); |
| 4502 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4503 | if (!quiet) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4504 | for_all_cpus(print_rapl, ODD_COUNTERS); |
| 4505 | |
| 4506 | for_all_cpus(set_temperature_target, ODD_COUNTERS); |
| 4507 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4508 | if (!quiet) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4509 | for_all_cpus(print_thermal, ODD_COUNTERS); |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 4510 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4511 | if (!quiet && do_irtl_snb) |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 4512 | print_irtl(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4513 | } |
| 4514 | |
| 4515 | int fork_it(char **argv) |
| 4516 | { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4517 | pid_t child_pid; |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 4518 | int status; |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 4519 | |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 4520 | snapshot_proc_sysfs_files(); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 4521 | status = for_all_cpus(get_counters, EVEN_COUNTERS); |
| 4522 | if (status) |
| 4523 | exit(status); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4524 | /* clear affinity side-effect of get_counters() */ |
| 4525 | sched_setaffinity(0, cpu_present_setsize, cpu_present_set); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4526 | gettimeofday(&tv_even, (struct timezone *)NULL); |
| 4527 | |
| 4528 | child_pid = fork(); |
| 4529 | if (!child_pid) { |
| 4530 | /* child */ |
| 4531 | execvp(argv[0], argv); |
Len Brown | 0815a3d | 2017-02-23 17:00:51 -0500 | [diff] [blame] | 4532 | err(errno, "exec %s", argv[0]); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4533 | } else { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4534 | |
| 4535 | /* parent */ |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4536 | if (child_pid == -1) |
| 4537 | err(1, "fork"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4538 | |
| 4539 | signal(SIGINT, SIG_IGN); |
| 4540 | signal(SIGQUIT, SIG_IGN); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4541 | if (waitpid(child_pid, &status, 0) == -1) |
| 4542 | err(status, "waitpid"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4543 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4544 | /* |
| 4545 | * n.b. fork_it() does not check for errors from for_all_cpus() |
| 4546 | * because re-starting is problematic when forking |
| 4547 | */ |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 4548 | snapshot_proc_sysfs_files(); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4549 | for_all_cpus(get_counters, ODD_COUNTERS); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4550 | gettimeofday(&tv_odd, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4551 | timersub(&tv_odd, &tv_even, &tv_delta); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 4552 | if (for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS)) |
| 4553 | fprintf(outf, "%s: Counter reset detected\n", progname); |
| 4554 | else { |
| 4555 | compute_average(EVEN_COUNTERS); |
| 4556 | format_all_counters(EVEN_COUNTERS); |
| 4557 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4558 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4559 | fprintf(outf, "%.6f sec\n", tv_delta.tv_sec + tv_delta.tv_usec/1000000.0); |
| 4560 | |
| 4561 | flush_output_stderr(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4562 | |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 4563 | return status; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4564 | } |
| 4565 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4566 | int get_and_dump_counters(void) |
| 4567 | { |
| 4568 | int status; |
| 4569 | |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 4570 | snapshot_proc_sysfs_files(); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4571 | status = for_all_cpus(get_counters, ODD_COUNTERS); |
| 4572 | if (status) |
| 4573 | return status; |
| 4574 | |
| 4575 | status = for_all_cpus(dump_counters, ODD_COUNTERS); |
| 4576 | if (status) |
| 4577 | return status; |
| 4578 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4579 | flush_output_stdout(); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4580 | |
| 4581 | return status; |
| 4582 | } |
| 4583 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4584 | void print_version() { |
Len Brown | e3942ed | 2017-01-21 02:33:23 -0500 | [diff] [blame] | 4585 | fprintf(outf, "turbostat version 17.02.24" |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4586 | " - Len Brown <lenb@kernel.org>\n"); |
| 4587 | } |
| 4588 | |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 4589 | int add_counter(unsigned int msr_num, char *path, char *name, |
| 4590 | unsigned int width, enum counter_scope scope, |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4591 | enum counter_type type, enum counter_format format, int flags) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4592 | { |
| 4593 | struct msr_counter *msrp; |
| 4594 | |
| 4595 | msrp = calloc(1, sizeof(struct msr_counter)); |
| 4596 | if (msrp == NULL) { |
| 4597 | perror("calloc"); |
| 4598 | exit(1); |
| 4599 | } |
| 4600 | |
| 4601 | msrp->msr_num = msr_num; |
| 4602 | strncpy(msrp->name, name, NAME_BYTES); |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 4603 | if (path) |
| 4604 | strncpy(msrp->path, path, PATH_BYTES); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4605 | msrp->width = width; |
| 4606 | msrp->type = type; |
| 4607 | msrp->format = format; |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4608 | msrp->flags = flags; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4609 | |
| 4610 | switch (scope) { |
| 4611 | |
| 4612 | case SCOPE_CPU: |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4613 | msrp->next = sys.tp; |
| 4614 | sys.tp = msrp; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4615 | sys.added_thread_counters++; |
| 4616 | if (sys.added_thread_counters > MAX_ADDED_COUNTERS) { |
| 4617 | fprintf(stderr, "exceeded max %d added thread counters\n", |
| 4618 | MAX_ADDED_COUNTERS); |
| 4619 | exit(-1); |
| 4620 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4621 | break; |
| 4622 | |
| 4623 | case SCOPE_CORE: |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4624 | msrp->next = sys.cp; |
| 4625 | sys.cp = msrp; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4626 | sys.added_core_counters++; |
| 4627 | if (sys.added_core_counters > MAX_ADDED_COUNTERS) { |
| 4628 | fprintf(stderr, "exceeded max %d added core counters\n", |
| 4629 | MAX_ADDED_COUNTERS); |
| 4630 | exit(-1); |
| 4631 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4632 | break; |
| 4633 | |
| 4634 | case SCOPE_PACKAGE: |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4635 | msrp->next = sys.pp; |
| 4636 | sys.pp = msrp; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4637 | sys.added_package_counters++; |
| 4638 | if (sys.added_package_counters > MAX_ADDED_COUNTERS) { |
| 4639 | fprintf(stderr, "exceeded max %d added package counters\n", |
| 4640 | MAX_ADDED_COUNTERS); |
| 4641 | exit(-1); |
| 4642 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4643 | break; |
| 4644 | } |
| 4645 | |
| 4646 | return 0; |
| 4647 | } |
| 4648 | |
| 4649 | void parse_add_command(char *add_command) |
| 4650 | { |
| 4651 | int msr_num = 0; |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 4652 | char *path = NULL; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4653 | char name_buffer[NAME_BYTES] = ""; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4654 | int width = 64; |
| 4655 | int fail = 0; |
| 4656 | enum counter_scope scope = SCOPE_CPU; |
| 4657 | enum counter_type type = COUNTER_CYCLES; |
| 4658 | enum counter_format format = FORMAT_DELTA; |
| 4659 | |
| 4660 | while (add_command) { |
| 4661 | |
| 4662 | if (sscanf(add_command, "msr0x%x", &msr_num) == 1) |
| 4663 | goto next; |
| 4664 | |
| 4665 | if (sscanf(add_command, "msr%d", &msr_num) == 1) |
| 4666 | goto next; |
| 4667 | |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 4668 | if (*add_command == '/') { |
| 4669 | path = add_command; |
| 4670 | goto next; |
| 4671 | } |
| 4672 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4673 | if (sscanf(add_command, "u%d", &width) == 1) { |
| 4674 | if ((width == 32) || (width == 64)) |
| 4675 | goto next; |
| 4676 | width = 64; |
| 4677 | } |
| 4678 | if (!strncmp(add_command, "cpu", strlen("cpu"))) { |
| 4679 | scope = SCOPE_CPU; |
| 4680 | goto next; |
| 4681 | } |
| 4682 | if (!strncmp(add_command, "core", strlen("core"))) { |
| 4683 | scope = SCOPE_CORE; |
| 4684 | goto next; |
| 4685 | } |
| 4686 | if (!strncmp(add_command, "package", strlen("package"))) { |
| 4687 | scope = SCOPE_PACKAGE; |
| 4688 | goto next; |
| 4689 | } |
| 4690 | if (!strncmp(add_command, "cycles", strlen("cycles"))) { |
| 4691 | type = COUNTER_CYCLES; |
| 4692 | goto next; |
| 4693 | } |
| 4694 | if (!strncmp(add_command, "seconds", strlen("seconds"))) { |
| 4695 | type = COUNTER_SECONDS; |
| 4696 | goto next; |
| 4697 | } |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4698 | if (!strncmp(add_command, "usec", strlen("usec"))) { |
| 4699 | type = COUNTER_USEC; |
| 4700 | goto next; |
| 4701 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4702 | if (!strncmp(add_command, "raw", strlen("raw"))) { |
| 4703 | format = FORMAT_RAW; |
| 4704 | goto next; |
| 4705 | } |
| 4706 | if (!strncmp(add_command, "delta", strlen("delta"))) { |
| 4707 | format = FORMAT_DELTA; |
| 4708 | goto next; |
| 4709 | } |
| 4710 | if (!strncmp(add_command, "percent", strlen("percent"))) { |
| 4711 | format = FORMAT_PERCENT; |
| 4712 | goto next; |
| 4713 | } |
| 4714 | |
| 4715 | if (sscanf(add_command, "%18s,%*s", name_buffer) == 1) { /* 18 < NAME_BYTES */ |
| 4716 | char *eos; |
| 4717 | |
| 4718 | eos = strchr(name_buffer, ','); |
| 4719 | if (eos) |
| 4720 | *eos = '\0'; |
| 4721 | goto next; |
| 4722 | } |
| 4723 | |
| 4724 | next: |
| 4725 | add_command = strchr(add_command, ','); |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 4726 | if (add_command) { |
| 4727 | *add_command = '\0'; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4728 | add_command++; |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 4729 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4730 | |
| 4731 | } |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 4732 | if ((msr_num == 0) && (path == NULL)) { |
| 4733 | fprintf(stderr, "--add: (msrDDD | msr0xXXX | /path_to_counter ) required\n"); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4734 | fail++; |
| 4735 | } |
| 4736 | |
| 4737 | /* generate default column header */ |
| 4738 | if (*name_buffer == '\0') { |
Len Brown | 5f3aea5 | 2017-02-23 18:10:27 -0500 | [diff] [blame] | 4739 | if (width == 32) |
| 4740 | sprintf(name_buffer, "M0x%x%s", msr_num, format == FORMAT_PERCENT ? "%" : ""); |
| 4741 | else |
| 4742 | sprintf(name_buffer, "M0X%x%s", msr_num, format == FORMAT_PERCENT ? "%" : ""); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4743 | } |
| 4744 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4745 | if (add_counter(msr_num, path, name_buffer, width, scope, type, format, 0)) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4746 | fail++; |
| 4747 | |
| 4748 | if (fail) { |
| 4749 | help(); |
| 4750 | exit(1); |
| 4751 | } |
| 4752 | } |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4753 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 4754 | int is_deferred_skip(char *name) |
| 4755 | { |
| 4756 | int i; |
| 4757 | |
| 4758 | for (i = 0; i < deferred_skip_index; ++i) |
| 4759 | if (!strcmp(name, deferred_skip_names[i])) |
| 4760 | return 1; |
| 4761 | return 0; |
| 4762 | } |
| 4763 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4764 | void probe_sysfs(void) |
| 4765 | { |
| 4766 | char path[64]; |
| 4767 | char name_buf[16]; |
| 4768 | FILE *input; |
| 4769 | int state; |
| 4770 | char *sp; |
| 4771 | |
| 4772 | if (!DO_BIC(BIC_sysfs)) |
| 4773 | return; |
| 4774 | |
| 4775 | for (state = 10; state > 0; --state) { |
| 4776 | |
| 4777 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", |
| 4778 | base_cpu, state); |
| 4779 | input = fopen(path, "r"); |
| 4780 | if (input == NULL) |
| 4781 | continue; |
| 4782 | fgets(name_buf, sizeof(name_buf), input); |
| 4783 | |
| 4784 | /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ |
| 4785 | sp = strchr(name_buf, '-'); |
| 4786 | if (!sp) |
| 4787 | sp = strchrnul(name_buf, '\n'); |
| 4788 | *sp = '%'; |
| 4789 | *(sp + 1) = '\0'; |
| 4790 | |
| 4791 | fclose(input); |
| 4792 | |
| 4793 | sprintf(path, "cpuidle/state%d/time", state); |
| 4794 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 4795 | if (is_deferred_skip(name_buf)) |
| 4796 | continue; |
| 4797 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4798 | add_counter(0, path, name_buf, 64, SCOPE_CPU, COUNTER_USEC, |
| 4799 | FORMAT_PERCENT, SYSFS_PERCPU); |
| 4800 | } |
| 4801 | |
| 4802 | for (state = 10; state > 0; --state) { |
| 4803 | |
| 4804 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", |
| 4805 | base_cpu, state); |
| 4806 | input = fopen(path, "r"); |
| 4807 | if (input == NULL) |
| 4808 | continue; |
| 4809 | fgets(name_buf, sizeof(name_buf), input); |
| 4810 | /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ |
| 4811 | sp = strchr(name_buf, '-'); |
| 4812 | if (!sp) |
| 4813 | sp = strchrnul(name_buf, '\n'); |
| 4814 | *sp = '\0'; |
| 4815 | fclose(input); |
| 4816 | |
| 4817 | sprintf(path, "cpuidle/state%d/usage", state); |
| 4818 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 4819 | if (is_deferred_skip(name_buf)) |
| 4820 | continue; |
| 4821 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4822 | add_counter(0, path, name_buf, 64, SCOPE_CPU, COUNTER_ITEMS, |
| 4823 | FORMAT_DELTA, SYSFS_PERCPU); |
| 4824 | } |
| 4825 | |
| 4826 | } |
| 4827 | |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 4828 | |
| 4829 | /* |
| 4830 | * parse cpuset with following syntax |
| 4831 | * 1,2,4..6,8-10 and set bits in cpu_subset |
| 4832 | */ |
| 4833 | void parse_cpu_command(char *optarg) |
| 4834 | { |
| 4835 | unsigned int start, end; |
| 4836 | char *next; |
| 4837 | |
Len Brown | 4e4e1e7 | 2017-02-21 22:33:42 -0500 | [diff] [blame] | 4838 | if (!strcmp(optarg, "core")) { |
| 4839 | if (cpu_subset) |
| 4840 | goto error; |
| 4841 | show_core_only++; |
| 4842 | return; |
| 4843 | } |
| 4844 | if (!strcmp(optarg, "package")) { |
| 4845 | if (cpu_subset) |
| 4846 | goto error; |
| 4847 | show_pkg_only++; |
| 4848 | return; |
| 4849 | } |
| 4850 | if (show_core_only || show_pkg_only) |
| 4851 | goto error; |
| 4852 | |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 4853 | cpu_subset = CPU_ALLOC(CPU_SUBSET_MAXCPUS); |
| 4854 | if (cpu_subset == NULL) |
| 4855 | err(3, "CPU_ALLOC"); |
| 4856 | cpu_subset_size = CPU_ALLOC_SIZE(CPU_SUBSET_MAXCPUS); |
| 4857 | |
| 4858 | CPU_ZERO_S(cpu_subset_size, cpu_subset); |
| 4859 | |
| 4860 | next = optarg; |
| 4861 | |
| 4862 | while (next && *next) { |
| 4863 | |
| 4864 | if (*next == '-') /* no negative cpu numbers */ |
| 4865 | goto error; |
| 4866 | |
| 4867 | start = strtoul(next, &next, 10); |
| 4868 | |
| 4869 | if (start >= CPU_SUBSET_MAXCPUS) |
| 4870 | goto error; |
| 4871 | CPU_SET_S(start, cpu_subset_size, cpu_subset); |
| 4872 | |
| 4873 | if (*next == '\0') |
| 4874 | break; |
| 4875 | |
| 4876 | if (*next == ',') { |
| 4877 | next += 1; |
| 4878 | continue; |
| 4879 | } |
| 4880 | |
| 4881 | if (*next == '-') { |
| 4882 | next += 1; /* start range */ |
| 4883 | } else if (*next == '.') { |
| 4884 | next += 1; |
| 4885 | if (*next == '.') |
| 4886 | next += 1; /* start range */ |
| 4887 | else |
| 4888 | goto error; |
| 4889 | } |
| 4890 | |
| 4891 | end = strtoul(next, &next, 10); |
| 4892 | if (end <= start) |
| 4893 | goto error; |
| 4894 | |
| 4895 | while (++start <= end) { |
| 4896 | if (start >= CPU_SUBSET_MAXCPUS) |
| 4897 | goto error; |
| 4898 | CPU_SET_S(start, cpu_subset_size, cpu_subset); |
| 4899 | } |
| 4900 | |
| 4901 | if (*next == ',') |
| 4902 | next += 1; |
| 4903 | else if (*next != '\0') |
| 4904 | goto error; |
| 4905 | } |
| 4906 | |
| 4907 | return; |
| 4908 | |
| 4909 | error: |
Len Brown | 4e4e1e7 | 2017-02-21 22:33:42 -0500 | [diff] [blame] | 4910 | fprintf(stderr, "\"--cpu %s\" malformed\n", optarg); |
| 4911 | help(); |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 4912 | exit(-1); |
| 4913 | } |
| 4914 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4915 | int shown; |
| 4916 | /* |
| 4917 | * parse_show_hide() - process cmdline to set default counter action |
| 4918 | */ |
| 4919 | void parse_show_hide(char *optarg, enum show_hide_mode new_mode) |
| 4920 | { |
| 4921 | /* |
| 4922 | * --show: show only those specified |
| 4923 | * The 1st invocation will clear and replace the enabled mask |
| 4924 | * subsequent invocations can add to it. |
| 4925 | */ |
| 4926 | if (new_mode == SHOW_LIST) { |
| 4927 | if (shown == 0) |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 4928 | bic_enabled = bic_lookup(optarg, new_mode); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4929 | else |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 4930 | bic_enabled |= bic_lookup(optarg, new_mode); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4931 | shown = 1; |
| 4932 | |
| 4933 | return; |
| 4934 | } |
| 4935 | |
| 4936 | /* |
| 4937 | * --hide: do not show those specified |
| 4938 | * multiple invocations simply clear more bits in enabled mask |
| 4939 | */ |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 4940 | bic_enabled &= ~bic_lookup(optarg, new_mode); |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4941 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4942 | } |
| 4943 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4944 | void cmdline(int argc, char **argv) |
| 4945 | { |
| 4946 | int opt; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4947 | int option_index = 0; |
| 4948 | static struct option long_options[] = { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4949 | {"add", required_argument, 0, 'a'}, |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 4950 | {"cpu", required_argument, 0, 'c'}, |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4951 | {"Dump", no_argument, 0, 'D'}, |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4952 | {"debug", no_argument, 0, 'd'}, /* internal, not documented */ |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4953 | {"interval", required_argument, 0, 'i'}, |
| 4954 | {"help", no_argument, 0, 'h'}, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4955 | {"hide", required_argument, 0, 'H'}, // meh, -h taken by --help |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4956 | {"Joules", no_argument, 0, 'J'}, |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 4957 | {"list", no_argument, 0, 'l'}, |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4958 | {"out", required_argument, 0, 'o'}, |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4959 | {"quiet", no_argument, 0, 'q'}, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4960 | {"show", required_argument, 0, 's'}, |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4961 | {"Summary", no_argument, 0, 'S'}, |
| 4962 | {"TCC", required_argument, 0, 'T'}, |
| 4963 | {"version", no_argument, 0, 'v' }, |
| 4964 | {0, 0, 0, 0 } |
| 4965 | }; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4966 | |
| 4967 | progname = argv[0]; |
| 4968 | |
Len Brown | 4e4e1e7 | 2017-02-21 22:33:42 -0500 | [diff] [blame] | 4969 | while ((opt = getopt_long_only(argc, argv, "+C:c:Ddhi:JM:m:o:qST:v", |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4970 | long_options, &option_index)) != -1) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4971 | switch (opt) { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4972 | case 'a': |
| 4973 | parse_add_command(optarg); |
| 4974 | break; |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 4975 | case 'c': |
| 4976 | parse_cpu_command(optarg); |
| 4977 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4978 | case 'D': |
| 4979 | dump_only++; |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 4980 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4981 | case 'd': |
| 4982 | debug++; |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 4983 | break; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4984 | case 'H': |
| 4985 | parse_show_hide(optarg, HIDE_LIST); |
| 4986 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4987 | case 'h': |
| 4988 | default: |
| 4989 | help(); |
| 4990 | exit(1); |
| 4991 | case 'i': |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 4992 | { |
| 4993 | double interval = strtod(optarg, NULL); |
| 4994 | |
| 4995 | if (interval < 0.001) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4996 | fprintf(outf, "interval %f seconds is too small\n", |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 4997 | interval); |
| 4998 | exit(2); |
| 4999 | } |
| 5000 | |
| 5001 | interval_ts.tv_sec = interval; |
| 5002 | interval_ts.tv_nsec = (interval - interval_ts.tv_sec) * 1000000000; |
| 5003 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 5004 | break; |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 5005 | case 'J': |
| 5006 | rapl_joules++; |
| 5007 | break; |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 5008 | case 'l': |
| 5009 | list_header_only++; |
| 5010 | quiet++; |
| 5011 | break; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5012 | case 'o': |
| 5013 | outf = fopen_or_die(optarg, "w"); |
| 5014 | break; |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5015 | case 'q': |
| 5016 | quiet = 1; |
| 5017 | break; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5018 | case 's': |
| 5019 | parse_show_hide(optarg, SHOW_LIST); |
| 5020 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5021 | case 'S': |
| 5022 | summary_only++; |
| 5023 | break; |
| 5024 | case 'T': |
| 5025 | tcc_activation_temp_override = atoi(optarg); |
| 5026 | break; |
| 5027 | case 'v': |
| 5028 | print_version(); |
| 5029 | exit(0); |
| 5030 | break; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5031 | } |
| 5032 | } |
| 5033 | } |
| 5034 | |
| 5035 | int main(int argc, char **argv) |
| 5036 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5037 | outf = stderr; |
| 5038 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5039 | cmdline(argc, argv); |
| 5040 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5041 | if (!quiet) |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5042 | print_version(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5043 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5044 | probe_sysfs(); |
| 5045 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5046 | turbostat_init(); |
| 5047 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 5048 | /* dump counters and exit */ |
| 5049 | if (dump_only) |
| 5050 | return get_and_dump_counters(); |
| 5051 | |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 5052 | /* list header and exit */ |
| 5053 | if (list_header_only) { |
| 5054 | print_header(","); |
| 5055 | flush_output_stdout(); |
| 5056 | return 0; |
| 5057 | } |
| 5058 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5059 | /* |
| 5060 | * if any params left, it must be a command to fork |
| 5061 | */ |
| 5062 | if (argc - optind) |
| 5063 | return fork_it(argv + optind); |
| 5064 | else |
| 5065 | turbostat_loop(); |
| 5066 | |
| 5067 | return 0; |
| 5068 | } |