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