Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1 | /* |
| 2 | * turbostat -- show CPU frequency and C-state residency |
| 3 | * on modern Intel turbo-capable processors. |
| 4 | * |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 5 | * Copyright (c) 2013 Intel Corporation. |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 6 | * Len Brown <len.brown@intel.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms and conditions of the GNU General Public License, |
| 10 | * version 2, as published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | */ |
| 21 | |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 22 | #define _GNU_SOURCE |
Josh Triplett | b731f31 | 2013-08-20 17:20:12 -0700 | [diff] [blame] | 23 | #include MSRHEADER |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 24 | #include INTEL_FAMILY_HEADER |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 25 | #include <stdarg.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 26 | #include <stdio.h> |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 27 | #include <err.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 28 | #include <unistd.h> |
| 29 | #include <sys/types.h> |
| 30 | #include <sys/wait.h> |
| 31 | #include <sys/stat.h> |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 32 | #include <sys/select.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 33 | #include <sys/resource.h> |
| 34 | #include <fcntl.h> |
| 35 | #include <signal.h> |
| 36 | #include <sys/time.h> |
| 37 | #include <stdlib.h> |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 38 | #include <getopt.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 39 | #include <dirent.h> |
| 40 | #include <string.h> |
| 41 | #include <ctype.h> |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 42 | #include <sched.h> |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 43 | #include <time.h> |
Josh Triplett | 2b92865 | 2013-08-20 17:20:14 -0700 | [diff] [blame] | 44 | #include <cpuid.h> |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 45 | #include <linux/capability.h> |
| 46 | #include <errno.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 47 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 48 | char *proc_stat = "/proc/stat"; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 49 | FILE *outf; |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 50 | int *fd_percpu; |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 51 | struct timeval interval_tv = {5, 0}; |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 52 | struct timespec interval_ts = {5, 0}; |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 53 | struct timespec one_msec = {0, 1000000}; |
Chen Yu | 023fe0a | 2018-04-26 08:41:03 +0800 | [diff] [blame] | 54 | unsigned int num_iterations; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 55 | unsigned int debug; |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 56 | unsigned int quiet; |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 57 | unsigned int shown; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 58 | unsigned int sums_need_wide_columns; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 59 | unsigned int rapl_joules; |
| 60 | unsigned int summary_only; |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 61 | unsigned int list_header_only; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 62 | unsigned int dump_only; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 63 | unsigned int do_snb_cstates; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 64 | unsigned int do_knl_cstates; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 65 | unsigned int do_slm_cstates; |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame] | 66 | unsigned int do_cnl_cstates; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 67 | unsigned int use_c1_residency_msr; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 68 | unsigned int has_aperf; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 69 | unsigned int has_epb; |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 70 | unsigned int do_irtl_snb; |
| 71 | unsigned int do_irtl_hsw; |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 72 | unsigned int units = 1000000; /* MHz etc */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 73 | unsigned int genuine_intel; |
| 74 | unsigned int has_invariant_tsc; |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 75 | unsigned int do_nhm_platform_info; |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 76 | unsigned int no_MSR_MISC_PWR_MGMT; |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 77 | unsigned int aperf_mperf_multiplier = 1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 78 | double bclk; |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 79 | double base_hz; |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 80 | unsigned int has_base_hz; |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 81 | double tsc_tweak = 1.0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 82 | unsigned int show_pkg_only; |
| 83 | unsigned int show_core_only; |
| 84 | char *output_buffer, *outp; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 85 | unsigned int do_rapl; |
| 86 | unsigned int do_dts; |
| 87 | unsigned int do_ptm; |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 88 | unsigned long long gfx_cur_rc6_ms; |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 89 | unsigned long long cpuidle_cur_cpu_lpi_us; |
| 90 | unsigned long long cpuidle_cur_sys_lpi_us; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 91 | unsigned int gfx_cur_mhz; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 92 | unsigned int tcc_activation_temp; |
| 93 | unsigned int tcc_activation_temp_override; |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 94 | double rapl_power_units, rapl_time_units; |
| 95 | double rapl_dram_energy_units, rapl_energy_units; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 96 | double rapl_joule_counter_range; |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 97 | unsigned int do_core_perf_limit_reasons; |
Artem Bityutskiy | ac980e1 | 2017-09-05 15:14:08 +0300 | [diff] [blame] | 98 | unsigned int has_automatic_cstate_conversion; |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 99 | unsigned int do_gfx_perf_limit_reasons; |
| 100 | unsigned int do_ring_perf_limit_reasons; |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 101 | unsigned int crystal_hz; |
| 102 | unsigned long long tsc_hz; |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 103 | int base_cpu; |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 104 | double discover_bclk(unsigned int family, unsigned int model); |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 105 | unsigned int has_hwp; /* IA32_PM_ENABLE, IA32_HWP_CAPABILITIES */ |
| 106 | /* IA32_HWP_REQUEST, IA32_HWP_STATUS */ |
| 107 | unsigned int has_hwp_notify; /* IA32_HWP_INTERRUPT */ |
| 108 | unsigned int has_hwp_activity_window; /* IA32_HWP_REQUEST[bits 41:32] */ |
| 109 | unsigned int has_hwp_epp; /* IA32_HWP_REQUEST[bits 31:24] */ |
| 110 | unsigned int has_hwp_pkg; /* IA32_HWP_REQUEST_PKG */ |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 111 | unsigned int has_misc_feature_control; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 112 | |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 113 | #define RAPL_PKG (1 << 0) |
| 114 | /* 0x610 MSR_PKG_POWER_LIMIT */ |
| 115 | /* 0x611 MSR_PKG_ENERGY_STATUS */ |
| 116 | #define RAPL_PKG_PERF_STATUS (1 << 1) |
| 117 | /* 0x613 MSR_PKG_PERF_STATUS */ |
| 118 | #define RAPL_PKG_POWER_INFO (1 << 2) |
| 119 | /* 0x614 MSR_PKG_POWER_INFO */ |
| 120 | |
| 121 | #define RAPL_DRAM (1 << 3) |
| 122 | /* 0x618 MSR_DRAM_POWER_LIMIT */ |
| 123 | /* 0x619 MSR_DRAM_ENERGY_STATUS */ |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 124 | #define RAPL_DRAM_PERF_STATUS (1 << 4) |
| 125 | /* 0x61b MSR_DRAM_PERF_STATUS */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 126 | #define RAPL_DRAM_POWER_INFO (1 << 5) |
| 127 | /* 0x61c MSR_DRAM_POWER_INFO */ |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 128 | |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 129 | #define RAPL_CORES_POWER_LIMIT (1 << 6) |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 130 | /* 0x638 MSR_PP0_POWER_LIMIT */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 131 | #define RAPL_CORE_POLICY (1 << 7) |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 132 | /* 0x63a MSR_PP0_POLICY */ |
| 133 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 134 | #define RAPL_GFX (1 << 8) |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 135 | /* 0x640 MSR_PP1_POWER_LIMIT */ |
| 136 | /* 0x641 MSR_PP1_ENERGY_STATUS */ |
| 137 | /* 0x642 MSR_PP1_POLICY */ |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 138 | |
| 139 | #define RAPL_CORES_ENERGY_STATUS (1 << 9) |
| 140 | /* 0x639 MSR_PP0_ENERGY_STATUS */ |
| 141 | #define RAPL_CORES (RAPL_CORES_ENERGY_STATUS | RAPL_CORES_POWER_LIMIT) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 142 | #define TJMAX_DEFAULT 100 |
| 143 | |
| 144 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 145 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 146 | /* |
| 147 | * buffer size used by sscanf() for added column names |
| 148 | * Usually truncated to 7 characters, but also handles 18 columns for raw 64-bit counters |
| 149 | */ |
| 150 | #define NAME_BYTES 20 |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 151 | #define PATH_BYTES 128 |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 152 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 153 | int backwards_count; |
| 154 | char *progname; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 155 | |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 156 | #define CPU_SUBSET_MAXCPUS 1024 /* need to use before probe... */ |
| 157 | cpu_set_t *cpu_present_set, *cpu_affinity_set, *cpu_subset; |
| 158 | size_t cpu_present_setsize, cpu_affinity_setsize, cpu_subset_size; |
Len Brown | 0748eaf | 2018-06-01 12:38:29 -0400 | [diff] [blame] | 159 | #define MAX_ADDED_COUNTERS 8 |
| 160 | #define MAX_ADDED_THREAD_COUNTERS 24 |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 161 | #define BITMASK_SIZE 32 |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 162 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 163 | struct thread_data { |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 164 | struct timeval tv_begin; |
| 165 | struct timeval tv_end; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 166 | unsigned long long tsc; |
| 167 | unsigned long long aperf; |
| 168 | unsigned long long mperf; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 169 | unsigned long long c1; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 170 | unsigned long long irq_count; |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 171 | unsigned int smi_count; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 172 | unsigned int cpu_id; |
| 173 | unsigned int flags; |
| 174 | #define CPU_IS_FIRST_THREAD_IN_CORE 0x2 |
| 175 | #define CPU_IS_FIRST_CORE_IN_PACKAGE 0x4 |
Len Brown | 0748eaf | 2018-06-01 12:38:29 -0400 | [diff] [blame] | 176 | unsigned long long counter[MAX_ADDED_THREAD_COUNTERS]; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 177 | } *thread_even, *thread_odd; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 178 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 179 | struct core_data { |
| 180 | unsigned long long c3; |
| 181 | unsigned long long c6; |
| 182 | unsigned long long c7; |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 183 | 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] | 184 | unsigned int core_temp_c; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 185 | unsigned int core_id; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 186 | unsigned long long counter[MAX_ADDED_COUNTERS]; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 187 | } *core_even, *core_odd; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 188 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 189 | struct pkg_data { |
| 190 | unsigned long long pc2; |
| 191 | unsigned long long pc3; |
| 192 | unsigned long long pc6; |
| 193 | unsigned long long pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 194 | unsigned long long pc8; |
| 195 | unsigned long long pc9; |
| 196 | unsigned long long pc10; |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 197 | unsigned long long cpu_lpi; |
| 198 | unsigned long long sys_lpi; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 199 | unsigned long long pkg_wtd_core_c0; |
| 200 | unsigned long long pkg_any_core_c0; |
| 201 | unsigned long long pkg_any_gfxe_c0; |
| 202 | unsigned long long pkg_both_core_gfxe_c0; |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 203 | long long gfx_rc6_ms; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 204 | unsigned int gfx_mhz; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 205 | unsigned int package_id; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 206 | unsigned int energy_pkg; /* MSR_PKG_ENERGY_STATUS */ |
| 207 | unsigned int energy_dram; /* MSR_DRAM_ENERGY_STATUS */ |
| 208 | unsigned int energy_cores; /* MSR_PP0_ENERGY_STATUS */ |
| 209 | unsigned int energy_gfx; /* MSR_PP1_ENERGY_STATUS */ |
| 210 | unsigned int rapl_pkg_perf_status; /* MSR_PKG_PERF_STATUS */ |
| 211 | unsigned int rapl_dram_perf_status; /* MSR_DRAM_PERF_STATUS */ |
| 212 | unsigned int pkg_temp_c; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 213 | unsigned long long counter[MAX_ADDED_COUNTERS]; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 214 | } *package_even, *package_odd; |
| 215 | |
| 216 | #define ODD_COUNTERS thread_odd, core_odd, package_odd |
| 217 | #define EVEN_COUNTERS thread_even, core_even, package_even |
| 218 | |
| 219 | #define GET_THREAD(thread_base, thread_no, core_no, pkg_no) \ |
| 220 | (thread_base + (pkg_no) * topo.num_cores_per_pkg * \ |
| 221 | topo.num_threads_per_core + \ |
| 222 | (core_no) * topo.num_threads_per_core + (thread_no)) |
| 223 | #define GET_CORE(core_base, core_no, pkg_no) \ |
| 224 | (core_base + (pkg_no) * topo.num_cores_per_pkg + (core_no)) |
| 225 | #define GET_PKG(pkg_base, pkg_no) (pkg_base + pkg_no) |
| 226 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 227 | enum counter_scope {SCOPE_CPU, SCOPE_CORE, SCOPE_PACKAGE}; |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 228 | enum counter_type {COUNTER_ITEMS, COUNTER_CYCLES, COUNTER_SECONDS, COUNTER_USEC}; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 229 | enum counter_format {FORMAT_RAW, FORMAT_DELTA, FORMAT_PERCENT}; |
| 230 | |
| 231 | struct msr_counter { |
| 232 | unsigned int msr_num; |
| 233 | char name[NAME_BYTES]; |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 234 | char path[PATH_BYTES]; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 235 | unsigned int width; |
| 236 | enum counter_type type; |
| 237 | enum counter_format format; |
| 238 | struct msr_counter *next; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 239 | unsigned int flags; |
| 240 | #define FLAGS_HIDE (1 << 0) |
| 241 | #define FLAGS_SHOW (1 << 1) |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 242 | #define SYSFS_PERCPU (1 << 1) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 243 | }; |
| 244 | |
| 245 | struct sys_counters { |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 246 | unsigned int added_thread_counters; |
| 247 | unsigned int added_core_counters; |
| 248 | unsigned int added_package_counters; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 249 | struct msr_counter *tp; |
| 250 | struct msr_counter *cp; |
| 251 | struct msr_counter *pp; |
| 252 | } sys; |
| 253 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 254 | struct system_summary { |
| 255 | struct thread_data threads; |
| 256 | struct core_data cores; |
| 257 | struct pkg_data packages; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 258 | } average; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 259 | |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 260 | struct cpu_topology { |
| 261 | int physical_package_id; |
| 262 | int logical_cpu_id; |
Prarit Bhargava | ef60574 | 2018-06-01 10:04:30 -0400 | [diff] [blame^] | 263 | int physical_node_id; |
| 264 | int logical_node_id; /* 0-based count within the package */ |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 265 | int physical_core_id; |
| 266 | cpu_set_t *put_ids; /* Processing Unit/Thread IDs */ |
| 267 | } *cpus; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 268 | |
| 269 | struct topo_params { |
| 270 | int num_packages; |
| 271 | int num_cpus; |
| 272 | int num_cores; |
| 273 | int max_cpu_num; |
Prarit Bhargava | ef60574 | 2018-06-01 10:04:30 -0400 | [diff] [blame^] | 274 | int max_node_num; |
| 275 | int num_nodes_per_pkg; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 276 | int num_cores_per_pkg; |
| 277 | int num_threads_per_core; |
| 278 | } topo; |
| 279 | |
| 280 | struct timeval tv_even, tv_odd, tv_delta; |
| 281 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 282 | int *irq_column_2_cpu; /* /proc/interrupts column numbers */ |
| 283 | int *irqs_per_cpu; /* indexed by cpu_num */ |
| 284 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 285 | void setup_all_buffers(void); |
| 286 | |
| 287 | int cpu_is_not_present(int cpu) |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 288 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 289 | return !CPU_ISSET_S(cpu, cpu_present_setsize, cpu_present_set); |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 290 | } |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 291 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 292 | * run func(thread, core, package) in topology order |
| 293 | * skip non-present cpus |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 294 | */ |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 295 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 296 | int for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg_data *), |
| 297 | 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] | 298 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 299 | int retval, pkg_no, core_no, thread_no; |
| 300 | |
| 301 | for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { |
| 302 | for (core_no = 0; core_no < topo.num_cores_per_pkg; ++core_no) { |
| 303 | for (thread_no = 0; thread_no < |
| 304 | topo.num_threads_per_core; ++thread_no) { |
| 305 | struct thread_data *t; |
| 306 | struct core_data *c; |
| 307 | struct pkg_data *p; |
| 308 | |
| 309 | t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); |
| 310 | |
| 311 | if (cpu_is_not_present(t->cpu_id)) |
| 312 | continue; |
| 313 | |
| 314 | c = GET_CORE(core_base, core_no, pkg_no); |
| 315 | p = GET_PKG(pkg_base, pkg_no); |
| 316 | |
| 317 | retval = func(t, c, p); |
| 318 | if (retval) |
| 319 | return retval; |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | return 0; |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | int cpu_migrate(int cpu) |
| 327 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 328 | CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); |
| 329 | CPU_SET_S(cpu, cpu_affinity_setsize, cpu_affinity_set); |
| 330 | if (sched_setaffinity(0, cpu_affinity_setsize, cpu_affinity_set) == -1) |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 331 | return -1; |
| 332 | else |
| 333 | return 0; |
| 334 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 335 | int get_msr_fd(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 336 | { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 337 | char pathname[32]; |
| 338 | int fd; |
| 339 | |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 340 | fd = fd_percpu[cpu]; |
| 341 | |
| 342 | if (fd) |
| 343 | return fd; |
| 344 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 345 | sprintf(pathname, "/dev/cpu/%d/msr", cpu); |
| 346 | fd = open(pathname, O_RDONLY); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 347 | if (fd < 0) |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 348 | 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] | 349 | |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 350 | fd_percpu[cpu] = fd; |
| 351 | |
| 352 | return fd; |
| 353 | } |
| 354 | |
| 355 | int get_msr(int cpu, off_t offset, unsigned long long *msr) |
| 356 | { |
| 357 | ssize_t retval; |
| 358 | |
| 359 | retval = pread(get_msr_fd(cpu), msr, sizeof(*msr), offset); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 360 | |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 361 | if (retval != sizeof *msr) |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 362 | 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] | 363 | |
| 364 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 365 | } |
| 366 | |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 367 | /* |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 368 | * Each string in this array is compared in --show and --hide cmdline. |
| 369 | * 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] | 370 | */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 371 | struct msr_counter bic[] = { |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 372 | { 0x0, "usec" }, |
| 373 | { 0x0, "Time_Of_Day_Seconds" }, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 374 | { 0x0, "Package" }, |
| 375 | { 0x0, "Avg_MHz" }, |
| 376 | { 0x0, "Bzy_MHz" }, |
| 377 | { 0x0, "TSC_MHz" }, |
| 378 | { 0x0, "IRQ" }, |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 379 | { 0x0, "SMI", "", 32, 0, FORMAT_DELTA, NULL}, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 380 | { 0x0, "Busy%" }, |
| 381 | { 0x0, "CPU%c1" }, |
| 382 | { 0x0, "CPU%c3" }, |
| 383 | { 0x0, "CPU%c6" }, |
| 384 | { 0x0, "CPU%c7" }, |
| 385 | { 0x0, "ThreadC" }, |
| 386 | { 0x0, "CoreTmp" }, |
| 387 | { 0x0, "CoreCnt" }, |
| 388 | { 0x0, "PkgTmp" }, |
| 389 | { 0x0, "GFX%rc6" }, |
| 390 | { 0x0, "GFXMHz" }, |
| 391 | { 0x0, "Pkg%pc2" }, |
| 392 | { 0x0, "Pkg%pc3" }, |
| 393 | { 0x0, "Pkg%pc6" }, |
| 394 | { 0x0, "Pkg%pc7" }, |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 395 | { 0x0, "Pkg%pc8" }, |
| 396 | { 0x0, "Pkg%pc9" }, |
Len Brown | 4bd1f8f | 2018-01-28 23:42:42 -0500 | [diff] [blame] | 397 | { 0x0, "Pk%pc10" }, |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 398 | { 0x0, "CPU%LPI" }, |
| 399 | { 0x0, "SYS%LPI" }, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 400 | { 0x0, "PkgWatt" }, |
| 401 | { 0x0, "CorWatt" }, |
| 402 | { 0x0, "GFXWatt" }, |
| 403 | { 0x0, "PkgCnt" }, |
| 404 | { 0x0, "RAMWatt" }, |
| 405 | { 0x0, "PKG_%" }, |
| 406 | { 0x0, "RAM_%" }, |
| 407 | { 0x0, "Pkg_J" }, |
| 408 | { 0x0, "Cor_J" }, |
| 409 | { 0x0, "GFX_J" }, |
| 410 | { 0x0, "RAM_J" }, |
| 411 | { 0x0, "Core" }, |
| 412 | { 0x0, "CPU" }, |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 413 | { 0x0, "Mod%c6" }, |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 414 | { 0x0, "sysfs" }, |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 415 | { 0x0, "Totl%C0" }, |
| 416 | { 0x0, "Any%C0" }, |
| 417 | { 0x0, "GFX%C0" }, |
| 418 | { 0x0, "CPUGFX%" }, |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 419 | { 0x0, "Node%" }, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 420 | }; |
| 421 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 422 | |
| 423 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 424 | #define MAX_BIC (sizeof(bic) / sizeof(struct msr_counter)) |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 425 | #define BIC_USEC (1ULL << 0) |
| 426 | #define BIC_TOD (1ULL << 1) |
| 427 | #define BIC_Package (1ULL << 2) |
| 428 | #define BIC_Avg_MHz (1ULL << 3) |
| 429 | #define BIC_Bzy_MHz (1ULL << 4) |
| 430 | #define BIC_TSC_MHz (1ULL << 5) |
| 431 | #define BIC_IRQ (1ULL << 6) |
| 432 | #define BIC_SMI (1ULL << 7) |
| 433 | #define BIC_Busy (1ULL << 8) |
| 434 | #define BIC_CPU_c1 (1ULL << 9) |
| 435 | #define BIC_CPU_c3 (1ULL << 10) |
| 436 | #define BIC_CPU_c6 (1ULL << 11) |
| 437 | #define BIC_CPU_c7 (1ULL << 12) |
| 438 | #define BIC_ThreadC (1ULL << 13) |
| 439 | #define BIC_CoreTmp (1ULL << 14) |
| 440 | #define BIC_CoreCnt (1ULL << 15) |
| 441 | #define BIC_PkgTmp (1ULL << 16) |
| 442 | #define BIC_GFX_rc6 (1ULL << 17) |
| 443 | #define BIC_GFXMHz (1ULL << 18) |
| 444 | #define BIC_Pkgpc2 (1ULL << 19) |
| 445 | #define BIC_Pkgpc3 (1ULL << 20) |
| 446 | #define BIC_Pkgpc6 (1ULL << 21) |
| 447 | #define BIC_Pkgpc7 (1ULL << 22) |
| 448 | #define BIC_Pkgpc8 (1ULL << 23) |
| 449 | #define BIC_Pkgpc9 (1ULL << 24) |
| 450 | #define BIC_Pkgpc10 (1ULL << 25) |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 451 | #define BIC_CPU_LPI (1ULL << 26) |
| 452 | #define BIC_SYS_LPI (1ULL << 27) |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 453 | #define BIC_PkgWatt (1ULL << 26) |
| 454 | #define BIC_CorWatt (1ULL << 27) |
| 455 | #define BIC_GFXWatt (1ULL << 28) |
| 456 | #define BIC_PkgCnt (1ULL << 29) |
| 457 | #define BIC_RAMWatt (1ULL << 30) |
| 458 | #define BIC_PKG__ (1ULL << 31) |
| 459 | #define BIC_RAM__ (1ULL << 32) |
| 460 | #define BIC_Pkg_J (1ULL << 33) |
| 461 | #define BIC_Cor_J (1ULL << 34) |
| 462 | #define BIC_GFX_J (1ULL << 35) |
| 463 | #define BIC_RAM_J (1ULL << 36) |
| 464 | #define BIC_Core (1ULL << 37) |
| 465 | #define BIC_CPU (1ULL << 38) |
| 466 | #define BIC_Mod_c6 (1ULL << 39) |
| 467 | #define BIC_sysfs (1ULL << 40) |
| 468 | #define BIC_Totl_c0 (1ULL << 41) |
| 469 | #define BIC_Any_c0 (1ULL << 42) |
| 470 | #define BIC_GFX_c0 (1ULL << 43) |
| 471 | #define BIC_CPUGFX (1ULL << 44) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 472 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 473 | #define BIC_DISABLED_BY_DEFAULT (BIC_USEC | BIC_TOD) |
| 474 | |
| 475 | unsigned long long bic_enabled = (0xFFFFFFFFFFFFFFFFULL & ~BIC_DISABLED_BY_DEFAULT); |
| 476 | unsigned long long bic_present = BIC_USEC | BIC_TOD | BIC_sysfs; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 477 | |
| 478 | #define DO_BIC(COUNTER_NAME) (bic_enabled & bic_present & COUNTER_NAME) |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 479 | #define ENABLE_BIC(COUNTER_NAME) (bic_enabled |= COUNTER_NAME) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 480 | #define BIC_PRESENT(COUNTER_BIT) (bic_present |= COUNTER_BIT) |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 481 | #define BIC_NOT_PRESENT(COUNTER_BIT) (bic_present &= ~COUNTER_BIT) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 482 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 483 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 484 | #define MAX_DEFERRED 16 |
| 485 | char *deferred_skip_names[MAX_DEFERRED]; |
| 486 | int deferred_skip_index; |
| 487 | |
| 488 | /* |
| 489 | * HIDE_LIST - hide this list of counters, show the rest [default] |
| 490 | * SHOW_LIST - show this list of counters, hide the rest |
| 491 | */ |
| 492 | enum show_hide_mode { SHOW_LIST, HIDE_LIST } global_show_hide_mode = HIDE_LIST; |
| 493 | |
| 494 | void help(void) |
| 495 | { |
| 496 | fprintf(outf, |
| 497 | "Usage: turbostat [OPTIONS][(--interval seconds) | COMMAND ...]\n" |
| 498 | "\n" |
| 499 | "Turbostat forks the specified COMMAND and prints statistics\n" |
| 500 | "when COMMAND completes.\n" |
| 501 | "If no COMMAND is specified, turbostat wakes every 5-seconds\n" |
| 502 | "to print statistics, until interrupted.\n" |
| 503 | "--add add a counter\n" |
| 504 | " eg. --add msr0x10,u64,cpu,delta,MY_TSC\n" |
| 505 | "--cpu cpu-set limit output to summary plus cpu-set:\n" |
| 506 | " {core | package | j,k,l..m,n-p }\n" |
| 507 | "--quiet skip decoding system configuration header\n" |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 508 | "--interval sec.subsec Override default 5-second measurement interval\n" |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 509 | "--help print this help message\n" |
| 510 | "--list list column headers only\n" |
Chen Yu | 023fe0a | 2018-04-26 08:41:03 +0800 | [diff] [blame] | 511 | "--num_iterations num number of the measurement iterations\n" |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 512 | "--out file create or truncate \"file\" for all output\n" |
| 513 | "--version print version information\n" |
| 514 | "\n" |
| 515 | "For more help, run \"man turbostat\"\n"); |
| 516 | } |
| 517 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 518 | /* |
| 519 | * bic_lookup |
| 520 | * for all the strings in comma separate name_list, |
| 521 | * set the approprate bit in return value. |
| 522 | */ |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 523 | 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] | 524 | { |
| 525 | int i; |
| 526 | unsigned long long retval = 0; |
| 527 | |
| 528 | while (name_list) { |
| 529 | char *comma; |
| 530 | |
| 531 | comma = strchr(name_list, ','); |
| 532 | |
| 533 | if (comma) |
| 534 | *comma = '\0'; |
| 535 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 536 | if (!strcmp(name_list, "all")) |
| 537 | return ~0; |
| 538 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 539 | for (i = 0; i < MAX_BIC; ++i) { |
| 540 | if (!strcmp(name_list, bic[i].name)) { |
| 541 | retval |= (1ULL << i); |
| 542 | break; |
| 543 | } |
| 544 | } |
| 545 | if (i == MAX_BIC) { |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 546 | if (mode == SHOW_LIST) { |
| 547 | fprintf(stderr, "Invalid counter name: %s\n", name_list); |
| 548 | exit(-1); |
| 549 | } |
| 550 | deferred_skip_names[deferred_skip_index++] = name_list; |
| 551 | if (debug) |
| 552 | fprintf(stderr, "deferred \"%s\"\n", name_list); |
| 553 | if (deferred_skip_index >= MAX_DEFERRED) { |
| 554 | fprintf(stderr, "More than max %d un-recognized --skip options '%s'\n", |
| 555 | MAX_DEFERRED, name_list); |
| 556 | help(); |
| 557 | exit(1); |
| 558 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | name_list = comma; |
| 562 | if (name_list) |
| 563 | name_list++; |
| 564 | |
| 565 | } |
| 566 | return retval; |
| 567 | } |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 568 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 569 | |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 570 | void print_header(char *delim) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 571 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 572 | struct msr_counter *mp; |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 573 | int printed = 0; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 574 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 575 | if (DO_BIC(BIC_USEC)) |
| 576 | outp += sprintf(outp, "%susec", (printed++ ? delim : "")); |
| 577 | if (DO_BIC(BIC_TOD)) |
| 578 | outp += sprintf(outp, "%sTime_Of_Day_Seconds", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 579 | if (DO_BIC(BIC_Package)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 580 | outp += sprintf(outp, "%sPackage", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 581 | if (DO_BIC(BIC_Core)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 582 | outp += sprintf(outp, "%sCore", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 583 | if (DO_BIC(BIC_CPU)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 584 | outp += sprintf(outp, "%sCPU", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 585 | if (DO_BIC(BIC_Avg_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 586 | outp += sprintf(outp, "%sAvg_MHz", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 587 | if (DO_BIC(BIC_Busy)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 588 | outp += sprintf(outp, "%sBusy%%", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 589 | if (DO_BIC(BIC_Bzy_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 590 | outp += sprintf(outp, "%sBzy_MHz", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 591 | if (DO_BIC(BIC_TSC_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 592 | outp += sprintf(outp, "%sTSC_MHz", (printed++ ? delim : "")); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 593 | |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 594 | if (DO_BIC(BIC_IRQ)) { |
| 595 | if (sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 596 | outp += sprintf(outp, "%s IRQ", (printed++ ? delim : "")); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 597 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 598 | outp += sprintf(outp, "%sIRQ", (printed++ ? delim : "")); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 599 | } |
| 600 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 601 | if (DO_BIC(BIC_SMI)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 602 | outp += sprintf(outp, "%sSMI", (printed++ ? delim : "")); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 603 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 604 | for (mp = sys.tp; mp; mp = mp->next) { |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 605 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 606 | if (mp->format == FORMAT_RAW) { |
| 607 | if (mp->width == 64) |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 608 | outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 609 | else |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 610 | outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 611 | } else { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 612 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 613 | outp += sprintf(outp, "%s%8s", (printed++ ? delim : ""), mp->name); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 614 | else |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 615 | outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 619 | if (DO_BIC(BIC_CPU_c1)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 620 | outp += sprintf(outp, "%sCPU%%c1", (printed++ ? delim : "")); |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame] | 621 | 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] | 622 | outp += sprintf(outp, "%sCPU%%c3", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 623 | if (DO_BIC(BIC_CPU_c6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 624 | outp += sprintf(outp, "%sCPU%%c6", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 625 | if (DO_BIC(BIC_CPU_c7)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 626 | outp += sprintf(outp, "%sCPU%%c7", (printed++ ? delim : "")); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 627 | |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 628 | if (DO_BIC(BIC_Mod_c6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 629 | outp += sprintf(outp, "%sMod%%c6", (printed++ ? delim : "")); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 630 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 631 | if (DO_BIC(BIC_CoreTmp)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 632 | outp += sprintf(outp, "%sCoreTmp", (printed++ ? delim : "")); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 633 | |
| 634 | for (mp = sys.cp; mp; mp = mp->next) { |
| 635 | if (mp->format == FORMAT_RAW) { |
| 636 | if (mp->width == 64) |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 637 | outp += sprintf(outp, "%s%18.18s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 638 | else |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 639 | outp += sprintf(outp, "%s%10.10s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 640 | } else { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 641 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
| 642 | outp += sprintf(outp, "%s%8s", delim, mp->name); |
| 643 | else |
| 644 | outp += sprintf(outp, "%s%s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 645 | } |
| 646 | } |
| 647 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 648 | if (DO_BIC(BIC_PkgTmp)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 649 | outp += sprintf(outp, "%sPkgTmp", (printed++ ? delim : "")); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 650 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 651 | if (DO_BIC(BIC_GFX_rc6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 652 | outp += sprintf(outp, "%sGFX%%rc6", (printed++ ? delim : "")); |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 653 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 654 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 655 | outp += sprintf(outp, "%sGFXMHz", (printed++ ? delim : "")); |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 656 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 657 | if (DO_BIC(BIC_Totl_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 658 | outp += sprintf(outp, "%sTotl%%C0", (printed++ ? delim : "")); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 659 | if (DO_BIC(BIC_Any_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 660 | outp += sprintf(outp, "%sAny%%C0", (printed++ ? delim : "")); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 661 | if (DO_BIC(BIC_GFX_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 662 | outp += sprintf(outp, "%sGFX%%C0", (printed++ ? delim : "")); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 663 | if (DO_BIC(BIC_CPUGFX)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 664 | outp += sprintf(outp, "%sCPUGFX%%", (printed++ ? delim : "")); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 665 | |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 666 | if (DO_BIC(BIC_Pkgpc2)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 667 | outp += sprintf(outp, "%sPkg%%pc2", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 668 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 669 | outp += sprintf(outp, "%sPkg%%pc3", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 670 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 671 | outp += sprintf(outp, "%sPkg%%pc6", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 672 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 673 | outp += sprintf(outp, "%sPkg%%pc7", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 674 | if (DO_BIC(BIC_Pkgpc8)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 675 | outp += sprintf(outp, "%sPkg%%pc8", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 676 | if (DO_BIC(BIC_Pkgpc9)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 677 | outp += sprintf(outp, "%sPkg%%pc9", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 678 | if (DO_BIC(BIC_Pkgpc10)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 679 | outp += sprintf(outp, "%sPk%%pc10", (printed++ ? delim : "")); |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 680 | if (DO_BIC(BIC_CPU_LPI)) |
| 681 | outp += sprintf(outp, "%sCPU%%LPI", (printed++ ? delim : "")); |
| 682 | if (DO_BIC(BIC_SYS_LPI)) |
| 683 | outp += sprintf(outp, "%sSYS%%LPI", (printed++ ? delim : "")); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 684 | |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 685 | if (do_rapl && !rapl_joules) { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 686 | if (DO_BIC(BIC_PkgWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 687 | outp += sprintf(outp, "%sPkgWatt", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 688 | if (DO_BIC(BIC_CorWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 689 | outp += sprintf(outp, "%sCorWatt", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 690 | if (DO_BIC(BIC_GFXWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 691 | outp += sprintf(outp, "%sGFXWatt", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 692 | if (DO_BIC(BIC_RAMWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 693 | outp += sprintf(outp, "%sRAMWatt", (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 : "")); |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 698 | } else if (do_rapl && rapl_joules) { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 699 | if (DO_BIC(BIC_Pkg_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 700 | outp += sprintf(outp, "%sPkg_J", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 701 | if (DO_BIC(BIC_Cor_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 702 | outp += sprintf(outp, "%sCor_J", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 703 | if (DO_BIC(BIC_GFX_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 704 | outp += sprintf(outp, "%sGFX_J", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 705 | if (DO_BIC(BIC_RAM_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 706 | outp += sprintf(outp, "%sRAM_J", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 707 | if (DO_BIC(BIC_PKG__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 708 | outp += sprintf(outp, "%sPKG_%%", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 709 | if (DO_BIC(BIC_RAM__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 710 | outp += sprintf(outp, "%sRAM_%%", (printed++ ? delim : "")); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 711 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 712 | for (mp = sys.pp; mp; mp = mp->next) { |
| 713 | if (mp->format == FORMAT_RAW) { |
| 714 | if (mp->width == 64) |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 715 | outp += sprintf(outp, "%s%18.18s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 716 | else |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 717 | outp += sprintf(outp, "%s%10.10s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 718 | } else { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 719 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
| 720 | outp += sprintf(outp, "%s%8s", delim, mp->name); |
| 721 | else |
| 722 | outp += sprintf(outp, "%s%s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 723 | } |
| 724 | } |
| 725 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 726 | outp += sprintf(outp, "\n"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 727 | } |
| 728 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 729 | int dump_counters(struct thread_data *t, struct core_data *c, |
| 730 | struct pkg_data *p) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 731 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 732 | int i; |
| 733 | struct msr_counter *mp; |
| 734 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 735 | 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] | 736 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 737 | if (t) { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 738 | outp += sprintf(outp, "CPU: %d flags 0x%x\n", |
| 739 | t->cpu_id, t->flags); |
| 740 | outp += sprintf(outp, "TSC: %016llX\n", t->tsc); |
| 741 | outp += sprintf(outp, "aperf: %016llX\n", t->aperf); |
| 742 | outp += sprintf(outp, "mperf: %016llX\n", t->mperf); |
| 743 | outp += sprintf(outp, "c1: %016llX\n", t->c1); |
Len Brown | 6886fee | 2016-12-24 15:18:37 -0500 | [diff] [blame] | 744 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 745 | if (DO_BIC(BIC_IRQ)) |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 746 | outp += sprintf(outp, "IRQ: %lld\n", t->irq_count); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 747 | if (DO_BIC(BIC_SMI)) |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 748 | outp += sprintf(outp, "SMI: %d\n", t->smi_count); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 749 | |
| 750 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 751 | outp += sprintf(outp, "tADDED [%d] msr0x%x: %08llX\n", |
| 752 | i, mp->msr_num, t->counter[i]); |
| 753 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 754 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 755 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 756 | if (c) { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 757 | outp += sprintf(outp, "core: %d\n", c->core_id); |
| 758 | outp += sprintf(outp, "c3: %016llX\n", c->c3); |
| 759 | outp += sprintf(outp, "c6: %016llX\n", c->c6); |
| 760 | outp += sprintf(outp, "c7: %016llX\n", c->c7); |
| 761 | outp += sprintf(outp, "DTS: %dC\n", c->core_temp_c); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 762 | |
| 763 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 764 | outp += sprintf(outp, "cADDED [%d] msr0x%x: %08llX\n", |
| 765 | i, mp->msr_num, c->counter[i]); |
| 766 | } |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 767 | outp += sprintf(outp, "mc6_us: %016llX\n", c->mc6_us); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | if (p) { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 771 | outp += sprintf(outp, "package: %d\n", p->package_id); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 772 | |
| 773 | outp += sprintf(outp, "Weighted cores: %016llX\n", p->pkg_wtd_core_c0); |
| 774 | outp += sprintf(outp, "Any cores: %016llX\n", p->pkg_any_core_c0); |
| 775 | outp += sprintf(outp, "Any GFX: %016llX\n", p->pkg_any_gfxe_c0); |
| 776 | outp += sprintf(outp, "CPU + GFX: %016llX\n", p->pkg_both_core_gfxe_c0); |
| 777 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 778 | outp += sprintf(outp, "pc2: %016llX\n", p->pc2); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 779 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 780 | outp += sprintf(outp, "pc3: %016llX\n", p->pc3); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 781 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 782 | outp += sprintf(outp, "pc6: %016llX\n", p->pc6); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 783 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 784 | outp += sprintf(outp, "pc7: %016llX\n", p->pc7); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 785 | outp += sprintf(outp, "pc8: %016llX\n", p->pc8); |
| 786 | outp += sprintf(outp, "pc9: %016llX\n", p->pc9); |
| 787 | outp += sprintf(outp, "pc10: %016llX\n", p->pc10); |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 788 | outp += sprintf(outp, "pc10: %016llX\n", p->pc10); |
| 789 | outp += sprintf(outp, "cpu_lpi: %016llX\n", p->cpu_lpi); |
| 790 | outp += sprintf(outp, "sys_lpi: %016llX\n", p->sys_lpi); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 791 | outp += sprintf(outp, "Joules PKG: %0X\n", p->energy_pkg); |
| 792 | outp += sprintf(outp, "Joules COR: %0X\n", p->energy_cores); |
| 793 | outp += sprintf(outp, "Joules GFX: %0X\n", p->energy_gfx); |
| 794 | outp += sprintf(outp, "Joules RAM: %0X\n", p->energy_dram); |
| 795 | outp += sprintf(outp, "Throttle PKG: %0X\n", |
| 796 | p->rapl_pkg_perf_status); |
| 797 | outp += sprintf(outp, "Throttle RAM: %0X\n", |
| 798 | p->rapl_dram_perf_status); |
| 799 | outp += sprintf(outp, "PTM: %dC\n", p->pkg_temp_c); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 800 | |
| 801 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 802 | outp += sprintf(outp, "pADDED [%d] msr0x%x: %08llX\n", |
| 803 | i, mp->msr_num, p->counter[i]); |
| 804 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 805 | } |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 806 | |
| 807 | outp += sprintf(outp, "\n"); |
| 808 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 809 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 810 | } |
| 811 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 812 | /* |
| 813 | * column formatting convention & formats |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 814 | */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 815 | int format_counters(struct thread_data *t, struct core_data *c, |
| 816 | struct pkg_data *p) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 817 | { |
Len Brown | 008d396e | 2017-02-10 00:29:51 -0500 | [diff] [blame] | 818 | double interval_float, tsc; |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 819 | char *fmt8; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 820 | int i; |
| 821 | struct msr_counter *mp; |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 822 | char *delim = "\t"; |
| 823 | int printed = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 824 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 825 | /* if showing only 1st thread in core and this isn't one, bail out */ |
| 826 | if (show_core_only && !(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 827 | return 0; |
| 828 | |
| 829 | /* if showing only 1st thread in pkg and this isn't one, bail out */ |
| 830 | if (show_pkg_only && !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 831 | return 0; |
| 832 | |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 833 | /*if not summary line and --cpu is used */ |
| 834 | if ((t != &average.threads) && |
| 835 | (cpu_subset && !CPU_ISSET_S(t->cpu_id, cpu_subset_size, cpu_subset))) |
| 836 | return 0; |
| 837 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 838 | if (DO_BIC(BIC_USEC)) { |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 839 | /* on each row, print how many usec each timestamp took to gather */ |
| 840 | struct timeval tv; |
| 841 | |
| 842 | timersub(&t->tv_end, &t->tv_begin, &tv); |
| 843 | outp += sprintf(outp, "%5ld\t", tv.tv_sec * 1000000 + tv.tv_usec); |
| 844 | } |
| 845 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 846 | /* Time_Of_Day_Seconds: on each row, print sec.usec last timestamp taken */ |
| 847 | if (DO_BIC(BIC_TOD)) |
| 848 | outp += sprintf(outp, "%10ld.%06ld\t", t->tv_end.tv_sec, t->tv_end.tv_usec); |
| 849 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 850 | interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0; |
| 851 | |
Len Brown | 008d396e | 2017-02-10 00:29:51 -0500 | [diff] [blame] | 852 | tsc = t->tsc * tsc_tweak; |
| 853 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 854 | /* topo columns, print blanks on 1st (average) line */ |
| 855 | if (t == &average.threads) { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 856 | if (DO_BIC(BIC_Package)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 857 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 858 | if (DO_BIC(BIC_Core)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 859 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 860 | if (DO_BIC(BIC_CPU)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 861 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 862 | } else { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 863 | if (DO_BIC(BIC_Package)) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 864 | if (p) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 865 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->package_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 866 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 867 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 868 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 869 | if (DO_BIC(BIC_Core)) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 870 | if (c) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 871 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), c->core_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 872 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 873 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 874 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 875 | if (DO_BIC(BIC_CPU)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 876 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->cpu_id); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 877 | } |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 878 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 879 | if (DO_BIC(BIC_Avg_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 880 | outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 881 | 1.0 / units * t->aperf / interval_float); |
| 882 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 883 | if (DO_BIC(BIC_Busy)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 884 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->mperf/tsc); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 885 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 886 | if (DO_BIC(BIC_Bzy_MHz)) { |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 887 | if (has_base_hz) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 888 | 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] | 889 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 890 | outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), |
Len Brown | 008d396e | 2017-02-10 00:29:51 -0500 | [diff] [blame] | 891 | tsc / units * t->aperf / t->mperf / interval_float); |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 892 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 893 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 894 | if (DO_BIC(BIC_TSC_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 895 | 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] | 896 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 897 | /* IRQ */ |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 898 | if (DO_BIC(BIC_IRQ)) { |
| 899 | if (sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 900 | outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), t->irq_count); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 901 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 902 | outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->irq_count); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 903 | } |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 904 | |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 905 | /* SMI */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 906 | if (DO_BIC(BIC_SMI)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 907 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->smi_count); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 908 | |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 909 | /* Added counters */ |
| 910 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 911 | if (mp->format == FORMAT_RAW) { |
| 912 | if (mp->width == 32) |
Len Brown | 5f3aea5 | 2017-02-23 18:10:27 -0500 | [diff] [blame] | 913 | outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int) t->counter[i]); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 914 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 915 | outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), t->counter[i]); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 916 | } else if (mp->format == FORMAT_DELTA) { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 917 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 918 | outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), t->counter[i]); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 919 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 920 | outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->counter[i]); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 921 | } else if (mp->format == FORMAT_PERCENT) { |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 922 | if (mp->type == COUNTER_USEC) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 923 | 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] | 924 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 925 | 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] | 926 | } |
| 927 | } |
| 928 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 929 | /* C1 */ |
| 930 | if (DO_BIC(BIC_CPU_c1)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 931 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->c1/tsc); |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 932 | |
| 933 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 934 | /* print per-core data only for 1st thread in core */ |
| 935 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 936 | goto done; |
| 937 | |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame] | 938 | 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] | 939 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c3/tsc); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 940 | if (DO_BIC(BIC_CPU_c6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 941 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c6/tsc); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 942 | if (DO_BIC(BIC_CPU_c7)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 943 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c7/tsc); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 944 | |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 945 | /* Mod%c6 */ |
| 946 | if (DO_BIC(BIC_Mod_c6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 947 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->mc6_us / tsc); |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 948 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 949 | if (DO_BIC(BIC_CoreTmp)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 950 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), c->core_temp_c); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 951 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 952 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 953 | if (mp->format == FORMAT_RAW) { |
| 954 | if (mp->width == 32) |
Len Brown | 5f3aea5 | 2017-02-23 18:10:27 -0500 | [diff] [blame] | 955 | outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int) c->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 956 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 957 | outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), c->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 958 | } else if (mp->format == FORMAT_DELTA) { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 959 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 960 | outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), c->counter[i]); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 961 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 962 | outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), c->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 963 | } else if (mp->format == FORMAT_PERCENT) { |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 964 | 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] | 965 | } |
| 966 | } |
| 967 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 968 | /* print per-package data only for 1st core in package */ |
| 969 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 970 | goto done; |
| 971 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 972 | /* PkgTmp */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 973 | if (DO_BIC(BIC_PkgTmp)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 974 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->pkg_temp_c); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 975 | |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 976 | /* GFXrc6 */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 977 | if (DO_BIC(BIC_GFX_rc6)) { |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 978 | if (p->gfx_rc6_ms == -1) { /* detect GFX counter reset */ |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 979 | outp += sprintf(outp, "%s**.**", (printed++ ? delim : "")); |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 980 | } else { |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 981 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 982 | p->gfx_rc6_ms / 10.0 / interval_float); |
| 983 | } |
| 984 | } |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 985 | |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 986 | /* GFXMHz */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 987 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 988 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->gfx_mhz); |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 989 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 990 | /* Totl%C0, Any%C0 GFX%C0 CPUGFX% */ |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 991 | if (DO_BIC(BIC_Totl_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 992 | 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] | 993 | if (DO_BIC(BIC_Any_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 994 | 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] | 995 | if (DO_BIC(BIC_GFX_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 996 | 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] | 997 | if (DO_BIC(BIC_CPUGFX)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 998 | 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] | 999 | |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1000 | if (DO_BIC(BIC_Pkgpc2)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1001 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc2/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1002 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1003 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc3/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1004 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1005 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc6/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1006 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1007 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc7/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1008 | if (DO_BIC(BIC_Pkgpc8)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1009 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc8/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1010 | if (DO_BIC(BIC_Pkgpc9)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1011 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc9/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1012 | if (DO_BIC(BIC_Pkgpc10)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1013 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc10/tsc); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1014 | |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 1015 | if (DO_BIC(BIC_CPU_LPI)) |
| 1016 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->cpu_lpi / 1000000.0 / interval_float); |
| 1017 | if (DO_BIC(BIC_SYS_LPI)) |
| 1018 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->sys_lpi / 1000000.0 / interval_float); |
| 1019 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1020 | /* |
| 1021 | * If measurement interval exceeds minimum RAPL Joule Counter range, |
| 1022 | * indicate that results are suspect by printing "**" in fraction place. |
| 1023 | */ |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 1024 | if (interval_float < rapl_joule_counter_range) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1025 | fmt8 = "%s%.2f"; |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 1026 | else |
Len Brown | e975db5 | 2016-04-06 23:56:02 -0400 | [diff] [blame] | 1027 | fmt8 = "%6.0f**"; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1028 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1029 | if (DO_BIC(BIC_PkgWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1030 | 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] | 1031 | if (DO_BIC(BIC_CorWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1032 | 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] | 1033 | if (DO_BIC(BIC_GFXWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1034 | 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] | 1035 | if (DO_BIC(BIC_RAMWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1036 | 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] | 1037 | if (DO_BIC(BIC_Pkg_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1038 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_pkg * rapl_energy_units); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1039 | if (DO_BIC(BIC_Cor_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1040 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_cores * rapl_energy_units); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1041 | if (DO_BIC(BIC_GFX_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1042 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_gfx * rapl_energy_units); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1043 | if (DO_BIC(BIC_RAM_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1044 | 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] | 1045 | if (DO_BIC(BIC_PKG__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1046 | 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] | 1047 | if (DO_BIC(BIC_RAM__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1048 | 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] | 1049 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1050 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1051 | if (mp->format == FORMAT_RAW) { |
| 1052 | if (mp->width == 32) |
Len Brown | 5f3aea5 | 2017-02-23 18:10:27 -0500 | [diff] [blame] | 1053 | outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int) p->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1054 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1055 | outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), p->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1056 | } else if (mp->format == FORMAT_DELTA) { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1057 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1058 | outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), p->counter[i]); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1059 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1060 | outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), p->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1061 | } else if (mp->format == FORMAT_PERCENT) { |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1062 | 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] | 1063 | } |
| 1064 | } |
| 1065 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1066 | done: |
Len Brown | 94d6ab4 | 2018-01-27 22:39:21 -0500 | [diff] [blame] | 1067 | if (*(outp - 1) != '\n') |
| 1068 | outp += sprintf(outp, "\n"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1069 | |
| 1070 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1071 | } |
| 1072 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1073 | void flush_output_stdout(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1074 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1075 | FILE *filep; |
| 1076 | |
| 1077 | if (outf == stderr) |
| 1078 | filep = stdout; |
| 1079 | else |
| 1080 | filep = outf; |
| 1081 | |
| 1082 | fputs(output_buffer, filep); |
| 1083 | fflush(filep); |
| 1084 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1085 | outp = output_buffer; |
| 1086 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1087 | void flush_output_stderr(void) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1088 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1089 | fputs(output_buffer, outf); |
| 1090 | fflush(outf); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1091 | outp = output_buffer; |
| 1092 | } |
| 1093 | void format_all_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 1094 | { |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 1095 | static int printed; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1096 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 1097 | if (!printed || !summary_only) |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 1098 | print_header("\t"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1099 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1100 | if (topo.num_cpus > 1) |
| 1101 | format_counters(&average.threads, &average.cores, |
| 1102 | &average.packages); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1103 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 1104 | printed = 1; |
| 1105 | |
| 1106 | if (summary_only) |
| 1107 | return; |
| 1108 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1109 | for_all_cpus(format_counters, t, c, p); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1110 | } |
| 1111 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1112 | #define DELTA_WRAP32(new, old) \ |
| 1113 | if (new > old) { \ |
| 1114 | old = new - old; \ |
| 1115 | } else { \ |
| 1116 | old = 0x100000000 + new - old; \ |
| 1117 | } |
| 1118 | |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1119 | int |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1120 | delta_package(struct pkg_data *new, struct pkg_data *old) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1121 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1122 | int i; |
| 1123 | struct msr_counter *mp; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1124 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1125 | |
| 1126 | if (DO_BIC(BIC_Totl_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1127 | 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] | 1128 | if (DO_BIC(BIC_Any_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1129 | 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] | 1130 | if (DO_BIC(BIC_GFX_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1131 | 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] | 1132 | if (DO_BIC(BIC_CPUGFX)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1133 | 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] | 1134 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1135 | old->pc2 = new->pc2 - old->pc2; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1136 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1137 | old->pc3 = new->pc3 - old->pc3; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1138 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1139 | old->pc6 = new->pc6 - old->pc6; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1140 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1141 | old->pc7 = new->pc7 - old->pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1142 | old->pc8 = new->pc8 - old->pc8; |
| 1143 | old->pc9 = new->pc9 - old->pc9; |
| 1144 | old->pc10 = new->pc10 - old->pc10; |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 1145 | old->cpu_lpi = new->cpu_lpi - old->cpu_lpi; |
| 1146 | old->sys_lpi = new->sys_lpi - old->sys_lpi; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1147 | old->pkg_temp_c = new->pkg_temp_c; |
| 1148 | |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 1149 | /* flag an error when rc6 counter resets/wraps */ |
| 1150 | if (old->gfx_rc6_ms > new->gfx_rc6_ms) |
| 1151 | old->gfx_rc6_ms = -1; |
| 1152 | else |
| 1153 | old->gfx_rc6_ms = new->gfx_rc6_ms - old->gfx_rc6_ms; |
| 1154 | |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1155 | old->gfx_mhz = new->gfx_mhz; |
| 1156 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1157 | DELTA_WRAP32(new->energy_pkg, old->energy_pkg); |
| 1158 | DELTA_WRAP32(new->energy_cores, old->energy_cores); |
| 1159 | DELTA_WRAP32(new->energy_gfx, old->energy_gfx); |
| 1160 | DELTA_WRAP32(new->energy_dram, old->energy_dram); |
| 1161 | DELTA_WRAP32(new->rapl_pkg_perf_status, old->rapl_pkg_perf_status); |
| 1162 | DELTA_WRAP32(new->rapl_dram_perf_status, old->rapl_dram_perf_status); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1163 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1164 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1165 | if (mp->format == FORMAT_RAW) |
| 1166 | old->counter[i] = new->counter[i]; |
| 1167 | else |
| 1168 | old->counter[i] = new->counter[i] - old->counter[i]; |
| 1169 | } |
| 1170 | |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1171 | return 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1172 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1173 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1174 | void |
| 1175 | delta_core(struct core_data *new, struct core_data *old) |
| 1176 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1177 | int i; |
| 1178 | struct msr_counter *mp; |
| 1179 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1180 | old->c3 = new->c3 - old->c3; |
| 1181 | old->c6 = new->c6 - old->c6; |
| 1182 | old->c7 = new->c7 - old->c7; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1183 | old->core_temp_c = new->core_temp_c; |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1184 | old->mc6_us = new->mc6_us - old->mc6_us; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1185 | |
| 1186 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 1187 | if (mp->format == FORMAT_RAW) |
| 1188 | old->counter[i] = new->counter[i]; |
| 1189 | else |
| 1190 | old->counter[i] = new->counter[i] - old->counter[i]; |
| 1191 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1192 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1193 | |
Len Brown | c3ae331 | 2012-06-13 21:31:46 -0400 | [diff] [blame] | 1194 | /* |
| 1195 | * old = new - old |
| 1196 | */ |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1197 | int |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1198 | delta_thread(struct thread_data *new, struct thread_data *old, |
| 1199 | struct core_data *core_delta) |
| 1200 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1201 | int i; |
| 1202 | struct msr_counter *mp; |
| 1203 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 1204 | /* |
| 1205 | * the timestamps from start of measurement interval are in "old" |
| 1206 | * the timestamp from end of measurement interval are in "new" |
| 1207 | * over-write old w/ new so we can print end of interval values |
| 1208 | */ |
| 1209 | |
| 1210 | old->tv_begin = new->tv_begin; |
| 1211 | old->tv_end = new->tv_end; |
| 1212 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1213 | old->tsc = new->tsc - old->tsc; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1214 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1215 | /* check for TSC < 1 Mcycles over interval */ |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 1216 | if (old->tsc < (1000 * 1000)) |
| 1217 | errx(-3, "Insanely slow TSC rate, TSC stops in idle?\n" |
| 1218 | "You can disable all c-states by booting with \"idle=poll\"\n" |
| 1219 | "or just the deep ones with \"processor.max_cstate=1\""); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1220 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1221 | old->c1 = new->c1 - old->c1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1222 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1223 | 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] | 1224 | if ((new->aperf > old->aperf) && (new->mperf > old->mperf)) { |
| 1225 | old->aperf = new->aperf - old->aperf; |
| 1226 | old->mperf = new->mperf - old->mperf; |
| 1227 | } else { |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1228 | return -1; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1229 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1230 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1231 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1232 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1233 | if (use_c1_residency_msr) { |
| 1234 | /* |
| 1235 | * Some models have a dedicated C1 residency MSR, |
| 1236 | * which should be more accurate than the derivation below. |
| 1237 | */ |
| 1238 | } else { |
| 1239 | /* |
| 1240 | * As counter collection is not atomic, |
| 1241 | * it is possible for mperf's non-halted cycles + idle states |
| 1242 | * to exceed TSC's all cycles: show c1 = 0% in that case. |
| 1243 | */ |
Len Brown | 9514936 | 2017-04-12 19:44:51 -0400 | [diff] [blame] | 1244 | 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] | 1245 | old->c1 = 0; |
| 1246 | else { |
| 1247 | /* normal case, derive c1 */ |
Len Brown | 008d396e | 2017-02-10 00:29:51 -0500 | [diff] [blame] | 1248 | old->c1 = (old->tsc * tsc_tweak) - old->mperf - core_delta->c3 |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1249 | - core_delta->c6 - core_delta->c7; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1250 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1251 | } |
Len Brown | c3ae331 | 2012-06-13 21:31:46 -0400 | [diff] [blame] | 1252 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1253 | if (old->mperf == 0) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1254 | if (debug > 1) |
| 1255 | fprintf(outf, "cpu%d MPERF 0!\n", old->cpu_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1256 | old->mperf = 1; /* divide by 0 protection */ |
| 1257 | } |
| 1258 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1259 | if (DO_BIC(BIC_IRQ)) |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1260 | old->irq_count = new->irq_count - old->irq_count; |
| 1261 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1262 | if (DO_BIC(BIC_SMI)) |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 1263 | old->smi_count = new->smi_count - old->smi_count; |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1264 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1265 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 1266 | if (mp->format == FORMAT_RAW) |
| 1267 | old->counter[i] = new->counter[i]; |
| 1268 | else |
| 1269 | old->counter[i] = new->counter[i] - old->counter[i]; |
| 1270 | } |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1271 | return 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | int delta_cpu(struct thread_data *t, struct core_data *c, |
| 1275 | struct pkg_data *p, struct thread_data *t2, |
| 1276 | struct core_data *c2, struct pkg_data *p2) |
| 1277 | { |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1278 | int retval = 0; |
| 1279 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1280 | /* calculate core delta only for 1st thread in core */ |
| 1281 | if (t->flags & CPU_IS_FIRST_THREAD_IN_CORE) |
| 1282 | delta_core(c, c2); |
| 1283 | |
| 1284 | /* always calculate thread delta */ |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1285 | retval = delta_thread(t, t2, c2); /* c2 is core delta */ |
| 1286 | if (retval) |
| 1287 | return retval; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1288 | |
| 1289 | /* calculate package delta only for 1st core in package */ |
| 1290 | if (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE) |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1291 | retval = delta_package(p, p2); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1292 | |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1293 | return retval; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | void clear_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 1297 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1298 | int i; |
| 1299 | struct msr_counter *mp; |
| 1300 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 1301 | t->tv_begin.tv_sec = 0; |
| 1302 | t->tv_begin.tv_usec = 0; |
| 1303 | t->tv_end.tv_sec = 0; |
| 1304 | t->tv_end.tv_usec = 0; |
| 1305 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1306 | t->tsc = 0; |
| 1307 | t->aperf = 0; |
| 1308 | t->mperf = 0; |
| 1309 | t->c1 = 0; |
| 1310 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1311 | t->irq_count = 0; |
| 1312 | t->smi_count = 0; |
| 1313 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1314 | /* tells format_counters to dump all fields from this set */ |
| 1315 | t->flags = CPU_IS_FIRST_THREAD_IN_CORE | CPU_IS_FIRST_CORE_IN_PACKAGE; |
| 1316 | |
| 1317 | c->c3 = 0; |
| 1318 | c->c6 = 0; |
| 1319 | c->c7 = 0; |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1320 | c->mc6_us = 0; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1321 | c->core_temp_c = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1322 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1323 | p->pkg_wtd_core_c0 = 0; |
| 1324 | p->pkg_any_core_c0 = 0; |
| 1325 | p->pkg_any_gfxe_c0 = 0; |
| 1326 | p->pkg_both_core_gfxe_c0 = 0; |
| 1327 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1328 | p->pc2 = 0; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1329 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1330 | p->pc3 = 0; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1331 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1332 | p->pc6 = 0; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1333 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1334 | p->pc7 = 0; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1335 | p->pc8 = 0; |
| 1336 | p->pc9 = 0; |
| 1337 | p->pc10 = 0; |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 1338 | p->cpu_lpi = 0; |
| 1339 | p->sys_lpi = 0; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1340 | |
| 1341 | p->energy_pkg = 0; |
| 1342 | p->energy_dram = 0; |
| 1343 | p->energy_cores = 0; |
| 1344 | p->energy_gfx = 0; |
| 1345 | p->rapl_pkg_perf_status = 0; |
| 1346 | p->rapl_dram_perf_status = 0; |
| 1347 | p->pkg_temp_c = 0; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1348 | |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1349 | p->gfx_rc6_ms = 0; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1350 | p->gfx_mhz = 0; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1351 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) |
| 1352 | t->counter[i] = 0; |
| 1353 | |
| 1354 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) |
| 1355 | c->counter[i] = 0; |
| 1356 | |
| 1357 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) |
| 1358 | p->counter[i] = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1359 | } |
| 1360 | int sum_counters(struct thread_data *t, struct core_data *c, |
| 1361 | struct pkg_data *p) |
| 1362 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1363 | int i; |
| 1364 | struct msr_counter *mp; |
| 1365 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 1366 | /* remember first tv_begin */ |
| 1367 | if (average.threads.tv_begin.tv_sec == 0) |
| 1368 | average.threads.tv_begin = t->tv_begin; |
| 1369 | |
| 1370 | /* remember last tv_end */ |
| 1371 | average.threads.tv_end = t->tv_end; |
| 1372 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1373 | average.threads.tsc += t->tsc; |
| 1374 | average.threads.aperf += t->aperf; |
| 1375 | average.threads.mperf += t->mperf; |
| 1376 | average.threads.c1 += t->c1; |
| 1377 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1378 | average.threads.irq_count += t->irq_count; |
| 1379 | average.threads.smi_count += t->smi_count; |
| 1380 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1381 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 1382 | if (mp->format == FORMAT_RAW) |
| 1383 | continue; |
| 1384 | average.threads.counter[i] += t->counter[i]; |
| 1385 | } |
| 1386 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1387 | /* sum per-core values only for 1st thread in core */ |
| 1388 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 1389 | return 0; |
| 1390 | |
| 1391 | average.cores.c3 += c->c3; |
| 1392 | average.cores.c6 += c->c6; |
| 1393 | average.cores.c7 += c->c7; |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1394 | average.cores.mc6_us += c->mc6_us; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1395 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1396 | average.cores.core_temp_c = MAX(average.cores.core_temp_c, c->core_temp_c); |
| 1397 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1398 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 1399 | if (mp->format == FORMAT_RAW) |
| 1400 | continue; |
| 1401 | average.cores.counter[i] += c->counter[i]; |
| 1402 | } |
| 1403 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1404 | /* sum per-pkg values only for 1st core in pkg */ |
| 1405 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 1406 | return 0; |
| 1407 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1408 | if (DO_BIC(BIC_Totl_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1409 | average.packages.pkg_wtd_core_c0 += p->pkg_wtd_core_c0; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1410 | if (DO_BIC(BIC_Any_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1411 | average.packages.pkg_any_core_c0 += p->pkg_any_core_c0; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1412 | if (DO_BIC(BIC_GFX_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1413 | average.packages.pkg_any_gfxe_c0 += p->pkg_any_gfxe_c0; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1414 | if (DO_BIC(BIC_CPUGFX)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1415 | 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] | 1416 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1417 | average.packages.pc2 += p->pc2; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1418 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1419 | average.packages.pc3 += p->pc3; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1420 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1421 | average.packages.pc6 += p->pc6; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1422 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1423 | average.packages.pc7 += p->pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1424 | average.packages.pc8 += p->pc8; |
| 1425 | average.packages.pc9 += p->pc9; |
| 1426 | average.packages.pc10 += p->pc10; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1427 | |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 1428 | average.packages.cpu_lpi = p->cpu_lpi; |
| 1429 | average.packages.sys_lpi = p->sys_lpi; |
| 1430 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1431 | average.packages.energy_pkg += p->energy_pkg; |
| 1432 | average.packages.energy_dram += p->energy_dram; |
| 1433 | average.packages.energy_cores += p->energy_cores; |
| 1434 | average.packages.energy_gfx += p->energy_gfx; |
| 1435 | |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1436 | average.packages.gfx_rc6_ms = p->gfx_rc6_ms; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1437 | average.packages.gfx_mhz = p->gfx_mhz; |
| 1438 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1439 | average.packages.pkg_temp_c = MAX(average.packages.pkg_temp_c, p->pkg_temp_c); |
| 1440 | |
| 1441 | average.packages.rapl_pkg_perf_status += p->rapl_pkg_perf_status; |
| 1442 | average.packages.rapl_dram_perf_status += p->rapl_dram_perf_status; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1443 | |
| 1444 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1445 | if (mp->format == FORMAT_RAW) |
| 1446 | continue; |
| 1447 | average.packages.counter[i] += p->counter[i]; |
| 1448 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1449 | return 0; |
| 1450 | } |
| 1451 | /* |
| 1452 | * sum the counters for all cpus in the system |
| 1453 | * compute the weighted average |
| 1454 | */ |
| 1455 | void compute_average(struct thread_data *t, struct core_data *c, |
| 1456 | struct pkg_data *p) |
| 1457 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1458 | int i; |
| 1459 | struct msr_counter *mp; |
| 1460 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1461 | clear_counters(&average.threads, &average.cores, &average.packages); |
| 1462 | |
| 1463 | for_all_cpus(sum_counters, t, c, p); |
| 1464 | |
| 1465 | average.threads.tsc /= topo.num_cpus; |
| 1466 | average.threads.aperf /= topo.num_cpus; |
| 1467 | average.threads.mperf /= topo.num_cpus; |
| 1468 | average.threads.c1 /= topo.num_cpus; |
| 1469 | |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1470 | if (average.threads.irq_count > 9999999) |
| 1471 | sums_need_wide_columns = 1; |
| 1472 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1473 | average.cores.c3 /= topo.num_cores; |
| 1474 | average.cores.c6 /= topo.num_cores; |
| 1475 | average.cores.c7 /= topo.num_cores; |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1476 | average.cores.mc6_us /= topo.num_cores; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1477 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1478 | if (DO_BIC(BIC_Totl_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1479 | average.packages.pkg_wtd_core_c0 /= topo.num_packages; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1480 | if (DO_BIC(BIC_Any_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1481 | average.packages.pkg_any_core_c0 /= topo.num_packages; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1482 | if (DO_BIC(BIC_GFX_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1483 | average.packages.pkg_any_gfxe_c0 /= topo.num_packages; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1484 | if (DO_BIC(BIC_CPUGFX)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1485 | average.packages.pkg_both_core_gfxe_c0 /= topo.num_packages; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1486 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1487 | average.packages.pc2 /= topo.num_packages; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1488 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1489 | average.packages.pc3 /= topo.num_packages; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1490 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1491 | average.packages.pc6 /= topo.num_packages; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1492 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1493 | average.packages.pc7 /= topo.num_packages; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1494 | |
| 1495 | average.packages.pc8 /= topo.num_packages; |
| 1496 | average.packages.pc9 /= topo.num_packages; |
| 1497 | average.packages.pc10 /= topo.num_packages; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1498 | |
| 1499 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 1500 | if (mp->format == FORMAT_RAW) |
| 1501 | continue; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1502 | if (mp->type == COUNTER_ITEMS) { |
| 1503 | if (average.threads.counter[i] > 9999999) |
| 1504 | sums_need_wide_columns = 1; |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 1505 | continue; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1506 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1507 | average.threads.counter[i] /= topo.num_cpus; |
| 1508 | } |
| 1509 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 1510 | if (mp->format == FORMAT_RAW) |
| 1511 | continue; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1512 | if (mp->type == COUNTER_ITEMS) { |
| 1513 | if (average.cores.counter[i] > 9999999) |
| 1514 | sums_need_wide_columns = 1; |
| 1515 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1516 | average.cores.counter[i] /= topo.num_cores; |
| 1517 | } |
| 1518 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1519 | if (mp->format == FORMAT_RAW) |
| 1520 | continue; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1521 | if (mp->type == COUNTER_ITEMS) { |
| 1522 | if (average.packages.counter[i] > 9999999) |
| 1523 | sums_need_wide_columns = 1; |
| 1524 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1525 | average.packages.counter[i] /= topo.num_packages; |
| 1526 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | static unsigned long long rdtsc(void) |
| 1530 | { |
| 1531 | unsigned int low, high; |
| 1532 | |
| 1533 | asm volatile("rdtsc" : "=a" (low), "=d" (high)); |
| 1534 | |
| 1535 | return low | ((unsigned long long)high) << 32; |
| 1536 | } |
| 1537 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1538 | /* |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1539 | * Open a file, and exit on failure |
| 1540 | */ |
| 1541 | FILE *fopen_or_die(const char *path, const char *mode) |
| 1542 | { |
| 1543 | FILE *filep = fopen(path, mode); |
| 1544 | |
| 1545 | if (!filep) |
| 1546 | err(1, "%s: open failed", path); |
| 1547 | return filep; |
| 1548 | } |
| 1549 | /* |
| 1550 | * snapshot_sysfs_counter() |
| 1551 | * |
| 1552 | * return snapshot of given counter |
| 1553 | */ |
| 1554 | unsigned long long snapshot_sysfs_counter(char *path) |
| 1555 | { |
| 1556 | FILE *fp; |
| 1557 | int retval; |
| 1558 | unsigned long long counter; |
| 1559 | |
| 1560 | fp = fopen_or_die(path, "r"); |
| 1561 | |
| 1562 | retval = fscanf(fp, "%lld", &counter); |
| 1563 | if (retval != 1) |
| 1564 | err(1, "snapshot_sysfs_counter(%s)", path); |
| 1565 | |
| 1566 | fclose(fp); |
| 1567 | |
| 1568 | return counter; |
| 1569 | } |
| 1570 | |
| 1571 | int get_mp(int cpu, struct msr_counter *mp, unsigned long long *counterp) |
| 1572 | { |
| 1573 | if (mp->msr_num != 0) { |
| 1574 | if (get_msr(cpu, mp->msr_num, counterp)) |
| 1575 | return -1; |
| 1576 | } else { |
Len Brown | 46c2797 | 2017-12-08 17:38:17 -0500 | [diff] [blame] | 1577 | char path[128 + PATH_BYTES]; |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 1578 | |
| 1579 | if (mp->flags & SYSFS_PERCPU) { |
| 1580 | sprintf(path, "/sys/devices/system/cpu/cpu%d/%s", |
| 1581 | cpu, mp->path); |
| 1582 | |
| 1583 | *counterp = snapshot_sysfs_counter(path); |
| 1584 | } else { |
| 1585 | *counterp = snapshot_sysfs_counter(mp->path); |
| 1586 | } |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | return 0; |
| 1590 | } |
| 1591 | |
| 1592 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1593 | * get_counters(...) |
| 1594 | * migrate to cpu |
| 1595 | * acquire and record local counters for that cpu |
| 1596 | */ |
| 1597 | int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 1598 | { |
| 1599 | int cpu = t->cpu_id; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1600 | unsigned long long msr; |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1601 | int aperf_mperf_retry_count = 0; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1602 | struct msr_counter *mp; |
| 1603 | int i; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1604 | |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 1605 | |
| 1606 | gettimeofday(&t->tv_begin, (struct timezone *)NULL); |
| 1607 | |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 1608 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1609 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1610 | return -1; |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 1611 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1612 | |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1613 | retry: |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1614 | t->tsc = rdtsc(); /* we are running on local CPU of interest */ |
| 1615 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1616 | 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] | 1617 | unsigned long long tsc_before, tsc_between, tsc_after, aperf_time, mperf_time; |
| 1618 | |
| 1619 | /* |
| 1620 | * The TSC, APERF and MPERF must be read together for |
| 1621 | * APERF/MPERF and MPERF/TSC to give accurate results. |
| 1622 | * |
| 1623 | * Unfortunately, APERF and MPERF are read by |
| 1624 | * individual system call, so delays may occur |
| 1625 | * between them. If the time to read them |
| 1626 | * varies by a large amount, we re-read them. |
| 1627 | */ |
| 1628 | |
| 1629 | /* |
| 1630 | * This initial dummy APERF read has been seen to |
| 1631 | * reduce jitter in the subsequent reads. |
| 1632 | */ |
| 1633 | |
Len Brown | 9c63a65 | 2012-10-31 01:29:52 -0400 | [diff] [blame] | 1634 | if (get_msr(cpu, MSR_IA32_APERF, &t->aperf)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1635 | return -3; |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1636 | |
| 1637 | t->tsc = rdtsc(); /* re-read close to APERF */ |
| 1638 | |
| 1639 | tsc_before = t->tsc; |
| 1640 | |
| 1641 | if (get_msr(cpu, MSR_IA32_APERF, &t->aperf)) |
| 1642 | return -3; |
| 1643 | |
| 1644 | tsc_between = rdtsc(); |
| 1645 | |
Len Brown | 9c63a65 | 2012-10-31 01:29:52 -0400 | [diff] [blame] | 1646 | if (get_msr(cpu, MSR_IA32_MPERF, &t->mperf)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1647 | return -4; |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1648 | |
| 1649 | tsc_after = rdtsc(); |
| 1650 | |
| 1651 | aperf_time = tsc_between - tsc_before; |
| 1652 | mperf_time = tsc_after - tsc_between; |
| 1653 | |
| 1654 | /* |
| 1655 | * If the system call latency to read APERF and MPERF |
| 1656 | * differ by more than 2x, then try again. |
| 1657 | */ |
| 1658 | if ((aperf_time > (2 * mperf_time)) || (mperf_time > (2 * aperf_time))) { |
| 1659 | aperf_mperf_retry_count++; |
| 1660 | if (aperf_mperf_retry_count < 5) |
| 1661 | goto retry; |
| 1662 | else |
| 1663 | warnx("cpu%d jitter %lld %lld", |
| 1664 | cpu, aperf_time, mperf_time); |
| 1665 | } |
| 1666 | aperf_mperf_retry_count = 0; |
| 1667 | |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 1668 | t->aperf = t->aperf * aperf_mperf_multiplier; |
| 1669 | t->mperf = t->mperf * aperf_mperf_multiplier; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1670 | } |
| 1671 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1672 | if (DO_BIC(BIC_IRQ)) |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1673 | t->irq_count = irqs_per_cpu[cpu]; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1674 | if (DO_BIC(BIC_SMI)) { |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 1675 | if (get_msr(cpu, MSR_SMI_COUNT, &msr)) |
| 1676 | return -5; |
| 1677 | t->smi_count = msr & 0xFFFFFFFF; |
| 1678 | } |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1679 | if (DO_BIC(BIC_CPU_c1) && use_c1_residency_msr) { |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1680 | if (get_msr(cpu, MSR_CORE_C1_RES, &t->c1)) |
| 1681 | return -6; |
| 1682 | } |
| 1683 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1684 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1685 | if (get_mp(cpu, mp, &t->counter[i])) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1686 | return -10; |
| 1687 | } |
| 1688 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1689 | /* collect core counters only for 1st thread in core */ |
| 1690 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 1691 | goto done; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1692 | |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame] | 1693 | 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] | 1694 | if (get_msr(cpu, MSR_CORE_C3_RESIDENCY, &c->c3)) |
| 1695 | return -6; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1696 | } |
| 1697 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1698 | if (DO_BIC(BIC_CPU_c6) && !do_knl_cstates) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1699 | if (get_msr(cpu, MSR_CORE_C6_RESIDENCY, &c->c6)) |
| 1700 | return -7; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1701 | } else if (do_knl_cstates) { |
| 1702 | if (get_msr(cpu, MSR_KNL_CORE_C6_RESIDENCY, &c->c6)) |
| 1703 | return -7; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1704 | } |
| 1705 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1706 | if (DO_BIC(BIC_CPU_c7)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1707 | if (get_msr(cpu, MSR_CORE_C7_RESIDENCY, &c->c7)) |
| 1708 | return -8; |
| 1709 | |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1710 | if (DO_BIC(BIC_Mod_c6)) |
| 1711 | if (get_msr(cpu, MSR_MODULE_C6_RES_MS, &c->mc6_us)) |
| 1712 | return -8; |
| 1713 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1714 | if (DO_BIC(BIC_CoreTmp)) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1715 | if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr)) |
| 1716 | return -9; |
| 1717 | c->core_temp_c = tcc_activation_temp - ((msr >> 16) & 0x7F); |
| 1718 | } |
| 1719 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1720 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1721 | if (get_mp(cpu, mp, &c->counter[i])) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1722 | return -10; |
| 1723 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1724 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1725 | /* collect package counters only for 1st core in package */ |
| 1726 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 1727 | goto done; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1728 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1729 | if (DO_BIC(BIC_Totl_c0)) { |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1730 | if (get_msr(cpu, MSR_PKG_WEIGHTED_CORE_C0_RES, &p->pkg_wtd_core_c0)) |
| 1731 | return -10; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1732 | } |
| 1733 | if (DO_BIC(BIC_Any_c0)) { |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1734 | if (get_msr(cpu, MSR_PKG_ANY_CORE_C0_RES, &p->pkg_any_core_c0)) |
| 1735 | return -11; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1736 | } |
| 1737 | if (DO_BIC(BIC_GFX_c0)) { |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1738 | if (get_msr(cpu, MSR_PKG_ANY_GFXE_C0_RES, &p->pkg_any_gfxe_c0)) |
| 1739 | return -12; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1740 | } |
| 1741 | if (DO_BIC(BIC_CPUGFX)) { |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1742 | if (get_msr(cpu, MSR_PKG_BOTH_CORE_GFXE_C0_RES, &p->pkg_both_core_gfxe_c0)) |
| 1743 | return -13; |
| 1744 | } |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1745 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1746 | if (get_msr(cpu, MSR_PKG_C3_RESIDENCY, &p->pc3)) |
| 1747 | return -9; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1748 | if (DO_BIC(BIC_Pkgpc6)) { |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1749 | if (do_slm_cstates) { |
| 1750 | if (get_msr(cpu, MSR_ATOM_PKG_C6_RESIDENCY, &p->pc6)) |
| 1751 | return -10; |
| 1752 | } else { |
| 1753 | if (get_msr(cpu, MSR_PKG_C6_RESIDENCY, &p->pc6)) |
| 1754 | return -10; |
| 1755 | } |
| 1756 | } |
| 1757 | |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1758 | if (DO_BIC(BIC_Pkgpc2)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1759 | if (get_msr(cpu, MSR_PKG_C2_RESIDENCY, &p->pc2)) |
| 1760 | return -11; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1761 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1762 | if (get_msr(cpu, MSR_PKG_C7_RESIDENCY, &p->pc7)) |
| 1763 | return -12; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1764 | if (DO_BIC(BIC_Pkgpc8)) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1765 | if (get_msr(cpu, MSR_PKG_C8_RESIDENCY, &p->pc8)) |
| 1766 | return -13; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1767 | if (DO_BIC(BIC_Pkgpc9)) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1768 | if (get_msr(cpu, MSR_PKG_C9_RESIDENCY, &p->pc9)) |
| 1769 | return -13; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1770 | if (DO_BIC(BIC_Pkgpc10)) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1771 | if (get_msr(cpu, MSR_PKG_C10_RESIDENCY, &p->pc10)) |
| 1772 | return -13; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1773 | |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 1774 | if (DO_BIC(BIC_CPU_LPI)) |
| 1775 | p->cpu_lpi = cpuidle_cur_cpu_lpi_us; |
| 1776 | if (DO_BIC(BIC_SYS_LPI)) |
| 1777 | p->sys_lpi = cpuidle_cur_sys_lpi_us; |
| 1778 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1779 | if (do_rapl & RAPL_PKG) { |
| 1780 | if (get_msr(cpu, MSR_PKG_ENERGY_STATUS, &msr)) |
| 1781 | return -13; |
| 1782 | p->energy_pkg = msr & 0xFFFFFFFF; |
| 1783 | } |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 1784 | if (do_rapl & RAPL_CORES_ENERGY_STATUS) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1785 | if (get_msr(cpu, MSR_PP0_ENERGY_STATUS, &msr)) |
| 1786 | return -14; |
| 1787 | p->energy_cores = msr & 0xFFFFFFFF; |
| 1788 | } |
| 1789 | if (do_rapl & RAPL_DRAM) { |
| 1790 | if (get_msr(cpu, MSR_DRAM_ENERGY_STATUS, &msr)) |
| 1791 | return -15; |
| 1792 | p->energy_dram = msr & 0xFFFFFFFF; |
| 1793 | } |
| 1794 | if (do_rapl & RAPL_GFX) { |
| 1795 | if (get_msr(cpu, MSR_PP1_ENERGY_STATUS, &msr)) |
| 1796 | return -16; |
| 1797 | p->energy_gfx = msr & 0xFFFFFFFF; |
| 1798 | } |
| 1799 | if (do_rapl & RAPL_PKG_PERF_STATUS) { |
| 1800 | if (get_msr(cpu, MSR_PKG_PERF_STATUS, &msr)) |
| 1801 | return -16; |
| 1802 | p->rapl_pkg_perf_status = msr & 0xFFFFFFFF; |
| 1803 | } |
| 1804 | if (do_rapl & RAPL_DRAM_PERF_STATUS) { |
| 1805 | if (get_msr(cpu, MSR_DRAM_PERF_STATUS, &msr)) |
| 1806 | return -16; |
| 1807 | p->rapl_dram_perf_status = msr & 0xFFFFFFFF; |
| 1808 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1809 | if (DO_BIC(BIC_PkgTmp)) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1810 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr)) |
| 1811 | return -17; |
| 1812 | p->pkg_temp_c = tcc_activation_temp - ((msr >> 16) & 0x7F); |
| 1813 | } |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1814 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1815 | if (DO_BIC(BIC_GFX_rc6)) |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1816 | p->gfx_rc6_ms = gfx_cur_rc6_ms; |
| 1817 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1818 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1819 | p->gfx_mhz = gfx_cur_mhz; |
| 1820 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1821 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1822 | if (get_mp(cpu, mp, &p->counter[i])) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1823 | return -10; |
| 1824 | } |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 1825 | done: |
| 1826 | gettimeofday(&t->tv_end, (struct timezone *)NULL); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1827 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1828 | return 0; |
| 1829 | } |
| 1830 | |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1831 | /* |
| 1832 | * MSR_PKG_CST_CONFIG_CONTROL decoding for pkg_cstate_limit: |
| 1833 | * If you change the values, note they are used both in comparisons |
| 1834 | * (>= PCL__7) and to index pkg_cstate_limit_strings[]. |
| 1835 | */ |
| 1836 | |
| 1837 | #define PCLUKN 0 /* Unknown */ |
| 1838 | #define PCLRSV 1 /* Reserved */ |
| 1839 | #define PCL__0 2 /* PC0 */ |
| 1840 | #define PCL__1 3 /* PC1 */ |
| 1841 | #define PCL__2 4 /* PC2 */ |
| 1842 | #define PCL__3 5 /* PC3 */ |
| 1843 | #define PCL__4 6 /* PC4 */ |
| 1844 | #define PCL__6 7 /* PC6 */ |
| 1845 | #define PCL_6N 8 /* PC6 No Retention */ |
| 1846 | #define PCL_6R 9 /* PC6 Retention */ |
| 1847 | #define PCL__7 10 /* PC7 */ |
| 1848 | #define PCL_7S 11 /* PC7 Shrink */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1849 | #define PCL__8 12 /* PC8 */ |
| 1850 | #define PCL__9 13 /* PC9 */ |
| 1851 | #define PCLUNL 14 /* Unlimited */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1852 | |
| 1853 | int pkg_cstate_limit = PCLUKN; |
| 1854 | char *pkg_cstate_limit_strings[] = { "reserved", "unknown", "pc0", "pc1", "pc2", |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1855 | "pc3", "pc4", "pc6", "pc6n", "pc6r", "pc7", "pc7s", "pc8", "pc9", "unlimited"}; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1856 | |
Len Brown | e9257f5 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 1857 | 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}; |
| 1858 | 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}; |
| 1859 | int hsw_pkg_cstate_limits[16] = {PCL__0, PCL__2, PCL__3, PCL__6, PCL__7, PCL_7S, PCL__8, PCL__9, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1860 | 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] | 1861 | 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] | 1862 | 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] | 1863 | 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] | 1864 | 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] | 1865 | |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 1866 | |
| 1867 | static void |
| 1868 | calculate_tsc_tweak() |
| 1869 | { |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 1870 | tsc_tweak = base_hz / tsc_hz; |
| 1871 | } |
| 1872 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1873 | static void |
| 1874 | dump_nhm_platform_info(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1875 | { |
| 1876 | unsigned long long msr; |
| 1877 | unsigned int ratio; |
| 1878 | |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 1879 | get_msr(base_cpu, MSR_PLATFORM_INFO, &msr); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1880 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1881 | 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] | 1882 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1883 | ratio = (msr >> 40) & 0xFF; |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1884 | fprintf(outf, "%d * %.1f = %.1f MHz max efficiency frequency\n", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1885 | ratio, bclk, ratio * bclk); |
| 1886 | |
| 1887 | ratio = (msr >> 8) & 0xFF; |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1888 | fprintf(outf, "%d * %.1f = %.1f MHz base frequency\n", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1889 | ratio, bclk, ratio * bclk); |
| 1890 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1891 | get_msr(base_cpu, MSR_IA32_POWER_CTL, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1892 | 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] | 1893 | base_cpu, msr, msr & 0x2 ? "EN" : "DIS"); |
Len Brown | 6792041 | 2013-01-31 15:22:15 -0500 | [diff] [blame] | 1894 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1895 | return; |
| 1896 | } |
| 1897 | |
| 1898 | static void |
| 1899 | dump_hsw_turbo_ratio_limits(void) |
| 1900 | { |
| 1901 | unsigned long long msr; |
| 1902 | unsigned int ratio; |
| 1903 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1904 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT2, &msr); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1905 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1906 | 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] | 1907 | |
| 1908 | ratio = (msr >> 8) & 0xFF; |
| 1909 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1910 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 18 active cores\n", |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1911 | ratio, bclk, ratio * bclk); |
| 1912 | |
| 1913 | ratio = (msr >> 0) & 0xFF; |
| 1914 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1915 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 17 active cores\n", |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1916 | ratio, bclk, ratio * bclk); |
| 1917 | return; |
| 1918 | } |
| 1919 | |
| 1920 | static void |
| 1921 | dump_ivt_turbo_ratio_limits(void) |
| 1922 | { |
| 1923 | unsigned long long msr; |
| 1924 | unsigned int ratio; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1925 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1926 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT1, &msr); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1927 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1928 | 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] | 1929 | |
| 1930 | ratio = (msr >> 56) & 0xFF; |
| 1931 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1932 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 16 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1933 | ratio, bclk, ratio * bclk); |
| 1934 | |
| 1935 | ratio = (msr >> 48) & 0xFF; |
| 1936 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1937 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 15 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1938 | ratio, bclk, ratio * bclk); |
| 1939 | |
| 1940 | ratio = (msr >> 40) & 0xFF; |
| 1941 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1942 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 14 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1943 | ratio, bclk, ratio * bclk); |
| 1944 | |
| 1945 | ratio = (msr >> 32) & 0xFF; |
| 1946 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1947 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 13 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1948 | ratio, bclk, ratio * bclk); |
| 1949 | |
| 1950 | ratio = (msr >> 24) & 0xFF; |
| 1951 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1952 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 12 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1953 | ratio, bclk, ratio * bclk); |
| 1954 | |
| 1955 | ratio = (msr >> 16) & 0xFF; |
| 1956 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1957 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 11 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1958 | ratio, bclk, ratio * bclk); |
| 1959 | |
| 1960 | ratio = (msr >> 8) & 0xFF; |
| 1961 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1962 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 10 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1963 | ratio, bclk, ratio * bclk); |
| 1964 | |
| 1965 | ratio = (msr >> 0) & 0xFF; |
| 1966 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 1967 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 9 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1968 | ratio, bclk, ratio * bclk); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1969 | return; |
| 1970 | } |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1971 | int has_turbo_ratio_group_limits(int family, int model) |
| 1972 | { |
| 1973 | |
| 1974 | if (!genuine_intel) |
| 1975 | return 0; |
| 1976 | |
| 1977 | switch (model) { |
| 1978 | case INTEL_FAM6_ATOM_GOLDMONT: |
| 1979 | case INTEL_FAM6_SKYLAKE_X: |
| 1980 | case INTEL_FAM6_ATOM_DENVERTON: |
| 1981 | return 1; |
| 1982 | } |
| 1983 | return 0; |
| 1984 | } |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1985 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1986 | static void |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1987 | dump_turbo_ratio_limits(int family, int model) |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1988 | { |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1989 | unsigned long long msr, core_counts; |
| 1990 | unsigned int ratio, group_size; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1991 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1992 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1993 | 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] | 1994 | |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 1995 | if (has_turbo_ratio_group_limits(family, model)) { |
| 1996 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT1, &core_counts); |
| 1997 | fprintf(outf, "cpu%d: MSR_TURBO_RATIO_LIMIT1: 0x%08llx\n", base_cpu, core_counts); |
| 1998 | } else { |
| 1999 | core_counts = 0x0807060504030201; |
| 2000 | } |
| 2001 | |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2002 | ratio = (msr >> 56) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2003 | group_size = (core_counts >> 56) & 0xFF; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2004 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2005 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2006 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2007 | |
| 2008 | ratio = (msr >> 48) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2009 | group_size = (core_counts >> 48) & 0xFF; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2010 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2011 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2012 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2013 | |
| 2014 | ratio = (msr >> 40) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2015 | group_size = (core_counts >> 40) & 0xFF; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2016 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2017 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2018 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2019 | |
| 2020 | ratio = (msr >> 32) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2021 | group_size = (core_counts >> 32) & 0xFF; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2022 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2023 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2024 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2025 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2026 | ratio = (msr >> 24) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2027 | group_size = (core_counts >> 24) & 0xFF; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2028 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2029 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2030 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2031 | |
| 2032 | ratio = (msr >> 16) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2033 | group_size = (core_counts >> 16) & 0xFF; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2034 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2035 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2036 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2037 | |
| 2038 | ratio = (msr >> 8) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2039 | group_size = (core_counts >> 8) & 0xFF; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2040 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2041 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2042 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2043 | |
| 2044 | ratio = (msr >> 0) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2045 | group_size = (core_counts >> 0) & 0xFF; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2046 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2047 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2048 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2049 | return; |
| 2050 | } |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 2051 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2052 | static void |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 2053 | dump_atom_turbo_ratio_limits(void) |
| 2054 | { |
| 2055 | unsigned long long msr; |
| 2056 | unsigned int ratio; |
| 2057 | |
| 2058 | get_msr(base_cpu, MSR_ATOM_CORE_RATIOS, &msr); |
| 2059 | fprintf(outf, "cpu%d: MSR_ATOM_CORE_RATIOS: 0x%08llx\n", base_cpu, msr & 0xFFFFFFFF); |
| 2060 | |
| 2061 | ratio = (msr >> 0) & 0x3F; |
| 2062 | if (ratio) |
| 2063 | fprintf(outf, "%d * %.1f = %.1f MHz minimum operating frequency\n", |
| 2064 | ratio, bclk, ratio * bclk); |
| 2065 | |
| 2066 | ratio = (msr >> 8) & 0x3F; |
| 2067 | if (ratio) |
| 2068 | fprintf(outf, "%d * %.1f = %.1f MHz low frequency mode (LFM)\n", |
| 2069 | ratio, bclk, ratio * bclk); |
| 2070 | |
| 2071 | ratio = (msr >> 16) & 0x3F; |
| 2072 | if (ratio) |
| 2073 | fprintf(outf, "%d * %.1f = %.1f MHz base frequency\n", |
| 2074 | ratio, bclk, ratio * bclk); |
| 2075 | |
| 2076 | get_msr(base_cpu, MSR_ATOM_CORE_TURBO_RATIOS, &msr); |
| 2077 | fprintf(outf, "cpu%d: MSR_ATOM_CORE_TURBO_RATIOS: 0x%08llx\n", base_cpu, msr & 0xFFFFFFFF); |
| 2078 | |
| 2079 | ratio = (msr >> 24) & 0x3F; |
| 2080 | if (ratio) |
| 2081 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 4 active cores\n", |
| 2082 | ratio, bclk, ratio * bclk); |
| 2083 | |
| 2084 | ratio = (msr >> 16) & 0x3F; |
| 2085 | if (ratio) |
| 2086 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 3 active cores\n", |
| 2087 | ratio, bclk, ratio * bclk); |
| 2088 | |
| 2089 | ratio = (msr >> 8) & 0x3F; |
| 2090 | if (ratio) |
| 2091 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 2 active cores\n", |
| 2092 | ratio, bclk, ratio * bclk); |
| 2093 | |
| 2094 | ratio = (msr >> 0) & 0x3F; |
| 2095 | if (ratio) |
| 2096 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 1 active core\n", |
| 2097 | ratio, bclk, ratio * bclk); |
| 2098 | } |
| 2099 | |
| 2100 | static void |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2101 | dump_knl_turbo_ratio_limits(void) |
| 2102 | { |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2103 | const unsigned int buckets_no = 7; |
| 2104 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2105 | unsigned long long msr; |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2106 | int delta_cores, delta_ratio; |
| 2107 | int i, b_nr; |
| 2108 | unsigned int cores[buckets_no]; |
| 2109 | unsigned int ratio[buckets_no]; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2110 | |
Srinivas Pandruvada | ebf5926 | 2016-07-06 16:07:56 -0700 | [diff] [blame] | 2111 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT, &msr); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2112 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2113 | fprintf(outf, "cpu%d: MSR_TURBO_RATIO_LIMIT: 0x%08llx\n", |
Len Brown | bfae205 | 2015-06-17 12:27:21 -0400 | [diff] [blame] | 2114 | base_cpu, msr); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2115 | |
| 2116 | /** |
| 2117 | * Turbo encoding in KNL is as follows: |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2118 | * [0] -- Reserved |
| 2119 | * [7:1] -- Base value of number of active cores of bucket 1. |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2120 | * [15:8] -- Base value of freq ratio of bucket 1. |
| 2121 | * [20:16] -- +ve delta of number of active cores of bucket 2. |
| 2122 | * i.e. active cores of bucket 2 = |
| 2123 | * active cores of bucket 1 + delta |
| 2124 | * [23:21] -- Negative delta of freq ratio of bucket 2. |
| 2125 | * i.e. freq ratio of bucket 2 = |
| 2126 | * freq ratio of bucket 1 - delta |
| 2127 | * [28:24]-- +ve delta of number of active cores of bucket 3. |
| 2128 | * [31:29]-- -ve delta of freq ratio of bucket 3. |
| 2129 | * [36:32]-- +ve delta of number of active cores of bucket 4. |
| 2130 | * [39:37]-- -ve delta of freq ratio of bucket 4. |
| 2131 | * [44:40]-- +ve delta of number of active cores of bucket 5. |
| 2132 | * [47:45]-- -ve delta of freq ratio of bucket 5. |
| 2133 | * [52:48]-- +ve delta of number of active cores of bucket 6. |
| 2134 | * [55:53]-- -ve delta of freq ratio of bucket 6. |
| 2135 | * [60:56]-- +ve delta of number of active cores of bucket 7. |
| 2136 | * [63:61]-- -ve delta of freq ratio of bucket 7. |
| 2137 | */ |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2138 | |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2139 | b_nr = 0; |
| 2140 | cores[b_nr] = (msr & 0xFF) >> 1; |
| 2141 | ratio[b_nr] = (msr >> 8) & 0xFF; |
| 2142 | |
| 2143 | for (i = 16; i < 64; i += 8) { |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2144 | delta_cores = (msr >> i) & 0x1F; |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2145 | delta_ratio = (msr >> (i + 5)) & 0x7; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2146 | |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2147 | cores[b_nr + 1] = cores[b_nr] + delta_cores; |
| 2148 | ratio[b_nr + 1] = ratio[b_nr] - delta_ratio; |
| 2149 | b_nr++; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2150 | } |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2151 | |
| 2152 | for (i = buckets_no - 1; i >= 0; i--) |
| 2153 | if (i > 0 ? ratio[i] != ratio[i - 1] : 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2154 | fprintf(outf, |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 2155 | "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2156 | ratio[i], bclk, ratio[i] * bclk, cores[i]); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | static void |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2160 | dump_nhm_cst_cfg(void) |
| 2161 | { |
| 2162 | unsigned long long msr; |
| 2163 | |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 2164 | get_msr(base_cpu, MSR_PKG_CST_CONFIG_CONTROL, &msr); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2165 | |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 2166 | 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] | 2167 | |
Artem Bityutskiy | 3e8b62b | 2017-09-05 15:25:42 +0300 | [diff] [blame] | 2168 | fprintf(outf, " (%s%s%s%s%slocked, pkg-cstate-limit=%d (%s)", |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2169 | (msr & SNB_C3_AUTO_UNDEMOTE) ? "UNdemote-C3, " : "", |
| 2170 | (msr & SNB_C1_AUTO_UNDEMOTE) ? "UNdemote-C1, " : "", |
| 2171 | (msr & NHM_C3_AUTO_DEMOTE) ? "demote-C3, " : "", |
| 2172 | (msr & NHM_C1_AUTO_DEMOTE) ? "demote-C1, " : "", |
| 2173 | (msr & (1 << 15)) ? "" : "UN", |
Len Brown | 6c34f16 | 2016-03-13 03:21:22 -0400 | [diff] [blame] | 2174 | (unsigned int)msr & 0xF, |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2175 | pkg_cstate_limit_strings[pkg_cstate_limit]); |
Artem Bityutskiy | ac980e1 | 2017-09-05 15:14:08 +0300 | [diff] [blame] | 2176 | |
| 2177 | #define AUTOMATIC_CSTATE_CONVERSION (1UL << 16) |
| 2178 | if (has_automatic_cstate_conversion) { |
| 2179 | fprintf(outf, ", automatic c-state conversion=%s", |
| 2180 | (msr & AUTOMATIC_CSTATE_CONVERSION) ? "on" : "off"); |
| 2181 | } |
| 2182 | |
| 2183 | fprintf(outf, ")\n"); |
| 2184 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2185 | return; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2186 | } |
| 2187 | |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2188 | static void |
| 2189 | dump_config_tdp(void) |
| 2190 | { |
| 2191 | unsigned long long msr; |
| 2192 | |
| 2193 | get_msr(base_cpu, MSR_CONFIG_TDP_NOMINAL, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2194 | 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] | 2195 | fprintf(outf, " (base_ratio=%d)\n", (unsigned int)msr & 0xFF); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2196 | |
| 2197 | get_msr(base_cpu, MSR_CONFIG_TDP_LEVEL_1, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2198 | 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] | 2199 | if (msr) { |
Chen Yu | 685b535 | 2015-12-13 21:09:31 +0800 | [diff] [blame] | 2200 | fprintf(outf, "PKG_MIN_PWR_LVL1=%d ", (unsigned int)(msr >> 48) & 0x7FFF); |
| 2201 | fprintf(outf, "PKG_MAX_PWR_LVL1=%d ", (unsigned int)(msr >> 32) & 0x7FFF); |
| 2202 | fprintf(outf, "LVL1_RATIO=%d ", (unsigned int)(msr >> 16) & 0xFF); |
| 2203 | fprintf(outf, "PKG_TDP_LVL1=%d", (unsigned int)(msr) & 0x7FFF); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2204 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2205 | fprintf(outf, ")\n"); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2206 | |
| 2207 | get_msr(base_cpu, MSR_CONFIG_TDP_LEVEL_2, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2208 | 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] | 2209 | if (msr) { |
Chen Yu | 685b535 | 2015-12-13 21:09:31 +0800 | [diff] [blame] | 2210 | fprintf(outf, "PKG_MIN_PWR_LVL2=%d ", (unsigned int)(msr >> 48) & 0x7FFF); |
| 2211 | fprintf(outf, "PKG_MAX_PWR_LVL2=%d ", (unsigned int)(msr >> 32) & 0x7FFF); |
| 2212 | fprintf(outf, "LVL2_RATIO=%d ", (unsigned int)(msr >> 16) & 0xFF); |
| 2213 | fprintf(outf, "PKG_TDP_LVL2=%d", (unsigned int)(msr) & 0x7FFF); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2214 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2215 | fprintf(outf, ")\n"); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2216 | |
| 2217 | get_msr(base_cpu, MSR_CONFIG_TDP_CONTROL, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2218 | 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] | 2219 | if ((msr) & 0x3) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2220 | fprintf(outf, "TDP_LEVEL=%d ", (unsigned int)(msr) & 0x3); |
| 2221 | fprintf(outf, " lock=%d", (unsigned int)(msr >> 31) & 1); |
| 2222 | fprintf(outf, ")\n"); |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2223 | |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2224 | get_msr(base_cpu, MSR_TURBO_ACTIVATION_RATIO, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2225 | 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] | 2226 | fprintf(outf, "MAX_NON_TURBO_RATIO=%d", (unsigned int)(msr) & 0xFF); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2227 | fprintf(outf, " lock=%d", (unsigned int)(msr >> 31) & 1); |
| 2228 | fprintf(outf, ")\n"); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2229 | } |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 2230 | |
| 2231 | unsigned int irtl_time_units[] = {1, 32, 1024, 32768, 1048576, 33554432, 0, 0 }; |
| 2232 | |
| 2233 | void print_irtl(void) |
| 2234 | { |
| 2235 | unsigned long long msr; |
| 2236 | |
| 2237 | get_msr(base_cpu, MSR_PKGC3_IRTL, &msr); |
| 2238 | fprintf(outf, "cpu%d: MSR_PKGC3_IRTL: 0x%08llx (", base_cpu, msr); |
| 2239 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2240 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2241 | |
| 2242 | get_msr(base_cpu, MSR_PKGC6_IRTL, &msr); |
| 2243 | fprintf(outf, "cpu%d: MSR_PKGC6_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_PKGC7_IRTL, &msr); |
| 2248 | fprintf(outf, "cpu%d: MSR_PKGC7_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 | if (!do_irtl_hsw) |
| 2253 | return; |
| 2254 | |
| 2255 | get_msr(base_cpu, MSR_PKGC8_IRTL, &msr); |
| 2256 | fprintf(outf, "cpu%d: MSR_PKGC8_IRTL: 0x%08llx (", base_cpu, msr); |
| 2257 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2258 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2259 | |
| 2260 | get_msr(base_cpu, MSR_PKGC9_IRTL, &msr); |
| 2261 | fprintf(outf, "cpu%d: MSR_PKGC9_IRTL: 0x%08llx (", base_cpu, msr); |
| 2262 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2263 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2264 | |
| 2265 | get_msr(base_cpu, MSR_PKGC10_IRTL, &msr); |
| 2266 | fprintf(outf, "cpu%d: MSR_PKGC10_IRTL: 0x%08llx (", base_cpu, msr); |
| 2267 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2268 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2269 | |
| 2270 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2271 | void free_fd_percpu(void) |
| 2272 | { |
| 2273 | int i; |
| 2274 | |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 2275 | for (i = 0; i < topo.max_cpu_num + 1; ++i) { |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2276 | if (fd_percpu[i] != 0) |
| 2277 | close(fd_percpu[i]); |
| 2278 | } |
| 2279 | |
| 2280 | free(fd_percpu); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2281 | } |
| 2282 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2283 | void free_all_buffers(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2284 | { |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 2285 | int i; |
| 2286 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2287 | CPU_FREE(cpu_present_set); |
| 2288 | cpu_present_set = NULL; |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2289 | cpu_present_setsize = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2290 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2291 | CPU_FREE(cpu_affinity_set); |
| 2292 | cpu_affinity_set = NULL; |
| 2293 | cpu_affinity_setsize = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2294 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2295 | free(thread_even); |
| 2296 | free(core_even); |
| 2297 | free(package_even); |
| 2298 | |
| 2299 | thread_even = NULL; |
| 2300 | core_even = NULL; |
| 2301 | package_even = NULL; |
| 2302 | |
| 2303 | free(thread_odd); |
| 2304 | free(core_odd); |
| 2305 | free(package_odd); |
| 2306 | |
| 2307 | thread_odd = NULL; |
| 2308 | core_odd = NULL; |
| 2309 | package_odd = NULL; |
| 2310 | |
| 2311 | free(output_buffer); |
| 2312 | output_buffer = NULL; |
| 2313 | outp = NULL; |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2314 | |
| 2315 | free_fd_percpu(); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2316 | |
| 2317 | free(irq_column_2_cpu); |
| 2318 | free(irqs_per_cpu); |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 2319 | |
| 2320 | for (i = 0; i <= topo.max_cpu_num; ++i) { |
| 2321 | if (cpus[i].put_ids) |
| 2322 | CPU_FREE(cpus[i].put_ids); |
| 2323 | } |
| 2324 | free(cpus); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2325 | } |
| 2326 | |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 2327 | |
| 2328 | /* |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2329 | * Parse a file containing a single int. |
| 2330 | */ |
| 2331 | int parse_int_file(const char *fmt, ...) |
| 2332 | { |
| 2333 | va_list args; |
| 2334 | char path[PATH_MAX]; |
| 2335 | FILE *filep; |
| 2336 | int value; |
| 2337 | |
| 2338 | va_start(args, fmt); |
| 2339 | vsnprintf(path, sizeof(path), fmt, args); |
| 2340 | va_end(args); |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 2341 | filep = fopen_or_die(path, "r"); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 2342 | if (fscanf(filep, "%d", &value) != 1) |
| 2343 | err(1, "%s: failed to parse number from file", path); |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2344 | fclose(filep); |
| 2345 | return value; |
| 2346 | } |
| 2347 | |
| 2348 | /* |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2349 | * get_cpu_position_in_core(cpu) |
| 2350 | * return the position of the CPU among its HT siblings in the core |
| 2351 | * return -1 if the sibling is not in list |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2352 | */ |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2353 | int get_cpu_position_in_core(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2354 | { |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2355 | char path[64]; |
| 2356 | FILE *filep; |
| 2357 | int this_cpu; |
| 2358 | char character; |
| 2359 | int i; |
| 2360 | |
| 2361 | sprintf(path, |
| 2362 | "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", |
| 2363 | cpu); |
| 2364 | filep = fopen(path, "r"); |
| 2365 | if (filep == NULL) { |
| 2366 | perror(path); |
| 2367 | exit(1); |
| 2368 | } |
| 2369 | |
| 2370 | for (i = 0; i < topo.num_threads_per_core; i++) { |
| 2371 | fscanf(filep, "%d", &this_cpu); |
| 2372 | if (this_cpu == cpu) { |
| 2373 | fclose(filep); |
| 2374 | return i; |
| 2375 | } |
| 2376 | |
| 2377 | /* Account for no separator after last thread*/ |
| 2378 | if (i != (topo.num_threads_per_core - 1)) |
| 2379 | fscanf(filep, "%c", &character); |
| 2380 | } |
| 2381 | |
| 2382 | fclose(filep); |
| 2383 | return -1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2384 | } |
| 2385 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2386 | /* |
| 2387 | * cpu_is_first_core_in_package(cpu) |
| 2388 | * return 1 if given CPU is 1st core in package |
| 2389 | */ |
| 2390 | int cpu_is_first_core_in_package(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2391 | { |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2392 | 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] | 2393 | } |
| 2394 | |
| 2395 | int get_physical_package_id(int cpu) |
| 2396 | { |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2397 | 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] | 2398 | } |
| 2399 | |
| 2400 | int get_core_id(int cpu) |
| 2401 | { |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2402 | 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] | 2403 | } |
| 2404 | |
Prarit Bhargava | ef60574 | 2018-06-01 10:04:30 -0400 | [diff] [blame^] | 2405 | void set_node_data(void) |
| 2406 | { |
| 2407 | char path[80]; |
| 2408 | FILE *filep; |
| 2409 | int pkg, node, cpu; |
| 2410 | |
| 2411 | struct pkg_node_info { |
| 2412 | int count; |
| 2413 | int min; |
| 2414 | } *pni; |
| 2415 | |
| 2416 | pni = calloc(topo.num_packages, sizeof(struct pkg_node_info)); |
| 2417 | if (!pni) |
| 2418 | err(1, "calloc pkg_node_count"); |
| 2419 | |
| 2420 | for (pkg = 0; pkg < topo.num_packages; pkg++) |
| 2421 | pni[pkg].min = topo.num_cpus; |
| 2422 | |
| 2423 | for (node = 0; node <= topo.max_node_num; node++) { |
| 2424 | /* find the "first" cpu in the node */ |
| 2425 | sprintf(path, "/sys/bus/node/devices/node%d/cpulist", node); |
| 2426 | filep = fopen(path, "r"); |
| 2427 | if (!filep) |
| 2428 | continue; |
| 2429 | fscanf(filep, "%d", &cpu); |
| 2430 | fclose(filep); |
| 2431 | |
| 2432 | pkg = cpus[cpu].physical_package_id; |
| 2433 | pni[pkg].count++; |
| 2434 | |
| 2435 | if (node < pni[pkg].min) |
| 2436 | pni[pkg].min = node; |
| 2437 | } |
| 2438 | |
| 2439 | for (pkg = 0; pkg < topo.num_packages; pkg++) |
| 2440 | if (pni[pkg].count > topo.num_nodes_per_pkg) |
| 2441 | topo.num_nodes_per_pkg = pni[0].count; |
| 2442 | |
| 2443 | for (cpu = 0; cpu < topo.num_cpus; cpu++) { |
| 2444 | pkg = cpus[cpu].physical_package_id; |
| 2445 | node = cpus[cpu].physical_node_id; |
| 2446 | cpus[cpu].logical_node_id = node - pni[pkg].min; |
| 2447 | } |
| 2448 | free(pni); |
| 2449 | |
| 2450 | } |
| 2451 | |
| 2452 | int get_physical_node_id(struct cpu_topology *thiscpu) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2453 | { |
| 2454 | char path[80]; |
| 2455 | FILE *filep; |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 2456 | int i; |
| 2457 | int cpu = thiscpu->logical_cpu_id; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2458 | |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 2459 | for (i = 0; i <= topo.max_cpu_num; i++) { |
| 2460 | sprintf(path, "/sys/devices/system/cpu/cpu%d/node%i/cpulist", |
| 2461 | cpu, i); |
| 2462 | filep = fopen(path, "r"); |
| 2463 | if (!filep) |
| 2464 | continue; |
| 2465 | fclose(filep); |
| 2466 | return i; |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2467 | } |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 2468 | return -1; |
| 2469 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2470 | |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 2471 | int get_thread_siblings(struct cpu_topology *thiscpu) |
| 2472 | { |
| 2473 | char path[80], character; |
| 2474 | FILE *filep; |
| 2475 | unsigned long map; |
| 2476 | int shift, sib_core; |
| 2477 | int cpu = thiscpu->logical_cpu_id; |
| 2478 | int offset = topo.max_cpu_num + 1; |
| 2479 | size_t size; |
| 2480 | |
| 2481 | thiscpu->put_ids = CPU_ALLOC((topo.max_cpu_num + 1)); |
| 2482 | if (!thiscpu->put_ids) |
| 2483 | return -1; |
| 2484 | |
| 2485 | size = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); |
| 2486 | CPU_ZERO_S(size, thiscpu->put_ids); |
| 2487 | |
| 2488 | sprintf(path, |
| 2489 | "/sys/devices/system/cpu/cpu%d/topology/thread_siblings", cpu); |
| 2490 | filep = fopen_or_die(path, "r"); |
| 2491 | do { |
| 2492 | offset -= BITMASK_SIZE; |
| 2493 | fscanf(filep, "%lx%c", &map, &character); |
| 2494 | for (shift = 0; shift < BITMASK_SIZE; shift++) { |
| 2495 | if ((map >> shift) & 0x1) { |
| 2496 | sib_core = get_core_id(shift + offset); |
| 2497 | if (sib_core == thiscpu->physical_core_id) |
| 2498 | CPU_SET_S(shift + offset, size, |
| 2499 | thiscpu->put_ids); |
| 2500 | } |
| 2501 | } |
| 2502 | } while (!strncmp(&character, ",", 1)); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2503 | fclose(filep); |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 2504 | |
| 2505 | return CPU_COUNT_S(size, thiscpu->put_ids); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2506 | } |
| 2507 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2508 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2509 | * run func(thread, core, package) in topology order |
| 2510 | * skip non-present cpus |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2511 | */ |
| 2512 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2513 | int for_all_cpus_2(int (func)(struct thread_data *, struct core_data *, |
| 2514 | struct pkg_data *, struct thread_data *, struct core_data *, |
| 2515 | struct pkg_data *), struct thread_data *thread_base, |
| 2516 | struct core_data *core_base, struct pkg_data *pkg_base, |
| 2517 | struct thread_data *thread_base2, struct core_data *core_base2, |
| 2518 | struct pkg_data *pkg_base2) |
| 2519 | { |
| 2520 | int retval, pkg_no, core_no, thread_no; |
| 2521 | |
| 2522 | for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { |
| 2523 | for (core_no = 0; core_no < topo.num_cores_per_pkg; ++core_no) { |
| 2524 | for (thread_no = 0; thread_no < |
| 2525 | topo.num_threads_per_core; ++thread_no) { |
| 2526 | struct thread_data *t, *t2; |
| 2527 | struct core_data *c, *c2; |
| 2528 | struct pkg_data *p, *p2; |
| 2529 | |
| 2530 | t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); |
| 2531 | |
| 2532 | if (cpu_is_not_present(t->cpu_id)) |
| 2533 | continue; |
| 2534 | |
| 2535 | t2 = GET_THREAD(thread_base2, thread_no, core_no, pkg_no); |
| 2536 | |
| 2537 | c = GET_CORE(core_base, core_no, pkg_no); |
| 2538 | c2 = GET_CORE(core_base2, core_no, pkg_no); |
| 2539 | |
| 2540 | p = GET_PKG(pkg_base, pkg_no); |
| 2541 | p2 = GET_PKG(pkg_base2, pkg_no); |
| 2542 | |
| 2543 | retval = func(t, c, p, t2, c2, p2); |
| 2544 | if (retval) |
| 2545 | return retval; |
| 2546 | } |
| 2547 | } |
| 2548 | } |
| 2549 | return 0; |
| 2550 | } |
| 2551 | |
| 2552 | /* |
| 2553 | * run func(cpu) on every cpu in /proc/stat |
| 2554 | * return max_cpu number |
| 2555 | */ |
| 2556 | int for_all_proc_cpus(int (func)(int)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2557 | { |
| 2558 | FILE *fp; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2559 | int cpu_num; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2560 | int retval; |
| 2561 | |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 2562 | fp = fopen_or_die(proc_stat, "r"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2563 | |
| 2564 | 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] | 2565 | if (retval != 0) |
| 2566 | err(1, "%s: failed to parse format", proc_stat); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2567 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2568 | while (1) { |
| 2569 | 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] | 2570 | if (retval != 1) |
| 2571 | break; |
| 2572 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2573 | retval = func(cpu_num); |
| 2574 | if (retval) { |
| 2575 | fclose(fp); |
| 2576 | return(retval); |
| 2577 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2578 | } |
| 2579 | fclose(fp); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2580 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2581 | } |
| 2582 | |
| 2583 | void re_initialize(void) |
| 2584 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2585 | free_all_buffers(); |
| 2586 | setup_all_buffers(); |
| 2587 | printf("turbostat: re-initialized with num_cpus %d\n", topo.num_cpus); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2588 | } |
| 2589 | |
Prarit Bhargava | 843c579 | 2018-06-01 10:04:28 -0400 | [diff] [blame] | 2590 | void set_max_cpu_num(void) |
| 2591 | { |
| 2592 | FILE *filep; |
| 2593 | unsigned long dummy; |
| 2594 | |
| 2595 | topo.max_cpu_num = 0; |
| 2596 | filep = fopen_or_die( |
| 2597 | "/sys/devices/system/cpu/cpu0/topology/thread_siblings", |
| 2598 | "r"); |
| 2599 | while (fscanf(filep, "%lx,", &dummy) == 1) |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 2600 | topo.max_cpu_num += BITMASK_SIZE; |
Prarit Bhargava | 843c579 | 2018-06-01 10:04:28 -0400 | [diff] [blame] | 2601 | fclose(filep); |
| 2602 | topo.max_cpu_num--; /* 0 based */ |
| 2603 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2604 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2605 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2606 | * count_cpus() |
| 2607 | * remember the last one seen, it will be the max |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2608 | */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2609 | int count_cpus(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2610 | { |
Prarit Bhargava | 843c579 | 2018-06-01 10:04:28 -0400 | [diff] [blame] | 2611 | topo.num_cpus++; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2612 | return 0; |
| 2613 | } |
| 2614 | int mark_cpu_present(int cpu) |
| 2615 | { |
| 2616 | CPU_SET_S(cpu, cpu_present_setsize, cpu_present_set); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 2617 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2618 | } |
| 2619 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2620 | /* |
| 2621 | * snapshot_proc_interrupts() |
| 2622 | * |
| 2623 | * read and record summary of /proc/interrupts |
| 2624 | * |
| 2625 | * return 1 if config change requires a restart, else return 0 |
| 2626 | */ |
| 2627 | int snapshot_proc_interrupts(void) |
| 2628 | { |
| 2629 | static FILE *fp; |
| 2630 | int column, retval; |
| 2631 | |
| 2632 | if (fp == NULL) |
| 2633 | fp = fopen_or_die("/proc/interrupts", "r"); |
| 2634 | else |
| 2635 | rewind(fp); |
| 2636 | |
| 2637 | /* read 1st line of /proc/interrupts to get cpu* name for each column */ |
| 2638 | for (column = 0; column < topo.num_cpus; ++column) { |
| 2639 | int cpu_number; |
| 2640 | |
| 2641 | retval = fscanf(fp, " CPU%d", &cpu_number); |
| 2642 | if (retval != 1) |
| 2643 | break; |
| 2644 | |
| 2645 | if (cpu_number > topo.max_cpu_num) { |
| 2646 | warn("/proc/interrupts: cpu%d: > %d", cpu_number, topo.max_cpu_num); |
| 2647 | return 1; |
| 2648 | } |
| 2649 | |
| 2650 | irq_column_2_cpu[column] = cpu_number; |
| 2651 | irqs_per_cpu[cpu_number] = 0; |
| 2652 | } |
| 2653 | |
| 2654 | /* read /proc/interrupt count lines and sum up irqs per cpu */ |
| 2655 | while (1) { |
| 2656 | int column; |
| 2657 | char buf[64]; |
| 2658 | |
| 2659 | retval = fscanf(fp, " %s:", buf); /* flush irq# "N:" */ |
| 2660 | if (retval != 1) |
| 2661 | break; |
| 2662 | |
| 2663 | /* read the count per cpu */ |
| 2664 | for (column = 0; column < topo.num_cpus; ++column) { |
| 2665 | |
| 2666 | int cpu_number, irq_count; |
| 2667 | |
| 2668 | retval = fscanf(fp, " %d", &irq_count); |
| 2669 | if (retval != 1) |
| 2670 | break; |
| 2671 | |
| 2672 | cpu_number = irq_column_2_cpu[column]; |
| 2673 | irqs_per_cpu[cpu_number] += irq_count; |
| 2674 | |
| 2675 | } |
| 2676 | |
| 2677 | while (getc(fp) != '\n') |
| 2678 | ; /* flush interrupt description */ |
| 2679 | |
| 2680 | } |
| 2681 | return 0; |
| 2682 | } |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2683 | /* |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 2684 | * snapshot_gfx_rc6_ms() |
| 2685 | * |
| 2686 | * record snapshot of |
| 2687 | * /sys/class/drm/card0/power/rc6_residency_ms |
| 2688 | * |
| 2689 | * return 1 if config change requires a restart, else return 0 |
| 2690 | */ |
| 2691 | int snapshot_gfx_rc6_ms(void) |
| 2692 | { |
| 2693 | FILE *fp; |
| 2694 | int retval; |
| 2695 | |
| 2696 | fp = fopen_or_die("/sys/class/drm/card0/power/rc6_residency_ms", "r"); |
| 2697 | |
| 2698 | retval = fscanf(fp, "%lld", &gfx_cur_rc6_ms); |
| 2699 | if (retval != 1) |
| 2700 | err(1, "GFX rc6"); |
| 2701 | |
| 2702 | fclose(fp); |
| 2703 | |
| 2704 | return 0; |
| 2705 | } |
| 2706 | /* |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2707 | * snapshot_gfx_mhz() |
| 2708 | * |
| 2709 | * record snapshot of |
| 2710 | * /sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz |
| 2711 | * |
| 2712 | * return 1 if config change requires a restart, else return 0 |
| 2713 | */ |
| 2714 | int snapshot_gfx_mhz(void) |
| 2715 | { |
| 2716 | static FILE *fp; |
| 2717 | int retval; |
| 2718 | |
| 2719 | if (fp == NULL) |
| 2720 | 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] | 2721 | else { |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2722 | rewind(fp); |
Len Brown | 22048c5 | 2017-03-04 15:42:48 -0500 | [diff] [blame] | 2723 | fflush(fp); |
| 2724 | } |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2725 | |
| 2726 | retval = fscanf(fp, "%d", &gfx_cur_mhz); |
| 2727 | if (retval != 1) |
| 2728 | err(1, "GFX MHz"); |
| 2729 | |
| 2730 | return 0; |
| 2731 | } |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2732 | |
| 2733 | /* |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 2734 | * snapshot_cpu_lpi() |
| 2735 | * |
| 2736 | * record snapshot of |
| 2737 | * /sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us |
| 2738 | * |
| 2739 | * return 1 if config change requires a restart, else return 0 |
| 2740 | */ |
| 2741 | int snapshot_cpu_lpi_us(void) |
| 2742 | { |
| 2743 | FILE *fp; |
| 2744 | int retval; |
| 2745 | |
| 2746 | fp = fopen_or_die("/sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us", "r"); |
| 2747 | |
| 2748 | retval = fscanf(fp, "%lld", &cpuidle_cur_cpu_lpi_us); |
| 2749 | if (retval != 1) |
| 2750 | err(1, "CPU LPI"); |
| 2751 | |
| 2752 | fclose(fp); |
| 2753 | |
| 2754 | return 0; |
| 2755 | } |
| 2756 | /* |
| 2757 | * snapshot_sys_lpi() |
| 2758 | * |
| 2759 | * record snapshot of |
| 2760 | * /sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us |
| 2761 | * |
| 2762 | * return 1 if config change requires a restart, else return 0 |
| 2763 | */ |
| 2764 | int snapshot_sys_lpi_us(void) |
| 2765 | { |
| 2766 | FILE *fp; |
| 2767 | int retval; |
| 2768 | |
| 2769 | fp = fopen_or_die("/sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us", "r"); |
| 2770 | |
| 2771 | retval = fscanf(fp, "%lld", &cpuidle_cur_sys_lpi_us); |
| 2772 | if (retval != 1) |
| 2773 | err(1, "SYS LPI"); |
| 2774 | |
| 2775 | fclose(fp); |
| 2776 | |
| 2777 | return 0; |
| 2778 | } |
| 2779 | /* |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2780 | * snapshot /proc and /sys files |
| 2781 | * |
| 2782 | * return 1 if configuration restart needed, else return 0 |
| 2783 | */ |
| 2784 | int snapshot_proc_sysfs_files(void) |
| 2785 | { |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 2786 | if (DO_BIC(BIC_IRQ)) |
| 2787 | if (snapshot_proc_interrupts()) |
| 2788 | return 1; |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2789 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 2790 | if (DO_BIC(BIC_GFX_rc6)) |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 2791 | snapshot_gfx_rc6_ms(); |
| 2792 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 2793 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2794 | snapshot_gfx_mhz(); |
| 2795 | |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 2796 | if (DO_BIC(BIC_CPU_LPI)) |
| 2797 | snapshot_cpu_lpi_us(); |
| 2798 | |
| 2799 | if (DO_BIC(BIC_SYS_LPI)) |
| 2800 | snapshot_sys_lpi_us(); |
| 2801 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2802 | return 0; |
| 2803 | } |
| 2804 | |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2805 | int exit_requested; |
| 2806 | |
| 2807 | static void signal_handler (int signal) |
| 2808 | { |
| 2809 | switch (signal) { |
| 2810 | case SIGINT: |
| 2811 | exit_requested = 1; |
| 2812 | if (debug) |
| 2813 | fprintf(stderr, " SIGINT\n"); |
| 2814 | break; |
Len Brown | 0721196 | 2017-07-15 15:51:26 -0400 | [diff] [blame] | 2815 | case SIGUSR1: |
| 2816 | if (debug > 1) |
| 2817 | fprintf(stderr, "SIGUSR1\n"); |
| 2818 | break; |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2819 | } |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2820 | /* make sure this manually-invoked interval is at least 1ms long */ |
| 2821 | nanosleep(&one_msec, NULL); |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2822 | } |
| 2823 | |
| 2824 | void setup_signal_handler(void) |
| 2825 | { |
| 2826 | struct sigaction sa; |
| 2827 | |
| 2828 | memset(&sa, 0, sizeof(sa)); |
| 2829 | |
| 2830 | sa.sa_handler = &signal_handler; |
| 2831 | |
| 2832 | if (sigaction(SIGINT, &sa, NULL) < 0) |
| 2833 | err(1, "sigaction SIGINT"); |
Len Brown | 0721196 | 2017-07-15 15:51:26 -0400 | [diff] [blame] | 2834 | if (sigaction(SIGUSR1, &sa, NULL) < 0) |
| 2835 | err(1, "sigaction SIGUSR1"); |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2836 | } |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2837 | |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 2838 | void do_sleep(void) |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2839 | { |
| 2840 | struct timeval select_timeout; |
| 2841 | fd_set readfds; |
| 2842 | int retval; |
| 2843 | |
| 2844 | FD_ZERO(&readfds); |
| 2845 | FD_SET(0, &readfds); |
| 2846 | |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 2847 | if (!isatty(fileno(stdin))) { |
| 2848 | nanosleep(&interval_ts, NULL); |
| 2849 | return; |
| 2850 | } |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2851 | |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 2852 | select_timeout = interval_tv; |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2853 | retval = select(1, &readfds, NULL, NULL, &select_timeout); |
| 2854 | |
| 2855 | if (retval == 1) { |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2856 | switch (getc(stdin)) { |
| 2857 | case 'q': |
| 2858 | exit_requested = 1; |
| 2859 | break; |
| 2860 | } |
| 2861 | /* make sure this manually-invoked interval is at least 1ms long */ |
| 2862 | nanosleep(&one_msec, NULL); |
| 2863 | } |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2864 | } |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 2865 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2866 | void turbostat_loop() |
| 2867 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2868 | int retval; |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 2869 | int restarted = 0; |
Chen Yu | 023fe0a | 2018-04-26 08:41:03 +0800 | [diff] [blame] | 2870 | int done_iters = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2871 | |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2872 | setup_signal_handler(); |
| 2873 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2874 | restart: |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 2875 | restarted++; |
| 2876 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2877 | snapshot_proc_sysfs_files(); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2878 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 2879 | if (retval < -1) { |
| 2880 | exit(retval); |
| 2881 | } else if (retval == -1) { |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 2882 | if (restarted > 1) { |
| 2883 | exit(retval); |
| 2884 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2885 | re_initialize(); |
| 2886 | goto restart; |
| 2887 | } |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 2888 | restarted = 0; |
Chen Yu | 023fe0a | 2018-04-26 08:41:03 +0800 | [diff] [blame] | 2889 | done_iters = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2890 | gettimeofday(&tv_even, (struct timezone *)NULL); |
| 2891 | |
| 2892 | while (1) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2893 | if (for_all_proc_cpus(cpu_is_not_present)) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2894 | re_initialize(); |
| 2895 | goto restart; |
| 2896 | } |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2897 | do_sleep(); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2898 | if (snapshot_proc_sysfs_files()) |
| 2899 | goto restart; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2900 | retval = for_all_cpus(get_counters, ODD_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 2901 | if (retval < -1) { |
| 2902 | exit(retval); |
| 2903 | } else if (retval == -1) { |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 2904 | re_initialize(); |
| 2905 | goto restart; |
| 2906 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2907 | gettimeofday(&tv_odd, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2908 | timersub(&tv_odd, &tv_even, &tv_delta); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 2909 | if (for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS)) { |
| 2910 | re_initialize(); |
| 2911 | goto restart; |
| 2912 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2913 | compute_average(EVEN_COUNTERS); |
| 2914 | format_all_counters(EVEN_COUNTERS); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2915 | flush_output_stdout(); |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2916 | if (exit_requested) |
| 2917 | break; |
Chen Yu | 023fe0a | 2018-04-26 08:41:03 +0800 | [diff] [blame] | 2918 | if (num_iterations && ++done_iters >= num_iterations) |
| 2919 | break; |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2920 | do_sleep(); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2921 | if (snapshot_proc_sysfs_files()) |
| 2922 | goto restart; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2923 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 2924 | if (retval < -1) { |
| 2925 | exit(retval); |
| 2926 | } else if (retval == -1) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2927 | re_initialize(); |
| 2928 | goto restart; |
| 2929 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2930 | gettimeofday(&tv_even, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2931 | timersub(&tv_even, &tv_odd, &tv_delta); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 2932 | if (for_all_cpus_2(delta_cpu, EVEN_COUNTERS, ODD_COUNTERS)) { |
| 2933 | re_initialize(); |
| 2934 | goto restart; |
| 2935 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2936 | compute_average(ODD_COUNTERS); |
| 2937 | format_all_counters(ODD_COUNTERS); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2938 | flush_output_stdout(); |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2939 | if (exit_requested) |
| 2940 | break; |
Chen Yu | 023fe0a | 2018-04-26 08:41:03 +0800 | [diff] [blame] | 2941 | if (num_iterations && ++done_iters >= num_iterations) |
| 2942 | break; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2943 | } |
| 2944 | } |
| 2945 | |
| 2946 | void check_dev_msr() |
| 2947 | { |
| 2948 | struct stat sb; |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2949 | char pathname[32]; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2950 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2951 | sprintf(pathname, "/dev/cpu/%d/msr", base_cpu); |
| 2952 | if (stat(pathname, &sb)) |
Len Brown | a21d38c | 2015-03-24 16:37:35 -0400 | [diff] [blame] | 2953 | if (system("/sbin/modprobe msr > /dev/null 2>&1")) |
| 2954 | err(-5, "no /dev/cpu/0/msr, Try \"# modprobe msr\" "); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2955 | } |
| 2956 | |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2957 | void check_permissions() |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2958 | { |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2959 | struct __user_cap_header_struct cap_header_data; |
| 2960 | cap_user_header_t cap_header = &cap_header_data; |
| 2961 | struct __user_cap_data_struct cap_data_data; |
| 2962 | cap_user_data_t cap_data = &cap_data_data; |
| 2963 | extern int capget(cap_user_header_t hdrp, cap_user_data_t datap); |
| 2964 | int do_exit = 0; |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2965 | char pathname[32]; |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2966 | |
| 2967 | /* check for CAP_SYS_RAWIO */ |
| 2968 | cap_header->pid = getpid(); |
| 2969 | cap_header->version = _LINUX_CAPABILITY_VERSION; |
| 2970 | if (capget(cap_header, cap_data) < 0) |
| 2971 | err(-6, "capget(2) failed"); |
| 2972 | |
| 2973 | if ((cap_data->effective & (1 << CAP_SYS_RAWIO)) == 0) { |
| 2974 | do_exit++; |
| 2975 | warnx("capget(CAP_SYS_RAWIO) failed," |
| 2976 | " try \"# setcap cap_sys_rawio=ep %s\"", progname); |
| 2977 | } |
| 2978 | |
| 2979 | /* test file permissions */ |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2980 | sprintf(pathname, "/dev/cpu/%d/msr", base_cpu); |
| 2981 | if (euidaccess(pathname, R_OK)) { |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2982 | do_exit++; |
| 2983 | warn("/dev/cpu/0/msr open failed, try chown or chmod +r /dev/cpu/*/msr"); |
| 2984 | } |
| 2985 | |
| 2986 | /* if all else fails, thell them to be root */ |
| 2987 | if (do_exit) |
| 2988 | if (getuid() != 0) |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2989 | warnx("... or simply run as root"); |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 2990 | |
| 2991 | if (do_exit) |
| 2992 | exit(-6); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2993 | } |
| 2994 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2995 | /* |
| 2996 | * NHM adds support for additional MSRs: |
| 2997 | * |
| 2998 | * MSR_SMI_COUNT 0x00000034 |
| 2999 | * |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 3000 | * MSR_PLATFORM_INFO 0x000000ce |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 3001 | * MSR_PKG_CST_CONFIG_CONTROL 0x000000e2 |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3002 | * |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 3003 | * MSR_MISC_PWR_MGMT 0x000001aa |
| 3004 | * |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3005 | * MSR_PKG_C3_RESIDENCY 0x000003f8 |
| 3006 | * MSR_PKG_C6_RESIDENCY 0x000003f9 |
| 3007 | * MSR_CORE_C3_RESIDENCY 0x000003fc |
| 3008 | * MSR_CORE_C6_RESIDENCY 0x000003fd |
| 3009 | * |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3010 | * Side effect: |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 3011 | * sets global pkg_cstate_limit to decode MSR_PKG_CST_CONFIG_CONTROL |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 3012 | * sets has_misc_feature_control |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3013 | */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3014 | int probe_nhm_msrs(unsigned int family, unsigned int model) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3015 | { |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3016 | unsigned long long msr; |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 3017 | unsigned int base_ratio; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3018 | int *pkg_cstate_limits; |
| 3019 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3020 | if (!genuine_intel) |
| 3021 | return 0; |
| 3022 | |
| 3023 | if (family != 6) |
| 3024 | return 0; |
| 3025 | |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 3026 | bclk = discover_bclk(family, model); |
| 3027 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3028 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3029 | case INTEL_FAM6_NEHALEM_EP: /* Core i7, Xeon 5500 series - Bloomfield, Gainstown NHM-EP */ |
| 3030 | 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] | 3031 | case 0x1F: /* Core i7 and i5 Processor - Nehalem */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3032 | case INTEL_FAM6_WESTMERE: /* Westmere Client - Clarkdale, Arrandale */ |
| 3033 | case INTEL_FAM6_WESTMERE_EP: /* Westmere EP - Gulftown */ |
| 3034 | case INTEL_FAM6_NEHALEM_EX: /* Nehalem-EX Xeon - Beckton */ |
| 3035 | case INTEL_FAM6_WESTMERE_EX: /* Westmere-EX Xeon - Eagleton */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3036 | pkg_cstate_limits = nhm_pkg_cstate_limits; |
| 3037 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3038 | case INTEL_FAM6_SANDYBRIDGE: /* SNB */ |
| 3039 | case INTEL_FAM6_SANDYBRIDGE_X: /* SNB Xeon */ |
| 3040 | case INTEL_FAM6_IVYBRIDGE: /* IVB */ |
| 3041 | case INTEL_FAM6_IVYBRIDGE_X: /* IVB Xeon */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3042 | pkg_cstate_limits = snb_pkg_cstate_limits; |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 3043 | has_misc_feature_control = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3044 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3045 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 3046 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 3047 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 3048 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 3049 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 3050 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
| 3051 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 3052 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 3053 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 3054 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 3055 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 3056 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame] | 3057 | case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3058 | pkg_cstate_limits = hsw_pkg_cstate_limits; |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 3059 | has_misc_feature_control = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3060 | break; |
Len Brown | d8ebb44 | 2016-12-01 20:27:46 -0500 | [diff] [blame] | 3061 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
| 3062 | pkg_cstate_limits = skx_pkg_cstate_limits; |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 3063 | has_misc_feature_control = 1; |
Len Brown | d8ebb44 | 2016-12-01 20:27:46 -0500 | [diff] [blame] | 3064 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3065 | case INTEL_FAM6_ATOM_SILVERMONT1: /* BYT */ |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 3066 | no_MSR_MISC_PWR_MGMT = 1; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3067 | case INTEL_FAM6_ATOM_SILVERMONT2: /* AVN */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3068 | pkg_cstate_limits = slv_pkg_cstate_limits; |
| 3069 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3070 | case INTEL_FAM6_ATOM_AIRMONT: /* AMT */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3071 | pkg_cstate_limits = amt_pkg_cstate_limits; |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 3072 | no_MSR_MISC_PWR_MGMT = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3073 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3074 | case INTEL_FAM6_XEON_PHI_KNL: /* PHI */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 3075 | case INTEL_FAM6_XEON_PHI_KNM: |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3076 | pkg_cstate_limits = phi_pkg_cstate_limits; |
| 3077 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3078 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | ac01ac1 | 2017-01-27 01:45:35 -0500 | [diff] [blame] | 3079 | case INTEL_FAM6_ATOM_GEMINI_LAKE: |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3080 | case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ |
Len Brown | e4085d5 | 2016-04-06 17:15:56 -0400 | [diff] [blame] | 3081 | pkg_cstate_limits = bxt_pkg_cstate_limits; |
| 3082 | break; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3083 | default: |
| 3084 | return 0; |
| 3085 | } |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 3086 | get_msr(base_cpu, MSR_PKG_CST_CONFIG_CONTROL, &msr); |
Len Brown | e9257f5 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 3087 | pkg_cstate_limit = pkg_cstate_limits[msr & 0xF]; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3088 | |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 3089 | get_msr(base_cpu, MSR_PLATFORM_INFO, &msr); |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 3090 | base_ratio = (msr >> 8) & 0xFF; |
| 3091 | |
| 3092 | base_hz = base_ratio * bclk * 1000000; |
| 3093 | has_base_hz = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3094 | return 1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3095 | } |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 3096 | /* |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 3097 | * SLV client has support for unique MSRs: |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 3098 | * |
| 3099 | * MSR_CC6_DEMOTION_POLICY_CONFIG |
| 3100 | * MSR_MC6_DEMOTION_POLICY_CONFIG |
| 3101 | */ |
| 3102 | |
| 3103 | int has_slv_msrs(unsigned int family, unsigned int model) |
| 3104 | { |
| 3105 | if (!genuine_intel) |
| 3106 | return 0; |
| 3107 | |
| 3108 | switch (model) { |
| 3109 | case INTEL_FAM6_ATOM_SILVERMONT1: |
| 3110 | case INTEL_FAM6_ATOM_MERRIFIELD: |
| 3111 | case INTEL_FAM6_ATOM_MOOREFIELD: |
| 3112 | return 1; |
| 3113 | } |
| 3114 | return 0; |
| 3115 | } |
Len Brown | 7170a37 | 2017-01-27 02:13:27 -0500 | [diff] [blame] | 3116 | int is_dnv(unsigned int family, unsigned int model) |
| 3117 | { |
| 3118 | |
| 3119 | if (!genuine_intel) |
| 3120 | return 0; |
| 3121 | |
| 3122 | switch (model) { |
| 3123 | case INTEL_FAM6_ATOM_DENVERTON: |
| 3124 | return 1; |
| 3125 | } |
| 3126 | return 0; |
| 3127 | } |
Len Brown | ade0eba | 2017-02-10 01:56:47 -0500 | [diff] [blame] | 3128 | int is_bdx(unsigned int family, unsigned int model) |
| 3129 | { |
| 3130 | |
| 3131 | if (!genuine_intel) |
| 3132 | return 0; |
| 3133 | |
| 3134 | switch (model) { |
| 3135 | case INTEL_FAM6_BROADWELL_X: |
| 3136 | case INTEL_FAM6_BROADWELL_XEON_D: |
| 3137 | return 1; |
| 3138 | } |
| 3139 | return 0; |
| 3140 | } |
Len Brown | 34c76197 | 2017-01-27 02:36:41 -0500 | [diff] [blame] | 3141 | int is_skx(unsigned int family, unsigned int model) |
| 3142 | { |
| 3143 | |
| 3144 | if (!genuine_intel) |
| 3145 | return 0; |
| 3146 | |
| 3147 | switch (model) { |
| 3148 | case INTEL_FAM6_SKYLAKE_X: |
| 3149 | return 1; |
| 3150 | } |
| 3151 | return 0; |
| 3152 | } |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 3153 | |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 3154 | int has_turbo_ratio_limit(unsigned int family, unsigned int model) |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3155 | { |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 3156 | if (has_slv_msrs(family, model)) |
| 3157 | return 0; |
| 3158 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3159 | switch (model) { |
| 3160 | /* Nehalem compatible, but do not include turbo-ratio limit support */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3161 | case INTEL_FAM6_NEHALEM_EX: /* Nehalem-EX Xeon - Beckton */ |
| 3162 | case INTEL_FAM6_WESTMERE_EX: /* Westmere-EX Xeon - Eagleton */ |
| 3163 | case INTEL_FAM6_XEON_PHI_KNL: /* PHI - Knights Landing (different MSR definition) */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 3164 | case INTEL_FAM6_XEON_PHI_KNM: |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3165 | return 0; |
| 3166 | default: |
| 3167 | return 1; |
| 3168 | } |
| 3169 | } |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 3170 | int has_atom_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 3171 | { |
| 3172 | if (has_slv_msrs(family, model)) |
| 3173 | return 1; |
| 3174 | |
| 3175 | return 0; |
| 3176 | } |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 3177 | int has_ivt_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 3178 | { |
| 3179 | if (!genuine_intel) |
| 3180 | return 0; |
| 3181 | |
| 3182 | if (family != 6) |
| 3183 | return 0; |
| 3184 | |
| 3185 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3186 | case INTEL_FAM6_IVYBRIDGE_X: /* IVB Xeon */ |
| 3187 | case INTEL_FAM6_HASWELL_X: /* HSW Xeon */ |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 3188 | return 1; |
| 3189 | default: |
| 3190 | return 0; |
| 3191 | } |
| 3192 | } |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3193 | int has_hsw_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 3194 | { |
| 3195 | if (!genuine_intel) |
| 3196 | return 0; |
| 3197 | |
| 3198 | if (family != 6) |
| 3199 | return 0; |
| 3200 | |
| 3201 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3202 | case INTEL_FAM6_HASWELL_X: /* HSW Xeon */ |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3203 | return 1; |
| 3204 | default: |
| 3205 | return 0; |
| 3206 | } |
| 3207 | } |
| 3208 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 3209 | int has_knl_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 3210 | { |
| 3211 | if (!genuine_intel) |
| 3212 | return 0; |
| 3213 | |
| 3214 | if (family != 6) |
| 3215 | return 0; |
| 3216 | |
| 3217 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3218 | case INTEL_FAM6_XEON_PHI_KNL: /* Knights Landing */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 3219 | case INTEL_FAM6_XEON_PHI_KNM: |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 3220 | return 1; |
| 3221 | default: |
| 3222 | return 0; |
| 3223 | } |
| 3224 | } |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 3225 | int has_glm_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 3226 | { |
| 3227 | if (!genuine_intel) |
| 3228 | return 0; |
| 3229 | |
| 3230 | if (family != 6) |
| 3231 | return 0; |
| 3232 | |
| 3233 | switch (model) { |
| 3234 | case INTEL_FAM6_ATOM_GOLDMONT: |
| 3235 | case INTEL_FAM6_SKYLAKE_X: |
| 3236 | return 1; |
| 3237 | default: |
| 3238 | return 0; |
| 3239 | } |
| 3240 | } |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 3241 | int has_config_tdp(unsigned int family, unsigned int model) |
| 3242 | { |
| 3243 | if (!genuine_intel) |
| 3244 | return 0; |
| 3245 | |
| 3246 | if (family != 6) |
| 3247 | return 0; |
| 3248 | |
| 3249 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3250 | case INTEL_FAM6_IVYBRIDGE: /* IVB */ |
| 3251 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 3252 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 3253 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 3254 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 3255 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 3256 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
| 3257 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 3258 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 3259 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 3260 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 3261 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 3262 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame] | 3263 | case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3264 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 3265 | |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3266 | case INTEL_FAM6_XEON_PHI_KNL: /* Knights Landing */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 3267 | case INTEL_FAM6_XEON_PHI_KNM: |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 3268 | return 1; |
| 3269 | default: |
| 3270 | return 0; |
| 3271 | } |
| 3272 | } |
| 3273 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3274 | static void |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 3275 | dump_cstate_pstate_config_info(unsigned int family, unsigned int model) |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3276 | { |
| 3277 | if (!do_nhm_platform_info) |
| 3278 | return; |
| 3279 | |
| 3280 | dump_nhm_platform_info(); |
| 3281 | |
| 3282 | if (has_hsw_turbo_ratio_limit(family, model)) |
| 3283 | dump_hsw_turbo_ratio_limits(); |
| 3284 | |
| 3285 | if (has_ivt_turbo_ratio_limit(family, model)) |
| 3286 | dump_ivt_turbo_ratio_limits(); |
| 3287 | |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 3288 | if (has_turbo_ratio_limit(family, model)) |
| 3289 | dump_turbo_ratio_limits(family, model); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3290 | |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 3291 | if (has_atom_turbo_ratio_limit(family, model)) |
| 3292 | dump_atom_turbo_ratio_limits(); |
| 3293 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 3294 | if (has_knl_turbo_ratio_limit(family, model)) |
| 3295 | dump_knl_turbo_ratio_limits(); |
| 3296 | |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 3297 | if (has_config_tdp(family, model)) |
| 3298 | dump_config_tdp(); |
| 3299 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3300 | dump_nhm_cst_cfg(); |
| 3301 | } |
| 3302 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 3303 | static void |
| 3304 | dump_sysfs_cstate_config(void) |
| 3305 | { |
| 3306 | char path[64]; |
| 3307 | char name_buf[16]; |
| 3308 | char desc[64]; |
| 3309 | FILE *input; |
| 3310 | int state; |
| 3311 | char *sp; |
| 3312 | |
| 3313 | if (!DO_BIC(BIC_sysfs)) |
| 3314 | return; |
| 3315 | |
| 3316 | for (state = 0; state < 10; ++state) { |
| 3317 | |
| 3318 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", |
| 3319 | base_cpu, state); |
| 3320 | input = fopen(path, "r"); |
| 3321 | if (input == NULL) |
| 3322 | continue; |
| 3323 | fgets(name_buf, sizeof(name_buf), input); |
| 3324 | |
| 3325 | /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ |
| 3326 | sp = strchr(name_buf, '-'); |
| 3327 | if (!sp) |
| 3328 | sp = strchrnul(name_buf, '\n'); |
| 3329 | *sp = '\0'; |
| 3330 | |
| 3331 | fclose(input); |
| 3332 | |
| 3333 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/desc", |
| 3334 | base_cpu, state); |
| 3335 | input = fopen(path, "r"); |
| 3336 | if (input == NULL) |
| 3337 | continue; |
| 3338 | fgets(desc, sizeof(desc), input); |
| 3339 | |
| 3340 | fprintf(outf, "cpu%d: %s: %s", base_cpu, name_buf, desc); |
| 3341 | fclose(input); |
| 3342 | } |
| 3343 | } |
Len Brown | 7293fcc | 2017-02-22 00:11:12 -0500 | [diff] [blame] | 3344 | static void |
| 3345 | dump_sysfs_pstate_config(void) |
| 3346 | { |
| 3347 | char path[64]; |
| 3348 | char driver_buf[64]; |
| 3349 | char governor_buf[64]; |
| 3350 | FILE *input; |
| 3351 | int turbo; |
| 3352 | |
| 3353 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_driver", |
| 3354 | base_cpu); |
| 3355 | input = fopen(path, "r"); |
| 3356 | if (input == NULL) { |
| 3357 | fprintf(stderr, "NSFOD %s\n", path); |
| 3358 | return; |
| 3359 | } |
| 3360 | fgets(driver_buf, sizeof(driver_buf), input); |
| 3361 | fclose(input); |
| 3362 | |
| 3363 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", |
| 3364 | base_cpu); |
| 3365 | input = fopen(path, "r"); |
| 3366 | if (input == NULL) { |
| 3367 | fprintf(stderr, "NSFOD %s\n", path); |
| 3368 | return; |
| 3369 | } |
| 3370 | fgets(governor_buf, sizeof(governor_buf), input); |
| 3371 | fclose(input); |
| 3372 | |
| 3373 | fprintf(outf, "cpu%d: cpufreq driver: %s", base_cpu, driver_buf); |
| 3374 | fprintf(outf, "cpu%d: cpufreq governor: %s", base_cpu, governor_buf); |
| 3375 | |
| 3376 | sprintf(path, "/sys/devices/system/cpu/cpufreq/boost"); |
| 3377 | input = fopen(path, "r"); |
| 3378 | if (input != NULL) { |
| 3379 | fscanf(input, "%d", &turbo); |
| 3380 | fprintf(outf, "cpufreq boost: %d\n", turbo); |
| 3381 | fclose(input); |
| 3382 | } |
| 3383 | |
| 3384 | sprintf(path, "/sys/devices/system/cpu/intel_pstate/no_turbo"); |
| 3385 | input = fopen(path, "r"); |
| 3386 | if (input != NULL) { |
| 3387 | fscanf(input, "%d", &turbo); |
| 3388 | fprintf(outf, "cpufreq intel_pstate no_turbo: %d\n", turbo); |
| 3389 | fclose(input); |
| 3390 | } |
| 3391 | } |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 3392 | |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 3393 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3394 | /* |
| 3395 | * print_epb() |
| 3396 | * Decode the ENERGY_PERF_BIAS MSR |
| 3397 | */ |
| 3398 | int print_epb(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3399 | { |
| 3400 | unsigned long long msr; |
| 3401 | char *epb_string; |
| 3402 | int cpu; |
| 3403 | |
| 3404 | if (!has_epb) |
| 3405 | return 0; |
| 3406 | |
| 3407 | cpu = t->cpu_id; |
| 3408 | |
| 3409 | /* EPB is per-package */ |
| 3410 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3411 | return 0; |
| 3412 | |
| 3413 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3414 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3415 | return -1; |
| 3416 | } |
| 3417 | |
| 3418 | if (get_msr(cpu, MSR_IA32_ENERGY_PERF_BIAS, &msr)) |
| 3419 | return 0; |
| 3420 | |
Len Brown | e9be7dd | 2015-05-26 12:19:37 -0400 | [diff] [blame] | 3421 | switch (msr & 0xF) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3422 | case ENERGY_PERF_BIAS_PERFORMANCE: |
| 3423 | epb_string = "performance"; |
| 3424 | break; |
| 3425 | case ENERGY_PERF_BIAS_NORMAL: |
| 3426 | epb_string = "balanced"; |
| 3427 | break; |
| 3428 | case ENERGY_PERF_BIAS_POWERSAVE: |
| 3429 | epb_string = "powersave"; |
| 3430 | break; |
| 3431 | default: |
| 3432 | epb_string = "custom"; |
| 3433 | break; |
| 3434 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3435 | 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] | 3436 | |
| 3437 | return 0; |
| 3438 | } |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3439 | /* |
| 3440 | * print_hwp() |
| 3441 | * Decode the MSR_HWP_CAPABILITIES |
| 3442 | */ |
| 3443 | int print_hwp(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3444 | { |
| 3445 | unsigned long long msr; |
| 3446 | int cpu; |
| 3447 | |
| 3448 | if (!has_hwp) |
| 3449 | return 0; |
| 3450 | |
| 3451 | cpu = t->cpu_id; |
| 3452 | |
| 3453 | /* MSR_HWP_CAPABILITIES is per-package */ |
| 3454 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3455 | return 0; |
| 3456 | |
| 3457 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3458 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3459 | return -1; |
| 3460 | } |
| 3461 | |
| 3462 | if (get_msr(cpu, MSR_PM_ENABLE, &msr)) |
| 3463 | return 0; |
| 3464 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3465 | fprintf(outf, "cpu%d: MSR_PM_ENABLE: 0x%08llx (%sHWP)\n", |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3466 | cpu, msr, (msr & (1 << 0)) ? "" : "No-"); |
| 3467 | |
| 3468 | /* MSR_PM_ENABLE[1] == 1 if HWP is enabled and MSRs visible */ |
| 3469 | if ((msr & (1 << 0)) == 0) |
| 3470 | return 0; |
| 3471 | |
| 3472 | if (get_msr(cpu, MSR_HWP_CAPABILITIES, &msr)) |
| 3473 | return 0; |
| 3474 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3475 | fprintf(outf, "cpu%d: MSR_HWP_CAPABILITIES: 0x%08llx " |
Len Brown | 6dbd25a | 2017-03-04 18:18:28 -0500 | [diff] [blame] | 3476 | "(high %d guar %d eff %d low %d)\n", |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3477 | cpu, msr, |
| 3478 | (unsigned int)HWP_HIGHEST_PERF(msr), |
| 3479 | (unsigned int)HWP_GUARANTEED_PERF(msr), |
| 3480 | (unsigned int)HWP_MOSTEFFICIENT_PERF(msr), |
| 3481 | (unsigned int)HWP_LOWEST_PERF(msr)); |
| 3482 | |
| 3483 | if (get_msr(cpu, MSR_HWP_REQUEST, &msr)) |
| 3484 | return 0; |
| 3485 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3486 | fprintf(outf, "cpu%d: MSR_HWP_REQUEST: 0x%08llx " |
Len Brown | 6dbd25a | 2017-03-04 18:18:28 -0500 | [diff] [blame] | 3487 | "(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] | 3488 | cpu, msr, |
| 3489 | (unsigned int)(((msr) >> 0) & 0xff), |
| 3490 | (unsigned int)(((msr) >> 8) & 0xff), |
| 3491 | (unsigned int)(((msr) >> 16) & 0xff), |
| 3492 | (unsigned int)(((msr) >> 24) & 0xff), |
| 3493 | (unsigned int)(((msr) >> 32) & 0xff3), |
| 3494 | (unsigned int)(((msr) >> 42) & 0x1)); |
| 3495 | |
| 3496 | if (has_hwp_pkg) { |
| 3497 | if (get_msr(cpu, MSR_HWP_REQUEST_PKG, &msr)) |
| 3498 | return 0; |
| 3499 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3500 | fprintf(outf, "cpu%d: MSR_HWP_REQUEST_PKG: 0x%08llx " |
Len Brown | 6dbd25a | 2017-03-04 18:18:28 -0500 | [diff] [blame] | 3501 | "(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] | 3502 | cpu, msr, |
| 3503 | (unsigned int)(((msr) >> 0) & 0xff), |
| 3504 | (unsigned int)(((msr) >> 8) & 0xff), |
| 3505 | (unsigned int)(((msr) >> 16) & 0xff), |
| 3506 | (unsigned int)(((msr) >> 24) & 0xff), |
| 3507 | (unsigned int)(((msr) >> 32) & 0xff3)); |
| 3508 | } |
| 3509 | if (has_hwp_notify) { |
| 3510 | if (get_msr(cpu, MSR_HWP_INTERRUPT, &msr)) |
| 3511 | return 0; |
| 3512 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3513 | fprintf(outf, "cpu%d: MSR_HWP_INTERRUPT: 0x%08llx " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3514 | "(%s_Guaranteed_Perf_Change, %s_Excursion_Min)\n", |
| 3515 | cpu, msr, |
| 3516 | ((msr) & 0x1) ? "EN" : "Dis", |
| 3517 | ((msr) & 0x2) ? "EN" : "Dis"); |
| 3518 | } |
| 3519 | if (get_msr(cpu, MSR_HWP_STATUS, &msr)) |
| 3520 | return 0; |
| 3521 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3522 | fprintf(outf, "cpu%d: MSR_HWP_STATUS: 0x%08llx " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3523 | "(%sGuaranteed_Perf_Change, %sExcursion_Min)\n", |
| 3524 | cpu, msr, |
| 3525 | ((msr) & 0x1) ? "" : "No-", |
| 3526 | ((msr) & 0x2) ? "" : "No-"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3527 | |
| 3528 | return 0; |
| 3529 | } |
| 3530 | |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3531 | /* |
| 3532 | * print_perf_limit() |
| 3533 | */ |
| 3534 | int print_perf_limit(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3535 | { |
| 3536 | unsigned long long msr; |
| 3537 | int cpu; |
| 3538 | |
| 3539 | cpu = t->cpu_id; |
| 3540 | |
| 3541 | /* per-package */ |
| 3542 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3543 | return 0; |
| 3544 | |
| 3545 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3546 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3547 | return -1; |
| 3548 | } |
| 3549 | |
| 3550 | if (do_core_perf_limit_reasons) { |
| 3551 | get_msr(cpu, MSR_CORE_PERF_LIMIT_REASONS, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3552 | fprintf(outf, "cpu%d: MSR_CORE_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr); |
| 3553 | 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] | 3554 | (msr & 1 << 15) ? "bit15, " : "", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3555 | (msr & 1 << 14) ? "bit14, " : "", |
Len Brown | e33cbe8 | 2015-03-13 16:30:57 -0400 | [diff] [blame] | 3556 | (msr & 1 << 13) ? "Transitions, " : "", |
| 3557 | (msr & 1 << 12) ? "MultiCoreTurbo, " : "", |
| 3558 | (msr & 1 << 11) ? "PkgPwrL2, " : "", |
| 3559 | (msr & 1 << 10) ? "PkgPwrL1, " : "", |
| 3560 | (msr & 1 << 9) ? "CorePwr, " : "", |
| 3561 | (msr & 1 << 8) ? "Amps, " : "", |
| 3562 | (msr & 1 << 6) ? "VR-Therm, " : "", |
| 3563 | (msr & 1 << 5) ? "Auto-HWP, " : "", |
| 3564 | (msr & 1 << 4) ? "Graphics, " : "", |
| 3565 | (msr & 1 << 2) ? "bit2, " : "", |
| 3566 | (msr & 1 << 1) ? "ThermStatus, " : "", |
| 3567 | (msr & 1 << 0) ? "PROCHOT, " : ""); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3568 | 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] | 3569 | (msr & 1 << 31) ? "bit31, " : "", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3570 | (msr & 1 << 30) ? "bit30, " : "", |
Len Brown | e33cbe8 | 2015-03-13 16:30:57 -0400 | [diff] [blame] | 3571 | (msr & 1 << 29) ? "Transitions, " : "", |
| 3572 | (msr & 1 << 28) ? "MultiCoreTurbo, " : "", |
| 3573 | (msr & 1 << 27) ? "PkgPwrL2, " : "", |
| 3574 | (msr & 1 << 26) ? "PkgPwrL1, " : "", |
| 3575 | (msr & 1 << 25) ? "CorePwr, " : "", |
| 3576 | (msr & 1 << 24) ? "Amps, " : "", |
| 3577 | (msr & 1 << 22) ? "VR-Therm, " : "", |
| 3578 | (msr & 1 << 21) ? "Auto-HWP, " : "", |
| 3579 | (msr & 1 << 20) ? "Graphics, " : "", |
| 3580 | (msr & 1 << 18) ? "bit18, " : "", |
| 3581 | (msr & 1 << 17) ? "ThermStatus, " : "", |
| 3582 | (msr & 1 << 16) ? "PROCHOT, " : ""); |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3583 | |
| 3584 | } |
| 3585 | if (do_gfx_perf_limit_reasons) { |
| 3586 | get_msr(cpu, MSR_GFX_PERF_LIMIT_REASONS, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3587 | fprintf(outf, "cpu%d: MSR_GFX_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr); |
| 3588 | fprintf(outf, " (Active: %s%s%s%s%s%s%s%s)", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3589 | (msr & 1 << 0) ? "PROCHOT, " : "", |
| 3590 | (msr & 1 << 1) ? "ThermStatus, " : "", |
| 3591 | (msr & 1 << 4) ? "Graphics, " : "", |
| 3592 | (msr & 1 << 6) ? "VR-Therm, " : "", |
| 3593 | (msr & 1 << 8) ? "Amps, " : "", |
| 3594 | (msr & 1 << 9) ? "GFXPwr, " : "", |
| 3595 | (msr & 1 << 10) ? "PkgPwrL1, " : "", |
| 3596 | (msr & 1 << 11) ? "PkgPwrL2, " : ""); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3597 | fprintf(outf, " (Logged: %s%s%s%s%s%s%s%s)\n", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3598 | (msr & 1 << 16) ? "PROCHOT, " : "", |
| 3599 | (msr & 1 << 17) ? "ThermStatus, " : "", |
| 3600 | (msr & 1 << 20) ? "Graphics, " : "", |
| 3601 | (msr & 1 << 22) ? "VR-Therm, " : "", |
| 3602 | (msr & 1 << 24) ? "Amps, " : "", |
| 3603 | (msr & 1 << 25) ? "GFXPwr, " : "", |
| 3604 | (msr & 1 << 26) ? "PkgPwrL1, " : "", |
| 3605 | (msr & 1 << 27) ? "PkgPwrL2, " : ""); |
| 3606 | } |
| 3607 | if (do_ring_perf_limit_reasons) { |
| 3608 | get_msr(cpu, MSR_RING_PERF_LIMIT_REASONS, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3609 | fprintf(outf, "cpu%d: MSR_RING_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr); |
| 3610 | fprintf(outf, " (Active: %s%s%s%s%s%s)", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3611 | (msr & 1 << 0) ? "PROCHOT, " : "", |
| 3612 | (msr & 1 << 1) ? "ThermStatus, " : "", |
| 3613 | (msr & 1 << 6) ? "VR-Therm, " : "", |
| 3614 | (msr & 1 << 8) ? "Amps, " : "", |
| 3615 | (msr & 1 << 10) ? "PkgPwrL1, " : "", |
| 3616 | (msr & 1 << 11) ? "PkgPwrL2, " : ""); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3617 | fprintf(outf, " (Logged: %s%s%s%s%s%s)\n", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3618 | (msr & 1 << 16) ? "PROCHOT, " : "", |
| 3619 | (msr & 1 << 17) ? "ThermStatus, " : "", |
| 3620 | (msr & 1 << 22) ? "VR-Therm, " : "", |
| 3621 | (msr & 1 << 24) ? "Amps, " : "", |
| 3622 | (msr & 1 << 26) ? "PkgPwrL1, " : "", |
| 3623 | (msr & 1 << 27) ? "PkgPwrL2, " : ""); |
| 3624 | } |
| 3625 | return 0; |
| 3626 | } |
| 3627 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3628 | #define RAPL_POWER_GRANULARITY 0x7FFF /* 15 bit power granularity */ |
| 3629 | #define RAPL_TIME_GRANULARITY 0x3F /* 6 bit time granularity */ |
| 3630 | |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 3631 | double get_tdp(unsigned int model) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3632 | { |
| 3633 | unsigned long long msr; |
| 3634 | |
| 3635 | if (do_rapl & RAPL_PKG_POWER_INFO) |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3636 | if (!get_msr(base_cpu, MSR_PKG_POWER_INFO, &msr)) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3637 | return ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units; |
| 3638 | |
| 3639 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3640 | case INTEL_FAM6_ATOM_SILVERMONT1: |
| 3641 | case INTEL_FAM6_ATOM_SILVERMONT2: |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3642 | return 30.0; |
| 3643 | default: |
| 3644 | return 135.0; |
| 3645 | } |
| 3646 | } |
| 3647 | |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 3648 | /* |
| 3649 | * rapl_dram_energy_units_probe() |
| 3650 | * Energy units are either hard-coded, or come from RAPL Energy Unit MSR. |
| 3651 | */ |
| 3652 | static double |
| 3653 | rapl_dram_energy_units_probe(int model, double rapl_energy_units) |
| 3654 | { |
| 3655 | /* only called for genuine_intel, family 6 */ |
| 3656 | |
| 3657 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3658 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 3659 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 3660 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 3661 | case INTEL_FAM6_XEON_PHI_KNL: /* KNL */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 3662 | case INTEL_FAM6_XEON_PHI_KNM: |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 3663 | return (rapl_dram_energy_units = 15.3 / 1000000); |
| 3664 | default: |
| 3665 | return (rapl_energy_units); |
| 3666 | } |
| 3667 | } |
| 3668 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3669 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3670 | /* |
| 3671 | * rapl_probe() |
| 3672 | * |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3673 | * sets do_rapl, rapl_power_units, rapl_energy_units, rapl_time_units |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3674 | */ |
| 3675 | void rapl_probe(unsigned int family, unsigned int model) |
| 3676 | { |
| 3677 | unsigned long long msr; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3678 | unsigned int time_unit; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3679 | double tdp; |
| 3680 | |
| 3681 | if (!genuine_intel) |
| 3682 | return; |
| 3683 | |
| 3684 | if (family != 6) |
| 3685 | return; |
| 3686 | |
| 3687 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3688 | case INTEL_FAM6_SANDYBRIDGE: |
| 3689 | case INTEL_FAM6_IVYBRIDGE: |
| 3690 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 3691 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 3692 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 3693 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 3694 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3695 | 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] | 3696 | if (rapl_joules) { |
| 3697 | BIC_PRESENT(BIC_Pkg_J); |
| 3698 | BIC_PRESENT(BIC_Cor_J); |
| 3699 | BIC_PRESENT(BIC_GFX_J); |
| 3700 | } else { |
| 3701 | BIC_PRESENT(BIC_PkgWatt); |
| 3702 | BIC_PRESENT(BIC_CorWatt); |
| 3703 | BIC_PRESENT(BIC_GFXWatt); |
| 3704 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3705 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3706 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | ac01ac1 | 2017-01-27 01:45:35 -0500 | [diff] [blame] | 3707 | case INTEL_FAM6_ATOM_GEMINI_LAKE: |
Len Brown | e4085d5 | 2016-04-06 17:15:56 -0400 | [diff] [blame] | 3708 | do_rapl = RAPL_PKG | RAPL_PKG_POWER_INFO; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3709 | if (rapl_joules) |
| 3710 | BIC_PRESENT(BIC_Pkg_J); |
| 3711 | else |
| 3712 | BIC_PRESENT(BIC_PkgWatt); |
Len Brown | e4085d5 | 2016-04-06 17:15:56 -0400 | [diff] [blame] | 3713 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3714 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 3715 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 3716 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 3717 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame] | 3718 | case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ |
Len Brown | 8182492 | 2017-03-04 17:23:07 -0500 | [diff] [blame] | 3719 | 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] | 3720 | BIC_PRESENT(BIC_PKG__); |
| 3721 | BIC_PRESENT(BIC_RAM__); |
| 3722 | if (rapl_joules) { |
| 3723 | BIC_PRESENT(BIC_Pkg_J); |
| 3724 | BIC_PRESENT(BIC_Cor_J); |
| 3725 | BIC_PRESENT(BIC_RAM_J); |
Len Brown | 8182492 | 2017-03-04 17:23:07 -0500 | [diff] [blame] | 3726 | BIC_PRESENT(BIC_GFX_J); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3727 | } else { |
| 3728 | BIC_PRESENT(BIC_PkgWatt); |
| 3729 | BIC_PRESENT(BIC_CorWatt); |
| 3730 | BIC_PRESENT(BIC_RAMWatt); |
Len Brown | 8182492 | 2017-03-04 17:23:07 -0500 | [diff] [blame] | 3731 | BIC_PRESENT(BIC_GFXWatt); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3732 | } |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3733 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3734 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 3735 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 3736 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 3737 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
| 3738 | case INTEL_FAM6_XEON_PHI_KNL: /* KNL */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 3739 | case INTEL_FAM6_XEON_PHI_KNM: |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3740 | 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] | 3741 | BIC_PRESENT(BIC_PKG__); |
| 3742 | BIC_PRESENT(BIC_RAM__); |
| 3743 | if (rapl_joules) { |
| 3744 | BIC_PRESENT(BIC_Pkg_J); |
| 3745 | BIC_PRESENT(BIC_RAM_J); |
| 3746 | } else { |
| 3747 | BIC_PRESENT(BIC_PkgWatt); |
| 3748 | BIC_PRESENT(BIC_RAMWatt); |
| 3749 | } |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 3750 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3751 | case INTEL_FAM6_SANDYBRIDGE_X: |
| 3752 | case INTEL_FAM6_IVYBRIDGE_X: |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3753 | 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] | 3754 | BIC_PRESENT(BIC_PKG__); |
| 3755 | BIC_PRESENT(BIC_RAM__); |
| 3756 | if (rapl_joules) { |
| 3757 | BIC_PRESENT(BIC_Pkg_J); |
| 3758 | BIC_PRESENT(BIC_Cor_J); |
| 3759 | BIC_PRESENT(BIC_RAM_J); |
| 3760 | } else { |
| 3761 | BIC_PRESENT(BIC_PkgWatt); |
| 3762 | BIC_PRESENT(BIC_CorWatt); |
| 3763 | BIC_PRESENT(BIC_RAMWatt); |
| 3764 | } |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3765 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3766 | case INTEL_FAM6_ATOM_SILVERMONT1: /* BYT */ |
| 3767 | case INTEL_FAM6_ATOM_SILVERMONT2: /* AVN */ |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 3768 | do_rapl = RAPL_PKG | RAPL_CORES; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3769 | if (rapl_joules) { |
| 3770 | BIC_PRESENT(BIC_Pkg_J); |
| 3771 | BIC_PRESENT(BIC_Cor_J); |
| 3772 | } else { |
| 3773 | BIC_PRESENT(BIC_PkgWatt); |
| 3774 | BIC_PRESENT(BIC_CorWatt); |
| 3775 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3776 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3777 | case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ |
Jacob Pan | 0f64490 | 2016-06-16 09:48:22 -0700 | [diff] [blame] | 3778 | 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] | 3779 | BIC_PRESENT(BIC_PKG__); |
| 3780 | BIC_PRESENT(BIC_RAM__); |
| 3781 | if (rapl_joules) { |
| 3782 | BIC_PRESENT(BIC_Pkg_J); |
| 3783 | BIC_PRESENT(BIC_Cor_J); |
| 3784 | BIC_PRESENT(BIC_RAM_J); |
| 3785 | } else { |
| 3786 | BIC_PRESENT(BIC_PkgWatt); |
| 3787 | BIC_PRESENT(BIC_CorWatt); |
| 3788 | BIC_PRESENT(BIC_RAMWatt); |
| 3789 | } |
Jacob Pan | 0f64490 | 2016-06-16 09:48:22 -0700 | [diff] [blame] | 3790 | break; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3791 | default: |
| 3792 | return; |
| 3793 | } |
| 3794 | |
| 3795 | /* units on package 0, verify later other packages match */ |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3796 | if (get_msr(base_cpu, MSR_RAPL_POWER_UNIT, &msr)) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3797 | return; |
| 3798 | |
| 3799 | rapl_power_units = 1.0 / (1 << (msr & 0xF)); |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3800 | if (model == INTEL_FAM6_ATOM_SILVERMONT1) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3801 | rapl_energy_units = 1.0 * (1 << (msr >> 8 & 0x1F)) / 1000000; |
| 3802 | else |
| 3803 | rapl_energy_units = 1.0 / (1 << (msr >> 8 & 0x1F)); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3804 | |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 3805 | rapl_dram_energy_units = rapl_dram_energy_units_probe(model, rapl_energy_units); |
| 3806 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3807 | time_unit = msr >> 16 & 0xF; |
| 3808 | if (time_unit == 0) |
| 3809 | time_unit = 0xA; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3810 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3811 | rapl_time_units = 1.0 / (1 << (time_unit)); |
| 3812 | |
| 3813 | tdp = get_tdp(model); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3814 | |
| 3815 | rapl_joule_counter_range = 0xFFFFFFFF * rapl_energy_units / tdp; |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3816 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3817 | 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] | 3818 | |
| 3819 | return; |
| 3820 | } |
| 3821 | |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 3822 | void perf_limit_reasons_probe(unsigned int family, unsigned int model) |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3823 | { |
| 3824 | if (!genuine_intel) |
| 3825 | return; |
| 3826 | |
| 3827 | if (family != 6) |
| 3828 | return; |
| 3829 | |
| 3830 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3831 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 3832 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 3833 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3834 | do_gfx_perf_limit_reasons = 1; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3835 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3836 | do_core_perf_limit_reasons = 1; |
| 3837 | do_ring_perf_limit_reasons = 1; |
| 3838 | default: |
| 3839 | return; |
| 3840 | } |
| 3841 | } |
| 3842 | |
Artem Bityutskiy | ac980e1 | 2017-09-05 15:14:08 +0300 | [diff] [blame] | 3843 | void automatic_cstate_conversion_probe(unsigned int family, unsigned int model) |
| 3844 | { |
| 3845 | if (is_skx(family, model) || is_bdx(family, model)) |
| 3846 | has_automatic_cstate_conversion = 1; |
| 3847 | } |
| 3848 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3849 | int print_thermal(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3850 | { |
| 3851 | unsigned long long msr; |
Len Brown | f4896fa5 | 2017-03-04 18:10:45 -0500 | [diff] [blame] | 3852 | unsigned int dts, dts2; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3853 | int cpu; |
| 3854 | |
| 3855 | if (!(do_dts || do_ptm)) |
| 3856 | return 0; |
| 3857 | |
| 3858 | cpu = t->cpu_id; |
| 3859 | |
| 3860 | /* DTS is per-core, no need to print for each thread */ |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 3861 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3862 | return 0; |
| 3863 | |
| 3864 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3865 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3866 | return -1; |
| 3867 | } |
| 3868 | |
| 3869 | if (do_ptm && (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) { |
| 3870 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr)) |
| 3871 | return 0; |
| 3872 | |
| 3873 | dts = (msr >> 16) & 0x7F; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3874 | 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] | 3875 | cpu, msr, tcc_activation_temp - dts); |
| 3876 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3877 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, &msr)) |
| 3878 | return 0; |
| 3879 | |
| 3880 | dts = (msr >> 16) & 0x7F; |
| 3881 | dts2 = (msr >> 8) & 0x7F; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3882 | 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] | 3883 | cpu, msr, tcc_activation_temp - dts, tcc_activation_temp - dts2); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3884 | } |
| 3885 | |
| 3886 | |
Len Brown | f4896fa5 | 2017-03-04 18:10:45 -0500 | [diff] [blame] | 3887 | if (do_dts && debug) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3888 | unsigned int resolution; |
| 3889 | |
| 3890 | if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr)) |
| 3891 | return 0; |
| 3892 | |
| 3893 | dts = (msr >> 16) & 0x7F; |
| 3894 | resolution = (msr >> 27) & 0xF; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3895 | 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] | 3896 | cpu, msr, tcc_activation_temp - dts, resolution); |
| 3897 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3898 | if (get_msr(cpu, MSR_IA32_THERM_INTERRUPT, &msr)) |
| 3899 | return 0; |
| 3900 | |
| 3901 | dts = (msr >> 16) & 0x7F; |
| 3902 | dts2 = (msr >> 8) & 0x7F; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3903 | 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] | 3904 | cpu, msr, tcc_activation_temp - dts, tcc_activation_temp - dts2); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3905 | } |
| 3906 | |
| 3907 | return 0; |
| 3908 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 3909 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3910 | void print_power_limit_msr(int cpu, unsigned long long msr, char *label) |
| 3911 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3912 | 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] | 3913 | cpu, label, |
| 3914 | ((msr >> 15) & 1) ? "EN" : "DIS", |
| 3915 | ((msr >> 0) & 0x7FFF) * rapl_power_units, |
| 3916 | (1.0 + (((msr >> 22) & 0x3)/4.0)) * (1 << ((msr >> 17) & 0x1F)) * rapl_time_units, |
| 3917 | (((msr >> 16) & 1) ? "EN" : "DIS")); |
| 3918 | |
| 3919 | return; |
| 3920 | } |
| 3921 | |
| 3922 | int print_rapl(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3923 | { |
| 3924 | unsigned long long msr; |
| 3925 | int cpu; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3926 | |
| 3927 | if (!do_rapl) |
| 3928 | return 0; |
| 3929 | |
| 3930 | /* RAPL counters are per package, so print only for 1st thread/package */ |
| 3931 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3932 | return 0; |
| 3933 | |
| 3934 | cpu = t->cpu_id; |
| 3935 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3936 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3937 | return -1; |
| 3938 | } |
| 3939 | |
| 3940 | if (get_msr(cpu, MSR_RAPL_POWER_UNIT, &msr)) |
| 3941 | return -1; |
| 3942 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3943 | fprintf(outf, "cpu%d: MSR_RAPL_POWER_UNIT: 0x%08llx (%f Watts, %f Joules, %f sec.)\n", cpu, msr, |
| 3944 | rapl_power_units, rapl_energy_units, rapl_time_units); |
| 3945 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3946 | if (do_rapl & RAPL_PKG_POWER_INFO) { |
| 3947 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3948 | if (get_msr(cpu, MSR_PKG_POWER_INFO, &msr)) |
| 3949 | return -5; |
| 3950 | |
| 3951 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3952 | 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] | 3953 | cpu, msr, |
| 3954 | ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3955 | ((msr >> 16) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3956 | ((msr >> 32) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3957 | ((msr >> 48) & RAPL_TIME_GRANULARITY) * rapl_time_units); |
| 3958 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3959 | } |
| 3960 | if (do_rapl & RAPL_PKG) { |
| 3961 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3962 | if (get_msr(cpu, MSR_PKG_POWER_LIMIT, &msr)) |
| 3963 | return -9; |
| 3964 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3965 | fprintf(outf, "cpu%d: MSR_PKG_POWER_LIMIT: 0x%08llx (%slocked)\n", |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3966 | cpu, msr, (msr >> 63) & 1 ? "" : "UN"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3967 | |
| 3968 | print_power_limit_msr(cpu, msr, "PKG Limit #1"); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3969 | 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] | 3970 | cpu, |
| 3971 | ((msr >> 47) & 1) ? "EN" : "DIS", |
| 3972 | ((msr >> 32) & 0x7FFF) * rapl_power_units, |
| 3973 | (1.0 + (((msr >> 54) & 0x3)/4.0)) * (1 << ((msr >> 49) & 0x1F)) * rapl_time_units, |
| 3974 | ((msr >> 48) & 1) ? "EN" : "DIS"); |
| 3975 | } |
| 3976 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3977 | if (do_rapl & RAPL_DRAM_POWER_INFO) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3978 | if (get_msr(cpu, MSR_DRAM_POWER_INFO, &msr)) |
| 3979 | return -6; |
| 3980 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3981 | 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] | 3982 | cpu, msr, |
| 3983 | ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3984 | ((msr >> 16) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3985 | ((msr >> 32) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 3986 | ((msr >> 48) & RAPL_TIME_GRANULARITY) * rapl_time_units); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3987 | } |
| 3988 | if (do_rapl & RAPL_DRAM) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3989 | if (get_msr(cpu, MSR_DRAM_POWER_LIMIT, &msr)) |
| 3990 | return -9; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3991 | fprintf(outf, "cpu%d: MSR_DRAM_POWER_LIMIT: 0x%08llx (%slocked)\n", |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3992 | cpu, msr, (msr >> 31) & 1 ? "" : "UN"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3993 | |
| 3994 | print_power_limit_msr(cpu, msr, "DRAM Limit"); |
| 3995 | } |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3996 | if (do_rapl & RAPL_CORE_POLICY) { |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3997 | if (get_msr(cpu, MSR_PP0_POLICY, &msr)) |
| 3998 | return -7; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3999 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4000 | fprintf(outf, "cpu%d: MSR_PP0_POLICY: %lld\n", cpu, msr & 0xF); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4001 | } |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 4002 | if (do_rapl & RAPL_CORES_POWER_LIMIT) { |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4003 | if (get_msr(cpu, MSR_PP0_POWER_LIMIT, &msr)) |
| 4004 | return -9; |
| 4005 | fprintf(outf, "cpu%d: MSR_PP0_POWER_LIMIT: 0x%08llx (%slocked)\n", |
| 4006 | cpu, msr, (msr >> 31) & 1 ? "" : "UN"); |
| 4007 | print_power_limit_msr(cpu, msr, "Cores Limit"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4008 | } |
| 4009 | if (do_rapl & RAPL_GFX) { |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4010 | if (get_msr(cpu, MSR_PP1_POLICY, &msr)) |
| 4011 | return -8; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4012 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4013 | fprintf(outf, "cpu%d: MSR_PP1_POLICY: %lld\n", cpu, msr & 0xF); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4014 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4015 | if (get_msr(cpu, MSR_PP1_POWER_LIMIT, &msr)) |
| 4016 | return -9; |
| 4017 | fprintf(outf, "cpu%d: MSR_PP1_POWER_LIMIT: 0x%08llx (%slocked)\n", |
| 4018 | cpu, msr, (msr >> 31) & 1 ? "" : "UN"); |
| 4019 | print_power_limit_msr(cpu, msr, "GFX Limit"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4020 | } |
| 4021 | return 0; |
| 4022 | } |
| 4023 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4024 | /* |
| 4025 | * SNB adds support for additional MSRs: |
| 4026 | * |
| 4027 | * MSR_PKG_C7_RESIDENCY 0x000003fa |
| 4028 | * MSR_CORE_C7_RESIDENCY 0x000003fe |
| 4029 | * MSR_PKG_C2_RESIDENCY 0x0000060d |
| 4030 | */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4031 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4032 | int has_snb_msrs(unsigned int family, unsigned int model) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4033 | { |
| 4034 | if (!genuine_intel) |
| 4035 | return 0; |
| 4036 | |
| 4037 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4038 | case INTEL_FAM6_SANDYBRIDGE: |
| 4039 | case INTEL_FAM6_SANDYBRIDGE_X: |
| 4040 | case INTEL_FAM6_IVYBRIDGE: /* IVB */ |
| 4041 | case INTEL_FAM6_IVYBRIDGE_X: /* IVB Xeon */ |
| 4042 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 4043 | case INTEL_FAM6_HASWELL_X: /* HSW */ |
| 4044 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 4045 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 4046 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 4047 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
| 4048 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
| 4049 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 4050 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 4051 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 4052 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 4053 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame] | 4054 | case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4055 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
| 4056 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | ac01ac1 | 2017-01-27 01:45:35 -0500 | [diff] [blame] | 4057 | case INTEL_FAM6_ATOM_GEMINI_LAKE: |
Xiaolong Wang | 5bbac26 | 2016-09-30 17:53:40 +0800 | [diff] [blame] | 4058 | case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4059 | return 1; |
| 4060 | } |
| 4061 | return 0; |
| 4062 | } |
| 4063 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4064 | /* |
| 4065 | * HSW adds support for additional MSRs: |
| 4066 | * |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 4067 | * MSR_PKG_C8_RESIDENCY 0x00000630 |
| 4068 | * MSR_PKG_C9_RESIDENCY 0x00000631 |
| 4069 | * MSR_PKG_C10_RESIDENCY 0x00000632 |
| 4070 | * |
| 4071 | * MSR_PKGC8_IRTL 0x00000633 |
| 4072 | * MSR_PKGC9_IRTL 0x00000634 |
| 4073 | * MSR_PKGC10_IRTL 0x00000635 |
| 4074 | * |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4075 | */ |
| 4076 | int has_hsw_msrs(unsigned int family, unsigned int model) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 4077 | { |
| 4078 | if (!genuine_intel) |
| 4079 | return 0; |
| 4080 | |
| 4081 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4082 | case INTEL_FAM6_HASWELL_ULT: /* HSW */ |
| 4083 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 4084 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 4085 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 4086 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 4087 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame] | 4088 | case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4089 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | ac01ac1 | 2017-01-27 01:45:35 -0500 | [diff] [blame] | 4090 | case INTEL_FAM6_ATOM_GEMINI_LAKE: |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 4091 | return 1; |
| 4092 | } |
| 4093 | return 0; |
| 4094 | } |
| 4095 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 4096 | /* |
| 4097 | * SKL adds support for additional MSRS: |
| 4098 | * |
| 4099 | * MSR_PKG_WEIGHTED_CORE_C0_RES 0x00000658 |
| 4100 | * MSR_PKG_ANY_CORE_C0_RES 0x00000659 |
| 4101 | * MSR_PKG_ANY_GFXE_C0_RES 0x0000065A |
| 4102 | * MSR_PKG_BOTH_CORE_GFXE_C0_RES 0x0000065B |
| 4103 | */ |
| 4104 | int has_skl_msrs(unsigned int family, unsigned int model) |
| 4105 | { |
| 4106 | if (!genuine_intel) |
| 4107 | return 0; |
| 4108 | |
| 4109 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4110 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 4111 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 4112 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 4113 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame] | 4114 | case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 4115 | return 1; |
| 4116 | } |
| 4117 | return 0; |
| 4118 | } |
| 4119 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4120 | int is_slm(unsigned int family, unsigned int model) |
| 4121 | { |
| 4122 | if (!genuine_intel) |
| 4123 | return 0; |
| 4124 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4125 | case INTEL_FAM6_ATOM_SILVERMONT1: /* BYT */ |
| 4126 | case INTEL_FAM6_ATOM_SILVERMONT2: /* AVN */ |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4127 | return 1; |
| 4128 | } |
| 4129 | return 0; |
| 4130 | } |
| 4131 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 4132 | int is_knl(unsigned int family, unsigned int model) |
| 4133 | { |
| 4134 | if (!genuine_intel) |
| 4135 | return 0; |
| 4136 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4137 | case INTEL_FAM6_XEON_PHI_KNL: /* KNL */ |
Len Brown | 005c82d | 2016-12-01 01:35:38 -0500 | [diff] [blame] | 4138 | case INTEL_FAM6_XEON_PHI_KNM: |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 4139 | return 1; |
| 4140 | } |
| 4141 | return 0; |
| 4142 | } |
| 4143 | |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame] | 4144 | int is_cnl(unsigned int family, unsigned int model) |
| 4145 | { |
| 4146 | if (!genuine_intel) |
| 4147 | return 0; |
| 4148 | |
| 4149 | switch (model) { |
| 4150 | case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ |
| 4151 | return 1; |
| 4152 | } |
| 4153 | |
| 4154 | return 0; |
| 4155 | } |
| 4156 | |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 4157 | unsigned int get_aperf_mperf_multiplier(unsigned int family, unsigned int model) |
| 4158 | { |
| 4159 | if (is_knl(family, model)) |
| 4160 | return 1024; |
| 4161 | return 1; |
| 4162 | } |
| 4163 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4164 | #define SLM_BCLK_FREQS 5 |
| 4165 | double slm_freq_table[SLM_BCLK_FREQS] = { 83.3, 100.0, 133.3, 116.7, 80.0}; |
| 4166 | |
| 4167 | double slm_bclk(void) |
| 4168 | { |
| 4169 | unsigned long long msr = 3; |
| 4170 | unsigned int i; |
| 4171 | double freq; |
| 4172 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 4173 | if (get_msr(base_cpu, MSR_FSB_FREQ, &msr)) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4174 | fprintf(outf, "SLM BCLK: unknown\n"); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4175 | |
| 4176 | i = msr & 0xf; |
| 4177 | if (i >= SLM_BCLK_FREQS) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4178 | fprintf(outf, "SLM BCLK[%d] invalid\n", i); |
Colin Ian King | 0a91e55 | 2016-04-25 13:03:15 +0100 | [diff] [blame] | 4179 | i = 3; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4180 | } |
| 4181 | freq = slm_freq_table[i]; |
| 4182 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4183 | if (!quiet) |
Len Brown | 8f6196c | 2017-01-07 22:40:23 -0500 | [diff] [blame] | 4184 | fprintf(outf, "SLM BCLK: %.1f Mhz\n", freq); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4185 | |
| 4186 | return freq; |
| 4187 | } |
| 4188 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4189 | double discover_bclk(unsigned int family, unsigned int model) |
| 4190 | { |
Chrzaniuk, Hubert | 121b48b | 2016-02-10 16:35:17 +0100 | [diff] [blame] | 4191 | if (has_snb_msrs(family, model) || is_knl(family, model)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4192 | return 100.00; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4193 | else if (is_slm(family, model)) |
| 4194 | return slm_bclk(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4195 | else |
| 4196 | return 133.33; |
| 4197 | } |
| 4198 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4199 | /* |
| 4200 | * MSR_IA32_TEMPERATURE_TARGET indicates the temperature where |
| 4201 | * the Thermal Control Circuit (TCC) activates. |
| 4202 | * This is usually equal to tjMax. |
| 4203 | * |
| 4204 | * Older processors do not have this MSR, so there we guess, |
| 4205 | * but also allow cmdline over-ride with -T. |
| 4206 | * |
| 4207 | * Several MSR temperature values are in units of degrees-C |
| 4208 | * below this value, including the Digital Thermal Sensor (DTS), |
| 4209 | * Package Thermal Management Sensor (PTM), and thermal event thresholds. |
| 4210 | */ |
| 4211 | int set_temperature_target(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 4212 | { |
| 4213 | unsigned long long msr; |
| 4214 | unsigned int target_c_local; |
| 4215 | int cpu; |
| 4216 | |
| 4217 | /* tcc_activation_temp is used only for dts or ptm */ |
| 4218 | if (!(do_dts || do_ptm)) |
| 4219 | return 0; |
| 4220 | |
| 4221 | /* this is a per-package concept */ |
| 4222 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 4223 | return 0; |
| 4224 | |
| 4225 | cpu = t->cpu_id; |
| 4226 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4227 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4228 | return -1; |
| 4229 | } |
| 4230 | |
| 4231 | if (tcc_activation_temp_override != 0) { |
| 4232 | tcc_activation_temp = tcc_activation_temp_override; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4233 | fprintf(outf, "cpu%d: Using cmdline TCC Target (%d C)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4234 | cpu, tcc_activation_temp); |
| 4235 | return 0; |
| 4236 | } |
| 4237 | |
| 4238 | /* Temperature Target MSR is Nehalem and newer only */ |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4239 | if (!do_nhm_platform_info) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4240 | goto guess; |
| 4241 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 4242 | if (get_msr(base_cpu, MSR_IA32_TEMPERATURE_TARGET, &msr)) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4243 | goto guess; |
| 4244 | |
Jean Delvare | 3482124 | 2014-05-01 11:40:19 +0200 | [diff] [blame] | 4245 | target_c_local = (msr >> 16) & 0xFF; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4246 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4247 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4248 | 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] | 4249 | cpu, msr, target_c_local); |
| 4250 | |
Jean Delvare | 3482124 | 2014-05-01 11:40:19 +0200 | [diff] [blame] | 4251 | if (!target_c_local) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4252 | goto guess; |
| 4253 | |
| 4254 | tcc_activation_temp = target_c_local; |
| 4255 | |
| 4256 | return 0; |
| 4257 | |
| 4258 | guess: |
| 4259 | tcc_activation_temp = TJMAX_DEFAULT; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4260 | 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] | 4261 | cpu, tcc_activation_temp); |
| 4262 | |
| 4263 | return 0; |
| 4264 | } |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4265 | |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 4266 | void decode_feature_control_msr(void) |
| 4267 | { |
| 4268 | unsigned long long msr; |
| 4269 | |
| 4270 | if (!get_msr(base_cpu, MSR_IA32_FEATURE_CONTROL, &msr)) |
| 4271 | fprintf(outf, "cpu%d: MSR_IA32_FEATURE_CONTROL: 0x%08llx (%sLocked %s)\n", |
| 4272 | base_cpu, msr, |
| 4273 | msr & FEATURE_CONTROL_LOCKED ? "" : "UN-", |
| 4274 | msr & (1 << 18) ? "SGX" : ""); |
| 4275 | } |
| 4276 | |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4277 | void decode_misc_enable_msr(void) |
| 4278 | { |
| 4279 | unsigned long long msr; |
| 4280 | |
Len Brown | f26b151 | 2017-06-23 20:45:54 -0700 | [diff] [blame] | 4281 | if (!genuine_intel) |
| 4282 | return; |
| 4283 | |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4284 | if (!get_msr(base_cpu, MSR_IA32_MISC_ENABLE, &msr)) |
Len Brown | e651262 | 2017-01-11 23:17:24 -0500 | [diff] [blame] | 4285 | 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] | 4286 | base_cpu, msr, |
Len Brown | e651262 | 2017-01-11 23:17:24 -0500 | [diff] [blame] | 4287 | msr & MSR_IA32_MISC_ENABLE_TM1 ? "" : "No-", |
| 4288 | msr & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP ? "" : "No-", |
Len Brown | fd3933c | 2017-11-08 23:15:42 -0500 | [diff] [blame] | 4289 | msr & MSR_IA32_MISC_ENABLE_MWAIT ? "" : "No-", |
Len Brown | e651262 | 2017-01-11 23:17:24 -0500 | [diff] [blame] | 4290 | msr & MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE ? "No-" : "", |
| 4291 | msr & MSR_IA32_MISC_ENABLE_TURBO_DISABLE ? "No-" : ""); |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4292 | } |
| 4293 | |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 4294 | void decode_misc_feature_control(void) |
| 4295 | { |
| 4296 | unsigned long long msr; |
| 4297 | |
| 4298 | if (!has_misc_feature_control) |
| 4299 | return; |
| 4300 | |
| 4301 | if (!get_msr(base_cpu, MSR_MISC_FEATURE_CONTROL, &msr)) |
| 4302 | fprintf(outf, "cpu%d: MSR_MISC_FEATURE_CONTROL: 0x%08llx (%sL2-Prefetch %sL2-Prefetch-pair %sL1-Prefetch %sL1-IP-Prefetch)\n", |
| 4303 | base_cpu, msr, |
| 4304 | msr & (0 << 0) ? "No-" : "", |
| 4305 | msr & (1 << 0) ? "No-" : "", |
| 4306 | msr & (2 << 0) ? "No-" : "", |
| 4307 | msr & (3 << 0) ? "No-" : ""); |
| 4308 | } |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 4309 | /* |
| 4310 | * Decode MSR_MISC_PWR_MGMT |
| 4311 | * |
| 4312 | * Decode the bits according to the Nehalem documentation |
| 4313 | * bit[0] seems to continue to have same meaning going forward |
| 4314 | * bit[1] less so... |
| 4315 | */ |
| 4316 | void decode_misc_pwr_mgmt_msr(void) |
| 4317 | { |
| 4318 | unsigned long long msr; |
| 4319 | |
| 4320 | if (!do_nhm_platform_info) |
| 4321 | return; |
| 4322 | |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 4323 | if (no_MSR_MISC_PWR_MGMT) |
| 4324 | return; |
| 4325 | |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 4326 | if (!get_msr(base_cpu, MSR_MISC_PWR_MGMT, &msr)) |
Srinivas Pandruvada | ddadb8a | 2016-11-11 14:29:48 -0800 | [diff] [blame] | 4327 | 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] | 4328 | base_cpu, msr, |
| 4329 | msr & (1 << 0) ? "DIS" : "EN", |
Srinivas Pandruvada | ddadb8a | 2016-11-11 14:29:48 -0800 | [diff] [blame] | 4330 | msr & (1 << 1) ? "EN" : "DIS", |
| 4331 | msr & (1 << 8) ? "EN" : "DIS"); |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 4332 | } |
Len Brown | 71616c8 | 2017-01-07 22:37:48 -0500 | [diff] [blame] | 4333 | /* |
| 4334 | * Decode MSR_CC6_DEMOTION_POLICY_CONFIG, MSR_MC6_DEMOTION_POLICY_CONFIG |
| 4335 | * |
| 4336 | * This MSRs are present on Silvermont processors, |
| 4337 | * Intel Atom processor E3000 series (Baytrail), and friends. |
| 4338 | */ |
| 4339 | void decode_c6_demotion_policy_msr(void) |
| 4340 | { |
| 4341 | unsigned long long msr; |
| 4342 | |
| 4343 | if (!get_msr(base_cpu, MSR_CC6_DEMOTION_POLICY_CONFIG, &msr)) |
| 4344 | fprintf(outf, "cpu%d: MSR_CC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-CC6-Demotion)\n", |
| 4345 | base_cpu, msr, msr & (1 << 0) ? "EN" : "DIS"); |
| 4346 | |
| 4347 | if (!get_msr(base_cpu, MSR_MC6_DEMOTION_POLICY_CONFIG, &msr)) |
| 4348 | fprintf(outf, "cpu%d: MSR_MC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-MC6-Demotion)\n", |
| 4349 | base_cpu, msr, msr & (1 << 0) ? "EN" : "DIS"); |
| 4350 | } |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4351 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 4352 | void process_cpuid() |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4353 | { |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 4354 | unsigned int eax, ebx, ecx, edx, max_level, max_extended_level; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4355 | unsigned int fms, family, model, stepping; |
Len Brown | b3a34e9 | 2017-01-21 00:50:08 -0500 | [diff] [blame] | 4356 | unsigned int has_turbo; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4357 | |
| 4358 | eax = ebx = ecx = edx = 0; |
| 4359 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4360 | __cpuid(0, max_level, ebx, ecx, edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4361 | |
| 4362 | if (ebx == 0x756e6547 && edx == 0x49656e69 && ecx == 0x6c65746e) |
| 4363 | genuine_intel = 1; |
| 4364 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4365 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4366 | fprintf(outf, "CPUID(0): %.4s%.4s%.4s ", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4367 | (char *)&ebx, (char *)&edx, (char *)&ecx); |
| 4368 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4369 | __cpuid(1, fms, ebx, ecx, edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4370 | family = (fms >> 8) & 0xf; |
| 4371 | model = (fms >> 4) & 0xf; |
| 4372 | stepping = fms & 0xf; |
| 4373 | if (family == 6 || family == 0xf) |
| 4374 | model += ((fms >> 16) & 0xf) << 4; |
| 4375 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4376 | if (!quiet) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4377 | 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] | 4378 | max_level, family, model, stepping, family, model, stepping); |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 4379 | 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] | 4380 | ecx & (1 << 0) ? "SSE3" : "-", |
| 4381 | ecx & (1 << 3) ? "MONITOR" : "-", |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 4382 | ecx & (1 << 6) ? "SMX" : "-", |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4383 | ecx & (1 << 7) ? "EIST" : "-", |
| 4384 | ecx & (1 << 8) ? "TM2" : "-", |
| 4385 | edx & (1 << 4) ? "TSC" : "-", |
| 4386 | edx & (1 << 5) ? "MSR" : "-", |
| 4387 | edx & (1 << 22) ? "ACPI-TM" : "-", |
| 4388 | edx & (1 << 29) ? "TM" : "-"); |
| 4389 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4390 | |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4391 | if (!(edx & (1 << 5))) |
| 4392 | errx(1, "CPUID: no MSR"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4393 | |
| 4394 | /* |
| 4395 | * check max extended function levels of CPUID. |
| 4396 | * This is needed to check for invariant TSC. |
| 4397 | * This check is valid for both Intel and AMD. |
| 4398 | */ |
| 4399 | ebx = ecx = edx = 0; |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4400 | __cpuid(0x80000000, max_extended_level, ebx, ecx, edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4401 | |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 4402 | if (max_extended_level >= 0x80000007) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4403 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4404 | /* |
| 4405 | * Non-Stop TSC is advertised by CPUID.EAX=0x80000007: EDX.bit8 |
| 4406 | * this check is valid for both Intel and AMD |
| 4407 | */ |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4408 | __cpuid(0x80000007, eax, ebx, ecx, edx); |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4409 | has_invariant_tsc = edx & (1 << 8); |
| 4410 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4411 | |
| 4412 | /* |
| 4413 | * APERF/MPERF is advertised by CPUID.EAX=0x6: ECX.bit0 |
| 4414 | * this check is valid for both Intel and AMD |
| 4415 | */ |
| 4416 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4417 | __cpuid(0x6, eax, ebx, ecx, edx); |
Thomas Renninger | 8209e05 | 2011-01-21 15:11:19 +0100 | [diff] [blame] | 4418 | has_aperf = ecx & (1 << 0); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4419 | if (has_aperf) { |
| 4420 | BIC_PRESENT(BIC_Avg_MHz); |
| 4421 | BIC_PRESENT(BIC_Busy); |
| 4422 | BIC_PRESENT(BIC_Bzy_MHz); |
| 4423 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4424 | do_dts = eax & (1 << 0); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4425 | if (do_dts) |
| 4426 | BIC_PRESENT(BIC_CoreTmp); |
Len Brown | b3a34e9 | 2017-01-21 00:50:08 -0500 | [diff] [blame] | 4427 | has_turbo = eax & (1 << 1); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4428 | do_ptm = eax & (1 << 6); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4429 | if (do_ptm) |
| 4430 | BIC_PRESENT(BIC_PkgTmp); |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4431 | has_hwp = eax & (1 << 7); |
| 4432 | has_hwp_notify = eax & (1 << 8); |
| 4433 | has_hwp_activity_window = eax & (1 << 9); |
| 4434 | has_hwp_epp = eax & (1 << 10); |
| 4435 | has_hwp_pkg = eax & (1 << 11); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4436 | has_epb = ecx & (1 << 3); |
| 4437 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4438 | if (!quiet) |
Len Brown | b3a34e9 | 2017-01-21 00:50:08 -0500 | [diff] [blame] | 4439 | fprintf(outf, "CPUID(6): %sAPERF, %sTURBO, %sDTS, %sPTM, %sHWP, " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4440 | "%sHWPnotify, %sHWPwindow, %sHWPepp, %sHWPpkg, %sEPB\n", |
| 4441 | has_aperf ? "" : "No-", |
Len Brown | b3a34e9 | 2017-01-21 00:50:08 -0500 | [diff] [blame] | 4442 | has_turbo ? "" : "No-", |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4443 | do_dts ? "" : "No-", |
| 4444 | do_ptm ? "" : "No-", |
| 4445 | has_hwp ? "" : "No-", |
| 4446 | has_hwp_notify ? "" : "No-", |
| 4447 | has_hwp_activity_window ? "" : "No-", |
| 4448 | has_hwp_epp ? "" : "No-", |
| 4449 | has_hwp_pkg ? "" : "No-", |
| 4450 | has_epb ? "" : "No-"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4451 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4452 | if (!quiet) |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4453 | decode_misc_enable_msr(); |
| 4454 | |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 4455 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4456 | if (max_level >= 0x7 && !quiet) { |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 4457 | int has_sgx; |
| 4458 | |
| 4459 | ecx = 0; |
| 4460 | |
| 4461 | __cpuid_count(0x7, 0, eax, ebx, ecx, edx); |
| 4462 | |
| 4463 | has_sgx = ebx & (1 << 2); |
| 4464 | fprintf(outf, "CPUID(7): %sSGX\n", has_sgx ? "" : "No-"); |
| 4465 | |
| 4466 | if (has_sgx) |
| 4467 | decode_feature_control_msr(); |
| 4468 | } |
| 4469 | |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 4470 | if (max_level >= 0x15) { |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4471 | unsigned int eax_crystal; |
| 4472 | unsigned int ebx_tsc; |
| 4473 | |
| 4474 | /* |
| 4475 | * CPUID 15H TSC/Crystal ratio, possibly Crystal Hz |
| 4476 | */ |
| 4477 | eax_crystal = ebx_tsc = crystal_hz = edx = 0; |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4478 | __cpuid(0x15, eax_crystal, ebx_tsc, crystal_hz, edx); |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4479 | |
| 4480 | if (ebx_tsc != 0) { |
| 4481 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4482 | if (!quiet && (ebx != 0)) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4483 | 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] | 4484 | eax_crystal, ebx_tsc, crystal_hz); |
| 4485 | |
| 4486 | if (crystal_hz == 0) |
| 4487 | switch(model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4488 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
| 4489 | case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ |
| 4490 | case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ |
| 4491 | case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ |
Len Brown | e8efbc8 | 2016-04-06 17:15:57 -0400 | [diff] [blame] | 4492 | crystal_hz = 24000000; /* 24.0 MHz */ |
| 4493 | break; |
Len Brown | 7268d40 | 2016-12-01 23:10:39 -0500 | [diff] [blame] | 4494 | case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ |
Len Brown | ec53e59 | 2016-04-06 17:15:58 -0400 | [diff] [blame] | 4495 | crystal_hz = 25000000; /* 25.0 MHz */ |
| 4496 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4497 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Len Brown | ac01ac1 | 2017-01-27 01:45:35 -0500 | [diff] [blame] | 4498 | case INTEL_FAM6_ATOM_GEMINI_LAKE: |
Len Brown | e8efbc8 | 2016-04-06 17:15:57 -0400 | [diff] [blame] | 4499 | crystal_hz = 19200000; /* 19.2 MHz */ |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4500 | break; |
| 4501 | default: |
| 4502 | crystal_hz = 0; |
| 4503 | } |
| 4504 | |
| 4505 | if (crystal_hz) { |
| 4506 | tsc_hz = (unsigned long long) crystal_hz * ebx_tsc / eax_crystal; |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4507 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4508 | fprintf(outf, "TSC: %lld MHz (%d Hz * %d / %d / 1000000)\n", |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4509 | tsc_hz / 1000000, crystal_hz, ebx_tsc, eax_crystal); |
| 4510 | } |
| 4511 | } |
| 4512 | } |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 4513 | if (max_level >= 0x16) { |
| 4514 | unsigned int base_mhz, max_mhz, bus_mhz, edx; |
| 4515 | |
| 4516 | /* |
| 4517 | * CPUID 16H Base MHz, Max MHz, Bus MHz |
| 4518 | */ |
| 4519 | base_mhz = max_mhz = bus_mhz = edx = 0; |
| 4520 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4521 | __cpuid(0x16, base_mhz, max_mhz, bus_mhz, edx); |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4522 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4523 | 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] | 4524 | base_mhz, max_mhz, bus_mhz); |
| 4525 | } |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4526 | |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 4527 | if (has_aperf) |
| 4528 | aperf_mperf_multiplier = get_aperf_mperf_multiplier(family, model); |
| 4529 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4530 | BIC_PRESENT(BIC_IRQ); |
| 4531 | BIC_PRESENT(BIC_TSC_MHz); |
| 4532 | |
| 4533 | if (probe_nhm_msrs(family, model)) { |
| 4534 | do_nhm_platform_info = 1; |
| 4535 | BIC_PRESENT(BIC_CPU_c1); |
| 4536 | BIC_PRESENT(BIC_CPU_c3); |
| 4537 | BIC_PRESENT(BIC_CPU_c6); |
| 4538 | BIC_PRESENT(BIC_SMI); |
| 4539 | } |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4540 | do_snb_cstates = has_snb_msrs(family, model); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4541 | |
| 4542 | if (do_snb_cstates) |
| 4543 | BIC_PRESENT(BIC_CPU_c7); |
| 4544 | |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 4545 | do_irtl_snb = has_snb_msrs(family, model); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4546 | if (do_snb_cstates && (pkg_cstate_limit >= PCL__2)) |
| 4547 | BIC_PRESENT(BIC_Pkgpc2); |
| 4548 | if (pkg_cstate_limit >= PCL__3) |
| 4549 | BIC_PRESENT(BIC_Pkgpc3); |
| 4550 | if (pkg_cstate_limit >= PCL__6) |
| 4551 | BIC_PRESENT(BIC_Pkgpc6); |
| 4552 | if (do_snb_cstates && (pkg_cstate_limit >= PCL__7)) |
| 4553 | BIC_PRESENT(BIC_Pkgpc7); |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 4554 | if (has_slv_msrs(family, model)) { |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4555 | BIC_NOT_PRESENT(BIC_Pkgpc2); |
| 4556 | BIC_NOT_PRESENT(BIC_Pkgpc3); |
| 4557 | BIC_PRESENT(BIC_Pkgpc6); |
| 4558 | BIC_NOT_PRESENT(BIC_Pkgpc7); |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 4559 | BIC_PRESENT(BIC_Mod_c6); |
| 4560 | use_c1_residency_msr = 1; |
| 4561 | } |
Len Brown | 7170a37 | 2017-01-27 02:13:27 -0500 | [diff] [blame] | 4562 | if (is_dnv(family, model)) { |
| 4563 | BIC_PRESENT(BIC_CPU_c1); |
| 4564 | BIC_NOT_PRESENT(BIC_CPU_c3); |
| 4565 | BIC_NOT_PRESENT(BIC_Pkgpc3); |
| 4566 | BIC_NOT_PRESENT(BIC_CPU_c7); |
| 4567 | BIC_NOT_PRESENT(BIC_Pkgpc7); |
| 4568 | use_c1_residency_msr = 1; |
| 4569 | } |
Len Brown | 34c76197 | 2017-01-27 02:36:41 -0500 | [diff] [blame] | 4570 | if (is_skx(family, model)) { |
| 4571 | BIC_NOT_PRESENT(BIC_CPU_c3); |
| 4572 | BIC_NOT_PRESENT(BIC_Pkgpc3); |
| 4573 | BIC_NOT_PRESENT(BIC_CPU_c7); |
| 4574 | BIC_NOT_PRESENT(BIC_Pkgpc7); |
| 4575 | } |
Len Brown | ade0eba | 2017-02-10 01:56:47 -0500 | [diff] [blame] | 4576 | if (is_bdx(family, model)) { |
| 4577 | BIC_NOT_PRESENT(BIC_CPU_c7); |
| 4578 | BIC_NOT_PRESENT(BIC_Pkgpc7); |
| 4579 | } |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4580 | if (has_hsw_msrs(family, model)) { |
| 4581 | BIC_PRESENT(BIC_Pkgpc8); |
| 4582 | BIC_PRESENT(BIC_Pkgpc9); |
| 4583 | BIC_PRESENT(BIC_Pkgpc10); |
| 4584 | } |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 4585 | do_irtl_hsw = has_hsw_msrs(family, model); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 4586 | if (has_skl_msrs(family, model)) { |
| 4587 | BIC_PRESENT(BIC_Totl_c0); |
| 4588 | BIC_PRESENT(BIC_Any_c0); |
| 4589 | BIC_PRESENT(BIC_GFX_c0); |
| 4590 | BIC_PRESENT(BIC_CPUGFX); |
| 4591 | } |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4592 | do_slm_cstates = is_slm(family, model); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 4593 | do_knl_cstates = is_knl(family, model); |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame] | 4594 | do_cnl_cstates = is_cnl(family, model); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4595 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4596 | if (!quiet) |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 4597 | decode_misc_pwr_mgmt_msr(); |
| 4598 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4599 | if (!quiet && has_slv_msrs(family, model)) |
Len Brown | 71616c8 | 2017-01-07 22:37:48 -0500 | [diff] [blame] | 4600 | decode_c6_demotion_policy_msr(); |
| 4601 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4602 | rapl_probe(family, model); |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 4603 | perf_limit_reasons_probe(family, model); |
Artem Bityutskiy | ac980e1 | 2017-09-05 15:14:08 +0300 | [diff] [blame] | 4604 | automatic_cstate_conversion_probe(family, model); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4605 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4606 | if (!quiet) |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 4607 | dump_cstate_pstate_config_info(family, model); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 4608 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4609 | if (!quiet) |
| 4610 | dump_sysfs_cstate_config(); |
Len Brown | 7293fcc | 2017-02-22 00:11:12 -0500 | [diff] [blame] | 4611 | if (!quiet) |
| 4612 | dump_sysfs_pstate_config(); |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4613 | |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 4614 | if (has_skl_msrs(family, model)) |
| 4615 | calculate_tsc_tweak(); |
| 4616 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4617 | if (!access("/sys/class/drm/card0/power/rc6_residency_ms", R_OK)) |
| 4618 | BIC_PRESENT(BIC_GFX_rc6); |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 4619 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4620 | if (!access("/sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz", R_OK)) |
| 4621 | BIC_PRESENT(BIC_GFXMHz); |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 4622 | |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 4623 | if (!access("/sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us", R_OK)) |
| 4624 | BIC_PRESENT(BIC_CPU_LPI); |
| 4625 | else |
| 4626 | BIC_NOT_PRESENT(BIC_CPU_LPI); |
| 4627 | |
| 4628 | if (!access("/sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us", R_OK)) |
| 4629 | BIC_PRESENT(BIC_SYS_LPI); |
| 4630 | else |
| 4631 | BIC_NOT_PRESENT(BIC_SYS_LPI); |
| 4632 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4633 | if (!quiet) |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 4634 | decode_misc_feature_control(); |
| 4635 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4636 | return; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4637 | } |
| 4638 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4639 | |
| 4640 | /* |
| 4641 | * in /dev/cpu/ return success for names that are numbers |
| 4642 | * ie. filter out ".", "..", "microcode". |
| 4643 | */ |
| 4644 | int dir_filter(const struct dirent *dirp) |
| 4645 | { |
| 4646 | if (isdigit(dirp->d_name[0])) |
| 4647 | return 1; |
| 4648 | else |
| 4649 | return 0; |
| 4650 | } |
| 4651 | |
| 4652 | int open_dev_cpu_msr(int dummy1) |
| 4653 | { |
| 4654 | return 0; |
| 4655 | } |
| 4656 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4657 | void topology_probe() |
| 4658 | { |
| 4659 | int i; |
| 4660 | int max_core_id = 0; |
| 4661 | int max_package_id = 0; |
| 4662 | int max_siblings = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4663 | |
| 4664 | /* Initialize num_cpus, max_cpu_num */ |
Prarit Bhargava | 843c579 | 2018-06-01 10:04:28 -0400 | [diff] [blame] | 4665 | set_max_cpu_num(); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4666 | topo.num_cpus = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4667 | for_all_proc_cpus(count_cpus); |
| 4668 | if (!summary_only && topo.num_cpus > 1) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4669 | BIC_PRESENT(BIC_CPU); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4670 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4671 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4672 | 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] | 4673 | |
| 4674 | cpus = calloc(1, (topo.max_cpu_num + 1) * sizeof(struct cpu_topology)); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4675 | if (cpus == NULL) |
| 4676 | err(1, "calloc cpus"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4677 | |
| 4678 | /* |
| 4679 | * Allocate and initialize cpu_present_set |
| 4680 | */ |
| 4681 | cpu_present_set = CPU_ALLOC((topo.max_cpu_num + 1)); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4682 | if (cpu_present_set == NULL) |
| 4683 | err(3, "CPU_ALLOC"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4684 | cpu_present_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); |
| 4685 | CPU_ZERO_S(cpu_present_setsize, cpu_present_set); |
| 4686 | for_all_proc_cpus(mark_cpu_present); |
| 4687 | |
| 4688 | /* |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 4689 | * Validate that all cpus in cpu_subset are also in cpu_present_set |
| 4690 | */ |
| 4691 | for (i = 0; i < CPU_SUBSET_MAXCPUS; ++i) { |
| 4692 | if (CPU_ISSET_S(i, cpu_subset_size, cpu_subset)) |
| 4693 | if (!CPU_ISSET_S(i, cpu_present_setsize, cpu_present_set)) |
| 4694 | err(1, "cpu%d not present", i); |
| 4695 | } |
| 4696 | |
| 4697 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4698 | * Allocate and initialize cpu_affinity_set |
| 4699 | */ |
| 4700 | cpu_affinity_set = CPU_ALLOC((topo.max_cpu_num + 1)); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4701 | if (cpu_affinity_set == NULL) |
| 4702 | err(3, "CPU_ALLOC"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4703 | cpu_affinity_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); |
| 4704 | CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); |
| 4705 | |
| 4706 | |
| 4707 | /* |
| 4708 | * For online cpus |
| 4709 | * find max_core_id, max_package_id |
| 4710 | */ |
| 4711 | for (i = 0; i <= topo.max_cpu_num; ++i) { |
| 4712 | int siblings; |
| 4713 | |
| 4714 | if (cpu_is_not_present(i)) { |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4715 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4716 | fprintf(outf, "cpu%d NOT PRESENT\n", i); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4717 | continue; |
| 4718 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4719 | |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 4720 | cpus[i].logical_cpu_id = i; |
| 4721 | |
| 4722 | /* get package information */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4723 | cpus[i].physical_package_id = get_physical_package_id(i); |
| 4724 | if (cpus[i].physical_package_id > max_package_id) |
| 4725 | max_package_id = cpus[i].physical_package_id; |
| 4726 | |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 4727 | /* get numa node information */ |
Prarit Bhargava | ef60574 | 2018-06-01 10:04:30 -0400 | [diff] [blame^] | 4728 | cpus[i].physical_node_id = get_physical_node_id(&cpus[i]); |
| 4729 | if (cpus[i].physical_node_id > topo.max_node_num) |
| 4730 | topo.max_node_num = cpus[i].physical_node_id; |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 4731 | |
| 4732 | /* get core information */ |
| 4733 | cpus[i].physical_core_id = get_core_id(i); |
| 4734 | if (cpus[i].physical_core_id > max_core_id) |
| 4735 | max_core_id = cpus[i].physical_core_id; |
| 4736 | |
| 4737 | /* get thread information */ |
| 4738 | siblings = get_thread_siblings(&cpus[i]); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4739 | if (siblings > max_siblings) |
| 4740 | max_siblings = siblings; |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 4741 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4742 | if (debug > 1) |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 4743 | fprintf(outf, "cpu %d pkg %d node %d core %d\n", |
| 4744 | i, cpus[i].physical_package_id, |
Prarit Bhargava | ef60574 | 2018-06-01 10:04:30 -0400 | [diff] [blame^] | 4745 | cpus[i].physical_node_id, |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 4746 | cpus[i].physical_core_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4747 | } |
Prarit Bhargava | ef60574 | 2018-06-01 10:04:30 -0400 | [diff] [blame^] | 4748 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4749 | topo.num_cores_per_pkg = max_core_id + 1; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4750 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4751 | 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] | 4752 | max_core_id, topo.num_cores_per_pkg); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4753 | if (!summary_only && topo.num_cores_per_pkg > 1) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4754 | BIC_PRESENT(BIC_Core); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4755 | |
| 4756 | topo.num_packages = max_package_id + 1; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4757 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4758 | fprintf(outf, "max_package_id %d, sizing for %d packages\n", |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4759 | max_package_id, topo.num_packages); |
Len Brown | 7da6e3e | 2017-02-21 23:43:41 -0500 | [diff] [blame] | 4760 | if (!summary_only && topo.num_packages > 1) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4761 | BIC_PRESENT(BIC_Package); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4762 | |
Prarit Bhargava | ef60574 | 2018-06-01 10:04:30 -0400 | [diff] [blame^] | 4763 | set_node_data(); |
| 4764 | if (debug > 1) |
| 4765 | fprintf(outf, "num_nodes_per_pkg %d\n", topo.num_nodes_per_pkg); |
| 4766 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4767 | topo.num_threads_per_core = max_siblings; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4768 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4769 | fprintf(outf, "max_siblings %d\n", max_siblings); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4770 | } |
| 4771 | |
| 4772 | void |
| 4773 | allocate_counters(struct thread_data **t, struct core_data **c, struct pkg_data **p) |
| 4774 | { |
| 4775 | int i; |
| 4776 | |
| 4777 | *t = calloc(topo.num_threads_per_core * topo.num_cores_per_pkg * |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4778 | topo.num_packages, sizeof(struct thread_data)); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4779 | if (*t == NULL) |
| 4780 | goto error; |
| 4781 | |
| 4782 | for (i = 0; i < topo.num_threads_per_core * |
| 4783 | topo.num_cores_per_pkg * topo.num_packages; i++) |
| 4784 | (*t)[i].cpu_id = -1; |
| 4785 | |
| 4786 | *c = calloc(topo.num_cores_per_pkg * topo.num_packages, |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4787 | sizeof(struct core_data)); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4788 | if (*c == NULL) |
| 4789 | goto error; |
| 4790 | |
| 4791 | for (i = 0; i < topo.num_cores_per_pkg * topo.num_packages; i++) |
| 4792 | (*c)[i].core_id = -1; |
| 4793 | |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 4794 | *p = calloc(topo.num_packages, sizeof(struct pkg_data)); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4795 | if (*p == NULL) |
| 4796 | goto error; |
| 4797 | |
| 4798 | for (i = 0; i < topo.num_packages; i++) |
| 4799 | (*p)[i].package_id = i; |
| 4800 | |
| 4801 | return; |
| 4802 | error: |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4803 | err(1, "calloc counters"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4804 | } |
| 4805 | /* |
| 4806 | * init_counter() |
| 4807 | * |
| 4808 | * set cpu_id, core_num, pkg_num |
| 4809 | * set FIRST_THREAD_IN_CORE and FIRST_CORE_IN_PACKAGE |
| 4810 | * |
| 4811 | * increment topo.num_cores when 1st core in pkg seen |
| 4812 | */ |
| 4813 | void init_counter(struct thread_data *thread_base, struct core_data *core_base, |
| 4814 | struct pkg_data *pkg_base, int thread_num, int core_num, |
| 4815 | int pkg_num, int cpu_id) |
| 4816 | { |
| 4817 | struct thread_data *t; |
| 4818 | struct core_data *c; |
| 4819 | struct pkg_data *p; |
| 4820 | |
| 4821 | t = GET_THREAD(thread_base, thread_num, core_num, pkg_num); |
| 4822 | c = GET_CORE(core_base, core_num, pkg_num); |
| 4823 | p = GET_PKG(pkg_base, pkg_num); |
| 4824 | |
| 4825 | t->cpu_id = cpu_id; |
| 4826 | if (thread_num == 0) { |
| 4827 | t->flags |= CPU_IS_FIRST_THREAD_IN_CORE; |
| 4828 | if (cpu_is_first_core_in_package(cpu_id)) |
| 4829 | t->flags |= CPU_IS_FIRST_CORE_IN_PACKAGE; |
| 4830 | } |
| 4831 | |
| 4832 | c->core_id = core_num; |
| 4833 | p->package_id = pkg_num; |
| 4834 | } |
| 4835 | |
| 4836 | |
| 4837 | int initialize_counters(int cpu_id) |
| 4838 | { |
| 4839 | int my_thread_id, my_core_id, my_package_id; |
| 4840 | |
| 4841 | my_package_id = get_physical_package_id(cpu_id); |
| 4842 | my_core_id = get_core_id(cpu_id); |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 4843 | my_thread_id = get_cpu_position_in_core(cpu_id); |
| 4844 | if (!my_thread_id) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4845 | topo.num_cores++; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4846 | |
| 4847 | init_counter(EVEN_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id); |
| 4848 | init_counter(ODD_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id); |
| 4849 | return 0; |
| 4850 | } |
| 4851 | |
| 4852 | void allocate_output_buffer() |
| 4853 | { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4854 | output_buffer = calloc(1, (1 + topo.num_cpus) * 1024); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4855 | outp = output_buffer; |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4856 | if (outp == NULL) |
| 4857 | err(-1, "calloc output buffer"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4858 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 4859 | void allocate_fd_percpu(void) |
| 4860 | { |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 4861 | fd_percpu = calloc(topo.max_cpu_num + 1, sizeof(int)); |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 4862 | if (fd_percpu == NULL) |
| 4863 | err(-1, "calloc fd_percpu"); |
| 4864 | } |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 4865 | void allocate_irq_buffers(void) |
| 4866 | { |
| 4867 | irq_column_2_cpu = calloc(topo.num_cpus, sizeof(int)); |
| 4868 | if (irq_column_2_cpu == NULL) |
| 4869 | err(-1, "calloc %d", topo.num_cpus); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4870 | |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 4871 | irqs_per_cpu = calloc(topo.max_cpu_num + 1, sizeof(int)); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 4872 | if (irqs_per_cpu == NULL) |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 4873 | err(-1, "calloc %d", topo.max_cpu_num + 1); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 4874 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4875 | void setup_all_buffers(void) |
| 4876 | { |
| 4877 | topology_probe(); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 4878 | allocate_irq_buffers(); |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 4879 | allocate_fd_percpu(); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4880 | allocate_counters(&thread_even, &core_even, &package_even); |
| 4881 | allocate_counters(&thread_odd, &core_odd, &package_odd); |
| 4882 | allocate_output_buffer(); |
| 4883 | for_all_proc_cpus(initialize_counters); |
| 4884 | } |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4885 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 4886 | void set_base_cpu(void) |
| 4887 | { |
| 4888 | base_cpu = sched_getcpu(); |
| 4889 | if (base_cpu < 0) |
| 4890 | err(-ENODEV, "No valid cpus found"); |
| 4891 | |
| 4892 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4893 | fprintf(outf, "base_cpu = %d\n", base_cpu); |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 4894 | } |
| 4895 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4896 | void turbostat_init() |
| 4897 | { |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 4898 | setup_all_buffers(); |
| 4899 | set_base_cpu(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4900 | check_dev_msr(); |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 4901 | check_permissions(); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 4902 | process_cpuid(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4903 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4904 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4905 | if (!quiet) |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4906 | for_all_cpus(print_hwp, ODD_COUNTERS); |
| 4907 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4908 | if (!quiet) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4909 | for_all_cpus(print_epb, ODD_COUNTERS); |
| 4910 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4911 | if (!quiet) |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 4912 | for_all_cpus(print_perf_limit, ODD_COUNTERS); |
| 4913 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4914 | if (!quiet) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4915 | for_all_cpus(print_rapl, ODD_COUNTERS); |
| 4916 | |
| 4917 | for_all_cpus(set_temperature_target, ODD_COUNTERS); |
| 4918 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4919 | if (!quiet) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4920 | for_all_cpus(print_thermal, ODD_COUNTERS); |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 4921 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4922 | if (!quiet && do_irtl_snb) |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 4923 | print_irtl(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4924 | } |
| 4925 | |
| 4926 | int fork_it(char **argv) |
| 4927 | { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4928 | pid_t child_pid; |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 4929 | int status; |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 4930 | |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 4931 | snapshot_proc_sysfs_files(); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 4932 | status = for_all_cpus(get_counters, EVEN_COUNTERS); |
| 4933 | if (status) |
| 4934 | exit(status); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4935 | /* clear affinity side-effect of get_counters() */ |
| 4936 | sched_setaffinity(0, cpu_present_setsize, cpu_present_set); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4937 | gettimeofday(&tv_even, (struct timezone *)NULL); |
| 4938 | |
| 4939 | child_pid = fork(); |
| 4940 | if (!child_pid) { |
| 4941 | /* child */ |
| 4942 | execvp(argv[0], argv); |
Len Brown | 0815a3d | 2017-02-23 17:00:51 -0500 | [diff] [blame] | 4943 | err(errno, "exec %s", argv[0]); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4944 | } else { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4945 | |
| 4946 | /* parent */ |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4947 | if (child_pid == -1) |
| 4948 | err(1, "fork"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4949 | |
| 4950 | signal(SIGINT, SIG_IGN); |
| 4951 | signal(SIGQUIT, SIG_IGN); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4952 | if (waitpid(child_pid, &status, 0) == -1) |
| 4953 | err(status, "waitpid"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4954 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4955 | /* |
| 4956 | * n.b. fork_it() does not check for errors from for_all_cpus() |
| 4957 | * because re-starting is problematic when forking |
| 4958 | */ |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 4959 | snapshot_proc_sysfs_files(); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4960 | for_all_cpus(get_counters, ODD_COUNTERS); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4961 | gettimeofday(&tv_odd, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4962 | timersub(&tv_odd, &tv_even, &tv_delta); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 4963 | if (for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS)) |
| 4964 | fprintf(outf, "%s: Counter reset detected\n", progname); |
| 4965 | else { |
| 4966 | compute_average(EVEN_COUNTERS); |
| 4967 | format_all_counters(EVEN_COUNTERS); |
| 4968 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4969 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4970 | fprintf(outf, "%.6f sec\n", tv_delta.tv_sec + tv_delta.tv_usec/1000000.0); |
| 4971 | |
| 4972 | flush_output_stderr(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4973 | |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 4974 | return status; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4975 | } |
| 4976 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4977 | int get_and_dump_counters(void) |
| 4978 | { |
| 4979 | int status; |
| 4980 | |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 4981 | snapshot_proc_sysfs_files(); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4982 | status = for_all_cpus(get_counters, ODD_COUNTERS); |
| 4983 | if (status) |
| 4984 | return status; |
| 4985 | |
| 4986 | status = for_all_cpus(dump_counters, ODD_COUNTERS); |
| 4987 | if (status) |
| 4988 | return status; |
| 4989 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4990 | flush_output_stdout(); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 4991 | |
| 4992 | return status; |
| 4993 | } |
| 4994 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4995 | void print_version() { |
Len Brown | f7d44a8 | 2017-05-27 21:24:58 -0700 | [diff] [blame] | 4996 | fprintf(outf, "turbostat version 17.06.23" |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4997 | " - Len Brown <lenb@kernel.org>\n"); |
| 4998 | } |
| 4999 | |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 5000 | int add_counter(unsigned int msr_num, char *path, char *name, |
| 5001 | unsigned int width, enum counter_scope scope, |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5002 | enum counter_type type, enum counter_format format, int flags) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5003 | { |
| 5004 | struct msr_counter *msrp; |
| 5005 | |
| 5006 | msrp = calloc(1, sizeof(struct msr_counter)); |
| 5007 | if (msrp == NULL) { |
| 5008 | perror("calloc"); |
| 5009 | exit(1); |
| 5010 | } |
| 5011 | |
| 5012 | msrp->msr_num = msr_num; |
| 5013 | strncpy(msrp->name, name, NAME_BYTES); |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 5014 | if (path) |
| 5015 | strncpy(msrp->path, path, PATH_BYTES); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5016 | msrp->width = width; |
| 5017 | msrp->type = type; |
| 5018 | msrp->format = format; |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5019 | msrp->flags = flags; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5020 | |
| 5021 | switch (scope) { |
| 5022 | |
| 5023 | case SCOPE_CPU: |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5024 | msrp->next = sys.tp; |
| 5025 | sys.tp = msrp; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 5026 | sys.added_thread_counters++; |
Len Brown | 0748eaf | 2018-06-01 12:38:29 -0400 | [diff] [blame] | 5027 | if (sys.added_thread_counters > MAX_ADDED_THREAD_COUNTERS) { |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 5028 | fprintf(stderr, "exceeded max %d added thread counters\n", |
| 5029 | MAX_ADDED_COUNTERS); |
| 5030 | exit(-1); |
| 5031 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5032 | break; |
| 5033 | |
| 5034 | case SCOPE_CORE: |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5035 | msrp->next = sys.cp; |
| 5036 | sys.cp = msrp; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 5037 | sys.added_core_counters++; |
| 5038 | if (sys.added_core_counters > MAX_ADDED_COUNTERS) { |
| 5039 | fprintf(stderr, "exceeded max %d added core counters\n", |
| 5040 | MAX_ADDED_COUNTERS); |
| 5041 | exit(-1); |
| 5042 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5043 | break; |
| 5044 | |
| 5045 | case SCOPE_PACKAGE: |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5046 | msrp->next = sys.pp; |
| 5047 | sys.pp = msrp; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 5048 | sys.added_package_counters++; |
| 5049 | if (sys.added_package_counters > MAX_ADDED_COUNTERS) { |
| 5050 | fprintf(stderr, "exceeded max %d added package counters\n", |
| 5051 | MAX_ADDED_COUNTERS); |
| 5052 | exit(-1); |
| 5053 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5054 | break; |
| 5055 | } |
| 5056 | |
| 5057 | return 0; |
| 5058 | } |
| 5059 | |
| 5060 | void parse_add_command(char *add_command) |
| 5061 | { |
| 5062 | int msr_num = 0; |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 5063 | char *path = NULL; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 5064 | char name_buffer[NAME_BYTES] = ""; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5065 | int width = 64; |
| 5066 | int fail = 0; |
| 5067 | enum counter_scope scope = SCOPE_CPU; |
| 5068 | enum counter_type type = COUNTER_CYCLES; |
| 5069 | enum counter_format format = FORMAT_DELTA; |
| 5070 | |
| 5071 | while (add_command) { |
| 5072 | |
| 5073 | if (sscanf(add_command, "msr0x%x", &msr_num) == 1) |
| 5074 | goto next; |
| 5075 | |
| 5076 | if (sscanf(add_command, "msr%d", &msr_num) == 1) |
| 5077 | goto next; |
| 5078 | |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 5079 | if (*add_command == '/') { |
| 5080 | path = add_command; |
| 5081 | goto next; |
| 5082 | } |
| 5083 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5084 | if (sscanf(add_command, "u%d", &width) == 1) { |
| 5085 | if ((width == 32) || (width == 64)) |
| 5086 | goto next; |
| 5087 | width = 64; |
| 5088 | } |
| 5089 | if (!strncmp(add_command, "cpu", strlen("cpu"))) { |
| 5090 | scope = SCOPE_CPU; |
| 5091 | goto next; |
| 5092 | } |
| 5093 | if (!strncmp(add_command, "core", strlen("core"))) { |
| 5094 | scope = SCOPE_CORE; |
| 5095 | goto next; |
| 5096 | } |
| 5097 | if (!strncmp(add_command, "package", strlen("package"))) { |
| 5098 | scope = SCOPE_PACKAGE; |
| 5099 | goto next; |
| 5100 | } |
| 5101 | if (!strncmp(add_command, "cycles", strlen("cycles"))) { |
| 5102 | type = COUNTER_CYCLES; |
| 5103 | goto next; |
| 5104 | } |
| 5105 | if (!strncmp(add_command, "seconds", strlen("seconds"))) { |
| 5106 | type = COUNTER_SECONDS; |
| 5107 | goto next; |
| 5108 | } |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5109 | if (!strncmp(add_command, "usec", strlen("usec"))) { |
| 5110 | type = COUNTER_USEC; |
| 5111 | goto next; |
| 5112 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5113 | if (!strncmp(add_command, "raw", strlen("raw"))) { |
| 5114 | format = FORMAT_RAW; |
| 5115 | goto next; |
| 5116 | } |
| 5117 | if (!strncmp(add_command, "delta", strlen("delta"))) { |
| 5118 | format = FORMAT_DELTA; |
| 5119 | goto next; |
| 5120 | } |
| 5121 | if (!strncmp(add_command, "percent", strlen("percent"))) { |
| 5122 | format = FORMAT_PERCENT; |
| 5123 | goto next; |
| 5124 | } |
| 5125 | |
| 5126 | if (sscanf(add_command, "%18s,%*s", name_buffer) == 1) { /* 18 < NAME_BYTES */ |
| 5127 | char *eos; |
| 5128 | |
| 5129 | eos = strchr(name_buffer, ','); |
| 5130 | if (eos) |
| 5131 | *eos = '\0'; |
| 5132 | goto next; |
| 5133 | } |
| 5134 | |
| 5135 | next: |
| 5136 | add_command = strchr(add_command, ','); |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 5137 | if (add_command) { |
| 5138 | *add_command = '\0'; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5139 | add_command++; |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 5140 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5141 | |
| 5142 | } |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 5143 | if ((msr_num == 0) && (path == NULL)) { |
| 5144 | fprintf(stderr, "--add: (msrDDD | msr0xXXX | /path_to_counter ) required\n"); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5145 | fail++; |
| 5146 | } |
| 5147 | |
| 5148 | /* generate default column header */ |
| 5149 | if (*name_buffer == '\0') { |
Len Brown | 5f3aea5 | 2017-02-23 18:10:27 -0500 | [diff] [blame] | 5150 | if (width == 32) |
| 5151 | sprintf(name_buffer, "M0x%x%s", msr_num, format == FORMAT_PERCENT ? "%" : ""); |
| 5152 | else |
| 5153 | sprintf(name_buffer, "M0X%x%s", msr_num, format == FORMAT_PERCENT ? "%" : ""); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5154 | } |
| 5155 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5156 | 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] | 5157 | fail++; |
| 5158 | |
| 5159 | if (fail) { |
| 5160 | help(); |
| 5161 | exit(1); |
| 5162 | } |
| 5163 | } |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5164 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 5165 | int is_deferred_skip(char *name) |
| 5166 | { |
| 5167 | int i; |
| 5168 | |
| 5169 | for (i = 0; i < deferred_skip_index; ++i) |
| 5170 | if (!strcmp(name, deferred_skip_names[i])) |
| 5171 | return 1; |
| 5172 | return 0; |
| 5173 | } |
| 5174 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5175 | void probe_sysfs(void) |
| 5176 | { |
| 5177 | char path[64]; |
| 5178 | char name_buf[16]; |
| 5179 | FILE *input; |
| 5180 | int state; |
| 5181 | char *sp; |
| 5182 | |
| 5183 | if (!DO_BIC(BIC_sysfs)) |
| 5184 | return; |
| 5185 | |
Len Brown | 0748eaf | 2018-06-01 12:38:29 -0400 | [diff] [blame] | 5186 | for (state = 10; state >= 0; --state) { |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5187 | |
| 5188 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", |
| 5189 | base_cpu, state); |
| 5190 | input = fopen(path, "r"); |
| 5191 | if (input == NULL) |
| 5192 | continue; |
| 5193 | fgets(name_buf, sizeof(name_buf), input); |
| 5194 | |
| 5195 | /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ |
| 5196 | sp = strchr(name_buf, '-'); |
| 5197 | if (!sp) |
| 5198 | sp = strchrnul(name_buf, '\n'); |
| 5199 | *sp = '%'; |
| 5200 | *(sp + 1) = '\0'; |
| 5201 | |
| 5202 | fclose(input); |
| 5203 | |
| 5204 | sprintf(path, "cpuidle/state%d/time", state); |
| 5205 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 5206 | if (is_deferred_skip(name_buf)) |
| 5207 | continue; |
| 5208 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5209 | add_counter(0, path, name_buf, 64, SCOPE_CPU, COUNTER_USEC, |
| 5210 | FORMAT_PERCENT, SYSFS_PERCPU); |
| 5211 | } |
| 5212 | |
Len Brown | 0748eaf | 2018-06-01 12:38:29 -0400 | [diff] [blame] | 5213 | for (state = 10; state >= 0; --state) { |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5214 | |
| 5215 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", |
| 5216 | base_cpu, state); |
| 5217 | input = fopen(path, "r"); |
| 5218 | if (input == NULL) |
| 5219 | continue; |
| 5220 | fgets(name_buf, sizeof(name_buf), input); |
| 5221 | /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ |
| 5222 | sp = strchr(name_buf, '-'); |
| 5223 | if (!sp) |
| 5224 | sp = strchrnul(name_buf, '\n'); |
| 5225 | *sp = '\0'; |
| 5226 | fclose(input); |
| 5227 | |
| 5228 | sprintf(path, "cpuidle/state%d/usage", state); |
| 5229 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 5230 | if (is_deferred_skip(name_buf)) |
| 5231 | continue; |
| 5232 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5233 | add_counter(0, path, name_buf, 64, SCOPE_CPU, COUNTER_ITEMS, |
| 5234 | FORMAT_DELTA, SYSFS_PERCPU); |
| 5235 | } |
| 5236 | |
| 5237 | } |
| 5238 | |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 5239 | |
| 5240 | /* |
| 5241 | * parse cpuset with following syntax |
| 5242 | * 1,2,4..6,8-10 and set bits in cpu_subset |
| 5243 | */ |
| 5244 | void parse_cpu_command(char *optarg) |
| 5245 | { |
| 5246 | unsigned int start, end; |
| 5247 | char *next; |
| 5248 | |
Len Brown | 4e4e1e7 | 2017-02-21 22:33:42 -0500 | [diff] [blame] | 5249 | if (!strcmp(optarg, "core")) { |
| 5250 | if (cpu_subset) |
| 5251 | goto error; |
| 5252 | show_core_only++; |
| 5253 | return; |
| 5254 | } |
| 5255 | if (!strcmp(optarg, "package")) { |
| 5256 | if (cpu_subset) |
| 5257 | goto error; |
| 5258 | show_pkg_only++; |
| 5259 | return; |
| 5260 | } |
| 5261 | if (show_core_only || show_pkg_only) |
| 5262 | goto error; |
| 5263 | |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 5264 | cpu_subset = CPU_ALLOC(CPU_SUBSET_MAXCPUS); |
| 5265 | if (cpu_subset == NULL) |
| 5266 | err(3, "CPU_ALLOC"); |
| 5267 | cpu_subset_size = CPU_ALLOC_SIZE(CPU_SUBSET_MAXCPUS); |
| 5268 | |
| 5269 | CPU_ZERO_S(cpu_subset_size, cpu_subset); |
| 5270 | |
| 5271 | next = optarg; |
| 5272 | |
| 5273 | while (next && *next) { |
| 5274 | |
| 5275 | if (*next == '-') /* no negative cpu numbers */ |
| 5276 | goto error; |
| 5277 | |
| 5278 | start = strtoul(next, &next, 10); |
| 5279 | |
| 5280 | if (start >= CPU_SUBSET_MAXCPUS) |
| 5281 | goto error; |
| 5282 | CPU_SET_S(start, cpu_subset_size, cpu_subset); |
| 5283 | |
| 5284 | if (*next == '\0') |
| 5285 | break; |
| 5286 | |
| 5287 | if (*next == ',') { |
| 5288 | next += 1; |
| 5289 | continue; |
| 5290 | } |
| 5291 | |
| 5292 | if (*next == '-') { |
| 5293 | next += 1; /* start range */ |
| 5294 | } else if (*next == '.') { |
| 5295 | next += 1; |
| 5296 | if (*next == '.') |
| 5297 | next += 1; /* start range */ |
| 5298 | else |
| 5299 | goto error; |
| 5300 | } |
| 5301 | |
| 5302 | end = strtoul(next, &next, 10); |
| 5303 | if (end <= start) |
| 5304 | goto error; |
| 5305 | |
| 5306 | while (++start <= end) { |
| 5307 | if (start >= CPU_SUBSET_MAXCPUS) |
| 5308 | goto error; |
| 5309 | CPU_SET_S(start, cpu_subset_size, cpu_subset); |
| 5310 | } |
| 5311 | |
| 5312 | if (*next == ',') |
| 5313 | next += 1; |
| 5314 | else if (*next != '\0') |
| 5315 | goto error; |
| 5316 | } |
| 5317 | |
| 5318 | return; |
| 5319 | |
| 5320 | error: |
Len Brown | 4e4e1e7 | 2017-02-21 22:33:42 -0500 | [diff] [blame] | 5321 | fprintf(stderr, "\"--cpu %s\" malformed\n", optarg); |
| 5322 | help(); |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 5323 | exit(-1); |
| 5324 | } |
| 5325 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5326 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5327 | void cmdline(int argc, char **argv) |
| 5328 | { |
| 5329 | int opt; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5330 | int option_index = 0; |
| 5331 | static struct option long_options[] = { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5332 | {"add", required_argument, 0, 'a'}, |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 5333 | {"cpu", required_argument, 0, 'c'}, |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5334 | {"Dump", no_argument, 0, 'D'}, |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5335 | {"debug", no_argument, 0, 'd'}, /* internal, not documented */ |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5336 | {"enable", required_argument, 0, 'e'}, |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5337 | {"interval", required_argument, 0, 'i'}, |
Chen Yu | 023fe0a | 2018-04-26 08:41:03 +0800 | [diff] [blame] | 5338 | {"num_iterations", required_argument, 0, 'n'}, |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5339 | {"help", no_argument, 0, 'h'}, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5340 | {"hide", required_argument, 0, 'H'}, // meh, -h taken by --help |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5341 | {"Joules", no_argument, 0, 'J'}, |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 5342 | {"list", no_argument, 0, 'l'}, |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5343 | {"out", required_argument, 0, 'o'}, |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5344 | {"quiet", no_argument, 0, 'q'}, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5345 | {"show", required_argument, 0, 's'}, |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5346 | {"Summary", no_argument, 0, 'S'}, |
| 5347 | {"TCC", required_argument, 0, 'T'}, |
| 5348 | {"version", no_argument, 0, 'v' }, |
| 5349 | {0, 0, 0, 0 } |
| 5350 | }; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5351 | |
| 5352 | progname = argv[0]; |
| 5353 | |
Chen Yu | 023fe0a | 2018-04-26 08:41:03 +0800 | [diff] [blame] | 5354 | while ((opt = getopt_long_only(argc, argv, "+C:c:Dde:hi:Jn:o:qST:v", |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5355 | long_options, &option_index)) != -1) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5356 | switch (opt) { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5357 | case 'a': |
| 5358 | parse_add_command(optarg); |
| 5359 | break; |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 5360 | case 'c': |
| 5361 | parse_cpu_command(optarg); |
| 5362 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5363 | case 'D': |
| 5364 | dump_only++; |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 5365 | break; |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5366 | case 'e': |
| 5367 | /* --enable specified counter */ |
| 5368 | bic_enabled |= bic_lookup(optarg, SHOW_LIST); |
| 5369 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5370 | case 'd': |
| 5371 | debug++; |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5372 | ENABLE_BIC(BIC_DISABLED_BY_DEFAULT); |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 5373 | break; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5374 | case 'H': |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5375 | /* |
| 5376 | * --hide: do not show those specified |
| 5377 | * multiple invocations simply clear more bits in enabled mask |
| 5378 | */ |
| 5379 | bic_enabled &= ~bic_lookup(optarg, HIDE_LIST); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5380 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5381 | case 'h': |
| 5382 | default: |
| 5383 | help(); |
| 5384 | exit(1); |
| 5385 | case 'i': |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 5386 | { |
| 5387 | double interval = strtod(optarg, NULL); |
| 5388 | |
| 5389 | if (interval < 0.001) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5390 | fprintf(outf, "interval %f seconds is too small\n", |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 5391 | interval); |
| 5392 | exit(2); |
| 5393 | } |
| 5394 | |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 5395 | interval_tv.tv_sec = interval_ts.tv_sec = interval; |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 5396 | interval_tv.tv_usec = (interval - interval_tv.tv_sec) * 1000000; |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 5397 | interval_ts.tv_nsec = (interval - interval_ts.tv_sec) * 1000000000; |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 5398 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 5399 | break; |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 5400 | case 'J': |
| 5401 | rapl_joules++; |
| 5402 | break; |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 5403 | case 'l': |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5404 | ENABLE_BIC(BIC_DISABLED_BY_DEFAULT); |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 5405 | list_header_only++; |
| 5406 | quiet++; |
| 5407 | break; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5408 | case 'o': |
| 5409 | outf = fopen_or_die(optarg, "w"); |
| 5410 | break; |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5411 | case 'q': |
| 5412 | quiet = 1; |
| 5413 | break; |
Chen Yu | 023fe0a | 2018-04-26 08:41:03 +0800 | [diff] [blame] | 5414 | case 'n': |
| 5415 | num_iterations = strtod(optarg, NULL); |
| 5416 | |
| 5417 | if (num_iterations <= 0) { |
| 5418 | fprintf(outf, "iterations %d should be positive number\n", |
| 5419 | num_iterations); |
| 5420 | exit(2); |
| 5421 | } |
| 5422 | break; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5423 | case 's': |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5424 | /* |
| 5425 | * --show: show only those specified |
| 5426 | * The 1st invocation will clear and replace the enabled mask |
| 5427 | * subsequent invocations can add to it. |
| 5428 | */ |
| 5429 | if (shown == 0) |
| 5430 | bic_enabled = bic_lookup(optarg, SHOW_LIST); |
| 5431 | else |
| 5432 | bic_enabled |= bic_lookup(optarg, SHOW_LIST); |
| 5433 | shown = 1; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5434 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5435 | case 'S': |
| 5436 | summary_only++; |
| 5437 | break; |
| 5438 | case 'T': |
| 5439 | tcc_activation_temp_override = atoi(optarg); |
| 5440 | break; |
| 5441 | case 'v': |
| 5442 | print_version(); |
| 5443 | exit(0); |
| 5444 | break; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5445 | } |
| 5446 | } |
| 5447 | } |
| 5448 | |
| 5449 | int main(int argc, char **argv) |
| 5450 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5451 | outf = stderr; |
| 5452 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5453 | cmdline(argc, argv); |
| 5454 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5455 | if (!quiet) |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5456 | print_version(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5457 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5458 | probe_sysfs(); |
| 5459 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5460 | turbostat_init(); |
| 5461 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 5462 | /* dump counters and exit */ |
| 5463 | if (dump_only) |
| 5464 | return get_and_dump_counters(); |
| 5465 | |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 5466 | /* list header and exit */ |
| 5467 | if (list_header_only) { |
| 5468 | print_header(","); |
| 5469 | flush_output_stdout(); |
| 5470 | return 0; |
| 5471 | } |
| 5472 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5473 | /* |
| 5474 | * if any params left, it must be a command to fork |
| 5475 | */ |
| 5476 | if (argc - optind) |
| 5477 | return fork_it(argv + optind); |
| 5478 | else |
| 5479 | turbostat_loop(); |
| 5480 | |
| 5481 | return 0; |
| 5482 | } |