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> |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 32 | #include <sys/select.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 33 | #include <sys/resource.h> |
| 34 | #include <fcntl.h> |
| 35 | #include <signal.h> |
| 36 | #include <sys/time.h> |
| 37 | #include <stdlib.h> |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 38 | #include <getopt.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 39 | #include <dirent.h> |
| 40 | #include <string.h> |
| 41 | #include <ctype.h> |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 42 | #include <sched.h> |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 43 | #include <time.h> |
Josh Triplett | 2b92865 | 2013-08-20 17:20:14 -0700 | [diff] [blame] | 44 | #include <cpuid.h> |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 45 | #include <linux/capability.h> |
| 46 | #include <errno.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 47 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 48 | char *proc_stat = "/proc/stat"; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 49 | FILE *outf; |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 50 | int *fd_percpu; |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 51 | struct timeval interval_tv = {5, 0}; |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 52 | struct timespec interval_ts = {5, 0}; |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 53 | struct timespec one_msec = {0, 1000000}; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 54 | unsigned int debug; |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 55 | unsigned int quiet; |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 56 | unsigned int shown; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 57 | unsigned int sums_need_wide_columns; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 58 | unsigned int rapl_joules; |
| 59 | unsigned int summary_only; |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 60 | unsigned int list_header_only; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 61 | unsigned int dump_only; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 62 | unsigned int do_snb_cstates; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 63 | unsigned int do_knl_cstates; |
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; |
Artem Bityutskiy | ac980e1 | 2017-09-05 15:14:08 +0300 | [diff] [blame^] | 94 | unsigned int has_automatic_cstate_conversion; |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 95 | unsigned int do_gfx_perf_limit_reasons; |
| 96 | unsigned int do_ring_perf_limit_reasons; |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 97 | unsigned int crystal_hz; |
| 98 | unsigned long long tsc_hz; |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 99 | int base_cpu; |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 100 | double discover_bclk(unsigned int family, unsigned int model); |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 101 | unsigned int has_hwp; /* IA32_PM_ENABLE, IA32_HWP_CAPABILITIES */ |
| 102 | /* IA32_HWP_REQUEST, IA32_HWP_STATUS */ |
| 103 | unsigned int has_hwp_notify; /* IA32_HWP_INTERRUPT */ |
| 104 | unsigned int has_hwp_activity_window; /* IA32_HWP_REQUEST[bits 41:32] */ |
| 105 | unsigned int has_hwp_epp; /* IA32_HWP_REQUEST[bits 31:24] */ |
| 106 | unsigned int has_hwp_pkg; /* IA32_HWP_REQUEST_PKG */ |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 107 | unsigned int has_misc_feature_control; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 108 | |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 109 | #define RAPL_PKG (1 << 0) |
| 110 | /* 0x610 MSR_PKG_POWER_LIMIT */ |
| 111 | /* 0x611 MSR_PKG_ENERGY_STATUS */ |
| 112 | #define RAPL_PKG_PERF_STATUS (1 << 1) |
| 113 | /* 0x613 MSR_PKG_PERF_STATUS */ |
| 114 | #define RAPL_PKG_POWER_INFO (1 << 2) |
| 115 | /* 0x614 MSR_PKG_POWER_INFO */ |
| 116 | |
| 117 | #define RAPL_DRAM (1 << 3) |
| 118 | /* 0x618 MSR_DRAM_POWER_LIMIT */ |
| 119 | /* 0x619 MSR_DRAM_ENERGY_STATUS */ |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 120 | #define RAPL_DRAM_PERF_STATUS (1 << 4) |
| 121 | /* 0x61b MSR_DRAM_PERF_STATUS */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 122 | #define RAPL_DRAM_POWER_INFO (1 << 5) |
| 123 | /* 0x61c MSR_DRAM_POWER_INFO */ |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 124 | |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 125 | #define RAPL_CORES_POWER_LIMIT (1 << 6) |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 126 | /* 0x638 MSR_PP0_POWER_LIMIT */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 127 | #define RAPL_CORE_POLICY (1 << 7) |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 128 | /* 0x63a MSR_PP0_POLICY */ |
| 129 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 130 | #define RAPL_GFX (1 << 8) |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 131 | /* 0x640 MSR_PP1_POWER_LIMIT */ |
| 132 | /* 0x641 MSR_PP1_ENERGY_STATUS */ |
| 133 | /* 0x642 MSR_PP1_POLICY */ |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 134 | |
| 135 | #define RAPL_CORES_ENERGY_STATUS (1 << 9) |
| 136 | /* 0x639 MSR_PP0_ENERGY_STATUS */ |
| 137 | #define RAPL_CORES (RAPL_CORES_ENERGY_STATUS | RAPL_CORES_POWER_LIMIT) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 138 | #define TJMAX_DEFAULT 100 |
| 139 | |
| 140 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 141 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 142 | /* |
| 143 | * buffer size used by sscanf() for added column names |
| 144 | * Usually truncated to 7 characters, but also handles 18 columns for raw 64-bit counters |
| 145 | */ |
| 146 | #define NAME_BYTES 20 |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 147 | #define PATH_BYTES 128 |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 148 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 149 | int backwards_count; |
| 150 | char *progname; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 151 | |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 152 | #define CPU_SUBSET_MAXCPUS 1024 /* need to use before probe... */ |
| 153 | cpu_set_t *cpu_present_set, *cpu_affinity_set, *cpu_subset; |
| 154 | size_t cpu_present_setsize, cpu_affinity_setsize, cpu_subset_size; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 155 | #define MAX_ADDED_COUNTERS 16 |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 156 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 157 | struct thread_data { |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 158 | struct timeval tv_begin; |
| 159 | struct timeval tv_end; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 160 | unsigned long long tsc; |
| 161 | unsigned long long aperf; |
| 162 | unsigned long long mperf; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 163 | unsigned long long c1; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 164 | unsigned long long irq_count; |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 165 | unsigned int smi_count; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 166 | unsigned int cpu_id; |
| 167 | unsigned int flags; |
| 168 | #define CPU_IS_FIRST_THREAD_IN_CORE 0x2 |
| 169 | #define CPU_IS_FIRST_CORE_IN_PACKAGE 0x4 |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 170 | unsigned long long counter[MAX_ADDED_COUNTERS]; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 171 | } *thread_even, *thread_odd; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 172 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 173 | struct core_data { |
| 174 | unsigned long long c3; |
| 175 | unsigned long long c6; |
| 176 | unsigned long long c7; |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 177 | 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] | 178 | unsigned int core_temp_c; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 179 | unsigned int core_id; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 180 | unsigned long long counter[MAX_ADDED_COUNTERS]; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 181 | } *core_even, *core_odd; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 182 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 183 | struct pkg_data { |
| 184 | unsigned long long pc2; |
| 185 | unsigned long long pc3; |
| 186 | unsigned long long pc6; |
| 187 | unsigned long long pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 188 | unsigned long long pc8; |
| 189 | unsigned long long pc9; |
| 190 | unsigned long long pc10; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 191 | unsigned long long pkg_wtd_core_c0; |
| 192 | unsigned long long pkg_any_core_c0; |
| 193 | unsigned long long pkg_any_gfxe_c0; |
| 194 | unsigned long long pkg_both_core_gfxe_c0; |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 195 | long long gfx_rc6_ms; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 196 | unsigned int gfx_mhz; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 197 | unsigned int package_id; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 198 | unsigned int energy_pkg; /* MSR_PKG_ENERGY_STATUS */ |
| 199 | unsigned int energy_dram; /* MSR_DRAM_ENERGY_STATUS */ |
| 200 | unsigned int energy_cores; /* MSR_PP0_ENERGY_STATUS */ |
| 201 | unsigned int energy_gfx; /* MSR_PP1_ENERGY_STATUS */ |
| 202 | unsigned int rapl_pkg_perf_status; /* MSR_PKG_PERF_STATUS */ |
| 203 | unsigned int rapl_dram_perf_status; /* MSR_DRAM_PERF_STATUS */ |
| 204 | unsigned int pkg_temp_c; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 205 | unsigned long long counter[MAX_ADDED_COUNTERS]; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 206 | } *package_even, *package_odd; |
| 207 | |
| 208 | #define ODD_COUNTERS thread_odd, core_odd, package_odd |
| 209 | #define EVEN_COUNTERS thread_even, core_even, package_even |
| 210 | |
| 211 | #define GET_THREAD(thread_base, thread_no, core_no, pkg_no) \ |
| 212 | (thread_base + (pkg_no) * topo.num_cores_per_pkg * \ |
| 213 | topo.num_threads_per_core + \ |
| 214 | (core_no) * topo.num_threads_per_core + (thread_no)) |
| 215 | #define GET_CORE(core_base, core_no, pkg_no) \ |
| 216 | (core_base + (pkg_no) * topo.num_cores_per_pkg + (core_no)) |
| 217 | #define GET_PKG(pkg_base, pkg_no) (pkg_base + pkg_no) |
| 218 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 219 | enum counter_scope {SCOPE_CPU, SCOPE_CORE, SCOPE_PACKAGE}; |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 220 | enum counter_type {COUNTER_ITEMS, COUNTER_CYCLES, COUNTER_SECONDS, COUNTER_USEC}; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 221 | enum counter_format {FORMAT_RAW, FORMAT_DELTA, FORMAT_PERCENT}; |
| 222 | |
| 223 | struct msr_counter { |
| 224 | unsigned int msr_num; |
| 225 | char name[NAME_BYTES]; |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 226 | char path[PATH_BYTES]; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 227 | unsigned int width; |
| 228 | enum counter_type type; |
| 229 | enum counter_format format; |
| 230 | struct msr_counter *next; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 231 | unsigned int flags; |
| 232 | #define FLAGS_HIDE (1 << 0) |
| 233 | #define FLAGS_SHOW (1 << 1) |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 234 | #define SYSFS_PERCPU (1 << 1) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 235 | }; |
| 236 | |
| 237 | struct sys_counters { |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 238 | unsigned int added_thread_counters; |
| 239 | unsigned int added_core_counters; |
| 240 | unsigned int added_package_counters; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 241 | struct msr_counter *tp; |
| 242 | struct msr_counter *cp; |
| 243 | struct msr_counter *pp; |
| 244 | } sys; |
| 245 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 246 | struct system_summary { |
| 247 | struct thread_data threads; |
| 248 | struct core_data cores; |
| 249 | struct pkg_data packages; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 250 | } average; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 251 | |
| 252 | |
| 253 | struct topo_params { |
| 254 | int num_packages; |
| 255 | int num_cpus; |
| 256 | int num_cores; |
| 257 | int max_cpu_num; |
| 258 | int num_cores_per_pkg; |
| 259 | int num_threads_per_core; |
| 260 | } topo; |
| 261 | |
| 262 | struct timeval tv_even, tv_odd, tv_delta; |
| 263 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 264 | int *irq_column_2_cpu; /* /proc/interrupts column numbers */ |
| 265 | int *irqs_per_cpu; /* indexed by cpu_num */ |
| 266 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 267 | void setup_all_buffers(void); |
| 268 | |
| 269 | int cpu_is_not_present(int cpu) |
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 | return !CPU_ISSET_S(cpu, cpu_present_setsize, cpu_present_set); |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 272 | } |
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 | * run func(thread, core, package) in topology order |
| 275 | * skip non-present cpus |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 276 | */ |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 277 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 278 | int for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg_data *), |
| 279 | 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] | 280 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 281 | int retval, pkg_no, core_no, thread_no; |
| 282 | |
| 283 | for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { |
| 284 | for (core_no = 0; core_no < topo.num_cores_per_pkg; ++core_no) { |
| 285 | for (thread_no = 0; thread_no < |
| 286 | topo.num_threads_per_core; ++thread_no) { |
| 287 | struct thread_data *t; |
| 288 | struct core_data *c; |
| 289 | struct pkg_data *p; |
| 290 | |
| 291 | t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); |
| 292 | |
| 293 | if (cpu_is_not_present(t->cpu_id)) |
| 294 | continue; |
| 295 | |
| 296 | c = GET_CORE(core_base, core_no, pkg_no); |
| 297 | p = GET_PKG(pkg_base, pkg_no); |
| 298 | |
| 299 | retval = func(t, c, p); |
| 300 | if (retval) |
| 301 | return retval; |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | return 0; |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | int cpu_migrate(int cpu) |
| 309 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 310 | CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); |
| 311 | CPU_SET_S(cpu, cpu_affinity_setsize, cpu_affinity_set); |
| 312 | if (sched_setaffinity(0, cpu_affinity_setsize, cpu_affinity_set) == -1) |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 313 | return -1; |
| 314 | else |
| 315 | return 0; |
| 316 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 317 | int get_msr_fd(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 318 | { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 319 | char pathname[32]; |
| 320 | int fd; |
| 321 | |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 322 | fd = fd_percpu[cpu]; |
| 323 | |
| 324 | if (fd) |
| 325 | return fd; |
| 326 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 327 | sprintf(pathname, "/dev/cpu/%d/msr", cpu); |
| 328 | fd = open(pathname, O_RDONLY); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 329 | if (fd < 0) |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 330 | 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] | 331 | |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 332 | fd_percpu[cpu] = fd; |
| 333 | |
| 334 | return fd; |
| 335 | } |
| 336 | |
| 337 | int get_msr(int cpu, off_t offset, unsigned long long *msr) |
| 338 | { |
| 339 | ssize_t retval; |
| 340 | |
| 341 | retval = pread(get_msr_fd(cpu), msr, sizeof(*msr), offset); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 342 | |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 343 | if (retval != sizeof *msr) |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 344 | 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] | 345 | |
| 346 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 347 | } |
| 348 | |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 349 | /* |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 350 | * Each string in this array is compared in --show and --hide cmdline. |
| 351 | * 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] | 352 | */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 353 | struct msr_counter bic[] = { |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 354 | { 0x0, "usec" }, |
| 355 | { 0x0, "Time_Of_Day_Seconds" }, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 356 | { 0x0, "Package" }, |
| 357 | { 0x0, "Avg_MHz" }, |
| 358 | { 0x0, "Bzy_MHz" }, |
| 359 | { 0x0, "TSC_MHz" }, |
| 360 | { 0x0, "IRQ" }, |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 361 | { 0x0, "SMI", "", 32, 0, FORMAT_DELTA, NULL}, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 362 | { 0x0, "Busy%" }, |
| 363 | { 0x0, "CPU%c1" }, |
| 364 | { 0x0, "CPU%c3" }, |
| 365 | { 0x0, "CPU%c6" }, |
| 366 | { 0x0, "CPU%c7" }, |
| 367 | { 0x0, "ThreadC" }, |
| 368 | { 0x0, "CoreTmp" }, |
| 369 | { 0x0, "CoreCnt" }, |
| 370 | { 0x0, "PkgTmp" }, |
| 371 | { 0x0, "GFX%rc6" }, |
| 372 | { 0x0, "GFXMHz" }, |
| 373 | { 0x0, "Pkg%pc2" }, |
| 374 | { 0x0, "Pkg%pc3" }, |
| 375 | { 0x0, "Pkg%pc6" }, |
| 376 | { 0x0, "Pkg%pc7" }, |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 377 | { 0x0, "Pkg%pc8" }, |
| 378 | { 0x0, "Pkg%pc9" }, |
| 379 | { 0x0, "Pkg%pc10" }, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 380 | { 0x0, "PkgWatt" }, |
| 381 | { 0x0, "CorWatt" }, |
| 382 | { 0x0, "GFXWatt" }, |
| 383 | { 0x0, "PkgCnt" }, |
| 384 | { 0x0, "RAMWatt" }, |
| 385 | { 0x0, "PKG_%" }, |
| 386 | { 0x0, "RAM_%" }, |
| 387 | { 0x0, "Pkg_J" }, |
| 388 | { 0x0, "Cor_J" }, |
| 389 | { 0x0, "GFX_J" }, |
| 390 | { 0x0, "RAM_J" }, |
| 391 | { 0x0, "Core" }, |
| 392 | { 0x0, "CPU" }, |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 393 | { 0x0, "Mod%c6" }, |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 394 | { 0x0, "sysfs" }, |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 395 | { 0x0, "Totl%C0" }, |
| 396 | { 0x0, "Any%C0" }, |
| 397 | { 0x0, "GFX%C0" }, |
| 398 | { 0x0, "CPUGFX%" }, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 399 | }; |
| 400 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 401 | |
| 402 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 403 | #define MAX_BIC (sizeof(bic) / sizeof(struct msr_counter)) |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 404 | #define BIC_USEC (1ULL << 0) |
| 405 | #define BIC_TOD (1ULL << 1) |
| 406 | #define BIC_Package (1ULL << 2) |
| 407 | #define BIC_Avg_MHz (1ULL << 3) |
| 408 | #define BIC_Bzy_MHz (1ULL << 4) |
| 409 | #define BIC_TSC_MHz (1ULL << 5) |
| 410 | #define BIC_IRQ (1ULL << 6) |
| 411 | #define BIC_SMI (1ULL << 7) |
| 412 | #define BIC_Busy (1ULL << 8) |
| 413 | #define BIC_CPU_c1 (1ULL << 9) |
| 414 | #define BIC_CPU_c3 (1ULL << 10) |
| 415 | #define BIC_CPU_c6 (1ULL << 11) |
| 416 | #define BIC_CPU_c7 (1ULL << 12) |
| 417 | #define BIC_ThreadC (1ULL << 13) |
| 418 | #define BIC_CoreTmp (1ULL << 14) |
| 419 | #define BIC_CoreCnt (1ULL << 15) |
| 420 | #define BIC_PkgTmp (1ULL << 16) |
| 421 | #define BIC_GFX_rc6 (1ULL << 17) |
| 422 | #define BIC_GFXMHz (1ULL << 18) |
| 423 | #define BIC_Pkgpc2 (1ULL << 19) |
| 424 | #define BIC_Pkgpc3 (1ULL << 20) |
| 425 | #define BIC_Pkgpc6 (1ULL << 21) |
| 426 | #define BIC_Pkgpc7 (1ULL << 22) |
| 427 | #define BIC_Pkgpc8 (1ULL << 23) |
| 428 | #define BIC_Pkgpc9 (1ULL << 24) |
| 429 | #define BIC_Pkgpc10 (1ULL << 25) |
| 430 | #define BIC_PkgWatt (1ULL << 26) |
| 431 | #define BIC_CorWatt (1ULL << 27) |
| 432 | #define BIC_GFXWatt (1ULL << 28) |
| 433 | #define BIC_PkgCnt (1ULL << 29) |
| 434 | #define BIC_RAMWatt (1ULL << 30) |
| 435 | #define BIC_PKG__ (1ULL << 31) |
| 436 | #define BIC_RAM__ (1ULL << 32) |
| 437 | #define BIC_Pkg_J (1ULL << 33) |
| 438 | #define BIC_Cor_J (1ULL << 34) |
| 439 | #define BIC_GFX_J (1ULL << 35) |
| 440 | #define BIC_RAM_J (1ULL << 36) |
| 441 | #define BIC_Core (1ULL << 37) |
| 442 | #define BIC_CPU (1ULL << 38) |
| 443 | #define BIC_Mod_c6 (1ULL << 39) |
| 444 | #define BIC_sysfs (1ULL << 40) |
| 445 | #define BIC_Totl_c0 (1ULL << 41) |
| 446 | #define BIC_Any_c0 (1ULL << 42) |
| 447 | #define BIC_GFX_c0 (1ULL << 43) |
| 448 | #define BIC_CPUGFX (1ULL << 44) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 449 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 450 | #define BIC_DISABLED_BY_DEFAULT (BIC_USEC | BIC_TOD) |
| 451 | |
| 452 | unsigned long long bic_enabled = (0xFFFFFFFFFFFFFFFFULL & ~BIC_DISABLED_BY_DEFAULT); |
| 453 | unsigned long long bic_present = BIC_USEC | BIC_TOD | BIC_sysfs; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 454 | |
| 455 | #define DO_BIC(COUNTER_NAME) (bic_enabled & bic_present & COUNTER_NAME) |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 456 | #define ENABLE_BIC(COUNTER_NAME) (bic_enabled |= COUNTER_NAME) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 457 | #define BIC_PRESENT(COUNTER_BIT) (bic_present |= COUNTER_BIT) |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 458 | #define BIC_NOT_PRESENT(COUNTER_BIT) (bic_present &= ~COUNTER_BIT) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 459 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 460 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 461 | #define MAX_DEFERRED 16 |
| 462 | char *deferred_skip_names[MAX_DEFERRED]; |
| 463 | int deferred_skip_index; |
| 464 | |
| 465 | /* |
| 466 | * HIDE_LIST - hide this list of counters, show the rest [default] |
| 467 | * SHOW_LIST - show this list of counters, hide the rest |
| 468 | */ |
| 469 | enum show_hide_mode { SHOW_LIST, HIDE_LIST } global_show_hide_mode = HIDE_LIST; |
| 470 | |
| 471 | void help(void) |
| 472 | { |
| 473 | fprintf(outf, |
| 474 | "Usage: turbostat [OPTIONS][(--interval seconds) | COMMAND ...]\n" |
| 475 | "\n" |
| 476 | "Turbostat forks the specified COMMAND and prints statistics\n" |
| 477 | "when COMMAND completes.\n" |
| 478 | "If no COMMAND is specified, turbostat wakes every 5-seconds\n" |
| 479 | "to print statistics, until interrupted.\n" |
| 480 | "--add add a counter\n" |
| 481 | " eg. --add msr0x10,u64,cpu,delta,MY_TSC\n" |
| 482 | "--cpu cpu-set limit output to summary plus cpu-set:\n" |
| 483 | " {core | package | j,k,l..m,n-p }\n" |
| 484 | "--quiet skip decoding system configuration header\n" |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 485 | "--interval sec.subsec Override default 5-second measurement interval\n" |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 486 | "--help print this help message\n" |
| 487 | "--list list column headers only\n" |
| 488 | "--out file create or truncate \"file\" for all output\n" |
| 489 | "--version print version information\n" |
| 490 | "\n" |
| 491 | "For more help, run \"man turbostat\"\n"); |
| 492 | } |
| 493 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 494 | /* |
| 495 | * bic_lookup |
| 496 | * for all the strings in comma separate name_list, |
| 497 | * set the approprate bit in return value. |
| 498 | */ |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 499 | unsigned long long bic_lookup(char *name_list, enum show_hide_mode mode) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 500 | { |
| 501 | int i; |
| 502 | unsigned long long retval = 0; |
| 503 | |
| 504 | while (name_list) { |
| 505 | char *comma; |
| 506 | |
| 507 | comma = strchr(name_list, ','); |
| 508 | |
| 509 | if (comma) |
| 510 | *comma = '\0'; |
| 511 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 512 | if (!strcmp(name_list, "all")) |
| 513 | return ~0; |
| 514 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 515 | for (i = 0; i < MAX_BIC; ++i) { |
| 516 | if (!strcmp(name_list, bic[i].name)) { |
| 517 | retval |= (1ULL << i); |
| 518 | break; |
| 519 | } |
| 520 | } |
| 521 | if (i == MAX_BIC) { |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 522 | if (mode == SHOW_LIST) { |
| 523 | fprintf(stderr, "Invalid counter name: %s\n", name_list); |
| 524 | exit(-1); |
| 525 | } |
| 526 | deferred_skip_names[deferred_skip_index++] = name_list; |
| 527 | if (debug) |
| 528 | fprintf(stderr, "deferred \"%s\"\n", name_list); |
| 529 | if (deferred_skip_index >= MAX_DEFERRED) { |
| 530 | fprintf(stderr, "More than max %d un-recognized --skip options '%s'\n", |
| 531 | MAX_DEFERRED, name_list); |
| 532 | help(); |
| 533 | exit(1); |
| 534 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | name_list = comma; |
| 538 | if (name_list) |
| 539 | name_list++; |
| 540 | |
| 541 | } |
| 542 | return retval; |
| 543 | } |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 544 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 545 | |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 546 | void print_header(char *delim) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 547 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 548 | struct msr_counter *mp; |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 549 | int printed = 0; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 550 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 551 | if (DO_BIC(BIC_USEC)) |
| 552 | outp += sprintf(outp, "%susec", (printed++ ? delim : "")); |
| 553 | if (DO_BIC(BIC_TOD)) |
| 554 | outp += sprintf(outp, "%sTime_Of_Day_Seconds", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 555 | if (DO_BIC(BIC_Package)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 556 | outp += sprintf(outp, "%sPackage", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 557 | if (DO_BIC(BIC_Core)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 558 | outp += sprintf(outp, "%sCore", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 559 | if (DO_BIC(BIC_CPU)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 560 | outp += sprintf(outp, "%sCPU", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 561 | if (DO_BIC(BIC_Avg_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 562 | outp += sprintf(outp, "%sAvg_MHz", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 563 | if (DO_BIC(BIC_Busy)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 564 | outp += sprintf(outp, "%sBusy%%", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 565 | if (DO_BIC(BIC_Bzy_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 566 | outp += sprintf(outp, "%sBzy_MHz", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 567 | if (DO_BIC(BIC_TSC_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 568 | outp += sprintf(outp, "%sTSC_MHz", (printed++ ? delim : "")); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 569 | |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 570 | if (DO_BIC(BIC_IRQ)) { |
| 571 | if (sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 572 | outp += sprintf(outp, "%s IRQ", (printed++ ? delim : "")); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 573 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 574 | outp += sprintf(outp, "%sIRQ", (printed++ ? delim : "")); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 575 | } |
| 576 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 577 | if (DO_BIC(BIC_SMI)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 578 | outp += sprintf(outp, "%sSMI", (printed++ ? delim : "")); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 579 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 580 | for (mp = sys.tp; mp; mp = mp->next) { |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 581 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 582 | if (mp->format == FORMAT_RAW) { |
| 583 | if (mp->width == 64) |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 584 | outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 585 | else |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 586 | outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 587 | } else { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 588 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 589 | outp += sprintf(outp, "%s%8s", (printed++ ? delim : ""), mp->name); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 590 | else |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 591 | outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 592 | } |
| 593 | } |
| 594 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 595 | if (DO_BIC(BIC_CPU_c1)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 596 | outp += sprintf(outp, "%sCPU%%c1", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 597 | if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 598 | outp += sprintf(outp, "%sCPU%%c3", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 599 | if (DO_BIC(BIC_CPU_c6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 600 | outp += sprintf(outp, "%sCPU%%c6", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 601 | if (DO_BIC(BIC_CPU_c7)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 602 | outp += sprintf(outp, "%sCPU%%c7", (printed++ ? delim : "")); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 603 | |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 604 | if (DO_BIC(BIC_Mod_c6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 605 | outp += sprintf(outp, "%sMod%%c6", (printed++ ? delim : "")); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 606 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 607 | if (DO_BIC(BIC_CoreTmp)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 608 | outp += sprintf(outp, "%sCoreTmp", (printed++ ? delim : "")); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 609 | |
| 610 | for (mp = sys.cp; mp; mp = mp->next) { |
| 611 | if (mp->format == FORMAT_RAW) { |
| 612 | if (mp->width == 64) |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 613 | outp += sprintf(outp, "%s%18.18s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 614 | else |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 615 | outp += sprintf(outp, "%s%10.10s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 616 | } else { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 617 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
| 618 | outp += sprintf(outp, "%s%8s", delim, mp->name); |
| 619 | else |
| 620 | outp += sprintf(outp, "%s%s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 624 | if (DO_BIC(BIC_PkgTmp)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 625 | outp += sprintf(outp, "%sPkgTmp", (printed++ ? delim : "")); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 626 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 627 | if (DO_BIC(BIC_GFX_rc6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 628 | outp += sprintf(outp, "%sGFX%%rc6", (printed++ ? delim : "")); |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 629 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 630 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 631 | outp += sprintf(outp, "%sGFXMHz", (printed++ ? delim : "")); |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 632 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 633 | if (DO_BIC(BIC_Totl_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 634 | outp += sprintf(outp, "%sTotl%%C0", (printed++ ? delim : "")); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 635 | if (DO_BIC(BIC_Any_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 636 | outp += sprintf(outp, "%sAny%%C0", (printed++ ? delim : "")); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 637 | if (DO_BIC(BIC_GFX_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 638 | outp += sprintf(outp, "%sGFX%%C0", (printed++ ? delim : "")); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 639 | if (DO_BIC(BIC_CPUGFX)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 640 | outp += sprintf(outp, "%sCPUGFX%%", (printed++ ? delim : "")); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 641 | |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 642 | if (DO_BIC(BIC_Pkgpc2)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 643 | outp += sprintf(outp, "%sPkg%%pc2", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 644 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 645 | outp += sprintf(outp, "%sPkg%%pc3", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 646 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 647 | outp += sprintf(outp, "%sPkg%%pc6", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 648 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 649 | outp += sprintf(outp, "%sPkg%%pc7", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 650 | if (DO_BIC(BIC_Pkgpc8)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 651 | outp += sprintf(outp, "%sPkg%%pc8", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 652 | if (DO_BIC(BIC_Pkgpc9)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 653 | outp += sprintf(outp, "%sPkg%%pc9", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 654 | if (DO_BIC(BIC_Pkgpc10)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 655 | outp += sprintf(outp, "%sPk%%pc10", (printed++ ? delim : "")); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 656 | |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 657 | if (do_rapl && !rapl_joules) { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 658 | if (DO_BIC(BIC_PkgWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 659 | outp += sprintf(outp, "%sPkgWatt", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 660 | if (DO_BIC(BIC_CorWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 661 | outp += sprintf(outp, "%sCorWatt", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 662 | if (DO_BIC(BIC_GFXWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 663 | outp += sprintf(outp, "%sGFXWatt", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 664 | if (DO_BIC(BIC_RAMWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 665 | outp += sprintf(outp, "%sRAMWatt", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 666 | if (DO_BIC(BIC_PKG__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 667 | outp += sprintf(outp, "%sPKG_%%", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 668 | if (DO_BIC(BIC_RAM__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 669 | outp += sprintf(outp, "%sRAM_%%", (printed++ ? delim : "")); |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 670 | } else if (do_rapl && rapl_joules) { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 671 | if (DO_BIC(BIC_Pkg_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 672 | outp += sprintf(outp, "%sPkg_J", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 673 | if (DO_BIC(BIC_Cor_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 674 | outp += sprintf(outp, "%sCor_J", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 675 | if (DO_BIC(BIC_GFX_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 676 | outp += sprintf(outp, "%sGFX_J", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 677 | if (DO_BIC(BIC_RAM_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 678 | outp += sprintf(outp, "%sRAM_J", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 679 | if (DO_BIC(BIC_PKG__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 680 | outp += sprintf(outp, "%sPKG_%%", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 681 | if (DO_BIC(BIC_RAM__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 682 | outp += sprintf(outp, "%sRAM_%%", (printed++ ? delim : "")); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 683 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 684 | for (mp = sys.pp; mp; mp = mp->next) { |
| 685 | if (mp->format == FORMAT_RAW) { |
| 686 | if (mp->width == 64) |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 687 | outp += sprintf(outp, "%s%18.18s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 688 | else |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 689 | outp += sprintf(outp, "%s%10.10s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 690 | } else { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 691 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
| 692 | outp += sprintf(outp, "%s%8s", delim, mp->name); |
| 693 | else |
| 694 | outp += sprintf(outp, "%s%s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 698 | outp += sprintf(outp, "\n"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 699 | } |
| 700 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 701 | int dump_counters(struct thread_data *t, struct core_data *c, |
| 702 | struct pkg_data *p) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 703 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 704 | int i; |
| 705 | struct msr_counter *mp; |
| 706 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 707 | 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] | 708 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 709 | if (t) { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 710 | outp += sprintf(outp, "CPU: %d flags 0x%x\n", |
| 711 | t->cpu_id, t->flags); |
| 712 | outp += sprintf(outp, "TSC: %016llX\n", t->tsc); |
| 713 | outp += sprintf(outp, "aperf: %016llX\n", t->aperf); |
| 714 | outp += sprintf(outp, "mperf: %016llX\n", t->mperf); |
| 715 | outp += sprintf(outp, "c1: %016llX\n", t->c1); |
Len Brown | 6886fee | 2016-12-24 15:18:37 -0500 | [diff] [blame] | 716 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 717 | if (DO_BIC(BIC_IRQ)) |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 718 | outp += sprintf(outp, "IRQ: %lld\n", t->irq_count); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 719 | if (DO_BIC(BIC_SMI)) |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 720 | outp += sprintf(outp, "SMI: %d\n", t->smi_count); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 721 | |
| 722 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 723 | outp += sprintf(outp, "tADDED [%d] msr0x%x: %08llX\n", |
| 724 | i, mp->msr_num, t->counter[i]); |
| 725 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 726 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 727 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 728 | if (c) { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 729 | outp += sprintf(outp, "core: %d\n", c->core_id); |
| 730 | outp += sprintf(outp, "c3: %016llX\n", c->c3); |
| 731 | outp += sprintf(outp, "c6: %016llX\n", c->c6); |
| 732 | outp += sprintf(outp, "c7: %016llX\n", c->c7); |
| 733 | outp += sprintf(outp, "DTS: %dC\n", c->core_temp_c); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 734 | |
| 735 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 736 | outp += sprintf(outp, "cADDED [%d] msr0x%x: %08llX\n", |
| 737 | i, mp->msr_num, c->counter[i]); |
| 738 | } |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 739 | outp += sprintf(outp, "mc6_us: %016llX\n", c->mc6_us); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | if (p) { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 743 | outp += sprintf(outp, "package: %d\n", p->package_id); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 744 | |
| 745 | outp += sprintf(outp, "Weighted cores: %016llX\n", p->pkg_wtd_core_c0); |
| 746 | outp += sprintf(outp, "Any cores: %016llX\n", p->pkg_any_core_c0); |
| 747 | outp += sprintf(outp, "Any GFX: %016llX\n", p->pkg_any_gfxe_c0); |
| 748 | outp += sprintf(outp, "CPU + GFX: %016llX\n", p->pkg_both_core_gfxe_c0); |
| 749 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 750 | outp += sprintf(outp, "pc2: %016llX\n", p->pc2); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 751 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 752 | outp += sprintf(outp, "pc3: %016llX\n", p->pc3); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 753 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 754 | outp += sprintf(outp, "pc6: %016llX\n", p->pc6); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 755 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 756 | outp += sprintf(outp, "pc7: %016llX\n", p->pc7); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 757 | outp += sprintf(outp, "pc8: %016llX\n", p->pc8); |
| 758 | outp += sprintf(outp, "pc9: %016llX\n", p->pc9); |
| 759 | outp += sprintf(outp, "pc10: %016llX\n", p->pc10); |
| 760 | outp += sprintf(outp, "Joules PKG: %0X\n", p->energy_pkg); |
| 761 | outp += sprintf(outp, "Joules COR: %0X\n", p->energy_cores); |
| 762 | outp += sprintf(outp, "Joules GFX: %0X\n", p->energy_gfx); |
| 763 | outp += sprintf(outp, "Joules RAM: %0X\n", p->energy_dram); |
| 764 | outp += sprintf(outp, "Throttle PKG: %0X\n", |
| 765 | p->rapl_pkg_perf_status); |
| 766 | outp += sprintf(outp, "Throttle RAM: %0X\n", |
| 767 | p->rapl_dram_perf_status); |
| 768 | outp += sprintf(outp, "PTM: %dC\n", p->pkg_temp_c); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 769 | |
| 770 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 771 | outp += sprintf(outp, "pADDED [%d] msr0x%x: %08llX\n", |
| 772 | i, mp->msr_num, p->counter[i]); |
| 773 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 774 | } |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 775 | |
| 776 | outp += sprintf(outp, "\n"); |
| 777 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 778 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 779 | } |
| 780 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 781 | /* |
| 782 | * column formatting convention & formats |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 783 | */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 784 | int format_counters(struct thread_data *t, struct core_data *c, |
| 785 | struct pkg_data *p) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 786 | { |
Len Brown | 008d396e | 2017-02-10 00:29:51 -0500 | [diff] [blame] | 787 | double interval_float, tsc; |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 788 | char *fmt8; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 789 | int i; |
| 790 | struct msr_counter *mp; |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 791 | char *delim = "\t"; |
| 792 | int printed = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 793 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 794 | /* if showing only 1st thread in core and this isn't one, bail out */ |
| 795 | if (show_core_only && !(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 796 | return 0; |
| 797 | |
| 798 | /* if showing only 1st thread in pkg and this isn't one, bail out */ |
| 799 | if (show_pkg_only && !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 800 | return 0; |
| 801 | |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 802 | /*if not summary line and --cpu is used */ |
| 803 | if ((t != &average.threads) && |
| 804 | (cpu_subset && !CPU_ISSET_S(t->cpu_id, cpu_subset_size, cpu_subset))) |
| 805 | return 0; |
| 806 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 807 | if (DO_BIC(BIC_USEC)) { |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 808 | /* on each row, print how many usec each timestamp took to gather */ |
| 809 | struct timeval tv; |
| 810 | |
| 811 | timersub(&t->tv_end, &t->tv_begin, &tv); |
| 812 | outp += sprintf(outp, "%5ld\t", tv.tv_sec * 1000000 + tv.tv_usec); |
| 813 | } |
| 814 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 815 | /* Time_Of_Day_Seconds: on each row, print sec.usec last timestamp taken */ |
| 816 | if (DO_BIC(BIC_TOD)) |
| 817 | outp += sprintf(outp, "%10ld.%06ld\t", t->tv_end.tv_sec, t->tv_end.tv_usec); |
| 818 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 819 | interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0; |
| 820 | |
Len Brown | 008d396e | 2017-02-10 00:29:51 -0500 | [diff] [blame] | 821 | tsc = t->tsc * tsc_tweak; |
| 822 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 823 | /* topo columns, print blanks on 1st (average) line */ |
| 824 | if (t == &average.threads) { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 825 | if (DO_BIC(BIC_Package)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 826 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 827 | if (DO_BIC(BIC_Core)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 828 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 829 | if (DO_BIC(BIC_CPU)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 830 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 831 | } else { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 832 | if (DO_BIC(BIC_Package)) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 833 | if (p) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 834 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->package_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 835 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 836 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 837 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 838 | if (DO_BIC(BIC_Core)) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 839 | if (c) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 840 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), c->core_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 841 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 842 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 843 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 844 | if (DO_BIC(BIC_CPU)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 845 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->cpu_id); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 846 | } |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 847 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 848 | if (DO_BIC(BIC_Avg_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 849 | outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 850 | 1.0 / units * t->aperf / interval_float); |
| 851 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 852 | if (DO_BIC(BIC_Busy)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 853 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->mperf/tsc); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 854 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 855 | if (DO_BIC(BIC_Bzy_MHz)) { |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 856 | if (has_base_hz) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 857 | outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), base_hz / units * t->aperf / t->mperf); |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 858 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 859 | outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), |
Len Brown | 008d396e | 2017-02-10 00:29:51 -0500 | [diff] [blame] | 860 | tsc / units * t->aperf / t->mperf / interval_float); |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 861 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 862 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 863 | if (DO_BIC(BIC_TSC_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 864 | outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), 1.0 * t->tsc/units/interval_float); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 865 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 866 | /* IRQ */ |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 867 | if (DO_BIC(BIC_IRQ)) { |
| 868 | if (sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 869 | outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), t->irq_count); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 870 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 871 | outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->irq_count); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 872 | } |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 873 | |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 874 | /* SMI */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 875 | if (DO_BIC(BIC_SMI)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 876 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->smi_count); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 877 | |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 878 | /* Added counters */ |
| 879 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 880 | if (mp->format == FORMAT_RAW) { |
| 881 | if (mp->width == 32) |
Len Brown | 5f3aea5 | 2017-02-23 18:10:27 -0500 | [diff] [blame] | 882 | outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int) t->counter[i]); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 883 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 884 | outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), t->counter[i]); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 885 | } else if (mp->format == FORMAT_DELTA) { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 886 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 887 | outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), t->counter[i]); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 888 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 889 | outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->counter[i]); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 890 | } else if (mp->format == FORMAT_PERCENT) { |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 891 | if (mp->type == COUNTER_USEC) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 892 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), t->counter[i]/interval_float/10000); |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 893 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 894 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->counter[i]/tsc); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 895 | } |
| 896 | } |
| 897 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 898 | /* C1 */ |
| 899 | if (DO_BIC(BIC_CPU_c1)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 900 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->c1/tsc); |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 901 | |
| 902 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 903 | /* print per-core data only for 1st thread in core */ |
| 904 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 905 | goto done; |
| 906 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 907 | if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 908 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c3/tsc); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 909 | if (DO_BIC(BIC_CPU_c6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 910 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c6/tsc); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 911 | if (DO_BIC(BIC_CPU_c7)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 912 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c7/tsc); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 913 | |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 914 | /* Mod%c6 */ |
| 915 | if (DO_BIC(BIC_Mod_c6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 916 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->mc6_us / tsc); |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 917 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 918 | if (DO_BIC(BIC_CoreTmp)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 919 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), c->core_temp_c); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 920 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 921 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 922 | if (mp->format == FORMAT_RAW) { |
| 923 | if (mp->width == 32) |
Len Brown | 5f3aea5 | 2017-02-23 18:10:27 -0500 | [diff] [blame] | 924 | outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int) c->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 925 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 926 | outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), c->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 927 | } else if (mp->format == FORMAT_DELTA) { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 928 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 929 | outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), c->counter[i]); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 930 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 931 | outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), c->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 932 | } else if (mp->format == FORMAT_PERCENT) { |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 933 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->counter[i]/tsc); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 934 | } |
| 935 | } |
| 936 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 937 | /* print per-package data only for 1st core in package */ |
| 938 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 939 | goto done; |
| 940 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 941 | /* PkgTmp */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 942 | if (DO_BIC(BIC_PkgTmp)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 943 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->pkg_temp_c); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 944 | |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 945 | /* GFXrc6 */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 946 | if (DO_BIC(BIC_GFX_rc6)) { |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 947 | if (p->gfx_rc6_ms == -1) { /* detect GFX counter reset */ |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 948 | outp += sprintf(outp, "%s**.**", (printed++ ? delim : "")); |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 949 | } else { |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 950 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 951 | p->gfx_rc6_ms / 10.0 / interval_float); |
| 952 | } |
| 953 | } |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 954 | |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 955 | /* GFXMHz */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 956 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 957 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->gfx_mhz); |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 958 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 959 | /* Totl%C0, Any%C0 GFX%C0 CPUGFX% */ |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 960 | if (DO_BIC(BIC_Totl_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 961 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_wtd_core_c0/tsc); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 962 | if (DO_BIC(BIC_Any_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 963 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_any_core_c0/tsc); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 964 | if (DO_BIC(BIC_GFX_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 965 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_any_gfxe_c0/tsc); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 966 | if (DO_BIC(BIC_CPUGFX)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 967 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_both_core_gfxe_c0/tsc); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 968 | |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 969 | if (DO_BIC(BIC_Pkgpc2)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 970 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc2/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 971 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 972 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc3/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 973 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 974 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc6/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 975 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 976 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc7/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 977 | if (DO_BIC(BIC_Pkgpc8)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 978 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc8/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 979 | if (DO_BIC(BIC_Pkgpc9)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 980 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc9/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 981 | if (DO_BIC(BIC_Pkgpc10)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 982 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc10/tsc); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 983 | |
| 984 | /* |
| 985 | * If measurement interval exceeds minimum RAPL Joule Counter range, |
| 986 | * indicate that results are suspect by printing "**" in fraction place. |
| 987 | */ |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 988 | if (interval_float < rapl_joule_counter_range) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 989 | fmt8 = "%s%.2f"; |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 990 | else |
Len Brown | e975db5 | 2016-04-06 23:56:02 -0400 | [diff] [blame] | 991 | fmt8 = "%6.0f**"; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 992 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 993 | if (DO_BIC(BIC_PkgWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 994 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_pkg * rapl_energy_units / interval_float); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 995 | if (DO_BIC(BIC_CorWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 996 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_cores * rapl_energy_units / interval_float); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 997 | if (DO_BIC(BIC_GFXWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 998 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_gfx * rapl_energy_units / interval_float); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 999 | if (DO_BIC(BIC_RAMWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1000 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_dram * rapl_dram_energy_units / interval_float); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1001 | if (DO_BIC(BIC_Pkg_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1002 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_pkg * rapl_energy_units); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1003 | if (DO_BIC(BIC_Cor_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1004 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_cores * rapl_energy_units); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1005 | if (DO_BIC(BIC_GFX_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1006 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_gfx * rapl_energy_units); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1007 | if (DO_BIC(BIC_RAM_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1008 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_dram * rapl_dram_energy_units); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1009 | if (DO_BIC(BIC_PKG__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1010 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), 100.0 * p->rapl_pkg_perf_status * rapl_time_units / interval_float); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1011 | if (DO_BIC(BIC_RAM__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1012 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), 100.0 * p->rapl_dram_perf_status * rapl_time_units / interval_float); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1013 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1014 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1015 | if (mp->format == FORMAT_RAW) { |
| 1016 | if (mp->width == 32) |
Len Brown | 5f3aea5 | 2017-02-23 18:10:27 -0500 | [diff] [blame] | 1017 | outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int) p->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1018 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1019 | outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), p->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1020 | } else if (mp->format == FORMAT_DELTA) { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1021 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1022 | outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), p->counter[i]); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1023 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1024 | outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), p->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1025 | } else if (mp->format == FORMAT_PERCENT) { |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1026 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->counter[i]/tsc); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1027 | } |
| 1028 | } |
| 1029 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1030 | done: |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1031 | outp += sprintf(outp, "\n"); |
| 1032 | |
| 1033 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1034 | } |
| 1035 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1036 | void flush_output_stdout(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1037 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1038 | FILE *filep; |
| 1039 | |
| 1040 | if (outf == stderr) |
| 1041 | filep = stdout; |
| 1042 | else |
| 1043 | filep = outf; |
| 1044 | |
| 1045 | fputs(output_buffer, filep); |
| 1046 | fflush(filep); |
| 1047 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1048 | outp = output_buffer; |
| 1049 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1050 | void flush_output_stderr(void) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1051 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1052 | fputs(output_buffer, outf); |
| 1053 | fflush(outf); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1054 | outp = output_buffer; |
| 1055 | } |
| 1056 | void format_all_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 1057 | { |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 1058 | static int printed; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1059 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 1060 | if (!printed || !summary_only) |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 1061 | print_header("\t"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1062 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1063 | if (topo.num_cpus > 1) |
| 1064 | format_counters(&average.threads, &average.cores, |
| 1065 | &average.packages); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1066 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 1067 | printed = 1; |
| 1068 | |
| 1069 | if (summary_only) |
| 1070 | return; |
| 1071 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1072 | for_all_cpus(format_counters, t, c, p); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1073 | } |
| 1074 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1075 | #define DELTA_WRAP32(new, old) \ |
| 1076 | if (new > old) { \ |
| 1077 | old = new - old; \ |
| 1078 | } else { \ |
| 1079 | old = 0x100000000 + new - old; \ |
| 1080 | } |
| 1081 | |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1082 | int |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1083 | delta_package(struct pkg_data *new, struct pkg_data *old) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1084 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1085 | int i; |
| 1086 | struct msr_counter *mp; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1087 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1088 | |
| 1089 | if (DO_BIC(BIC_Totl_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1090 | old->pkg_wtd_core_c0 = new->pkg_wtd_core_c0 - old->pkg_wtd_core_c0; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1091 | if (DO_BIC(BIC_Any_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1092 | old->pkg_any_core_c0 = new->pkg_any_core_c0 - old->pkg_any_core_c0; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1093 | if (DO_BIC(BIC_GFX_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1094 | old->pkg_any_gfxe_c0 = new->pkg_any_gfxe_c0 - old->pkg_any_gfxe_c0; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1095 | if (DO_BIC(BIC_CPUGFX)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1096 | old->pkg_both_core_gfxe_c0 = new->pkg_both_core_gfxe_c0 - old->pkg_both_core_gfxe_c0; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1097 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1098 | old->pc2 = new->pc2 - old->pc2; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1099 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1100 | old->pc3 = new->pc3 - old->pc3; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1101 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1102 | old->pc6 = new->pc6 - old->pc6; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1103 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1104 | old->pc7 = new->pc7 - old->pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1105 | old->pc8 = new->pc8 - old->pc8; |
| 1106 | old->pc9 = new->pc9 - old->pc9; |
| 1107 | old->pc10 = new->pc10 - old->pc10; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1108 | old->pkg_temp_c = new->pkg_temp_c; |
| 1109 | |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 1110 | /* flag an error when rc6 counter resets/wraps */ |
| 1111 | if (old->gfx_rc6_ms > new->gfx_rc6_ms) |
| 1112 | old->gfx_rc6_ms = -1; |
| 1113 | else |
| 1114 | old->gfx_rc6_ms = new->gfx_rc6_ms - old->gfx_rc6_ms; |
| 1115 | |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1116 | old->gfx_mhz = new->gfx_mhz; |
| 1117 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1118 | DELTA_WRAP32(new->energy_pkg, old->energy_pkg); |
| 1119 | DELTA_WRAP32(new->energy_cores, old->energy_cores); |
| 1120 | DELTA_WRAP32(new->energy_gfx, old->energy_gfx); |
| 1121 | DELTA_WRAP32(new->energy_dram, old->energy_dram); |
| 1122 | DELTA_WRAP32(new->rapl_pkg_perf_status, old->rapl_pkg_perf_status); |
| 1123 | DELTA_WRAP32(new->rapl_dram_perf_status, old->rapl_dram_perf_status); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1124 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1125 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1126 | if (mp->format == FORMAT_RAW) |
| 1127 | old->counter[i] = new->counter[i]; |
| 1128 | else |
| 1129 | old->counter[i] = new->counter[i] - old->counter[i]; |
| 1130 | } |
| 1131 | |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1132 | return 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1133 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1134 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1135 | void |
| 1136 | delta_core(struct core_data *new, struct core_data *old) |
| 1137 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1138 | int i; |
| 1139 | struct msr_counter *mp; |
| 1140 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1141 | old->c3 = new->c3 - old->c3; |
| 1142 | old->c6 = new->c6 - old->c6; |
| 1143 | old->c7 = new->c7 - old->c7; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1144 | old->core_temp_c = new->core_temp_c; |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1145 | old->mc6_us = new->mc6_us - old->mc6_us; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1146 | |
| 1147 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 1148 | if (mp->format == FORMAT_RAW) |
| 1149 | old->counter[i] = new->counter[i]; |
| 1150 | else |
| 1151 | old->counter[i] = new->counter[i] - old->counter[i]; |
| 1152 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1153 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1154 | |
Len Brown | c3ae331 | 2012-06-13 21:31:46 -0400 | [diff] [blame] | 1155 | /* |
| 1156 | * old = new - old |
| 1157 | */ |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1158 | int |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1159 | delta_thread(struct thread_data *new, struct thread_data *old, |
| 1160 | struct core_data *core_delta) |
| 1161 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1162 | int i; |
| 1163 | struct msr_counter *mp; |
| 1164 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 1165 | /* |
| 1166 | * the timestamps from start of measurement interval are in "old" |
| 1167 | * the timestamp from end of measurement interval are in "new" |
| 1168 | * over-write old w/ new so we can print end of interval values |
| 1169 | */ |
| 1170 | |
| 1171 | old->tv_begin = new->tv_begin; |
| 1172 | old->tv_end = new->tv_end; |
| 1173 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1174 | old->tsc = new->tsc - old->tsc; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1175 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1176 | /* check for TSC < 1 Mcycles over interval */ |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 1177 | if (old->tsc < (1000 * 1000)) |
| 1178 | errx(-3, "Insanely slow TSC rate, TSC stops in idle?\n" |
| 1179 | "You can disable all c-states by booting with \"idle=poll\"\n" |
| 1180 | "or just the deep ones with \"processor.max_cstate=1\""); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1181 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1182 | old->c1 = new->c1 - old->c1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1183 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1184 | 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] | 1185 | if ((new->aperf > old->aperf) && (new->mperf > old->mperf)) { |
| 1186 | old->aperf = new->aperf - old->aperf; |
| 1187 | old->mperf = new->mperf - old->mperf; |
| 1188 | } else { |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1189 | return -1; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1190 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1191 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1192 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1193 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1194 | if (use_c1_residency_msr) { |
| 1195 | /* |
| 1196 | * Some models have a dedicated C1 residency MSR, |
| 1197 | * which should be more accurate than the derivation below. |
| 1198 | */ |
| 1199 | } else { |
| 1200 | /* |
| 1201 | * As counter collection is not atomic, |
| 1202 | * it is possible for mperf's non-halted cycles + idle states |
| 1203 | * to exceed TSC's all cycles: show c1 = 0% in that case. |
| 1204 | */ |
Len Brown | 9514936 | 2017-04-12 19:44:51 -0400 | [diff] [blame] | 1205 | if ((old->mperf + core_delta->c3 + core_delta->c6 + core_delta->c7) > (old->tsc * tsc_tweak)) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1206 | old->c1 = 0; |
| 1207 | else { |
| 1208 | /* normal case, derive c1 */ |
Len Brown | 008d396e | 2017-02-10 00:29:51 -0500 | [diff] [blame] | 1209 | old->c1 = (old->tsc * tsc_tweak) - old->mperf - core_delta->c3 |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1210 | - core_delta->c6 - core_delta->c7; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1211 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1212 | } |
Len Brown | c3ae331 | 2012-06-13 21:31:46 -0400 | [diff] [blame] | 1213 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1214 | if (old->mperf == 0) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1215 | if (debug > 1) |
| 1216 | fprintf(outf, "cpu%d MPERF 0!\n", old->cpu_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1217 | old->mperf = 1; /* divide by 0 protection */ |
| 1218 | } |
| 1219 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1220 | if (DO_BIC(BIC_IRQ)) |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1221 | old->irq_count = new->irq_count - old->irq_count; |
| 1222 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1223 | if (DO_BIC(BIC_SMI)) |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 1224 | old->smi_count = new->smi_count - old->smi_count; |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1225 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1226 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 1227 | if (mp->format == FORMAT_RAW) |
| 1228 | old->counter[i] = new->counter[i]; |
| 1229 | else |
| 1230 | old->counter[i] = new->counter[i] - old->counter[i]; |
| 1231 | } |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1232 | return 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | int delta_cpu(struct thread_data *t, struct core_data *c, |
| 1236 | struct pkg_data *p, struct thread_data *t2, |
| 1237 | struct core_data *c2, struct pkg_data *p2) |
| 1238 | { |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1239 | int retval = 0; |
| 1240 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1241 | /* calculate core delta only for 1st thread in core */ |
| 1242 | if (t->flags & CPU_IS_FIRST_THREAD_IN_CORE) |
| 1243 | delta_core(c, c2); |
| 1244 | |
| 1245 | /* always calculate thread delta */ |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1246 | retval = delta_thread(t, t2, c2); /* c2 is core delta */ |
| 1247 | if (retval) |
| 1248 | return retval; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1249 | |
| 1250 | /* calculate package delta only for 1st core in package */ |
| 1251 | if (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE) |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1252 | retval = delta_package(p, p2); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1253 | |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1254 | return retval; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | void clear_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 1258 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1259 | int i; |
| 1260 | struct msr_counter *mp; |
| 1261 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 1262 | t->tv_begin.tv_sec = 0; |
| 1263 | t->tv_begin.tv_usec = 0; |
| 1264 | t->tv_end.tv_sec = 0; |
| 1265 | t->tv_end.tv_usec = 0; |
| 1266 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1267 | t->tsc = 0; |
| 1268 | t->aperf = 0; |
| 1269 | t->mperf = 0; |
| 1270 | t->c1 = 0; |
| 1271 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1272 | t->irq_count = 0; |
| 1273 | t->smi_count = 0; |
| 1274 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1275 | /* tells format_counters to dump all fields from this set */ |
| 1276 | t->flags = CPU_IS_FIRST_THREAD_IN_CORE | CPU_IS_FIRST_CORE_IN_PACKAGE; |
| 1277 | |
| 1278 | c->c3 = 0; |
| 1279 | c->c6 = 0; |
| 1280 | c->c7 = 0; |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1281 | c->mc6_us = 0; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1282 | c->core_temp_c = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1283 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1284 | p->pkg_wtd_core_c0 = 0; |
| 1285 | p->pkg_any_core_c0 = 0; |
| 1286 | p->pkg_any_gfxe_c0 = 0; |
| 1287 | p->pkg_both_core_gfxe_c0 = 0; |
| 1288 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1289 | p->pc2 = 0; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1290 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1291 | p->pc3 = 0; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1292 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1293 | p->pc6 = 0; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1294 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1295 | p->pc7 = 0; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1296 | p->pc8 = 0; |
| 1297 | p->pc9 = 0; |
| 1298 | p->pc10 = 0; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1299 | |
| 1300 | p->energy_pkg = 0; |
| 1301 | p->energy_dram = 0; |
| 1302 | p->energy_cores = 0; |
| 1303 | p->energy_gfx = 0; |
| 1304 | p->rapl_pkg_perf_status = 0; |
| 1305 | p->rapl_dram_perf_status = 0; |
| 1306 | p->pkg_temp_c = 0; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1307 | |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1308 | p->gfx_rc6_ms = 0; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1309 | p->gfx_mhz = 0; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1310 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) |
| 1311 | t->counter[i] = 0; |
| 1312 | |
| 1313 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) |
| 1314 | c->counter[i] = 0; |
| 1315 | |
| 1316 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) |
| 1317 | p->counter[i] = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1318 | } |
| 1319 | int sum_counters(struct thread_data *t, struct core_data *c, |
| 1320 | struct pkg_data *p) |
| 1321 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1322 | int i; |
| 1323 | struct msr_counter *mp; |
| 1324 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 1325 | /* remember first tv_begin */ |
| 1326 | if (average.threads.tv_begin.tv_sec == 0) |
| 1327 | average.threads.tv_begin = t->tv_begin; |
| 1328 | |
| 1329 | /* remember last tv_end */ |
| 1330 | average.threads.tv_end = t->tv_end; |
| 1331 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1332 | average.threads.tsc += t->tsc; |
| 1333 | average.threads.aperf += t->aperf; |
| 1334 | average.threads.mperf += t->mperf; |
| 1335 | average.threads.c1 += t->c1; |
| 1336 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1337 | average.threads.irq_count += t->irq_count; |
| 1338 | average.threads.smi_count += t->smi_count; |
| 1339 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1340 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 1341 | if (mp->format == FORMAT_RAW) |
| 1342 | continue; |
| 1343 | average.threads.counter[i] += t->counter[i]; |
| 1344 | } |
| 1345 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1346 | /* sum per-core values only for 1st thread in core */ |
| 1347 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 1348 | return 0; |
| 1349 | |
| 1350 | average.cores.c3 += c->c3; |
| 1351 | average.cores.c6 += c->c6; |
| 1352 | average.cores.c7 += c->c7; |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1353 | average.cores.mc6_us += c->mc6_us; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1354 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1355 | average.cores.core_temp_c = MAX(average.cores.core_temp_c, c->core_temp_c); |
| 1356 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1357 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 1358 | if (mp->format == FORMAT_RAW) |
| 1359 | continue; |
| 1360 | average.cores.counter[i] += c->counter[i]; |
| 1361 | } |
| 1362 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1363 | /* sum per-pkg values only for 1st core in pkg */ |
| 1364 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 1365 | return 0; |
| 1366 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1367 | if (DO_BIC(BIC_Totl_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1368 | average.packages.pkg_wtd_core_c0 += p->pkg_wtd_core_c0; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1369 | if (DO_BIC(BIC_Any_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1370 | average.packages.pkg_any_core_c0 += p->pkg_any_core_c0; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1371 | if (DO_BIC(BIC_GFX_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1372 | average.packages.pkg_any_gfxe_c0 += p->pkg_any_gfxe_c0; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1373 | if (DO_BIC(BIC_CPUGFX)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1374 | average.packages.pkg_both_core_gfxe_c0 += p->pkg_both_core_gfxe_c0; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1375 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1376 | average.packages.pc2 += p->pc2; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1377 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1378 | average.packages.pc3 += p->pc3; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1379 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1380 | average.packages.pc6 += p->pc6; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1381 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1382 | average.packages.pc7 += p->pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1383 | average.packages.pc8 += p->pc8; |
| 1384 | average.packages.pc9 += p->pc9; |
| 1385 | average.packages.pc10 += p->pc10; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1386 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1387 | average.packages.energy_pkg += p->energy_pkg; |
| 1388 | average.packages.energy_dram += p->energy_dram; |
| 1389 | average.packages.energy_cores += p->energy_cores; |
| 1390 | average.packages.energy_gfx += p->energy_gfx; |
| 1391 | |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1392 | average.packages.gfx_rc6_ms = p->gfx_rc6_ms; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1393 | average.packages.gfx_mhz = p->gfx_mhz; |
| 1394 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1395 | average.packages.pkg_temp_c = MAX(average.packages.pkg_temp_c, p->pkg_temp_c); |
| 1396 | |
| 1397 | average.packages.rapl_pkg_perf_status += p->rapl_pkg_perf_status; |
| 1398 | average.packages.rapl_dram_perf_status += p->rapl_dram_perf_status; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1399 | |
| 1400 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1401 | if (mp->format == FORMAT_RAW) |
| 1402 | continue; |
| 1403 | average.packages.counter[i] += p->counter[i]; |
| 1404 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1405 | return 0; |
| 1406 | } |
| 1407 | /* |
| 1408 | * sum the counters for all cpus in the system |
| 1409 | * compute the weighted average |
| 1410 | */ |
| 1411 | void compute_average(struct thread_data *t, struct core_data *c, |
| 1412 | struct pkg_data *p) |
| 1413 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1414 | int i; |
| 1415 | struct msr_counter *mp; |
| 1416 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1417 | clear_counters(&average.threads, &average.cores, &average.packages); |
| 1418 | |
| 1419 | for_all_cpus(sum_counters, t, c, p); |
| 1420 | |
| 1421 | average.threads.tsc /= topo.num_cpus; |
| 1422 | average.threads.aperf /= topo.num_cpus; |
| 1423 | average.threads.mperf /= topo.num_cpus; |
| 1424 | average.threads.c1 /= topo.num_cpus; |
| 1425 | |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1426 | if (average.threads.irq_count > 9999999) |
| 1427 | sums_need_wide_columns = 1; |
| 1428 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1429 | average.cores.c3 /= topo.num_cores; |
| 1430 | average.cores.c6 /= topo.num_cores; |
| 1431 | average.cores.c7 /= topo.num_cores; |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1432 | average.cores.mc6_us /= topo.num_cores; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1433 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1434 | if (DO_BIC(BIC_Totl_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1435 | average.packages.pkg_wtd_core_c0 /= topo.num_packages; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1436 | if (DO_BIC(BIC_Any_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1437 | average.packages.pkg_any_core_c0 /= topo.num_packages; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1438 | if (DO_BIC(BIC_GFX_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1439 | average.packages.pkg_any_gfxe_c0 /= topo.num_packages; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1440 | if (DO_BIC(BIC_CPUGFX)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1441 | average.packages.pkg_both_core_gfxe_c0 /= topo.num_packages; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1442 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1443 | average.packages.pc2 /= topo.num_packages; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1444 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1445 | average.packages.pc3 /= topo.num_packages; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1446 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1447 | average.packages.pc6 /= topo.num_packages; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1448 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1449 | average.packages.pc7 /= topo.num_packages; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1450 | |
| 1451 | average.packages.pc8 /= topo.num_packages; |
| 1452 | average.packages.pc9 /= topo.num_packages; |
| 1453 | average.packages.pc10 /= topo.num_packages; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1454 | |
| 1455 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 1456 | if (mp->format == FORMAT_RAW) |
| 1457 | continue; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1458 | if (mp->type == COUNTER_ITEMS) { |
| 1459 | if (average.threads.counter[i] > 9999999) |
| 1460 | sums_need_wide_columns = 1; |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 1461 | continue; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1462 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1463 | average.threads.counter[i] /= topo.num_cpus; |
| 1464 | } |
| 1465 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 1466 | if (mp->format == FORMAT_RAW) |
| 1467 | continue; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1468 | if (mp->type == COUNTER_ITEMS) { |
| 1469 | if (average.cores.counter[i] > 9999999) |
| 1470 | sums_need_wide_columns = 1; |
| 1471 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1472 | average.cores.counter[i] /= topo.num_cores; |
| 1473 | } |
| 1474 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1475 | if (mp->format == FORMAT_RAW) |
| 1476 | continue; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1477 | if (mp->type == COUNTER_ITEMS) { |
| 1478 | if (average.packages.counter[i] > 9999999) |
| 1479 | sums_need_wide_columns = 1; |
| 1480 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1481 | average.packages.counter[i] /= topo.num_packages; |
| 1482 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | static unsigned long long rdtsc(void) |
| 1486 | { |
| 1487 | unsigned int low, high; |
| 1488 | |
| 1489 | asm volatile("rdtsc" : "=a" (low), "=d" (high)); |
| 1490 | |
| 1491 | return low | ((unsigned long long)high) << 32; |
| 1492 | } |
| 1493 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1494 | /* |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1495 | * Open a file, and exit on failure |
| 1496 | */ |
| 1497 | FILE *fopen_or_die(const char *path, const char *mode) |
| 1498 | { |
| 1499 | FILE *filep = fopen(path, mode); |
| 1500 | |
| 1501 | if (!filep) |
| 1502 | err(1, "%s: open failed", path); |
| 1503 | return filep; |
| 1504 | } |
| 1505 | /* |
| 1506 | * snapshot_sysfs_counter() |
| 1507 | * |
| 1508 | * return snapshot of given counter |
| 1509 | */ |
| 1510 | unsigned long long snapshot_sysfs_counter(char *path) |
| 1511 | { |
| 1512 | FILE *fp; |
| 1513 | int retval; |
| 1514 | unsigned long long counter; |
| 1515 | |
| 1516 | fp = fopen_or_die(path, "r"); |
| 1517 | |
| 1518 | retval = fscanf(fp, "%lld", &counter); |
| 1519 | if (retval != 1) |
| 1520 | err(1, "snapshot_sysfs_counter(%s)", path); |
| 1521 | |
| 1522 | fclose(fp); |
| 1523 | |
| 1524 | return counter; |
| 1525 | } |
| 1526 | |
| 1527 | int get_mp(int cpu, struct msr_counter *mp, unsigned long long *counterp) |
| 1528 | { |
| 1529 | if (mp->msr_num != 0) { |
| 1530 | if (get_msr(cpu, mp->msr_num, counterp)) |
| 1531 | return -1; |
| 1532 | } else { |
Len Brown | 46c2797 | 2017-12-08 17:38:17 -0500 | [diff] [blame] | 1533 | char path[128 + PATH_BYTES]; |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 1534 | |
| 1535 | if (mp->flags & SYSFS_PERCPU) { |
| 1536 | sprintf(path, "/sys/devices/system/cpu/cpu%d/%s", |
| 1537 | cpu, mp->path); |
| 1538 | |
| 1539 | *counterp = snapshot_sysfs_counter(path); |
| 1540 | } else { |
| 1541 | *counterp = snapshot_sysfs_counter(mp->path); |
| 1542 | } |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | return 0; |
| 1546 | } |
| 1547 | |
| 1548 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1549 | * get_counters(...) |
| 1550 | * migrate to cpu |
| 1551 | * acquire and record local counters for that cpu |
| 1552 | */ |
| 1553 | int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 1554 | { |
| 1555 | int cpu = t->cpu_id; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1556 | unsigned long long msr; |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1557 | int aperf_mperf_retry_count = 0; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1558 | struct msr_counter *mp; |
| 1559 | int i; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1560 | |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 1561 | |
| 1562 | gettimeofday(&t->tv_begin, (struct timezone *)NULL); |
| 1563 | |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 1564 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1565 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1566 | return -1; |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 1567 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1568 | |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1569 | retry: |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1570 | t->tsc = rdtsc(); /* we are running on local CPU of interest */ |
| 1571 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1572 | 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] | 1573 | unsigned long long tsc_before, tsc_between, tsc_after, aperf_time, mperf_time; |
| 1574 | |
| 1575 | /* |
| 1576 | * The TSC, APERF and MPERF must be read together for |
| 1577 | * APERF/MPERF and MPERF/TSC to give accurate results. |
| 1578 | * |
| 1579 | * Unfortunately, APERF and MPERF are read by |
| 1580 | * individual system call, so delays may occur |
| 1581 | * between them. If the time to read them |
| 1582 | * varies by a large amount, we re-read them. |
| 1583 | */ |
| 1584 | |
| 1585 | /* |
| 1586 | * This initial dummy APERF read has been seen to |
| 1587 | * reduce jitter in the subsequent reads. |
| 1588 | */ |
| 1589 | |
Len Brown | 9c63a65 | 2012-10-31 01:29:52 -0400 | [diff] [blame] | 1590 | if (get_msr(cpu, MSR_IA32_APERF, &t->aperf)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1591 | return -3; |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1592 | |
| 1593 | t->tsc = rdtsc(); /* re-read close to APERF */ |
| 1594 | |
| 1595 | tsc_before = t->tsc; |
| 1596 | |
| 1597 | if (get_msr(cpu, MSR_IA32_APERF, &t->aperf)) |
| 1598 | return -3; |
| 1599 | |
| 1600 | tsc_between = rdtsc(); |
| 1601 | |
Len Brown | 9c63a65 | 2012-10-31 01:29:52 -0400 | [diff] [blame] | 1602 | if (get_msr(cpu, MSR_IA32_MPERF, &t->mperf)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1603 | return -4; |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1604 | |
| 1605 | tsc_after = rdtsc(); |
| 1606 | |
| 1607 | aperf_time = tsc_between - tsc_before; |
| 1608 | mperf_time = tsc_after - tsc_between; |
| 1609 | |
| 1610 | /* |
| 1611 | * If the system call latency to read APERF and MPERF |
| 1612 | * differ by more than 2x, then try again. |
| 1613 | */ |
| 1614 | if ((aperf_time > (2 * mperf_time)) || (mperf_time > (2 * aperf_time))) { |
| 1615 | aperf_mperf_retry_count++; |
| 1616 | if (aperf_mperf_retry_count < 5) |
| 1617 | goto retry; |
| 1618 | else |
| 1619 | warnx("cpu%d jitter %lld %lld", |
| 1620 | cpu, aperf_time, mperf_time); |
| 1621 | } |
| 1622 | aperf_mperf_retry_count = 0; |
| 1623 | |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 1624 | t->aperf = t->aperf * aperf_mperf_multiplier; |
| 1625 | t->mperf = t->mperf * aperf_mperf_multiplier; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1626 | } |
| 1627 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1628 | if (DO_BIC(BIC_IRQ)) |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1629 | t->irq_count = irqs_per_cpu[cpu]; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1630 | if (DO_BIC(BIC_SMI)) { |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 1631 | if (get_msr(cpu, MSR_SMI_COUNT, &msr)) |
| 1632 | return -5; |
| 1633 | t->smi_count = msr & 0xFFFFFFFF; |
| 1634 | } |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1635 | if (DO_BIC(BIC_CPU_c1) && use_c1_residency_msr) { |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1636 | if (get_msr(cpu, MSR_CORE_C1_RES, &t->c1)) |
| 1637 | return -6; |
| 1638 | } |
| 1639 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1640 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1641 | if (get_mp(cpu, mp, &t->counter[i])) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1642 | return -10; |
| 1643 | } |
| 1644 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1645 | /* collect core counters only for 1st thread in core */ |
| 1646 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 1647 | goto done; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1648 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1649 | if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1650 | if (get_msr(cpu, MSR_CORE_C3_RESIDENCY, &c->c3)) |
| 1651 | return -6; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1652 | } |
| 1653 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1654 | if (DO_BIC(BIC_CPU_c6) && !do_knl_cstates) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1655 | if (get_msr(cpu, MSR_CORE_C6_RESIDENCY, &c->c6)) |
| 1656 | return -7; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1657 | } else if (do_knl_cstates) { |
| 1658 | if (get_msr(cpu, MSR_KNL_CORE_C6_RESIDENCY, &c->c6)) |
| 1659 | return -7; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1660 | } |
| 1661 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1662 | if (DO_BIC(BIC_CPU_c7)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1663 | if (get_msr(cpu, MSR_CORE_C7_RESIDENCY, &c->c7)) |
| 1664 | return -8; |
| 1665 | |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1666 | if (DO_BIC(BIC_Mod_c6)) |
| 1667 | if (get_msr(cpu, MSR_MODULE_C6_RES_MS, &c->mc6_us)) |
| 1668 | return -8; |
| 1669 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1670 | if (DO_BIC(BIC_CoreTmp)) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1671 | if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr)) |
| 1672 | return -9; |
| 1673 | c->core_temp_c = tcc_activation_temp - ((msr >> 16) & 0x7F); |
| 1674 | } |
| 1675 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1676 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1677 | if (get_mp(cpu, mp, &c->counter[i])) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1678 | return -10; |
| 1679 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1680 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1681 | /* collect package counters only for 1st core in package */ |
| 1682 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 1683 | goto done; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1684 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1685 | if (DO_BIC(BIC_Totl_c0)) { |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1686 | if (get_msr(cpu, MSR_PKG_WEIGHTED_CORE_C0_RES, &p->pkg_wtd_core_c0)) |
| 1687 | return -10; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1688 | } |
| 1689 | if (DO_BIC(BIC_Any_c0)) { |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1690 | if (get_msr(cpu, MSR_PKG_ANY_CORE_C0_RES, &p->pkg_any_core_c0)) |
| 1691 | return -11; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1692 | } |
| 1693 | if (DO_BIC(BIC_GFX_c0)) { |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1694 | if (get_msr(cpu, MSR_PKG_ANY_GFXE_C0_RES, &p->pkg_any_gfxe_c0)) |
| 1695 | return -12; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1696 | } |
| 1697 | if (DO_BIC(BIC_CPUGFX)) { |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1698 | if (get_msr(cpu, MSR_PKG_BOTH_CORE_GFXE_C0_RES, &p->pkg_both_core_gfxe_c0)) |
| 1699 | return -13; |
| 1700 | } |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1701 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1702 | if (get_msr(cpu, MSR_PKG_C3_RESIDENCY, &p->pc3)) |
| 1703 | return -9; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1704 | if (DO_BIC(BIC_Pkgpc6)) { |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1705 | if (do_slm_cstates) { |
| 1706 | if (get_msr(cpu, MSR_ATOM_PKG_C6_RESIDENCY, &p->pc6)) |
| 1707 | return -10; |
| 1708 | } else { |
| 1709 | if (get_msr(cpu, MSR_PKG_C6_RESIDENCY, &p->pc6)) |
| 1710 | return -10; |
| 1711 | } |
| 1712 | } |
| 1713 | |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1714 | if (DO_BIC(BIC_Pkgpc2)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1715 | if (get_msr(cpu, MSR_PKG_C2_RESIDENCY, &p->pc2)) |
| 1716 | return -11; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1717 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1718 | if (get_msr(cpu, MSR_PKG_C7_RESIDENCY, &p->pc7)) |
| 1719 | return -12; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1720 | if (DO_BIC(BIC_Pkgpc8)) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1721 | if (get_msr(cpu, MSR_PKG_C8_RESIDENCY, &p->pc8)) |
| 1722 | return -13; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1723 | if (DO_BIC(BIC_Pkgpc9)) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1724 | if (get_msr(cpu, MSR_PKG_C9_RESIDENCY, &p->pc9)) |
| 1725 | return -13; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1726 | if (DO_BIC(BIC_Pkgpc10)) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1727 | if (get_msr(cpu, MSR_PKG_C10_RESIDENCY, &p->pc10)) |
| 1728 | return -13; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1729 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1730 | if (do_rapl & RAPL_PKG) { |
| 1731 | if (get_msr(cpu, MSR_PKG_ENERGY_STATUS, &msr)) |
| 1732 | return -13; |
| 1733 | p->energy_pkg = msr & 0xFFFFFFFF; |
| 1734 | } |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 1735 | if (do_rapl & RAPL_CORES_ENERGY_STATUS) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1736 | if (get_msr(cpu, MSR_PP0_ENERGY_STATUS, &msr)) |
| 1737 | return -14; |
| 1738 | p->energy_cores = msr & 0xFFFFFFFF; |
| 1739 | } |
| 1740 | if (do_rapl & RAPL_DRAM) { |
| 1741 | if (get_msr(cpu, MSR_DRAM_ENERGY_STATUS, &msr)) |
| 1742 | return -15; |
| 1743 | p->energy_dram = msr & 0xFFFFFFFF; |
| 1744 | } |
| 1745 | if (do_rapl & RAPL_GFX) { |
| 1746 | if (get_msr(cpu, MSR_PP1_ENERGY_STATUS, &msr)) |
| 1747 | return -16; |
| 1748 | p->energy_gfx = msr & 0xFFFFFFFF; |
| 1749 | } |
| 1750 | if (do_rapl & RAPL_PKG_PERF_STATUS) { |
| 1751 | if (get_msr(cpu, MSR_PKG_PERF_STATUS, &msr)) |
| 1752 | return -16; |
| 1753 | p->rapl_pkg_perf_status = msr & 0xFFFFFFFF; |
| 1754 | } |
| 1755 | if (do_rapl & RAPL_DRAM_PERF_STATUS) { |
| 1756 | if (get_msr(cpu, MSR_DRAM_PERF_STATUS, &msr)) |
| 1757 | return -16; |
| 1758 | p->rapl_dram_perf_status = msr & 0xFFFFFFFF; |
| 1759 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1760 | if (DO_BIC(BIC_PkgTmp)) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1761 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr)) |
| 1762 | return -17; |
| 1763 | p->pkg_temp_c = tcc_activation_temp - ((msr >> 16) & 0x7F); |
| 1764 | } |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1765 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1766 | if (DO_BIC(BIC_GFX_rc6)) |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1767 | p->gfx_rc6_ms = gfx_cur_rc6_ms; |
| 1768 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1769 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1770 | p->gfx_mhz = gfx_cur_mhz; |
| 1771 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1772 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1773 | if (get_mp(cpu, mp, &p->counter[i])) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1774 | return -10; |
| 1775 | } |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 1776 | done: |
| 1777 | gettimeofday(&t->tv_end, (struct timezone *)NULL); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1778 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1779 | return 0; |
| 1780 | } |
| 1781 | |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1782 | /* |
| 1783 | * MSR_PKG_CST_CONFIG_CONTROL decoding for pkg_cstate_limit: |
| 1784 | * If you change the values, note they are used both in comparisons |
| 1785 | * (>= PCL__7) and to index pkg_cstate_limit_strings[]. |
| 1786 | */ |
| 1787 | |
| 1788 | #define PCLUKN 0 /* Unknown */ |
| 1789 | #define PCLRSV 1 /* Reserved */ |
| 1790 | #define PCL__0 2 /* PC0 */ |
| 1791 | #define PCL__1 3 /* PC1 */ |
| 1792 | #define PCL__2 4 /* PC2 */ |
| 1793 | #define PCL__3 5 /* PC3 */ |
| 1794 | #define PCL__4 6 /* PC4 */ |
| 1795 | #define PCL__6 7 /* PC6 */ |
| 1796 | #define PCL_6N 8 /* PC6 No Retention */ |
| 1797 | #define PCL_6R 9 /* PC6 Retention */ |
| 1798 | #define PCL__7 10 /* PC7 */ |
| 1799 | #define PCL_7S 11 /* PC7 Shrink */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1800 | #define PCL__8 12 /* PC8 */ |
| 1801 | #define PCL__9 13 /* PC9 */ |
| 1802 | #define PCLUNL 14 /* Unlimited */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1803 | |
| 1804 | int pkg_cstate_limit = PCLUKN; |
| 1805 | char *pkg_cstate_limit_strings[] = { "reserved", "unknown", "pc0", "pc1", "pc2", |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1806 | "pc3", "pc4", "pc6", "pc6n", "pc6r", "pc7", "pc7s", "pc8", "pc9", "unlimited"}; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1807 | |
Len Brown | e9257f5 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 1808 | 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}; |
| 1809 | 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}; |
| 1810 | 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] | 1811 | 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] | 1812 | 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] | 1813 | 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] | 1814 | int bxt_pkg_cstate_limits[16] = {PCL__0, PCL__2, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; |
Artem Bityutskiy | 2085e12 | 2017-08-04 18:42:23 +0300 | [diff] [blame] | 1815 | int skx_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 | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1816 | |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 1817 | |
| 1818 | static void |
| 1819 | calculate_tsc_tweak() |
| 1820 | { |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 1821 | tsc_tweak = base_hz / tsc_hz; |
| 1822 | } |
| 1823 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1824 | static void |
| 1825 | dump_nhm_platform_info(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1826 | { |
| 1827 | unsigned long long msr; |
| 1828 | unsigned int ratio; |
| 1829 | |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 1830 | get_msr(base_cpu, MSR_PLATFORM_INFO, &msr); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1831 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1832 | 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] | 1833 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1834 | ratio = (msr >> 40) & 0xFF; |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1835 | fprintf(outf, "%d * %.1f = %.1f MHz max efficiency frequency\n", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1836 | ratio, bclk, ratio * bclk); |
| 1837 | |
| 1838 | ratio = (msr >> 8) & 0xFF; |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1839 | fprintf(outf, "%d * %.1f = %.1f MHz base frequency\n", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1840 | ratio, bclk, ratio * bclk); |
| 1841 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1842 | get_msr(base_cpu, MSR_IA32_POWER_CTL, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1843 | 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] | 1844 | base_cpu, msr, msr & 0x2 ? "EN" : "DIS"); |
Len Brown | 6792041 | 2013-01-31 15:22:15 -0500 | [diff] [blame] | 1845 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1846 | return; |
| 1847 | } |
| 1848 | |
| 1849 | static void |
| 1850 | dump_hsw_turbo_ratio_limits(void) |
| 1851 | { |
| 1852 | unsigned long long msr; |
| 1853 | unsigned int ratio; |
| 1854 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1855 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT2, &msr); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1856 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1857 | 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] | 1858 | |
| 1859 | ratio = (msr >> 8) & 0xFF; |
| 1860 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1861 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 18 active cores\n", |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1862 | ratio, bclk, ratio * bclk); |
| 1863 | |
| 1864 | ratio = (msr >> 0) & 0xFF; |
| 1865 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1866 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 17 active cores\n", |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1867 | ratio, bclk, ratio * bclk); |
| 1868 | return; |
| 1869 | } |
| 1870 | |
| 1871 | static void |
| 1872 | dump_ivt_turbo_ratio_limits(void) |
| 1873 | { |
| 1874 | unsigned long long msr; |
| 1875 | unsigned int ratio; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1876 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1877 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT1, &msr); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1878 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1879 | 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] | 1880 | |
| 1881 | ratio = (msr >> 56) & 0xFF; |
| 1882 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1883 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 16 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1884 | ratio, bclk, ratio * bclk); |
| 1885 | |
| 1886 | ratio = (msr >> 48) & 0xFF; |
| 1887 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1888 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 15 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1889 | ratio, bclk, ratio * bclk); |
| 1890 | |
| 1891 | ratio = (msr >> 40) & 0xFF; |
| 1892 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1893 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 14 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1894 | ratio, bclk, ratio * bclk); |
| 1895 | |
| 1896 | ratio = (msr >> 32) & 0xFF; |
| 1897 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1898 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 13 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1899 | ratio, bclk, ratio * bclk); |
| 1900 | |
| 1901 | ratio = (msr >> 24) & 0xFF; |
| 1902 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1903 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 12 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1904 | ratio, bclk, ratio * bclk); |
| 1905 | |
| 1906 | ratio = (msr >> 16) & 0xFF; |
| 1907 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1908 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 11 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1909 | ratio, bclk, ratio * bclk); |
| 1910 | |
| 1911 | ratio = (msr >> 8) & 0xFF; |
| 1912 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1913 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 10 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1914 | ratio, bclk, ratio * bclk); |
| 1915 | |
| 1916 | ratio = (msr >> 0) & 0xFF; |
| 1917 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1918 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 9 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1919 | ratio, bclk, ratio * bclk); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1920 | return; |
| 1921 | } |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1922 | int has_turbo_ratio_group_limits(int family, int model) |
| 1923 | { |
| 1924 | |
| 1925 | if (!genuine_intel) |
| 1926 | return 0; |
| 1927 | |
| 1928 | switch (model) { |
| 1929 | case INTEL_FAM6_ATOM_GOLDMONT: |
| 1930 | case INTEL_FAM6_SKYLAKE_X: |
| 1931 | case INTEL_FAM6_ATOM_DENVERTON: |
| 1932 | return 1; |
| 1933 | } |
| 1934 | return 0; |
| 1935 | } |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1936 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1937 | static void |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1938 | dump_turbo_ratio_limits(int family, int model) |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1939 | { |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1940 | unsigned long long msr, core_counts; |
| 1941 | unsigned int ratio, group_size; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1942 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1943 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1944 | 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] | 1945 | |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1946 | if (has_turbo_ratio_group_limits(family, model)) { |
| 1947 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT1, &core_counts); |
| 1948 | fprintf(outf, "cpu%d: MSR_TURBO_RATIO_LIMIT1: 0x%08llx\n", base_cpu, core_counts); |
| 1949 | } else { |
| 1950 | core_counts = 0x0807060504030201; |
| 1951 | } |
| 1952 | |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1953 | ratio = (msr >> 56) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1954 | group_size = (core_counts >> 56) & 0xFF; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1955 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1956 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 1957 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1958 | |
| 1959 | ratio = (msr >> 48) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1960 | group_size = (core_counts >> 48) & 0xFF; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1961 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1962 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 1963 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1964 | |
| 1965 | ratio = (msr >> 40) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1966 | group_size = (core_counts >> 40) & 0xFF; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1967 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1968 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 1969 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1970 | |
| 1971 | ratio = (msr >> 32) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1972 | group_size = (core_counts >> 32) & 0xFF; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1973 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1974 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 1975 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1976 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1977 | ratio = (msr >> 24) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1978 | group_size = (core_counts >> 24) & 0xFF; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1979 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1980 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 1981 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1982 | |
| 1983 | ratio = (msr >> 16) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1984 | group_size = (core_counts >> 16) & 0xFF; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1985 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1986 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 1987 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1988 | |
| 1989 | ratio = (msr >> 8) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1990 | group_size = (core_counts >> 8) & 0xFF; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1991 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1992 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 1993 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1994 | |
| 1995 | ratio = (msr >> 0) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1996 | group_size = (core_counts >> 0) & 0xFF; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1997 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1998 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 1999 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2000 | return; |
| 2001 | } |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 2002 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2003 | static void |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 2004 | dump_atom_turbo_ratio_limits(void) |
| 2005 | { |
| 2006 | unsigned long long msr; |
| 2007 | unsigned int ratio; |
| 2008 | |
| 2009 | get_msr(base_cpu, MSR_ATOM_CORE_RATIOS, &msr); |
| 2010 | fprintf(outf, "cpu%d: MSR_ATOM_CORE_RATIOS: 0x%08llx\n", base_cpu, msr & 0xFFFFFFFF); |
| 2011 | |
| 2012 | ratio = (msr >> 0) & 0x3F; |
| 2013 | if (ratio) |
| 2014 | fprintf(outf, "%d * %.1f = %.1f MHz minimum operating frequency\n", |
| 2015 | ratio, bclk, ratio * bclk); |
| 2016 | |
| 2017 | ratio = (msr >> 8) & 0x3F; |
| 2018 | if (ratio) |
| 2019 | fprintf(outf, "%d * %.1f = %.1f MHz low frequency mode (LFM)\n", |
| 2020 | ratio, bclk, ratio * bclk); |
| 2021 | |
| 2022 | ratio = (msr >> 16) & 0x3F; |
| 2023 | if (ratio) |
| 2024 | fprintf(outf, "%d * %.1f = %.1f MHz base frequency\n", |
| 2025 | ratio, bclk, ratio * bclk); |
| 2026 | |
| 2027 | get_msr(base_cpu, MSR_ATOM_CORE_TURBO_RATIOS, &msr); |
| 2028 | fprintf(outf, "cpu%d: MSR_ATOM_CORE_TURBO_RATIOS: 0x%08llx\n", base_cpu, msr & 0xFFFFFFFF); |
| 2029 | |
| 2030 | ratio = (msr >> 24) & 0x3F; |
| 2031 | if (ratio) |
| 2032 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 4 active cores\n", |
| 2033 | ratio, bclk, ratio * bclk); |
| 2034 | |
| 2035 | ratio = (msr >> 16) & 0x3F; |
| 2036 | if (ratio) |
| 2037 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 3 active cores\n", |
| 2038 | ratio, bclk, ratio * bclk); |
| 2039 | |
| 2040 | ratio = (msr >> 8) & 0x3F; |
| 2041 | if (ratio) |
| 2042 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 2 active cores\n", |
| 2043 | ratio, bclk, ratio * bclk); |
| 2044 | |
| 2045 | ratio = (msr >> 0) & 0x3F; |
| 2046 | if (ratio) |
| 2047 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 1 active core\n", |
| 2048 | ratio, bclk, ratio * bclk); |
| 2049 | } |
| 2050 | |
| 2051 | static void |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2052 | dump_knl_turbo_ratio_limits(void) |
| 2053 | { |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2054 | const unsigned int buckets_no = 7; |
| 2055 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2056 | unsigned long long msr; |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2057 | int delta_cores, delta_ratio; |
| 2058 | int i, b_nr; |
| 2059 | unsigned int cores[buckets_no]; |
| 2060 | unsigned int ratio[buckets_no]; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2061 | |
Srinivas Pandruvada | ebf5926 | 2016-07-06 16:07:56 -0700 | [diff] [blame] | 2062 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT, &msr); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2063 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2064 | fprintf(outf, "cpu%d: MSR_TURBO_RATIO_LIMIT: 0x%08llx\n", |
Len Brown | bfae205 | 2015-06-17 12:27:21 -0400 | [diff] [blame] | 2065 | base_cpu, msr); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2066 | |
| 2067 | /** |
| 2068 | * Turbo encoding in KNL is as follows: |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2069 | * [0] -- Reserved |
| 2070 | * [7:1] -- Base value of number of active cores of bucket 1. |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2071 | * [15:8] -- Base value of freq ratio of bucket 1. |
| 2072 | * [20:16] -- +ve delta of number of active cores of bucket 2. |
| 2073 | * i.e. active cores of bucket 2 = |
| 2074 | * active cores of bucket 1 + delta |
| 2075 | * [23:21] -- Negative delta of freq ratio of bucket 2. |
| 2076 | * i.e. freq ratio of bucket 2 = |
| 2077 | * freq ratio of bucket 1 - delta |
| 2078 | * [28:24]-- +ve delta of number of active cores of bucket 3. |
| 2079 | * [31:29]-- -ve delta of freq ratio of bucket 3. |
| 2080 | * [36:32]-- +ve delta of number of active cores of bucket 4. |
| 2081 | * [39:37]-- -ve delta of freq ratio of bucket 4. |
| 2082 | * [44:40]-- +ve delta of number of active cores of bucket 5. |
| 2083 | * [47:45]-- -ve delta of freq ratio of bucket 5. |
| 2084 | * [52:48]-- +ve delta of number of active cores of bucket 6. |
| 2085 | * [55:53]-- -ve delta of freq ratio of bucket 6. |
| 2086 | * [60:56]-- +ve delta of number of active cores of bucket 7. |
| 2087 | * [63:61]-- -ve delta of freq ratio of bucket 7. |
| 2088 | */ |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2089 | |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2090 | b_nr = 0; |
| 2091 | cores[b_nr] = (msr & 0xFF) >> 1; |
| 2092 | ratio[b_nr] = (msr >> 8) & 0xFF; |
| 2093 | |
| 2094 | for (i = 16; i < 64; i += 8) { |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2095 | delta_cores = (msr >> i) & 0x1F; |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2096 | delta_ratio = (msr >> (i + 5)) & 0x7; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2097 | |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2098 | cores[b_nr + 1] = cores[b_nr] + delta_cores; |
| 2099 | ratio[b_nr + 1] = ratio[b_nr] - delta_ratio; |
| 2100 | b_nr++; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2101 | } |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2102 | |
| 2103 | for (i = buckets_no - 1; i >= 0; i--) |
| 2104 | if (i > 0 ? ratio[i] != ratio[i - 1] : 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2105 | fprintf(outf, |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 2106 | "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2107 | ratio[i], bclk, ratio[i] * bclk, cores[i]); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
| 2110 | static void |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2111 | dump_nhm_cst_cfg(void) |
| 2112 | { |
| 2113 | unsigned long long msr; |
| 2114 | |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 2115 | get_msr(base_cpu, MSR_PKG_CST_CONFIG_CONTROL, &msr); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2116 | |
| 2117 | #define SNB_C1_AUTO_UNDEMOTE (1UL << 27) |
| 2118 | #define SNB_C3_AUTO_UNDEMOTE (1UL << 28) |
| 2119 | |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 2120 | 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] | 2121 | |
Artem Bityutskiy | ac980e1 | 2017-09-05 15:14:08 +0300 | [diff] [blame^] | 2122 | fprintf(outf, " (%s%s%s%s%slocked: pkg-cstate-limit=%d: %s", |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2123 | (msr & SNB_C3_AUTO_UNDEMOTE) ? "UNdemote-C3, " : "", |
| 2124 | (msr & SNB_C1_AUTO_UNDEMOTE) ? "UNdemote-C1, " : "", |
| 2125 | (msr & NHM_C3_AUTO_DEMOTE) ? "demote-C3, " : "", |
| 2126 | (msr & NHM_C1_AUTO_DEMOTE) ? "demote-C1, " : "", |
| 2127 | (msr & (1 << 15)) ? "" : "UN", |
Len Brown | 6c34f16 | 2016-03-13 03:21:22 -0400 | [diff] [blame] | 2128 | (unsigned int)msr & 0xF, |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2129 | pkg_cstate_limit_strings[pkg_cstate_limit]); |
Artem Bityutskiy | ac980e1 | 2017-09-05 15:14:08 +0300 | [diff] [blame^] | 2130 | |
| 2131 | #define AUTOMATIC_CSTATE_CONVERSION (1UL << 16) |
| 2132 | if (has_automatic_cstate_conversion) { |
| 2133 | fprintf(outf, ", automatic c-state conversion=%s", |
| 2134 | (msr & AUTOMATIC_CSTATE_CONVERSION) ? "on" : "off"); |
| 2135 | } |
| 2136 | |
| 2137 | fprintf(outf, ")\n"); |
| 2138 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2139 | return; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2140 | } |
| 2141 | |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2142 | static void |
| 2143 | dump_config_tdp(void) |
| 2144 | { |
| 2145 | unsigned long long msr; |
| 2146 | |
| 2147 | get_msr(base_cpu, MSR_CONFIG_TDP_NOMINAL, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2148 | 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] | 2149 | fprintf(outf, " (base_ratio=%d)\n", (unsigned int)msr & 0xFF); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2150 | |
| 2151 | get_msr(base_cpu, MSR_CONFIG_TDP_LEVEL_1, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2152 | 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] | 2153 | if (msr) { |
Chen Yu | 685b535 | 2015-12-13 21:09:31 +0800 | [diff] [blame] | 2154 | fprintf(outf, "PKG_MIN_PWR_LVL1=%d ", (unsigned int)(msr >> 48) & 0x7FFF); |
| 2155 | fprintf(outf, "PKG_MAX_PWR_LVL1=%d ", (unsigned int)(msr >> 32) & 0x7FFF); |
| 2156 | fprintf(outf, "LVL1_RATIO=%d ", (unsigned int)(msr >> 16) & 0xFF); |
| 2157 | fprintf(outf, "PKG_TDP_LVL1=%d", (unsigned int)(msr) & 0x7FFF); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2158 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2159 | fprintf(outf, ")\n"); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2160 | |
| 2161 | get_msr(base_cpu, MSR_CONFIG_TDP_LEVEL_2, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2162 | 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] | 2163 | if (msr) { |
Chen Yu | 685b535 | 2015-12-13 21:09:31 +0800 | [diff] [blame] | 2164 | fprintf(outf, "PKG_MIN_PWR_LVL2=%d ", (unsigned int)(msr >> 48) & 0x7FFF); |
| 2165 | fprintf(outf, "PKG_MAX_PWR_LVL2=%d ", (unsigned int)(msr >> 32) & 0x7FFF); |
| 2166 | fprintf(outf, "LVL2_RATIO=%d ", (unsigned int)(msr >> 16) & 0xFF); |
| 2167 | fprintf(outf, "PKG_TDP_LVL2=%d", (unsigned int)(msr) & 0x7FFF); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2168 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2169 | fprintf(outf, ")\n"); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2170 | |
| 2171 | get_msr(base_cpu, MSR_CONFIG_TDP_CONTROL, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2172 | 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] | 2173 | if ((msr) & 0x3) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2174 | fprintf(outf, "TDP_LEVEL=%d ", (unsigned int)(msr) & 0x3); |
| 2175 | fprintf(outf, " lock=%d", (unsigned int)(msr >> 31) & 1); |
| 2176 | fprintf(outf, ")\n"); |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2177 | |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2178 | get_msr(base_cpu, MSR_TURBO_ACTIVATION_RATIO, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2179 | 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] | 2180 | fprintf(outf, "MAX_NON_TURBO_RATIO=%d", (unsigned int)(msr) & 0xFF); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2181 | fprintf(outf, " lock=%d", (unsigned int)(msr >> 31) & 1); |
| 2182 | fprintf(outf, ")\n"); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2183 | } |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 2184 | |
| 2185 | unsigned int irtl_time_units[] = {1, 32, 1024, 32768, 1048576, 33554432, 0, 0 }; |
| 2186 | |
| 2187 | void print_irtl(void) |
| 2188 | { |
| 2189 | unsigned long long msr; |
| 2190 | |
| 2191 | get_msr(base_cpu, MSR_PKGC3_IRTL, &msr); |
| 2192 | fprintf(outf, "cpu%d: MSR_PKGC3_IRTL: 0x%08llx (", base_cpu, msr); |
| 2193 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2194 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2195 | |
| 2196 | get_msr(base_cpu, MSR_PKGC6_IRTL, &msr); |
| 2197 | fprintf(outf, "cpu%d: MSR_PKGC6_IRTL: 0x%08llx (", base_cpu, msr); |
| 2198 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2199 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2200 | |
| 2201 | get_msr(base_cpu, MSR_PKGC7_IRTL, &msr); |
| 2202 | fprintf(outf, "cpu%d: MSR_PKGC7_IRTL: 0x%08llx (", base_cpu, msr); |
| 2203 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2204 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2205 | |
| 2206 | if (!do_irtl_hsw) |
| 2207 | return; |
| 2208 | |
| 2209 | get_msr(base_cpu, MSR_PKGC8_IRTL, &msr); |
| 2210 | fprintf(outf, "cpu%d: MSR_PKGC8_IRTL: 0x%08llx (", base_cpu, msr); |
| 2211 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2212 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2213 | |
| 2214 | get_msr(base_cpu, MSR_PKGC9_IRTL, &msr); |
| 2215 | fprintf(outf, "cpu%d: MSR_PKGC9_IRTL: 0x%08llx (", base_cpu, msr); |
| 2216 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2217 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2218 | |
| 2219 | get_msr(base_cpu, MSR_PKGC10_IRTL, &msr); |
| 2220 | fprintf(outf, "cpu%d: MSR_PKGC10_IRTL: 0x%08llx (", base_cpu, msr); |
| 2221 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2222 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2223 | |
| 2224 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2225 | void free_fd_percpu(void) |
| 2226 | { |
| 2227 | int i; |
| 2228 | |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 2229 | for (i = 0; i < topo.max_cpu_num + 1; ++i) { |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2230 | if (fd_percpu[i] != 0) |
| 2231 | close(fd_percpu[i]); |
| 2232 | } |
| 2233 | |
| 2234 | free(fd_percpu); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2235 | } |
| 2236 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2237 | void free_all_buffers(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2238 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2239 | CPU_FREE(cpu_present_set); |
| 2240 | cpu_present_set = NULL; |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2241 | cpu_present_setsize = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2242 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2243 | CPU_FREE(cpu_affinity_set); |
| 2244 | cpu_affinity_set = NULL; |
| 2245 | cpu_affinity_setsize = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2246 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2247 | free(thread_even); |
| 2248 | free(core_even); |
| 2249 | free(package_even); |
| 2250 | |
| 2251 | thread_even = NULL; |
| 2252 | core_even = NULL; |
| 2253 | package_even = NULL; |
| 2254 | |
| 2255 | free(thread_odd); |
| 2256 | free(core_odd); |
| 2257 | free(package_odd); |
| 2258 | |
| 2259 | thread_odd = NULL; |
| 2260 | core_odd = NULL; |
| 2261 | package_odd = NULL; |
| 2262 | |
| 2263 | free(output_buffer); |
| 2264 | output_buffer = NULL; |
| 2265 | outp = NULL; |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2266 | |
| 2267 | free_fd_percpu(); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2268 | |
| 2269 | free(irq_column_2_cpu); |
| 2270 | free(irqs_per_cpu); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2271 | } |
| 2272 | |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 2273 | |
| 2274 | /* |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2275 | * Parse a file containing a single int. |
| 2276 | */ |
| 2277 | int parse_int_file(const char *fmt, ...) |
| 2278 | { |
| 2279 | va_list args; |
| 2280 | char path[PATH_MAX]; |
| 2281 | FILE *filep; |
| 2282 | int value; |
| 2283 | |
| 2284 | va_start(args, fmt); |
| 2285 | vsnprintf(path, sizeof(path), fmt, args); |
| 2286 | va_end(args); |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 2287 | filep = fopen_or_die(path, "r"); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 2288 | if (fscanf(filep, "%d", &value) != 1) |
| 2289 | err(1, "%s: failed to parse number from file", path); |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2290 | fclose(filep); |
| 2291 | return value; |
| 2292 | } |
| 2293 | |
| 2294 | /* |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2295 | * get_cpu_position_in_core(cpu) |
| 2296 | * return the position of the CPU among its HT siblings in the core |
| 2297 | * return -1 if the sibling is not in list |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2298 | */ |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2299 | int get_cpu_position_in_core(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2300 | { |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2301 | char path[64]; |
| 2302 | FILE *filep; |
| 2303 | int this_cpu; |
| 2304 | char character; |
| 2305 | int i; |
| 2306 | |
| 2307 | sprintf(path, |
| 2308 | "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", |
| 2309 | cpu); |
| 2310 | filep = fopen(path, "r"); |
| 2311 | if (filep == NULL) { |
| 2312 | perror(path); |
| 2313 | exit(1); |
| 2314 | } |
| 2315 | |
| 2316 | for (i = 0; i < topo.num_threads_per_core; i++) { |
| 2317 | fscanf(filep, "%d", &this_cpu); |
| 2318 | if (this_cpu == cpu) { |
| 2319 | fclose(filep); |
| 2320 | return i; |
| 2321 | } |
| 2322 | |
| 2323 | /* Account for no separator after last thread*/ |
| 2324 | if (i != (topo.num_threads_per_core - 1)) |
| 2325 | fscanf(filep, "%c", &character); |
| 2326 | } |
| 2327 | |
| 2328 | fclose(filep); |
| 2329 | return -1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2330 | } |
| 2331 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2332 | /* |
| 2333 | * cpu_is_first_core_in_package(cpu) |
| 2334 | * return 1 if given CPU is 1st core in package |
| 2335 | */ |
| 2336 | int cpu_is_first_core_in_package(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2337 | { |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2338 | 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] | 2339 | } |
| 2340 | |
| 2341 | int get_physical_package_id(int cpu) |
| 2342 | { |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2343 | 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] | 2344 | } |
| 2345 | |
| 2346 | int get_core_id(int cpu) |
| 2347 | { |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2348 | 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] | 2349 | } |
| 2350 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2351 | int get_num_ht_siblings(int cpu) |
| 2352 | { |
| 2353 | char path[80]; |
| 2354 | FILE *filep; |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2355 | int sib1; |
| 2356 | int matches = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2357 | char character; |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2358 | char str[100]; |
| 2359 | char *ch; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2360 | |
| 2361 | 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] | 2362 | filep = fopen_or_die(path, "r"); |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2363 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2364 | /* |
| 2365 | * file format: |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2366 | * A ',' separated or '-' separated set of numbers |
| 2367 | * (eg 1-2 or 1,3,4,5) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2368 | */ |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2369 | fscanf(filep, "%d%c\n", &sib1, &character); |
| 2370 | fseek(filep, 0, SEEK_SET); |
| 2371 | fgets(str, 100, filep); |
| 2372 | ch = strchr(str, character); |
| 2373 | while (ch != NULL) { |
| 2374 | matches++; |
| 2375 | ch = strchr(ch+1, character); |
| 2376 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2377 | |
| 2378 | fclose(filep); |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2379 | return matches+1; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2380 | } |
| 2381 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2382 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2383 | * run func(thread, core, package) in topology order |
| 2384 | * skip non-present cpus |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2385 | */ |
| 2386 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2387 | int for_all_cpus_2(int (func)(struct thread_data *, struct core_data *, |
| 2388 | struct pkg_data *, struct thread_data *, struct core_data *, |
| 2389 | struct pkg_data *), struct thread_data *thread_base, |
| 2390 | struct core_data *core_base, struct pkg_data *pkg_base, |
| 2391 | struct thread_data *thread_base2, struct core_data *core_base2, |
| 2392 | struct pkg_data *pkg_base2) |
| 2393 | { |
| 2394 | int retval, pkg_no, core_no, thread_no; |
| 2395 | |
| 2396 | for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { |
| 2397 | for (core_no = 0; core_no < topo.num_cores_per_pkg; ++core_no) { |
| 2398 | for (thread_no = 0; thread_no < |
| 2399 | topo.num_threads_per_core; ++thread_no) { |
| 2400 | struct thread_data *t, *t2; |
| 2401 | struct core_data *c, *c2; |
| 2402 | struct pkg_data *p, *p2; |
| 2403 | |
| 2404 | t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); |
| 2405 | |
| 2406 | if (cpu_is_not_present(t->cpu_id)) |
| 2407 | continue; |
| 2408 | |
| 2409 | t2 = GET_THREAD(thread_base2, thread_no, core_no, pkg_no); |
| 2410 | |
| 2411 | c = GET_CORE(core_base, core_no, pkg_no); |
| 2412 | c2 = GET_CORE(core_base2, core_no, pkg_no); |
| 2413 | |
| 2414 | p = GET_PKG(pkg_base, pkg_no); |
| 2415 | p2 = GET_PKG(pkg_base2, pkg_no); |
| 2416 | |
| 2417 | retval = func(t, c, p, t2, c2, p2); |
| 2418 | if (retval) |
| 2419 | return retval; |
| 2420 | } |
| 2421 | } |
| 2422 | } |
| 2423 | return 0; |
| 2424 | } |
| 2425 | |
| 2426 | /* |
| 2427 | * run func(cpu) on every cpu in /proc/stat |
| 2428 | * return max_cpu number |
| 2429 | */ |
| 2430 | int for_all_proc_cpus(int (func)(int)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2431 | { |
| 2432 | FILE *fp; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2433 | int cpu_num; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2434 | int retval; |
| 2435 | |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 2436 | fp = fopen_or_die(proc_stat, "r"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2437 | |
| 2438 | 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] | 2439 | if (retval != 0) |
| 2440 | err(1, "%s: failed to parse format", proc_stat); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2441 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2442 | while (1) { |
| 2443 | 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] | 2444 | if (retval != 1) |
| 2445 | break; |
| 2446 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2447 | retval = func(cpu_num); |
| 2448 | if (retval) { |
| 2449 | fclose(fp); |
| 2450 | return(retval); |
| 2451 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2452 | } |
| 2453 | fclose(fp); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2454 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2455 | } |
| 2456 | |
| 2457 | void re_initialize(void) |
| 2458 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2459 | free_all_buffers(); |
| 2460 | setup_all_buffers(); |
| 2461 | printf("turbostat: re-initialized with num_cpus %d\n", topo.num_cpus); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2462 | } |
| 2463 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2464 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2465 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2466 | * count_cpus() |
| 2467 | * remember the last one seen, it will be the max |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2468 | */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2469 | int count_cpus(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2470 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2471 | if (topo.max_cpu_num < cpu) |
| 2472 | topo.max_cpu_num = cpu; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2473 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2474 | topo.num_cpus += 1; |
| 2475 | return 0; |
| 2476 | } |
| 2477 | int mark_cpu_present(int cpu) |
| 2478 | { |
| 2479 | CPU_SET_S(cpu, cpu_present_setsize, cpu_present_set); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 2480 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2481 | } |
| 2482 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2483 | /* |
| 2484 | * snapshot_proc_interrupts() |
| 2485 | * |
| 2486 | * read and record summary of /proc/interrupts |
| 2487 | * |
| 2488 | * return 1 if config change requires a restart, else return 0 |
| 2489 | */ |
| 2490 | int snapshot_proc_interrupts(void) |
| 2491 | { |
| 2492 | static FILE *fp; |
| 2493 | int column, retval; |
| 2494 | |
| 2495 | if (fp == NULL) |
| 2496 | fp = fopen_or_die("/proc/interrupts", "r"); |
| 2497 | else |
| 2498 | rewind(fp); |
| 2499 | |
| 2500 | /* read 1st line of /proc/interrupts to get cpu* name for each column */ |
| 2501 | for (column = 0; column < topo.num_cpus; ++column) { |
| 2502 | int cpu_number; |
| 2503 | |
| 2504 | retval = fscanf(fp, " CPU%d", &cpu_number); |
| 2505 | if (retval != 1) |
| 2506 | break; |
| 2507 | |
| 2508 | if (cpu_number > topo.max_cpu_num) { |
| 2509 | warn("/proc/interrupts: cpu%d: > %d", cpu_number, topo.max_cpu_num); |
| 2510 | return 1; |
| 2511 | } |
| 2512 | |
| 2513 | irq_column_2_cpu[column] = cpu_number; |
| 2514 | irqs_per_cpu[cpu_number] = 0; |
| 2515 | } |
| 2516 | |
| 2517 | /* read /proc/interrupt count lines and sum up irqs per cpu */ |
| 2518 | while (1) { |
| 2519 | int column; |
| 2520 | char buf[64]; |
| 2521 | |
| 2522 | retval = fscanf(fp, " %s:", buf); /* flush irq# "N:" */ |
| 2523 | if (retval != 1) |
| 2524 | break; |
| 2525 | |
| 2526 | /* read the count per cpu */ |
| 2527 | for (column = 0; column < topo.num_cpus; ++column) { |
| 2528 | |
| 2529 | int cpu_number, irq_count; |
| 2530 | |
| 2531 | retval = fscanf(fp, " %d", &irq_count); |
| 2532 | if (retval != 1) |
| 2533 | break; |
| 2534 | |
| 2535 | cpu_number = irq_column_2_cpu[column]; |
| 2536 | irqs_per_cpu[cpu_number] += irq_count; |
| 2537 | |
| 2538 | } |
| 2539 | |
| 2540 | while (getc(fp) != '\n') |
| 2541 | ; /* flush interrupt description */ |
| 2542 | |
| 2543 | } |
| 2544 | return 0; |
| 2545 | } |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2546 | /* |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 2547 | * snapshot_gfx_rc6_ms() |
| 2548 | * |
| 2549 | * record snapshot of |
| 2550 | * /sys/class/drm/card0/power/rc6_residency_ms |
| 2551 | * |
| 2552 | * return 1 if config change requires a restart, else return 0 |
| 2553 | */ |
| 2554 | int snapshot_gfx_rc6_ms(void) |
| 2555 | { |
| 2556 | FILE *fp; |
| 2557 | int retval; |
| 2558 | |
| 2559 | fp = fopen_or_die("/sys/class/drm/card0/power/rc6_residency_ms", "r"); |
| 2560 | |
| 2561 | retval = fscanf(fp, "%lld", &gfx_cur_rc6_ms); |
| 2562 | if (retval != 1) |
| 2563 | err(1, "GFX rc6"); |
| 2564 | |
| 2565 | fclose(fp); |
| 2566 | |
| 2567 | return 0; |
| 2568 | } |
| 2569 | /* |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2570 | * snapshot_gfx_mhz() |
| 2571 | * |
| 2572 | * record snapshot of |
| 2573 | * /sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz |
| 2574 | * |
| 2575 | * return 1 if config change requires a restart, else return 0 |
| 2576 | */ |
| 2577 | int snapshot_gfx_mhz(void) |
| 2578 | { |
| 2579 | static FILE *fp; |
| 2580 | int retval; |
| 2581 | |
| 2582 | if (fp == NULL) |
| 2583 | fp = fopen_or_die("/sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz", "r"); |
Len Brown | 22048c5 | 2017-03-04 15:42:48 -0500 | [diff] [blame] | 2584 | else { |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2585 | rewind(fp); |
Len Brown | 22048c5 | 2017-03-04 15:42:48 -0500 | [diff] [blame] | 2586 | fflush(fp); |
| 2587 | } |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2588 | |
| 2589 | retval = fscanf(fp, "%d", &gfx_cur_mhz); |
| 2590 | if (retval != 1) |
| 2591 | err(1, "GFX MHz"); |
| 2592 | |
| 2593 | return 0; |
| 2594 | } |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2595 | |
| 2596 | /* |
| 2597 | * snapshot /proc and /sys files |
| 2598 | * |
| 2599 | * return 1 if configuration restart needed, else return 0 |
| 2600 | */ |
| 2601 | int snapshot_proc_sysfs_files(void) |
| 2602 | { |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 2603 | if (DO_BIC(BIC_IRQ)) |
| 2604 | if (snapshot_proc_interrupts()) |
| 2605 | return 1; |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2606 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 2607 | if (DO_BIC(BIC_GFX_rc6)) |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 2608 | snapshot_gfx_rc6_ms(); |
| 2609 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 2610 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2611 | snapshot_gfx_mhz(); |
| 2612 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2613 | return 0; |
| 2614 | } |
| 2615 | |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2616 | int exit_requested; |
| 2617 | |
| 2618 | static void signal_handler (int signal) |
| 2619 | { |
| 2620 | switch (signal) { |
| 2621 | case SIGINT: |
| 2622 | exit_requested = 1; |
| 2623 | if (debug) |
| 2624 | fprintf(stderr, " SIGINT\n"); |
| 2625 | break; |
Len Brown | 0721196 | 2017-07-15 15:51:26 -0400 | [diff] [blame] | 2626 | case SIGUSR1: |
| 2627 | if (debug > 1) |
| 2628 | fprintf(stderr, "SIGUSR1\n"); |
| 2629 | break; |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2630 | } |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2631 | /* make sure this manually-invoked interval is at least 1ms long */ |
| 2632 | nanosleep(&one_msec, NULL); |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2633 | } |
| 2634 | |
| 2635 | void setup_signal_handler(void) |
| 2636 | { |
| 2637 | struct sigaction sa; |
| 2638 | |
| 2639 | memset(&sa, 0, sizeof(sa)); |
| 2640 | |
| 2641 | sa.sa_handler = &signal_handler; |
| 2642 | |
| 2643 | if (sigaction(SIGINT, &sa, NULL) < 0) |
| 2644 | err(1, "sigaction SIGINT"); |
Len Brown | 0721196 | 2017-07-15 15:51:26 -0400 | [diff] [blame] | 2645 | if (sigaction(SIGUSR1, &sa, NULL) < 0) |
| 2646 | err(1, "sigaction SIGUSR1"); |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2647 | } |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2648 | |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 2649 | void do_sleep(void) |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2650 | { |
| 2651 | struct timeval select_timeout; |
| 2652 | fd_set readfds; |
| 2653 | int retval; |
| 2654 | |
| 2655 | FD_ZERO(&readfds); |
| 2656 | FD_SET(0, &readfds); |
| 2657 | |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 2658 | if (!isatty(fileno(stdin))) { |
| 2659 | nanosleep(&interval_ts, NULL); |
| 2660 | return; |
| 2661 | } |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2662 | |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 2663 | select_timeout = interval_tv; |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2664 | retval = select(1, &readfds, NULL, NULL, &select_timeout); |
| 2665 | |
| 2666 | if (retval == 1) { |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2667 | switch (getc(stdin)) { |
| 2668 | case 'q': |
| 2669 | exit_requested = 1; |
| 2670 | break; |
| 2671 | } |
| 2672 | /* make sure this manually-invoked interval is at least 1ms long */ |
| 2673 | nanosleep(&one_msec, NULL); |
| 2674 | } |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2675 | } |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 2676 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2677 | void turbostat_loop() |
| 2678 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2679 | int retval; |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 2680 | int restarted = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2681 | |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2682 | setup_signal_handler(); |
| 2683 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2684 | restart: |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 2685 | restarted++; |
| 2686 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2687 | snapshot_proc_sysfs_files(); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2688 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 2689 | if (retval < -1) { |
| 2690 | exit(retval); |
| 2691 | } else if (retval == -1) { |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 2692 | if (restarted > 1) { |
| 2693 | exit(retval); |
| 2694 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2695 | re_initialize(); |
| 2696 | goto restart; |
| 2697 | } |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 2698 | restarted = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2699 | gettimeofday(&tv_even, (struct timezone *)NULL); |
| 2700 | |
| 2701 | while (1) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2702 | if (for_all_proc_cpus(cpu_is_not_present)) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2703 | re_initialize(); |
| 2704 | goto restart; |
| 2705 | } |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2706 | do_sleep(); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2707 | if (snapshot_proc_sysfs_files()) |
| 2708 | goto restart; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2709 | retval = for_all_cpus(get_counters, ODD_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 2710 | if (retval < -1) { |
| 2711 | exit(retval); |
| 2712 | } else if (retval == -1) { |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 2713 | re_initialize(); |
| 2714 | goto restart; |
| 2715 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2716 | gettimeofday(&tv_odd, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2717 | timersub(&tv_odd, &tv_even, &tv_delta); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 2718 | if (for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS)) { |
| 2719 | re_initialize(); |
| 2720 | goto restart; |
| 2721 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2722 | compute_average(EVEN_COUNTERS); |
| 2723 | format_all_counters(EVEN_COUNTERS); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2724 | flush_output_stdout(); |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2725 | if (exit_requested) |
| 2726 | break; |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2727 | do_sleep(); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2728 | if (snapshot_proc_sysfs_files()) |
| 2729 | goto restart; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2730 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 2731 | if (retval < -1) { |
| 2732 | exit(retval); |
| 2733 | } else if (retval == -1) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2734 | re_initialize(); |
| 2735 | goto restart; |
| 2736 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2737 | gettimeofday(&tv_even, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2738 | timersub(&tv_even, &tv_odd, &tv_delta); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 2739 | if (for_all_cpus_2(delta_cpu, EVEN_COUNTERS, ODD_COUNTERS)) { |
| 2740 | re_initialize(); |
| 2741 | goto restart; |
| 2742 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2743 | compute_average(ODD_COUNTERS); |
| 2744 | format_all_counters(ODD_COUNTERS); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2745 | flush_output_stdout(); |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2746 | if (exit_requested) |
| 2747 | break; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2748 | } |
| 2749 | } |
| 2750 | |
| 2751 | void check_dev_msr() |
| 2752 | { |
| 2753 | struct stat sb; |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2754 | char pathname[32]; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2755 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2756 | sprintf(pathname, "/dev/cpu/%d/msr", base_cpu); |
| 2757 | if (stat(pathname, &sb)) |
Len Brown | a21d38c | 2015-03-24 16:37:35 -0400 | [diff] [blame] | 2758 | if (system("/sbin/modprobe msr > /dev/null 2>&1")) |
| 2759 | err(-5, "no /dev/cpu/0/msr, Try \"# modprobe msr\" "); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2760 | } |
| 2761 | |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2762 | void check_permissions() |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2763 | { |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2764 | struct __user_cap_header_struct cap_header_data; |
| 2765 | cap_user_header_t cap_header = &cap_header_data; |
| 2766 | struct __user_cap_data_struct cap_data_data; |
| 2767 | cap_user_data_t cap_data = &cap_data_data; |
| 2768 | extern int capget(cap_user_header_t hdrp, cap_user_data_t datap); |
| 2769 | int do_exit = 0; |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2770 | char pathname[32]; |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2771 | |
| 2772 | /* check for CAP_SYS_RAWIO */ |
| 2773 | cap_header->pid = getpid(); |
| 2774 | cap_header->version = _LINUX_CAPABILITY_VERSION; |
| 2775 | if (capget(cap_header, cap_data) < 0) |
| 2776 | err(-6, "capget(2) failed"); |
| 2777 | |
| 2778 | if ((cap_data->effective & (1 << CAP_SYS_RAWIO)) == 0) { |
| 2779 | do_exit++; |
| 2780 | warnx("capget(CAP_SYS_RAWIO) failed," |
| 2781 | " try \"# setcap cap_sys_rawio=ep %s\"", progname); |
| 2782 | } |
| 2783 | |
| 2784 | /* test file permissions */ |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2785 | sprintf(pathname, "/dev/cpu/%d/msr", base_cpu); |
| 2786 | if (euidaccess(pathname, R_OK)) { |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2787 | do_exit++; |
| 2788 | warn("/dev/cpu/0/msr open failed, try chown or chmod +r /dev/cpu/*/msr"); |
| 2789 | } |
| 2790 | |
| 2791 | /* if all else fails, thell them to be root */ |
| 2792 | if (do_exit) |
| 2793 | if (getuid() != 0) |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2794 | warnx("... or simply run as root"); |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2795 | |
| 2796 | if (do_exit) |
| 2797 | exit(-6); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2798 | } |
| 2799 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2800 | /* |
| 2801 | * NHM adds support for additional MSRs: |
| 2802 | * |
| 2803 | * MSR_SMI_COUNT 0x00000034 |
| 2804 | * |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 2805 | * MSR_PLATFORM_INFO 0x000000ce |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 2806 | * MSR_PKG_CST_CONFIG_CONTROL 0x000000e2 |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2807 | * |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 2808 | * MSR_MISC_PWR_MGMT 0x000001aa |
| 2809 | * |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2810 | * MSR_PKG_C3_RESIDENCY 0x000003f8 |
| 2811 | * MSR_PKG_C6_RESIDENCY 0x000003f9 |
| 2812 | * MSR_CORE_C3_RESIDENCY 0x000003fc |
| 2813 | * MSR_CORE_C6_RESIDENCY 0x000003fd |
| 2814 | * |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2815 | * Side effect: |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 2816 | * sets global pkg_cstate_limit to decode MSR_PKG_CST_CONFIG_CONTROL |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 2817 | * sets has_misc_feature_control |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2818 | */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2819 | int probe_nhm_msrs(unsigned int family, unsigned int model) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2820 | { |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2821 | unsigned long long msr; |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 2822 | unsigned int base_ratio; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2823 | int *pkg_cstate_limits; |
| 2824 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2825 | if (!genuine_intel) |
| 2826 | return 0; |
| 2827 | |
| 2828 | if (family != 6) |
| 2829 | return 0; |
| 2830 | |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 2831 | bclk = discover_bclk(family, model); |
| 2832 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2833 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2834 | case INTEL_FAM6_NEHALEM_EP: /* Core i7, Xeon 5500 series - Bloomfield, Gainstown NHM-EP */ |
| 2835 | 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] | 2836 | case 0x1F: /* Core i7 and i5 Processor - Nehalem */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2837 | case INTEL_FAM6_WESTMERE: /* Westmere Client - Clarkdale, Arrandale */ |
| 2838 | case INTEL_FAM6_WESTMERE_EP: /* Westmere EP - Gulftown */ |
| 2839 | case INTEL_FAM6_NEHALEM_EX: /* Nehalem-EX Xeon - Beckton */ |
| 2840 | case INTEL_FAM6_WESTMERE_EX: /* Westmere-EX Xeon - Eagleton */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2841 | pkg_cstate_limits = nhm_pkg_cstate_limits; |
| 2842 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2843 | case INTEL_FAM6_SANDYBRIDGE: /* SNB */ |
| 2844 | case INTEL_FAM6_SANDYBRIDGE_X: /* SNB Xeon */ |
| 2845 | case INTEL_FAM6_IVYBRIDGE: /* IVB */ |
| 2846 | case INTEL_FAM6_IVYBRIDGE_X: /* IVB Xeon */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2847 | pkg_cstate_limits = snb_pkg_cstate_limits; |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 2848 | has_misc_feature_control = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2849 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2850 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 2851 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 2852 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 2853 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 2854 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 2855 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
| 2856 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 2857 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 2858 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 2859 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 2860 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 2861 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2862 | pkg_cstate_limits = hsw_pkg_cstate_limits; |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 2863 | has_misc_feature_control = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2864 | break; |
Len Brown | d8ebb44 | 2016-12-01 20:27:46 -0500 | [diff] [blame] | 2865 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
| 2866 | pkg_cstate_limits = skx_pkg_cstate_limits; |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 2867 | has_misc_feature_control = 1; |
Len Brown | d8ebb44 | 2016-12-01 20:27:46 -0500 | [diff] [blame] | 2868 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2869 | case INTEL_FAM6_ATOM_SILVERMONT1: /* BYT */ |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 2870 | no_MSR_MISC_PWR_MGMT = 1; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2871 | case INTEL_FAM6_ATOM_SILVERMONT2: /* AVN */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2872 | pkg_cstate_limits = slv_pkg_cstate_limits; |
| 2873 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2874 | case INTEL_FAM6_ATOM_AIRMONT: /* AMT */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2875 | pkg_cstate_limits = amt_pkg_cstate_limits; |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 2876 | no_MSR_MISC_PWR_MGMT = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2877 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2878 | case INTEL_FAM6_XEON_PHI_KNL: /* PHI */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 2879 | case INTEL_FAM6_XEON_PHI_KNM: |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2880 | pkg_cstate_limits = phi_pkg_cstate_limits; |
| 2881 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2882 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | ac01ac1 | 2017-01-27 01:45:35 -0500 | [diff] [blame] | 2883 | case INTEL_FAM6_ATOM_GEMINI_LAKE: |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2884 | case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ |
Len Brown | e4085d5 | 2016-04-06 17:15:56 -0400 | [diff] [blame] | 2885 | pkg_cstate_limits = bxt_pkg_cstate_limits; |
| 2886 | break; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2887 | default: |
| 2888 | return 0; |
| 2889 | } |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 2890 | get_msr(base_cpu, MSR_PKG_CST_CONFIG_CONTROL, &msr); |
Len Brown | e9257f5 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 2891 | pkg_cstate_limit = pkg_cstate_limits[msr & 0xF]; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2892 | |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 2893 | get_msr(base_cpu, MSR_PLATFORM_INFO, &msr); |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 2894 | base_ratio = (msr >> 8) & 0xFF; |
| 2895 | |
| 2896 | base_hz = base_ratio * bclk * 1000000; |
| 2897 | has_base_hz = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2898 | return 1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2899 | } |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 2900 | /* |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 2901 | * SLV client has support for unique MSRs: |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 2902 | * |
| 2903 | * MSR_CC6_DEMOTION_POLICY_CONFIG |
| 2904 | * MSR_MC6_DEMOTION_POLICY_CONFIG |
| 2905 | */ |
| 2906 | |
| 2907 | int has_slv_msrs(unsigned int family, unsigned int model) |
| 2908 | { |
| 2909 | if (!genuine_intel) |
| 2910 | return 0; |
| 2911 | |
| 2912 | switch (model) { |
| 2913 | case INTEL_FAM6_ATOM_SILVERMONT1: |
| 2914 | case INTEL_FAM6_ATOM_MERRIFIELD: |
| 2915 | case INTEL_FAM6_ATOM_MOOREFIELD: |
| 2916 | return 1; |
| 2917 | } |
| 2918 | return 0; |
| 2919 | } |
Len Brown | 7170a37 | 2017-01-27 02:13:27 -0500 | [diff] [blame] | 2920 | int is_dnv(unsigned int family, unsigned int model) |
| 2921 | { |
| 2922 | |
| 2923 | if (!genuine_intel) |
| 2924 | return 0; |
| 2925 | |
| 2926 | switch (model) { |
| 2927 | case INTEL_FAM6_ATOM_DENVERTON: |
| 2928 | return 1; |
| 2929 | } |
| 2930 | return 0; |
| 2931 | } |
Len Brown | ade0eba | 2017-02-10 01:56:47 -0500 | [diff] [blame] | 2932 | int is_bdx(unsigned int family, unsigned int model) |
| 2933 | { |
| 2934 | |
| 2935 | if (!genuine_intel) |
| 2936 | return 0; |
| 2937 | |
| 2938 | switch (model) { |
| 2939 | case INTEL_FAM6_BROADWELL_X: |
| 2940 | case INTEL_FAM6_BROADWELL_XEON_D: |
| 2941 | return 1; |
| 2942 | } |
| 2943 | return 0; |
| 2944 | } |
Len Brown | 34c76197 | 2017-01-27 02:36:41 -0500 | [diff] [blame] | 2945 | int is_skx(unsigned int family, unsigned int model) |
| 2946 | { |
| 2947 | |
| 2948 | if (!genuine_intel) |
| 2949 | return 0; |
| 2950 | |
| 2951 | switch (model) { |
| 2952 | case INTEL_FAM6_SKYLAKE_X: |
| 2953 | return 1; |
| 2954 | } |
| 2955 | return 0; |
| 2956 | } |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 2957 | |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2958 | int has_turbo_ratio_limit(unsigned int family, unsigned int model) |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2959 | { |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 2960 | if (has_slv_msrs(family, model)) |
| 2961 | return 0; |
| 2962 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2963 | switch (model) { |
| 2964 | /* Nehalem compatible, but do not include turbo-ratio limit support */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2965 | case INTEL_FAM6_NEHALEM_EX: /* Nehalem-EX Xeon - Beckton */ |
| 2966 | case INTEL_FAM6_WESTMERE_EX: /* Westmere-EX Xeon - Eagleton */ |
| 2967 | case INTEL_FAM6_XEON_PHI_KNL: /* PHI - Knights Landing (different MSR definition) */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 2968 | case INTEL_FAM6_XEON_PHI_KNM: |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2969 | return 0; |
| 2970 | default: |
| 2971 | return 1; |
| 2972 | } |
| 2973 | } |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 2974 | int has_atom_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 2975 | { |
| 2976 | if (has_slv_msrs(family, model)) |
| 2977 | return 1; |
| 2978 | |
| 2979 | return 0; |
| 2980 | } |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2981 | int has_ivt_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 2982 | { |
| 2983 | if (!genuine_intel) |
| 2984 | return 0; |
| 2985 | |
| 2986 | if (family != 6) |
| 2987 | return 0; |
| 2988 | |
| 2989 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2990 | case INTEL_FAM6_IVYBRIDGE_X: /* IVB Xeon */ |
| 2991 | case INTEL_FAM6_HASWELL_X: /* HSW Xeon */ |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2992 | return 1; |
| 2993 | default: |
| 2994 | return 0; |
| 2995 | } |
| 2996 | } |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2997 | int has_hsw_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 2998 | { |
| 2999 | if (!genuine_intel) |
| 3000 | return 0; |
| 3001 | |
| 3002 | if (family != 6) |
| 3003 | return 0; |
| 3004 | |
| 3005 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3006 | case INTEL_FAM6_HASWELL_X: /* HSW Xeon */ |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3007 | return 1; |
| 3008 | default: |
| 3009 | return 0; |
| 3010 | } |
| 3011 | } |
| 3012 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 3013 | int has_knl_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 3014 | { |
| 3015 | if (!genuine_intel) |
| 3016 | return 0; |
| 3017 | |
| 3018 | if (family != 6) |
| 3019 | return 0; |
| 3020 | |
| 3021 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3022 | case INTEL_FAM6_XEON_PHI_KNL: /* Knights Landing */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 3023 | case INTEL_FAM6_XEON_PHI_KNM: |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 3024 | return 1; |
| 3025 | default: |
| 3026 | return 0; |
| 3027 | } |
| 3028 | } |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 3029 | int has_glm_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 3030 | { |
| 3031 | if (!genuine_intel) |
| 3032 | return 0; |
| 3033 | |
| 3034 | if (family != 6) |
| 3035 | return 0; |
| 3036 | |
| 3037 | switch (model) { |
| 3038 | case INTEL_FAM6_ATOM_GOLDMONT: |
| 3039 | case INTEL_FAM6_SKYLAKE_X: |
| 3040 | return 1; |
| 3041 | default: |
| 3042 | return 0; |
| 3043 | } |
| 3044 | } |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 3045 | int has_config_tdp(unsigned int family, unsigned int model) |
| 3046 | { |
| 3047 | if (!genuine_intel) |
| 3048 | return 0; |
| 3049 | |
| 3050 | if (family != 6) |
| 3051 | return 0; |
| 3052 | |
| 3053 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3054 | case INTEL_FAM6_IVYBRIDGE: /* IVB */ |
| 3055 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 3056 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 3057 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 3058 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 3059 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 3060 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
| 3061 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 3062 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 3063 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 3064 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 3065 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 3066 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
| 3067 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 3068 | |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3069 | case INTEL_FAM6_XEON_PHI_KNL: /* Knights Landing */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 3070 | case INTEL_FAM6_XEON_PHI_KNM: |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 3071 | return 1; |
| 3072 | default: |
| 3073 | return 0; |
| 3074 | } |
| 3075 | } |
| 3076 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3077 | static void |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 3078 | dump_cstate_pstate_config_info(unsigned int family, unsigned int model) |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3079 | { |
| 3080 | if (!do_nhm_platform_info) |
| 3081 | return; |
| 3082 | |
| 3083 | dump_nhm_platform_info(); |
| 3084 | |
| 3085 | if (has_hsw_turbo_ratio_limit(family, model)) |
| 3086 | dump_hsw_turbo_ratio_limits(); |
| 3087 | |
| 3088 | if (has_ivt_turbo_ratio_limit(family, model)) |
| 3089 | dump_ivt_turbo_ratio_limits(); |
| 3090 | |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 3091 | if (has_turbo_ratio_limit(family, model)) |
| 3092 | dump_turbo_ratio_limits(family, model); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3093 | |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 3094 | if (has_atom_turbo_ratio_limit(family, model)) |
| 3095 | dump_atom_turbo_ratio_limits(); |
| 3096 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 3097 | if (has_knl_turbo_ratio_limit(family, model)) |
| 3098 | dump_knl_turbo_ratio_limits(); |
| 3099 | |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 3100 | if (has_config_tdp(family, model)) |
| 3101 | dump_config_tdp(); |
| 3102 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3103 | dump_nhm_cst_cfg(); |
| 3104 | } |
| 3105 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 3106 | static void |
| 3107 | dump_sysfs_cstate_config(void) |
| 3108 | { |
| 3109 | char path[64]; |
| 3110 | char name_buf[16]; |
| 3111 | char desc[64]; |
| 3112 | FILE *input; |
| 3113 | int state; |
| 3114 | char *sp; |
| 3115 | |
| 3116 | if (!DO_BIC(BIC_sysfs)) |
| 3117 | return; |
| 3118 | |
| 3119 | for (state = 0; state < 10; ++state) { |
| 3120 | |
| 3121 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", |
| 3122 | base_cpu, state); |
| 3123 | input = fopen(path, "r"); |
| 3124 | if (input == NULL) |
| 3125 | continue; |
| 3126 | fgets(name_buf, sizeof(name_buf), input); |
| 3127 | |
| 3128 | /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ |
| 3129 | sp = strchr(name_buf, '-'); |
| 3130 | if (!sp) |
| 3131 | sp = strchrnul(name_buf, '\n'); |
| 3132 | *sp = '\0'; |
| 3133 | |
| 3134 | fclose(input); |
| 3135 | |
| 3136 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/desc", |
| 3137 | base_cpu, state); |
| 3138 | input = fopen(path, "r"); |
| 3139 | if (input == NULL) |
| 3140 | continue; |
| 3141 | fgets(desc, sizeof(desc), input); |
| 3142 | |
| 3143 | fprintf(outf, "cpu%d: %s: %s", base_cpu, name_buf, desc); |
| 3144 | fclose(input); |
| 3145 | } |
| 3146 | } |
Len Brown | 7293fcc | 2017-02-22 00:11:12 -0500 | [diff] [blame] | 3147 | static void |
| 3148 | dump_sysfs_pstate_config(void) |
| 3149 | { |
| 3150 | char path[64]; |
| 3151 | char driver_buf[64]; |
| 3152 | char governor_buf[64]; |
| 3153 | FILE *input; |
| 3154 | int turbo; |
| 3155 | |
| 3156 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_driver", |
| 3157 | base_cpu); |
| 3158 | input = fopen(path, "r"); |
| 3159 | if (input == NULL) { |
| 3160 | fprintf(stderr, "NSFOD %s\n", path); |
| 3161 | return; |
| 3162 | } |
| 3163 | fgets(driver_buf, sizeof(driver_buf), input); |
| 3164 | fclose(input); |
| 3165 | |
| 3166 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", |
| 3167 | base_cpu); |
| 3168 | input = fopen(path, "r"); |
| 3169 | if (input == NULL) { |
| 3170 | fprintf(stderr, "NSFOD %s\n", path); |
| 3171 | return; |
| 3172 | } |
| 3173 | fgets(governor_buf, sizeof(governor_buf), input); |
| 3174 | fclose(input); |
| 3175 | |
| 3176 | fprintf(outf, "cpu%d: cpufreq driver: %s", base_cpu, driver_buf); |
| 3177 | fprintf(outf, "cpu%d: cpufreq governor: %s", base_cpu, governor_buf); |
| 3178 | |
| 3179 | sprintf(path, "/sys/devices/system/cpu/cpufreq/boost"); |
| 3180 | input = fopen(path, "r"); |
| 3181 | if (input != NULL) { |
| 3182 | fscanf(input, "%d", &turbo); |
| 3183 | fprintf(outf, "cpufreq boost: %d\n", turbo); |
| 3184 | fclose(input); |
| 3185 | } |
| 3186 | |
| 3187 | sprintf(path, "/sys/devices/system/cpu/intel_pstate/no_turbo"); |
| 3188 | input = fopen(path, "r"); |
| 3189 | if (input != NULL) { |
| 3190 | fscanf(input, "%d", &turbo); |
| 3191 | fprintf(outf, "cpufreq intel_pstate no_turbo: %d\n", turbo); |
| 3192 | fclose(input); |
| 3193 | } |
| 3194 | } |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 3195 | |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 3196 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3197 | /* |
| 3198 | * print_epb() |
| 3199 | * Decode the ENERGY_PERF_BIAS MSR |
| 3200 | */ |
| 3201 | int print_epb(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3202 | { |
| 3203 | unsigned long long msr; |
| 3204 | char *epb_string; |
| 3205 | int cpu; |
| 3206 | |
| 3207 | if (!has_epb) |
| 3208 | return 0; |
| 3209 | |
| 3210 | cpu = t->cpu_id; |
| 3211 | |
| 3212 | /* EPB is per-package */ |
| 3213 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3214 | return 0; |
| 3215 | |
| 3216 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3217 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3218 | return -1; |
| 3219 | } |
| 3220 | |
| 3221 | if (get_msr(cpu, MSR_IA32_ENERGY_PERF_BIAS, &msr)) |
| 3222 | return 0; |
| 3223 | |
Len Brown | e9be7dd | 2015-05-26 12:19:37 -0400 | [diff] [blame] | 3224 | switch (msr & 0xF) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3225 | case ENERGY_PERF_BIAS_PERFORMANCE: |
| 3226 | epb_string = "performance"; |
| 3227 | break; |
| 3228 | case ENERGY_PERF_BIAS_NORMAL: |
| 3229 | epb_string = "balanced"; |
| 3230 | break; |
| 3231 | case ENERGY_PERF_BIAS_POWERSAVE: |
| 3232 | epb_string = "powersave"; |
| 3233 | break; |
| 3234 | default: |
| 3235 | epb_string = "custom"; |
| 3236 | break; |
| 3237 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3238 | 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] | 3239 | |
| 3240 | return 0; |
| 3241 | } |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3242 | /* |
| 3243 | * print_hwp() |
| 3244 | * Decode the MSR_HWP_CAPABILITIES |
| 3245 | */ |
| 3246 | int print_hwp(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3247 | { |
| 3248 | unsigned long long msr; |
| 3249 | int cpu; |
| 3250 | |
| 3251 | if (!has_hwp) |
| 3252 | return 0; |
| 3253 | |
| 3254 | cpu = t->cpu_id; |
| 3255 | |
| 3256 | /* MSR_HWP_CAPABILITIES is per-package */ |
| 3257 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3258 | return 0; |
| 3259 | |
| 3260 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3261 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3262 | return -1; |
| 3263 | } |
| 3264 | |
| 3265 | if (get_msr(cpu, MSR_PM_ENABLE, &msr)) |
| 3266 | return 0; |
| 3267 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3268 | fprintf(outf, "cpu%d: MSR_PM_ENABLE: 0x%08llx (%sHWP)\n", |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3269 | cpu, msr, (msr & (1 << 0)) ? "" : "No-"); |
| 3270 | |
| 3271 | /* MSR_PM_ENABLE[1] == 1 if HWP is enabled and MSRs visible */ |
| 3272 | if ((msr & (1 << 0)) == 0) |
| 3273 | return 0; |
| 3274 | |
| 3275 | if (get_msr(cpu, MSR_HWP_CAPABILITIES, &msr)) |
| 3276 | return 0; |
| 3277 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3278 | fprintf(outf, "cpu%d: MSR_HWP_CAPABILITIES: 0x%08llx " |
Len Brown | 6dbd25a | 2017-03-04 18:18:28 -0500 | [diff] [blame] | 3279 | "(high %d guar %d eff %d low %d)\n", |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3280 | cpu, msr, |
| 3281 | (unsigned int)HWP_HIGHEST_PERF(msr), |
| 3282 | (unsigned int)HWP_GUARANTEED_PERF(msr), |
| 3283 | (unsigned int)HWP_MOSTEFFICIENT_PERF(msr), |
| 3284 | (unsigned int)HWP_LOWEST_PERF(msr)); |
| 3285 | |
| 3286 | if (get_msr(cpu, MSR_HWP_REQUEST, &msr)) |
| 3287 | return 0; |
| 3288 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3289 | fprintf(outf, "cpu%d: MSR_HWP_REQUEST: 0x%08llx " |
Len Brown | 6dbd25a | 2017-03-04 18:18:28 -0500 | [diff] [blame] | 3290 | "(min %d max %d des %d epp 0x%x window 0x%x pkg 0x%x)\n", |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3291 | cpu, msr, |
| 3292 | (unsigned int)(((msr) >> 0) & 0xff), |
| 3293 | (unsigned int)(((msr) >> 8) & 0xff), |
| 3294 | (unsigned int)(((msr) >> 16) & 0xff), |
| 3295 | (unsigned int)(((msr) >> 24) & 0xff), |
| 3296 | (unsigned int)(((msr) >> 32) & 0xff3), |
| 3297 | (unsigned int)(((msr) >> 42) & 0x1)); |
| 3298 | |
| 3299 | if (has_hwp_pkg) { |
| 3300 | if (get_msr(cpu, MSR_HWP_REQUEST_PKG, &msr)) |
| 3301 | return 0; |
| 3302 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3303 | fprintf(outf, "cpu%d: MSR_HWP_REQUEST_PKG: 0x%08llx " |
Len Brown | 6dbd25a | 2017-03-04 18:18:28 -0500 | [diff] [blame] | 3304 | "(min %d max %d des %d epp 0x%x window 0x%x)\n", |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3305 | cpu, msr, |
| 3306 | (unsigned int)(((msr) >> 0) & 0xff), |
| 3307 | (unsigned int)(((msr) >> 8) & 0xff), |
| 3308 | (unsigned int)(((msr) >> 16) & 0xff), |
| 3309 | (unsigned int)(((msr) >> 24) & 0xff), |
| 3310 | (unsigned int)(((msr) >> 32) & 0xff3)); |
| 3311 | } |
| 3312 | if (has_hwp_notify) { |
| 3313 | if (get_msr(cpu, MSR_HWP_INTERRUPT, &msr)) |
| 3314 | return 0; |
| 3315 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3316 | fprintf(outf, "cpu%d: MSR_HWP_INTERRUPT: 0x%08llx " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3317 | "(%s_Guaranteed_Perf_Change, %s_Excursion_Min)\n", |
| 3318 | cpu, msr, |
| 3319 | ((msr) & 0x1) ? "EN" : "Dis", |
| 3320 | ((msr) & 0x2) ? "EN" : "Dis"); |
| 3321 | } |
| 3322 | if (get_msr(cpu, MSR_HWP_STATUS, &msr)) |
| 3323 | return 0; |
| 3324 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3325 | fprintf(outf, "cpu%d: MSR_HWP_STATUS: 0x%08llx " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3326 | "(%sGuaranteed_Perf_Change, %sExcursion_Min)\n", |
| 3327 | cpu, msr, |
| 3328 | ((msr) & 0x1) ? "" : "No-", |
| 3329 | ((msr) & 0x2) ? "" : "No-"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3330 | |
| 3331 | return 0; |
| 3332 | } |
| 3333 | |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3334 | /* |
| 3335 | * print_perf_limit() |
| 3336 | */ |
| 3337 | int print_perf_limit(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3338 | { |
| 3339 | unsigned long long msr; |
| 3340 | int cpu; |
| 3341 | |
| 3342 | cpu = t->cpu_id; |
| 3343 | |
| 3344 | /* per-package */ |
| 3345 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3346 | return 0; |
| 3347 | |
| 3348 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3349 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3350 | return -1; |
| 3351 | } |
| 3352 | |
| 3353 | if (do_core_perf_limit_reasons) { |
| 3354 | get_msr(cpu, MSR_CORE_PERF_LIMIT_REASONS, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3355 | fprintf(outf, "cpu%d: MSR_CORE_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr); |
| 3356 | 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] | 3357 | (msr & 1 << 15) ? "bit15, " : "", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3358 | (msr & 1 << 14) ? "bit14, " : "", |
Len Brown | e33cbe8 | 2015-03-13 16:30:57 -0400 | [diff] [blame] | 3359 | (msr & 1 << 13) ? "Transitions, " : "", |
| 3360 | (msr & 1 << 12) ? "MultiCoreTurbo, " : "", |
| 3361 | (msr & 1 << 11) ? "PkgPwrL2, " : "", |
| 3362 | (msr & 1 << 10) ? "PkgPwrL1, " : "", |
| 3363 | (msr & 1 << 9) ? "CorePwr, " : "", |
| 3364 | (msr & 1 << 8) ? "Amps, " : "", |
| 3365 | (msr & 1 << 6) ? "VR-Therm, " : "", |
| 3366 | (msr & 1 << 5) ? "Auto-HWP, " : "", |
| 3367 | (msr & 1 << 4) ? "Graphics, " : "", |
| 3368 | (msr & 1 << 2) ? "bit2, " : "", |
| 3369 | (msr & 1 << 1) ? "ThermStatus, " : "", |
| 3370 | (msr & 1 << 0) ? "PROCHOT, " : ""); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3371 | 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] | 3372 | (msr & 1 << 31) ? "bit31, " : "", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3373 | (msr & 1 << 30) ? "bit30, " : "", |
Len Brown | e33cbe8 | 2015-03-13 16:30:57 -0400 | [diff] [blame] | 3374 | (msr & 1 << 29) ? "Transitions, " : "", |
| 3375 | (msr & 1 << 28) ? "MultiCoreTurbo, " : "", |
| 3376 | (msr & 1 << 27) ? "PkgPwrL2, " : "", |
| 3377 | (msr & 1 << 26) ? "PkgPwrL1, " : "", |
| 3378 | (msr & 1 << 25) ? "CorePwr, " : "", |
| 3379 | (msr & 1 << 24) ? "Amps, " : "", |
| 3380 | (msr & 1 << 22) ? "VR-Therm, " : "", |
| 3381 | (msr & 1 << 21) ? "Auto-HWP, " : "", |
| 3382 | (msr & 1 << 20) ? "Graphics, " : "", |
| 3383 | (msr & 1 << 18) ? "bit18, " : "", |
| 3384 | (msr & 1 << 17) ? "ThermStatus, " : "", |
| 3385 | (msr & 1 << 16) ? "PROCHOT, " : ""); |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3386 | |
| 3387 | } |
| 3388 | if (do_gfx_perf_limit_reasons) { |
| 3389 | get_msr(cpu, MSR_GFX_PERF_LIMIT_REASONS, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3390 | fprintf(outf, "cpu%d: MSR_GFX_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr); |
| 3391 | fprintf(outf, " (Active: %s%s%s%s%s%s%s%s)", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3392 | (msr & 1 << 0) ? "PROCHOT, " : "", |
| 3393 | (msr & 1 << 1) ? "ThermStatus, " : "", |
| 3394 | (msr & 1 << 4) ? "Graphics, " : "", |
| 3395 | (msr & 1 << 6) ? "VR-Therm, " : "", |
| 3396 | (msr & 1 << 8) ? "Amps, " : "", |
| 3397 | (msr & 1 << 9) ? "GFXPwr, " : "", |
| 3398 | (msr & 1 << 10) ? "PkgPwrL1, " : "", |
| 3399 | (msr & 1 << 11) ? "PkgPwrL2, " : ""); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3400 | fprintf(outf, " (Logged: %s%s%s%s%s%s%s%s)\n", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3401 | (msr & 1 << 16) ? "PROCHOT, " : "", |
| 3402 | (msr & 1 << 17) ? "ThermStatus, " : "", |
| 3403 | (msr & 1 << 20) ? "Graphics, " : "", |
| 3404 | (msr & 1 << 22) ? "VR-Therm, " : "", |
| 3405 | (msr & 1 << 24) ? "Amps, " : "", |
| 3406 | (msr & 1 << 25) ? "GFXPwr, " : "", |
| 3407 | (msr & 1 << 26) ? "PkgPwrL1, " : "", |
| 3408 | (msr & 1 << 27) ? "PkgPwrL2, " : ""); |
| 3409 | } |
| 3410 | if (do_ring_perf_limit_reasons) { |
| 3411 | get_msr(cpu, MSR_RING_PERF_LIMIT_REASONS, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3412 | fprintf(outf, "cpu%d: MSR_RING_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr); |
| 3413 | fprintf(outf, " (Active: %s%s%s%s%s%s)", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3414 | (msr & 1 << 0) ? "PROCHOT, " : "", |
| 3415 | (msr & 1 << 1) ? "ThermStatus, " : "", |
| 3416 | (msr & 1 << 6) ? "VR-Therm, " : "", |
| 3417 | (msr & 1 << 8) ? "Amps, " : "", |
| 3418 | (msr & 1 << 10) ? "PkgPwrL1, " : "", |
| 3419 | (msr & 1 << 11) ? "PkgPwrL2, " : ""); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3420 | fprintf(outf, " (Logged: %s%s%s%s%s%s)\n", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3421 | (msr & 1 << 16) ? "PROCHOT, " : "", |
| 3422 | (msr & 1 << 17) ? "ThermStatus, " : "", |
| 3423 | (msr & 1 << 22) ? "VR-Therm, " : "", |
| 3424 | (msr & 1 << 24) ? "Amps, " : "", |
| 3425 | (msr & 1 << 26) ? "PkgPwrL1, " : "", |
| 3426 | (msr & 1 << 27) ? "PkgPwrL2, " : ""); |
| 3427 | } |
| 3428 | return 0; |
| 3429 | } |
| 3430 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3431 | #define RAPL_POWER_GRANULARITY 0x7FFF /* 15 bit power granularity */ |
| 3432 | #define RAPL_TIME_GRANULARITY 0x3F /* 6 bit time granularity */ |
| 3433 | |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 3434 | double get_tdp(unsigned int model) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3435 | { |
| 3436 | unsigned long long msr; |
| 3437 | |
| 3438 | if (do_rapl & RAPL_PKG_POWER_INFO) |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3439 | if (!get_msr(base_cpu, MSR_PKG_POWER_INFO, &msr)) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3440 | return ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units; |
| 3441 | |
| 3442 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3443 | case INTEL_FAM6_ATOM_SILVERMONT1: |
| 3444 | case INTEL_FAM6_ATOM_SILVERMONT2: |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3445 | return 30.0; |
| 3446 | default: |
| 3447 | return 135.0; |
| 3448 | } |
| 3449 | } |
| 3450 | |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 3451 | /* |
| 3452 | * rapl_dram_energy_units_probe() |
| 3453 | * Energy units are either hard-coded, or come from RAPL Energy Unit MSR. |
| 3454 | */ |
| 3455 | static double |
| 3456 | rapl_dram_energy_units_probe(int model, double rapl_energy_units) |
| 3457 | { |
| 3458 | /* only called for genuine_intel, family 6 */ |
| 3459 | |
| 3460 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3461 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 3462 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 3463 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 3464 | case INTEL_FAM6_XEON_PHI_KNL: /* KNL */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 3465 | case INTEL_FAM6_XEON_PHI_KNM: |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 3466 | return (rapl_dram_energy_units = 15.3 / 1000000); |
| 3467 | default: |
| 3468 | return (rapl_energy_units); |
| 3469 | } |
| 3470 | } |
| 3471 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3472 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3473 | /* |
| 3474 | * rapl_probe() |
| 3475 | * |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3476 | * sets do_rapl, rapl_power_units, rapl_energy_units, rapl_time_units |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3477 | */ |
| 3478 | void rapl_probe(unsigned int family, unsigned int model) |
| 3479 | { |
| 3480 | unsigned long long msr; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3481 | unsigned int time_unit; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3482 | double tdp; |
| 3483 | |
| 3484 | if (!genuine_intel) |
| 3485 | return; |
| 3486 | |
| 3487 | if (family != 6) |
| 3488 | return; |
| 3489 | |
| 3490 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3491 | case INTEL_FAM6_SANDYBRIDGE: |
| 3492 | case INTEL_FAM6_IVYBRIDGE: |
| 3493 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 3494 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 3495 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 3496 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 3497 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3498 | 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] | 3499 | if (rapl_joules) { |
| 3500 | BIC_PRESENT(BIC_Pkg_J); |
| 3501 | BIC_PRESENT(BIC_Cor_J); |
| 3502 | BIC_PRESENT(BIC_GFX_J); |
| 3503 | } else { |
| 3504 | BIC_PRESENT(BIC_PkgWatt); |
| 3505 | BIC_PRESENT(BIC_CorWatt); |
| 3506 | BIC_PRESENT(BIC_GFXWatt); |
| 3507 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3508 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3509 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | ac01ac1 | 2017-01-27 01:45:35 -0500 | [diff] [blame] | 3510 | case INTEL_FAM6_ATOM_GEMINI_LAKE: |
Len Brown | e4085d5 | 2016-04-06 17:15:56 -0400 | [diff] [blame] | 3511 | do_rapl = RAPL_PKG | RAPL_PKG_POWER_INFO; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3512 | if (rapl_joules) |
| 3513 | BIC_PRESENT(BIC_Pkg_J); |
| 3514 | else |
| 3515 | BIC_PRESENT(BIC_PkgWatt); |
Len Brown | e4085d5 | 2016-04-06 17:15:56 -0400 | [diff] [blame] | 3516 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3517 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 3518 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 3519 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 3520 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Len Brown | 8182492 | 2017-03-04 17:23:07 -0500 | [diff] [blame] | 3521 | do_rapl = RAPL_PKG | RAPL_CORES | RAPL_CORE_POLICY | RAPL_DRAM | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_GFX | RAPL_PKG_POWER_INFO; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3522 | BIC_PRESENT(BIC_PKG__); |
| 3523 | BIC_PRESENT(BIC_RAM__); |
| 3524 | if (rapl_joules) { |
| 3525 | BIC_PRESENT(BIC_Pkg_J); |
| 3526 | BIC_PRESENT(BIC_Cor_J); |
| 3527 | BIC_PRESENT(BIC_RAM_J); |
Len Brown | 8182492 | 2017-03-04 17:23:07 -0500 | [diff] [blame] | 3528 | BIC_PRESENT(BIC_GFX_J); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3529 | } else { |
| 3530 | BIC_PRESENT(BIC_PkgWatt); |
| 3531 | BIC_PRESENT(BIC_CorWatt); |
| 3532 | BIC_PRESENT(BIC_RAMWatt); |
Len Brown | 8182492 | 2017-03-04 17:23:07 -0500 | [diff] [blame] | 3533 | BIC_PRESENT(BIC_GFXWatt); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3534 | } |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3535 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3536 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 3537 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 3538 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 3539 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
| 3540 | case INTEL_FAM6_XEON_PHI_KNL: /* KNL */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 3541 | case INTEL_FAM6_XEON_PHI_KNM: |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3542 | 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] | 3543 | BIC_PRESENT(BIC_PKG__); |
| 3544 | BIC_PRESENT(BIC_RAM__); |
| 3545 | if (rapl_joules) { |
| 3546 | BIC_PRESENT(BIC_Pkg_J); |
| 3547 | BIC_PRESENT(BIC_RAM_J); |
| 3548 | } else { |
| 3549 | BIC_PRESENT(BIC_PkgWatt); |
| 3550 | BIC_PRESENT(BIC_RAMWatt); |
| 3551 | } |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 3552 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3553 | case INTEL_FAM6_SANDYBRIDGE_X: |
| 3554 | case INTEL_FAM6_IVYBRIDGE_X: |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3555 | 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] | 3556 | BIC_PRESENT(BIC_PKG__); |
| 3557 | BIC_PRESENT(BIC_RAM__); |
| 3558 | if (rapl_joules) { |
| 3559 | BIC_PRESENT(BIC_Pkg_J); |
| 3560 | BIC_PRESENT(BIC_Cor_J); |
| 3561 | BIC_PRESENT(BIC_RAM_J); |
| 3562 | } else { |
| 3563 | BIC_PRESENT(BIC_PkgWatt); |
| 3564 | BIC_PRESENT(BIC_CorWatt); |
| 3565 | BIC_PRESENT(BIC_RAMWatt); |
| 3566 | } |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3567 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3568 | case INTEL_FAM6_ATOM_SILVERMONT1: /* BYT */ |
| 3569 | case INTEL_FAM6_ATOM_SILVERMONT2: /* AVN */ |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 3570 | do_rapl = RAPL_PKG | RAPL_CORES; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3571 | if (rapl_joules) { |
| 3572 | BIC_PRESENT(BIC_Pkg_J); |
| 3573 | BIC_PRESENT(BIC_Cor_J); |
| 3574 | } else { |
| 3575 | BIC_PRESENT(BIC_PkgWatt); |
| 3576 | BIC_PRESENT(BIC_CorWatt); |
| 3577 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3578 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3579 | case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ |
Jacob Pan | 0f64490 | 2016-06-16 09:48:22 -0700 | [diff] [blame] | 3580 | 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] | 3581 | BIC_PRESENT(BIC_PKG__); |
| 3582 | BIC_PRESENT(BIC_RAM__); |
| 3583 | if (rapl_joules) { |
| 3584 | BIC_PRESENT(BIC_Pkg_J); |
| 3585 | BIC_PRESENT(BIC_Cor_J); |
| 3586 | BIC_PRESENT(BIC_RAM_J); |
| 3587 | } else { |
| 3588 | BIC_PRESENT(BIC_PkgWatt); |
| 3589 | BIC_PRESENT(BIC_CorWatt); |
| 3590 | BIC_PRESENT(BIC_RAMWatt); |
| 3591 | } |
Jacob Pan | 0f64490 | 2016-06-16 09:48:22 -0700 | [diff] [blame] | 3592 | break; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3593 | default: |
| 3594 | return; |
| 3595 | } |
| 3596 | |
| 3597 | /* units on package 0, verify later other packages match */ |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3598 | if (get_msr(base_cpu, MSR_RAPL_POWER_UNIT, &msr)) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3599 | return; |
| 3600 | |
| 3601 | rapl_power_units = 1.0 / (1 << (msr & 0xF)); |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3602 | if (model == INTEL_FAM6_ATOM_SILVERMONT1) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3603 | rapl_energy_units = 1.0 * (1 << (msr >> 8 & 0x1F)) / 1000000; |
| 3604 | else |
| 3605 | rapl_energy_units = 1.0 / (1 << (msr >> 8 & 0x1F)); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3606 | |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 3607 | rapl_dram_energy_units = rapl_dram_energy_units_probe(model, rapl_energy_units); |
| 3608 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3609 | time_unit = msr >> 16 & 0xF; |
| 3610 | if (time_unit == 0) |
| 3611 | time_unit = 0xA; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3612 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3613 | rapl_time_units = 1.0 / (1 << (time_unit)); |
| 3614 | |
| 3615 | tdp = get_tdp(model); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3616 | |
| 3617 | rapl_joule_counter_range = 0xFFFFFFFF * rapl_energy_units / tdp; |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3618 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3619 | 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] | 3620 | |
| 3621 | return; |
| 3622 | } |
| 3623 | |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 3624 | void perf_limit_reasons_probe(unsigned int family, unsigned int model) |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3625 | { |
| 3626 | if (!genuine_intel) |
| 3627 | return; |
| 3628 | |
| 3629 | if (family != 6) |
| 3630 | return; |
| 3631 | |
| 3632 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3633 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 3634 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 3635 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3636 | do_gfx_perf_limit_reasons = 1; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3637 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3638 | do_core_perf_limit_reasons = 1; |
| 3639 | do_ring_perf_limit_reasons = 1; |
| 3640 | default: |
| 3641 | return; |
| 3642 | } |
| 3643 | } |
| 3644 | |
Artem Bityutskiy | ac980e1 | 2017-09-05 15:14:08 +0300 | [diff] [blame^] | 3645 | void automatic_cstate_conversion_probe(unsigned int family, unsigned int model) |
| 3646 | { |
| 3647 | if (is_skx(family, model) || is_bdx(family, model)) |
| 3648 | has_automatic_cstate_conversion = 1; |
| 3649 | } |
| 3650 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3651 | int print_thermal(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3652 | { |
| 3653 | unsigned long long msr; |
Len Brown | f4896fa5 | 2017-03-04 18:10:45 -0500 | [diff] [blame] | 3654 | unsigned int dts, dts2; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3655 | int cpu; |
| 3656 | |
| 3657 | if (!(do_dts || do_ptm)) |
| 3658 | return 0; |
| 3659 | |
| 3660 | cpu = t->cpu_id; |
| 3661 | |
| 3662 | /* DTS is per-core, no need to print for each thread */ |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 3663 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3664 | return 0; |
| 3665 | |
| 3666 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3667 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3668 | return -1; |
| 3669 | } |
| 3670 | |
| 3671 | if (do_ptm && (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) { |
| 3672 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr)) |
| 3673 | return 0; |
| 3674 | |
| 3675 | dts = (msr >> 16) & 0x7F; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3676 | 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] | 3677 | cpu, msr, tcc_activation_temp - dts); |
| 3678 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3679 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, &msr)) |
| 3680 | return 0; |
| 3681 | |
| 3682 | dts = (msr >> 16) & 0x7F; |
| 3683 | dts2 = (msr >> 8) & 0x7F; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3684 | 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] | 3685 | cpu, msr, tcc_activation_temp - dts, tcc_activation_temp - dts2); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3686 | } |
| 3687 | |
| 3688 | |
Len Brown | f4896fa5 | 2017-03-04 18:10:45 -0500 | [diff] [blame] | 3689 | if (do_dts && debug) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3690 | unsigned int resolution; |
| 3691 | |
| 3692 | if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr)) |
| 3693 | return 0; |
| 3694 | |
| 3695 | dts = (msr >> 16) & 0x7F; |
| 3696 | resolution = (msr >> 27) & 0xF; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3697 | 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] | 3698 | cpu, msr, tcc_activation_temp - dts, resolution); |
| 3699 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3700 | if (get_msr(cpu, MSR_IA32_THERM_INTERRUPT, &msr)) |
| 3701 | return 0; |
| 3702 | |
| 3703 | dts = (msr >> 16) & 0x7F; |
| 3704 | dts2 = (msr >> 8) & 0x7F; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3705 | 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] | 3706 | cpu, msr, tcc_activation_temp - dts, tcc_activation_temp - dts2); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3707 | } |
| 3708 | |
| 3709 | return 0; |
| 3710 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 3711 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3712 | void print_power_limit_msr(int cpu, unsigned long long msr, char *label) |
| 3713 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3714 | 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] | 3715 | cpu, label, |
| 3716 | ((msr >> 15) & 1) ? "EN" : "DIS", |
| 3717 | ((msr >> 0) & 0x7FFF) * rapl_power_units, |
| 3718 | (1.0 + (((msr >> 22) & 0x3)/4.0)) * (1 << ((msr >> 17) & 0x1F)) * rapl_time_units, |
| 3719 | (((msr >> 16) & 1) ? "EN" : "DIS")); |
| 3720 | |
| 3721 | return; |
| 3722 | } |
| 3723 | |
| 3724 | int print_rapl(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3725 | { |
| 3726 | unsigned long long msr; |
| 3727 | int cpu; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3728 | |
| 3729 | if (!do_rapl) |
| 3730 | return 0; |
| 3731 | |
| 3732 | /* RAPL counters are per package, so print only for 1st thread/package */ |
| 3733 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3734 | return 0; |
| 3735 | |
| 3736 | cpu = t->cpu_id; |
| 3737 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3738 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3739 | return -1; |
| 3740 | } |
| 3741 | |
| 3742 | if (get_msr(cpu, MSR_RAPL_POWER_UNIT, &msr)) |
| 3743 | return -1; |
| 3744 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3745 | fprintf(outf, "cpu%d: MSR_RAPL_POWER_UNIT: 0x%08llx (%f Watts, %f Joules, %f sec.)\n", cpu, msr, |
| 3746 | rapl_power_units, rapl_energy_units, rapl_time_units); |
| 3747 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3748 | if (do_rapl & RAPL_PKG_POWER_INFO) { |
| 3749 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3750 | if (get_msr(cpu, MSR_PKG_POWER_INFO, &msr)) |
| 3751 | return -5; |
| 3752 | |
| 3753 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3754 | 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] | 3755 | cpu, msr, |
| 3756 | ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3757 | ((msr >> 16) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3758 | ((msr >> 32) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3759 | ((msr >> 48) & RAPL_TIME_GRANULARITY) * rapl_time_units); |
| 3760 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3761 | } |
| 3762 | if (do_rapl & RAPL_PKG) { |
| 3763 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3764 | if (get_msr(cpu, MSR_PKG_POWER_LIMIT, &msr)) |
| 3765 | return -9; |
| 3766 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3767 | fprintf(outf, "cpu%d: MSR_PKG_POWER_LIMIT: 0x%08llx (%slocked)\n", |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3768 | cpu, msr, (msr >> 63) & 1 ? "" : "UN"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3769 | |
| 3770 | print_power_limit_msr(cpu, msr, "PKG Limit #1"); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3771 | 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] | 3772 | cpu, |
| 3773 | ((msr >> 47) & 1) ? "EN" : "DIS", |
| 3774 | ((msr >> 32) & 0x7FFF) * rapl_power_units, |
| 3775 | (1.0 + (((msr >> 54) & 0x3)/4.0)) * (1 << ((msr >> 49) & 0x1F)) * rapl_time_units, |
| 3776 | ((msr >> 48) & 1) ? "EN" : "DIS"); |
| 3777 | } |
| 3778 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3779 | if (do_rapl & RAPL_DRAM_POWER_INFO) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3780 | if (get_msr(cpu, MSR_DRAM_POWER_INFO, &msr)) |
| 3781 | return -6; |
| 3782 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3783 | 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] | 3784 | cpu, msr, |
| 3785 | ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3786 | ((msr >> 16) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3787 | ((msr >> 32) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3788 | ((msr >> 48) & RAPL_TIME_GRANULARITY) * rapl_time_units); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3789 | } |
| 3790 | if (do_rapl & RAPL_DRAM) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3791 | if (get_msr(cpu, MSR_DRAM_POWER_LIMIT, &msr)) |
| 3792 | return -9; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3793 | fprintf(outf, "cpu%d: MSR_DRAM_POWER_LIMIT: 0x%08llx (%slocked)\n", |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3794 | cpu, msr, (msr >> 31) & 1 ? "" : "UN"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3795 | |
| 3796 | print_power_limit_msr(cpu, msr, "DRAM Limit"); |
| 3797 | } |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3798 | if (do_rapl & RAPL_CORE_POLICY) { |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3799 | if (get_msr(cpu, MSR_PP0_POLICY, &msr)) |
| 3800 | return -7; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3801 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3802 | fprintf(outf, "cpu%d: MSR_PP0_POLICY: %lld\n", cpu, msr & 0xF); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3803 | } |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 3804 | if (do_rapl & RAPL_CORES_POWER_LIMIT) { |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3805 | if (get_msr(cpu, MSR_PP0_POWER_LIMIT, &msr)) |
| 3806 | return -9; |
| 3807 | fprintf(outf, "cpu%d: MSR_PP0_POWER_LIMIT: 0x%08llx (%slocked)\n", |
| 3808 | cpu, msr, (msr >> 31) & 1 ? "" : "UN"); |
| 3809 | print_power_limit_msr(cpu, msr, "Cores Limit"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3810 | } |
| 3811 | if (do_rapl & RAPL_GFX) { |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3812 | if (get_msr(cpu, MSR_PP1_POLICY, &msr)) |
| 3813 | return -8; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3814 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3815 | fprintf(outf, "cpu%d: MSR_PP1_POLICY: %lld\n", cpu, msr & 0xF); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3816 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3817 | if (get_msr(cpu, MSR_PP1_POWER_LIMIT, &msr)) |
| 3818 | return -9; |
| 3819 | fprintf(outf, "cpu%d: MSR_PP1_POWER_LIMIT: 0x%08llx (%slocked)\n", |
| 3820 | cpu, msr, (msr >> 31) & 1 ? "" : "UN"); |
| 3821 | print_power_limit_msr(cpu, msr, "GFX Limit"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3822 | } |
| 3823 | return 0; |
| 3824 | } |
| 3825 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3826 | /* |
| 3827 | * SNB adds support for additional MSRs: |
| 3828 | * |
| 3829 | * MSR_PKG_C7_RESIDENCY 0x000003fa |
| 3830 | * MSR_CORE_C7_RESIDENCY 0x000003fe |
| 3831 | * MSR_PKG_C2_RESIDENCY 0x0000060d |
| 3832 | */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3833 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3834 | int has_snb_msrs(unsigned int family, unsigned int model) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3835 | { |
| 3836 | if (!genuine_intel) |
| 3837 | return 0; |
| 3838 | |
| 3839 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3840 | case INTEL_FAM6_SANDYBRIDGE: |
| 3841 | case INTEL_FAM6_SANDYBRIDGE_X: |
| 3842 | case INTEL_FAM6_IVYBRIDGE: /* IVB */ |
| 3843 | case INTEL_FAM6_IVYBRIDGE_X: /* IVB Xeon */ |
| 3844 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 3845 | case INTEL_FAM6_HASWELL_X: /* HSW */ |
| 3846 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 3847 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 3848 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 3849 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
| 3850 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 3851 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 3852 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 3853 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 3854 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 3855 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
| 3856 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
| 3857 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | ac01ac1 | 2017-01-27 01:45:35 -0500 | [diff] [blame] | 3858 | case INTEL_FAM6_ATOM_GEMINI_LAKE: |
Xiaolong Wang | 5bbac26 | 2016-09-30 17:53:40 +0800 | [diff] [blame] | 3859 | case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3860 | return 1; |
| 3861 | } |
| 3862 | return 0; |
| 3863 | } |
| 3864 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3865 | /* |
| 3866 | * HSW adds support for additional MSRs: |
| 3867 | * |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 3868 | * MSR_PKG_C8_RESIDENCY 0x00000630 |
| 3869 | * MSR_PKG_C9_RESIDENCY 0x00000631 |
| 3870 | * MSR_PKG_C10_RESIDENCY 0x00000632 |
| 3871 | * |
| 3872 | * MSR_PKGC8_IRTL 0x00000633 |
| 3873 | * MSR_PKGC9_IRTL 0x00000634 |
| 3874 | * MSR_PKGC10_IRTL 0x00000635 |
| 3875 | * |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3876 | */ |
| 3877 | int has_hsw_msrs(unsigned int family, unsigned int model) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 3878 | { |
| 3879 | if (!genuine_intel) |
| 3880 | return 0; |
| 3881 | |
| 3882 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3883 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 3884 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 3885 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 3886 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 3887 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 3888 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
| 3889 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | ac01ac1 | 2017-01-27 01:45:35 -0500 | [diff] [blame] | 3890 | case INTEL_FAM6_ATOM_GEMINI_LAKE: |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 3891 | return 1; |
| 3892 | } |
| 3893 | return 0; |
| 3894 | } |
| 3895 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3896 | /* |
| 3897 | * SKL adds support for additional MSRS: |
| 3898 | * |
| 3899 | * MSR_PKG_WEIGHTED_CORE_C0_RES 0x00000658 |
| 3900 | * MSR_PKG_ANY_CORE_C0_RES 0x00000659 |
| 3901 | * MSR_PKG_ANY_GFXE_C0_RES 0x0000065A |
| 3902 | * MSR_PKG_BOTH_CORE_GFXE_C0_RES 0x0000065B |
| 3903 | */ |
| 3904 | int has_skl_msrs(unsigned int family, unsigned int model) |
| 3905 | { |
| 3906 | if (!genuine_intel) |
| 3907 | return 0; |
| 3908 | |
| 3909 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3910 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 3911 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 3912 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 3913 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3914 | return 1; |
| 3915 | } |
| 3916 | return 0; |
| 3917 | } |
| 3918 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3919 | int is_slm(unsigned int family, unsigned int model) |
| 3920 | { |
| 3921 | if (!genuine_intel) |
| 3922 | return 0; |
| 3923 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3924 | case INTEL_FAM6_ATOM_SILVERMONT1: /* BYT */ |
| 3925 | case INTEL_FAM6_ATOM_SILVERMONT2: /* AVN */ |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3926 | return 1; |
| 3927 | } |
| 3928 | return 0; |
| 3929 | } |
| 3930 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 3931 | int is_knl(unsigned int family, unsigned int model) |
| 3932 | { |
| 3933 | if (!genuine_intel) |
| 3934 | return 0; |
| 3935 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3936 | case INTEL_FAM6_XEON_PHI_KNL: /* KNL */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 3937 | case INTEL_FAM6_XEON_PHI_KNM: |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 3938 | return 1; |
| 3939 | } |
| 3940 | return 0; |
| 3941 | } |
| 3942 | |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 3943 | unsigned int get_aperf_mperf_multiplier(unsigned int family, unsigned int model) |
| 3944 | { |
| 3945 | if (is_knl(family, model)) |
| 3946 | return 1024; |
| 3947 | return 1; |
| 3948 | } |
| 3949 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3950 | #define SLM_BCLK_FREQS 5 |
| 3951 | double slm_freq_table[SLM_BCLK_FREQS] = { 83.3, 100.0, 133.3, 116.7, 80.0}; |
| 3952 | |
| 3953 | double slm_bclk(void) |
| 3954 | { |
| 3955 | unsigned long long msr = 3; |
| 3956 | unsigned int i; |
| 3957 | double freq; |
| 3958 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3959 | if (get_msr(base_cpu, MSR_FSB_FREQ, &msr)) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3960 | fprintf(outf, "SLM BCLK: unknown\n"); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3961 | |
| 3962 | i = msr & 0xf; |
| 3963 | if (i >= SLM_BCLK_FREQS) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3964 | fprintf(outf, "SLM BCLK[%d] invalid\n", i); |
Colin Ian King | 0a91e55 | 2016-04-25 13:03:15 +0100 | [diff] [blame] | 3965 | i = 3; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3966 | } |
| 3967 | freq = slm_freq_table[i]; |
| 3968 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3969 | if (!quiet) |
Len Brown | 8f6196c | 2017-01-07 22:40:23 -0500 | [diff] [blame] | 3970 | fprintf(outf, "SLM BCLK: %.1f Mhz\n", freq); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3971 | |
| 3972 | return freq; |
| 3973 | } |
| 3974 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3975 | double discover_bclk(unsigned int family, unsigned int model) |
| 3976 | { |
Chrzaniuk, Hubert | 121b48b | 2016-02-10 16:35:17 +0100 | [diff] [blame] | 3977 | if (has_snb_msrs(family, model) || is_knl(family, model)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3978 | return 100.00; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3979 | else if (is_slm(family, model)) |
| 3980 | return slm_bclk(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3981 | else |
| 3982 | return 133.33; |
| 3983 | } |
| 3984 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3985 | /* |
| 3986 | * MSR_IA32_TEMPERATURE_TARGET indicates the temperature where |
| 3987 | * the Thermal Control Circuit (TCC) activates. |
| 3988 | * This is usually equal to tjMax. |
| 3989 | * |
| 3990 | * Older processors do not have this MSR, so there we guess, |
| 3991 | * but also allow cmdline over-ride with -T. |
| 3992 | * |
| 3993 | * Several MSR temperature values are in units of degrees-C |
| 3994 | * below this value, including the Digital Thermal Sensor (DTS), |
| 3995 | * Package Thermal Management Sensor (PTM), and thermal event thresholds. |
| 3996 | */ |
| 3997 | int set_temperature_target(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3998 | { |
| 3999 | unsigned long long msr; |
| 4000 | unsigned int target_c_local; |
| 4001 | int cpu; |
| 4002 | |
| 4003 | /* tcc_activation_temp is used only for dts or ptm */ |
| 4004 | if (!(do_dts || do_ptm)) |
| 4005 | return 0; |
| 4006 | |
| 4007 | /* this is a per-package concept */ |
| 4008 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 4009 | return 0; |
| 4010 | |
| 4011 | cpu = t->cpu_id; |
| 4012 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4013 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4014 | return -1; |
| 4015 | } |
| 4016 | |
| 4017 | if (tcc_activation_temp_override != 0) { |
| 4018 | tcc_activation_temp = tcc_activation_temp_override; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4019 | fprintf(outf, "cpu%d: Using cmdline TCC Target (%d C)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4020 | cpu, tcc_activation_temp); |
| 4021 | return 0; |
| 4022 | } |
| 4023 | |
| 4024 | /* Temperature Target MSR is Nehalem and newer only */ |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4025 | if (!do_nhm_platform_info) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4026 | goto guess; |
| 4027 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 4028 | if (get_msr(base_cpu, MSR_IA32_TEMPERATURE_TARGET, &msr)) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4029 | goto guess; |
| 4030 | |
Jean Delvare | 3482124 | 2014-05-01 11:40:19 +0200 | [diff] [blame] | 4031 | target_c_local = (msr >> 16) & 0xFF; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4032 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4033 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4034 | 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] | 4035 | cpu, msr, target_c_local); |
| 4036 | |
Jean Delvare | 3482124 | 2014-05-01 11:40:19 +0200 | [diff] [blame] | 4037 | if (!target_c_local) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4038 | goto guess; |
| 4039 | |
| 4040 | tcc_activation_temp = target_c_local; |
| 4041 | |
| 4042 | return 0; |
| 4043 | |
| 4044 | guess: |
| 4045 | tcc_activation_temp = TJMAX_DEFAULT; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4046 | 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] | 4047 | cpu, tcc_activation_temp); |
| 4048 | |
| 4049 | return 0; |
| 4050 | } |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4051 | |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 4052 | void decode_feature_control_msr(void) |
| 4053 | { |
| 4054 | unsigned long long msr; |
| 4055 | |
| 4056 | if (!get_msr(base_cpu, MSR_IA32_FEATURE_CONTROL, &msr)) |
| 4057 | fprintf(outf, "cpu%d: MSR_IA32_FEATURE_CONTROL: 0x%08llx (%sLocked %s)\n", |
| 4058 | base_cpu, msr, |
| 4059 | msr & FEATURE_CONTROL_LOCKED ? "" : "UN-", |
| 4060 | msr & (1 << 18) ? "SGX" : ""); |
| 4061 | } |
| 4062 | |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4063 | void decode_misc_enable_msr(void) |
| 4064 | { |
| 4065 | unsigned long long msr; |
| 4066 | |
Len Brown | f26b151 | 2017-06-23 20:45:54 -0700 | [diff] [blame] | 4067 | if (!genuine_intel) |
| 4068 | return; |
| 4069 | |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4070 | if (!get_msr(base_cpu, MSR_IA32_MISC_ENABLE, &msr)) |
Len Brown | e651262 | 2017-01-11 23:17:24 -0500 | [diff] [blame] | 4071 | 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] | 4072 | base_cpu, msr, |
Len Brown | e651262 | 2017-01-11 23:17:24 -0500 | [diff] [blame] | 4073 | msr & MSR_IA32_MISC_ENABLE_TM1 ? "" : "No-", |
| 4074 | msr & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP ? "" : "No-", |
Len Brown | fd3933c | 2017-11-08 23:15:42 -0500 | [diff] [blame] | 4075 | msr & MSR_IA32_MISC_ENABLE_MWAIT ? "" : "No-", |
Len Brown | e651262 | 2017-01-11 23:17:24 -0500 | [diff] [blame] | 4076 | msr & MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE ? "No-" : "", |
| 4077 | msr & MSR_IA32_MISC_ENABLE_TURBO_DISABLE ? "No-" : ""); |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4078 | } |
| 4079 | |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 4080 | void decode_misc_feature_control(void) |
| 4081 | { |
| 4082 | unsigned long long msr; |
| 4083 | |
| 4084 | if (!has_misc_feature_control) |
| 4085 | return; |
| 4086 | |
| 4087 | if (!get_msr(base_cpu, MSR_MISC_FEATURE_CONTROL, &msr)) |
| 4088 | fprintf(outf, "cpu%d: MSR_MISC_FEATURE_CONTROL: 0x%08llx (%sL2-Prefetch %sL2-Prefetch-pair %sL1-Prefetch %sL1-IP-Prefetch)\n", |
| 4089 | base_cpu, msr, |
| 4090 | msr & (0 << 0) ? "No-" : "", |
| 4091 | msr & (1 << 0) ? "No-" : "", |
| 4092 | msr & (2 << 0) ? "No-" : "", |
| 4093 | msr & (3 << 0) ? "No-" : ""); |
| 4094 | } |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 4095 | /* |
| 4096 | * Decode MSR_MISC_PWR_MGMT |
| 4097 | * |
| 4098 | * Decode the bits according to the Nehalem documentation |
| 4099 | * bit[0] seems to continue to have same meaning going forward |
| 4100 | * bit[1] less so... |
| 4101 | */ |
| 4102 | void decode_misc_pwr_mgmt_msr(void) |
| 4103 | { |
| 4104 | unsigned long long msr; |
| 4105 | |
| 4106 | if (!do_nhm_platform_info) |
| 4107 | return; |
| 4108 | |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 4109 | if (no_MSR_MISC_PWR_MGMT) |
| 4110 | return; |
| 4111 | |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 4112 | if (!get_msr(base_cpu, MSR_MISC_PWR_MGMT, &msr)) |
Srinivas Pandruvada | ddadb8a | 2016-11-11 14:29:48 -0800 | [diff] [blame] | 4113 | 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] | 4114 | base_cpu, msr, |
| 4115 | msr & (1 << 0) ? "DIS" : "EN", |
Srinivas Pandruvada | ddadb8a | 2016-11-11 14:29:48 -0800 | [diff] [blame] | 4116 | msr & (1 << 1) ? "EN" : "DIS", |
| 4117 | msr & (1 << 8) ? "EN" : "DIS"); |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 4118 | } |
Len Brown | 71616c8 | 2017-01-07 22:37:48 -0500 | [diff] [blame] | 4119 | /* |
| 4120 | * Decode MSR_CC6_DEMOTION_POLICY_CONFIG, MSR_MC6_DEMOTION_POLICY_CONFIG |
| 4121 | * |
| 4122 | * This MSRs are present on Silvermont processors, |
| 4123 | * Intel Atom processor E3000 series (Baytrail), and friends. |
| 4124 | */ |
| 4125 | void decode_c6_demotion_policy_msr(void) |
| 4126 | { |
| 4127 | unsigned long long msr; |
| 4128 | |
| 4129 | if (!get_msr(base_cpu, MSR_CC6_DEMOTION_POLICY_CONFIG, &msr)) |
| 4130 | fprintf(outf, "cpu%d: MSR_CC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-CC6-Demotion)\n", |
| 4131 | base_cpu, msr, msr & (1 << 0) ? "EN" : "DIS"); |
| 4132 | |
| 4133 | if (!get_msr(base_cpu, MSR_MC6_DEMOTION_POLICY_CONFIG, &msr)) |
| 4134 | fprintf(outf, "cpu%d: MSR_MC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-MC6-Demotion)\n", |
| 4135 | base_cpu, msr, msr & (1 << 0) ? "EN" : "DIS"); |
| 4136 | } |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4137 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 4138 | void process_cpuid() |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4139 | { |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 4140 | unsigned int eax, ebx, ecx, edx, max_level, max_extended_level; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4141 | unsigned int fms, family, model, stepping; |
Len Brown | b3a34e9 | 2017-01-21 00:50:08 -0500 | [diff] [blame] | 4142 | unsigned int has_turbo; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4143 | |
| 4144 | eax = ebx = ecx = edx = 0; |
| 4145 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4146 | __cpuid(0, max_level, ebx, ecx, edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4147 | |
| 4148 | if (ebx == 0x756e6547 && edx == 0x49656e69 && ecx == 0x6c65746e) |
| 4149 | genuine_intel = 1; |
| 4150 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4151 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4152 | fprintf(outf, "CPUID(0): %.4s%.4s%.4s ", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4153 | (char *)&ebx, (char *)&edx, (char *)&ecx); |
| 4154 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4155 | __cpuid(1, fms, ebx, ecx, edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4156 | family = (fms >> 8) & 0xf; |
| 4157 | model = (fms >> 4) & 0xf; |
| 4158 | stepping = fms & 0xf; |
| 4159 | if (family == 6 || family == 0xf) |
| 4160 | model += ((fms >> 16) & 0xf) << 4; |
| 4161 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4162 | if (!quiet) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4163 | 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] | 4164 | max_level, family, model, stepping, family, model, stepping); |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 4165 | 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] | 4166 | ecx & (1 << 0) ? "SSE3" : "-", |
| 4167 | ecx & (1 << 3) ? "MONITOR" : "-", |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 4168 | ecx & (1 << 6) ? "SMX" : "-", |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4169 | ecx & (1 << 7) ? "EIST" : "-", |
| 4170 | ecx & (1 << 8) ? "TM2" : "-", |
| 4171 | edx & (1 << 4) ? "TSC" : "-", |
| 4172 | edx & (1 << 5) ? "MSR" : "-", |
| 4173 | edx & (1 << 22) ? "ACPI-TM" : "-", |
| 4174 | edx & (1 << 29) ? "TM" : "-"); |
| 4175 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4176 | |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4177 | if (!(edx & (1 << 5))) |
| 4178 | errx(1, "CPUID: no MSR"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4179 | |
| 4180 | /* |
| 4181 | * check max extended function levels of CPUID. |
| 4182 | * This is needed to check for invariant TSC. |
| 4183 | * This check is valid for both Intel and AMD. |
| 4184 | */ |
| 4185 | ebx = ecx = edx = 0; |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4186 | __cpuid(0x80000000, max_extended_level, ebx, ecx, edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4187 | |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 4188 | if (max_extended_level >= 0x80000007) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4189 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4190 | /* |
| 4191 | * Non-Stop TSC is advertised by CPUID.EAX=0x80000007: EDX.bit8 |
| 4192 | * this check is valid for both Intel and AMD |
| 4193 | */ |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4194 | __cpuid(0x80000007, eax, ebx, ecx, edx); |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4195 | has_invariant_tsc = edx & (1 << 8); |
| 4196 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4197 | |
| 4198 | /* |
| 4199 | * APERF/MPERF is advertised by CPUID.EAX=0x6: ECX.bit0 |
| 4200 | * this check is valid for both Intel and AMD |
| 4201 | */ |
| 4202 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4203 | __cpuid(0x6, eax, ebx, ecx, edx); |
Thomas Renninger | 8209e05 | 2011-01-21 15:11:19 +0100 | [diff] [blame] | 4204 | has_aperf = ecx & (1 << 0); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4205 | if (has_aperf) { |
| 4206 | BIC_PRESENT(BIC_Avg_MHz); |
| 4207 | BIC_PRESENT(BIC_Busy); |
| 4208 | BIC_PRESENT(BIC_Bzy_MHz); |
| 4209 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4210 | do_dts = eax & (1 << 0); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4211 | if (do_dts) |
| 4212 | BIC_PRESENT(BIC_CoreTmp); |
Len Brown | b3a34e9 | 2017-01-21 00:50:08 -0500 | [diff] [blame] | 4213 | has_turbo = eax & (1 << 1); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4214 | do_ptm = eax & (1 << 6); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4215 | if (do_ptm) |
| 4216 | BIC_PRESENT(BIC_PkgTmp); |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4217 | has_hwp = eax & (1 << 7); |
| 4218 | has_hwp_notify = eax & (1 << 8); |
| 4219 | has_hwp_activity_window = eax & (1 << 9); |
| 4220 | has_hwp_epp = eax & (1 << 10); |
| 4221 | has_hwp_pkg = eax & (1 << 11); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4222 | has_epb = ecx & (1 << 3); |
| 4223 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4224 | if (!quiet) |
Len Brown | b3a34e9 | 2017-01-21 00:50:08 -0500 | [diff] [blame] | 4225 | fprintf(outf, "CPUID(6): %sAPERF, %sTURBO, %sDTS, %sPTM, %sHWP, " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4226 | "%sHWPnotify, %sHWPwindow, %sHWPepp, %sHWPpkg, %sEPB\n", |
| 4227 | has_aperf ? "" : "No-", |
Len Brown | b3a34e9 | 2017-01-21 00:50:08 -0500 | [diff] [blame] | 4228 | has_turbo ? "" : "No-", |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4229 | do_dts ? "" : "No-", |
| 4230 | do_ptm ? "" : "No-", |
| 4231 | has_hwp ? "" : "No-", |
| 4232 | has_hwp_notify ? "" : "No-", |
| 4233 | has_hwp_activity_window ? "" : "No-", |
| 4234 | has_hwp_epp ? "" : "No-", |
| 4235 | has_hwp_pkg ? "" : "No-", |
| 4236 | has_epb ? "" : "No-"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4237 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4238 | if (!quiet) |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4239 | decode_misc_enable_msr(); |
| 4240 | |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 4241 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4242 | if (max_level >= 0x7 && !quiet) { |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 4243 | int has_sgx; |
| 4244 | |
| 4245 | ecx = 0; |
| 4246 | |
| 4247 | __cpuid_count(0x7, 0, eax, ebx, ecx, edx); |
| 4248 | |
| 4249 | has_sgx = ebx & (1 << 2); |
| 4250 | fprintf(outf, "CPUID(7): %sSGX\n", has_sgx ? "" : "No-"); |
| 4251 | |
| 4252 | if (has_sgx) |
| 4253 | decode_feature_control_msr(); |
| 4254 | } |
| 4255 | |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 4256 | if (max_level >= 0x15) { |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4257 | unsigned int eax_crystal; |
| 4258 | unsigned int ebx_tsc; |
| 4259 | |
| 4260 | /* |
| 4261 | * CPUID 15H TSC/Crystal ratio, possibly Crystal Hz |
| 4262 | */ |
| 4263 | eax_crystal = ebx_tsc = crystal_hz = edx = 0; |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4264 | __cpuid(0x15, eax_crystal, ebx_tsc, crystal_hz, edx); |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4265 | |
| 4266 | if (ebx_tsc != 0) { |
| 4267 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4268 | if (!quiet && (ebx != 0)) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4269 | 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] | 4270 | eax_crystal, ebx_tsc, crystal_hz); |
| 4271 | |
| 4272 | if (crystal_hz == 0) |
| 4273 | switch(model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4274 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 4275 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 4276 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 4277 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Len Brown | e8efbc8 | 2016-04-06 17:15:57 -0400 | [diff] [blame] | 4278 | crystal_hz = 24000000; /* 24.0 MHz */ |
| 4279 | break; |
Len Brown | 7268d40 | 2016-12-01 23:10:39 -0500 | [diff] [blame] | 4280 | case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ |
Len Brown | ec53e59 | 2016-04-06 17:15:58 -0400 | [diff] [blame] | 4281 | crystal_hz = 25000000; /* 25.0 MHz */ |
| 4282 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4283 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | ac01ac1 | 2017-01-27 01:45:35 -0500 | [diff] [blame] | 4284 | case INTEL_FAM6_ATOM_GEMINI_LAKE: |
Len Brown | e8efbc8 | 2016-04-06 17:15:57 -0400 | [diff] [blame] | 4285 | crystal_hz = 19200000; /* 19.2 MHz */ |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4286 | break; |
| 4287 | default: |
| 4288 | crystal_hz = 0; |
| 4289 | } |
| 4290 | |
| 4291 | if (crystal_hz) { |
| 4292 | tsc_hz = (unsigned long long) crystal_hz * ebx_tsc / eax_crystal; |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4293 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4294 | fprintf(outf, "TSC: %lld MHz (%d Hz * %d / %d / 1000000)\n", |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4295 | tsc_hz / 1000000, crystal_hz, ebx_tsc, eax_crystal); |
| 4296 | } |
| 4297 | } |
| 4298 | } |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 4299 | if (max_level >= 0x16) { |
| 4300 | unsigned int base_mhz, max_mhz, bus_mhz, edx; |
| 4301 | |
| 4302 | /* |
| 4303 | * CPUID 16H Base MHz, Max MHz, Bus MHz |
| 4304 | */ |
| 4305 | base_mhz = max_mhz = bus_mhz = edx = 0; |
| 4306 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4307 | __cpuid(0x16, base_mhz, max_mhz, bus_mhz, edx); |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4308 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4309 | 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] | 4310 | base_mhz, max_mhz, bus_mhz); |
| 4311 | } |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4312 | |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 4313 | if (has_aperf) |
| 4314 | aperf_mperf_multiplier = get_aperf_mperf_multiplier(family, model); |
| 4315 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4316 | BIC_PRESENT(BIC_IRQ); |
| 4317 | BIC_PRESENT(BIC_TSC_MHz); |
| 4318 | |
| 4319 | if (probe_nhm_msrs(family, model)) { |
| 4320 | do_nhm_platform_info = 1; |
| 4321 | BIC_PRESENT(BIC_CPU_c1); |
| 4322 | BIC_PRESENT(BIC_CPU_c3); |
| 4323 | BIC_PRESENT(BIC_CPU_c6); |
| 4324 | BIC_PRESENT(BIC_SMI); |
| 4325 | } |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4326 | do_snb_cstates = has_snb_msrs(family, model); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4327 | |
| 4328 | if (do_snb_cstates) |
| 4329 | BIC_PRESENT(BIC_CPU_c7); |
| 4330 | |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 4331 | do_irtl_snb = has_snb_msrs(family, model); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4332 | if (do_snb_cstates && (pkg_cstate_limit >= PCL__2)) |
| 4333 | BIC_PRESENT(BIC_Pkgpc2); |
| 4334 | if (pkg_cstate_limit >= PCL__3) |
| 4335 | BIC_PRESENT(BIC_Pkgpc3); |
| 4336 | if (pkg_cstate_limit >= PCL__6) |
| 4337 | BIC_PRESENT(BIC_Pkgpc6); |
| 4338 | if (do_snb_cstates && (pkg_cstate_limit >= PCL__7)) |
| 4339 | BIC_PRESENT(BIC_Pkgpc7); |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 4340 | if (has_slv_msrs(family, model)) { |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4341 | BIC_NOT_PRESENT(BIC_Pkgpc2); |
| 4342 | BIC_NOT_PRESENT(BIC_Pkgpc3); |
| 4343 | BIC_PRESENT(BIC_Pkgpc6); |
| 4344 | BIC_NOT_PRESENT(BIC_Pkgpc7); |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 4345 | BIC_PRESENT(BIC_Mod_c6); |
| 4346 | use_c1_residency_msr = 1; |
| 4347 | } |
Len Brown | 7170a37 | 2017-01-27 02:13:27 -0500 | [diff] [blame] | 4348 | if (is_dnv(family, model)) { |
| 4349 | BIC_PRESENT(BIC_CPU_c1); |
| 4350 | BIC_NOT_PRESENT(BIC_CPU_c3); |
| 4351 | BIC_NOT_PRESENT(BIC_Pkgpc3); |
| 4352 | BIC_NOT_PRESENT(BIC_CPU_c7); |
| 4353 | BIC_NOT_PRESENT(BIC_Pkgpc7); |
| 4354 | use_c1_residency_msr = 1; |
| 4355 | } |
Len Brown | 34c76197 | 2017-01-27 02:36:41 -0500 | [diff] [blame] | 4356 | if (is_skx(family, model)) { |
| 4357 | BIC_NOT_PRESENT(BIC_CPU_c3); |
| 4358 | BIC_NOT_PRESENT(BIC_Pkgpc3); |
| 4359 | BIC_NOT_PRESENT(BIC_CPU_c7); |
| 4360 | BIC_NOT_PRESENT(BIC_Pkgpc7); |
| 4361 | } |
Len Brown | ade0eba | 2017-02-10 01:56:47 -0500 | [diff] [blame] | 4362 | if (is_bdx(family, model)) { |
| 4363 | BIC_NOT_PRESENT(BIC_CPU_c7); |
| 4364 | BIC_NOT_PRESENT(BIC_Pkgpc7); |
| 4365 | } |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4366 | if (has_hsw_msrs(family, model)) { |
| 4367 | BIC_PRESENT(BIC_Pkgpc8); |
| 4368 | BIC_PRESENT(BIC_Pkgpc9); |
| 4369 | BIC_PRESENT(BIC_Pkgpc10); |
| 4370 | } |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 4371 | do_irtl_hsw = has_hsw_msrs(family, model); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 4372 | if (has_skl_msrs(family, model)) { |
| 4373 | BIC_PRESENT(BIC_Totl_c0); |
| 4374 | BIC_PRESENT(BIC_Any_c0); |
| 4375 | BIC_PRESENT(BIC_GFX_c0); |
| 4376 | BIC_PRESENT(BIC_CPUGFX); |
| 4377 | } |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4378 | do_slm_cstates = is_slm(family, model); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 4379 | do_knl_cstates = is_knl(family, model); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4380 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4381 | if (!quiet) |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 4382 | decode_misc_pwr_mgmt_msr(); |
| 4383 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4384 | if (!quiet && has_slv_msrs(family, model)) |
Len Brown | 71616c8 | 2017-01-07 22:37:48 -0500 | [diff] [blame] | 4385 | decode_c6_demotion_policy_msr(); |
| 4386 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4387 | rapl_probe(family, model); |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 4388 | perf_limit_reasons_probe(family, model); |
Artem Bityutskiy | ac980e1 | 2017-09-05 15:14:08 +0300 | [diff] [blame^] | 4389 | automatic_cstate_conversion_probe(family, model); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4390 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4391 | if (!quiet) |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 4392 | dump_cstate_pstate_config_info(family, model); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 4393 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4394 | if (!quiet) |
| 4395 | dump_sysfs_cstate_config(); |
Len Brown | 7293fcc | 2017-02-22 00:11:12 -0500 | [diff] [blame] | 4396 | if (!quiet) |
| 4397 | dump_sysfs_pstate_config(); |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4398 | |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 4399 | if (has_skl_msrs(family, model)) |
| 4400 | calculate_tsc_tweak(); |
| 4401 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4402 | if (!access("/sys/class/drm/card0/power/rc6_residency_ms", R_OK)) |
| 4403 | BIC_PRESENT(BIC_GFX_rc6); |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 4404 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4405 | if (!access("/sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz", R_OK)) |
| 4406 | BIC_PRESENT(BIC_GFXMHz); |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 4407 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4408 | if (!quiet) |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 4409 | decode_misc_feature_control(); |
| 4410 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4411 | return; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4412 | } |
| 4413 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4414 | |
| 4415 | /* |
| 4416 | * in /dev/cpu/ return success for names that are numbers |
| 4417 | * ie. filter out ".", "..", "microcode". |
| 4418 | */ |
| 4419 | int dir_filter(const struct dirent *dirp) |
| 4420 | { |
| 4421 | if (isdigit(dirp->d_name[0])) |
| 4422 | return 1; |
| 4423 | else |
| 4424 | return 0; |
| 4425 | } |
| 4426 | |
| 4427 | int open_dev_cpu_msr(int dummy1) |
| 4428 | { |
| 4429 | return 0; |
| 4430 | } |
| 4431 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4432 | void topology_probe() |
| 4433 | { |
| 4434 | int i; |
| 4435 | int max_core_id = 0; |
| 4436 | int max_package_id = 0; |
| 4437 | int max_siblings = 0; |
| 4438 | struct cpu_topology { |
| 4439 | int core_id; |
| 4440 | int physical_package_id; |
| 4441 | } *cpus; |
| 4442 | |
| 4443 | /* Initialize num_cpus, max_cpu_num */ |
| 4444 | topo.num_cpus = 0; |
| 4445 | topo.max_cpu_num = 0; |
| 4446 | for_all_proc_cpus(count_cpus); |
| 4447 | if (!summary_only && topo.num_cpus > 1) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4448 | BIC_PRESENT(BIC_CPU); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4449 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4450 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4451 | 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] | 4452 | |
| 4453 | cpus = calloc(1, (topo.max_cpu_num + 1) * sizeof(struct cpu_topology)); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4454 | if (cpus == NULL) |
| 4455 | err(1, "calloc cpus"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4456 | |
| 4457 | /* |
| 4458 | * Allocate and initialize cpu_present_set |
| 4459 | */ |
| 4460 | cpu_present_set = CPU_ALLOC((topo.max_cpu_num + 1)); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4461 | if (cpu_present_set == NULL) |
| 4462 | err(3, "CPU_ALLOC"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4463 | cpu_present_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); |
| 4464 | CPU_ZERO_S(cpu_present_setsize, cpu_present_set); |
| 4465 | for_all_proc_cpus(mark_cpu_present); |
| 4466 | |
| 4467 | /* |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 4468 | * Validate that all cpus in cpu_subset are also in cpu_present_set |
| 4469 | */ |
| 4470 | for (i = 0; i < CPU_SUBSET_MAXCPUS; ++i) { |
| 4471 | if (CPU_ISSET_S(i, cpu_subset_size, cpu_subset)) |
| 4472 | if (!CPU_ISSET_S(i, cpu_present_setsize, cpu_present_set)) |
| 4473 | err(1, "cpu%d not present", i); |
| 4474 | } |
| 4475 | |
| 4476 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4477 | * Allocate and initialize cpu_affinity_set |
| 4478 | */ |
| 4479 | cpu_affinity_set = CPU_ALLOC((topo.max_cpu_num + 1)); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4480 | if (cpu_affinity_set == NULL) |
| 4481 | err(3, "CPU_ALLOC"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4482 | cpu_affinity_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); |
| 4483 | CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); |
| 4484 | |
| 4485 | |
| 4486 | /* |
| 4487 | * For online cpus |
| 4488 | * find max_core_id, max_package_id |
| 4489 | */ |
| 4490 | for (i = 0; i <= topo.max_cpu_num; ++i) { |
| 4491 | int siblings; |
| 4492 | |
| 4493 | if (cpu_is_not_present(i)) { |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4494 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4495 | fprintf(outf, "cpu%d NOT PRESENT\n", i); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4496 | continue; |
| 4497 | } |
| 4498 | cpus[i].core_id = get_core_id(i); |
| 4499 | if (cpus[i].core_id > max_core_id) |
| 4500 | max_core_id = cpus[i].core_id; |
| 4501 | |
| 4502 | cpus[i].physical_package_id = get_physical_package_id(i); |
| 4503 | if (cpus[i].physical_package_id > max_package_id) |
| 4504 | max_package_id = cpus[i].physical_package_id; |
| 4505 | |
| 4506 | siblings = get_num_ht_siblings(i); |
| 4507 | if (siblings > max_siblings) |
| 4508 | max_siblings = siblings; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4509 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4510 | fprintf(outf, "cpu %d pkg %d core %d\n", |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4511 | i, cpus[i].physical_package_id, cpus[i].core_id); |
| 4512 | } |
| 4513 | topo.num_cores_per_pkg = max_core_id + 1; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4514 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4515 | 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] | 4516 | max_core_id, topo.num_cores_per_pkg); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4517 | if (!summary_only && topo.num_cores_per_pkg > 1) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4518 | BIC_PRESENT(BIC_Core); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4519 | |
| 4520 | topo.num_packages = max_package_id + 1; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4521 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4522 | fprintf(outf, "max_package_id %d, sizing for %d packages\n", |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4523 | max_package_id, topo.num_packages); |
Len Brown | 7da6e3e | 2017-02-21 23:43:41 -0500 | [diff] [blame] | 4524 | if (!summary_only && topo.num_packages > 1) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4525 | BIC_PRESENT(BIC_Package); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4526 | |
| 4527 | topo.num_threads_per_core = max_siblings; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4528 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4529 | fprintf(outf, "max_siblings %d\n", max_siblings); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4530 | |
| 4531 | free(cpus); |
| 4532 | } |
| 4533 | |
| 4534 | void |
| 4535 | allocate_counters(struct thread_data **t, struct core_data **c, struct pkg_data **p) |
| 4536 | { |
| 4537 | int i; |
| 4538 | |
| 4539 | *t = calloc(topo.num_threads_per_core * topo.num_cores_per_pkg * |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4540 | topo.num_packages, sizeof(struct thread_data)); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4541 | if (*t == NULL) |
| 4542 | goto error; |
| 4543 | |
| 4544 | for (i = 0; i < topo.num_threads_per_core * |
| 4545 | topo.num_cores_per_pkg * topo.num_packages; i++) |
| 4546 | (*t)[i].cpu_id = -1; |
| 4547 | |
| 4548 | *c = calloc(topo.num_cores_per_pkg * topo.num_packages, |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4549 | sizeof(struct core_data)); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4550 | if (*c == NULL) |
| 4551 | goto error; |
| 4552 | |
| 4553 | for (i = 0; i < topo.num_cores_per_pkg * topo.num_packages; i++) |
| 4554 | (*c)[i].core_id = -1; |
| 4555 | |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4556 | *p = calloc(topo.num_packages, sizeof(struct pkg_data)); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4557 | if (*p == NULL) |
| 4558 | goto error; |
| 4559 | |
| 4560 | for (i = 0; i < topo.num_packages; i++) |
| 4561 | (*p)[i].package_id = i; |
| 4562 | |
| 4563 | return; |
| 4564 | error: |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4565 | err(1, "calloc counters"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4566 | } |
| 4567 | /* |
| 4568 | * init_counter() |
| 4569 | * |
| 4570 | * set cpu_id, core_num, pkg_num |
| 4571 | * set FIRST_THREAD_IN_CORE and FIRST_CORE_IN_PACKAGE |
| 4572 | * |
| 4573 | * increment topo.num_cores when 1st core in pkg seen |
| 4574 | */ |
| 4575 | void init_counter(struct thread_data *thread_base, struct core_data *core_base, |
| 4576 | struct pkg_data *pkg_base, int thread_num, int core_num, |
| 4577 | int pkg_num, int cpu_id) |
| 4578 | { |
| 4579 | struct thread_data *t; |
| 4580 | struct core_data *c; |
| 4581 | struct pkg_data *p; |
| 4582 | |
| 4583 | t = GET_THREAD(thread_base, thread_num, core_num, pkg_num); |
| 4584 | c = GET_CORE(core_base, core_num, pkg_num); |
| 4585 | p = GET_PKG(pkg_base, pkg_num); |
| 4586 | |
| 4587 | t->cpu_id = cpu_id; |
| 4588 | if (thread_num == 0) { |
| 4589 | t->flags |= CPU_IS_FIRST_THREAD_IN_CORE; |
| 4590 | if (cpu_is_first_core_in_package(cpu_id)) |
| 4591 | t->flags |= CPU_IS_FIRST_CORE_IN_PACKAGE; |
| 4592 | } |
| 4593 | |
| 4594 | c->core_id = core_num; |
| 4595 | p->package_id = pkg_num; |
| 4596 | } |
| 4597 | |
| 4598 | |
| 4599 | int initialize_counters(int cpu_id) |
| 4600 | { |
| 4601 | int my_thread_id, my_core_id, my_package_id; |
| 4602 | |
| 4603 | my_package_id = get_physical_package_id(cpu_id); |
| 4604 | my_core_id = get_core_id(cpu_id); |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 4605 | my_thread_id = get_cpu_position_in_core(cpu_id); |
| 4606 | if (!my_thread_id) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4607 | topo.num_cores++; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4608 | |
| 4609 | init_counter(EVEN_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id); |
| 4610 | init_counter(ODD_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id); |
| 4611 | return 0; |
| 4612 | } |
| 4613 | |
| 4614 | void allocate_output_buffer() |
| 4615 | { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4616 | output_buffer = calloc(1, (1 + topo.num_cpus) * 1024); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4617 | outp = output_buffer; |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4618 | if (outp == NULL) |
| 4619 | err(-1, "calloc output buffer"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4620 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 4621 | void allocate_fd_percpu(void) |
| 4622 | { |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 4623 | fd_percpu = calloc(topo.max_cpu_num + 1, sizeof(int)); |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 4624 | if (fd_percpu == NULL) |
| 4625 | err(-1, "calloc fd_percpu"); |
| 4626 | } |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 4627 | void allocate_irq_buffers(void) |
| 4628 | { |
| 4629 | irq_column_2_cpu = calloc(topo.num_cpus, sizeof(int)); |
| 4630 | if (irq_column_2_cpu == NULL) |
| 4631 | err(-1, "calloc %d", topo.num_cpus); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4632 | |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 4633 | irqs_per_cpu = calloc(topo.max_cpu_num + 1, sizeof(int)); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 4634 | if (irqs_per_cpu == NULL) |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 4635 | err(-1, "calloc %d", topo.max_cpu_num + 1); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 4636 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4637 | void setup_all_buffers(void) |
| 4638 | { |
| 4639 | topology_probe(); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 4640 | allocate_irq_buffers(); |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 4641 | allocate_fd_percpu(); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4642 | allocate_counters(&thread_even, &core_even, &package_even); |
| 4643 | allocate_counters(&thread_odd, &core_odd, &package_odd); |
| 4644 | allocate_output_buffer(); |
| 4645 | for_all_proc_cpus(initialize_counters); |
| 4646 | } |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4647 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 4648 | void set_base_cpu(void) |
| 4649 | { |
| 4650 | base_cpu = sched_getcpu(); |
| 4651 | if (base_cpu < 0) |
| 4652 | err(-ENODEV, "No valid cpus found"); |
| 4653 | |
| 4654 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4655 | fprintf(outf, "base_cpu = %d\n", base_cpu); |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 4656 | } |
| 4657 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4658 | void turbostat_init() |
| 4659 | { |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 4660 | setup_all_buffers(); |
| 4661 | set_base_cpu(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4662 | check_dev_msr(); |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 4663 | check_permissions(); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 4664 | process_cpuid(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4665 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4666 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4667 | if (!quiet) |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4668 | for_all_cpus(print_hwp, ODD_COUNTERS); |
| 4669 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4670 | if (!quiet) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4671 | for_all_cpus(print_epb, ODD_COUNTERS); |
| 4672 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4673 | if (!quiet) |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 4674 | for_all_cpus(print_perf_limit, ODD_COUNTERS); |
| 4675 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4676 | if (!quiet) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4677 | for_all_cpus(print_rapl, ODD_COUNTERS); |
| 4678 | |
| 4679 | for_all_cpus(set_temperature_target, ODD_COUNTERS); |
| 4680 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4681 | if (!quiet) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4682 | for_all_cpus(print_thermal, ODD_COUNTERS); |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 4683 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4684 | if (!quiet && do_irtl_snb) |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 4685 | print_irtl(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4686 | } |
| 4687 | |
| 4688 | int fork_it(char **argv) |
| 4689 | { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4690 | pid_t child_pid; |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 4691 | int status; |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 4692 | |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 4693 | snapshot_proc_sysfs_files(); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 4694 | status = for_all_cpus(get_counters, EVEN_COUNTERS); |
| 4695 | if (status) |
| 4696 | exit(status); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4697 | /* clear affinity side-effect of get_counters() */ |
| 4698 | sched_setaffinity(0, cpu_present_setsize, cpu_present_set); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4699 | gettimeofday(&tv_even, (struct timezone *)NULL); |
| 4700 | |
| 4701 | child_pid = fork(); |
| 4702 | if (!child_pid) { |
| 4703 | /* child */ |
| 4704 | execvp(argv[0], argv); |
Len Brown | 0815a3d | 2017-02-23 17:00:51 -0500 | [diff] [blame] | 4705 | err(errno, "exec %s", argv[0]); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4706 | } else { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4707 | |
| 4708 | /* parent */ |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4709 | if (child_pid == -1) |
| 4710 | err(1, "fork"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4711 | |
| 4712 | signal(SIGINT, SIG_IGN); |
| 4713 | signal(SIGQUIT, SIG_IGN); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4714 | if (waitpid(child_pid, &status, 0) == -1) |
| 4715 | err(status, "waitpid"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4716 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4717 | /* |
| 4718 | * n.b. fork_it() does not check for errors from for_all_cpus() |
| 4719 | * because re-starting is problematic when forking |
| 4720 | */ |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 4721 | snapshot_proc_sysfs_files(); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4722 | for_all_cpus(get_counters, ODD_COUNTERS); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4723 | gettimeofday(&tv_odd, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4724 | timersub(&tv_odd, &tv_even, &tv_delta); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 4725 | if (for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS)) |
| 4726 | fprintf(outf, "%s: Counter reset detected\n", progname); |
| 4727 | else { |
| 4728 | compute_average(EVEN_COUNTERS); |
| 4729 | format_all_counters(EVEN_COUNTERS); |
| 4730 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4731 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4732 | fprintf(outf, "%.6f sec\n", tv_delta.tv_sec + tv_delta.tv_usec/1000000.0); |
| 4733 | |
| 4734 | flush_output_stderr(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4735 | |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 4736 | return status; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4737 | } |
| 4738 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4739 | int get_and_dump_counters(void) |
| 4740 | { |
| 4741 | int status; |
| 4742 | |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 4743 | snapshot_proc_sysfs_files(); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4744 | status = for_all_cpus(get_counters, ODD_COUNTERS); |
| 4745 | if (status) |
| 4746 | return status; |
| 4747 | |
| 4748 | status = for_all_cpus(dump_counters, ODD_COUNTERS); |
| 4749 | if (status) |
| 4750 | return status; |
| 4751 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4752 | flush_output_stdout(); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4753 | |
| 4754 | return status; |
| 4755 | } |
| 4756 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4757 | void print_version() { |
Len Brown | f7d44a8 | 2017-05-27 21:24:58 -0700 | [diff] [blame] | 4758 | fprintf(outf, "turbostat version 17.06.23" |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4759 | " - Len Brown <lenb@kernel.org>\n"); |
| 4760 | } |
| 4761 | |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 4762 | int add_counter(unsigned int msr_num, char *path, char *name, |
| 4763 | unsigned int width, enum counter_scope scope, |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4764 | enum counter_type type, enum counter_format format, int flags) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4765 | { |
| 4766 | struct msr_counter *msrp; |
| 4767 | |
| 4768 | msrp = calloc(1, sizeof(struct msr_counter)); |
| 4769 | if (msrp == NULL) { |
| 4770 | perror("calloc"); |
| 4771 | exit(1); |
| 4772 | } |
| 4773 | |
| 4774 | msrp->msr_num = msr_num; |
| 4775 | strncpy(msrp->name, name, NAME_BYTES); |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 4776 | if (path) |
| 4777 | strncpy(msrp->path, path, PATH_BYTES); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4778 | msrp->width = width; |
| 4779 | msrp->type = type; |
| 4780 | msrp->format = format; |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4781 | msrp->flags = flags; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4782 | |
| 4783 | switch (scope) { |
| 4784 | |
| 4785 | case SCOPE_CPU: |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4786 | msrp->next = sys.tp; |
| 4787 | sys.tp = msrp; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4788 | sys.added_thread_counters++; |
| 4789 | if (sys.added_thread_counters > MAX_ADDED_COUNTERS) { |
| 4790 | fprintf(stderr, "exceeded max %d added thread counters\n", |
| 4791 | MAX_ADDED_COUNTERS); |
| 4792 | exit(-1); |
| 4793 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4794 | break; |
| 4795 | |
| 4796 | case SCOPE_CORE: |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4797 | msrp->next = sys.cp; |
| 4798 | sys.cp = msrp; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4799 | sys.added_core_counters++; |
| 4800 | if (sys.added_core_counters > MAX_ADDED_COUNTERS) { |
| 4801 | fprintf(stderr, "exceeded max %d added core counters\n", |
| 4802 | MAX_ADDED_COUNTERS); |
| 4803 | exit(-1); |
| 4804 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4805 | break; |
| 4806 | |
| 4807 | case SCOPE_PACKAGE: |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4808 | msrp->next = sys.pp; |
| 4809 | sys.pp = msrp; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4810 | sys.added_package_counters++; |
| 4811 | if (sys.added_package_counters > MAX_ADDED_COUNTERS) { |
| 4812 | fprintf(stderr, "exceeded max %d added package counters\n", |
| 4813 | MAX_ADDED_COUNTERS); |
| 4814 | exit(-1); |
| 4815 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4816 | break; |
| 4817 | } |
| 4818 | |
| 4819 | return 0; |
| 4820 | } |
| 4821 | |
| 4822 | void parse_add_command(char *add_command) |
| 4823 | { |
| 4824 | int msr_num = 0; |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 4825 | char *path = NULL; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4826 | char name_buffer[NAME_BYTES] = ""; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4827 | int width = 64; |
| 4828 | int fail = 0; |
| 4829 | enum counter_scope scope = SCOPE_CPU; |
| 4830 | enum counter_type type = COUNTER_CYCLES; |
| 4831 | enum counter_format format = FORMAT_DELTA; |
| 4832 | |
| 4833 | while (add_command) { |
| 4834 | |
| 4835 | if (sscanf(add_command, "msr0x%x", &msr_num) == 1) |
| 4836 | goto next; |
| 4837 | |
| 4838 | if (sscanf(add_command, "msr%d", &msr_num) == 1) |
| 4839 | goto next; |
| 4840 | |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 4841 | if (*add_command == '/') { |
| 4842 | path = add_command; |
| 4843 | goto next; |
| 4844 | } |
| 4845 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4846 | if (sscanf(add_command, "u%d", &width) == 1) { |
| 4847 | if ((width == 32) || (width == 64)) |
| 4848 | goto next; |
| 4849 | width = 64; |
| 4850 | } |
| 4851 | if (!strncmp(add_command, "cpu", strlen("cpu"))) { |
| 4852 | scope = SCOPE_CPU; |
| 4853 | goto next; |
| 4854 | } |
| 4855 | if (!strncmp(add_command, "core", strlen("core"))) { |
| 4856 | scope = SCOPE_CORE; |
| 4857 | goto next; |
| 4858 | } |
| 4859 | if (!strncmp(add_command, "package", strlen("package"))) { |
| 4860 | scope = SCOPE_PACKAGE; |
| 4861 | goto next; |
| 4862 | } |
| 4863 | if (!strncmp(add_command, "cycles", strlen("cycles"))) { |
| 4864 | type = COUNTER_CYCLES; |
| 4865 | goto next; |
| 4866 | } |
| 4867 | if (!strncmp(add_command, "seconds", strlen("seconds"))) { |
| 4868 | type = COUNTER_SECONDS; |
| 4869 | goto next; |
| 4870 | } |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4871 | if (!strncmp(add_command, "usec", strlen("usec"))) { |
| 4872 | type = COUNTER_USEC; |
| 4873 | goto next; |
| 4874 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4875 | if (!strncmp(add_command, "raw", strlen("raw"))) { |
| 4876 | format = FORMAT_RAW; |
| 4877 | goto next; |
| 4878 | } |
| 4879 | if (!strncmp(add_command, "delta", strlen("delta"))) { |
| 4880 | format = FORMAT_DELTA; |
| 4881 | goto next; |
| 4882 | } |
| 4883 | if (!strncmp(add_command, "percent", strlen("percent"))) { |
| 4884 | format = FORMAT_PERCENT; |
| 4885 | goto next; |
| 4886 | } |
| 4887 | |
| 4888 | if (sscanf(add_command, "%18s,%*s", name_buffer) == 1) { /* 18 < NAME_BYTES */ |
| 4889 | char *eos; |
| 4890 | |
| 4891 | eos = strchr(name_buffer, ','); |
| 4892 | if (eos) |
| 4893 | *eos = '\0'; |
| 4894 | goto next; |
| 4895 | } |
| 4896 | |
| 4897 | next: |
| 4898 | add_command = strchr(add_command, ','); |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 4899 | if (add_command) { |
| 4900 | *add_command = '\0'; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4901 | add_command++; |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 4902 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4903 | |
| 4904 | } |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 4905 | if ((msr_num == 0) && (path == NULL)) { |
| 4906 | fprintf(stderr, "--add: (msrDDD | msr0xXXX | /path_to_counter ) required\n"); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4907 | fail++; |
| 4908 | } |
| 4909 | |
| 4910 | /* generate default column header */ |
| 4911 | if (*name_buffer == '\0') { |
Len Brown | 5f3aea5 | 2017-02-23 18:10:27 -0500 | [diff] [blame] | 4912 | if (width == 32) |
| 4913 | sprintf(name_buffer, "M0x%x%s", msr_num, format == FORMAT_PERCENT ? "%" : ""); |
| 4914 | else |
| 4915 | sprintf(name_buffer, "M0X%x%s", msr_num, format == FORMAT_PERCENT ? "%" : ""); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4916 | } |
| 4917 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4918 | if (add_counter(msr_num, path, name_buffer, width, scope, type, format, 0)) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4919 | fail++; |
| 4920 | |
| 4921 | if (fail) { |
| 4922 | help(); |
| 4923 | exit(1); |
| 4924 | } |
| 4925 | } |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4926 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 4927 | int is_deferred_skip(char *name) |
| 4928 | { |
| 4929 | int i; |
| 4930 | |
| 4931 | for (i = 0; i < deferred_skip_index; ++i) |
| 4932 | if (!strcmp(name, deferred_skip_names[i])) |
| 4933 | return 1; |
| 4934 | return 0; |
| 4935 | } |
| 4936 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4937 | void probe_sysfs(void) |
| 4938 | { |
| 4939 | char path[64]; |
| 4940 | char name_buf[16]; |
| 4941 | FILE *input; |
| 4942 | int state; |
| 4943 | char *sp; |
| 4944 | |
| 4945 | if (!DO_BIC(BIC_sysfs)) |
| 4946 | return; |
| 4947 | |
| 4948 | for (state = 10; state > 0; --state) { |
| 4949 | |
| 4950 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", |
| 4951 | base_cpu, state); |
| 4952 | input = fopen(path, "r"); |
| 4953 | if (input == NULL) |
| 4954 | continue; |
| 4955 | fgets(name_buf, sizeof(name_buf), input); |
| 4956 | |
| 4957 | /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ |
| 4958 | sp = strchr(name_buf, '-'); |
| 4959 | if (!sp) |
| 4960 | sp = strchrnul(name_buf, '\n'); |
| 4961 | *sp = '%'; |
| 4962 | *(sp + 1) = '\0'; |
| 4963 | |
| 4964 | fclose(input); |
| 4965 | |
| 4966 | sprintf(path, "cpuidle/state%d/time", state); |
| 4967 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 4968 | if (is_deferred_skip(name_buf)) |
| 4969 | continue; |
| 4970 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4971 | add_counter(0, path, name_buf, 64, SCOPE_CPU, COUNTER_USEC, |
| 4972 | FORMAT_PERCENT, SYSFS_PERCPU); |
| 4973 | } |
| 4974 | |
| 4975 | for (state = 10; state > 0; --state) { |
| 4976 | |
| 4977 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", |
| 4978 | base_cpu, state); |
| 4979 | input = fopen(path, "r"); |
| 4980 | if (input == NULL) |
| 4981 | continue; |
| 4982 | fgets(name_buf, sizeof(name_buf), input); |
| 4983 | /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ |
| 4984 | sp = strchr(name_buf, '-'); |
| 4985 | if (!sp) |
| 4986 | sp = strchrnul(name_buf, '\n'); |
| 4987 | *sp = '\0'; |
| 4988 | fclose(input); |
| 4989 | |
| 4990 | sprintf(path, "cpuidle/state%d/usage", state); |
| 4991 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 4992 | if (is_deferred_skip(name_buf)) |
| 4993 | continue; |
| 4994 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4995 | add_counter(0, path, name_buf, 64, SCOPE_CPU, COUNTER_ITEMS, |
| 4996 | FORMAT_DELTA, SYSFS_PERCPU); |
| 4997 | } |
| 4998 | |
| 4999 | } |
| 5000 | |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 5001 | |
| 5002 | /* |
| 5003 | * parse cpuset with following syntax |
| 5004 | * 1,2,4..6,8-10 and set bits in cpu_subset |
| 5005 | */ |
| 5006 | void parse_cpu_command(char *optarg) |
| 5007 | { |
| 5008 | unsigned int start, end; |
| 5009 | char *next; |
| 5010 | |
Len Brown | 4e4e1e7 | 2017-02-21 22:33:42 -0500 | [diff] [blame] | 5011 | if (!strcmp(optarg, "core")) { |
| 5012 | if (cpu_subset) |
| 5013 | goto error; |
| 5014 | show_core_only++; |
| 5015 | return; |
| 5016 | } |
| 5017 | if (!strcmp(optarg, "package")) { |
| 5018 | if (cpu_subset) |
| 5019 | goto error; |
| 5020 | show_pkg_only++; |
| 5021 | return; |
| 5022 | } |
| 5023 | if (show_core_only || show_pkg_only) |
| 5024 | goto error; |
| 5025 | |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 5026 | cpu_subset = CPU_ALLOC(CPU_SUBSET_MAXCPUS); |
| 5027 | if (cpu_subset == NULL) |
| 5028 | err(3, "CPU_ALLOC"); |
| 5029 | cpu_subset_size = CPU_ALLOC_SIZE(CPU_SUBSET_MAXCPUS); |
| 5030 | |
| 5031 | CPU_ZERO_S(cpu_subset_size, cpu_subset); |
| 5032 | |
| 5033 | next = optarg; |
| 5034 | |
| 5035 | while (next && *next) { |
| 5036 | |
| 5037 | if (*next == '-') /* no negative cpu numbers */ |
| 5038 | goto error; |
| 5039 | |
| 5040 | start = strtoul(next, &next, 10); |
| 5041 | |
| 5042 | if (start >= CPU_SUBSET_MAXCPUS) |
| 5043 | goto error; |
| 5044 | CPU_SET_S(start, cpu_subset_size, cpu_subset); |
| 5045 | |
| 5046 | if (*next == '\0') |
| 5047 | break; |
| 5048 | |
| 5049 | if (*next == ',') { |
| 5050 | next += 1; |
| 5051 | continue; |
| 5052 | } |
| 5053 | |
| 5054 | if (*next == '-') { |
| 5055 | next += 1; /* start range */ |
| 5056 | } else if (*next == '.') { |
| 5057 | next += 1; |
| 5058 | if (*next == '.') |
| 5059 | next += 1; /* start range */ |
| 5060 | else |
| 5061 | goto error; |
| 5062 | } |
| 5063 | |
| 5064 | end = strtoul(next, &next, 10); |
| 5065 | if (end <= start) |
| 5066 | goto error; |
| 5067 | |
| 5068 | while (++start <= end) { |
| 5069 | if (start >= CPU_SUBSET_MAXCPUS) |
| 5070 | goto error; |
| 5071 | CPU_SET_S(start, cpu_subset_size, cpu_subset); |
| 5072 | } |
| 5073 | |
| 5074 | if (*next == ',') |
| 5075 | next += 1; |
| 5076 | else if (*next != '\0') |
| 5077 | goto error; |
| 5078 | } |
| 5079 | |
| 5080 | return; |
| 5081 | |
| 5082 | error: |
Len Brown | 4e4e1e7 | 2017-02-21 22:33:42 -0500 | [diff] [blame] | 5083 | fprintf(stderr, "\"--cpu %s\" malformed\n", optarg); |
| 5084 | help(); |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 5085 | exit(-1); |
| 5086 | } |
| 5087 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5088 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5089 | void cmdline(int argc, char **argv) |
| 5090 | { |
| 5091 | int opt; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5092 | int option_index = 0; |
| 5093 | static struct option long_options[] = { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5094 | {"add", required_argument, 0, 'a'}, |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 5095 | {"cpu", required_argument, 0, 'c'}, |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5096 | {"Dump", no_argument, 0, 'D'}, |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5097 | {"debug", no_argument, 0, 'd'}, /* internal, not documented */ |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5098 | {"enable", required_argument, 0, 'e'}, |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5099 | {"interval", required_argument, 0, 'i'}, |
| 5100 | {"help", no_argument, 0, 'h'}, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5101 | {"hide", required_argument, 0, 'H'}, // meh, -h taken by --help |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5102 | {"Joules", no_argument, 0, 'J'}, |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 5103 | {"list", no_argument, 0, 'l'}, |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5104 | {"out", required_argument, 0, 'o'}, |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5105 | {"quiet", no_argument, 0, 'q'}, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5106 | {"show", required_argument, 0, 's'}, |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5107 | {"Summary", no_argument, 0, 'S'}, |
| 5108 | {"TCC", required_argument, 0, 'T'}, |
| 5109 | {"version", no_argument, 0, 'v' }, |
| 5110 | {0, 0, 0, 0 } |
| 5111 | }; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5112 | |
| 5113 | progname = argv[0]; |
| 5114 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5115 | while ((opt = getopt_long_only(argc, argv, "+C:c:Dde:hi:Jo:qST:v", |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5116 | long_options, &option_index)) != -1) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5117 | switch (opt) { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5118 | case 'a': |
| 5119 | parse_add_command(optarg); |
| 5120 | break; |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 5121 | case 'c': |
| 5122 | parse_cpu_command(optarg); |
| 5123 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5124 | case 'D': |
| 5125 | dump_only++; |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 5126 | break; |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5127 | case 'e': |
| 5128 | /* --enable specified counter */ |
| 5129 | bic_enabled |= bic_lookup(optarg, SHOW_LIST); |
| 5130 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5131 | case 'd': |
| 5132 | debug++; |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5133 | ENABLE_BIC(BIC_DISABLED_BY_DEFAULT); |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 5134 | break; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5135 | case 'H': |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5136 | /* |
| 5137 | * --hide: do not show those specified |
| 5138 | * multiple invocations simply clear more bits in enabled mask |
| 5139 | */ |
| 5140 | bic_enabled &= ~bic_lookup(optarg, HIDE_LIST); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5141 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5142 | case 'h': |
| 5143 | default: |
| 5144 | help(); |
| 5145 | exit(1); |
| 5146 | case 'i': |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 5147 | { |
| 5148 | double interval = strtod(optarg, NULL); |
| 5149 | |
| 5150 | if (interval < 0.001) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5151 | fprintf(outf, "interval %f seconds is too small\n", |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 5152 | interval); |
| 5153 | exit(2); |
| 5154 | } |
| 5155 | |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 5156 | interval_tv.tv_sec = interval_ts.tv_sec = interval; |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 5157 | interval_tv.tv_usec = (interval - interval_tv.tv_sec) * 1000000; |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 5158 | interval_ts.tv_nsec = (interval - interval_ts.tv_sec) * 1000000000; |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 5159 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 5160 | break; |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 5161 | case 'J': |
| 5162 | rapl_joules++; |
| 5163 | break; |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 5164 | case 'l': |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5165 | ENABLE_BIC(BIC_DISABLED_BY_DEFAULT); |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 5166 | list_header_only++; |
| 5167 | quiet++; |
| 5168 | break; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5169 | case 'o': |
| 5170 | outf = fopen_or_die(optarg, "w"); |
| 5171 | break; |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5172 | case 'q': |
| 5173 | quiet = 1; |
| 5174 | break; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5175 | case 's': |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5176 | /* |
| 5177 | * --show: show only those specified |
| 5178 | * The 1st invocation will clear and replace the enabled mask |
| 5179 | * subsequent invocations can add to it. |
| 5180 | */ |
| 5181 | if (shown == 0) |
| 5182 | bic_enabled = bic_lookup(optarg, SHOW_LIST); |
| 5183 | else |
| 5184 | bic_enabled |= bic_lookup(optarg, SHOW_LIST); |
| 5185 | shown = 1; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5186 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5187 | case 'S': |
| 5188 | summary_only++; |
| 5189 | break; |
| 5190 | case 'T': |
| 5191 | tcc_activation_temp_override = atoi(optarg); |
| 5192 | break; |
| 5193 | case 'v': |
| 5194 | print_version(); |
| 5195 | exit(0); |
| 5196 | break; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5197 | } |
| 5198 | } |
| 5199 | } |
| 5200 | |
| 5201 | int main(int argc, char **argv) |
| 5202 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5203 | outf = stderr; |
| 5204 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5205 | cmdline(argc, argv); |
| 5206 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5207 | if (!quiet) |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5208 | print_version(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5209 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5210 | probe_sysfs(); |
| 5211 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5212 | turbostat_init(); |
| 5213 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 5214 | /* dump counters and exit */ |
| 5215 | if (dump_only) |
| 5216 | return get_and_dump_counters(); |
| 5217 | |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 5218 | /* list header and exit */ |
| 5219 | if (list_header_only) { |
| 5220 | print_header(","); |
| 5221 | flush_output_stdout(); |
| 5222 | return 0; |
| 5223 | } |
| 5224 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5225 | /* |
| 5226 | * if any params left, it must be a command to fork |
| 5227 | */ |
| 5228 | if (argc - optind) |
| 5229 | return fork_it(argv + optind); |
| 5230 | else |
| 5231 | turbostat_loop(); |
| 5232 | |
| 5233 | return 0; |
| 5234 | } |