Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1 | /* |
| 2 | * turbostat -- show CPU frequency and C-state residency |
| 3 | * on modern Intel turbo-capable processors. |
| 4 | * |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 5 | * Copyright (c) 2013 Intel Corporation. |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 6 | * Len Brown <len.brown@intel.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms and conditions of the GNU General Public License, |
| 10 | * version 2, as published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | */ |
| 21 | |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 22 | #define _GNU_SOURCE |
Josh Triplett | b731f31 | 2013-08-20 17:20:12 -0700 | [diff] [blame] | 23 | #include MSRHEADER |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 24 | #include INTEL_FAMILY_HEADER |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 25 | #include <stdarg.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 26 | #include <stdio.h> |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 27 | #include <err.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 28 | #include <unistd.h> |
| 29 | #include <sys/types.h> |
| 30 | #include <sys/wait.h> |
| 31 | #include <sys/stat.h> |
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; |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame^] | 65 | unsigned int do_cnl_cstates; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 66 | unsigned int use_c1_residency_msr; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 67 | unsigned int has_aperf; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 68 | unsigned int has_epb; |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 69 | unsigned int do_irtl_snb; |
| 70 | unsigned int do_irtl_hsw; |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 71 | unsigned int units = 1000000; /* MHz etc */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 72 | unsigned int genuine_intel; |
| 73 | unsigned int has_invariant_tsc; |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 74 | unsigned int do_nhm_platform_info; |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 75 | unsigned int no_MSR_MISC_PWR_MGMT; |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 76 | unsigned int aperf_mperf_multiplier = 1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 77 | double bclk; |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 78 | double base_hz; |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 79 | unsigned int has_base_hz; |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 80 | double tsc_tweak = 1.0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 81 | unsigned int show_pkg_only; |
| 82 | unsigned int show_core_only; |
| 83 | char *output_buffer, *outp; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 84 | unsigned int do_rapl; |
| 85 | unsigned int do_dts; |
| 86 | unsigned int do_ptm; |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 87 | unsigned long long gfx_cur_rc6_ms; |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 88 | unsigned long long cpuidle_cur_cpu_lpi_us; |
| 89 | unsigned long long cpuidle_cur_sys_lpi_us; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 90 | unsigned int gfx_cur_mhz; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 91 | unsigned int tcc_activation_temp; |
| 92 | unsigned int tcc_activation_temp_override; |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 93 | double rapl_power_units, rapl_time_units; |
| 94 | double rapl_dram_energy_units, rapl_energy_units; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 95 | double rapl_joule_counter_range; |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 96 | unsigned int do_core_perf_limit_reasons; |
Artem Bityutskiy | ac980e1 | 2017-09-05 15:14:08 +0300 | [diff] [blame] | 97 | unsigned int has_automatic_cstate_conversion; |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 98 | unsigned int do_gfx_perf_limit_reasons; |
| 99 | unsigned int do_ring_perf_limit_reasons; |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 100 | unsigned int crystal_hz; |
| 101 | unsigned long long tsc_hz; |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 102 | int base_cpu; |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 103 | double discover_bclk(unsigned int family, unsigned int model); |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 104 | unsigned int has_hwp; /* IA32_PM_ENABLE, IA32_HWP_CAPABILITIES */ |
| 105 | /* IA32_HWP_REQUEST, IA32_HWP_STATUS */ |
| 106 | unsigned int has_hwp_notify; /* IA32_HWP_INTERRUPT */ |
| 107 | unsigned int has_hwp_activity_window; /* IA32_HWP_REQUEST[bits 41:32] */ |
| 108 | unsigned int has_hwp_epp; /* IA32_HWP_REQUEST[bits 31:24] */ |
| 109 | unsigned int has_hwp_pkg; /* IA32_HWP_REQUEST_PKG */ |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 110 | unsigned int has_misc_feature_control; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 111 | |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 112 | #define RAPL_PKG (1 << 0) |
| 113 | /* 0x610 MSR_PKG_POWER_LIMIT */ |
| 114 | /* 0x611 MSR_PKG_ENERGY_STATUS */ |
| 115 | #define RAPL_PKG_PERF_STATUS (1 << 1) |
| 116 | /* 0x613 MSR_PKG_PERF_STATUS */ |
| 117 | #define RAPL_PKG_POWER_INFO (1 << 2) |
| 118 | /* 0x614 MSR_PKG_POWER_INFO */ |
| 119 | |
| 120 | #define RAPL_DRAM (1 << 3) |
| 121 | /* 0x618 MSR_DRAM_POWER_LIMIT */ |
| 122 | /* 0x619 MSR_DRAM_ENERGY_STATUS */ |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 123 | #define RAPL_DRAM_PERF_STATUS (1 << 4) |
| 124 | /* 0x61b MSR_DRAM_PERF_STATUS */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 125 | #define RAPL_DRAM_POWER_INFO (1 << 5) |
| 126 | /* 0x61c MSR_DRAM_POWER_INFO */ |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 127 | |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 128 | #define RAPL_CORES_POWER_LIMIT (1 << 6) |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 129 | /* 0x638 MSR_PP0_POWER_LIMIT */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 130 | #define RAPL_CORE_POLICY (1 << 7) |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 131 | /* 0x63a MSR_PP0_POLICY */ |
| 132 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 133 | #define RAPL_GFX (1 << 8) |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 134 | /* 0x640 MSR_PP1_POWER_LIMIT */ |
| 135 | /* 0x641 MSR_PP1_ENERGY_STATUS */ |
| 136 | /* 0x642 MSR_PP1_POLICY */ |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 137 | |
| 138 | #define RAPL_CORES_ENERGY_STATUS (1 << 9) |
| 139 | /* 0x639 MSR_PP0_ENERGY_STATUS */ |
| 140 | #define RAPL_CORES (RAPL_CORES_ENERGY_STATUS | RAPL_CORES_POWER_LIMIT) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 141 | #define TJMAX_DEFAULT 100 |
| 142 | |
| 143 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 144 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 145 | /* |
| 146 | * buffer size used by sscanf() for added column names |
| 147 | * Usually truncated to 7 characters, but also handles 18 columns for raw 64-bit counters |
| 148 | */ |
| 149 | #define NAME_BYTES 20 |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 150 | #define PATH_BYTES 128 |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 151 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 152 | int backwards_count; |
| 153 | char *progname; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 154 | |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 155 | #define CPU_SUBSET_MAXCPUS 1024 /* need to use before probe... */ |
| 156 | cpu_set_t *cpu_present_set, *cpu_affinity_set, *cpu_subset; |
| 157 | size_t cpu_present_setsize, cpu_affinity_setsize, cpu_subset_size; |
Len Brown | 0748eaf | 2018-06-01 12:38:29 -0400 | [diff] [blame] | 158 | #define MAX_ADDED_COUNTERS 8 |
| 159 | #define MAX_ADDED_THREAD_COUNTERS 24 |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 160 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 161 | struct thread_data { |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 162 | struct timeval tv_begin; |
| 163 | struct timeval tv_end; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 164 | unsigned long long tsc; |
| 165 | unsigned long long aperf; |
| 166 | unsigned long long mperf; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 167 | unsigned long long c1; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 168 | unsigned long long irq_count; |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 169 | unsigned int smi_count; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 170 | unsigned int cpu_id; |
| 171 | unsigned int flags; |
| 172 | #define CPU_IS_FIRST_THREAD_IN_CORE 0x2 |
| 173 | #define CPU_IS_FIRST_CORE_IN_PACKAGE 0x4 |
Len Brown | 0748eaf | 2018-06-01 12:38:29 -0400 | [diff] [blame] | 174 | unsigned long long counter[MAX_ADDED_THREAD_COUNTERS]; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 175 | } *thread_even, *thread_odd; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 176 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 177 | struct core_data { |
| 178 | unsigned long long c3; |
| 179 | unsigned long long c6; |
| 180 | unsigned long long c7; |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 181 | 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] | 182 | unsigned int core_temp_c; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 183 | unsigned int core_id; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 184 | unsigned long long counter[MAX_ADDED_COUNTERS]; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 185 | } *core_even, *core_odd; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 186 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 187 | struct pkg_data { |
| 188 | unsigned long long pc2; |
| 189 | unsigned long long pc3; |
| 190 | unsigned long long pc6; |
| 191 | unsigned long long pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 192 | unsigned long long pc8; |
| 193 | unsigned long long pc9; |
| 194 | unsigned long long pc10; |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 195 | unsigned long long cpu_lpi; |
| 196 | unsigned long long sys_lpi; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 197 | unsigned long long pkg_wtd_core_c0; |
| 198 | unsigned long long pkg_any_core_c0; |
| 199 | unsigned long long pkg_any_gfxe_c0; |
| 200 | unsigned long long pkg_both_core_gfxe_c0; |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 201 | long long gfx_rc6_ms; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 202 | unsigned int gfx_mhz; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 203 | unsigned int package_id; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 204 | unsigned int energy_pkg; /* MSR_PKG_ENERGY_STATUS */ |
| 205 | unsigned int energy_dram; /* MSR_DRAM_ENERGY_STATUS */ |
| 206 | unsigned int energy_cores; /* MSR_PP0_ENERGY_STATUS */ |
| 207 | unsigned int energy_gfx; /* MSR_PP1_ENERGY_STATUS */ |
| 208 | unsigned int rapl_pkg_perf_status; /* MSR_PKG_PERF_STATUS */ |
| 209 | unsigned int rapl_dram_perf_status; /* MSR_DRAM_PERF_STATUS */ |
| 210 | unsigned int pkg_temp_c; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 211 | unsigned long long counter[MAX_ADDED_COUNTERS]; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 212 | } *package_even, *package_odd; |
| 213 | |
| 214 | #define ODD_COUNTERS thread_odd, core_odd, package_odd |
| 215 | #define EVEN_COUNTERS thread_even, core_even, package_even |
| 216 | |
| 217 | #define GET_THREAD(thread_base, thread_no, core_no, pkg_no) \ |
| 218 | (thread_base + (pkg_no) * topo.num_cores_per_pkg * \ |
| 219 | topo.num_threads_per_core + \ |
| 220 | (core_no) * topo.num_threads_per_core + (thread_no)) |
| 221 | #define GET_CORE(core_base, core_no, pkg_no) \ |
| 222 | (core_base + (pkg_no) * topo.num_cores_per_pkg + (core_no)) |
| 223 | #define GET_PKG(pkg_base, pkg_no) (pkg_base + pkg_no) |
| 224 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 225 | enum counter_scope {SCOPE_CPU, SCOPE_CORE, SCOPE_PACKAGE}; |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 226 | enum counter_type {COUNTER_ITEMS, COUNTER_CYCLES, COUNTER_SECONDS, COUNTER_USEC}; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 227 | enum counter_format {FORMAT_RAW, FORMAT_DELTA, FORMAT_PERCENT}; |
| 228 | |
| 229 | struct msr_counter { |
| 230 | unsigned int msr_num; |
| 231 | char name[NAME_BYTES]; |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 232 | char path[PATH_BYTES]; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 233 | unsigned int width; |
| 234 | enum counter_type type; |
| 235 | enum counter_format format; |
| 236 | struct msr_counter *next; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 237 | unsigned int flags; |
| 238 | #define FLAGS_HIDE (1 << 0) |
| 239 | #define FLAGS_SHOW (1 << 1) |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 240 | #define SYSFS_PERCPU (1 << 1) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 241 | }; |
| 242 | |
| 243 | struct sys_counters { |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 244 | unsigned int added_thread_counters; |
| 245 | unsigned int added_core_counters; |
| 246 | unsigned int added_package_counters; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 247 | struct msr_counter *tp; |
| 248 | struct msr_counter *cp; |
| 249 | struct msr_counter *pp; |
| 250 | } sys; |
| 251 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 252 | struct system_summary { |
| 253 | struct thread_data threads; |
| 254 | struct core_data cores; |
| 255 | struct pkg_data packages; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 256 | } average; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 257 | |
| 258 | |
| 259 | struct topo_params { |
| 260 | int num_packages; |
| 261 | int num_cpus; |
| 262 | int num_cores; |
| 263 | int max_cpu_num; |
| 264 | int num_cores_per_pkg; |
| 265 | int num_threads_per_core; |
| 266 | } topo; |
| 267 | |
| 268 | struct timeval tv_even, tv_odd, tv_delta; |
| 269 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 270 | int *irq_column_2_cpu; /* /proc/interrupts column numbers */ |
| 271 | int *irqs_per_cpu; /* indexed by cpu_num */ |
| 272 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 273 | void setup_all_buffers(void); |
| 274 | |
| 275 | int cpu_is_not_present(int cpu) |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 276 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 277 | return !CPU_ISSET_S(cpu, cpu_present_setsize, cpu_present_set); |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 278 | } |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 279 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 280 | * run func(thread, core, package) in topology order |
| 281 | * skip non-present cpus |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 282 | */ |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 283 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 284 | int for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg_data *), |
| 285 | 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] | 286 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 287 | int retval, pkg_no, core_no, thread_no; |
| 288 | |
| 289 | for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { |
| 290 | for (core_no = 0; core_no < topo.num_cores_per_pkg; ++core_no) { |
| 291 | for (thread_no = 0; thread_no < |
| 292 | topo.num_threads_per_core; ++thread_no) { |
| 293 | struct thread_data *t; |
| 294 | struct core_data *c; |
| 295 | struct pkg_data *p; |
| 296 | |
| 297 | t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); |
| 298 | |
| 299 | if (cpu_is_not_present(t->cpu_id)) |
| 300 | continue; |
| 301 | |
| 302 | c = GET_CORE(core_base, core_no, pkg_no); |
| 303 | p = GET_PKG(pkg_base, pkg_no); |
| 304 | |
| 305 | retval = func(t, c, p); |
| 306 | if (retval) |
| 307 | return retval; |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | return 0; |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | int cpu_migrate(int cpu) |
| 315 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 316 | CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); |
| 317 | CPU_SET_S(cpu, cpu_affinity_setsize, cpu_affinity_set); |
| 318 | if (sched_setaffinity(0, cpu_affinity_setsize, cpu_affinity_set) == -1) |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 319 | return -1; |
| 320 | else |
| 321 | return 0; |
| 322 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 323 | int get_msr_fd(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 324 | { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 325 | char pathname[32]; |
| 326 | int fd; |
| 327 | |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 328 | fd = fd_percpu[cpu]; |
| 329 | |
| 330 | if (fd) |
| 331 | return fd; |
| 332 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 333 | sprintf(pathname, "/dev/cpu/%d/msr", cpu); |
| 334 | fd = open(pathname, O_RDONLY); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 335 | if (fd < 0) |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 336 | 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] | 337 | |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 338 | fd_percpu[cpu] = fd; |
| 339 | |
| 340 | return fd; |
| 341 | } |
| 342 | |
| 343 | int get_msr(int cpu, off_t offset, unsigned long long *msr) |
| 344 | { |
| 345 | ssize_t retval; |
| 346 | |
| 347 | retval = pread(get_msr_fd(cpu), msr, sizeof(*msr), offset); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 348 | |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 349 | if (retval != sizeof *msr) |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 350 | 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] | 351 | |
| 352 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 353 | } |
| 354 | |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 355 | /* |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 356 | * Each string in this array is compared in --show and --hide cmdline. |
| 357 | * 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] | 358 | */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 359 | struct msr_counter bic[] = { |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 360 | { 0x0, "usec" }, |
| 361 | { 0x0, "Time_Of_Day_Seconds" }, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 362 | { 0x0, "Package" }, |
| 363 | { 0x0, "Avg_MHz" }, |
| 364 | { 0x0, "Bzy_MHz" }, |
| 365 | { 0x0, "TSC_MHz" }, |
| 366 | { 0x0, "IRQ" }, |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 367 | { 0x0, "SMI", "", 32, 0, FORMAT_DELTA, NULL}, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 368 | { 0x0, "Busy%" }, |
| 369 | { 0x0, "CPU%c1" }, |
| 370 | { 0x0, "CPU%c3" }, |
| 371 | { 0x0, "CPU%c6" }, |
| 372 | { 0x0, "CPU%c7" }, |
| 373 | { 0x0, "ThreadC" }, |
| 374 | { 0x0, "CoreTmp" }, |
| 375 | { 0x0, "CoreCnt" }, |
| 376 | { 0x0, "PkgTmp" }, |
| 377 | { 0x0, "GFX%rc6" }, |
| 378 | { 0x0, "GFXMHz" }, |
| 379 | { 0x0, "Pkg%pc2" }, |
| 380 | { 0x0, "Pkg%pc3" }, |
| 381 | { 0x0, "Pkg%pc6" }, |
| 382 | { 0x0, "Pkg%pc7" }, |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 383 | { 0x0, "Pkg%pc8" }, |
| 384 | { 0x0, "Pkg%pc9" }, |
Len Brown | 4bd1f8f | 2018-01-28 23:42:42 -0500 | [diff] [blame] | 385 | { 0x0, "Pk%pc10" }, |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 386 | { 0x0, "CPU%LPI" }, |
| 387 | { 0x0, "SYS%LPI" }, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 388 | { 0x0, "PkgWatt" }, |
| 389 | { 0x0, "CorWatt" }, |
| 390 | { 0x0, "GFXWatt" }, |
| 391 | { 0x0, "PkgCnt" }, |
| 392 | { 0x0, "RAMWatt" }, |
| 393 | { 0x0, "PKG_%" }, |
| 394 | { 0x0, "RAM_%" }, |
| 395 | { 0x0, "Pkg_J" }, |
| 396 | { 0x0, "Cor_J" }, |
| 397 | { 0x0, "GFX_J" }, |
| 398 | { 0x0, "RAM_J" }, |
| 399 | { 0x0, "Core" }, |
| 400 | { 0x0, "CPU" }, |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 401 | { 0x0, "Mod%c6" }, |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 402 | { 0x0, "sysfs" }, |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 403 | { 0x0, "Totl%C0" }, |
| 404 | { 0x0, "Any%C0" }, |
| 405 | { 0x0, "GFX%C0" }, |
| 406 | { 0x0, "CPUGFX%" }, |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 407 | { 0x0, "Node%" }, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 408 | }; |
| 409 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 410 | |
| 411 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 412 | #define MAX_BIC (sizeof(bic) / sizeof(struct msr_counter)) |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 413 | #define BIC_USEC (1ULL << 0) |
| 414 | #define BIC_TOD (1ULL << 1) |
| 415 | #define BIC_Package (1ULL << 2) |
| 416 | #define BIC_Avg_MHz (1ULL << 3) |
| 417 | #define BIC_Bzy_MHz (1ULL << 4) |
| 418 | #define BIC_TSC_MHz (1ULL << 5) |
| 419 | #define BIC_IRQ (1ULL << 6) |
| 420 | #define BIC_SMI (1ULL << 7) |
| 421 | #define BIC_Busy (1ULL << 8) |
| 422 | #define BIC_CPU_c1 (1ULL << 9) |
| 423 | #define BIC_CPU_c3 (1ULL << 10) |
| 424 | #define BIC_CPU_c6 (1ULL << 11) |
| 425 | #define BIC_CPU_c7 (1ULL << 12) |
| 426 | #define BIC_ThreadC (1ULL << 13) |
| 427 | #define BIC_CoreTmp (1ULL << 14) |
| 428 | #define BIC_CoreCnt (1ULL << 15) |
| 429 | #define BIC_PkgTmp (1ULL << 16) |
| 430 | #define BIC_GFX_rc6 (1ULL << 17) |
| 431 | #define BIC_GFXMHz (1ULL << 18) |
| 432 | #define BIC_Pkgpc2 (1ULL << 19) |
| 433 | #define BIC_Pkgpc3 (1ULL << 20) |
| 434 | #define BIC_Pkgpc6 (1ULL << 21) |
| 435 | #define BIC_Pkgpc7 (1ULL << 22) |
| 436 | #define BIC_Pkgpc8 (1ULL << 23) |
| 437 | #define BIC_Pkgpc9 (1ULL << 24) |
| 438 | #define BIC_Pkgpc10 (1ULL << 25) |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 439 | #define BIC_CPU_LPI (1ULL << 26) |
| 440 | #define BIC_SYS_LPI (1ULL << 27) |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 441 | #define BIC_PkgWatt (1ULL << 26) |
| 442 | #define BIC_CorWatt (1ULL << 27) |
| 443 | #define BIC_GFXWatt (1ULL << 28) |
| 444 | #define BIC_PkgCnt (1ULL << 29) |
| 445 | #define BIC_RAMWatt (1ULL << 30) |
| 446 | #define BIC_PKG__ (1ULL << 31) |
| 447 | #define BIC_RAM__ (1ULL << 32) |
| 448 | #define BIC_Pkg_J (1ULL << 33) |
| 449 | #define BIC_Cor_J (1ULL << 34) |
| 450 | #define BIC_GFX_J (1ULL << 35) |
| 451 | #define BIC_RAM_J (1ULL << 36) |
| 452 | #define BIC_Core (1ULL << 37) |
| 453 | #define BIC_CPU (1ULL << 38) |
| 454 | #define BIC_Mod_c6 (1ULL << 39) |
| 455 | #define BIC_sysfs (1ULL << 40) |
| 456 | #define BIC_Totl_c0 (1ULL << 41) |
| 457 | #define BIC_Any_c0 (1ULL << 42) |
| 458 | #define BIC_GFX_c0 (1ULL << 43) |
| 459 | #define BIC_CPUGFX (1ULL << 44) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 460 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 461 | #define BIC_DISABLED_BY_DEFAULT (BIC_USEC | BIC_TOD) |
| 462 | |
| 463 | unsigned long long bic_enabled = (0xFFFFFFFFFFFFFFFFULL & ~BIC_DISABLED_BY_DEFAULT); |
| 464 | unsigned long long bic_present = BIC_USEC | BIC_TOD | BIC_sysfs; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 465 | |
| 466 | #define DO_BIC(COUNTER_NAME) (bic_enabled & bic_present & COUNTER_NAME) |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 467 | #define ENABLE_BIC(COUNTER_NAME) (bic_enabled |= COUNTER_NAME) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 468 | #define BIC_PRESENT(COUNTER_BIT) (bic_present |= COUNTER_BIT) |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 469 | #define BIC_NOT_PRESENT(COUNTER_BIT) (bic_present &= ~COUNTER_BIT) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 470 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 471 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 472 | #define MAX_DEFERRED 16 |
| 473 | char *deferred_skip_names[MAX_DEFERRED]; |
| 474 | int deferred_skip_index; |
| 475 | |
| 476 | /* |
| 477 | * HIDE_LIST - hide this list of counters, show the rest [default] |
| 478 | * SHOW_LIST - show this list of counters, hide the rest |
| 479 | */ |
| 480 | enum show_hide_mode { SHOW_LIST, HIDE_LIST } global_show_hide_mode = HIDE_LIST; |
| 481 | |
| 482 | void help(void) |
| 483 | { |
| 484 | fprintf(outf, |
| 485 | "Usage: turbostat [OPTIONS][(--interval seconds) | COMMAND ...]\n" |
| 486 | "\n" |
| 487 | "Turbostat forks the specified COMMAND and prints statistics\n" |
| 488 | "when COMMAND completes.\n" |
| 489 | "If no COMMAND is specified, turbostat wakes every 5-seconds\n" |
| 490 | "to print statistics, until interrupted.\n" |
| 491 | "--add add a counter\n" |
| 492 | " eg. --add msr0x10,u64,cpu,delta,MY_TSC\n" |
| 493 | "--cpu cpu-set limit output to summary plus cpu-set:\n" |
| 494 | " {core | package | j,k,l..m,n-p }\n" |
| 495 | "--quiet skip decoding system configuration header\n" |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 496 | "--interval sec.subsec Override default 5-second measurement interval\n" |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 497 | "--help print this help message\n" |
| 498 | "--list list column headers only\n" |
| 499 | "--out file create or truncate \"file\" for all output\n" |
| 500 | "--version print version information\n" |
| 501 | "\n" |
| 502 | "For more help, run \"man turbostat\"\n"); |
| 503 | } |
| 504 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 505 | /* |
| 506 | * bic_lookup |
| 507 | * for all the strings in comma separate name_list, |
| 508 | * set the approprate bit in return value. |
| 509 | */ |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 510 | 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] | 511 | { |
| 512 | int i; |
| 513 | unsigned long long retval = 0; |
| 514 | |
| 515 | while (name_list) { |
| 516 | char *comma; |
| 517 | |
| 518 | comma = strchr(name_list, ','); |
| 519 | |
| 520 | if (comma) |
| 521 | *comma = '\0'; |
| 522 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 523 | if (!strcmp(name_list, "all")) |
| 524 | return ~0; |
| 525 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 526 | for (i = 0; i < MAX_BIC; ++i) { |
| 527 | if (!strcmp(name_list, bic[i].name)) { |
| 528 | retval |= (1ULL << i); |
| 529 | break; |
| 530 | } |
| 531 | } |
| 532 | if (i == MAX_BIC) { |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 533 | if (mode == SHOW_LIST) { |
| 534 | fprintf(stderr, "Invalid counter name: %s\n", name_list); |
| 535 | exit(-1); |
| 536 | } |
| 537 | deferred_skip_names[deferred_skip_index++] = name_list; |
| 538 | if (debug) |
| 539 | fprintf(stderr, "deferred \"%s\"\n", name_list); |
| 540 | if (deferred_skip_index >= MAX_DEFERRED) { |
| 541 | fprintf(stderr, "More than max %d un-recognized --skip options '%s'\n", |
| 542 | MAX_DEFERRED, name_list); |
| 543 | help(); |
| 544 | exit(1); |
| 545 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | name_list = comma; |
| 549 | if (name_list) |
| 550 | name_list++; |
| 551 | |
| 552 | } |
| 553 | return retval; |
| 554 | } |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 555 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 556 | |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 557 | void print_header(char *delim) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 558 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 559 | struct msr_counter *mp; |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 560 | int printed = 0; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 561 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 562 | if (DO_BIC(BIC_USEC)) |
| 563 | outp += sprintf(outp, "%susec", (printed++ ? delim : "")); |
| 564 | if (DO_BIC(BIC_TOD)) |
| 565 | outp += sprintf(outp, "%sTime_Of_Day_Seconds", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 566 | if (DO_BIC(BIC_Package)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 567 | outp += sprintf(outp, "%sPackage", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 568 | if (DO_BIC(BIC_Core)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 569 | outp += sprintf(outp, "%sCore", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 570 | if (DO_BIC(BIC_CPU)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 571 | outp += sprintf(outp, "%sCPU", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 572 | if (DO_BIC(BIC_Avg_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 573 | outp += sprintf(outp, "%sAvg_MHz", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 574 | if (DO_BIC(BIC_Busy)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 575 | outp += sprintf(outp, "%sBusy%%", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 576 | if (DO_BIC(BIC_Bzy_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 577 | outp += sprintf(outp, "%sBzy_MHz", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 578 | if (DO_BIC(BIC_TSC_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 579 | outp += sprintf(outp, "%sTSC_MHz", (printed++ ? delim : "")); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 580 | |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 581 | if (DO_BIC(BIC_IRQ)) { |
| 582 | if (sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 583 | outp += sprintf(outp, "%s IRQ", (printed++ ? delim : "")); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 584 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 585 | outp += sprintf(outp, "%sIRQ", (printed++ ? delim : "")); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 586 | } |
| 587 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 588 | if (DO_BIC(BIC_SMI)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 589 | outp += sprintf(outp, "%sSMI", (printed++ ? delim : "")); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 590 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 591 | for (mp = sys.tp; mp; mp = mp->next) { |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 592 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 593 | if (mp->format == FORMAT_RAW) { |
| 594 | if (mp->width == 64) |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 595 | outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 596 | else |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 597 | outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 598 | } else { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 599 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 600 | outp += sprintf(outp, "%s%8s", (printed++ ? delim : ""), mp->name); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 601 | else |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 602 | outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 603 | } |
| 604 | } |
| 605 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 606 | if (DO_BIC(BIC_CPU_c1)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 607 | outp += sprintf(outp, "%sCPU%%c1", (printed++ ? delim : "")); |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame^] | 608 | if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates && !do_cnl_cstates) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 609 | outp += sprintf(outp, "%sCPU%%c3", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 610 | if (DO_BIC(BIC_CPU_c6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 611 | outp += sprintf(outp, "%sCPU%%c6", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 612 | if (DO_BIC(BIC_CPU_c7)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 613 | outp += sprintf(outp, "%sCPU%%c7", (printed++ ? delim : "")); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 614 | |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 615 | if (DO_BIC(BIC_Mod_c6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 616 | outp += sprintf(outp, "%sMod%%c6", (printed++ ? delim : "")); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 617 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 618 | if (DO_BIC(BIC_CoreTmp)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 619 | outp += sprintf(outp, "%sCoreTmp", (printed++ ? delim : "")); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 620 | |
| 621 | for (mp = sys.cp; mp; mp = mp->next) { |
| 622 | if (mp->format == FORMAT_RAW) { |
| 623 | if (mp->width == 64) |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 624 | outp += sprintf(outp, "%s%18.18s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 625 | else |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 626 | outp += sprintf(outp, "%s%10.10s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 627 | } else { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 628 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
| 629 | outp += sprintf(outp, "%s%8s", delim, mp->name); |
| 630 | else |
| 631 | outp += sprintf(outp, "%s%s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 632 | } |
| 633 | } |
| 634 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 635 | if (DO_BIC(BIC_PkgTmp)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 636 | outp += sprintf(outp, "%sPkgTmp", (printed++ ? delim : "")); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 637 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 638 | if (DO_BIC(BIC_GFX_rc6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 639 | outp += sprintf(outp, "%sGFX%%rc6", (printed++ ? delim : "")); |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 640 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 641 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 642 | outp += sprintf(outp, "%sGFXMHz", (printed++ ? delim : "")); |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 643 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 644 | if (DO_BIC(BIC_Totl_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 645 | outp += sprintf(outp, "%sTotl%%C0", (printed++ ? delim : "")); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 646 | if (DO_BIC(BIC_Any_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 647 | outp += sprintf(outp, "%sAny%%C0", (printed++ ? delim : "")); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 648 | if (DO_BIC(BIC_GFX_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 649 | outp += sprintf(outp, "%sGFX%%C0", (printed++ ? delim : "")); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 650 | if (DO_BIC(BIC_CPUGFX)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 651 | outp += sprintf(outp, "%sCPUGFX%%", (printed++ ? delim : "")); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 652 | |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 653 | if (DO_BIC(BIC_Pkgpc2)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 654 | outp += sprintf(outp, "%sPkg%%pc2", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 655 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 656 | outp += sprintf(outp, "%sPkg%%pc3", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 657 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 658 | outp += sprintf(outp, "%sPkg%%pc6", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 659 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 660 | outp += sprintf(outp, "%sPkg%%pc7", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 661 | if (DO_BIC(BIC_Pkgpc8)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 662 | outp += sprintf(outp, "%sPkg%%pc8", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 663 | if (DO_BIC(BIC_Pkgpc9)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 664 | outp += sprintf(outp, "%sPkg%%pc9", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 665 | if (DO_BIC(BIC_Pkgpc10)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 666 | outp += sprintf(outp, "%sPk%%pc10", (printed++ ? delim : "")); |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 667 | if (DO_BIC(BIC_CPU_LPI)) |
| 668 | outp += sprintf(outp, "%sCPU%%LPI", (printed++ ? delim : "")); |
| 669 | if (DO_BIC(BIC_SYS_LPI)) |
| 670 | outp += sprintf(outp, "%sSYS%%LPI", (printed++ ? delim : "")); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 671 | |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 672 | if (do_rapl && !rapl_joules) { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 673 | if (DO_BIC(BIC_PkgWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 674 | outp += sprintf(outp, "%sPkgWatt", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 675 | if (DO_BIC(BIC_CorWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 676 | outp += sprintf(outp, "%sCorWatt", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 677 | if (DO_BIC(BIC_GFXWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 678 | outp += sprintf(outp, "%sGFXWatt", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 679 | if (DO_BIC(BIC_RAMWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 680 | outp += sprintf(outp, "%sRAMWatt", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 681 | if (DO_BIC(BIC_PKG__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 682 | outp += sprintf(outp, "%sPKG_%%", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 683 | if (DO_BIC(BIC_RAM__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 684 | outp += sprintf(outp, "%sRAM_%%", (printed++ ? delim : "")); |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 685 | } else if (do_rapl && rapl_joules) { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 686 | if (DO_BIC(BIC_Pkg_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 687 | outp += sprintf(outp, "%sPkg_J", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 688 | if (DO_BIC(BIC_Cor_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 689 | outp += sprintf(outp, "%sCor_J", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 690 | if (DO_BIC(BIC_GFX_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 691 | outp += sprintf(outp, "%sGFX_J", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 692 | if (DO_BIC(BIC_RAM_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 693 | outp += sprintf(outp, "%sRAM_J", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 694 | if (DO_BIC(BIC_PKG__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 695 | outp += sprintf(outp, "%sPKG_%%", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 696 | if (DO_BIC(BIC_RAM__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 697 | outp += sprintf(outp, "%sRAM_%%", (printed++ ? delim : "")); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 698 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 699 | for (mp = sys.pp; mp; mp = mp->next) { |
| 700 | if (mp->format == FORMAT_RAW) { |
| 701 | if (mp->width == 64) |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 702 | outp += sprintf(outp, "%s%18.18s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 703 | else |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 704 | outp += sprintf(outp, "%s%10.10s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 705 | } else { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 706 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
| 707 | outp += sprintf(outp, "%s%8s", delim, mp->name); |
| 708 | else |
| 709 | outp += sprintf(outp, "%s%s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 710 | } |
| 711 | } |
| 712 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 713 | outp += sprintf(outp, "\n"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 714 | } |
| 715 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 716 | int dump_counters(struct thread_data *t, struct core_data *c, |
| 717 | struct pkg_data *p) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 718 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 719 | int i; |
| 720 | struct msr_counter *mp; |
| 721 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 722 | 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] | 723 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 724 | if (t) { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 725 | outp += sprintf(outp, "CPU: %d flags 0x%x\n", |
| 726 | t->cpu_id, t->flags); |
| 727 | outp += sprintf(outp, "TSC: %016llX\n", t->tsc); |
| 728 | outp += sprintf(outp, "aperf: %016llX\n", t->aperf); |
| 729 | outp += sprintf(outp, "mperf: %016llX\n", t->mperf); |
| 730 | outp += sprintf(outp, "c1: %016llX\n", t->c1); |
Len Brown | 6886fee | 2016-12-24 15:18:37 -0500 | [diff] [blame] | 731 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 732 | if (DO_BIC(BIC_IRQ)) |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 733 | outp += sprintf(outp, "IRQ: %lld\n", t->irq_count); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 734 | if (DO_BIC(BIC_SMI)) |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 735 | outp += sprintf(outp, "SMI: %d\n", t->smi_count); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 736 | |
| 737 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 738 | outp += sprintf(outp, "tADDED [%d] msr0x%x: %08llX\n", |
| 739 | i, mp->msr_num, t->counter[i]); |
| 740 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 741 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 742 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 743 | if (c) { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 744 | outp += sprintf(outp, "core: %d\n", c->core_id); |
| 745 | outp += sprintf(outp, "c3: %016llX\n", c->c3); |
| 746 | outp += sprintf(outp, "c6: %016llX\n", c->c6); |
| 747 | outp += sprintf(outp, "c7: %016llX\n", c->c7); |
| 748 | outp += sprintf(outp, "DTS: %dC\n", c->core_temp_c); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 749 | |
| 750 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 751 | outp += sprintf(outp, "cADDED [%d] msr0x%x: %08llX\n", |
| 752 | i, mp->msr_num, c->counter[i]); |
| 753 | } |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 754 | outp += sprintf(outp, "mc6_us: %016llX\n", c->mc6_us); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | if (p) { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 758 | outp += sprintf(outp, "package: %d\n", p->package_id); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 759 | |
| 760 | outp += sprintf(outp, "Weighted cores: %016llX\n", p->pkg_wtd_core_c0); |
| 761 | outp += sprintf(outp, "Any cores: %016llX\n", p->pkg_any_core_c0); |
| 762 | outp += sprintf(outp, "Any GFX: %016llX\n", p->pkg_any_gfxe_c0); |
| 763 | outp += sprintf(outp, "CPU + GFX: %016llX\n", p->pkg_both_core_gfxe_c0); |
| 764 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 765 | outp += sprintf(outp, "pc2: %016llX\n", p->pc2); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 766 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 767 | outp += sprintf(outp, "pc3: %016llX\n", p->pc3); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 768 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 769 | outp += sprintf(outp, "pc6: %016llX\n", p->pc6); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 770 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 771 | outp += sprintf(outp, "pc7: %016llX\n", p->pc7); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 772 | outp += sprintf(outp, "pc8: %016llX\n", p->pc8); |
| 773 | outp += sprintf(outp, "pc9: %016llX\n", p->pc9); |
| 774 | outp += sprintf(outp, "pc10: %016llX\n", p->pc10); |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 775 | outp += sprintf(outp, "pc10: %016llX\n", p->pc10); |
| 776 | outp += sprintf(outp, "cpu_lpi: %016llX\n", p->cpu_lpi); |
| 777 | outp += sprintf(outp, "sys_lpi: %016llX\n", p->sys_lpi); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 778 | outp += sprintf(outp, "Joules PKG: %0X\n", p->energy_pkg); |
| 779 | outp += sprintf(outp, "Joules COR: %0X\n", p->energy_cores); |
| 780 | outp += sprintf(outp, "Joules GFX: %0X\n", p->energy_gfx); |
| 781 | outp += sprintf(outp, "Joules RAM: %0X\n", p->energy_dram); |
| 782 | outp += sprintf(outp, "Throttle PKG: %0X\n", |
| 783 | p->rapl_pkg_perf_status); |
| 784 | outp += sprintf(outp, "Throttle RAM: %0X\n", |
| 785 | p->rapl_dram_perf_status); |
| 786 | outp += sprintf(outp, "PTM: %dC\n", p->pkg_temp_c); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 787 | |
| 788 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 789 | outp += sprintf(outp, "pADDED [%d] msr0x%x: %08llX\n", |
| 790 | i, mp->msr_num, p->counter[i]); |
| 791 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 792 | } |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 793 | |
| 794 | outp += sprintf(outp, "\n"); |
| 795 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 796 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 797 | } |
| 798 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 799 | /* |
| 800 | * column formatting convention & formats |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 801 | */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 802 | int format_counters(struct thread_data *t, struct core_data *c, |
| 803 | struct pkg_data *p) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 804 | { |
Len Brown | 008d396e | 2017-02-10 00:29:51 -0500 | [diff] [blame] | 805 | double interval_float, tsc; |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 806 | char *fmt8; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 807 | int i; |
| 808 | struct msr_counter *mp; |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 809 | char *delim = "\t"; |
| 810 | int printed = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 811 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 812 | /* if showing only 1st thread in core and this isn't one, bail out */ |
| 813 | if (show_core_only && !(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 814 | return 0; |
| 815 | |
| 816 | /* if showing only 1st thread in pkg and this isn't one, bail out */ |
| 817 | if (show_pkg_only && !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 818 | return 0; |
| 819 | |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 820 | /*if not summary line and --cpu is used */ |
| 821 | if ((t != &average.threads) && |
| 822 | (cpu_subset && !CPU_ISSET_S(t->cpu_id, cpu_subset_size, cpu_subset))) |
| 823 | return 0; |
| 824 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 825 | if (DO_BIC(BIC_USEC)) { |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 826 | /* on each row, print how many usec each timestamp took to gather */ |
| 827 | struct timeval tv; |
| 828 | |
| 829 | timersub(&t->tv_end, &t->tv_begin, &tv); |
| 830 | outp += sprintf(outp, "%5ld\t", tv.tv_sec * 1000000 + tv.tv_usec); |
| 831 | } |
| 832 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 833 | /* Time_Of_Day_Seconds: on each row, print sec.usec last timestamp taken */ |
| 834 | if (DO_BIC(BIC_TOD)) |
| 835 | outp += sprintf(outp, "%10ld.%06ld\t", t->tv_end.tv_sec, t->tv_end.tv_usec); |
| 836 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 837 | interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0; |
| 838 | |
Len Brown | 008d396e | 2017-02-10 00:29:51 -0500 | [diff] [blame] | 839 | tsc = t->tsc * tsc_tweak; |
| 840 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 841 | /* topo columns, print blanks on 1st (average) line */ |
| 842 | if (t == &average.threads) { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 843 | if (DO_BIC(BIC_Package)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 844 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 845 | if (DO_BIC(BIC_Core)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 846 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 847 | if (DO_BIC(BIC_CPU)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 848 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 849 | } else { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 850 | if (DO_BIC(BIC_Package)) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 851 | if (p) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 852 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->package_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 853 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 854 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 855 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 856 | if (DO_BIC(BIC_Core)) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 857 | if (c) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 858 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), c->core_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 859 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 860 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 861 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 862 | if (DO_BIC(BIC_CPU)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 863 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->cpu_id); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 864 | } |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 865 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 866 | if (DO_BIC(BIC_Avg_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 867 | outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 868 | 1.0 / units * t->aperf / interval_float); |
| 869 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 870 | if (DO_BIC(BIC_Busy)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 871 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->mperf/tsc); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 872 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 873 | if (DO_BIC(BIC_Bzy_MHz)) { |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 874 | if (has_base_hz) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 875 | 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] | 876 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 877 | outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), |
Len Brown | 008d396e | 2017-02-10 00:29:51 -0500 | [diff] [blame] | 878 | tsc / units * t->aperf / t->mperf / interval_float); |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 879 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 880 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 881 | if (DO_BIC(BIC_TSC_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 882 | 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] | 883 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 884 | /* IRQ */ |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 885 | if (DO_BIC(BIC_IRQ)) { |
| 886 | if (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->irq_count); |
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->irq_count); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 890 | } |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 891 | |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 892 | /* SMI */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 893 | if (DO_BIC(BIC_SMI)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 894 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->smi_count); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 895 | |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 896 | /* Added counters */ |
| 897 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 898 | if (mp->format == FORMAT_RAW) { |
| 899 | if (mp->width == 32) |
Len Brown | 5f3aea5 | 2017-02-23 18:10:27 -0500 | [diff] [blame] | 900 | outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int) t->counter[i]); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 901 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 902 | outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), t->counter[i]); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 903 | } else if (mp->format == FORMAT_DELTA) { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 904 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 905 | outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), t->counter[i]); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 906 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 907 | outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->counter[i]); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 908 | } else if (mp->format == FORMAT_PERCENT) { |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 909 | if (mp->type == COUNTER_USEC) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 910 | 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] | 911 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 912 | 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] | 913 | } |
| 914 | } |
| 915 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 916 | /* C1 */ |
| 917 | if (DO_BIC(BIC_CPU_c1)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 918 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->c1/tsc); |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 919 | |
| 920 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 921 | /* print per-core data only for 1st thread in core */ |
| 922 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 923 | goto done; |
| 924 | |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame^] | 925 | if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates && !do_cnl_cstates) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 926 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c3/tsc); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 927 | if (DO_BIC(BIC_CPU_c6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 928 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c6/tsc); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 929 | if (DO_BIC(BIC_CPU_c7)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 930 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c7/tsc); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 931 | |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 932 | /* Mod%c6 */ |
| 933 | if (DO_BIC(BIC_Mod_c6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 934 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->mc6_us / tsc); |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 935 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 936 | if (DO_BIC(BIC_CoreTmp)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 937 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), c->core_temp_c); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 938 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 939 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 940 | if (mp->format == FORMAT_RAW) { |
| 941 | if (mp->width == 32) |
Len Brown | 5f3aea5 | 2017-02-23 18:10:27 -0500 | [diff] [blame] | 942 | outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int) c->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 943 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 944 | outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), c->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 945 | } else if (mp->format == FORMAT_DELTA) { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 946 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 947 | outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), c->counter[i]); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 948 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 949 | outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), c->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 950 | } else if (mp->format == FORMAT_PERCENT) { |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 951 | 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] | 952 | } |
| 953 | } |
| 954 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 955 | /* print per-package data only for 1st core in package */ |
| 956 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 957 | goto done; |
| 958 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 959 | /* PkgTmp */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 960 | if (DO_BIC(BIC_PkgTmp)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 961 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->pkg_temp_c); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 962 | |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 963 | /* GFXrc6 */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 964 | if (DO_BIC(BIC_GFX_rc6)) { |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 965 | if (p->gfx_rc6_ms == -1) { /* detect GFX counter reset */ |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 966 | outp += sprintf(outp, "%s**.**", (printed++ ? delim : "")); |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 967 | } else { |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 968 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 969 | p->gfx_rc6_ms / 10.0 / interval_float); |
| 970 | } |
| 971 | } |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 972 | |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 973 | /* GFXMHz */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 974 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 975 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->gfx_mhz); |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 976 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 977 | /* Totl%C0, Any%C0 GFX%C0 CPUGFX% */ |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 978 | if (DO_BIC(BIC_Totl_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 979 | 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] | 980 | if (DO_BIC(BIC_Any_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 981 | 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] | 982 | if (DO_BIC(BIC_GFX_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 983 | 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] | 984 | if (DO_BIC(BIC_CPUGFX)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 985 | 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] | 986 | |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 987 | if (DO_BIC(BIC_Pkgpc2)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 988 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc2/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 989 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 990 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc3/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 991 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 992 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc6/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 993 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 994 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc7/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 995 | if (DO_BIC(BIC_Pkgpc8)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 996 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc8/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 997 | if (DO_BIC(BIC_Pkgpc9)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 998 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc9/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 999 | if (DO_BIC(BIC_Pkgpc10)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1000 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc10/tsc); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1001 | |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 1002 | if (DO_BIC(BIC_CPU_LPI)) |
| 1003 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->cpu_lpi / 1000000.0 / interval_float); |
| 1004 | if (DO_BIC(BIC_SYS_LPI)) |
| 1005 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->sys_lpi / 1000000.0 / interval_float); |
| 1006 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1007 | /* |
| 1008 | * If measurement interval exceeds minimum RAPL Joule Counter range, |
| 1009 | * indicate that results are suspect by printing "**" in fraction place. |
| 1010 | */ |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 1011 | if (interval_float < rapl_joule_counter_range) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1012 | fmt8 = "%s%.2f"; |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 1013 | else |
Len Brown | e975db5 | 2016-04-06 23:56:02 -0400 | [diff] [blame] | 1014 | fmt8 = "%6.0f**"; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1015 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1016 | if (DO_BIC(BIC_PkgWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1017 | 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] | 1018 | if (DO_BIC(BIC_CorWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1019 | 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] | 1020 | if (DO_BIC(BIC_GFXWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1021 | 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] | 1022 | if (DO_BIC(BIC_RAMWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1023 | 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] | 1024 | if (DO_BIC(BIC_Pkg_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1025 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_pkg * rapl_energy_units); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1026 | if (DO_BIC(BIC_Cor_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1027 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_cores * rapl_energy_units); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1028 | if (DO_BIC(BIC_GFX_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1029 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_gfx * rapl_energy_units); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1030 | if (DO_BIC(BIC_RAM_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1031 | 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] | 1032 | if (DO_BIC(BIC_PKG__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1033 | 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] | 1034 | if (DO_BIC(BIC_RAM__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1035 | 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] | 1036 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1037 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1038 | if (mp->format == FORMAT_RAW) { |
| 1039 | if (mp->width == 32) |
Len Brown | 5f3aea5 | 2017-02-23 18:10:27 -0500 | [diff] [blame] | 1040 | outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int) p->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1041 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1042 | outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), p->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1043 | } else if (mp->format == FORMAT_DELTA) { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1044 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1045 | outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), p->counter[i]); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1046 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1047 | outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), p->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1048 | } else if (mp->format == FORMAT_PERCENT) { |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1049 | 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] | 1050 | } |
| 1051 | } |
| 1052 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1053 | done: |
Len Brown | 94d6ab4 | 2018-01-27 22:39:21 -0500 | [diff] [blame] | 1054 | if (*(outp - 1) != '\n') |
| 1055 | outp += sprintf(outp, "\n"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1056 | |
| 1057 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1058 | } |
| 1059 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1060 | void flush_output_stdout(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1061 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1062 | FILE *filep; |
| 1063 | |
| 1064 | if (outf == stderr) |
| 1065 | filep = stdout; |
| 1066 | else |
| 1067 | filep = outf; |
| 1068 | |
| 1069 | fputs(output_buffer, filep); |
| 1070 | fflush(filep); |
| 1071 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1072 | outp = output_buffer; |
| 1073 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1074 | void flush_output_stderr(void) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1075 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1076 | fputs(output_buffer, outf); |
| 1077 | fflush(outf); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1078 | outp = output_buffer; |
| 1079 | } |
| 1080 | void format_all_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 1081 | { |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 1082 | static int printed; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1083 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 1084 | if (!printed || !summary_only) |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 1085 | print_header("\t"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1086 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1087 | if (topo.num_cpus > 1) |
| 1088 | format_counters(&average.threads, &average.cores, |
| 1089 | &average.packages); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1090 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 1091 | printed = 1; |
| 1092 | |
| 1093 | if (summary_only) |
| 1094 | return; |
| 1095 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1096 | for_all_cpus(format_counters, t, c, p); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1097 | } |
| 1098 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1099 | #define DELTA_WRAP32(new, old) \ |
| 1100 | if (new > old) { \ |
| 1101 | old = new - old; \ |
| 1102 | } else { \ |
| 1103 | old = 0x100000000 + new - old; \ |
| 1104 | } |
| 1105 | |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1106 | int |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1107 | delta_package(struct pkg_data *new, struct pkg_data *old) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1108 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1109 | int i; |
| 1110 | struct msr_counter *mp; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1111 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1112 | |
| 1113 | if (DO_BIC(BIC_Totl_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1114 | 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] | 1115 | if (DO_BIC(BIC_Any_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1116 | 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] | 1117 | if (DO_BIC(BIC_GFX_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1118 | 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] | 1119 | if (DO_BIC(BIC_CPUGFX)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1120 | 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] | 1121 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1122 | old->pc2 = new->pc2 - old->pc2; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1123 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1124 | old->pc3 = new->pc3 - old->pc3; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1125 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1126 | old->pc6 = new->pc6 - old->pc6; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1127 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1128 | old->pc7 = new->pc7 - old->pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1129 | old->pc8 = new->pc8 - old->pc8; |
| 1130 | old->pc9 = new->pc9 - old->pc9; |
| 1131 | old->pc10 = new->pc10 - old->pc10; |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 1132 | old->cpu_lpi = new->cpu_lpi - old->cpu_lpi; |
| 1133 | old->sys_lpi = new->sys_lpi - old->sys_lpi; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1134 | old->pkg_temp_c = new->pkg_temp_c; |
| 1135 | |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 1136 | /* flag an error when rc6 counter resets/wraps */ |
| 1137 | if (old->gfx_rc6_ms > new->gfx_rc6_ms) |
| 1138 | old->gfx_rc6_ms = -1; |
| 1139 | else |
| 1140 | old->gfx_rc6_ms = new->gfx_rc6_ms - old->gfx_rc6_ms; |
| 1141 | |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1142 | old->gfx_mhz = new->gfx_mhz; |
| 1143 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1144 | DELTA_WRAP32(new->energy_pkg, old->energy_pkg); |
| 1145 | DELTA_WRAP32(new->energy_cores, old->energy_cores); |
| 1146 | DELTA_WRAP32(new->energy_gfx, old->energy_gfx); |
| 1147 | DELTA_WRAP32(new->energy_dram, old->energy_dram); |
| 1148 | DELTA_WRAP32(new->rapl_pkg_perf_status, old->rapl_pkg_perf_status); |
| 1149 | DELTA_WRAP32(new->rapl_dram_perf_status, old->rapl_dram_perf_status); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1150 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1151 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1152 | if (mp->format == FORMAT_RAW) |
| 1153 | old->counter[i] = new->counter[i]; |
| 1154 | else |
| 1155 | old->counter[i] = new->counter[i] - old->counter[i]; |
| 1156 | } |
| 1157 | |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1158 | return 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1159 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1160 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1161 | void |
| 1162 | delta_core(struct core_data *new, struct core_data *old) |
| 1163 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1164 | int i; |
| 1165 | struct msr_counter *mp; |
| 1166 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1167 | old->c3 = new->c3 - old->c3; |
| 1168 | old->c6 = new->c6 - old->c6; |
| 1169 | old->c7 = new->c7 - old->c7; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1170 | old->core_temp_c = new->core_temp_c; |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1171 | old->mc6_us = new->mc6_us - old->mc6_us; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1172 | |
| 1173 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 1174 | if (mp->format == FORMAT_RAW) |
| 1175 | old->counter[i] = new->counter[i]; |
| 1176 | else |
| 1177 | old->counter[i] = new->counter[i] - old->counter[i]; |
| 1178 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1179 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1180 | |
Len Brown | c3ae331 | 2012-06-13 21:31:46 -0400 | [diff] [blame] | 1181 | /* |
| 1182 | * old = new - old |
| 1183 | */ |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1184 | int |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1185 | delta_thread(struct thread_data *new, struct thread_data *old, |
| 1186 | struct core_data *core_delta) |
| 1187 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1188 | int i; |
| 1189 | struct msr_counter *mp; |
| 1190 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 1191 | /* |
| 1192 | * the timestamps from start of measurement interval are in "old" |
| 1193 | * the timestamp from end of measurement interval are in "new" |
| 1194 | * over-write old w/ new so we can print end of interval values |
| 1195 | */ |
| 1196 | |
| 1197 | old->tv_begin = new->tv_begin; |
| 1198 | old->tv_end = new->tv_end; |
| 1199 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1200 | old->tsc = new->tsc - old->tsc; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1201 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1202 | /* check for TSC < 1 Mcycles over interval */ |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 1203 | if (old->tsc < (1000 * 1000)) |
| 1204 | errx(-3, "Insanely slow TSC rate, TSC stops in idle?\n" |
| 1205 | "You can disable all c-states by booting with \"idle=poll\"\n" |
| 1206 | "or just the deep ones with \"processor.max_cstate=1\""); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1207 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1208 | old->c1 = new->c1 - old->c1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1209 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1210 | 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] | 1211 | if ((new->aperf > old->aperf) && (new->mperf > old->mperf)) { |
| 1212 | old->aperf = new->aperf - old->aperf; |
| 1213 | old->mperf = new->mperf - old->mperf; |
| 1214 | } else { |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1215 | return -1; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1216 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1217 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1218 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1219 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1220 | if (use_c1_residency_msr) { |
| 1221 | /* |
| 1222 | * Some models have a dedicated C1 residency MSR, |
| 1223 | * which should be more accurate than the derivation below. |
| 1224 | */ |
| 1225 | } else { |
| 1226 | /* |
| 1227 | * As counter collection is not atomic, |
| 1228 | * it is possible for mperf's non-halted cycles + idle states |
| 1229 | * to exceed TSC's all cycles: show c1 = 0% in that case. |
| 1230 | */ |
Len Brown | 9514936 | 2017-04-12 19:44:51 -0400 | [diff] [blame] | 1231 | 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] | 1232 | old->c1 = 0; |
| 1233 | else { |
| 1234 | /* normal case, derive c1 */ |
Len Brown | 008d396e | 2017-02-10 00:29:51 -0500 | [diff] [blame] | 1235 | old->c1 = (old->tsc * tsc_tweak) - old->mperf - core_delta->c3 |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1236 | - core_delta->c6 - core_delta->c7; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1237 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1238 | } |
Len Brown | c3ae331 | 2012-06-13 21:31:46 -0400 | [diff] [blame] | 1239 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1240 | if (old->mperf == 0) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1241 | if (debug > 1) |
| 1242 | fprintf(outf, "cpu%d MPERF 0!\n", old->cpu_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1243 | old->mperf = 1; /* divide by 0 protection */ |
| 1244 | } |
| 1245 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1246 | if (DO_BIC(BIC_IRQ)) |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1247 | old->irq_count = new->irq_count - old->irq_count; |
| 1248 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1249 | if (DO_BIC(BIC_SMI)) |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 1250 | old->smi_count = new->smi_count - old->smi_count; |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1251 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1252 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 1253 | if (mp->format == FORMAT_RAW) |
| 1254 | old->counter[i] = new->counter[i]; |
| 1255 | else |
| 1256 | old->counter[i] = new->counter[i] - old->counter[i]; |
| 1257 | } |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1258 | return 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | int delta_cpu(struct thread_data *t, struct core_data *c, |
| 1262 | struct pkg_data *p, struct thread_data *t2, |
| 1263 | struct core_data *c2, struct pkg_data *p2) |
| 1264 | { |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1265 | int retval = 0; |
| 1266 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1267 | /* calculate core delta only for 1st thread in core */ |
| 1268 | if (t->flags & CPU_IS_FIRST_THREAD_IN_CORE) |
| 1269 | delta_core(c, c2); |
| 1270 | |
| 1271 | /* always calculate thread delta */ |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1272 | retval = delta_thread(t, t2, c2); /* c2 is core delta */ |
| 1273 | if (retval) |
| 1274 | return retval; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1275 | |
| 1276 | /* calculate package delta only for 1st core in package */ |
| 1277 | if (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE) |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1278 | retval = delta_package(p, p2); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1279 | |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1280 | return retval; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | void clear_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 1284 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1285 | int i; |
| 1286 | struct msr_counter *mp; |
| 1287 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 1288 | t->tv_begin.tv_sec = 0; |
| 1289 | t->tv_begin.tv_usec = 0; |
| 1290 | t->tv_end.tv_sec = 0; |
| 1291 | t->tv_end.tv_usec = 0; |
| 1292 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1293 | t->tsc = 0; |
| 1294 | t->aperf = 0; |
| 1295 | t->mperf = 0; |
| 1296 | t->c1 = 0; |
| 1297 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1298 | t->irq_count = 0; |
| 1299 | t->smi_count = 0; |
| 1300 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1301 | /* tells format_counters to dump all fields from this set */ |
| 1302 | t->flags = CPU_IS_FIRST_THREAD_IN_CORE | CPU_IS_FIRST_CORE_IN_PACKAGE; |
| 1303 | |
| 1304 | c->c3 = 0; |
| 1305 | c->c6 = 0; |
| 1306 | c->c7 = 0; |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1307 | c->mc6_us = 0; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1308 | c->core_temp_c = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1309 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1310 | p->pkg_wtd_core_c0 = 0; |
| 1311 | p->pkg_any_core_c0 = 0; |
| 1312 | p->pkg_any_gfxe_c0 = 0; |
| 1313 | p->pkg_both_core_gfxe_c0 = 0; |
| 1314 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1315 | p->pc2 = 0; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1316 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1317 | p->pc3 = 0; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1318 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1319 | p->pc6 = 0; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1320 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1321 | p->pc7 = 0; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1322 | p->pc8 = 0; |
| 1323 | p->pc9 = 0; |
| 1324 | p->pc10 = 0; |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 1325 | p->cpu_lpi = 0; |
| 1326 | p->sys_lpi = 0; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1327 | |
| 1328 | p->energy_pkg = 0; |
| 1329 | p->energy_dram = 0; |
| 1330 | p->energy_cores = 0; |
| 1331 | p->energy_gfx = 0; |
| 1332 | p->rapl_pkg_perf_status = 0; |
| 1333 | p->rapl_dram_perf_status = 0; |
| 1334 | p->pkg_temp_c = 0; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1335 | |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1336 | p->gfx_rc6_ms = 0; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1337 | p->gfx_mhz = 0; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1338 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) |
| 1339 | t->counter[i] = 0; |
| 1340 | |
| 1341 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) |
| 1342 | c->counter[i] = 0; |
| 1343 | |
| 1344 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) |
| 1345 | p->counter[i] = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1346 | } |
| 1347 | int sum_counters(struct thread_data *t, struct core_data *c, |
| 1348 | struct pkg_data *p) |
| 1349 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1350 | int i; |
| 1351 | struct msr_counter *mp; |
| 1352 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 1353 | /* remember first tv_begin */ |
| 1354 | if (average.threads.tv_begin.tv_sec == 0) |
| 1355 | average.threads.tv_begin = t->tv_begin; |
| 1356 | |
| 1357 | /* remember last tv_end */ |
| 1358 | average.threads.tv_end = t->tv_end; |
| 1359 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1360 | average.threads.tsc += t->tsc; |
| 1361 | average.threads.aperf += t->aperf; |
| 1362 | average.threads.mperf += t->mperf; |
| 1363 | average.threads.c1 += t->c1; |
| 1364 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1365 | average.threads.irq_count += t->irq_count; |
| 1366 | average.threads.smi_count += t->smi_count; |
| 1367 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1368 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 1369 | if (mp->format == FORMAT_RAW) |
| 1370 | continue; |
| 1371 | average.threads.counter[i] += t->counter[i]; |
| 1372 | } |
| 1373 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1374 | /* sum per-core values only for 1st thread in core */ |
| 1375 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 1376 | return 0; |
| 1377 | |
| 1378 | average.cores.c3 += c->c3; |
| 1379 | average.cores.c6 += c->c6; |
| 1380 | average.cores.c7 += c->c7; |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1381 | average.cores.mc6_us += c->mc6_us; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1382 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1383 | average.cores.core_temp_c = MAX(average.cores.core_temp_c, c->core_temp_c); |
| 1384 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1385 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 1386 | if (mp->format == FORMAT_RAW) |
| 1387 | continue; |
| 1388 | average.cores.counter[i] += c->counter[i]; |
| 1389 | } |
| 1390 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1391 | /* sum per-pkg values only for 1st core in pkg */ |
| 1392 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 1393 | return 0; |
| 1394 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1395 | if (DO_BIC(BIC_Totl_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1396 | average.packages.pkg_wtd_core_c0 += p->pkg_wtd_core_c0; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1397 | if (DO_BIC(BIC_Any_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1398 | average.packages.pkg_any_core_c0 += p->pkg_any_core_c0; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1399 | if (DO_BIC(BIC_GFX_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1400 | average.packages.pkg_any_gfxe_c0 += p->pkg_any_gfxe_c0; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1401 | if (DO_BIC(BIC_CPUGFX)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1402 | 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] | 1403 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1404 | average.packages.pc2 += p->pc2; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1405 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1406 | average.packages.pc3 += p->pc3; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1407 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1408 | average.packages.pc6 += p->pc6; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1409 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1410 | average.packages.pc7 += p->pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1411 | average.packages.pc8 += p->pc8; |
| 1412 | average.packages.pc9 += p->pc9; |
| 1413 | average.packages.pc10 += p->pc10; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1414 | |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 1415 | average.packages.cpu_lpi = p->cpu_lpi; |
| 1416 | average.packages.sys_lpi = p->sys_lpi; |
| 1417 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1418 | average.packages.energy_pkg += p->energy_pkg; |
| 1419 | average.packages.energy_dram += p->energy_dram; |
| 1420 | average.packages.energy_cores += p->energy_cores; |
| 1421 | average.packages.energy_gfx += p->energy_gfx; |
| 1422 | |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1423 | average.packages.gfx_rc6_ms = p->gfx_rc6_ms; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1424 | average.packages.gfx_mhz = p->gfx_mhz; |
| 1425 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1426 | average.packages.pkg_temp_c = MAX(average.packages.pkg_temp_c, p->pkg_temp_c); |
| 1427 | |
| 1428 | average.packages.rapl_pkg_perf_status += p->rapl_pkg_perf_status; |
| 1429 | average.packages.rapl_dram_perf_status += p->rapl_dram_perf_status; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1430 | |
| 1431 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1432 | if (mp->format == FORMAT_RAW) |
| 1433 | continue; |
| 1434 | average.packages.counter[i] += p->counter[i]; |
| 1435 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1436 | return 0; |
| 1437 | } |
| 1438 | /* |
| 1439 | * sum the counters for all cpus in the system |
| 1440 | * compute the weighted average |
| 1441 | */ |
| 1442 | void compute_average(struct thread_data *t, struct core_data *c, |
| 1443 | struct pkg_data *p) |
| 1444 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1445 | int i; |
| 1446 | struct msr_counter *mp; |
| 1447 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1448 | clear_counters(&average.threads, &average.cores, &average.packages); |
| 1449 | |
| 1450 | for_all_cpus(sum_counters, t, c, p); |
| 1451 | |
| 1452 | average.threads.tsc /= topo.num_cpus; |
| 1453 | average.threads.aperf /= topo.num_cpus; |
| 1454 | average.threads.mperf /= topo.num_cpus; |
| 1455 | average.threads.c1 /= topo.num_cpus; |
| 1456 | |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1457 | if (average.threads.irq_count > 9999999) |
| 1458 | sums_need_wide_columns = 1; |
| 1459 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1460 | average.cores.c3 /= topo.num_cores; |
| 1461 | average.cores.c6 /= topo.num_cores; |
| 1462 | average.cores.c7 /= topo.num_cores; |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1463 | average.cores.mc6_us /= topo.num_cores; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1464 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1465 | if (DO_BIC(BIC_Totl_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1466 | average.packages.pkg_wtd_core_c0 /= topo.num_packages; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1467 | if (DO_BIC(BIC_Any_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1468 | average.packages.pkg_any_core_c0 /= topo.num_packages; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1469 | if (DO_BIC(BIC_GFX_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1470 | average.packages.pkg_any_gfxe_c0 /= topo.num_packages; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1471 | if (DO_BIC(BIC_CPUGFX)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1472 | average.packages.pkg_both_core_gfxe_c0 /= topo.num_packages; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1473 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1474 | average.packages.pc2 /= topo.num_packages; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1475 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1476 | average.packages.pc3 /= topo.num_packages; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1477 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1478 | average.packages.pc6 /= topo.num_packages; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1479 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1480 | average.packages.pc7 /= topo.num_packages; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1481 | |
| 1482 | average.packages.pc8 /= topo.num_packages; |
| 1483 | average.packages.pc9 /= topo.num_packages; |
| 1484 | average.packages.pc10 /= topo.num_packages; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1485 | |
| 1486 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 1487 | if (mp->format == FORMAT_RAW) |
| 1488 | continue; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1489 | if (mp->type == COUNTER_ITEMS) { |
| 1490 | if (average.threads.counter[i] > 9999999) |
| 1491 | sums_need_wide_columns = 1; |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 1492 | continue; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1493 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1494 | average.threads.counter[i] /= topo.num_cpus; |
| 1495 | } |
| 1496 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 1497 | if (mp->format == FORMAT_RAW) |
| 1498 | continue; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1499 | if (mp->type == COUNTER_ITEMS) { |
| 1500 | if (average.cores.counter[i] > 9999999) |
| 1501 | sums_need_wide_columns = 1; |
| 1502 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1503 | average.cores.counter[i] /= topo.num_cores; |
| 1504 | } |
| 1505 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1506 | if (mp->format == FORMAT_RAW) |
| 1507 | continue; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1508 | if (mp->type == COUNTER_ITEMS) { |
| 1509 | if (average.packages.counter[i] > 9999999) |
| 1510 | sums_need_wide_columns = 1; |
| 1511 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1512 | average.packages.counter[i] /= topo.num_packages; |
| 1513 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | static unsigned long long rdtsc(void) |
| 1517 | { |
| 1518 | unsigned int low, high; |
| 1519 | |
| 1520 | asm volatile("rdtsc" : "=a" (low), "=d" (high)); |
| 1521 | |
| 1522 | return low | ((unsigned long long)high) << 32; |
| 1523 | } |
| 1524 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1525 | /* |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1526 | * Open a file, and exit on failure |
| 1527 | */ |
| 1528 | FILE *fopen_or_die(const char *path, const char *mode) |
| 1529 | { |
| 1530 | FILE *filep = fopen(path, mode); |
| 1531 | |
| 1532 | if (!filep) |
| 1533 | err(1, "%s: open failed", path); |
| 1534 | return filep; |
| 1535 | } |
| 1536 | /* |
| 1537 | * snapshot_sysfs_counter() |
| 1538 | * |
| 1539 | * return snapshot of given counter |
| 1540 | */ |
| 1541 | unsigned long long snapshot_sysfs_counter(char *path) |
| 1542 | { |
| 1543 | FILE *fp; |
| 1544 | int retval; |
| 1545 | unsigned long long counter; |
| 1546 | |
| 1547 | fp = fopen_or_die(path, "r"); |
| 1548 | |
| 1549 | retval = fscanf(fp, "%lld", &counter); |
| 1550 | if (retval != 1) |
| 1551 | err(1, "snapshot_sysfs_counter(%s)", path); |
| 1552 | |
| 1553 | fclose(fp); |
| 1554 | |
| 1555 | return counter; |
| 1556 | } |
| 1557 | |
| 1558 | int get_mp(int cpu, struct msr_counter *mp, unsigned long long *counterp) |
| 1559 | { |
| 1560 | if (mp->msr_num != 0) { |
| 1561 | if (get_msr(cpu, mp->msr_num, counterp)) |
| 1562 | return -1; |
| 1563 | } else { |
Len Brown | 46c2797 | 2017-12-08 17:38:17 -0500 | [diff] [blame] | 1564 | char path[128 + PATH_BYTES]; |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 1565 | |
| 1566 | if (mp->flags & SYSFS_PERCPU) { |
| 1567 | sprintf(path, "/sys/devices/system/cpu/cpu%d/%s", |
| 1568 | cpu, mp->path); |
| 1569 | |
| 1570 | *counterp = snapshot_sysfs_counter(path); |
| 1571 | } else { |
| 1572 | *counterp = snapshot_sysfs_counter(mp->path); |
| 1573 | } |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | return 0; |
| 1577 | } |
| 1578 | |
| 1579 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1580 | * get_counters(...) |
| 1581 | * migrate to cpu |
| 1582 | * acquire and record local counters for that cpu |
| 1583 | */ |
| 1584 | int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 1585 | { |
| 1586 | int cpu = t->cpu_id; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1587 | unsigned long long msr; |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1588 | int aperf_mperf_retry_count = 0; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1589 | struct msr_counter *mp; |
| 1590 | int i; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1591 | |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 1592 | |
| 1593 | gettimeofday(&t->tv_begin, (struct timezone *)NULL); |
| 1594 | |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 1595 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1596 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1597 | return -1; |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 1598 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1599 | |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1600 | retry: |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1601 | t->tsc = rdtsc(); /* we are running on local CPU of interest */ |
| 1602 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1603 | 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] | 1604 | unsigned long long tsc_before, tsc_between, tsc_after, aperf_time, mperf_time; |
| 1605 | |
| 1606 | /* |
| 1607 | * The TSC, APERF and MPERF must be read together for |
| 1608 | * APERF/MPERF and MPERF/TSC to give accurate results. |
| 1609 | * |
| 1610 | * Unfortunately, APERF and MPERF are read by |
| 1611 | * individual system call, so delays may occur |
| 1612 | * between them. If the time to read them |
| 1613 | * varies by a large amount, we re-read them. |
| 1614 | */ |
| 1615 | |
| 1616 | /* |
| 1617 | * This initial dummy APERF read has been seen to |
| 1618 | * reduce jitter in the subsequent reads. |
| 1619 | */ |
| 1620 | |
Len Brown | 9c63a65 | 2012-10-31 01:29:52 -0400 | [diff] [blame] | 1621 | if (get_msr(cpu, MSR_IA32_APERF, &t->aperf)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1622 | return -3; |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1623 | |
| 1624 | t->tsc = rdtsc(); /* re-read close to APERF */ |
| 1625 | |
| 1626 | tsc_before = t->tsc; |
| 1627 | |
| 1628 | if (get_msr(cpu, MSR_IA32_APERF, &t->aperf)) |
| 1629 | return -3; |
| 1630 | |
| 1631 | tsc_between = rdtsc(); |
| 1632 | |
Len Brown | 9c63a65 | 2012-10-31 01:29:52 -0400 | [diff] [blame] | 1633 | if (get_msr(cpu, MSR_IA32_MPERF, &t->mperf)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1634 | return -4; |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1635 | |
| 1636 | tsc_after = rdtsc(); |
| 1637 | |
| 1638 | aperf_time = tsc_between - tsc_before; |
| 1639 | mperf_time = tsc_after - tsc_between; |
| 1640 | |
| 1641 | /* |
| 1642 | * If the system call latency to read APERF and MPERF |
| 1643 | * differ by more than 2x, then try again. |
| 1644 | */ |
| 1645 | if ((aperf_time > (2 * mperf_time)) || (mperf_time > (2 * aperf_time))) { |
| 1646 | aperf_mperf_retry_count++; |
| 1647 | if (aperf_mperf_retry_count < 5) |
| 1648 | goto retry; |
| 1649 | else |
| 1650 | warnx("cpu%d jitter %lld %lld", |
| 1651 | cpu, aperf_time, mperf_time); |
| 1652 | } |
| 1653 | aperf_mperf_retry_count = 0; |
| 1654 | |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 1655 | t->aperf = t->aperf * aperf_mperf_multiplier; |
| 1656 | t->mperf = t->mperf * aperf_mperf_multiplier; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1657 | } |
| 1658 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1659 | if (DO_BIC(BIC_IRQ)) |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1660 | t->irq_count = irqs_per_cpu[cpu]; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1661 | if (DO_BIC(BIC_SMI)) { |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 1662 | if (get_msr(cpu, MSR_SMI_COUNT, &msr)) |
| 1663 | return -5; |
| 1664 | t->smi_count = msr & 0xFFFFFFFF; |
| 1665 | } |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1666 | if (DO_BIC(BIC_CPU_c1) && use_c1_residency_msr) { |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1667 | if (get_msr(cpu, MSR_CORE_C1_RES, &t->c1)) |
| 1668 | return -6; |
| 1669 | } |
| 1670 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1671 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1672 | if (get_mp(cpu, mp, &t->counter[i])) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1673 | return -10; |
| 1674 | } |
| 1675 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1676 | /* collect core counters only for 1st thread in core */ |
| 1677 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 1678 | goto done; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1679 | |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame^] | 1680 | if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates && !do_cnl_cstates) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1681 | if (get_msr(cpu, MSR_CORE_C3_RESIDENCY, &c->c3)) |
| 1682 | return -6; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1683 | } |
| 1684 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1685 | if (DO_BIC(BIC_CPU_c6) && !do_knl_cstates) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1686 | if (get_msr(cpu, MSR_CORE_C6_RESIDENCY, &c->c6)) |
| 1687 | return -7; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1688 | } else if (do_knl_cstates) { |
| 1689 | if (get_msr(cpu, MSR_KNL_CORE_C6_RESIDENCY, &c->c6)) |
| 1690 | return -7; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1691 | } |
| 1692 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1693 | if (DO_BIC(BIC_CPU_c7)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1694 | if (get_msr(cpu, MSR_CORE_C7_RESIDENCY, &c->c7)) |
| 1695 | return -8; |
| 1696 | |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1697 | if (DO_BIC(BIC_Mod_c6)) |
| 1698 | if (get_msr(cpu, MSR_MODULE_C6_RES_MS, &c->mc6_us)) |
| 1699 | return -8; |
| 1700 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1701 | if (DO_BIC(BIC_CoreTmp)) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1702 | if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr)) |
| 1703 | return -9; |
| 1704 | c->core_temp_c = tcc_activation_temp - ((msr >> 16) & 0x7F); |
| 1705 | } |
| 1706 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1707 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1708 | if (get_mp(cpu, mp, &c->counter[i])) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1709 | return -10; |
| 1710 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1711 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1712 | /* collect package counters only for 1st core in package */ |
| 1713 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 1714 | goto done; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1715 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1716 | if (DO_BIC(BIC_Totl_c0)) { |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1717 | if (get_msr(cpu, MSR_PKG_WEIGHTED_CORE_C0_RES, &p->pkg_wtd_core_c0)) |
| 1718 | return -10; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1719 | } |
| 1720 | if (DO_BIC(BIC_Any_c0)) { |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1721 | if (get_msr(cpu, MSR_PKG_ANY_CORE_C0_RES, &p->pkg_any_core_c0)) |
| 1722 | return -11; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1723 | } |
| 1724 | if (DO_BIC(BIC_GFX_c0)) { |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1725 | if (get_msr(cpu, MSR_PKG_ANY_GFXE_C0_RES, &p->pkg_any_gfxe_c0)) |
| 1726 | return -12; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1727 | } |
| 1728 | if (DO_BIC(BIC_CPUGFX)) { |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1729 | if (get_msr(cpu, MSR_PKG_BOTH_CORE_GFXE_C0_RES, &p->pkg_both_core_gfxe_c0)) |
| 1730 | return -13; |
| 1731 | } |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1732 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1733 | if (get_msr(cpu, MSR_PKG_C3_RESIDENCY, &p->pc3)) |
| 1734 | return -9; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1735 | if (DO_BIC(BIC_Pkgpc6)) { |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1736 | if (do_slm_cstates) { |
| 1737 | if (get_msr(cpu, MSR_ATOM_PKG_C6_RESIDENCY, &p->pc6)) |
| 1738 | return -10; |
| 1739 | } else { |
| 1740 | if (get_msr(cpu, MSR_PKG_C6_RESIDENCY, &p->pc6)) |
| 1741 | return -10; |
| 1742 | } |
| 1743 | } |
| 1744 | |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1745 | if (DO_BIC(BIC_Pkgpc2)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1746 | if (get_msr(cpu, MSR_PKG_C2_RESIDENCY, &p->pc2)) |
| 1747 | return -11; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1748 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1749 | if (get_msr(cpu, MSR_PKG_C7_RESIDENCY, &p->pc7)) |
| 1750 | return -12; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1751 | if (DO_BIC(BIC_Pkgpc8)) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1752 | if (get_msr(cpu, MSR_PKG_C8_RESIDENCY, &p->pc8)) |
| 1753 | return -13; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1754 | if (DO_BIC(BIC_Pkgpc9)) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1755 | if (get_msr(cpu, MSR_PKG_C9_RESIDENCY, &p->pc9)) |
| 1756 | return -13; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1757 | if (DO_BIC(BIC_Pkgpc10)) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1758 | if (get_msr(cpu, MSR_PKG_C10_RESIDENCY, &p->pc10)) |
| 1759 | return -13; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1760 | |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 1761 | if (DO_BIC(BIC_CPU_LPI)) |
| 1762 | p->cpu_lpi = cpuidle_cur_cpu_lpi_us; |
| 1763 | if (DO_BIC(BIC_SYS_LPI)) |
| 1764 | p->sys_lpi = cpuidle_cur_sys_lpi_us; |
| 1765 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1766 | if (do_rapl & RAPL_PKG) { |
| 1767 | if (get_msr(cpu, MSR_PKG_ENERGY_STATUS, &msr)) |
| 1768 | return -13; |
| 1769 | p->energy_pkg = msr & 0xFFFFFFFF; |
| 1770 | } |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 1771 | if (do_rapl & RAPL_CORES_ENERGY_STATUS) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1772 | if (get_msr(cpu, MSR_PP0_ENERGY_STATUS, &msr)) |
| 1773 | return -14; |
| 1774 | p->energy_cores = msr & 0xFFFFFFFF; |
| 1775 | } |
| 1776 | if (do_rapl & RAPL_DRAM) { |
| 1777 | if (get_msr(cpu, MSR_DRAM_ENERGY_STATUS, &msr)) |
| 1778 | return -15; |
| 1779 | p->energy_dram = msr & 0xFFFFFFFF; |
| 1780 | } |
| 1781 | if (do_rapl & RAPL_GFX) { |
| 1782 | if (get_msr(cpu, MSR_PP1_ENERGY_STATUS, &msr)) |
| 1783 | return -16; |
| 1784 | p->energy_gfx = msr & 0xFFFFFFFF; |
| 1785 | } |
| 1786 | if (do_rapl & RAPL_PKG_PERF_STATUS) { |
| 1787 | if (get_msr(cpu, MSR_PKG_PERF_STATUS, &msr)) |
| 1788 | return -16; |
| 1789 | p->rapl_pkg_perf_status = msr & 0xFFFFFFFF; |
| 1790 | } |
| 1791 | if (do_rapl & RAPL_DRAM_PERF_STATUS) { |
| 1792 | if (get_msr(cpu, MSR_DRAM_PERF_STATUS, &msr)) |
| 1793 | return -16; |
| 1794 | p->rapl_dram_perf_status = msr & 0xFFFFFFFF; |
| 1795 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1796 | if (DO_BIC(BIC_PkgTmp)) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1797 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr)) |
| 1798 | return -17; |
| 1799 | p->pkg_temp_c = tcc_activation_temp - ((msr >> 16) & 0x7F); |
| 1800 | } |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1801 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1802 | if (DO_BIC(BIC_GFX_rc6)) |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1803 | p->gfx_rc6_ms = gfx_cur_rc6_ms; |
| 1804 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1805 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1806 | p->gfx_mhz = gfx_cur_mhz; |
| 1807 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1808 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1809 | if (get_mp(cpu, mp, &p->counter[i])) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1810 | return -10; |
| 1811 | } |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 1812 | done: |
| 1813 | gettimeofday(&t->tv_end, (struct timezone *)NULL); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1814 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1815 | return 0; |
| 1816 | } |
| 1817 | |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1818 | /* |
| 1819 | * MSR_PKG_CST_CONFIG_CONTROL decoding for pkg_cstate_limit: |
| 1820 | * If you change the values, note they are used both in comparisons |
| 1821 | * (>= PCL__7) and to index pkg_cstate_limit_strings[]. |
| 1822 | */ |
| 1823 | |
| 1824 | #define PCLUKN 0 /* Unknown */ |
| 1825 | #define PCLRSV 1 /* Reserved */ |
| 1826 | #define PCL__0 2 /* PC0 */ |
| 1827 | #define PCL__1 3 /* PC1 */ |
| 1828 | #define PCL__2 4 /* PC2 */ |
| 1829 | #define PCL__3 5 /* PC3 */ |
| 1830 | #define PCL__4 6 /* PC4 */ |
| 1831 | #define PCL__6 7 /* PC6 */ |
| 1832 | #define PCL_6N 8 /* PC6 No Retention */ |
| 1833 | #define PCL_6R 9 /* PC6 Retention */ |
| 1834 | #define PCL__7 10 /* PC7 */ |
| 1835 | #define PCL_7S 11 /* PC7 Shrink */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1836 | #define PCL__8 12 /* PC8 */ |
| 1837 | #define PCL__9 13 /* PC9 */ |
| 1838 | #define PCLUNL 14 /* Unlimited */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1839 | |
| 1840 | int pkg_cstate_limit = PCLUKN; |
| 1841 | char *pkg_cstate_limit_strings[] = { "reserved", "unknown", "pc0", "pc1", "pc2", |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1842 | "pc3", "pc4", "pc6", "pc6n", "pc6r", "pc7", "pc7s", "pc8", "pc9", "unlimited"}; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1843 | |
Len Brown | e9257f5 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 1844 | 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}; |
| 1845 | 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}; |
| 1846 | int hsw_pkg_cstate_limits[16] = {PCL__0, PCL__2, PCL__3, PCL__6, PCL__7, PCL_7S, PCL__8, PCL__9, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1847 | 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] | 1848 | 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] | 1849 | 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] | 1850 | 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] | 1851 | 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] | 1852 | |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 1853 | |
| 1854 | static void |
| 1855 | calculate_tsc_tweak() |
| 1856 | { |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 1857 | tsc_tweak = base_hz / tsc_hz; |
| 1858 | } |
| 1859 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1860 | static void |
| 1861 | dump_nhm_platform_info(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1862 | { |
| 1863 | unsigned long long msr; |
| 1864 | unsigned int ratio; |
| 1865 | |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 1866 | get_msr(base_cpu, MSR_PLATFORM_INFO, &msr); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1867 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1868 | 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] | 1869 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1870 | ratio = (msr >> 40) & 0xFF; |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1871 | fprintf(outf, "%d * %.1f = %.1f MHz max efficiency frequency\n", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1872 | ratio, bclk, ratio * bclk); |
| 1873 | |
| 1874 | ratio = (msr >> 8) & 0xFF; |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1875 | fprintf(outf, "%d * %.1f = %.1f MHz base frequency\n", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1876 | ratio, bclk, ratio * bclk); |
| 1877 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1878 | get_msr(base_cpu, MSR_IA32_POWER_CTL, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1879 | 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] | 1880 | base_cpu, msr, msr & 0x2 ? "EN" : "DIS"); |
Len Brown | 6792041 | 2013-01-31 15:22:15 -0500 | [diff] [blame] | 1881 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1882 | return; |
| 1883 | } |
| 1884 | |
| 1885 | static void |
| 1886 | dump_hsw_turbo_ratio_limits(void) |
| 1887 | { |
| 1888 | unsigned long long msr; |
| 1889 | unsigned int ratio; |
| 1890 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1891 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT2, &msr); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1892 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1893 | 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] | 1894 | |
| 1895 | ratio = (msr >> 8) & 0xFF; |
| 1896 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1897 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 18 active cores\n", |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1898 | ratio, bclk, ratio * bclk); |
| 1899 | |
| 1900 | ratio = (msr >> 0) & 0xFF; |
| 1901 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1902 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 17 active cores\n", |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1903 | ratio, bclk, ratio * bclk); |
| 1904 | return; |
| 1905 | } |
| 1906 | |
| 1907 | static void |
| 1908 | dump_ivt_turbo_ratio_limits(void) |
| 1909 | { |
| 1910 | unsigned long long msr; |
| 1911 | unsigned int ratio; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1912 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1913 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT1, &msr); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1914 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1915 | 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] | 1916 | |
| 1917 | ratio = (msr >> 56) & 0xFF; |
| 1918 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1919 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 16 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1920 | ratio, bclk, ratio * bclk); |
| 1921 | |
| 1922 | ratio = (msr >> 48) & 0xFF; |
| 1923 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1924 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 15 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1925 | ratio, bclk, ratio * bclk); |
| 1926 | |
| 1927 | ratio = (msr >> 40) & 0xFF; |
| 1928 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1929 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 14 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1930 | ratio, bclk, ratio * bclk); |
| 1931 | |
| 1932 | ratio = (msr >> 32) & 0xFF; |
| 1933 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1934 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 13 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1935 | ratio, bclk, ratio * bclk); |
| 1936 | |
| 1937 | ratio = (msr >> 24) & 0xFF; |
| 1938 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1939 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 12 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1940 | ratio, bclk, ratio * bclk); |
| 1941 | |
| 1942 | ratio = (msr >> 16) & 0xFF; |
| 1943 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1944 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 11 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1945 | ratio, bclk, ratio * bclk); |
| 1946 | |
| 1947 | ratio = (msr >> 8) & 0xFF; |
| 1948 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1949 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 10 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1950 | ratio, bclk, ratio * bclk); |
| 1951 | |
| 1952 | ratio = (msr >> 0) & 0xFF; |
| 1953 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1954 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 9 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1955 | ratio, bclk, ratio * bclk); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1956 | return; |
| 1957 | } |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1958 | int has_turbo_ratio_group_limits(int family, int model) |
| 1959 | { |
| 1960 | |
| 1961 | if (!genuine_intel) |
| 1962 | return 0; |
| 1963 | |
| 1964 | switch (model) { |
| 1965 | case INTEL_FAM6_ATOM_GOLDMONT: |
| 1966 | case INTEL_FAM6_SKYLAKE_X: |
| 1967 | case INTEL_FAM6_ATOM_DENVERTON: |
| 1968 | return 1; |
| 1969 | } |
| 1970 | return 0; |
| 1971 | } |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1972 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1973 | static void |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1974 | dump_turbo_ratio_limits(int family, int model) |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1975 | { |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1976 | unsigned long long msr, core_counts; |
| 1977 | unsigned int ratio, group_size; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1978 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1979 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1980 | 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] | 1981 | |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1982 | if (has_turbo_ratio_group_limits(family, model)) { |
| 1983 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT1, &core_counts); |
| 1984 | fprintf(outf, "cpu%d: MSR_TURBO_RATIO_LIMIT1: 0x%08llx\n", base_cpu, core_counts); |
| 1985 | } else { |
| 1986 | core_counts = 0x0807060504030201; |
| 1987 | } |
| 1988 | |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1989 | ratio = (msr >> 56) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1990 | group_size = (core_counts >> 56) & 0xFF; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -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 | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1994 | |
| 1995 | ratio = (msr >> 48) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1996 | group_size = (core_counts >> 48) & 0xFF; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -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 | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2000 | |
| 2001 | ratio = (msr >> 40) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2002 | group_size = (core_counts >> 40) & 0xFF; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2003 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2004 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2005 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2006 | |
| 2007 | ratio = (msr >> 32) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2008 | group_size = (core_counts >> 32) & 0xFF; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2009 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2010 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2011 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2012 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2013 | ratio = (msr >> 24) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2014 | group_size = (core_counts >> 24) & 0xFF; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2015 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2016 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2017 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2018 | |
| 2019 | ratio = (msr >> 16) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2020 | group_size = (core_counts >> 16) & 0xFF; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2021 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2022 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2023 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2024 | |
| 2025 | ratio = (msr >> 8) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2026 | group_size = (core_counts >> 8) & 0xFF; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2027 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2028 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2029 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2030 | |
| 2031 | ratio = (msr >> 0) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2032 | group_size = (core_counts >> 0) & 0xFF; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2033 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2034 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2035 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2036 | return; |
| 2037 | } |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 2038 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2039 | static void |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 2040 | dump_atom_turbo_ratio_limits(void) |
| 2041 | { |
| 2042 | unsigned long long msr; |
| 2043 | unsigned int ratio; |
| 2044 | |
| 2045 | get_msr(base_cpu, MSR_ATOM_CORE_RATIOS, &msr); |
| 2046 | fprintf(outf, "cpu%d: MSR_ATOM_CORE_RATIOS: 0x%08llx\n", base_cpu, msr & 0xFFFFFFFF); |
| 2047 | |
| 2048 | ratio = (msr >> 0) & 0x3F; |
| 2049 | if (ratio) |
| 2050 | fprintf(outf, "%d * %.1f = %.1f MHz minimum operating frequency\n", |
| 2051 | ratio, bclk, ratio * bclk); |
| 2052 | |
| 2053 | ratio = (msr >> 8) & 0x3F; |
| 2054 | if (ratio) |
| 2055 | fprintf(outf, "%d * %.1f = %.1f MHz low frequency mode (LFM)\n", |
| 2056 | ratio, bclk, ratio * bclk); |
| 2057 | |
| 2058 | ratio = (msr >> 16) & 0x3F; |
| 2059 | if (ratio) |
| 2060 | fprintf(outf, "%d * %.1f = %.1f MHz base frequency\n", |
| 2061 | ratio, bclk, ratio * bclk); |
| 2062 | |
| 2063 | get_msr(base_cpu, MSR_ATOM_CORE_TURBO_RATIOS, &msr); |
| 2064 | fprintf(outf, "cpu%d: MSR_ATOM_CORE_TURBO_RATIOS: 0x%08llx\n", base_cpu, msr & 0xFFFFFFFF); |
| 2065 | |
| 2066 | ratio = (msr >> 24) & 0x3F; |
| 2067 | if (ratio) |
| 2068 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 4 active cores\n", |
| 2069 | ratio, bclk, ratio * bclk); |
| 2070 | |
| 2071 | ratio = (msr >> 16) & 0x3F; |
| 2072 | if (ratio) |
| 2073 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 3 active cores\n", |
| 2074 | ratio, bclk, ratio * bclk); |
| 2075 | |
| 2076 | ratio = (msr >> 8) & 0x3F; |
| 2077 | if (ratio) |
| 2078 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 2 active cores\n", |
| 2079 | ratio, bclk, ratio * bclk); |
| 2080 | |
| 2081 | ratio = (msr >> 0) & 0x3F; |
| 2082 | if (ratio) |
| 2083 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 1 active core\n", |
| 2084 | ratio, bclk, ratio * bclk); |
| 2085 | } |
| 2086 | |
| 2087 | static void |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2088 | dump_knl_turbo_ratio_limits(void) |
| 2089 | { |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2090 | const unsigned int buckets_no = 7; |
| 2091 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2092 | unsigned long long msr; |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2093 | int delta_cores, delta_ratio; |
| 2094 | int i, b_nr; |
| 2095 | unsigned int cores[buckets_no]; |
| 2096 | unsigned int ratio[buckets_no]; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2097 | |
Srinivas Pandruvada | ebf5926 | 2016-07-06 16:07:56 -0700 | [diff] [blame] | 2098 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT, &msr); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2099 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2100 | fprintf(outf, "cpu%d: MSR_TURBO_RATIO_LIMIT: 0x%08llx\n", |
Len Brown | bfae205 | 2015-06-17 12:27:21 -0400 | [diff] [blame] | 2101 | base_cpu, msr); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2102 | |
| 2103 | /** |
| 2104 | * Turbo encoding in KNL is as follows: |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2105 | * [0] -- Reserved |
| 2106 | * [7:1] -- Base value of number of active cores of bucket 1. |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2107 | * [15:8] -- Base value of freq ratio of bucket 1. |
| 2108 | * [20:16] -- +ve delta of number of active cores of bucket 2. |
| 2109 | * i.e. active cores of bucket 2 = |
| 2110 | * active cores of bucket 1 + delta |
| 2111 | * [23:21] -- Negative delta of freq ratio of bucket 2. |
| 2112 | * i.e. freq ratio of bucket 2 = |
| 2113 | * freq ratio of bucket 1 - delta |
| 2114 | * [28:24]-- +ve delta of number of active cores of bucket 3. |
| 2115 | * [31:29]-- -ve delta of freq ratio of bucket 3. |
| 2116 | * [36:32]-- +ve delta of number of active cores of bucket 4. |
| 2117 | * [39:37]-- -ve delta of freq ratio of bucket 4. |
| 2118 | * [44:40]-- +ve delta of number of active cores of bucket 5. |
| 2119 | * [47:45]-- -ve delta of freq ratio of bucket 5. |
| 2120 | * [52:48]-- +ve delta of number of active cores of bucket 6. |
| 2121 | * [55:53]-- -ve delta of freq ratio of bucket 6. |
| 2122 | * [60:56]-- +ve delta of number of active cores of bucket 7. |
| 2123 | * [63:61]-- -ve delta of freq ratio of bucket 7. |
| 2124 | */ |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2125 | |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2126 | b_nr = 0; |
| 2127 | cores[b_nr] = (msr & 0xFF) >> 1; |
| 2128 | ratio[b_nr] = (msr >> 8) & 0xFF; |
| 2129 | |
| 2130 | for (i = 16; i < 64; i += 8) { |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2131 | delta_cores = (msr >> i) & 0x1F; |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2132 | delta_ratio = (msr >> (i + 5)) & 0x7; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2133 | |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2134 | cores[b_nr + 1] = cores[b_nr] + delta_cores; |
| 2135 | ratio[b_nr + 1] = ratio[b_nr] - delta_ratio; |
| 2136 | b_nr++; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2137 | } |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2138 | |
| 2139 | for (i = buckets_no - 1; i >= 0; i--) |
| 2140 | if (i > 0 ? ratio[i] != ratio[i - 1] : 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2141 | fprintf(outf, |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 2142 | "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2143 | ratio[i], bclk, ratio[i] * bclk, cores[i]); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | static void |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2147 | dump_nhm_cst_cfg(void) |
| 2148 | { |
| 2149 | unsigned long long msr; |
| 2150 | |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 2151 | get_msr(base_cpu, MSR_PKG_CST_CONFIG_CONTROL, &msr); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2152 | |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 2153 | 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] | 2154 | |
Artem Bityutskiy | 3e8b62b | 2017-09-05 15:25:42 +0300 | [diff] [blame] | 2155 | fprintf(outf, " (%s%s%s%s%slocked, pkg-cstate-limit=%d (%s)", |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2156 | (msr & SNB_C3_AUTO_UNDEMOTE) ? "UNdemote-C3, " : "", |
| 2157 | (msr & SNB_C1_AUTO_UNDEMOTE) ? "UNdemote-C1, " : "", |
| 2158 | (msr & NHM_C3_AUTO_DEMOTE) ? "demote-C3, " : "", |
| 2159 | (msr & NHM_C1_AUTO_DEMOTE) ? "demote-C1, " : "", |
| 2160 | (msr & (1 << 15)) ? "" : "UN", |
Len Brown | 6c34f16 | 2016-03-13 03:21:22 -0400 | [diff] [blame] | 2161 | (unsigned int)msr & 0xF, |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2162 | pkg_cstate_limit_strings[pkg_cstate_limit]); |
Artem Bityutskiy | ac980e1 | 2017-09-05 15:14:08 +0300 | [diff] [blame] | 2163 | |
| 2164 | #define AUTOMATIC_CSTATE_CONVERSION (1UL << 16) |
| 2165 | if (has_automatic_cstate_conversion) { |
| 2166 | fprintf(outf, ", automatic c-state conversion=%s", |
| 2167 | (msr & AUTOMATIC_CSTATE_CONVERSION) ? "on" : "off"); |
| 2168 | } |
| 2169 | |
| 2170 | fprintf(outf, ")\n"); |
| 2171 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2172 | return; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2173 | } |
| 2174 | |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2175 | static void |
| 2176 | dump_config_tdp(void) |
| 2177 | { |
| 2178 | unsigned long long msr; |
| 2179 | |
| 2180 | get_msr(base_cpu, MSR_CONFIG_TDP_NOMINAL, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2181 | 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] | 2182 | fprintf(outf, " (base_ratio=%d)\n", (unsigned int)msr & 0xFF); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2183 | |
| 2184 | get_msr(base_cpu, MSR_CONFIG_TDP_LEVEL_1, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2185 | 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] | 2186 | if (msr) { |
Chen Yu | 685b535 | 2015-12-13 21:09:31 +0800 | [diff] [blame] | 2187 | fprintf(outf, "PKG_MIN_PWR_LVL1=%d ", (unsigned int)(msr >> 48) & 0x7FFF); |
| 2188 | fprintf(outf, "PKG_MAX_PWR_LVL1=%d ", (unsigned int)(msr >> 32) & 0x7FFF); |
| 2189 | fprintf(outf, "LVL1_RATIO=%d ", (unsigned int)(msr >> 16) & 0xFF); |
| 2190 | fprintf(outf, "PKG_TDP_LVL1=%d", (unsigned int)(msr) & 0x7FFF); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2191 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2192 | fprintf(outf, ")\n"); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2193 | |
| 2194 | get_msr(base_cpu, MSR_CONFIG_TDP_LEVEL_2, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2195 | 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] | 2196 | if (msr) { |
Chen Yu | 685b535 | 2015-12-13 21:09:31 +0800 | [diff] [blame] | 2197 | fprintf(outf, "PKG_MIN_PWR_LVL2=%d ", (unsigned int)(msr >> 48) & 0x7FFF); |
| 2198 | fprintf(outf, "PKG_MAX_PWR_LVL2=%d ", (unsigned int)(msr >> 32) & 0x7FFF); |
| 2199 | fprintf(outf, "LVL2_RATIO=%d ", (unsigned int)(msr >> 16) & 0xFF); |
| 2200 | fprintf(outf, "PKG_TDP_LVL2=%d", (unsigned int)(msr) & 0x7FFF); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2201 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2202 | fprintf(outf, ")\n"); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2203 | |
| 2204 | get_msr(base_cpu, MSR_CONFIG_TDP_CONTROL, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2205 | 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] | 2206 | if ((msr) & 0x3) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2207 | fprintf(outf, "TDP_LEVEL=%d ", (unsigned int)(msr) & 0x3); |
| 2208 | fprintf(outf, " lock=%d", (unsigned int)(msr >> 31) & 1); |
| 2209 | fprintf(outf, ")\n"); |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2210 | |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2211 | get_msr(base_cpu, MSR_TURBO_ACTIVATION_RATIO, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2212 | 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] | 2213 | fprintf(outf, "MAX_NON_TURBO_RATIO=%d", (unsigned int)(msr) & 0xFF); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2214 | fprintf(outf, " lock=%d", (unsigned int)(msr >> 31) & 1); |
| 2215 | fprintf(outf, ")\n"); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2216 | } |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 2217 | |
| 2218 | unsigned int irtl_time_units[] = {1, 32, 1024, 32768, 1048576, 33554432, 0, 0 }; |
| 2219 | |
| 2220 | void print_irtl(void) |
| 2221 | { |
| 2222 | unsigned long long msr; |
| 2223 | |
| 2224 | get_msr(base_cpu, MSR_PKGC3_IRTL, &msr); |
| 2225 | fprintf(outf, "cpu%d: MSR_PKGC3_IRTL: 0x%08llx (", base_cpu, msr); |
| 2226 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2227 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2228 | |
| 2229 | get_msr(base_cpu, MSR_PKGC6_IRTL, &msr); |
| 2230 | fprintf(outf, "cpu%d: MSR_PKGC6_IRTL: 0x%08llx (", base_cpu, msr); |
| 2231 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2232 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2233 | |
| 2234 | get_msr(base_cpu, MSR_PKGC7_IRTL, &msr); |
| 2235 | fprintf(outf, "cpu%d: MSR_PKGC7_IRTL: 0x%08llx (", base_cpu, msr); |
| 2236 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2237 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2238 | |
| 2239 | if (!do_irtl_hsw) |
| 2240 | return; |
| 2241 | |
| 2242 | get_msr(base_cpu, MSR_PKGC8_IRTL, &msr); |
| 2243 | fprintf(outf, "cpu%d: MSR_PKGC8_IRTL: 0x%08llx (", base_cpu, msr); |
| 2244 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2245 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2246 | |
| 2247 | get_msr(base_cpu, MSR_PKGC9_IRTL, &msr); |
| 2248 | fprintf(outf, "cpu%d: MSR_PKGC9_IRTL: 0x%08llx (", base_cpu, msr); |
| 2249 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2250 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2251 | |
| 2252 | get_msr(base_cpu, MSR_PKGC10_IRTL, &msr); |
| 2253 | fprintf(outf, "cpu%d: MSR_PKGC10_IRTL: 0x%08llx (", base_cpu, msr); |
| 2254 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2255 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2256 | |
| 2257 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2258 | void free_fd_percpu(void) |
| 2259 | { |
| 2260 | int i; |
| 2261 | |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 2262 | for (i = 0; i < topo.max_cpu_num + 1; ++i) { |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2263 | if (fd_percpu[i] != 0) |
| 2264 | close(fd_percpu[i]); |
| 2265 | } |
| 2266 | |
| 2267 | free(fd_percpu); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2268 | } |
| 2269 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2270 | void free_all_buffers(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2271 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2272 | CPU_FREE(cpu_present_set); |
| 2273 | cpu_present_set = NULL; |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2274 | cpu_present_setsize = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2275 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2276 | CPU_FREE(cpu_affinity_set); |
| 2277 | cpu_affinity_set = NULL; |
| 2278 | cpu_affinity_setsize = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2279 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2280 | free(thread_even); |
| 2281 | free(core_even); |
| 2282 | free(package_even); |
| 2283 | |
| 2284 | thread_even = NULL; |
| 2285 | core_even = NULL; |
| 2286 | package_even = NULL; |
| 2287 | |
| 2288 | free(thread_odd); |
| 2289 | free(core_odd); |
| 2290 | free(package_odd); |
| 2291 | |
| 2292 | thread_odd = NULL; |
| 2293 | core_odd = NULL; |
| 2294 | package_odd = NULL; |
| 2295 | |
| 2296 | free(output_buffer); |
| 2297 | output_buffer = NULL; |
| 2298 | outp = NULL; |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2299 | |
| 2300 | free_fd_percpu(); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2301 | |
| 2302 | free(irq_column_2_cpu); |
| 2303 | free(irqs_per_cpu); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2304 | } |
| 2305 | |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 2306 | |
| 2307 | /* |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2308 | * Parse a file containing a single int. |
| 2309 | */ |
| 2310 | int parse_int_file(const char *fmt, ...) |
| 2311 | { |
| 2312 | va_list args; |
| 2313 | char path[PATH_MAX]; |
| 2314 | FILE *filep; |
| 2315 | int value; |
| 2316 | |
| 2317 | va_start(args, fmt); |
| 2318 | vsnprintf(path, sizeof(path), fmt, args); |
| 2319 | va_end(args); |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 2320 | filep = fopen_or_die(path, "r"); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 2321 | if (fscanf(filep, "%d", &value) != 1) |
| 2322 | err(1, "%s: failed to parse number from file", path); |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2323 | fclose(filep); |
| 2324 | return value; |
| 2325 | } |
| 2326 | |
| 2327 | /* |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2328 | * get_cpu_position_in_core(cpu) |
| 2329 | * return the position of the CPU among its HT siblings in the core |
| 2330 | * return -1 if the sibling is not in list |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2331 | */ |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2332 | int get_cpu_position_in_core(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2333 | { |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2334 | char path[64]; |
| 2335 | FILE *filep; |
| 2336 | int this_cpu; |
| 2337 | char character; |
| 2338 | int i; |
| 2339 | |
| 2340 | sprintf(path, |
| 2341 | "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", |
| 2342 | cpu); |
| 2343 | filep = fopen(path, "r"); |
| 2344 | if (filep == NULL) { |
| 2345 | perror(path); |
| 2346 | exit(1); |
| 2347 | } |
| 2348 | |
| 2349 | for (i = 0; i < topo.num_threads_per_core; i++) { |
| 2350 | fscanf(filep, "%d", &this_cpu); |
| 2351 | if (this_cpu == cpu) { |
| 2352 | fclose(filep); |
| 2353 | return i; |
| 2354 | } |
| 2355 | |
| 2356 | /* Account for no separator after last thread*/ |
| 2357 | if (i != (topo.num_threads_per_core - 1)) |
| 2358 | fscanf(filep, "%c", &character); |
| 2359 | } |
| 2360 | |
| 2361 | fclose(filep); |
| 2362 | return -1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2363 | } |
| 2364 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2365 | /* |
| 2366 | * cpu_is_first_core_in_package(cpu) |
| 2367 | * return 1 if given CPU is 1st core in package |
| 2368 | */ |
| 2369 | int cpu_is_first_core_in_package(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2370 | { |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2371 | 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] | 2372 | } |
| 2373 | |
| 2374 | int get_physical_package_id(int cpu) |
| 2375 | { |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2376 | 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] | 2377 | } |
| 2378 | |
| 2379 | int get_core_id(int cpu) |
| 2380 | { |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2381 | 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] | 2382 | } |
| 2383 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2384 | int get_num_ht_siblings(int cpu) |
| 2385 | { |
| 2386 | char path[80]; |
| 2387 | FILE *filep; |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2388 | int sib1; |
| 2389 | int matches = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2390 | char character; |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2391 | char str[100]; |
| 2392 | char *ch; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2393 | |
| 2394 | 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] | 2395 | filep = fopen_or_die(path, "r"); |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2396 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2397 | /* |
| 2398 | * file format: |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2399 | * A ',' separated or '-' separated set of numbers |
| 2400 | * (eg 1-2 or 1,3,4,5) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2401 | */ |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2402 | fscanf(filep, "%d%c\n", &sib1, &character); |
| 2403 | fseek(filep, 0, SEEK_SET); |
| 2404 | fgets(str, 100, filep); |
| 2405 | ch = strchr(str, character); |
| 2406 | while (ch != NULL) { |
| 2407 | matches++; |
| 2408 | ch = strchr(ch+1, character); |
| 2409 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2410 | |
| 2411 | fclose(filep); |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2412 | return matches+1; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2413 | } |
| 2414 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2415 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2416 | * run func(thread, core, package) in topology order |
| 2417 | * skip non-present cpus |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2418 | */ |
| 2419 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2420 | int for_all_cpus_2(int (func)(struct thread_data *, struct core_data *, |
| 2421 | struct pkg_data *, struct thread_data *, struct core_data *, |
| 2422 | struct pkg_data *), struct thread_data *thread_base, |
| 2423 | struct core_data *core_base, struct pkg_data *pkg_base, |
| 2424 | struct thread_data *thread_base2, struct core_data *core_base2, |
| 2425 | struct pkg_data *pkg_base2) |
| 2426 | { |
| 2427 | int retval, pkg_no, core_no, thread_no; |
| 2428 | |
| 2429 | for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { |
| 2430 | for (core_no = 0; core_no < topo.num_cores_per_pkg; ++core_no) { |
| 2431 | for (thread_no = 0; thread_no < |
| 2432 | topo.num_threads_per_core; ++thread_no) { |
| 2433 | struct thread_data *t, *t2; |
| 2434 | struct core_data *c, *c2; |
| 2435 | struct pkg_data *p, *p2; |
| 2436 | |
| 2437 | t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); |
| 2438 | |
| 2439 | if (cpu_is_not_present(t->cpu_id)) |
| 2440 | continue; |
| 2441 | |
| 2442 | t2 = GET_THREAD(thread_base2, thread_no, core_no, pkg_no); |
| 2443 | |
| 2444 | c = GET_CORE(core_base, core_no, pkg_no); |
| 2445 | c2 = GET_CORE(core_base2, core_no, pkg_no); |
| 2446 | |
| 2447 | p = GET_PKG(pkg_base, pkg_no); |
| 2448 | p2 = GET_PKG(pkg_base2, pkg_no); |
| 2449 | |
| 2450 | retval = func(t, c, p, t2, c2, p2); |
| 2451 | if (retval) |
| 2452 | return retval; |
| 2453 | } |
| 2454 | } |
| 2455 | } |
| 2456 | return 0; |
| 2457 | } |
| 2458 | |
| 2459 | /* |
| 2460 | * run func(cpu) on every cpu in /proc/stat |
| 2461 | * return max_cpu number |
| 2462 | */ |
| 2463 | int for_all_proc_cpus(int (func)(int)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2464 | { |
| 2465 | FILE *fp; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2466 | int cpu_num; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2467 | int retval; |
| 2468 | |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 2469 | fp = fopen_or_die(proc_stat, "r"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2470 | |
| 2471 | 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] | 2472 | if (retval != 0) |
| 2473 | err(1, "%s: failed to parse format", proc_stat); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2474 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2475 | while (1) { |
| 2476 | 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] | 2477 | if (retval != 1) |
| 2478 | break; |
| 2479 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2480 | retval = func(cpu_num); |
| 2481 | if (retval) { |
| 2482 | fclose(fp); |
| 2483 | return(retval); |
| 2484 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2485 | } |
| 2486 | fclose(fp); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2487 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2488 | } |
| 2489 | |
| 2490 | void re_initialize(void) |
| 2491 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2492 | free_all_buffers(); |
| 2493 | setup_all_buffers(); |
| 2494 | printf("turbostat: re-initialized with num_cpus %d\n", topo.num_cpus); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2495 | } |
| 2496 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2497 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2498 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2499 | * count_cpus() |
| 2500 | * remember the last one seen, it will be the max |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2501 | */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2502 | int count_cpus(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2503 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2504 | if (topo.max_cpu_num < cpu) |
| 2505 | topo.max_cpu_num = cpu; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2506 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2507 | topo.num_cpus += 1; |
| 2508 | return 0; |
| 2509 | } |
| 2510 | int mark_cpu_present(int cpu) |
| 2511 | { |
| 2512 | CPU_SET_S(cpu, cpu_present_setsize, cpu_present_set); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 2513 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2514 | } |
| 2515 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2516 | /* |
| 2517 | * snapshot_proc_interrupts() |
| 2518 | * |
| 2519 | * read and record summary of /proc/interrupts |
| 2520 | * |
| 2521 | * return 1 if config change requires a restart, else return 0 |
| 2522 | */ |
| 2523 | int snapshot_proc_interrupts(void) |
| 2524 | { |
| 2525 | static FILE *fp; |
| 2526 | int column, retval; |
| 2527 | |
| 2528 | if (fp == NULL) |
| 2529 | fp = fopen_or_die("/proc/interrupts", "r"); |
| 2530 | else |
| 2531 | rewind(fp); |
| 2532 | |
| 2533 | /* read 1st line of /proc/interrupts to get cpu* name for each column */ |
| 2534 | for (column = 0; column < topo.num_cpus; ++column) { |
| 2535 | int cpu_number; |
| 2536 | |
| 2537 | retval = fscanf(fp, " CPU%d", &cpu_number); |
| 2538 | if (retval != 1) |
| 2539 | break; |
| 2540 | |
| 2541 | if (cpu_number > topo.max_cpu_num) { |
| 2542 | warn("/proc/interrupts: cpu%d: > %d", cpu_number, topo.max_cpu_num); |
| 2543 | return 1; |
| 2544 | } |
| 2545 | |
| 2546 | irq_column_2_cpu[column] = cpu_number; |
| 2547 | irqs_per_cpu[cpu_number] = 0; |
| 2548 | } |
| 2549 | |
| 2550 | /* read /proc/interrupt count lines and sum up irqs per cpu */ |
| 2551 | while (1) { |
| 2552 | int column; |
| 2553 | char buf[64]; |
| 2554 | |
| 2555 | retval = fscanf(fp, " %s:", buf); /* flush irq# "N:" */ |
| 2556 | if (retval != 1) |
| 2557 | break; |
| 2558 | |
| 2559 | /* read the count per cpu */ |
| 2560 | for (column = 0; column < topo.num_cpus; ++column) { |
| 2561 | |
| 2562 | int cpu_number, irq_count; |
| 2563 | |
| 2564 | retval = fscanf(fp, " %d", &irq_count); |
| 2565 | if (retval != 1) |
| 2566 | break; |
| 2567 | |
| 2568 | cpu_number = irq_column_2_cpu[column]; |
| 2569 | irqs_per_cpu[cpu_number] += irq_count; |
| 2570 | |
| 2571 | } |
| 2572 | |
| 2573 | while (getc(fp) != '\n') |
| 2574 | ; /* flush interrupt description */ |
| 2575 | |
| 2576 | } |
| 2577 | return 0; |
| 2578 | } |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2579 | /* |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 2580 | * snapshot_gfx_rc6_ms() |
| 2581 | * |
| 2582 | * record snapshot of |
| 2583 | * /sys/class/drm/card0/power/rc6_residency_ms |
| 2584 | * |
| 2585 | * return 1 if config change requires a restart, else return 0 |
| 2586 | */ |
| 2587 | int snapshot_gfx_rc6_ms(void) |
| 2588 | { |
| 2589 | FILE *fp; |
| 2590 | int retval; |
| 2591 | |
| 2592 | fp = fopen_or_die("/sys/class/drm/card0/power/rc6_residency_ms", "r"); |
| 2593 | |
| 2594 | retval = fscanf(fp, "%lld", &gfx_cur_rc6_ms); |
| 2595 | if (retval != 1) |
| 2596 | err(1, "GFX rc6"); |
| 2597 | |
| 2598 | fclose(fp); |
| 2599 | |
| 2600 | return 0; |
| 2601 | } |
| 2602 | /* |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2603 | * snapshot_gfx_mhz() |
| 2604 | * |
| 2605 | * record snapshot of |
| 2606 | * /sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz |
| 2607 | * |
| 2608 | * return 1 if config change requires a restart, else return 0 |
| 2609 | */ |
| 2610 | int snapshot_gfx_mhz(void) |
| 2611 | { |
| 2612 | static FILE *fp; |
| 2613 | int retval; |
| 2614 | |
| 2615 | if (fp == NULL) |
| 2616 | 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] | 2617 | else { |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2618 | rewind(fp); |
Len Brown | 22048c5 | 2017-03-04 15:42:48 -0500 | [diff] [blame] | 2619 | fflush(fp); |
| 2620 | } |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2621 | |
| 2622 | retval = fscanf(fp, "%d", &gfx_cur_mhz); |
| 2623 | if (retval != 1) |
| 2624 | err(1, "GFX MHz"); |
| 2625 | |
| 2626 | return 0; |
| 2627 | } |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2628 | |
| 2629 | /* |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 2630 | * snapshot_cpu_lpi() |
| 2631 | * |
| 2632 | * record snapshot of |
| 2633 | * /sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us |
| 2634 | * |
| 2635 | * return 1 if config change requires a restart, else return 0 |
| 2636 | */ |
| 2637 | int snapshot_cpu_lpi_us(void) |
| 2638 | { |
| 2639 | FILE *fp; |
| 2640 | int retval; |
| 2641 | |
| 2642 | fp = fopen_or_die("/sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us", "r"); |
| 2643 | |
| 2644 | retval = fscanf(fp, "%lld", &cpuidle_cur_cpu_lpi_us); |
| 2645 | if (retval != 1) |
| 2646 | err(1, "CPU LPI"); |
| 2647 | |
| 2648 | fclose(fp); |
| 2649 | |
| 2650 | return 0; |
| 2651 | } |
| 2652 | /* |
| 2653 | * snapshot_sys_lpi() |
| 2654 | * |
| 2655 | * record snapshot of |
| 2656 | * /sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us |
| 2657 | * |
| 2658 | * return 1 if config change requires a restart, else return 0 |
| 2659 | */ |
| 2660 | int snapshot_sys_lpi_us(void) |
| 2661 | { |
| 2662 | FILE *fp; |
| 2663 | int retval; |
| 2664 | |
| 2665 | fp = fopen_or_die("/sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us", "r"); |
| 2666 | |
| 2667 | retval = fscanf(fp, "%lld", &cpuidle_cur_sys_lpi_us); |
| 2668 | if (retval != 1) |
| 2669 | err(1, "SYS LPI"); |
| 2670 | |
| 2671 | fclose(fp); |
| 2672 | |
| 2673 | return 0; |
| 2674 | } |
| 2675 | /* |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2676 | * snapshot /proc and /sys files |
| 2677 | * |
| 2678 | * return 1 if configuration restart needed, else return 0 |
| 2679 | */ |
| 2680 | int snapshot_proc_sysfs_files(void) |
| 2681 | { |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 2682 | if (DO_BIC(BIC_IRQ)) |
| 2683 | if (snapshot_proc_interrupts()) |
| 2684 | return 1; |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2685 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 2686 | if (DO_BIC(BIC_GFX_rc6)) |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 2687 | snapshot_gfx_rc6_ms(); |
| 2688 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 2689 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2690 | snapshot_gfx_mhz(); |
| 2691 | |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 2692 | if (DO_BIC(BIC_CPU_LPI)) |
| 2693 | snapshot_cpu_lpi_us(); |
| 2694 | |
| 2695 | if (DO_BIC(BIC_SYS_LPI)) |
| 2696 | snapshot_sys_lpi_us(); |
| 2697 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2698 | return 0; |
| 2699 | } |
| 2700 | |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2701 | int exit_requested; |
| 2702 | |
| 2703 | static void signal_handler (int signal) |
| 2704 | { |
| 2705 | switch (signal) { |
| 2706 | case SIGINT: |
| 2707 | exit_requested = 1; |
| 2708 | if (debug) |
| 2709 | fprintf(stderr, " SIGINT\n"); |
| 2710 | break; |
Len Brown | 0721196 | 2017-07-15 15:51:26 -0400 | [diff] [blame] | 2711 | case SIGUSR1: |
| 2712 | if (debug > 1) |
| 2713 | fprintf(stderr, "SIGUSR1\n"); |
| 2714 | break; |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2715 | } |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2716 | /* make sure this manually-invoked interval is at least 1ms long */ |
| 2717 | nanosleep(&one_msec, NULL); |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2718 | } |
| 2719 | |
| 2720 | void setup_signal_handler(void) |
| 2721 | { |
| 2722 | struct sigaction sa; |
| 2723 | |
| 2724 | memset(&sa, 0, sizeof(sa)); |
| 2725 | |
| 2726 | sa.sa_handler = &signal_handler; |
| 2727 | |
| 2728 | if (sigaction(SIGINT, &sa, NULL) < 0) |
| 2729 | err(1, "sigaction SIGINT"); |
Len Brown | 0721196 | 2017-07-15 15:51:26 -0400 | [diff] [blame] | 2730 | if (sigaction(SIGUSR1, &sa, NULL) < 0) |
| 2731 | err(1, "sigaction SIGUSR1"); |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2732 | } |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2733 | |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 2734 | void do_sleep(void) |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2735 | { |
| 2736 | struct timeval select_timeout; |
| 2737 | fd_set readfds; |
| 2738 | int retval; |
| 2739 | |
| 2740 | FD_ZERO(&readfds); |
| 2741 | FD_SET(0, &readfds); |
| 2742 | |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 2743 | if (!isatty(fileno(stdin))) { |
| 2744 | nanosleep(&interval_ts, NULL); |
| 2745 | return; |
| 2746 | } |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2747 | |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 2748 | select_timeout = interval_tv; |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2749 | retval = select(1, &readfds, NULL, NULL, &select_timeout); |
| 2750 | |
| 2751 | if (retval == 1) { |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2752 | switch (getc(stdin)) { |
| 2753 | case 'q': |
| 2754 | exit_requested = 1; |
| 2755 | break; |
| 2756 | } |
| 2757 | /* make sure this manually-invoked interval is at least 1ms long */ |
| 2758 | nanosleep(&one_msec, NULL); |
| 2759 | } |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2760 | } |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 2761 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2762 | void turbostat_loop() |
| 2763 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2764 | int retval; |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 2765 | int restarted = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2766 | |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2767 | setup_signal_handler(); |
| 2768 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2769 | restart: |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 2770 | restarted++; |
| 2771 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2772 | snapshot_proc_sysfs_files(); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2773 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 2774 | if (retval < -1) { |
| 2775 | exit(retval); |
| 2776 | } else if (retval == -1) { |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 2777 | if (restarted > 1) { |
| 2778 | exit(retval); |
| 2779 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2780 | re_initialize(); |
| 2781 | goto restart; |
| 2782 | } |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 2783 | restarted = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2784 | gettimeofday(&tv_even, (struct timezone *)NULL); |
| 2785 | |
| 2786 | while (1) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2787 | if (for_all_proc_cpus(cpu_is_not_present)) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2788 | re_initialize(); |
| 2789 | goto restart; |
| 2790 | } |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2791 | do_sleep(); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2792 | if (snapshot_proc_sysfs_files()) |
| 2793 | goto restart; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2794 | retval = for_all_cpus(get_counters, ODD_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 2795 | if (retval < -1) { |
| 2796 | exit(retval); |
| 2797 | } else if (retval == -1) { |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 2798 | re_initialize(); |
| 2799 | goto restart; |
| 2800 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2801 | gettimeofday(&tv_odd, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2802 | timersub(&tv_odd, &tv_even, &tv_delta); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 2803 | if (for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS)) { |
| 2804 | re_initialize(); |
| 2805 | goto restart; |
| 2806 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2807 | compute_average(EVEN_COUNTERS); |
| 2808 | format_all_counters(EVEN_COUNTERS); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2809 | flush_output_stdout(); |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2810 | if (exit_requested) |
| 2811 | break; |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2812 | do_sleep(); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2813 | if (snapshot_proc_sysfs_files()) |
| 2814 | goto restart; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2815 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 2816 | if (retval < -1) { |
| 2817 | exit(retval); |
| 2818 | } else if (retval == -1) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2819 | re_initialize(); |
| 2820 | goto restart; |
| 2821 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2822 | gettimeofday(&tv_even, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2823 | timersub(&tv_even, &tv_odd, &tv_delta); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 2824 | if (for_all_cpus_2(delta_cpu, EVEN_COUNTERS, ODD_COUNTERS)) { |
| 2825 | re_initialize(); |
| 2826 | goto restart; |
| 2827 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2828 | compute_average(ODD_COUNTERS); |
| 2829 | format_all_counters(ODD_COUNTERS); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2830 | flush_output_stdout(); |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2831 | if (exit_requested) |
| 2832 | break; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2833 | } |
| 2834 | } |
| 2835 | |
| 2836 | void check_dev_msr() |
| 2837 | { |
| 2838 | struct stat sb; |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2839 | char pathname[32]; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2840 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2841 | sprintf(pathname, "/dev/cpu/%d/msr", base_cpu); |
| 2842 | if (stat(pathname, &sb)) |
Len Brown | a21d38c | 2015-03-24 16:37:35 -0400 | [diff] [blame] | 2843 | if (system("/sbin/modprobe msr > /dev/null 2>&1")) |
| 2844 | err(-5, "no /dev/cpu/0/msr, Try \"# modprobe msr\" "); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2845 | } |
| 2846 | |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2847 | void check_permissions() |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2848 | { |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2849 | struct __user_cap_header_struct cap_header_data; |
| 2850 | cap_user_header_t cap_header = &cap_header_data; |
| 2851 | struct __user_cap_data_struct cap_data_data; |
| 2852 | cap_user_data_t cap_data = &cap_data_data; |
| 2853 | extern int capget(cap_user_header_t hdrp, cap_user_data_t datap); |
| 2854 | int do_exit = 0; |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2855 | char pathname[32]; |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2856 | |
| 2857 | /* check for CAP_SYS_RAWIO */ |
| 2858 | cap_header->pid = getpid(); |
| 2859 | cap_header->version = _LINUX_CAPABILITY_VERSION; |
| 2860 | if (capget(cap_header, cap_data) < 0) |
| 2861 | err(-6, "capget(2) failed"); |
| 2862 | |
| 2863 | if ((cap_data->effective & (1 << CAP_SYS_RAWIO)) == 0) { |
| 2864 | do_exit++; |
| 2865 | warnx("capget(CAP_SYS_RAWIO) failed," |
| 2866 | " try \"# setcap cap_sys_rawio=ep %s\"", progname); |
| 2867 | } |
| 2868 | |
| 2869 | /* test file permissions */ |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2870 | sprintf(pathname, "/dev/cpu/%d/msr", base_cpu); |
| 2871 | if (euidaccess(pathname, R_OK)) { |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2872 | do_exit++; |
| 2873 | warn("/dev/cpu/0/msr open failed, try chown or chmod +r /dev/cpu/*/msr"); |
| 2874 | } |
| 2875 | |
| 2876 | /* if all else fails, thell them to be root */ |
| 2877 | if (do_exit) |
| 2878 | if (getuid() != 0) |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2879 | warnx("... or simply run as root"); |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2880 | |
| 2881 | if (do_exit) |
| 2882 | exit(-6); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2883 | } |
| 2884 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2885 | /* |
| 2886 | * NHM adds support for additional MSRs: |
| 2887 | * |
| 2888 | * MSR_SMI_COUNT 0x00000034 |
| 2889 | * |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 2890 | * MSR_PLATFORM_INFO 0x000000ce |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 2891 | * MSR_PKG_CST_CONFIG_CONTROL 0x000000e2 |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2892 | * |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 2893 | * MSR_MISC_PWR_MGMT 0x000001aa |
| 2894 | * |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2895 | * MSR_PKG_C3_RESIDENCY 0x000003f8 |
| 2896 | * MSR_PKG_C6_RESIDENCY 0x000003f9 |
| 2897 | * MSR_CORE_C3_RESIDENCY 0x000003fc |
| 2898 | * MSR_CORE_C6_RESIDENCY 0x000003fd |
| 2899 | * |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2900 | * Side effect: |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 2901 | * sets global pkg_cstate_limit to decode MSR_PKG_CST_CONFIG_CONTROL |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 2902 | * sets has_misc_feature_control |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2903 | */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2904 | int probe_nhm_msrs(unsigned int family, unsigned int model) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2905 | { |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2906 | unsigned long long msr; |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 2907 | unsigned int base_ratio; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2908 | int *pkg_cstate_limits; |
| 2909 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2910 | if (!genuine_intel) |
| 2911 | return 0; |
| 2912 | |
| 2913 | if (family != 6) |
| 2914 | return 0; |
| 2915 | |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 2916 | bclk = discover_bclk(family, model); |
| 2917 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2918 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2919 | case INTEL_FAM6_NEHALEM_EP: /* Core i7, Xeon 5500 series - Bloomfield, Gainstown NHM-EP */ |
| 2920 | 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] | 2921 | case 0x1F: /* Core i7 and i5 Processor - Nehalem */ |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2922 | case INTEL_FAM6_WESTMERE: /* Westmere Client - Clarkdale, Arrandale */ |
| 2923 | case INTEL_FAM6_WESTMERE_EP: /* Westmere EP - Gulftown */ |
| 2924 | case INTEL_FAM6_NEHALEM_EX: /* Nehalem-EX Xeon - Beckton */ |
| 2925 | case INTEL_FAM6_WESTMERE_EX: /* Westmere-EX Xeon - Eagleton */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2926 | pkg_cstate_limits = nhm_pkg_cstate_limits; |
| 2927 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2928 | case INTEL_FAM6_SANDYBRIDGE: /* SNB */ |
| 2929 | case INTEL_FAM6_SANDYBRIDGE_X: /* SNB Xeon */ |
| 2930 | case INTEL_FAM6_IVYBRIDGE: /* IVB */ |
| 2931 | case INTEL_FAM6_IVYBRIDGE_X: /* IVB Xeon */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2932 | pkg_cstate_limits = snb_pkg_cstate_limits; |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 2933 | has_misc_feature_control = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2934 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2935 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 2936 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 2937 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 2938 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 2939 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 2940 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
| 2941 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 2942 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 2943 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 2944 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 2945 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 2946 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame^] | 2947 | case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2948 | pkg_cstate_limits = hsw_pkg_cstate_limits; |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 2949 | has_misc_feature_control = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2950 | break; |
Len Brown | d8ebb44 | 2016-12-01 20:27:46 -0500 | [diff] [blame] | 2951 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
| 2952 | pkg_cstate_limits = skx_pkg_cstate_limits; |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 2953 | has_misc_feature_control = 1; |
Len Brown | d8ebb44 | 2016-12-01 20:27:46 -0500 | [diff] [blame] | 2954 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2955 | case INTEL_FAM6_ATOM_SILVERMONT1: /* BYT */ |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 2956 | no_MSR_MISC_PWR_MGMT = 1; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2957 | case INTEL_FAM6_ATOM_SILVERMONT2: /* AVN */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2958 | pkg_cstate_limits = slv_pkg_cstate_limits; |
| 2959 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2960 | case INTEL_FAM6_ATOM_AIRMONT: /* AMT */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2961 | pkg_cstate_limits = amt_pkg_cstate_limits; |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 2962 | no_MSR_MISC_PWR_MGMT = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2963 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2964 | case INTEL_FAM6_XEON_PHI_KNL: /* PHI */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 2965 | case INTEL_FAM6_XEON_PHI_KNM: |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2966 | pkg_cstate_limits = phi_pkg_cstate_limits; |
| 2967 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2968 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | ac01ac1 | 2017-01-27 01:45:35 -0500 | [diff] [blame] | 2969 | case INTEL_FAM6_ATOM_GEMINI_LAKE: |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 2970 | case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ |
Len Brown | e4085d5 | 2016-04-06 17:15:56 -0400 | [diff] [blame] | 2971 | pkg_cstate_limits = bxt_pkg_cstate_limits; |
| 2972 | break; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2973 | default: |
| 2974 | return 0; |
| 2975 | } |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 2976 | get_msr(base_cpu, MSR_PKG_CST_CONFIG_CONTROL, &msr); |
Len Brown | e9257f5 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 2977 | pkg_cstate_limit = pkg_cstate_limits[msr & 0xF]; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2978 | |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 2979 | get_msr(base_cpu, MSR_PLATFORM_INFO, &msr); |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 2980 | base_ratio = (msr >> 8) & 0xFF; |
| 2981 | |
| 2982 | base_hz = base_ratio * bclk * 1000000; |
| 2983 | has_base_hz = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2984 | return 1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2985 | } |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 2986 | /* |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 2987 | * SLV client has support for unique MSRs: |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 2988 | * |
| 2989 | * MSR_CC6_DEMOTION_POLICY_CONFIG |
| 2990 | * MSR_MC6_DEMOTION_POLICY_CONFIG |
| 2991 | */ |
| 2992 | |
| 2993 | int has_slv_msrs(unsigned int family, unsigned int model) |
| 2994 | { |
| 2995 | if (!genuine_intel) |
| 2996 | return 0; |
| 2997 | |
| 2998 | switch (model) { |
| 2999 | case INTEL_FAM6_ATOM_SILVERMONT1: |
| 3000 | case INTEL_FAM6_ATOM_MERRIFIELD: |
| 3001 | case INTEL_FAM6_ATOM_MOOREFIELD: |
| 3002 | return 1; |
| 3003 | } |
| 3004 | return 0; |
| 3005 | } |
Len Brown | 7170a37 | 2017-01-27 02:13:27 -0500 | [diff] [blame] | 3006 | int is_dnv(unsigned int family, unsigned int model) |
| 3007 | { |
| 3008 | |
| 3009 | if (!genuine_intel) |
| 3010 | return 0; |
| 3011 | |
| 3012 | switch (model) { |
| 3013 | case INTEL_FAM6_ATOM_DENVERTON: |
| 3014 | return 1; |
| 3015 | } |
| 3016 | return 0; |
| 3017 | } |
Len Brown | ade0eba | 2017-02-10 01:56:47 -0500 | [diff] [blame] | 3018 | int is_bdx(unsigned int family, unsigned int model) |
| 3019 | { |
| 3020 | |
| 3021 | if (!genuine_intel) |
| 3022 | return 0; |
| 3023 | |
| 3024 | switch (model) { |
| 3025 | case INTEL_FAM6_BROADWELL_X: |
| 3026 | case INTEL_FAM6_BROADWELL_XEON_D: |
| 3027 | return 1; |
| 3028 | } |
| 3029 | return 0; |
| 3030 | } |
Len Brown | 34c76197 | 2017-01-27 02:36:41 -0500 | [diff] [blame] | 3031 | int is_skx(unsigned int family, unsigned int model) |
| 3032 | { |
| 3033 | |
| 3034 | if (!genuine_intel) |
| 3035 | return 0; |
| 3036 | |
| 3037 | switch (model) { |
| 3038 | case INTEL_FAM6_SKYLAKE_X: |
| 3039 | return 1; |
| 3040 | } |
| 3041 | return 0; |
| 3042 | } |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 3043 | |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 3044 | int has_turbo_ratio_limit(unsigned int family, unsigned int model) |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3045 | { |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 3046 | if (has_slv_msrs(family, model)) |
| 3047 | return 0; |
| 3048 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3049 | switch (model) { |
| 3050 | /* Nehalem compatible, but do not include turbo-ratio limit support */ |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3051 | case INTEL_FAM6_NEHALEM_EX: /* Nehalem-EX Xeon - Beckton */ |
| 3052 | case INTEL_FAM6_WESTMERE_EX: /* Westmere-EX Xeon - Eagleton */ |
| 3053 | case INTEL_FAM6_XEON_PHI_KNL: /* PHI - Knights Landing (different MSR definition) */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 3054 | case INTEL_FAM6_XEON_PHI_KNM: |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3055 | return 0; |
| 3056 | default: |
| 3057 | return 1; |
| 3058 | } |
| 3059 | } |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 3060 | int has_atom_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 3061 | { |
| 3062 | if (has_slv_msrs(family, model)) |
| 3063 | return 1; |
| 3064 | |
| 3065 | return 0; |
| 3066 | } |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 3067 | int has_ivt_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 3068 | { |
| 3069 | if (!genuine_intel) |
| 3070 | return 0; |
| 3071 | |
| 3072 | if (family != 6) |
| 3073 | return 0; |
| 3074 | |
| 3075 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3076 | case INTEL_FAM6_IVYBRIDGE_X: /* IVB Xeon */ |
| 3077 | case INTEL_FAM6_HASWELL_X: /* HSW Xeon */ |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 3078 | return 1; |
| 3079 | default: |
| 3080 | return 0; |
| 3081 | } |
| 3082 | } |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3083 | int has_hsw_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 3084 | { |
| 3085 | if (!genuine_intel) |
| 3086 | return 0; |
| 3087 | |
| 3088 | if (family != 6) |
| 3089 | return 0; |
| 3090 | |
| 3091 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3092 | case INTEL_FAM6_HASWELL_X: /* HSW Xeon */ |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3093 | return 1; |
| 3094 | default: |
| 3095 | return 0; |
| 3096 | } |
| 3097 | } |
| 3098 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 3099 | int has_knl_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 3100 | { |
| 3101 | if (!genuine_intel) |
| 3102 | return 0; |
| 3103 | |
| 3104 | if (family != 6) |
| 3105 | return 0; |
| 3106 | |
| 3107 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3108 | case INTEL_FAM6_XEON_PHI_KNL: /* Knights Landing */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 3109 | case INTEL_FAM6_XEON_PHI_KNM: |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 3110 | return 1; |
| 3111 | default: |
| 3112 | return 0; |
| 3113 | } |
| 3114 | } |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 3115 | int has_glm_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 3116 | { |
| 3117 | if (!genuine_intel) |
| 3118 | return 0; |
| 3119 | |
| 3120 | if (family != 6) |
| 3121 | return 0; |
| 3122 | |
| 3123 | switch (model) { |
| 3124 | case INTEL_FAM6_ATOM_GOLDMONT: |
| 3125 | case INTEL_FAM6_SKYLAKE_X: |
| 3126 | return 1; |
| 3127 | default: |
| 3128 | return 0; |
| 3129 | } |
| 3130 | } |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 3131 | int has_config_tdp(unsigned int family, unsigned int model) |
| 3132 | { |
| 3133 | if (!genuine_intel) |
| 3134 | return 0; |
| 3135 | |
| 3136 | if (family != 6) |
| 3137 | return 0; |
| 3138 | |
| 3139 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3140 | case INTEL_FAM6_IVYBRIDGE: /* IVB */ |
| 3141 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 3142 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 3143 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 3144 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 3145 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 3146 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
| 3147 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 3148 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 3149 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 3150 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 3151 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 3152 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame^] | 3153 | case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3154 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 3155 | |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3156 | case INTEL_FAM6_XEON_PHI_KNL: /* Knights Landing */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 3157 | case INTEL_FAM6_XEON_PHI_KNM: |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 3158 | return 1; |
| 3159 | default: |
| 3160 | return 0; |
| 3161 | } |
| 3162 | } |
| 3163 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3164 | static void |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 3165 | dump_cstate_pstate_config_info(unsigned int family, unsigned int model) |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3166 | { |
| 3167 | if (!do_nhm_platform_info) |
| 3168 | return; |
| 3169 | |
| 3170 | dump_nhm_platform_info(); |
| 3171 | |
| 3172 | if (has_hsw_turbo_ratio_limit(family, model)) |
| 3173 | dump_hsw_turbo_ratio_limits(); |
| 3174 | |
| 3175 | if (has_ivt_turbo_ratio_limit(family, model)) |
| 3176 | dump_ivt_turbo_ratio_limits(); |
| 3177 | |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 3178 | if (has_turbo_ratio_limit(family, model)) |
| 3179 | dump_turbo_ratio_limits(family, model); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3180 | |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 3181 | if (has_atom_turbo_ratio_limit(family, model)) |
| 3182 | dump_atom_turbo_ratio_limits(); |
| 3183 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 3184 | if (has_knl_turbo_ratio_limit(family, model)) |
| 3185 | dump_knl_turbo_ratio_limits(); |
| 3186 | |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 3187 | if (has_config_tdp(family, model)) |
| 3188 | dump_config_tdp(); |
| 3189 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3190 | dump_nhm_cst_cfg(); |
| 3191 | } |
| 3192 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 3193 | static void |
| 3194 | dump_sysfs_cstate_config(void) |
| 3195 | { |
| 3196 | char path[64]; |
| 3197 | char name_buf[16]; |
| 3198 | char desc[64]; |
| 3199 | FILE *input; |
| 3200 | int state; |
| 3201 | char *sp; |
| 3202 | |
| 3203 | if (!DO_BIC(BIC_sysfs)) |
| 3204 | return; |
| 3205 | |
| 3206 | for (state = 0; state < 10; ++state) { |
| 3207 | |
| 3208 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", |
| 3209 | base_cpu, state); |
| 3210 | input = fopen(path, "r"); |
| 3211 | if (input == NULL) |
| 3212 | continue; |
| 3213 | fgets(name_buf, sizeof(name_buf), input); |
| 3214 | |
| 3215 | /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ |
| 3216 | sp = strchr(name_buf, '-'); |
| 3217 | if (!sp) |
| 3218 | sp = strchrnul(name_buf, '\n'); |
| 3219 | *sp = '\0'; |
| 3220 | |
| 3221 | fclose(input); |
| 3222 | |
| 3223 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/desc", |
| 3224 | base_cpu, state); |
| 3225 | input = fopen(path, "r"); |
| 3226 | if (input == NULL) |
| 3227 | continue; |
| 3228 | fgets(desc, sizeof(desc), input); |
| 3229 | |
| 3230 | fprintf(outf, "cpu%d: %s: %s", base_cpu, name_buf, desc); |
| 3231 | fclose(input); |
| 3232 | } |
| 3233 | } |
Len Brown | 7293fcc | 2017-02-22 00:11:12 -0500 | [diff] [blame] | 3234 | static void |
| 3235 | dump_sysfs_pstate_config(void) |
| 3236 | { |
| 3237 | char path[64]; |
| 3238 | char driver_buf[64]; |
| 3239 | char governor_buf[64]; |
| 3240 | FILE *input; |
| 3241 | int turbo; |
| 3242 | |
| 3243 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_driver", |
| 3244 | base_cpu); |
| 3245 | input = fopen(path, "r"); |
| 3246 | if (input == NULL) { |
| 3247 | fprintf(stderr, "NSFOD %s\n", path); |
| 3248 | return; |
| 3249 | } |
| 3250 | fgets(driver_buf, sizeof(driver_buf), input); |
| 3251 | fclose(input); |
| 3252 | |
| 3253 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", |
| 3254 | base_cpu); |
| 3255 | input = fopen(path, "r"); |
| 3256 | if (input == NULL) { |
| 3257 | fprintf(stderr, "NSFOD %s\n", path); |
| 3258 | return; |
| 3259 | } |
| 3260 | fgets(governor_buf, sizeof(governor_buf), input); |
| 3261 | fclose(input); |
| 3262 | |
| 3263 | fprintf(outf, "cpu%d: cpufreq driver: %s", base_cpu, driver_buf); |
| 3264 | fprintf(outf, "cpu%d: cpufreq governor: %s", base_cpu, governor_buf); |
| 3265 | |
| 3266 | sprintf(path, "/sys/devices/system/cpu/cpufreq/boost"); |
| 3267 | input = fopen(path, "r"); |
| 3268 | if (input != NULL) { |
| 3269 | fscanf(input, "%d", &turbo); |
| 3270 | fprintf(outf, "cpufreq boost: %d\n", turbo); |
| 3271 | fclose(input); |
| 3272 | } |
| 3273 | |
| 3274 | sprintf(path, "/sys/devices/system/cpu/intel_pstate/no_turbo"); |
| 3275 | input = fopen(path, "r"); |
| 3276 | if (input != NULL) { |
| 3277 | fscanf(input, "%d", &turbo); |
| 3278 | fprintf(outf, "cpufreq intel_pstate no_turbo: %d\n", turbo); |
| 3279 | fclose(input); |
| 3280 | } |
| 3281 | } |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 3282 | |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 3283 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3284 | /* |
| 3285 | * print_epb() |
| 3286 | * Decode the ENERGY_PERF_BIAS MSR |
| 3287 | */ |
| 3288 | int print_epb(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3289 | { |
| 3290 | unsigned long long msr; |
| 3291 | char *epb_string; |
| 3292 | int cpu; |
| 3293 | |
| 3294 | if (!has_epb) |
| 3295 | return 0; |
| 3296 | |
| 3297 | cpu = t->cpu_id; |
| 3298 | |
| 3299 | /* EPB is per-package */ |
| 3300 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3301 | return 0; |
| 3302 | |
| 3303 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3304 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3305 | return -1; |
| 3306 | } |
| 3307 | |
| 3308 | if (get_msr(cpu, MSR_IA32_ENERGY_PERF_BIAS, &msr)) |
| 3309 | return 0; |
| 3310 | |
Len Brown | e9be7dd | 2015-05-26 12:19:37 -0400 | [diff] [blame] | 3311 | switch (msr & 0xF) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3312 | case ENERGY_PERF_BIAS_PERFORMANCE: |
| 3313 | epb_string = "performance"; |
| 3314 | break; |
| 3315 | case ENERGY_PERF_BIAS_NORMAL: |
| 3316 | epb_string = "balanced"; |
| 3317 | break; |
| 3318 | case ENERGY_PERF_BIAS_POWERSAVE: |
| 3319 | epb_string = "powersave"; |
| 3320 | break; |
| 3321 | default: |
| 3322 | epb_string = "custom"; |
| 3323 | break; |
| 3324 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3325 | 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] | 3326 | |
| 3327 | return 0; |
| 3328 | } |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3329 | /* |
| 3330 | * print_hwp() |
| 3331 | * Decode the MSR_HWP_CAPABILITIES |
| 3332 | */ |
| 3333 | int print_hwp(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3334 | { |
| 3335 | unsigned long long msr; |
| 3336 | int cpu; |
| 3337 | |
| 3338 | if (!has_hwp) |
| 3339 | return 0; |
| 3340 | |
| 3341 | cpu = t->cpu_id; |
| 3342 | |
| 3343 | /* MSR_HWP_CAPABILITIES is per-package */ |
| 3344 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3345 | return 0; |
| 3346 | |
| 3347 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3348 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3349 | return -1; |
| 3350 | } |
| 3351 | |
| 3352 | if (get_msr(cpu, MSR_PM_ENABLE, &msr)) |
| 3353 | return 0; |
| 3354 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3355 | fprintf(outf, "cpu%d: MSR_PM_ENABLE: 0x%08llx (%sHWP)\n", |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3356 | cpu, msr, (msr & (1 << 0)) ? "" : "No-"); |
| 3357 | |
| 3358 | /* MSR_PM_ENABLE[1] == 1 if HWP is enabled and MSRs visible */ |
| 3359 | if ((msr & (1 << 0)) == 0) |
| 3360 | return 0; |
| 3361 | |
| 3362 | if (get_msr(cpu, MSR_HWP_CAPABILITIES, &msr)) |
| 3363 | return 0; |
| 3364 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3365 | fprintf(outf, "cpu%d: MSR_HWP_CAPABILITIES: 0x%08llx " |
Len Brown | 6dbd25a | 2017-03-04 18:18:28 -0500 | [diff] [blame] | 3366 | "(high %d guar %d eff %d low %d)\n", |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3367 | cpu, msr, |
| 3368 | (unsigned int)HWP_HIGHEST_PERF(msr), |
| 3369 | (unsigned int)HWP_GUARANTEED_PERF(msr), |
| 3370 | (unsigned int)HWP_MOSTEFFICIENT_PERF(msr), |
| 3371 | (unsigned int)HWP_LOWEST_PERF(msr)); |
| 3372 | |
| 3373 | if (get_msr(cpu, MSR_HWP_REQUEST, &msr)) |
| 3374 | return 0; |
| 3375 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3376 | fprintf(outf, "cpu%d: MSR_HWP_REQUEST: 0x%08llx " |
Len Brown | 6dbd25a | 2017-03-04 18:18:28 -0500 | [diff] [blame] | 3377 | "(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] | 3378 | cpu, msr, |
| 3379 | (unsigned int)(((msr) >> 0) & 0xff), |
| 3380 | (unsigned int)(((msr) >> 8) & 0xff), |
| 3381 | (unsigned int)(((msr) >> 16) & 0xff), |
| 3382 | (unsigned int)(((msr) >> 24) & 0xff), |
| 3383 | (unsigned int)(((msr) >> 32) & 0xff3), |
| 3384 | (unsigned int)(((msr) >> 42) & 0x1)); |
| 3385 | |
| 3386 | if (has_hwp_pkg) { |
| 3387 | if (get_msr(cpu, MSR_HWP_REQUEST_PKG, &msr)) |
| 3388 | return 0; |
| 3389 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3390 | fprintf(outf, "cpu%d: MSR_HWP_REQUEST_PKG: 0x%08llx " |
Len Brown | 6dbd25a | 2017-03-04 18:18:28 -0500 | [diff] [blame] | 3391 | "(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] | 3392 | cpu, msr, |
| 3393 | (unsigned int)(((msr) >> 0) & 0xff), |
| 3394 | (unsigned int)(((msr) >> 8) & 0xff), |
| 3395 | (unsigned int)(((msr) >> 16) & 0xff), |
| 3396 | (unsigned int)(((msr) >> 24) & 0xff), |
| 3397 | (unsigned int)(((msr) >> 32) & 0xff3)); |
| 3398 | } |
| 3399 | if (has_hwp_notify) { |
| 3400 | if (get_msr(cpu, MSR_HWP_INTERRUPT, &msr)) |
| 3401 | return 0; |
| 3402 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3403 | fprintf(outf, "cpu%d: MSR_HWP_INTERRUPT: 0x%08llx " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3404 | "(%s_Guaranteed_Perf_Change, %s_Excursion_Min)\n", |
| 3405 | cpu, msr, |
| 3406 | ((msr) & 0x1) ? "EN" : "Dis", |
| 3407 | ((msr) & 0x2) ? "EN" : "Dis"); |
| 3408 | } |
| 3409 | if (get_msr(cpu, MSR_HWP_STATUS, &msr)) |
| 3410 | return 0; |
| 3411 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3412 | fprintf(outf, "cpu%d: MSR_HWP_STATUS: 0x%08llx " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3413 | "(%sGuaranteed_Perf_Change, %sExcursion_Min)\n", |
| 3414 | cpu, msr, |
| 3415 | ((msr) & 0x1) ? "" : "No-", |
| 3416 | ((msr) & 0x2) ? "" : "No-"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3417 | |
| 3418 | return 0; |
| 3419 | } |
| 3420 | |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3421 | /* |
| 3422 | * print_perf_limit() |
| 3423 | */ |
| 3424 | int print_perf_limit(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3425 | { |
| 3426 | unsigned long long msr; |
| 3427 | int cpu; |
| 3428 | |
| 3429 | cpu = t->cpu_id; |
| 3430 | |
| 3431 | /* per-package */ |
| 3432 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3433 | return 0; |
| 3434 | |
| 3435 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3436 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3437 | return -1; |
| 3438 | } |
| 3439 | |
| 3440 | if (do_core_perf_limit_reasons) { |
| 3441 | get_msr(cpu, MSR_CORE_PERF_LIMIT_REASONS, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3442 | fprintf(outf, "cpu%d: MSR_CORE_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr); |
| 3443 | 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] | 3444 | (msr & 1 << 15) ? "bit15, " : "", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3445 | (msr & 1 << 14) ? "bit14, " : "", |
Len Brown | e33cbe8 | 2015-03-13 16:30:57 -0400 | [diff] [blame] | 3446 | (msr & 1 << 13) ? "Transitions, " : "", |
| 3447 | (msr & 1 << 12) ? "MultiCoreTurbo, " : "", |
| 3448 | (msr & 1 << 11) ? "PkgPwrL2, " : "", |
| 3449 | (msr & 1 << 10) ? "PkgPwrL1, " : "", |
| 3450 | (msr & 1 << 9) ? "CorePwr, " : "", |
| 3451 | (msr & 1 << 8) ? "Amps, " : "", |
| 3452 | (msr & 1 << 6) ? "VR-Therm, " : "", |
| 3453 | (msr & 1 << 5) ? "Auto-HWP, " : "", |
| 3454 | (msr & 1 << 4) ? "Graphics, " : "", |
| 3455 | (msr & 1 << 2) ? "bit2, " : "", |
| 3456 | (msr & 1 << 1) ? "ThermStatus, " : "", |
| 3457 | (msr & 1 << 0) ? "PROCHOT, " : ""); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3458 | 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] | 3459 | (msr & 1 << 31) ? "bit31, " : "", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3460 | (msr & 1 << 30) ? "bit30, " : "", |
Len Brown | e33cbe8 | 2015-03-13 16:30:57 -0400 | [diff] [blame] | 3461 | (msr & 1 << 29) ? "Transitions, " : "", |
| 3462 | (msr & 1 << 28) ? "MultiCoreTurbo, " : "", |
| 3463 | (msr & 1 << 27) ? "PkgPwrL2, " : "", |
| 3464 | (msr & 1 << 26) ? "PkgPwrL1, " : "", |
| 3465 | (msr & 1 << 25) ? "CorePwr, " : "", |
| 3466 | (msr & 1 << 24) ? "Amps, " : "", |
| 3467 | (msr & 1 << 22) ? "VR-Therm, " : "", |
| 3468 | (msr & 1 << 21) ? "Auto-HWP, " : "", |
| 3469 | (msr & 1 << 20) ? "Graphics, " : "", |
| 3470 | (msr & 1 << 18) ? "bit18, " : "", |
| 3471 | (msr & 1 << 17) ? "ThermStatus, " : "", |
| 3472 | (msr & 1 << 16) ? "PROCHOT, " : ""); |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3473 | |
| 3474 | } |
| 3475 | if (do_gfx_perf_limit_reasons) { |
| 3476 | get_msr(cpu, MSR_GFX_PERF_LIMIT_REASONS, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3477 | fprintf(outf, "cpu%d: MSR_GFX_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr); |
| 3478 | fprintf(outf, " (Active: %s%s%s%s%s%s%s%s)", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3479 | (msr & 1 << 0) ? "PROCHOT, " : "", |
| 3480 | (msr & 1 << 1) ? "ThermStatus, " : "", |
| 3481 | (msr & 1 << 4) ? "Graphics, " : "", |
| 3482 | (msr & 1 << 6) ? "VR-Therm, " : "", |
| 3483 | (msr & 1 << 8) ? "Amps, " : "", |
| 3484 | (msr & 1 << 9) ? "GFXPwr, " : "", |
| 3485 | (msr & 1 << 10) ? "PkgPwrL1, " : "", |
| 3486 | (msr & 1 << 11) ? "PkgPwrL2, " : ""); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3487 | fprintf(outf, " (Logged: %s%s%s%s%s%s%s%s)\n", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3488 | (msr & 1 << 16) ? "PROCHOT, " : "", |
| 3489 | (msr & 1 << 17) ? "ThermStatus, " : "", |
| 3490 | (msr & 1 << 20) ? "Graphics, " : "", |
| 3491 | (msr & 1 << 22) ? "VR-Therm, " : "", |
| 3492 | (msr & 1 << 24) ? "Amps, " : "", |
| 3493 | (msr & 1 << 25) ? "GFXPwr, " : "", |
| 3494 | (msr & 1 << 26) ? "PkgPwrL1, " : "", |
| 3495 | (msr & 1 << 27) ? "PkgPwrL2, " : ""); |
| 3496 | } |
| 3497 | if (do_ring_perf_limit_reasons) { |
| 3498 | get_msr(cpu, MSR_RING_PERF_LIMIT_REASONS, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3499 | fprintf(outf, "cpu%d: MSR_RING_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr); |
| 3500 | fprintf(outf, " (Active: %s%s%s%s%s%s)", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3501 | (msr & 1 << 0) ? "PROCHOT, " : "", |
| 3502 | (msr & 1 << 1) ? "ThermStatus, " : "", |
| 3503 | (msr & 1 << 6) ? "VR-Therm, " : "", |
| 3504 | (msr & 1 << 8) ? "Amps, " : "", |
| 3505 | (msr & 1 << 10) ? "PkgPwrL1, " : "", |
| 3506 | (msr & 1 << 11) ? "PkgPwrL2, " : ""); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3507 | fprintf(outf, " (Logged: %s%s%s%s%s%s)\n", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3508 | (msr & 1 << 16) ? "PROCHOT, " : "", |
| 3509 | (msr & 1 << 17) ? "ThermStatus, " : "", |
| 3510 | (msr & 1 << 22) ? "VR-Therm, " : "", |
| 3511 | (msr & 1 << 24) ? "Amps, " : "", |
| 3512 | (msr & 1 << 26) ? "PkgPwrL1, " : "", |
| 3513 | (msr & 1 << 27) ? "PkgPwrL2, " : ""); |
| 3514 | } |
| 3515 | return 0; |
| 3516 | } |
| 3517 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3518 | #define RAPL_POWER_GRANULARITY 0x7FFF /* 15 bit power granularity */ |
| 3519 | #define RAPL_TIME_GRANULARITY 0x3F /* 6 bit time granularity */ |
| 3520 | |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 3521 | double get_tdp(unsigned int model) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3522 | { |
| 3523 | unsigned long long msr; |
| 3524 | |
| 3525 | if (do_rapl & RAPL_PKG_POWER_INFO) |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3526 | if (!get_msr(base_cpu, MSR_PKG_POWER_INFO, &msr)) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3527 | return ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units; |
| 3528 | |
| 3529 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3530 | case INTEL_FAM6_ATOM_SILVERMONT1: |
| 3531 | case INTEL_FAM6_ATOM_SILVERMONT2: |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3532 | return 30.0; |
| 3533 | default: |
| 3534 | return 135.0; |
| 3535 | } |
| 3536 | } |
| 3537 | |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 3538 | /* |
| 3539 | * rapl_dram_energy_units_probe() |
| 3540 | * Energy units are either hard-coded, or come from RAPL Energy Unit MSR. |
| 3541 | */ |
| 3542 | static double |
| 3543 | rapl_dram_energy_units_probe(int model, double rapl_energy_units) |
| 3544 | { |
| 3545 | /* only called for genuine_intel, family 6 */ |
| 3546 | |
| 3547 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3548 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 3549 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 3550 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 3551 | case INTEL_FAM6_XEON_PHI_KNL: /* KNL */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 3552 | case INTEL_FAM6_XEON_PHI_KNM: |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 3553 | return (rapl_dram_energy_units = 15.3 / 1000000); |
| 3554 | default: |
| 3555 | return (rapl_energy_units); |
| 3556 | } |
| 3557 | } |
| 3558 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3559 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3560 | /* |
| 3561 | * rapl_probe() |
| 3562 | * |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3563 | * sets do_rapl, rapl_power_units, rapl_energy_units, rapl_time_units |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3564 | */ |
| 3565 | void rapl_probe(unsigned int family, unsigned int model) |
| 3566 | { |
| 3567 | unsigned long long msr; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3568 | unsigned int time_unit; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3569 | double tdp; |
| 3570 | |
| 3571 | if (!genuine_intel) |
| 3572 | return; |
| 3573 | |
| 3574 | if (family != 6) |
| 3575 | return; |
| 3576 | |
| 3577 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3578 | case INTEL_FAM6_SANDYBRIDGE: |
| 3579 | case INTEL_FAM6_IVYBRIDGE: |
| 3580 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 3581 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 3582 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 3583 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 3584 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3585 | 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] | 3586 | if (rapl_joules) { |
| 3587 | BIC_PRESENT(BIC_Pkg_J); |
| 3588 | BIC_PRESENT(BIC_Cor_J); |
| 3589 | BIC_PRESENT(BIC_GFX_J); |
| 3590 | } else { |
| 3591 | BIC_PRESENT(BIC_PkgWatt); |
| 3592 | BIC_PRESENT(BIC_CorWatt); |
| 3593 | BIC_PRESENT(BIC_GFXWatt); |
| 3594 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3595 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3596 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | ac01ac1 | 2017-01-27 01:45:35 -0500 | [diff] [blame] | 3597 | case INTEL_FAM6_ATOM_GEMINI_LAKE: |
Len Brown | e4085d5 | 2016-04-06 17:15:56 -0400 | [diff] [blame] | 3598 | do_rapl = RAPL_PKG | RAPL_PKG_POWER_INFO; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3599 | if (rapl_joules) |
| 3600 | BIC_PRESENT(BIC_Pkg_J); |
| 3601 | else |
| 3602 | BIC_PRESENT(BIC_PkgWatt); |
Len Brown | e4085d5 | 2016-04-06 17:15:56 -0400 | [diff] [blame] | 3603 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3604 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 3605 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 3606 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 3607 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame^] | 3608 | case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ |
Len Brown | 8182492 | 2017-03-04 17:23:07 -0500 | [diff] [blame] | 3609 | 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] | 3610 | BIC_PRESENT(BIC_PKG__); |
| 3611 | BIC_PRESENT(BIC_RAM__); |
| 3612 | if (rapl_joules) { |
| 3613 | BIC_PRESENT(BIC_Pkg_J); |
| 3614 | BIC_PRESENT(BIC_Cor_J); |
| 3615 | BIC_PRESENT(BIC_RAM_J); |
Len Brown | 8182492 | 2017-03-04 17:23:07 -0500 | [diff] [blame] | 3616 | BIC_PRESENT(BIC_GFX_J); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3617 | } else { |
| 3618 | BIC_PRESENT(BIC_PkgWatt); |
| 3619 | BIC_PRESENT(BIC_CorWatt); |
| 3620 | BIC_PRESENT(BIC_RAMWatt); |
Len Brown | 8182492 | 2017-03-04 17:23:07 -0500 | [diff] [blame] | 3621 | BIC_PRESENT(BIC_GFXWatt); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3622 | } |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3623 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3624 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 3625 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 3626 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 3627 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
| 3628 | case INTEL_FAM6_XEON_PHI_KNL: /* KNL */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 3629 | case INTEL_FAM6_XEON_PHI_KNM: |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3630 | 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] | 3631 | BIC_PRESENT(BIC_PKG__); |
| 3632 | BIC_PRESENT(BIC_RAM__); |
| 3633 | if (rapl_joules) { |
| 3634 | BIC_PRESENT(BIC_Pkg_J); |
| 3635 | BIC_PRESENT(BIC_RAM_J); |
| 3636 | } else { |
| 3637 | BIC_PRESENT(BIC_PkgWatt); |
| 3638 | BIC_PRESENT(BIC_RAMWatt); |
| 3639 | } |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 3640 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3641 | case INTEL_FAM6_SANDYBRIDGE_X: |
| 3642 | case INTEL_FAM6_IVYBRIDGE_X: |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3643 | 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] | 3644 | BIC_PRESENT(BIC_PKG__); |
| 3645 | BIC_PRESENT(BIC_RAM__); |
| 3646 | if (rapl_joules) { |
| 3647 | BIC_PRESENT(BIC_Pkg_J); |
| 3648 | BIC_PRESENT(BIC_Cor_J); |
| 3649 | BIC_PRESENT(BIC_RAM_J); |
| 3650 | } else { |
| 3651 | BIC_PRESENT(BIC_PkgWatt); |
| 3652 | BIC_PRESENT(BIC_CorWatt); |
| 3653 | BIC_PRESENT(BIC_RAMWatt); |
| 3654 | } |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3655 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3656 | case INTEL_FAM6_ATOM_SILVERMONT1: /* BYT */ |
| 3657 | case INTEL_FAM6_ATOM_SILVERMONT2: /* AVN */ |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 3658 | do_rapl = RAPL_PKG | RAPL_CORES; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3659 | if (rapl_joules) { |
| 3660 | BIC_PRESENT(BIC_Pkg_J); |
| 3661 | BIC_PRESENT(BIC_Cor_J); |
| 3662 | } else { |
| 3663 | BIC_PRESENT(BIC_PkgWatt); |
| 3664 | BIC_PRESENT(BIC_CorWatt); |
| 3665 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3666 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3667 | case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ |
Jacob Pan | 0f64490 | 2016-06-16 09:48:22 -0700 | [diff] [blame] | 3668 | 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] | 3669 | BIC_PRESENT(BIC_PKG__); |
| 3670 | BIC_PRESENT(BIC_RAM__); |
| 3671 | if (rapl_joules) { |
| 3672 | BIC_PRESENT(BIC_Pkg_J); |
| 3673 | BIC_PRESENT(BIC_Cor_J); |
| 3674 | BIC_PRESENT(BIC_RAM_J); |
| 3675 | } else { |
| 3676 | BIC_PRESENT(BIC_PkgWatt); |
| 3677 | BIC_PRESENT(BIC_CorWatt); |
| 3678 | BIC_PRESENT(BIC_RAMWatt); |
| 3679 | } |
Jacob Pan | 0f64490 | 2016-06-16 09:48:22 -0700 | [diff] [blame] | 3680 | break; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3681 | default: |
| 3682 | return; |
| 3683 | } |
| 3684 | |
| 3685 | /* units on package 0, verify later other packages match */ |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3686 | if (get_msr(base_cpu, MSR_RAPL_POWER_UNIT, &msr)) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3687 | return; |
| 3688 | |
| 3689 | rapl_power_units = 1.0 / (1 << (msr & 0xF)); |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3690 | if (model == INTEL_FAM6_ATOM_SILVERMONT1) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3691 | rapl_energy_units = 1.0 * (1 << (msr >> 8 & 0x1F)) / 1000000; |
| 3692 | else |
| 3693 | rapl_energy_units = 1.0 / (1 << (msr >> 8 & 0x1F)); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3694 | |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 3695 | rapl_dram_energy_units = rapl_dram_energy_units_probe(model, rapl_energy_units); |
| 3696 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3697 | time_unit = msr >> 16 & 0xF; |
| 3698 | if (time_unit == 0) |
| 3699 | time_unit = 0xA; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3700 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3701 | rapl_time_units = 1.0 / (1 << (time_unit)); |
| 3702 | |
| 3703 | tdp = get_tdp(model); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3704 | |
| 3705 | rapl_joule_counter_range = 0xFFFFFFFF * rapl_energy_units / tdp; |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3706 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3707 | 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] | 3708 | |
| 3709 | return; |
| 3710 | } |
| 3711 | |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 3712 | void perf_limit_reasons_probe(unsigned int family, unsigned int model) |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3713 | { |
| 3714 | if (!genuine_intel) |
| 3715 | return; |
| 3716 | |
| 3717 | if (family != 6) |
| 3718 | return; |
| 3719 | |
| 3720 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3721 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 3722 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 3723 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3724 | do_gfx_perf_limit_reasons = 1; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3725 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3726 | do_core_perf_limit_reasons = 1; |
| 3727 | do_ring_perf_limit_reasons = 1; |
| 3728 | default: |
| 3729 | return; |
| 3730 | } |
| 3731 | } |
| 3732 | |
Artem Bityutskiy | ac980e1 | 2017-09-05 15:14:08 +0300 | [diff] [blame] | 3733 | void automatic_cstate_conversion_probe(unsigned int family, unsigned int model) |
| 3734 | { |
| 3735 | if (is_skx(family, model) || is_bdx(family, model)) |
| 3736 | has_automatic_cstate_conversion = 1; |
| 3737 | } |
| 3738 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3739 | int print_thermal(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3740 | { |
| 3741 | unsigned long long msr; |
Len Brown | f4896fa5 | 2017-03-04 18:10:45 -0500 | [diff] [blame] | 3742 | unsigned int dts, dts2; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3743 | int cpu; |
| 3744 | |
| 3745 | if (!(do_dts || do_ptm)) |
| 3746 | return 0; |
| 3747 | |
| 3748 | cpu = t->cpu_id; |
| 3749 | |
| 3750 | /* DTS is per-core, no need to print for each thread */ |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 3751 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3752 | return 0; |
| 3753 | |
| 3754 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3755 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3756 | return -1; |
| 3757 | } |
| 3758 | |
| 3759 | if (do_ptm && (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) { |
| 3760 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr)) |
| 3761 | return 0; |
| 3762 | |
| 3763 | dts = (msr >> 16) & 0x7F; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3764 | 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] | 3765 | cpu, msr, tcc_activation_temp - dts); |
| 3766 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3767 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, &msr)) |
| 3768 | return 0; |
| 3769 | |
| 3770 | dts = (msr >> 16) & 0x7F; |
| 3771 | dts2 = (msr >> 8) & 0x7F; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3772 | 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] | 3773 | cpu, msr, tcc_activation_temp - dts, tcc_activation_temp - dts2); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3774 | } |
| 3775 | |
| 3776 | |
Len Brown | f4896fa5 | 2017-03-04 18:10:45 -0500 | [diff] [blame] | 3777 | if (do_dts && debug) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3778 | unsigned int resolution; |
| 3779 | |
| 3780 | if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr)) |
| 3781 | return 0; |
| 3782 | |
| 3783 | dts = (msr >> 16) & 0x7F; |
| 3784 | resolution = (msr >> 27) & 0xF; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3785 | 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] | 3786 | cpu, msr, tcc_activation_temp - dts, resolution); |
| 3787 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3788 | if (get_msr(cpu, MSR_IA32_THERM_INTERRUPT, &msr)) |
| 3789 | return 0; |
| 3790 | |
| 3791 | dts = (msr >> 16) & 0x7F; |
| 3792 | dts2 = (msr >> 8) & 0x7F; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3793 | 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] | 3794 | cpu, msr, tcc_activation_temp - dts, tcc_activation_temp - dts2); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3795 | } |
| 3796 | |
| 3797 | return 0; |
| 3798 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 3799 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3800 | void print_power_limit_msr(int cpu, unsigned long long msr, char *label) |
| 3801 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3802 | 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] | 3803 | cpu, label, |
| 3804 | ((msr >> 15) & 1) ? "EN" : "DIS", |
| 3805 | ((msr >> 0) & 0x7FFF) * rapl_power_units, |
| 3806 | (1.0 + (((msr >> 22) & 0x3)/4.0)) * (1 << ((msr >> 17) & 0x1F)) * rapl_time_units, |
| 3807 | (((msr >> 16) & 1) ? "EN" : "DIS")); |
| 3808 | |
| 3809 | return; |
| 3810 | } |
| 3811 | |
| 3812 | int print_rapl(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3813 | { |
| 3814 | unsigned long long msr; |
| 3815 | int cpu; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3816 | |
| 3817 | if (!do_rapl) |
| 3818 | return 0; |
| 3819 | |
| 3820 | /* RAPL counters are per package, so print only for 1st thread/package */ |
| 3821 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3822 | return 0; |
| 3823 | |
| 3824 | cpu = t->cpu_id; |
| 3825 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3826 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3827 | return -1; |
| 3828 | } |
| 3829 | |
| 3830 | if (get_msr(cpu, MSR_RAPL_POWER_UNIT, &msr)) |
| 3831 | return -1; |
| 3832 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3833 | fprintf(outf, "cpu%d: MSR_RAPL_POWER_UNIT: 0x%08llx (%f Watts, %f Joules, %f sec.)\n", cpu, msr, |
| 3834 | rapl_power_units, rapl_energy_units, rapl_time_units); |
| 3835 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3836 | if (do_rapl & RAPL_PKG_POWER_INFO) { |
| 3837 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3838 | if (get_msr(cpu, MSR_PKG_POWER_INFO, &msr)) |
| 3839 | return -5; |
| 3840 | |
| 3841 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3842 | 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] | 3843 | cpu, msr, |
| 3844 | ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3845 | ((msr >> 16) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3846 | ((msr >> 32) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3847 | ((msr >> 48) & RAPL_TIME_GRANULARITY) * rapl_time_units); |
| 3848 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3849 | } |
| 3850 | if (do_rapl & RAPL_PKG) { |
| 3851 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3852 | if (get_msr(cpu, MSR_PKG_POWER_LIMIT, &msr)) |
| 3853 | return -9; |
| 3854 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3855 | fprintf(outf, "cpu%d: MSR_PKG_POWER_LIMIT: 0x%08llx (%slocked)\n", |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3856 | cpu, msr, (msr >> 63) & 1 ? "" : "UN"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3857 | |
| 3858 | print_power_limit_msr(cpu, msr, "PKG Limit #1"); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3859 | 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] | 3860 | cpu, |
| 3861 | ((msr >> 47) & 1) ? "EN" : "DIS", |
| 3862 | ((msr >> 32) & 0x7FFF) * rapl_power_units, |
| 3863 | (1.0 + (((msr >> 54) & 0x3)/4.0)) * (1 << ((msr >> 49) & 0x1F)) * rapl_time_units, |
| 3864 | ((msr >> 48) & 1) ? "EN" : "DIS"); |
| 3865 | } |
| 3866 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3867 | if (do_rapl & RAPL_DRAM_POWER_INFO) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3868 | if (get_msr(cpu, MSR_DRAM_POWER_INFO, &msr)) |
| 3869 | return -6; |
| 3870 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3871 | 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] | 3872 | cpu, msr, |
| 3873 | ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3874 | ((msr >> 16) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3875 | ((msr >> 32) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3876 | ((msr >> 48) & RAPL_TIME_GRANULARITY) * rapl_time_units); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3877 | } |
| 3878 | if (do_rapl & RAPL_DRAM) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3879 | if (get_msr(cpu, MSR_DRAM_POWER_LIMIT, &msr)) |
| 3880 | return -9; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3881 | fprintf(outf, "cpu%d: MSR_DRAM_POWER_LIMIT: 0x%08llx (%slocked)\n", |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3882 | cpu, msr, (msr >> 31) & 1 ? "" : "UN"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3883 | |
| 3884 | print_power_limit_msr(cpu, msr, "DRAM Limit"); |
| 3885 | } |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3886 | if (do_rapl & RAPL_CORE_POLICY) { |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3887 | if (get_msr(cpu, MSR_PP0_POLICY, &msr)) |
| 3888 | return -7; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3889 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3890 | fprintf(outf, "cpu%d: MSR_PP0_POLICY: %lld\n", cpu, msr & 0xF); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3891 | } |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 3892 | if (do_rapl & RAPL_CORES_POWER_LIMIT) { |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3893 | if (get_msr(cpu, MSR_PP0_POWER_LIMIT, &msr)) |
| 3894 | return -9; |
| 3895 | fprintf(outf, "cpu%d: MSR_PP0_POWER_LIMIT: 0x%08llx (%slocked)\n", |
| 3896 | cpu, msr, (msr >> 31) & 1 ? "" : "UN"); |
| 3897 | print_power_limit_msr(cpu, msr, "Cores Limit"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3898 | } |
| 3899 | if (do_rapl & RAPL_GFX) { |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3900 | if (get_msr(cpu, MSR_PP1_POLICY, &msr)) |
| 3901 | return -8; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3902 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3903 | fprintf(outf, "cpu%d: MSR_PP1_POLICY: %lld\n", cpu, msr & 0xF); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3904 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3905 | if (get_msr(cpu, MSR_PP1_POWER_LIMIT, &msr)) |
| 3906 | return -9; |
| 3907 | fprintf(outf, "cpu%d: MSR_PP1_POWER_LIMIT: 0x%08llx (%slocked)\n", |
| 3908 | cpu, msr, (msr >> 31) & 1 ? "" : "UN"); |
| 3909 | print_power_limit_msr(cpu, msr, "GFX Limit"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3910 | } |
| 3911 | return 0; |
| 3912 | } |
| 3913 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3914 | /* |
| 3915 | * SNB adds support for additional MSRs: |
| 3916 | * |
| 3917 | * MSR_PKG_C7_RESIDENCY 0x000003fa |
| 3918 | * MSR_CORE_C7_RESIDENCY 0x000003fe |
| 3919 | * MSR_PKG_C2_RESIDENCY 0x0000060d |
| 3920 | */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3921 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3922 | int has_snb_msrs(unsigned int family, unsigned int model) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3923 | { |
| 3924 | if (!genuine_intel) |
| 3925 | return 0; |
| 3926 | |
| 3927 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3928 | case INTEL_FAM6_SANDYBRIDGE: |
| 3929 | case INTEL_FAM6_SANDYBRIDGE_X: |
| 3930 | case INTEL_FAM6_IVYBRIDGE: /* IVB */ |
| 3931 | case INTEL_FAM6_IVYBRIDGE_X: /* IVB Xeon */ |
| 3932 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 3933 | case INTEL_FAM6_HASWELL_X: /* HSW */ |
| 3934 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 3935 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 3936 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 3937 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
| 3938 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 3939 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 3940 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 3941 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 3942 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 3943 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame^] | 3944 | case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3945 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
| 3946 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | ac01ac1 | 2017-01-27 01:45:35 -0500 | [diff] [blame] | 3947 | case INTEL_FAM6_ATOM_GEMINI_LAKE: |
Xiaolong Wang | 5bbac26 | 2016-09-30 17:53:40 +0800 | [diff] [blame] | 3948 | case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3949 | return 1; |
| 3950 | } |
| 3951 | return 0; |
| 3952 | } |
| 3953 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3954 | /* |
| 3955 | * HSW adds support for additional MSRs: |
| 3956 | * |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 3957 | * MSR_PKG_C8_RESIDENCY 0x00000630 |
| 3958 | * MSR_PKG_C9_RESIDENCY 0x00000631 |
| 3959 | * MSR_PKG_C10_RESIDENCY 0x00000632 |
| 3960 | * |
| 3961 | * MSR_PKGC8_IRTL 0x00000633 |
| 3962 | * MSR_PKGC9_IRTL 0x00000634 |
| 3963 | * MSR_PKGC10_IRTL 0x00000635 |
| 3964 | * |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3965 | */ |
| 3966 | int has_hsw_msrs(unsigned int family, unsigned int model) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 3967 | { |
| 3968 | if (!genuine_intel) |
| 3969 | return 0; |
| 3970 | |
| 3971 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3972 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 3973 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 3974 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 3975 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 3976 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 3977 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame^] | 3978 | case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3979 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | ac01ac1 | 2017-01-27 01:45:35 -0500 | [diff] [blame] | 3980 | case INTEL_FAM6_ATOM_GEMINI_LAKE: |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 3981 | return 1; |
| 3982 | } |
| 3983 | return 0; |
| 3984 | } |
| 3985 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3986 | /* |
| 3987 | * SKL adds support for additional MSRS: |
| 3988 | * |
| 3989 | * MSR_PKG_WEIGHTED_CORE_C0_RES 0x00000658 |
| 3990 | * MSR_PKG_ANY_CORE_C0_RES 0x00000659 |
| 3991 | * MSR_PKG_ANY_GFXE_C0_RES 0x0000065A |
| 3992 | * MSR_PKG_BOTH_CORE_GFXE_C0_RES 0x0000065B |
| 3993 | */ |
| 3994 | int has_skl_msrs(unsigned int family, unsigned int model) |
| 3995 | { |
| 3996 | if (!genuine_intel) |
| 3997 | return 0; |
| 3998 | |
| 3999 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4000 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 4001 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 4002 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 4003 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame^] | 4004 | case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 4005 | return 1; |
| 4006 | } |
| 4007 | return 0; |
| 4008 | } |
| 4009 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4010 | int is_slm(unsigned int family, unsigned int model) |
| 4011 | { |
| 4012 | if (!genuine_intel) |
| 4013 | return 0; |
| 4014 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4015 | case INTEL_FAM6_ATOM_SILVERMONT1: /* BYT */ |
| 4016 | case INTEL_FAM6_ATOM_SILVERMONT2: /* AVN */ |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4017 | return 1; |
| 4018 | } |
| 4019 | return 0; |
| 4020 | } |
| 4021 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 4022 | int is_knl(unsigned int family, unsigned int model) |
| 4023 | { |
| 4024 | if (!genuine_intel) |
| 4025 | return 0; |
| 4026 | switch (model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4027 | case INTEL_FAM6_XEON_PHI_KNL: /* KNL */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 4028 | case INTEL_FAM6_XEON_PHI_KNM: |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 4029 | return 1; |
| 4030 | } |
| 4031 | return 0; |
| 4032 | } |
| 4033 | |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame^] | 4034 | int is_cnl(unsigned int family, unsigned int model) |
| 4035 | { |
| 4036 | if (!genuine_intel) |
| 4037 | return 0; |
| 4038 | |
| 4039 | switch (model) { |
| 4040 | case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ |
| 4041 | return 1; |
| 4042 | } |
| 4043 | |
| 4044 | return 0; |
| 4045 | } |
| 4046 | |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 4047 | unsigned int get_aperf_mperf_multiplier(unsigned int family, unsigned int model) |
| 4048 | { |
| 4049 | if (is_knl(family, model)) |
| 4050 | return 1024; |
| 4051 | return 1; |
| 4052 | } |
| 4053 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4054 | #define SLM_BCLK_FREQS 5 |
| 4055 | double slm_freq_table[SLM_BCLK_FREQS] = { 83.3, 100.0, 133.3, 116.7, 80.0}; |
| 4056 | |
| 4057 | double slm_bclk(void) |
| 4058 | { |
| 4059 | unsigned long long msr = 3; |
| 4060 | unsigned int i; |
| 4061 | double freq; |
| 4062 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 4063 | if (get_msr(base_cpu, MSR_FSB_FREQ, &msr)) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4064 | fprintf(outf, "SLM BCLK: unknown\n"); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4065 | |
| 4066 | i = msr & 0xf; |
| 4067 | if (i >= SLM_BCLK_FREQS) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4068 | fprintf(outf, "SLM BCLK[%d] invalid\n", i); |
Colin Ian King | 0a91e55 | 2016-04-25 13:03:15 +0100 | [diff] [blame] | 4069 | i = 3; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4070 | } |
| 4071 | freq = slm_freq_table[i]; |
| 4072 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4073 | if (!quiet) |
Len Brown | 8f6196c | 2017-01-07 22:40:23 -0500 | [diff] [blame] | 4074 | fprintf(outf, "SLM BCLK: %.1f Mhz\n", freq); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4075 | |
| 4076 | return freq; |
| 4077 | } |
| 4078 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4079 | double discover_bclk(unsigned int family, unsigned int model) |
| 4080 | { |
Chrzaniuk, Hubert | 121b48b | 2016-02-10 16:35:17 +0100 | [diff] [blame] | 4081 | if (has_snb_msrs(family, model) || is_knl(family, model)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4082 | return 100.00; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4083 | else if (is_slm(family, model)) |
| 4084 | return slm_bclk(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4085 | else |
| 4086 | return 133.33; |
| 4087 | } |
| 4088 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4089 | /* |
| 4090 | * MSR_IA32_TEMPERATURE_TARGET indicates the temperature where |
| 4091 | * the Thermal Control Circuit (TCC) activates. |
| 4092 | * This is usually equal to tjMax. |
| 4093 | * |
| 4094 | * Older processors do not have this MSR, so there we guess, |
| 4095 | * but also allow cmdline over-ride with -T. |
| 4096 | * |
| 4097 | * Several MSR temperature values are in units of degrees-C |
| 4098 | * below this value, including the Digital Thermal Sensor (DTS), |
| 4099 | * Package Thermal Management Sensor (PTM), and thermal event thresholds. |
| 4100 | */ |
| 4101 | int set_temperature_target(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 4102 | { |
| 4103 | unsigned long long msr; |
| 4104 | unsigned int target_c_local; |
| 4105 | int cpu; |
| 4106 | |
| 4107 | /* tcc_activation_temp is used only for dts or ptm */ |
| 4108 | if (!(do_dts || do_ptm)) |
| 4109 | return 0; |
| 4110 | |
| 4111 | /* this is a per-package concept */ |
| 4112 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 4113 | return 0; |
| 4114 | |
| 4115 | cpu = t->cpu_id; |
| 4116 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4117 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4118 | return -1; |
| 4119 | } |
| 4120 | |
| 4121 | if (tcc_activation_temp_override != 0) { |
| 4122 | tcc_activation_temp = tcc_activation_temp_override; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4123 | fprintf(outf, "cpu%d: Using cmdline TCC Target (%d C)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4124 | cpu, tcc_activation_temp); |
| 4125 | return 0; |
| 4126 | } |
| 4127 | |
| 4128 | /* Temperature Target MSR is Nehalem and newer only */ |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4129 | if (!do_nhm_platform_info) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4130 | goto guess; |
| 4131 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 4132 | if (get_msr(base_cpu, MSR_IA32_TEMPERATURE_TARGET, &msr)) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4133 | goto guess; |
| 4134 | |
Jean Delvare | 3482124 | 2014-05-01 11:40:19 +0200 | [diff] [blame] | 4135 | target_c_local = (msr >> 16) & 0xFF; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4136 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4137 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4138 | 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] | 4139 | cpu, msr, target_c_local); |
| 4140 | |
Jean Delvare | 3482124 | 2014-05-01 11:40:19 +0200 | [diff] [blame] | 4141 | if (!target_c_local) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4142 | goto guess; |
| 4143 | |
| 4144 | tcc_activation_temp = target_c_local; |
| 4145 | |
| 4146 | return 0; |
| 4147 | |
| 4148 | guess: |
| 4149 | tcc_activation_temp = TJMAX_DEFAULT; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4150 | 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] | 4151 | cpu, tcc_activation_temp); |
| 4152 | |
| 4153 | return 0; |
| 4154 | } |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4155 | |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 4156 | void decode_feature_control_msr(void) |
| 4157 | { |
| 4158 | unsigned long long msr; |
| 4159 | |
| 4160 | if (!get_msr(base_cpu, MSR_IA32_FEATURE_CONTROL, &msr)) |
| 4161 | fprintf(outf, "cpu%d: MSR_IA32_FEATURE_CONTROL: 0x%08llx (%sLocked %s)\n", |
| 4162 | base_cpu, msr, |
| 4163 | msr & FEATURE_CONTROL_LOCKED ? "" : "UN-", |
| 4164 | msr & (1 << 18) ? "SGX" : ""); |
| 4165 | } |
| 4166 | |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4167 | void decode_misc_enable_msr(void) |
| 4168 | { |
| 4169 | unsigned long long msr; |
| 4170 | |
Len Brown | f26b151 | 2017-06-23 20:45:54 -0700 | [diff] [blame] | 4171 | if (!genuine_intel) |
| 4172 | return; |
| 4173 | |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4174 | if (!get_msr(base_cpu, MSR_IA32_MISC_ENABLE, &msr)) |
Len Brown | e651262 | 2017-01-11 23:17:24 -0500 | [diff] [blame] | 4175 | 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] | 4176 | base_cpu, msr, |
Len Brown | e651262 | 2017-01-11 23:17:24 -0500 | [diff] [blame] | 4177 | msr & MSR_IA32_MISC_ENABLE_TM1 ? "" : "No-", |
| 4178 | msr & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP ? "" : "No-", |
Len Brown | fd3933c | 2017-11-08 23:15:42 -0500 | [diff] [blame] | 4179 | msr & MSR_IA32_MISC_ENABLE_MWAIT ? "" : "No-", |
Len Brown | e651262 | 2017-01-11 23:17:24 -0500 | [diff] [blame] | 4180 | msr & MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE ? "No-" : "", |
| 4181 | msr & MSR_IA32_MISC_ENABLE_TURBO_DISABLE ? "No-" : ""); |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4182 | } |
| 4183 | |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 4184 | void decode_misc_feature_control(void) |
| 4185 | { |
| 4186 | unsigned long long msr; |
| 4187 | |
| 4188 | if (!has_misc_feature_control) |
| 4189 | return; |
| 4190 | |
| 4191 | if (!get_msr(base_cpu, MSR_MISC_FEATURE_CONTROL, &msr)) |
| 4192 | fprintf(outf, "cpu%d: MSR_MISC_FEATURE_CONTROL: 0x%08llx (%sL2-Prefetch %sL2-Prefetch-pair %sL1-Prefetch %sL1-IP-Prefetch)\n", |
| 4193 | base_cpu, msr, |
| 4194 | msr & (0 << 0) ? "No-" : "", |
| 4195 | msr & (1 << 0) ? "No-" : "", |
| 4196 | msr & (2 << 0) ? "No-" : "", |
| 4197 | msr & (3 << 0) ? "No-" : ""); |
| 4198 | } |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 4199 | /* |
| 4200 | * Decode MSR_MISC_PWR_MGMT |
| 4201 | * |
| 4202 | * Decode the bits according to the Nehalem documentation |
| 4203 | * bit[0] seems to continue to have same meaning going forward |
| 4204 | * bit[1] less so... |
| 4205 | */ |
| 4206 | void decode_misc_pwr_mgmt_msr(void) |
| 4207 | { |
| 4208 | unsigned long long msr; |
| 4209 | |
| 4210 | if (!do_nhm_platform_info) |
| 4211 | return; |
| 4212 | |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 4213 | if (no_MSR_MISC_PWR_MGMT) |
| 4214 | return; |
| 4215 | |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 4216 | if (!get_msr(base_cpu, MSR_MISC_PWR_MGMT, &msr)) |
Srinivas Pandruvada | ddadb8a | 2016-11-11 14:29:48 -0800 | [diff] [blame] | 4217 | 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] | 4218 | base_cpu, msr, |
| 4219 | msr & (1 << 0) ? "DIS" : "EN", |
Srinivas Pandruvada | ddadb8a | 2016-11-11 14:29:48 -0800 | [diff] [blame] | 4220 | msr & (1 << 1) ? "EN" : "DIS", |
| 4221 | msr & (1 << 8) ? "EN" : "DIS"); |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 4222 | } |
Len Brown | 71616c8 | 2017-01-07 22:37:48 -0500 | [diff] [blame] | 4223 | /* |
| 4224 | * Decode MSR_CC6_DEMOTION_POLICY_CONFIG, MSR_MC6_DEMOTION_POLICY_CONFIG |
| 4225 | * |
| 4226 | * This MSRs are present on Silvermont processors, |
| 4227 | * Intel Atom processor E3000 series (Baytrail), and friends. |
| 4228 | */ |
| 4229 | void decode_c6_demotion_policy_msr(void) |
| 4230 | { |
| 4231 | unsigned long long msr; |
| 4232 | |
| 4233 | if (!get_msr(base_cpu, MSR_CC6_DEMOTION_POLICY_CONFIG, &msr)) |
| 4234 | fprintf(outf, "cpu%d: MSR_CC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-CC6-Demotion)\n", |
| 4235 | base_cpu, msr, msr & (1 << 0) ? "EN" : "DIS"); |
| 4236 | |
| 4237 | if (!get_msr(base_cpu, MSR_MC6_DEMOTION_POLICY_CONFIG, &msr)) |
| 4238 | fprintf(outf, "cpu%d: MSR_MC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-MC6-Demotion)\n", |
| 4239 | base_cpu, msr, msr & (1 << 0) ? "EN" : "DIS"); |
| 4240 | } |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4241 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 4242 | void process_cpuid() |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4243 | { |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 4244 | unsigned int eax, ebx, ecx, edx, max_level, max_extended_level; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4245 | unsigned int fms, family, model, stepping; |
Len Brown | b3a34e9 | 2017-01-21 00:50:08 -0500 | [diff] [blame] | 4246 | unsigned int has_turbo; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4247 | |
| 4248 | eax = ebx = ecx = edx = 0; |
| 4249 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4250 | __cpuid(0, max_level, ebx, ecx, edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4251 | |
| 4252 | if (ebx == 0x756e6547 && edx == 0x49656e69 && ecx == 0x6c65746e) |
| 4253 | genuine_intel = 1; |
| 4254 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4255 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4256 | fprintf(outf, "CPUID(0): %.4s%.4s%.4s ", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4257 | (char *)&ebx, (char *)&edx, (char *)&ecx); |
| 4258 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4259 | __cpuid(1, fms, ebx, ecx, edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4260 | family = (fms >> 8) & 0xf; |
| 4261 | model = (fms >> 4) & 0xf; |
| 4262 | stepping = fms & 0xf; |
| 4263 | if (family == 6 || family == 0xf) |
| 4264 | model += ((fms >> 16) & 0xf) << 4; |
| 4265 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4266 | if (!quiet) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4267 | 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] | 4268 | max_level, family, model, stepping, family, model, stepping); |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 4269 | 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] | 4270 | ecx & (1 << 0) ? "SSE3" : "-", |
| 4271 | ecx & (1 << 3) ? "MONITOR" : "-", |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 4272 | ecx & (1 << 6) ? "SMX" : "-", |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4273 | ecx & (1 << 7) ? "EIST" : "-", |
| 4274 | ecx & (1 << 8) ? "TM2" : "-", |
| 4275 | edx & (1 << 4) ? "TSC" : "-", |
| 4276 | edx & (1 << 5) ? "MSR" : "-", |
| 4277 | edx & (1 << 22) ? "ACPI-TM" : "-", |
| 4278 | edx & (1 << 29) ? "TM" : "-"); |
| 4279 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4280 | |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4281 | if (!(edx & (1 << 5))) |
| 4282 | errx(1, "CPUID: no MSR"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4283 | |
| 4284 | /* |
| 4285 | * check max extended function levels of CPUID. |
| 4286 | * This is needed to check for invariant TSC. |
| 4287 | * This check is valid for both Intel and AMD. |
| 4288 | */ |
| 4289 | ebx = ecx = edx = 0; |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4290 | __cpuid(0x80000000, max_extended_level, ebx, ecx, edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4291 | |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 4292 | if (max_extended_level >= 0x80000007) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4293 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4294 | /* |
| 4295 | * Non-Stop TSC is advertised by CPUID.EAX=0x80000007: EDX.bit8 |
| 4296 | * this check is valid for both Intel and AMD |
| 4297 | */ |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4298 | __cpuid(0x80000007, eax, ebx, ecx, edx); |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4299 | has_invariant_tsc = edx & (1 << 8); |
| 4300 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4301 | |
| 4302 | /* |
| 4303 | * APERF/MPERF is advertised by CPUID.EAX=0x6: ECX.bit0 |
| 4304 | * this check is valid for both Intel and AMD |
| 4305 | */ |
| 4306 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4307 | __cpuid(0x6, eax, ebx, ecx, edx); |
Thomas Renninger | 8209e05 | 2011-01-21 15:11:19 +0100 | [diff] [blame] | 4308 | has_aperf = ecx & (1 << 0); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4309 | if (has_aperf) { |
| 4310 | BIC_PRESENT(BIC_Avg_MHz); |
| 4311 | BIC_PRESENT(BIC_Busy); |
| 4312 | BIC_PRESENT(BIC_Bzy_MHz); |
| 4313 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4314 | do_dts = eax & (1 << 0); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4315 | if (do_dts) |
| 4316 | BIC_PRESENT(BIC_CoreTmp); |
Len Brown | b3a34e9 | 2017-01-21 00:50:08 -0500 | [diff] [blame] | 4317 | has_turbo = eax & (1 << 1); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4318 | do_ptm = eax & (1 << 6); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4319 | if (do_ptm) |
| 4320 | BIC_PRESENT(BIC_PkgTmp); |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4321 | has_hwp = eax & (1 << 7); |
| 4322 | has_hwp_notify = eax & (1 << 8); |
| 4323 | has_hwp_activity_window = eax & (1 << 9); |
| 4324 | has_hwp_epp = eax & (1 << 10); |
| 4325 | has_hwp_pkg = eax & (1 << 11); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4326 | has_epb = ecx & (1 << 3); |
| 4327 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4328 | if (!quiet) |
Len Brown | b3a34e9 | 2017-01-21 00:50:08 -0500 | [diff] [blame] | 4329 | fprintf(outf, "CPUID(6): %sAPERF, %sTURBO, %sDTS, %sPTM, %sHWP, " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4330 | "%sHWPnotify, %sHWPwindow, %sHWPepp, %sHWPpkg, %sEPB\n", |
| 4331 | has_aperf ? "" : "No-", |
Len Brown | b3a34e9 | 2017-01-21 00:50:08 -0500 | [diff] [blame] | 4332 | has_turbo ? "" : "No-", |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4333 | do_dts ? "" : "No-", |
| 4334 | do_ptm ? "" : "No-", |
| 4335 | has_hwp ? "" : "No-", |
| 4336 | has_hwp_notify ? "" : "No-", |
| 4337 | has_hwp_activity_window ? "" : "No-", |
| 4338 | has_hwp_epp ? "" : "No-", |
| 4339 | has_hwp_pkg ? "" : "No-", |
| 4340 | has_epb ? "" : "No-"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4341 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4342 | if (!quiet) |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4343 | decode_misc_enable_msr(); |
| 4344 | |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 4345 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4346 | if (max_level >= 0x7 && !quiet) { |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 4347 | int has_sgx; |
| 4348 | |
| 4349 | ecx = 0; |
| 4350 | |
| 4351 | __cpuid_count(0x7, 0, eax, ebx, ecx, edx); |
| 4352 | |
| 4353 | has_sgx = ebx & (1 << 2); |
| 4354 | fprintf(outf, "CPUID(7): %sSGX\n", has_sgx ? "" : "No-"); |
| 4355 | |
| 4356 | if (has_sgx) |
| 4357 | decode_feature_control_msr(); |
| 4358 | } |
| 4359 | |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 4360 | if (max_level >= 0x15) { |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4361 | unsigned int eax_crystal; |
| 4362 | unsigned int ebx_tsc; |
| 4363 | |
| 4364 | /* |
| 4365 | * CPUID 15H TSC/Crystal ratio, possibly Crystal Hz |
| 4366 | */ |
| 4367 | eax_crystal = ebx_tsc = crystal_hz = edx = 0; |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4368 | __cpuid(0x15, eax_crystal, ebx_tsc, crystal_hz, edx); |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4369 | |
| 4370 | if (ebx_tsc != 0) { |
| 4371 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4372 | if (!quiet && (ebx != 0)) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4373 | 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] | 4374 | eax_crystal, ebx_tsc, crystal_hz); |
| 4375 | |
| 4376 | if (crystal_hz == 0) |
| 4377 | switch(model) { |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4378 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 4379 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 4380 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 4381 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Len Brown | e8efbc8 | 2016-04-06 17:15:57 -0400 | [diff] [blame] | 4382 | crystal_hz = 24000000; /* 24.0 MHz */ |
| 4383 | break; |
Len Brown | 7268d40 | 2016-12-01 23:10:39 -0500 | [diff] [blame] | 4384 | case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ |
Len Brown | ec53e59 | 2016-04-06 17:15:58 -0400 | [diff] [blame] | 4385 | crystal_hz = 25000000; /* 25.0 MHz */ |
| 4386 | break; |
Len Brown | 869ce69 | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4387 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | ac01ac1 | 2017-01-27 01:45:35 -0500 | [diff] [blame] | 4388 | case INTEL_FAM6_ATOM_GEMINI_LAKE: |
Len Brown | e8efbc8 | 2016-04-06 17:15:57 -0400 | [diff] [blame] | 4389 | crystal_hz = 19200000; /* 19.2 MHz */ |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4390 | break; |
| 4391 | default: |
| 4392 | crystal_hz = 0; |
| 4393 | } |
| 4394 | |
| 4395 | if (crystal_hz) { |
| 4396 | tsc_hz = (unsigned long long) crystal_hz * ebx_tsc / eax_crystal; |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4397 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4398 | fprintf(outf, "TSC: %lld MHz (%d Hz * %d / %d / 1000000)\n", |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4399 | tsc_hz / 1000000, crystal_hz, ebx_tsc, eax_crystal); |
| 4400 | } |
| 4401 | } |
| 4402 | } |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 4403 | if (max_level >= 0x16) { |
| 4404 | unsigned int base_mhz, max_mhz, bus_mhz, edx; |
| 4405 | |
| 4406 | /* |
| 4407 | * CPUID 16H Base MHz, Max MHz, Bus MHz |
| 4408 | */ |
| 4409 | base_mhz = max_mhz = bus_mhz = edx = 0; |
| 4410 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4411 | __cpuid(0x16, base_mhz, max_mhz, bus_mhz, edx); |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4412 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4413 | 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] | 4414 | base_mhz, max_mhz, bus_mhz); |
| 4415 | } |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4416 | |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 4417 | if (has_aperf) |
| 4418 | aperf_mperf_multiplier = get_aperf_mperf_multiplier(family, model); |
| 4419 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4420 | BIC_PRESENT(BIC_IRQ); |
| 4421 | BIC_PRESENT(BIC_TSC_MHz); |
| 4422 | |
| 4423 | if (probe_nhm_msrs(family, model)) { |
| 4424 | do_nhm_platform_info = 1; |
| 4425 | BIC_PRESENT(BIC_CPU_c1); |
| 4426 | BIC_PRESENT(BIC_CPU_c3); |
| 4427 | BIC_PRESENT(BIC_CPU_c6); |
| 4428 | BIC_PRESENT(BIC_SMI); |
| 4429 | } |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4430 | do_snb_cstates = has_snb_msrs(family, model); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4431 | |
| 4432 | if (do_snb_cstates) |
| 4433 | BIC_PRESENT(BIC_CPU_c7); |
| 4434 | |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 4435 | do_irtl_snb = has_snb_msrs(family, model); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4436 | if (do_snb_cstates && (pkg_cstate_limit >= PCL__2)) |
| 4437 | BIC_PRESENT(BIC_Pkgpc2); |
| 4438 | if (pkg_cstate_limit >= PCL__3) |
| 4439 | BIC_PRESENT(BIC_Pkgpc3); |
| 4440 | if (pkg_cstate_limit >= PCL__6) |
| 4441 | BIC_PRESENT(BIC_Pkgpc6); |
| 4442 | if (do_snb_cstates && (pkg_cstate_limit >= PCL__7)) |
| 4443 | BIC_PRESENT(BIC_Pkgpc7); |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 4444 | if (has_slv_msrs(family, model)) { |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4445 | BIC_NOT_PRESENT(BIC_Pkgpc2); |
| 4446 | BIC_NOT_PRESENT(BIC_Pkgpc3); |
| 4447 | BIC_PRESENT(BIC_Pkgpc6); |
| 4448 | BIC_NOT_PRESENT(BIC_Pkgpc7); |
Len Brown | 0539ba1 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 4449 | BIC_PRESENT(BIC_Mod_c6); |
| 4450 | use_c1_residency_msr = 1; |
| 4451 | } |
Len Brown | 7170a37 | 2017-01-27 02:13:27 -0500 | [diff] [blame] | 4452 | if (is_dnv(family, model)) { |
| 4453 | BIC_PRESENT(BIC_CPU_c1); |
| 4454 | BIC_NOT_PRESENT(BIC_CPU_c3); |
| 4455 | BIC_NOT_PRESENT(BIC_Pkgpc3); |
| 4456 | BIC_NOT_PRESENT(BIC_CPU_c7); |
| 4457 | BIC_NOT_PRESENT(BIC_Pkgpc7); |
| 4458 | use_c1_residency_msr = 1; |
| 4459 | } |
Len Brown | 34c76197 | 2017-01-27 02:36:41 -0500 | [diff] [blame] | 4460 | if (is_skx(family, model)) { |
| 4461 | BIC_NOT_PRESENT(BIC_CPU_c3); |
| 4462 | BIC_NOT_PRESENT(BIC_Pkgpc3); |
| 4463 | BIC_NOT_PRESENT(BIC_CPU_c7); |
| 4464 | BIC_NOT_PRESENT(BIC_Pkgpc7); |
| 4465 | } |
Len Brown | ade0eba | 2017-02-10 01:56:47 -0500 | [diff] [blame] | 4466 | if (is_bdx(family, model)) { |
| 4467 | BIC_NOT_PRESENT(BIC_CPU_c7); |
| 4468 | BIC_NOT_PRESENT(BIC_Pkgpc7); |
| 4469 | } |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4470 | if (has_hsw_msrs(family, model)) { |
| 4471 | BIC_PRESENT(BIC_Pkgpc8); |
| 4472 | BIC_PRESENT(BIC_Pkgpc9); |
| 4473 | BIC_PRESENT(BIC_Pkgpc10); |
| 4474 | } |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 4475 | do_irtl_hsw = has_hsw_msrs(family, model); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 4476 | if (has_skl_msrs(family, model)) { |
| 4477 | BIC_PRESENT(BIC_Totl_c0); |
| 4478 | BIC_PRESENT(BIC_Any_c0); |
| 4479 | BIC_PRESENT(BIC_GFX_c0); |
| 4480 | BIC_PRESENT(BIC_CPUGFX); |
| 4481 | } |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4482 | do_slm_cstates = is_slm(family, model); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 4483 | do_knl_cstates = is_knl(family, model); |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame^] | 4484 | do_cnl_cstates = is_cnl(family, model); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4485 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4486 | if (!quiet) |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 4487 | decode_misc_pwr_mgmt_msr(); |
| 4488 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4489 | if (!quiet && has_slv_msrs(family, model)) |
Len Brown | 71616c8 | 2017-01-07 22:37:48 -0500 | [diff] [blame] | 4490 | decode_c6_demotion_policy_msr(); |
| 4491 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4492 | rapl_probe(family, model); |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 4493 | perf_limit_reasons_probe(family, model); |
Artem Bityutskiy | ac980e1 | 2017-09-05 15:14:08 +0300 | [diff] [blame] | 4494 | automatic_cstate_conversion_probe(family, model); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4495 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4496 | if (!quiet) |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 4497 | dump_cstate_pstate_config_info(family, model); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 4498 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4499 | if (!quiet) |
| 4500 | dump_sysfs_cstate_config(); |
Len Brown | 7293fcc | 2017-02-22 00:11:12 -0500 | [diff] [blame] | 4501 | if (!quiet) |
| 4502 | dump_sysfs_pstate_config(); |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4503 | |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 4504 | if (has_skl_msrs(family, model)) |
| 4505 | calculate_tsc_tweak(); |
| 4506 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4507 | if (!access("/sys/class/drm/card0/power/rc6_residency_ms", R_OK)) |
| 4508 | BIC_PRESENT(BIC_GFX_rc6); |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 4509 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4510 | if (!access("/sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz", R_OK)) |
| 4511 | BIC_PRESENT(BIC_GFXMHz); |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 4512 | |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 4513 | if (!access("/sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us", R_OK)) |
| 4514 | BIC_PRESENT(BIC_CPU_LPI); |
| 4515 | else |
| 4516 | BIC_NOT_PRESENT(BIC_CPU_LPI); |
| 4517 | |
| 4518 | if (!access("/sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us", R_OK)) |
| 4519 | BIC_PRESENT(BIC_SYS_LPI); |
| 4520 | else |
| 4521 | BIC_NOT_PRESENT(BIC_SYS_LPI); |
| 4522 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4523 | if (!quiet) |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 4524 | decode_misc_feature_control(); |
| 4525 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4526 | return; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4527 | } |
| 4528 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4529 | |
| 4530 | /* |
| 4531 | * in /dev/cpu/ return success for names that are numbers |
| 4532 | * ie. filter out ".", "..", "microcode". |
| 4533 | */ |
| 4534 | int dir_filter(const struct dirent *dirp) |
| 4535 | { |
| 4536 | if (isdigit(dirp->d_name[0])) |
| 4537 | return 1; |
| 4538 | else |
| 4539 | return 0; |
| 4540 | } |
| 4541 | |
| 4542 | int open_dev_cpu_msr(int dummy1) |
| 4543 | { |
| 4544 | return 0; |
| 4545 | } |
| 4546 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4547 | void topology_probe() |
| 4548 | { |
| 4549 | int i; |
| 4550 | int max_core_id = 0; |
| 4551 | int max_package_id = 0; |
| 4552 | int max_siblings = 0; |
| 4553 | struct cpu_topology { |
| 4554 | int core_id; |
| 4555 | int physical_package_id; |
| 4556 | } *cpus; |
| 4557 | |
| 4558 | /* Initialize num_cpus, max_cpu_num */ |
| 4559 | topo.num_cpus = 0; |
| 4560 | topo.max_cpu_num = 0; |
| 4561 | for_all_proc_cpus(count_cpus); |
| 4562 | if (!summary_only && topo.num_cpus > 1) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4563 | BIC_PRESENT(BIC_CPU); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4564 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4565 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4566 | 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] | 4567 | |
| 4568 | cpus = calloc(1, (topo.max_cpu_num + 1) * sizeof(struct cpu_topology)); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4569 | if (cpus == NULL) |
| 4570 | err(1, "calloc cpus"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4571 | |
| 4572 | /* |
| 4573 | * Allocate and initialize cpu_present_set |
| 4574 | */ |
| 4575 | cpu_present_set = CPU_ALLOC((topo.max_cpu_num + 1)); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4576 | if (cpu_present_set == NULL) |
| 4577 | err(3, "CPU_ALLOC"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4578 | cpu_present_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); |
| 4579 | CPU_ZERO_S(cpu_present_setsize, cpu_present_set); |
| 4580 | for_all_proc_cpus(mark_cpu_present); |
| 4581 | |
| 4582 | /* |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 4583 | * Validate that all cpus in cpu_subset are also in cpu_present_set |
| 4584 | */ |
| 4585 | for (i = 0; i < CPU_SUBSET_MAXCPUS; ++i) { |
| 4586 | if (CPU_ISSET_S(i, cpu_subset_size, cpu_subset)) |
| 4587 | if (!CPU_ISSET_S(i, cpu_present_setsize, cpu_present_set)) |
| 4588 | err(1, "cpu%d not present", i); |
| 4589 | } |
| 4590 | |
| 4591 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4592 | * Allocate and initialize cpu_affinity_set |
| 4593 | */ |
| 4594 | cpu_affinity_set = CPU_ALLOC((topo.max_cpu_num + 1)); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4595 | if (cpu_affinity_set == NULL) |
| 4596 | err(3, "CPU_ALLOC"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4597 | cpu_affinity_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); |
| 4598 | CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); |
| 4599 | |
| 4600 | |
| 4601 | /* |
| 4602 | * For online cpus |
| 4603 | * find max_core_id, max_package_id |
| 4604 | */ |
| 4605 | for (i = 0; i <= topo.max_cpu_num; ++i) { |
| 4606 | int siblings; |
| 4607 | |
| 4608 | if (cpu_is_not_present(i)) { |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4609 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4610 | fprintf(outf, "cpu%d NOT PRESENT\n", i); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4611 | continue; |
| 4612 | } |
| 4613 | cpus[i].core_id = get_core_id(i); |
| 4614 | if (cpus[i].core_id > max_core_id) |
| 4615 | max_core_id = cpus[i].core_id; |
| 4616 | |
| 4617 | cpus[i].physical_package_id = get_physical_package_id(i); |
| 4618 | if (cpus[i].physical_package_id > max_package_id) |
| 4619 | max_package_id = cpus[i].physical_package_id; |
| 4620 | |
| 4621 | siblings = get_num_ht_siblings(i); |
| 4622 | if (siblings > max_siblings) |
| 4623 | max_siblings = siblings; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4624 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4625 | fprintf(outf, "cpu %d pkg %d core %d\n", |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4626 | i, cpus[i].physical_package_id, cpus[i].core_id); |
| 4627 | } |
| 4628 | topo.num_cores_per_pkg = max_core_id + 1; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4629 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4630 | 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] | 4631 | max_core_id, topo.num_cores_per_pkg); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4632 | if (!summary_only && topo.num_cores_per_pkg > 1) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4633 | BIC_PRESENT(BIC_Core); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4634 | |
| 4635 | topo.num_packages = max_package_id + 1; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4636 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4637 | fprintf(outf, "max_package_id %d, sizing for %d packages\n", |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4638 | max_package_id, topo.num_packages); |
Len Brown | 7da6e3e | 2017-02-21 23:43:41 -0500 | [diff] [blame] | 4639 | if (!summary_only && topo.num_packages > 1) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4640 | BIC_PRESENT(BIC_Package); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4641 | |
| 4642 | topo.num_threads_per_core = max_siblings; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4643 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4644 | fprintf(outf, "max_siblings %d\n", max_siblings); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4645 | |
| 4646 | free(cpus); |
| 4647 | } |
| 4648 | |
| 4649 | void |
| 4650 | allocate_counters(struct thread_data **t, struct core_data **c, struct pkg_data **p) |
| 4651 | { |
| 4652 | int i; |
| 4653 | |
| 4654 | *t = calloc(topo.num_threads_per_core * topo.num_cores_per_pkg * |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4655 | topo.num_packages, sizeof(struct thread_data)); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4656 | if (*t == NULL) |
| 4657 | goto error; |
| 4658 | |
| 4659 | for (i = 0; i < topo.num_threads_per_core * |
| 4660 | topo.num_cores_per_pkg * topo.num_packages; i++) |
| 4661 | (*t)[i].cpu_id = -1; |
| 4662 | |
| 4663 | *c = calloc(topo.num_cores_per_pkg * topo.num_packages, |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4664 | sizeof(struct core_data)); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4665 | if (*c == NULL) |
| 4666 | goto error; |
| 4667 | |
| 4668 | for (i = 0; i < topo.num_cores_per_pkg * topo.num_packages; i++) |
| 4669 | (*c)[i].core_id = -1; |
| 4670 | |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4671 | *p = calloc(topo.num_packages, sizeof(struct pkg_data)); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4672 | if (*p == NULL) |
| 4673 | goto error; |
| 4674 | |
| 4675 | for (i = 0; i < topo.num_packages; i++) |
| 4676 | (*p)[i].package_id = i; |
| 4677 | |
| 4678 | return; |
| 4679 | error: |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4680 | err(1, "calloc counters"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4681 | } |
| 4682 | /* |
| 4683 | * init_counter() |
| 4684 | * |
| 4685 | * set cpu_id, core_num, pkg_num |
| 4686 | * set FIRST_THREAD_IN_CORE and FIRST_CORE_IN_PACKAGE |
| 4687 | * |
| 4688 | * increment topo.num_cores when 1st core in pkg seen |
| 4689 | */ |
| 4690 | void init_counter(struct thread_data *thread_base, struct core_data *core_base, |
| 4691 | struct pkg_data *pkg_base, int thread_num, int core_num, |
| 4692 | int pkg_num, int cpu_id) |
| 4693 | { |
| 4694 | struct thread_data *t; |
| 4695 | struct core_data *c; |
| 4696 | struct pkg_data *p; |
| 4697 | |
| 4698 | t = GET_THREAD(thread_base, thread_num, core_num, pkg_num); |
| 4699 | c = GET_CORE(core_base, core_num, pkg_num); |
| 4700 | p = GET_PKG(pkg_base, pkg_num); |
| 4701 | |
| 4702 | t->cpu_id = cpu_id; |
| 4703 | if (thread_num == 0) { |
| 4704 | t->flags |= CPU_IS_FIRST_THREAD_IN_CORE; |
| 4705 | if (cpu_is_first_core_in_package(cpu_id)) |
| 4706 | t->flags |= CPU_IS_FIRST_CORE_IN_PACKAGE; |
| 4707 | } |
| 4708 | |
| 4709 | c->core_id = core_num; |
| 4710 | p->package_id = pkg_num; |
| 4711 | } |
| 4712 | |
| 4713 | |
| 4714 | int initialize_counters(int cpu_id) |
| 4715 | { |
| 4716 | int my_thread_id, my_core_id, my_package_id; |
| 4717 | |
| 4718 | my_package_id = get_physical_package_id(cpu_id); |
| 4719 | my_core_id = get_core_id(cpu_id); |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 4720 | my_thread_id = get_cpu_position_in_core(cpu_id); |
| 4721 | if (!my_thread_id) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4722 | topo.num_cores++; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4723 | |
| 4724 | init_counter(EVEN_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id); |
| 4725 | init_counter(ODD_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id); |
| 4726 | return 0; |
| 4727 | } |
| 4728 | |
| 4729 | void allocate_output_buffer() |
| 4730 | { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4731 | output_buffer = calloc(1, (1 + topo.num_cpus) * 1024); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4732 | outp = output_buffer; |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4733 | if (outp == NULL) |
| 4734 | err(-1, "calloc output buffer"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4735 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 4736 | void allocate_fd_percpu(void) |
| 4737 | { |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 4738 | fd_percpu = calloc(topo.max_cpu_num + 1, sizeof(int)); |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 4739 | if (fd_percpu == NULL) |
| 4740 | err(-1, "calloc fd_percpu"); |
| 4741 | } |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 4742 | void allocate_irq_buffers(void) |
| 4743 | { |
| 4744 | irq_column_2_cpu = calloc(topo.num_cpus, sizeof(int)); |
| 4745 | if (irq_column_2_cpu == NULL) |
| 4746 | err(-1, "calloc %d", topo.num_cpus); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4747 | |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 4748 | irqs_per_cpu = calloc(topo.max_cpu_num + 1, sizeof(int)); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 4749 | if (irqs_per_cpu == NULL) |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 4750 | err(-1, "calloc %d", topo.max_cpu_num + 1); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 4751 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4752 | void setup_all_buffers(void) |
| 4753 | { |
| 4754 | topology_probe(); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 4755 | allocate_irq_buffers(); |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 4756 | allocate_fd_percpu(); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4757 | allocate_counters(&thread_even, &core_even, &package_even); |
| 4758 | allocate_counters(&thread_odd, &core_odd, &package_odd); |
| 4759 | allocate_output_buffer(); |
| 4760 | for_all_proc_cpus(initialize_counters); |
| 4761 | } |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4762 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 4763 | void set_base_cpu(void) |
| 4764 | { |
| 4765 | base_cpu = sched_getcpu(); |
| 4766 | if (base_cpu < 0) |
| 4767 | err(-ENODEV, "No valid cpus found"); |
| 4768 | |
| 4769 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4770 | fprintf(outf, "base_cpu = %d\n", base_cpu); |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 4771 | } |
| 4772 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4773 | void turbostat_init() |
| 4774 | { |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 4775 | setup_all_buffers(); |
| 4776 | set_base_cpu(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4777 | check_dev_msr(); |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 4778 | check_permissions(); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 4779 | process_cpuid(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4780 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4781 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4782 | if (!quiet) |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4783 | for_all_cpus(print_hwp, ODD_COUNTERS); |
| 4784 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4785 | if (!quiet) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4786 | for_all_cpus(print_epb, ODD_COUNTERS); |
| 4787 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4788 | if (!quiet) |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 4789 | for_all_cpus(print_perf_limit, ODD_COUNTERS); |
| 4790 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4791 | if (!quiet) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4792 | for_all_cpus(print_rapl, ODD_COUNTERS); |
| 4793 | |
| 4794 | for_all_cpus(set_temperature_target, ODD_COUNTERS); |
| 4795 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4796 | if (!quiet) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4797 | for_all_cpus(print_thermal, ODD_COUNTERS); |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 4798 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4799 | if (!quiet && do_irtl_snb) |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 4800 | print_irtl(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4801 | } |
| 4802 | |
| 4803 | int fork_it(char **argv) |
| 4804 | { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4805 | pid_t child_pid; |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 4806 | int status; |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 4807 | |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 4808 | snapshot_proc_sysfs_files(); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 4809 | status = for_all_cpus(get_counters, EVEN_COUNTERS); |
| 4810 | if (status) |
| 4811 | exit(status); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4812 | /* clear affinity side-effect of get_counters() */ |
| 4813 | sched_setaffinity(0, cpu_present_setsize, cpu_present_set); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4814 | gettimeofday(&tv_even, (struct timezone *)NULL); |
| 4815 | |
| 4816 | child_pid = fork(); |
| 4817 | if (!child_pid) { |
| 4818 | /* child */ |
| 4819 | execvp(argv[0], argv); |
Len Brown | 0815a3d | 2017-02-23 17:00:51 -0500 | [diff] [blame] | 4820 | err(errno, "exec %s", argv[0]); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4821 | } else { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4822 | |
| 4823 | /* parent */ |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4824 | if (child_pid == -1) |
| 4825 | err(1, "fork"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4826 | |
| 4827 | signal(SIGINT, SIG_IGN); |
| 4828 | signal(SIGQUIT, SIG_IGN); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4829 | if (waitpid(child_pid, &status, 0) == -1) |
| 4830 | err(status, "waitpid"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4831 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4832 | /* |
| 4833 | * n.b. fork_it() does not check for errors from for_all_cpus() |
| 4834 | * because re-starting is problematic when forking |
| 4835 | */ |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 4836 | snapshot_proc_sysfs_files(); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4837 | for_all_cpus(get_counters, ODD_COUNTERS); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4838 | gettimeofday(&tv_odd, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4839 | timersub(&tv_odd, &tv_even, &tv_delta); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 4840 | if (for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS)) |
| 4841 | fprintf(outf, "%s: Counter reset detected\n", progname); |
| 4842 | else { |
| 4843 | compute_average(EVEN_COUNTERS); |
| 4844 | format_all_counters(EVEN_COUNTERS); |
| 4845 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4846 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4847 | fprintf(outf, "%.6f sec\n", tv_delta.tv_sec + tv_delta.tv_usec/1000000.0); |
| 4848 | |
| 4849 | flush_output_stderr(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4850 | |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 4851 | return status; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4852 | } |
| 4853 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4854 | int get_and_dump_counters(void) |
| 4855 | { |
| 4856 | int status; |
| 4857 | |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 4858 | snapshot_proc_sysfs_files(); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4859 | status = for_all_cpus(get_counters, ODD_COUNTERS); |
| 4860 | if (status) |
| 4861 | return status; |
| 4862 | |
| 4863 | status = for_all_cpus(dump_counters, ODD_COUNTERS); |
| 4864 | if (status) |
| 4865 | return status; |
| 4866 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4867 | flush_output_stdout(); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4868 | |
| 4869 | return status; |
| 4870 | } |
| 4871 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4872 | void print_version() { |
Len Brown | f7d44a8 | 2017-05-27 21:24:58 -0700 | [diff] [blame] | 4873 | fprintf(outf, "turbostat version 17.06.23" |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4874 | " - Len Brown <lenb@kernel.org>\n"); |
| 4875 | } |
| 4876 | |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 4877 | int add_counter(unsigned int msr_num, char *path, char *name, |
| 4878 | unsigned int width, enum counter_scope scope, |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4879 | enum counter_type type, enum counter_format format, int flags) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4880 | { |
| 4881 | struct msr_counter *msrp; |
| 4882 | |
| 4883 | msrp = calloc(1, sizeof(struct msr_counter)); |
| 4884 | if (msrp == NULL) { |
| 4885 | perror("calloc"); |
| 4886 | exit(1); |
| 4887 | } |
| 4888 | |
| 4889 | msrp->msr_num = msr_num; |
| 4890 | strncpy(msrp->name, name, NAME_BYTES); |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 4891 | if (path) |
| 4892 | strncpy(msrp->path, path, PATH_BYTES); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4893 | msrp->width = width; |
| 4894 | msrp->type = type; |
| 4895 | msrp->format = format; |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4896 | msrp->flags = flags; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4897 | |
| 4898 | switch (scope) { |
| 4899 | |
| 4900 | case SCOPE_CPU: |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4901 | msrp->next = sys.tp; |
| 4902 | sys.tp = msrp; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4903 | sys.added_thread_counters++; |
Len Brown | 0748eaf | 2018-06-01 12:38:29 -0400 | [diff] [blame] | 4904 | if (sys.added_thread_counters > MAX_ADDED_THREAD_COUNTERS) { |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4905 | fprintf(stderr, "exceeded max %d added thread counters\n", |
| 4906 | MAX_ADDED_COUNTERS); |
| 4907 | exit(-1); |
| 4908 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4909 | break; |
| 4910 | |
| 4911 | case SCOPE_CORE: |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4912 | msrp->next = sys.cp; |
| 4913 | sys.cp = msrp; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4914 | sys.added_core_counters++; |
| 4915 | if (sys.added_core_counters > MAX_ADDED_COUNTERS) { |
| 4916 | fprintf(stderr, "exceeded max %d added core counters\n", |
| 4917 | MAX_ADDED_COUNTERS); |
| 4918 | exit(-1); |
| 4919 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4920 | break; |
| 4921 | |
| 4922 | case SCOPE_PACKAGE: |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4923 | msrp->next = sys.pp; |
| 4924 | sys.pp = msrp; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4925 | sys.added_package_counters++; |
| 4926 | if (sys.added_package_counters > MAX_ADDED_COUNTERS) { |
| 4927 | fprintf(stderr, "exceeded max %d added package counters\n", |
| 4928 | MAX_ADDED_COUNTERS); |
| 4929 | exit(-1); |
| 4930 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4931 | break; |
| 4932 | } |
| 4933 | |
| 4934 | return 0; |
| 4935 | } |
| 4936 | |
| 4937 | void parse_add_command(char *add_command) |
| 4938 | { |
| 4939 | int msr_num = 0; |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 4940 | char *path = NULL; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4941 | char name_buffer[NAME_BYTES] = ""; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4942 | int width = 64; |
| 4943 | int fail = 0; |
| 4944 | enum counter_scope scope = SCOPE_CPU; |
| 4945 | enum counter_type type = COUNTER_CYCLES; |
| 4946 | enum counter_format format = FORMAT_DELTA; |
| 4947 | |
| 4948 | while (add_command) { |
| 4949 | |
| 4950 | if (sscanf(add_command, "msr0x%x", &msr_num) == 1) |
| 4951 | goto next; |
| 4952 | |
| 4953 | if (sscanf(add_command, "msr%d", &msr_num) == 1) |
| 4954 | goto next; |
| 4955 | |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 4956 | if (*add_command == '/') { |
| 4957 | path = add_command; |
| 4958 | goto next; |
| 4959 | } |
| 4960 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4961 | if (sscanf(add_command, "u%d", &width) == 1) { |
| 4962 | if ((width == 32) || (width == 64)) |
| 4963 | goto next; |
| 4964 | width = 64; |
| 4965 | } |
| 4966 | if (!strncmp(add_command, "cpu", strlen("cpu"))) { |
| 4967 | scope = SCOPE_CPU; |
| 4968 | goto next; |
| 4969 | } |
| 4970 | if (!strncmp(add_command, "core", strlen("core"))) { |
| 4971 | scope = SCOPE_CORE; |
| 4972 | goto next; |
| 4973 | } |
| 4974 | if (!strncmp(add_command, "package", strlen("package"))) { |
| 4975 | scope = SCOPE_PACKAGE; |
| 4976 | goto next; |
| 4977 | } |
| 4978 | if (!strncmp(add_command, "cycles", strlen("cycles"))) { |
| 4979 | type = COUNTER_CYCLES; |
| 4980 | goto next; |
| 4981 | } |
| 4982 | if (!strncmp(add_command, "seconds", strlen("seconds"))) { |
| 4983 | type = COUNTER_SECONDS; |
| 4984 | goto next; |
| 4985 | } |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4986 | if (!strncmp(add_command, "usec", strlen("usec"))) { |
| 4987 | type = COUNTER_USEC; |
| 4988 | goto next; |
| 4989 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4990 | if (!strncmp(add_command, "raw", strlen("raw"))) { |
| 4991 | format = FORMAT_RAW; |
| 4992 | goto next; |
| 4993 | } |
| 4994 | if (!strncmp(add_command, "delta", strlen("delta"))) { |
| 4995 | format = FORMAT_DELTA; |
| 4996 | goto next; |
| 4997 | } |
| 4998 | if (!strncmp(add_command, "percent", strlen("percent"))) { |
| 4999 | format = FORMAT_PERCENT; |
| 5000 | goto next; |
| 5001 | } |
| 5002 | |
| 5003 | if (sscanf(add_command, "%18s,%*s", name_buffer) == 1) { /* 18 < NAME_BYTES */ |
| 5004 | char *eos; |
| 5005 | |
| 5006 | eos = strchr(name_buffer, ','); |
| 5007 | if (eos) |
| 5008 | *eos = '\0'; |
| 5009 | goto next; |
| 5010 | } |
| 5011 | |
| 5012 | next: |
| 5013 | add_command = strchr(add_command, ','); |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 5014 | if (add_command) { |
| 5015 | *add_command = '\0'; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5016 | add_command++; |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 5017 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5018 | |
| 5019 | } |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 5020 | if ((msr_num == 0) && (path == NULL)) { |
| 5021 | fprintf(stderr, "--add: (msrDDD | msr0xXXX | /path_to_counter ) required\n"); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5022 | fail++; |
| 5023 | } |
| 5024 | |
| 5025 | /* generate default column header */ |
| 5026 | if (*name_buffer == '\0') { |
Len Brown | 5f3aea5 | 2017-02-23 18:10:27 -0500 | [diff] [blame] | 5027 | if (width == 32) |
| 5028 | sprintf(name_buffer, "M0x%x%s", msr_num, format == FORMAT_PERCENT ? "%" : ""); |
| 5029 | else |
| 5030 | sprintf(name_buffer, "M0X%x%s", msr_num, format == FORMAT_PERCENT ? "%" : ""); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5031 | } |
| 5032 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5033 | 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] | 5034 | fail++; |
| 5035 | |
| 5036 | if (fail) { |
| 5037 | help(); |
| 5038 | exit(1); |
| 5039 | } |
| 5040 | } |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5041 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 5042 | int is_deferred_skip(char *name) |
| 5043 | { |
| 5044 | int i; |
| 5045 | |
| 5046 | for (i = 0; i < deferred_skip_index; ++i) |
| 5047 | if (!strcmp(name, deferred_skip_names[i])) |
| 5048 | return 1; |
| 5049 | return 0; |
| 5050 | } |
| 5051 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5052 | void probe_sysfs(void) |
| 5053 | { |
| 5054 | char path[64]; |
| 5055 | char name_buf[16]; |
| 5056 | FILE *input; |
| 5057 | int state; |
| 5058 | char *sp; |
| 5059 | |
| 5060 | if (!DO_BIC(BIC_sysfs)) |
| 5061 | return; |
| 5062 | |
Len Brown | 0748eaf | 2018-06-01 12:38:29 -0400 | [diff] [blame] | 5063 | for (state = 10; state >= 0; --state) { |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5064 | |
| 5065 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", |
| 5066 | base_cpu, state); |
| 5067 | input = fopen(path, "r"); |
| 5068 | if (input == NULL) |
| 5069 | continue; |
| 5070 | fgets(name_buf, sizeof(name_buf), input); |
| 5071 | |
| 5072 | /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ |
| 5073 | sp = strchr(name_buf, '-'); |
| 5074 | if (!sp) |
| 5075 | sp = strchrnul(name_buf, '\n'); |
| 5076 | *sp = '%'; |
| 5077 | *(sp + 1) = '\0'; |
| 5078 | |
| 5079 | fclose(input); |
| 5080 | |
| 5081 | sprintf(path, "cpuidle/state%d/time", state); |
| 5082 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 5083 | if (is_deferred_skip(name_buf)) |
| 5084 | continue; |
| 5085 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5086 | add_counter(0, path, name_buf, 64, SCOPE_CPU, COUNTER_USEC, |
| 5087 | FORMAT_PERCENT, SYSFS_PERCPU); |
| 5088 | } |
| 5089 | |
Len Brown | 0748eaf | 2018-06-01 12:38:29 -0400 | [diff] [blame] | 5090 | for (state = 10; state >= 0; --state) { |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5091 | |
| 5092 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", |
| 5093 | base_cpu, state); |
| 5094 | input = fopen(path, "r"); |
| 5095 | if (input == NULL) |
| 5096 | continue; |
| 5097 | fgets(name_buf, sizeof(name_buf), input); |
| 5098 | /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ |
| 5099 | sp = strchr(name_buf, '-'); |
| 5100 | if (!sp) |
| 5101 | sp = strchrnul(name_buf, '\n'); |
| 5102 | *sp = '\0'; |
| 5103 | fclose(input); |
| 5104 | |
| 5105 | sprintf(path, "cpuidle/state%d/usage", state); |
| 5106 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 5107 | if (is_deferred_skip(name_buf)) |
| 5108 | continue; |
| 5109 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5110 | add_counter(0, path, name_buf, 64, SCOPE_CPU, COUNTER_ITEMS, |
| 5111 | FORMAT_DELTA, SYSFS_PERCPU); |
| 5112 | } |
| 5113 | |
| 5114 | } |
| 5115 | |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 5116 | |
| 5117 | /* |
| 5118 | * parse cpuset with following syntax |
| 5119 | * 1,2,4..6,8-10 and set bits in cpu_subset |
| 5120 | */ |
| 5121 | void parse_cpu_command(char *optarg) |
| 5122 | { |
| 5123 | unsigned int start, end; |
| 5124 | char *next; |
| 5125 | |
Len Brown | 4e4e1e7 | 2017-02-21 22:33:42 -0500 | [diff] [blame] | 5126 | if (!strcmp(optarg, "core")) { |
| 5127 | if (cpu_subset) |
| 5128 | goto error; |
| 5129 | show_core_only++; |
| 5130 | return; |
| 5131 | } |
| 5132 | if (!strcmp(optarg, "package")) { |
| 5133 | if (cpu_subset) |
| 5134 | goto error; |
| 5135 | show_pkg_only++; |
| 5136 | return; |
| 5137 | } |
| 5138 | if (show_core_only || show_pkg_only) |
| 5139 | goto error; |
| 5140 | |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 5141 | cpu_subset = CPU_ALLOC(CPU_SUBSET_MAXCPUS); |
| 5142 | if (cpu_subset == NULL) |
| 5143 | err(3, "CPU_ALLOC"); |
| 5144 | cpu_subset_size = CPU_ALLOC_SIZE(CPU_SUBSET_MAXCPUS); |
| 5145 | |
| 5146 | CPU_ZERO_S(cpu_subset_size, cpu_subset); |
| 5147 | |
| 5148 | next = optarg; |
| 5149 | |
| 5150 | while (next && *next) { |
| 5151 | |
| 5152 | if (*next == '-') /* no negative cpu numbers */ |
| 5153 | goto error; |
| 5154 | |
| 5155 | start = strtoul(next, &next, 10); |
| 5156 | |
| 5157 | if (start >= CPU_SUBSET_MAXCPUS) |
| 5158 | goto error; |
| 5159 | CPU_SET_S(start, cpu_subset_size, cpu_subset); |
| 5160 | |
| 5161 | if (*next == '\0') |
| 5162 | break; |
| 5163 | |
| 5164 | if (*next == ',') { |
| 5165 | next += 1; |
| 5166 | continue; |
| 5167 | } |
| 5168 | |
| 5169 | if (*next == '-') { |
| 5170 | next += 1; /* start range */ |
| 5171 | } else if (*next == '.') { |
| 5172 | next += 1; |
| 5173 | if (*next == '.') |
| 5174 | next += 1; /* start range */ |
| 5175 | else |
| 5176 | goto error; |
| 5177 | } |
| 5178 | |
| 5179 | end = strtoul(next, &next, 10); |
| 5180 | if (end <= start) |
| 5181 | goto error; |
| 5182 | |
| 5183 | while (++start <= end) { |
| 5184 | if (start >= CPU_SUBSET_MAXCPUS) |
| 5185 | goto error; |
| 5186 | CPU_SET_S(start, cpu_subset_size, cpu_subset); |
| 5187 | } |
| 5188 | |
| 5189 | if (*next == ',') |
| 5190 | next += 1; |
| 5191 | else if (*next != '\0') |
| 5192 | goto error; |
| 5193 | } |
| 5194 | |
| 5195 | return; |
| 5196 | |
| 5197 | error: |
Len Brown | 4e4e1e7 | 2017-02-21 22:33:42 -0500 | [diff] [blame] | 5198 | fprintf(stderr, "\"--cpu %s\" malformed\n", optarg); |
| 5199 | help(); |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 5200 | exit(-1); |
| 5201 | } |
| 5202 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5203 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5204 | void cmdline(int argc, char **argv) |
| 5205 | { |
| 5206 | int opt; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5207 | int option_index = 0; |
| 5208 | static struct option long_options[] = { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5209 | {"add", required_argument, 0, 'a'}, |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 5210 | {"cpu", required_argument, 0, 'c'}, |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5211 | {"Dump", no_argument, 0, 'D'}, |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5212 | {"debug", no_argument, 0, 'd'}, /* internal, not documented */ |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5213 | {"enable", required_argument, 0, 'e'}, |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5214 | {"interval", required_argument, 0, 'i'}, |
| 5215 | {"help", no_argument, 0, 'h'}, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5216 | {"hide", required_argument, 0, 'H'}, // meh, -h taken by --help |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5217 | {"Joules", no_argument, 0, 'J'}, |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 5218 | {"list", no_argument, 0, 'l'}, |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5219 | {"out", required_argument, 0, 'o'}, |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5220 | {"quiet", no_argument, 0, 'q'}, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5221 | {"show", required_argument, 0, 's'}, |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5222 | {"Summary", no_argument, 0, 'S'}, |
| 5223 | {"TCC", required_argument, 0, 'T'}, |
| 5224 | {"version", no_argument, 0, 'v' }, |
| 5225 | {0, 0, 0, 0 } |
| 5226 | }; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5227 | |
| 5228 | progname = argv[0]; |
| 5229 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5230 | 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] | 5231 | long_options, &option_index)) != -1) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5232 | switch (opt) { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5233 | case 'a': |
| 5234 | parse_add_command(optarg); |
| 5235 | break; |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 5236 | case 'c': |
| 5237 | parse_cpu_command(optarg); |
| 5238 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5239 | case 'D': |
| 5240 | dump_only++; |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 5241 | break; |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5242 | case 'e': |
| 5243 | /* --enable specified counter */ |
| 5244 | bic_enabled |= bic_lookup(optarg, SHOW_LIST); |
| 5245 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5246 | case 'd': |
| 5247 | debug++; |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5248 | ENABLE_BIC(BIC_DISABLED_BY_DEFAULT); |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 5249 | break; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5250 | case 'H': |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5251 | /* |
| 5252 | * --hide: do not show those specified |
| 5253 | * multiple invocations simply clear more bits in enabled mask |
| 5254 | */ |
| 5255 | bic_enabled &= ~bic_lookup(optarg, HIDE_LIST); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5256 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5257 | case 'h': |
| 5258 | default: |
| 5259 | help(); |
| 5260 | exit(1); |
| 5261 | case 'i': |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 5262 | { |
| 5263 | double interval = strtod(optarg, NULL); |
| 5264 | |
| 5265 | if (interval < 0.001) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5266 | fprintf(outf, "interval %f seconds is too small\n", |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 5267 | interval); |
| 5268 | exit(2); |
| 5269 | } |
| 5270 | |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 5271 | interval_tv.tv_sec = interval_ts.tv_sec = interval; |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 5272 | interval_tv.tv_usec = (interval - interval_tv.tv_sec) * 1000000; |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 5273 | interval_ts.tv_nsec = (interval - interval_ts.tv_sec) * 1000000000; |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 5274 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 5275 | break; |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 5276 | case 'J': |
| 5277 | rapl_joules++; |
| 5278 | break; |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 5279 | case 'l': |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5280 | ENABLE_BIC(BIC_DISABLED_BY_DEFAULT); |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 5281 | list_header_only++; |
| 5282 | quiet++; |
| 5283 | break; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5284 | case 'o': |
| 5285 | outf = fopen_or_die(optarg, "w"); |
| 5286 | break; |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5287 | case 'q': |
| 5288 | quiet = 1; |
| 5289 | break; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5290 | case 's': |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5291 | /* |
| 5292 | * --show: show only those specified |
| 5293 | * The 1st invocation will clear and replace the enabled mask |
| 5294 | * subsequent invocations can add to it. |
| 5295 | */ |
| 5296 | if (shown == 0) |
| 5297 | bic_enabled = bic_lookup(optarg, SHOW_LIST); |
| 5298 | else |
| 5299 | bic_enabled |= bic_lookup(optarg, SHOW_LIST); |
| 5300 | shown = 1; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5301 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5302 | case 'S': |
| 5303 | summary_only++; |
| 5304 | break; |
| 5305 | case 'T': |
| 5306 | tcc_activation_temp_override = atoi(optarg); |
| 5307 | break; |
| 5308 | case 'v': |
| 5309 | print_version(); |
| 5310 | exit(0); |
| 5311 | break; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5312 | } |
| 5313 | } |
| 5314 | } |
| 5315 | |
| 5316 | int main(int argc, char **argv) |
| 5317 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5318 | outf = stderr; |
| 5319 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5320 | cmdline(argc, argv); |
| 5321 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5322 | if (!quiet) |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5323 | print_version(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5324 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5325 | probe_sysfs(); |
| 5326 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5327 | turbostat_init(); |
| 5328 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 5329 | /* dump counters and exit */ |
| 5330 | if (dump_only) |
| 5331 | return get_and_dump_counters(); |
| 5332 | |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 5333 | /* list header and exit */ |
| 5334 | if (list_header_only) { |
| 5335 | print_header(","); |
| 5336 | flush_output_stdout(); |
| 5337 | return 0; |
| 5338 | } |
| 5339 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5340 | /* |
| 5341 | * if any params left, it must be a command to fork |
| 5342 | */ |
| 5343 | if (argc - optind) |
| 5344 | return fork_it(argv + optind); |
| 5345 | else |
| 5346 | turbostat_loop(); |
| 5347 | |
| 5348 | return 0; |
| 5349 | } |