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 |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 24 | #include <stdarg.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 25 | #include <stdio.h> |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 26 | #include <err.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 27 | #include <unistd.h> |
| 28 | #include <sys/types.h> |
| 29 | #include <sys/wait.h> |
| 30 | #include <sys/stat.h> |
| 31 | #include <sys/resource.h> |
| 32 | #include <fcntl.h> |
| 33 | #include <signal.h> |
| 34 | #include <sys/time.h> |
| 35 | #include <stdlib.h> |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 36 | #include <getopt.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 37 | #include <dirent.h> |
| 38 | #include <string.h> |
| 39 | #include <ctype.h> |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 40 | #include <sched.h> |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 41 | #include <time.h> |
Josh Triplett | 2b92865 | 2013-08-20 17:20:14 -0700 | [diff] [blame] | 42 | #include <cpuid.h> |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 43 | #include <linux/capability.h> |
| 44 | #include <errno.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 45 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 46 | char *proc_stat = "/proc/stat"; |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 47 | struct timespec interval_ts = {5, 0}; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 48 | unsigned int debug; |
| 49 | unsigned int rapl_joules; |
| 50 | unsigned int summary_only; |
| 51 | unsigned int dump_only; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 52 | unsigned int skip_c0; |
| 53 | unsigned int skip_c1; |
| 54 | unsigned int do_nhm_cstates; |
| 55 | unsigned int do_snb_cstates; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 56 | unsigned int do_knl_cstates; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 57 | unsigned int do_pc2; |
| 58 | unsigned int do_pc3; |
| 59 | unsigned int do_pc6; |
| 60 | unsigned int do_pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 61 | unsigned int do_c8_c9_c10; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 62 | unsigned int do_skl_residency; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 63 | unsigned int do_slm_cstates; |
| 64 | unsigned int use_c1_residency_msr; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 65 | unsigned int has_aperf; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 66 | unsigned int has_epb; |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 67 | unsigned int units = 1000000; /* MHz etc */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 68 | unsigned int genuine_intel; |
| 69 | unsigned int has_invariant_tsc; |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 70 | unsigned int do_nhm_platform_info; |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 71 | unsigned int extra_msr_offset32; |
| 72 | unsigned int extra_msr_offset64; |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 73 | unsigned int extra_delta_offset32; |
| 74 | unsigned int extra_delta_offset64; |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 75 | unsigned int aperf_mperf_multiplier = 1; |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 76 | int do_smi; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 77 | double bclk; |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 78 | double base_hz; |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 79 | unsigned int has_base_hz; |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 80 | double tsc_tweak = 1.0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 81 | unsigned int show_pkg; |
| 82 | unsigned int show_core; |
| 83 | unsigned int show_cpu; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 84 | unsigned int show_pkg_only; |
| 85 | unsigned int show_core_only; |
| 86 | char *output_buffer, *outp; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 87 | unsigned int do_rapl; |
| 88 | unsigned int do_dts; |
| 89 | unsigned int do_ptm; |
| 90 | unsigned int tcc_activation_temp; |
| 91 | unsigned int tcc_activation_temp_override; |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 92 | double rapl_power_units, rapl_time_units; |
| 93 | double rapl_dram_energy_units, rapl_energy_units; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 94 | double rapl_joule_counter_range; |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 95 | unsigned int do_core_perf_limit_reasons; |
| 96 | unsigned int do_gfx_perf_limit_reasons; |
| 97 | unsigned int do_ring_perf_limit_reasons; |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 98 | unsigned int crystal_hz; |
| 99 | unsigned long long tsc_hz; |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 100 | int base_cpu; |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 101 | double discover_bclk(unsigned int family, unsigned int model); |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 102 | unsigned int has_hwp; /* IA32_PM_ENABLE, IA32_HWP_CAPABILITIES */ |
| 103 | /* IA32_HWP_REQUEST, IA32_HWP_STATUS */ |
| 104 | unsigned int has_hwp_notify; /* IA32_HWP_INTERRUPT */ |
| 105 | unsigned int has_hwp_activity_window; /* IA32_HWP_REQUEST[bits 41:32] */ |
| 106 | unsigned int has_hwp_epp; /* IA32_HWP_REQUEST[bits 31:24] */ |
| 107 | unsigned int has_hwp_pkg; /* IA32_HWP_REQUEST_PKG */ |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 108 | |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 109 | #define RAPL_PKG (1 << 0) |
| 110 | /* 0x610 MSR_PKG_POWER_LIMIT */ |
| 111 | /* 0x611 MSR_PKG_ENERGY_STATUS */ |
| 112 | #define RAPL_PKG_PERF_STATUS (1 << 1) |
| 113 | /* 0x613 MSR_PKG_PERF_STATUS */ |
| 114 | #define RAPL_PKG_POWER_INFO (1 << 2) |
| 115 | /* 0x614 MSR_PKG_POWER_INFO */ |
| 116 | |
| 117 | #define RAPL_DRAM (1 << 3) |
| 118 | /* 0x618 MSR_DRAM_POWER_LIMIT */ |
| 119 | /* 0x619 MSR_DRAM_ENERGY_STATUS */ |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 120 | #define RAPL_DRAM_PERF_STATUS (1 << 4) |
| 121 | /* 0x61b MSR_DRAM_PERF_STATUS */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 122 | #define RAPL_DRAM_POWER_INFO (1 << 5) |
| 123 | /* 0x61c MSR_DRAM_POWER_INFO */ |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 124 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 125 | #define RAPL_CORES (1 << 6) |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 126 | /* 0x638 MSR_PP0_POWER_LIMIT */ |
| 127 | /* 0x639 MSR_PP0_ENERGY_STATUS */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 128 | #define RAPL_CORE_POLICY (1 << 7) |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 129 | /* 0x63a MSR_PP0_POLICY */ |
| 130 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 131 | #define RAPL_GFX (1 << 8) |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 132 | /* 0x640 MSR_PP1_POWER_LIMIT */ |
| 133 | /* 0x641 MSR_PP1_ENERGY_STATUS */ |
| 134 | /* 0x642 MSR_PP1_POLICY */ |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 135 | #define TJMAX_DEFAULT 100 |
| 136 | |
| 137 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 138 | |
| 139 | int aperf_mperf_unstable; |
| 140 | int backwards_count; |
| 141 | char *progname; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 142 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 143 | cpu_set_t *cpu_present_set, *cpu_affinity_set; |
| 144 | size_t cpu_present_setsize, cpu_affinity_setsize; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 145 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 146 | struct thread_data { |
| 147 | unsigned long long tsc; |
| 148 | unsigned long long aperf; |
| 149 | unsigned long long mperf; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 150 | unsigned long long c1; |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 151 | unsigned long long extra_msr64; |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 152 | unsigned long long extra_delta64; |
| 153 | unsigned long long extra_msr32; |
| 154 | unsigned long long extra_delta32; |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 155 | unsigned int smi_count; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 156 | unsigned int cpu_id; |
| 157 | unsigned int flags; |
| 158 | #define CPU_IS_FIRST_THREAD_IN_CORE 0x2 |
| 159 | #define CPU_IS_FIRST_CORE_IN_PACKAGE 0x4 |
| 160 | } *thread_even, *thread_odd; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 161 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 162 | struct core_data { |
| 163 | unsigned long long c3; |
| 164 | unsigned long long c6; |
| 165 | unsigned long long c7; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 166 | unsigned int core_temp_c; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 167 | unsigned int core_id; |
| 168 | } *core_even, *core_odd; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 169 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 170 | struct pkg_data { |
| 171 | unsigned long long pc2; |
| 172 | unsigned long long pc3; |
| 173 | unsigned long long pc6; |
| 174 | unsigned long long pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 175 | unsigned long long pc8; |
| 176 | unsigned long long pc9; |
| 177 | unsigned long long pc10; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 178 | unsigned long long pkg_wtd_core_c0; |
| 179 | unsigned long long pkg_any_core_c0; |
| 180 | unsigned long long pkg_any_gfxe_c0; |
| 181 | unsigned long long pkg_both_core_gfxe_c0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 182 | unsigned int package_id; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 183 | unsigned int energy_pkg; /* MSR_PKG_ENERGY_STATUS */ |
| 184 | unsigned int energy_dram; /* MSR_DRAM_ENERGY_STATUS */ |
| 185 | unsigned int energy_cores; /* MSR_PP0_ENERGY_STATUS */ |
| 186 | unsigned int energy_gfx; /* MSR_PP1_ENERGY_STATUS */ |
| 187 | unsigned int rapl_pkg_perf_status; /* MSR_PKG_PERF_STATUS */ |
| 188 | unsigned int rapl_dram_perf_status; /* MSR_DRAM_PERF_STATUS */ |
| 189 | unsigned int pkg_temp_c; |
| 190 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 191 | } *package_even, *package_odd; |
| 192 | |
| 193 | #define ODD_COUNTERS thread_odd, core_odd, package_odd |
| 194 | #define EVEN_COUNTERS thread_even, core_even, package_even |
| 195 | |
| 196 | #define GET_THREAD(thread_base, thread_no, core_no, pkg_no) \ |
| 197 | (thread_base + (pkg_no) * topo.num_cores_per_pkg * \ |
| 198 | topo.num_threads_per_core + \ |
| 199 | (core_no) * topo.num_threads_per_core + (thread_no)) |
| 200 | #define GET_CORE(core_base, core_no, pkg_no) \ |
| 201 | (core_base + (pkg_no) * topo.num_cores_per_pkg + (core_no)) |
| 202 | #define GET_PKG(pkg_base, pkg_no) (pkg_base + pkg_no) |
| 203 | |
| 204 | struct system_summary { |
| 205 | struct thread_data threads; |
| 206 | struct core_data cores; |
| 207 | struct pkg_data packages; |
| 208 | } sum, average; |
| 209 | |
| 210 | |
| 211 | struct topo_params { |
| 212 | int num_packages; |
| 213 | int num_cpus; |
| 214 | int num_cores; |
| 215 | int max_cpu_num; |
| 216 | int num_cores_per_pkg; |
| 217 | int num_threads_per_core; |
| 218 | } topo; |
| 219 | |
| 220 | struct timeval tv_even, tv_odd, tv_delta; |
| 221 | |
| 222 | void setup_all_buffers(void); |
| 223 | |
| 224 | int cpu_is_not_present(int cpu) |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 225 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 226 | return !CPU_ISSET_S(cpu, cpu_present_setsize, cpu_present_set); |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 227 | } |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 228 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 229 | * run func(thread, core, package) in topology order |
| 230 | * skip non-present cpus |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 231 | */ |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 232 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 233 | int for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg_data *), |
| 234 | 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] | 235 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 236 | int retval, pkg_no, core_no, thread_no; |
| 237 | |
| 238 | for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { |
| 239 | for (core_no = 0; core_no < topo.num_cores_per_pkg; ++core_no) { |
| 240 | for (thread_no = 0; thread_no < |
| 241 | topo.num_threads_per_core; ++thread_no) { |
| 242 | struct thread_data *t; |
| 243 | struct core_data *c; |
| 244 | struct pkg_data *p; |
| 245 | |
| 246 | t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); |
| 247 | |
| 248 | if (cpu_is_not_present(t->cpu_id)) |
| 249 | continue; |
| 250 | |
| 251 | c = GET_CORE(core_base, core_no, pkg_no); |
| 252 | p = GET_PKG(pkg_base, pkg_no); |
| 253 | |
| 254 | retval = func(t, c, p); |
| 255 | if (retval) |
| 256 | return retval; |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | return 0; |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | int cpu_migrate(int cpu) |
| 264 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 265 | CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); |
| 266 | CPU_SET_S(cpu, cpu_affinity_setsize, cpu_affinity_set); |
| 267 | if (sched_setaffinity(0, cpu_affinity_setsize, cpu_affinity_set) == -1) |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 268 | return -1; |
| 269 | else |
| 270 | return 0; |
| 271 | } |
| 272 | |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 273 | int get_msr(int cpu, off_t offset, unsigned long long *msr) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 274 | { |
| 275 | ssize_t retval; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 276 | char pathname[32]; |
| 277 | int fd; |
| 278 | |
| 279 | sprintf(pathname, "/dev/cpu/%d/msr", cpu); |
| 280 | fd = open(pathname, O_RDONLY); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 281 | if (fd < 0) |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 282 | 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] | 283 | |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 284 | retval = pread(fd, msr, sizeof *msr, offset); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 285 | close(fd); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 286 | |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 287 | if (retval != sizeof *msr) |
| 288 | err(-1, "%s offset 0x%llx read failed", pathname, (unsigned long long)offset); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 289 | |
| 290 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 291 | } |
| 292 | |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 293 | /* |
| 294 | * Example Format w/ field column widths: |
| 295 | * |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 296 | * Package Core CPU Avg_MHz Bzy_MHz TSC_MHz SMI %Busy CPU_%c1 CPU_%c3 CPU_%c6 CPU_%c7 CoreTmp PkgTmp Pkg%pc2 Pkg%pc3 Pkg%pc6 Pkg%pc7 PkgWatt CorWatt GFXWatt |
| 297 | * 123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678 |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 298 | */ |
| 299 | |
Len Brown | a829eb4 | 2011-02-10 23:36:34 -0500 | [diff] [blame] | 300 | void print_header(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 301 | { |
| 302 | if (show_pkg) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 303 | outp += sprintf(outp, " Package"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 304 | if (show_core) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 305 | outp += sprintf(outp, " Core"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 306 | if (show_cpu) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 307 | outp += sprintf(outp, " CPU"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 308 | if (has_aperf) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 309 | outp += sprintf(outp, " Avg_MHz"); |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 310 | if (has_aperf) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 311 | outp += sprintf(outp, " %%Busy"); |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 312 | if (has_aperf) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 313 | outp += sprintf(outp, " Bzy_MHz"); |
| 314 | outp += sprintf(outp, " TSC_MHz"); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 315 | |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 316 | if (extra_delta_offset32) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 317 | outp += sprintf(outp, " count 0x%03X", extra_delta_offset32); |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 318 | if (extra_delta_offset64) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 319 | outp += sprintf(outp, " COUNT 0x%03X", extra_delta_offset64); |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 320 | if (extra_msr_offset32) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 321 | outp += sprintf(outp, " MSR 0x%03X", extra_msr_offset32); |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 322 | if (extra_msr_offset64) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 323 | outp += sprintf(outp, " MSR 0x%03X", extra_msr_offset64); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 324 | |
| 325 | if (!debug) |
| 326 | goto done; |
| 327 | |
| 328 | if (do_smi) |
| 329 | outp += sprintf(outp, " SMI"); |
| 330 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 331 | if (do_nhm_cstates) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 332 | outp += sprintf(outp, " CPU%%c1"); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 333 | if (do_nhm_cstates && !do_slm_cstates && !do_knl_cstates) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 334 | outp += sprintf(outp, " CPU%%c3"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 335 | if (do_nhm_cstates) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 336 | outp += sprintf(outp, " CPU%%c6"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 337 | if (do_snb_cstates) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 338 | outp += sprintf(outp, " CPU%%c7"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 339 | |
| 340 | if (do_dts) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 341 | outp += sprintf(outp, " CoreTmp"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 342 | if (do_ptm) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 343 | outp += sprintf(outp, " PkgTmp"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 344 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 345 | if (do_skl_residency) { |
| 346 | outp += sprintf(outp, " Totl%%C0"); |
| 347 | outp += sprintf(outp, " Any%%C0"); |
| 348 | outp += sprintf(outp, " GFX%%C0"); |
| 349 | outp += sprintf(outp, " CPUGFX%%"); |
| 350 | } |
| 351 | |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 352 | if (do_pc2) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 353 | outp += sprintf(outp, " Pkg%%pc2"); |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 354 | if (do_pc3) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 355 | outp += sprintf(outp, " Pkg%%pc3"); |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 356 | if (do_pc6) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 357 | outp += sprintf(outp, " Pkg%%pc6"); |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 358 | if (do_pc7) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 359 | outp += sprintf(outp, " Pkg%%pc7"); |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 360 | if (do_c8_c9_c10) { |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 361 | outp += sprintf(outp, " Pkg%%pc8"); |
| 362 | outp += sprintf(outp, " Pkg%%pc9"); |
| 363 | outp += sprintf(outp, " Pk%%pc10"); |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 364 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 365 | |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 366 | if (do_rapl && !rapl_joules) { |
| 367 | if (do_rapl & RAPL_PKG) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 368 | outp += sprintf(outp, " PkgWatt"); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 369 | if (do_rapl & RAPL_CORES) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 370 | outp += sprintf(outp, " CorWatt"); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 371 | if (do_rapl & RAPL_GFX) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 372 | outp += sprintf(outp, " GFXWatt"); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 373 | if (do_rapl & RAPL_DRAM) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 374 | outp += sprintf(outp, " RAMWatt"); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 375 | if (do_rapl & RAPL_PKG_PERF_STATUS) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 376 | outp += sprintf(outp, " PKG_%%"); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 377 | if (do_rapl & RAPL_DRAM_PERF_STATUS) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 378 | outp += sprintf(outp, " RAM_%%"); |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 379 | } else if (do_rapl && rapl_joules) { |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 380 | if (do_rapl & RAPL_PKG) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 381 | outp += sprintf(outp, " Pkg_J"); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 382 | if (do_rapl & RAPL_CORES) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 383 | outp += sprintf(outp, " Cor_J"); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 384 | if (do_rapl & RAPL_GFX) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 385 | outp += sprintf(outp, " GFX_J"); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 386 | if (do_rapl & RAPL_DRAM) |
Len Brown | bd6906e | 2015-07-24 10:35:23 -0400 | [diff] [blame] | 387 | outp += sprintf(outp, " RAM_J"); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 388 | if (do_rapl & RAPL_PKG_PERF_STATUS) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 389 | outp += sprintf(outp, " PKG_%%"); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 390 | if (do_rapl & RAPL_DRAM_PERF_STATUS) |
Len Brown | e7c95ff | 2014-08-14 21:22:13 -0400 | [diff] [blame] | 391 | outp += sprintf(outp, " RAM_%%"); |
| 392 | outp += sprintf(outp, " time"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 393 | |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 394 | } |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 395 | done: |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 396 | outp += sprintf(outp, "\n"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 397 | } |
| 398 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 399 | int dump_counters(struct thread_data *t, struct core_data *c, |
| 400 | struct pkg_data *p) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 401 | { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 402 | 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] | 403 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 404 | if (t) { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 405 | outp += sprintf(outp, "CPU: %d flags 0x%x\n", |
| 406 | t->cpu_id, t->flags); |
| 407 | outp += sprintf(outp, "TSC: %016llX\n", t->tsc); |
| 408 | outp += sprintf(outp, "aperf: %016llX\n", t->aperf); |
| 409 | outp += sprintf(outp, "mperf: %016llX\n", t->mperf); |
| 410 | outp += sprintf(outp, "c1: %016llX\n", t->c1); |
| 411 | outp += sprintf(outp, "msr0x%x: %08llX\n", |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 412 | extra_delta_offset32, t->extra_delta32); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 413 | outp += sprintf(outp, "msr0x%x: %016llX\n", |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 414 | extra_delta_offset64, t->extra_delta64); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 415 | outp += sprintf(outp, "msr0x%x: %08llX\n", |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 416 | extra_msr_offset32, t->extra_msr32); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 417 | outp += sprintf(outp, "msr0x%x: %016llX\n", |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 418 | extra_msr_offset64, t->extra_msr64); |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 419 | if (do_smi) |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 420 | outp += sprintf(outp, "SMI: %08X\n", t->smi_count); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 421 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 422 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 423 | if (c) { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 424 | outp += sprintf(outp, "core: %d\n", c->core_id); |
| 425 | outp += sprintf(outp, "c3: %016llX\n", c->c3); |
| 426 | outp += sprintf(outp, "c6: %016llX\n", c->c6); |
| 427 | outp += sprintf(outp, "c7: %016llX\n", c->c7); |
| 428 | outp += sprintf(outp, "DTS: %dC\n", c->core_temp_c); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | if (p) { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 432 | outp += sprintf(outp, "package: %d\n", p->package_id); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 433 | |
| 434 | outp += sprintf(outp, "Weighted cores: %016llX\n", p->pkg_wtd_core_c0); |
| 435 | outp += sprintf(outp, "Any cores: %016llX\n", p->pkg_any_core_c0); |
| 436 | outp += sprintf(outp, "Any GFX: %016llX\n", p->pkg_any_gfxe_c0); |
| 437 | outp += sprintf(outp, "CPU + GFX: %016llX\n", p->pkg_both_core_gfxe_c0); |
| 438 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 439 | outp += sprintf(outp, "pc2: %016llX\n", p->pc2); |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 440 | if (do_pc3) |
| 441 | outp += sprintf(outp, "pc3: %016llX\n", p->pc3); |
| 442 | if (do_pc6) |
| 443 | outp += sprintf(outp, "pc6: %016llX\n", p->pc6); |
| 444 | if (do_pc7) |
| 445 | outp += sprintf(outp, "pc7: %016llX\n", p->pc7); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 446 | outp += sprintf(outp, "pc8: %016llX\n", p->pc8); |
| 447 | outp += sprintf(outp, "pc9: %016llX\n", p->pc9); |
| 448 | outp += sprintf(outp, "pc10: %016llX\n", p->pc10); |
| 449 | outp += sprintf(outp, "Joules PKG: %0X\n", p->energy_pkg); |
| 450 | outp += sprintf(outp, "Joules COR: %0X\n", p->energy_cores); |
| 451 | outp += sprintf(outp, "Joules GFX: %0X\n", p->energy_gfx); |
| 452 | outp += sprintf(outp, "Joules RAM: %0X\n", p->energy_dram); |
| 453 | outp += sprintf(outp, "Throttle PKG: %0X\n", |
| 454 | p->rapl_pkg_perf_status); |
| 455 | outp += sprintf(outp, "Throttle RAM: %0X\n", |
| 456 | p->rapl_dram_perf_status); |
| 457 | outp += sprintf(outp, "PTM: %dC\n", p->pkg_temp_c); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 458 | } |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 459 | |
| 460 | outp += sprintf(outp, "\n"); |
| 461 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 462 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 463 | } |
| 464 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 465 | /* |
| 466 | * column formatting convention & formats |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 467 | */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 468 | int format_counters(struct thread_data *t, struct core_data *c, |
| 469 | struct pkg_data *p) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 470 | { |
| 471 | double interval_float; |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 472 | char *fmt8; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 473 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 474 | /* if showing only 1st thread in core and this isn't one, bail out */ |
| 475 | if (show_core_only && !(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 476 | return 0; |
| 477 | |
| 478 | /* if showing only 1st thread in pkg and this isn't one, bail out */ |
| 479 | if (show_pkg_only && !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 480 | return 0; |
| 481 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 482 | interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0; |
| 483 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 484 | /* topo columns, print blanks on 1st (average) line */ |
| 485 | if (t == &average.threads) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 486 | if (show_pkg) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 487 | outp += sprintf(outp, " -"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 488 | if (show_core) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 489 | outp += sprintf(outp, " -"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 490 | if (show_cpu) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 491 | outp += sprintf(outp, " -"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 492 | } else { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 493 | if (show_pkg) { |
| 494 | if (p) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 495 | outp += sprintf(outp, "%8d", p->package_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 496 | else |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 497 | outp += sprintf(outp, " -"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 498 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 499 | if (show_core) { |
| 500 | if (c) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 501 | outp += sprintf(outp, "%8d", c->core_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 502 | else |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 503 | outp += sprintf(outp, " -"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 504 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 505 | if (show_cpu) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 506 | outp += sprintf(outp, "%8d", t->cpu_id); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 507 | } |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 508 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 509 | /* Avg_MHz */ |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 510 | if (has_aperf) |
| 511 | outp += sprintf(outp, "%8.0f", |
| 512 | 1.0 / units * t->aperf / interval_float); |
| 513 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 514 | /* %Busy */ |
| 515 | if (has_aperf) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 516 | if (!skip_c0) |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 517 | outp += sprintf(outp, "%8.2f", 100.0 * t->mperf/t->tsc/tsc_tweak); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 518 | else |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 519 | outp += sprintf(outp, "********"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 520 | } |
| 521 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 522 | /* Bzy_MHz */ |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 523 | if (has_aperf) { |
| 524 | if (has_base_hz) |
| 525 | outp += sprintf(outp, "%8.0f", base_hz / units * t->aperf / t->mperf); |
| 526 | else |
| 527 | outp += sprintf(outp, "%8.0f", |
| 528 | 1.0 * t->tsc / units * t->aperf / t->mperf / interval_float); |
| 529 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 530 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 531 | /* TSC_MHz */ |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 532 | outp += sprintf(outp, "%8.0f", 1.0 * t->tsc/units/interval_float); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 533 | |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 534 | /* delta */ |
| 535 | if (extra_delta_offset32) |
| 536 | outp += sprintf(outp, " %11llu", t->extra_delta32); |
| 537 | |
| 538 | /* DELTA */ |
| 539 | if (extra_delta_offset64) |
| 540 | outp += sprintf(outp, " %11llu", t->extra_delta64); |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 541 | /* msr */ |
| 542 | if (extra_msr_offset32) |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 543 | outp += sprintf(outp, " 0x%08llx", t->extra_msr32); |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 544 | |
Len Brown | 130ff30 | 2012-09-21 22:56:06 -0400 | [diff] [blame] | 545 | /* MSR */ |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 546 | if (extra_msr_offset64) |
| 547 | outp += sprintf(outp, " 0x%016llx", t->extra_msr64); |
Len Brown | 130ff30 | 2012-09-21 22:56:06 -0400 | [diff] [blame] | 548 | |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 549 | if (!debug) |
| 550 | goto done; |
| 551 | |
| 552 | /* SMI */ |
| 553 | if (do_smi) |
| 554 | outp += sprintf(outp, "%8d", t->smi_count); |
| 555 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 556 | if (do_nhm_cstates) { |
| 557 | if (!skip_c1) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 558 | outp += sprintf(outp, "%8.2f", 100.0 * t->c1/t->tsc); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 559 | else |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 560 | outp += sprintf(outp, "********"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 561 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 562 | |
| 563 | /* print per-core data only for 1st thread in core */ |
| 564 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 565 | goto done; |
| 566 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 567 | if (do_nhm_cstates && !do_slm_cstates && !do_knl_cstates) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 568 | outp += sprintf(outp, "%8.2f", 100.0 * c->c3/t->tsc); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 569 | if (do_nhm_cstates) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 570 | outp += sprintf(outp, "%8.2f", 100.0 * c->c6/t->tsc); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 571 | if (do_snb_cstates) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 572 | outp += sprintf(outp, "%8.2f", 100.0 * c->c7/t->tsc); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 573 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 574 | if (do_dts) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 575 | outp += sprintf(outp, "%8d", c->core_temp_c); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 576 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 577 | /* print per-package data only for 1st core in package */ |
| 578 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 579 | goto done; |
| 580 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 581 | /* PkgTmp */ |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 582 | if (do_ptm) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 583 | outp += sprintf(outp, "%8d", p->pkg_temp_c); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 584 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 585 | /* Totl%C0, Any%C0 GFX%C0 CPUGFX% */ |
| 586 | if (do_skl_residency) { |
| 587 | outp += sprintf(outp, "%8.2f", 100.0 * p->pkg_wtd_core_c0/t->tsc); |
| 588 | outp += sprintf(outp, "%8.2f", 100.0 * p->pkg_any_core_c0/t->tsc); |
| 589 | outp += sprintf(outp, "%8.2f", 100.0 * p->pkg_any_gfxe_c0/t->tsc); |
| 590 | outp += sprintf(outp, "%8.2f", 100.0 * p->pkg_both_core_gfxe_c0/t->tsc); |
| 591 | } |
| 592 | |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 593 | if (do_pc2) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 594 | outp += sprintf(outp, "%8.2f", 100.0 * p->pc2/t->tsc); |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 595 | if (do_pc3) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 596 | outp += sprintf(outp, "%8.2f", 100.0 * p->pc3/t->tsc); |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 597 | if (do_pc6) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 598 | outp += sprintf(outp, "%8.2f", 100.0 * p->pc6/t->tsc); |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 599 | if (do_pc7) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 600 | outp += sprintf(outp, "%8.2f", 100.0 * p->pc7/t->tsc); |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 601 | if (do_c8_c9_c10) { |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 602 | outp += sprintf(outp, "%8.2f", 100.0 * p->pc8/t->tsc); |
| 603 | outp += sprintf(outp, "%8.2f", 100.0 * p->pc9/t->tsc); |
| 604 | outp += sprintf(outp, "%8.2f", 100.0 * p->pc10/t->tsc); |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 605 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 606 | |
| 607 | /* |
| 608 | * If measurement interval exceeds minimum RAPL Joule Counter range, |
| 609 | * indicate that results are suspect by printing "**" in fraction place. |
| 610 | */ |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 611 | if (interval_float < rapl_joule_counter_range) |
| 612 | fmt8 = "%8.2f"; |
| 613 | else |
| 614 | fmt8 = " %6.0f**"; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 615 | |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 616 | if (do_rapl && !rapl_joules) { |
| 617 | if (do_rapl & RAPL_PKG) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 618 | outp += sprintf(outp, fmt8, p->energy_pkg * rapl_energy_units / interval_float); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 619 | if (do_rapl & RAPL_CORES) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 620 | outp += sprintf(outp, fmt8, p->energy_cores * rapl_energy_units / interval_float); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 621 | if (do_rapl & RAPL_GFX) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 622 | outp += sprintf(outp, fmt8, p->energy_gfx * rapl_energy_units / interval_float); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 623 | if (do_rapl & RAPL_DRAM) |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 624 | outp += sprintf(outp, fmt8, p->energy_dram * rapl_dram_energy_units / interval_float); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 625 | if (do_rapl & RAPL_PKG_PERF_STATUS) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 626 | outp += sprintf(outp, fmt8, 100.0 * p->rapl_pkg_perf_status * rapl_time_units / interval_float); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 627 | if (do_rapl & RAPL_DRAM_PERF_STATUS) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 628 | outp += sprintf(outp, fmt8, 100.0 * p->rapl_dram_perf_status * rapl_time_units / interval_float); |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 629 | } else if (do_rapl && rapl_joules) { |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 630 | if (do_rapl & RAPL_PKG) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 631 | outp += sprintf(outp, fmt8, |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 632 | p->energy_pkg * rapl_energy_units); |
| 633 | if (do_rapl & RAPL_CORES) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 634 | outp += sprintf(outp, fmt8, |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 635 | p->energy_cores * rapl_energy_units); |
| 636 | if (do_rapl & RAPL_GFX) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 637 | outp += sprintf(outp, fmt8, |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 638 | p->energy_gfx * rapl_energy_units); |
| 639 | if (do_rapl & RAPL_DRAM) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 640 | outp += sprintf(outp, fmt8, |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 641 | p->energy_dram * rapl_dram_energy_units); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 642 | if (do_rapl & RAPL_PKG_PERF_STATUS) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 643 | outp += sprintf(outp, fmt8, 100.0 * p->rapl_pkg_perf_status * rapl_time_units / interval_float); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 644 | if (do_rapl & RAPL_DRAM_PERF_STATUS) |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 645 | outp += sprintf(outp, fmt8, 100.0 * p->rapl_dram_perf_status * rapl_time_units / interval_float); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 646 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 647 | outp += sprintf(outp, fmt8, interval_float); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 648 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 649 | done: |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 650 | outp += sprintf(outp, "\n"); |
| 651 | |
| 652 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 653 | } |
| 654 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 655 | void flush_stdout() |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 656 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 657 | fputs(output_buffer, stdout); |
Len Brown | ddac0d6 | 2012-11-30 01:01:40 -0500 | [diff] [blame] | 658 | fflush(stdout); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 659 | outp = output_buffer; |
| 660 | } |
| 661 | void flush_stderr() |
| 662 | { |
| 663 | fputs(output_buffer, stderr); |
| 664 | outp = output_buffer; |
| 665 | } |
| 666 | void format_all_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 667 | { |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 668 | static int printed; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 669 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 670 | if (!printed || !summary_only) |
| 671 | print_header(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 672 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 673 | if (topo.num_cpus > 1) |
| 674 | format_counters(&average.threads, &average.cores, |
| 675 | &average.packages); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 676 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 677 | printed = 1; |
| 678 | |
| 679 | if (summary_only) |
| 680 | return; |
| 681 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 682 | for_all_cpus(format_counters, t, c, p); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 683 | } |
| 684 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 685 | #define DELTA_WRAP32(new, old) \ |
| 686 | if (new > old) { \ |
| 687 | old = new - old; \ |
| 688 | } else { \ |
| 689 | old = 0x100000000 + new - old; \ |
| 690 | } |
| 691 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 692 | void |
| 693 | delta_package(struct pkg_data *new, struct pkg_data *old) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 694 | { |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 695 | |
| 696 | if (do_skl_residency) { |
| 697 | old->pkg_wtd_core_c0 = new->pkg_wtd_core_c0 - old->pkg_wtd_core_c0; |
| 698 | old->pkg_any_core_c0 = new->pkg_any_core_c0 - old->pkg_any_core_c0; |
| 699 | old->pkg_any_gfxe_c0 = new->pkg_any_gfxe_c0 - old->pkg_any_gfxe_c0; |
| 700 | old->pkg_both_core_gfxe_c0 = new->pkg_both_core_gfxe_c0 - old->pkg_both_core_gfxe_c0; |
| 701 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 702 | old->pc2 = new->pc2 - old->pc2; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 703 | if (do_pc3) |
| 704 | old->pc3 = new->pc3 - old->pc3; |
| 705 | if (do_pc6) |
| 706 | old->pc6 = new->pc6 - old->pc6; |
| 707 | if (do_pc7) |
| 708 | old->pc7 = new->pc7 - old->pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 709 | old->pc8 = new->pc8 - old->pc8; |
| 710 | old->pc9 = new->pc9 - old->pc9; |
| 711 | old->pc10 = new->pc10 - old->pc10; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 712 | old->pkg_temp_c = new->pkg_temp_c; |
| 713 | |
| 714 | DELTA_WRAP32(new->energy_pkg, old->energy_pkg); |
| 715 | DELTA_WRAP32(new->energy_cores, old->energy_cores); |
| 716 | DELTA_WRAP32(new->energy_gfx, old->energy_gfx); |
| 717 | DELTA_WRAP32(new->energy_dram, old->energy_dram); |
| 718 | DELTA_WRAP32(new->rapl_pkg_perf_status, old->rapl_pkg_perf_status); |
| 719 | DELTA_WRAP32(new->rapl_dram_perf_status, old->rapl_dram_perf_status); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 720 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 721 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 722 | void |
| 723 | delta_core(struct core_data *new, struct core_data *old) |
| 724 | { |
| 725 | old->c3 = new->c3 - old->c3; |
| 726 | old->c6 = new->c6 - old->c6; |
| 727 | old->c7 = new->c7 - old->c7; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 728 | old->core_temp_c = new->core_temp_c; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 729 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 730 | |
Len Brown | c3ae331 | 2012-06-13 21:31:46 -0400 | [diff] [blame] | 731 | /* |
| 732 | * old = new - old |
| 733 | */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 734 | void |
| 735 | delta_thread(struct thread_data *new, struct thread_data *old, |
| 736 | struct core_data *core_delta) |
| 737 | { |
| 738 | old->tsc = new->tsc - old->tsc; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 739 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 740 | /* check for TSC < 1 Mcycles over interval */ |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 741 | if (old->tsc < (1000 * 1000)) |
| 742 | errx(-3, "Insanely slow TSC rate, TSC stops in idle?\n" |
| 743 | "You can disable all c-states by booting with \"idle=poll\"\n" |
| 744 | "or just the deep ones with \"processor.max_cstate=1\""); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 745 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 746 | old->c1 = new->c1 - old->c1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 747 | |
Len Brown | a729617 | 2015-01-23 01:33:58 -0500 | [diff] [blame] | 748 | if (has_aperf) { |
| 749 | if ((new->aperf > old->aperf) && (new->mperf > old->mperf)) { |
| 750 | old->aperf = new->aperf - old->aperf; |
| 751 | old->mperf = new->mperf - old->mperf; |
| 752 | } else { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 753 | |
Len Brown | a729617 | 2015-01-23 01:33:58 -0500 | [diff] [blame] | 754 | if (!aperf_mperf_unstable) { |
| 755 | fprintf(stderr, "%s: APERF or MPERF went backwards *\n", progname); |
| 756 | fprintf(stderr, "* Frequency results do not cover entire interval *\n"); |
| 757 | fprintf(stderr, "* fix this by running Linux-2.6.30 or later *\n"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 758 | |
Len Brown | a729617 | 2015-01-23 01:33:58 -0500 | [diff] [blame] | 759 | aperf_mperf_unstable = 1; |
| 760 | } |
| 761 | /* |
| 762 | * mperf delta is likely a huge "positive" number |
| 763 | * can not use it for calculating c0 time |
| 764 | */ |
| 765 | skip_c0 = 1; |
| 766 | skip_c1 = 1; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 767 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 768 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 769 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 770 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 771 | if (use_c1_residency_msr) { |
| 772 | /* |
| 773 | * Some models have a dedicated C1 residency MSR, |
| 774 | * which should be more accurate than the derivation below. |
| 775 | */ |
| 776 | } else { |
| 777 | /* |
| 778 | * As counter collection is not atomic, |
| 779 | * it is possible for mperf's non-halted cycles + idle states |
| 780 | * to exceed TSC's all cycles: show c1 = 0% in that case. |
| 781 | */ |
| 782 | if ((old->mperf + core_delta->c3 + core_delta->c6 + core_delta->c7) > old->tsc) |
| 783 | old->c1 = 0; |
| 784 | else { |
| 785 | /* normal case, derive c1 */ |
| 786 | old->c1 = old->tsc - old->mperf - core_delta->c3 |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 787 | - core_delta->c6 - core_delta->c7; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 788 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 789 | } |
Len Brown | c3ae331 | 2012-06-13 21:31:46 -0400 | [diff] [blame] | 790 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 791 | if (old->mperf == 0) { |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 792 | if (debug > 1) fprintf(stderr, "cpu%d MPERF 0!\n", old->cpu_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 793 | old->mperf = 1; /* divide by 0 protection */ |
| 794 | } |
| 795 | |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 796 | old->extra_delta32 = new->extra_delta32 - old->extra_delta32; |
| 797 | old->extra_delta32 &= 0xFFFFFFFF; |
| 798 | |
| 799 | old->extra_delta64 = new->extra_delta64 - old->extra_delta64; |
| 800 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 801 | /* |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 802 | * Extra MSR is just a snapshot, simply copy latest w/o subtracting |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 803 | */ |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 804 | old->extra_msr32 = new->extra_msr32; |
| 805 | old->extra_msr64 = new->extra_msr64; |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 806 | |
| 807 | if (do_smi) |
| 808 | old->smi_count = new->smi_count - old->smi_count; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | int delta_cpu(struct thread_data *t, struct core_data *c, |
| 812 | struct pkg_data *p, struct thread_data *t2, |
| 813 | struct core_data *c2, struct pkg_data *p2) |
| 814 | { |
| 815 | /* calculate core delta only for 1st thread in core */ |
| 816 | if (t->flags & CPU_IS_FIRST_THREAD_IN_CORE) |
| 817 | delta_core(c, c2); |
| 818 | |
| 819 | /* always calculate thread delta */ |
| 820 | delta_thread(t, t2, c2); /* c2 is core delta */ |
| 821 | |
| 822 | /* calculate package delta only for 1st core in package */ |
| 823 | if (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE) |
| 824 | delta_package(p, p2); |
| 825 | |
| 826 | return 0; |
| 827 | } |
| 828 | |
| 829 | void clear_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 830 | { |
| 831 | t->tsc = 0; |
| 832 | t->aperf = 0; |
| 833 | t->mperf = 0; |
| 834 | t->c1 = 0; |
| 835 | |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 836 | t->smi_count = 0; |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 837 | t->extra_delta32 = 0; |
| 838 | t->extra_delta64 = 0; |
| 839 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 840 | /* tells format_counters to dump all fields from this set */ |
| 841 | t->flags = CPU_IS_FIRST_THREAD_IN_CORE | CPU_IS_FIRST_CORE_IN_PACKAGE; |
| 842 | |
| 843 | c->c3 = 0; |
| 844 | c->c6 = 0; |
| 845 | c->c7 = 0; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 846 | c->core_temp_c = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 847 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 848 | p->pkg_wtd_core_c0 = 0; |
| 849 | p->pkg_any_core_c0 = 0; |
| 850 | p->pkg_any_gfxe_c0 = 0; |
| 851 | p->pkg_both_core_gfxe_c0 = 0; |
| 852 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 853 | p->pc2 = 0; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 854 | if (do_pc3) |
| 855 | p->pc3 = 0; |
| 856 | if (do_pc6) |
| 857 | p->pc6 = 0; |
| 858 | if (do_pc7) |
| 859 | p->pc7 = 0; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 860 | p->pc8 = 0; |
| 861 | p->pc9 = 0; |
| 862 | p->pc10 = 0; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 863 | |
| 864 | p->energy_pkg = 0; |
| 865 | p->energy_dram = 0; |
| 866 | p->energy_cores = 0; |
| 867 | p->energy_gfx = 0; |
| 868 | p->rapl_pkg_perf_status = 0; |
| 869 | p->rapl_dram_perf_status = 0; |
| 870 | p->pkg_temp_c = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 871 | } |
| 872 | int sum_counters(struct thread_data *t, struct core_data *c, |
| 873 | struct pkg_data *p) |
| 874 | { |
| 875 | average.threads.tsc += t->tsc; |
| 876 | average.threads.aperf += t->aperf; |
| 877 | average.threads.mperf += t->mperf; |
| 878 | average.threads.c1 += t->c1; |
| 879 | |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 880 | average.threads.extra_delta32 += t->extra_delta32; |
| 881 | average.threads.extra_delta64 += t->extra_delta64; |
| 882 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 883 | /* sum per-core values only for 1st thread in core */ |
| 884 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 885 | return 0; |
| 886 | |
| 887 | average.cores.c3 += c->c3; |
| 888 | average.cores.c6 += c->c6; |
| 889 | average.cores.c7 += c->c7; |
| 890 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 891 | average.cores.core_temp_c = MAX(average.cores.core_temp_c, c->core_temp_c); |
| 892 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 893 | /* sum per-pkg values only for 1st core in pkg */ |
| 894 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 895 | return 0; |
| 896 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 897 | if (do_skl_residency) { |
| 898 | average.packages.pkg_wtd_core_c0 += p->pkg_wtd_core_c0; |
| 899 | average.packages.pkg_any_core_c0 += p->pkg_any_core_c0; |
| 900 | average.packages.pkg_any_gfxe_c0 += p->pkg_any_gfxe_c0; |
| 901 | average.packages.pkg_both_core_gfxe_c0 += p->pkg_both_core_gfxe_c0; |
| 902 | } |
| 903 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 904 | average.packages.pc2 += p->pc2; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 905 | if (do_pc3) |
| 906 | average.packages.pc3 += p->pc3; |
| 907 | if (do_pc6) |
| 908 | average.packages.pc6 += p->pc6; |
| 909 | if (do_pc7) |
| 910 | average.packages.pc7 += p->pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 911 | average.packages.pc8 += p->pc8; |
| 912 | average.packages.pc9 += p->pc9; |
| 913 | average.packages.pc10 += p->pc10; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 914 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 915 | average.packages.energy_pkg += p->energy_pkg; |
| 916 | average.packages.energy_dram += p->energy_dram; |
| 917 | average.packages.energy_cores += p->energy_cores; |
| 918 | average.packages.energy_gfx += p->energy_gfx; |
| 919 | |
| 920 | average.packages.pkg_temp_c = MAX(average.packages.pkg_temp_c, p->pkg_temp_c); |
| 921 | |
| 922 | average.packages.rapl_pkg_perf_status += p->rapl_pkg_perf_status; |
| 923 | average.packages.rapl_dram_perf_status += p->rapl_dram_perf_status; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 924 | return 0; |
| 925 | } |
| 926 | /* |
| 927 | * sum the counters for all cpus in the system |
| 928 | * compute the weighted average |
| 929 | */ |
| 930 | void compute_average(struct thread_data *t, struct core_data *c, |
| 931 | struct pkg_data *p) |
| 932 | { |
| 933 | clear_counters(&average.threads, &average.cores, &average.packages); |
| 934 | |
| 935 | for_all_cpus(sum_counters, t, c, p); |
| 936 | |
| 937 | average.threads.tsc /= topo.num_cpus; |
| 938 | average.threads.aperf /= topo.num_cpus; |
| 939 | average.threads.mperf /= topo.num_cpus; |
| 940 | average.threads.c1 /= topo.num_cpus; |
| 941 | |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 942 | average.threads.extra_delta32 /= topo.num_cpus; |
| 943 | average.threads.extra_delta32 &= 0xFFFFFFFF; |
| 944 | |
| 945 | average.threads.extra_delta64 /= topo.num_cpus; |
| 946 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 947 | average.cores.c3 /= topo.num_cores; |
| 948 | average.cores.c6 /= topo.num_cores; |
| 949 | average.cores.c7 /= topo.num_cores; |
| 950 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 951 | if (do_skl_residency) { |
| 952 | average.packages.pkg_wtd_core_c0 /= topo.num_packages; |
| 953 | average.packages.pkg_any_core_c0 /= topo.num_packages; |
| 954 | average.packages.pkg_any_gfxe_c0 /= topo.num_packages; |
| 955 | average.packages.pkg_both_core_gfxe_c0 /= topo.num_packages; |
| 956 | } |
| 957 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 958 | average.packages.pc2 /= topo.num_packages; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 959 | if (do_pc3) |
| 960 | average.packages.pc3 /= topo.num_packages; |
| 961 | if (do_pc6) |
| 962 | average.packages.pc6 /= topo.num_packages; |
| 963 | if (do_pc7) |
| 964 | average.packages.pc7 /= topo.num_packages; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 965 | |
| 966 | average.packages.pc8 /= topo.num_packages; |
| 967 | average.packages.pc9 /= topo.num_packages; |
| 968 | average.packages.pc10 /= topo.num_packages; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | static unsigned long long rdtsc(void) |
| 972 | { |
| 973 | unsigned int low, high; |
| 974 | |
| 975 | asm volatile("rdtsc" : "=a" (low), "=d" (high)); |
| 976 | |
| 977 | return low | ((unsigned long long)high) << 32; |
| 978 | } |
| 979 | |
| 980 | |
| 981 | /* |
| 982 | * get_counters(...) |
| 983 | * migrate to cpu |
| 984 | * acquire and record local counters for that cpu |
| 985 | */ |
| 986 | int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 987 | { |
| 988 | int cpu = t->cpu_id; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 989 | unsigned long long msr; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 990 | |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 991 | if (cpu_migrate(cpu)) { |
| 992 | fprintf(stderr, "Could not migrate to CPU %d\n", cpu); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 993 | return -1; |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 994 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 995 | |
| 996 | t->tsc = rdtsc(); /* we are running on local CPU of interest */ |
| 997 | |
| 998 | if (has_aperf) { |
Len Brown | 9c63a65 | 2012-10-31 01:29:52 -0400 | [diff] [blame] | 999 | if (get_msr(cpu, MSR_IA32_APERF, &t->aperf)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1000 | return -3; |
Len Brown | 9c63a65 | 2012-10-31 01:29:52 -0400 | [diff] [blame] | 1001 | if (get_msr(cpu, MSR_IA32_MPERF, &t->mperf)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1002 | return -4; |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 1003 | t->aperf = t->aperf * aperf_mperf_multiplier; |
| 1004 | t->mperf = t->mperf * aperf_mperf_multiplier; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1005 | } |
| 1006 | |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 1007 | if (do_smi) { |
| 1008 | if (get_msr(cpu, MSR_SMI_COUNT, &msr)) |
| 1009 | return -5; |
| 1010 | t->smi_count = msr & 0xFFFFFFFF; |
| 1011 | } |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 1012 | if (extra_delta_offset32) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1013 | if (get_msr(cpu, extra_delta_offset32, &msr)) |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 1014 | return -5; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1015 | t->extra_delta32 = msr & 0xFFFFFFFF; |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | if (extra_delta_offset64) |
| 1019 | if (get_msr(cpu, extra_delta_offset64, &t->extra_delta64)) |
| 1020 | return -5; |
| 1021 | |
| 1022 | if (extra_msr_offset32) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1023 | if (get_msr(cpu, extra_msr_offset32, &msr)) |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 1024 | return -5; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1025 | t->extra_msr32 = msr & 0xFFFFFFFF; |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 1026 | } |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 1027 | |
| 1028 | if (extra_msr_offset64) |
| 1029 | if (get_msr(cpu, extra_msr_offset64, &t->extra_msr64)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1030 | return -5; |
| 1031 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1032 | if (use_c1_residency_msr) { |
| 1033 | if (get_msr(cpu, MSR_CORE_C1_RES, &t->c1)) |
| 1034 | return -6; |
| 1035 | } |
| 1036 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1037 | /* collect core counters only for 1st thread in core */ |
| 1038 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 1039 | return 0; |
| 1040 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1041 | if (do_nhm_cstates && !do_slm_cstates && !do_knl_cstates) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1042 | if (get_msr(cpu, MSR_CORE_C3_RESIDENCY, &c->c3)) |
| 1043 | return -6; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1044 | } |
| 1045 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1046 | if (do_nhm_cstates && !do_knl_cstates) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1047 | if (get_msr(cpu, MSR_CORE_C6_RESIDENCY, &c->c6)) |
| 1048 | return -7; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1049 | } else if (do_knl_cstates) { |
| 1050 | if (get_msr(cpu, MSR_KNL_CORE_C6_RESIDENCY, &c->c6)) |
| 1051 | return -7; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | if (do_snb_cstates) |
| 1055 | if (get_msr(cpu, MSR_CORE_C7_RESIDENCY, &c->c7)) |
| 1056 | return -8; |
| 1057 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1058 | if (do_dts) { |
| 1059 | if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr)) |
| 1060 | return -9; |
| 1061 | c->core_temp_c = tcc_activation_temp - ((msr >> 16) & 0x7F); |
| 1062 | } |
| 1063 | |
| 1064 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1065 | /* collect package counters only for 1st core in package */ |
| 1066 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 1067 | return 0; |
| 1068 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1069 | if (do_skl_residency) { |
| 1070 | if (get_msr(cpu, MSR_PKG_WEIGHTED_CORE_C0_RES, &p->pkg_wtd_core_c0)) |
| 1071 | return -10; |
| 1072 | if (get_msr(cpu, MSR_PKG_ANY_CORE_C0_RES, &p->pkg_any_core_c0)) |
| 1073 | return -11; |
| 1074 | if (get_msr(cpu, MSR_PKG_ANY_GFXE_C0_RES, &p->pkg_any_gfxe_c0)) |
| 1075 | return -12; |
| 1076 | if (get_msr(cpu, MSR_PKG_BOTH_CORE_GFXE_C0_RES, &p->pkg_both_core_gfxe_c0)) |
| 1077 | return -13; |
| 1078 | } |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1079 | if (do_pc3) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1080 | if (get_msr(cpu, MSR_PKG_C3_RESIDENCY, &p->pc3)) |
| 1081 | return -9; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1082 | if (do_pc6) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1083 | if (get_msr(cpu, MSR_PKG_C6_RESIDENCY, &p->pc6)) |
| 1084 | return -10; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1085 | if (do_pc2) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1086 | if (get_msr(cpu, MSR_PKG_C2_RESIDENCY, &p->pc2)) |
| 1087 | return -11; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1088 | if (do_pc7) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1089 | if (get_msr(cpu, MSR_PKG_C7_RESIDENCY, &p->pc7)) |
| 1090 | return -12; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1091 | if (do_c8_c9_c10) { |
| 1092 | if (get_msr(cpu, MSR_PKG_C8_RESIDENCY, &p->pc8)) |
| 1093 | return -13; |
| 1094 | if (get_msr(cpu, MSR_PKG_C9_RESIDENCY, &p->pc9)) |
| 1095 | return -13; |
| 1096 | if (get_msr(cpu, MSR_PKG_C10_RESIDENCY, &p->pc10)) |
| 1097 | return -13; |
| 1098 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1099 | if (do_rapl & RAPL_PKG) { |
| 1100 | if (get_msr(cpu, MSR_PKG_ENERGY_STATUS, &msr)) |
| 1101 | return -13; |
| 1102 | p->energy_pkg = msr & 0xFFFFFFFF; |
| 1103 | } |
| 1104 | if (do_rapl & RAPL_CORES) { |
| 1105 | if (get_msr(cpu, MSR_PP0_ENERGY_STATUS, &msr)) |
| 1106 | return -14; |
| 1107 | p->energy_cores = msr & 0xFFFFFFFF; |
| 1108 | } |
| 1109 | if (do_rapl & RAPL_DRAM) { |
| 1110 | if (get_msr(cpu, MSR_DRAM_ENERGY_STATUS, &msr)) |
| 1111 | return -15; |
| 1112 | p->energy_dram = msr & 0xFFFFFFFF; |
| 1113 | } |
| 1114 | if (do_rapl & RAPL_GFX) { |
| 1115 | if (get_msr(cpu, MSR_PP1_ENERGY_STATUS, &msr)) |
| 1116 | return -16; |
| 1117 | p->energy_gfx = msr & 0xFFFFFFFF; |
| 1118 | } |
| 1119 | if (do_rapl & RAPL_PKG_PERF_STATUS) { |
| 1120 | if (get_msr(cpu, MSR_PKG_PERF_STATUS, &msr)) |
| 1121 | return -16; |
| 1122 | p->rapl_pkg_perf_status = msr & 0xFFFFFFFF; |
| 1123 | } |
| 1124 | if (do_rapl & RAPL_DRAM_PERF_STATUS) { |
| 1125 | if (get_msr(cpu, MSR_DRAM_PERF_STATUS, &msr)) |
| 1126 | return -16; |
| 1127 | p->rapl_dram_perf_status = msr & 0xFFFFFFFF; |
| 1128 | } |
| 1129 | if (do_ptm) { |
| 1130 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr)) |
| 1131 | return -17; |
| 1132 | p->pkg_temp_c = tcc_activation_temp - ((msr >> 16) & 0x7F); |
| 1133 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1134 | return 0; |
| 1135 | } |
| 1136 | |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1137 | /* |
| 1138 | * MSR_PKG_CST_CONFIG_CONTROL decoding for pkg_cstate_limit: |
| 1139 | * If you change the values, note they are used both in comparisons |
| 1140 | * (>= PCL__7) and to index pkg_cstate_limit_strings[]. |
| 1141 | */ |
| 1142 | |
| 1143 | #define PCLUKN 0 /* Unknown */ |
| 1144 | #define PCLRSV 1 /* Reserved */ |
| 1145 | #define PCL__0 2 /* PC0 */ |
| 1146 | #define PCL__1 3 /* PC1 */ |
| 1147 | #define PCL__2 4 /* PC2 */ |
| 1148 | #define PCL__3 5 /* PC3 */ |
| 1149 | #define PCL__4 6 /* PC4 */ |
| 1150 | #define PCL__6 7 /* PC6 */ |
| 1151 | #define PCL_6N 8 /* PC6 No Retention */ |
| 1152 | #define PCL_6R 9 /* PC6 Retention */ |
| 1153 | #define PCL__7 10 /* PC7 */ |
| 1154 | #define PCL_7S 11 /* PC7 Shrink */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1155 | #define PCL__8 12 /* PC8 */ |
| 1156 | #define PCL__9 13 /* PC9 */ |
| 1157 | #define PCLUNL 14 /* Unlimited */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1158 | |
| 1159 | int pkg_cstate_limit = PCLUKN; |
| 1160 | char *pkg_cstate_limit_strings[] = { "reserved", "unknown", "pc0", "pc1", "pc2", |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1161 | "pc3", "pc4", "pc6", "pc6n", "pc6r", "pc7", "pc7s", "pc8", "pc9", "unlimited"}; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1162 | |
Len Brown | e9257f5 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 1163 | 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}; |
| 1164 | 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}; |
| 1165 | 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}; |
| 1166 | int slv_pkg_cstate_limits[16] = {PCL__0, PCL__1, PCLRSV, PCLRSV, PCL__4, PCLRSV, PCL__6, PCL__7, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; |
| 1167 | int amt_pkg_cstate_limits[16] = {PCL__0, PCL__1, PCL__2, PCLRSV, PCLRSV, PCLRSV, PCL__6, PCL__7, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; |
| 1168 | 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 | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1169 | |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 1170 | |
| 1171 | static void |
| 1172 | calculate_tsc_tweak() |
| 1173 | { |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 1174 | tsc_tweak = base_hz / tsc_hz; |
| 1175 | } |
| 1176 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1177 | static void |
| 1178 | dump_nhm_platform_info(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1179 | { |
| 1180 | unsigned long long msr; |
| 1181 | unsigned int ratio; |
| 1182 | |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 1183 | get_msr(base_cpu, MSR_PLATFORM_INFO, &msr); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1184 | |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 1185 | fprintf(stderr, "cpu%d: MSR_PLATFORM_INFO: 0x%08llx\n", base_cpu, msr); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1186 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1187 | ratio = (msr >> 40) & 0xFF; |
Len Brown | 8f61f35 | 2015-03-23 18:36:57 -0400 | [diff] [blame] | 1188 | fprintf(stderr, "%d * %.0f = %.0f MHz max efficiency frequency\n", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1189 | ratio, bclk, ratio * bclk); |
| 1190 | |
| 1191 | ratio = (msr >> 8) & 0xFF; |
Len Brown | 8f61f35 | 2015-03-23 18:36:57 -0400 | [diff] [blame] | 1192 | fprintf(stderr, "%d * %.0f = %.0f MHz base frequency\n", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1193 | ratio, bclk, ratio * bclk); |
| 1194 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1195 | get_msr(base_cpu, MSR_IA32_POWER_CTL, &msr); |
Len Brown | bfae205 | 2015-06-17 12:27:21 -0400 | [diff] [blame] | 1196 | fprintf(stderr, "cpu%d: MSR_IA32_POWER_CTL: 0x%08llx (C1E auto-promotion: %sabled)\n", |
| 1197 | base_cpu, msr, msr & 0x2 ? "EN" : "DIS"); |
Len Brown | 6792041 | 2013-01-31 15:22:15 -0500 | [diff] [blame] | 1198 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1199 | return; |
| 1200 | } |
| 1201 | |
| 1202 | static void |
| 1203 | dump_hsw_turbo_ratio_limits(void) |
| 1204 | { |
| 1205 | unsigned long long msr; |
| 1206 | unsigned int ratio; |
| 1207 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1208 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT2, &msr); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1209 | |
Len Brown | bfae205 | 2015-06-17 12:27:21 -0400 | [diff] [blame] | 1210 | fprintf(stderr, "cpu%d: MSR_TURBO_RATIO_LIMIT2: 0x%08llx\n", base_cpu, msr); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1211 | |
| 1212 | ratio = (msr >> 8) & 0xFF; |
| 1213 | if (ratio) |
| 1214 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 18 active cores\n", |
| 1215 | ratio, bclk, ratio * bclk); |
| 1216 | |
| 1217 | ratio = (msr >> 0) & 0xFF; |
| 1218 | if (ratio) |
| 1219 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 17 active cores\n", |
| 1220 | ratio, bclk, ratio * bclk); |
| 1221 | return; |
| 1222 | } |
| 1223 | |
| 1224 | static void |
| 1225 | dump_ivt_turbo_ratio_limits(void) |
| 1226 | { |
| 1227 | unsigned long long msr; |
| 1228 | unsigned int ratio; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1229 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1230 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT1, &msr); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1231 | |
Len Brown | bfae205 | 2015-06-17 12:27:21 -0400 | [diff] [blame] | 1232 | fprintf(stderr, "cpu%d: MSR_TURBO_RATIO_LIMIT1: 0x%08llx\n", base_cpu, msr); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1233 | |
| 1234 | ratio = (msr >> 56) & 0xFF; |
| 1235 | if (ratio) |
| 1236 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 16 active cores\n", |
| 1237 | ratio, bclk, ratio * bclk); |
| 1238 | |
| 1239 | ratio = (msr >> 48) & 0xFF; |
| 1240 | if (ratio) |
| 1241 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 15 active cores\n", |
| 1242 | ratio, bclk, ratio * bclk); |
| 1243 | |
| 1244 | ratio = (msr >> 40) & 0xFF; |
| 1245 | if (ratio) |
| 1246 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 14 active cores\n", |
| 1247 | ratio, bclk, ratio * bclk); |
| 1248 | |
| 1249 | ratio = (msr >> 32) & 0xFF; |
| 1250 | if (ratio) |
| 1251 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 13 active cores\n", |
| 1252 | ratio, bclk, ratio * bclk); |
| 1253 | |
| 1254 | ratio = (msr >> 24) & 0xFF; |
| 1255 | if (ratio) |
| 1256 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 12 active cores\n", |
| 1257 | ratio, bclk, ratio * bclk); |
| 1258 | |
| 1259 | ratio = (msr >> 16) & 0xFF; |
| 1260 | if (ratio) |
| 1261 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 11 active cores\n", |
| 1262 | ratio, bclk, ratio * bclk); |
| 1263 | |
| 1264 | ratio = (msr >> 8) & 0xFF; |
| 1265 | if (ratio) |
| 1266 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 10 active cores\n", |
| 1267 | ratio, bclk, ratio * bclk); |
| 1268 | |
| 1269 | ratio = (msr >> 0) & 0xFF; |
| 1270 | if (ratio) |
| 1271 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 9 active cores\n", |
| 1272 | ratio, bclk, ratio * bclk); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1273 | return; |
| 1274 | } |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1275 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1276 | static void |
| 1277 | dump_nhm_turbo_ratio_limits(void) |
| 1278 | { |
| 1279 | unsigned long long msr; |
| 1280 | unsigned int ratio; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1281 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1282 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT, &msr); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1283 | |
Len Brown | bfae205 | 2015-06-17 12:27:21 -0400 | [diff] [blame] | 1284 | fprintf(stderr, "cpu%d: MSR_TURBO_RATIO_LIMIT: 0x%08llx\n", base_cpu, msr); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1285 | |
| 1286 | ratio = (msr >> 56) & 0xFF; |
| 1287 | if (ratio) |
| 1288 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 8 active cores\n", |
| 1289 | ratio, bclk, ratio * bclk); |
| 1290 | |
| 1291 | ratio = (msr >> 48) & 0xFF; |
| 1292 | if (ratio) |
| 1293 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 7 active cores\n", |
| 1294 | ratio, bclk, ratio * bclk); |
| 1295 | |
| 1296 | ratio = (msr >> 40) & 0xFF; |
| 1297 | if (ratio) |
| 1298 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 6 active cores\n", |
| 1299 | ratio, bclk, ratio * bclk); |
| 1300 | |
| 1301 | ratio = (msr >> 32) & 0xFF; |
| 1302 | if (ratio) |
| 1303 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 5 active cores\n", |
| 1304 | ratio, bclk, ratio * bclk); |
| 1305 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1306 | ratio = (msr >> 24) & 0xFF; |
| 1307 | if (ratio) |
| 1308 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 4 active cores\n", |
| 1309 | ratio, bclk, ratio * bclk); |
| 1310 | |
| 1311 | ratio = (msr >> 16) & 0xFF; |
| 1312 | if (ratio) |
| 1313 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 3 active cores\n", |
| 1314 | ratio, bclk, ratio * bclk); |
| 1315 | |
| 1316 | ratio = (msr >> 8) & 0xFF; |
| 1317 | if (ratio) |
| 1318 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 2 active cores\n", |
| 1319 | ratio, bclk, ratio * bclk); |
| 1320 | |
| 1321 | ratio = (msr >> 0) & 0xFF; |
| 1322 | if (ratio) |
| 1323 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 1 active cores\n", |
| 1324 | ratio, bclk, ratio * bclk); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1325 | return; |
| 1326 | } |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 1327 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1328 | static void |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1329 | dump_knl_turbo_ratio_limits(void) |
| 1330 | { |
| 1331 | int cores; |
| 1332 | unsigned int ratio; |
| 1333 | unsigned long long msr; |
| 1334 | int delta_cores; |
| 1335 | int delta_ratio; |
| 1336 | int i; |
| 1337 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1338 | get_msr(base_cpu, MSR_NHM_TURBO_RATIO_LIMIT, &msr); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1339 | |
Len Brown | bfae205 | 2015-06-17 12:27:21 -0400 | [diff] [blame] | 1340 | fprintf(stderr, "cpu%d: MSR_NHM_TURBO_RATIO_LIMIT: 0x%08llx\n", |
| 1341 | base_cpu, msr); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1342 | |
| 1343 | /** |
| 1344 | * Turbo encoding in KNL is as follows: |
| 1345 | * [7:0] -- Base value of number of active cores of bucket 1. |
| 1346 | * [15:8] -- Base value of freq ratio of bucket 1. |
| 1347 | * [20:16] -- +ve delta of number of active cores of bucket 2. |
| 1348 | * i.e. active cores of bucket 2 = |
| 1349 | * active cores of bucket 1 + delta |
| 1350 | * [23:21] -- Negative delta of freq ratio of bucket 2. |
| 1351 | * i.e. freq ratio of bucket 2 = |
| 1352 | * freq ratio of bucket 1 - delta |
| 1353 | * [28:24]-- +ve delta of number of active cores of bucket 3. |
| 1354 | * [31:29]-- -ve delta of freq ratio of bucket 3. |
| 1355 | * [36:32]-- +ve delta of number of active cores of bucket 4. |
| 1356 | * [39:37]-- -ve delta of freq ratio of bucket 4. |
| 1357 | * [44:40]-- +ve delta of number of active cores of bucket 5. |
| 1358 | * [47:45]-- -ve delta of freq ratio of bucket 5. |
| 1359 | * [52:48]-- +ve delta of number of active cores of bucket 6. |
| 1360 | * [55:53]-- -ve delta of freq ratio of bucket 6. |
| 1361 | * [60:56]-- +ve delta of number of active cores of bucket 7. |
| 1362 | * [63:61]-- -ve delta of freq ratio of bucket 7. |
| 1363 | */ |
| 1364 | cores = msr & 0xFF; |
| 1365 | ratio = (msr >> 8) && 0xFF; |
| 1366 | if (ratio > 0) |
| 1367 | fprintf(stderr, |
| 1368 | "%d * %.0f = %.0f MHz max turbo %d active cores\n", |
| 1369 | ratio, bclk, ratio * bclk, cores); |
| 1370 | |
| 1371 | for (i = 16; i < 64; i = i + 8) { |
| 1372 | delta_cores = (msr >> i) & 0x1F; |
| 1373 | delta_ratio = (msr >> (i + 5)) && 0x7; |
| 1374 | if (!delta_cores || !delta_ratio) |
| 1375 | return; |
| 1376 | cores = cores + delta_cores; |
| 1377 | ratio = ratio - delta_ratio; |
| 1378 | |
| 1379 | /** -ve ratios will make successive ratio calculations |
| 1380 | * negative. Hence return instead of carrying on. |
| 1381 | */ |
| 1382 | if (ratio > 0) |
| 1383 | fprintf(stderr, |
| 1384 | "%d * %.0f = %.0f MHz max turbo %d active cores\n", |
| 1385 | ratio, bclk, ratio * bclk, cores); |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | static void |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1390 | dump_nhm_cst_cfg(void) |
| 1391 | { |
| 1392 | unsigned long long msr; |
| 1393 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1394 | get_msr(base_cpu, MSR_NHM_SNB_PKG_CST_CFG_CTL, &msr); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1395 | |
| 1396 | #define SNB_C1_AUTO_UNDEMOTE (1UL << 27) |
| 1397 | #define SNB_C3_AUTO_UNDEMOTE (1UL << 28) |
| 1398 | |
Len Brown | bfae205 | 2015-06-17 12:27:21 -0400 | [diff] [blame] | 1399 | fprintf(stderr, "cpu%d: MSR_NHM_SNB_PKG_CST_CFG_CTL: 0x%08llx", base_cpu, msr); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1400 | |
| 1401 | fprintf(stderr, " (%s%s%s%s%slocked: pkg-cstate-limit=%d: %s)\n", |
| 1402 | (msr & SNB_C3_AUTO_UNDEMOTE) ? "UNdemote-C3, " : "", |
| 1403 | (msr & SNB_C1_AUTO_UNDEMOTE) ? "UNdemote-C1, " : "", |
| 1404 | (msr & NHM_C3_AUTO_DEMOTE) ? "demote-C3, " : "", |
| 1405 | (msr & NHM_C1_AUTO_DEMOTE) ? "demote-C1, " : "", |
| 1406 | (msr & (1 << 15)) ? "" : "UN", |
| 1407 | (unsigned int)msr & 7, |
| 1408 | pkg_cstate_limit_strings[pkg_cstate_limit]); |
| 1409 | return; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1410 | } |
| 1411 | |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 1412 | static void |
| 1413 | dump_config_tdp(void) |
| 1414 | { |
| 1415 | unsigned long long msr; |
| 1416 | |
| 1417 | get_msr(base_cpu, MSR_CONFIG_TDP_NOMINAL, &msr); |
| 1418 | fprintf(stderr, "cpu%d: MSR_CONFIG_TDP_NOMINAL: 0x%08llx", base_cpu, msr); |
| 1419 | fprintf(stderr, " (base_ratio=%d)\n", (unsigned int)msr & 0xEF); |
| 1420 | |
| 1421 | get_msr(base_cpu, MSR_CONFIG_TDP_LEVEL_1, &msr); |
| 1422 | fprintf(stderr, "cpu%d: MSR_CONFIG_TDP_LEVEL_1: 0x%08llx (", base_cpu, msr); |
| 1423 | if (msr) { |
| 1424 | fprintf(stderr, "PKG_MIN_PWR_LVL1=%d ", (unsigned int)(msr >> 48) & 0xEFFF); |
| 1425 | fprintf(stderr, "PKG_MAX_PWR_LVL1=%d ", (unsigned int)(msr >> 32) & 0xEFFF); |
| 1426 | fprintf(stderr, "LVL1_RATIO=%d ", (unsigned int)(msr >> 16) & 0xEF); |
| 1427 | fprintf(stderr, "PKG_TDP_LVL1=%d", (unsigned int)(msr) & 0xEFFF); |
| 1428 | } |
| 1429 | fprintf(stderr, ")\n"); |
| 1430 | |
| 1431 | get_msr(base_cpu, MSR_CONFIG_TDP_LEVEL_2, &msr); |
| 1432 | fprintf(stderr, "cpu%d: MSR_CONFIG_TDP_LEVEL_2: 0x%08llx (", base_cpu, msr); |
| 1433 | if (msr) { |
| 1434 | fprintf(stderr, "PKG_MIN_PWR_LVL2=%d ", (unsigned int)(msr >> 48) & 0xEFFF); |
| 1435 | fprintf(stderr, "PKG_MAX_PWR_LVL2=%d ", (unsigned int)(msr >> 32) & 0xEFFF); |
| 1436 | fprintf(stderr, "LVL2_RATIO=%d ", (unsigned int)(msr >> 16) & 0xEF); |
| 1437 | fprintf(stderr, "PKG_TDP_LVL2=%d", (unsigned int)(msr) & 0xEFFF); |
| 1438 | } |
| 1439 | fprintf(stderr, ")\n"); |
| 1440 | |
| 1441 | get_msr(base_cpu, MSR_CONFIG_TDP_CONTROL, &msr); |
| 1442 | fprintf(stderr, "cpu%d: MSR_CONFIG_TDP_CONTROL: 0x%08llx (", base_cpu, msr); |
| 1443 | if ((msr) & 0x3) |
| 1444 | fprintf(stderr, "TDP_LEVEL=%d ", (unsigned int)(msr) & 0x3); |
| 1445 | fprintf(stderr, " lock=%d", (unsigned int)(msr >> 31) & 1); |
| 1446 | fprintf(stderr, ")\n"); |
| 1447 | |
| 1448 | get_msr(base_cpu, MSR_TURBO_ACTIVATION_RATIO, &msr); |
| 1449 | fprintf(stderr, "cpu%d: MSR_TURBO_ACTIVATION_RATIO: 0x%08llx (", base_cpu, msr); |
Len Brown | 759d2a9 | 2015-10-22 02:42:12 -0400 | [diff] [blame] | 1450 | fprintf(stderr, "MAX_NON_TURBO_RATIO=%d", (unsigned int)(msr) & 0x7F); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 1451 | fprintf(stderr, " lock=%d", (unsigned int)(msr >> 31) & 1); |
| 1452 | fprintf(stderr, ")\n"); |
| 1453 | } |
| 1454 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1455 | void free_all_buffers(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1456 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1457 | CPU_FREE(cpu_present_set); |
| 1458 | cpu_present_set = NULL; |
| 1459 | cpu_present_set = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1460 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1461 | CPU_FREE(cpu_affinity_set); |
| 1462 | cpu_affinity_set = NULL; |
| 1463 | cpu_affinity_setsize = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1464 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1465 | free(thread_even); |
| 1466 | free(core_even); |
| 1467 | free(package_even); |
| 1468 | |
| 1469 | thread_even = NULL; |
| 1470 | core_even = NULL; |
| 1471 | package_even = NULL; |
| 1472 | |
| 1473 | free(thread_odd); |
| 1474 | free(core_odd); |
| 1475 | free(package_odd); |
| 1476 | |
| 1477 | thread_odd = NULL; |
| 1478 | core_odd = NULL; |
| 1479 | package_odd = NULL; |
| 1480 | |
| 1481 | free(output_buffer); |
| 1482 | output_buffer = NULL; |
| 1483 | outp = NULL; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1484 | } |
| 1485 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1486 | /* |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 1487 | * Open a file, and exit on failure |
| 1488 | */ |
| 1489 | FILE *fopen_or_die(const char *path, const char *mode) |
| 1490 | { |
| 1491 | FILE *filep = fopen(path, "r"); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 1492 | if (!filep) |
| 1493 | err(1, "%s: open failed", path); |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 1494 | return filep; |
| 1495 | } |
| 1496 | |
| 1497 | /* |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 1498 | * Parse a file containing a single int. |
| 1499 | */ |
| 1500 | int parse_int_file(const char *fmt, ...) |
| 1501 | { |
| 1502 | va_list args; |
| 1503 | char path[PATH_MAX]; |
| 1504 | FILE *filep; |
| 1505 | int value; |
| 1506 | |
| 1507 | va_start(args, fmt); |
| 1508 | vsnprintf(path, sizeof(path), fmt, args); |
| 1509 | va_end(args); |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 1510 | filep = fopen_or_die(path, "r"); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 1511 | if (fscanf(filep, "%d", &value) != 1) |
| 1512 | err(1, "%s: failed to parse number from file", path); |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 1513 | fclose(filep); |
| 1514 | return value; |
| 1515 | } |
| 1516 | |
| 1517 | /* |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 1518 | * get_cpu_position_in_core(cpu) |
| 1519 | * return the position of the CPU among its HT siblings in the core |
| 1520 | * return -1 if the sibling is not in list |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1521 | */ |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 1522 | int get_cpu_position_in_core(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1523 | { |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 1524 | char path[64]; |
| 1525 | FILE *filep; |
| 1526 | int this_cpu; |
| 1527 | char character; |
| 1528 | int i; |
| 1529 | |
| 1530 | sprintf(path, |
| 1531 | "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", |
| 1532 | cpu); |
| 1533 | filep = fopen(path, "r"); |
| 1534 | if (filep == NULL) { |
| 1535 | perror(path); |
| 1536 | exit(1); |
| 1537 | } |
| 1538 | |
| 1539 | for (i = 0; i < topo.num_threads_per_core; i++) { |
| 1540 | fscanf(filep, "%d", &this_cpu); |
| 1541 | if (this_cpu == cpu) { |
| 1542 | fclose(filep); |
| 1543 | return i; |
| 1544 | } |
| 1545 | |
| 1546 | /* Account for no separator after last thread*/ |
| 1547 | if (i != (topo.num_threads_per_core - 1)) |
| 1548 | fscanf(filep, "%c", &character); |
| 1549 | } |
| 1550 | |
| 1551 | fclose(filep); |
| 1552 | return -1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1553 | } |
| 1554 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1555 | /* |
| 1556 | * cpu_is_first_core_in_package(cpu) |
| 1557 | * return 1 if given CPU is 1st core in package |
| 1558 | */ |
| 1559 | int cpu_is_first_core_in_package(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1560 | { |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 1561 | 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] | 1562 | } |
| 1563 | |
| 1564 | int get_physical_package_id(int cpu) |
| 1565 | { |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 1566 | 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] | 1567 | } |
| 1568 | |
| 1569 | int get_core_id(int cpu) |
| 1570 | { |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 1571 | 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] | 1572 | } |
| 1573 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1574 | int get_num_ht_siblings(int cpu) |
| 1575 | { |
| 1576 | char path[80]; |
| 1577 | FILE *filep; |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 1578 | int sib1; |
| 1579 | int matches = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1580 | char character; |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 1581 | char str[100]; |
| 1582 | char *ch; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1583 | |
| 1584 | sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu); |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 1585 | filep = fopen_or_die(path, "r"); |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 1586 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1587 | /* |
| 1588 | * file format: |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 1589 | * A ',' separated or '-' separated set of numbers |
| 1590 | * (eg 1-2 or 1,3,4,5) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1591 | */ |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 1592 | fscanf(filep, "%d%c\n", &sib1, &character); |
| 1593 | fseek(filep, 0, SEEK_SET); |
| 1594 | fgets(str, 100, filep); |
| 1595 | ch = strchr(str, character); |
| 1596 | while (ch != NULL) { |
| 1597 | matches++; |
| 1598 | ch = strchr(ch+1, character); |
| 1599 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1600 | |
| 1601 | fclose(filep); |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 1602 | return matches+1; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1603 | } |
| 1604 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1605 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1606 | * run func(thread, core, package) in topology order |
| 1607 | * skip non-present cpus |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1608 | */ |
| 1609 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1610 | int for_all_cpus_2(int (func)(struct thread_data *, struct core_data *, |
| 1611 | struct pkg_data *, struct thread_data *, struct core_data *, |
| 1612 | struct pkg_data *), struct thread_data *thread_base, |
| 1613 | struct core_data *core_base, struct pkg_data *pkg_base, |
| 1614 | struct thread_data *thread_base2, struct core_data *core_base2, |
| 1615 | struct pkg_data *pkg_base2) |
| 1616 | { |
| 1617 | int retval, pkg_no, core_no, thread_no; |
| 1618 | |
| 1619 | for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { |
| 1620 | for (core_no = 0; core_no < topo.num_cores_per_pkg; ++core_no) { |
| 1621 | for (thread_no = 0; thread_no < |
| 1622 | topo.num_threads_per_core; ++thread_no) { |
| 1623 | struct thread_data *t, *t2; |
| 1624 | struct core_data *c, *c2; |
| 1625 | struct pkg_data *p, *p2; |
| 1626 | |
| 1627 | t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); |
| 1628 | |
| 1629 | if (cpu_is_not_present(t->cpu_id)) |
| 1630 | continue; |
| 1631 | |
| 1632 | t2 = GET_THREAD(thread_base2, thread_no, core_no, pkg_no); |
| 1633 | |
| 1634 | c = GET_CORE(core_base, core_no, pkg_no); |
| 1635 | c2 = GET_CORE(core_base2, core_no, pkg_no); |
| 1636 | |
| 1637 | p = GET_PKG(pkg_base, pkg_no); |
| 1638 | p2 = GET_PKG(pkg_base2, pkg_no); |
| 1639 | |
| 1640 | retval = func(t, c, p, t2, c2, p2); |
| 1641 | if (retval) |
| 1642 | return retval; |
| 1643 | } |
| 1644 | } |
| 1645 | } |
| 1646 | return 0; |
| 1647 | } |
| 1648 | |
| 1649 | /* |
| 1650 | * run func(cpu) on every cpu in /proc/stat |
| 1651 | * return max_cpu number |
| 1652 | */ |
| 1653 | int for_all_proc_cpus(int (func)(int)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1654 | { |
| 1655 | FILE *fp; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1656 | int cpu_num; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1657 | int retval; |
| 1658 | |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 1659 | fp = fopen_or_die(proc_stat, "r"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1660 | |
| 1661 | 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] | 1662 | if (retval != 0) |
| 1663 | err(1, "%s: failed to parse format", proc_stat); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1664 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1665 | while (1) { |
| 1666 | 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] | 1667 | if (retval != 1) |
| 1668 | break; |
| 1669 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1670 | retval = func(cpu_num); |
| 1671 | if (retval) { |
| 1672 | fclose(fp); |
| 1673 | return(retval); |
| 1674 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1675 | } |
| 1676 | fclose(fp); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1677 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | void re_initialize(void) |
| 1681 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1682 | free_all_buffers(); |
| 1683 | setup_all_buffers(); |
| 1684 | printf("turbostat: re-initialized with num_cpus %d\n", topo.num_cpus); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1685 | } |
| 1686 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1687 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1688 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1689 | * count_cpus() |
| 1690 | * remember the last one seen, it will be the max |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1691 | */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1692 | int count_cpus(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1693 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1694 | if (topo.max_cpu_num < cpu) |
| 1695 | topo.max_cpu_num = cpu; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1696 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1697 | topo.num_cpus += 1; |
| 1698 | return 0; |
| 1699 | } |
| 1700 | int mark_cpu_present(int cpu) |
| 1701 | { |
| 1702 | CPU_SET_S(cpu, cpu_present_setsize, cpu_present_set); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 1703 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | void turbostat_loop() |
| 1707 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1708 | int retval; |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 1709 | int restarted = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1710 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1711 | restart: |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 1712 | restarted++; |
| 1713 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1714 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 1715 | if (retval < -1) { |
| 1716 | exit(retval); |
| 1717 | } else if (retval == -1) { |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 1718 | if (restarted > 1) { |
| 1719 | exit(retval); |
| 1720 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1721 | re_initialize(); |
| 1722 | goto restart; |
| 1723 | } |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 1724 | restarted = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1725 | gettimeofday(&tv_even, (struct timezone *)NULL); |
| 1726 | |
| 1727 | while (1) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1728 | if (for_all_proc_cpus(cpu_is_not_present)) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1729 | re_initialize(); |
| 1730 | goto restart; |
| 1731 | } |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 1732 | nanosleep(&interval_ts, NULL); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1733 | retval = for_all_cpus(get_counters, ODD_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 1734 | if (retval < -1) { |
| 1735 | exit(retval); |
| 1736 | } else if (retval == -1) { |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 1737 | re_initialize(); |
| 1738 | goto restart; |
| 1739 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1740 | gettimeofday(&tv_odd, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1741 | timersub(&tv_odd, &tv_even, &tv_delta); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1742 | for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS); |
| 1743 | compute_average(EVEN_COUNTERS); |
| 1744 | format_all_counters(EVEN_COUNTERS); |
| 1745 | flush_stdout(); |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 1746 | nanosleep(&interval_ts, NULL); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1747 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 1748 | if (retval < -1) { |
| 1749 | exit(retval); |
| 1750 | } else if (retval == -1) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1751 | re_initialize(); |
| 1752 | goto restart; |
| 1753 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1754 | gettimeofday(&tv_even, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1755 | timersub(&tv_even, &tv_odd, &tv_delta); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1756 | for_all_cpus_2(delta_cpu, EVEN_COUNTERS, ODD_COUNTERS); |
| 1757 | compute_average(ODD_COUNTERS); |
| 1758 | format_all_counters(ODD_COUNTERS); |
| 1759 | flush_stdout(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | void check_dev_msr() |
| 1764 | { |
| 1765 | struct stat sb; |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1766 | char pathname[32]; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1767 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1768 | sprintf(pathname, "/dev/cpu/%d/msr", base_cpu); |
| 1769 | if (stat(pathname, &sb)) |
Len Brown | a21d38c | 2015-03-24 16:37:35 -0400 | [diff] [blame] | 1770 | if (system("/sbin/modprobe msr > /dev/null 2>&1")) |
| 1771 | err(-5, "no /dev/cpu/0/msr, Try \"# modprobe msr\" "); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1772 | } |
| 1773 | |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 1774 | void check_permissions() |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1775 | { |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 1776 | struct __user_cap_header_struct cap_header_data; |
| 1777 | cap_user_header_t cap_header = &cap_header_data; |
| 1778 | struct __user_cap_data_struct cap_data_data; |
| 1779 | cap_user_data_t cap_data = &cap_data_data; |
| 1780 | extern int capget(cap_user_header_t hdrp, cap_user_data_t datap); |
| 1781 | int do_exit = 0; |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1782 | char pathname[32]; |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 1783 | |
| 1784 | /* check for CAP_SYS_RAWIO */ |
| 1785 | cap_header->pid = getpid(); |
| 1786 | cap_header->version = _LINUX_CAPABILITY_VERSION; |
| 1787 | if (capget(cap_header, cap_data) < 0) |
| 1788 | err(-6, "capget(2) failed"); |
| 1789 | |
| 1790 | if ((cap_data->effective & (1 << CAP_SYS_RAWIO)) == 0) { |
| 1791 | do_exit++; |
| 1792 | warnx("capget(CAP_SYS_RAWIO) failed," |
| 1793 | " try \"# setcap cap_sys_rawio=ep %s\"", progname); |
| 1794 | } |
| 1795 | |
| 1796 | /* test file permissions */ |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1797 | sprintf(pathname, "/dev/cpu/%d/msr", base_cpu); |
| 1798 | if (euidaccess(pathname, R_OK)) { |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 1799 | do_exit++; |
| 1800 | warn("/dev/cpu/0/msr open failed, try chown or chmod +r /dev/cpu/*/msr"); |
| 1801 | } |
| 1802 | |
| 1803 | /* if all else fails, thell them to be root */ |
| 1804 | if (do_exit) |
| 1805 | if (getuid() != 0) |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 1806 | warnx("... or simply run as root"); |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 1807 | |
| 1808 | if (do_exit) |
| 1809 | exit(-6); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1810 | } |
| 1811 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 1812 | /* |
| 1813 | * NHM adds support for additional MSRs: |
| 1814 | * |
| 1815 | * MSR_SMI_COUNT 0x00000034 |
| 1816 | * |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 1817 | * MSR_PLATFORM_INFO 0x000000ce |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 1818 | * MSR_NHM_SNB_PKG_CST_CFG_CTL 0x000000e2 |
| 1819 | * |
| 1820 | * MSR_PKG_C3_RESIDENCY 0x000003f8 |
| 1821 | * MSR_PKG_C6_RESIDENCY 0x000003f9 |
| 1822 | * MSR_CORE_C3_RESIDENCY 0x000003fc |
| 1823 | * MSR_CORE_C6_RESIDENCY 0x000003fd |
| 1824 | * |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1825 | * Side effect: |
| 1826 | * sets global pkg_cstate_limit to decode MSR_NHM_SNB_PKG_CST_CFG_CTL |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 1827 | */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1828 | int probe_nhm_msrs(unsigned int family, unsigned int model) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1829 | { |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1830 | unsigned long long msr; |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 1831 | unsigned int base_ratio; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1832 | int *pkg_cstate_limits; |
| 1833 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1834 | if (!genuine_intel) |
| 1835 | return 0; |
| 1836 | |
| 1837 | if (family != 6) |
| 1838 | return 0; |
| 1839 | |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 1840 | bclk = discover_bclk(family, model); |
| 1841 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1842 | switch (model) { |
| 1843 | case 0x1A: /* Core i7, Xeon 5500 series - Bloomfield, Gainstown NHM-EP */ |
| 1844 | case 0x1E: /* Core i7 and i5 Processor - Clarksfield, Lynnfield, Jasper Forest */ |
| 1845 | case 0x1F: /* Core i7 and i5 Processor - Nehalem */ |
| 1846 | case 0x25: /* Westmere Client - Clarkdale, Arrandale */ |
| 1847 | case 0x2C: /* Westmere EP - Gulftown */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1848 | case 0x2E: /* Nehalem-EX Xeon - Beckton */ |
| 1849 | case 0x2F: /* Westmere-EX Xeon - Eagleton */ |
| 1850 | pkg_cstate_limits = nhm_pkg_cstate_limits; |
| 1851 | break; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1852 | case 0x2A: /* SNB */ |
| 1853 | case 0x2D: /* SNB Xeon */ |
Len Brown | 553575f | 2011-11-18 03:32:01 -0500 | [diff] [blame] | 1854 | case 0x3A: /* IVB */ |
Len Brown | 1300651 | 2012-09-26 18:11:31 -0400 | [diff] [blame] | 1855 | case 0x3E: /* IVB Xeon */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1856 | pkg_cstate_limits = snb_pkg_cstate_limits; |
| 1857 | break; |
Len Brown | 70b4340 | 2013-01-08 01:26:07 -0500 | [diff] [blame] | 1858 | case 0x3C: /* HSW */ |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 1859 | case 0x3F: /* HSX */ |
Len Brown | 70b4340 | 2013-01-08 01:26:07 -0500 | [diff] [blame] | 1860 | case 0x45: /* HSW */ |
Len Brown | 149c231 | 2013-03-15 10:58:02 -0400 | [diff] [blame] | 1861 | case 0x46: /* HSW */ |
Len Brown | 4e8e863f | 2014-02-27 23:28:53 -0500 | [diff] [blame] | 1862 | case 0x3D: /* BDW */ |
Len Brown | 48a0631 | 2015-02-10 15:38:04 -0500 | [diff] [blame] | 1863 | case 0x47: /* BDW */ |
Len Brown | 4e8e863f | 2014-02-27 23:28:53 -0500 | [diff] [blame] | 1864 | case 0x4F: /* BDX */ |
| 1865 | case 0x56: /* BDX-DE */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1866 | case 0x4E: /* SKL */ |
| 1867 | case 0x5E: /* SKL */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1868 | pkg_cstate_limits = hsw_pkg_cstate_limits; |
| 1869 | break; |
| 1870 | case 0x37: /* BYT */ |
| 1871 | case 0x4D: /* AVN */ |
| 1872 | pkg_cstate_limits = slv_pkg_cstate_limits; |
| 1873 | break; |
| 1874 | case 0x4C: /* AMT */ |
| 1875 | pkg_cstate_limits = amt_pkg_cstate_limits; |
| 1876 | break; |
| 1877 | case 0x57: /* PHI */ |
| 1878 | pkg_cstate_limits = phi_pkg_cstate_limits; |
| 1879 | break; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1880 | default: |
| 1881 | return 0; |
| 1882 | } |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 1883 | get_msr(base_cpu, MSR_NHM_SNB_PKG_CST_CFG_CTL, &msr); |
Len Brown | e9257f5 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 1884 | pkg_cstate_limit = pkg_cstate_limits[msr & 0xF]; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1885 | |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 1886 | get_msr(base_cpu, MSR_PLATFORM_INFO, &msr); |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 1887 | base_ratio = (msr >> 8) & 0xFF; |
| 1888 | |
| 1889 | base_hz = base_ratio * bclk * 1000000; |
| 1890 | has_base_hz = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1891 | return 1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1892 | } |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 1893 | int has_nhm_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 1894 | { |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 1895 | switch (model) { |
| 1896 | /* Nehalem compatible, but do not include turbo-ratio limit support */ |
| 1897 | case 0x2E: /* Nehalem-EX Xeon - Beckton */ |
| 1898 | case 0x2F: /* Westmere-EX Xeon - Eagleton */ |
| 1899 | return 0; |
| 1900 | default: |
| 1901 | return 1; |
| 1902 | } |
| 1903 | } |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1904 | int has_ivt_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 1905 | { |
| 1906 | if (!genuine_intel) |
| 1907 | return 0; |
| 1908 | |
| 1909 | if (family != 6) |
| 1910 | return 0; |
| 1911 | |
| 1912 | switch (model) { |
| 1913 | case 0x3E: /* IVB Xeon */ |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1914 | case 0x3F: /* HSW Xeon */ |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1915 | return 1; |
| 1916 | default: |
| 1917 | return 0; |
| 1918 | } |
| 1919 | } |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1920 | int has_hsw_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 1921 | { |
| 1922 | if (!genuine_intel) |
| 1923 | return 0; |
| 1924 | |
| 1925 | if (family != 6) |
| 1926 | return 0; |
| 1927 | |
| 1928 | switch (model) { |
| 1929 | case 0x3F: /* HSW Xeon */ |
| 1930 | return 1; |
| 1931 | default: |
| 1932 | return 0; |
| 1933 | } |
| 1934 | } |
| 1935 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1936 | int has_knl_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 1937 | { |
| 1938 | if (!genuine_intel) |
| 1939 | return 0; |
| 1940 | |
| 1941 | if (family != 6) |
| 1942 | return 0; |
| 1943 | |
| 1944 | switch (model) { |
| 1945 | case 0x57: /* Knights Landing */ |
| 1946 | return 1; |
| 1947 | default: |
| 1948 | return 0; |
| 1949 | } |
| 1950 | } |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 1951 | int has_config_tdp(unsigned int family, unsigned int model) |
| 1952 | { |
| 1953 | if (!genuine_intel) |
| 1954 | return 0; |
| 1955 | |
| 1956 | if (family != 6) |
| 1957 | return 0; |
| 1958 | |
| 1959 | switch (model) { |
| 1960 | case 0x3A: /* IVB */ |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 1961 | case 0x3C: /* HSW */ |
| 1962 | case 0x3F: /* HSX */ |
| 1963 | case 0x45: /* HSW */ |
| 1964 | case 0x46: /* HSW */ |
| 1965 | case 0x3D: /* BDW */ |
| 1966 | case 0x47: /* BDW */ |
| 1967 | case 0x4F: /* BDX */ |
| 1968 | case 0x56: /* BDX-DE */ |
| 1969 | case 0x4E: /* SKL */ |
| 1970 | case 0x5E: /* SKL */ |
| 1971 | |
| 1972 | case 0x57: /* Knights Landing */ |
| 1973 | return 1; |
| 1974 | default: |
| 1975 | return 0; |
| 1976 | } |
| 1977 | } |
| 1978 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 1979 | static void |
| 1980 | dump_cstate_pstate_config_info(family, model) |
| 1981 | { |
| 1982 | if (!do_nhm_platform_info) |
| 1983 | return; |
| 1984 | |
| 1985 | dump_nhm_platform_info(); |
| 1986 | |
| 1987 | if (has_hsw_turbo_ratio_limit(family, model)) |
| 1988 | dump_hsw_turbo_ratio_limits(); |
| 1989 | |
| 1990 | if (has_ivt_turbo_ratio_limit(family, model)) |
| 1991 | dump_ivt_turbo_ratio_limits(); |
| 1992 | |
| 1993 | if (has_nhm_turbo_ratio_limit(family, model)) |
| 1994 | dump_nhm_turbo_ratio_limits(); |
| 1995 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1996 | if (has_knl_turbo_ratio_limit(family, model)) |
| 1997 | dump_knl_turbo_ratio_limits(); |
| 1998 | |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 1999 | if (has_config_tdp(family, model)) |
| 2000 | dump_config_tdp(); |
| 2001 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2002 | dump_nhm_cst_cfg(); |
| 2003 | } |
| 2004 | |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2005 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2006 | /* |
| 2007 | * print_epb() |
| 2008 | * Decode the ENERGY_PERF_BIAS MSR |
| 2009 | */ |
| 2010 | int print_epb(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 2011 | { |
| 2012 | unsigned long long msr; |
| 2013 | char *epb_string; |
| 2014 | int cpu; |
| 2015 | |
| 2016 | if (!has_epb) |
| 2017 | return 0; |
| 2018 | |
| 2019 | cpu = t->cpu_id; |
| 2020 | |
| 2021 | /* EPB is per-package */ |
| 2022 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 2023 | return 0; |
| 2024 | |
| 2025 | if (cpu_migrate(cpu)) { |
| 2026 | fprintf(stderr, "Could not migrate to CPU %d\n", cpu); |
| 2027 | return -1; |
| 2028 | } |
| 2029 | |
| 2030 | if (get_msr(cpu, MSR_IA32_ENERGY_PERF_BIAS, &msr)) |
| 2031 | return 0; |
| 2032 | |
Len Brown | e9be7dd | 2015-05-26 12:19:37 -0400 | [diff] [blame] | 2033 | switch (msr & 0xF) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2034 | case ENERGY_PERF_BIAS_PERFORMANCE: |
| 2035 | epb_string = "performance"; |
| 2036 | break; |
| 2037 | case ENERGY_PERF_BIAS_NORMAL: |
| 2038 | epb_string = "balanced"; |
| 2039 | break; |
| 2040 | case ENERGY_PERF_BIAS_POWERSAVE: |
| 2041 | epb_string = "powersave"; |
| 2042 | break; |
| 2043 | default: |
| 2044 | epb_string = "custom"; |
| 2045 | break; |
| 2046 | } |
| 2047 | fprintf(stderr, "cpu%d: MSR_IA32_ENERGY_PERF_BIAS: 0x%08llx (%s)\n", cpu, msr, epb_string); |
| 2048 | |
| 2049 | return 0; |
| 2050 | } |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 2051 | /* |
| 2052 | * print_hwp() |
| 2053 | * Decode the MSR_HWP_CAPABILITIES |
| 2054 | */ |
| 2055 | int print_hwp(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 2056 | { |
| 2057 | unsigned long long msr; |
| 2058 | int cpu; |
| 2059 | |
| 2060 | if (!has_hwp) |
| 2061 | return 0; |
| 2062 | |
| 2063 | cpu = t->cpu_id; |
| 2064 | |
| 2065 | /* MSR_HWP_CAPABILITIES is per-package */ |
| 2066 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 2067 | return 0; |
| 2068 | |
| 2069 | if (cpu_migrate(cpu)) { |
| 2070 | fprintf(stderr, "Could not migrate to CPU %d\n", cpu); |
| 2071 | return -1; |
| 2072 | } |
| 2073 | |
| 2074 | if (get_msr(cpu, MSR_PM_ENABLE, &msr)) |
| 2075 | return 0; |
| 2076 | |
| 2077 | fprintf(stderr, "cpu%d: MSR_PM_ENABLE: 0x%08llx (%sHWP)\n", |
| 2078 | cpu, msr, (msr & (1 << 0)) ? "" : "No-"); |
| 2079 | |
| 2080 | /* MSR_PM_ENABLE[1] == 1 if HWP is enabled and MSRs visible */ |
| 2081 | if ((msr & (1 << 0)) == 0) |
| 2082 | return 0; |
| 2083 | |
| 2084 | if (get_msr(cpu, MSR_HWP_CAPABILITIES, &msr)) |
| 2085 | return 0; |
| 2086 | |
| 2087 | fprintf(stderr, "cpu%d: MSR_HWP_CAPABILITIES: 0x%08llx " |
| 2088 | "(high 0x%x guar 0x%x eff 0x%x low 0x%x)\n", |
| 2089 | cpu, msr, |
| 2090 | (unsigned int)HWP_HIGHEST_PERF(msr), |
| 2091 | (unsigned int)HWP_GUARANTEED_PERF(msr), |
| 2092 | (unsigned int)HWP_MOSTEFFICIENT_PERF(msr), |
| 2093 | (unsigned int)HWP_LOWEST_PERF(msr)); |
| 2094 | |
| 2095 | if (get_msr(cpu, MSR_HWP_REQUEST, &msr)) |
| 2096 | return 0; |
| 2097 | |
| 2098 | fprintf(stderr, "cpu%d: MSR_HWP_REQUEST: 0x%08llx " |
| 2099 | "(min 0x%x max 0x%x des 0x%x epp 0x%x window 0x%x pkg 0x%x)\n", |
| 2100 | cpu, msr, |
| 2101 | (unsigned int)(((msr) >> 0) & 0xff), |
| 2102 | (unsigned int)(((msr) >> 8) & 0xff), |
| 2103 | (unsigned int)(((msr) >> 16) & 0xff), |
| 2104 | (unsigned int)(((msr) >> 24) & 0xff), |
| 2105 | (unsigned int)(((msr) >> 32) & 0xff3), |
| 2106 | (unsigned int)(((msr) >> 42) & 0x1)); |
| 2107 | |
| 2108 | if (has_hwp_pkg) { |
| 2109 | if (get_msr(cpu, MSR_HWP_REQUEST_PKG, &msr)) |
| 2110 | return 0; |
| 2111 | |
| 2112 | fprintf(stderr, "cpu%d: MSR_HWP_REQUEST_PKG: 0x%08llx " |
| 2113 | "(min 0x%x max 0x%x des 0x%x epp 0x%x window 0x%x)\n", |
| 2114 | cpu, msr, |
| 2115 | (unsigned int)(((msr) >> 0) & 0xff), |
| 2116 | (unsigned int)(((msr) >> 8) & 0xff), |
| 2117 | (unsigned int)(((msr) >> 16) & 0xff), |
| 2118 | (unsigned int)(((msr) >> 24) & 0xff), |
| 2119 | (unsigned int)(((msr) >> 32) & 0xff3)); |
| 2120 | } |
| 2121 | if (has_hwp_notify) { |
| 2122 | if (get_msr(cpu, MSR_HWP_INTERRUPT, &msr)) |
| 2123 | return 0; |
| 2124 | |
| 2125 | fprintf(stderr, "cpu%d: MSR_HWP_INTERRUPT: 0x%08llx " |
| 2126 | "(%s_Guaranteed_Perf_Change, %s_Excursion_Min)\n", |
| 2127 | cpu, msr, |
| 2128 | ((msr) & 0x1) ? "EN" : "Dis", |
| 2129 | ((msr) & 0x2) ? "EN" : "Dis"); |
| 2130 | } |
| 2131 | if (get_msr(cpu, MSR_HWP_STATUS, &msr)) |
| 2132 | return 0; |
| 2133 | |
| 2134 | fprintf(stderr, "cpu%d: MSR_HWP_STATUS: 0x%08llx " |
| 2135 | "(%sGuaranteed_Perf_Change, %sExcursion_Min)\n", |
| 2136 | cpu, msr, |
| 2137 | ((msr) & 0x1) ? "" : "No-", |
| 2138 | ((msr) & 0x2) ? "" : "No-"); |
| 2139 | |
| 2140 | return 0; |
| 2141 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2142 | |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 2143 | /* |
| 2144 | * print_perf_limit() |
| 2145 | */ |
| 2146 | int print_perf_limit(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 2147 | { |
| 2148 | unsigned long long msr; |
| 2149 | int cpu; |
| 2150 | |
| 2151 | cpu = t->cpu_id; |
| 2152 | |
| 2153 | /* per-package */ |
| 2154 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 2155 | return 0; |
| 2156 | |
| 2157 | if (cpu_migrate(cpu)) { |
| 2158 | fprintf(stderr, "Could not migrate to CPU %d\n", cpu); |
| 2159 | return -1; |
| 2160 | } |
| 2161 | |
| 2162 | if (do_core_perf_limit_reasons) { |
| 2163 | get_msr(cpu, MSR_CORE_PERF_LIMIT_REASONS, &msr); |
| 2164 | fprintf(stderr, "cpu%d: MSR_CORE_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr); |
| 2165 | fprintf(stderr, " (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] | 2166 | (msr & 1 << 15) ? "bit15, " : "", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 2167 | (msr & 1 << 14) ? "bit14, " : "", |
Len Brown | e33cbe8 | 2015-03-13 16:30:57 -0400 | [diff] [blame] | 2168 | (msr & 1 << 13) ? "Transitions, " : "", |
| 2169 | (msr & 1 << 12) ? "MultiCoreTurbo, " : "", |
| 2170 | (msr & 1 << 11) ? "PkgPwrL2, " : "", |
| 2171 | (msr & 1 << 10) ? "PkgPwrL1, " : "", |
| 2172 | (msr & 1 << 9) ? "CorePwr, " : "", |
| 2173 | (msr & 1 << 8) ? "Amps, " : "", |
| 2174 | (msr & 1 << 6) ? "VR-Therm, " : "", |
| 2175 | (msr & 1 << 5) ? "Auto-HWP, " : "", |
| 2176 | (msr & 1 << 4) ? "Graphics, " : "", |
| 2177 | (msr & 1 << 2) ? "bit2, " : "", |
| 2178 | (msr & 1 << 1) ? "ThermStatus, " : "", |
| 2179 | (msr & 1 << 0) ? "PROCHOT, " : ""); |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 2180 | fprintf(stderr, " (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] | 2181 | (msr & 1 << 31) ? "bit31, " : "", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 2182 | (msr & 1 << 30) ? "bit30, " : "", |
Len Brown | e33cbe8 | 2015-03-13 16:30:57 -0400 | [diff] [blame] | 2183 | (msr & 1 << 29) ? "Transitions, " : "", |
| 2184 | (msr & 1 << 28) ? "MultiCoreTurbo, " : "", |
| 2185 | (msr & 1 << 27) ? "PkgPwrL2, " : "", |
| 2186 | (msr & 1 << 26) ? "PkgPwrL1, " : "", |
| 2187 | (msr & 1 << 25) ? "CorePwr, " : "", |
| 2188 | (msr & 1 << 24) ? "Amps, " : "", |
| 2189 | (msr & 1 << 22) ? "VR-Therm, " : "", |
| 2190 | (msr & 1 << 21) ? "Auto-HWP, " : "", |
| 2191 | (msr & 1 << 20) ? "Graphics, " : "", |
| 2192 | (msr & 1 << 18) ? "bit18, " : "", |
| 2193 | (msr & 1 << 17) ? "ThermStatus, " : "", |
| 2194 | (msr & 1 << 16) ? "PROCHOT, " : ""); |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 2195 | |
| 2196 | } |
| 2197 | if (do_gfx_perf_limit_reasons) { |
| 2198 | get_msr(cpu, MSR_GFX_PERF_LIMIT_REASONS, &msr); |
| 2199 | fprintf(stderr, "cpu%d: MSR_GFX_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr); |
| 2200 | fprintf(stderr, " (Active: %s%s%s%s%s%s%s%s)", |
| 2201 | (msr & 1 << 0) ? "PROCHOT, " : "", |
| 2202 | (msr & 1 << 1) ? "ThermStatus, " : "", |
| 2203 | (msr & 1 << 4) ? "Graphics, " : "", |
| 2204 | (msr & 1 << 6) ? "VR-Therm, " : "", |
| 2205 | (msr & 1 << 8) ? "Amps, " : "", |
| 2206 | (msr & 1 << 9) ? "GFXPwr, " : "", |
| 2207 | (msr & 1 << 10) ? "PkgPwrL1, " : "", |
| 2208 | (msr & 1 << 11) ? "PkgPwrL2, " : ""); |
| 2209 | fprintf(stderr, " (Logged: %s%s%s%s%s%s%s%s)\n", |
| 2210 | (msr & 1 << 16) ? "PROCHOT, " : "", |
| 2211 | (msr & 1 << 17) ? "ThermStatus, " : "", |
| 2212 | (msr & 1 << 20) ? "Graphics, " : "", |
| 2213 | (msr & 1 << 22) ? "VR-Therm, " : "", |
| 2214 | (msr & 1 << 24) ? "Amps, " : "", |
| 2215 | (msr & 1 << 25) ? "GFXPwr, " : "", |
| 2216 | (msr & 1 << 26) ? "PkgPwrL1, " : "", |
| 2217 | (msr & 1 << 27) ? "PkgPwrL2, " : ""); |
| 2218 | } |
| 2219 | if (do_ring_perf_limit_reasons) { |
| 2220 | get_msr(cpu, MSR_RING_PERF_LIMIT_REASONS, &msr); |
| 2221 | fprintf(stderr, "cpu%d: MSR_RING_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr); |
| 2222 | fprintf(stderr, " (Active: %s%s%s%s%s%s)", |
| 2223 | (msr & 1 << 0) ? "PROCHOT, " : "", |
| 2224 | (msr & 1 << 1) ? "ThermStatus, " : "", |
| 2225 | (msr & 1 << 6) ? "VR-Therm, " : "", |
| 2226 | (msr & 1 << 8) ? "Amps, " : "", |
| 2227 | (msr & 1 << 10) ? "PkgPwrL1, " : "", |
| 2228 | (msr & 1 << 11) ? "PkgPwrL2, " : ""); |
| 2229 | fprintf(stderr, " (Logged: %s%s%s%s%s%s)\n", |
| 2230 | (msr & 1 << 16) ? "PROCHOT, " : "", |
| 2231 | (msr & 1 << 17) ? "ThermStatus, " : "", |
| 2232 | (msr & 1 << 22) ? "VR-Therm, " : "", |
| 2233 | (msr & 1 << 24) ? "Amps, " : "", |
| 2234 | (msr & 1 << 26) ? "PkgPwrL1, " : "", |
| 2235 | (msr & 1 << 27) ? "PkgPwrL2, " : ""); |
| 2236 | } |
| 2237 | return 0; |
| 2238 | } |
| 2239 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2240 | #define RAPL_POWER_GRANULARITY 0x7FFF /* 15 bit power granularity */ |
| 2241 | #define RAPL_TIME_GRANULARITY 0x3F /* 6 bit time granularity */ |
| 2242 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2243 | double get_tdp(model) |
| 2244 | { |
| 2245 | unsigned long long msr; |
| 2246 | |
| 2247 | if (do_rapl & RAPL_PKG_POWER_INFO) |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2248 | if (!get_msr(base_cpu, MSR_PKG_POWER_INFO, &msr)) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2249 | return ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units; |
| 2250 | |
| 2251 | switch (model) { |
| 2252 | case 0x37: |
| 2253 | case 0x4D: |
| 2254 | return 30.0; |
| 2255 | default: |
| 2256 | return 135.0; |
| 2257 | } |
| 2258 | } |
| 2259 | |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 2260 | /* |
| 2261 | * rapl_dram_energy_units_probe() |
| 2262 | * Energy units are either hard-coded, or come from RAPL Energy Unit MSR. |
| 2263 | */ |
| 2264 | static double |
| 2265 | rapl_dram_energy_units_probe(int model, double rapl_energy_units) |
| 2266 | { |
| 2267 | /* only called for genuine_intel, family 6 */ |
| 2268 | |
| 2269 | switch (model) { |
| 2270 | case 0x3F: /* HSX */ |
| 2271 | case 0x4F: /* BDX */ |
| 2272 | case 0x56: /* BDX-DE */ |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2273 | case 0x57: /* KNL */ |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 2274 | return (rapl_dram_energy_units = 15.3 / 1000000); |
| 2275 | default: |
| 2276 | return (rapl_energy_units); |
| 2277 | } |
| 2278 | } |
| 2279 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2280 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2281 | /* |
| 2282 | * rapl_probe() |
| 2283 | * |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2284 | * sets do_rapl, rapl_power_units, rapl_energy_units, rapl_time_units |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2285 | */ |
| 2286 | void rapl_probe(unsigned int family, unsigned int model) |
| 2287 | { |
| 2288 | unsigned long long msr; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2289 | unsigned int time_unit; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2290 | double tdp; |
| 2291 | |
| 2292 | if (!genuine_intel) |
| 2293 | return; |
| 2294 | |
| 2295 | if (family != 6) |
| 2296 | return; |
| 2297 | |
| 2298 | switch (model) { |
| 2299 | case 0x2A: |
| 2300 | case 0x3A: |
Len Brown | 70b4340 | 2013-01-08 01:26:07 -0500 | [diff] [blame] | 2301 | case 0x3C: /* HSW */ |
Len Brown | 70b4340 | 2013-01-08 01:26:07 -0500 | [diff] [blame] | 2302 | case 0x45: /* HSW */ |
Len Brown | 149c231 | 2013-03-15 10:58:02 -0400 | [diff] [blame] | 2303 | case 0x46: /* HSW */ |
Len Brown | 4e8e863f | 2014-02-27 23:28:53 -0500 | [diff] [blame] | 2304 | case 0x3D: /* BDW */ |
Len Brown | 48a0631 | 2015-02-10 15:38:04 -0500 | [diff] [blame] | 2305 | case 0x47: /* BDW */ |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2306 | do_rapl = RAPL_PKG | RAPL_CORES | RAPL_CORE_POLICY | RAPL_GFX | RAPL_PKG_POWER_INFO; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2307 | break; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 2308 | case 0x4E: /* SKL */ |
| 2309 | case 0x5E: /* SKL */ |
| 2310 | do_rapl = RAPL_PKG | RAPL_DRAM | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_PKG_POWER_INFO; |
| 2311 | break; |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 2312 | case 0x3F: /* HSX */ |
Len Brown | 4e8e863f | 2014-02-27 23:28:53 -0500 | [diff] [blame] | 2313 | case 0x4F: /* BDX */ |
| 2314 | case 0x56: /* BDX-DE */ |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2315 | case 0x57: /* KNL */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 2316 | do_rapl = RAPL_PKG | RAPL_DRAM | RAPL_DRAM_POWER_INFO | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_PKG_POWER_INFO; |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 2317 | break; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2318 | case 0x2D: |
| 2319 | case 0x3E: |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 2320 | 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 | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2321 | break; |
| 2322 | case 0x37: /* BYT */ |
| 2323 | case 0x4D: /* AVN */ |
| 2324 | do_rapl = RAPL_PKG | RAPL_CORES ; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2325 | break; |
| 2326 | default: |
| 2327 | return; |
| 2328 | } |
| 2329 | |
| 2330 | /* units on package 0, verify later other packages match */ |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2331 | if (get_msr(base_cpu, MSR_RAPL_POWER_UNIT, &msr)) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2332 | return; |
| 2333 | |
| 2334 | rapl_power_units = 1.0 / (1 << (msr & 0xF)); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2335 | if (model == 0x37) |
| 2336 | rapl_energy_units = 1.0 * (1 << (msr >> 8 & 0x1F)) / 1000000; |
| 2337 | else |
| 2338 | rapl_energy_units = 1.0 / (1 << (msr >> 8 & 0x1F)); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2339 | |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 2340 | rapl_dram_energy_units = rapl_dram_energy_units_probe(model, rapl_energy_units); |
| 2341 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2342 | time_unit = msr >> 16 & 0xF; |
| 2343 | if (time_unit == 0) |
| 2344 | time_unit = 0xA; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2345 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2346 | rapl_time_units = 1.0 / (1 << (time_unit)); |
| 2347 | |
| 2348 | tdp = get_tdp(model); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2349 | |
| 2350 | rapl_joule_counter_range = 0xFFFFFFFF * rapl_energy_units / tdp; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 2351 | if (debug) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2352 | fprintf(stderr, "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] | 2353 | |
| 2354 | return; |
| 2355 | } |
| 2356 | |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 2357 | void perf_limit_reasons_probe(family, model) |
| 2358 | { |
| 2359 | if (!genuine_intel) |
| 2360 | return; |
| 2361 | |
| 2362 | if (family != 6) |
| 2363 | return; |
| 2364 | |
| 2365 | switch (model) { |
| 2366 | case 0x3C: /* HSW */ |
| 2367 | case 0x45: /* HSW */ |
| 2368 | case 0x46: /* HSW */ |
| 2369 | do_gfx_perf_limit_reasons = 1; |
| 2370 | case 0x3F: /* HSX */ |
| 2371 | do_core_perf_limit_reasons = 1; |
| 2372 | do_ring_perf_limit_reasons = 1; |
| 2373 | default: |
| 2374 | return; |
| 2375 | } |
| 2376 | } |
| 2377 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2378 | int print_thermal(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 2379 | { |
| 2380 | unsigned long long msr; |
| 2381 | unsigned int dts; |
| 2382 | int cpu; |
| 2383 | |
| 2384 | if (!(do_dts || do_ptm)) |
| 2385 | return 0; |
| 2386 | |
| 2387 | cpu = t->cpu_id; |
| 2388 | |
| 2389 | /* DTS is per-core, no need to print for each thread */ |
| 2390 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 2391 | return 0; |
| 2392 | |
| 2393 | if (cpu_migrate(cpu)) { |
| 2394 | fprintf(stderr, "Could not migrate to CPU %d\n", cpu); |
| 2395 | return -1; |
| 2396 | } |
| 2397 | |
| 2398 | if (do_ptm && (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) { |
| 2399 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr)) |
| 2400 | return 0; |
| 2401 | |
| 2402 | dts = (msr >> 16) & 0x7F; |
| 2403 | fprintf(stderr, "cpu%d: MSR_IA32_PACKAGE_THERM_STATUS: 0x%08llx (%d C)\n", |
| 2404 | cpu, msr, tcc_activation_temp - dts); |
| 2405 | |
| 2406 | #ifdef THERM_DEBUG |
| 2407 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, &msr)) |
| 2408 | return 0; |
| 2409 | |
| 2410 | dts = (msr >> 16) & 0x7F; |
| 2411 | dts2 = (msr >> 8) & 0x7F; |
| 2412 | fprintf(stderr, "cpu%d: MSR_IA32_PACKAGE_THERM_INTERRUPT: 0x%08llx (%d C, %d C)\n", |
| 2413 | cpu, msr, tcc_activation_temp - dts, tcc_activation_temp - dts2); |
| 2414 | #endif |
| 2415 | } |
| 2416 | |
| 2417 | |
| 2418 | if (do_dts) { |
| 2419 | unsigned int resolution; |
| 2420 | |
| 2421 | if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr)) |
| 2422 | return 0; |
| 2423 | |
| 2424 | dts = (msr >> 16) & 0x7F; |
| 2425 | resolution = (msr >> 27) & 0xF; |
| 2426 | fprintf(stderr, "cpu%d: MSR_IA32_THERM_STATUS: 0x%08llx (%d C +/- %d)\n", |
| 2427 | cpu, msr, tcc_activation_temp - dts, resolution); |
| 2428 | |
| 2429 | #ifdef THERM_DEBUG |
| 2430 | if (get_msr(cpu, MSR_IA32_THERM_INTERRUPT, &msr)) |
| 2431 | return 0; |
| 2432 | |
| 2433 | dts = (msr >> 16) & 0x7F; |
| 2434 | dts2 = (msr >> 8) & 0x7F; |
| 2435 | fprintf(stderr, "cpu%d: MSR_IA32_THERM_INTERRUPT: 0x%08llx (%d C, %d C)\n", |
| 2436 | cpu, msr, tcc_activation_temp - dts, tcc_activation_temp - dts2); |
| 2437 | #endif |
| 2438 | } |
| 2439 | |
| 2440 | return 0; |
| 2441 | } |
| 2442 | |
| 2443 | void print_power_limit_msr(int cpu, unsigned long long msr, char *label) |
| 2444 | { |
| 2445 | fprintf(stderr, "cpu%d: %s: %sabled (%f Watts, %f sec, clamp %sabled)\n", |
| 2446 | cpu, label, |
| 2447 | ((msr >> 15) & 1) ? "EN" : "DIS", |
| 2448 | ((msr >> 0) & 0x7FFF) * rapl_power_units, |
| 2449 | (1.0 + (((msr >> 22) & 0x3)/4.0)) * (1 << ((msr >> 17) & 0x1F)) * rapl_time_units, |
| 2450 | (((msr >> 16) & 1) ? "EN" : "DIS")); |
| 2451 | |
| 2452 | return; |
| 2453 | } |
| 2454 | |
| 2455 | int print_rapl(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 2456 | { |
| 2457 | unsigned long long msr; |
| 2458 | int cpu; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2459 | |
| 2460 | if (!do_rapl) |
| 2461 | return 0; |
| 2462 | |
| 2463 | /* RAPL counters are per package, so print only for 1st thread/package */ |
| 2464 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 2465 | return 0; |
| 2466 | |
| 2467 | cpu = t->cpu_id; |
| 2468 | if (cpu_migrate(cpu)) { |
| 2469 | fprintf(stderr, "Could not migrate to CPU %d\n", cpu); |
| 2470 | return -1; |
| 2471 | } |
| 2472 | |
| 2473 | if (get_msr(cpu, MSR_RAPL_POWER_UNIT, &msr)) |
| 2474 | return -1; |
| 2475 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 2476 | if (debug) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2477 | fprintf(stderr, "cpu%d: MSR_RAPL_POWER_UNIT: 0x%08llx " |
| 2478 | "(%f Watts, %f Joules, %f sec.)\n", cpu, msr, |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2479 | rapl_power_units, rapl_energy_units, rapl_time_units); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2480 | } |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2481 | if (do_rapl & RAPL_PKG_POWER_INFO) { |
| 2482 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2483 | if (get_msr(cpu, MSR_PKG_POWER_INFO, &msr)) |
| 2484 | return -5; |
| 2485 | |
| 2486 | |
| 2487 | fprintf(stderr, "cpu%d: MSR_PKG_POWER_INFO: 0x%08llx (%.0f W TDP, RAPL %.0f - %.0f W, %f sec.)\n", |
| 2488 | cpu, msr, |
| 2489 | ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 2490 | ((msr >> 16) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 2491 | ((msr >> 32) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 2492 | ((msr >> 48) & RAPL_TIME_GRANULARITY) * rapl_time_units); |
| 2493 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2494 | } |
| 2495 | if (do_rapl & RAPL_PKG) { |
| 2496 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2497 | if (get_msr(cpu, MSR_PKG_POWER_LIMIT, &msr)) |
| 2498 | return -9; |
| 2499 | |
| 2500 | fprintf(stderr, "cpu%d: MSR_PKG_POWER_LIMIT: 0x%08llx (%slocked)\n", |
| 2501 | cpu, msr, (msr >> 63) & 1 ? "": "UN"); |
| 2502 | |
| 2503 | print_power_limit_msr(cpu, msr, "PKG Limit #1"); |
| 2504 | fprintf(stderr, "cpu%d: PKG Limit #2: %sabled (%f Watts, %f* sec, clamp %sabled)\n", |
| 2505 | cpu, |
| 2506 | ((msr >> 47) & 1) ? "EN" : "DIS", |
| 2507 | ((msr >> 32) & 0x7FFF) * rapl_power_units, |
| 2508 | (1.0 + (((msr >> 54) & 0x3)/4.0)) * (1 << ((msr >> 49) & 0x1F)) * rapl_time_units, |
| 2509 | ((msr >> 48) & 1) ? "EN" : "DIS"); |
| 2510 | } |
| 2511 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 2512 | if (do_rapl & RAPL_DRAM_POWER_INFO) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2513 | if (get_msr(cpu, MSR_DRAM_POWER_INFO, &msr)) |
| 2514 | return -6; |
| 2515 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2516 | fprintf(stderr, "cpu%d: MSR_DRAM_POWER_INFO,: 0x%08llx (%.0f W TDP, RAPL %.0f - %.0f W, %f sec.)\n", |
| 2517 | cpu, msr, |
| 2518 | ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 2519 | ((msr >> 16) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 2520 | ((msr >> 32) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 2521 | ((msr >> 48) & RAPL_TIME_GRANULARITY) * rapl_time_units); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 2522 | } |
| 2523 | if (do_rapl & RAPL_DRAM) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2524 | if (get_msr(cpu, MSR_DRAM_POWER_LIMIT, &msr)) |
| 2525 | return -9; |
| 2526 | fprintf(stderr, "cpu%d: MSR_DRAM_POWER_LIMIT: 0x%08llx (%slocked)\n", |
| 2527 | cpu, msr, (msr >> 31) & 1 ? "": "UN"); |
| 2528 | |
| 2529 | print_power_limit_msr(cpu, msr, "DRAM Limit"); |
| 2530 | } |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2531 | if (do_rapl & RAPL_CORE_POLICY) { |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 2532 | if (debug) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2533 | if (get_msr(cpu, MSR_PP0_POLICY, &msr)) |
| 2534 | return -7; |
| 2535 | |
| 2536 | fprintf(stderr, "cpu%d: MSR_PP0_POLICY: %lld\n", cpu, msr & 0xF); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2537 | } |
| 2538 | } |
| 2539 | if (do_rapl & RAPL_CORES) { |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 2540 | if (debug) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2541 | |
| 2542 | if (get_msr(cpu, MSR_PP0_POWER_LIMIT, &msr)) |
| 2543 | return -9; |
| 2544 | fprintf(stderr, "cpu%d: MSR_PP0_POWER_LIMIT: 0x%08llx (%slocked)\n", |
| 2545 | cpu, msr, (msr >> 31) & 1 ? "": "UN"); |
| 2546 | print_power_limit_msr(cpu, msr, "Cores Limit"); |
| 2547 | } |
| 2548 | } |
| 2549 | if (do_rapl & RAPL_GFX) { |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 2550 | if (debug) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2551 | if (get_msr(cpu, MSR_PP1_POLICY, &msr)) |
| 2552 | return -8; |
| 2553 | |
| 2554 | fprintf(stderr, "cpu%d: MSR_PP1_POLICY: %lld\n", cpu, msr & 0xF); |
| 2555 | |
| 2556 | if (get_msr(cpu, MSR_PP1_POWER_LIMIT, &msr)) |
| 2557 | return -9; |
| 2558 | fprintf(stderr, "cpu%d: MSR_PP1_POWER_LIMIT: 0x%08llx (%slocked)\n", |
| 2559 | cpu, msr, (msr >> 31) & 1 ? "": "UN"); |
| 2560 | print_power_limit_msr(cpu, msr, "GFX Limit"); |
| 2561 | } |
| 2562 | } |
| 2563 | return 0; |
| 2564 | } |
| 2565 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2566 | /* |
| 2567 | * SNB adds support for additional MSRs: |
| 2568 | * |
| 2569 | * MSR_PKG_C7_RESIDENCY 0x000003fa |
| 2570 | * MSR_CORE_C7_RESIDENCY 0x000003fe |
| 2571 | * MSR_PKG_C2_RESIDENCY 0x0000060d |
| 2572 | */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2573 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2574 | int has_snb_msrs(unsigned int family, unsigned int model) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2575 | { |
| 2576 | if (!genuine_intel) |
| 2577 | return 0; |
| 2578 | |
| 2579 | switch (model) { |
| 2580 | case 0x2A: |
| 2581 | case 0x2D: |
Len Brown | 650a37f | 2012-06-03 23:34:44 -0400 | [diff] [blame] | 2582 | case 0x3A: /* IVB */ |
Len Brown | 1300651 | 2012-09-26 18:11:31 -0400 | [diff] [blame] | 2583 | case 0x3E: /* IVB Xeon */ |
Len Brown | 70b4340 | 2013-01-08 01:26:07 -0500 | [diff] [blame] | 2584 | case 0x3C: /* HSW */ |
| 2585 | case 0x3F: /* HSW */ |
| 2586 | case 0x45: /* HSW */ |
Len Brown | 149c231 | 2013-03-15 10:58:02 -0400 | [diff] [blame] | 2587 | case 0x46: /* HSW */ |
Len Brown | 4e8e863f | 2014-02-27 23:28:53 -0500 | [diff] [blame] | 2588 | case 0x3D: /* BDW */ |
Len Brown | 48a0631 | 2015-02-10 15:38:04 -0500 | [diff] [blame] | 2589 | case 0x47: /* BDW */ |
Len Brown | 4e8e863f | 2014-02-27 23:28:53 -0500 | [diff] [blame] | 2590 | case 0x4F: /* BDX */ |
| 2591 | case 0x56: /* BDX-DE */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 2592 | case 0x4E: /* SKL */ |
| 2593 | case 0x5E: /* SKL */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2594 | return 1; |
| 2595 | } |
| 2596 | return 0; |
| 2597 | } |
| 2598 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2599 | /* |
| 2600 | * HSW adds support for additional MSRs: |
| 2601 | * |
| 2602 | * MSR_PKG_C8_RESIDENCY 0x00000630 |
| 2603 | * MSR_PKG_C9_RESIDENCY 0x00000631 |
| 2604 | * MSR_PKG_C10_RESIDENCY 0x00000632 |
| 2605 | */ |
| 2606 | int has_hsw_msrs(unsigned int family, unsigned int model) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 2607 | { |
| 2608 | if (!genuine_intel) |
| 2609 | return 0; |
| 2610 | |
| 2611 | switch (model) { |
Len Brown | 4e8e863f | 2014-02-27 23:28:53 -0500 | [diff] [blame] | 2612 | case 0x45: /* HSW */ |
| 2613 | case 0x3D: /* BDW */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 2614 | case 0x4E: /* SKL */ |
| 2615 | case 0x5E: /* SKL */ |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 2616 | return 1; |
| 2617 | } |
| 2618 | return 0; |
| 2619 | } |
| 2620 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 2621 | /* |
| 2622 | * SKL adds support for additional MSRS: |
| 2623 | * |
| 2624 | * MSR_PKG_WEIGHTED_CORE_C0_RES 0x00000658 |
| 2625 | * MSR_PKG_ANY_CORE_C0_RES 0x00000659 |
| 2626 | * MSR_PKG_ANY_GFXE_C0_RES 0x0000065A |
| 2627 | * MSR_PKG_BOTH_CORE_GFXE_C0_RES 0x0000065B |
| 2628 | */ |
| 2629 | int has_skl_msrs(unsigned int family, unsigned int model) |
| 2630 | { |
| 2631 | if (!genuine_intel) |
| 2632 | return 0; |
| 2633 | |
| 2634 | switch (model) { |
| 2635 | case 0x4E: /* SKL */ |
| 2636 | case 0x5E: /* SKL */ |
| 2637 | return 1; |
| 2638 | } |
| 2639 | return 0; |
| 2640 | } |
| 2641 | |
| 2642 | |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 2643 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2644 | int is_slm(unsigned int family, unsigned int model) |
| 2645 | { |
| 2646 | if (!genuine_intel) |
| 2647 | return 0; |
| 2648 | switch (model) { |
| 2649 | case 0x37: /* BYT */ |
| 2650 | case 0x4D: /* AVN */ |
| 2651 | return 1; |
| 2652 | } |
| 2653 | return 0; |
| 2654 | } |
| 2655 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2656 | int is_knl(unsigned int family, unsigned int model) |
| 2657 | { |
| 2658 | if (!genuine_intel) |
| 2659 | return 0; |
| 2660 | switch (model) { |
| 2661 | case 0x57: /* KNL */ |
| 2662 | return 1; |
| 2663 | } |
| 2664 | return 0; |
| 2665 | } |
| 2666 | |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 2667 | unsigned int get_aperf_mperf_multiplier(unsigned int family, unsigned int model) |
| 2668 | { |
| 2669 | if (is_knl(family, model)) |
| 2670 | return 1024; |
| 2671 | return 1; |
| 2672 | } |
| 2673 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2674 | #define SLM_BCLK_FREQS 5 |
| 2675 | double slm_freq_table[SLM_BCLK_FREQS] = { 83.3, 100.0, 133.3, 116.7, 80.0}; |
| 2676 | |
| 2677 | double slm_bclk(void) |
| 2678 | { |
| 2679 | unsigned long long msr = 3; |
| 2680 | unsigned int i; |
| 2681 | double freq; |
| 2682 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2683 | if (get_msr(base_cpu, MSR_FSB_FREQ, &msr)) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2684 | fprintf(stderr, "SLM BCLK: unknown\n"); |
| 2685 | |
| 2686 | i = msr & 0xf; |
| 2687 | if (i >= SLM_BCLK_FREQS) { |
| 2688 | fprintf(stderr, "SLM BCLK[%d] invalid\n", i); |
| 2689 | msr = 3; |
| 2690 | } |
| 2691 | freq = slm_freq_table[i]; |
| 2692 | |
| 2693 | fprintf(stderr, "SLM BCLK: %.1f Mhz\n", freq); |
| 2694 | |
| 2695 | return freq; |
| 2696 | } |
| 2697 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2698 | double discover_bclk(unsigned int family, unsigned int model) |
| 2699 | { |
Chrzaniuk, Hubert | 121b48b | 2016-02-10 16:35:17 +0100 | [diff] [blame^] | 2700 | if (has_snb_msrs(family, model) || is_knl(family, model)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2701 | return 100.00; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2702 | else if (is_slm(family, model)) |
| 2703 | return slm_bclk(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2704 | else |
| 2705 | return 133.33; |
| 2706 | } |
| 2707 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2708 | /* |
| 2709 | * MSR_IA32_TEMPERATURE_TARGET indicates the temperature where |
| 2710 | * the Thermal Control Circuit (TCC) activates. |
| 2711 | * This is usually equal to tjMax. |
| 2712 | * |
| 2713 | * Older processors do not have this MSR, so there we guess, |
| 2714 | * but also allow cmdline over-ride with -T. |
| 2715 | * |
| 2716 | * Several MSR temperature values are in units of degrees-C |
| 2717 | * below this value, including the Digital Thermal Sensor (DTS), |
| 2718 | * Package Thermal Management Sensor (PTM), and thermal event thresholds. |
| 2719 | */ |
| 2720 | int set_temperature_target(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 2721 | { |
| 2722 | unsigned long long msr; |
| 2723 | unsigned int target_c_local; |
| 2724 | int cpu; |
| 2725 | |
| 2726 | /* tcc_activation_temp is used only for dts or ptm */ |
| 2727 | if (!(do_dts || do_ptm)) |
| 2728 | return 0; |
| 2729 | |
| 2730 | /* this is a per-package concept */ |
| 2731 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 2732 | return 0; |
| 2733 | |
| 2734 | cpu = t->cpu_id; |
| 2735 | if (cpu_migrate(cpu)) { |
| 2736 | fprintf(stderr, "Could not migrate to CPU %d\n", cpu); |
| 2737 | return -1; |
| 2738 | } |
| 2739 | |
| 2740 | if (tcc_activation_temp_override != 0) { |
| 2741 | tcc_activation_temp = tcc_activation_temp_override; |
| 2742 | fprintf(stderr, "cpu%d: Using cmdline TCC Target (%d C)\n", |
| 2743 | cpu, tcc_activation_temp); |
| 2744 | return 0; |
| 2745 | } |
| 2746 | |
| 2747 | /* Temperature Target MSR is Nehalem and newer only */ |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2748 | if (!do_nhm_platform_info) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2749 | goto guess; |
| 2750 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2751 | if (get_msr(base_cpu, MSR_IA32_TEMPERATURE_TARGET, &msr)) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2752 | goto guess; |
| 2753 | |
Jean Delvare | 3482124 | 2014-05-01 11:40:19 +0200 | [diff] [blame] | 2754 | target_c_local = (msr >> 16) & 0xFF; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2755 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 2756 | if (debug) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2757 | fprintf(stderr, "cpu%d: MSR_IA32_TEMPERATURE_TARGET: 0x%08llx (%d C)\n", |
| 2758 | cpu, msr, target_c_local); |
| 2759 | |
Jean Delvare | 3482124 | 2014-05-01 11:40:19 +0200 | [diff] [blame] | 2760 | if (!target_c_local) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2761 | goto guess; |
| 2762 | |
| 2763 | tcc_activation_temp = target_c_local; |
| 2764 | |
| 2765 | return 0; |
| 2766 | |
| 2767 | guess: |
| 2768 | tcc_activation_temp = TJMAX_DEFAULT; |
| 2769 | fprintf(stderr, "cpu%d: Guessing tjMax %d C, Please use -T to specify\n", |
| 2770 | cpu, tcc_activation_temp); |
| 2771 | |
| 2772 | return 0; |
| 2773 | } |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 2774 | |
| 2775 | void decode_misc_enable_msr(void) |
| 2776 | { |
| 2777 | unsigned long long msr; |
| 2778 | |
| 2779 | if (!get_msr(base_cpu, MSR_IA32_MISC_ENABLE, &msr)) |
| 2780 | fprintf(stderr, "cpu%d: MSR_IA32_MISC_ENABLE: 0x%08llx (%s %s %s)\n", |
| 2781 | base_cpu, msr, |
| 2782 | msr & (1 << 3) ? "TCC" : "", |
| 2783 | msr & (1 << 16) ? "EIST" : "", |
| 2784 | msr & (1 << 18) ? "MONITOR" : ""); |
| 2785 | } |
| 2786 | |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 2787 | /* |
| 2788 | * Decode MSR_MISC_PWR_MGMT |
| 2789 | * |
| 2790 | * Decode the bits according to the Nehalem documentation |
| 2791 | * bit[0] seems to continue to have same meaning going forward |
| 2792 | * bit[1] less so... |
| 2793 | */ |
| 2794 | void decode_misc_pwr_mgmt_msr(void) |
| 2795 | { |
| 2796 | unsigned long long msr; |
| 2797 | |
| 2798 | if (!do_nhm_platform_info) |
| 2799 | return; |
| 2800 | |
| 2801 | if (!get_msr(base_cpu, MSR_MISC_PWR_MGMT, &msr)) |
| 2802 | fprintf(stderr, "cpu%d: MSR_MISC_PWR_MGMT: 0x%08llx (%sable-EIST_Coordination %sable-EPB)\n", |
| 2803 | base_cpu, msr, |
| 2804 | msr & (1 << 0) ? "DIS" : "EN", |
| 2805 | msr & (1 << 1) ? "EN" : "DIS"); |
| 2806 | } |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 2807 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2808 | void process_cpuid() |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2809 | { |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 2810 | unsigned int eax, ebx, ecx, edx, max_level, max_extended_level; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2811 | unsigned int fms, family, model, stepping; |
| 2812 | |
| 2813 | eax = ebx = ecx = edx = 0; |
| 2814 | |
Josh Triplett | 2b92865 | 2013-08-20 17:20:14 -0700 | [diff] [blame] | 2815 | __get_cpuid(0, &max_level, &ebx, &ecx, &edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2816 | |
| 2817 | if (ebx == 0x756e6547 && edx == 0x49656e69 && ecx == 0x6c65746e) |
| 2818 | genuine_intel = 1; |
| 2819 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 2820 | if (debug) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2821 | fprintf(stderr, "CPUID(0): %.4s%.4s%.4s ", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2822 | (char *)&ebx, (char *)&edx, (char *)&ecx); |
| 2823 | |
Josh Triplett | 2b92865 | 2013-08-20 17:20:14 -0700 | [diff] [blame] | 2824 | __get_cpuid(1, &fms, &ebx, &ecx, &edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2825 | family = (fms >> 8) & 0xf; |
| 2826 | model = (fms >> 4) & 0xf; |
| 2827 | stepping = fms & 0xf; |
| 2828 | if (family == 6 || family == 0xf) |
| 2829 | model += ((fms >> 16) & 0xf) << 4; |
| 2830 | |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 2831 | if (debug) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2832 | fprintf(stderr, "%d CPUID levels; family:model:stepping 0x%x:%x:%x (%d:%d:%d)\n", |
| 2833 | max_level, family, model, stepping, family, model, stepping); |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 2834 | fprintf(stderr, "CPUID(1): %s %s %s %s %s %s %s %s\n", |
| 2835 | ecx & (1 << 0) ? "SSE3" : "-", |
| 2836 | ecx & (1 << 3) ? "MONITOR" : "-", |
| 2837 | ecx & (1 << 7) ? "EIST" : "-", |
| 2838 | ecx & (1 << 8) ? "TM2" : "-", |
| 2839 | edx & (1 << 4) ? "TSC" : "-", |
| 2840 | edx & (1 << 5) ? "MSR" : "-", |
| 2841 | edx & (1 << 22) ? "ACPI-TM" : "-", |
| 2842 | edx & (1 << 29) ? "TM" : "-"); |
| 2843 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2844 | |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 2845 | if (!(edx & (1 << 5))) |
| 2846 | errx(1, "CPUID: no MSR"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2847 | |
| 2848 | /* |
| 2849 | * check max extended function levels of CPUID. |
| 2850 | * This is needed to check for invariant TSC. |
| 2851 | * This check is valid for both Intel and AMD. |
| 2852 | */ |
| 2853 | ebx = ecx = edx = 0; |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 2854 | __get_cpuid(0x80000000, &max_extended_level, &ebx, &ecx, &edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2855 | |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 2856 | if (max_extended_level >= 0x80000007) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2857 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2858 | /* |
| 2859 | * Non-Stop TSC is advertised by CPUID.EAX=0x80000007: EDX.bit8 |
| 2860 | * this check is valid for both Intel and AMD |
| 2861 | */ |
| 2862 | __get_cpuid(0x80000007, &eax, &ebx, &ecx, &edx); |
| 2863 | has_invariant_tsc = edx & (1 << 8); |
| 2864 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2865 | |
| 2866 | /* |
| 2867 | * APERF/MPERF is advertised by CPUID.EAX=0x6: ECX.bit0 |
| 2868 | * this check is valid for both Intel and AMD |
| 2869 | */ |
| 2870 | |
Josh Triplett | 2b92865 | 2013-08-20 17:20:14 -0700 | [diff] [blame] | 2871 | __get_cpuid(0x6, &eax, &ebx, &ecx, &edx); |
Thomas Renninger | 8209e05 | 2011-01-21 15:11:19 +0100 | [diff] [blame] | 2872 | has_aperf = ecx & (1 << 0); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2873 | do_dts = eax & (1 << 0); |
| 2874 | do_ptm = eax & (1 << 6); |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 2875 | has_hwp = eax & (1 << 7); |
| 2876 | has_hwp_notify = eax & (1 << 8); |
| 2877 | has_hwp_activity_window = eax & (1 << 9); |
| 2878 | has_hwp_epp = eax & (1 << 10); |
| 2879 | has_hwp_pkg = eax & (1 << 11); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2880 | has_epb = ecx & (1 << 3); |
| 2881 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 2882 | if (debug) |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 2883 | fprintf(stderr, "CPUID(6): %sAPERF, %sDTS, %sPTM, %sHWP, " |
| 2884 | "%sHWPnotify, %sHWPwindow, %sHWPepp, %sHWPpkg, %sEPB\n", |
| 2885 | has_aperf ? "" : "No-", |
| 2886 | do_dts ? "" : "No-", |
| 2887 | do_ptm ? "" : "No-", |
| 2888 | has_hwp ? "" : "No-", |
| 2889 | has_hwp_notify ? "" : "No-", |
| 2890 | has_hwp_activity_window ? "" : "No-", |
| 2891 | has_hwp_epp ? "" : "No-", |
| 2892 | has_hwp_pkg ? "" : "No-", |
| 2893 | has_epb ? "" : "No-"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2894 | |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 2895 | if (debug) |
| 2896 | decode_misc_enable_msr(); |
| 2897 | |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 2898 | if (max_level >= 0x15) { |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 2899 | unsigned int eax_crystal; |
| 2900 | unsigned int ebx_tsc; |
| 2901 | |
| 2902 | /* |
| 2903 | * CPUID 15H TSC/Crystal ratio, possibly Crystal Hz |
| 2904 | */ |
| 2905 | eax_crystal = ebx_tsc = crystal_hz = edx = 0; |
| 2906 | __get_cpuid(0x15, &eax_crystal, &ebx_tsc, &crystal_hz, &edx); |
| 2907 | |
| 2908 | if (ebx_tsc != 0) { |
| 2909 | |
| 2910 | if (debug && (ebx != 0)) |
| 2911 | fprintf(stderr, "CPUID(0x15): eax_crystal: %d ebx_tsc: %d ecx_crystal_hz: %d\n", |
| 2912 | eax_crystal, ebx_tsc, crystal_hz); |
| 2913 | |
| 2914 | if (crystal_hz == 0) |
| 2915 | switch(model) { |
| 2916 | case 0x4E: /* SKL */ |
| 2917 | case 0x5E: /* SKL */ |
| 2918 | crystal_hz = 24000000; /* 24 MHz */ |
| 2919 | break; |
| 2920 | default: |
| 2921 | crystal_hz = 0; |
| 2922 | } |
| 2923 | |
| 2924 | if (crystal_hz) { |
| 2925 | tsc_hz = (unsigned long long) crystal_hz * ebx_tsc / eax_crystal; |
| 2926 | if (debug) |
| 2927 | fprintf(stderr, "TSC: %lld MHz (%d Hz * %d / %d / 1000000)\n", |
| 2928 | tsc_hz / 1000000, crystal_hz, ebx_tsc, eax_crystal); |
| 2929 | } |
| 2930 | } |
| 2931 | } |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 2932 | if (max_level >= 0x16) { |
| 2933 | unsigned int base_mhz, max_mhz, bus_mhz, edx; |
| 2934 | |
| 2935 | /* |
| 2936 | * CPUID 16H Base MHz, Max MHz, Bus MHz |
| 2937 | */ |
| 2938 | base_mhz = max_mhz = bus_mhz = edx = 0; |
| 2939 | |
| 2940 | __get_cpuid(0x16, &base_mhz, &max_mhz, &bus_mhz, &edx); |
| 2941 | if (debug) |
| 2942 | fprintf(stderr, "CPUID(0x16): base_mhz: %d max_mhz: %d bus_mhz: %d\n", |
| 2943 | base_mhz, max_mhz, bus_mhz); |
| 2944 | } |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 2945 | |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 2946 | if (has_aperf) |
| 2947 | aperf_mperf_multiplier = get_aperf_mperf_multiplier(family, model); |
| 2948 | |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2949 | do_nhm_platform_info = do_nhm_cstates = do_smi = probe_nhm_msrs(family, model); |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2950 | do_snb_cstates = has_snb_msrs(family, model); |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2951 | do_pc2 = do_snb_cstates && (pkg_cstate_limit >= PCL__2); |
| 2952 | do_pc3 = (pkg_cstate_limit >= PCL__3); |
| 2953 | do_pc6 = (pkg_cstate_limit >= PCL__6); |
| 2954 | do_pc7 = do_snb_cstates && (pkg_cstate_limit >= PCL__7); |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 2955 | do_c8_c9_c10 = has_hsw_msrs(family, model); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 2956 | do_skl_residency = has_skl_msrs(family, model); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2957 | do_slm_cstates = is_slm(family, model); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2958 | do_knl_cstates = is_knl(family, model); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2959 | |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 2960 | if (debug) |
| 2961 | decode_misc_pwr_mgmt_msr(); |
| 2962 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2963 | rapl_probe(family, model); |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 2964 | perf_limit_reasons_probe(family, model); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2965 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2966 | if (debug) |
| 2967 | dump_cstate_pstate_config_info(); |
| 2968 | |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 2969 | if (has_skl_msrs(family, model)) |
| 2970 | calculate_tsc_tweak(); |
| 2971 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2972 | return; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2973 | } |
| 2974 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 2975 | void help() |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2976 | { |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 2977 | fprintf(stderr, |
| 2978 | "Usage: turbostat [OPTIONS][(--interval seconds) | COMMAND ...]\n" |
| 2979 | "\n" |
| 2980 | "Turbostat forks the specified COMMAND and prints statistics\n" |
| 2981 | "when COMMAND completes.\n" |
| 2982 | "If no COMMAND is specified, turbostat wakes every 5-seconds\n" |
| 2983 | "to print statistics, until interrupted.\n" |
| 2984 | "--debug run in \"debug\" mode\n" |
| 2985 | "--interval sec Override default 5-second measurement interval\n" |
| 2986 | "--help print this help message\n" |
| 2987 | "--counter msr print 32-bit counter at address \"msr\"\n" |
| 2988 | "--Counter msr print 64-bit Counter at address \"msr\"\n" |
| 2989 | "--msr msr print 32-bit value at address \"msr\"\n" |
| 2990 | "--MSR msr print 64-bit Value at address \"msr\"\n" |
| 2991 | "--version print version information\n" |
| 2992 | "\n" |
| 2993 | "For more help, run \"man turbostat\"\n"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2994 | } |
| 2995 | |
| 2996 | |
| 2997 | /* |
| 2998 | * in /dev/cpu/ return success for names that are numbers |
| 2999 | * ie. filter out ".", "..", "microcode". |
| 3000 | */ |
| 3001 | int dir_filter(const struct dirent *dirp) |
| 3002 | { |
| 3003 | if (isdigit(dirp->d_name[0])) |
| 3004 | return 1; |
| 3005 | else |
| 3006 | return 0; |
| 3007 | } |
| 3008 | |
| 3009 | int open_dev_cpu_msr(int dummy1) |
| 3010 | { |
| 3011 | return 0; |
| 3012 | } |
| 3013 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3014 | void topology_probe() |
| 3015 | { |
| 3016 | int i; |
| 3017 | int max_core_id = 0; |
| 3018 | int max_package_id = 0; |
| 3019 | int max_siblings = 0; |
| 3020 | struct cpu_topology { |
| 3021 | int core_id; |
| 3022 | int physical_package_id; |
| 3023 | } *cpus; |
| 3024 | |
| 3025 | /* Initialize num_cpus, max_cpu_num */ |
| 3026 | topo.num_cpus = 0; |
| 3027 | topo.max_cpu_num = 0; |
| 3028 | for_all_proc_cpus(count_cpus); |
| 3029 | if (!summary_only && topo.num_cpus > 1) |
| 3030 | show_cpu = 1; |
| 3031 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3032 | if (debug > 1) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3033 | fprintf(stderr, "num_cpus %d max_cpu_num %d\n", topo.num_cpus, topo.max_cpu_num); |
| 3034 | |
| 3035 | cpus = calloc(1, (topo.max_cpu_num + 1) * sizeof(struct cpu_topology)); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 3036 | if (cpus == NULL) |
| 3037 | err(1, "calloc cpus"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3038 | |
| 3039 | /* |
| 3040 | * Allocate and initialize cpu_present_set |
| 3041 | */ |
| 3042 | cpu_present_set = CPU_ALLOC((topo.max_cpu_num + 1)); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 3043 | if (cpu_present_set == NULL) |
| 3044 | err(3, "CPU_ALLOC"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3045 | cpu_present_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); |
| 3046 | CPU_ZERO_S(cpu_present_setsize, cpu_present_set); |
| 3047 | for_all_proc_cpus(mark_cpu_present); |
| 3048 | |
| 3049 | /* |
| 3050 | * Allocate and initialize cpu_affinity_set |
| 3051 | */ |
| 3052 | cpu_affinity_set = CPU_ALLOC((topo.max_cpu_num + 1)); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 3053 | if (cpu_affinity_set == NULL) |
| 3054 | err(3, "CPU_ALLOC"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3055 | cpu_affinity_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); |
| 3056 | CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); |
| 3057 | |
| 3058 | |
| 3059 | /* |
| 3060 | * For online cpus |
| 3061 | * find max_core_id, max_package_id |
| 3062 | */ |
| 3063 | for (i = 0; i <= topo.max_cpu_num; ++i) { |
| 3064 | int siblings; |
| 3065 | |
| 3066 | if (cpu_is_not_present(i)) { |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3067 | if (debug > 1) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3068 | fprintf(stderr, "cpu%d NOT PRESENT\n", i); |
| 3069 | continue; |
| 3070 | } |
| 3071 | cpus[i].core_id = get_core_id(i); |
| 3072 | if (cpus[i].core_id > max_core_id) |
| 3073 | max_core_id = cpus[i].core_id; |
| 3074 | |
| 3075 | cpus[i].physical_package_id = get_physical_package_id(i); |
| 3076 | if (cpus[i].physical_package_id > max_package_id) |
| 3077 | max_package_id = cpus[i].physical_package_id; |
| 3078 | |
| 3079 | siblings = get_num_ht_siblings(i); |
| 3080 | if (siblings > max_siblings) |
| 3081 | max_siblings = siblings; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3082 | if (debug > 1) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3083 | fprintf(stderr, "cpu %d pkg %d core %d\n", |
| 3084 | i, cpus[i].physical_package_id, cpus[i].core_id); |
| 3085 | } |
| 3086 | topo.num_cores_per_pkg = max_core_id + 1; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3087 | if (debug > 1) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3088 | fprintf(stderr, "max_core_id %d, sizing for %d cores per package\n", |
| 3089 | max_core_id, topo.num_cores_per_pkg); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 3090 | if (debug && !summary_only && topo.num_cores_per_pkg > 1) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3091 | show_core = 1; |
| 3092 | |
| 3093 | topo.num_packages = max_package_id + 1; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3094 | if (debug > 1) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3095 | fprintf(stderr, "max_package_id %d, sizing for %d packages\n", |
| 3096 | max_package_id, topo.num_packages); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 3097 | if (debug && !summary_only && topo.num_packages > 1) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3098 | show_pkg = 1; |
| 3099 | |
| 3100 | topo.num_threads_per_core = max_siblings; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3101 | if (debug > 1) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3102 | fprintf(stderr, "max_siblings %d\n", max_siblings); |
| 3103 | |
| 3104 | free(cpus); |
| 3105 | } |
| 3106 | |
| 3107 | void |
| 3108 | allocate_counters(struct thread_data **t, struct core_data **c, struct pkg_data **p) |
| 3109 | { |
| 3110 | int i; |
| 3111 | |
| 3112 | *t = calloc(topo.num_threads_per_core * topo.num_cores_per_pkg * |
| 3113 | topo.num_packages, sizeof(struct thread_data)); |
| 3114 | if (*t == NULL) |
| 3115 | goto error; |
| 3116 | |
| 3117 | for (i = 0; i < topo.num_threads_per_core * |
| 3118 | topo.num_cores_per_pkg * topo.num_packages; i++) |
| 3119 | (*t)[i].cpu_id = -1; |
| 3120 | |
| 3121 | *c = calloc(topo.num_cores_per_pkg * topo.num_packages, |
| 3122 | sizeof(struct core_data)); |
| 3123 | if (*c == NULL) |
| 3124 | goto error; |
| 3125 | |
| 3126 | for (i = 0; i < topo.num_cores_per_pkg * topo.num_packages; i++) |
| 3127 | (*c)[i].core_id = -1; |
| 3128 | |
| 3129 | *p = calloc(topo.num_packages, sizeof(struct pkg_data)); |
| 3130 | if (*p == NULL) |
| 3131 | goto error; |
| 3132 | |
| 3133 | for (i = 0; i < topo.num_packages; i++) |
| 3134 | (*p)[i].package_id = i; |
| 3135 | |
| 3136 | return; |
| 3137 | error: |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 3138 | err(1, "calloc counters"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3139 | } |
| 3140 | /* |
| 3141 | * init_counter() |
| 3142 | * |
| 3143 | * set cpu_id, core_num, pkg_num |
| 3144 | * set FIRST_THREAD_IN_CORE and FIRST_CORE_IN_PACKAGE |
| 3145 | * |
| 3146 | * increment topo.num_cores when 1st core in pkg seen |
| 3147 | */ |
| 3148 | void init_counter(struct thread_data *thread_base, struct core_data *core_base, |
| 3149 | struct pkg_data *pkg_base, int thread_num, int core_num, |
| 3150 | int pkg_num, int cpu_id) |
| 3151 | { |
| 3152 | struct thread_data *t; |
| 3153 | struct core_data *c; |
| 3154 | struct pkg_data *p; |
| 3155 | |
| 3156 | t = GET_THREAD(thread_base, thread_num, core_num, pkg_num); |
| 3157 | c = GET_CORE(core_base, core_num, pkg_num); |
| 3158 | p = GET_PKG(pkg_base, pkg_num); |
| 3159 | |
| 3160 | t->cpu_id = cpu_id; |
| 3161 | if (thread_num == 0) { |
| 3162 | t->flags |= CPU_IS_FIRST_THREAD_IN_CORE; |
| 3163 | if (cpu_is_first_core_in_package(cpu_id)) |
| 3164 | t->flags |= CPU_IS_FIRST_CORE_IN_PACKAGE; |
| 3165 | } |
| 3166 | |
| 3167 | c->core_id = core_num; |
| 3168 | p->package_id = pkg_num; |
| 3169 | } |
| 3170 | |
| 3171 | |
| 3172 | int initialize_counters(int cpu_id) |
| 3173 | { |
| 3174 | int my_thread_id, my_core_id, my_package_id; |
| 3175 | |
| 3176 | my_package_id = get_physical_package_id(cpu_id); |
| 3177 | my_core_id = get_core_id(cpu_id); |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 3178 | my_thread_id = get_cpu_position_in_core(cpu_id); |
| 3179 | if (!my_thread_id) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3180 | topo.num_cores++; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3181 | |
| 3182 | init_counter(EVEN_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id); |
| 3183 | init_counter(ODD_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id); |
| 3184 | return 0; |
| 3185 | } |
| 3186 | |
| 3187 | void allocate_output_buffer() |
| 3188 | { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 3189 | output_buffer = calloc(1, (1 + topo.num_cpus) * 1024); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3190 | outp = output_buffer; |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 3191 | if (outp == NULL) |
| 3192 | err(-1, "calloc output buffer"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3193 | } |
| 3194 | |
| 3195 | void setup_all_buffers(void) |
| 3196 | { |
| 3197 | topology_probe(); |
| 3198 | allocate_counters(&thread_even, &core_even, &package_even); |
| 3199 | allocate_counters(&thread_odd, &core_odd, &package_odd); |
| 3200 | allocate_output_buffer(); |
| 3201 | for_all_proc_cpus(initialize_counters); |
| 3202 | } |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 3203 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3204 | void set_base_cpu(void) |
| 3205 | { |
| 3206 | base_cpu = sched_getcpu(); |
| 3207 | if (base_cpu < 0) |
| 3208 | err(-ENODEV, "No valid cpus found"); |
| 3209 | |
| 3210 | if (debug > 1) |
| 3211 | fprintf(stderr, "base_cpu = %d\n", base_cpu); |
| 3212 | } |
| 3213 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3214 | void turbostat_init() |
| 3215 | { |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3216 | setup_all_buffers(); |
| 3217 | set_base_cpu(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3218 | check_dev_msr(); |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 3219 | check_permissions(); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3220 | process_cpuid(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3221 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3222 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3223 | if (debug) |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3224 | for_all_cpus(print_hwp, ODD_COUNTERS); |
| 3225 | |
| 3226 | if (debug) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3227 | for_all_cpus(print_epb, ODD_COUNTERS); |
| 3228 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3229 | if (debug) |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3230 | for_all_cpus(print_perf_limit, ODD_COUNTERS); |
| 3231 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3232 | if (debug) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3233 | for_all_cpus(print_rapl, ODD_COUNTERS); |
| 3234 | |
| 3235 | for_all_cpus(set_temperature_target, ODD_COUNTERS); |
| 3236 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3237 | if (debug) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3238 | for_all_cpus(print_thermal, ODD_COUNTERS); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3239 | } |
| 3240 | |
| 3241 | int fork_it(char **argv) |
| 3242 | { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3243 | pid_t child_pid; |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 3244 | int status; |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 3245 | |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 3246 | status = for_all_cpus(get_counters, EVEN_COUNTERS); |
| 3247 | if (status) |
| 3248 | exit(status); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3249 | /* clear affinity side-effect of get_counters() */ |
| 3250 | sched_setaffinity(0, cpu_present_setsize, cpu_present_set); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3251 | gettimeofday(&tv_even, (struct timezone *)NULL); |
| 3252 | |
| 3253 | child_pid = fork(); |
| 3254 | if (!child_pid) { |
| 3255 | /* child */ |
| 3256 | execvp(argv[0], argv); |
| 3257 | } else { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3258 | |
| 3259 | /* parent */ |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 3260 | if (child_pid == -1) |
| 3261 | err(1, "fork"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3262 | |
| 3263 | signal(SIGINT, SIG_IGN); |
| 3264 | signal(SIGQUIT, SIG_IGN); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 3265 | if (waitpid(child_pid, &status, 0) == -1) |
| 3266 | err(status, "waitpid"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3267 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3268 | /* |
| 3269 | * n.b. fork_it() does not check for errors from for_all_cpus() |
| 3270 | * because re-starting is problematic when forking |
| 3271 | */ |
| 3272 | for_all_cpus(get_counters, ODD_COUNTERS); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3273 | gettimeofday(&tv_odd, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3274 | timersub(&tv_odd, &tv_even, &tv_delta); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3275 | for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS); |
| 3276 | compute_average(EVEN_COUNTERS); |
| 3277 | format_all_counters(EVEN_COUNTERS); |
| 3278 | flush_stderr(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3279 | |
Justin P. Mattock | 6eab04a | 2011-04-08 19:49:08 -0700 | [diff] [blame] | 3280 | fprintf(stderr, "%.6f sec\n", tv_delta.tv_sec + tv_delta.tv_usec/1000000.0); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3281 | |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 3282 | return status; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3283 | } |
| 3284 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 3285 | int get_and_dump_counters(void) |
| 3286 | { |
| 3287 | int status; |
| 3288 | |
| 3289 | status = for_all_cpus(get_counters, ODD_COUNTERS); |
| 3290 | if (status) |
| 3291 | return status; |
| 3292 | |
| 3293 | status = for_all_cpus(dump_counters, ODD_COUNTERS); |
| 3294 | if (status) |
| 3295 | return status; |
| 3296 | |
| 3297 | flush_stdout(); |
| 3298 | |
| 3299 | return status; |
| 3300 | } |
| 3301 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3302 | void print_version() { |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3303 | fprintf(stderr, "turbostat version 4.10 10 Dec, 2015" |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3304 | " - Len Brown <lenb@kernel.org>\n"); |
| 3305 | } |
| 3306 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3307 | void cmdline(int argc, char **argv) |
| 3308 | { |
| 3309 | int opt; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3310 | int option_index = 0; |
| 3311 | static struct option long_options[] = { |
| 3312 | {"Counter", required_argument, 0, 'C'}, |
| 3313 | {"counter", required_argument, 0, 'c'}, |
| 3314 | {"Dump", no_argument, 0, 'D'}, |
| 3315 | {"debug", no_argument, 0, 'd'}, |
| 3316 | {"interval", required_argument, 0, 'i'}, |
| 3317 | {"help", no_argument, 0, 'h'}, |
| 3318 | {"Joules", no_argument, 0, 'J'}, |
| 3319 | {"MSR", required_argument, 0, 'M'}, |
| 3320 | {"msr", required_argument, 0, 'm'}, |
| 3321 | {"Package", no_argument, 0, 'p'}, |
| 3322 | {"processor", no_argument, 0, 'p'}, |
| 3323 | {"Summary", no_argument, 0, 'S'}, |
| 3324 | {"TCC", required_argument, 0, 'T'}, |
| 3325 | {"version", no_argument, 0, 'v' }, |
| 3326 | {0, 0, 0, 0 } |
| 3327 | }; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3328 | |
| 3329 | progname = argv[0]; |
| 3330 | |
Len Brown | a01e72f | 2015-07-15 21:49:41 -0400 | [diff] [blame] | 3331 | while ((opt = getopt_long_only(argc, argv, "+C:c:Ddhi:JM:m:PpST:v", |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3332 | long_options, &option_index)) != -1) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3333 | switch (opt) { |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3334 | case 'C': |
| 3335 | sscanf(optarg, "%x", &extra_delta_offset64); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3336 | break; |
Len Brown | f924081 | 2012-10-06 15:26:31 -0400 | [diff] [blame] | 3337 | case 'c': |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 3338 | sscanf(optarg, "%x", &extra_delta_offset32); |
| 3339 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3340 | case 'D': |
| 3341 | dump_only++; |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 3342 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3343 | case 'd': |
| 3344 | debug++; |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 3345 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3346 | case 'h': |
| 3347 | default: |
| 3348 | help(); |
| 3349 | exit(1); |
| 3350 | case 'i': |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 3351 | { |
| 3352 | double interval = strtod(optarg, NULL); |
| 3353 | |
| 3354 | if (interval < 0.001) { |
| 3355 | fprintf(stderr, "interval %f seconds is too small\n", |
| 3356 | interval); |
| 3357 | exit(2); |
| 3358 | } |
| 3359 | |
| 3360 | interval_ts.tv_sec = interval; |
| 3361 | interval_ts.tv_nsec = (interval - interval_ts.tv_sec) * 1000000000; |
| 3362 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3363 | break; |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 3364 | case 'J': |
| 3365 | rapl_joules++; |
| 3366 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3367 | case 'M': |
| 3368 | sscanf(optarg, "%x", &extra_msr_offset64); |
| 3369 | break; |
| 3370 | case 'm': |
| 3371 | sscanf(optarg, "%x", &extra_msr_offset32); |
| 3372 | break; |
| 3373 | case 'P': |
| 3374 | show_pkg_only++; |
| 3375 | break; |
| 3376 | case 'p': |
| 3377 | show_core_only++; |
| 3378 | break; |
| 3379 | case 'S': |
| 3380 | summary_only++; |
| 3381 | break; |
| 3382 | case 'T': |
| 3383 | tcc_activation_temp_override = atoi(optarg); |
| 3384 | break; |
| 3385 | case 'v': |
| 3386 | print_version(); |
| 3387 | exit(0); |
| 3388 | break; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3389 | } |
| 3390 | } |
| 3391 | } |
| 3392 | |
| 3393 | int main(int argc, char **argv) |
| 3394 | { |
| 3395 | cmdline(argc, argv); |
| 3396 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 3397 | if (debug) |
| 3398 | print_version(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3399 | |
| 3400 | turbostat_init(); |
| 3401 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 3402 | /* dump counters and exit */ |
| 3403 | if (dump_only) |
| 3404 | return get_and_dump_counters(); |
| 3405 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3406 | /* |
| 3407 | * if any params left, it must be a command to fork |
| 3408 | */ |
| 3409 | if (argc - optind) |
| 3410 | return fork_it(argv + optind); |
| 3411 | else |
| 3412 | turbostat_loop(); |
| 3413 | |
| 3414 | return 0; |
| 3415 | } |