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; |
| 52 | unsigned int rapl_joules; |
| 53 | unsigned int summary_only; |
| 54 | unsigned int dump_only; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 55 | unsigned int do_snb_cstates; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 56 | unsigned int do_knl_cstates; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 57 | unsigned int do_pc2; |
| 58 | unsigned int do_pc3; |
| 59 | unsigned int do_pc6; |
| 60 | unsigned int do_pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 61 | unsigned int do_c8_c9_c10; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 62 | unsigned int do_skl_residency; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 63 | unsigned int do_slm_cstates; |
| 64 | unsigned int use_c1_residency_msr; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 65 | unsigned int has_aperf; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 66 | unsigned int has_epb; |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 67 | unsigned int do_irtl_snb; |
| 68 | unsigned int do_irtl_hsw; |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 69 | unsigned int units = 1000000; /* MHz etc */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 70 | unsigned int genuine_intel; |
| 71 | unsigned int has_invariant_tsc; |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 72 | unsigned int do_nhm_platform_info; |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame^] | 73 | unsigned int no_MSR_MISC_PWR_MGMT; |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 74 | unsigned int aperf_mperf_multiplier = 1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 75 | double bclk; |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 76 | double base_hz; |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 77 | unsigned int has_base_hz; |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 78 | double tsc_tweak = 1.0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 79 | unsigned int show_pkg_only; |
| 80 | unsigned int show_core_only; |
| 81 | char *output_buffer, *outp; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 82 | unsigned int do_rapl; |
| 83 | unsigned int do_dts; |
| 84 | unsigned int do_ptm; |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 85 | unsigned long long gfx_cur_rc6_ms; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 86 | unsigned int gfx_cur_mhz; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 87 | unsigned int tcc_activation_temp; |
| 88 | unsigned int tcc_activation_temp_override; |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 89 | double rapl_power_units, rapl_time_units; |
| 90 | double rapl_dram_energy_units, rapl_energy_units; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 91 | double rapl_joule_counter_range; |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 92 | unsigned int do_core_perf_limit_reasons; |
| 93 | unsigned int do_gfx_perf_limit_reasons; |
| 94 | unsigned int do_ring_perf_limit_reasons; |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 95 | unsigned int crystal_hz; |
| 96 | unsigned long long tsc_hz; |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 97 | int base_cpu; |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 98 | double discover_bclk(unsigned int family, unsigned int model); |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 99 | unsigned int has_hwp; /* IA32_PM_ENABLE, IA32_HWP_CAPABILITIES */ |
| 100 | /* IA32_HWP_REQUEST, IA32_HWP_STATUS */ |
| 101 | unsigned int has_hwp_notify; /* IA32_HWP_INTERRUPT */ |
| 102 | unsigned int has_hwp_activity_window; /* IA32_HWP_REQUEST[bits 41:32] */ |
| 103 | unsigned int has_hwp_epp; /* IA32_HWP_REQUEST[bits 31:24] */ |
| 104 | unsigned int has_hwp_pkg; /* IA32_HWP_REQUEST_PKG */ |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 105 | |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 106 | #define RAPL_PKG (1 << 0) |
| 107 | /* 0x610 MSR_PKG_POWER_LIMIT */ |
| 108 | /* 0x611 MSR_PKG_ENERGY_STATUS */ |
| 109 | #define RAPL_PKG_PERF_STATUS (1 << 1) |
| 110 | /* 0x613 MSR_PKG_PERF_STATUS */ |
| 111 | #define RAPL_PKG_POWER_INFO (1 << 2) |
| 112 | /* 0x614 MSR_PKG_POWER_INFO */ |
| 113 | |
| 114 | #define RAPL_DRAM (1 << 3) |
| 115 | /* 0x618 MSR_DRAM_POWER_LIMIT */ |
| 116 | /* 0x619 MSR_DRAM_ENERGY_STATUS */ |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 117 | #define RAPL_DRAM_PERF_STATUS (1 << 4) |
| 118 | /* 0x61b MSR_DRAM_PERF_STATUS */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 119 | #define RAPL_DRAM_POWER_INFO (1 << 5) |
| 120 | /* 0x61c MSR_DRAM_POWER_INFO */ |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 121 | |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 122 | #define RAPL_CORES_POWER_LIMIT (1 << 6) |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 123 | /* 0x638 MSR_PP0_POWER_LIMIT */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 124 | #define RAPL_CORE_POLICY (1 << 7) |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 125 | /* 0x63a MSR_PP0_POLICY */ |
| 126 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 127 | #define RAPL_GFX (1 << 8) |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 128 | /* 0x640 MSR_PP1_POWER_LIMIT */ |
| 129 | /* 0x641 MSR_PP1_ENERGY_STATUS */ |
| 130 | /* 0x642 MSR_PP1_POLICY */ |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 131 | |
| 132 | #define RAPL_CORES_ENERGY_STATUS (1 << 9) |
| 133 | /* 0x639 MSR_PP0_ENERGY_STATUS */ |
| 134 | #define RAPL_CORES (RAPL_CORES_ENERGY_STATUS | RAPL_CORES_POWER_LIMIT) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 135 | #define TJMAX_DEFAULT 100 |
| 136 | |
| 137 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 138 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 139 | /* |
| 140 | * buffer size used by sscanf() for added column names |
| 141 | * Usually truncated to 7 characters, but also handles 18 columns for raw 64-bit counters |
| 142 | */ |
| 143 | #define NAME_BYTES 20 |
| 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 | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 148 | cpu_set_t *cpu_present_set, *cpu_affinity_set; |
| 149 | size_t cpu_present_setsize, cpu_affinity_setsize; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 150 | #define MAX_ADDED_COUNTERS 16 |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 151 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 152 | struct thread_data { |
| 153 | unsigned long long tsc; |
| 154 | unsigned long long aperf; |
| 155 | unsigned long long mperf; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 156 | unsigned long long c1; |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 157 | unsigned int irq_count; |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 158 | unsigned int smi_count; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 159 | unsigned int cpu_id; |
| 160 | unsigned int flags; |
| 161 | #define CPU_IS_FIRST_THREAD_IN_CORE 0x2 |
| 162 | #define CPU_IS_FIRST_CORE_IN_PACKAGE 0x4 |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 163 | unsigned long long counter[MAX_ADDED_COUNTERS]; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 164 | } *thread_even, *thread_odd; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 165 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 166 | struct core_data { |
| 167 | unsigned long long c3; |
| 168 | unsigned long long c6; |
| 169 | unsigned long long c7; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 170 | unsigned int core_temp_c; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 171 | unsigned int core_id; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 172 | unsigned long long counter[MAX_ADDED_COUNTERS]; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 173 | } *core_even, *core_odd; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 174 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 175 | struct pkg_data { |
| 176 | unsigned long long pc2; |
| 177 | unsigned long long pc3; |
| 178 | unsigned long long pc6; |
| 179 | unsigned long long pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 180 | unsigned long long pc8; |
| 181 | unsigned long long pc9; |
| 182 | unsigned long long pc10; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 183 | unsigned long long pkg_wtd_core_c0; |
| 184 | unsigned long long pkg_any_core_c0; |
| 185 | unsigned long long pkg_any_gfxe_c0; |
| 186 | unsigned long long pkg_both_core_gfxe_c0; |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 187 | long long gfx_rc6_ms; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 188 | unsigned int gfx_mhz; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 189 | unsigned int package_id; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 190 | unsigned int energy_pkg; /* MSR_PKG_ENERGY_STATUS */ |
| 191 | unsigned int energy_dram; /* MSR_DRAM_ENERGY_STATUS */ |
| 192 | unsigned int energy_cores; /* MSR_PP0_ENERGY_STATUS */ |
| 193 | unsigned int energy_gfx; /* MSR_PP1_ENERGY_STATUS */ |
| 194 | unsigned int rapl_pkg_perf_status; /* MSR_PKG_PERF_STATUS */ |
| 195 | unsigned int rapl_dram_perf_status; /* MSR_DRAM_PERF_STATUS */ |
| 196 | unsigned int pkg_temp_c; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 197 | unsigned long long counter[MAX_ADDED_COUNTERS]; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 198 | } *package_even, *package_odd; |
| 199 | |
| 200 | #define ODD_COUNTERS thread_odd, core_odd, package_odd |
| 201 | #define EVEN_COUNTERS thread_even, core_even, package_even |
| 202 | |
| 203 | #define GET_THREAD(thread_base, thread_no, core_no, pkg_no) \ |
| 204 | (thread_base + (pkg_no) * topo.num_cores_per_pkg * \ |
| 205 | topo.num_threads_per_core + \ |
| 206 | (core_no) * topo.num_threads_per_core + (thread_no)) |
| 207 | #define GET_CORE(core_base, core_no, pkg_no) \ |
| 208 | (core_base + (pkg_no) * topo.num_cores_per_pkg + (core_no)) |
| 209 | #define GET_PKG(pkg_base, pkg_no) (pkg_base + pkg_no) |
| 210 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 211 | enum counter_scope {SCOPE_CPU, SCOPE_CORE, SCOPE_PACKAGE}; |
| 212 | enum counter_type {COUNTER_CYCLES, COUNTER_SECONDS}; |
| 213 | enum counter_format {FORMAT_RAW, FORMAT_DELTA, FORMAT_PERCENT}; |
| 214 | |
| 215 | struct msr_counter { |
| 216 | unsigned int msr_num; |
| 217 | char name[NAME_BYTES]; |
| 218 | unsigned int width; |
| 219 | enum counter_type type; |
| 220 | enum counter_format format; |
| 221 | struct msr_counter *next; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 222 | unsigned int flags; |
| 223 | #define FLAGS_HIDE (1 << 0) |
| 224 | #define FLAGS_SHOW (1 << 1) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 225 | }; |
| 226 | |
| 227 | struct sys_counters { |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 228 | unsigned int added_thread_counters; |
| 229 | unsigned int added_core_counters; |
| 230 | unsigned int added_package_counters; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 231 | struct msr_counter *tp; |
| 232 | struct msr_counter *cp; |
| 233 | struct msr_counter *pp; |
| 234 | } sys; |
| 235 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 236 | struct system_summary { |
| 237 | struct thread_data threads; |
| 238 | struct core_data cores; |
| 239 | struct pkg_data packages; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 240 | } average; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 241 | |
| 242 | |
| 243 | struct topo_params { |
| 244 | int num_packages; |
| 245 | int num_cpus; |
| 246 | int num_cores; |
| 247 | int max_cpu_num; |
| 248 | int num_cores_per_pkg; |
| 249 | int num_threads_per_core; |
| 250 | } topo; |
| 251 | |
| 252 | struct timeval tv_even, tv_odd, tv_delta; |
| 253 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 254 | int *irq_column_2_cpu; /* /proc/interrupts column numbers */ |
| 255 | int *irqs_per_cpu; /* indexed by cpu_num */ |
| 256 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 257 | void setup_all_buffers(void); |
| 258 | |
| 259 | int cpu_is_not_present(int cpu) |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 260 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 261 | return !CPU_ISSET_S(cpu, cpu_present_setsize, cpu_present_set); |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 262 | } |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 263 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 264 | * run func(thread, core, package) in topology order |
| 265 | * skip non-present cpus |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 266 | */ |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 267 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 268 | int for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg_data *), |
| 269 | 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] | 270 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 271 | int retval, pkg_no, core_no, thread_no; |
| 272 | |
| 273 | for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { |
| 274 | for (core_no = 0; core_no < topo.num_cores_per_pkg; ++core_no) { |
| 275 | for (thread_no = 0; thread_no < |
| 276 | topo.num_threads_per_core; ++thread_no) { |
| 277 | struct thread_data *t; |
| 278 | struct core_data *c; |
| 279 | struct pkg_data *p; |
| 280 | |
| 281 | t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); |
| 282 | |
| 283 | if (cpu_is_not_present(t->cpu_id)) |
| 284 | continue; |
| 285 | |
| 286 | c = GET_CORE(core_base, core_no, pkg_no); |
| 287 | p = GET_PKG(pkg_base, pkg_no); |
| 288 | |
| 289 | retval = func(t, c, p); |
| 290 | if (retval) |
| 291 | return retval; |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | return 0; |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | int cpu_migrate(int cpu) |
| 299 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 300 | CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); |
| 301 | CPU_SET_S(cpu, cpu_affinity_setsize, cpu_affinity_set); |
| 302 | if (sched_setaffinity(0, cpu_affinity_setsize, cpu_affinity_set) == -1) |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 303 | return -1; |
| 304 | else |
| 305 | return 0; |
| 306 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 307 | int get_msr_fd(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 308 | { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 309 | char pathname[32]; |
| 310 | int fd; |
| 311 | |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 312 | fd = fd_percpu[cpu]; |
| 313 | |
| 314 | if (fd) |
| 315 | return fd; |
| 316 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 317 | sprintf(pathname, "/dev/cpu/%d/msr", cpu); |
| 318 | fd = open(pathname, O_RDONLY); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 319 | if (fd < 0) |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 320 | 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] | 321 | |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 322 | fd_percpu[cpu] = fd; |
| 323 | |
| 324 | return fd; |
| 325 | } |
| 326 | |
| 327 | int get_msr(int cpu, off_t offset, unsigned long long *msr) |
| 328 | { |
| 329 | ssize_t retval; |
| 330 | |
| 331 | retval = pread(get_msr_fd(cpu), msr, sizeof(*msr), offset); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 332 | |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 333 | if (retval != sizeof *msr) |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame^] | 334 | 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] | 335 | |
| 336 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 337 | } |
| 338 | |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 339 | /* |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 340 | * Each string in this array is compared in --show and --hide cmdline. |
| 341 | * 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] | 342 | */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 343 | struct msr_counter bic[] = { |
| 344 | { 0x0, "Package" }, |
| 345 | { 0x0, "Avg_MHz" }, |
| 346 | { 0x0, "Bzy_MHz" }, |
| 347 | { 0x0, "TSC_MHz" }, |
| 348 | { 0x0, "IRQ" }, |
| 349 | { 0x0, "SMI", 32, 0, FORMAT_DELTA, NULL}, |
| 350 | { 0x0, "Busy%" }, |
| 351 | { 0x0, "CPU%c1" }, |
| 352 | { 0x0, "CPU%c3" }, |
| 353 | { 0x0, "CPU%c6" }, |
| 354 | { 0x0, "CPU%c7" }, |
| 355 | { 0x0, "ThreadC" }, |
| 356 | { 0x0, "CoreTmp" }, |
| 357 | { 0x0, "CoreCnt" }, |
| 358 | { 0x0, "PkgTmp" }, |
| 359 | { 0x0, "GFX%rc6" }, |
| 360 | { 0x0, "GFXMHz" }, |
| 361 | { 0x0, "Pkg%pc2" }, |
| 362 | { 0x0, "Pkg%pc3" }, |
| 363 | { 0x0, "Pkg%pc6" }, |
| 364 | { 0x0, "Pkg%pc7" }, |
| 365 | { 0x0, "PkgWatt" }, |
| 366 | { 0x0, "CorWatt" }, |
| 367 | { 0x0, "GFXWatt" }, |
| 368 | { 0x0, "PkgCnt" }, |
| 369 | { 0x0, "RAMWatt" }, |
| 370 | { 0x0, "PKG_%" }, |
| 371 | { 0x0, "RAM_%" }, |
| 372 | { 0x0, "Pkg_J" }, |
| 373 | { 0x0, "Cor_J" }, |
| 374 | { 0x0, "GFX_J" }, |
| 375 | { 0x0, "RAM_J" }, |
| 376 | { 0x0, "Core" }, |
| 377 | { 0x0, "CPU" }, |
| 378 | }; |
| 379 | |
| 380 | #define MAX_BIC (sizeof(bic) / sizeof(struct msr_counter)) |
| 381 | #define BIC_Package (1ULL << 0) |
| 382 | #define BIC_Avg_MHz (1ULL << 1) |
| 383 | #define BIC_Bzy_MHz (1ULL << 2) |
| 384 | #define BIC_TSC_MHz (1ULL << 3) |
| 385 | #define BIC_IRQ (1ULL << 4) |
| 386 | #define BIC_SMI (1ULL << 5) |
| 387 | #define BIC_Busy (1ULL << 6) |
| 388 | #define BIC_CPU_c1 (1ULL << 7) |
| 389 | #define BIC_CPU_c3 (1ULL << 8) |
| 390 | #define BIC_CPU_c6 (1ULL << 9) |
| 391 | #define BIC_CPU_c7 (1ULL << 10) |
| 392 | #define BIC_ThreadC (1ULL << 11) |
| 393 | #define BIC_CoreTmp (1ULL << 12) |
| 394 | #define BIC_CoreCnt (1ULL << 13) |
| 395 | #define BIC_PkgTmp (1ULL << 14) |
| 396 | #define BIC_GFX_rc6 (1ULL << 15) |
| 397 | #define BIC_GFXMHz (1ULL << 16) |
| 398 | #define BIC_Pkgpc2 (1ULL << 17) |
| 399 | #define BIC_Pkgpc3 (1ULL << 18) |
| 400 | #define BIC_Pkgpc6 (1ULL << 19) |
| 401 | #define BIC_Pkgpc7 (1ULL << 20) |
| 402 | #define BIC_PkgWatt (1ULL << 21) |
| 403 | #define BIC_CorWatt (1ULL << 22) |
| 404 | #define BIC_GFXWatt (1ULL << 23) |
| 405 | #define BIC_PkgCnt (1ULL << 24) |
| 406 | #define BIC_RAMWatt (1ULL << 27) |
| 407 | #define BIC_PKG__ (1ULL << 28) |
| 408 | #define BIC_RAM__ (1ULL << 29) |
| 409 | #define BIC_Pkg_J (1ULL << 30) |
| 410 | #define BIC_Cor_J (1ULL << 31) |
| 411 | #define BIC_GFX_J (1ULL << 30) |
| 412 | #define BIC_RAM_J (1ULL << 31) |
| 413 | #define BIC_Core (1ULL << 32) |
| 414 | #define BIC_CPU (1ULL << 33) |
| 415 | |
| 416 | unsigned long long bic_enabled = 0xFFFFFFFFFFFFFFFFULL; |
| 417 | unsigned long long bic_present; |
| 418 | |
| 419 | #define DO_BIC(COUNTER_NAME) (bic_enabled & bic_present & COUNTER_NAME) |
| 420 | #define BIC_PRESENT(COUNTER_BIT) (bic_present |= COUNTER_BIT) |
| 421 | |
| 422 | /* |
| 423 | * bic_lookup |
| 424 | * for all the strings in comma separate name_list, |
| 425 | * set the approprate bit in return value. |
| 426 | */ |
| 427 | unsigned long long bic_lookup(char *name_list) |
| 428 | { |
| 429 | int i; |
| 430 | unsigned long long retval = 0; |
| 431 | |
| 432 | while (name_list) { |
| 433 | char *comma; |
| 434 | |
| 435 | comma = strchr(name_list, ','); |
| 436 | |
| 437 | if (comma) |
| 438 | *comma = '\0'; |
| 439 | |
| 440 | for (i = 0; i < MAX_BIC; ++i) { |
| 441 | if (!strcmp(name_list, bic[i].name)) { |
| 442 | retval |= (1ULL << i); |
| 443 | break; |
| 444 | } |
| 445 | } |
| 446 | if (i == MAX_BIC) { |
| 447 | fprintf(stderr, "Invalid counter name: %s\n", name_list); |
| 448 | exit(-1); |
| 449 | } |
| 450 | |
| 451 | name_list = comma; |
| 452 | if (name_list) |
| 453 | name_list++; |
| 454 | |
| 455 | } |
| 456 | return retval; |
| 457 | } |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 458 | |
Len Brown | a829eb4 | 2011-02-10 23:36:34 -0500 | [diff] [blame] | 459 | void print_header(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 460 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 461 | struct msr_counter *mp; |
| 462 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 463 | if (DO_BIC(BIC_Package)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 464 | outp += sprintf(outp, "\tPackage"); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 465 | if (DO_BIC(BIC_Core)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 466 | outp += sprintf(outp, "\tCore"); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 467 | if (DO_BIC(BIC_CPU)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 468 | outp += sprintf(outp, "\tCPU"); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 469 | if (DO_BIC(BIC_Avg_MHz)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 470 | outp += sprintf(outp, "\tAvg_MHz"); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 471 | if (DO_BIC(BIC_Busy)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 472 | outp += sprintf(outp, "\tBusy%%"); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 473 | if (DO_BIC(BIC_Bzy_MHz)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 474 | outp += sprintf(outp, "\tBzy_MHz"); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 475 | if (DO_BIC(BIC_TSC_MHz)) |
| 476 | outp += sprintf(outp, "\tTSC_MHz"); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 477 | |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 478 | if (!debug) |
| 479 | goto done; |
| 480 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 481 | if (DO_BIC(BIC_IRQ)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 482 | outp += sprintf(outp, "\tIRQ"); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 483 | if (DO_BIC(BIC_SMI)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 484 | outp += sprintf(outp, "\tSMI"); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 485 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 486 | if (DO_BIC(BIC_CPU_c1)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 487 | outp += sprintf(outp, "\tCPU%%c1"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 488 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 489 | for (mp = sys.tp; mp; mp = mp->next) { |
| 490 | if (mp->format == FORMAT_RAW) { |
| 491 | if (mp->width == 64) |
| 492 | outp += sprintf(outp, "\t%18.18s", mp->name); |
| 493 | else |
| 494 | outp += sprintf(outp, "\t%10.10s", mp->name); |
| 495 | } else { |
| 496 | outp += sprintf(outp, "\t%-7.7s", mp->name); |
| 497 | } |
| 498 | } |
| 499 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 500 | if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates) |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 501 | outp += sprintf(outp, "\tCPU%%c3"); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 502 | if (DO_BIC(BIC_CPU_c6)) |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 503 | outp += sprintf(outp, "\tCPU%%c6"); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 504 | if (DO_BIC(BIC_CPU_c7)) |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 505 | outp += sprintf(outp, "\tCPU%%c7"); |
| 506 | |
| 507 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 508 | if (DO_BIC(BIC_CoreTmp)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 509 | outp += sprintf(outp, "\tCoreTmp"); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 510 | |
| 511 | for (mp = sys.cp; mp; mp = mp->next) { |
| 512 | if (mp->format == FORMAT_RAW) { |
| 513 | if (mp->width == 64) |
| 514 | outp += sprintf(outp, "\t%18.18s", mp->name); |
| 515 | else |
| 516 | outp += sprintf(outp, "\t%10.10s", mp->name); |
| 517 | } else { |
| 518 | outp += sprintf(outp, "\t%-7.7s", mp->name); |
| 519 | } |
| 520 | } |
| 521 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 522 | if (DO_BIC(BIC_PkgTmp)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 523 | outp += sprintf(outp, "\tPkgTmp"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 524 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 525 | if (DO_BIC(BIC_GFX_rc6)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 526 | outp += sprintf(outp, "\tGFX%%rc6"); |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 527 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 528 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 529 | outp += sprintf(outp, "\tGFXMHz"); |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 530 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 531 | if (do_skl_residency) { |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 532 | outp += sprintf(outp, "\tTotl%%C0"); |
| 533 | outp += sprintf(outp, "\tAny%%C0"); |
| 534 | outp += sprintf(outp, "\tGFX%%C0"); |
| 535 | outp += sprintf(outp, "\tCPUGFX%%"); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 536 | } |
| 537 | |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 538 | if (do_pc2) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 539 | outp += sprintf(outp, "\tPkg%%pc2"); |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 540 | if (do_pc3) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 541 | outp += sprintf(outp, "\tPkg%%pc3"); |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 542 | if (do_pc6) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 543 | outp += sprintf(outp, "\tPkg%%pc6"); |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 544 | if (do_pc7) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 545 | outp += sprintf(outp, "\tPkg%%pc7"); |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 546 | if (do_c8_c9_c10) { |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 547 | outp += sprintf(outp, "\tPkg%%pc8"); |
| 548 | outp += sprintf(outp, "\tPkg%%pc9"); |
| 549 | outp += sprintf(outp, "\tPk%%pc10"); |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 550 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 551 | |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 552 | if (do_rapl && !rapl_joules) { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 553 | if (DO_BIC(BIC_PkgWatt)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 554 | outp += sprintf(outp, "\tPkgWatt"); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 555 | if (DO_BIC(BIC_CorWatt)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 556 | outp += sprintf(outp, "\tCorWatt"); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 557 | if (DO_BIC(BIC_GFXWatt)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 558 | outp += sprintf(outp, "\tGFXWatt"); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 559 | if (DO_BIC(BIC_RAMWatt)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 560 | outp += sprintf(outp, "\tRAMWatt"); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 561 | if (DO_BIC(BIC_PKG__)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 562 | outp += sprintf(outp, "\tPKG_%%"); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 563 | if (DO_BIC(BIC_RAM__)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 564 | outp += sprintf(outp, "\tRAM_%%"); |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 565 | } else if (do_rapl && rapl_joules) { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 566 | if (DO_BIC(BIC_Pkg_J)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 567 | outp += sprintf(outp, "\tPkg_J"); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 568 | if (DO_BIC(BIC_Cor_J)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 569 | outp += sprintf(outp, "\tCor_J"); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 570 | if (DO_BIC(BIC_GFX_J)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 571 | outp += sprintf(outp, "\tGFX_J"); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 572 | if (DO_BIC(BIC_RAM_J)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 573 | outp += sprintf(outp, "\tRAM_J"); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 574 | if (DO_BIC(BIC_PKG__)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 575 | outp += sprintf(outp, "\tPKG_%%"); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 576 | if (DO_BIC(BIC_RAM__)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 577 | outp += sprintf(outp, "\tRAM_%%"); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 578 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 579 | for (mp = sys.pp; mp; mp = mp->next) { |
| 580 | if (mp->format == FORMAT_RAW) { |
| 581 | if (mp->width == 64) |
| 582 | outp += sprintf(outp, "\t%18.18s", mp->name); |
| 583 | else |
| 584 | outp += sprintf(outp, "\t%10.10s", mp->name); |
| 585 | } else { |
| 586 | outp += sprintf(outp, "\t%-7.7s", mp->name); |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | done: |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 591 | outp += sprintf(outp, "\n"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 592 | } |
| 593 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 594 | int dump_counters(struct thread_data *t, struct core_data *c, |
| 595 | struct pkg_data *p) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 596 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 597 | int i; |
| 598 | struct msr_counter *mp; |
| 599 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 600 | 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] | 601 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 602 | if (t) { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 603 | outp += sprintf(outp, "CPU: %d flags 0x%x\n", |
| 604 | t->cpu_id, t->flags); |
| 605 | outp += sprintf(outp, "TSC: %016llX\n", t->tsc); |
| 606 | outp += sprintf(outp, "aperf: %016llX\n", t->aperf); |
| 607 | outp += sprintf(outp, "mperf: %016llX\n", t->mperf); |
| 608 | outp += sprintf(outp, "c1: %016llX\n", t->c1); |
Len Brown | 6886fee | 2016-12-24 15:18:37 -0500 | [diff] [blame] | 609 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 610 | if (DO_BIC(BIC_IRQ)) |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 611 | outp += sprintf(outp, "IRQ: %08X\n", t->irq_count); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 612 | if (DO_BIC(BIC_SMI)) |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 613 | outp += sprintf(outp, "SMI: %08X\n", t->smi_count); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 614 | |
| 615 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 616 | outp += sprintf(outp, "tADDED [%d] msr0x%x: %08llX\n", |
| 617 | i, mp->msr_num, t->counter[i]); |
| 618 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 619 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 620 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 621 | if (c) { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 622 | outp += sprintf(outp, "core: %d\n", c->core_id); |
| 623 | outp += sprintf(outp, "c3: %016llX\n", c->c3); |
| 624 | outp += sprintf(outp, "c6: %016llX\n", c->c6); |
| 625 | outp += sprintf(outp, "c7: %016llX\n", c->c7); |
| 626 | outp += sprintf(outp, "DTS: %dC\n", c->core_temp_c); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 627 | |
| 628 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 629 | outp += sprintf(outp, "cADDED [%d] msr0x%x: %08llX\n", |
| 630 | i, mp->msr_num, c->counter[i]); |
| 631 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | if (p) { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 635 | outp += sprintf(outp, "package: %d\n", p->package_id); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 636 | |
| 637 | outp += sprintf(outp, "Weighted cores: %016llX\n", p->pkg_wtd_core_c0); |
| 638 | outp += sprintf(outp, "Any cores: %016llX\n", p->pkg_any_core_c0); |
| 639 | outp += sprintf(outp, "Any GFX: %016llX\n", p->pkg_any_gfxe_c0); |
| 640 | outp += sprintf(outp, "CPU + GFX: %016llX\n", p->pkg_both_core_gfxe_c0); |
| 641 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 642 | outp += sprintf(outp, "pc2: %016llX\n", p->pc2); |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 643 | if (do_pc3) |
| 644 | outp += sprintf(outp, "pc3: %016llX\n", p->pc3); |
| 645 | if (do_pc6) |
| 646 | outp += sprintf(outp, "pc6: %016llX\n", p->pc6); |
| 647 | if (do_pc7) |
| 648 | outp += sprintf(outp, "pc7: %016llX\n", p->pc7); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 649 | outp += sprintf(outp, "pc8: %016llX\n", p->pc8); |
| 650 | outp += sprintf(outp, "pc9: %016llX\n", p->pc9); |
| 651 | outp += sprintf(outp, "pc10: %016llX\n", p->pc10); |
| 652 | outp += sprintf(outp, "Joules PKG: %0X\n", p->energy_pkg); |
| 653 | outp += sprintf(outp, "Joules COR: %0X\n", p->energy_cores); |
| 654 | outp += sprintf(outp, "Joules GFX: %0X\n", p->energy_gfx); |
| 655 | outp += sprintf(outp, "Joules RAM: %0X\n", p->energy_dram); |
| 656 | outp += sprintf(outp, "Throttle PKG: %0X\n", |
| 657 | p->rapl_pkg_perf_status); |
| 658 | outp += sprintf(outp, "Throttle RAM: %0X\n", |
| 659 | p->rapl_dram_perf_status); |
| 660 | outp += sprintf(outp, "PTM: %dC\n", p->pkg_temp_c); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 661 | |
| 662 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 663 | outp += sprintf(outp, "pADDED [%d] msr0x%x: %08llX\n", |
| 664 | i, mp->msr_num, p->counter[i]); |
| 665 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 666 | } |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 667 | |
| 668 | outp += sprintf(outp, "\n"); |
| 669 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 670 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 671 | } |
| 672 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 673 | /* |
| 674 | * column formatting convention & formats |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 675 | */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 676 | int format_counters(struct thread_data *t, struct core_data *c, |
| 677 | struct pkg_data *p) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 678 | { |
| 679 | double interval_float; |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 680 | char *fmt8; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 681 | int i; |
| 682 | struct msr_counter *mp; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 683 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 684 | /* if showing only 1st thread in core and this isn't one, bail out */ |
| 685 | if (show_core_only && !(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 686 | return 0; |
| 687 | |
| 688 | /* if showing only 1st thread in pkg and this isn't one, bail out */ |
| 689 | if (show_pkg_only && !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 690 | return 0; |
| 691 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 692 | interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0; |
| 693 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 694 | /* topo columns, print blanks on 1st (average) line */ |
| 695 | if (t == &average.threads) { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 696 | if (DO_BIC(BIC_Package)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 697 | outp += sprintf(outp, "\t-"); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 698 | if (DO_BIC(BIC_Core)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 699 | outp += sprintf(outp, "\t-"); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 700 | if (DO_BIC(BIC_CPU)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 701 | outp += sprintf(outp, "\t-"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 702 | } else { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 703 | if (DO_BIC(BIC_Package)) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 704 | if (p) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 705 | outp += sprintf(outp, "\t%d", p->package_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 706 | else |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 707 | outp += sprintf(outp, "\t-"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 708 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 709 | if (DO_BIC(BIC_Core)) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 710 | if (c) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 711 | outp += sprintf(outp, "\t%d", c->core_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 712 | else |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 713 | outp += sprintf(outp, "\t-"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 714 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 715 | if (DO_BIC(BIC_CPU)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 716 | outp += sprintf(outp, "\t%d", t->cpu_id); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 717 | } |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 718 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 719 | if (DO_BIC(BIC_Avg_MHz)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 720 | outp += sprintf(outp, "\t%.0f", |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 721 | 1.0 / units * t->aperf / interval_float); |
| 722 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 723 | if (DO_BIC(BIC_Busy)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 724 | outp += sprintf(outp, "\t%.2f", 100.0 * t->mperf/t->tsc/tsc_tweak); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 725 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 726 | if (DO_BIC(BIC_Bzy_MHz)) { |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 727 | if (has_base_hz) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 728 | outp += sprintf(outp, "\t%.0f", base_hz / units * t->aperf / t->mperf); |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 729 | else |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 730 | outp += sprintf(outp, "\t%.0f", |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 731 | 1.0 * t->tsc / units * t->aperf / t->mperf / interval_float); |
| 732 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 733 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 734 | if (DO_BIC(BIC_TSC_MHz)) |
| 735 | outp += sprintf(outp, "\t%.0f", 1.0 * t->tsc/units/interval_float); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 736 | |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 737 | if (!debug) |
| 738 | goto done; |
| 739 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 740 | /* IRQ */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 741 | if (DO_BIC(BIC_IRQ)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 742 | outp += sprintf(outp, "\t%d", t->irq_count); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 743 | |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 744 | /* SMI */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 745 | if (DO_BIC(BIC_SMI)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 746 | outp += sprintf(outp, "\t%d", t->smi_count); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 747 | |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 748 | /* C1 */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 749 | if (DO_BIC(BIC_CPU_c1)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 750 | outp += sprintf(outp, "\t%.2f", 100.0 * t->c1/t->tsc); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 751 | |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 752 | /* Added counters */ |
| 753 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 754 | if (mp->format == FORMAT_RAW) { |
| 755 | if (mp->width == 32) |
| 756 | outp += sprintf(outp, "\t0x%08lx", (unsigned long) t->counter[i]); |
| 757 | else |
| 758 | outp += sprintf(outp, "\t0x%016llx", t->counter[i]); |
| 759 | } else if (mp->format == FORMAT_DELTA) { |
| 760 | outp += sprintf(outp, "\t%lld", t->counter[i]); |
| 761 | } else if (mp->format == FORMAT_PERCENT) { |
| 762 | outp += sprintf(outp, "\t%.2f", 100.0 * t->counter[i]/t->tsc); |
| 763 | } |
| 764 | } |
| 765 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 766 | /* print per-core data only for 1st thread in core */ |
| 767 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 768 | goto done; |
| 769 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 770 | if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 771 | outp += sprintf(outp, "\t%.2f", 100.0 * c->c3/t->tsc); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 772 | if (DO_BIC(BIC_CPU_c6)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 773 | outp += sprintf(outp, "\t%.2f", 100.0 * c->c6/t->tsc); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 774 | if (DO_BIC(BIC_CPU_c7)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 775 | outp += sprintf(outp, "\t%.2f", 100.0 * c->c7/t->tsc); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 776 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 777 | if (DO_BIC(BIC_CoreTmp)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 778 | outp += sprintf(outp, "\t%d", c->core_temp_c); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 779 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 780 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 781 | if (mp->format == FORMAT_RAW) { |
| 782 | if (mp->width == 32) |
| 783 | outp += sprintf(outp, "\t0x%08lx", (unsigned long) c->counter[i]); |
| 784 | else |
| 785 | outp += sprintf(outp, "\t0x%016llx", c->counter[i]); |
| 786 | } else if (mp->format == FORMAT_DELTA) { |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 787 | outp += sprintf(outp, "\t%lld", c->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 788 | } else if (mp->format == FORMAT_PERCENT) { |
| 789 | outp += sprintf(outp, "\t%.2f", 100.0 * c->counter[i]/t->tsc); |
| 790 | } |
| 791 | } |
| 792 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 793 | /* print per-package data only for 1st core in package */ |
| 794 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 795 | goto done; |
| 796 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 797 | /* PkgTmp */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 798 | if (DO_BIC(BIC_PkgTmp)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 799 | outp += sprintf(outp, "\t%d", p->pkg_temp_c); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 800 | |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 801 | /* GFXrc6 */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 802 | if (DO_BIC(BIC_GFX_rc6)) { |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 803 | if (p->gfx_rc6_ms == -1) { /* detect GFX counter reset */ |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 804 | outp += sprintf(outp, "\t**.**"); |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 805 | } else { |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 806 | outp += sprintf(outp, "\t%.2f", |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 807 | p->gfx_rc6_ms / 10.0 / interval_float); |
| 808 | } |
| 809 | } |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 810 | |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 811 | /* GFXMHz */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 812 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 813 | outp += sprintf(outp, "\t%d", p->gfx_mhz); |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 814 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 815 | /* Totl%C0, Any%C0 GFX%C0 CPUGFX% */ |
| 816 | if (do_skl_residency) { |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 817 | outp += sprintf(outp, "\t%.2f", 100.0 * p->pkg_wtd_core_c0/t->tsc); |
| 818 | outp += sprintf(outp, "\t%.2f", 100.0 * p->pkg_any_core_c0/t->tsc); |
| 819 | outp += sprintf(outp, "\t%.2f", 100.0 * p->pkg_any_gfxe_c0/t->tsc); |
| 820 | outp += sprintf(outp, "\t%.2f", 100.0 * p->pkg_both_core_gfxe_c0/t->tsc); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 821 | } |
| 822 | |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 823 | if (do_pc2) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 824 | outp += sprintf(outp, "\t%.2f", 100.0 * p->pc2/t->tsc); |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 825 | if (do_pc3) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 826 | outp += sprintf(outp, "\t%.2f", 100.0 * p->pc3/t->tsc); |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 827 | if (do_pc6) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 828 | outp += sprintf(outp, "\t%.2f", 100.0 * p->pc6/t->tsc); |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 829 | if (do_pc7) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 830 | outp += sprintf(outp, "\t%.2f", 100.0 * p->pc7/t->tsc); |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 831 | if (do_c8_c9_c10) { |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 832 | outp += sprintf(outp, "\t%.2f", 100.0 * p->pc8/t->tsc); |
| 833 | outp += sprintf(outp, "\t%.2f", 100.0 * p->pc9/t->tsc); |
| 834 | outp += sprintf(outp, "\t%.2f", 100.0 * p->pc10/t->tsc); |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 835 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 836 | |
| 837 | /* |
| 838 | * If measurement interval exceeds minimum RAPL Joule Counter range, |
| 839 | * indicate that results are suspect by printing "**" in fraction place. |
| 840 | */ |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 841 | if (interval_float < rapl_joule_counter_range) |
Len Brown | 3d109de | 2016-04-22 23:24:27 -0400 | [diff] [blame] | 842 | fmt8 = "\t%.2f"; |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 843 | else |
Len Brown | e975db5 | 2016-04-06 23:56:02 -0400 | [diff] [blame] | 844 | fmt8 = "%6.0f**"; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 845 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 846 | if (DO_BIC(BIC_PkgWatt)) |
| 847 | outp += sprintf(outp, fmt8, p->energy_pkg * rapl_energy_units / interval_float); |
| 848 | if (DO_BIC(BIC_CorWatt)) |
| 849 | outp += sprintf(outp, fmt8, p->energy_cores * rapl_energy_units / interval_float); |
| 850 | if (DO_BIC(BIC_GFXWatt)) |
| 851 | outp += sprintf(outp, fmt8, p->energy_gfx * rapl_energy_units / interval_float); |
| 852 | if (DO_BIC(BIC_RAMWatt)) |
| 853 | outp += sprintf(outp, fmt8, p->energy_dram * rapl_dram_energy_units / interval_float); |
| 854 | if (DO_BIC(BIC_Pkg_J)) |
| 855 | outp += sprintf(outp, fmt8, p->energy_pkg * rapl_energy_units); |
| 856 | if (DO_BIC(BIC_Cor_J)) |
| 857 | outp += sprintf(outp, fmt8, p->energy_cores * rapl_energy_units); |
| 858 | if (DO_BIC(BIC_GFX_J)) |
| 859 | outp += sprintf(outp, fmt8, p->energy_gfx * rapl_energy_units); |
| 860 | if (DO_BIC(BIC_RAM_J)) |
| 861 | outp += sprintf(outp, fmt8, p->energy_dram * rapl_dram_energy_units); |
| 862 | if (DO_BIC(BIC_PKG__)) |
| 863 | outp += sprintf(outp, fmt8, 100.0 * p->rapl_pkg_perf_status * rapl_time_units / interval_float); |
| 864 | if (DO_BIC(BIC_RAM__)) |
| 865 | outp += sprintf(outp, fmt8, 100.0 * p->rapl_dram_perf_status * rapl_time_units / interval_float); |
| 866 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 867 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 868 | if (mp->format == FORMAT_RAW) { |
| 869 | if (mp->width == 32) |
| 870 | outp += sprintf(outp, "\t0x%08lx", (unsigned long) p->counter[i]); |
| 871 | else |
| 872 | outp += sprintf(outp, "\t0x%016llx", p->counter[i]); |
| 873 | } else if (mp->format == FORMAT_DELTA) { |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 874 | outp += sprintf(outp, "\t%lld", p->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 875 | } else if (mp->format == FORMAT_PERCENT) { |
| 876 | outp += sprintf(outp, "\t%.2f", 100.0 * p->counter[i]/t->tsc); |
| 877 | } |
| 878 | } |
| 879 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 880 | done: |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 881 | outp += sprintf(outp, "\n"); |
| 882 | |
| 883 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 884 | } |
| 885 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 886 | void flush_output_stdout(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 887 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 888 | FILE *filep; |
| 889 | |
| 890 | if (outf == stderr) |
| 891 | filep = stdout; |
| 892 | else |
| 893 | filep = outf; |
| 894 | |
| 895 | fputs(output_buffer, filep); |
| 896 | fflush(filep); |
| 897 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 898 | outp = output_buffer; |
| 899 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 900 | void flush_output_stderr(void) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 901 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 902 | fputs(output_buffer, outf); |
| 903 | fflush(outf); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 904 | outp = output_buffer; |
| 905 | } |
| 906 | void format_all_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 907 | { |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 908 | static int printed; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 909 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 910 | if (!printed || !summary_only) |
| 911 | print_header(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 912 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 913 | if (topo.num_cpus > 1) |
| 914 | format_counters(&average.threads, &average.cores, |
| 915 | &average.packages); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 916 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 917 | printed = 1; |
| 918 | |
| 919 | if (summary_only) |
| 920 | return; |
| 921 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 922 | for_all_cpus(format_counters, t, c, p); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 923 | } |
| 924 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 925 | #define DELTA_WRAP32(new, old) \ |
| 926 | if (new > old) { \ |
| 927 | old = new - old; \ |
| 928 | } else { \ |
| 929 | old = 0x100000000 + new - old; \ |
| 930 | } |
| 931 | |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 932 | int |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 933 | delta_package(struct pkg_data *new, struct pkg_data *old) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 934 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 935 | int i; |
| 936 | struct msr_counter *mp; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 937 | |
| 938 | if (do_skl_residency) { |
| 939 | old->pkg_wtd_core_c0 = new->pkg_wtd_core_c0 - old->pkg_wtd_core_c0; |
| 940 | old->pkg_any_core_c0 = new->pkg_any_core_c0 - old->pkg_any_core_c0; |
| 941 | old->pkg_any_gfxe_c0 = new->pkg_any_gfxe_c0 - old->pkg_any_gfxe_c0; |
| 942 | old->pkg_both_core_gfxe_c0 = new->pkg_both_core_gfxe_c0 - old->pkg_both_core_gfxe_c0; |
| 943 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 944 | old->pc2 = new->pc2 - old->pc2; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 945 | if (do_pc3) |
| 946 | old->pc3 = new->pc3 - old->pc3; |
| 947 | if (do_pc6) |
| 948 | old->pc6 = new->pc6 - old->pc6; |
| 949 | if (do_pc7) |
| 950 | old->pc7 = new->pc7 - old->pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 951 | old->pc8 = new->pc8 - old->pc8; |
| 952 | old->pc9 = new->pc9 - old->pc9; |
| 953 | old->pc10 = new->pc10 - old->pc10; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 954 | old->pkg_temp_c = new->pkg_temp_c; |
| 955 | |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 956 | /* flag an error when rc6 counter resets/wraps */ |
| 957 | if (old->gfx_rc6_ms > new->gfx_rc6_ms) |
| 958 | old->gfx_rc6_ms = -1; |
| 959 | else |
| 960 | old->gfx_rc6_ms = new->gfx_rc6_ms - old->gfx_rc6_ms; |
| 961 | |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 962 | old->gfx_mhz = new->gfx_mhz; |
| 963 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 964 | DELTA_WRAP32(new->energy_pkg, old->energy_pkg); |
| 965 | DELTA_WRAP32(new->energy_cores, old->energy_cores); |
| 966 | DELTA_WRAP32(new->energy_gfx, old->energy_gfx); |
| 967 | DELTA_WRAP32(new->energy_dram, old->energy_dram); |
| 968 | DELTA_WRAP32(new->rapl_pkg_perf_status, old->rapl_pkg_perf_status); |
| 969 | DELTA_WRAP32(new->rapl_dram_perf_status, old->rapl_dram_perf_status); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 970 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 971 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 972 | if (mp->format == FORMAT_RAW) |
| 973 | old->counter[i] = new->counter[i]; |
| 974 | else |
| 975 | old->counter[i] = new->counter[i] - old->counter[i]; |
| 976 | } |
| 977 | |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 978 | return 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 979 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 980 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 981 | void |
| 982 | delta_core(struct core_data *new, struct core_data *old) |
| 983 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 984 | int i; |
| 985 | struct msr_counter *mp; |
| 986 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 987 | old->c3 = new->c3 - old->c3; |
| 988 | old->c6 = new->c6 - old->c6; |
| 989 | old->c7 = new->c7 - old->c7; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 990 | old->core_temp_c = new->core_temp_c; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 991 | |
| 992 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 993 | if (mp->format == FORMAT_RAW) |
| 994 | old->counter[i] = new->counter[i]; |
| 995 | else |
| 996 | old->counter[i] = new->counter[i] - old->counter[i]; |
| 997 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 998 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 999 | |
Len Brown | c3ae331 | 2012-06-13 21:31:46 -0400 | [diff] [blame] | 1000 | /* |
| 1001 | * old = new - old |
| 1002 | */ |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1003 | int |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1004 | delta_thread(struct thread_data *new, struct thread_data *old, |
| 1005 | struct core_data *core_delta) |
| 1006 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1007 | int i; |
| 1008 | struct msr_counter *mp; |
| 1009 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1010 | old->tsc = new->tsc - old->tsc; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1011 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1012 | /* check for TSC < 1 Mcycles over interval */ |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 1013 | if (old->tsc < (1000 * 1000)) |
| 1014 | errx(-3, "Insanely slow TSC rate, TSC stops in idle?\n" |
| 1015 | "You can disable all c-states by booting with \"idle=poll\"\n" |
| 1016 | "or just the deep ones with \"processor.max_cstate=1\""); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1017 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1018 | old->c1 = new->c1 - old->c1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1019 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1020 | 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] | 1021 | if ((new->aperf > old->aperf) && (new->mperf > old->mperf)) { |
| 1022 | old->aperf = new->aperf - old->aperf; |
| 1023 | old->mperf = new->mperf - old->mperf; |
| 1024 | } else { |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1025 | return -1; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1026 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1027 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1028 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1029 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1030 | if (use_c1_residency_msr) { |
| 1031 | /* |
| 1032 | * Some models have a dedicated C1 residency MSR, |
| 1033 | * which should be more accurate than the derivation below. |
| 1034 | */ |
| 1035 | } else { |
| 1036 | /* |
| 1037 | * As counter collection is not atomic, |
| 1038 | * it is possible for mperf's non-halted cycles + idle states |
| 1039 | * to exceed TSC's all cycles: show c1 = 0% in that case. |
| 1040 | */ |
| 1041 | if ((old->mperf + core_delta->c3 + core_delta->c6 + core_delta->c7) > old->tsc) |
| 1042 | old->c1 = 0; |
| 1043 | else { |
| 1044 | /* normal case, derive c1 */ |
| 1045 | old->c1 = old->tsc - old->mperf - core_delta->c3 |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1046 | - core_delta->c6 - core_delta->c7; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1047 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1048 | } |
Len Brown | c3ae331 | 2012-06-13 21:31:46 -0400 | [diff] [blame] | 1049 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1050 | if (old->mperf == 0) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1051 | if (debug > 1) |
| 1052 | fprintf(outf, "cpu%d MPERF 0!\n", old->cpu_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1053 | old->mperf = 1; /* divide by 0 protection */ |
| 1054 | } |
| 1055 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1056 | if (DO_BIC(BIC_IRQ)) |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1057 | old->irq_count = new->irq_count - old->irq_count; |
| 1058 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1059 | if (DO_BIC(BIC_SMI)) |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 1060 | old->smi_count = new->smi_count - old->smi_count; |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1061 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1062 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 1063 | if (mp->format == FORMAT_RAW) |
| 1064 | old->counter[i] = new->counter[i]; |
| 1065 | else |
| 1066 | old->counter[i] = new->counter[i] - old->counter[i]; |
| 1067 | } |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1068 | return 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | int delta_cpu(struct thread_data *t, struct core_data *c, |
| 1072 | struct pkg_data *p, struct thread_data *t2, |
| 1073 | struct core_data *c2, struct pkg_data *p2) |
| 1074 | { |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1075 | int retval = 0; |
| 1076 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1077 | /* calculate core delta only for 1st thread in core */ |
| 1078 | if (t->flags & CPU_IS_FIRST_THREAD_IN_CORE) |
| 1079 | delta_core(c, c2); |
| 1080 | |
| 1081 | /* always calculate thread delta */ |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1082 | retval = delta_thread(t, t2, c2); /* c2 is core delta */ |
| 1083 | if (retval) |
| 1084 | return retval; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1085 | |
| 1086 | /* calculate package delta only for 1st core in package */ |
| 1087 | if (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE) |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1088 | retval = delta_package(p, p2); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1089 | |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1090 | return retval; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | void clear_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 1094 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1095 | int i; |
| 1096 | struct msr_counter *mp; |
| 1097 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1098 | t->tsc = 0; |
| 1099 | t->aperf = 0; |
| 1100 | t->mperf = 0; |
| 1101 | t->c1 = 0; |
| 1102 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1103 | t->irq_count = 0; |
| 1104 | t->smi_count = 0; |
| 1105 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1106 | /* tells format_counters to dump all fields from this set */ |
| 1107 | t->flags = CPU_IS_FIRST_THREAD_IN_CORE | CPU_IS_FIRST_CORE_IN_PACKAGE; |
| 1108 | |
| 1109 | c->c3 = 0; |
| 1110 | c->c6 = 0; |
| 1111 | c->c7 = 0; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1112 | c->core_temp_c = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1113 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1114 | p->pkg_wtd_core_c0 = 0; |
| 1115 | p->pkg_any_core_c0 = 0; |
| 1116 | p->pkg_any_gfxe_c0 = 0; |
| 1117 | p->pkg_both_core_gfxe_c0 = 0; |
| 1118 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1119 | p->pc2 = 0; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1120 | if (do_pc3) |
| 1121 | p->pc3 = 0; |
| 1122 | if (do_pc6) |
| 1123 | p->pc6 = 0; |
| 1124 | if (do_pc7) |
| 1125 | p->pc7 = 0; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1126 | p->pc8 = 0; |
| 1127 | p->pc9 = 0; |
| 1128 | p->pc10 = 0; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1129 | |
| 1130 | p->energy_pkg = 0; |
| 1131 | p->energy_dram = 0; |
| 1132 | p->energy_cores = 0; |
| 1133 | p->energy_gfx = 0; |
| 1134 | p->rapl_pkg_perf_status = 0; |
| 1135 | p->rapl_dram_perf_status = 0; |
| 1136 | p->pkg_temp_c = 0; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1137 | |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1138 | p->gfx_rc6_ms = 0; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1139 | p->gfx_mhz = 0; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1140 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) |
| 1141 | t->counter[i] = 0; |
| 1142 | |
| 1143 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) |
| 1144 | c->counter[i] = 0; |
| 1145 | |
| 1146 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) |
| 1147 | p->counter[i] = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1148 | } |
| 1149 | int sum_counters(struct thread_data *t, struct core_data *c, |
| 1150 | struct pkg_data *p) |
| 1151 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1152 | int i; |
| 1153 | struct msr_counter *mp; |
| 1154 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1155 | average.threads.tsc += t->tsc; |
| 1156 | average.threads.aperf += t->aperf; |
| 1157 | average.threads.mperf += t->mperf; |
| 1158 | average.threads.c1 += t->c1; |
| 1159 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1160 | average.threads.irq_count += t->irq_count; |
| 1161 | average.threads.smi_count += t->smi_count; |
| 1162 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1163 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 1164 | if (mp->format == FORMAT_RAW) |
| 1165 | continue; |
| 1166 | average.threads.counter[i] += t->counter[i]; |
| 1167 | } |
| 1168 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1169 | /* sum per-core values only for 1st thread in core */ |
| 1170 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 1171 | return 0; |
| 1172 | |
| 1173 | average.cores.c3 += c->c3; |
| 1174 | average.cores.c6 += c->c6; |
| 1175 | average.cores.c7 += c->c7; |
| 1176 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1177 | average.cores.core_temp_c = MAX(average.cores.core_temp_c, c->core_temp_c); |
| 1178 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1179 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 1180 | if (mp->format == FORMAT_RAW) |
| 1181 | continue; |
| 1182 | average.cores.counter[i] += c->counter[i]; |
| 1183 | } |
| 1184 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1185 | /* sum per-pkg values only for 1st core in pkg */ |
| 1186 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 1187 | return 0; |
| 1188 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1189 | if (do_skl_residency) { |
| 1190 | average.packages.pkg_wtd_core_c0 += p->pkg_wtd_core_c0; |
| 1191 | average.packages.pkg_any_core_c0 += p->pkg_any_core_c0; |
| 1192 | average.packages.pkg_any_gfxe_c0 += p->pkg_any_gfxe_c0; |
| 1193 | average.packages.pkg_both_core_gfxe_c0 += p->pkg_both_core_gfxe_c0; |
| 1194 | } |
| 1195 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1196 | average.packages.pc2 += p->pc2; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1197 | if (do_pc3) |
| 1198 | average.packages.pc3 += p->pc3; |
| 1199 | if (do_pc6) |
| 1200 | average.packages.pc6 += p->pc6; |
| 1201 | if (do_pc7) |
| 1202 | average.packages.pc7 += p->pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1203 | average.packages.pc8 += p->pc8; |
| 1204 | average.packages.pc9 += p->pc9; |
| 1205 | average.packages.pc10 += p->pc10; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1206 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1207 | average.packages.energy_pkg += p->energy_pkg; |
| 1208 | average.packages.energy_dram += p->energy_dram; |
| 1209 | average.packages.energy_cores += p->energy_cores; |
| 1210 | average.packages.energy_gfx += p->energy_gfx; |
| 1211 | |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1212 | average.packages.gfx_rc6_ms = p->gfx_rc6_ms; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1213 | average.packages.gfx_mhz = p->gfx_mhz; |
| 1214 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1215 | average.packages.pkg_temp_c = MAX(average.packages.pkg_temp_c, p->pkg_temp_c); |
| 1216 | |
| 1217 | average.packages.rapl_pkg_perf_status += p->rapl_pkg_perf_status; |
| 1218 | average.packages.rapl_dram_perf_status += p->rapl_dram_perf_status; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1219 | |
| 1220 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1221 | if (mp->format == FORMAT_RAW) |
| 1222 | continue; |
| 1223 | average.packages.counter[i] += p->counter[i]; |
| 1224 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1225 | return 0; |
| 1226 | } |
| 1227 | /* |
| 1228 | * sum the counters for all cpus in the system |
| 1229 | * compute the weighted average |
| 1230 | */ |
| 1231 | void compute_average(struct thread_data *t, struct core_data *c, |
| 1232 | struct pkg_data *p) |
| 1233 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1234 | int i; |
| 1235 | struct msr_counter *mp; |
| 1236 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1237 | clear_counters(&average.threads, &average.cores, &average.packages); |
| 1238 | |
| 1239 | for_all_cpus(sum_counters, t, c, p); |
| 1240 | |
| 1241 | average.threads.tsc /= topo.num_cpus; |
| 1242 | average.threads.aperf /= topo.num_cpus; |
| 1243 | average.threads.mperf /= topo.num_cpus; |
| 1244 | average.threads.c1 /= topo.num_cpus; |
| 1245 | |
| 1246 | average.cores.c3 /= topo.num_cores; |
| 1247 | average.cores.c6 /= topo.num_cores; |
| 1248 | average.cores.c7 /= topo.num_cores; |
| 1249 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1250 | if (do_skl_residency) { |
| 1251 | average.packages.pkg_wtd_core_c0 /= topo.num_packages; |
| 1252 | average.packages.pkg_any_core_c0 /= topo.num_packages; |
| 1253 | average.packages.pkg_any_gfxe_c0 /= topo.num_packages; |
| 1254 | average.packages.pkg_both_core_gfxe_c0 /= topo.num_packages; |
| 1255 | } |
| 1256 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1257 | average.packages.pc2 /= topo.num_packages; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1258 | if (do_pc3) |
| 1259 | average.packages.pc3 /= topo.num_packages; |
| 1260 | if (do_pc6) |
| 1261 | average.packages.pc6 /= topo.num_packages; |
| 1262 | if (do_pc7) |
| 1263 | average.packages.pc7 /= topo.num_packages; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1264 | |
| 1265 | average.packages.pc8 /= topo.num_packages; |
| 1266 | average.packages.pc9 /= topo.num_packages; |
| 1267 | average.packages.pc10 /= topo.num_packages; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1268 | |
| 1269 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 1270 | if (mp->format == FORMAT_RAW) |
| 1271 | continue; |
| 1272 | average.threads.counter[i] /= topo.num_cpus; |
| 1273 | } |
| 1274 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 1275 | if (mp->format == FORMAT_RAW) |
| 1276 | continue; |
| 1277 | average.cores.counter[i] /= topo.num_cores; |
| 1278 | } |
| 1279 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1280 | if (mp->format == FORMAT_RAW) |
| 1281 | continue; |
| 1282 | average.packages.counter[i] /= topo.num_packages; |
| 1283 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | static unsigned long long rdtsc(void) |
| 1287 | { |
| 1288 | unsigned int low, high; |
| 1289 | |
| 1290 | asm volatile("rdtsc" : "=a" (low), "=d" (high)); |
| 1291 | |
| 1292 | return low | ((unsigned long long)high) << 32; |
| 1293 | } |
| 1294 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1295 | /* |
| 1296 | * get_counters(...) |
| 1297 | * migrate to cpu |
| 1298 | * acquire and record local counters for that cpu |
| 1299 | */ |
| 1300 | int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 1301 | { |
| 1302 | int cpu = t->cpu_id; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1303 | unsigned long long msr; |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1304 | int aperf_mperf_retry_count = 0; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1305 | struct msr_counter *mp; |
| 1306 | int i; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1307 | |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 1308 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1309 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1310 | return -1; |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 1311 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1312 | |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1313 | retry: |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1314 | t->tsc = rdtsc(); /* we are running on local CPU of interest */ |
| 1315 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1316 | 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] | 1317 | unsigned long long tsc_before, tsc_between, tsc_after, aperf_time, mperf_time; |
| 1318 | |
| 1319 | /* |
| 1320 | * The TSC, APERF and MPERF must be read together for |
| 1321 | * APERF/MPERF and MPERF/TSC to give accurate results. |
| 1322 | * |
| 1323 | * Unfortunately, APERF and MPERF are read by |
| 1324 | * individual system call, so delays may occur |
| 1325 | * between them. If the time to read them |
| 1326 | * varies by a large amount, we re-read them. |
| 1327 | */ |
| 1328 | |
| 1329 | /* |
| 1330 | * This initial dummy APERF read has been seen to |
| 1331 | * reduce jitter in the subsequent reads. |
| 1332 | */ |
| 1333 | |
Len Brown | 9c63a65 | 2012-10-31 01:29:52 -0400 | [diff] [blame] | 1334 | if (get_msr(cpu, MSR_IA32_APERF, &t->aperf)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1335 | return -3; |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1336 | |
| 1337 | t->tsc = rdtsc(); /* re-read close to APERF */ |
| 1338 | |
| 1339 | tsc_before = t->tsc; |
| 1340 | |
| 1341 | if (get_msr(cpu, MSR_IA32_APERF, &t->aperf)) |
| 1342 | return -3; |
| 1343 | |
| 1344 | tsc_between = rdtsc(); |
| 1345 | |
Len Brown | 9c63a65 | 2012-10-31 01:29:52 -0400 | [diff] [blame] | 1346 | if (get_msr(cpu, MSR_IA32_MPERF, &t->mperf)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1347 | return -4; |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1348 | |
| 1349 | tsc_after = rdtsc(); |
| 1350 | |
| 1351 | aperf_time = tsc_between - tsc_before; |
| 1352 | mperf_time = tsc_after - tsc_between; |
| 1353 | |
| 1354 | /* |
| 1355 | * If the system call latency to read APERF and MPERF |
| 1356 | * differ by more than 2x, then try again. |
| 1357 | */ |
| 1358 | if ((aperf_time > (2 * mperf_time)) || (mperf_time > (2 * aperf_time))) { |
| 1359 | aperf_mperf_retry_count++; |
| 1360 | if (aperf_mperf_retry_count < 5) |
| 1361 | goto retry; |
| 1362 | else |
| 1363 | warnx("cpu%d jitter %lld %lld", |
| 1364 | cpu, aperf_time, mperf_time); |
| 1365 | } |
| 1366 | aperf_mperf_retry_count = 0; |
| 1367 | |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 1368 | t->aperf = t->aperf * aperf_mperf_multiplier; |
| 1369 | t->mperf = t->mperf * aperf_mperf_multiplier; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1370 | } |
| 1371 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1372 | if (DO_BIC(BIC_IRQ)) |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1373 | t->irq_count = irqs_per_cpu[cpu]; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1374 | if (DO_BIC(BIC_SMI)) { |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 1375 | if (get_msr(cpu, MSR_SMI_COUNT, &msr)) |
| 1376 | return -5; |
| 1377 | t->smi_count = msr & 0xFFFFFFFF; |
| 1378 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1379 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1380 | if (use_c1_residency_msr) { |
| 1381 | if (get_msr(cpu, MSR_CORE_C1_RES, &t->c1)) |
| 1382 | return -6; |
| 1383 | } |
| 1384 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1385 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 1386 | if (get_msr(cpu, mp->msr_num, &t->counter[i])) |
| 1387 | return -10; |
| 1388 | } |
| 1389 | |
| 1390 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1391 | /* collect core counters only for 1st thread in core */ |
| 1392 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 1393 | return 0; |
| 1394 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1395 | if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1396 | if (get_msr(cpu, MSR_CORE_C3_RESIDENCY, &c->c3)) |
| 1397 | return -6; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1398 | } |
| 1399 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1400 | if (DO_BIC(BIC_CPU_c6) && !do_knl_cstates) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1401 | if (get_msr(cpu, MSR_CORE_C6_RESIDENCY, &c->c6)) |
| 1402 | return -7; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1403 | } else if (do_knl_cstates) { |
| 1404 | if (get_msr(cpu, MSR_KNL_CORE_C6_RESIDENCY, &c->c6)) |
| 1405 | return -7; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1406 | } |
| 1407 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1408 | if (DO_BIC(BIC_CPU_c7)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1409 | if (get_msr(cpu, MSR_CORE_C7_RESIDENCY, &c->c7)) |
| 1410 | return -8; |
| 1411 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1412 | if (DO_BIC(BIC_CoreTmp)) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1413 | if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr)) |
| 1414 | return -9; |
| 1415 | c->core_temp_c = tcc_activation_temp - ((msr >> 16) & 0x7F); |
| 1416 | } |
| 1417 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1418 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 1419 | if (get_msr(cpu, mp->msr_num, &c->counter[i])) |
| 1420 | return -10; |
| 1421 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1422 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1423 | /* collect package counters only for 1st core in package */ |
| 1424 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 1425 | return 0; |
| 1426 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1427 | if (do_skl_residency) { |
| 1428 | if (get_msr(cpu, MSR_PKG_WEIGHTED_CORE_C0_RES, &p->pkg_wtd_core_c0)) |
| 1429 | return -10; |
| 1430 | if (get_msr(cpu, MSR_PKG_ANY_CORE_C0_RES, &p->pkg_any_core_c0)) |
| 1431 | return -11; |
| 1432 | if (get_msr(cpu, MSR_PKG_ANY_GFXE_C0_RES, &p->pkg_any_gfxe_c0)) |
| 1433 | return -12; |
| 1434 | if (get_msr(cpu, MSR_PKG_BOTH_CORE_GFXE_C0_RES, &p->pkg_both_core_gfxe_c0)) |
| 1435 | return -13; |
| 1436 | } |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1437 | if (do_pc3) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1438 | if (get_msr(cpu, MSR_PKG_C3_RESIDENCY, &p->pc3)) |
| 1439 | return -9; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1440 | if (do_pc6) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1441 | if (get_msr(cpu, MSR_PKG_C6_RESIDENCY, &p->pc6)) |
| 1442 | return -10; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1443 | if (do_pc2) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1444 | if (get_msr(cpu, MSR_PKG_C2_RESIDENCY, &p->pc2)) |
| 1445 | return -11; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1446 | if (do_pc7) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1447 | if (get_msr(cpu, MSR_PKG_C7_RESIDENCY, &p->pc7)) |
| 1448 | return -12; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1449 | if (do_c8_c9_c10) { |
| 1450 | if (get_msr(cpu, MSR_PKG_C8_RESIDENCY, &p->pc8)) |
| 1451 | return -13; |
| 1452 | if (get_msr(cpu, MSR_PKG_C9_RESIDENCY, &p->pc9)) |
| 1453 | return -13; |
| 1454 | if (get_msr(cpu, MSR_PKG_C10_RESIDENCY, &p->pc10)) |
| 1455 | return -13; |
| 1456 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1457 | if (do_rapl & RAPL_PKG) { |
| 1458 | if (get_msr(cpu, MSR_PKG_ENERGY_STATUS, &msr)) |
| 1459 | return -13; |
| 1460 | p->energy_pkg = msr & 0xFFFFFFFF; |
| 1461 | } |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 1462 | if (do_rapl & RAPL_CORES_ENERGY_STATUS) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1463 | if (get_msr(cpu, MSR_PP0_ENERGY_STATUS, &msr)) |
| 1464 | return -14; |
| 1465 | p->energy_cores = msr & 0xFFFFFFFF; |
| 1466 | } |
| 1467 | if (do_rapl & RAPL_DRAM) { |
| 1468 | if (get_msr(cpu, MSR_DRAM_ENERGY_STATUS, &msr)) |
| 1469 | return -15; |
| 1470 | p->energy_dram = msr & 0xFFFFFFFF; |
| 1471 | } |
| 1472 | if (do_rapl & RAPL_GFX) { |
| 1473 | if (get_msr(cpu, MSR_PP1_ENERGY_STATUS, &msr)) |
| 1474 | return -16; |
| 1475 | p->energy_gfx = msr & 0xFFFFFFFF; |
| 1476 | } |
| 1477 | if (do_rapl & RAPL_PKG_PERF_STATUS) { |
| 1478 | if (get_msr(cpu, MSR_PKG_PERF_STATUS, &msr)) |
| 1479 | return -16; |
| 1480 | p->rapl_pkg_perf_status = msr & 0xFFFFFFFF; |
| 1481 | } |
| 1482 | if (do_rapl & RAPL_DRAM_PERF_STATUS) { |
| 1483 | if (get_msr(cpu, MSR_DRAM_PERF_STATUS, &msr)) |
| 1484 | return -16; |
| 1485 | p->rapl_dram_perf_status = msr & 0xFFFFFFFF; |
| 1486 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1487 | if (DO_BIC(BIC_PkgTmp)) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1488 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr)) |
| 1489 | return -17; |
| 1490 | p->pkg_temp_c = tcc_activation_temp - ((msr >> 16) & 0x7F); |
| 1491 | } |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1492 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1493 | if (DO_BIC(BIC_GFX_rc6)) |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1494 | p->gfx_rc6_ms = gfx_cur_rc6_ms; |
| 1495 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1496 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1497 | p->gfx_mhz = gfx_cur_mhz; |
| 1498 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1499 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1500 | if (get_msr(cpu, mp->msr_num, &p->counter[i])) |
| 1501 | return -10; |
| 1502 | } |
| 1503 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1504 | return 0; |
| 1505 | } |
| 1506 | |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1507 | /* |
| 1508 | * MSR_PKG_CST_CONFIG_CONTROL decoding for pkg_cstate_limit: |
| 1509 | * If you change the values, note they are used both in comparisons |
| 1510 | * (>= PCL__7) and to index pkg_cstate_limit_strings[]. |
| 1511 | */ |
| 1512 | |
| 1513 | #define PCLUKN 0 /* Unknown */ |
| 1514 | #define PCLRSV 1 /* Reserved */ |
| 1515 | #define PCL__0 2 /* PC0 */ |
| 1516 | #define PCL__1 3 /* PC1 */ |
| 1517 | #define PCL__2 4 /* PC2 */ |
| 1518 | #define PCL__3 5 /* PC3 */ |
| 1519 | #define PCL__4 6 /* PC4 */ |
| 1520 | #define PCL__6 7 /* PC6 */ |
| 1521 | #define PCL_6N 8 /* PC6 No Retention */ |
| 1522 | #define PCL_6R 9 /* PC6 Retention */ |
| 1523 | #define PCL__7 10 /* PC7 */ |
| 1524 | #define PCL_7S 11 /* PC7 Shrink */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1525 | #define PCL__8 12 /* PC8 */ |
| 1526 | #define PCL__9 13 /* PC9 */ |
| 1527 | #define PCLUNL 14 /* Unlimited */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1528 | |
| 1529 | int pkg_cstate_limit = PCLUKN; |
| 1530 | char *pkg_cstate_limit_strings[] = { "reserved", "unknown", "pc0", "pc1", "pc2", |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1531 | "pc3", "pc4", "pc6", "pc6n", "pc6r", "pc7", "pc7s", "pc8", "pc9", "unlimited"}; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1532 | |
Len Brown | e9257f5 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 1533 | 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}; |
| 1534 | 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}; |
| 1535 | 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}; |
| 1536 | 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, PCLRSV, PCLRSV}; |
| 1537 | int amt_pkg_cstate_limits[16] = {PCL__0, PCL__1, PCL__2, PCLRSV, PCLRSV, PCLRSV, PCL__6, PCL__7, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; |
| 1538 | 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] | 1539 | 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] | 1540 | 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] | 1541 | |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 1542 | |
| 1543 | static void |
| 1544 | calculate_tsc_tweak() |
| 1545 | { |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 1546 | tsc_tweak = base_hz / tsc_hz; |
| 1547 | } |
| 1548 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1549 | static void |
| 1550 | dump_nhm_platform_info(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1551 | { |
| 1552 | unsigned long long msr; |
| 1553 | unsigned int ratio; |
| 1554 | |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 1555 | get_msr(base_cpu, MSR_PLATFORM_INFO, &msr); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1556 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1557 | 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] | 1558 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1559 | ratio = (msr >> 40) & 0xFF; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1560 | fprintf(outf, "%d * %.0f = %.0f MHz max efficiency frequency\n", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1561 | ratio, bclk, ratio * bclk); |
| 1562 | |
| 1563 | ratio = (msr >> 8) & 0xFF; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1564 | fprintf(outf, "%d * %.0f = %.0f MHz base frequency\n", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1565 | ratio, bclk, ratio * bclk); |
| 1566 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1567 | get_msr(base_cpu, MSR_IA32_POWER_CTL, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1568 | 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] | 1569 | base_cpu, msr, msr & 0x2 ? "EN" : "DIS"); |
Len Brown | 6792041 | 2013-01-31 15:22:15 -0500 | [diff] [blame] | 1570 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1571 | return; |
| 1572 | } |
| 1573 | |
| 1574 | static void |
| 1575 | dump_hsw_turbo_ratio_limits(void) |
| 1576 | { |
| 1577 | unsigned long long msr; |
| 1578 | unsigned int ratio; |
| 1579 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1580 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT2, &msr); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1581 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1582 | 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] | 1583 | |
| 1584 | ratio = (msr >> 8) & 0xFF; |
| 1585 | if (ratio) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1586 | fprintf(outf, "%d * %.0f = %.0f MHz max turbo 18 active cores\n", |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1587 | ratio, bclk, ratio * bclk); |
| 1588 | |
| 1589 | ratio = (msr >> 0) & 0xFF; |
| 1590 | if (ratio) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1591 | fprintf(outf, "%d * %.0f = %.0f MHz max turbo 17 active cores\n", |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1592 | ratio, bclk, ratio * bclk); |
| 1593 | return; |
| 1594 | } |
| 1595 | |
| 1596 | static void |
| 1597 | dump_ivt_turbo_ratio_limits(void) |
| 1598 | { |
| 1599 | unsigned long long msr; |
| 1600 | unsigned int ratio; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1601 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1602 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT1, &msr); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1603 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1604 | 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] | 1605 | |
| 1606 | ratio = (msr >> 56) & 0xFF; |
| 1607 | if (ratio) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1608 | fprintf(outf, "%d * %.0f = %.0f MHz max turbo 16 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1609 | ratio, bclk, ratio * bclk); |
| 1610 | |
| 1611 | ratio = (msr >> 48) & 0xFF; |
| 1612 | if (ratio) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1613 | fprintf(outf, "%d * %.0f = %.0f MHz max turbo 15 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1614 | ratio, bclk, ratio * bclk); |
| 1615 | |
| 1616 | ratio = (msr >> 40) & 0xFF; |
| 1617 | if (ratio) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1618 | fprintf(outf, "%d * %.0f = %.0f MHz max turbo 14 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1619 | ratio, bclk, ratio * bclk); |
| 1620 | |
| 1621 | ratio = (msr >> 32) & 0xFF; |
| 1622 | if (ratio) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1623 | fprintf(outf, "%d * %.0f = %.0f MHz max turbo 13 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1624 | ratio, bclk, ratio * bclk); |
| 1625 | |
| 1626 | ratio = (msr >> 24) & 0xFF; |
| 1627 | if (ratio) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1628 | fprintf(outf, "%d * %.0f = %.0f MHz max turbo 12 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1629 | ratio, bclk, ratio * bclk); |
| 1630 | |
| 1631 | ratio = (msr >> 16) & 0xFF; |
| 1632 | if (ratio) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1633 | fprintf(outf, "%d * %.0f = %.0f MHz max turbo 11 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1634 | ratio, bclk, ratio * bclk); |
| 1635 | |
| 1636 | ratio = (msr >> 8) & 0xFF; |
| 1637 | if (ratio) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1638 | fprintf(outf, "%d * %.0f = %.0f MHz max turbo 10 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1639 | ratio, bclk, ratio * bclk); |
| 1640 | |
| 1641 | ratio = (msr >> 0) & 0xFF; |
| 1642 | if (ratio) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1643 | fprintf(outf, "%d * %.0f = %.0f MHz max turbo 9 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1644 | ratio, bclk, ratio * bclk); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1645 | return; |
| 1646 | } |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1647 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1648 | static void |
| 1649 | dump_nhm_turbo_ratio_limits(void) |
| 1650 | { |
| 1651 | unsigned long long msr; |
| 1652 | unsigned int ratio; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1653 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1654 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT, &msr); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1655 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1656 | 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] | 1657 | |
| 1658 | ratio = (msr >> 56) & 0xFF; |
| 1659 | if (ratio) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1660 | fprintf(outf, "%d * %.0f = %.0f MHz max turbo 8 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1661 | ratio, bclk, ratio * bclk); |
| 1662 | |
| 1663 | ratio = (msr >> 48) & 0xFF; |
| 1664 | if (ratio) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1665 | fprintf(outf, "%d * %.0f = %.0f MHz max turbo 7 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1666 | ratio, bclk, ratio * bclk); |
| 1667 | |
| 1668 | ratio = (msr >> 40) & 0xFF; |
| 1669 | if (ratio) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1670 | fprintf(outf, "%d * %.0f = %.0f MHz max turbo 6 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1671 | ratio, bclk, ratio * bclk); |
| 1672 | |
| 1673 | ratio = (msr >> 32) & 0xFF; |
| 1674 | if (ratio) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1675 | fprintf(outf, "%d * %.0f = %.0f MHz max turbo 5 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1676 | ratio, bclk, ratio * bclk); |
| 1677 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1678 | ratio = (msr >> 24) & 0xFF; |
| 1679 | if (ratio) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1680 | fprintf(outf, "%d * %.0f = %.0f MHz max turbo 4 active cores\n", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1681 | ratio, bclk, ratio * bclk); |
| 1682 | |
| 1683 | ratio = (msr >> 16) & 0xFF; |
| 1684 | if (ratio) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1685 | fprintf(outf, "%d * %.0f = %.0f MHz max turbo 3 active cores\n", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1686 | ratio, bclk, ratio * bclk); |
| 1687 | |
| 1688 | ratio = (msr >> 8) & 0xFF; |
| 1689 | if (ratio) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1690 | fprintf(outf, "%d * %.0f = %.0f MHz max turbo 2 active cores\n", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1691 | ratio, bclk, ratio * bclk); |
| 1692 | |
| 1693 | ratio = (msr >> 0) & 0xFF; |
| 1694 | if (ratio) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1695 | fprintf(outf, "%d * %.0f = %.0f MHz max turbo 1 active cores\n", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1696 | ratio, bclk, ratio * bclk); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1697 | return; |
| 1698 | } |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 1699 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1700 | static void |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1701 | dump_knl_turbo_ratio_limits(void) |
| 1702 | { |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 1703 | const unsigned int buckets_no = 7; |
| 1704 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1705 | unsigned long long msr; |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 1706 | int delta_cores, delta_ratio; |
| 1707 | int i, b_nr; |
| 1708 | unsigned int cores[buckets_no]; |
| 1709 | unsigned int ratio[buckets_no]; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1710 | |
Srinivas Pandruvada | ebf5926 | 2016-07-06 16:07:56 -0700 | [diff] [blame] | 1711 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT, &msr); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1712 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1713 | fprintf(outf, "cpu%d: MSR_TURBO_RATIO_LIMIT: 0x%08llx\n", |
Len Brown | bfae205 | 2015-06-17 12:27:21 -0400 | [diff] [blame] | 1714 | base_cpu, msr); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1715 | |
| 1716 | /** |
| 1717 | * Turbo encoding in KNL is as follows: |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 1718 | * [0] -- Reserved |
| 1719 | * [7:1] -- Base value of number of active cores of bucket 1. |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1720 | * [15:8] -- Base value of freq ratio of bucket 1. |
| 1721 | * [20:16] -- +ve delta of number of active cores of bucket 2. |
| 1722 | * i.e. active cores of bucket 2 = |
| 1723 | * active cores of bucket 1 + delta |
| 1724 | * [23:21] -- Negative delta of freq ratio of bucket 2. |
| 1725 | * i.e. freq ratio of bucket 2 = |
| 1726 | * freq ratio of bucket 1 - delta |
| 1727 | * [28:24]-- +ve delta of number of active cores of bucket 3. |
| 1728 | * [31:29]-- -ve delta of freq ratio of bucket 3. |
| 1729 | * [36:32]-- +ve delta of number of active cores of bucket 4. |
| 1730 | * [39:37]-- -ve delta of freq ratio of bucket 4. |
| 1731 | * [44:40]-- +ve delta of number of active cores of bucket 5. |
| 1732 | * [47:45]-- -ve delta of freq ratio of bucket 5. |
| 1733 | * [52:48]-- +ve delta of number of active cores of bucket 6. |
| 1734 | * [55:53]-- -ve delta of freq ratio of bucket 6. |
| 1735 | * [60:56]-- +ve delta of number of active cores of bucket 7. |
| 1736 | * [63:61]-- -ve delta of freq ratio of bucket 7. |
| 1737 | */ |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1738 | |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 1739 | b_nr = 0; |
| 1740 | cores[b_nr] = (msr & 0xFF) >> 1; |
| 1741 | ratio[b_nr] = (msr >> 8) & 0xFF; |
| 1742 | |
| 1743 | for (i = 16; i < 64; i += 8) { |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1744 | delta_cores = (msr >> i) & 0x1F; |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 1745 | delta_ratio = (msr >> (i + 5)) & 0x7; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1746 | |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 1747 | cores[b_nr + 1] = cores[b_nr] + delta_cores; |
| 1748 | ratio[b_nr + 1] = ratio[b_nr] - delta_ratio; |
| 1749 | b_nr++; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1750 | } |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 1751 | |
| 1752 | for (i = buckets_no - 1; i >= 0; i--) |
| 1753 | if (i > 0 ? ratio[i] != ratio[i - 1] : 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1754 | fprintf(outf, |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1755 | "%d * %.0f = %.0f MHz max turbo %d active cores\n", |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 1756 | ratio[i], bclk, ratio[i] * bclk, cores[i]); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1757 | } |
| 1758 | |
| 1759 | static void |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1760 | dump_nhm_cst_cfg(void) |
| 1761 | { |
| 1762 | unsigned long long msr; |
| 1763 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1764 | get_msr(base_cpu, MSR_NHM_SNB_PKG_CST_CFG_CTL, &msr); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1765 | |
| 1766 | #define SNB_C1_AUTO_UNDEMOTE (1UL << 27) |
| 1767 | #define SNB_C3_AUTO_UNDEMOTE (1UL << 28) |
| 1768 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1769 | fprintf(outf, "cpu%d: MSR_NHM_SNB_PKG_CST_CFG_CTL: 0x%08llx", base_cpu, msr); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1770 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1771 | 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] | 1772 | (msr & SNB_C3_AUTO_UNDEMOTE) ? "UNdemote-C3, " : "", |
| 1773 | (msr & SNB_C1_AUTO_UNDEMOTE) ? "UNdemote-C1, " : "", |
| 1774 | (msr & NHM_C3_AUTO_DEMOTE) ? "demote-C3, " : "", |
| 1775 | (msr & NHM_C1_AUTO_DEMOTE) ? "demote-C1, " : "", |
| 1776 | (msr & (1 << 15)) ? "" : "UN", |
Len Brown | 6c34f16 | 2016-03-13 03:21:22 -0400 | [diff] [blame] | 1777 | (unsigned int)msr & 0xF, |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1778 | pkg_cstate_limit_strings[pkg_cstate_limit]); |
| 1779 | return; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1780 | } |
| 1781 | |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 1782 | static void |
| 1783 | dump_config_tdp(void) |
| 1784 | { |
| 1785 | unsigned long long msr; |
| 1786 | |
| 1787 | get_msr(base_cpu, MSR_CONFIG_TDP_NOMINAL, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1788 | 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] | 1789 | fprintf(outf, " (base_ratio=%d)\n", (unsigned int)msr & 0xFF); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 1790 | |
| 1791 | get_msr(base_cpu, MSR_CONFIG_TDP_LEVEL_1, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1792 | 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] | 1793 | if (msr) { |
Chen Yu | 685b535 | 2015-12-13 21:09:31 +0800 | [diff] [blame] | 1794 | fprintf(outf, "PKG_MIN_PWR_LVL1=%d ", (unsigned int)(msr >> 48) & 0x7FFF); |
| 1795 | fprintf(outf, "PKG_MAX_PWR_LVL1=%d ", (unsigned int)(msr >> 32) & 0x7FFF); |
| 1796 | fprintf(outf, "LVL1_RATIO=%d ", (unsigned int)(msr >> 16) & 0xFF); |
| 1797 | fprintf(outf, "PKG_TDP_LVL1=%d", (unsigned int)(msr) & 0x7FFF); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 1798 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1799 | fprintf(outf, ")\n"); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 1800 | |
| 1801 | get_msr(base_cpu, MSR_CONFIG_TDP_LEVEL_2, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1802 | 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] | 1803 | if (msr) { |
Chen Yu | 685b535 | 2015-12-13 21:09:31 +0800 | [diff] [blame] | 1804 | fprintf(outf, "PKG_MIN_PWR_LVL2=%d ", (unsigned int)(msr >> 48) & 0x7FFF); |
| 1805 | fprintf(outf, "PKG_MAX_PWR_LVL2=%d ", (unsigned int)(msr >> 32) & 0x7FFF); |
| 1806 | fprintf(outf, "LVL2_RATIO=%d ", (unsigned int)(msr >> 16) & 0xFF); |
| 1807 | fprintf(outf, "PKG_TDP_LVL2=%d", (unsigned int)(msr) & 0x7FFF); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 1808 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1809 | fprintf(outf, ")\n"); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 1810 | |
| 1811 | get_msr(base_cpu, MSR_CONFIG_TDP_CONTROL, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1812 | 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] | 1813 | if ((msr) & 0x3) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1814 | fprintf(outf, "TDP_LEVEL=%d ", (unsigned int)(msr) & 0x3); |
| 1815 | fprintf(outf, " lock=%d", (unsigned int)(msr >> 31) & 1); |
| 1816 | fprintf(outf, ")\n"); |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 1817 | |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 1818 | get_msr(base_cpu, MSR_TURBO_ACTIVATION_RATIO, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1819 | 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] | 1820 | fprintf(outf, "MAX_NON_TURBO_RATIO=%d", (unsigned int)(msr) & 0xFF); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1821 | fprintf(outf, " lock=%d", (unsigned int)(msr >> 31) & 1); |
| 1822 | fprintf(outf, ")\n"); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 1823 | } |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 1824 | |
| 1825 | unsigned int irtl_time_units[] = {1, 32, 1024, 32768, 1048576, 33554432, 0, 0 }; |
| 1826 | |
| 1827 | void print_irtl(void) |
| 1828 | { |
| 1829 | unsigned long long msr; |
| 1830 | |
| 1831 | get_msr(base_cpu, MSR_PKGC3_IRTL, &msr); |
| 1832 | fprintf(outf, "cpu%d: MSR_PKGC3_IRTL: 0x%08llx (", base_cpu, msr); |
| 1833 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 1834 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 1835 | |
| 1836 | get_msr(base_cpu, MSR_PKGC6_IRTL, &msr); |
| 1837 | fprintf(outf, "cpu%d: MSR_PKGC6_IRTL: 0x%08llx (", base_cpu, msr); |
| 1838 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 1839 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 1840 | |
| 1841 | get_msr(base_cpu, MSR_PKGC7_IRTL, &msr); |
| 1842 | fprintf(outf, "cpu%d: MSR_PKGC7_IRTL: 0x%08llx (", base_cpu, msr); |
| 1843 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 1844 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 1845 | |
| 1846 | if (!do_irtl_hsw) |
| 1847 | return; |
| 1848 | |
| 1849 | get_msr(base_cpu, MSR_PKGC8_IRTL, &msr); |
| 1850 | fprintf(outf, "cpu%d: MSR_PKGC8_IRTL: 0x%08llx (", base_cpu, msr); |
| 1851 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 1852 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 1853 | |
| 1854 | get_msr(base_cpu, MSR_PKGC9_IRTL, &msr); |
| 1855 | fprintf(outf, "cpu%d: MSR_PKGC9_IRTL: 0x%08llx (", base_cpu, msr); |
| 1856 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 1857 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 1858 | |
| 1859 | get_msr(base_cpu, MSR_PKGC10_IRTL, &msr); |
| 1860 | fprintf(outf, "cpu%d: MSR_PKGC10_IRTL: 0x%08llx (", base_cpu, msr); |
| 1861 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 1862 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 1863 | |
| 1864 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 1865 | void free_fd_percpu(void) |
| 1866 | { |
| 1867 | int i; |
| 1868 | |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 1869 | for (i = 0; i < topo.max_cpu_num + 1; ++i) { |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 1870 | if (fd_percpu[i] != 0) |
| 1871 | close(fd_percpu[i]); |
| 1872 | } |
| 1873 | |
| 1874 | free(fd_percpu); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 1875 | } |
| 1876 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1877 | void free_all_buffers(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1878 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1879 | CPU_FREE(cpu_present_set); |
| 1880 | cpu_present_set = NULL; |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 1881 | cpu_present_setsize = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1882 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1883 | CPU_FREE(cpu_affinity_set); |
| 1884 | cpu_affinity_set = NULL; |
| 1885 | cpu_affinity_setsize = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1886 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1887 | free(thread_even); |
| 1888 | free(core_even); |
| 1889 | free(package_even); |
| 1890 | |
| 1891 | thread_even = NULL; |
| 1892 | core_even = NULL; |
| 1893 | package_even = NULL; |
| 1894 | |
| 1895 | free(thread_odd); |
| 1896 | free(core_odd); |
| 1897 | free(package_odd); |
| 1898 | |
| 1899 | thread_odd = NULL; |
| 1900 | core_odd = NULL; |
| 1901 | package_odd = NULL; |
| 1902 | |
| 1903 | free(output_buffer); |
| 1904 | output_buffer = NULL; |
| 1905 | outp = NULL; |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 1906 | |
| 1907 | free_fd_percpu(); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1908 | |
| 1909 | free(irq_column_2_cpu); |
| 1910 | free(irqs_per_cpu); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1911 | } |
| 1912 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1913 | /* |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 1914 | * Open a file, and exit on failure |
| 1915 | */ |
| 1916 | FILE *fopen_or_die(const char *path, const char *mode) |
| 1917 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1918 | FILE *filep = fopen(path, mode); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 1919 | if (!filep) |
| 1920 | err(1, "%s: open failed", path); |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 1921 | return filep; |
| 1922 | } |
| 1923 | |
| 1924 | /* |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 1925 | * Parse a file containing a single int. |
| 1926 | */ |
| 1927 | int parse_int_file(const char *fmt, ...) |
| 1928 | { |
| 1929 | va_list args; |
| 1930 | char path[PATH_MAX]; |
| 1931 | FILE *filep; |
| 1932 | int value; |
| 1933 | |
| 1934 | va_start(args, fmt); |
| 1935 | vsnprintf(path, sizeof(path), fmt, args); |
| 1936 | va_end(args); |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 1937 | filep = fopen_or_die(path, "r"); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 1938 | if (fscanf(filep, "%d", &value) != 1) |
| 1939 | err(1, "%s: failed to parse number from file", path); |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 1940 | fclose(filep); |
| 1941 | return value; |
| 1942 | } |
| 1943 | |
| 1944 | /* |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 1945 | * get_cpu_position_in_core(cpu) |
| 1946 | * return the position of the CPU among its HT siblings in the core |
| 1947 | * return -1 if the sibling is not in list |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1948 | */ |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 1949 | int get_cpu_position_in_core(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1950 | { |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 1951 | char path[64]; |
| 1952 | FILE *filep; |
| 1953 | int this_cpu; |
| 1954 | char character; |
| 1955 | int i; |
| 1956 | |
| 1957 | sprintf(path, |
| 1958 | "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", |
| 1959 | cpu); |
| 1960 | filep = fopen(path, "r"); |
| 1961 | if (filep == NULL) { |
| 1962 | perror(path); |
| 1963 | exit(1); |
| 1964 | } |
| 1965 | |
| 1966 | for (i = 0; i < topo.num_threads_per_core; i++) { |
| 1967 | fscanf(filep, "%d", &this_cpu); |
| 1968 | if (this_cpu == cpu) { |
| 1969 | fclose(filep); |
| 1970 | return i; |
| 1971 | } |
| 1972 | |
| 1973 | /* Account for no separator after last thread*/ |
| 1974 | if (i != (topo.num_threads_per_core - 1)) |
| 1975 | fscanf(filep, "%c", &character); |
| 1976 | } |
| 1977 | |
| 1978 | fclose(filep); |
| 1979 | return -1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1980 | } |
| 1981 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1982 | /* |
| 1983 | * cpu_is_first_core_in_package(cpu) |
| 1984 | * return 1 if given CPU is 1st core in package |
| 1985 | */ |
| 1986 | int cpu_is_first_core_in_package(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1987 | { |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 1988 | 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] | 1989 | } |
| 1990 | |
| 1991 | int get_physical_package_id(int cpu) |
| 1992 | { |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 1993 | 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] | 1994 | } |
| 1995 | |
| 1996 | int get_core_id(int cpu) |
| 1997 | { |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 1998 | 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] | 1999 | } |
| 2000 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2001 | int get_num_ht_siblings(int cpu) |
| 2002 | { |
| 2003 | char path[80]; |
| 2004 | FILE *filep; |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2005 | int sib1; |
| 2006 | int matches = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2007 | char character; |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2008 | char str[100]; |
| 2009 | char *ch; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2010 | |
| 2011 | 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] | 2012 | filep = fopen_or_die(path, "r"); |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2013 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2014 | /* |
| 2015 | * file format: |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2016 | * A ',' separated or '-' separated set of numbers |
| 2017 | * (eg 1-2 or 1,3,4,5) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2018 | */ |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2019 | fscanf(filep, "%d%c\n", &sib1, &character); |
| 2020 | fseek(filep, 0, SEEK_SET); |
| 2021 | fgets(str, 100, filep); |
| 2022 | ch = strchr(str, character); |
| 2023 | while (ch != NULL) { |
| 2024 | matches++; |
| 2025 | ch = strchr(ch+1, character); |
| 2026 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2027 | |
| 2028 | fclose(filep); |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2029 | return matches+1; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2030 | } |
| 2031 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2032 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2033 | * run func(thread, core, package) in topology order |
| 2034 | * skip non-present cpus |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2035 | */ |
| 2036 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2037 | int for_all_cpus_2(int (func)(struct thread_data *, struct core_data *, |
| 2038 | struct pkg_data *, struct thread_data *, struct core_data *, |
| 2039 | struct pkg_data *), struct thread_data *thread_base, |
| 2040 | struct core_data *core_base, struct pkg_data *pkg_base, |
| 2041 | struct thread_data *thread_base2, struct core_data *core_base2, |
| 2042 | struct pkg_data *pkg_base2) |
| 2043 | { |
| 2044 | int retval, pkg_no, core_no, thread_no; |
| 2045 | |
| 2046 | for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { |
| 2047 | for (core_no = 0; core_no < topo.num_cores_per_pkg; ++core_no) { |
| 2048 | for (thread_no = 0; thread_no < |
| 2049 | topo.num_threads_per_core; ++thread_no) { |
| 2050 | struct thread_data *t, *t2; |
| 2051 | struct core_data *c, *c2; |
| 2052 | struct pkg_data *p, *p2; |
| 2053 | |
| 2054 | t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); |
| 2055 | |
| 2056 | if (cpu_is_not_present(t->cpu_id)) |
| 2057 | continue; |
| 2058 | |
| 2059 | t2 = GET_THREAD(thread_base2, thread_no, core_no, pkg_no); |
| 2060 | |
| 2061 | c = GET_CORE(core_base, core_no, pkg_no); |
| 2062 | c2 = GET_CORE(core_base2, core_no, pkg_no); |
| 2063 | |
| 2064 | p = GET_PKG(pkg_base, pkg_no); |
| 2065 | p2 = GET_PKG(pkg_base2, pkg_no); |
| 2066 | |
| 2067 | retval = func(t, c, p, t2, c2, p2); |
| 2068 | if (retval) |
| 2069 | return retval; |
| 2070 | } |
| 2071 | } |
| 2072 | } |
| 2073 | return 0; |
| 2074 | } |
| 2075 | |
| 2076 | /* |
| 2077 | * run func(cpu) on every cpu in /proc/stat |
| 2078 | * return max_cpu number |
| 2079 | */ |
| 2080 | int for_all_proc_cpus(int (func)(int)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2081 | { |
| 2082 | FILE *fp; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2083 | int cpu_num; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2084 | int retval; |
| 2085 | |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 2086 | fp = fopen_or_die(proc_stat, "r"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2087 | |
| 2088 | 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] | 2089 | if (retval != 0) |
| 2090 | err(1, "%s: failed to parse format", proc_stat); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2091 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2092 | while (1) { |
| 2093 | 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] | 2094 | if (retval != 1) |
| 2095 | break; |
| 2096 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2097 | retval = func(cpu_num); |
| 2098 | if (retval) { |
| 2099 | fclose(fp); |
| 2100 | return(retval); |
| 2101 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2102 | } |
| 2103 | fclose(fp); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2104 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | void re_initialize(void) |
| 2108 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2109 | free_all_buffers(); |
| 2110 | setup_all_buffers(); |
| 2111 | printf("turbostat: re-initialized with num_cpus %d\n", topo.num_cpus); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2112 | } |
| 2113 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2114 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2115 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2116 | * count_cpus() |
| 2117 | * remember the last one seen, it will be the max |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2118 | */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2119 | int count_cpus(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2120 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2121 | if (topo.max_cpu_num < cpu) |
| 2122 | topo.max_cpu_num = cpu; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2123 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2124 | topo.num_cpus += 1; |
| 2125 | return 0; |
| 2126 | } |
| 2127 | int mark_cpu_present(int cpu) |
| 2128 | { |
| 2129 | CPU_SET_S(cpu, cpu_present_setsize, cpu_present_set); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 2130 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2131 | } |
| 2132 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2133 | /* |
| 2134 | * snapshot_proc_interrupts() |
| 2135 | * |
| 2136 | * read and record summary of /proc/interrupts |
| 2137 | * |
| 2138 | * return 1 if config change requires a restart, else return 0 |
| 2139 | */ |
| 2140 | int snapshot_proc_interrupts(void) |
| 2141 | { |
| 2142 | static FILE *fp; |
| 2143 | int column, retval; |
| 2144 | |
| 2145 | if (fp == NULL) |
| 2146 | fp = fopen_or_die("/proc/interrupts", "r"); |
| 2147 | else |
| 2148 | rewind(fp); |
| 2149 | |
| 2150 | /* read 1st line of /proc/interrupts to get cpu* name for each column */ |
| 2151 | for (column = 0; column < topo.num_cpus; ++column) { |
| 2152 | int cpu_number; |
| 2153 | |
| 2154 | retval = fscanf(fp, " CPU%d", &cpu_number); |
| 2155 | if (retval != 1) |
| 2156 | break; |
| 2157 | |
| 2158 | if (cpu_number > topo.max_cpu_num) { |
| 2159 | warn("/proc/interrupts: cpu%d: > %d", cpu_number, topo.max_cpu_num); |
| 2160 | return 1; |
| 2161 | } |
| 2162 | |
| 2163 | irq_column_2_cpu[column] = cpu_number; |
| 2164 | irqs_per_cpu[cpu_number] = 0; |
| 2165 | } |
| 2166 | |
| 2167 | /* read /proc/interrupt count lines and sum up irqs per cpu */ |
| 2168 | while (1) { |
| 2169 | int column; |
| 2170 | char buf[64]; |
| 2171 | |
| 2172 | retval = fscanf(fp, " %s:", buf); /* flush irq# "N:" */ |
| 2173 | if (retval != 1) |
| 2174 | break; |
| 2175 | |
| 2176 | /* read the count per cpu */ |
| 2177 | for (column = 0; column < topo.num_cpus; ++column) { |
| 2178 | |
| 2179 | int cpu_number, irq_count; |
| 2180 | |
| 2181 | retval = fscanf(fp, " %d", &irq_count); |
| 2182 | if (retval != 1) |
| 2183 | break; |
| 2184 | |
| 2185 | cpu_number = irq_column_2_cpu[column]; |
| 2186 | irqs_per_cpu[cpu_number] += irq_count; |
| 2187 | |
| 2188 | } |
| 2189 | |
| 2190 | while (getc(fp) != '\n') |
| 2191 | ; /* flush interrupt description */ |
| 2192 | |
| 2193 | } |
| 2194 | return 0; |
| 2195 | } |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2196 | /* |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 2197 | * snapshot_gfx_rc6_ms() |
| 2198 | * |
| 2199 | * record snapshot of |
| 2200 | * /sys/class/drm/card0/power/rc6_residency_ms |
| 2201 | * |
| 2202 | * return 1 if config change requires a restart, else return 0 |
| 2203 | */ |
| 2204 | int snapshot_gfx_rc6_ms(void) |
| 2205 | { |
| 2206 | FILE *fp; |
| 2207 | int retval; |
| 2208 | |
| 2209 | fp = fopen_or_die("/sys/class/drm/card0/power/rc6_residency_ms", "r"); |
| 2210 | |
| 2211 | retval = fscanf(fp, "%lld", &gfx_cur_rc6_ms); |
| 2212 | if (retval != 1) |
| 2213 | err(1, "GFX rc6"); |
| 2214 | |
| 2215 | fclose(fp); |
| 2216 | |
| 2217 | return 0; |
| 2218 | } |
| 2219 | /* |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2220 | * snapshot_gfx_mhz() |
| 2221 | * |
| 2222 | * record snapshot of |
| 2223 | * /sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz |
| 2224 | * |
| 2225 | * return 1 if config change requires a restart, else return 0 |
| 2226 | */ |
| 2227 | int snapshot_gfx_mhz(void) |
| 2228 | { |
| 2229 | static FILE *fp; |
| 2230 | int retval; |
| 2231 | |
| 2232 | if (fp == NULL) |
| 2233 | fp = fopen_or_die("/sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz", "r"); |
| 2234 | else |
| 2235 | rewind(fp); |
| 2236 | |
| 2237 | retval = fscanf(fp, "%d", &gfx_cur_mhz); |
| 2238 | if (retval != 1) |
| 2239 | err(1, "GFX MHz"); |
| 2240 | |
| 2241 | return 0; |
| 2242 | } |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2243 | |
| 2244 | /* |
| 2245 | * snapshot /proc and /sys files |
| 2246 | * |
| 2247 | * return 1 if configuration restart needed, else return 0 |
| 2248 | */ |
| 2249 | int snapshot_proc_sysfs_files(void) |
| 2250 | { |
| 2251 | if (snapshot_proc_interrupts()) |
| 2252 | return 1; |
| 2253 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 2254 | if (DO_BIC(BIC_GFX_rc6)) |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 2255 | snapshot_gfx_rc6_ms(); |
| 2256 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 2257 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2258 | snapshot_gfx_mhz(); |
| 2259 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2260 | return 0; |
| 2261 | } |
| 2262 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2263 | void turbostat_loop() |
| 2264 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2265 | int retval; |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 2266 | int restarted = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2267 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2268 | restart: |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 2269 | restarted++; |
| 2270 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2271 | snapshot_proc_sysfs_files(); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2272 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 2273 | if (retval < -1) { |
| 2274 | exit(retval); |
| 2275 | } else if (retval == -1) { |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 2276 | if (restarted > 1) { |
| 2277 | exit(retval); |
| 2278 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2279 | re_initialize(); |
| 2280 | goto restart; |
| 2281 | } |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 2282 | restarted = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2283 | gettimeofday(&tv_even, (struct timezone *)NULL); |
| 2284 | |
| 2285 | while (1) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2286 | if (for_all_proc_cpus(cpu_is_not_present)) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2287 | re_initialize(); |
| 2288 | goto restart; |
| 2289 | } |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 2290 | nanosleep(&interval_ts, NULL); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2291 | if (snapshot_proc_sysfs_files()) |
| 2292 | goto restart; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2293 | retval = for_all_cpus(get_counters, ODD_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 2294 | if (retval < -1) { |
| 2295 | exit(retval); |
| 2296 | } else if (retval == -1) { |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 2297 | re_initialize(); |
| 2298 | goto restart; |
| 2299 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2300 | gettimeofday(&tv_odd, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2301 | timersub(&tv_odd, &tv_even, &tv_delta); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 2302 | if (for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS)) { |
| 2303 | re_initialize(); |
| 2304 | goto restart; |
| 2305 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2306 | compute_average(EVEN_COUNTERS); |
| 2307 | format_all_counters(EVEN_COUNTERS); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2308 | flush_output_stdout(); |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 2309 | nanosleep(&interval_ts, NULL); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2310 | if (snapshot_proc_sysfs_files()) |
| 2311 | goto restart; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2312 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 2313 | if (retval < -1) { |
| 2314 | exit(retval); |
| 2315 | } else if (retval == -1) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2316 | re_initialize(); |
| 2317 | goto restart; |
| 2318 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2319 | gettimeofday(&tv_even, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2320 | timersub(&tv_even, &tv_odd, &tv_delta); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 2321 | if (for_all_cpus_2(delta_cpu, EVEN_COUNTERS, ODD_COUNTERS)) { |
| 2322 | re_initialize(); |
| 2323 | goto restart; |
| 2324 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2325 | compute_average(ODD_COUNTERS); |
| 2326 | format_all_counters(ODD_COUNTERS); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2327 | flush_output_stdout(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2328 | } |
| 2329 | } |
| 2330 | |
| 2331 | void check_dev_msr() |
| 2332 | { |
| 2333 | struct stat sb; |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2334 | char pathname[32]; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2335 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2336 | sprintf(pathname, "/dev/cpu/%d/msr", base_cpu); |
| 2337 | if (stat(pathname, &sb)) |
Len Brown | a21d38c | 2015-03-24 16:37:35 -0400 | [diff] [blame] | 2338 | if (system("/sbin/modprobe msr > /dev/null 2>&1")) |
| 2339 | err(-5, "no /dev/cpu/0/msr, Try \"# modprobe msr\" "); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2340 | } |
| 2341 | |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2342 | void check_permissions() |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2343 | { |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2344 | struct __user_cap_header_struct cap_header_data; |
| 2345 | cap_user_header_t cap_header = &cap_header_data; |
| 2346 | struct __user_cap_data_struct cap_data_data; |
| 2347 | cap_user_data_t cap_data = &cap_data_data; |
| 2348 | extern int capget(cap_user_header_t hdrp, cap_user_data_t datap); |
| 2349 | int do_exit = 0; |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2350 | char pathname[32]; |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2351 | |
| 2352 | /* check for CAP_SYS_RAWIO */ |
| 2353 | cap_header->pid = getpid(); |
| 2354 | cap_header->version = _LINUX_CAPABILITY_VERSION; |
| 2355 | if (capget(cap_header, cap_data) < 0) |
| 2356 | err(-6, "capget(2) failed"); |
| 2357 | |
| 2358 | if ((cap_data->effective & (1 << CAP_SYS_RAWIO)) == 0) { |
| 2359 | do_exit++; |
| 2360 | warnx("capget(CAP_SYS_RAWIO) failed," |
| 2361 | " try \"# setcap cap_sys_rawio=ep %s\"", progname); |
| 2362 | } |
| 2363 | |
| 2364 | /* test file permissions */ |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2365 | sprintf(pathname, "/dev/cpu/%d/msr", base_cpu); |
| 2366 | if (euidaccess(pathname, R_OK)) { |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2367 | do_exit++; |
| 2368 | warn("/dev/cpu/0/msr open failed, try chown or chmod +r /dev/cpu/*/msr"); |
| 2369 | } |
| 2370 | |
| 2371 | /* if all else fails, thell them to be root */ |
| 2372 | if (do_exit) |
| 2373 | if (getuid() != 0) |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2374 | warnx("... or simply run as root"); |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2375 | |
| 2376 | if (do_exit) |
| 2377 | exit(-6); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2378 | } |
| 2379 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2380 | /* |
| 2381 | * NHM adds support for additional MSRs: |
| 2382 | * |
| 2383 | * MSR_SMI_COUNT 0x00000034 |
| 2384 | * |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 2385 | * MSR_PLATFORM_INFO 0x000000ce |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2386 | * MSR_NHM_SNB_PKG_CST_CFG_CTL 0x000000e2 |
| 2387 | * |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame^] | 2388 | * MSR_MISC_PWR_MGMT 0x000001aa |
| 2389 | * |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2390 | * MSR_PKG_C3_RESIDENCY 0x000003f8 |
| 2391 | * MSR_PKG_C6_RESIDENCY 0x000003f9 |
| 2392 | * MSR_CORE_C3_RESIDENCY 0x000003fc |
| 2393 | * MSR_CORE_C6_RESIDENCY 0x000003fd |
| 2394 | * |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2395 | * Side effect: |
| 2396 | * sets global pkg_cstate_limit to decode MSR_NHM_SNB_PKG_CST_CFG_CTL |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2397 | */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2398 | int probe_nhm_msrs(unsigned int family, unsigned int model) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2399 | { |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2400 | unsigned long long msr; |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 2401 | unsigned int base_ratio; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2402 | int *pkg_cstate_limits; |
| 2403 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2404 | if (!genuine_intel) |
| 2405 | return 0; |
| 2406 | |
| 2407 | if (family != 6) |
| 2408 | return 0; |
| 2409 | |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 2410 | bclk = discover_bclk(family, model); |
| 2411 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2412 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2413 | case INTEL_FAM6_NEHALEM_EP: /* Core i7, Xeon 5500 series - Bloomfield, Gainstown NHM-EP */ |
| 2414 | 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] | 2415 | case 0x1F: /* Core i7 and i5 Processor - Nehalem */ |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2416 | case INTEL_FAM6_WESTMERE: /* Westmere Client - Clarkdale, Arrandale */ |
| 2417 | case INTEL_FAM6_WESTMERE_EP: /* Westmere EP - Gulftown */ |
| 2418 | case INTEL_FAM6_NEHALEM_EX: /* Nehalem-EX Xeon - Beckton */ |
| 2419 | case INTEL_FAM6_WESTMERE_EX: /* Westmere-EX Xeon - Eagleton */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2420 | pkg_cstate_limits = nhm_pkg_cstate_limits; |
| 2421 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2422 | case INTEL_FAM6_SANDYBRIDGE: /* SNB */ |
| 2423 | case INTEL_FAM6_SANDYBRIDGE_X: /* SNB Xeon */ |
| 2424 | case INTEL_FAM6_IVYBRIDGE: /* IVB */ |
| 2425 | case INTEL_FAM6_IVYBRIDGE_X: /* IVB Xeon */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2426 | pkg_cstate_limits = snb_pkg_cstate_limits; |
| 2427 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2428 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 2429 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 2430 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 2431 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 2432 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 2433 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
| 2434 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 2435 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 2436 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 2437 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 2438 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 2439 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2440 | pkg_cstate_limits = hsw_pkg_cstate_limits; |
| 2441 | break; |
Len Brown | d8ebb44 | 2016-12-01 20:27:46 -0500 | [diff] [blame] | 2442 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
| 2443 | pkg_cstate_limits = skx_pkg_cstate_limits; |
| 2444 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2445 | case INTEL_FAM6_ATOM_SILVERMONT1: /* BYT */ |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame^] | 2446 | no_MSR_MISC_PWR_MGMT = 1; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2447 | case INTEL_FAM6_ATOM_SILVERMONT2: /* AVN */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2448 | pkg_cstate_limits = slv_pkg_cstate_limits; |
| 2449 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2450 | case INTEL_FAM6_ATOM_AIRMONT: /* AMT */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2451 | pkg_cstate_limits = amt_pkg_cstate_limits; |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame^] | 2452 | no_MSR_MISC_PWR_MGMT = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2453 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2454 | case INTEL_FAM6_XEON_PHI_KNL: /* PHI */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 2455 | case INTEL_FAM6_XEON_PHI_KNM: |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2456 | pkg_cstate_limits = phi_pkg_cstate_limits; |
| 2457 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2458 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
| 2459 | case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ |
Len Brown | e4085d5 | 2016-04-06 17:15:56 -0400 | [diff] [blame] | 2460 | pkg_cstate_limits = bxt_pkg_cstate_limits; |
| 2461 | break; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2462 | default: |
| 2463 | return 0; |
| 2464 | } |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2465 | get_msr(base_cpu, MSR_NHM_SNB_PKG_CST_CFG_CTL, &msr); |
Len Brown | e9257f5 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 2466 | pkg_cstate_limit = pkg_cstate_limits[msr & 0xF]; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2467 | |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 2468 | get_msr(base_cpu, MSR_PLATFORM_INFO, &msr); |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 2469 | base_ratio = (msr >> 8) & 0xFF; |
| 2470 | |
| 2471 | base_hz = base_ratio * bclk * 1000000; |
| 2472 | has_base_hz = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2473 | return 1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2474 | } |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2475 | int has_nhm_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 2476 | { |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2477 | switch (model) { |
| 2478 | /* Nehalem compatible, but do not include turbo-ratio limit support */ |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2479 | case INTEL_FAM6_NEHALEM_EX: /* Nehalem-EX Xeon - Beckton */ |
| 2480 | case INTEL_FAM6_WESTMERE_EX: /* Westmere-EX Xeon - Eagleton */ |
| 2481 | case INTEL_FAM6_XEON_PHI_KNL: /* PHI - Knights Landing (different MSR definition) */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 2482 | case INTEL_FAM6_XEON_PHI_KNM: |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2483 | return 0; |
| 2484 | default: |
| 2485 | return 1; |
| 2486 | } |
| 2487 | } |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2488 | int has_ivt_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 2489 | { |
| 2490 | if (!genuine_intel) |
| 2491 | return 0; |
| 2492 | |
| 2493 | if (family != 6) |
| 2494 | return 0; |
| 2495 | |
| 2496 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2497 | case INTEL_FAM6_IVYBRIDGE_X: /* IVB Xeon */ |
| 2498 | case INTEL_FAM6_HASWELL_X: /* HSW Xeon */ |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2499 | return 1; |
| 2500 | default: |
| 2501 | return 0; |
| 2502 | } |
| 2503 | } |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2504 | int has_hsw_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 2505 | { |
| 2506 | if (!genuine_intel) |
| 2507 | return 0; |
| 2508 | |
| 2509 | if (family != 6) |
| 2510 | return 0; |
| 2511 | |
| 2512 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2513 | case INTEL_FAM6_HASWELL_X: /* HSW Xeon */ |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2514 | return 1; |
| 2515 | default: |
| 2516 | return 0; |
| 2517 | } |
| 2518 | } |
| 2519 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2520 | int has_knl_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 2521 | { |
| 2522 | if (!genuine_intel) |
| 2523 | return 0; |
| 2524 | |
| 2525 | if (family != 6) |
| 2526 | return 0; |
| 2527 | |
| 2528 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2529 | case INTEL_FAM6_XEON_PHI_KNL: /* Knights Landing */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 2530 | case INTEL_FAM6_XEON_PHI_KNM: |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2531 | return 1; |
| 2532 | default: |
| 2533 | return 0; |
| 2534 | } |
| 2535 | } |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2536 | int has_config_tdp(unsigned int family, unsigned int model) |
| 2537 | { |
| 2538 | if (!genuine_intel) |
| 2539 | return 0; |
| 2540 | |
| 2541 | if (family != 6) |
| 2542 | return 0; |
| 2543 | |
| 2544 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2545 | case INTEL_FAM6_IVYBRIDGE: /* IVB */ |
| 2546 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 2547 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 2548 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 2549 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 2550 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 2551 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
| 2552 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 2553 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 2554 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 2555 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 2556 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 2557 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
| 2558 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2559 | |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2560 | case INTEL_FAM6_XEON_PHI_KNL: /* Knights Landing */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 2561 | case INTEL_FAM6_XEON_PHI_KNM: |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2562 | return 1; |
| 2563 | default: |
| 2564 | return 0; |
| 2565 | } |
| 2566 | } |
| 2567 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2568 | static void |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 2569 | dump_cstate_pstate_config_info(unsigned int family, unsigned int model) |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2570 | { |
| 2571 | if (!do_nhm_platform_info) |
| 2572 | return; |
| 2573 | |
| 2574 | dump_nhm_platform_info(); |
| 2575 | |
| 2576 | if (has_hsw_turbo_ratio_limit(family, model)) |
| 2577 | dump_hsw_turbo_ratio_limits(); |
| 2578 | |
| 2579 | if (has_ivt_turbo_ratio_limit(family, model)) |
| 2580 | dump_ivt_turbo_ratio_limits(); |
| 2581 | |
| 2582 | if (has_nhm_turbo_ratio_limit(family, model)) |
| 2583 | dump_nhm_turbo_ratio_limits(); |
| 2584 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2585 | if (has_knl_turbo_ratio_limit(family, model)) |
| 2586 | dump_knl_turbo_ratio_limits(); |
| 2587 | |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2588 | if (has_config_tdp(family, model)) |
| 2589 | dump_config_tdp(); |
| 2590 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2591 | dump_nhm_cst_cfg(); |
| 2592 | } |
| 2593 | |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2594 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2595 | /* |
| 2596 | * print_epb() |
| 2597 | * Decode the ENERGY_PERF_BIAS MSR |
| 2598 | */ |
| 2599 | int print_epb(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 2600 | { |
| 2601 | unsigned long long msr; |
| 2602 | char *epb_string; |
| 2603 | int cpu; |
| 2604 | |
| 2605 | if (!has_epb) |
| 2606 | return 0; |
| 2607 | |
| 2608 | cpu = t->cpu_id; |
| 2609 | |
| 2610 | /* EPB is per-package */ |
| 2611 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 2612 | return 0; |
| 2613 | |
| 2614 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2615 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2616 | return -1; |
| 2617 | } |
| 2618 | |
| 2619 | if (get_msr(cpu, MSR_IA32_ENERGY_PERF_BIAS, &msr)) |
| 2620 | return 0; |
| 2621 | |
Len Brown | e9be7dd | 2015-05-26 12:19:37 -0400 | [diff] [blame] | 2622 | switch (msr & 0xF) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2623 | case ENERGY_PERF_BIAS_PERFORMANCE: |
| 2624 | epb_string = "performance"; |
| 2625 | break; |
| 2626 | case ENERGY_PERF_BIAS_NORMAL: |
| 2627 | epb_string = "balanced"; |
| 2628 | break; |
| 2629 | case ENERGY_PERF_BIAS_POWERSAVE: |
| 2630 | epb_string = "powersave"; |
| 2631 | break; |
| 2632 | default: |
| 2633 | epb_string = "custom"; |
| 2634 | break; |
| 2635 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2636 | 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] | 2637 | |
| 2638 | return 0; |
| 2639 | } |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 2640 | /* |
| 2641 | * print_hwp() |
| 2642 | * Decode the MSR_HWP_CAPABILITIES |
| 2643 | */ |
| 2644 | int print_hwp(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 2645 | { |
| 2646 | unsigned long long msr; |
| 2647 | int cpu; |
| 2648 | |
| 2649 | if (!has_hwp) |
| 2650 | return 0; |
| 2651 | |
| 2652 | cpu = t->cpu_id; |
| 2653 | |
| 2654 | /* MSR_HWP_CAPABILITIES is per-package */ |
| 2655 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 2656 | return 0; |
| 2657 | |
| 2658 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2659 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 2660 | return -1; |
| 2661 | } |
| 2662 | |
| 2663 | if (get_msr(cpu, MSR_PM_ENABLE, &msr)) |
| 2664 | return 0; |
| 2665 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2666 | fprintf(outf, "cpu%d: MSR_PM_ENABLE: 0x%08llx (%sHWP)\n", |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 2667 | cpu, msr, (msr & (1 << 0)) ? "" : "No-"); |
| 2668 | |
| 2669 | /* MSR_PM_ENABLE[1] == 1 if HWP is enabled and MSRs visible */ |
| 2670 | if ((msr & (1 << 0)) == 0) |
| 2671 | return 0; |
| 2672 | |
| 2673 | if (get_msr(cpu, MSR_HWP_CAPABILITIES, &msr)) |
| 2674 | return 0; |
| 2675 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2676 | fprintf(outf, "cpu%d: MSR_HWP_CAPABILITIES: 0x%08llx " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 2677 | "(high 0x%x guar 0x%x eff 0x%x low 0x%x)\n", |
| 2678 | cpu, msr, |
| 2679 | (unsigned int)HWP_HIGHEST_PERF(msr), |
| 2680 | (unsigned int)HWP_GUARANTEED_PERF(msr), |
| 2681 | (unsigned int)HWP_MOSTEFFICIENT_PERF(msr), |
| 2682 | (unsigned int)HWP_LOWEST_PERF(msr)); |
| 2683 | |
| 2684 | if (get_msr(cpu, MSR_HWP_REQUEST, &msr)) |
| 2685 | return 0; |
| 2686 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2687 | fprintf(outf, "cpu%d: MSR_HWP_REQUEST: 0x%08llx " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 2688 | "(min 0x%x max 0x%x des 0x%x epp 0x%x window 0x%x pkg 0x%x)\n", |
| 2689 | cpu, msr, |
| 2690 | (unsigned int)(((msr) >> 0) & 0xff), |
| 2691 | (unsigned int)(((msr) >> 8) & 0xff), |
| 2692 | (unsigned int)(((msr) >> 16) & 0xff), |
| 2693 | (unsigned int)(((msr) >> 24) & 0xff), |
| 2694 | (unsigned int)(((msr) >> 32) & 0xff3), |
| 2695 | (unsigned int)(((msr) >> 42) & 0x1)); |
| 2696 | |
| 2697 | if (has_hwp_pkg) { |
| 2698 | if (get_msr(cpu, MSR_HWP_REQUEST_PKG, &msr)) |
| 2699 | return 0; |
| 2700 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2701 | fprintf(outf, "cpu%d: MSR_HWP_REQUEST_PKG: 0x%08llx " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 2702 | "(min 0x%x max 0x%x des 0x%x epp 0x%x window 0x%x)\n", |
| 2703 | cpu, msr, |
| 2704 | (unsigned int)(((msr) >> 0) & 0xff), |
| 2705 | (unsigned int)(((msr) >> 8) & 0xff), |
| 2706 | (unsigned int)(((msr) >> 16) & 0xff), |
| 2707 | (unsigned int)(((msr) >> 24) & 0xff), |
| 2708 | (unsigned int)(((msr) >> 32) & 0xff3)); |
| 2709 | } |
| 2710 | if (has_hwp_notify) { |
| 2711 | if (get_msr(cpu, MSR_HWP_INTERRUPT, &msr)) |
| 2712 | return 0; |
| 2713 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2714 | fprintf(outf, "cpu%d: MSR_HWP_INTERRUPT: 0x%08llx " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 2715 | "(%s_Guaranteed_Perf_Change, %s_Excursion_Min)\n", |
| 2716 | cpu, msr, |
| 2717 | ((msr) & 0x1) ? "EN" : "Dis", |
| 2718 | ((msr) & 0x2) ? "EN" : "Dis"); |
| 2719 | } |
| 2720 | if (get_msr(cpu, MSR_HWP_STATUS, &msr)) |
| 2721 | return 0; |
| 2722 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2723 | fprintf(outf, "cpu%d: MSR_HWP_STATUS: 0x%08llx " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 2724 | "(%sGuaranteed_Perf_Change, %sExcursion_Min)\n", |
| 2725 | cpu, msr, |
| 2726 | ((msr) & 0x1) ? "" : "No-", |
| 2727 | ((msr) & 0x2) ? "" : "No-"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2728 | |
| 2729 | return 0; |
| 2730 | } |
| 2731 | |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 2732 | /* |
| 2733 | * print_perf_limit() |
| 2734 | */ |
| 2735 | int print_perf_limit(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 2736 | { |
| 2737 | unsigned long long msr; |
| 2738 | int cpu; |
| 2739 | |
| 2740 | cpu = t->cpu_id; |
| 2741 | |
| 2742 | /* per-package */ |
| 2743 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 2744 | return 0; |
| 2745 | |
| 2746 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2747 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 2748 | return -1; |
| 2749 | } |
| 2750 | |
| 2751 | if (do_core_perf_limit_reasons) { |
| 2752 | get_msr(cpu, MSR_CORE_PERF_LIMIT_REASONS, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2753 | fprintf(outf, "cpu%d: MSR_CORE_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr); |
| 2754 | 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] | 2755 | (msr & 1 << 15) ? "bit15, " : "", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 2756 | (msr & 1 << 14) ? "bit14, " : "", |
Len Brown | e33cbe8 | 2015-03-13 16:30:57 -0400 | [diff] [blame] | 2757 | (msr & 1 << 13) ? "Transitions, " : "", |
| 2758 | (msr & 1 << 12) ? "MultiCoreTurbo, " : "", |
| 2759 | (msr & 1 << 11) ? "PkgPwrL2, " : "", |
| 2760 | (msr & 1 << 10) ? "PkgPwrL1, " : "", |
| 2761 | (msr & 1 << 9) ? "CorePwr, " : "", |
| 2762 | (msr & 1 << 8) ? "Amps, " : "", |
| 2763 | (msr & 1 << 6) ? "VR-Therm, " : "", |
| 2764 | (msr & 1 << 5) ? "Auto-HWP, " : "", |
| 2765 | (msr & 1 << 4) ? "Graphics, " : "", |
| 2766 | (msr & 1 << 2) ? "bit2, " : "", |
| 2767 | (msr & 1 << 1) ? "ThermStatus, " : "", |
| 2768 | (msr & 1 << 0) ? "PROCHOT, " : ""); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2769 | 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] | 2770 | (msr & 1 << 31) ? "bit31, " : "", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 2771 | (msr & 1 << 30) ? "bit30, " : "", |
Len Brown | e33cbe8 | 2015-03-13 16:30:57 -0400 | [diff] [blame] | 2772 | (msr & 1 << 29) ? "Transitions, " : "", |
| 2773 | (msr & 1 << 28) ? "MultiCoreTurbo, " : "", |
| 2774 | (msr & 1 << 27) ? "PkgPwrL2, " : "", |
| 2775 | (msr & 1 << 26) ? "PkgPwrL1, " : "", |
| 2776 | (msr & 1 << 25) ? "CorePwr, " : "", |
| 2777 | (msr & 1 << 24) ? "Amps, " : "", |
| 2778 | (msr & 1 << 22) ? "VR-Therm, " : "", |
| 2779 | (msr & 1 << 21) ? "Auto-HWP, " : "", |
| 2780 | (msr & 1 << 20) ? "Graphics, " : "", |
| 2781 | (msr & 1 << 18) ? "bit18, " : "", |
| 2782 | (msr & 1 << 17) ? "ThermStatus, " : "", |
| 2783 | (msr & 1 << 16) ? "PROCHOT, " : ""); |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 2784 | |
| 2785 | } |
| 2786 | if (do_gfx_perf_limit_reasons) { |
| 2787 | get_msr(cpu, MSR_GFX_PERF_LIMIT_REASONS, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2788 | fprintf(outf, "cpu%d: MSR_GFX_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr); |
| 2789 | fprintf(outf, " (Active: %s%s%s%s%s%s%s%s)", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 2790 | (msr & 1 << 0) ? "PROCHOT, " : "", |
| 2791 | (msr & 1 << 1) ? "ThermStatus, " : "", |
| 2792 | (msr & 1 << 4) ? "Graphics, " : "", |
| 2793 | (msr & 1 << 6) ? "VR-Therm, " : "", |
| 2794 | (msr & 1 << 8) ? "Amps, " : "", |
| 2795 | (msr & 1 << 9) ? "GFXPwr, " : "", |
| 2796 | (msr & 1 << 10) ? "PkgPwrL1, " : "", |
| 2797 | (msr & 1 << 11) ? "PkgPwrL2, " : ""); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2798 | fprintf(outf, " (Logged: %s%s%s%s%s%s%s%s)\n", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 2799 | (msr & 1 << 16) ? "PROCHOT, " : "", |
| 2800 | (msr & 1 << 17) ? "ThermStatus, " : "", |
| 2801 | (msr & 1 << 20) ? "Graphics, " : "", |
| 2802 | (msr & 1 << 22) ? "VR-Therm, " : "", |
| 2803 | (msr & 1 << 24) ? "Amps, " : "", |
| 2804 | (msr & 1 << 25) ? "GFXPwr, " : "", |
| 2805 | (msr & 1 << 26) ? "PkgPwrL1, " : "", |
| 2806 | (msr & 1 << 27) ? "PkgPwrL2, " : ""); |
| 2807 | } |
| 2808 | if (do_ring_perf_limit_reasons) { |
| 2809 | get_msr(cpu, MSR_RING_PERF_LIMIT_REASONS, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2810 | fprintf(outf, "cpu%d: MSR_RING_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr); |
| 2811 | fprintf(outf, " (Active: %s%s%s%s%s%s)", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 2812 | (msr & 1 << 0) ? "PROCHOT, " : "", |
| 2813 | (msr & 1 << 1) ? "ThermStatus, " : "", |
| 2814 | (msr & 1 << 6) ? "VR-Therm, " : "", |
| 2815 | (msr & 1 << 8) ? "Amps, " : "", |
| 2816 | (msr & 1 << 10) ? "PkgPwrL1, " : "", |
| 2817 | (msr & 1 << 11) ? "PkgPwrL2, " : ""); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2818 | fprintf(outf, " (Logged: %s%s%s%s%s%s)\n", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 2819 | (msr & 1 << 16) ? "PROCHOT, " : "", |
| 2820 | (msr & 1 << 17) ? "ThermStatus, " : "", |
| 2821 | (msr & 1 << 22) ? "VR-Therm, " : "", |
| 2822 | (msr & 1 << 24) ? "Amps, " : "", |
| 2823 | (msr & 1 << 26) ? "PkgPwrL1, " : "", |
| 2824 | (msr & 1 << 27) ? "PkgPwrL2, " : ""); |
| 2825 | } |
| 2826 | return 0; |
| 2827 | } |
| 2828 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2829 | #define RAPL_POWER_GRANULARITY 0x7FFF /* 15 bit power granularity */ |
| 2830 | #define RAPL_TIME_GRANULARITY 0x3F /* 6 bit time granularity */ |
| 2831 | |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 2832 | double get_tdp(unsigned int model) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2833 | { |
| 2834 | unsigned long long msr; |
| 2835 | |
| 2836 | if (do_rapl & RAPL_PKG_POWER_INFO) |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2837 | if (!get_msr(base_cpu, MSR_PKG_POWER_INFO, &msr)) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2838 | return ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units; |
| 2839 | |
| 2840 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2841 | case INTEL_FAM6_ATOM_SILVERMONT1: |
| 2842 | case INTEL_FAM6_ATOM_SILVERMONT2: |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2843 | return 30.0; |
| 2844 | default: |
| 2845 | return 135.0; |
| 2846 | } |
| 2847 | } |
| 2848 | |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 2849 | /* |
| 2850 | * rapl_dram_energy_units_probe() |
| 2851 | * Energy units are either hard-coded, or come from RAPL Energy Unit MSR. |
| 2852 | */ |
| 2853 | static double |
| 2854 | rapl_dram_energy_units_probe(int model, double rapl_energy_units) |
| 2855 | { |
| 2856 | /* only called for genuine_intel, family 6 */ |
| 2857 | |
| 2858 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2859 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 2860 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 2861 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 2862 | case INTEL_FAM6_XEON_PHI_KNL: /* KNL */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 2863 | case INTEL_FAM6_XEON_PHI_KNM: |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 2864 | return (rapl_dram_energy_units = 15.3 / 1000000); |
| 2865 | default: |
| 2866 | return (rapl_energy_units); |
| 2867 | } |
| 2868 | } |
| 2869 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2870 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2871 | /* |
| 2872 | * rapl_probe() |
| 2873 | * |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2874 | * sets do_rapl, rapl_power_units, rapl_energy_units, rapl_time_units |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2875 | */ |
| 2876 | void rapl_probe(unsigned int family, unsigned int model) |
| 2877 | { |
| 2878 | unsigned long long msr; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2879 | unsigned int time_unit; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2880 | double tdp; |
| 2881 | |
| 2882 | if (!genuine_intel) |
| 2883 | return; |
| 2884 | |
| 2885 | if (family != 6) |
| 2886 | return; |
| 2887 | |
| 2888 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2889 | case INTEL_FAM6_SANDYBRIDGE: |
| 2890 | case INTEL_FAM6_IVYBRIDGE: |
| 2891 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 2892 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 2893 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 2894 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 2895 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2896 | 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] | 2897 | if (rapl_joules) { |
| 2898 | BIC_PRESENT(BIC_Pkg_J); |
| 2899 | BIC_PRESENT(BIC_Cor_J); |
| 2900 | BIC_PRESENT(BIC_GFX_J); |
| 2901 | } else { |
| 2902 | BIC_PRESENT(BIC_PkgWatt); |
| 2903 | BIC_PRESENT(BIC_CorWatt); |
| 2904 | BIC_PRESENT(BIC_GFXWatt); |
| 2905 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2906 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2907 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | e4085d5 | 2016-04-06 17:15:56 -0400 | [diff] [blame] | 2908 | do_rapl = RAPL_PKG | RAPL_PKG_POWER_INFO; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 2909 | if (rapl_joules) |
| 2910 | BIC_PRESENT(BIC_Pkg_J); |
| 2911 | else |
| 2912 | BIC_PRESENT(BIC_PkgWatt); |
Len Brown | e4085d5 | 2016-04-06 17:15:56 -0400 | [diff] [blame] | 2913 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2914 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 2915 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 2916 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 2917 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 2918 | do_rapl = RAPL_PKG | RAPL_DRAM | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_PKG_POWER_INFO; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 2919 | BIC_PRESENT(BIC_PKG__); |
| 2920 | BIC_PRESENT(BIC_RAM__); |
| 2921 | if (rapl_joules) { |
| 2922 | BIC_PRESENT(BIC_Pkg_J); |
| 2923 | BIC_PRESENT(BIC_Cor_J); |
| 2924 | BIC_PRESENT(BIC_RAM_J); |
| 2925 | } else { |
| 2926 | BIC_PRESENT(BIC_PkgWatt); |
| 2927 | BIC_PRESENT(BIC_CorWatt); |
| 2928 | BIC_PRESENT(BIC_RAMWatt); |
| 2929 | } |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 2930 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2931 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 2932 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 2933 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 2934 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
| 2935 | case INTEL_FAM6_XEON_PHI_KNL: /* KNL */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 2936 | case INTEL_FAM6_XEON_PHI_KNM: |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 2937 | 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] | 2938 | BIC_PRESENT(BIC_PKG__); |
| 2939 | BIC_PRESENT(BIC_RAM__); |
| 2940 | if (rapl_joules) { |
| 2941 | BIC_PRESENT(BIC_Pkg_J); |
| 2942 | BIC_PRESENT(BIC_RAM_J); |
| 2943 | } else { |
| 2944 | BIC_PRESENT(BIC_PkgWatt); |
| 2945 | BIC_PRESENT(BIC_RAMWatt); |
| 2946 | } |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 2947 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2948 | case INTEL_FAM6_SANDYBRIDGE_X: |
| 2949 | case INTEL_FAM6_IVYBRIDGE_X: |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 2950 | 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] | 2951 | BIC_PRESENT(BIC_PKG__); |
| 2952 | BIC_PRESENT(BIC_RAM__); |
| 2953 | if (rapl_joules) { |
| 2954 | BIC_PRESENT(BIC_Pkg_J); |
| 2955 | BIC_PRESENT(BIC_Cor_J); |
| 2956 | BIC_PRESENT(BIC_RAM_J); |
| 2957 | } else { |
| 2958 | BIC_PRESENT(BIC_PkgWatt); |
| 2959 | BIC_PRESENT(BIC_CorWatt); |
| 2960 | BIC_PRESENT(BIC_RAMWatt); |
| 2961 | } |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2962 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2963 | case INTEL_FAM6_ATOM_SILVERMONT1: /* BYT */ |
| 2964 | case INTEL_FAM6_ATOM_SILVERMONT2: /* AVN */ |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 2965 | do_rapl = RAPL_PKG | RAPL_CORES; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 2966 | if (rapl_joules) { |
| 2967 | BIC_PRESENT(BIC_Pkg_J); |
| 2968 | BIC_PRESENT(BIC_Cor_J); |
| 2969 | } else { |
| 2970 | BIC_PRESENT(BIC_PkgWatt); |
| 2971 | BIC_PRESENT(BIC_CorWatt); |
| 2972 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2973 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2974 | case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ |
Jacob Pan | 0f64490 | 2016-06-16 09:48:22 -0700 | [diff] [blame] | 2975 | 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] | 2976 | BIC_PRESENT(BIC_PKG__); |
| 2977 | BIC_PRESENT(BIC_RAM__); |
| 2978 | if (rapl_joules) { |
| 2979 | BIC_PRESENT(BIC_Pkg_J); |
| 2980 | BIC_PRESENT(BIC_Cor_J); |
| 2981 | BIC_PRESENT(BIC_RAM_J); |
| 2982 | } else { |
| 2983 | BIC_PRESENT(BIC_PkgWatt); |
| 2984 | BIC_PRESENT(BIC_CorWatt); |
| 2985 | BIC_PRESENT(BIC_RAMWatt); |
| 2986 | } |
Jacob Pan | 0f64490 | 2016-06-16 09:48:22 -0700 | [diff] [blame] | 2987 | break; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2988 | default: |
| 2989 | return; |
| 2990 | } |
| 2991 | |
| 2992 | /* units on package 0, verify later other packages match */ |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2993 | if (get_msr(base_cpu, MSR_RAPL_POWER_UNIT, &msr)) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2994 | return; |
| 2995 | |
| 2996 | rapl_power_units = 1.0 / (1 << (msr & 0xF)); |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2997 | if (model == INTEL_FAM6_ATOM_SILVERMONT1) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2998 | rapl_energy_units = 1.0 * (1 << (msr >> 8 & 0x1F)) / 1000000; |
| 2999 | else |
| 3000 | rapl_energy_units = 1.0 / (1 << (msr >> 8 & 0x1F)); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3001 | |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 3002 | rapl_dram_energy_units = rapl_dram_energy_units_probe(model, rapl_energy_units); |
| 3003 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3004 | time_unit = msr >> 16 & 0xF; |
| 3005 | if (time_unit == 0) |
| 3006 | time_unit = 0xA; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3007 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3008 | rapl_time_units = 1.0 / (1 << (time_unit)); |
| 3009 | |
| 3010 | tdp = get_tdp(model); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3011 | |
| 3012 | rapl_joule_counter_range = 0xFFFFFFFF * rapl_energy_units / tdp; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3013 | if (debug) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3014 | 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] | 3015 | |
| 3016 | return; |
| 3017 | } |
| 3018 | |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 3019 | void perf_limit_reasons_probe(unsigned int family, unsigned int model) |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3020 | { |
| 3021 | if (!genuine_intel) |
| 3022 | return; |
| 3023 | |
| 3024 | if (family != 6) |
| 3025 | return; |
| 3026 | |
| 3027 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3028 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 3029 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 3030 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3031 | do_gfx_perf_limit_reasons = 1; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3032 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3033 | do_core_perf_limit_reasons = 1; |
| 3034 | do_ring_perf_limit_reasons = 1; |
| 3035 | default: |
| 3036 | return; |
| 3037 | } |
| 3038 | } |
| 3039 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3040 | int print_thermal(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3041 | { |
| 3042 | unsigned long long msr; |
| 3043 | unsigned int dts; |
| 3044 | int cpu; |
| 3045 | |
| 3046 | if (!(do_dts || do_ptm)) |
| 3047 | return 0; |
| 3048 | |
| 3049 | cpu = t->cpu_id; |
| 3050 | |
| 3051 | /* DTS is per-core, no need to print for each thread */ |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 3052 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3053 | return 0; |
| 3054 | |
| 3055 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3056 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3057 | return -1; |
| 3058 | } |
| 3059 | |
| 3060 | if (do_ptm && (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) { |
| 3061 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr)) |
| 3062 | return 0; |
| 3063 | |
| 3064 | dts = (msr >> 16) & 0x7F; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3065 | 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] | 3066 | cpu, msr, tcc_activation_temp - dts); |
| 3067 | |
| 3068 | #ifdef THERM_DEBUG |
| 3069 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, &msr)) |
| 3070 | return 0; |
| 3071 | |
| 3072 | dts = (msr >> 16) & 0x7F; |
| 3073 | dts2 = (msr >> 8) & 0x7F; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3074 | 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] | 3075 | cpu, msr, tcc_activation_temp - dts, tcc_activation_temp - dts2); |
| 3076 | #endif |
| 3077 | } |
| 3078 | |
| 3079 | |
| 3080 | if (do_dts) { |
| 3081 | unsigned int resolution; |
| 3082 | |
| 3083 | if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr)) |
| 3084 | return 0; |
| 3085 | |
| 3086 | dts = (msr >> 16) & 0x7F; |
| 3087 | resolution = (msr >> 27) & 0xF; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3088 | 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] | 3089 | cpu, msr, tcc_activation_temp - dts, resolution); |
| 3090 | |
| 3091 | #ifdef THERM_DEBUG |
| 3092 | if (get_msr(cpu, MSR_IA32_THERM_INTERRUPT, &msr)) |
| 3093 | return 0; |
| 3094 | |
| 3095 | dts = (msr >> 16) & 0x7F; |
| 3096 | dts2 = (msr >> 8) & 0x7F; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3097 | 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] | 3098 | cpu, msr, tcc_activation_temp - dts, tcc_activation_temp - dts2); |
| 3099 | #endif |
| 3100 | } |
| 3101 | |
| 3102 | return 0; |
| 3103 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 3104 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3105 | void print_power_limit_msr(int cpu, unsigned long long msr, char *label) |
| 3106 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3107 | 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] | 3108 | cpu, label, |
| 3109 | ((msr >> 15) & 1) ? "EN" : "DIS", |
| 3110 | ((msr >> 0) & 0x7FFF) * rapl_power_units, |
| 3111 | (1.0 + (((msr >> 22) & 0x3)/4.0)) * (1 << ((msr >> 17) & 0x1F)) * rapl_time_units, |
| 3112 | (((msr >> 16) & 1) ? "EN" : "DIS")); |
| 3113 | |
| 3114 | return; |
| 3115 | } |
| 3116 | |
| 3117 | int print_rapl(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3118 | { |
| 3119 | unsigned long long msr; |
| 3120 | int cpu; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3121 | |
| 3122 | if (!do_rapl) |
| 3123 | return 0; |
| 3124 | |
| 3125 | /* RAPL counters are per package, so print only for 1st thread/package */ |
| 3126 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3127 | return 0; |
| 3128 | |
| 3129 | cpu = t->cpu_id; |
| 3130 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3131 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3132 | return -1; |
| 3133 | } |
| 3134 | |
| 3135 | if (get_msr(cpu, MSR_RAPL_POWER_UNIT, &msr)) |
| 3136 | return -1; |
| 3137 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3138 | if (debug) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3139 | fprintf(outf, "cpu%d: MSR_RAPL_POWER_UNIT: 0x%08llx " |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3140 | "(%f Watts, %f Joules, %f sec.)\n", cpu, msr, |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3141 | rapl_power_units, rapl_energy_units, rapl_time_units); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3142 | } |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3143 | if (do_rapl & RAPL_PKG_POWER_INFO) { |
| 3144 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3145 | if (get_msr(cpu, MSR_PKG_POWER_INFO, &msr)) |
| 3146 | return -5; |
| 3147 | |
| 3148 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3149 | 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] | 3150 | cpu, msr, |
| 3151 | ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3152 | ((msr >> 16) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3153 | ((msr >> 32) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3154 | ((msr >> 48) & RAPL_TIME_GRANULARITY) * rapl_time_units); |
| 3155 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3156 | } |
| 3157 | if (do_rapl & RAPL_PKG) { |
| 3158 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3159 | if (get_msr(cpu, MSR_PKG_POWER_LIMIT, &msr)) |
| 3160 | return -9; |
| 3161 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3162 | fprintf(outf, "cpu%d: MSR_PKG_POWER_LIMIT: 0x%08llx (%slocked)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3163 | cpu, msr, (msr >> 63) & 1 ? "": "UN"); |
| 3164 | |
| 3165 | print_power_limit_msr(cpu, msr, "PKG Limit #1"); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3166 | 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] | 3167 | cpu, |
| 3168 | ((msr >> 47) & 1) ? "EN" : "DIS", |
| 3169 | ((msr >> 32) & 0x7FFF) * rapl_power_units, |
| 3170 | (1.0 + (((msr >> 54) & 0x3)/4.0)) * (1 << ((msr >> 49) & 0x1F)) * rapl_time_units, |
| 3171 | ((msr >> 48) & 1) ? "EN" : "DIS"); |
| 3172 | } |
| 3173 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3174 | if (do_rapl & RAPL_DRAM_POWER_INFO) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3175 | if (get_msr(cpu, MSR_DRAM_POWER_INFO, &msr)) |
| 3176 | return -6; |
| 3177 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3178 | 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] | 3179 | cpu, msr, |
| 3180 | ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3181 | ((msr >> 16) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3182 | ((msr >> 32) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3183 | ((msr >> 48) & RAPL_TIME_GRANULARITY) * rapl_time_units); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3184 | } |
| 3185 | if (do_rapl & RAPL_DRAM) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3186 | if (get_msr(cpu, MSR_DRAM_POWER_LIMIT, &msr)) |
| 3187 | return -9; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3188 | fprintf(outf, "cpu%d: MSR_DRAM_POWER_LIMIT: 0x%08llx (%slocked)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3189 | cpu, msr, (msr >> 31) & 1 ? "": "UN"); |
| 3190 | |
| 3191 | print_power_limit_msr(cpu, msr, "DRAM Limit"); |
| 3192 | } |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3193 | if (do_rapl & RAPL_CORE_POLICY) { |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3194 | if (debug) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3195 | if (get_msr(cpu, MSR_PP0_POLICY, &msr)) |
| 3196 | return -7; |
| 3197 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3198 | fprintf(outf, "cpu%d: MSR_PP0_POLICY: %lld\n", cpu, msr & 0xF); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3199 | } |
| 3200 | } |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 3201 | if (do_rapl & RAPL_CORES_POWER_LIMIT) { |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3202 | if (debug) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3203 | if (get_msr(cpu, MSR_PP0_POWER_LIMIT, &msr)) |
| 3204 | return -9; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3205 | fprintf(outf, "cpu%d: MSR_PP0_POWER_LIMIT: 0x%08llx (%slocked)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3206 | cpu, msr, (msr >> 31) & 1 ? "": "UN"); |
| 3207 | print_power_limit_msr(cpu, msr, "Cores Limit"); |
| 3208 | } |
| 3209 | } |
| 3210 | if (do_rapl & RAPL_GFX) { |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3211 | if (debug) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3212 | if (get_msr(cpu, MSR_PP1_POLICY, &msr)) |
| 3213 | return -8; |
| 3214 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3215 | fprintf(outf, "cpu%d: MSR_PP1_POLICY: %lld\n", cpu, msr & 0xF); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3216 | |
| 3217 | if (get_msr(cpu, MSR_PP1_POWER_LIMIT, &msr)) |
| 3218 | return -9; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3219 | fprintf(outf, "cpu%d: MSR_PP1_POWER_LIMIT: 0x%08llx (%slocked)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3220 | cpu, msr, (msr >> 31) & 1 ? "": "UN"); |
| 3221 | print_power_limit_msr(cpu, msr, "GFX Limit"); |
| 3222 | } |
| 3223 | } |
| 3224 | return 0; |
| 3225 | } |
| 3226 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3227 | /* |
| 3228 | * SNB adds support for additional MSRs: |
| 3229 | * |
| 3230 | * MSR_PKG_C7_RESIDENCY 0x000003fa |
| 3231 | * MSR_CORE_C7_RESIDENCY 0x000003fe |
| 3232 | * MSR_PKG_C2_RESIDENCY 0x0000060d |
| 3233 | */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3234 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3235 | int has_snb_msrs(unsigned int family, unsigned int model) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3236 | { |
| 3237 | if (!genuine_intel) |
| 3238 | return 0; |
| 3239 | |
| 3240 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3241 | case INTEL_FAM6_SANDYBRIDGE: |
| 3242 | case INTEL_FAM6_SANDYBRIDGE_X: |
| 3243 | case INTEL_FAM6_IVYBRIDGE: /* IVB */ |
| 3244 | case INTEL_FAM6_IVYBRIDGE_X: /* IVB Xeon */ |
| 3245 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 3246 | case INTEL_FAM6_HASWELL_X: /* HSW */ |
| 3247 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 3248 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 3249 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 3250 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
| 3251 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 3252 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 3253 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 3254 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 3255 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 3256 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
| 3257 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
| 3258 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Xiaolong Wang | 5bbac26 | 2016-09-30 17:53:40 +0800 | [diff] [blame] | 3259 | case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3260 | return 1; |
| 3261 | } |
| 3262 | return 0; |
| 3263 | } |
| 3264 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3265 | /* |
| 3266 | * HSW adds support for additional MSRs: |
| 3267 | * |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 3268 | * MSR_PKG_C8_RESIDENCY 0x00000630 |
| 3269 | * MSR_PKG_C9_RESIDENCY 0x00000631 |
| 3270 | * MSR_PKG_C10_RESIDENCY 0x00000632 |
| 3271 | * |
| 3272 | * MSR_PKGC8_IRTL 0x00000633 |
| 3273 | * MSR_PKGC9_IRTL 0x00000634 |
| 3274 | * MSR_PKGC10_IRTL 0x00000635 |
| 3275 | * |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3276 | */ |
| 3277 | int has_hsw_msrs(unsigned int family, unsigned int model) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 3278 | { |
| 3279 | if (!genuine_intel) |
| 3280 | return 0; |
| 3281 | |
| 3282 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3283 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 3284 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 3285 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 3286 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 3287 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 3288 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
| 3289 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 3290 | return 1; |
| 3291 | } |
| 3292 | return 0; |
| 3293 | } |
| 3294 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3295 | /* |
| 3296 | * SKL adds support for additional MSRS: |
| 3297 | * |
| 3298 | * MSR_PKG_WEIGHTED_CORE_C0_RES 0x00000658 |
| 3299 | * MSR_PKG_ANY_CORE_C0_RES 0x00000659 |
| 3300 | * MSR_PKG_ANY_GFXE_C0_RES 0x0000065A |
| 3301 | * MSR_PKG_BOTH_CORE_GFXE_C0_RES 0x0000065B |
| 3302 | */ |
| 3303 | int has_skl_msrs(unsigned int family, unsigned int model) |
| 3304 | { |
| 3305 | if (!genuine_intel) |
| 3306 | return 0; |
| 3307 | |
| 3308 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3309 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 3310 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 3311 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 3312 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3313 | return 1; |
| 3314 | } |
| 3315 | return 0; |
| 3316 | } |
| 3317 | |
| 3318 | |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 3319 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3320 | int is_slm(unsigned int family, unsigned int model) |
| 3321 | { |
| 3322 | if (!genuine_intel) |
| 3323 | return 0; |
| 3324 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3325 | case INTEL_FAM6_ATOM_SILVERMONT1: /* BYT */ |
| 3326 | case INTEL_FAM6_ATOM_SILVERMONT2: /* AVN */ |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3327 | return 1; |
| 3328 | } |
| 3329 | return 0; |
| 3330 | } |
| 3331 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 3332 | int is_knl(unsigned int family, unsigned int model) |
| 3333 | { |
| 3334 | if (!genuine_intel) |
| 3335 | return 0; |
| 3336 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3337 | case INTEL_FAM6_XEON_PHI_KNL: /* KNL */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 3338 | case INTEL_FAM6_XEON_PHI_KNM: |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 3339 | return 1; |
| 3340 | } |
| 3341 | return 0; |
| 3342 | } |
| 3343 | |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 3344 | unsigned int get_aperf_mperf_multiplier(unsigned int family, unsigned int model) |
| 3345 | { |
| 3346 | if (is_knl(family, model)) |
| 3347 | return 1024; |
| 3348 | return 1; |
| 3349 | } |
| 3350 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3351 | #define SLM_BCLK_FREQS 5 |
| 3352 | double slm_freq_table[SLM_BCLK_FREQS] = { 83.3, 100.0, 133.3, 116.7, 80.0}; |
| 3353 | |
| 3354 | double slm_bclk(void) |
| 3355 | { |
| 3356 | unsigned long long msr = 3; |
| 3357 | unsigned int i; |
| 3358 | double freq; |
| 3359 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3360 | if (get_msr(base_cpu, MSR_FSB_FREQ, &msr)) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3361 | fprintf(outf, "SLM BCLK: unknown\n"); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3362 | |
| 3363 | i = msr & 0xf; |
| 3364 | if (i >= SLM_BCLK_FREQS) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3365 | fprintf(outf, "SLM BCLK[%d] invalid\n", i); |
Colin Ian King | 0a91e55 | 2016-04-25 13:03:15 +0100 | [diff] [blame] | 3366 | i = 3; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3367 | } |
| 3368 | freq = slm_freq_table[i]; |
| 3369 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3370 | fprintf(outf, "SLM BCLK: %.1f Mhz\n", freq); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3371 | |
| 3372 | return freq; |
| 3373 | } |
| 3374 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3375 | double discover_bclk(unsigned int family, unsigned int model) |
| 3376 | { |
Chrzaniuk, Hubert | 121b48b | 2016-02-10 16:35:17 +0100 | [diff] [blame] | 3377 | if (has_snb_msrs(family, model) || is_knl(family, model)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3378 | return 100.00; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3379 | else if (is_slm(family, model)) |
| 3380 | return slm_bclk(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3381 | else |
| 3382 | return 133.33; |
| 3383 | } |
| 3384 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3385 | /* |
| 3386 | * MSR_IA32_TEMPERATURE_TARGET indicates the temperature where |
| 3387 | * the Thermal Control Circuit (TCC) activates. |
| 3388 | * This is usually equal to tjMax. |
| 3389 | * |
| 3390 | * Older processors do not have this MSR, so there we guess, |
| 3391 | * but also allow cmdline over-ride with -T. |
| 3392 | * |
| 3393 | * Several MSR temperature values are in units of degrees-C |
| 3394 | * below this value, including the Digital Thermal Sensor (DTS), |
| 3395 | * Package Thermal Management Sensor (PTM), and thermal event thresholds. |
| 3396 | */ |
| 3397 | int set_temperature_target(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3398 | { |
| 3399 | unsigned long long msr; |
| 3400 | unsigned int target_c_local; |
| 3401 | int cpu; |
| 3402 | |
| 3403 | /* tcc_activation_temp is used only for dts or ptm */ |
| 3404 | if (!(do_dts || do_ptm)) |
| 3405 | return 0; |
| 3406 | |
| 3407 | /* this is a per-package concept */ |
| 3408 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3409 | return 0; |
| 3410 | |
| 3411 | cpu = t->cpu_id; |
| 3412 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3413 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3414 | return -1; |
| 3415 | } |
| 3416 | |
| 3417 | if (tcc_activation_temp_override != 0) { |
| 3418 | tcc_activation_temp = tcc_activation_temp_override; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3419 | fprintf(outf, "cpu%d: Using cmdline TCC Target (%d C)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3420 | cpu, tcc_activation_temp); |
| 3421 | return 0; |
| 3422 | } |
| 3423 | |
| 3424 | /* Temperature Target MSR is Nehalem and newer only */ |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3425 | if (!do_nhm_platform_info) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3426 | goto guess; |
| 3427 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3428 | if (get_msr(base_cpu, MSR_IA32_TEMPERATURE_TARGET, &msr)) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3429 | goto guess; |
| 3430 | |
Jean Delvare | 3482124 | 2014-05-01 11:40:19 +0200 | [diff] [blame] | 3431 | target_c_local = (msr >> 16) & 0xFF; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3432 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3433 | if (debug) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3434 | 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] | 3435 | cpu, msr, target_c_local); |
| 3436 | |
Jean Delvare | 3482124 | 2014-05-01 11:40:19 +0200 | [diff] [blame] | 3437 | if (!target_c_local) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3438 | goto guess; |
| 3439 | |
| 3440 | tcc_activation_temp = target_c_local; |
| 3441 | |
| 3442 | return 0; |
| 3443 | |
| 3444 | guess: |
| 3445 | tcc_activation_temp = TJMAX_DEFAULT; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3446 | 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] | 3447 | cpu, tcc_activation_temp); |
| 3448 | |
| 3449 | return 0; |
| 3450 | } |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 3451 | |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 3452 | void decode_feature_control_msr(void) |
| 3453 | { |
| 3454 | unsigned long long msr; |
| 3455 | |
| 3456 | if (!get_msr(base_cpu, MSR_IA32_FEATURE_CONTROL, &msr)) |
| 3457 | fprintf(outf, "cpu%d: MSR_IA32_FEATURE_CONTROL: 0x%08llx (%sLocked %s)\n", |
| 3458 | base_cpu, msr, |
| 3459 | msr & FEATURE_CONTROL_LOCKED ? "" : "UN-", |
| 3460 | msr & (1 << 18) ? "SGX" : ""); |
| 3461 | } |
| 3462 | |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 3463 | void decode_misc_enable_msr(void) |
| 3464 | { |
| 3465 | unsigned long long msr; |
| 3466 | |
| 3467 | if (!get_msr(base_cpu, MSR_IA32_MISC_ENABLE, &msr)) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3468 | fprintf(outf, "cpu%d: MSR_IA32_MISC_ENABLE: 0x%08llx (%s %s %s)\n", |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 3469 | base_cpu, msr, |
| 3470 | msr & (1 << 3) ? "TCC" : "", |
| 3471 | msr & (1 << 16) ? "EIST" : "", |
| 3472 | msr & (1 << 18) ? "MONITOR" : ""); |
| 3473 | } |
| 3474 | |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 3475 | /* |
| 3476 | * Decode MSR_MISC_PWR_MGMT |
| 3477 | * |
| 3478 | * Decode the bits according to the Nehalem documentation |
| 3479 | * bit[0] seems to continue to have same meaning going forward |
| 3480 | * bit[1] less so... |
| 3481 | */ |
| 3482 | void decode_misc_pwr_mgmt_msr(void) |
| 3483 | { |
| 3484 | unsigned long long msr; |
| 3485 | |
| 3486 | if (!do_nhm_platform_info) |
| 3487 | return; |
| 3488 | |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame^] | 3489 | if (no_MSR_MISC_PWR_MGMT) |
| 3490 | return; |
| 3491 | |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 3492 | if (!get_msr(base_cpu, MSR_MISC_PWR_MGMT, &msr)) |
Srinivas Pandruvada | ddadb8a | 2016-11-11 14:29:48 -0800 | [diff] [blame] | 3493 | 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] | 3494 | base_cpu, msr, |
| 3495 | msr & (1 << 0) ? "DIS" : "EN", |
Srinivas Pandruvada | ddadb8a | 2016-11-11 14:29:48 -0800 | [diff] [blame] | 3496 | msr & (1 << 1) ? "EN" : "DIS", |
| 3497 | msr & (1 << 8) ? "EN" : "DIS"); |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 3498 | } |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3499 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3500 | void process_cpuid() |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3501 | { |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 3502 | unsigned int eax, ebx, ecx, edx, max_level, max_extended_level; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3503 | unsigned int fms, family, model, stepping; |
| 3504 | |
| 3505 | eax = ebx = ecx = edx = 0; |
| 3506 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 3507 | __cpuid(0, max_level, ebx, ecx, edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3508 | |
| 3509 | if (ebx == 0x756e6547 && edx == 0x49656e69 && ecx == 0x6c65746e) |
| 3510 | genuine_intel = 1; |
| 3511 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3512 | if (debug) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3513 | fprintf(outf, "CPUID(0): %.4s%.4s%.4s ", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3514 | (char *)&ebx, (char *)&edx, (char *)&ecx); |
| 3515 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 3516 | __cpuid(1, fms, ebx, ecx, edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3517 | family = (fms >> 8) & 0xf; |
| 3518 | model = (fms >> 4) & 0xf; |
| 3519 | stepping = fms & 0xf; |
| 3520 | if (family == 6 || family == 0xf) |
| 3521 | model += ((fms >> 16) & 0xf) << 4; |
| 3522 | |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 3523 | if (debug) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3524 | 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] | 3525 | max_level, family, model, stepping, family, model, stepping); |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 3526 | 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] | 3527 | ecx & (1 << 0) ? "SSE3" : "-", |
| 3528 | ecx & (1 << 3) ? "MONITOR" : "-", |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 3529 | ecx & (1 << 6) ? "SMX" : "-", |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 3530 | ecx & (1 << 7) ? "EIST" : "-", |
| 3531 | ecx & (1 << 8) ? "TM2" : "-", |
| 3532 | edx & (1 << 4) ? "TSC" : "-", |
| 3533 | edx & (1 << 5) ? "MSR" : "-", |
| 3534 | edx & (1 << 22) ? "ACPI-TM" : "-", |
| 3535 | edx & (1 << 29) ? "TM" : "-"); |
| 3536 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3537 | |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 3538 | if (!(edx & (1 << 5))) |
| 3539 | errx(1, "CPUID: no MSR"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3540 | |
| 3541 | /* |
| 3542 | * check max extended function levels of CPUID. |
| 3543 | * This is needed to check for invariant TSC. |
| 3544 | * This check is valid for both Intel and AMD. |
| 3545 | */ |
| 3546 | ebx = ecx = edx = 0; |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 3547 | __cpuid(0x80000000, max_extended_level, ebx, ecx, edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3548 | |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 3549 | if (max_extended_level >= 0x80000007) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3550 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3551 | /* |
| 3552 | * Non-Stop TSC is advertised by CPUID.EAX=0x80000007: EDX.bit8 |
| 3553 | * this check is valid for both Intel and AMD |
| 3554 | */ |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 3555 | __cpuid(0x80000007, eax, ebx, ecx, edx); |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3556 | has_invariant_tsc = edx & (1 << 8); |
| 3557 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3558 | |
| 3559 | /* |
| 3560 | * APERF/MPERF is advertised by CPUID.EAX=0x6: ECX.bit0 |
| 3561 | * this check is valid for both Intel and AMD |
| 3562 | */ |
| 3563 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 3564 | __cpuid(0x6, eax, ebx, ecx, edx); |
Thomas Renninger | 8209e05 | 2011-01-21 15:11:19 +0100 | [diff] [blame] | 3565 | has_aperf = ecx & (1 << 0); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3566 | if (has_aperf) { |
| 3567 | BIC_PRESENT(BIC_Avg_MHz); |
| 3568 | BIC_PRESENT(BIC_Busy); |
| 3569 | BIC_PRESENT(BIC_Bzy_MHz); |
| 3570 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3571 | do_dts = eax & (1 << 0); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3572 | if (do_dts) |
| 3573 | BIC_PRESENT(BIC_CoreTmp); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3574 | do_ptm = eax & (1 << 6); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3575 | if (do_ptm) |
| 3576 | BIC_PRESENT(BIC_PkgTmp); |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3577 | has_hwp = eax & (1 << 7); |
| 3578 | has_hwp_notify = eax & (1 << 8); |
| 3579 | has_hwp_activity_window = eax & (1 << 9); |
| 3580 | has_hwp_epp = eax & (1 << 10); |
| 3581 | has_hwp_pkg = eax & (1 << 11); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3582 | has_epb = ecx & (1 << 3); |
| 3583 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3584 | if (debug) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3585 | fprintf(outf, "CPUID(6): %sAPERF, %sDTS, %sPTM, %sHWP, " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3586 | "%sHWPnotify, %sHWPwindow, %sHWPepp, %sHWPpkg, %sEPB\n", |
| 3587 | has_aperf ? "" : "No-", |
| 3588 | do_dts ? "" : "No-", |
| 3589 | do_ptm ? "" : "No-", |
| 3590 | has_hwp ? "" : "No-", |
| 3591 | has_hwp_notify ? "" : "No-", |
| 3592 | has_hwp_activity_window ? "" : "No-", |
| 3593 | has_hwp_epp ? "" : "No-", |
| 3594 | has_hwp_pkg ? "" : "No-", |
| 3595 | has_epb ? "" : "No-"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3596 | |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 3597 | if (debug) |
| 3598 | decode_misc_enable_msr(); |
| 3599 | |
Len Brown | 8ae7225 | 2016-04-06 17:15:54 -0400 | [diff] [blame] | 3600 | if (max_level >= 0x7 && debug) { |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 3601 | int has_sgx; |
| 3602 | |
| 3603 | ecx = 0; |
| 3604 | |
| 3605 | __cpuid_count(0x7, 0, eax, ebx, ecx, edx); |
| 3606 | |
| 3607 | has_sgx = ebx & (1 << 2); |
| 3608 | fprintf(outf, "CPUID(7): %sSGX\n", has_sgx ? "" : "No-"); |
| 3609 | |
| 3610 | if (has_sgx) |
| 3611 | decode_feature_control_msr(); |
| 3612 | } |
| 3613 | |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 3614 | if (max_level >= 0x15) { |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 3615 | unsigned int eax_crystal; |
| 3616 | unsigned int ebx_tsc; |
| 3617 | |
| 3618 | /* |
| 3619 | * CPUID 15H TSC/Crystal ratio, possibly Crystal Hz |
| 3620 | */ |
| 3621 | eax_crystal = ebx_tsc = crystal_hz = edx = 0; |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 3622 | __cpuid(0x15, eax_crystal, ebx_tsc, crystal_hz, edx); |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 3623 | |
| 3624 | if (ebx_tsc != 0) { |
| 3625 | |
| 3626 | if (debug && (ebx != 0)) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3627 | 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] | 3628 | eax_crystal, ebx_tsc, crystal_hz); |
| 3629 | |
| 3630 | if (crystal_hz == 0) |
| 3631 | switch(model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3632 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 3633 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 3634 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 3635 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Len Brown | e8efbc8 | 2016-04-06 17:15:57 -0400 | [diff] [blame] | 3636 | crystal_hz = 24000000; /* 24.0 MHz */ |
| 3637 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3638 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
Len Brown | 7268d40 | 2016-12-01 23:10:39 -0500 | [diff] [blame] | 3639 | case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ |
Len Brown | ec53e59 | 2016-04-06 17:15:58 -0400 | [diff] [blame] | 3640 | crystal_hz = 25000000; /* 25.0 MHz */ |
| 3641 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3642 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | e8efbc8 | 2016-04-06 17:15:57 -0400 | [diff] [blame] | 3643 | crystal_hz = 19200000; /* 19.2 MHz */ |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 3644 | break; |
| 3645 | default: |
| 3646 | crystal_hz = 0; |
| 3647 | } |
| 3648 | |
| 3649 | if (crystal_hz) { |
| 3650 | tsc_hz = (unsigned long long) crystal_hz * ebx_tsc / eax_crystal; |
| 3651 | if (debug) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3652 | fprintf(outf, "TSC: %lld MHz (%d Hz * %d / %d / 1000000)\n", |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 3653 | tsc_hz / 1000000, crystal_hz, ebx_tsc, eax_crystal); |
| 3654 | } |
| 3655 | } |
| 3656 | } |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 3657 | if (max_level >= 0x16) { |
| 3658 | unsigned int base_mhz, max_mhz, bus_mhz, edx; |
| 3659 | |
| 3660 | /* |
| 3661 | * CPUID 16H Base MHz, Max MHz, Bus MHz |
| 3662 | */ |
| 3663 | base_mhz = max_mhz = bus_mhz = edx = 0; |
| 3664 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 3665 | __cpuid(0x16, base_mhz, max_mhz, bus_mhz, edx); |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 3666 | if (debug) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3667 | 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] | 3668 | base_mhz, max_mhz, bus_mhz); |
| 3669 | } |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 3670 | |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 3671 | if (has_aperf) |
| 3672 | aperf_mperf_multiplier = get_aperf_mperf_multiplier(family, model); |
| 3673 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3674 | BIC_PRESENT(BIC_IRQ); |
| 3675 | BIC_PRESENT(BIC_TSC_MHz); |
| 3676 | |
| 3677 | if (probe_nhm_msrs(family, model)) { |
| 3678 | do_nhm_platform_info = 1; |
| 3679 | BIC_PRESENT(BIC_CPU_c1); |
| 3680 | BIC_PRESENT(BIC_CPU_c3); |
| 3681 | BIC_PRESENT(BIC_CPU_c6); |
| 3682 | BIC_PRESENT(BIC_SMI); |
| 3683 | } |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3684 | do_snb_cstates = has_snb_msrs(family, model); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3685 | |
| 3686 | if (do_snb_cstates) |
| 3687 | BIC_PRESENT(BIC_CPU_c7); |
| 3688 | |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 3689 | do_irtl_snb = has_snb_msrs(family, model); |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3690 | do_pc2 = do_snb_cstates && (pkg_cstate_limit >= PCL__2); |
| 3691 | do_pc3 = (pkg_cstate_limit >= PCL__3); |
| 3692 | do_pc6 = (pkg_cstate_limit >= PCL__6); |
| 3693 | do_pc7 = do_snb_cstates && (pkg_cstate_limit >= PCL__7); |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3694 | do_c8_c9_c10 = has_hsw_msrs(family, model); |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 3695 | do_irtl_hsw = has_hsw_msrs(family, model); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3696 | do_skl_residency = has_skl_msrs(family, model); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3697 | do_slm_cstates = is_slm(family, model); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 3698 | do_knl_cstates = is_knl(family, model); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3699 | |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 3700 | if (debug) |
| 3701 | decode_misc_pwr_mgmt_msr(); |
| 3702 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3703 | rapl_probe(family, model); |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3704 | perf_limit_reasons_probe(family, model); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3705 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3706 | if (debug) |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 3707 | dump_cstate_pstate_config_info(family, model); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3708 | |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 3709 | if (has_skl_msrs(family, model)) |
| 3710 | calculate_tsc_tweak(); |
| 3711 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3712 | if (!access("/sys/class/drm/card0/power/rc6_residency_ms", R_OK)) |
| 3713 | BIC_PRESENT(BIC_GFX_rc6); |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 3714 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3715 | if (!access("/sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz", R_OK)) |
| 3716 | BIC_PRESENT(BIC_GFXMHz); |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 3717 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3718 | return; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3719 | } |
| 3720 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3721 | void help() |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3722 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3723 | fprintf(outf, |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3724 | "Usage: turbostat [OPTIONS][(--interval seconds) | COMMAND ...]\n" |
| 3725 | "\n" |
| 3726 | "Turbostat forks the specified COMMAND and prints statistics\n" |
| 3727 | "when COMMAND completes.\n" |
| 3728 | "If no COMMAND is specified, turbostat wakes every 5-seconds\n" |
| 3729 | "to print statistics, until interrupted.\n" |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 3730 | "--add add a counter\n" |
| 3731 | " eg. --add msr0x10,u64,cpu,delta,MY_TSC\n" |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3732 | "--debug run in \"debug\" mode\n" |
| 3733 | "--interval sec Override default 5-second measurement interval\n" |
| 3734 | "--help print this help message\n" |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3735 | "--out file create or truncate \"file\" for all output\n" |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3736 | "--version print version information\n" |
| 3737 | "\n" |
| 3738 | "For more help, run \"man turbostat\"\n"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3739 | } |
| 3740 | |
| 3741 | |
| 3742 | /* |
| 3743 | * in /dev/cpu/ return success for names that are numbers |
| 3744 | * ie. filter out ".", "..", "microcode". |
| 3745 | */ |
| 3746 | int dir_filter(const struct dirent *dirp) |
| 3747 | { |
| 3748 | if (isdigit(dirp->d_name[0])) |
| 3749 | return 1; |
| 3750 | else |
| 3751 | return 0; |
| 3752 | } |
| 3753 | |
| 3754 | int open_dev_cpu_msr(int dummy1) |
| 3755 | { |
| 3756 | return 0; |
| 3757 | } |
| 3758 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3759 | void topology_probe() |
| 3760 | { |
| 3761 | int i; |
| 3762 | int max_core_id = 0; |
| 3763 | int max_package_id = 0; |
| 3764 | int max_siblings = 0; |
| 3765 | struct cpu_topology { |
| 3766 | int core_id; |
| 3767 | int physical_package_id; |
| 3768 | } *cpus; |
| 3769 | |
| 3770 | /* Initialize num_cpus, max_cpu_num */ |
| 3771 | topo.num_cpus = 0; |
| 3772 | topo.max_cpu_num = 0; |
| 3773 | for_all_proc_cpus(count_cpus); |
| 3774 | if (!summary_only && topo.num_cpus > 1) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3775 | BIC_PRESENT(BIC_CPU); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3776 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3777 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3778 | 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] | 3779 | |
| 3780 | cpus = calloc(1, (topo.max_cpu_num + 1) * sizeof(struct cpu_topology)); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 3781 | if (cpus == NULL) |
| 3782 | err(1, "calloc cpus"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3783 | |
| 3784 | /* |
| 3785 | * Allocate and initialize cpu_present_set |
| 3786 | */ |
| 3787 | cpu_present_set = CPU_ALLOC((topo.max_cpu_num + 1)); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 3788 | if (cpu_present_set == NULL) |
| 3789 | err(3, "CPU_ALLOC"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3790 | cpu_present_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); |
| 3791 | CPU_ZERO_S(cpu_present_setsize, cpu_present_set); |
| 3792 | for_all_proc_cpus(mark_cpu_present); |
| 3793 | |
| 3794 | /* |
| 3795 | * Allocate and initialize cpu_affinity_set |
| 3796 | */ |
| 3797 | cpu_affinity_set = CPU_ALLOC((topo.max_cpu_num + 1)); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 3798 | if (cpu_affinity_set == NULL) |
| 3799 | err(3, "CPU_ALLOC"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3800 | cpu_affinity_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); |
| 3801 | CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); |
| 3802 | |
| 3803 | |
| 3804 | /* |
| 3805 | * For online cpus |
| 3806 | * find max_core_id, max_package_id |
| 3807 | */ |
| 3808 | for (i = 0; i <= topo.max_cpu_num; ++i) { |
| 3809 | int siblings; |
| 3810 | |
| 3811 | if (cpu_is_not_present(i)) { |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3812 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3813 | fprintf(outf, "cpu%d NOT PRESENT\n", i); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3814 | continue; |
| 3815 | } |
| 3816 | cpus[i].core_id = get_core_id(i); |
| 3817 | if (cpus[i].core_id > max_core_id) |
| 3818 | max_core_id = cpus[i].core_id; |
| 3819 | |
| 3820 | cpus[i].physical_package_id = get_physical_package_id(i); |
| 3821 | if (cpus[i].physical_package_id > max_package_id) |
| 3822 | max_package_id = cpus[i].physical_package_id; |
| 3823 | |
| 3824 | siblings = get_num_ht_siblings(i); |
| 3825 | if (siblings > max_siblings) |
| 3826 | max_siblings = siblings; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3827 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3828 | fprintf(outf, "cpu %d pkg %d core %d\n", |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3829 | i, cpus[i].physical_package_id, cpus[i].core_id); |
| 3830 | } |
| 3831 | topo.num_cores_per_pkg = max_core_id + 1; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3832 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3833 | 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] | 3834 | max_core_id, topo.num_cores_per_pkg); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 3835 | if (debug && !summary_only && topo.num_cores_per_pkg > 1) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3836 | BIC_PRESENT(BIC_Core); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3837 | |
| 3838 | topo.num_packages = max_package_id + 1; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3839 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3840 | fprintf(outf, "max_package_id %d, sizing for %d packages\n", |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3841 | max_package_id, topo.num_packages); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 3842 | if (debug && !summary_only && topo.num_packages > 1) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3843 | BIC_PRESENT(BIC_Package); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3844 | |
| 3845 | topo.num_threads_per_core = max_siblings; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3846 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3847 | fprintf(outf, "max_siblings %d\n", max_siblings); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3848 | |
| 3849 | free(cpus); |
| 3850 | } |
| 3851 | |
| 3852 | void |
| 3853 | allocate_counters(struct thread_data **t, struct core_data **c, struct pkg_data **p) |
| 3854 | { |
| 3855 | int i; |
| 3856 | |
| 3857 | *t = calloc(topo.num_threads_per_core * topo.num_cores_per_pkg * |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 3858 | topo.num_packages, sizeof(struct thread_data)); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3859 | if (*t == NULL) |
| 3860 | goto error; |
| 3861 | |
| 3862 | for (i = 0; i < topo.num_threads_per_core * |
| 3863 | topo.num_cores_per_pkg * topo.num_packages; i++) |
| 3864 | (*t)[i].cpu_id = -1; |
| 3865 | |
| 3866 | *c = calloc(topo.num_cores_per_pkg * topo.num_packages, |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 3867 | sizeof(struct core_data)); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3868 | if (*c == NULL) |
| 3869 | goto error; |
| 3870 | |
| 3871 | for (i = 0; i < topo.num_cores_per_pkg * topo.num_packages; i++) |
| 3872 | (*c)[i].core_id = -1; |
| 3873 | |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 3874 | *p = calloc(topo.num_packages, sizeof(struct pkg_data)); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3875 | if (*p == NULL) |
| 3876 | goto error; |
| 3877 | |
| 3878 | for (i = 0; i < topo.num_packages; i++) |
| 3879 | (*p)[i].package_id = i; |
| 3880 | |
| 3881 | return; |
| 3882 | error: |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 3883 | err(1, "calloc counters"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3884 | } |
| 3885 | /* |
| 3886 | * init_counter() |
| 3887 | * |
| 3888 | * set cpu_id, core_num, pkg_num |
| 3889 | * set FIRST_THREAD_IN_CORE and FIRST_CORE_IN_PACKAGE |
| 3890 | * |
| 3891 | * increment topo.num_cores when 1st core in pkg seen |
| 3892 | */ |
| 3893 | void init_counter(struct thread_data *thread_base, struct core_data *core_base, |
| 3894 | struct pkg_data *pkg_base, int thread_num, int core_num, |
| 3895 | int pkg_num, int cpu_id) |
| 3896 | { |
| 3897 | struct thread_data *t; |
| 3898 | struct core_data *c; |
| 3899 | struct pkg_data *p; |
| 3900 | |
| 3901 | t = GET_THREAD(thread_base, thread_num, core_num, pkg_num); |
| 3902 | c = GET_CORE(core_base, core_num, pkg_num); |
| 3903 | p = GET_PKG(pkg_base, pkg_num); |
| 3904 | |
| 3905 | t->cpu_id = cpu_id; |
| 3906 | if (thread_num == 0) { |
| 3907 | t->flags |= CPU_IS_FIRST_THREAD_IN_CORE; |
| 3908 | if (cpu_is_first_core_in_package(cpu_id)) |
| 3909 | t->flags |= CPU_IS_FIRST_CORE_IN_PACKAGE; |
| 3910 | } |
| 3911 | |
| 3912 | c->core_id = core_num; |
| 3913 | p->package_id = pkg_num; |
| 3914 | } |
| 3915 | |
| 3916 | |
| 3917 | int initialize_counters(int cpu_id) |
| 3918 | { |
| 3919 | int my_thread_id, my_core_id, my_package_id; |
| 3920 | |
| 3921 | my_package_id = get_physical_package_id(cpu_id); |
| 3922 | my_core_id = get_core_id(cpu_id); |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 3923 | my_thread_id = get_cpu_position_in_core(cpu_id); |
| 3924 | if (!my_thread_id) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3925 | topo.num_cores++; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3926 | |
| 3927 | init_counter(EVEN_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id); |
| 3928 | init_counter(ODD_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id); |
| 3929 | return 0; |
| 3930 | } |
| 3931 | |
| 3932 | void allocate_output_buffer() |
| 3933 | { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 3934 | output_buffer = calloc(1, (1 + topo.num_cpus) * 1024); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3935 | outp = output_buffer; |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 3936 | if (outp == NULL) |
| 3937 | err(-1, "calloc output buffer"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3938 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 3939 | void allocate_fd_percpu(void) |
| 3940 | { |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 3941 | fd_percpu = calloc(topo.max_cpu_num + 1, sizeof(int)); |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 3942 | if (fd_percpu == NULL) |
| 3943 | err(-1, "calloc fd_percpu"); |
| 3944 | } |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 3945 | void allocate_irq_buffers(void) |
| 3946 | { |
| 3947 | irq_column_2_cpu = calloc(topo.num_cpus, sizeof(int)); |
| 3948 | if (irq_column_2_cpu == NULL) |
| 3949 | err(-1, "calloc %d", topo.num_cpus); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3950 | |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 3951 | irqs_per_cpu = calloc(topo.max_cpu_num + 1, sizeof(int)); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 3952 | if (irqs_per_cpu == NULL) |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 3953 | err(-1, "calloc %d", topo.max_cpu_num + 1); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 3954 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3955 | void setup_all_buffers(void) |
| 3956 | { |
| 3957 | topology_probe(); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 3958 | allocate_irq_buffers(); |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 3959 | allocate_fd_percpu(); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3960 | allocate_counters(&thread_even, &core_even, &package_even); |
| 3961 | allocate_counters(&thread_odd, &core_odd, &package_odd); |
| 3962 | allocate_output_buffer(); |
| 3963 | for_all_proc_cpus(initialize_counters); |
| 3964 | } |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 3965 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3966 | void set_base_cpu(void) |
| 3967 | { |
| 3968 | base_cpu = sched_getcpu(); |
| 3969 | if (base_cpu < 0) |
| 3970 | err(-ENODEV, "No valid cpus found"); |
| 3971 | |
| 3972 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3973 | fprintf(outf, "base_cpu = %d\n", base_cpu); |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3974 | } |
| 3975 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3976 | void turbostat_init() |
| 3977 | { |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3978 | setup_all_buffers(); |
| 3979 | set_base_cpu(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3980 | check_dev_msr(); |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 3981 | check_permissions(); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3982 | process_cpuid(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3983 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3984 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3985 | if (debug) |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3986 | for_all_cpus(print_hwp, ODD_COUNTERS); |
| 3987 | |
| 3988 | if (debug) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3989 | for_all_cpus(print_epb, ODD_COUNTERS); |
| 3990 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3991 | if (debug) |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3992 | for_all_cpus(print_perf_limit, ODD_COUNTERS); |
| 3993 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3994 | if (debug) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3995 | for_all_cpus(print_rapl, ODD_COUNTERS); |
| 3996 | |
| 3997 | for_all_cpus(set_temperature_target, ODD_COUNTERS); |
| 3998 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3999 | if (debug) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4000 | for_all_cpus(print_thermal, ODD_COUNTERS); |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 4001 | |
| 4002 | if (debug && do_irtl_snb) |
| 4003 | print_irtl(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4004 | } |
| 4005 | |
| 4006 | int fork_it(char **argv) |
| 4007 | { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4008 | pid_t child_pid; |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 4009 | int status; |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 4010 | |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 4011 | status = for_all_cpus(get_counters, EVEN_COUNTERS); |
| 4012 | if (status) |
| 4013 | exit(status); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4014 | /* clear affinity side-effect of get_counters() */ |
| 4015 | sched_setaffinity(0, cpu_present_setsize, cpu_present_set); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4016 | gettimeofday(&tv_even, (struct timezone *)NULL); |
| 4017 | |
| 4018 | child_pid = fork(); |
| 4019 | if (!child_pid) { |
| 4020 | /* child */ |
| 4021 | execvp(argv[0], argv); |
| 4022 | } else { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4023 | |
| 4024 | /* parent */ |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4025 | if (child_pid == -1) |
| 4026 | err(1, "fork"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4027 | |
| 4028 | signal(SIGINT, SIG_IGN); |
| 4029 | signal(SIGQUIT, SIG_IGN); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4030 | if (waitpid(child_pid, &status, 0) == -1) |
| 4031 | err(status, "waitpid"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4032 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4033 | /* |
| 4034 | * n.b. fork_it() does not check for errors from for_all_cpus() |
| 4035 | * because re-starting is problematic when forking |
| 4036 | */ |
| 4037 | for_all_cpus(get_counters, ODD_COUNTERS); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4038 | gettimeofday(&tv_odd, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4039 | timersub(&tv_odd, &tv_even, &tv_delta); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 4040 | if (for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS)) |
| 4041 | fprintf(outf, "%s: Counter reset detected\n", progname); |
| 4042 | else { |
| 4043 | compute_average(EVEN_COUNTERS); |
| 4044 | format_all_counters(EVEN_COUNTERS); |
| 4045 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4046 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4047 | fprintf(outf, "%.6f sec\n", tv_delta.tv_sec + tv_delta.tv_usec/1000000.0); |
| 4048 | |
| 4049 | flush_output_stderr(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4050 | |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 4051 | return status; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4052 | } |
| 4053 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4054 | int get_and_dump_counters(void) |
| 4055 | { |
| 4056 | int status; |
| 4057 | |
| 4058 | status = for_all_cpus(get_counters, ODD_COUNTERS); |
| 4059 | if (status) |
| 4060 | return status; |
| 4061 | |
| 4062 | status = for_all_cpus(dump_counters, ODD_COUNTERS); |
| 4063 | if (status) |
| 4064 | return status; |
| 4065 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4066 | flush_output_stdout(); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4067 | |
| 4068 | return status; |
| 4069 | } |
| 4070 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4071 | void print_version() { |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame^] | 4072 | fprintf(outf, "turbostat version 4.17 1 Jan 2017" |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4073 | " - Len Brown <lenb@kernel.org>\n"); |
| 4074 | } |
| 4075 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4076 | int add_counter(unsigned int msr_num, char *name, unsigned int width, |
| 4077 | enum counter_scope scope, enum counter_type type, |
| 4078 | enum counter_format format) |
| 4079 | { |
| 4080 | struct msr_counter *msrp; |
| 4081 | |
| 4082 | msrp = calloc(1, sizeof(struct msr_counter)); |
| 4083 | if (msrp == NULL) { |
| 4084 | perror("calloc"); |
| 4085 | exit(1); |
| 4086 | } |
| 4087 | |
| 4088 | msrp->msr_num = msr_num; |
| 4089 | strncpy(msrp->name, name, NAME_BYTES); |
| 4090 | msrp->width = width; |
| 4091 | msrp->type = type; |
| 4092 | msrp->format = format; |
| 4093 | |
| 4094 | switch (scope) { |
| 4095 | |
| 4096 | case SCOPE_CPU: |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4097 | msrp->next = sys.tp; |
| 4098 | sys.tp = msrp; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4099 | sys.added_thread_counters++; |
| 4100 | if (sys.added_thread_counters > MAX_ADDED_COUNTERS) { |
| 4101 | fprintf(stderr, "exceeded max %d added thread counters\n", |
| 4102 | MAX_ADDED_COUNTERS); |
| 4103 | exit(-1); |
| 4104 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4105 | break; |
| 4106 | |
| 4107 | case SCOPE_CORE: |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4108 | msrp->next = sys.cp; |
| 4109 | sys.cp = msrp; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4110 | sys.added_core_counters++; |
| 4111 | if (sys.added_core_counters > MAX_ADDED_COUNTERS) { |
| 4112 | fprintf(stderr, "exceeded max %d added core counters\n", |
| 4113 | MAX_ADDED_COUNTERS); |
| 4114 | exit(-1); |
| 4115 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4116 | break; |
| 4117 | |
| 4118 | case SCOPE_PACKAGE: |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4119 | msrp->next = sys.pp; |
| 4120 | sys.pp = msrp; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4121 | sys.added_package_counters++; |
| 4122 | if (sys.added_package_counters > MAX_ADDED_COUNTERS) { |
| 4123 | fprintf(stderr, "exceeded max %d added package counters\n", |
| 4124 | MAX_ADDED_COUNTERS); |
| 4125 | exit(-1); |
| 4126 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4127 | break; |
| 4128 | } |
| 4129 | |
| 4130 | return 0; |
| 4131 | } |
| 4132 | |
| 4133 | void parse_add_command(char *add_command) |
| 4134 | { |
| 4135 | int msr_num = 0; |
| 4136 | char name_buffer[NAME_BYTES]; |
| 4137 | int width = 64; |
| 4138 | int fail = 0; |
| 4139 | enum counter_scope scope = SCOPE_CPU; |
| 4140 | enum counter_type type = COUNTER_CYCLES; |
| 4141 | enum counter_format format = FORMAT_DELTA; |
| 4142 | |
| 4143 | while (add_command) { |
| 4144 | |
| 4145 | if (sscanf(add_command, "msr0x%x", &msr_num) == 1) |
| 4146 | goto next; |
| 4147 | |
| 4148 | if (sscanf(add_command, "msr%d", &msr_num) == 1) |
| 4149 | goto next; |
| 4150 | |
| 4151 | if (sscanf(add_command, "u%d", &width) == 1) { |
| 4152 | if ((width == 32) || (width == 64)) |
| 4153 | goto next; |
| 4154 | width = 64; |
| 4155 | } |
| 4156 | if (!strncmp(add_command, "cpu", strlen("cpu"))) { |
| 4157 | scope = SCOPE_CPU; |
| 4158 | goto next; |
| 4159 | } |
| 4160 | if (!strncmp(add_command, "core", strlen("core"))) { |
| 4161 | scope = SCOPE_CORE; |
| 4162 | goto next; |
| 4163 | } |
| 4164 | if (!strncmp(add_command, "package", strlen("package"))) { |
| 4165 | scope = SCOPE_PACKAGE; |
| 4166 | goto next; |
| 4167 | } |
| 4168 | if (!strncmp(add_command, "cycles", strlen("cycles"))) { |
| 4169 | type = COUNTER_CYCLES; |
| 4170 | goto next; |
| 4171 | } |
| 4172 | if (!strncmp(add_command, "seconds", strlen("seconds"))) { |
| 4173 | type = COUNTER_SECONDS; |
| 4174 | goto next; |
| 4175 | } |
| 4176 | if (!strncmp(add_command, "raw", strlen("raw"))) { |
| 4177 | format = FORMAT_RAW; |
| 4178 | goto next; |
| 4179 | } |
| 4180 | if (!strncmp(add_command, "delta", strlen("delta"))) { |
| 4181 | format = FORMAT_DELTA; |
| 4182 | goto next; |
| 4183 | } |
| 4184 | if (!strncmp(add_command, "percent", strlen("percent"))) { |
| 4185 | format = FORMAT_PERCENT; |
| 4186 | goto next; |
| 4187 | } |
| 4188 | |
| 4189 | if (sscanf(add_command, "%18s,%*s", name_buffer) == 1) { /* 18 < NAME_BYTES */ |
| 4190 | char *eos; |
| 4191 | |
| 4192 | eos = strchr(name_buffer, ','); |
| 4193 | if (eos) |
| 4194 | *eos = '\0'; |
| 4195 | goto next; |
| 4196 | } |
| 4197 | |
| 4198 | next: |
| 4199 | add_command = strchr(add_command, ','); |
| 4200 | if (add_command) |
| 4201 | add_command++; |
| 4202 | |
| 4203 | } |
| 4204 | if (msr_num == 0) { |
| 4205 | fprintf(stderr, "--add: (msrDDD | msr0xXXX) required\n"); |
| 4206 | fail++; |
| 4207 | } |
| 4208 | |
| 4209 | /* generate default column header */ |
| 4210 | if (*name_buffer == '\0') { |
| 4211 | if (format == FORMAT_RAW) { |
| 4212 | if (width == 32) |
| 4213 | sprintf(name_buffer, "msr%d", msr_num); |
| 4214 | else |
| 4215 | sprintf(name_buffer, "MSR%d", msr_num); |
| 4216 | } else if (format == FORMAT_DELTA) { |
| 4217 | if (width == 32) |
| 4218 | sprintf(name_buffer, "cnt%d", msr_num); |
| 4219 | else |
| 4220 | sprintf(name_buffer, "CNT%d", msr_num); |
| 4221 | } else if (format == FORMAT_PERCENT) { |
| 4222 | if (width == 32) |
| 4223 | sprintf(name_buffer, "msr%d%%", msr_num); |
| 4224 | else |
| 4225 | sprintf(name_buffer, "MSR%d%%", msr_num); |
| 4226 | } |
| 4227 | } |
| 4228 | |
| 4229 | if (add_counter(msr_num, name_buffer, width, scope, type, format)) |
| 4230 | fail++; |
| 4231 | |
| 4232 | if (fail) { |
| 4233 | help(); |
| 4234 | exit(1); |
| 4235 | } |
| 4236 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4237 | /* |
| 4238 | * HIDE_LIST - hide this list of counters, show the rest [default] |
| 4239 | * SHOW_LIST - show this list of counters, hide the rest |
| 4240 | */ |
| 4241 | enum show_hide_mode { SHOW_LIST, HIDE_LIST } global_show_hide_mode = HIDE_LIST; |
| 4242 | |
| 4243 | int shown; |
| 4244 | /* |
| 4245 | * parse_show_hide() - process cmdline to set default counter action |
| 4246 | */ |
| 4247 | void parse_show_hide(char *optarg, enum show_hide_mode new_mode) |
| 4248 | { |
| 4249 | /* |
| 4250 | * --show: show only those specified |
| 4251 | * The 1st invocation will clear and replace the enabled mask |
| 4252 | * subsequent invocations can add to it. |
| 4253 | */ |
| 4254 | if (new_mode == SHOW_LIST) { |
| 4255 | if (shown == 0) |
| 4256 | bic_enabled = bic_lookup(optarg); |
| 4257 | else |
| 4258 | bic_enabled |= bic_lookup(optarg); |
| 4259 | shown = 1; |
| 4260 | |
| 4261 | return; |
| 4262 | } |
| 4263 | |
| 4264 | /* |
| 4265 | * --hide: do not show those specified |
| 4266 | * multiple invocations simply clear more bits in enabled mask |
| 4267 | */ |
| 4268 | bic_enabled &= ~bic_lookup(optarg); |
| 4269 | } |
| 4270 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4271 | void cmdline(int argc, char **argv) |
| 4272 | { |
| 4273 | int opt; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4274 | int option_index = 0; |
| 4275 | static struct option long_options[] = { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4276 | {"add", required_argument, 0, 'a'}, |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4277 | {"Dump", no_argument, 0, 'D'}, |
| 4278 | {"debug", no_argument, 0, 'd'}, |
| 4279 | {"interval", required_argument, 0, 'i'}, |
| 4280 | {"help", no_argument, 0, 'h'}, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4281 | {"hide", required_argument, 0, 'H'}, // meh, -h taken by --help |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4282 | {"Joules", no_argument, 0, 'J'}, |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4283 | {"out", required_argument, 0, 'o'}, |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4284 | {"Package", no_argument, 0, 'p'}, |
| 4285 | {"processor", no_argument, 0, 'p'}, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4286 | {"show", required_argument, 0, 's'}, |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4287 | {"Summary", no_argument, 0, 'S'}, |
| 4288 | {"TCC", required_argument, 0, 'T'}, |
| 4289 | {"version", no_argument, 0, 'v' }, |
| 4290 | {0, 0, 0, 0 } |
| 4291 | }; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4292 | |
| 4293 | progname = argv[0]; |
| 4294 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4295 | while ((opt = getopt_long_only(argc, argv, "+C:c:Ddhi:JM:m:o:PpST:v", |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4296 | long_options, &option_index)) != -1) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4297 | switch (opt) { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4298 | case 'a': |
| 4299 | parse_add_command(optarg); |
| 4300 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4301 | case 'D': |
| 4302 | dump_only++; |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 4303 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4304 | case 'd': |
| 4305 | debug++; |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 4306 | break; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4307 | case 'H': |
| 4308 | parse_show_hide(optarg, HIDE_LIST); |
| 4309 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4310 | case 'h': |
| 4311 | default: |
| 4312 | help(); |
| 4313 | exit(1); |
| 4314 | case 'i': |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 4315 | { |
| 4316 | double interval = strtod(optarg, NULL); |
| 4317 | |
| 4318 | if (interval < 0.001) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4319 | fprintf(outf, "interval %f seconds is too small\n", |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 4320 | interval); |
| 4321 | exit(2); |
| 4322 | } |
| 4323 | |
| 4324 | interval_ts.tv_sec = interval; |
| 4325 | interval_ts.tv_nsec = (interval - interval_ts.tv_sec) * 1000000000; |
| 4326 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4327 | break; |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 4328 | case 'J': |
| 4329 | rapl_joules++; |
| 4330 | break; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4331 | case 'o': |
| 4332 | outf = fopen_or_die(optarg, "w"); |
| 4333 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4334 | case 'P': |
| 4335 | show_pkg_only++; |
| 4336 | break; |
| 4337 | case 'p': |
| 4338 | show_core_only++; |
| 4339 | break; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4340 | case 's': |
| 4341 | parse_show_hide(optarg, SHOW_LIST); |
| 4342 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4343 | case 'S': |
| 4344 | summary_only++; |
| 4345 | break; |
| 4346 | case 'T': |
| 4347 | tcc_activation_temp_override = atoi(optarg); |
| 4348 | break; |
| 4349 | case 'v': |
| 4350 | print_version(); |
| 4351 | exit(0); |
| 4352 | break; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4353 | } |
| 4354 | } |
| 4355 | } |
| 4356 | |
| 4357 | int main(int argc, char **argv) |
| 4358 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4359 | outf = stderr; |
| 4360 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4361 | cmdline(argc, argv); |
| 4362 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4363 | if (debug) |
| 4364 | print_version(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4365 | |
| 4366 | turbostat_init(); |
| 4367 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4368 | /* dump counters and exit */ |
| 4369 | if (dump_only) |
| 4370 | return get_and_dump_counters(); |
| 4371 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4372 | /* |
| 4373 | * if any params left, it must be a command to fork |
| 4374 | */ |
| 4375 | if (argc - optind) |
| 4376 | return fork_it(argv + optind); |
| 4377 | else |
| 4378 | turbostat_loop(); |
| 4379 | |
| 4380 | return 0; |
| 4381 | } |