Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1 | /* |
| 2 | * turbostat -- show CPU frequency and C-state residency |
| 3 | * on modern Intel turbo-capable processors. |
| 4 | * |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 5 | * Copyright (c) 2013 Intel Corporation. |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 6 | * Len Brown <len.brown@intel.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms and conditions of the GNU General Public License, |
| 10 | * version 2, as published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | */ |
| 21 | |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 22 | #define _GNU_SOURCE |
Josh Triplett | b731f31 | 2013-08-20 17:20:12 -0700 | [diff] [blame] | 23 | #include MSRHEADER |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 24 | #include <stdio.h> |
| 25 | #include <unistd.h> |
| 26 | #include <sys/types.h> |
| 27 | #include <sys/wait.h> |
| 28 | #include <sys/stat.h> |
| 29 | #include <sys/resource.h> |
| 30 | #include <fcntl.h> |
| 31 | #include <signal.h> |
| 32 | #include <sys/time.h> |
| 33 | #include <stdlib.h> |
| 34 | #include <dirent.h> |
| 35 | #include <string.h> |
| 36 | #include <ctype.h> |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 37 | #include <sched.h> |
Josh Triplett | 2b92865 | 2013-08-20 17:20:14 -0700 | [diff] [blame^] | 38 | #include <cpuid.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 39 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 40 | char *proc_stat = "/proc/stat"; |
| 41 | unsigned int interval_sec = 5; /* set with -i interval_sec */ |
| 42 | unsigned int verbose; /* set with -v */ |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 43 | unsigned int rapl_verbose; /* set with -R */ |
| 44 | unsigned int thermal_verbose; /* set with -T */ |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 45 | unsigned int summary_only; /* set with -s */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 46 | unsigned int skip_c0; |
| 47 | unsigned int skip_c1; |
| 48 | unsigned int do_nhm_cstates; |
| 49 | unsigned int do_snb_cstates; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 50 | unsigned int do_c8_c9_c10; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 51 | unsigned int do_slm_cstates; |
| 52 | unsigned int use_c1_residency_msr; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 53 | unsigned int has_aperf; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 54 | unsigned int has_epb; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 55 | unsigned int units = 1000000000; /* Ghz etc */ |
| 56 | unsigned int genuine_intel; |
| 57 | unsigned int has_invariant_tsc; |
| 58 | unsigned int do_nehalem_platform_info; |
| 59 | unsigned int do_nehalem_turbo_ratio_limit; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 60 | unsigned int do_ivt_turbo_ratio_limit; |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 61 | unsigned int extra_msr_offset32; |
| 62 | unsigned int extra_msr_offset64; |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 63 | unsigned int extra_delta_offset32; |
| 64 | unsigned int extra_delta_offset64; |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 65 | int do_smi; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 66 | double bclk; |
| 67 | unsigned int show_pkg; |
| 68 | unsigned int show_core; |
| 69 | unsigned int show_cpu; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 70 | unsigned int show_pkg_only; |
| 71 | unsigned int show_core_only; |
| 72 | char *output_buffer, *outp; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 73 | unsigned int do_rapl; |
| 74 | unsigned int do_dts; |
| 75 | unsigned int do_ptm; |
| 76 | unsigned int tcc_activation_temp; |
| 77 | unsigned int tcc_activation_temp_override; |
| 78 | double rapl_power_units, rapl_energy_units, rapl_time_units; |
| 79 | double rapl_joule_counter_range; |
| 80 | |
| 81 | #define RAPL_PKG (1 << 0) |
| 82 | #define RAPL_CORES (1 << 1) |
| 83 | #define RAPL_GFX (1 << 2) |
| 84 | #define RAPL_DRAM (1 << 3) |
| 85 | #define RAPL_PKG_PERF_STATUS (1 << 4) |
| 86 | #define RAPL_DRAM_PERF_STATUS (1 << 5) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 87 | #define RAPL_PKG_POWER_INFO (1 << 6) |
| 88 | #define RAPL_CORE_POLICY (1 << 7) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 89 | #define TJMAX_DEFAULT 100 |
| 90 | |
| 91 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 92 | |
| 93 | int aperf_mperf_unstable; |
| 94 | int backwards_count; |
| 95 | char *progname; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 96 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 97 | cpu_set_t *cpu_present_set, *cpu_affinity_set; |
| 98 | size_t cpu_present_setsize, cpu_affinity_setsize; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 99 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 100 | struct thread_data { |
| 101 | unsigned long long tsc; |
| 102 | unsigned long long aperf; |
| 103 | unsigned long long mperf; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 104 | unsigned long long c1; |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 105 | unsigned long long extra_msr64; |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 106 | unsigned long long extra_delta64; |
| 107 | unsigned long long extra_msr32; |
| 108 | unsigned long long extra_delta32; |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 109 | unsigned int smi_count; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 110 | unsigned int cpu_id; |
| 111 | unsigned int flags; |
| 112 | #define CPU_IS_FIRST_THREAD_IN_CORE 0x2 |
| 113 | #define CPU_IS_FIRST_CORE_IN_PACKAGE 0x4 |
| 114 | } *thread_even, *thread_odd; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 115 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 116 | struct core_data { |
| 117 | unsigned long long c3; |
| 118 | unsigned long long c6; |
| 119 | unsigned long long c7; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 120 | unsigned int core_temp_c; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 121 | unsigned int core_id; |
| 122 | } *core_even, *core_odd; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 123 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 124 | struct pkg_data { |
| 125 | unsigned long long pc2; |
| 126 | unsigned long long pc3; |
| 127 | unsigned long long pc6; |
| 128 | unsigned long long pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 129 | unsigned long long pc8; |
| 130 | unsigned long long pc9; |
| 131 | unsigned long long pc10; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 132 | unsigned int package_id; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 133 | unsigned int energy_pkg; /* MSR_PKG_ENERGY_STATUS */ |
| 134 | unsigned int energy_dram; /* MSR_DRAM_ENERGY_STATUS */ |
| 135 | unsigned int energy_cores; /* MSR_PP0_ENERGY_STATUS */ |
| 136 | unsigned int energy_gfx; /* MSR_PP1_ENERGY_STATUS */ |
| 137 | unsigned int rapl_pkg_perf_status; /* MSR_PKG_PERF_STATUS */ |
| 138 | unsigned int rapl_dram_perf_status; /* MSR_DRAM_PERF_STATUS */ |
| 139 | unsigned int pkg_temp_c; |
| 140 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 141 | } *package_even, *package_odd; |
| 142 | |
| 143 | #define ODD_COUNTERS thread_odd, core_odd, package_odd |
| 144 | #define EVEN_COUNTERS thread_even, core_even, package_even |
| 145 | |
| 146 | #define GET_THREAD(thread_base, thread_no, core_no, pkg_no) \ |
| 147 | (thread_base + (pkg_no) * topo.num_cores_per_pkg * \ |
| 148 | topo.num_threads_per_core + \ |
| 149 | (core_no) * topo.num_threads_per_core + (thread_no)) |
| 150 | #define GET_CORE(core_base, core_no, pkg_no) \ |
| 151 | (core_base + (pkg_no) * topo.num_cores_per_pkg + (core_no)) |
| 152 | #define GET_PKG(pkg_base, pkg_no) (pkg_base + pkg_no) |
| 153 | |
| 154 | struct system_summary { |
| 155 | struct thread_data threads; |
| 156 | struct core_data cores; |
| 157 | struct pkg_data packages; |
| 158 | } sum, average; |
| 159 | |
| 160 | |
| 161 | struct topo_params { |
| 162 | int num_packages; |
| 163 | int num_cpus; |
| 164 | int num_cores; |
| 165 | int max_cpu_num; |
| 166 | int num_cores_per_pkg; |
| 167 | int num_threads_per_core; |
| 168 | } topo; |
| 169 | |
| 170 | struct timeval tv_even, tv_odd, tv_delta; |
| 171 | |
| 172 | void setup_all_buffers(void); |
| 173 | |
| 174 | int cpu_is_not_present(int cpu) |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 175 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 176 | return !CPU_ISSET_S(cpu, cpu_present_setsize, cpu_present_set); |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 177 | } |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 178 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 179 | * run func(thread, core, package) in topology order |
| 180 | * skip non-present cpus |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 181 | */ |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 182 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 183 | int for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg_data *), |
| 184 | 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] | 185 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 186 | int retval, pkg_no, core_no, thread_no; |
| 187 | |
| 188 | for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { |
| 189 | for (core_no = 0; core_no < topo.num_cores_per_pkg; ++core_no) { |
| 190 | for (thread_no = 0; thread_no < |
| 191 | topo.num_threads_per_core; ++thread_no) { |
| 192 | struct thread_data *t; |
| 193 | struct core_data *c; |
| 194 | struct pkg_data *p; |
| 195 | |
| 196 | t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); |
| 197 | |
| 198 | if (cpu_is_not_present(t->cpu_id)) |
| 199 | continue; |
| 200 | |
| 201 | c = GET_CORE(core_base, core_no, pkg_no); |
| 202 | p = GET_PKG(pkg_base, pkg_no); |
| 203 | |
| 204 | retval = func(t, c, p); |
| 205 | if (retval) |
| 206 | return retval; |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | return 0; |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | int cpu_migrate(int cpu) |
| 214 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 215 | CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); |
| 216 | CPU_SET_S(cpu, cpu_affinity_setsize, cpu_affinity_set); |
| 217 | if (sched_setaffinity(0, cpu_affinity_setsize, cpu_affinity_set) == -1) |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 218 | return -1; |
| 219 | else |
| 220 | return 0; |
| 221 | } |
| 222 | |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 223 | int get_msr(int cpu, off_t offset, unsigned long long *msr) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 224 | { |
| 225 | ssize_t retval; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 226 | char pathname[32]; |
| 227 | int fd; |
| 228 | |
| 229 | sprintf(pathname, "/dev/cpu/%d/msr", cpu); |
| 230 | fd = open(pathname, O_RDONLY); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 231 | if (fd < 0) |
| 232 | return -1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 233 | |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 234 | retval = pread(fd, msr, sizeof *msr, offset); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 235 | close(fd); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 236 | |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 237 | if (retval != sizeof *msr) { |
Josh Triplett | 2e9c6bc | 2013-08-20 17:20:13 -0700 | [diff] [blame] | 238 | fprintf(stderr, "%s offset 0x%llx read failed\n", pathname, (unsigned long long)offset); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 239 | return -1; |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 240 | } |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 241 | |
| 242 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 243 | } |
| 244 | |
Len Brown | a829eb4 | 2011-02-10 23:36:34 -0500 | [diff] [blame] | 245 | void print_header(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 246 | { |
| 247 | if (show_pkg) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 248 | outp += sprintf(outp, "pk"); |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 249 | if (show_pkg) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 250 | outp += sprintf(outp, " "); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 251 | if (show_core) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 252 | outp += sprintf(outp, "cor"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 253 | if (show_cpu) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 254 | outp += sprintf(outp, " CPU"); |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 255 | if (show_pkg || show_core || show_cpu) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 256 | outp += sprintf(outp, " "); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 257 | if (do_nhm_cstates) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 258 | outp += sprintf(outp, " %%c0"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 259 | if (has_aperf) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 260 | outp += sprintf(outp, " GHz"); |
| 261 | outp += sprintf(outp, " TSC"); |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 262 | if (do_smi) |
| 263 | outp += sprintf(outp, " SMI"); |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 264 | if (extra_delta_offset32) |
Len Brown | f924081 | 2012-10-06 15:26:31 -0400 | [diff] [blame] | 265 | outp += sprintf(outp, " count 0x%03X", extra_delta_offset32); |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 266 | if (extra_delta_offset64) |
Len Brown | f924081 | 2012-10-06 15:26:31 -0400 | [diff] [blame] | 267 | outp += sprintf(outp, " COUNT 0x%03X", extra_delta_offset64); |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 268 | if (extra_msr_offset32) |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 269 | outp += sprintf(outp, " MSR 0x%03X", extra_msr_offset32); |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 270 | if (extra_msr_offset64) |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 271 | outp += sprintf(outp, " MSR 0x%03X", extra_msr_offset64); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 272 | if (do_nhm_cstates) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 273 | outp += sprintf(outp, " %%c1"); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 274 | if (do_nhm_cstates && !do_slm_cstates) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 275 | outp += sprintf(outp, " %%c3"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 276 | if (do_nhm_cstates) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 277 | outp += sprintf(outp, " %%c6"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 278 | if (do_snb_cstates) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 279 | outp += sprintf(outp, " %%c7"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 280 | |
| 281 | if (do_dts) |
| 282 | outp += sprintf(outp, " CTMP"); |
| 283 | if (do_ptm) |
| 284 | outp += sprintf(outp, " PTMP"); |
| 285 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 286 | if (do_snb_cstates) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 287 | outp += sprintf(outp, " %%pc2"); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 288 | if (do_nhm_cstates && !do_slm_cstates) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 289 | outp += sprintf(outp, " %%pc3"); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 290 | if (do_nhm_cstates && !do_slm_cstates) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 291 | outp += sprintf(outp, " %%pc6"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 292 | if (do_snb_cstates) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 293 | outp += sprintf(outp, " %%pc7"); |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 294 | if (do_c8_c9_c10) { |
| 295 | outp += sprintf(outp, " %%pc8"); |
| 296 | outp += sprintf(outp, " %%pc9"); |
| 297 | outp += sprintf(outp, " %%pc10"); |
| 298 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 299 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 300 | if (do_rapl & RAPL_PKG) |
| 301 | outp += sprintf(outp, " Pkg_W"); |
| 302 | if (do_rapl & RAPL_CORES) |
| 303 | outp += sprintf(outp, " Cor_W"); |
| 304 | if (do_rapl & RAPL_GFX) |
| 305 | outp += sprintf(outp, " GFX_W"); |
| 306 | if (do_rapl & RAPL_DRAM) |
| 307 | outp += sprintf(outp, " RAM_W"); |
| 308 | if (do_rapl & RAPL_PKG_PERF_STATUS) |
| 309 | outp += sprintf(outp, " PKG_%%"); |
| 310 | if (do_rapl & RAPL_DRAM_PERF_STATUS) |
| 311 | outp += sprintf(outp, " RAM_%%"); |
| 312 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 313 | outp += sprintf(outp, "\n"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 314 | } |
| 315 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 316 | int dump_counters(struct thread_data *t, struct core_data *c, |
| 317 | struct pkg_data *p) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 318 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 319 | fprintf(stderr, "t %p, c %p, p %p\n", t, c, p); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 320 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 321 | if (t) { |
| 322 | fprintf(stderr, "CPU: %d flags 0x%x\n", t->cpu_id, t->flags); |
| 323 | fprintf(stderr, "TSC: %016llX\n", t->tsc); |
| 324 | fprintf(stderr, "aperf: %016llX\n", t->aperf); |
| 325 | fprintf(stderr, "mperf: %016llX\n", t->mperf); |
| 326 | fprintf(stderr, "c1: %016llX\n", t->c1); |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 327 | fprintf(stderr, "msr0x%x: %08llX\n", |
| 328 | extra_delta_offset32, t->extra_delta32); |
| 329 | fprintf(stderr, "msr0x%x: %016llX\n", |
| 330 | extra_delta_offset64, t->extra_delta64); |
| 331 | fprintf(stderr, "msr0x%x: %08llX\n", |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 332 | extra_msr_offset32, t->extra_msr32); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 333 | fprintf(stderr, "msr0x%x: %016llX\n", |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 334 | extra_msr_offset64, t->extra_msr64); |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 335 | if (do_smi) |
| 336 | fprintf(stderr, "SMI: %08X\n", t->smi_count); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 337 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 338 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 339 | if (c) { |
| 340 | fprintf(stderr, "core: %d\n", c->core_id); |
| 341 | fprintf(stderr, "c3: %016llX\n", c->c3); |
| 342 | fprintf(stderr, "c6: %016llX\n", c->c6); |
| 343 | fprintf(stderr, "c7: %016llX\n", c->c7); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 344 | fprintf(stderr, "DTS: %dC\n", c->core_temp_c); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | if (p) { |
| 348 | fprintf(stderr, "package: %d\n", p->package_id); |
| 349 | fprintf(stderr, "pc2: %016llX\n", p->pc2); |
| 350 | fprintf(stderr, "pc3: %016llX\n", p->pc3); |
| 351 | fprintf(stderr, "pc6: %016llX\n", p->pc6); |
| 352 | fprintf(stderr, "pc7: %016llX\n", p->pc7); |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 353 | fprintf(stderr, "pc8: %016llX\n", p->pc8); |
| 354 | fprintf(stderr, "pc9: %016llX\n", p->pc9); |
| 355 | fprintf(stderr, "pc10: %016llX\n", p->pc10); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 356 | fprintf(stderr, "Joules PKG: %0X\n", p->energy_pkg); |
| 357 | fprintf(stderr, "Joules COR: %0X\n", p->energy_cores); |
| 358 | fprintf(stderr, "Joules GFX: %0X\n", p->energy_gfx); |
| 359 | fprintf(stderr, "Joules RAM: %0X\n", p->energy_dram); |
| 360 | fprintf(stderr, "Throttle PKG: %0X\n", p->rapl_pkg_perf_status); |
| 361 | fprintf(stderr, "Throttle RAM: %0X\n", p->rapl_dram_perf_status); |
| 362 | fprintf(stderr, "PTM: %dC\n", p->pkg_temp_c); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 363 | } |
| 364 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 365 | } |
| 366 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 367 | /* |
| 368 | * column formatting convention & formats |
| 369 | * package: "pk" 2 columns %2d |
| 370 | * core: "cor" 3 columns %3d |
| 371 | * CPU: "CPU" 3 columns %3d |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 372 | * Pkg_W: %6.2 |
| 373 | * Cor_W: %6.2 |
| 374 | * GFX_W: %5.2 |
| 375 | * RAM_W: %5.2 |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 376 | * GHz: "GHz" 3 columns %3.2 |
| 377 | * TSC: "TSC" 3 columns %3.2 |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 378 | * SMI: "SMI" 4 columns %4d |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 379 | * percentage " %pc3" %6.2 |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 380 | * Perf Status percentage: %5.2 |
| 381 | * "CTMP" 4 columns %4d |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 382 | */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 383 | int format_counters(struct thread_data *t, struct core_data *c, |
| 384 | struct pkg_data *p) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 385 | { |
| 386 | double interval_float; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 387 | char *fmt5, *fmt6; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 388 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 389 | /* if showing only 1st thread in core and this isn't one, bail out */ |
| 390 | if (show_core_only && !(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 391 | return 0; |
| 392 | |
| 393 | /* if showing only 1st thread in pkg and this isn't one, bail out */ |
| 394 | if (show_pkg_only && !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 395 | return 0; |
| 396 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 397 | interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0; |
| 398 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 399 | /* topo columns, print blanks on 1st (average) line */ |
| 400 | if (t == &average.threads) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 401 | if (show_pkg) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 402 | outp += sprintf(outp, " "); |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 403 | if (show_pkg && show_core) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 404 | outp += sprintf(outp, " "); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 405 | if (show_core) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 406 | outp += sprintf(outp, " "); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 407 | if (show_cpu) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 408 | outp += sprintf(outp, " " " "); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 409 | } else { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 410 | if (show_pkg) { |
| 411 | if (p) |
| 412 | outp += sprintf(outp, "%2d", p->package_id); |
| 413 | else |
| 414 | outp += sprintf(outp, " "); |
| 415 | } |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 416 | if (show_pkg && show_core) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 417 | outp += sprintf(outp, " "); |
| 418 | if (show_core) { |
| 419 | if (c) |
| 420 | outp += sprintf(outp, "%3d", c->core_id); |
| 421 | else |
| 422 | outp += sprintf(outp, " "); |
| 423 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 424 | if (show_cpu) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 425 | outp += sprintf(outp, " %3d", t->cpu_id); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 426 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 427 | /* %c0 */ |
| 428 | if (do_nhm_cstates) { |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 429 | if (show_pkg || show_core || show_cpu) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 430 | outp += sprintf(outp, " "); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 431 | if (!skip_c0) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 432 | outp += sprintf(outp, "%6.2f", 100.0 * t->mperf/t->tsc); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 433 | else |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 434 | outp += sprintf(outp, " ****"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | /* GHz */ |
| 438 | if (has_aperf) { |
| 439 | if (!aperf_mperf_unstable) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 440 | outp += sprintf(outp, " %3.2f", |
| 441 | 1.0 * t->tsc / units * t->aperf / |
| 442 | t->mperf / interval_float); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 443 | } else { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 444 | if (t->aperf > t->tsc || t->mperf > t->tsc) { |
| 445 | outp += sprintf(outp, " ***"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 446 | } else { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 447 | outp += sprintf(outp, "%3.1f*", |
| 448 | 1.0 * t->tsc / |
| 449 | units * t->aperf / |
| 450 | t->mperf / interval_float); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 451 | } |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | /* TSC */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 456 | outp += sprintf(outp, "%5.2f", 1.0 * t->tsc/units/interval_float); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 457 | |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 458 | /* SMI */ |
| 459 | if (do_smi) |
| 460 | outp += sprintf(outp, "%4d", t->smi_count); |
| 461 | |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 462 | /* delta */ |
| 463 | if (extra_delta_offset32) |
| 464 | outp += sprintf(outp, " %11llu", t->extra_delta32); |
| 465 | |
| 466 | /* DELTA */ |
| 467 | if (extra_delta_offset64) |
| 468 | outp += sprintf(outp, " %11llu", t->extra_delta64); |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 469 | /* msr */ |
| 470 | if (extra_msr_offset32) |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 471 | outp += sprintf(outp, " 0x%08llx", t->extra_msr32); |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 472 | |
Len Brown | 130ff30 | 2012-09-21 22:56:06 -0400 | [diff] [blame] | 473 | /* MSR */ |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 474 | if (extra_msr_offset64) |
| 475 | outp += sprintf(outp, " 0x%016llx", t->extra_msr64); |
Len Brown | 130ff30 | 2012-09-21 22:56:06 -0400 | [diff] [blame] | 476 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 477 | if (do_nhm_cstates) { |
| 478 | if (!skip_c1) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 479 | outp += sprintf(outp, " %6.2f", 100.0 * t->c1/t->tsc); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 480 | else |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 481 | outp += sprintf(outp, " ****"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 482 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 483 | |
| 484 | /* print per-core data only for 1st thread in core */ |
| 485 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 486 | goto done; |
| 487 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 488 | if (do_nhm_cstates && !do_slm_cstates) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 489 | outp += sprintf(outp, " %6.2f", 100.0 * c->c3/t->tsc); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 490 | if (do_nhm_cstates) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 491 | outp += sprintf(outp, " %6.2f", 100.0 * c->c6/t->tsc); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 492 | if (do_snb_cstates) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 493 | outp += sprintf(outp, " %6.2f", 100.0 * c->c7/t->tsc); |
| 494 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 495 | if (do_dts) |
| 496 | outp += sprintf(outp, " %4d", c->core_temp_c); |
| 497 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 498 | /* print per-package data only for 1st core in package */ |
| 499 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 500 | goto done; |
| 501 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 502 | if (do_ptm) |
| 503 | outp += sprintf(outp, " %4d", p->pkg_temp_c); |
| 504 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 505 | if (do_snb_cstates) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 506 | outp += sprintf(outp, " %6.2f", 100.0 * p->pc2/t->tsc); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 507 | if (do_nhm_cstates && !do_slm_cstates) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 508 | outp += sprintf(outp, " %6.2f", 100.0 * p->pc3/t->tsc); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 509 | if (do_nhm_cstates && !do_slm_cstates) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 510 | outp += sprintf(outp, " %6.2f", 100.0 * p->pc6/t->tsc); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 511 | if (do_snb_cstates) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 512 | outp += sprintf(outp, " %6.2f", 100.0 * p->pc7/t->tsc); |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 513 | if (do_c8_c9_c10) { |
| 514 | outp += sprintf(outp, " %6.2f", 100.0 * p->pc8/t->tsc); |
| 515 | outp += sprintf(outp, " %6.2f", 100.0 * p->pc9/t->tsc); |
| 516 | outp += sprintf(outp, " %6.2f", 100.0 * p->pc10/t->tsc); |
| 517 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 518 | |
| 519 | /* |
| 520 | * If measurement interval exceeds minimum RAPL Joule Counter range, |
| 521 | * indicate that results are suspect by printing "**" in fraction place. |
| 522 | */ |
| 523 | if (interval_float < rapl_joule_counter_range) { |
| 524 | fmt5 = " %5.2f"; |
| 525 | fmt6 = " %6.2f"; |
| 526 | } else { |
| 527 | fmt5 = " %3.0f**"; |
| 528 | fmt6 = " %4.0f**"; |
| 529 | } |
| 530 | |
| 531 | if (do_rapl & RAPL_PKG) |
| 532 | outp += sprintf(outp, fmt6, p->energy_pkg * rapl_energy_units / interval_float); |
| 533 | if (do_rapl & RAPL_CORES) |
| 534 | outp += sprintf(outp, fmt6, p->energy_cores * rapl_energy_units / interval_float); |
| 535 | if (do_rapl & RAPL_GFX) |
| 536 | outp += sprintf(outp, fmt5, p->energy_gfx * rapl_energy_units / interval_float); |
| 537 | if (do_rapl & RAPL_DRAM) |
| 538 | outp += sprintf(outp, fmt5, p->energy_dram * rapl_energy_units / interval_float); |
| 539 | if (do_rapl & RAPL_PKG_PERF_STATUS ) |
| 540 | outp += sprintf(outp, fmt5, 100.0 * p->rapl_pkg_perf_status * rapl_time_units / interval_float); |
| 541 | if (do_rapl & RAPL_DRAM_PERF_STATUS ) |
| 542 | outp += sprintf(outp, fmt5, 100.0 * p->rapl_dram_perf_status * rapl_time_units / interval_float); |
| 543 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 544 | done: |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 545 | outp += sprintf(outp, "\n"); |
| 546 | |
| 547 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 548 | } |
| 549 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 550 | void flush_stdout() |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 551 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 552 | fputs(output_buffer, stdout); |
Len Brown | ddac0d6 | 2012-11-30 01:01:40 -0500 | [diff] [blame] | 553 | fflush(stdout); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 554 | outp = output_buffer; |
| 555 | } |
| 556 | void flush_stderr() |
| 557 | { |
| 558 | fputs(output_buffer, stderr); |
| 559 | outp = output_buffer; |
| 560 | } |
| 561 | void format_all_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 562 | { |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 563 | static int printed; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 564 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 565 | if (!printed || !summary_only) |
| 566 | print_header(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 567 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 568 | if (topo.num_cpus > 1) |
| 569 | format_counters(&average.threads, &average.cores, |
| 570 | &average.packages); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 571 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 572 | printed = 1; |
| 573 | |
| 574 | if (summary_only) |
| 575 | return; |
| 576 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 577 | for_all_cpus(format_counters, t, c, p); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 578 | } |
| 579 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 580 | #define DELTA_WRAP32(new, old) \ |
| 581 | if (new > old) { \ |
| 582 | old = new - old; \ |
| 583 | } else { \ |
| 584 | old = 0x100000000 + new - old; \ |
| 585 | } |
| 586 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 587 | void |
| 588 | delta_package(struct pkg_data *new, struct pkg_data *old) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 589 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 590 | old->pc2 = new->pc2 - old->pc2; |
| 591 | old->pc3 = new->pc3 - old->pc3; |
| 592 | old->pc6 = new->pc6 - old->pc6; |
| 593 | old->pc7 = new->pc7 - old->pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 594 | old->pc8 = new->pc8 - old->pc8; |
| 595 | old->pc9 = new->pc9 - old->pc9; |
| 596 | old->pc10 = new->pc10 - old->pc10; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 597 | old->pkg_temp_c = new->pkg_temp_c; |
| 598 | |
| 599 | DELTA_WRAP32(new->energy_pkg, old->energy_pkg); |
| 600 | DELTA_WRAP32(new->energy_cores, old->energy_cores); |
| 601 | DELTA_WRAP32(new->energy_gfx, old->energy_gfx); |
| 602 | DELTA_WRAP32(new->energy_dram, old->energy_dram); |
| 603 | DELTA_WRAP32(new->rapl_pkg_perf_status, old->rapl_pkg_perf_status); |
| 604 | DELTA_WRAP32(new->rapl_dram_perf_status, old->rapl_dram_perf_status); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 605 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 606 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 607 | void |
| 608 | delta_core(struct core_data *new, struct core_data *old) |
| 609 | { |
| 610 | old->c3 = new->c3 - old->c3; |
| 611 | old->c6 = new->c6 - old->c6; |
| 612 | old->c7 = new->c7 - old->c7; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 613 | old->core_temp_c = new->core_temp_c; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 614 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 615 | |
Len Brown | c3ae331 | 2012-06-13 21:31:46 -0400 | [diff] [blame] | 616 | /* |
| 617 | * old = new - old |
| 618 | */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 619 | void |
| 620 | delta_thread(struct thread_data *new, struct thread_data *old, |
| 621 | struct core_data *core_delta) |
| 622 | { |
| 623 | old->tsc = new->tsc - old->tsc; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 624 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 625 | /* check for TSC < 1 Mcycles over interval */ |
| 626 | if (old->tsc < (1000 * 1000)) { |
| 627 | fprintf(stderr, "Insanely slow TSC rate, TSC stops in idle?\n"); |
| 628 | fprintf(stderr, "You can disable all c-states by booting with \"idle=poll\"\n"); |
| 629 | fprintf(stderr, "or just the deep ones with \"processor.max_cstate=1\"\n"); |
| 630 | exit(-3); |
| 631 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 632 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 633 | old->c1 = new->c1 - old->c1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 634 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 635 | if ((new->aperf > old->aperf) && (new->mperf > old->mperf)) { |
| 636 | old->aperf = new->aperf - old->aperf; |
| 637 | old->mperf = new->mperf - old->mperf; |
| 638 | } else { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 639 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 640 | if (!aperf_mperf_unstable) { |
| 641 | fprintf(stderr, "%s: APERF or MPERF went backwards *\n", progname); |
| 642 | fprintf(stderr, "* Frequency results do not cover entire interval *\n"); |
| 643 | fprintf(stderr, "* fix this by running Linux-2.6.30 or later *\n"); |
| 644 | |
| 645 | aperf_mperf_unstable = 1; |
| 646 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 647 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 648 | * mperf delta is likely a huge "positive" number |
| 649 | * can not use it for calculating c0 time |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 650 | */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 651 | skip_c0 = 1; |
| 652 | skip_c1 = 1; |
| 653 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 654 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 655 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 656 | if (use_c1_residency_msr) { |
| 657 | /* |
| 658 | * Some models have a dedicated C1 residency MSR, |
| 659 | * which should be more accurate than the derivation below. |
| 660 | */ |
| 661 | } else { |
| 662 | /* |
| 663 | * As counter collection is not atomic, |
| 664 | * it is possible for mperf's non-halted cycles + idle states |
| 665 | * to exceed TSC's all cycles: show c1 = 0% in that case. |
| 666 | */ |
| 667 | if ((old->mperf + core_delta->c3 + core_delta->c6 + core_delta->c7) > old->tsc) |
| 668 | old->c1 = 0; |
| 669 | else { |
| 670 | /* normal case, derive c1 */ |
| 671 | old->c1 = old->tsc - old->mperf - core_delta->c3 |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 672 | - core_delta->c6 - core_delta->c7; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 673 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 674 | } |
Len Brown | c3ae331 | 2012-06-13 21:31:46 -0400 | [diff] [blame] | 675 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 676 | if (old->mperf == 0) { |
Len Brown | c3ae331 | 2012-06-13 21:31:46 -0400 | [diff] [blame] | 677 | if (verbose > 1) fprintf(stderr, "cpu%d MPERF 0!\n", old->cpu_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 678 | old->mperf = 1; /* divide by 0 protection */ |
| 679 | } |
| 680 | |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 681 | old->extra_delta32 = new->extra_delta32 - old->extra_delta32; |
| 682 | old->extra_delta32 &= 0xFFFFFFFF; |
| 683 | |
| 684 | old->extra_delta64 = new->extra_delta64 - old->extra_delta64; |
| 685 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 686 | /* |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 687 | * Extra MSR is just a snapshot, simply copy latest w/o subtracting |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 688 | */ |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 689 | old->extra_msr32 = new->extra_msr32; |
| 690 | old->extra_msr64 = new->extra_msr64; |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 691 | |
| 692 | if (do_smi) |
| 693 | old->smi_count = new->smi_count - old->smi_count; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | int delta_cpu(struct thread_data *t, struct core_data *c, |
| 697 | struct pkg_data *p, struct thread_data *t2, |
| 698 | struct core_data *c2, struct pkg_data *p2) |
| 699 | { |
| 700 | /* calculate core delta only for 1st thread in core */ |
| 701 | if (t->flags & CPU_IS_FIRST_THREAD_IN_CORE) |
| 702 | delta_core(c, c2); |
| 703 | |
| 704 | /* always calculate thread delta */ |
| 705 | delta_thread(t, t2, c2); /* c2 is core delta */ |
| 706 | |
| 707 | /* calculate package delta only for 1st core in package */ |
| 708 | if (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE) |
| 709 | delta_package(p, p2); |
| 710 | |
| 711 | return 0; |
| 712 | } |
| 713 | |
| 714 | void clear_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 715 | { |
| 716 | t->tsc = 0; |
| 717 | t->aperf = 0; |
| 718 | t->mperf = 0; |
| 719 | t->c1 = 0; |
| 720 | |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 721 | t->smi_count = 0; |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 722 | t->extra_delta32 = 0; |
| 723 | t->extra_delta64 = 0; |
| 724 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 725 | /* tells format_counters to dump all fields from this set */ |
| 726 | t->flags = CPU_IS_FIRST_THREAD_IN_CORE | CPU_IS_FIRST_CORE_IN_PACKAGE; |
| 727 | |
| 728 | c->c3 = 0; |
| 729 | c->c6 = 0; |
| 730 | c->c7 = 0; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 731 | c->core_temp_c = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 732 | |
| 733 | p->pc2 = 0; |
| 734 | p->pc3 = 0; |
| 735 | p->pc6 = 0; |
| 736 | p->pc7 = 0; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 737 | p->pc8 = 0; |
| 738 | p->pc9 = 0; |
| 739 | p->pc10 = 0; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 740 | |
| 741 | p->energy_pkg = 0; |
| 742 | p->energy_dram = 0; |
| 743 | p->energy_cores = 0; |
| 744 | p->energy_gfx = 0; |
| 745 | p->rapl_pkg_perf_status = 0; |
| 746 | p->rapl_dram_perf_status = 0; |
| 747 | p->pkg_temp_c = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 748 | } |
| 749 | int sum_counters(struct thread_data *t, struct core_data *c, |
| 750 | struct pkg_data *p) |
| 751 | { |
| 752 | average.threads.tsc += t->tsc; |
| 753 | average.threads.aperf += t->aperf; |
| 754 | average.threads.mperf += t->mperf; |
| 755 | average.threads.c1 += t->c1; |
| 756 | |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 757 | average.threads.extra_delta32 += t->extra_delta32; |
| 758 | average.threads.extra_delta64 += t->extra_delta64; |
| 759 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 760 | /* sum per-core values only for 1st thread in core */ |
| 761 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 762 | return 0; |
| 763 | |
| 764 | average.cores.c3 += c->c3; |
| 765 | average.cores.c6 += c->c6; |
| 766 | average.cores.c7 += c->c7; |
| 767 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 768 | average.cores.core_temp_c = MAX(average.cores.core_temp_c, c->core_temp_c); |
| 769 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 770 | /* sum per-pkg values only for 1st core in pkg */ |
| 771 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 772 | return 0; |
| 773 | |
| 774 | average.packages.pc2 += p->pc2; |
| 775 | average.packages.pc3 += p->pc3; |
| 776 | average.packages.pc6 += p->pc6; |
| 777 | average.packages.pc7 += p->pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 778 | average.packages.pc8 += p->pc8; |
| 779 | average.packages.pc9 += p->pc9; |
| 780 | average.packages.pc10 += p->pc10; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 781 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 782 | average.packages.energy_pkg += p->energy_pkg; |
| 783 | average.packages.energy_dram += p->energy_dram; |
| 784 | average.packages.energy_cores += p->energy_cores; |
| 785 | average.packages.energy_gfx += p->energy_gfx; |
| 786 | |
| 787 | average.packages.pkg_temp_c = MAX(average.packages.pkg_temp_c, p->pkg_temp_c); |
| 788 | |
| 789 | average.packages.rapl_pkg_perf_status += p->rapl_pkg_perf_status; |
| 790 | average.packages.rapl_dram_perf_status += p->rapl_dram_perf_status; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 791 | return 0; |
| 792 | } |
| 793 | /* |
| 794 | * sum the counters for all cpus in the system |
| 795 | * compute the weighted average |
| 796 | */ |
| 797 | void compute_average(struct thread_data *t, struct core_data *c, |
| 798 | struct pkg_data *p) |
| 799 | { |
| 800 | clear_counters(&average.threads, &average.cores, &average.packages); |
| 801 | |
| 802 | for_all_cpus(sum_counters, t, c, p); |
| 803 | |
| 804 | average.threads.tsc /= topo.num_cpus; |
| 805 | average.threads.aperf /= topo.num_cpus; |
| 806 | average.threads.mperf /= topo.num_cpus; |
| 807 | average.threads.c1 /= topo.num_cpus; |
| 808 | |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 809 | average.threads.extra_delta32 /= topo.num_cpus; |
| 810 | average.threads.extra_delta32 &= 0xFFFFFFFF; |
| 811 | |
| 812 | average.threads.extra_delta64 /= topo.num_cpus; |
| 813 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 814 | average.cores.c3 /= topo.num_cores; |
| 815 | average.cores.c6 /= topo.num_cores; |
| 816 | average.cores.c7 /= topo.num_cores; |
| 817 | |
| 818 | average.packages.pc2 /= topo.num_packages; |
| 819 | average.packages.pc3 /= topo.num_packages; |
| 820 | average.packages.pc6 /= topo.num_packages; |
| 821 | average.packages.pc7 /= topo.num_packages; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 822 | |
| 823 | average.packages.pc8 /= topo.num_packages; |
| 824 | average.packages.pc9 /= topo.num_packages; |
| 825 | average.packages.pc10 /= topo.num_packages; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | static unsigned long long rdtsc(void) |
| 829 | { |
| 830 | unsigned int low, high; |
| 831 | |
| 832 | asm volatile("rdtsc" : "=a" (low), "=d" (high)); |
| 833 | |
| 834 | return low | ((unsigned long long)high) << 32; |
| 835 | } |
| 836 | |
| 837 | |
| 838 | /* |
| 839 | * get_counters(...) |
| 840 | * migrate to cpu |
| 841 | * acquire and record local counters for that cpu |
| 842 | */ |
| 843 | int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 844 | { |
| 845 | int cpu = t->cpu_id; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 846 | unsigned long long msr; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 847 | |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 848 | if (cpu_migrate(cpu)) { |
| 849 | fprintf(stderr, "Could not migrate to CPU %d\n", cpu); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 850 | return -1; |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 851 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 852 | |
| 853 | t->tsc = rdtsc(); /* we are running on local CPU of interest */ |
| 854 | |
| 855 | if (has_aperf) { |
Len Brown | 9c63a65 | 2012-10-31 01:29:52 -0400 | [diff] [blame] | 856 | if (get_msr(cpu, MSR_IA32_APERF, &t->aperf)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 857 | return -3; |
Len Brown | 9c63a65 | 2012-10-31 01:29:52 -0400 | [diff] [blame] | 858 | if (get_msr(cpu, MSR_IA32_MPERF, &t->mperf)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 859 | return -4; |
| 860 | } |
| 861 | |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 862 | if (do_smi) { |
| 863 | if (get_msr(cpu, MSR_SMI_COUNT, &msr)) |
| 864 | return -5; |
| 865 | t->smi_count = msr & 0xFFFFFFFF; |
| 866 | } |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 867 | if (extra_delta_offset32) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 868 | if (get_msr(cpu, extra_delta_offset32, &msr)) |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 869 | return -5; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 870 | t->extra_delta32 = msr & 0xFFFFFFFF; |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | if (extra_delta_offset64) |
| 874 | if (get_msr(cpu, extra_delta_offset64, &t->extra_delta64)) |
| 875 | return -5; |
| 876 | |
| 877 | if (extra_msr_offset32) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 878 | if (get_msr(cpu, extra_msr_offset32, &msr)) |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 879 | return -5; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 880 | t->extra_msr32 = msr & 0xFFFFFFFF; |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 881 | } |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 882 | |
| 883 | if (extra_msr_offset64) |
| 884 | if (get_msr(cpu, extra_msr_offset64, &t->extra_msr64)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 885 | return -5; |
| 886 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 887 | if (use_c1_residency_msr) { |
| 888 | if (get_msr(cpu, MSR_CORE_C1_RES, &t->c1)) |
| 889 | return -6; |
| 890 | } |
| 891 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 892 | /* collect core counters only for 1st thread in core */ |
| 893 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 894 | return 0; |
| 895 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 896 | if (do_nhm_cstates && !do_slm_cstates) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 897 | if (get_msr(cpu, MSR_CORE_C3_RESIDENCY, &c->c3)) |
| 898 | return -6; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | if (do_nhm_cstates) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 902 | if (get_msr(cpu, MSR_CORE_C6_RESIDENCY, &c->c6)) |
| 903 | return -7; |
| 904 | } |
| 905 | |
| 906 | if (do_snb_cstates) |
| 907 | if (get_msr(cpu, MSR_CORE_C7_RESIDENCY, &c->c7)) |
| 908 | return -8; |
| 909 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 910 | if (do_dts) { |
| 911 | if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr)) |
| 912 | return -9; |
| 913 | c->core_temp_c = tcc_activation_temp - ((msr >> 16) & 0x7F); |
| 914 | } |
| 915 | |
| 916 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 917 | /* collect package counters only for 1st core in package */ |
| 918 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 919 | return 0; |
| 920 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 921 | if (do_nhm_cstates && !do_slm_cstates) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 922 | if (get_msr(cpu, MSR_PKG_C3_RESIDENCY, &p->pc3)) |
| 923 | return -9; |
| 924 | if (get_msr(cpu, MSR_PKG_C6_RESIDENCY, &p->pc6)) |
| 925 | return -10; |
| 926 | } |
| 927 | if (do_snb_cstates) { |
| 928 | if (get_msr(cpu, MSR_PKG_C2_RESIDENCY, &p->pc2)) |
| 929 | return -11; |
| 930 | if (get_msr(cpu, MSR_PKG_C7_RESIDENCY, &p->pc7)) |
| 931 | return -12; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 932 | } |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 933 | if (do_c8_c9_c10) { |
| 934 | if (get_msr(cpu, MSR_PKG_C8_RESIDENCY, &p->pc8)) |
| 935 | return -13; |
| 936 | if (get_msr(cpu, MSR_PKG_C9_RESIDENCY, &p->pc9)) |
| 937 | return -13; |
| 938 | if (get_msr(cpu, MSR_PKG_C10_RESIDENCY, &p->pc10)) |
| 939 | return -13; |
| 940 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 941 | if (do_rapl & RAPL_PKG) { |
| 942 | if (get_msr(cpu, MSR_PKG_ENERGY_STATUS, &msr)) |
| 943 | return -13; |
| 944 | p->energy_pkg = msr & 0xFFFFFFFF; |
| 945 | } |
| 946 | if (do_rapl & RAPL_CORES) { |
| 947 | if (get_msr(cpu, MSR_PP0_ENERGY_STATUS, &msr)) |
| 948 | return -14; |
| 949 | p->energy_cores = msr & 0xFFFFFFFF; |
| 950 | } |
| 951 | if (do_rapl & RAPL_DRAM) { |
| 952 | if (get_msr(cpu, MSR_DRAM_ENERGY_STATUS, &msr)) |
| 953 | return -15; |
| 954 | p->energy_dram = msr & 0xFFFFFFFF; |
| 955 | } |
| 956 | if (do_rapl & RAPL_GFX) { |
| 957 | if (get_msr(cpu, MSR_PP1_ENERGY_STATUS, &msr)) |
| 958 | return -16; |
| 959 | p->energy_gfx = msr & 0xFFFFFFFF; |
| 960 | } |
| 961 | if (do_rapl & RAPL_PKG_PERF_STATUS) { |
| 962 | if (get_msr(cpu, MSR_PKG_PERF_STATUS, &msr)) |
| 963 | return -16; |
| 964 | p->rapl_pkg_perf_status = msr & 0xFFFFFFFF; |
| 965 | } |
| 966 | if (do_rapl & RAPL_DRAM_PERF_STATUS) { |
| 967 | if (get_msr(cpu, MSR_DRAM_PERF_STATUS, &msr)) |
| 968 | return -16; |
| 969 | p->rapl_dram_perf_status = msr & 0xFFFFFFFF; |
| 970 | } |
| 971 | if (do_ptm) { |
| 972 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr)) |
| 973 | return -17; |
| 974 | p->pkg_temp_c = tcc_activation_temp - ((msr >> 16) & 0x7F); |
| 975 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 976 | return 0; |
| 977 | } |
| 978 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 979 | void print_verbose_header(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 980 | { |
| 981 | unsigned long long msr; |
| 982 | unsigned int ratio; |
| 983 | |
| 984 | if (!do_nehalem_platform_info) |
| 985 | return; |
| 986 | |
Len Brown | 9c63a65 | 2012-10-31 01:29:52 -0400 | [diff] [blame] | 987 | get_msr(0, MSR_NHM_PLATFORM_INFO, &msr); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 988 | |
Len Brown | 6792041 | 2013-01-31 15:22:15 -0500 | [diff] [blame] | 989 | fprintf(stderr, "cpu0: MSR_NHM_PLATFORM_INFO: 0x%08llx\n", msr); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 990 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 991 | ratio = (msr >> 40) & 0xFF; |
| 992 | fprintf(stderr, "%d * %.0f = %.0f MHz max efficiency\n", |
| 993 | ratio, bclk, ratio * bclk); |
| 994 | |
| 995 | ratio = (msr >> 8) & 0xFF; |
| 996 | fprintf(stderr, "%d * %.0f = %.0f MHz TSC frequency\n", |
| 997 | ratio, bclk, ratio * bclk); |
| 998 | |
Len Brown | 6792041 | 2013-01-31 15:22:15 -0500 | [diff] [blame] | 999 | get_msr(0, MSR_IA32_POWER_CTL, &msr); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1000 | fprintf(stderr, "cpu0: MSR_IA32_POWER_CTL: 0x%08llx (C1E auto-promotion: %sabled)\n", |
Len Brown | 6792041 | 2013-01-31 15:22:15 -0500 | [diff] [blame] | 1001 | msr, msr & 0x2 ? "EN" : "DIS"); |
| 1002 | |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1003 | if (!do_ivt_turbo_ratio_limit) |
| 1004 | goto print_nhm_turbo_ratio_limits; |
| 1005 | |
| 1006 | get_msr(0, MSR_IVT_TURBO_RATIO_LIMIT, &msr); |
| 1007 | |
Len Brown | 6792041 | 2013-01-31 15:22:15 -0500 | [diff] [blame] | 1008 | fprintf(stderr, "cpu0: MSR_IVT_TURBO_RATIO_LIMIT: 0x%08llx\n", msr); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1009 | |
| 1010 | ratio = (msr >> 56) & 0xFF; |
| 1011 | if (ratio) |
| 1012 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 16 active cores\n", |
| 1013 | ratio, bclk, ratio * bclk); |
| 1014 | |
| 1015 | ratio = (msr >> 48) & 0xFF; |
| 1016 | if (ratio) |
| 1017 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 15 active cores\n", |
| 1018 | ratio, bclk, ratio * bclk); |
| 1019 | |
| 1020 | ratio = (msr >> 40) & 0xFF; |
| 1021 | if (ratio) |
| 1022 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 14 active cores\n", |
| 1023 | ratio, bclk, ratio * bclk); |
| 1024 | |
| 1025 | ratio = (msr >> 32) & 0xFF; |
| 1026 | if (ratio) |
| 1027 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 13 active cores\n", |
| 1028 | ratio, bclk, ratio * bclk); |
| 1029 | |
| 1030 | ratio = (msr >> 24) & 0xFF; |
| 1031 | if (ratio) |
| 1032 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 12 active cores\n", |
| 1033 | ratio, bclk, ratio * bclk); |
| 1034 | |
| 1035 | ratio = (msr >> 16) & 0xFF; |
| 1036 | if (ratio) |
| 1037 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 11 active cores\n", |
| 1038 | ratio, bclk, ratio * bclk); |
| 1039 | |
| 1040 | ratio = (msr >> 8) & 0xFF; |
| 1041 | if (ratio) |
| 1042 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 10 active cores\n", |
| 1043 | ratio, bclk, ratio * bclk); |
| 1044 | |
| 1045 | ratio = (msr >> 0) & 0xFF; |
| 1046 | if (ratio) |
| 1047 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 9 active cores\n", |
| 1048 | ratio, bclk, ratio * bclk); |
| 1049 | |
| 1050 | print_nhm_turbo_ratio_limits: |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1051 | get_msr(0, MSR_NHM_SNB_PKG_CST_CFG_CTL, &msr); |
| 1052 | |
| 1053 | #define SNB_C1_AUTO_UNDEMOTE (1UL << 27) |
| 1054 | #define SNB_C3_AUTO_UNDEMOTE (1UL << 28) |
| 1055 | |
| 1056 | fprintf(stderr, "cpu0: MSR_NHM_SNB_PKG_CST_CFG_CTL: 0x%08llx", msr); |
| 1057 | |
| 1058 | fprintf(stderr, " (%s%s%s%s%slocked: pkg-cstate-limit=%d: ", |
| 1059 | (msr & SNB_C3_AUTO_UNDEMOTE) ? "UNdemote-C3, " : "", |
| 1060 | (msr & SNB_C1_AUTO_UNDEMOTE) ? "UNdemote-C1, " : "", |
| 1061 | (msr & NHM_C3_AUTO_DEMOTE) ? "demote-C3, " : "", |
| 1062 | (msr & NHM_C1_AUTO_DEMOTE) ? "demote-C1, " : "", |
| 1063 | (msr & (1 << 15)) ? "" : "UN", |
| 1064 | (unsigned int)msr & 7); |
| 1065 | |
| 1066 | |
| 1067 | switch(msr & 0x7) { |
| 1068 | case 0: |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1069 | fprintf(stderr, do_slm_cstates ? "no pkg states" : "pc0"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1070 | break; |
| 1071 | case 1: |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1072 | fprintf(stderr, do_slm_cstates ? "no pkg states" : do_snb_cstates ? "pc2" : "pc0"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1073 | break; |
| 1074 | case 2: |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1075 | fprintf(stderr, do_slm_cstates ? "invalid" : do_snb_cstates ? "pc6-noret" : "pc3"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1076 | break; |
| 1077 | case 3: |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1078 | fprintf(stderr, do_slm_cstates ? "invalid" : "pc6"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1079 | break; |
| 1080 | case 4: |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1081 | fprintf(stderr, do_slm_cstates ? "pc4" : "pc7"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1082 | break; |
| 1083 | case 5: |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1084 | fprintf(stderr, do_slm_cstates ? "invalid" : do_snb_cstates ? "pc7s" : "invalid"); |
| 1085 | break; |
| 1086 | case 6: |
| 1087 | fprintf(stderr, do_slm_cstates ? "pc6" : "invalid"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1088 | break; |
| 1089 | case 7: |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1090 | fprintf(stderr, do_slm_cstates ? "pc7" : "unlimited"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1091 | break; |
| 1092 | default: |
| 1093 | fprintf(stderr, "invalid"); |
| 1094 | } |
| 1095 | fprintf(stderr, ")\n"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1096 | |
| 1097 | if (!do_nehalem_turbo_ratio_limit) |
| 1098 | return; |
| 1099 | |
Len Brown | 9c63a65 | 2012-10-31 01:29:52 -0400 | [diff] [blame] | 1100 | get_msr(0, MSR_NHM_TURBO_RATIO_LIMIT, &msr); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1101 | |
Len Brown | 6792041 | 2013-01-31 15:22:15 -0500 | [diff] [blame] | 1102 | fprintf(stderr, "cpu0: MSR_NHM_TURBO_RATIO_LIMIT: 0x%08llx\n", msr); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1103 | |
| 1104 | ratio = (msr >> 56) & 0xFF; |
| 1105 | if (ratio) |
| 1106 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 8 active cores\n", |
| 1107 | ratio, bclk, ratio * bclk); |
| 1108 | |
| 1109 | ratio = (msr >> 48) & 0xFF; |
| 1110 | if (ratio) |
| 1111 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 7 active cores\n", |
| 1112 | ratio, bclk, ratio * bclk); |
| 1113 | |
| 1114 | ratio = (msr >> 40) & 0xFF; |
| 1115 | if (ratio) |
| 1116 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 6 active cores\n", |
| 1117 | ratio, bclk, ratio * bclk); |
| 1118 | |
| 1119 | ratio = (msr >> 32) & 0xFF; |
| 1120 | if (ratio) |
| 1121 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 5 active cores\n", |
| 1122 | ratio, bclk, ratio * bclk); |
| 1123 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1124 | ratio = (msr >> 24) & 0xFF; |
| 1125 | if (ratio) |
| 1126 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 4 active cores\n", |
| 1127 | ratio, bclk, ratio * bclk); |
| 1128 | |
| 1129 | ratio = (msr >> 16) & 0xFF; |
| 1130 | if (ratio) |
| 1131 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 3 active cores\n", |
| 1132 | ratio, bclk, ratio * bclk); |
| 1133 | |
| 1134 | ratio = (msr >> 8) & 0xFF; |
| 1135 | if (ratio) |
| 1136 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 2 active cores\n", |
| 1137 | ratio, bclk, ratio * bclk); |
| 1138 | |
| 1139 | ratio = (msr >> 0) & 0xFF; |
| 1140 | if (ratio) |
| 1141 | fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 1 active cores\n", |
| 1142 | ratio, bclk, ratio * bclk); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1143 | } |
| 1144 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1145 | void free_all_buffers(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1146 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1147 | CPU_FREE(cpu_present_set); |
| 1148 | cpu_present_set = NULL; |
| 1149 | cpu_present_set = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1150 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1151 | CPU_FREE(cpu_affinity_set); |
| 1152 | cpu_affinity_set = NULL; |
| 1153 | cpu_affinity_setsize = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1154 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1155 | free(thread_even); |
| 1156 | free(core_even); |
| 1157 | free(package_even); |
| 1158 | |
| 1159 | thread_even = NULL; |
| 1160 | core_even = NULL; |
| 1161 | package_even = NULL; |
| 1162 | |
| 1163 | free(thread_odd); |
| 1164 | free(core_odd); |
| 1165 | free(package_odd); |
| 1166 | |
| 1167 | thread_odd = NULL; |
| 1168 | core_odd = NULL; |
| 1169 | package_odd = NULL; |
| 1170 | |
| 1171 | free(output_buffer); |
| 1172 | output_buffer = NULL; |
| 1173 | outp = NULL; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1174 | } |
| 1175 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1176 | /* |
| 1177 | * cpu_is_first_sibling_in_core(cpu) |
| 1178 | * return 1 if given CPU is 1st HT sibling in the core |
| 1179 | */ |
| 1180 | int cpu_is_first_sibling_in_core(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1181 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1182 | char path[64]; |
| 1183 | FILE *filep; |
| 1184 | int first_cpu; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1185 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1186 | sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu); |
| 1187 | filep = fopen(path, "r"); |
| 1188 | if (filep == NULL) { |
| 1189 | perror(path); |
| 1190 | exit(1); |
| 1191 | } |
| 1192 | fscanf(filep, "%d", &first_cpu); |
| 1193 | fclose(filep); |
| 1194 | return (cpu == first_cpu); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1195 | } |
| 1196 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1197 | /* |
| 1198 | * cpu_is_first_core_in_package(cpu) |
| 1199 | * return 1 if given CPU is 1st core in package |
| 1200 | */ |
| 1201 | int cpu_is_first_core_in_package(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1202 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1203 | char path[64]; |
| 1204 | FILE *filep; |
| 1205 | int first_cpu; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1206 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1207 | sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/core_siblings_list", cpu); |
| 1208 | filep = fopen(path, "r"); |
| 1209 | if (filep == NULL) { |
| 1210 | perror(path); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1211 | exit(1); |
| 1212 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1213 | fscanf(filep, "%d", &first_cpu); |
| 1214 | fclose(filep); |
| 1215 | return (cpu == first_cpu); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | int get_physical_package_id(int cpu) |
| 1219 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1220 | char path[80]; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1221 | FILE *filep; |
| 1222 | int pkg; |
| 1223 | |
| 1224 | sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/physical_package_id", cpu); |
| 1225 | filep = fopen(path, "r"); |
| 1226 | if (filep == NULL) { |
| 1227 | perror(path); |
| 1228 | exit(1); |
| 1229 | } |
| 1230 | fscanf(filep, "%d", &pkg); |
| 1231 | fclose(filep); |
| 1232 | return pkg; |
| 1233 | } |
| 1234 | |
| 1235 | int get_core_id(int cpu) |
| 1236 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1237 | char path[80]; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1238 | FILE *filep; |
| 1239 | int core; |
| 1240 | |
| 1241 | sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/core_id", cpu); |
| 1242 | filep = fopen(path, "r"); |
| 1243 | if (filep == NULL) { |
| 1244 | perror(path); |
| 1245 | exit(1); |
| 1246 | } |
| 1247 | fscanf(filep, "%d", &core); |
| 1248 | fclose(filep); |
| 1249 | return core; |
| 1250 | } |
| 1251 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1252 | int get_num_ht_siblings(int cpu) |
| 1253 | { |
| 1254 | char path[80]; |
| 1255 | FILE *filep; |
| 1256 | int sib1, sib2; |
| 1257 | int matches; |
| 1258 | char character; |
| 1259 | |
| 1260 | sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu); |
| 1261 | filep = fopen(path, "r"); |
| 1262 | if (filep == NULL) { |
| 1263 | perror(path); |
| 1264 | exit(1); |
| 1265 | } |
| 1266 | /* |
| 1267 | * file format: |
| 1268 | * if a pair of number with a character between: 2 siblings (eg. 1-2, or 1,4) |
| 1269 | * otherwinse 1 sibling (self). |
| 1270 | */ |
| 1271 | matches = fscanf(filep, "%d%c%d\n", &sib1, &character, &sib2); |
| 1272 | |
| 1273 | fclose(filep); |
| 1274 | |
| 1275 | if (matches == 3) |
| 1276 | return 2; |
| 1277 | else |
| 1278 | return 1; |
| 1279 | } |
| 1280 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1281 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1282 | * run func(thread, core, package) in topology order |
| 1283 | * skip non-present cpus |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1284 | */ |
| 1285 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1286 | int for_all_cpus_2(int (func)(struct thread_data *, struct core_data *, |
| 1287 | struct pkg_data *, struct thread_data *, struct core_data *, |
| 1288 | struct pkg_data *), struct thread_data *thread_base, |
| 1289 | struct core_data *core_base, struct pkg_data *pkg_base, |
| 1290 | struct thread_data *thread_base2, struct core_data *core_base2, |
| 1291 | struct pkg_data *pkg_base2) |
| 1292 | { |
| 1293 | int retval, pkg_no, core_no, thread_no; |
| 1294 | |
| 1295 | for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { |
| 1296 | for (core_no = 0; core_no < topo.num_cores_per_pkg; ++core_no) { |
| 1297 | for (thread_no = 0; thread_no < |
| 1298 | topo.num_threads_per_core; ++thread_no) { |
| 1299 | struct thread_data *t, *t2; |
| 1300 | struct core_data *c, *c2; |
| 1301 | struct pkg_data *p, *p2; |
| 1302 | |
| 1303 | t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); |
| 1304 | |
| 1305 | if (cpu_is_not_present(t->cpu_id)) |
| 1306 | continue; |
| 1307 | |
| 1308 | t2 = GET_THREAD(thread_base2, thread_no, core_no, pkg_no); |
| 1309 | |
| 1310 | c = GET_CORE(core_base, core_no, pkg_no); |
| 1311 | c2 = GET_CORE(core_base2, core_no, pkg_no); |
| 1312 | |
| 1313 | p = GET_PKG(pkg_base, pkg_no); |
| 1314 | p2 = GET_PKG(pkg_base2, pkg_no); |
| 1315 | |
| 1316 | retval = func(t, c, p, t2, c2, p2); |
| 1317 | if (retval) |
| 1318 | return retval; |
| 1319 | } |
| 1320 | } |
| 1321 | } |
| 1322 | return 0; |
| 1323 | } |
| 1324 | |
| 1325 | /* |
| 1326 | * run func(cpu) on every cpu in /proc/stat |
| 1327 | * return max_cpu number |
| 1328 | */ |
| 1329 | int for_all_proc_cpus(int (func)(int)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1330 | { |
| 1331 | FILE *fp; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1332 | int cpu_num; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1333 | int retval; |
| 1334 | |
| 1335 | fp = fopen(proc_stat, "r"); |
| 1336 | if (fp == NULL) { |
| 1337 | perror(proc_stat); |
| 1338 | exit(1); |
| 1339 | } |
| 1340 | |
| 1341 | retval = fscanf(fp, "cpu %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n"); |
| 1342 | if (retval != 0) { |
| 1343 | perror("/proc/stat format"); |
| 1344 | exit(1); |
| 1345 | } |
| 1346 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1347 | while (1) { |
| 1348 | 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] | 1349 | if (retval != 1) |
| 1350 | break; |
| 1351 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1352 | retval = func(cpu_num); |
| 1353 | if (retval) { |
| 1354 | fclose(fp); |
| 1355 | return(retval); |
| 1356 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1357 | } |
| 1358 | fclose(fp); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1359 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | void re_initialize(void) |
| 1363 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1364 | free_all_buffers(); |
| 1365 | setup_all_buffers(); |
| 1366 | printf("turbostat: re-initialized with num_cpus %d\n", topo.num_cpus); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1367 | } |
| 1368 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1369 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1370 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1371 | * count_cpus() |
| 1372 | * remember the last one seen, it will be the max |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1373 | */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1374 | int count_cpus(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1375 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1376 | if (topo.max_cpu_num < cpu) |
| 1377 | topo.max_cpu_num = cpu; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1378 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1379 | topo.num_cpus += 1; |
| 1380 | return 0; |
| 1381 | } |
| 1382 | int mark_cpu_present(int cpu) |
| 1383 | { |
| 1384 | CPU_SET_S(cpu, cpu_present_setsize, cpu_present_set); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 1385 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | void turbostat_loop() |
| 1389 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1390 | int retval; |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 1391 | int restarted = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1392 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1393 | restart: |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 1394 | restarted++; |
| 1395 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1396 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 1397 | if (retval < -1) { |
| 1398 | exit(retval); |
| 1399 | } else if (retval == -1) { |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 1400 | if (restarted > 1) { |
| 1401 | exit(retval); |
| 1402 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1403 | re_initialize(); |
| 1404 | goto restart; |
| 1405 | } |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 1406 | restarted = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1407 | gettimeofday(&tv_even, (struct timezone *)NULL); |
| 1408 | |
| 1409 | while (1) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1410 | if (for_all_proc_cpus(cpu_is_not_present)) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1411 | re_initialize(); |
| 1412 | goto restart; |
| 1413 | } |
| 1414 | sleep(interval_sec); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1415 | retval = for_all_cpus(get_counters, ODD_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 1416 | if (retval < -1) { |
| 1417 | exit(retval); |
| 1418 | } else if (retval == -1) { |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 1419 | re_initialize(); |
| 1420 | goto restart; |
| 1421 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1422 | gettimeofday(&tv_odd, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1423 | timersub(&tv_odd, &tv_even, &tv_delta); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1424 | for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS); |
| 1425 | compute_average(EVEN_COUNTERS); |
| 1426 | format_all_counters(EVEN_COUNTERS); |
| 1427 | flush_stdout(); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 1428 | sleep(interval_sec); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1429 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 1430 | if (retval < -1) { |
| 1431 | exit(retval); |
| 1432 | } else if (retval == -1) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1433 | re_initialize(); |
| 1434 | goto restart; |
| 1435 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1436 | gettimeofday(&tv_even, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1437 | timersub(&tv_even, &tv_odd, &tv_delta); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1438 | for_all_cpus_2(delta_cpu, EVEN_COUNTERS, ODD_COUNTERS); |
| 1439 | compute_average(ODD_COUNTERS); |
| 1440 | format_all_counters(ODD_COUNTERS); |
| 1441 | flush_stdout(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1442 | } |
| 1443 | } |
| 1444 | |
| 1445 | void check_dev_msr() |
| 1446 | { |
| 1447 | struct stat sb; |
| 1448 | |
| 1449 | if (stat("/dev/cpu/0/msr", &sb)) { |
| 1450 | fprintf(stderr, "no /dev/cpu/0/msr\n"); |
| 1451 | fprintf(stderr, "Try \"# modprobe msr\"\n"); |
| 1452 | exit(-5); |
| 1453 | } |
| 1454 | } |
| 1455 | |
| 1456 | void check_super_user() |
| 1457 | { |
| 1458 | if (getuid() != 0) { |
| 1459 | fprintf(stderr, "must be root\n"); |
| 1460 | exit(-6); |
| 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | int has_nehalem_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 1465 | { |
| 1466 | if (!genuine_intel) |
| 1467 | return 0; |
| 1468 | |
| 1469 | if (family != 6) |
| 1470 | return 0; |
| 1471 | |
| 1472 | switch (model) { |
| 1473 | case 0x1A: /* Core i7, Xeon 5500 series - Bloomfield, Gainstown NHM-EP */ |
| 1474 | case 0x1E: /* Core i7 and i5 Processor - Clarksfield, Lynnfield, Jasper Forest */ |
| 1475 | case 0x1F: /* Core i7 and i5 Processor - Nehalem */ |
| 1476 | case 0x25: /* Westmere Client - Clarkdale, Arrandale */ |
| 1477 | case 0x2C: /* Westmere EP - Gulftown */ |
| 1478 | case 0x2A: /* SNB */ |
| 1479 | case 0x2D: /* SNB Xeon */ |
Len Brown | 553575f | 2011-11-18 03:32:01 -0500 | [diff] [blame] | 1480 | case 0x3A: /* IVB */ |
Len Brown | 1300651 | 2012-09-26 18:11:31 -0400 | [diff] [blame] | 1481 | case 0x3E: /* IVB Xeon */ |
Len Brown | 70b4340 | 2013-01-08 01:26:07 -0500 | [diff] [blame] | 1482 | case 0x3C: /* HSW */ |
| 1483 | case 0x3F: /* HSW */ |
| 1484 | case 0x45: /* HSW */ |
Len Brown | 149c231 | 2013-03-15 10:58:02 -0400 | [diff] [blame] | 1485 | case 0x46: /* HSW */ |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1486 | case 0x37: /* BYT */ |
| 1487 | case 0x4D: /* AVN */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1488 | return 1; |
| 1489 | case 0x2E: /* Nehalem-EX Xeon - Beckton */ |
| 1490 | case 0x2F: /* Westmere-EX Xeon - Eagleton */ |
| 1491 | default: |
| 1492 | return 0; |
| 1493 | } |
| 1494 | } |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 1495 | int has_ivt_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 1496 | { |
| 1497 | if (!genuine_intel) |
| 1498 | return 0; |
| 1499 | |
| 1500 | if (family != 6) |
| 1501 | return 0; |
| 1502 | |
| 1503 | switch (model) { |
| 1504 | case 0x3E: /* IVB Xeon */ |
| 1505 | return 1; |
| 1506 | default: |
| 1507 | return 0; |
| 1508 | } |
| 1509 | } |
| 1510 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1511 | /* |
| 1512 | * print_epb() |
| 1513 | * Decode the ENERGY_PERF_BIAS MSR |
| 1514 | */ |
| 1515 | int print_epb(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 1516 | { |
| 1517 | unsigned long long msr; |
| 1518 | char *epb_string; |
| 1519 | int cpu; |
| 1520 | |
| 1521 | if (!has_epb) |
| 1522 | return 0; |
| 1523 | |
| 1524 | cpu = t->cpu_id; |
| 1525 | |
| 1526 | /* EPB is per-package */ |
| 1527 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 1528 | return 0; |
| 1529 | |
| 1530 | if (cpu_migrate(cpu)) { |
| 1531 | fprintf(stderr, "Could not migrate to CPU %d\n", cpu); |
| 1532 | return -1; |
| 1533 | } |
| 1534 | |
| 1535 | if (get_msr(cpu, MSR_IA32_ENERGY_PERF_BIAS, &msr)) |
| 1536 | return 0; |
| 1537 | |
| 1538 | switch (msr & 0x7) { |
| 1539 | case ENERGY_PERF_BIAS_PERFORMANCE: |
| 1540 | epb_string = "performance"; |
| 1541 | break; |
| 1542 | case ENERGY_PERF_BIAS_NORMAL: |
| 1543 | epb_string = "balanced"; |
| 1544 | break; |
| 1545 | case ENERGY_PERF_BIAS_POWERSAVE: |
| 1546 | epb_string = "powersave"; |
| 1547 | break; |
| 1548 | default: |
| 1549 | epb_string = "custom"; |
| 1550 | break; |
| 1551 | } |
| 1552 | fprintf(stderr, "cpu%d: MSR_IA32_ENERGY_PERF_BIAS: 0x%08llx (%s)\n", cpu, msr, epb_string); |
| 1553 | |
| 1554 | return 0; |
| 1555 | } |
| 1556 | |
| 1557 | #define RAPL_POWER_GRANULARITY 0x7FFF /* 15 bit power granularity */ |
| 1558 | #define RAPL_TIME_GRANULARITY 0x3F /* 6 bit time granularity */ |
| 1559 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1560 | double get_tdp(model) |
| 1561 | { |
| 1562 | unsigned long long msr; |
| 1563 | |
| 1564 | if (do_rapl & RAPL_PKG_POWER_INFO) |
| 1565 | if (!get_msr(0, MSR_PKG_POWER_INFO, &msr)) |
| 1566 | return ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units; |
| 1567 | |
| 1568 | switch (model) { |
| 1569 | case 0x37: |
| 1570 | case 0x4D: |
| 1571 | return 30.0; |
| 1572 | default: |
| 1573 | return 135.0; |
| 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1578 | /* |
| 1579 | * rapl_probe() |
| 1580 | * |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1581 | * sets do_rapl, rapl_power_units, rapl_energy_units, rapl_time_units |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1582 | */ |
| 1583 | void rapl_probe(unsigned int family, unsigned int model) |
| 1584 | { |
| 1585 | unsigned long long msr; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1586 | unsigned int time_unit; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1587 | double tdp; |
| 1588 | |
| 1589 | if (!genuine_intel) |
| 1590 | return; |
| 1591 | |
| 1592 | if (family != 6) |
| 1593 | return; |
| 1594 | |
| 1595 | switch (model) { |
| 1596 | case 0x2A: |
| 1597 | case 0x3A: |
Len Brown | 70b4340 | 2013-01-08 01:26:07 -0500 | [diff] [blame] | 1598 | case 0x3C: /* HSW */ |
| 1599 | case 0x3F: /* HSW */ |
| 1600 | case 0x45: /* HSW */ |
Len Brown | 149c231 | 2013-03-15 10:58:02 -0400 | [diff] [blame] | 1601 | case 0x46: /* HSW */ |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1602 | 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] | 1603 | break; |
| 1604 | case 0x2D: |
| 1605 | case 0x3E: |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1606 | do_rapl = RAPL_PKG | RAPL_CORES | RAPL_CORE_POLICY | RAPL_DRAM | RAPL_PKG_PERF_STATUS | RAPL_DRAM_PERF_STATUS | RAPL_PKG_POWER_INFO; |
| 1607 | break; |
| 1608 | case 0x37: /* BYT */ |
| 1609 | case 0x4D: /* AVN */ |
| 1610 | do_rapl = RAPL_PKG | RAPL_CORES ; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1611 | break; |
| 1612 | default: |
| 1613 | return; |
| 1614 | } |
| 1615 | |
| 1616 | /* units on package 0, verify later other packages match */ |
| 1617 | if (get_msr(0, MSR_RAPL_POWER_UNIT, &msr)) |
| 1618 | return; |
| 1619 | |
| 1620 | rapl_power_units = 1.0 / (1 << (msr & 0xF)); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1621 | if (model == 0x37) |
| 1622 | rapl_energy_units = 1.0 * (1 << (msr >> 8 & 0x1F)) / 1000000; |
| 1623 | else |
| 1624 | rapl_energy_units = 1.0 / (1 << (msr >> 8 & 0x1F)); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1625 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1626 | time_unit = msr >> 16 & 0xF; |
| 1627 | if (time_unit == 0) |
| 1628 | time_unit = 0xA; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1629 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1630 | rapl_time_units = 1.0 / (1 << (time_unit)); |
| 1631 | |
| 1632 | tdp = get_tdp(model); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1633 | |
| 1634 | rapl_joule_counter_range = 0xFFFFFFFF * rapl_energy_units / tdp; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1635 | if (verbose) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1636 | 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] | 1637 | |
| 1638 | return; |
| 1639 | } |
| 1640 | |
| 1641 | int print_thermal(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 1642 | { |
| 1643 | unsigned long long msr; |
| 1644 | unsigned int dts; |
| 1645 | int cpu; |
| 1646 | |
| 1647 | if (!(do_dts || do_ptm)) |
| 1648 | return 0; |
| 1649 | |
| 1650 | cpu = t->cpu_id; |
| 1651 | |
| 1652 | /* DTS is per-core, no need to print for each thread */ |
| 1653 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 1654 | return 0; |
| 1655 | |
| 1656 | if (cpu_migrate(cpu)) { |
| 1657 | fprintf(stderr, "Could not migrate to CPU %d\n", cpu); |
| 1658 | return -1; |
| 1659 | } |
| 1660 | |
| 1661 | if (do_ptm && (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) { |
| 1662 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr)) |
| 1663 | return 0; |
| 1664 | |
| 1665 | dts = (msr >> 16) & 0x7F; |
| 1666 | fprintf(stderr, "cpu%d: MSR_IA32_PACKAGE_THERM_STATUS: 0x%08llx (%d C)\n", |
| 1667 | cpu, msr, tcc_activation_temp - dts); |
| 1668 | |
| 1669 | #ifdef THERM_DEBUG |
| 1670 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, &msr)) |
| 1671 | return 0; |
| 1672 | |
| 1673 | dts = (msr >> 16) & 0x7F; |
| 1674 | dts2 = (msr >> 8) & 0x7F; |
| 1675 | fprintf(stderr, "cpu%d: MSR_IA32_PACKAGE_THERM_INTERRUPT: 0x%08llx (%d C, %d C)\n", |
| 1676 | cpu, msr, tcc_activation_temp - dts, tcc_activation_temp - dts2); |
| 1677 | #endif |
| 1678 | } |
| 1679 | |
| 1680 | |
| 1681 | if (do_dts) { |
| 1682 | unsigned int resolution; |
| 1683 | |
| 1684 | if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr)) |
| 1685 | return 0; |
| 1686 | |
| 1687 | dts = (msr >> 16) & 0x7F; |
| 1688 | resolution = (msr >> 27) & 0xF; |
| 1689 | fprintf(stderr, "cpu%d: MSR_IA32_THERM_STATUS: 0x%08llx (%d C +/- %d)\n", |
| 1690 | cpu, msr, tcc_activation_temp - dts, resolution); |
| 1691 | |
| 1692 | #ifdef THERM_DEBUG |
| 1693 | if (get_msr(cpu, MSR_IA32_THERM_INTERRUPT, &msr)) |
| 1694 | return 0; |
| 1695 | |
| 1696 | dts = (msr >> 16) & 0x7F; |
| 1697 | dts2 = (msr >> 8) & 0x7F; |
| 1698 | fprintf(stderr, "cpu%d: MSR_IA32_THERM_INTERRUPT: 0x%08llx (%d C, %d C)\n", |
| 1699 | cpu, msr, tcc_activation_temp - dts, tcc_activation_temp - dts2); |
| 1700 | #endif |
| 1701 | } |
| 1702 | |
| 1703 | return 0; |
| 1704 | } |
| 1705 | |
| 1706 | void print_power_limit_msr(int cpu, unsigned long long msr, char *label) |
| 1707 | { |
| 1708 | fprintf(stderr, "cpu%d: %s: %sabled (%f Watts, %f sec, clamp %sabled)\n", |
| 1709 | cpu, label, |
| 1710 | ((msr >> 15) & 1) ? "EN" : "DIS", |
| 1711 | ((msr >> 0) & 0x7FFF) * rapl_power_units, |
| 1712 | (1.0 + (((msr >> 22) & 0x3)/4.0)) * (1 << ((msr >> 17) & 0x1F)) * rapl_time_units, |
| 1713 | (((msr >> 16) & 1) ? "EN" : "DIS")); |
| 1714 | |
| 1715 | return; |
| 1716 | } |
| 1717 | |
| 1718 | int print_rapl(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 1719 | { |
| 1720 | unsigned long long msr; |
| 1721 | int cpu; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1722 | |
| 1723 | if (!do_rapl) |
| 1724 | return 0; |
| 1725 | |
| 1726 | /* RAPL counters are per package, so print only for 1st thread/package */ |
| 1727 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 1728 | return 0; |
| 1729 | |
| 1730 | cpu = t->cpu_id; |
| 1731 | if (cpu_migrate(cpu)) { |
| 1732 | fprintf(stderr, "Could not migrate to CPU %d\n", cpu); |
| 1733 | return -1; |
| 1734 | } |
| 1735 | |
| 1736 | if (get_msr(cpu, MSR_RAPL_POWER_UNIT, &msr)) |
| 1737 | return -1; |
| 1738 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1739 | if (verbose) { |
| 1740 | fprintf(stderr, "cpu%d: MSR_RAPL_POWER_UNIT: 0x%08llx " |
| 1741 | "(%f Watts, %f Joules, %f sec.)\n", cpu, msr, |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1742 | rapl_power_units, rapl_energy_units, rapl_time_units); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1743 | } |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1744 | if (do_rapl & RAPL_PKG_POWER_INFO) { |
| 1745 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1746 | if (get_msr(cpu, MSR_PKG_POWER_INFO, &msr)) |
| 1747 | return -5; |
| 1748 | |
| 1749 | |
| 1750 | fprintf(stderr, "cpu%d: MSR_PKG_POWER_INFO: 0x%08llx (%.0f W TDP, RAPL %.0f - %.0f W, %f sec.)\n", |
| 1751 | cpu, msr, |
| 1752 | ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 1753 | ((msr >> 16) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 1754 | ((msr >> 32) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 1755 | ((msr >> 48) & RAPL_TIME_GRANULARITY) * rapl_time_units); |
| 1756 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1757 | } |
| 1758 | if (do_rapl & RAPL_PKG) { |
| 1759 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1760 | if (get_msr(cpu, MSR_PKG_POWER_LIMIT, &msr)) |
| 1761 | return -9; |
| 1762 | |
| 1763 | fprintf(stderr, "cpu%d: MSR_PKG_POWER_LIMIT: 0x%08llx (%slocked)\n", |
| 1764 | cpu, msr, (msr >> 63) & 1 ? "": "UN"); |
| 1765 | |
| 1766 | print_power_limit_msr(cpu, msr, "PKG Limit #1"); |
| 1767 | fprintf(stderr, "cpu%d: PKG Limit #2: %sabled (%f Watts, %f* sec, clamp %sabled)\n", |
| 1768 | cpu, |
| 1769 | ((msr >> 47) & 1) ? "EN" : "DIS", |
| 1770 | ((msr >> 32) & 0x7FFF) * rapl_power_units, |
| 1771 | (1.0 + (((msr >> 54) & 0x3)/4.0)) * (1 << ((msr >> 49) & 0x1F)) * rapl_time_units, |
| 1772 | ((msr >> 48) & 1) ? "EN" : "DIS"); |
| 1773 | } |
| 1774 | |
| 1775 | if (do_rapl & RAPL_DRAM) { |
| 1776 | if (get_msr(cpu, MSR_DRAM_POWER_INFO, &msr)) |
| 1777 | return -6; |
| 1778 | |
| 1779 | |
| 1780 | fprintf(stderr, "cpu%d: MSR_DRAM_POWER_INFO,: 0x%08llx (%.0f W TDP, RAPL %.0f - %.0f W, %f sec.)\n", |
| 1781 | cpu, msr, |
| 1782 | ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 1783 | ((msr >> 16) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 1784 | ((msr >> 32) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 1785 | ((msr >> 48) & RAPL_TIME_GRANULARITY) * rapl_time_units); |
| 1786 | |
| 1787 | |
| 1788 | if (get_msr(cpu, MSR_DRAM_POWER_LIMIT, &msr)) |
| 1789 | return -9; |
| 1790 | fprintf(stderr, "cpu%d: MSR_DRAM_POWER_LIMIT: 0x%08llx (%slocked)\n", |
| 1791 | cpu, msr, (msr >> 31) & 1 ? "": "UN"); |
| 1792 | |
| 1793 | print_power_limit_msr(cpu, msr, "DRAM Limit"); |
| 1794 | } |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1795 | if (do_rapl & RAPL_CORE_POLICY) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1796 | if (verbose) { |
| 1797 | if (get_msr(cpu, MSR_PP0_POLICY, &msr)) |
| 1798 | return -7; |
| 1799 | |
| 1800 | fprintf(stderr, "cpu%d: MSR_PP0_POLICY: %lld\n", cpu, msr & 0xF); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1801 | } |
| 1802 | } |
| 1803 | if (do_rapl & RAPL_CORES) { |
| 1804 | if (verbose) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1805 | |
| 1806 | if (get_msr(cpu, MSR_PP0_POWER_LIMIT, &msr)) |
| 1807 | return -9; |
| 1808 | fprintf(stderr, "cpu%d: MSR_PP0_POWER_LIMIT: 0x%08llx (%slocked)\n", |
| 1809 | cpu, msr, (msr >> 31) & 1 ? "": "UN"); |
| 1810 | print_power_limit_msr(cpu, msr, "Cores Limit"); |
| 1811 | } |
| 1812 | } |
| 1813 | if (do_rapl & RAPL_GFX) { |
| 1814 | if (verbose) { |
| 1815 | if (get_msr(cpu, MSR_PP1_POLICY, &msr)) |
| 1816 | return -8; |
| 1817 | |
| 1818 | fprintf(stderr, "cpu%d: MSR_PP1_POLICY: %lld\n", cpu, msr & 0xF); |
| 1819 | |
| 1820 | if (get_msr(cpu, MSR_PP1_POWER_LIMIT, &msr)) |
| 1821 | return -9; |
| 1822 | fprintf(stderr, "cpu%d: MSR_PP1_POWER_LIMIT: 0x%08llx (%slocked)\n", |
| 1823 | cpu, msr, (msr >> 31) & 1 ? "": "UN"); |
| 1824 | print_power_limit_msr(cpu, msr, "GFX Limit"); |
| 1825 | } |
| 1826 | } |
| 1827 | return 0; |
| 1828 | } |
| 1829 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1830 | |
| 1831 | int is_snb(unsigned int family, unsigned int model) |
| 1832 | { |
| 1833 | if (!genuine_intel) |
| 1834 | return 0; |
| 1835 | |
| 1836 | switch (model) { |
| 1837 | case 0x2A: |
| 1838 | case 0x2D: |
Len Brown | 650a37f | 2012-06-03 23:34:44 -0400 | [diff] [blame] | 1839 | case 0x3A: /* IVB */ |
Len Brown | 1300651 | 2012-09-26 18:11:31 -0400 | [diff] [blame] | 1840 | case 0x3E: /* IVB Xeon */ |
Len Brown | 70b4340 | 2013-01-08 01:26:07 -0500 | [diff] [blame] | 1841 | case 0x3C: /* HSW */ |
| 1842 | case 0x3F: /* HSW */ |
| 1843 | case 0x45: /* HSW */ |
Len Brown | 149c231 | 2013-03-15 10:58:02 -0400 | [diff] [blame] | 1844 | case 0x46: /* HSW */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1845 | return 1; |
| 1846 | } |
| 1847 | return 0; |
| 1848 | } |
| 1849 | |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1850 | int has_c8_c9_c10(unsigned int family, unsigned int model) |
| 1851 | { |
| 1852 | if (!genuine_intel) |
| 1853 | return 0; |
| 1854 | |
| 1855 | switch (model) { |
| 1856 | case 0x45: |
| 1857 | return 1; |
| 1858 | } |
| 1859 | return 0; |
| 1860 | } |
| 1861 | |
| 1862 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1863 | int is_slm(unsigned int family, unsigned int model) |
| 1864 | { |
| 1865 | if (!genuine_intel) |
| 1866 | return 0; |
| 1867 | switch (model) { |
| 1868 | case 0x37: /* BYT */ |
| 1869 | case 0x4D: /* AVN */ |
| 1870 | return 1; |
| 1871 | } |
| 1872 | return 0; |
| 1873 | } |
| 1874 | |
| 1875 | #define SLM_BCLK_FREQS 5 |
| 1876 | double slm_freq_table[SLM_BCLK_FREQS] = { 83.3, 100.0, 133.3, 116.7, 80.0}; |
| 1877 | |
| 1878 | double slm_bclk(void) |
| 1879 | { |
| 1880 | unsigned long long msr = 3; |
| 1881 | unsigned int i; |
| 1882 | double freq; |
| 1883 | |
| 1884 | if (get_msr(0, MSR_FSB_FREQ, &msr)) |
| 1885 | fprintf(stderr, "SLM BCLK: unknown\n"); |
| 1886 | |
| 1887 | i = msr & 0xf; |
| 1888 | if (i >= SLM_BCLK_FREQS) { |
| 1889 | fprintf(stderr, "SLM BCLK[%d] invalid\n", i); |
| 1890 | msr = 3; |
| 1891 | } |
| 1892 | freq = slm_freq_table[i]; |
| 1893 | |
| 1894 | fprintf(stderr, "SLM BCLK: %.1f Mhz\n", freq); |
| 1895 | |
| 1896 | return freq; |
| 1897 | } |
| 1898 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1899 | double discover_bclk(unsigned int family, unsigned int model) |
| 1900 | { |
| 1901 | if (is_snb(family, model)) |
| 1902 | return 100.00; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1903 | else if (is_slm(family, model)) |
| 1904 | return slm_bclk(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1905 | else |
| 1906 | return 133.33; |
| 1907 | } |
| 1908 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1909 | /* |
| 1910 | * MSR_IA32_TEMPERATURE_TARGET indicates the temperature where |
| 1911 | * the Thermal Control Circuit (TCC) activates. |
| 1912 | * This is usually equal to tjMax. |
| 1913 | * |
| 1914 | * Older processors do not have this MSR, so there we guess, |
| 1915 | * but also allow cmdline over-ride with -T. |
| 1916 | * |
| 1917 | * Several MSR temperature values are in units of degrees-C |
| 1918 | * below this value, including the Digital Thermal Sensor (DTS), |
| 1919 | * Package Thermal Management Sensor (PTM), and thermal event thresholds. |
| 1920 | */ |
| 1921 | int set_temperature_target(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 1922 | { |
| 1923 | unsigned long long msr; |
| 1924 | unsigned int target_c_local; |
| 1925 | int cpu; |
| 1926 | |
| 1927 | /* tcc_activation_temp is used only for dts or ptm */ |
| 1928 | if (!(do_dts || do_ptm)) |
| 1929 | return 0; |
| 1930 | |
| 1931 | /* this is a per-package concept */ |
| 1932 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 1933 | return 0; |
| 1934 | |
| 1935 | cpu = t->cpu_id; |
| 1936 | if (cpu_migrate(cpu)) { |
| 1937 | fprintf(stderr, "Could not migrate to CPU %d\n", cpu); |
| 1938 | return -1; |
| 1939 | } |
| 1940 | |
| 1941 | if (tcc_activation_temp_override != 0) { |
| 1942 | tcc_activation_temp = tcc_activation_temp_override; |
| 1943 | fprintf(stderr, "cpu%d: Using cmdline TCC Target (%d C)\n", |
| 1944 | cpu, tcc_activation_temp); |
| 1945 | return 0; |
| 1946 | } |
| 1947 | |
| 1948 | /* Temperature Target MSR is Nehalem and newer only */ |
| 1949 | if (!do_nehalem_platform_info) |
| 1950 | goto guess; |
| 1951 | |
| 1952 | if (get_msr(0, MSR_IA32_TEMPERATURE_TARGET, &msr)) |
| 1953 | goto guess; |
| 1954 | |
| 1955 | target_c_local = (msr >> 16) & 0x7F; |
| 1956 | |
| 1957 | if (verbose) |
| 1958 | fprintf(stderr, "cpu%d: MSR_IA32_TEMPERATURE_TARGET: 0x%08llx (%d C)\n", |
| 1959 | cpu, msr, target_c_local); |
| 1960 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1961 | if (target_c_local < 85 || target_c_local > 127) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1962 | goto guess; |
| 1963 | |
| 1964 | tcc_activation_temp = target_c_local; |
| 1965 | |
| 1966 | return 0; |
| 1967 | |
| 1968 | guess: |
| 1969 | tcc_activation_temp = TJMAX_DEFAULT; |
| 1970 | fprintf(stderr, "cpu%d: Guessing tjMax %d C, Please use -T to specify\n", |
| 1971 | cpu, tcc_activation_temp); |
| 1972 | |
| 1973 | return 0; |
| 1974 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1975 | void check_cpuid() |
| 1976 | { |
| 1977 | unsigned int eax, ebx, ecx, edx, max_level; |
| 1978 | unsigned int fms, family, model, stepping; |
| 1979 | |
| 1980 | eax = ebx = ecx = edx = 0; |
| 1981 | |
Josh Triplett | 2b92865 | 2013-08-20 17:20:14 -0700 | [diff] [blame^] | 1982 | __get_cpuid(0, &max_level, &ebx, &ecx, &edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1983 | |
| 1984 | if (ebx == 0x756e6547 && edx == 0x49656e69 && ecx == 0x6c65746e) |
| 1985 | genuine_intel = 1; |
| 1986 | |
| 1987 | if (verbose) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1988 | fprintf(stderr, "CPUID(0): %.4s%.4s%.4s ", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1989 | (char *)&ebx, (char *)&edx, (char *)&ecx); |
| 1990 | |
Josh Triplett | 2b92865 | 2013-08-20 17:20:14 -0700 | [diff] [blame^] | 1991 | __get_cpuid(1, &fms, &ebx, &ecx, &edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1992 | family = (fms >> 8) & 0xf; |
| 1993 | model = (fms >> 4) & 0xf; |
| 1994 | stepping = fms & 0xf; |
| 1995 | if (family == 6 || family == 0xf) |
| 1996 | model += ((fms >> 16) & 0xf) << 4; |
| 1997 | |
| 1998 | if (verbose) |
| 1999 | fprintf(stderr, "%d CPUID levels; family:model:stepping 0x%x:%x:%x (%d:%d:%d)\n", |
| 2000 | max_level, family, model, stepping, family, model, stepping); |
| 2001 | |
| 2002 | if (!(edx & (1 << 5))) { |
| 2003 | fprintf(stderr, "CPUID: no MSR\n"); |
| 2004 | exit(1); |
| 2005 | } |
| 2006 | |
| 2007 | /* |
| 2008 | * check max extended function levels of CPUID. |
| 2009 | * This is needed to check for invariant TSC. |
| 2010 | * This check is valid for both Intel and AMD. |
| 2011 | */ |
| 2012 | ebx = ecx = edx = 0; |
Josh Triplett | 2b92865 | 2013-08-20 17:20:14 -0700 | [diff] [blame^] | 2013 | __get_cpuid(0x80000000, &max_level, &ebx, &ecx, &edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2014 | |
| 2015 | if (max_level < 0x80000007) { |
| 2016 | fprintf(stderr, "CPUID: no invariant TSC (max_level 0x%x)\n", max_level); |
| 2017 | exit(1); |
| 2018 | } |
| 2019 | |
| 2020 | /* |
| 2021 | * Non-Stop TSC is advertised by CPUID.EAX=0x80000007: EDX.bit8 |
| 2022 | * this check is valid for both Intel and AMD |
| 2023 | */ |
Josh Triplett | 2b92865 | 2013-08-20 17:20:14 -0700 | [diff] [blame^] | 2024 | __get_cpuid(0x80000007, &eax, &ebx, &ecx, &edx); |
Thomas Renninger | 8209e05 | 2011-01-21 15:11:19 +0100 | [diff] [blame] | 2025 | has_invariant_tsc = edx & (1 << 8); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2026 | |
| 2027 | if (!has_invariant_tsc) { |
| 2028 | fprintf(stderr, "No invariant TSC\n"); |
| 2029 | exit(1); |
| 2030 | } |
| 2031 | |
| 2032 | /* |
| 2033 | * APERF/MPERF is advertised by CPUID.EAX=0x6: ECX.bit0 |
| 2034 | * this check is valid for both Intel and AMD |
| 2035 | */ |
| 2036 | |
Josh Triplett | 2b92865 | 2013-08-20 17:20:14 -0700 | [diff] [blame^] | 2037 | __get_cpuid(0x6, &eax, &ebx, &ecx, &edx); |
Thomas Renninger | 8209e05 | 2011-01-21 15:11:19 +0100 | [diff] [blame] | 2038 | has_aperf = ecx & (1 << 0); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2039 | do_dts = eax & (1 << 0); |
| 2040 | do_ptm = eax & (1 << 6); |
| 2041 | has_epb = ecx & (1 << 3); |
| 2042 | |
| 2043 | if (verbose) |
| 2044 | fprintf(stderr, "CPUID(6): %s%s%s%s\n", |
| 2045 | has_aperf ? "APERF" : "No APERF!", |
| 2046 | do_dts ? ", DTS" : "", |
| 2047 | do_ptm ? ", PTM": "", |
| 2048 | has_epb ? ", EPB": ""); |
| 2049 | |
| 2050 | if (!has_aperf) |
| 2051 | exit(-1); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2052 | |
| 2053 | do_nehalem_platform_info = genuine_intel && has_invariant_tsc; |
| 2054 | do_nhm_cstates = genuine_intel; /* all Intel w/ non-stop TSC have NHM counters */ |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 2055 | do_smi = do_nhm_cstates; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2056 | do_snb_cstates = is_snb(family, model); |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 2057 | do_c8_c9_c10 = has_c8_c9_c10(family, model); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2058 | do_slm_cstates = is_slm(family, model); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2059 | bclk = discover_bclk(family, model); |
| 2060 | |
| 2061 | do_nehalem_turbo_ratio_limit = has_nehalem_turbo_ratio_limit(family, model); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2062 | do_ivt_turbo_ratio_limit = has_ivt_turbo_ratio_limit(family, model); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2063 | rapl_probe(family, model); |
| 2064 | |
| 2065 | return; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | |
| 2069 | void usage() |
| 2070 | { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2071 | fprintf(stderr, "%s: [-v][-R][-T][-p|-P|-S][-c MSR# | -s]][-C MSR#][-m MSR#][-M MSR#][-i interval_sec | command ...]\n", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2072 | progname); |
| 2073 | exit(1); |
| 2074 | } |
| 2075 | |
| 2076 | |
| 2077 | /* |
| 2078 | * in /dev/cpu/ return success for names that are numbers |
| 2079 | * ie. filter out ".", "..", "microcode". |
| 2080 | */ |
| 2081 | int dir_filter(const struct dirent *dirp) |
| 2082 | { |
| 2083 | if (isdigit(dirp->d_name[0])) |
| 2084 | return 1; |
| 2085 | else |
| 2086 | return 0; |
| 2087 | } |
| 2088 | |
| 2089 | int open_dev_cpu_msr(int dummy1) |
| 2090 | { |
| 2091 | return 0; |
| 2092 | } |
| 2093 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2094 | void topology_probe() |
| 2095 | { |
| 2096 | int i; |
| 2097 | int max_core_id = 0; |
| 2098 | int max_package_id = 0; |
| 2099 | int max_siblings = 0; |
| 2100 | struct cpu_topology { |
| 2101 | int core_id; |
| 2102 | int physical_package_id; |
| 2103 | } *cpus; |
| 2104 | |
| 2105 | /* Initialize num_cpus, max_cpu_num */ |
| 2106 | topo.num_cpus = 0; |
| 2107 | topo.max_cpu_num = 0; |
| 2108 | for_all_proc_cpus(count_cpus); |
| 2109 | if (!summary_only && topo.num_cpus > 1) |
| 2110 | show_cpu = 1; |
| 2111 | |
| 2112 | if (verbose > 1) |
| 2113 | fprintf(stderr, "num_cpus %d max_cpu_num %d\n", topo.num_cpus, topo.max_cpu_num); |
| 2114 | |
| 2115 | cpus = calloc(1, (topo.max_cpu_num + 1) * sizeof(struct cpu_topology)); |
| 2116 | if (cpus == NULL) { |
| 2117 | perror("calloc cpus"); |
| 2118 | exit(1); |
| 2119 | } |
| 2120 | |
| 2121 | /* |
| 2122 | * Allocate and initialize cpu_present_set |
| 2123 | */ |
| 2124 | cpu_present_set = CPU_ALLOC((topo.max_cpu_num + 1)); |
| 2125 | if (cpu_present_set == NULL) { |
| 2126 | perror("CPU_ALLOC"); |
| 2127 | exit(3); |
| 2128 | } |
| 2129 | cpu_present_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); |
| 2130 | CPU_ZERO_S(cpu_present_setsize, cpu_present_set); |
| 2131 | for_all_proc_cpus(mark_cpu_present); |
| 2132 | |
| 2133 | /* |
| 2134 | * Allocate and initialize cpu_affinity_set |
| 2135 | */ |
| 2136 | cpu_affinity_set = CPU_ALLOC((topo.max_cpu_num + 1)); |
| 2137 | if (cpu_affinity_set == NULL) { |
| 2138 | perror("CPU_ALLOC"); |
| 2139 | exit(3); |
| 2140 | } |
| 2141 | cpu_affinity_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); |
| 2142 | CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); |
| 2143 | |
| 2144 | |
| 2145 | /* |
| 2146 | * For online cpus |
| 2147 | * find max_core_id, max_package_id |
| 2148 | */ |
| 2149 | for (i = 0; i <= topo.max_cpu_num; ++i) { |
| 2150 | int siblings; |
| 2151 | |
| 2152 | if (cpu_is_not_present(i)) { |
| 2153 | if (verbose > 1) |
| 2154 | fprintf(stderr, "cpu%d NOT PRESENT\n", i); |
| 2155 | continue; |
| 2156 | } |
| 2157 | cpus[i].core_id = get_core_id(i); |
| 2158 | if (cpus[i].core_id > max_core_id) |
| 2159 | max_core_id = cpus[i].core_id; |
| 2160 | |
| 2161 | cpus[i].physical_package_id = get_physical_package_id(i); |
| 2162 | if (cpus[i].physical_package_id > max_package_id) |
| 2163 | max_package_id = cpus[i].physical_package_id; |
| 2164 | |
| 2165 | siblings = get_num_ht_siblings(i); |
| 2166 | if (siblings > max_siblings) |
| 2167 | max_siblings = siblings; |
| 2168 | if (verbose > 1) |
| 2169 | fprintf(stderr, "cpu %d pkg %d core %d\n", |
| 2170 | i, cpus[i].physical_package_id, cpus[i].core_id); |
| 2171 | } |
| 2172 | topo.num_cores_per_pkg = max_core_id + 1; |
| 2173 | if (verbose > 1) |
| 2174 | fprintf(stderr, "max_core_id %d, sizing for %d cores per package\n", |
| 2175 | max_core_id, topo.num_cores_per_pkg); |
| 2176 | if (!summary_only && topo.num_cores_per_pkg > 1) |
| 2177 | show_core = 1; |
| 2178 | |
| 2179 | topo.num_packages = max_package_id + 1; |
| 2180 | if (verbose > 1) |
| 2181 | fprintf(stderr, "max_package_id %d, sizing for %d packages\n", |
| 2182 | max_package_id, topo.num_packages); |
| 2183 | if (!summary_only && topo.num_packages > 1) |
| 2184 | show_pkg = 1; |
| 2185 | |
| 2186 | topo.num_threads_per_core = max_siblings; |
| 2187 | if (verbose > 1) |
| 2188 | fprintf(stderr, "max_siblings %d\n", max_siblings); |
| 2189 | |
| 2190 | free(cpus); |
| 2191 | } |
| 2192 | |
| 2193 | void |
| 2194 | allocate_counters(struct thread_data **t, struct core_data **c, struct pkg_data **p) |
| 2195 | { |
| 2196 | int i; |
| 2197 | |
| 2198 | *t = calloc(topo.num_threads_per_core * topo.num_cores_per_pkg * |
| 2199 | topo.num_packages, sizeof(struct thread_data)); |
| 2200 | if (*t == NULL) |
| 2201 | goto error; |
| 2202 | |
| 2203 | for (i = 0; i < topo.num_threads_per_core * |
| 2204 | topo.num_cores_per_pkg * topo.num_packages; i++) |
| 2205 | (*t)[i].cpu_id = -1; |
| 2206 | |
| 2207 | *c = calloc(topo.num_cores_per_pkg * topo.num_packages, |
| 2208 | sizeof(struct core_data)); |
| 2209 | if (*c == NULL) |
| 2210 | goto error; |
| 2211 | |
| 2212 | for (i = 0; i < topo.num_cores_per_pkg * topo.num_packages; i++) |
| 2213 | (*c)[i].core_id = -1; |
| 2214 | |
| 2215 | *p = calloc(topo.num_packages, sizeof(struct pkg_data)); |
| 2216 | if (*p == NULL) |
| 2217 | goto error; |
| 2218 | |
| 2219 | for (i = 0; i < topo.num_packages; i++) |
| 2220 | (*p)[i].package_id = i; |
| 2221 | |
| 2222 | return; |
| 2223 | error: |
| 2224 | perror("calloc counters"); |
| 2225 | exit(1); |
| 2226 | } |
| 2227 | /* |
| 2228 | * init_counter() |
| 2229 | * |
| 2230 | * set cpu_id, core_num, pkg_num |
| 2231 | * set FIRST_THREAD_IN_CORE and FIRST_CORE_IN_PACKAGE |
| 2232 | * |
| 2233 | * increment topo.num_cores when 1st core in pkg seen |
| 2234 | */ |
| 2235 | void init_counter(struct thread_data *thread_base, struct core_data *core_base, |
| 2236 | struct pkg_data *pkg_base, int thread_num, int core_num, |
| 2237 | int pkg_num, int cpu_id) |
| 2238 | { |
| 2239 | struct thread_data *t; |
| 2240 | struct core_data *c; |
| 2241 | struct pkg_data *p; |
| 2242 | |
| 2243 | t = GET_THREAD(thread_base, thread_num, core_num, pkg_num); |
| 2244 | c = GET_CORE(core_base, core_num, pkg_num); |
| 2245 | p = GET_PKG(pkg_base, pkg_num); |
| 2246 | |
| 2247 | t->cpu_id = cpu_id; |
| 2248 | if (thread_num == 0) { |
| 2249 | t->flags |= CPU_IS_FIRST_THREAD_IN_CORE; |
| 2250 | if (cpu_is_first_core_in_package(cpu_id)) |
| 2251 | t->flags |= CPU_IS_FIRST_CORE_IN_PACKAGE; |
| 2252 | } |
| 2253 | |
| 2254 | c->core_id = core_num; |
| 2255 | p->package_id = pkg_num; |
| 2256 | } |
| 2257 | |
| 2258 | |
| 2259 | int initialize_counters(int cpu_id) |
| 2260 | { |
| 2261 | int my_thread_id, my_core_id, my_package_id; |
| 2262 | |
| 2263 | my_package_id = get_physical_package_id(cpu_id); |
| 2264 | my_core_id = get_core_id(cpu_id); |
| 2265 | |
| 2266 | if (cpu_is_first_sibling_in_core(cpu_id)) { |
| 2267 | my_thread_id = 0; |
| 2268 | topo.num_cores++; |
| 2269 | } else { |
| 2270 | my_thread_id = 1; |
| 2271 | } |
| 2272 | |
| 2273 | init_counter(EVEN_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id); |
| 2274 | init_counter(ODD_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id); |
| 2275 | return 0; |
| 2276 | } |
| 2277 | |
| 2278 | void allocate_output_buffer() |
| 2279 | { |
Josh Triplett | b844db3 | 2013-06-12 17:26:37 -0700 | [diff] [blame] | 2280 | output_buffer = calloc(1, (1 + topo.num_cpus) * 256); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2281 | outp = output_buffer; |
| 2282 | if (outp == NULL) { |
| 2283 | perror("calloc"); |
| 2284 | exit(-1); |
| 2285 | } |
| 2286 | } |
| 2287 | |
| 2288 | void setup_all_buffers(void) |
| 2289 | { |
| 2290 | topology_probe(); |
| 2291 | allocate_counters(&thread_even, &core_even, &package_even); |
| 2292 | allocate_counters(&thread_odd, &core_odd, &package_odd); |
| 2293 | allocate_output_buffer(); |
| 2294 | for_all_proc_cpus(initialize_counters); |
| 2295 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2296 | void turbostat_init() |
| 2297 | { |
| 2298 | check_cpuid(); |
| 2299 | |
| 2300 | check_dev_msr(); |
| 2301 | check_super_user(); |
| 2302 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2303 | setup_all_buffers(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2304 | |
| 2305 | if (verbose) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2306 | print_verbose_header(); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2307 | |
| 2308 | if (verbose) |
| 2309 | for_all_cpus(print_epb, ODD_COUNTERS); |
| 2310 | |
| 2311 | if (verbose) |
| 2312 | for_all_cpus(print_rapl, ODD_COUNTERS); |
| 2313 | |
| 2314 | for_all_cpus(set_temperature_target, ODD_COUNTERS); |
| 2315 | |
| 2316 | if (verbose) |
| 2317 | for_all_cpus(print_thermal, ODD_COUNTERS); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2318 | } |
| 2319 | |
| 2320 | int fork_it(char **argv) |
| 2321 | { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2322 | pid_t child_pid; |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 2323 | int status; |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 2324 | |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 2325 | status = for_all_cpus(get_counters, EVEN_COUNTERS); |
| 2326 | if (status) |
| 2327 | exit(status); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2328 | /* clear affinity side-effect of get_counters() */ |
| 2329 | sched_setaffinity(0, cpu_present_setsize, cpu_present_set); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2330 | gettimeofday(&tv_even, (struct timezone *)NULL); |
| 2331 | |
| 2332 | child_pid = fork(); |
| 2333 | if (!child_pid) { |
| 2334 | /* child */ |
| 2335 | execvp(argv[0], argv); |
| 2336 | } else { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2337 | |
| 2338 | /* parent */ |
| 2339 | if (child_pid == -1) { |
| 2340 | perror("fork"); |
| 2341 | exit(1); |
| 2342 | } |
| 2343 | |
| 2344 | signal(SIGINT, SIG_IGN); |
| 2345 | signal(SIGQUIT, SIG_IGN); |
| 2346 | if (waitpid(child_pid, &status, 0) == -1) { |
| 2347 | perror("wait"); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 2348 | exit(status); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2349 | } |
| 2350 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2351 | /* |
| 2352 | * n.b. fork_it() does not check for errors from for_all_cpus() |
| 2353 | * because re-starting is problematic when forking |
| 2354 | */ |
| 2355 | for_all_cpus(get_counters, ODD_COUNTERS); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2356 | gettimeofday(&tv_odd, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2357 | timersub(&tv_odd, &tv_even, &tv_delta); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2358 | for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS); |
| 2359 | compute_average(EVEN_COUNTERS); |
| 2360 | format_all_counters(EVEN_COUNTERS); |
| 2361 | flush_stderr(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2362 | |
Justin P. Mattock | 6eab04a | 2011-04-08 19:49:08 -0700 | [diff] [blame] | 2363 | 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] | 2364 | |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 2365 | return status; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2366 | } |
| 2367 | |
| 2368 | void cmdline(int argc, char **argv) |
| 2369 | { |
| 2370 | int opt; |
| 2371 | |
| 2372 | progname = argv[0]; |
| 2373 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2374 | while ((opt = getopt(argc, argv, "+pPSvi:sc:sC:m:M:RT:")) != -1) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2375 | switch (opt) { |
Len Brown | f924081 | 2012-10-06 15:26:31 -0400 | [diff] [blame] | 2376 | case 'p': |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2377 | show_core_only++; |
| 2378 | break; |
Len Brown | f924081 | 2012-10-06 15:26:31 -0400 | [diff] [blame] | 2379 | case 'P': |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2380 | show_pkg_only++; |
| 2381 | break; |
Len Brown | f924081 | 2012-10-06 15:26:31 -0400 | [diff] [blame] | 2382 | case 'S': |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 2383 | summary_only++; |
| 2384 | break; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2385 | case 'v': |
| 2386 | verbose++; |
| 2387 | break; |
| 2388 | case 'i': |
| 2389 | interval_sec = atoi(optarg); |
| 2390 | break; |
Len Brown | f924081 | 2012-10-06 15:26:31 -0400 | [diff] [blame] | 2391 | case 'c': |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 2392 | sscanf(optarg, "%x", &extra_delta_offset32); |
| 2393 | break; |
Len Brown | f924081 | 2012-10-06 15:26:31 -0400 | [diff] [blame] | 2394 | case 'C': |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 2395 | sscanf(optarg, "%x", &extra_delta_offset64); |
| 2396 | break; |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 2397 | case 'm': |
| 2398 | sscanf(optarg, "%x", &extra_msr_offset32); |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 2399 | break; |
| 2400 | case 'M': |
| 2401 | sscanf(optarg, "%x", &extra_msr_offset64); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2402 | break; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2403 | case 'R': |
| 2404 | rapl_verbose++; |
| 2405 | break; |
| 2406 | case 'T': |
| 2407 | tcc_activation_temp_override = atoi(optarg); |
| 2408 | break; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2409 | default: |
| 2410 | usage(); |
| 2411 | } |
| 2412 | } |
| 2413 | } |
| 2414 | |
| 2415 | int main(int argc, char **argv) |
| 2416 | { |
| 2417 | cmdline(argc, argv); |
| 2418 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 2419 | if (verbose) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 2420 | fprintf(stderr, "turbostat v3.5 April 26, 2013" |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2421 | " - Len Brown <lenb@kernel.org>\n"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2422 | |
| 2423 | turbostat_init(); |
| 2424 | |
| 2425 | /* |
| 2426 | * if any params left, it must be a command to fork |
| 2427 | */ |
| 2428 | if (argc - optind) |
| 2429 | return fork_it(argv + optind); |
| 2430 | else |
| 2431 | turbostat_loop(); |
| 2432 | |
| 2433 | return 0; |
| 2434 | } |