Thomas Gleixner | a61127c | 2019-05-29 16:57:49 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2 | /* |
| 3 | * turbostat -- show CPU frequency and C-state residency |
Len Brown | 3404155 | 2018-08-07 20:22:28 -0400 | [diff] [blame] | 4 | * on modern Intel and AMD processors. |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5 | * |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 6 | * Copyright (c) 2013 Intel Corporation. |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 7 | * Len Brown <len.brown@intel.com> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 8 | */ |
| 9 | |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 10 | #define _GNU_SOURCE |
Josh Triplett | b731f31 | 2013-08-20 17:20:12 -0700 | [diff] [blame] | 11 | #include MSRHEADER |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 12 | #include INTEL_FAMILY_HEADER |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 13 | #include <stdarg.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 14 | #include <stdio.h> |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 15 | #include <err.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 16 | #include <unistd.h> |
| 17 | #include <sys/types.h> |
| 18 | #include <sys/wait.h> |
| 19 | #include <sys/stat.h> |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 20 | #include <sys/select.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 21 | #include <sys/resource.h> |
| 22 | #include <fcntl.h> |
| 23 | #include <signal.h> |
| 24 | #include <sys/time.h> |
| 25 | #include <stdlib.h> |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 26 | #include <getopt.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 27 | #include <dirent.h> |
| 28 | #include <string.h> |
| 29 | #include <ctype.h> |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 30 | #include <sched.h> |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 31 | #include <time.h> |
Josh Triplett | 2b92865 | 2013-08-20 17:20:14 -0700 | [diff] [blame] | 32 | #include <cpuid.h> |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 33 | #include <linux/capability.h> |
| 34 | #include <errno.h> |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 35 | #include <math.h> |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 36 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 37 | char *proc_stat = "/proc/stat"; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 38 | FILE *outf; |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 39 | int *fd_percpu; |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 40 | struct timeval interval_tv = {5, 0}; |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 41 | struct timespec interval_ts = {5, 0}; |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 42 | struct timespec one_msec = {0, 1000000}; |
Chen Yu | 023fe0a | 2018-04-26 08:41:03 +0800 | [diff] [blame] | 43 | unsigned int num_iterations; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 44 | unsigned int debug; |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 45 | unsigned int quiet; |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 46 | unsigned int shown; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 47 | unsigned int sums_need_wide_columns; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 48 | unsigned int rapl_joules; |
| 49 | unsigned int summary_only; |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 50 | unsigned int list_header_only; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 51 | unsigned int dump_only; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 52 | unsigned int do_snb_cstates; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 53 | unsigned int do_knl_cstates; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 54 | unsigned int do_slm_cstates; |
| 55 | unsigned int use_c1_residency_msr; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 56 | unsigned int has_aperf; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 57 | unsigned int has_epb; |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 58 | unsigned int do_irtl_snb; |
| 59 | unsigned int do_irtl_hsw; |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 60 | unsigned int units = 1000000; /* MHz etc */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 61 | unsigned int genuine_intel; |
Len Brown | 3404155 | 2018-08-07 20:22:28 -0400 | [diff] [blame] | 62 | unsigned int authentic_amd; |
| 63 | unsigned int max_level, max_extended_level; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 64 | unsigned int has_invariant_tsc; |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 65 | unsigned int do_nhm_platform_info; |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 66 | unsigned int no_MSR_MISC_PWR_MGMT; |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 67 | unsigned int aperf_mperf_multiplier = 1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 68 | double bclk; |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 69 | double base_hz; |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 70 | unsigned int has_base_hz; |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 71 | double tsc_tweak = 1.0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 72 | unsigned int show_pkg_only; |
| 73 | unsigned int show_core_only; |
| 74 | char *output_buffer, *outp; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 75 | unsigned int do_rapl; |
| 76 | unsigned int do_dts; |
| 77 | unsigned int do_ptm; |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 78 | unsigned long long gfx_cur_rc6_ms; |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 79 | unsigned long long cpuidle_cur_cpu_lpi_us; |
| 80 | unsigned long long cpuidle_cur_sys_lpi_us; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 81 | unsigned int gfx_cur_mhz; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 82 | unsigned int tcc_activation_temp; |
| 83 | unsigned int tcc_activation_temp_override; |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 84 | double rapl_power_units, rapl_time_units; |
| 85 | double rapl_dram_energy_units, rapl_energy_units; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 86 | double rapl_joule_counter_range; |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 87 | unsigned int do_core_perf_limit_reasons; |
Artem Bityutskiy | ac980e1 | 2017-09-05 15:14:08 +0300 | [diff] [blame] | 88 | unsigned int has_automatic_cstate_conversion; |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 89 | unsigned int do_gfx_perf_limit_reasons; |
| 90 | unsigned int do_ring_perf_limit_reasons; |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 91 | unsigned int crystal_hz; |
| 92 | unsigned long long tsc_hz; |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 93 | int base_cpu; |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 94 | double discover_bclk(unsigned int family, unsigned int model); |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 95 | unsigned int has_hwp; /* IA32_PM_ENABLE, IA32_HWP_CAPABILITIES */ |
| 96 | /* IA32_HWP_REQUEST, IA32_HWP_STATUS */ |
| 97 | unsigned int has_hwp_notify; /* IA32_HWP_INTERRUPT */ |
| 98 | unsigned int has_hwp_activity_window; /* IA32_HWP_REQUEST[bits 41:32] */ |
| 99 | unsigned int has_hwp_epp; /* IA32_HWP_REQUEST[bits 31:24] */ |
| 100 | unsigned int has_hwp_pkg; /* IA32_HWP_REQUEST_PKG */ |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 101 | unsigned int has_misc_feature_control; |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 102 | unsigned int first_counter_read = 1; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 103 | |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 104 | #define RAPL_PKG (1 << 0) |
| 105 | /* 0x610 MSR_PKG_POWER_LIMIT */ |
| 106 | /* 0x611 MSR_PKG_ENERGY_STATUS */ |
| 107 | #define RAPL_PKG_PERF_STATUS (1 << 1) |
| 108 | /* 0x613 MSR_PKG_PERF_STATUS */ |
| 109 | #define RAPL_PKG_POWER_INFO (1 << 2) |
| 110 | /* 0x614 MSR_PKG_POWER_INFO */ |
| 111 | |
| 112 | #define RAPL_DRAM (1 << 3) |
| 113 | /* 0x618 MSR_DRAM_POWER_LIMIT */ |
| 114 | /* 0x619 MSR_DRAM_ENERGY_STATUS */ |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 115 | #define RAPL_DRAM_PERF_STATUS (1 << 4) |
| 116 | /* 0x61b MSR_DRAM_PERF_STATUS */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 117 | #define RAPL_DRAM_POWER_INFO (1 << 5) |
| 118 | /* 0x61c MSR_DRAM_POWER_INFO */ |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 119 | |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 120 | #define RAPL_CORES_POWER_LIMIT (1 << 6) |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 121 | /* 0x638 MSR_PP0_POWER_LIMIT */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 122 | #define RAPL_CORE_POLICY (1 << 7) |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 123 | /* 0x63a MSR_PP0_POLICY */ |
| 124 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 125 | #define RAPL_GFX (1 << 8) |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 126 | /* 0x640 MSR_PP1_POWER_LIMIT */ |
| 127 | /* 0x641 MSR_PP1_ENERGY_STATUS */ |
| 128 | /* 0x642 MSR_PP1_POLICY */ |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 129 | |
| 130 | #define RAPL_CORES_ENERGY_STATUS (1 << 9) |
| 131 | /* 0x639 MSR_PP0_ENERGY_STATUS */ |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 132 | #define RAPL_PER_CORE_ENERGY (1 << 10) |
| 133 | /* Indicates cores energy collection is per-core, |
| 134 | * not per-package. */ |
| 135 | #define RAPL_AMD_F17H (1 << 11) |
| 136 | /* 0xc0010299 MSR_RAPL_PWR_UNIT */ |
| 137 | /* 0xc001029a MSR_CORE_ENERGY_STAT */ |
| 138 | /* 0xc001029b MSR_PKG_ENERGY_STAT */ |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 139 | #define RAPL_CORES (RAPL_CORES_ENERGY_STATUS | RAPL_CORES_POWER_LIMIT) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 140 | #define TJMAX_DEFAULT 100 |
| 141 | |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 142 | /* MSRs that are not yet in the kernel-provided header. */ |
| 143 | #define MSR_RAPL_PWR_UNIT 0xc0010299 |
| 144 | #define MSR_CORE_ENERGY_STAT 0xc001029a |
| 145 | #define MSR_PKG_ENERGY_STAT 0xc001029b |
| 146 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 147 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 148 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 149 | /* |
| 150 | * buffer size used by sscanf() for added column names |
| 151 | * Usually truncated to 7 characters, but also handles 18 columns for raw 64-bit counters |
| 152 | */ |
| 153 | #define NAME_BYTES 20 |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 154 | #define PATH_BYTES 128 |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 155 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 156 | int backwards_count; |
| 157 | char *progname; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 158 | |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 159 | #define CPU_SUBSET_MAXCPUS 1024 /* need to use before probe... */ |
| 160 | cpu_set_t *cpu_present_set, *cpu_affinity_set, *cpu_subset; |
| 161 | size_t cpu_present_setsize, cpu_affinity_setsize, cpu_subset_size; |
Len Brown | 0748eaf | 2018-06-01 12:38:29 -0400 | [diff] [blame] | 162 | #define MAX_ADDED_COUNTERS 8 |
| 163 | #define MAX_ADDED_THREAD_COUNTERS 24 |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 164 | #define BITMASK_SIZE 32 |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 165 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 166 | struct thread_data { |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 167 | struct timeval tv_begin; |
| 168 | struct timeval tv_end; |
Yazen Ghannam | d4794f2 | 2019-03-25 17:32:42 +0000 | [diff] [blame] | 169 | struct timeval tv_delta; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 170 | unsigned long long tsc; |
| 171 | unsigned long long aperf; |
| 172 | unsigned long long mperf; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 173 | unsigned long long c1; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 174 | unsigned long long irq_count; |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 175 | unsigned int smi_count; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 176 | unsigned int cpu_id; |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 177 | unsigned int apic_id; |
| 178 | unsigned int x2apic_id; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 179 | unsigned int flags; |
| 180 | #define CPU_IS_FIRST_THREAD_IN_CORE 0x2 |
| 181 | #define CPU_IS_FIRST_CORE_IN_PACKAGE 0x4 |
Len Brown | 0748eaf | 2018-06-01 12:38:29 -0400 | [diff] [blame] | 182 | unsigned long long counter[MAX_ADDED_THREAD_COUNTERS]; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 183 | } *thread_even, *thread_odd; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 184 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 185 | struct core_data { |
| 186 | unsigned long long c3; |
| 187 | unsigned long long c6; |
| 188 | unsigned long long c7; |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 189 | unsigned long long mc6_us; /* duplicate as per-core for now, even though per module */ |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 190 | unsigned int core_temp_c; |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 191 | unsigned int core_energy; /* MSR_CORE_ENERGY_STAT */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 192 | unsigned int core_id; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 193 | unsigned long long counter[MAX_ADDED_COUNTERS]; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 194 | } *core_even, *core_odd; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 195 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 196 | struct pkg_data { |
| 197 | unsigned long long pc2; |
| 198 | unsigned long long pc3; |
| 199 | unsigned long long pc6; |
| 200 | unsigned long long pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 201 | unsigned long long pc8; |
| 202 | unsigned long long pc9; |
| 203 | unsigned long long pc10; |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 204 | unsigned long long cpu_lpi; |
| 205 | unsigned long long sys_lpi; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 206 | unsigned long long pkg_wtd_core_c0; |
| 207 | unsigned long long pkg_any_core_c0; |
| 208 | unsigned long long pkg_any_gfxe_c0; |
| 209 | unsigned long long pkg_both_core_gfxe_c0; |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 210 | long long gfx_rc6_ms; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 211 | unsigned int gfx_mhz; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 212 | unsigned int package_id; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 213 | unsigned int energy_pkg; /* MSR_PKG_ENERGY_STATUS */ |
| 214 | unsigned int energy_dram; /* MSR_DRAM_ENERGY_STATUS */ |
| 215 | unsigned int energy_cores; /* MSR_PP0_ENERGY_STATUS */ |
| 216 | unsigned int energy_gfx; /* MSR_PP1_ENERGY_STATUS */ |
| 217 | unsigned int rapl_pkg_perf_status; /* MSR_PKG_PERF_STATUS */ |
| 218 | unsigned int rapl_dram_perf_status; /* MSR_DRAM_PERF_STATUS */ |
| 219 | unsigned int pkg_temp_c; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 220 | unsigned long long counter[MAX_ADDED_COUNTERS]; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 221 | } *package_even, *package_odd; |
| 222 | |
| 223 | #define ODD_COUNTERS thread_odd, core_odd, package_odd |
| 224 | #define EVEN_COUNTERS thread_even, core_even, package_even |
| 225 | |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 226 | #define GET_THREAD(thread_base, thread_no, core_no, node_no, pkg_no) \ |
| 227 | ((thread_base) + \ |
| 228 | ((pkg_no) * \ |
| 229 | topo.nodes_per_pkg * topo.cores_per_node * topo.threads_per_core) + \ |
| 230 | ((node_no) * topo.cores_per_node * topo.threads_per_core) + \ |
| 231 | ((core_no) * topo.threads_per_core) + \ |
| 232 | (thread_no)) |
| 233 | |
| 234 | #define GET_CORE(core_base, core_no, node_no, pkg_no) \ |
| 235 | ((core_base) + \ |
| 236 | ((pkg_no) * topo.nodes_per_pkg * topo.cores_per_node) + \ |
| 237 | ((node_no) * topo.cores_per_node) + \ |
| 238 | (core_no)) |
| 239 | |
| 240 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 241 | #define GET_PKG(pkg_base, pkg_no) (pkg_base + pkg_no) |
| 242 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 243 | enum counter_scope {SCOPE_CPU, SCOPE_CORE, SCOPE_PACKAGE}; |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 244 | enum counter_type {COUNTER_ITEMS, COUNTER_CYCLES, COUNTER_SECONDS, COUNTER_USEC}; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 245 | enum counter_format {FORMAT_RAW, FORMAT_DELTA, FORMAT_PERCENT}; |
| 246 | |
| 247 | struct msr_counter { |
| 248 | unsigned int msr_num; |
| 249 | char name[NAME_BYTES]; |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 250 | char path[PATH_BYTES]; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 251 | unsigned int width; |
| 252 | enum counter_type type; |
| 253 | enum counter_format format; |
| 254 | struct msr_counter *next; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 255 | unsigned int flags; |
| 256 | #define FLAGS_HIDE (1 << 0) |
| 257 | #define FLAGS_SHOW (1 << 1) |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 258 | #define SYSFS_PERCPU (1 << 1) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 259 | }; |
| 260 | |
| 261 | struct sys_counters { |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 262 | unsigned int added_thread_counters; |
| 263 | unsigned int added_core_counters; |
| 264 | unsigned int added_package_counters; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 265 | struct msr_counter *tp; |
| 266 | struct msr_counter *cp; |
| 267 | struct msr_counter *pp; |
| 268 | } sys; |
| 269 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 270 | struct system_summary { |
| 271 | struct thread_data threads; |
| 272 | struct core_data cores; |
| 273 | struct pkg_data packages; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 274 | } average; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 275 | |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 276 | struct cpu_topology { |
| 277 | int physical_package_id; |
Len Brown | 6de68fe | 2019-02-14 19:17:40 -0800 | [diff] [blame] | 278 | int die_id; |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 279 | int logical_cpu_id; |
Prarit Bhargava | ef60574 | 2018-06-01 10:04:30 -0400 | [diff] [blame] | 280 | int physical_node_id; |
| 281 | int logical_node_id; /* 0-based count within the package */ |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 282 | int physical_core_id; |
Prarit Bhargava | 8cb48b3 | 2018-06-01 10:04:31 -0400 | [diff] [blame] | 283 | int thread_id; |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 284 | cpu_set_t *put_ids; /* Processing Unit/Thread IDs */ |
| 285 | } *cpus; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 286 | |
| 287 | struct topo_params { |
| 288 | int num_packages; |
Len Brown | 6de68fe | 2019-02-14 19:17:40 -0800 | [diff] [blame] | 289 | int num_die; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 290 | int num_cpus; |
| 291 | int num_cores; |
| 292 | int max_cpu_num; |
Prarit Bhargava | ef60574 | 2018-06-01 10:04:30 -0400 | [diff] [blame] | 293 | int max_node_num; |
Prarit Bhargava | 70a9c6e | 2018-06-01 10:04:33 -0400 | [diff] [blame] | 294 | int nodes_per_pkg; |
| 295 | int cores_per_node; |
| 296 | int threads_per_core; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 297 | } topo; |
| 298 | |
| 299 | struct timeval tv_even, tv_odd, tv_delta; |
| 300 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 301 | int *irq_column_2_cpu; /* /proc/interrupts column numbers */ |
| 302 | int *irqs_per_cpu; /* indexed by cpu_num */ |
| 303 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 304 | void setup_all_buffers(void); |
| 305 | |
| 306 | int cpu_is_not_present(int cpu) |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 307 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 308 | return !CPU_ISSET_S(cpu, cpu_present_setsize, cpu_present_set); |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 309 | } |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 310 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 311 | * run func(thread, core, package) in topology order |
| 312 | * skip non-present cpus |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 313 | */ |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 314 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 315 | int for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg_data *), |
| 316 | 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] | 317 | { |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 318 | int retval, pkg_no, core_no, thread_no, node_no; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 319 | |
| 320 | for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { |
Len Brown | df2f677 | 2019-02-15 21:58:23 -0800 | [diff] [blame] | 321 | for (node_no = 0; node_no < topo.nodes_per_pkg; node_no++) { |
| 322 | for (core_no = 0; core_no < topo.cores_per_node; ++core_no) { |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 323 | for (thread_no = 0; thread_no < |
| 324 | topo.threads_per_core; ++thread_no) { |
| 325 | struct thread_data *t; |
| 326 | struct core_data *c; |
| 327 | struct pkg_data *p; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 328 | |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 329 | t = GET_THREAD(thread_base, thread_no, |
| 330 | core_no, node_no, |
| 331 | pkg_no); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 332 | |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 333 | if (cpu_is_not_present(t->cpu_id)) |
| 334 | continue; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 335 | |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 336 | c = GET_CORE(core_base, core_no, |
| 337 | node_no, pkg_no); |
| 338 | p = GET_PKG(pkg_base, pkg_no); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 339 | |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 340 | retval = func(t, c, p); |
| 341 | if (retval) |
| 342 | return retval; |
| 343 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | } |
| 347 | return 0; |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | int cpu_migrate(int cpu) |
| 351 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 352 | CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); |
| 353 | CPU_SET_S(cpu, cpu_affinity_setsize, cpu_affinity_set); |
| 354 | if (sched_setaffinity(0, cpu_affinity_setsize, cpu_affinity_set) == -1) |
Len Brown | 88c3281 | 2012-03-29 21:44:40 -0400 | [diff] [blame] | 355 | return -1; |
| 356 | else |
| 357 | return 0; |
| 358 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 359 | int get_msr_fd(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 360 | { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 361 | char pathname[32]; |
| 362 | int fd; |
| 363 | |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 364 | fd = fd_percpu[cpu]; |
| 365 | |
| 366 | if (fd) |
| 367 | return fd; |
| 368 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 369 | sprintf(pathname, "/dev/cpu/%d/msr", cpu); |
| 370 | fd = open(pathname, O_RDONLY); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 371 | if (fd < 0) |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 372 | err(-1, "%s open failed, try chown or chmod +r /dev/cpu/*/msr, or run as root", pathname); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 373 | |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 374 | fd_percpu[cpu] = fd; |
| 375 | |
| 376 | return fd; |
| 377 | } |
| 378 | |
| 379 | int get_msr(int cpu, off_t offset, unsigned long long *msr) |
| 380 | { |
| 381 | ssize_t retval; |
| 382 | |
| 383 | retval = pread(get_msr_fd(cpu), msr, sizeof(*msr), offset); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 384 | |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 385 | if (retval != sizeof *msr) |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 386 | err(-1, "cpu%d: msr offset 0x%llx read failed", cpu, (unsigned long long)offset); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 387 | |
| 388 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 389 | } |
| 390 | |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 391 | /* |
Len Brown | bdd5ae3 | 2018-06-06 17:18:36 -0400 | [diff] [blame] | 392 | * This list matches the column headers, except |
| 393 | * 1. built-in only, the sysfs counters are not here -- we learn of those at run-time |
| 394 | * 2. Core and CPU are moved to the end, we can't have strings that contain them |
| 395 | * matching on them for --show and --hide. |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 396 | */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 397 | struct msr_counter bic[] = { |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 398 | { 0x0, "usec" }, |
| 399 | { 0x0, "Time_Of_Day_Seconds" }, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 400 | { 0x0, "Package" }, |
Len Brown | bdd5ae3 | 2018-06-06 17:18:36 -0400 | [diff] [blame] | 401 | { 0x0, "Node" }, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 402 | { 0x0, "Avg_MHz" }, |
Len Brown | bdd5ae3 | 2018-06-06 17:18:36 -0400 | [diff] [blame] | 403 | { 0x0, "Busy%" }, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 404 | { 0x0, "Bzy_MHz" }, |
| 405 | { 0x0, "TSC_MHz" }, |
| 406 | { 0x0, "IRQ" }, |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 407 | { 0x0, "SMI", "", 32, 0, FORMAT_DELTA, NULL}, |
Len Brown | bdd5ae3 | 2018-06-06 17:18:36 -0400 | [diff] [blame] | 408 | { 0x0, "sysfs" }, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 409 | { 0x0, "CPU%c1" }, |
| 410 | { 0x0, "CPU%c3" }, |
| 411 | { 0x0, "CPU%c6" }, |
| 412 | { 0x0, "CPU%c7" }, |
| 413 | { 0x0, "ThreadC" }, |
| 414 | { 0x0, "CoreTmp" }, |
| 415 | { 0x0, "CoreCnt" }, |
| 416 | { 0x0, "PkgTmp" }, |
| 417 | { 0x0, "GFX%rc6" }, |
| 418 | { 0x0, "GFXMHz" }, |
| 419 | { 0x0, "Pkg%pc2" }, |
| 420 | { 0x0, "Pkg%pc3" }, |
| 421 | { 0x0, "Pkg%pc6" }, |
| 422 | { 0x0, "Pkg%pc7" }, |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 423 | { 0x0, "Pkg%pc8" }, |
| 424 | { 0x0, "Pkg%pc9" }, |
Len Brown | 4bd1f8f | 2018-01-28 23:42:42 -0500 | [diff] [blame] | 425 | { 0x0, "Pk%pc10" }, |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 426 | { 0x0, "CPU%LPI" }, |
| 427 | { 0x0, "SYS%LPI" }, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 428 | { 0x0, "PkgWatt" }, |
| 429 | { 0x0, "CorWatt" }, |
| 430 | { 0x0, "GFXWatt" }, |
| 431 | { 0x0, "PkgCnt" }, |
| 432 | { 0x0, "RAMWatt" }, |
| 433 | { 0x0, "PKG_%" }, |
| 434 | { 0x0, "RAM_%" }, |
| 435 | { 0x0, "Pkg_J" }, |
| 436 | { 0x0, "Cor_J" }, |
| 437 | { 0x0, "GFX_J" }, |
| 438 | { 0x0, "RAM_J" }, |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 439 | { 0x0, "Mod%c6" }, |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 440 | { 0x0, "Totl%C0" }, |
| 441 | { 0x0, "Any%C0" }, |
| 442 | { 0x0, "GFX%C0" }, |
| 443 | { 0x0, "CPUGFX%" }, |
Len Brown | bdd5ae3 | 2018-06-06 17:18:36 -0400 | [diff] [blame] | 444 | { 0x0, "Core" }, |
| 445 | { 0x0, "CPU" }, |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 446 | { 0x0, "APIC" }, |
| 447 | { 0x0, "X2APIC" }, |
Len Brown | 6de68fe | 2019-02-14 19:17:40 -0800 | [diff] [blame] | 448 | { 0x0, "Die" }, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 449 | }; |
| 450 | |
| 451 | #define MAX_BIC (sizeof(bic) / sizeof(struct msr_counter)) |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 452 | #define BIC_USEC (1ULL << 0) |
| 453 | #define BIC_TOD (1ULL << 1) |
| 454 | #define BIC_Package (1ULL << 2) |
Len Brown | bdd5ae3 | 2018-06-06 17:18:36 -0400 | [diff] [blame] | 455 | #define BIC_Node (1ULL << 3) |
| 456 | #define BIC_Avg_MHz (1ULL << 4) |
| 457 | #define BIC_Busy (1ULL << 5) |
| 458 | #define BIC_Bzy_MHz (1ULL << 6) |
| 459 | #define BIC_TSC_MHz (1ULL << 7) |
| 460 | #define BIC_IRQ (1ULL << 8) |
| 461 | #define BIC_SMI (1ULL << 9) |
| 462 | #define BIC_sysfs (1ULL << 10) |
| 463 | #define BIC_CPU_c1 (1ULL << 11) |
| 464 | #define BIC_CPU_c3 (1ULL << 12) |
| 465 | #define BIC_CPU_c6 (1ULL << 13) |
| 466 | #define BIC_CPU_c7 (1ULL << 14) |
| 467 | #define BIC_ThreadC (1ULL << 15) |
| 468 | #define BIC_CoreTmp (1ULL << 16) |
| 469 | #define BIC_CoreCnt (1ULL << 17) |
| 470 | #define BIC_PkgTmp (1ULL << 18) |
| 471 | #define BIC_GFX_rc6 (1ULL << 19) |
| 472 | #define BIC_GFXMHz (1ULL << 20) |
| 473 | #define BIC_Pkgpc2 (1ULL << 21) |
| 474 | #define BIC_Pkgpc3 (1ULL << 22) |
| 475 | #define BIC_Pkgpc6 (1ULL << 23) |
| 476 | #define BIC_Pkgpc7 (1ULL << 24) |
| 477 | #define BIC_Pkgpc8 (1ULL << 25) |
| 478 | #define BIC_Pkgpc9 (1ULL << 26) |
| 479 | #define BIC_Pkgpc10 (1ULL << 27) |
| 480 | #define BIC_CPU_LPI (1ULL << 28) |
| 481 | #define BIC_SYS_LPI (1ULL << 29) |
| 482 | #define BIC_PkgWatt (1ULL << 30) |
| 483 | #define BIC_CorWatt (1ULL << 31) |
| 484 | #define BIC_GFXWatt (1ULL << 32) |
| 485 | #define BIC_PkgCnt (1ULL << 33) |
| 486 | #define BIC_RAMWatt (1ULL << 34) |
| 487 | #define BIC_PKG__ (1ULL << 35) |
| 488 | #define BIC_RAM__ (1ULL << 36) |
| 489 | #define BIC_Pkg_J (1ULL << 37) |
| 490 | #define BIC_Cor_J (1ULL << 38) |
| 491 | #define BIC_GFX_J (1ULL << 39) |
| 492 | #define BIC_RAM_J (1ULL << 40) |
| 493 | #define BIC_Mod_c6 (1ULL << 41) |
| 494 | #define BIC_Totl_c0 (1ULL << 42) |
| 495 | #define BIC_Any_c0 (1ULL << 43) |
| 496 | #define BIC_GFX_c0 (1ULL << 44) |
| 497 | #define BIC_CPUGFX (1ULL << 45) |
| 498 | #define BIC_Core (1ULL << 46) |
| 499 | #define BIC_CPU (1ULL << 47) |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 500 | #define BIC_APIC (1ULL << 48) |
| 501 | #define BIC_X2APIC (1ULL << 49) |
Len Brown | 6de68fe | 2019-02-14 19:17:40 -0800 | [diff] [blame] | 502 | #define BIC_Die (1ULL << 50) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 503 | |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 504 | #define BIC_DISABLED_BY_DEFAULT (BIC_USEC | BIC_TOD | BIC_APIC | BIC_X2APIC) |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 505 | |
| 506 | unsigned long long bic_enabled = (0xFFFFFFFFFFFFFFFFULL & ~BIC_DISABLED_BY_DEFAULT); |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 507 | unsigned long long bic_present = BIC_USEC | BIC_TOD | BIC_sysfs | BIC_APIC | BIC_X2APIC; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 508 | |
| 509 | #define DO_BIC(COUNTER_NAME) (bic_enabled & bic_present & COUNTER_NAME) |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 510 | #define ENABLE_BIC(COUNTER_NAME) (bic_enabled |= COUNTER_NAME) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 511 | #define BIC_PRESENT(COUNTER_BIT) (bic_present |= COUNTER_BIT) |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 512 | #define BIC_NOT_PRESENT(COUNTER_BIT) (bic_present &= ~COUNTER_BIT) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 513 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 514 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 515 | #define MAX_DEFERRED 16 |
| 516 | char *deferred_skip_names[MAX_DEFERRED]; |
| 517 | int deferred_skip_index; |
| 518 | |
| 519 | /* |
| 520 | * HIDE_LIST - hide this list of counters, show the rest [default] |
| 521 | * SHOW_LIST - show this list of counters, hide the rest |
| 522 | */ |
| 523 | enum show_hide_mode { SHOW_LIST, HIDE_LIST } global_show_hide_mode = HIDE_LIST; |
| 524 | |
| 525 | void help(void) |
| 526 | { |
| 527 | fprintf(outf, |
| 528 | "Usage: turbostat [OPTIONS][(--interval seconds) | COMMAND ...]\n" |
| 529 | "\n" |
| 530 | "Turbostat forks the specified COMMAND and prints statistics\n" |
| 531 | "when COMMAND completes.\n" |
| 532 | "If no COMMAND is specified, turbostat wakes every 5-seconds\n" |
| 533 | "to print statistics, until interrupted.\n" |
Nathan Ciobanu | cc48165 | 2018-06-13 19:51:33 -0700 | [diff] [blame] | 534 | " -a, --add add a counter\n" |
| 535 | " eg. --add msr0x10,u64,cpu,delta,MY_TSC\n" |
| 536 | " -c, --cpu cpu-set limit output to summary plus cpu-set:\n" |
| 537 | " {core | package | j,k,l..m,n-p }\n" |
Nathan Ciobanu | 9ce8057 | 2018-06-13 19:51:34 -0700 | [diff] [blame] | 538 | " -d, --debug displays usec, Time_Of_Day_Seconds and more debugging\n" |
| 539 | " -D, --Dump displays the raw counter values\n" |
| 540 | " -e, --enable [all | column]\n" |
| 541 | " shows all or the specified disabled column\n" |
| 542 | " -H, --hide [column|column,column,...]\n" |
| 543 | " hide the specified column(s)\n" |
Nathan Ciobanu | cc48165 | 2018-06-13 19:51:33 -0700 | [diff] [blame] | 544 | " -i, --interval sec.subsec\n" |
| 545 | " Override default 5-second measurement interval\n" |
Nathan Ciobanu | 9ce8057 | 2018-06-13 19:51:34 -0700 | [diff] [blame] | 546 | " -J, --Joules displays energy in Joules instead of Watts\n" |
Nathan Ciobanu | cc48165 | 2018-06-13 19:51:33 -0700 | [diff] [blame] | 547 | " -l, --list list column headers only\n" |
| 548 | " -n, --num_iterations num\n" |
| 549 | " number of the measurement iterations\n" |
| 550 | " -o, --out file\n" |
| 551 | " create or truncate \"file\" for all output\n" |
| 552 | " -q, --quiet skip decoding system configuration header\n" |
Nathan Ciobanu | 9ce8057 | 2018-06-13 19:51:34 -0700 | [diff] [blame] | 553 | " -s, --show [column|column,column,...]\n" |
| 554 | " show only the specified column(s)\n" |
| 555 | " -S, --Summary\n" |
| 556 | " limits output to 1-line system summary per interval\n" |
| 557 | " -T, --TCC temperature\n" |
| 558 | " sets the Thermal Control Circuit temperature in\n" |
| 559 | " degrees Celsius\n" |
Nathan Ciobanu | cc48165 | 2018-06-13 19:51:33 -0700 | [diff] [blame] | 560 | " -h, --help print this help message\n" |
| 561 | " -v, --version print version information\n" |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 562 | "\n" |
| 563 | "For more help, run \"man turbostat\"\n"); |
| 564 | } |
| 565 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 566 | /* |
| 567 | * bic_lookup |
| 568 | * for all the strings in comma separate name_list, |
| 569 | * set the approprate bit in return value. |
| 570 | */ |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 571 | unsigned long long bic_lookup(char *name_list, enum show_hide_mode mode) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 572 | { |
| 573 | int i; |
| 574 | unsigned long long retval = 0; |
| 575 | |
| 576 | while (name_list) { |
| 577 | char *comma; |
| 578 | |
| 579 | comma = strchr(name_list, ','); |
| 580 | |
| 581 | if (comma) |
| 582 | *comma = '\0'; |
| 583 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 584 | if (!strcmp(name_list, "all")) |
| 585 | return ~0; |
| 586 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 587 | for (i = 0; i < MAX_BIC; ++i) { |
| 588 | if (!strcmp(name_list, bic[i].name)) { |
| 589 | retval |= (1ULL << i); |
| 590 | break; |
| 591 | } |
| 592 | } |
| 593 | if (i == MAX_BIC) { |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 594 | if (mode == SHOW_LIST) { |
| 595 | fprintf(stderr, "Invalid counter name: %s\n", name_list); |
| 596 | exit(-1); |
| 597 | } |
| 598 | deferred_skip_names[deferred_skip_index++] = name_list; |
| 599 | if (debug) |
| 600 | fprintf(stderr, "deferred \"%s\"\n", name_list); |
| 601 | if (deferred_skip_index >= MAX_DEFERRED) { |
| 602 | fprintf(stderr, "More than max %d un-recognized --skip options '%s'\n", |
| 603 | MAX_DEFERRED, name_list); |
| 604 | help(); |
| 605 | exit(1); |
| 606 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | name_list = comma; |
| 610 | if (name_list) |
| 611 | name_list++; |
| 612 | |
| 613 | } |
| 614 | return retval; |
| 615 | } |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 616 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 617 | |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 618 | void print_header(char *delim) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 619 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 620 | struct msr_counter *mp; |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 621 | int printed = 0; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 622 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 623 | if (DO_BIC(BIC_USEC)) |
| 624 | outp += sprintf(outp, "%susec", (printed++ ? delim : "")); |
| 625 | if (DO_BIC(BIC_TOD)) |
| 626 | outp += sprintf(outp, "%sTime_Of_Day_Seconds", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 627 | if (DO_BIC(BIC_Package)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 628 | outp += sprintf(outp, "%sPackage", (printed++ ? delim : "")); |
Len Brown | 6de68fe | 2019-02-14 19:17:40 -0800 | [diff] [blame] | 629 | if (DO_BIC(BIC_Die)) |
| 630 | outp += sprintf(outp, "%sDie", (printed++ ? delim : "")); |
Prarit Bhargava | 0123504 | 2018-06-01 10:04:35 -0400 | [diff] [blame] | 631 | if (DO_BIC(BIC_Node)) |
| 632 | outp += sprintf(outp, "%sNode", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 633 | if (DO_BIC(BIC_Core)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 634 | outp += sprintf(outp, "%sCore", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 635 | if (DO_BIC(BIC_CPU)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 636 | outp += sprintf(outp, "%sCPU", (printed++ ? delim : "")); |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 637 | if (DO_BIC(BIC_APIC)) |
| 638 | outp += sprintf(outp, "%sAPIC", (printed++ ? delim : "")); |
| 639 | if (DO_BIC(BIC_X2APIC)) |
| 640 | outp += sprintf(outp, "%sX2APIC", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 641 | if (DO_BIC(BIC_Avg_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 642 | outp += sprintf(outp, "%sAvg_MHz", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 643 | if (DO_BIC(BIC_Busy)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 644 | outp += sprintf(outp, "%sBusy%%", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 645 | if (DO_BIC(BIC_Bzy_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 646 | outp += sprintf(outp, "%sBzy_MHz", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 647 | if (DO_BIC(BIC_TSC_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 648 | outp += sprintf(outp, "%sTSC_MHz", (printed++ ? delim : "")); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 649 | |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 650 | if (DO_BIC(BIC_IRQ)) { |
| 651 | if (sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 652 | outp += sprintf(outp, "%s IRQ", (printed++ ? delim : "")); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 653 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 654 | outp += sprintf(outp, "%sIRQ", (printed++ ? delim : "")); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 655 | } |
| 656 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 657 | if (DO_BIC(BIC_SMI)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 658 | outp += sprintf(outp, "%sSMI", (printed++ ? delim : "")); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 659 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 660 | for (mp = sys.tp; mp; mp = mp->next) { |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 661 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 662 | if (mp->format == FORMAT_RAW) { |
| 663 | if (mp->width == 64) |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 664 | outp += sprintf(outp, "%s%18.18s", (printed++ ? delim : ""), mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 665 | else |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 666 | outp += sprintf(outp, "%s%10.10s", (printed++ ? delim : ""), mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 667 | } else { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 668 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 669 | outp += sprintf(outp, "%s%8s", (printed++ ? delim : ""), mp->name); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 670 | else |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 671 | outp += sprintf(outp, "%s%s", (printed++ ? delim : ""), mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 672 | } |
| 673 | } |
| 674 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 675 | if (DO_BIC(BIC_CPU_c1)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 676 | outp += sprintf(outp, "%sCPU%%c1", (printed++ ? delim : "")); |
Len Brown | 562855e | 2019-03-19 17:52:32 -0400 | [diff] [blame] | 677 | if (DO_BIC(BIC_CPU_c3)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 678 | outp += sprintf(outp, "%sCPU%%c3", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 679 | if (DO_BIC(BIC_CPU_c6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 680 | outp += sprintf(outp, "%sCPU%%c6", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 681 | if (DO_BIC(BIC_CPU_c7)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 682 | outp += sprintf(outp, "%sCPU%%c7", (printed++ ? delim : "")); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 683 | |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 684 | if (DO_BIC(BIC_Mod_c6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 685 | outp += sprintf(outp, "%sMod%%c6", (printed++ ? delim : "")); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 686 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 687 | if (DO_BIC(BIC_CoreTmp)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 688 | outp += sprintf(outp, "%sCoreTmp", (printed++ ? delim : "")); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 689 | |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 690 | if (do_rapl && !rapl_joules) { |
| 691 | if (DO_BIC(BIC_CorWatt) && (do_rapl & RAPL_PER_CORE_ENERGY)) |
| 692 | outp += sprintf(outp, "%sCorWatt", (printed++ ? delim : "")); |
| 693 | } else if (do_rapl && rapl_joules) { |
| 694 | if (DO_BIC(BIC_Cor_J) && (do_rapl & RAPL_PER_CORE_ENERGY)) |
| 695 | outp += sprintf(outp, "%sCor_J", (printed++ ? delim : "")); |
| 696 | } |
| 697 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 698 | for (mp = sys.cp; mp; mp = mp->next) { |
| 699 | if (mp->format == FORMAT_RAW) { |
| 700 | if (mp->width == 64) |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 701 | outp += sprintf(outp, "%s%18.18s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 702 | else |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 703 | outp += sprintf(outp, "%s%10.10s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 704 | } else { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 705 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
| 706 | outp += sprintf(outp, "%s%8s", delim, mp->name); |
| 707 | else |
| 708 | outp += sprintf(outp, "%s%s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 709 | } |
| 710 | } |
| 711 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 712 | if (DO_BIC(BIC_PkgTmp)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 713 | outp += sprintf(outp, "%sPkgTmp", (printed++ ? delim : "")); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 714 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 715 | if (DO_BIC(BIC_GFX_rc6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 716 | outp += sprintf(outp, "%sGFX%%rc6", (printed++ ? delim : "")); |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 717 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 718 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 719 | outp += sprintf(outp, "%sGFXMHz", (printed++ ? delim : "")); |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 720 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 721 | if (DO_BIC(BIC_Totl_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 722 | outp += sprintf(outp, "%sTotl%%C0", (printed++ ? delim : "")); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 723 | if (DO_BIC(BIC_Any_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 724 | outp += sprintf(outp, "%sAny%%C0", (printed++ ? delim : "")); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 725 | if (DO_BIC(BIC_GFX_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 726 | outp += sprintf(outp, "%sGFX%%C0", (printed++ ? delim : "")); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 727 | if (DO_BIC(BIC_CPUGFX)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 728 | outp += sprintf(outp, "%sCPUGFX%%", (printed++ ? delim : "")); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 729 | |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 730 | if (DO_BIC(BIC_Pkgpc2)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 731 | outp += sprintf(outp, "%sPkg%%pc2", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 732 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 733 | outp += sprintf(outp, "%sPkg%%pc3", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 734 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 735 | outp += sprintf(outp, "%sPkg%%pc6", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 736 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 737 | outp += sprintf(outp, "%sPkg%%pc7", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 738 | if (DO_BIC(BIC_Pkgpc8)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 739 | outp += sprintf(outp, "%sPkg%%pc8", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 740 | if (DO_BIC(BIC_Pkgpc9)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 741 | outp += sprintf(outp, "%sPkg%%pc9", (printed++ ? delim : "")); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 742 | if (DO_BIC(BIC_Pkgpc10)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 743 | outp += sprintf(outp, "%sPk%%pc10", (printed++ ? delim : "")); |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 744 | if (DO_BIC(BIC_CPU_LPI)) |
| 745 | outp += sprintf(outp, "%sCPU%%LPI", (printed++ ? delim : "")); |
| 746 | if (DO_BIC(BIC_SYS_LPI)) |
| 747 | outp += sprintf(outp, "%sSYS%%LPI", (printed++ ? delim : "")); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 748 | |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 749 | if (do_rapl && !rapl_joules) { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 750 | if (DO_BIC(BIC_PkgWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 751 | outp += sprintf(outp, "%sPkgWatt", (printed++ ? delim : "")); |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 752 | if (DO_BIC(BIC_CorWatt) && !(do_rapl & RAPL_PER_CORE_ENERGY)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 753 | outp += sprintf(outp, "%sCorWatt", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 754 | if (DO_BIC(BIC_GFXWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 755 | outp += sprintf(outp, "%sGFXWatt", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 756 | if (DO_BIC(BIC_RAMWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 757 | outp += sprintf(outp, "%sRAMWatt", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 758 | if (DO_BIC(BIC_PKG__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 759 | outp += sprintf(outp, "%sPKG_%%", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 760 | if (DO_BIC(BIC_RAM__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 761 | outp += sprintf(outp, "%sRAM_%%", (printed++ ? delim : "")); |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 762 | } else if (do_rapl && rapl_joules) { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 763 | if (DO_BIC(BIC_Pkg_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 764 | outp += sprintf(outp, "%sPkg_J", (printed++ ? delim : "")); |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 765 | if (DO_BIC(BIC_Cor_J) && !(do_rapl & RAPL_PER_CORE_ENERGY)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 766 | outp += sprintf(outp, "%sCor_J", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 767 | if (DO_BIC(BIC_GFX_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 768 | outp += sprintf(outp, "%sGFX_J", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 769 | if (DO_BIC(BIC_RAM_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 770 | outp += sprintf(outp, "%sRAM_J", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 771 | if (DO_BIC(BIC_PKG__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 772 | outp += sprintf(outp, "%sPKG_%%", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 773 | if (DO_BIC(BIC_RAM__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 774 | outp += sprintf(outp, "%sRAM_%%", (printed++ ? delim : "")); |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 775 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 776 | for (mp = sys.pp; mp; mp = mp->next) { |
| 777 | if (mp->format == FORMAT_RAW) { |
| 778 | if (mp->width == 64) |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 779 | outp += sprintf(outp, "%s%18.18s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 780 | else |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 781 | outp += sprintf(outp, "%s%10.10s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 782 | } else { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 783 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
| 784 | outp += sprintf(outp, "%s%8s", delim, mp->name); |
| 785 | else |
| 786 | outp += sprintf(outp, "%s%s", delim, mp->name); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 787 | } |
| 788 | } |
| 789 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 790 | outp += sprintf(outp, "\n"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 791 | } |
| 792 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 793 | int dump_counters(struct thread_data *t, struct core_data *c, |
| 794 | struct pkg_data *p) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 795 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 796 | int i; |
| 797 | struct msr_counter *mp; |
| 798 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 799 | outp += sprintf(outp, "t %p, c %p, p %p\n", t, c, p); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 800 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 801 | if (t) { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 802 | outp += sprintf(outp, "CPU: %d flags 0x%x\n", |
| 803 | t->cpu_id, t->flags); |
| 804 | outp += sprintf(outp, "TSC: %016llX\n", t->tsc); |
| 805 | outp += sprintf(outp, "aperf: %016llX\n", t->aperf); |
| 806 | outp += sprintf(outp, "mperf: %016llX\n", t->mperf); |
| 807 | outp += sprintf(outp, "c1: %016llX\n", t->c1); |
Len Brown | 6886fee | 2016-12-24 15:18:37 -0500 | [diff] [blame] | 808 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 809 | if (DO_BIC(BIC_IRQ)) |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 810 | outp += sprintf(outp, "IRQ: %lld\n", t->irq_count); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 811 | if (DO_BIC(BIC_SMI)) |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 812 | outp += sprintf(outp, "SMI: %d\n", t->smi_count); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 813 | |
| 814 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 815 | outp += sprintf(outp, "tADDED [%d] msr0x%x: %08llX\n", |
| 816 | i, mp->msr_num, t->counter[i]); |
| 817 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 818 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 819 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 820 | if (c) { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 821 | outp += sprintf(outp, "core: %d\n", c->core_id); |
| 822 | outp += sprintf(outp, "c3: %016llX\n", c->c3); |
| 823 | outp += sprintf(outp, "c6: %016llX\n", c->c6); |
| 824 | outp += sprintf(outp, "c7: %016llX\n", c->c7); |
| 825 | outp += sprintf(outp, "DTS: %dC\n", c->core_temp_c); |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 826 | outp += sprintf(outp, "Joules: %0X\n", c->core_energy); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 827 | |
| 828 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 829 | outp += sprintf(outp, "cADDED [%d] msr0x%x: %08llX\n", |
| 830 | i, mp->msr_num, c->counter[i]); |
| 831 | } |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 832 | outp += sprintf(outp, "mc6_us: %016llX\n", c->mc6_us); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | if (p) { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 836 | outp += sprintf(outp, "package: %d\n", p->package_id); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 837 | |
| 838 | outp += sprintf(outp, "Weighted cores: %016llX\n", p->pkg_wtd_core_c0); |
| 839 | outp += sprintf(outp, "Any cores: %016llX\n", p->pkg_any_core_c0); |
| 840 | outp += sprintf(outp, "Any GFX: %016llX\n", p->pkg_any_gfxe_c0); |
| 841 | outp += sprintf(outp, "CPU + GFX: %016llX\n", p->pkg_both_core_gfxe_c0); |
| 842 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 843 | outp += sprintf(outp, "pc2: %016llX\n", p->pc2); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 844 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 845 | outp += sprintf(outp, "pc3: %016llX\n", p->pc3); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 846 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 847 | outp += sprintf(outp, "pc6: %016llX\n", p->pc6); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 848 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 849 | outp += sprintf(outp, "pc7: %016llX\n", p->pc7); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 850 | outp += sprintf(outp, "pc8: %016llX\n", p->pc8); |
| 851 | outp += sprintf(outp, "pc9: %016llX\n", p->pc9); |
| 852 | outp += sprintf(outp, "pc10: %016llX\n", p->pc10); |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 853 | outp += sprintf(outp, "cpu_lpi: %016llX\n", p->cpu_lpi); |
| 854 | outp += sprintf(outp, "sys_lpi: %016llX\n", p->sys_lpi); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 855 | outp += sprintf(outp, "Joules PKG: %0X\n", p->energy_pkg); |
| 856 | outp += sprintf(outp, "Joules COR: %0X\n", p->energy_cores); |
| 857 | outp += sprintf(outp, "Joules GFX: %0X\n", p->energy_gfx); |
| 858 | outp += sprintf(outp, "Joules RAM: %0X\n", p->energy_dram); |
| 859 | outp += sprintf(outp, "Throttle PKG: %0X\n", |
| 860 | p->rapl_pkg_perf_status); |
| 861 | outp += sprintf(outp, "Throttle RAM: %0X\n", |
| 862 | p->rapl_dram_perf_status); |
| 863 | outp += sprintf(outp, "PTM: %dC\n", p->pkg_temp_c); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 864 | |
| 865 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 866 | outp += sprintf(outp, "pADDED [%d] msr0x%x: %08llX\n", |
| 867 | i, mp->msr_num, p->counter[i]); |
| 868 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 869 | } |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 870 | |
| 871 | outp += sprintf(outp, "\n"); |
| 872 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 873 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 874 | } |
| 875 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 876 | /* |
| 877 | * column formatting convention & formats |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 878 | */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 879 | int format_counters(struct thread_data *t, struct core_data *c, |
| 880 | struct pkg_data *p) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 881 | { |
Len Brown | 008d396e | 2017-02-10 00:29:51 -0500 | [diff] [blame] | 882 | double interval_float, tsc; |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 883 | char *fmt8; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 884 | int i; |
| 885 | struct msr_counter *mp; |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 886 | char *delim = "\t"; |
| 887 | int printed = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 888 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 889 | /* if showing only 1st thread in core and this isn't one, bail out */ |
| 890 | if (show_core_only && !(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 891 | return 0; |
| 892 | |
| 893 | /* if showing only 1st thread in pkg and this isn't one, bail out */ |
| 894 | if (show_pkg_only && !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 895 | return 0; |
| 896 | |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 897 | /*if not summary line and --cpu is used */ |
| 898 | if ((t != &average.threads) && |
| 899 | (cpu_subset && !CPU_ISSET_S(t->cpu_id, cpu_subset_size, cpu_subset))) |
| 900 | return 0; |
| 901 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 902 | if (DO_BIC(BIC_USEC)) { |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 903 | /* on each row, print how many usec each timestamp took to gather */ |
| 904 | struct timeval tv; |
| 905 | |
| 906 | timersub(&t->tv_end, &t->tv_begin, &tv); |
| 907 | outp += sprintf(outp, "%5ld\t", tv.tv_sec * 1000000 + tv.tv_usec); |
| 908 | } |
| 909 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 910 | /* Time_Of_Day_Seconds: on each row, print sec.usec last timestamp taken */ |
| 911 | if (DO_BIC(BIC_TOD)) |
| 912 | outp += sprintf(outp, "%10ld.%06ld\t", t->tv_end.tv_sec, t->tv_end.tv_usec); |
| 913 | |
Yazen Ghannam | d4794f2 | 2019-03-25 17:32:42 +0000 | [diff] [blame] | 914 | interval_float = t->tv_delta.tv_sec + t->tv_delta.tv_usec/1000000.0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 915 | |
Len Brown | 008d396e | 2017-02-10 00:29:51 -0500 | [diff] [blame] | 916 | tsc = t->tsc * tsc_tweak; |
| 917 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 918 | /* topo columns, print blanks on 1st (average) line */ |
| 919 | if (t == &average.threads) { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 920 | if (DO_BIC(BIC_Package)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 921 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | 6de68fe | 2019-02-14 19:17:40 -0800 | [diff] [blame] | 922 | if (DO_BIC(BIC_Die)) |
| 923 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Prarit Bhargava | 0123504 | 2018-06-01 10:04:35 -0400 | [diff] [blame] | 924 | if (DO_BIC(BIC_Node)) |
| 925 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 926 | if (DO_BIC(BIC_Core)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 927 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 928 | if (DO_BIC(BIC_CPU)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 929 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 930 | if (DO_BIC(BIC_APIC)) |
| 931 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
| 932 | if (DO_BIC(BIC_X2APIC)) |
| 933 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 934 | } else { |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 935 | if (DO_BIC(BIC_Package)) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 936 | if (p) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 937 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->package_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 938 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 939 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 940 | } |
Len Brown | 6de68fe | 2019-02-14 19:17:40 -0800 | [diff] [blame] | 941 | if (DO_BIC(BIC_Die)) { |
| 942 | if (c) |
| 943 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), cpus[t->cpu_id].die_id); |
| 944 | else |
| 945 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
| 946 | } |
Prarit Bhargava | 0123504 | 2018-06-01 10:04:35 -0400 | [diff] [blame] | 947 | if (DO_BIC(BIC_Node)) { |
| 948 | if (t) |
| 949 | outp += sprintf(outp, "%s%d", |
| 950 | (printed++ ? delim : ""), |
| 951 | cpus[t->cpu_id].physical_node_id); |
| 952 | else |
| 953 | outp += sprintf(outp, "%s-", |
| 954 | (printed++ ? delim : "")); |
| 955 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 956 | if (DO_BIC(BIC_Core)) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 957 | if (c) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 958 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), c->core_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 959 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 960 | outp += sprintf(outp, "%s-", (printed++ ? delim : "")); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 961 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 962 | if (DO_BIC(BIC_CPU)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 963 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->cpu_id); |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 964 | if (DO_BIC(BIC_APIC)) |
| 965 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->apic_id); |
| 966 | if (DO_BIC(BIC_X2APIC)) |
| 967 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->x2apic_id); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 968 | } |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 969 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 970 | if (DO_BIC(BIC_Avg_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 971 | outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), |
Len Brown | fc04cc6 | 2014-02-06 00:55:19 -0500 | [diff] [blame] | 972 | 1.0 / units * t->aperf / interval_float); |
| 973 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 974 | if (DO_BIC(BIC_Busy)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 975 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->mperf/tsc); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 976 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 977 | if (DO_BIC(BIC_Bzy_MHz)) { |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 978 | if (has_base_hz) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 979 | outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), base_hz / units * t->aperf / t->mperf); |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 980 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 981 | outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), |
Len Brown | 008d396e | 2017-02-10 00:29:51 -0500 | [diff] [blame] | 982 | tsc / units * t->aperf / t->mperf / interval_float); |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 983 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 984 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 985 | if (DO_BIC(BIC_TSC_MHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 986 | outp += sprintf(outp, "%s%.0f", (printed++ ? delim : ""), 1.0 * t->tsc/units/interval_float); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 987 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 988 | /* IRQ */ |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 989 | if (DO_BIC(BIC_IRQ)) { |
| 990 | if (sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 991 | outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), t->irq_count); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 992 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 993 | outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->irq_count); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 994 | } |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 995 | |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 996 | /* SMI */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 997 | if (DO_BIC(BIC_SMI)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 998 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), t->smi_count); |
Len Brown | 1cc21f7 | 2015-02-23 00:34:57 -0500 | [diff] [blame] | 999 | |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 1000 | /* Added counters */ |
| 1001 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 1002 | if (mp->format == FORMAT_RAW) { |
| 1003 | if (mp->width == 32) |
Len Brown | 5f3aea5 | 2017-02-23 18:10:27 -0500 | [diff] [blame] | 1004 | outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int) t->counter[i]); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 1005 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1006 | outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), t->counter[i]); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 1007 | } else if (mp->format == FORMAT_DELTA) { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1008 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1009 | outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), t->counter[i]); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1010 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1011 | outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), t->counter[i]); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 1012 | } else if (mp->format == FORMAT_PERCENT) { |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 1013 | if (mp->type == COUNTER_USEC) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1014 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), t->counter[i]/interval_float/10000); |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 1015 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1016 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->counter[i]/tsc); |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 1017 | } |
| 1018 | } |
| 1019 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 1020 | /* C1 */ |
| 1021 | if (DO_BIC(BIC_CPU_c1)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1022 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * t->c1/tsc); |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 1023 | |
| 1024 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1025 | /* print per-core data only for 1st thread in core */ |
| 1026 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 1027 | goto done; |
| 1028 | |
Len Brown | 562855e | 2019-03-19 17:52:32 -0400 | [diff] [blame] | 1029 | if (DO_BIC(BIC_CPU_c3)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1030 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c3/tsc); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1031 | if (DO_BIC(BIC_CPU_c6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1032 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c6/tsc); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1033 | if (DO_BIC(BIC_CPU_c7)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1034 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c7/tsc); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1035 | |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1036 | /* Mod%c6 */ |
| 1037 | if (DO_BIC(BIC_Mod_c6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1038 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->mc6_us / tsc); |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1039 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1040 | if (DO_BIC(BIC_CoreTmp)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1041 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), c->core_temp_c); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1042 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1043 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 1044 | if (mp->format == FORMAT_RAW) { |
| 1045 | if (mp->width == 32) |
Len Brown | 5f3aea5 | 2017-02-23 18:10:27 -0500 | [diff] [blame] | 1046 | outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int) c->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1047 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1048 | outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), c->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1049 | } else if (mp->format == FORMAT_DELTA) { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1050 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1051 | outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), c->counter[i]); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1052 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1053 | outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), c->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1054 | } else if (mp->format == FORMAT_PERCENT) { |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1055 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->counter[i]/tsc); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1056 | } |
| 1057 | } |
| 1058 | |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 1059 | /* |
| 1060 | * If measurement interval exceeds minimum RAPL Joule Counter range, |
| 1061 | * indicate that results are suspect by printing "**" in fraction place. |
| 1062 | */ |
| 1063 | if (interval_float < rapl_joule_counter_range) |
| 1064 | fmt8 = "%s%.2f"; |
| 1065 | else |
| 1066 | fmt8 = "%6.0f**"; |
| 1067 | |
| 1068 | if (DO_BIC(BIC_CorWatt) && (do_rapl & RAPL_PER_CORE_ENERGY)) |
| 1069 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), c->core_energy * rapl_energy_units / interval_float); |
| 1070 | if (DO_BIC(BIC_Cor_J) && (do_rapl & RAPL_PER_CORE_ENERGY)) |
| 1071 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), c->core_energy * rapl_energy_units); |
| 1072 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1073 | /* print per-package data only for 1st core in package */ |
| 1074 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 1075 | goto done; |
| 1076 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1077 | /* PkgTmp */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1078 | if (DO_BIC(BIC_PkgTmp)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1079 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->pkg_temp_c); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1080 | |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1081 | /* GFXrc6 */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1082 | if (DO_BIC(BIC_GFX_rc6)) { |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1083 | if (p->gfx_rc6_ms == -1) { /* detect GFX counter reset */ |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1084 | outp += sprintf(outp, "%s**.**", (printed++ ? delim : "")); |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 1085 | } else { |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1086 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 1087 | p->gfx_rc6_ms / 10.0 / interval_float); |
| 1088 | } |
| 1089 | } |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1090 | |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1091 | /* GFXMHz */ |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1092 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1093 | outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->gfx_mhz); |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1094 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1095 | /* Totl%C0, Any%C0 GFX%C0 CPUGFX% */ |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1096 | if (DO_BIC(BIC_Totl_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1097 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_wtd_core_c0/tsc); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1098 | if (DO_BIC(BIC_Any_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1099 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_any_core_c0/tsc); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1100 | if (DO_BIC(BIC_GFX_c0)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1101 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_any_gfxe_c0/tsc); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1102 | if (DO_BIC(BIC_CPUGFX)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1103 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_both_core_gfxe_c0/tsc); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1104 | |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1105 | if (DO_BIC(BIC_Pkgpc2)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1106 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc2/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1107 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1108 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc3/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1109 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1110 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc6/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1111 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1112 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc7/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1113 | if (DO_BIC(BIC_Pkgpc8)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1114 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc8/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1115 | if (DO_BIC(BIC_Pkgpc9)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1116 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc9/tsc); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1117 | if (DO_BIC(BIC_Pkgpc10)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1118 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc10/tsc); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1119 | |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 1120 | if (DO_BIC(BIC_CPU_LPI)) |
| 1121 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->cpu_lpi / 1000000.0 / interval_float); |
| 1122 | if (DO_BIC(BIC_SYS_LPI)) |
| 1123 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->sys_lpi / 1000000.0 / interval_float); |
| 1124 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1125 | if (DO_BIC(BIC_PkgWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1126 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_pkg * rapl_energy_units / interval_float); |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 1127 | if (DO_BIC(BIC_CorWatt) && !(do_rapl & RAPL_PER_CORE_ENERGY)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1128 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_cores * rapl_energy_units / interval_float); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1129 | if (DO_BIC(BIC_GFXWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1130 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_gfx * rapl_energy_units / interval_float); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1131 | if (DO_BIC(BIC_RAMWatt)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1132 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_dram * rapl_dram_energy_units / interval_float); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1133 | if (DO_BIC(BIC_Pkg_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1134 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_pkg * rapl_energy_units); |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 1135 | if (DO_BIC(BIC_Cor_J) && !(do_rapl & RAPL_PER_CORE_ENERGY)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1136 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_cores * rapl_energy_units); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1137 | if (DO_BIC(BIC_GFX_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1138 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_gfx * rapl_energy_units); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1139 | if (DO_BIC(BIC_RAM_J)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1140 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), p->energy_dram * rapl_dram_energy_units); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1141 | if (DO_BIC(BIC_PKG__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1142 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), 100.0 * p->rapl_pkg_perf_status * rapl_time_units / interval_float); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1143 | if (DO_BIC(BIC_RAM__)) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1144 | outp += sprintf(outp, fmt8, (printed++ ? delim : ""), 100.0 * p->rapl_dram_perf_status * rapl_time_units / interval_float); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1145 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1146 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1147 | if (mp->format == FORMAT_RAW) { |
| 1148 | if (mp->width == 32) |
Len Brown | 5f3aea5 | 2017-02-23 18:10:27 -0500 | [diff] [blame] | 1149 | outp += sprintf(outp, "%s0x%08x", (printed++ ? delim : ""), (unsigned int) p->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1150 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1151 | outp += sprintf(outp, "%s0x%016llx", (printed++ ? delim : ""), p->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1152 | } else if (mp->format == FORMAT_DELTA) { |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1153 | if ((mp->type == COUNTER_ITEMS) && sums_need_wide_columns) |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1154 | outp += sprintf(outp, "%s%8lld", (printed++ ? delim : ""), p->counter[i]); |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1155 | else |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1156 | outp += sprintf(outp, "%s%lld", (printed++ ? delim : ""), p->counter[i]); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1157 | } else if (mp->format == FORMAT_PERCENT) { |
Len Brown | 6168c2e | 2017-02-16 23:07:51 -0500 | [diff] [blame] | 1158 | outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->counter[i]/tsc); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1159 | } |
| 1160 | } |
| 1161 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1162 | done: |
Len Brown | 94d6ab4 | 2018-01-27 22:39:21 -0500 | [diff] [blame] | 1163 | if (*(outp - 1) != '\n') |
| 1164 | outp += sprintf(outp, "\n"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1165 | |
| 1166 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1167 | } |
| 1168 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1169 | void flush_output_stdout(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1170 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1171 | FILE *filep; |
| 1172 | |
| 1173 | if (outf == stderr) |
| 1174 | filep = stdout; |
| 1175 | else |
| 1176 | filep = outf; |
| 1177 | |
| 1178 | fputs(output_buffer, filep); |
| 1179 | fflush(filep); |
| 1180 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1181 | outp = output_buffer; |
| 1182 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1183 | void flush_output_stderr(void) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1184 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1185 | fputs(output_buffer, outf); |
| 1186 | fflush(outf); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1187 | outp = output_buffer; |
| 1188 | } |
| 1189 | void format_all_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 1190 | { |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 1191 | static int printed; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1192 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 1193 | if (!printed || !summary_only) |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 1194 | print_header("\t"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1195 | |
Len Brown | 9d83601 | 2018-07-20 14:47:03 -0400 | [diff] [blame] | 1196 | format_counters(&average.threads, &average.cores, &average.packages); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1197 | |
Len Brown | e23da03 | 2012-02-06 18:37:16 -0500 | [diff] [blame] | 1198 | printed = 1; |
| 1199 | |
| 1200 | if (summary_only) |
| 1201 | return; |
| 1202 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1203 | for_all_cpus(format_counters, t, c, p); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1204 | } |
| 1205 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1206 | #define DELTA_WRAP32(new, old) \ |
| 1207 | if (new > old) { \ |
| 1208 | old = new - old; \ |
| 1209 | } else { \ |
| 1210 | old = 0x100000000 + new - old; \ |
| 1211 | } |
| 1212 | |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1213 | int |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1214 | delta_package(struct pkg_data *new, struct pkg_data *old) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1215 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1216 | int i; |
| 1217 | struct msr_counter *mp; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1218 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1219 | |
| 1220 | if (DO_BIC(BIC_Totl_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1221 | old->pkg_wtd_core_c0 = new->pkg_wtd_core_c0 - old->pkg_wtd_core_c0; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1222 | if (DO_BIC(BIC_Any_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1223 | old->pkg_any_core_c0 = new->pkg_any_core_c0 - old->pkg_any_core_c0; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1224 | if (DO_BIC(BIC_GFX_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1225 | old->pkg_any_gfxe_c0 = new->pkg_any_gfxe_c0 - old->pkg_any_gfxe_c0; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1226 | if (DO_BIC(BIC_CPUGFX)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1227 | old->pkg_both_core_gfxe_c0 = new->pkg_both_core_gfxe_c0 - old->pkg_both_core_gfxe_c0; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1228 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1229 | old->pc2 = new->pc2 - old->pc2; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1230 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1231 | old->pc3 = new->pc3 - old->pc3; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1232 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1233 | old->pc6 = new->pc6 - old->pc6; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1234 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1235 | old->pc7 = new->pc7 - old->pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1236 | old->pc8 = new->pc8 - old->pc8; |
| 1237 | old->pc9 = new->pc9 - old->pc9; |
| 1238 | old->pc10 = new->pc10 - old->pc10; |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 1239 | old->cpu_lpi = new->cpu_lpi - old->cpu_lpi; |
| 1240 | old->sys_lpi = new->sys_lpi - old->sys_lpi; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1241 | old->pkg_temp_c = new->pkg_temp_c; |
| 1242 | |
Len Brown | 9185e98 | 2016-04-06 17:16:00 -0400 | [diff] [blame] | 1243 | /* flag an error when rc6 counter resets/wraps */ |
| 1244 | if (old->gfx_rc6_ms > new->gfx_rc6_ms) |
| 1245 | old->gfx_rc6_ms = -1; |
| 1246 | else |
| 1247 | old->gfx_rc6_ms = new->gfx_rc6_ms - old->gfx_rc6_ms; |
| 1248 | |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1249 | old->gfx_mhz = new->gfx_mhz; |
| 1250 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1251 | DELTA_WRAP32(new->energy_pkg, old->energy_pkg); |
| 1252 | DELTA_WRAP32(new->energy_cores, old->energy_cores); |
| 1253 | DELTA_WRAP32(new->energy_gfx, old->energy_gfx); |
| 1254 | DELTA_WRAP32(new->energy_dram, old->energy_dram); |
| 1255 | DELTA_WRAP32(new->rapl_pkg_perf_status, old->rapl_pkg_perf_status); |
| 1256 | DELTA_WRAP32(new->rapl_dram_perf_status, old->rapl_dram_perf_status); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1257 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1258 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1259 | if (mp->format == FORMAT_RAW) |
| 1260 | old->counter[i] = new->counter[i]; |
| 1261 | else |
| 1262 | old->counter[i] = new->counter[i] - old->counter[i]; |
| 1263 | } |
| 1264 | |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1265 | return 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1266 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1267 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1268 | void |
| 1269 | delta_core(struct core_data *new, struct core_data *old) |
| 1270 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1271 | int i; |
| 1272 | struct msr_counter *mp; |
| 1273 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1274 | old->c3 = new->c3 - old->c3; |
| 1275 | old->c6 = new->c6 - old->c6; |
| 1276 | old->c7 = new->c7 - old->c7; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1277 | old->core_temp_c = new->core_temp_c; |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1278 | old->mc6_us = new->mc6_us - old->mc6_us; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1279 | |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 1280 | DELTA_WRAP32(new->core_energy, old->core_energy); |
| 1281 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1282 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 1283 | if (mp->format == FORMAT_RAW) |
| 1284 | old->counter[i] = new->counter[i]; |
| 1285 | else |
| 1286 | old->counter[i] = new->counter[i] - old->counter[i]; |
| 1287 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1288 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1289 | |
Len Brown | c3ae331 | 2012-06-13 21:31:46 -0400 | [diff] [blame] | 1290 | /* |
| 1291 | * old = new - old |
| 1292 | */ |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1293 | int |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1294 | delta_thread(struct thread_data *new, struct thread_data *old, |
| 1295 | struct core_data *core_delta) |
| 1296 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1297 | int i; |
| 1298 | struct msr_counter *mp; |
| 1299 | |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 1300 | /* we run cpuid just the 1st time, copy the results */ |
| 1301 | if (DO_BIC(BIC_APIC)) |
| 1302 | new->apic_id = old->apic_id; |
| 1303 | if (DO_BIC(BIC_X2APIC)) |
| 1304 | new->x2apic_id = old->x2apic_id; |
| 1305 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 1306 | /* |
| 1307 | * the timestamps from start of measurement interval are in "old" |
| 1308 | * the timestamp from end of measurement interval are in "new" |
| 1309 | * over-write old w/ new so we can print end of interval values |
| 1310 | */ |
| 1311 | |
Yazen Ghannam | d4794f2 | 2019-03-25 17:32:42 +0000 | [diff] [blame] | 1312 | timersub(&new->tv_begin, &old->tv_begin, &old->tv_delta); |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 1313 | old->tv_begin = new->tv_begin; |
| 1314 | old->tv_end = new->tv_end; |
| 1315 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1316 | old->tsc = new->tsc - old->tsc; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1317 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1318 | /* check for TSC < 1 Mcycles over interval */ |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 1319 | if (old->tsc < (1000 * 1000)) |
| 1320 | errx(-3, "Insanely slow TSC rate, TSC stops in idle?\n" |
| 1321 | "You can disable all c-states by booting with \"idle=poll\"\n" |
| 1322 | "or just the deep ones with \"processor.max_cstate=1\""); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1323 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1324 | old->c1 = new->c1 - old->c1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1325 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1326 | if (DO_BIC(BIC_Avg_MHz) || DO_BIC(BIC_Busy) || DO_BIC(BIC_Bzy_MHz)) { |
Len Brown | a729617 | 2015-01-23 01:33:58 -0500 | [diff] [blame] | 1327 | if ((new->aperf > old->aperf) && (new->mperf > old->mperf)) { |
| 1328 | old->aperf = new->aperf - old->aperf; |
| 1329 | old->mperf = new->mperf - old->mperf; |
| 1330 | } else { |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1331 | return -1; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1332 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1333 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1334 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 1335 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1336 | if (use_c1_residency_msr) { |
| 1337 | /* |
| 1338 | * Some models have a dedicated C1 residency MSR, |
| 1339 | * which should be more accurate than the derivation below. |
| 1340 | */ |
| 1341 | } else { |
| 1342 | /* |
| 1343 | * As counter collection is not atomic, |
| 1344 | * it is possible for mperf's non-halted cycles + idle states |
| 1345 | * to exceed TSC's all cycles: show c1 = 0% in that case. |
| 1346 | */ |
Len Brown | 9514936 | 2017-04-12 19:44:51 -0400 | [diff] [blame] | 1347 | if ((old->mperf + core_delta->c3 + core_delta->c6 + core_delta->c7) > (old->tsc * tsc_tweak)) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1348 | old->c1 = 0; |
| 1349 | else { |
| 1350 | /* normal case, derive c1 */ |
Len Brown | 008d396e | 2017-02-10 00:29:51 -0500 | [diff] [blame] | 1351 | old->c1 = (old->tsc * tsc_tweak) - old->mperf - core_delta->c3 |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1352 | - core_delta->c6 - core_delta->c7; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1353 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1354 | } |
Len Brown | c3ae331 | 2012-06-13 21:31:46 -0400 | [diff] [blame] | 1355 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1356 | if (old->mperf == 0) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1357 | if (debug > 1) |
| 1358 | fprintf(outf, "cpu%d MPERF 0!\n", old->cpu_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1359 | old->mperf = 1; /* divide by 0 protection */ |
| 1360 | } |
| 1361 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1362 | if (DO_BIC(BIC_IRQ)) |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1363 | old->irq_count = new->irq_count - old->irq_count; |
| 1364 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1365 | if (DO_BIC(BIC_SMI)) |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 1366 | old->smi_count = new->smi_count - old->smi_count; |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1367 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1368 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 1369 | if (mp->format == FORMAT_RAW) |
| 1370 | old->counter[i] = new->counter[i]; |
| 1371 | else |
| 1372 | old->counter[i] = new->counter[i] - old->counter[i]; |
| 1373 | } |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1374 | return 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | int delta_cpu(struct thread_data *t, struct core_data *c, |
| 1378 | struct pkg_data *p, struct thread_data *t2, |
| 1379 | struct core_data *c2, struct pkg_data *p2) |
| 1380 | { |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1381 | int retval = 0; |
| 1382 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1383 | /* calculate core delta only for 1st thread in core */ |
| 1384 | if (t->flags & CPU_IS_FIRST_THREAD_IN_CORE) |
| 1385 | delta_core(c, c2); |
| 1386 | |
| 1387 | /* always calculate thread delta */ |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1388 | retval = delta_thread(t, t2, c2); /* c2 is core delta */ |
| 1389 | if (retval) |
| 1390 | return retval; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1391 | |
| 1392 | /* calculate package delta only for 1st core in package */ |
| 1393 | if (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE) |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1394 | retval = delta_package(p, p2); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1395 | |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 1396 | return retval; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | void clear_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 1400 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1401 | int i; |
| 1402 | struct msr_counter *mp; |
| 1403 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 1404 | t->tv_begin.tv_sec = 0; |
| 1405 | t->tv_begin.tv_usec = 0; |
| 1406 | t->tv_end.tv_sec = 0; |
| 1407 | t->tv_end.tv_usec = 0; |
Yazen Ghannam | d4794f2 | 2019-03-25 17:32:42 +0000 | [diff] [blame] | 1408 | t->tv_delta.tv_sec = 0; |
| 1409 | t->tv_delta.tv_usec = 0; |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 1410 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1411 | t->tsc = 0; |
| 1412 | t->aperf = 0; |
| 1413 | t->mperf = 0; |
| 1414 | t->c1 = 0; |
| 1415 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1416 | t->irq_count = 0; |
| 1417 | t->smi_count = 0; |
| 1418 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1419 | /* tells format_counters to dump all fields from this set */ |
| 1420 | t->flags = CPU_IS_FIRST_THREAD_IN_CORE | CPU_IS_FIRST_CORE_IN_PACKAGE; |
| 1421 | |
| 1422 | c->c3 = 0; |
| 1423 | c->c6 = 0; |
| 1424 | c->c7 = 0; |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1425 | c->mc6_us = 0; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1426 | c->core_temp_c = 0; |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 1427 | c->core_energy = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1428 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1429 | p->pkg_wtd_core_c0 = 0; |
| 1430 | p->pkg_any_core_c0 = 0; |
| 1431 | p->pkg_any_gfxe_c0 = 0; |
| 1432 | p->pkg_both_core_gfxe_c0 = 0; |
| 1433 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1434 | p->pc2 = 0; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1435 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1436 | p->pc3 = 0; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1437 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1438 | p->pc6 = 0; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1439 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1440 | p->pc7 = 0; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1441 | p->pc8 = 0; |
| 1442 | p->pc9 = 0; |
| 1443 | p->pc10 = 0; |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 1444 | p->cpu_lpi = 0; |
| 1445 | p->sys_lpi = 0; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1446 | |
| 1447 | p->energy_pkg = 0; |
| 1448 | p->energy_dram = 0; |
| 1449 | p->energy_cores = 0; |
| 1450 | p->energy_gfx = 0; |
| 1451 | p->rapl_pkg_perf_status = 0; |
| 1452 | p->rapl_dram_perf_status = 0; |
| 1453 | p->pkg_temp_c = 0; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1454 | |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1455 | p->gfx_rc6_ms = 0; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1456 | p->gfx_mhz = 0; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1457 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) |
| 1458 | t->counter[i] = 0; |
| 1459 | |
| 1460 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) |
| 1461 | c->counter[i] = 0; |
| 1462 | |
| 1463 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) |
| 1464 | p->counter[i] = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1465 | } |
| 1466 | int sum_counters(struct thread_data *t, struct core_data *c, |
| 1467 | struct pkg_data *p) |
| 1468 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1469 | int i; |
| 1470 | struct msr_counter *mp; |
| 1471 | |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 1472 | /* copy un-changing apic_id's */ |
| 1473 | if (DO_BIC(BIC_APIC)) |
| 1474 | average.threads.apic_id = t->apic_id; |
| 1475 | if (DO_BIC(BIC_X2APIC)) |
| 1476 | average.threads.x2apic_id = t->x2apic_id; |
| 1477 | |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 1478 | /* remember first tv_begin */ |
| 1479 | if (average.threads.tv_begin.tv_sec == 0) |
| 1480 | average.threads.tv_begin = t->tv_begin; |
| 1481 | |
| 1482 | /* remember last tv_end */ |
| 1483 | average.threads.tv_end = t->tv_end; |
| 1484 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1485 | average.threads.tsc += t->tsc; |
| 1486 | average.threads.aperf += t->aperf; |
| 1487 | average.threads.mperf += t->mperf; |
| 1488 | average.threads.c1 += t->c1; |
| 1489 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1490 | average.threads.irq_count += t->irq_count; |
| 1491 | average.threads.smi_count += t->smi_count; |
| 1492 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1493 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 1494 | if (mp->format == FORMAT_RAW) |
| 1495 | continue; |
| 1496 | average.threads.counter[i] += t->counter[i]; |
| 1497 | } |
| 1498 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1499 | /* sum per-core values only for 1st thread in core */ |
| 1500 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
| 1501 | return 0; |
| 1502 | |
| 1503 | average.cores.c3 += c->c3; |
| 1504 | average.cores.c6 += c->c6; |
| 1505 | average.cores.c7 += c->c7; |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1506 | average.cores.mc6_us += c->mc6_us; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1507 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1508 | average.cores.core_temp_c = MAX(average.cores.core_temp_c, c->core_temp_c); |
| 1509 | |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 1510 | average.cores.core_energy += c->core_energy; |
| 1511 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1512 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 1513 | if (mp->format == FORMAT_RAW) |
| 1514 | continue; |
| 1515 | average.cores.counter[i] += c->counter[i]; |
| 1516 | } |
| 1517 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1518 | /* sum per-pkg values only for 1st core in pkg */ |
| 1519 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 1520 | return 0; |
| 1521 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1522 | if (DO_BIC(BIC_Totl_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1523 | average.packages.pkg_wtd_core_c0 += p->pkg_wtd_core_c0; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1524 | if (DO_BIC(BIC_Any_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1525 | average.packages.pkg_any_core_c0 += p->pkg_any_core_c0; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1526 | if (DO_BIC(BIC_GFX_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1527 | average.packages.pkg_any_gfxe_c0 += p->pkg_any_gfxe_c0; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1528 | if (DO_BIC(BIC_CPUGFX)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1529 | average.packages.pkg_both_core_gfxe_c0 += p->pkg_both_core_gfxe_c0; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1530 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1531 | average.packages.pc2 += p->pc2; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1532 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1533 | average.packages.pc3 += p->pc3; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1534 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1535 | average.packages.pc6 += p->pc6; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1536 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1537 | average.packages.pc7 += p->pc7; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1538 | average.packages.pc8 += p->pc8; |
| 1539 | average.packages.pc9 += p->pc9; |
| 1540 | average.packages.pc10 += p->pc10; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1541 | |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 1542 | average.packages.cpu_lpi = p->cpu_lpi; |
| 1543 | average.packages.sys_lpi = p->sys_lpi; |
| 1544 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1545 | average.packages.energy_pkg += p->energy_pkg; |
| 1546 | average.packages.energy_dram += p->energy_dram; |
| 1547 | average.packages.energy_cores += p->energy_cores; |
| 1548 | average.packages.energy_gfx += p->energy_gfx; |
| 1549 | |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1550 | average.packages.gfx_rc6_ms = p->gfx_rc6_ms; |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1551 | average.packages.gfx_mhz = p->gfx_mhz; |
| 1552 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1553 | average.packages.pkg_temp_c = MAX(average.packages.pkg_temp_c, p->pkg_temp_c); |
| 1554 | |
| 1555 | average.packages.rapl_pkg_perf_status += p->rapl_pkg_perf_status; |
| 1556 | average.packages.rapl_dram_perf_status += p->rapl_dram_perf_status; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1557 | |
| 1558 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1559 | if (mp->format == FORMAT_RAW) |
| 1560 | continue; |
| 1561 | average.packages.counter[i] += p->counter[i]; |
| 1562 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1563 | return 0; |
| 1564 | } |
| 1565 | /* |
| 1566 | * sum the counters for all cpus in the system |
| 1567 | * compute the weighted average |
| 1568 | */ |
| 1569 | void compute_average(struct thread_data *t, struct core_data *c, |
| 1570 | struct pkg_data *p) |
| 1571 | { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1572 | int i; |
| 1573 | struct msr_counter *mp; |
| 1574 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1575 | clear_counters(&average.threads, &average.cores, &average.packages); |
| 1576 | |
| 1577 | for_all_cpus(sum_counters, t, c, p); |
| 1578 | |
Yazen Ghannam | d4794f2 | 2019-03-25 17:32:42 +0000 | [diff] [blame] | 1579 | /* Use the global time delta for the average. */ |
| 1580 | average.threads.tv_delta = tv_delta; |
| 1581 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1582 | average.threads.tsc /= topo.num_cpus; |
| 1583 | average.threads.aperf /= topo.num_cpus; |
| 1584 | average.threads.mperf /= topo.num_cpus; |
| 1585 | average.threads.c1 /= topo.num_cpus; |
| 1586 | |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1587 | if (average.threads.irq_count > 9999999) |
| 1588 | sums_need_wide_columns = 1; |
| 1589 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1590 | average.cores.c3 /= topo.num_cores; |
| 1591 | average.cores.c6 /= topo.num_cores; |
| 1592 | average.cores.c7 /= topo.num_cores; |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1593 | average.cores.mc6_us /= topo.num_cores; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1594 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1595 | if (DO_BIC(BIC_Totl_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1596 | average.packages.pkg_wtd_core_c0 /= topo.num_packages; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1597 | if (DO_BIC(BIC_Any_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1598 | average.packages.pkg_any_core_c0 /= topo.num_packages; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1599 | if (DO_BIC(BIC_GFX_c0)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1600 | average.packages.pkg_any_gfxe_c0 /= topo.num_packages; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1601 | if (DO_BIC(BIC_CPUGFX)) |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1602 | average.packages.pkg_both_core_gfxe_c0 /= topo.num_packages; |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1603 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1604 | average.packages.pc2 /= topo.num_packages; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1605 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1606 | average.packages.pc3 /= topo.num_packages; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1607 | if (DO_BIC(BIC_Pkgpc6)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1608 | average.packages.pc6 /= topo.num_packages; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1609 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 1610 | average.packages.pc7 /= topo.num_packages; |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1611 | |
| 1612 | average.packages.pc8 /= topo.num_packages; |
| 1613 | average.packages.pc9 /= topo.num_packages; |
| 1614 | average.packages.pc10 /= topo.num_packages; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1615 | |
| 1616 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
| 1617 | if (mp->format == FORMAT_RAW) |
| 1618 | continue; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1619 | if (mp->type == COUNTER_ITEMS) { |
| 1620 | if (average.threads.counter[i] > 9999999) |
| 1621 | sums_need_wide_columns = 1; |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 1622 | continue; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1623 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1624 | average.threads.counter[i] /= topo.num_cpus; |
| 1625 | } |
| 1626 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
| 1627 | if (mp->format == FORMAT_RAW) |
| 1628 | continue; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1629 | if (mp->type == COUNTER_ITEMS) { |
| 1630 | if (average.cores.counter[i] > 9999999) |
| 1631 | sums_need_wide_columns = 1; |
| 1632 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1633 | average.cores.counter[i] /= topo.num_cores; |
| 1634 | } |
| 1635 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
| 1636 | if (mp->format == FORMAT_RAW) |
| 1637 | continue; |
Len Brown | 0de6c0d | 2017-02-15 21:45:40 -0500 | [diff] [blame] | 1638 | if (mp->type == COUNTER_ITEMS) { |
| 1639 | if (average.packages.counter[i] > 9999999) |
| 1640 | sums_need_wide_columns = 1; |
| 1641 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1642 | average.packages.counter[i] /= topo.num_packages; |
| 1643 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1644 | } |
| 1645 | |
| 1646 | static unsigned long long rdtsc(void) |
| 1647 | { |
| 1648 | unsigned int low, high; |
| 1649 | |
| 1650 | asm volatile("rdtsc" : "=a" (low), "=d" (high)); |
| 1651 | |
| 1652 | return low | ((unsigned long long)high) << 32; |
| 1653 | } |
| 1654 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1655 | /* |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1656 | * Open a file, and exit on failure |
| 1657 | */ |
| 1658 | FILE *fopen_or_die(const char *path, const char *mode) |
| 1659 | { |
| 1660 | FILE *filep = fopen(path, mode); |
| 1661 | |
| 1662 | if (!filep) |
| 1663 | err(1, "%s: open failed", path); |
| 1664 | return filep; |
| 1665 | } |
| 1666 | /* |
| 1667 | * snapshot_sysfs_counter() |
| 1668 | * |
| 1669 | * return snapshot of given counter |
| 1670 | */ |
| 1671 | unsigned long long snapshot_sysfs_counter(char *path) |
| 1672 | { |
| 1673 | FILE *fp; |
| 1674 | int retval; |
| 1675 | unsigned long long counter; |
| 1676 | |
| 1677 | fp = fopen_or_die(path, "r"); |
| 1678 | |
| 1679 | retval = fscanf(fp, "%lld", &counter); |
| 1680 | if (retval != 1) |
| 1681 | err(1, "snapshot_sysfs_counter(%s)", path); |
| 1682 | |
| 1683 | fclose(fp); |
| 1684 | |
| 1685 | return counter; |
| 1686 | } |
| 1687 | |
| 1688 | int get_mp(int cpu, struct msr_counter *mp, unsigned long long *counterp) |
| 1689 | { |
| 1690 | if (mp->msr_num != 0) { |
| 1691 | if (get_msr(cpu, mp->msr_num, counterp)) |
| 1692 | return -1; |
| 1693 | } else { |
Len Brown | 46c2797 | 2017-12-08 17:38:17 -0500 | [diff] [blame] | 1694 | char path[128 + PATH_BYTES]; |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 1695 | |
| 1696 | if (mp->flags & SYSFS_PERCPU) { |
| 1697 | sprintf(path, "/sys/devices/system/cpu/cpu%d/%s", |
| 1698 | cpu, mp->path); |
| 1699 | |
| 1700 | *counterp = snapshot_sysfs_counter(path); |
| 1701 | } else { |
| 1702 | *counterp = snapshot_sysfs_counter(mp->path); |
| 1703 | } |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | return 0; |
| 1707 | } |
| 1708 | |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 1709 | void get_apic_id(struct thread_data *t) |
| 1710 | { |
Len Brown | 3404155 | 2018-08-07 20:22:28 -0400 | [diff] [blame] | 1711 | unsigned int eax, ebx, ecx, edx; |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 1712 | |
Len Brown | 3404155 | 2018-08-07 20:22:28 -0400 | [diff] [blame] | 1713 | if (DO_BIC(BIC_APIC)) { |
| 1714 | eax = ebx = ecx = edx = 0; |
| 1715 | __cpuid(1, eax, ebx, ecx, edx); |
| 1716 | |
| 1717 | t->apic_id = (ebx >> 24) & 0xff; |
| 1718 | } |
| 1719 | |
| 1720 | if (!DO_BIC(BIC_X2APIC)) |
| 1721 | return; |
| 1722 | |
| 1723 | if (authentic_amd) { |
| 1724 | unsigned int topology_extensions; |
| 1725 | |
| 1726 | if (max_extended_level < 0x8000001e) |
| 1727 | return; |
| 1728 | |
| 1729 | eax = ebx = ecx = edx = 0; |
| 1730 | __cpuid(0x80000001, eax, ebx, ecx, edx); |
| 1731 | topology_extensions = ecx & (1 << 22); |
| 1732 | |
| 1733 | if (topology_extensions == 0) |
| 1734 | return; |
| 1735 | |
| 1736 | eax = ebx = ecx = edx = 0; |
| 1737 | __cpuid(0x8000001e, eax, ebx, ecx, edx); |
| 1738 | |
| 1739 | t->x2apic_id = eax; |
| 1740 | return; |
| 1741 | } |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 1742 | |
| 1743 | if (!genuine_intel) |
| 1744 | return; |
| 1745 | |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 1746 | if (max_level < 0xb) |
| 1747 | return; |
| 1748 | |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 1749 | ecx = 0; |
| 1750 | __cpuid(0xb, eax, ebx, ecx, edx); |
| 1751 | t->x2apic_id = edx; |
| 1752 | |
Len Brown | 3404155 | 2018-08-07 20:22:28 -0400 | [diff] [blame] | 1753 | if (debug && (t->apic_id != (t->x2apic_id & 0xff))) |
| 1754 | fprintf(outf, "cpu%d: BIOS BUG: apic 0x%x x2apic 0x%x\n", |
| 1755 | t->cpu_id, t->apic_id, t->x2apic_id); |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 1756 | } |
| 1757 | |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1758 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1759 | * get_counters(...) |
| 1760 | * migrate to cpu |
| 1761 | * acquire and record local counters for that cpu |
| 1762 | */ |
| 1763 | int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 1764 | { |
| 1765 | int cpu = t->cpu_id; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1766 | unsigned long long msr; |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1767 | int aperf_mperf_retry_count = 0; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1768 | struct msr_counter *mp; |
| 1769 | int i; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1770 | |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 1771 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 1772 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1773 | return -1; |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 1774 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1775 | |
Yazen Ghannam | d4794f2 | 2019-03-25 17:32:42 +0000 | [diff] [blame] | 1776 | gettimeofday(&t->tv_begin, (struct timezone *)NULL); |
| 1777 | |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 1778 | if (first_counter_read) |
| 1779 | get_apic_id(t); |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1780 | retry: |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1781 | t->tsc = rdtsc(); /* we are running on local CPU of interest */ |
| 1782 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1783 | if (DO_BIC(BIC_Avg_MHz) || DO_BIC(BIC_Busy) || DO_BIC(BIC_Bzy_MHz)) { |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1784 | unsigned long long tsc_before, tsc_between, tsc_after, aperf_time, mperf_time; |
| 1785 | |
| 1786 | /* |
| 1787 | * The TSC, APERF and MPERF must be read together for |
| 1788 | * APERF/MPERF and MPERF/TSC to give accurate results. |
| 1789 | * |
| 1790 | * Unfortunately, APERF and MPERF are read by |
| 1791 | * individual system call, so delays may occur |
| 1792 | * between them. If the time to read them |
| 1793 | * varies by a large amount, we re-read them. |
| 1794 | */ |
| 1795 | |
| 1796 | /* |
| 1797 | * This initial dummy APERF read has been seen to |
| 1798 | * reduce jitter in the subsequent reads. |
| 1799 | */ |
| 1800 | |
Len Brown | 9c63a65 | 2012-10-31 01:29:52 -0400 | [diff] [blame] | 1801 | if (get_msr(cpu, MSR_IA32_APERF, &t->aperf)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1802 | return -3; |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1803 | |
| 1804 | t->tsc = rdtsc(); /* re-read close to APERF */ |
| 1805 | |
| 1806 | tsc_before = t->tsc; |
| 1807 | |
| 1808 | if (get_msr(cpu, MSR_IA32_APERF, &t->aperf)) |
| 1809 | return -3; |
| 1810 | |
| 1811 | tsc_between = rdtsc(); |
| 1812 | |
Len Brown | 9c63a65 | 2012-10-31 01:29:52 -0400 | [diff] [blame] | 1813 | if (get_msr(cpu, MSR_IA32_MPERF, &t->mperf)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1814 | return -4; |
Len Brown | 0102b06 | 2016-02-27 03:11:29 -0500 | [diff] [blame] | 1815 | |
| 1816 | tsc_after = rdtsc(); |
| 1817 | |
| 1818 | aperf_time = tsc_between - tsc_before; |
| 1819 | mperf_time = tsc_after - tsc_between; |
| 1820 | |
| 1821 | /* |
| 1822 | * If the system call latency to read APERF and MPERF |
| 1823 | * differ by more than 2x, then try again. |
| 1824 | */ |
| 1825 | if ((aperf_time > (2 * mperf_time)) || (mperf_time > (2 * aperf_time))) { |
| 1826 | aperf_mperf_retry_count++; |
| 1827 | if (aperf_mperf_retry_count < 5) |
| 1828 | goto retry; |
| 1829 | else |
| 1830 | warnx("cpu%d jitter %lld %lld", |
| 1831 | cpu, aperf_time, mperf_time); |
| 1832 | } |
| 1833 | aperf_mperf_retry_count = 0; |
| 1834 | |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 1835 | t->aperf = t->aperf * aperf_mperf_multiplier; |
| 1836 | t->mperf = t->mperf * aperf_mperf_multiplier; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1837 | } |
| 1838 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1839 | if (DO_BIC(BIC_IRQ)) |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 1840 | t->irq_count = irqs_per_cpu[cpu]; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1841 | if (DO_BIC(BIC_SMI)) { |
Len Brown | 1ed5101 | 2013-02-10 17:19:24 -0500 | [diff] [blame] | 1842 | if (get_msr(cpu, MSR_SMI_COUNT, &msr)) |
| 1843 | return -5; |
| 1844 | t->smi_count = msr & 0xFFFFFFFF; |
| 1845 | } |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1846 | if (DO_BIC(BIC_CPU_c1) && use_c1_residency_msr) { |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1847 | if (get_msr(cpu, MSR_CORE_C1_RES, &t->c1)) |
| 1848 | return -6; |
| 1849 | } |
| 1850 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1851 | for (i = 0, mp = sys.tp; mp; i++, mp = mp->next) { |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1852 | if (get_mp(cpu, mp, &t->counter[i])) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1853 | return -10; |
| 1854 | } |
| 1855 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1856 | /* collect core counters only for 1st thread in core */ |
| 1857 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 1858 | goto done; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1859 | |
Len Brown | 562855e | 2019-03-19 17:52:32 -0400 | [diff] [blame] | 1860 | if (DO_BIC(BIC_CPU_c3)) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1861 | if (get_msr(cpu, MSR_CORE_C3_RESIDENCY, &c->c3)) |
| 1862 | return -6; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 1863 | } |
| 1864 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1865 | if (DO_BIC(BIC_CPU_c6) && !do_knl_cstates) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1866 | if (get_msr(cpu, MSR_CORE_C6_RESIDENCY, &c->c6)) |
| 1867 | return -7; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 1868 | } else if (do_knl_cstates) { |
| 1869 | if (get_msr(cpu, MSR_KNL_CORE_C6_RESIDENCY, &c->c6)) |
| 1870 | return -7; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1871 | } |
| 1872 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1873 | if (DO_BIC(BIC_CPU_c7)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1874 | if (get_msr(cpu, MSR_CORE_C7_RESIDENCY, &c->c7)) |
| 1875 | return -8; |
| 1876 | |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1877 | if (DO_BIC(BIC_Mod_c6)) |
| 1878 | if (get_msr(cpu, MSR_MODULE_C6_RES_MS, &c->mc6_us)) |
| 1879 | return -8; |
| 1880 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1881 | if (DO_BIC(BIC_CoreTmp)) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1882 | if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr)) |
| 1883 | return -9; |
| 1884 | c->core_temp_c = tcc_activation_temp - ((msr >> 16) & 0x7F); |
| 1885 | } |
| 1886 | |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 1887 | if (do_rapl & RAPL_AMD_F17H) { |
| 1888 | if (get_msr(cpu, MSR_CORE_ENERGY_STAT, &msr)) |
| 1889 | return -14; |
| 1890 | c->core_energy = msr & 0xFFFFFFFF; |
| 1891 | } |
| 1892 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1893 | for (i = 0, mp = sys.cp; mp; i++, mp = mp->next) { |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 1894 | if (get_mp(cpu, mp, &c->counter[i])) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1895 | return -10; |
| 1896 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1897 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1898 | /* collect package counters only for 1st core in package */ |
| 1899 | if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 1900 | goto done; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1901 | |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1902 | if (DO_BIC(BIC_Totl_c0)) { |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1903 | if (get_msr(cpu, MSR_PKG_WEIGHTED_CORE_C0_RES, &p->pkg_wtd_core_c0)) |
| 1904 | return -10; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1905 | } |
| 1906 | if (DO_BIC(BIC_Any_c0)) { |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1907 | if (get_msr(cpu, MSR_PKG_ANY_CORE_C0_RES, &p->pkg_any_core_c0)) |
| 1908 | return -11; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1909 | } |
| 1910 | if (DO_BIC(BIC_GFX_c0)) { |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1911 | if (get_msr(cpu, MSR_PKG_ANY_GFXE_C0_RES, &p->pkg_any_gfxe_c0)) |
| 1912 | return -12; |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 1913 | } |
| 1914 | if (DO_BIC(BIC_CPUGFX)) { |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 1915 | if (get_msr(cpu, MSR_PKG_BOTH_CORE_GFXE_C0_RES, &p->pkg_both_core_gfxe_c0)) |
| 1916 | return -13; |
| 1917 | } |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1918 | if (DO_BIC(BIC_Pkgpc3)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1919 | if (get_msr(cpu, MSR_PKG_C3_RESIDENCY, &p->pc3)) |
| 1920 | return -9; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1921 | if (DO_BIC(BIC_Pkgpc6)) { |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 1922 | if (do_slm_cstates) { |
| 1923 | if (get_msr(cpu, MSR_ATOM_PKG_C6_RESIDENCY, &p->pc6)) |
| 1924 | return -10; |
| 1925 | } else { |
| 1926 | if (get_msr(cpu, MSR_PKG_C6_RESIDENCY, &p->pc6)) |
| 1927 | return -10; |
| 1928 | } |
| 1929 | } |
| 1930 | |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1931 | if (DO_BIC(BIC_Pkgpc2)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1932 | if (get_msr(cpu, MSR_PKG_C2_RESIDENCY, &p->pc2)) |
| 1933 | return -11; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1934 | if (DO_BIC(BIC_Pkgpc7)) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 1935 | if (get_msr(cpu, MSR_PKG_C7_RESIDENCY, &p->pc7)) |
| 1936 | return -12; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1937 | if (DO_BIC(BIC_Pkgpc8)) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1938 | if (get_msr(cpu, MSR_PKG_C8_RESIDENCY, &p->pc8)) |
| 1939 | return -13; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1940 | if (DO_BIC(BIC_Pkgpc9)) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1941 | if (get_msr(cpu, MSR_PKG_C9_RESIDENCY, &p->pc9)) |
| 1942 | return -13; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1943 | if (DO_BIC(BIC_Pkgpc10)) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 1944 | if (get_msr(cpu, MSR_PKG_C10_RESIDENCY, &p->pc10)) |
| 1945 | return -13; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 1946 | |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 1947 | if (DO_BIC(BIC_CPU_LPI)) |
| 1948 | p->cpu_lpi = cpuidle_cur_cpu_lpi_us; |
| 1949 | if (DO_BIC(BIC_SYS_LPI)) |
| 1950 | p->sys_lpi = cpuidle_cur_sys_lpi_us; |
| 1951 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1952 | if (do_rapl & RAPL_PKG) { |
| 1953 | if (get_msr(cpu, MSR_PKG_ENERGY_STATUS, &msr)) |
| 1954 | return -13; |
| 1955 | p->energy_pkg = msr & 0xFFFFFFFF; |
| 1956 | } |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 1957 | if (do_rapl & RAPL_CORES_ENERGY_STATUS) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1958 | if (get_msr(cpu, MSR_PP0_ENERGY_STATUS, &msr)) |
| 1959 | return -14; |
| 1960 | p->energy_cores = msr & 0xFFFFFFFF; |
| 1961 | } |
| 1962 | if (do_rapl & RAPL_DRAM) { |
| 1963 | if (get_msr(cpu, MSR_DRAM_ENERGY_STATUS, &msr)) |
| 1964 | return -15; |
| 1965 | p->energy_dram = msr & 0xFFFFFFFF; |
| 1966 | } |
| 1967 | if (do_rapl & RAPL_GFX) { |
| 1968 | if (get_msr(cpu, MSR_PP1_ENERGY_STATUS, &msr)) |
| 1969 | return -16; |
| 1970 | p->energy_gfx = msr & 0xFFFFFFFF; |
| 1971 | } |
| 1972 | if (do_rapl & RAPL_PKG_PERF_STATUS) { |
| 1973 | if (get_msr(cpu, MSR_PKG_PERF_STATUS, &msr)) |
| 1974 | return -16; |
| 1975 | p->rapl_pkg_perf_status = msr & 0xFFFFFFFF; |
| 1976 | } |
| 1977 | if (do_rapl & RAPL_DRAM_PERF_STATUS) { |
| 1978 | if (get_msr(cpu, MSR_DRAM_PERF_STATUS, &msr)) |
| 1979 | return -16; |
| 1980 | p->rapl_dram_perf_status = msr & 0xFFFFFFFF; |
| 1981 | } |
Calvin Walton | 3316f99 | 2018-08-17 12:34:42 -0400 | [diff] [blame] | 1982 | if (do_rapl & RAPL_AMD_F17H) { |
| 1983 | if (get_msr(cpu, MSR_PKG_ENERGY_STAT, &msr)) |
| 1984 | return -13; |
| 1985 | p->energy_pkg = msr & 0xFFFFFFFF; |
| 1986 | } |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1987 | if (DO_BIC(BIC_PkgTmp)) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 1988 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr)) |
| 1989 | return -17; |
| 1990 | p->pkg_temp_c = tcc_activation_temp - ((msr >> 16) & 0x7F); |
| 1991 | } |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1992 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1993 | if (DO_BIC(BIC_GFX_rc6)) |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 1994 | p->gfx_rc6_ms = gfx_cur_rc6_ms; |
| 1995 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 1996 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 1997 | p->gfx_mhz = gfx_cur_mhz; |
| 1998 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 1999 | for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) { |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 2000 | if (get_mp(cpu, mp, &p->counter[i])) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 2001 | return -10; |
| 2002 | } |
Len Brown | f4fdf2b | 2017-05-27 21:06:55 -0700 | [diff] [blame] | 2003 | done: |
| 2004 | gettimeofday(&t->tv_end, (struct timezone *)NULL); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 2005 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2006 | return 0; |
| 2007 | } |
| 2008 | |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2009 | /* |
| 2010 | * MSR_PKG_CST_CONFIG_CONTROL decoding for pkg_cstate_limit: |
| 2011 | * If you change the values, note they are used both in comparisons |
| 2012 | * (>= PCL__7) and to index pkg_cstate_limit_strings[]. |
| 2013 | */ |
| 2014 | |
| 2015 | #define PCLUKN 0 /* Unknown */ |
| 2016 | #define PCLRSV 1 /* Reserved */ |
| 2017 | #define PCL__0 2 /* PC0 */ |
| 2018 | #define PCL__1 3 /* PC1 */ |
| 2019 | #define PCL__2 4 /* PC2 */ |
| 2020 | #define PCL__3 5 /* PC3 */ |
| 2021 | #define PCL__4 6 /* PC4 */ |
| 2022 | #define PCL__6 7 /* PC6 */ |
| 2023 | #define PCL_6N 8 /* PC6 No Retention */ |
| 2024 | #define PCL_6R 9 /* PC6 Retention */ |
| 2025 | #define PCL__7 10 /* PC7 */ |
| 2026 | #define PCL_7S 11 /* PC7 Shrink */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 2027 | #define PCL__8 12 /* PC8 */ |
| 2028 | #define PCL__9 13 /* PC9 */ |
Len Brown | 445640a | 2018-12-14 20:02:27 -0500 | [diff] [blame] | 2029 | #define PCL_10 14 /* PC10 */ |
| 2030 | #define PCLUNL 15 /* Unlimited */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2031 | |
| 2032 | int pkg_cstate_limit = PCLUKN; |
| 2033 | char *pkg_cstate_limit_strings[] = { "reserved", "unknown", "pc0", "pc1", "pc2", |
Len Brown | 445640a | 2018-12-14 20:02:27 -0500 | [diff] [blame] | 2034 | "pc3", "pc4", "pc6", "pc6n", "pc6r", "pc7", "pc7s", "pc8", "pc9", "pc10", "unlimited"}; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2035 | |
Len Brown | e9257f5 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 2036 | int nhm_pkg_cstate_limits[16] = {PCL__0, PCL__1, PCL__3, PCL__6, PCL__7, PCLRSV, PCLRSV, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; |
| 2037 | int snb_pkg_cstate_limits[16] = {PCL__0, PCL__2, PCL_6N, PCL_6R, PCL__7, PCL_7S, PCLRSV, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; |
| 2038 | int hsw_pkg_cstate_limits[16] = {PCL__0, PCL__2, PCL__3, PCL__6, PCL__7, PCL_7S, PCL__8, PCL__9, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 2039 | int slv_pkg_cstate_limits[16] = {PCL__0, PCL__1, PCLRSV, PCLRSV, PCL__4, PCLRSV, PCL__6, PCL__7, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCL__6, PCL__7}; |
Len Brown | f264288 | 2017-01-07 23:13:15 -0500 | [diff] [blame] | 2040 | int amt_pkg_cstate_limits[16] = {PCLUNL, PCL__1, PCL__2, PCLRSV, PCLRSV, PCLRSV, PCL__6, PCL__7, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; |
Len Brown | e9257f5 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 2041 | int phi_pkg_cstate_limits[16] = {PCL__0, PCL__2, PCL_6N, PCL_6R, PCLRSV, PCLRSV, PCLRSV, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; |
Len Brown | 445640a | 2018-12-14 20:02:27 -0500 | [diff] [blame] | 2042 | int glm_pkg_cstate_limits[16] = {PCLUNL, PCL__1, PCL__3, PCL__6, PCL__7, PCL_7S, PCL__8, PCL__9, PCL_10, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; |
Artem Bityutskiy | 2085e12 | 2017-08-04 18:42:23 +0300 | [diff] [blame] | 2043 | int skx_pkg_cstate_limits[16] = {PCL__0, PCL__2, PCL_6N, PCL_6R, PCLRSV, PCLRSV, PCLRSV, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 2044 | |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 2045 | |
| 2046 | static void |
| 2047 | calculate_tsc_tweak() |
| 2048 | { |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 2049 | tsc_tweak = base_hz / tsc_hz; |
| 2050 | } |
| 2051 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2052 | static void |
| 2053 | dump_nhm_platform_info(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2054 | { |
| 2055 | unsigned long long msr; |
| 2056 | unsigned int ratio; |
| 2057 | |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 2058 | get_msr(base_cpu, MSR_PLATFORM_INFO, &msr); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2059 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2060 | fprintf(outf, "cpu%d: MSR_PLATFORM_INFO: 0x%08llx\n", base_cpu, msr); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2061 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2062 | ratio = (msr >> 40) & 0xFF; |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 2063 | fprintf(outf, "%d * %.1f = %.1f MHz max efficiency frequency\n", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2064 | ratio, bclk, ratio * bclk); |
| 2065 | |
| 2066 | ratio = (msr >> 8) & 0xFF; |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 2067 | fprintf(outf, "%d * %.1f = %.1f MHz base frequency\n", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2068 | ratio, bclk, ratio * bclk); |
| 2069 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2070 | get_msr(base_cpu, MSR_IA32_POWER_CTL, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2071 | fprintf(outf, "cpu%d: MSR_IA32_POWER_CTL: 0x%08llx (C1E auto-promotion: %sabled)\n", |
Len Brown | bfae205 | 2015-06-17 12:27:21 -0400 | [diff] [blame] | 2072 | base_cpu, msr, msr & 0x2 ? "EN" : "DIS"); |
Len Brown | 6792041 | 2013-01-31 15:22:15 -0500 | [diff] [blame] | 2073 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2074 | return; |
| 2075 | } |
| 2076 | |
| 2077 | static void |
| 2078 | dump_hsw_turbo_ratio_limits(void) |
| 2079 | { |
| 2080 | unsigned long long msr; |
| 2081 | unsigned int ratio; |
| 2082 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2083 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT2, &msr); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2084 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2085 | fprintf(outf, "cpu%d: MSR_TURBO_RATIO_LIMIT2: 0x%08llx\n", base_cpu, msr); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2086 | |
| 2087 | ratio = (msr >> 8) & 0xFF; |
| 2088 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 2089 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 18 active cores\n", |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2090 | ratio, bclk, ratio * bclk); |
| 2091 | |
| 2092 | ratio = (msr >> 0) & 0xFF; |
| 2093 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 2094 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 17 active cores\n", |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2095 | ratio, bclk, ratio * bclk); |
| 2096 | return; |
| 2097 | } |
| 2098 | |
| 2099 | static void |
| 2100 | dump_ivt_turbo_ratio_limits(void) |
| 2101 | { |
| 2102 | unsigned long long msr; |
| 2103 | unsigned int ratio; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2104 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2105 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT1, &msr); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2106 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2107 | fprintf(outf, "cpu%d: MSR_TURBO_RATIO_LIMIT1: 0x%08llx\n", base_cpu, msr); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2108 | |
| 2109 | ratio = (msr >> 56) & 0xFF; |
| 2110 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 2111 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 16 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2112 | ratio, bclk, ratio * bclk); |
| 2113 | |
| 2114 | ratio = (msr >> 48) & 0xFF; |
| 2115 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 2116 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 15 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2117 | ratio, bclk, ratio * bclk); |
| 2118 | |
| 2119 | ratio = (msr >> 40) & 0xFF; |
| 2120 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 2121 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 14 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2122 | ratio, bclk, ratio * bclk); |
| 2123 | |
| 2124 | ratio = (msr >> 32) & 0xFF; |
| 2125 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 2126 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 13 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2127 | ratio, bclk, ratio * bclk); |
| 2128 | |
| 2129 | ratio = (msr >> 24) & 0xFF; |
| 2130 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 2131 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 12 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2132 | ratio, bclk, ratio * bclk); |
| 2133 | |
| 2134 | ratio = (msr >> 16) & 0xFF; |
| 2135 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 2136 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 11 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2137 | ratio, bclk, ratio * bclk); |
| 2138 | |
| 2139 | ratio = (msr >> 8) & 0xFF; |
| 2140 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 2141 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 10 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2142 | ratio, bclk, ratio * bclk); |
| 2143 | |
| 2144 | ratio = (msr >> 0) & 0xFF; |
| 2145 | if (ratio) |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 2146 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 9 active cores\n", |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2147 | ratio, bclk, ratio * bclk); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2148 | return; |
| 2149 | } |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2150 | int has_turbo_ratio_group_limits(int family, int model) |
| 2151 | { |
| 2152 | |
| 2153 | if (!genuine_intel) |
| 2154 | return 0; |
| 2155 | |
| 2156 | switch (model) { |
| 2157 | case INTEL_FAM6_ATOM_GOLDMONT: |
| 2158 | case INTEL_FAM6_SKYLAKE_X: |
Peter Zijlstra | f2c4db1 | 2018-08-07 10:17:27 -0700 | [diff] [blame] | 2159 | case INTEL_FAM6_ATOM_GOLDMONT_X: |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2160 | return 1; |
| 2161 | } |
| 2162 | return 0; |
| 2163 | } |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2164 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2165 | static void |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2166 | dump_turbo_ratio_limits(int family, int model) |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2167 | { |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2168 | unsigned long long msr, core_counts; |
| 2169 | unsigned int ratio, group_size; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2170 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 2171 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2172 | fprintf(outf, "cpu%d: MSR_TURBO_RATIO_LIMIT: 0x%08llx\n", base_cpu, msr); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2173 | |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2174 | if (has_turbo_ratio_group_limits(family, model)) { |
| 2175 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT1, &core_counts); |
| 2176 | fprintf(outf, "cpu%d: MSR_TURBO_RATIO_LIMIT1: 0x%08llx\n", base_cpu, core_counts); |
| 2177 | } else { |
| 2178 | core_counts = 0x0807060504030201; |
| 2179 | } |
| 2180 | |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2181 | ratio = (msr >> 56) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2182 | group_size = (core_counts >> 56) & 0xFF; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2183 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2184 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2185 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2186 | |
| 2187 | ratio = (msr >> 48) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2188 | group_size = (core_counts >> 48) & 0xFF; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2189 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2190 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2191 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2192 | |
| 2193 | ratio = (msr >> 40) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2194 | group_size = (core_counts >> 40) & 0xFF; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2195 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2196 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2197 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2198 | |
| 2199 | ratio = (msr >> 32) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2200 | group_size = (core_counts >> 32) & 0xFF; |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2201 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2202 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2203 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 2204 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2205 | ratio = (msr >> 24) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2206 | group_size = (core_counts >> 24) & 0xFF; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2207 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2208 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2209 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2210 | |
| 2211 | ratio = (msr >> 16) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2212 | group_size = (core_counts >> 16) & 0xFF; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2213 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2214 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2215 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2216 | |
| 2217 | ratio = (msr >> 8) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2218 | group_size = (core_counts >> 8) & 0xFF; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2219 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2220 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2221 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2222 | |
| 2223 | ratio = (msr >> 0) & 0xFF; |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2224 | group_size = (core_counts >> 0) & 0xFF; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2225 | if (ratio) |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 2226 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
| 2227 | ratio, bclk, ratio * bclk, group_size); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2228 | return; |
| 2229 | } |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 2230 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2231 | static void |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 2232 | dump_atom_turbo_ratio_limits(void) |
| 2233 | { |
| 2234 | unsigned long long msr; |
| 2235 | unsigned int ratio; |
| 2236 | |
| 2237 | get_msr(base_cpu, MSR_ATOM_CORE_RATIOS, &msr); |
| 2238 | fprintf(outf, "cpu%d: MSR_ATOM_CORE_RATIOS: 0x%08llx\n", base_cpu, msr & 0xFFFFFFFF); |
| 2239 | |
| 2240 | ratio = (msr >> 0) & 0x3F; |
| 2241 | if (ratio) |
| 2242 | fprintf(outf, "%d * %.1f = %.1f MHz minimum operating frequency\n", |
| 2243 | ratio, bclk, ratio * bclk); |
| 2244 | |
| 2245 | ratio = (msr >> 8) & 0x3F; |
| 2246 | if (ratio) |
| 2247 | fprintf(outf, "%d * %.1f = %.1f MHz low frequency mode (LFM)\n", |
| 2248 | ratio, bclk, ratio * bclk); |
| 2249 | |
| 2250 | ratio = (msr >> 16) & 0x3F; |
| 2251 | if (ratio) |
| 2252 | fprintf(outf, "%d * %.1f = %.1f MHz base frequency\n", |
| 2253 | ratio, bclk, ratio * bclk); |
| 2254 | |
| 2255 | get_msr(base_cpu, MSR_ATOM_CORE_TURBO_RATIOS, &msr); |
| 2256 | fprintf(outf, "cpu%d: MSR_ATOM_CORE_TURBO_RATIOS: 0x%08llx\n", base_cpu, msr & 0xFFFFFFFF); |
| 2257 | |
| 2258 | ratio = (msr >> 24) & 0x3F; |
| 2259 | if (ratio) |
| 2260 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 4 active cores\n", |
| 2261 | ratio, bclk, ratio * bclk); |
| 2262 | |
| 2263 | ratio = (msr >> 16) & 0x3F; |
| 2264 | if (ratio) |
| 2265 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 3 active cores\n", |
| 2266 | ratio, bclk, ratio * bclk); |
| 2267 | |
| 2268 | ratio = (msr >> 8) & 0x3F; |
| 2269 | if (ratio) |
| 2270 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 2 active cores\n", |
| 2271 | ratio, bclk, ratio * bclk); |
| 2272 | |
| 2273 | ratio = (msr >> 0) & 0x3F; |
| 2274 | if (ratio) |
| 2275 | fprintf(outf, "%d * %.1f = %.1f MHz max turbo 1 active core\n", |
| 2276 | ratio, bclk, ratio * bclk); |
| 2277 | } |
| 2278 | |
| 2279 | static void |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2280 | dump_knl_turbo_ratio_limits(void) |
| 2281 | { |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2282 | const unsigned int buckets_no = 7; |
| 2283 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2284 | unsigned long long msr; |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2285 | int delta_cores, delta_ratio; |
| 2286 | int i, b_nr; |
| 2287 | unsigned int cores[buckets_no]; |
| 2288 | unsigned int ratio[buckets_no]; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2289 | |
Srinivas Pandruvada | ebf5926 | 2016-07-06 16:07:56 -0700 | [diff] [blame] | 2290 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT, &msr); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2291 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2292 | fprintf(outf, "cpu%d: MSR_TURBO_RATIO_LIMIT: 0x%08llx\n", |
Len Brown | bfae205 | 2015-06-17 12:27:21 -0400 | [diff] [blame] | 2293 | base_cpu, msr); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2294 | |
| 2295 | /** |
| 2296 | * Turbo encoding in KNL is as follows: |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2297 | * [0] -- Reserved |
| 2298 | * [7:1] -- Base value of number of active cores of bucket 1. |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2299 | * [15:8] -- Base value of freq ratio of bucket 1. |
| 2300 | * [20:16] -- +ve delta of number of active cores of bucket 2. |
| 2301 | * i.e. active cores of bucket 2 = |
| 2302 | * active cores of bucket 1 + delta |
| 2303 | * [23:21] -- Negative delta of freq ratio of bucket 2. |
| 2304 | * i.e. freq ratio of bucket 2 = |
| 2305 | * freq ratio of bucket 1 - delta |
| 2306 | * [28:24]-- +ve delta of number of active cores of bucket 3. |
| 2307 | * [31:29]-- -ve delta of freq ratio of bucket 3. |
| 2308 | * [36:32]-- +ve delta of number of active cores of bucket 4. |
| 2309 | * [39:37]-- -ve delta of freq ratio of bucket 4. |
| 2310 | * [44:40]-- +ve delta of number of active cores of bucket 5. |
| 2311 | * [47:45]-- -ve delta of freq ratio of bucket 5. |
| 2312 | * [52:48]-- +ve delta of number of active cores of bucket 6. |
| 2313 | * [55:53]-- -ve delta of freq ratio of bucket 6. |
| 2314 | * [60:56]-- +ve delta of number of active cores of bucket 7. |
| 2315 | * [63:61]-- -ve delta of freq ratio of bucket 7. |
| 2316 | */ |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2317 | |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2318 | b_nr = 0; |
| 2319 | cores[b_nr] = (msr & 0xFF) >> 1; |
| 2320 | ratio[b_nr] = (msr >> 8) & 0xFF; |
| 2321 | |
| 2322 | for (i = 16; i < 64; i += 8) { |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2323 | delta_cores = (msr >> i) & 0x1F; |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2324 | delta_ratio = (msr >> (i + 5)) & 0x7; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2325 | |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2326 | cores[b_nr + 1] = cores[b_nr] + delta_cores; |
| 2327 | ratio[b_nr + 1] = ratio[b_nr] - delta_ratio; |
| 2328 | b_nr++; |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2329 | } |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2330 | |
| 2331 | for (i = buckets_no - 1; i >= 0; i--) |
| 2332 | if (i > 0 ? ratio[i] != ratio[i - 1] : 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2333 | fprintf(outf, |
Len Brown | 710f273 | 2017-01-11 22:12:25 -0500 | [diff] [blame] | 2334 | "%d * %.1f = %.1f MHz max turbo %d active cores\n", |
Hubert Chrzaniuk | cbf97ab | 2016-02-10 14:55:22 +0100 | [diff] [blame] | 2335 | ratio[i], bclk, ratio[i] * bclk, cores[i]); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 2336 | } |
| 2337 | |
| 2338 | static void |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2339 | dump_nhm_cst_cfg(void) |
| 2340 | { |
| 2341 | unsigned long long msr; |
| 2342 | |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 2343 | get_msr(base_cpu, MSR_PKG_CST_CONFIG_CONTROL, &msr); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2344 | |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 2345 | fprintf(outf, "cpu%d: MSR_PKG_CST_CONFIG_CONTROL: 0x%08llx", base_cpu, msr); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2346 | |
Artem Bityutskiy | 3e8b62b | 2017-09-05 15:25:42 +0300 | [diff] [blame] | 2347 | fprintf(outf, " (%s%s%s%s%slocked, pkg-cstate-limit=%d (%s)", |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2348 | (msr & SNB_C3_AUTO_UNDEMOTE) ? "UNdemote-C3, " : "", |
| 2349 | (msr & SNB_C1_AUTO_UNDEMOTE) ? "UNdemote-C1, " : "", |
| 2350 | (msr & NHM_C3_AUTO_DEMOTE) ? "demote-C3, " : "", |
| 2351 | (msr & NHM_C1_AUTO_DEMOTE) ? "demote-C1, " : "", |
| 2352 | (msr & (1 << 15)) ? "" : "UN", |
Len Brown | 6c34f16 | 2016-03-13 03:21:22 -0400 | [diff] [blame] | 2353 | (unsigned int)msr & 0xF, |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2354 | pkg_cstate_limit_strings[pkg_cstate_limit]); |
Artem Bityutskiy | ac980e1 | 2017-09-05 15:14:08 +0300 | [diff] [blame] | 2355 | |
| 2356 | #define AUTOMATIC_CSTATE_CONVERSION (1UL << 16) |
| 2357 | if (has_automatic_cstate_conversion) { |
| 2358 | fprintf(outf, ", automatic c-state conversion=%s", |
| 2359 | (msr & AUTOMATIC_CSTATE_CONVERSION) ? "on" : "off"); |
| 2360 | } |
| 2361 | |
| 2362 | fprintf(outf, ")\n"); |
| 2363 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 2364 | return; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2365 | } |
| 2366 | |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2367 | static void |
| 2368 | dump_config_tdp(void) |
| 2369 | { |
| 2370 | unsigned long long msr; |
| 2371 | |
| 2372 | get_msr(base_cpu, MSR_CONFIG_TDP_NOMINAL, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2373 | fprintf(outf, "cpu%d: MSR_CONFIG_TDP_NOMINAL: 0x%08llx", base_cpu, msr); |
Chen Yu | 685b535 | 2015-12-13 21:09:31 +0800 | [diff] [blame] | 2374 | fprintf(outf, " (base_ratio=%d)\n", (unsigned int)msr & 0xFF); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2375 | |
| 2376 | get_msr(base_cpu, MSR_CONFIG_TDP_LEVEL_1, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2377 | fprintf(outf, "cpu%d: MSR_CONFIG_TDP_LEVEL_1: 0x%08llx (", base_cpu, msr); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2378 | if (msr) { |
Chen Yu | 685b535 | 2015-12-13 21:09:31 +0800 | [diff] [blame] | 2379 | fprintf(outf, "PKG_MIN_PWR_LVL1=%d ", (unsigned int)(msr >> 48) & 0x7FFF); |
| 2380 | fprintf(outf, "PKG_MAX_PWR_LVL1=%d ", (unsigned int)(msr >> 32) & 0x7FFF); |
| 2381 | fprintf(outf, "LVL1_RATIO=%d ", (unsigned int)(msr >> 16) & 0xFF); |
| 2382 | fprintf(outf, "PKG_TDP_LVL1=%d", (unsigned int)(msr) & 0x7FFF); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2383 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2384 | fprintf(outf, ")\n"); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2385 | |
| 2386 | get_msr(base_cpu, MSR_CONFIG_TDP_LEVEL_2, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2387 | fprintf(outf, "cpu%d: MSR_CONFIG_TDP_LEVEL_2: 0x%08llx (", base_cpu, msr); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2388 | if (msr) { |
Chen Yu | 685b535 | 2015-12-13 21:09:31 +0800 | [diff] [blame] | 2389 | fprintf(outf, "PKG_MIN_PWR_LVL2=%d ", (unsigned int)(msr >> 48) & 0x7FFF); |
| 2390 | fprintf(outf, "PKG_MAX_PWR_LVL2=%d ", (unsigned int)(msr >> 32) & 0x7FFF); |
| 2391 | fprintf(outf, "LVL2_RATIO=%d ", (unsigned int)(msr >> 16) & 0xFF); |
| 2392 | fprintf(outf, "PKG_TDP_LVL2=%d", (unsigned int)(msr) & 0x7FFF); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2393 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2394 | fprintf(outf, ")\n"); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2395 | |
| 2396 | get_msr(base_cpu, MSR_CONFIG_TDP_CONTROL, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2397 | fprintf(outf, "cpu%d: MSR_CONFIG_TDP_CONTROL: 0x%08llx (", base_cpu, msr); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2398 | if ((msr) & 0x3) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2399 | fprintf(outf, "TDP_LEVEL=%d ", (unsigned int)(msr) & 0x3); |
| 2400 | fprintf(outf, " lock=%d", (unsigned int)(msr >> 31) & 1); |
| 2401 | fprintf(outf, ")\n"); |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2402 | |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2403 | get_msr(base_cpu, MSR_TURBO_ACTIVATION_RATIO, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2404 | fprintf(outf, "cpu%d: MSR_TURBO_ACTIVATION_RATIO: 0x%08llx (", base_cpu, msr); |
Chen Yu | 685b535 | 2015-12-13 21:09:31 +0800 | [diff] [blame] | 2405 | fprintf(outf, "MAX_NON_TURBO_RATIO=%d", (unsigned int)(msr) & 0xFF); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 2406 | fprintf(outf, " lock=%d", (unsigned int)(msr >> 31) & 1); |
| 2407 | fprintf(outf, ")\n"); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2408 | } |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 2409 | |
| 2410 | unsigned int irtl_time_units[] = {1, 32, 1024, 32768, 1048576, 33554432, 0, 0 }; |
| 2411 | |
| 2412 | void print_irtl(void) |
| 2413 | { |
| 2414 | unsigned long long msr; |
| 2415 | |
| 2416 | get_msr(base_cpu, MSR_PKGC3_IRTL, &msr); |
| 2417 | fprintf(outf, "cpu%d: MSR_PKGC3_IRTL: 0x%08llx (", base_cpu, msr); |
| 2418 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2419 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2420 | |
| 2421 | get_msr(base_cpu, MSR_PKGC6_IRTL, &msr); |
| 2422 | fprintf(outf, "cpu%d: MSR_PKGC6_IRTL: 0x%08llx (", base_cpu, msr); |
| 2423 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2424 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2425 | |
| 2426 | get_msr(base_cpu, MSR_PKGC7_IRTL, &msr); |
| 2427 | fprintf(outf, "cpu%d: MSR_PKGC7_IRTL: 0x%08llx (", base_cpu, msr); |
| 2428 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2429 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2430 | |
| 2431 | if (!do_irtl_hsw) |
| 2432 | return; |
| 2433 | |
| 2434 | get_msr(base_cpu, MSR_PKGC8_IRTL, &msr); |
| 2435 | fprintf(outf, "cpu%d: MSR_PKGC8_IRTL: 0x%08llx (", base_cpu, msr); |
| 2436 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2437 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2438 | |
| 2439 | get_msr(base_cpu, MSR_PKGC9_IRTL, &msr); |
| 2440 | fprintf(outf, "cpu%d: MSR_PKGC9_IRTL: 0x%08llx (", base_cpu, msr); |
| 2441 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2442 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2443 | |
| 2444 | get_msr(base_cpu, MSR_PKGC10_IRTL, &msr); |
| 2445 | fprintf(outf, "cpu%d: MSR_PKGC10_IRTL: 0x%08llx (", base_cpu, msr); |
| 2446 | fprintf(outf, "%svalid, %lld ns)\n", msr & (1 << 15) ? "" : "NOT", |
| 2447 | (msr & 0x3FF) * irtl_time_units[(msr >> 10) & 0x3]); |
| 2448 | |
| 2449 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2450 | void free_fd_percpu(void) |
| 2451 | { |
| 2452 | int i; |
| 2453 | |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 2454 | for (i = 0; i < topo.max_cpu_num + 1; ++i) { |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2455 | if (fd_percpu[i] != 0) |
| 2456 | close(fd_percpu[i]); |
| 2457 | } |
| 2458 | |
| 2459 | free(fd_percpu); |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 2460 | } |
| 2461 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2462 | void free_all_buffers(void) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2463 | { |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 2464 | int i; |
| 2465 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2466 | CPU_FREE(cpu_present_set); |
| 2467 | cpu_present_set = NULL; |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2468 | cpu_present_setsize = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2469 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2470 | CPU_FREE(cpu_affinity_set); |
| 2471 | cpu_affinity_set = NULL; |
| 2472 | cpu_affinity_setsize = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2473 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2474 | free(thread_even); |
| 2475 | free(core_even); |
| 2476 | free(package_even); |
| 2477 | |
| 2478 | thread_even = NULL; |
| 2479 | core_even = NULL; |
| 2480 | package_even = NULL; |
| 2481 | |
| 2482 | free(thread_odd); |
| 2483 | free(core_odd); |
| 2484 | free(package_odd); |
| 2485 | |
| 2486 | thread_odd = NULL; |
| 2487 | core_odd = NULL; |
| 2488 | package_odd = NULL; |
| 2489 | |
| 2490 | free(output_buffer); |
| 2491 | output_buffer = NULL; |
| 2492 | outp = NULL; |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 2493 | |
| 2494 | free_fd_percpu(); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2495 | |
| 2496 | free(irq_column_2_cpu); |
| 2497 | free(irqs_per_cpu); |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 2498 | |
| 2499 | for (i = 0; i <= topo.max_cpu_num; ++i) { |
| 2500 | if (cpus[i].put_ids) |
| 2501 | CPU_FREE(cpus[i].put_ids); |
| 2502 | } |
| 2503 | free(cpus); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2504 | } |
| 2505 | |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 2506 | |
| 2507 | /* |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2508 | * Parse a file containing a single int. |
Len Brown | 6de68fe | 2019-02-14 19:17:40 -0800 | [diff] [blame] | 2509 | * Return 0 if file can not be opened |
| 2510 | * Exit if file can be opened, but can not be parsed |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2511 | */ |
| 2512 | int parse_int_file(const char *fmt, ...) |
| 2513 | { |
| 2514 | va_list args; |
| 2515 | char path[PATH_MAX]; |
| 2516 | FILE *filep; |
| 2517 | int value; |
| 2518 | |
| 2519 | va_start(args, fmt); |
| 2520 | vsnprintf(path, sizeof(path), fmt, args); |
| 2521 | va_end(args); |
Len Brown | 6de68fe | 2019-02-14 19:17:40 -0800 | [diff] [blame] | 2522 | filep = fopen(path, "r"); |
| 2523 | if (!filep) |
| 2524 | return 0; |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 2525 | if (fscanf(filep, "%d", &value) != 1) |
| 2526 | err(1, "%s: failed to parse number from file", path); |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2527 | fclose(filep); |
| 2528 | return value; |
| 2529 | } |
| 2530 | |
| 2531 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2532 | * cpu_is_first_core_in_package(cpu) |
| 2533 | * return 1 if given CPU is 1st core in package |
| 2534 | */ |
| 2535 | int cpu_is_first_core_in_package(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2536 | { |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2537 | return cpu == parse_int_file("/sys/devices/system/cpu/cpu%d/topology/core_siblings_list", cpu); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | int get_physical_package_id(int cpu) |
| 2541 | { |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2542 | return parse_int_file("/sys/devices/system/cpu/cpu%d/topology/physical_package_id", cpu); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2543 | } |
| 2544 | |
Len Brown | 6de68fe | 2019-02-14 19:17:40 -0800 | [diff] [blame] | 2545 | int get_die_id(int cpu) |
| 2546 | { |
| 2547 | return parse_int_file("/sys/devices/system/cpu/cpu%d/topology/die_id", cpu); |
| 2548 | } |
| 2549 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2550 | int get_core_id(int cpu) |
| 2551 | { |
Josh Triplett | 95aebc4 | 2013-08-20 17:20:16 -0700 | [diff] [blame] | 2552 | return parse_int_file("/sys/devices/system/cpu/cpu%d/topology/core_id", cpu); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2553 | } |
| 2554 | |
Prarit Bhargava | ef60574 | 2018-06-01 10:04:30 -0400 | [diff] [blame] | 2555 | void set_node_data(void) |
| 2556 | { |
Prarit Bhargava | 2ffbb22 | 2018-07-26 09:08:54 -0400 | [diff] [blame] | 2557 | int pkg, node, lnode, cpu, cpux; |
| 2558 | int cpu_count; |
Prarit Bhargava | ef60574 | 2018-06-01 10:04:30 -0400 | [diff] [blame] | 2559 | |
Prarit Bhargava | 2ffbb22 | 2018-07-26 09:08:54 -0400 | [diff] [blame] | 2560 | /* initialize logical_node_id */ |
| 2561 | for (cpu = 0; cpu <= topo.max_cpu_num; ++cpu) |
| 2562 | cpus[cpu].logical_node_id = -1; |
Prarit Bhargava | ef60574 | 2018-06-01 10:04:30 -0400 | [diff] [blame] | 2563 | |
Prarit Bhargava | 2ffbb22 | 2018-07-26 09:08:54 -0400 | [diff] [blame] | 2564 | cpu_count = 0; |
| 2565 | for (pkg = 0; pkg < topo.num_packages; pkg++) { |
| 2566 | lnode = 0; |
| 2567 | for (cpu = 0; cpu <= topo.max_cpu_num; ++cpu) { |
| 2568 | if (cpus[cpu].physical_package_id != pkg) |
| 2569 | continue; |
| 2570 | /* find a cpu with an unset logical_node_id */ |
| 2571 | if (cpus[cpu].logical_node_id != -1) |
| 2572 | continue; |
| 2573 | cpus[cpu].logical_node_id = lnode; |
| 2574 | node = cpus[cpu].physical_node_id; |
| 2575 | cpu_count++; |
| 2576 | /* |
| 2577 | * find all matching cpus on this pkg and set |
| 2578 | * the logical_node_id |
| 2579 | */ |
| 2580 | for (cpux = cpu; cpux <= topo.max_cpu_num; cpux++) { |
| 2581 | if ((cpus[cpux].physical_package_id == pkg) && |
| 2582 | (cpus[cpux].physical_node_id == node)) { |
| 2583 | cpus[cpux].logical_node_id = lnode; |
| 2584 | cpu_count++; |
| 2585 | } |
| 2586 | } |
| 2587 | lnode++; |
| 2588 | if (lnode > topo.nodes_per_pkg) |
| 2589 | topo.nodes_per_pkg = lnode; |
| 2590 | } |
| 2591 | if (cpu_count >= topo.max_cpu_num) |
| 2592 | break; |
Prarit Bhargava | ef60574 | 2018-06-01 10:04:30 -0400 | [diff] [blame] | 2593 | } |
Prarit Bhargava | ef60574 | 2018-06-01 10:04:30 -0400 | [diff] [blame] | 2594 | } |
| 2595 | |
| 2596 | int get_physical_node_id(struct cpu_topology *thiscpu) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2597 | { |
| 2598 | char path[80]; |
| 2599 | FILE *filep; |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 2600 | int i; |
| 2601 | int cpu = thiscpu->logical_cpu_id; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2602 | |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 2603 | for (i = 0; i <= topo.max_cpu_num; i++) { |
| 2604 | sprintf(path, "/sys/devices/system/cpu/cpu%d/node%i/cpulist", |
| 2605 | cpu, i); |
| 2606 | filep = fopen(path, "r"); |
| 2607 | if (!filep) |
| 2608 | continue; |
| 2609 | fclose(filep); |
| 2610 | return i; |
Dasaratharaman Chandramouli | e275b38 | 2015-04-15 10:09:50 -0700 | [diff] [blame] | 2611 | } |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 2612 | return -1; |
| 2613 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2614 | |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 2615 | int get_thread_siblings(struct cpu_topology *thiscpu) |
| 2616 | { |
| 2617 | char path[80], character; |
| 2618 | FILE *filep; |
| 2619 | unsigned long map; |
Prarit Bhargava | 8cb48b3 | 2018-06-01 10:04:31 -0400 | [diff] [blame] | 2620 | int so, shift, sib_core; |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 2621 | int cpu = thiscpu->logical_cpu_id; |
| 2622 | int offset = topo.max_cpu_num + 1; |
| 2623 | size_t size; |
Prarit Bhargava | 8cb48b3 | 2018-06-01 10:04:31 -0400 | [diff] [blame] | 2624 | int thread_id = 0; |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 2625 | |
| 2626 | thiscpu->put_ids = CPU_ALLOC((topo.max_cpu_num + 1)); |
Prarit Bhargava | 8cb48b3 | 2018-06-01 10:04:31 -0400 | [diff] [blame] | 2627 | if (thiscpu->thread_id < 0) |
| 2628 | thiscpu->thread_id = thread_id++; |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 2629 | if (!thiscpu->put_ids) |
| 2630 | return -1; |
| 2631 | |
| 2632 | size = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); |
| 2633 | CPU_ZERO_S(size, thiscpu->put_ids); |
| 2634 | |
| 2635 | sprintf(path, |
| 2636 | "/sys/devices/system/cpu/cpu%d/topology/thread_siblings", cpu); |
| 2637 | filep = fopen_or_die(path, "r"); |
| 2638 | do { |
| 2639 | offset -= BITMASK_SIZE; |
Ben Hutchings | 8173c33 | 2019-03-20 23:01:03 -0400 | [diff] [blame] | 2640 | if (fscanf(filep, "%lx%c", &map, &character) != 2) |
| 2641 | err(1, "%s: failed to parse file", path); |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 2642 | for (shift = 0; shift < BITMASK_SIZE; shift++) { |
| 2643 | if ((map >> shift) & 0x1) { |
Prarit Bhargava | 8cb48b3 | 2018-06-01 10:04:31 -0400 | [diff] [blame] | 2644 | so = shift + offset; |
| 2645 | sib_core = get_core_id(so); |
| 2646 | if (sib_core == thiscpu->physical_core_id) { |
| 2647 | CPU_SET_S(so, size, thiscpu->put_ids); |
| 2648 | if ((so != cpu) && |
| 2649 | (cpus[so].thread_id < 0)) |
| 2650 | cpus[so].thread_id = |
| 2651 | thread_id++; |
| 2652 | } |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 2653 | } |
| 2654 | } |
| 2655 | } while (!strncmp(&character, ",", 1)); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2656 | fclose(filep); |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 2657 | |
| 2658 | return CPU_COUNT_S(size, thiscpu->put_ids); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2659 | } |
| 2660 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2661 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2662 | * run func(thread, core, package) in topology order |
| 2663 | * skip non-present cpus |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2664 | */ |
| 2665 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2666 | int for_all_cpus_2(int (func)(struct thread_data *, struct core_data *, |
| 2667 | struct pkg_data *, struct thread_data *, struct core_data *, |
| 2668 | struct pkg_data *), struct thread_data *thread_base, |
| 2669 | struct core_data *core_base, struct pkg_data *pkg_base, |
| 2670 | struct thread_data *thread_base2, struct core_data *core_base2, |
| 2671 | struct pkg_data *pkg_base2) |
| 2672 | { |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 2673 | int retval, pkg_no, node_no, core_no, thread_no; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2674 | |
| 2675 | for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 2676 | for (node_no = 0; node_no < topo.nodes_per_pkg; ++node_no) { |
| 2677 | for (core_no = 0; core_no < topo.cores_per_node; |
| 2678 | ++core_no) { |
| 2679 | for (thread_no = 0; thread_no < |
| 2680 | topo.threads_per_core; ++thread_no) { |
| 2681 | struct thread_data *t, *t2; |
| 2682 | struct core_data *c, *c2; |
| 2683 | struct pkg_data *p, *p2; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2684 | |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 2685 | t = GET_THREAD(thread_base, thread_no, |
| 2686 | core_no, node_no, |
| 2687 | pkg_no); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2688 | |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 2689 | if (cpu_is_not_present(t->cpu_id)) |
| 2690 | continue; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2691 | |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 2692 | t2 = GET_THREAD(thread_base2, thread_no, |
| 2693 | core_no, node_no, |
| 2694 | pkg_no); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2695 | |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 2696 | c = GET_CORE(core_base, core_no, |
| 2697 | node_no, pkg_no); |
| 2698 | c2 = GET_CORE(core_base2, core_no, |
| 2699 | node_no, |
| 2700 | pkg_no); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2701 | |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 2702 | p = GET_PKG(pkg_base, pkg_no); |
| 2703 | p2 = GET_PKG(pkg_base2, pkg_no); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2704 | |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 2705 | retval = func(t, c, p, t2, c2, p2); |
| 2706 | if (retval) |
| 2707 | return retval; |
| 2708 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2709 | } |
| 2710 | } |
| 2711 | } |
| 2712 | return 0; |
| 2713 | } |
| 2714 | |
| 2715 | /* |
| 2716 | * run func(cpu) on every cpu in /proc/stat |
| 2717 | * return max_cpu number |
| 2718 | */ |
| 2719 | int for_all_proc_cpus(int (func)(int)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2720 | { |
| 2721 | FILE *fp; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2722 | int cpu_num; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2723 | int retval; |
| 2724 | |
Josh Triplett | 57a42a3 | 2013-08-20 17:20:17 -0700 | [diff] [blame] | 2725 | fp = fopen_or_die(proc_stat, "r"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2726 | |
| 2727 | retval = fscanf(fp, "cpu %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n"); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 2728 | if (retval != 0) |
| 2729 | err(1, "%s: failed to parse format", proc_stat); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2730 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2731 | while (1) { |
| 2732 | 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] | 2733 | if (retval != 1) |
| 2734 | break; |
| 2735 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2736 | retval = func(cpu_num); |
| 2737 | if (retval) { |
| 2738 | fclose(fp); |
| 2739 | return(retval); |
| 2740 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2741 | } |
| 2742 | fclose(fp); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2743 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2744 | } |
| 2745 | |
| 2746 | void re_initialize(void) |
| 2747 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2748 | free_all_buffers(); |
| 2749 | setup_all_buffers(); |
| 2750 | printf("turbostat: re-initialized with num_cpus %d\n", topo.num_cpus); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2751 | } |
| 2752 | |
Prarit Bhargava | 843c579 | 2018-06-01 10:04:28 -0400 | [diff] [blame] | 2753 | void set_max_cpu_num(void) |
| 2754 | { |
| 2755 | FILE *filep; |
| 2756 | unsigned long dummy; |
| 2757 | |
| 2758 | topo.max_cpu_num = 0; |
| 2759 | filep = fopen_or_die( |
| 2760 | "/sys/devices/system/cpu/cpu0/topology/thread_siblings", |
| 2761 | "r"); |
| 2762 | while (fscanf(filep, "%lx,", &dummy) == 1) |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 2763 | topo.max_cpu_num += BITMASK_SIZE; |
Prarit Bhargava | 843c579 | 2018-06-01 10:04:28 -0400 | [diff] [blame] | 2764 | fclose(filep); |
| 2765 | topo.max_cpu_num--; /* 0 based */ |
| 2766 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2767 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2768 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2769 | * count_cpus() |
| 2770 | * remember the last one seen, it will be the max |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2771 | */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2772 | int count_cpus(int cpu) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2773 | { |
Prarit Bhargava | 843c579 | 2018-06-01 10:04:28 -0400 | [diff] [blame] | 2774 | topo.num_cpus++; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 2775 | return 0; |
| 2776 | } |
| 2777 | int mark_cpu_present(int cpu) |
| 2778 | { |
| 2779 | CPU_SET_S(cpu, cpu_present_setsize, cpu_present_set); |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 2780 | return 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 2781 | } |
| 2782 | |
Prarit Bhargava | 8cb48b3 | 2018-06-01 10:04:31 -0400 | [diff] [blame] | 2783 | int init_thread_id(int cpu) |
| 2784 | { |
| 2785 | cpus[cpu].thread_id = -1; |
| 2786 | return 0; |
| 2787 | } |
| 2788 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2789 | /* |
| 2790 | * snapshot_proc_interrupts() |
| 2791 | * |
| 2792 | * read and record summary of /proc/interrupts |
| 2793 | * |
| 2794 | * return 1 if config change requires a restart, else return 0 |
| 2795 | */ |
| 2796 | int snapshot_proc_interrupts(void) |
| 2797 | { |
| 2798 | static FILE *fp; |
| 2799 | int column, retval; |
| 2800 | |
| 2801 | if (fp == NULL) |
| 2802 | fp = fopen_or_die("/proc/interrupts", "r"); |
| 2803 | else |
| 2804 | rewind(fp); |
| 2805 | |
| 2806 | /* read 1st line of /proc/interrupts to get cpu* name for each column */ |
| 2807 | for (column = 0; column < topo.num_cpus; ++column) { |
| 2808 | int cpu_number; |
| 2809 | |
| 2810 | retval = fscanf(fp, " CPU%d", &cpu_number); |
| 2811 | if (retval != 1) |
| 2812 | break; |
| 2813 | |
| 2814 | if (cpu_number > topo.max_cpu_num) { |
| 2815 | warn("/proc/interrupts: cpu%d: > %d", cpu_number, topo.max_cpu_num); |
| 2816 | return 1; |
| 2817 | } |
| 2818 | |
| 2819 | irq_column_2_cpu[column] = cpu_number; |
| 2820 | irqs_per_cpu[cpu_number] = 0; |
| 2821 | } |
| 2822 | |
| 2823 | /* read /proc/interrupt count lines and sum up irqs per cpu */ |
| 2824 | while (1) { |
| 2825 | int column; |
| 2826 | char buf[64]; |
| 2827 | |
| 2828 | retval = fscanf(fp, " %s:", buf); /* flush irq# "N:" */ |
| 2829 | if (retval != 1) |
| 2830 | break; |
| 2831 | |
| 2832 | /* read the count per cpu */ |
| 2833 | for (column = 0; column < topo.num_cpus; ++column) { |
| 2834 | |
| 2835 | int cpu_number, irq_count; |
| 2836 | |
| 2837 | retval = fscanf(fp, " %d", &irq_count); |
| 2838 | if (retval != 1) |
| 2839 | break; |
| 2840 | |
| 2841 | cpu_number = irq_column_2_cpu[column]; |
| 2842 | irqs_per_cpu[cpu_number] += irq_count; |
| 2843 | |
| 2844 | } |
| 2845 | |
| 2846 | while (getc(fp) != '\n') |
| 2847 | ; /* flush interrupt description */ |
| 2848 | |
| 2849 | } |
| 2850 | return 0; |
| 2851 | } |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2852 | /* |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 2853 | * snapshot_gfx_rc6_ms() |
| 2854 | * |
| 2855 | * record snapshot of |
| 2856 | * /sys/class/drm/card0/power/rc6_residency_ms |
| 2857 | * |
| 2858 | * return 1 if config change requires a restart, else return 0 |
| 2859 | */ |
| 2860 | int snapshot_gfx_rc6_ms(void) |
| 2861 | { |
| 2862 | FILE *fp; |
| 2863 | int retval; |
| 2864 | |
| 2865 | fp = fopen_or_die("/sys/class/drm/card0/power/rc6_residency_ms", "r"); |
| 2866 | |
| 2867 | retval = fscanf(fp, "%lld", &gfx_cur_rc6_ms); |
| 2868 | if (retval != 1) |
| 2869 | err(1, "GFX rc6"); |
| 2870 | |
| 2871 | fclose(fp); |
| 2872 | |
| 2873 | return 0; |
| 2874 | } |
| 2875 | /* |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2876 | * snapshot_gfx_mhz() |
| 2877 | * |
| 2878 | * record snapshot of |
| 2879 | * /sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz |
| 2880 | * |
| 2881 | * return 1 if config change requires a restart, else return 0 |
| 2882 | */ |
| 2883 | int snapshot_gfx_mhz(void) |
| 2884 | { |
| 2885 | static FILE *fp; |
| 2886 | int retval; |
| 2887 | |
| 2888 | if (fp == NULL) |
| 2889 | fp = fopen_or_die("/sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz", "r"); |
Len Brown | 22048c5 | 2017-03-04 15:42:48 -0500 | [diff] [blame] | 2890 | else { |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2891 | rewind(fp); |
Len Brown | 22048c5 | 2017-03-04 15:42:48 -0500 | [diff] [blame] | 2892 | fflush(fp); |
| 2893 | } |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2894 | |
| 2895 | retval = fscanf(fp, "%d", &gfx_cur_mhz); |
| 2896 | if (retval != 1) |
| 2897 | err(1, "GFX MHz"); |
| 2898 | |
| 2899 | return 0; |
| 2900 | } |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2901 | |
| 2902 | /* |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 2903 | * snapshot_cpu_lpi() |
| 2904 | * |
| 2905 | * record snapshot of |
| 2906 | * /sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us |
| 2907 | * |
| 2908 | * return 1 if config change requires a restart, else return 0 |
| 2909 | */ |
| 2910 | int snapshot_cpu_lpi_us(void) |
| 2911 | { |
| 2912 | FILE *fp; |
| 2913 | int retval; |
| 2914 | |
| 2915 | fp = fopen_or_die("/sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us", "r"); |
| 2916 | |
| 2917 | retval = fscanf(fp, "%lld", &cpuidle_cur_cpu_lpi_us); |
Prarit Bhargava | 5ea7647 | 2018-09-25 08:59:26 -0400 | [diff] [blame] | 2918 | if (retval != 1) { |
| 2919 | fprintf(stderr, "Disabling Low Power Idle CPU output\n"); |
| 2920 | BIC_NOT_PRESENT(BIC_CPU_LPI); |
| 2921 | return -1; |
| 2922 | } |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 2923 | |
| 2924 | fclose(fp); |
| 2925 | |
| 2926 | return 0; |
| 2927 | } |
| 2928 | /* |
| 2929 | * snapshot_sys_lpi() |
| 2930 | * |
| 2931 | * record snapshot of |
| 2932 | * /sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us |
| 2933 | * |
| 2934 | * return 1 if config change requires a restart, else return 0 |
| 2935 | */ |
| 2936 | int snapshot_sys_lpi_us(void) |
| 2937 | { |
| 2938 | FILE *fp; |
| 2939 | int retval; |
| 2940 | |
| 2941 | fp = fopen_or_die("/sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us", "r"); |
| 2942 | |
| 2943 | retval = fscanf(fp, "%lld", &cpuidle_cur_sys_lpi_us); |
Prarit Bhargava | 5ea7647 | 2018-09-25 08:59:26 -0400 | [diff] [blame] | 2944 | if (retval != 1) { |
| 2945 | fprintf(stderr, "Disabling Low Power Idle System output\n"); |
| 2946 | BIC_NOT_PRESENT(BIC_SYS_LPI); |
Colin Ian King | 15423b9 | 2019-04-08 10:00:44 +0100 | [diff] [blame^] | 2947 | fclose(fp); |
Prarit Bhargava | 5ea7647 | 2018-09-25 08:59:26 -0400 | [diff] [blame] | 2948 | return -1; |
| 2949 | } |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 2950 | fclose(fp); |
| 2951 | |
| 2952 | return 0; |
| 2953 | } |
| 2954 | /* |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2955 | * snapshot /proc and /sys files |
| 2956 | * |
| 2957 | * return 1 if configuration restart needed, else return 0 |
| 2958 | */ |
| 2959 | int snapshot_proc_sysfs_files(void) |
| 2960 | { |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 2961 | if (DO_BIC(BIC_IRQ)) |
| 2962 | if (snapshot_proc_interrupts()) |
| 2963 | return 1; |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2964 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 2965 | if (DO_BIC(BIC_GFX_rc6)) |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 2966 | snapshot_gfx_rc6_ms(); |
| 2967 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 2968 | if (DO_BIC(BIC_GFXMHz)) |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 2969 | snapshot_gfx_mhz(); |
| 2970 | |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 2971 | if (DO_BIC(BIC_CPU_LPI)) |
| 2972 | snapshot_cpu_lpi_us(); |
| 2973 | |
| 2974 | if (DO_BIC(BIC_SYS_LPI)) |
| 2975 | snapshot_sys_lpi_us(); |
| 2976 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 2977 | return 0; |
| 2978 | } |
| 2979 | |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2980 | int exit_requested; |
| 2981 | |
| 2982 | static void signal_handler (int signal) |
| 2983 | { |
| 2984 | switch (signal) { |
| 2985 | case SIGINT: |
| 2986 | exit_requested = 1; |
| 2987 | if (debug) |
| 2988 | fprintf(stderr, " SIGINT\n"); |
| 2989 | break; |
Len Brown | 0721196 | 2017-07-15 15:51:26 -0400 | [diff] [blame] | 2990 | case SIGUSR1: |
| 2991 | if (debug > 1) |
| 2992 | fprintf(stderr, "SIGUSR1\n"); |
| 2993 | break; |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2994 | } |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 2995 | /* make sure this manually-invoked interval is at least 1ms long */ |
| 2996 | nanosleep(&one_msec, NULL); |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 2997 | } |
| 2998 | |
| 2999 | void setup_signal_handler(void) |
| 3000 | { |
| 3001 | struct sigaction sa; |
| 3002 | |
| 3003 | memset(&sa, 0, sizeof(sa)); |
| 3004 | |
| 3005 | sa.sa_handler = &signal_handler; |
| 3006 | |
| 3007 | if (sigaction(SIGINT, &sa, NULL) < 0) |
| 3008 | err(1, "sigaction SIGINT"); |
Len Brown | 0721196 | 2017-07-15 15:51:26 -0400 | [diff] [blame] | 3009 | if (sigaction(SIGUSR1, &sa, NULL) < 0) |
| 3010 | err(1, "sigaction SIGUSR1"); |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 3011 | } |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 3012 | |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 3013 | void do_sleep(void) |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 3014 | { |
| 3015 | struct timeval select_timeout; |
| 3016 | fd_set readfds; |
| 3017 | int retval; |
| 3018 | |
| 3019 | FD_ZERO(&readfds); |
| 3020 | FD_SET(0, &readfds); |
| 3021 | |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 3022 | if (!isatty(fileno(stdin))) { |
| 3023 | nanosleep(&interval_ts, NULL); |
| 3024 | return; |
| 3025 | } |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 3026 | |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 3027 | select_timeout = interval_tv; |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 3028 | retval = select(1, &readfds, NULL, NULL, &select_timeout); |
| 3029 | |
| 3030 | if (retval == 1) { |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 3031 | switch (getc(stdin)) { |
| 3032 | case 'q': |
| 3033 | exit_requested = 1; |
| 3034 | break; |
| 3035 | } |
| 3036 | /* make sure this manually-invoked interval is at least 1ms long */ |
| 3037 | nanosleep(&one_msec, NULL); |
| 3038 | } |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 3039 | } |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 3040 | |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 3041 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3042 | void turbostat_loop() |
| 3043 | { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3044 | int retval; |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 3045 | int restarted = 0; |
Chen Yu | 023fe0a | 2018-04-26 08:41:03 +0800 | [diff] [blame] | 3046 | int done_iters = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3047 | |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 3048 | setup_signal_handler(); |
| 3049 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3050 | restart: |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 3051 | restarted++; |
| 3052 | |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 3053 | snapshot_proc_sysfs_files(); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3054 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 3055 | first_counter_read = 0; |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 3056 | if (retval < -1) { |
| 3057 | exit(retval); |
| 3058 | } else if (retval == -1) { |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 3059 | if (restarted > 1) { |
| 3060 | exit(retval); |
| 3061 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3062 | re_initialize(); |
| 3063 | goto restart; |
| 3064 | } |
Len Brown | e52966c | 2012-11-08 22:38:05 -0500 | [diff] [blame] | 3065 | restarted = 0; |
Chen Yu | 023fe0a | 2018-04-26 08:41:03 +0800 | [diff] [blame] | 3066 | done_iters = 0; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3067 | gettimeofday(&tv_even, (struct timezone *)NULL); |
| 3068 | |
| 3069 | while (1) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3070 | if (for_all_proc_cpus(cpu_is_not_present)) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3071 | re_initialize(); |
| 3072 | goto restart; |
| 3073 | } |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 3074 | do_sleep(); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 3075 | if (snapshot_proc_sysfs_files()) |
| 3076 | goto restart; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3077 | retval = for_all_cpus(get_counters, ODD_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 3078 | if (retval < -1) { |
| 3079 | exit(retval); |
| 3080 | } else if (retval == -1) { |
Len Brown | 15aaa34 | 2012-03-29 22:19:58 -0400 | [diff] [blame] | 3081 | re_initialize(); |
| 3082 | goto restart; |
| 3083 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3084 | gettimeofday(&tv_odd, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3085 | timersub(&tv_odd, &tv_even, &tv_delta); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 3086 | if (for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS)) { |
| 3087 | re_initialize(); |
| 3088 | goto restart; |
| 3089 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3090 | compute_average(EVEN_COUNTERS); |
| 3091 | format_all_counters(EVEN_COUNTERS); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3092 | flush_output_stdout(); |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 3093 | if (exit_requested) |
| 3094 | break; |
Chen Yu | 023fe0a | 2018-04-26 08:41:03 +0800 | [diff] [blame] | 3095 | if (num_iterations && ++done_iters >= num_iterations) |
| 3096 | break; |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 3097 | do_sleep(); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 3098 | if (snapshot_proc_sysfs_files()) |
| 3099 | goto restart; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3100 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 3101 | if (retval < -1) { |
| 3102 | exit(retval); |
| 3103 | } else if (retval == -1) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3104 | re_initialize(); |
| 3105 | goto restart; |
| 3106 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3107 | gettimeofday(&tv_even, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3108 | timersub(&tv_even, &tv_odd, &tv_delta); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 3109 | if (for_all_cpus_2(delta_cpu, EVEN_COUNTERS, ODD_COUNTERS)) { |
| 3110 | re_initialize(); |
| 3111 | goto restart; |
| 3112 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 3113 | compute_average(ODD_COUNTERS); |
| 3114 | format_all_counters(ODD_COUNTERS); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3115 | flush_output_stdout(); |
Len Brown | 8aa2ed0 | 2017-07-15 14:57:37 -0400 | [diff] [blame] | 3116 | if (exit_requested) |
| 3117 | break; |
Chen Yu | 023fe0a | 2018-04-26 08:41:03 +0800 | [diff] [blame] | 3118 | if (num_iterations && ++done_iters >= num_iterations) |
| 3119 | break; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3120 | } |
| 3121 | } |
| 3122 | |
| 3123 | void check_dev_msr() |
| 3124 | { |
| 3125 | struct stat sb; |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3126 | char pathname[32]; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3127 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3128 | sprintf(pathname, "/dev/cpu/%d/msr", base_cpu); |
| 3129 | if (stat(pathname, &sb)) |
Len Brown | a21d38c | 2015-03-24 16:37:35 -0400 | [diff] [blame] | 3130 | if (system("/sbin/modprobe msr > /dev/null 2>&1")) |
| 3131 | err(-5, "no /dev/cpu/0/msr, Try \"# modprobe msr\" "); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3132 | } |
| 3133 | |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 3134 | void check_permissions() |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3135 | { |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 3136 | struct __user_cap_header_struct cap_header_data; |
| 3137 | cap_user_header_t cap_header = &cap_header_data; |
| 3138 | struct __user_cap_data_struct cap_data_data; |
| 3139 | cap_user_data_t cap_data = &cap_data_data; |
| 3140 | extern int capget(cap_user_header_t hdrp, cap_user_data_t datap); |
| 3141 | int do_exit = 0; |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3142 | char pathname[32]; |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 3143 | |
| 3144 | /* check for CAP_SYS_RAWIO */ |
| 3145 | cap_header->pid = getpid(); |
| 3146 | cap_header->version = _LINUX_CAPABILITY_VERSION; |
| 3147 | if (capget(cap_header, cap_data) < 0) |
| 3148 | err(-6, "capget(2) failed"); |
| 3149 | |
| 3150 | if ((cap_data->effective & (1 << CAP_SYS_RAWIO)) == 0) { |
| 3151 | do_exit++; |
| 3152 | warnx("capget(CAP_SYS_RAWIO) failed," |
| 3153 | " try \"# setcap cap_sys_rawio=ep %s\"", progname); |
| 3154 | } |
| 3155 | |
| 3156 | /* test file permissions */ |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3157 | sprintf(pathname, "/dev/cpu/%d/msr", base_cpu); |
| 3158 | if (euidaccess(pathname, R_OK)) { |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 3159 | do_exit++; |
| 3160 | warn("/dev/cpu/0/msr open failed, try chown or chmod +r /dev/cpu/*/msr"); |
| 3161 | } |
| 3162 | |
| 3163 | /* if all else fails, thell them to be root */ |
| 3164 | if (do_exit) |
| 3165 | if (getuid() != 0) |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3166 | warnx("... or simply run as root"); |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 3167 | |
| 3168 | if (do_exit) |
| 3169 | exit(-6); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3170 | } |
| 3171 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3172 | /* |
| 3173 | * NHM adds support for additional MSRs: |
| 3174 | * |
| 3175 | * MSR_SMI_COUNT 0x00000034 |
| 3176 | * |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 3177 | * MSR_PLATFORM_INFO 0x000000ce |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 3178 | * MSR_PKG_CST_CONFIG_CONTROL 0x000000e2 |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3179 | * |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 3180 | * MSR_MISC_PWR_MGMT 0x000001aa |
| 3181 | * |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3182 | * MSR_PKG_C3_RESIDENCY 0x000003f8 |
| 3183 | * MSR_PKG_C6_RESIDENCY 0x000003f9 |
| 3184 | * MSR_CORE_C3_RESIDENCY 0x000003fc |
| 3185 | * MSR_CORE_C6_RESIDENCY 0x000003fd |
| 3186 | * |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3187 | * Side effect: |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 3188 | * sets global pkg_cstate_limit to decode MSR_PKG_CST_CONFIG_CONTROL |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 3189 | * sets has_misc_feature_control |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3190 | */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3191 | int probe_nhm_msrs(unsigned int family, unsigned int model) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3192 | { |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3193 | unsigned long long msr; |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 3194 | unsigned int base_ratio; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3195 | int *pkg_cstate_limits; |
| 3196 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3197 | if (!genuine_intel) |
| 3198 | return 0; |
| 3199 | |
| 3200 | if (family != 6) |
| 3201 | return 0; |
| 3202 | |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 3203 | bclk = discover_bclk(family, model); |
| 3204 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3205 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3206 | case INTEL_FAM6_NEHALEM: /* Core i7 and i5 Processor - Clarksfield, Lynnfield, Jasper Forest */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3207 | case INTEL_FAM6_NEHALEM_EX: /* Nehalem-EX Xeon - Beckton */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3208 | pkg_cstate_limits = nhm_pkg_cstate_limits; |
| 3209 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3210 | case INTEL_FAM6_SANDYBRIDGE: /* SNB */ |
| 3211 | case INTEL_FAM6_SANDYBRIDGE_X: /* SNB Xeon */ |
| 3212 | case INTEL_FAM6_IVYBRIDGE: /* IVB */ |
| 3213 | case INTEL_FAM6_IVYBRIDGE_X: /* IVB Xeon */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3214 | pkg_cstate_limits = snb_pkg_cstate_limits; |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 3215 | has_misc_feature_control = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3216 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3217 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 3218 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3219 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 3220 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 3221 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
| 3222 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3223 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame] | 3224 | case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3225 | pkg_cstate_limits = hsw_pkg_cstate_limits; |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 3226 | has_misc_feature_control = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3227 | break; |
Len Brown | d8ebb44 | 2016-12-01 20:27:46 -0500 | [diff] [blame] | 3228 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
| 3229 | pkg_cstate_limits = skx_pkg_cstate_limits; |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 3230 | has_misc_feature_control = 1; |
Len Brown | d8ebb44 | 2016-12-01 20:27:46 -0500 | [diff] [blame] | 3231 | break; |
Peter Zijlstra | f2c4db1 | 2018-08-07 10:17:27 -0700 | [diff] [blame] | 3232 | case INTEL_FAM6_ATOM_SILVERMONT: /* BYT */ |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 3233 | no_MSR_MISC_PWR_MGMT = 1; |
Peter Zijlstra | f2c4db1 | 2018-08-07 10:17:27 -0700 | [diff] [blame] | 3234 | case INTEL_FAM6_ATOM_SILVERMONT_X: /* AVN */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3235 | pkg_cstate_limits = slv_pkg_cstate_limits; |
| 3236 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3237 | case INTEL_FAM6_ATOM_AIRMONT: /* AMT */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3238 | pkg_cstate_limits = amt_pkg_cstate_limits; |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 3239 | no_MSR_MISC_PWR_MGMT = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3240 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3241 | case INTEL_FAM6_XEON_PHI_KNL: /* PHI */ |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3242 | pkg_cstate_limits = phi_pkg_cstate_limits; |
| 3243 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3244 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Peter Zijlstra | f2c4db1 | 2018-08-07 10:17:27 -0700 | [diff] [blame] | 3245 | case INTEL_FAM6_ATOM_GOLDMONT_PLUS: |
| 3246 | case INTEL_FAM6_ATOM_GOLDMONT_X: /* DNV */ |
Len Brown | 445640a | 2018-12-14 20:02:27 -0500 | [diff] [blame] | 3247 | pkg_cstate_limits = glm_pkg_cstate_limits; |
Len Brown | e4085d5 | 2016-04-06 17:15:56 -0400 | [diff] [blame] | 3248 | break; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3249 | default: |
| 3250 | return 0; |
| 3251 | } |
Len Brown | 1df2e55 | 2017-01-07 23:24:57 -0500 | [diff] [blame] | 3252 | get_msr(base_cpu, MSR_PKG_CST_CONFIG_CONTROL, &msr); |
Len Brown | e9257f5 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 3253 | pkg_cstate_limit = pkg_cstate_limits[msr & 0xF]; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3254 | |
Len Brown | ec0adc5 | 2015-11-12 02:42:31 -0500 | [diff] [blame] | 3255 | get_msr(base_cpu, MSR_PLATFORM_INFO, &msr); |
Len Brown | 21ed557 | 2015-10-19 22:37:40 -0400 | [diff] [blame] | 3256 | base_ratio = (msr >> 8) & 0xFF; |
| 3257 | |
| 3258 | base_hz = base_ratio * bclk * 1000000; |
| 3259 | has_base_hz = 1; |
Len Brown | ee7e38e | 2015-02-09 23:39:45 -0500 | [diff] [blame] | 3260 | return 1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 3261 | } |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 3262 | /* |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 3263 | * SLV client has support for unique MSRs: |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 3264 | * |
| 3265 | * MSR_CC6_DEMOTION_POLICY_CONFIG |
| 3266 | * MSR_MC6_DEMOTION_POLICY_CONFIG |
| 3267 | */ |
| 3268 | |
| 3269 | int has_slv_msrs(unsigned int family, unsigned int model) |
| 3270 | { |
| 3271 | if (!genuine_intel) |
| 3272 | return 0; |
| 3273 | |
| 3274 | switch (model) { |
Peter Zijlstra | f2c4db1 | 2018-08-07 10:17:27 -0700 | [diff] [blame] | 3275 | case INTEL_FAM6_ATOM_SILVERMONT: |
| 3276 | case INTEL_FAM6_ATOM_SILVERMONT_MID: |
| 3277 | case INTEL_FAM6_ATOM_AIRMONT_MID: |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 3278 | return 1; |
| 3279 | } |
| 3280 | return 0; |
| 3281 | } |
Len Brown | 7170a37 | 2017-01-27 02:13:27 -0500 | [diff] [blame] | 3282 | int is_dnv(unsigned int family, unsigned int model) |
| 3283 | { |
| 3284 | |
| 3285 | if (!genuine_intel) |
| 3286 | return 0; |
| 3287 | |
| 3288 | switch (model) { |
Peter Zijlstra | f2c4db1 | 2018-08-07 10:17:27 -0700 | [diff] [blame] | 3289 | case INTEL_FAM6_ATOM_GOLDMONT_X: |
Len Brown | 7170a37 | 2017-01-27 02:13:27 -0500 | [diff] [blame] | 3290 | return 1; |
| 3291 | } |
| 3292 | return 0; |
| 3293 | } |
Len Brown | ade0eba | 2017-02-10 01:56:47 -0500 | [diff] [blame] | 3294 | int is_bdx(unsigned int family, unsigned int model) |
| 3295 | { |
| 3296 | |
| 3297 | if (!genuine_intel) |
| 3298 | return 0; |
| 3299 | |
| 3300 | switch (model) { |
| 3301 | case INTEL_FAM6_BROADWELL_X: |
Len Brown | ade0eba | 2017-02-10 01:56:47 -0500 | [diff] [blame] | 3302 | return 1; |
| 3303 | } |
| 3304 | return 0; |
| 3305 | } |
Len Brown | 34c76197 | 2017-01-27 02:36:41 -0500 | [diff] [blame] | 3306 | int is_skx(unsigned int family, unsigned int model) |
| 3307 | { |
| 3308 | |
| 3309 | if (!genuine_intel) |
| 3310 | return 0; |
| 3311 | |
| 3312 | switch (model) { |
| 3313 | case INTEL_FAM6_SKYLAKE_X: |
| 3314 | return 1; |
| 3315 | } |
| 3316 | return 0; |
| 3317 | } |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 3318 | |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 3319 | int has_turbo_ratio_limit(unsigned int family, unsigned int model) |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3320 | { |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 3321 | if (has_slv_msrs(family, model)) |
| 3322 | return 0; |
| 3323 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3324 | switch (model) { |
| 3325 | /* Nehalem compatible, but do not include turbo-ratio limit support */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3326 | case INTEL_FAM6_NEHALEM_EX: /* Nehalem-EX Xeon - Beckton */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3327 | case INTEL_FAM6_XEON_PHI_KNL: /* PHI - Knights Landing (different MSR definition) */ |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 3328 | return 0; |
| 3329 | default: |
| 3330 | return 1; |
| 3331 | } |
| 3332 | } |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 3333 | int has_atom_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 3334 | { |
| 3335 | if (has_slv_msrs(family, model)) |
| 3336 | return 1; |
| 3337 | |
| 3338 | return 0; |
| 3339 | } |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 3340 | int has_ivt_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 3341 | { |
| 3342 | if (!genuine_intel) |
| 3343 | return 0; |
| 3344 | |
| 3345 | if (family != 6) |
| 3346 | return 0; |
| 3347 | |
| 3348 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3349 | case INTEL_FAM6_IVYBRIDGE_X: /* IVB Xeon */ |
| 3350 | case INTEL_FAM6_HASWELL_X: /* HSW Xeon */ |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 3351 | return 1; |
| 3352 | default: |
| 3353 | return 0; |
| 3354 | } |
| 3355 | } |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3356 | int has_hsw_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 3357 | { |
| 3358 | if (!genuine_intel) |
| 3359 | return 0; |
| 3360 | |
| 3361 | if (family != 6) |
| 3362 | return 0; |
| 3363 | |
| 3364 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3365 | case INTEL_FAM6_HASWELL_X: /* HSW Xeon */ |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3366 | return 1; |
| 3367 | default: |
| 3368 | return 0; |
| 3369 | } |
| 3370 | } |
| 3371 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 3372 | int has_knl_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 3373 | { |
| 3374 | if (!genuine_intel) |
| 3375 | return 0; |
| 3376 | |
| 3377 | if (family != 6) |
| 3378 | return 0; |
| 3379 | |
| 3380 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3381 | case INTEL_FAM6_XEON_PHI_KNL: /* Knights Landing */ |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 3382 | return 1; |
| 3383 | default: |
| 3384 | return 0; |
| 3385 | } |
| 3386 | } |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 3387 | int has_glm_turbo_ratio_limit(unsigned int family, unsigned int model) |
| 3388 | { |
| 3389 | if (!genuine_intel) |
| 3390 | return 0; |
| 3391 | |
| 3392 | if (family != 6) |
| 3393 | return 0; |
| 3394 | |
| 3395 | switch (model) { |
| 3396 | case INTEL_FAM6_ATOM_GOLDMONT: |
| 3397 | case INTEL_FAM6_SKYLAKE_X: |
| 3398 | return 1; |
| 3399 | default: |
| 3400 | return 0; |
| 3401 | } |
| 3402 | } |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 3403 | int has_config_tdp(unsigned int family, unsigned int model) |
| 3404 | { |
| 3405 | if (!genuine_intel) |
| 3406 | return 0; |
| 3407 | |
| 3408 | if (family != 6) |
| 3409 | return 0; |
| 3410 | |
| 3411 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3412 | case INTEL_FAM6_IVYBRIDGE: /* IVB */ |
| 3413 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 3414 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3415 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 3416 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 3417 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
| 3418 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3419 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame] | 3420 | case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3421 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 3422 | |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3423 | case INTEL_FAM6_XEON_PHI_KNL: /* Knights Landing */ |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 3424 | return 1; |
| 3425 | default: |
| 3426 | return 0; |
| 3427 | } |
| 3428 | } |
| 3429 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3430 | static void |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 3431 | dump_cstate_pstate_config_info(unsigned int family, unsigned int model) |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3432 | { |
| 3433 | if (!do_nhm_platform_info) |
| 3434 | return; |
| 3435 | |
| 3436 | dump_nhm_platform_info(); |
| 3437 | |
| 3438 | if (has_hsw_turbo_ratio_limit(family, model)) |
| 3439 | dump_hsw_turbo_ratio_limits(); |
| 3440 | |
| 3441 | if (has_ivt_turbo_ratio_limit(family, model)) |
| 3442 | dump_ivt_turbo_ratio_limits(); |
| 3443 | |
Len Brown | 31e0752 | 2017-01-31 23:07:49 -0500 | [diff] [blame] | 3444 | if (has_turbo_ratio_limit(family, model)) |
| 3445 | dump_turbo_ratio_limits(family, model); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3446 | |
Len Brown | 0f7887c | 2017-01-12 23:49:18 -0500 | [diff] [blame] | 3447 | if (has_atom_turbo_ratio_limit(family, model)) |
| 3448 | dump_atom_turbo_ratio_limits(); |
| 3449 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 3450 | if (has_knl_turbo_ratio_limit(family, model)) |
| 3451 | dump_knl_turbo_ratio_limits(); |
| 3452 | |
Len Brown | 6fb3143 | 2015-06-17 16:23:45 -0400 | [diff] [blame] | 3453 | if (has_config_tdp(family, model)) |
| 3454 | dump_config_tdp(); |
| 3455 | |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 3456 | dump_nhm_cst_cfg(); |
| 3457 | } |
| 3458 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 3459 | static void |
| 3460 | dump_sysfs_cstate_config(void) |
| 3461 | { |
| 3462 | char path[64]; |
| 3463 | char name_buf[16]; |
| 3464 | char desc[64]; |
| 3465 | FILE *input; |
| 3466 | int state; |
| 3467 | char *sp; |
| 3468 | |
| 3469 | if (!DO_BIC(BIC_sysfs)) |
| 3470 | return; |
| 3471 | |
| 3472 | for (state = 0; state < 10; ++state) { |
| 3473 | |
| 3474 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", |
| 3475 | base_cpu, state); |
| 3476 | input = fopen(path, "r"); |
| 3477 | if (input == NULL) |
| 3478 | continue; |
Ben Hutchings | 8173c33 | 2019-03-20 23:01:03 -0400 | [diff] [blame] | 3479 | if (!fgets(name_buf, sizeof(name_buf), input)) |
| 3480 | err(1, "%s: failed to read file", path); |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 3481 | |
| 3482 | /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ |
| 3483 | sp = strchr(name_buf, '-'); |
| 3484 | if (!sp) |
| 3485 | sp = strchrnul(name_buf, '\n'); |
| 3486 | *sp = '\0'; |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 3487 | fclose(input); |
| 3488 | |
| 3489 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/desc", |
| 3490 | base_cpu, state); |
| 3491 | input = fopen(path, "r"); |
| 3492 | if (input == NULL) |
| 3493 | continue; |
Ben Hutchings | 8173c33 | 2019-03-20 23:01:03 -0400 | [diff] [blame] | 3494 | if (!fgets(desc, sizeof(desc), input)) |
| 3495 | err(1, "%s: failed to read file", path); |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 3496 | |
| 3497 | fprintf(outf, "cpu%d: %s: %s", base_cpu, name_buf, desc); |
| 3498 | fclose(input); |
| 3499 | } |
| 3500 | } |
Len Brown | 7293fcc | 2017-02-22 00:11:12 -0500 | [diff] [blame] | 3501 | static void |
| 3502 | dump_sysfs_pstate_config(void) |
| 3503 | { |
| 3504 | char path[64]; |
| 3505 | char driver_buf[64]; |
| 3506 | char governor_buf[64]; |
| 3507 | FILE *input; |
| 3508 | int turbo; |
| 3509 | |
| 3510 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_driver", |
| 3511 | base_cpu); |
| 3512 | input = fopen(path, "r"); |
| 3513 | if (input == NULL) { |
Prarit Bhargava | 0a42d23 | 2018-08-13 08:45:01 -0400 | [diff] [blame] | 3514 | fprintf(outf, "NSFOD %s\n", path); |
Len Brown | 7293fcc | 2017-02-22 00:11:12 -0500 | [diff] [blame] | 3515 | return; |
| 3516 | } |
Ben Hutchings | 8173c33 | 2019-03-20 23:01:03 -0400 | [diff] [blame] | 3517 | if (!fgets(driver_buf, sizeof(driver_buf), input)) |
| 3518 | err(1, "%s: failed to read file", path); |
Len Brown | 7293fcc | 2017-02-22 00:11:12 -0500 | [diff] [blame] | 3519 | fclose(input); |
| 3520 | |
| 3521 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor", |
| 3522 | base_cpu); |
| 3523 | input = fopen(path, "r"); |
| 3524 | if (input == NULL) { |
Prarit Bhargava | 0a42d23 | 2018-08-13 08:45:01 -0400 | [diff] [blame] | 3525 | fprintf(outf, "NSFOD %s\n", path); |
Len Brown | 7293fcc | 2017-02-22 00:11:12 -0500 | [diff] [blame] | 3526 | return; |
| 3527 | } |
Ben Hutchings | 8173c33 | 2019-03-20 23:01:03 -0400 | [diff] [blame] | 3528 | if (!fgets(governor_buf, sizeof(governor_buf), input)) |
| 3529 | err(1, "%s: failed to read file", path); |
Len Brown | 7293fcc | 2017-02-22 00:11:12 -0500 | [diff] [blame] | 3530 | fclose(input); |
| 3531 | |
| 3532 | fprintf(outf, "cpu%d: cpufreq driver: %s", base_cpu, driver_buf); |
| 3533 | fprintf(outf, "cpu%d: cpufreq governor: %s", base_cpu, governor_buf); |
| 3534 | |
| 3535 | sprintf(path, "/sys/devices/system/cpu/cpufreq/boost"); |
| 3536 | input = fopen(path, "r"); |
| 3537 | if (input != NULL) { |
Ben Hutchings | 8173c33 | 2019-03-20 23:01:03 -0400 | [diff] [blame] | 3538 | if (fscanf(input, "%d", &turbo) != 1) |
| 3539 | err(1, "%s: failed to parse number from file", path); |
Len Brown | 7293fcc | 2017-02-22 00:11:12 -0500 | [diff] [blame] | 3540 | fprintf(outf, "cpufreq boost: %d\n", turbo); |
| 3541 | fclose(input); |
| 3542 | } |
| 3543 | |
| 3544 | sprintf(path, "/sys/devices/system/cpu/intel_pstate/no_turbo"); |
| 3545 | input = fopen(path, "r"); |
| 3546 | if (input != NULL) { |
Ben Hutchings | 8173c33 | 2019-03-20 23:01:03 -0400 | [diff] [blame] | 3547 | if (fscanf(input, "%d", &turbo) != 1) |
| 3548 | err(1, "%s: failed to parse number from file", path); |
Len Brown | 7293fcc | 2017-02-22 00:11:12 -0500 | [diff] [blame] | 3549 | fprintf(outf, "cpufreq intel_pstate no_turbo: %d\n", turbo); |
| 3550 | fclose(input); |
| 3551 | } |
| 3552 | } |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 3553 | |
Len Brown | 6574a5d | 2012-09-21 00:01:31 -0400 | [diff] [blame] | 3554 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3555 | /* |
| 3556 | * print_epb() |
| 3557 | * Decode the ENERGY_PERF_BIAS MSR |
| 3558 | */ |
| 3559 | int print_epb(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3560 | { |
| 3561 | unsigned long long msr; |
| 3562 | char *epb_string; |
| 3563 | int cpu; |
| 3564 | |
| 3565 | if (!has_epb) |
| 3566 | return 0; |
| 3567 | |
| 3568 | cpu = t->cpu_id; |
| 3569 | |
| 3570 | /* EPB is per-package */ |
| 3571 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3572 | return 0; |
| 3573 | |
| 3574 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3575 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3576 | return -1; |
| 3577 | } |
| 3578 | |
| 3579 | if (get_msr(cpu, MSR_IA32_ENERGY_PERF_BIAS, &msr)) |
| 3580 | return 0; |
| 3581 | |
Len Brown | e9be7dd | 2015-05-26 12:19:37 -0400 | [diff] [blame] | 3582 | switch (msr & 0xF) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3583 | case ENERGY_PERF_BIAS_PERFORMANCE: |
| 3584 | epb_string = "performance"; |
| 3585 | break; |
| 3586 | case ENERGY_PERF_BIAS_NORMAL: |
| 3587 | epb_string = "balanced"; |
| 3588 | break; |
| 3589 | case ENERGY_PERF_BIAS_POWERSAVE: |
| 3590 | epb_string = "powersave"; |
| 3591 | break; |
| 3592 | default: |
| 3593 | epb_string = "custom"; |
| 3594 | break; |
| 3595 | } |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3596 | fprintf(outf, "cpu%d: MSR_IA32_ENERGY_PERF_BIAS: 0x%08llx (%s)\n", cpu, msr, epb_string); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3597 | |
| 3598 | return 0; |
| 3599 | } |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3600 | /* |
| 3601 | * print_hwp() |
| 3602 | * Decode the MSR_HWP_CAPABILITIES |
| 3603 | */ |
| 3604 | int print_hwp(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3605 | { |
| 3606 | unsigned long long msr; |
| 3607 | int cpu; |
| 3608 | |
| 3609 | if (!has_hwp) |
| 3610 | return 0; |
| 3611 | |
| 3612 | cpu = t->cpu_id; |
| 3613 | |
| 3614 | /* MSR_HWP_CAPABILITIES is per-package */ |
| 3615 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3616 | return 0; |
| 3617 | |
| 3618 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3619 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3620 | return -1; |
| 3621 | } |
| 3622 | |
| 3623 | if (get_msr(cpu, MSR_PM_ENABLE, &msr)) |
| 3624 | return 0; |
| 3625 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3626 | fprintf(outf, "cpu%d: MSR_PM_ENABLE: 0x%08llx (%sHWP)\n", |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3627 | cpu, msr, (msr & (1 << 0)) ? "" : "No-"); |
| 3628 | |
| 3629 | /* MSR_PM_ENABLE[1] == 1 if HWP is enabled and MSRs visible */ |
| 3630 | if ((msr & (1 << 0)) == 0) |
| 3631 | return 0; |
| 3632 | |
| 3633 | if (get_msr(cpu, MSR_HWP_CAPABILITIES, &msr)) |
| 3634 | return 0; |
| 3635 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3636 | fprintf(outf, "cpu%d: MSR_HWP_CAPABILITIES: 0x%08llx " |
Len Brown | 6dbd25a | 2017-03-04 18:18:28 -0500 | [diff] [blame] | 3637 | "(high %d guar %d eff %d low %d)\n", |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3638 | cpu, msr, |
| 3639 | (unsigned int)HWP_HIGHEST_PERF(msr), |
| 3640 | (unsigned int)HWP_GUARANTEED_PERF(msr), |
| 3641 | (unsigned int)HWP_MOSTEFFICIENT_PERF(msr), |
| 3642 | (unsigned int)HWP_LOWEST_PERF(msr)); |
| 3643 | |
| 3644 | if (get_msr(cpu, MSR_HWP_REQUEST, &msr)) |
| 3645 | return 0; |
| 3646 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3647 | fprintf(outf, "cpu%d: MSR_HWP_REQUEST: 0x%08llx " |
Len Brown | 6dbd25a | 2017-03-04 18:18:28 -0500 | [diff] [blame] | 3648 | "(min %d max %d des %d epp 0x%x window 0x%x pkg 0x%x)\n", |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3649 | cpu, msr, |
| 3650 | (unsigned int)(((msr) >> 0) & 0xff), |
| 3651 | (unsigned int)(((msr) >> 8) & 0xff), |
| 3652 | (unsigned int)(((msr) >> 16) & 0xff), |
| 3653 | (unsigned int)(((msr) >> 24) & 0xff), |
| 3654 | (unsigned int)(((msr) >> 32) & 0xff3), |
| 3655 | (unsigned int)(((msr) >> 42) & 0x1)); |
| 3656 | |
| 3657 | if (has_hwp_pkg) { |
| 3658 | if (get_msr(cpu, MSR_HWP_REQUEST_PKG, &msr)) |
| 3659 | return 0; |
| 3660 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3661 | fprintf(outf, "cpu%d: MSR_HWP_REQUEST_PKG: 0x%08llx " |
Len Brown | 6dbd25a | 2017-03-04 18:18:28 -0500 | [diff] [blame] | 3662 | "(min %d max %d des %d epp 0x%x window 0x%x)\n", |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3663 | cpu, msr, |
| 3664 | (unsigned int)(((msr) >> 0) & 0xff), |
| 3665 | (unsigned int)(((msr) >> 8) & 0xff), |
| 3666 | (unsigned int)(((msr) >> 16) & 0xff), |
| 3667 | (unsigned int)(((msr) >> 24) & 0xff), |
| 3668 | (unsigned int)(((msr) >> 32) & 0xff3)); |
| 3669 | } |
| 3670 | if (has_hwp_notify) { |
| 3671 | if (get_msr(cpu, MSR_HWP_INTERRUPT, &msr)) |
| 3672 | return 0; |
| 3673 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3674 | fprintf(outf, "cpu%d: MSR_HWP_INTERRUPT: 0x%08llx " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3675 | "(%s_Guaranteed_Perf_Change, %s_Excursion_Min)\n", |
| 3676 | cpu, msr, |
| 3677 | ((msr) & 0x1) ? "EN" : "Dis", |
| 3678 | ((msr) & 0x2) ? "EN" : "Dis"); |
| 3679 | } |
| 3680 | if (get_msr(cpu, MSR_HWP_STATUS, &msr)) |
| 3681 | return 0; |
| 3682 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3683 | fprintf(outf, "cpu%d: MSR_HWP_STATUS: 0x%08llx " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 3684 | "(%sGuaranteed_Perf_Change, %sExcursion_Min)\n", |
| 3685 | cpu, msr, |
| 3686 | ((msr) & 0x1) ? "" : "No-", |
| 3687 | ((msr) & 0x2) ? "" : "No-"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3688 | |
| 3689 | return 0; |
| 3690 | } |
| 3691 | |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3692 | /* |
| 3693 | * print_perf_limit() |
| 3694 | */ |
| 3695 | int print_perf_limit(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 3696 | { |
| 3697 | unsigned long long msr; |
| 3698 | int cpu; |
| 3699 | |
| 3700 | cpu = t->cpu_id; |
| 3701 | |
| 3702 | /* per-package */ |
| 3703 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 3704 | return 0; |
| 3705 | |
| 3706 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3707 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3708 | return -1; |
| 3709 | } |
| 3710 | |
| 3711 | if (do_core_perf_limit_reasons) { |
| 3712 | get_msr(cpu, MSR_CORE_PERF_LIMIT_REASONS, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3713 | fprintf(outf, "cpu%d: MSR_CORE_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr); |
| 3714 | fprintf(outf, " (Active: %s%s%s%s%s%s%s%s%s%s%s%s%s%s)", |
Len Brown | e33cbe8 | 2015-03-13 16:30:57 -0400 | [diff] [blame] | 3715 | (msr & 1 << 15) ? "bit15, " : "", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3716 | (msr & 1 << 14) ? "bit14, " : "", |
Len Brown | e33cbe8 | 2015-03-13 16:30:57 -0400 | [diff] [blame] | 3717 | (msr & 1 << 13) ? "Transitions, " : "", |
| 3718 | (msr & 1 << 12) ? "MultiCoreTurbo, " : "", |
| 3719 | (msr & 1 << 11) ? "PkgPwrL2, " : "", |
| 3720 | (msr & 1 << 10) ? "PkgPwrL1, " : "", |
| 3721 | (msr & 1 << 9) ? "CorePwr, " : "", |
| 3722 | (msr & 1 << 8) ? "Amps, " : "", |
| 3723 | (msr & 1 << 6) ? "VR-Therm, " : "", |
| 3724 | (msr & 1 << 5) ? "Auto-HWP, " : "", |
| 3725 | (msr & 1 << 4) ? "Graphics, " : "", |
| 3726 | (msr & 1 << 2) ? "bit2, " : "", |
| 3727 | (msr & 1 << 1) ? "ThermStatus, " : "", |
| 3728 | (msr & 1 << 0) ? "PROCHOT, " : ""); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3729 | fprintf(outf, " (Logged: %s%s%s%s%s%s%s%s%s%s%s%s%s%s)\n", |
Len Brown | e33cbe8 | 2015-03-13 16:30:57 -0400 | [diff] [blame] | 3730 | (msr & 1 << 31) ? "bit31, " : "", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3731 | (msr & 1 << 30) ? "bit30, " : "", |
Len Brown | e33cbe8 | 2015-03-13 16:30:57 -0400 | [diff] [blame] | 3732 | (msr & 1 << 29) ? "Transitions, " : "", |
| 3733 | (msr & 1 << 28) ? "MultiCoreTurbo, " : "", |
| 3734 | (msr & 1 << 27) ? "PkgPwrL2, " : "", |
| 3735 | (msr & 1 << 26) ? "PkgPwrL1, " : "", |
| 3736 | (msr & 1 << 25) ? "CorePwr, " : "", |
| 3737 | (msr & 1 << 24) ? "Amps, " : "", |
| 3738 | (msr & 1 << 22) ? "VR-Therm, " : "", |
| 3739 | (msr & 1 << 21) ? "Auto-HWP, " : "", |
| 3740 | (msr & 1 << 20) ? "Graphics, " : "", |
| 3741 | (msr & 1 << 18) ? "bit18, " : "", |
| 3742 | (msr & 1 << 17) ? "ThermStatus, " : "", |
| 3743 | (msr & 1 << 16) ? "PROCHOT, " : ""); |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3744 | |
| 3745 | } |
| 3746 | if (do_gfx_perf_limit_reasons) { |
| 3747 | get_msr(cpu, MSR_GFX_PERF_LIMIT_REASONS, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3748 | fprintf(outf, "cpu%d: MSR_GFX_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr); |
| 3749 | fprintf(outf, " (Active: %s%s%s%s%s%s%s%s)", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3750 | (msr & 1 << 0) ? "PROCHOT, " : "", |
| 3751 | (msr & 1 << 1) ? "ThermStatus, " : "", |
| 3752 | (msr & 1 << 4) ? "Graphics, " : "", |
| 3753 | (msr & 1 << 6) ? "VR-Therm, " : "", |
| 3754 | (msr & 1 << 8) ? "Amps, " : "", |
| 3755 | (msr & 1 << 9) ? "GFXPwr, " : "", |
| 3756 | (msr & 1 << 10) ? "PkgPwrL1, " : "", |
| 3757 | (msr & 1 << 11) ? "PkgPwrL2, " : ""); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3758 | fprintf(outf, " (Logged: %s%s%s%s%s%s%s%s)\n", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3759 | (msr & 1 << 16) ? "PROCHOT, " : "", |
| 3760 | (msr & 1 << 17) ? "ThermStatus, " : "", |
| 3761 | (msr & 1 << 20) ? "Graphics, " : "", |
| 3762 | (msr & 1 << 22) ? "VR-Therm, " : "", |
| 3763 | (msr & 1 << 24) ? "Amps, " : "", |
| 3764 | (msr & 1 << 25) ? "GFXPwr, " : "", |
| 3765 | (msr & 1 << 26) ? "PkgPwrL1, " : "", |
| 3766 | (msr & 1 << 27) ? "PkgPwrL2, " : ""); |
| 3767 | } |
| 3768 | if (do_ring_perf_limit_reasons) { |
| 3769 | get_msr(cpu, MSR_RING_PERF_LIMIT_REASONS, &msr); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3770 | fprintf(outf, "cpu%d: MSR_RING_PERF_LIMIT_REASONS, 0x%08llx", cpu, msr); |
| 3771 | fprintf(outf, " (Active: %s%s%s%s%s%s)", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3772 | (msr & 1 << 0) ? "PROCHOT, " : "", |
| 3773 | (msr & 1 << 1) ? "ThermStatus, " : "", |
| 3774 | (msr & 1 << 6) ? "VR-Therm, " : "", |
| 3775 | (msr & 1 << 8) ? "Amps, " : "", |
| 3776 | (msr & 1 << 10) ? "PkgPwrL1, " : "", |
| 3777 | (msr & 1 << 11) ? "PkgPwrL2, " : ""); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3778 | fprintf(outf, " (Logged: %s%s%s%s%s%s)\n", |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 3779 | (msr & 1 << 16) ? "PROCHOT, " : "", |
| 3780 | (msr & 1 << 17) ? "ThermStatus, " : "", |
| 3781 | (msr & 1 << 22) ? "VR-Therm, " : "", |
| 3782 | (msr & 1 << 24) ? "Amps, " : "", |
| 3783 | (msr & 1 << 26) ? "PkgPwrL1, " : "", |
| 3784 | (msr & 1 << 27) ? "PkgPwrL2, " : ""); |
| 3785 | } |
| 3786 | return 0; |
| 3787 | } |
| 3788 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3789 | #define RAPL_POWER_GRANULARITY 0x7FFF /* 15 bit power granularity */ |
| 3790 | #define RAPL_TIME_GRANULARITY 0x3F /* 6 bit time granularity */ |
| 3791 | |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 3792 | double get_tdp_intel(unsigned int model) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3793 | { |
| 3794 | unsigned long long msr; |
| 3795 | |
| 3796 | if (do_rapl & RAPL_PKG_POWER_INFO) |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3797 | if (!get_msr(base_cpu, MSR_PKG_POWER_INFO, &msr)) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3798 | return ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units; |
| 3799 | |
| 3800 | switch (model) { |
Peter Zijlstra | f2c4db1 | 2018-08-07 10:17:27 -0700 | [diff] [blame] | 3801 | case INTEL_FAM6_ATOM_SILVERMONT: |
| 3802 | case INTEL_FAM6_ATOM_SILVERMONT_X: |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3803 | return 30.0; |
| 3804 | default: |
| 3805 | return 135.0; |
| 3806 | } |
| 3807 | } |
| 3808 | |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 3809 | double get_tdp_amd(unsigned int family) |
| 3810 | { |
| 3811 | switch (family) { |
| 3812 | case 0x17: |
| 3813 | default: |
| 3814 | /* This is the max stock TDP of HEDT/Server Fam17h chips */ |
| 3815 | return 250.0; |
| 3816 | } |
| 3817 | } |
| 3818 | |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 3819 | /* |
| 3820 | * rapl_dram_energy_units_probe() |
| 3821 | * Energy units are either hard-coded, or come from RAPL Energy Unit MSR. |
| 3822 | */ |
| 3823 | static double |
| 3824 | rapl_dram_energy_units_probe(int model, double rapl_energy_units) |
| 3825 | { |
| 3826 | /* only called for genuine_intel, family 6 */ |
| 3827 | |
| 3828 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3829 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 3830 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3831 | case INTEL_FAM6_XEON_PHI_KNL: /* KNL */ |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 3832 | return (rapl_dram_energy_units = 15.3 / 1000000); |
| 3833 | default: |
| 3834 | return (rapl_energy_units); |
| 3835 | } |
| 3836 | } |
| 3837 | |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 3838 | void rapl_probe_intel(unsigned int family, unsigned int model) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3839 | { |
| 3840 | unsigned long long msr; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3841 | unsigned int time_unit; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3842 | double tdp; |
| 3843 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3844 | if (family != 6) |
| 3845 | return; |
| 3846 | |
| 3847 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3848 | case INTEL_FAM6_SANDYBRIDGE: |
| 3849 | case INTEL_FAM6_IVYBRIDGE: |
| 3850 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3851 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 3852 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 3853 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3854 | do_rapl = RAPL_PKG | RAPL_CORES | RAPL_CORE_POLICY | RAPL_GFX | RAPL_PKG_POWER_INFO; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3855 | if (rapl_joules) { |
| 3856 | BIC_PRESENT(BIC_Pkg_J); |
| 3857 | BIC_PRESENT(BIC_Cor_J); |
| 3858 | BIC_PRESENT(BIC_GFX_J); |
| 3859 | } else { |
| 3860 | BIC_PRESENT(BIC_PkgWatt); |
| 3861 | BIC_PRESENT(BIC_CorWatt); |
| 3862 | BIC_PRESENT(BIC_GFXWatt); |
| 3863 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3864 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3865 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Peter Zijlstra | f2c4db1 | 2018-08-07 10:17:27 -0700 | [diff] [blame] | 3866 | case INTEL_FAM6_ATOM_GOLDMONT_PLUS: |
Len Brown | e4085d5 | 2016-04-06 17:15:56 -0400 | [diff] [blame] | 3867 | do_rapl = RAPL_PKG | RAPL_PKG_POWER_INFO; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3868 | if (rapl_joules) |
| 3869 | BIC_PRESENT(BIC_Pkg_J); |
| 3870 | else |
| 3871 | BIC_PRESENT(BIC_PkgWatt); |
Len Brown | e4085d5 | 2016-04-06 17:15:56 -0400 | [diff] [blame] | 3872 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3873 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame] | 3874 | case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ |
Len Brown | 8182492 | 2017-03-04 17:23:07 -0500 | [diff] [blame] | 3875 | do_rapl = RAPL_PKG | RAPL_CORES | RAPL_CORE_POLICY | RAPL_DRAM | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_GFX | RAPL_PKG_POWER_INFO; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3876 | BIC_PRESENT(BIC_PKG__); |
| 3877 | BIC_PRESENT(BIC_RAM__); |
| 3878 | if (rapl_joules) { |
| 3879 | BIC_PRESENT(BIC_Pkg_J); |
| 3880 | BIC_PRESENT(BIC_Cor_J); |
| 3881 | BIC_PRESENT(BIC_RAM_J); |
Len Brown | 8182492 | 2017-03-04 17:23:07 -0500 | [diff] [blame] | 3882 | BIC_PRESENT(BIC_GFX_J); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3883 | } else { |
| 3884 | BIC_PRESENT(BIC_PkgWatt); |
| 3885 | BIC_PRESENT(BIC_CorWatt); |
| 3886 | BIC_PRESENT(BIC_RAMWatt); |
Len Brown | 8182492 | 2017-03-04 17:23:07 -0500 | [diff] [blame] | 3887 | BIC_PRESENT(BIC_GFXWatt); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3888 | } |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3889 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3890 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
| 3891 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3892 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
| 3893 | case INTEL_FAM6_XEON_PHI_KNL: /* KNL */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3894 | do_rapl = RAPL_PKG | RAPL_DRAM | RAPL_DRAM_POWER_INFO | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_PKG_POWER_INFO; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3895 | BIC_PRESENT(BIC_PKG__); |
| 3896 | BIC_PRESENT(BIC_RAM__); |
| 3897 | if (rapl_joules) { |
| 3898 | BIC_PRESENT(BIC_Pkg_J); |
| 3899 | BIC_PRESENT(BIC_RAM_J); |
| 3900 | } else { |
| 3901 | BIC_PRESENT(BIC_PkgWatt); |
| 3902 | BIC_PRESENT(BIC_RAMWatt); |
| 3903 | } |
Len Brown | e6f9bb3 | 2013-12-03 02:19:19 -0500 | [diff] [blame] | 3904 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 3905 | case INTEL_FAM6_SANDYBRIDGE_X: |
| 3906 | case INTEL_FAM6_IVYBRIDGE_X: |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 3907 | do_rapl = RAPL_PKG | RAPL_CORES | RAPL_CORE_POLICY | RAPL_DRAM | RAPL_DRAM_POWER_INFO | RAPL_PKG_PERF_STATUS | RAPL_DRAM_PERF_STATUS | RAPL_PKG_POWER_INFO; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3908 | BIC_PRESENT(BIC_PKG__); |
| 3909 | BIC_PRESENT(BIC_RAM__); |
| 3910 | if (rapl_joules) { |
| 3911 | BIC_PRESENT(BIC_Pkg_J); |
| 3912 | BIC_PRESENT(BIC_Cor_J); |
| 3913 | BIC_PRESENT(BIC_RAM_J); |
| 3914 | } else { |
| 3915 | BIC_PRESENT(BIC_PkgWatt); |
| 3916 | BIC_PRESENT(BIC_CorWatt); |
| 3917 | BIC_PRESENT(BIC_RAMWatt); |
| 3918 | } |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3919 | break; |
Peter Zijlstra | f2c4db1 | 2018-08-07 10:17:27 -0700 | [diff] [blame] | 3920 | case INTEL_FAM6_ATOM_SILVERMONT: /* BYT */ |
| 3921 | case INTEL_FAM6_ATOM_SILVERMONT_X: /* AVN */ |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 3922 | do_rapl = RAPL_PKG | RAPL_CORES; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3923 | if (rapl_joules) { |
| 3924 | BIC_PRESENT(BIC_Pkg_J); |
| 3925 | BIC_PRESENT(BIC_Cor_J); |
| 3926 | } else { |
| 3927 | BIC_PRESENT(BIC_PkgWatt); |
| 3928 | BIC_PRESENT(BIC_CorWatt); |
| 3929 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3930 | break; |
Peter Zijlstra | f2c4db1 | 2018-08-07 10:17:27 -0700 | [diff] [blame] | 3931 | case INTEL_FAM6_ATOM_GOLDMONT_X: /* DNV */ |
Jacob Pan | 0f64490 | 2016-06-16 09:48:22 -0700 | [diff] [blame] | 3932 | do_rapl = RAPL_PKG | RAPL_DRAM | RAPL_DRAM_POWER_INFO | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_PKG_POWER_INFO | RAPL_CORES_ENERGY_STATUS; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 3933 | BIC_PRESENT(BIC_PKG__); |
| 3934 | BIC_PRESENT(BIC_RAM__); |
| 3935 | if (rapl_joules) { |
| 3936 | BIC_PRESENT(BIC_Pkg_J); |
| 3937 | BIC_PRESENT(BIC_Cor_J); |
| 3938 | BIC_PRESENT(BIC_RAM_J); |
| 3939 | } else { |
| 3940 | BIC_PRESENT(BIC_PkgWatt); |
| 3941 | BIC_PRESENT(BIC_CorWatt); |
| 3942 | BIC_PRESENT(BIC_RAMWatt); |
| 3943 | } |
Jacob Pan | 0f64490 | 2016-06-16 09:48:22 -0700 | [diff] [blame] | 3944 | break; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3945 | default: |
| 3946 | return; |
| 3947 | } |
| 3948 | |
| 3949 | /* units on package 0, verify later other packages match */ |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 3950 | if (get_msr(base_cpu, MSR_RAPL_POWER_UNIT, &msr)) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3951 | return; |
| 3952 | |
| 3953 | rapl_power_units = 1.0 / (1 << (msr & 0xF)); |
Peter Zijlstra | f2c4db1 | 2018-08-07 10:17:27 -0700 | [diff] [blame] | 3954 | if (model == INTEL_FAM6_ATOM_SILVERMONT) |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3955 | rapl_energy_units = 1.0 * (1 << (msr >> 8 & 0x1F)) / 1000000; |
| 3956 | else |
| 3957 | rapl_energy_units = 1.0 / (1 << (msr >> 8 & 0x1F)); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3958 | |
Andrey Semin | 40ee8e3 | 2014-12-05 00:07:00 -0500 | [diff] [blame] | 3959 | rapl_dram_energy_units = rapl_dram_energy_units_probe(model, rapl_energy_units); |
| 3960 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3961 | time_unit = msr >> 16 & 0xF; |
| 3962 | if (time_unit == 0) |
| 3963 | time_unit = 0xA; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3964 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 3965 | rapl_time_units = 1.0 / (1 << (time_unit)); |
| 3966 | |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 3967 | tdp = get_tdp_intel(model); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3968 | |
| 3969 | rapl_joule_counter_range = 0xFFFFFFFF * rapl_energy_units / tdp; |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 3970 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 3971 | fprintf(outf, "RAPL: %.0f sec. Joule Counter Range, at %.0f Watts\n", rapl_joule_counter_range, tdp); |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 3972 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 3973 | |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 3974 | void rapl_probe_amd(unsigned int family, unsigned int model) |
| 3975 | { |
| 3976 | unsigned long long msr; |
| 3977 | unsigned int eax, ebx, ecx, edx; |
| 3978 | unsigned int has_rapl = 0; |
| 3979 | double tdp; |
| 3980 | |
| 3981 | if (max_extended_level >= 0x80000007) { |
| 3982 | __cpuid(0x80000007, eax, ebx, ecx, edx); |
| 3983 | /* RAPL (Fam 17h) */ |
| 3984 | has_rapl = edx & (1 << 14); |
| 3985 | } |
| 3986 | |
| 3987 | if (!has_rapl) |
| 3988 | return; |
| 3989 | |
| 3990 | switch (family) { |
| 3991 | case 0x17: /* Zen, Zen+ */ |
| 3992 | do_rapl = RAPL_AMD_F17H | RAPL_PER_CORE_ENERGY; |
Calvin Walton | 3316f99 | 2018-08-17 12:34:42 -0400 | [diff] [blame] | 3993 | if (rapl_joules) { |
| 3994 | BIC_PRESENT(BIC_Pkg_J); |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 3995 | BIC_PRESENT(BIC_Cor_J); |
Calvin Walton | 3316f99 | 2018-08-17 12:34:42 -0400 | [diff] [blame] | 3996 | } else { |
| 3997 | BIC_PRESENT(BIC_PkgWatt); |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 3998 | BIC_PRESENT(BIC_CorWatt); |
Calvin Walton | 3316f99 | 2018-08-17 12:34:42 -0400 | [diff] [blame] | 3999 | } |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 4000 | break; |
| 4001 | default: |
| 4002 | return; |
| 4003 | } |
| 4004 | |
| 4005 | if (get_msr(base_cpu, MSR_RAPL_PWR_UNIT, &msr)) |
| 4006 | return; |
| 4007 | |
| 4008 | rapl_time_units = ldexp(1.0, -(msr >> 16 & 0xf)); |
| 4009 | rapl_energy_units = ldexp(1.0, -(msr >> 8 & 0x1f)); |
| 4010 | rapl_power_units = ldexp(1.0, -(msr & 0xf)); |
| 4011 | |
| 4012 | tdp = get_tdp_amd(model); |
| 4013 | |
| 4014 | rapl_joule_counter_range = 0xFFFFFFFF * rapl_energy_units / tdp; |
| 4015 | if (!quiet) |
| 4016 | fprintf(outf, "RAPL: %.0f sec. Joule Counter Range, at %.0f Watts\n", rapl_joule_counter_range, tdp); |
| 4017 | } |
| 4018 | |
| 4019 | /* |
| 4020 | * rapl_probe() |
| 4021 | * |
| 4022 | * sets do_rapl, rapl_power_units, rapl_energy_units, rapl_time_units |
| 4023 | */ |
| 4024 | void rapl_probe(unsigned int family, unsigned int model) |
| 4025 | { |
| 4026 | if (genuine_intel) |
| 4027 | rapl_probe_intel(family, model); |
| 4028 | if (authentic_amd) |
| 4029 | rapl_probe_amd(family, model); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4030 | } |
| 4031 | |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 4032 | void perf_limit_reasons_probe(unsigned int family, unsigned int model) |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 4033 | { |
| 4034 | if (!genuine_intel) |
| 4035 | return; |
| 4036 | |
| 4037 | if (family != 6) |
| 4038 | return; |
| 4039 | |
| 4040 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4041 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4042 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 4043 | do_gfx_perf_limit_reasons = 1; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4044 | case INTEL_FAM6_HASWELL_X: /* HSX */ |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 4045 | do_core_perf_limit_reasons = 1; |
| 4046 | do_ring_perf_limit_reasons = 1; |
| 4047 | default: |
| 4048 | return; |
| 4049 | } |
| 4050 | } |
| 4051 | |
Artem Bityutskiy | ac980e1 | 2017-09-05 15:14:08 +0300 | [diff] [blame] | 4052 | void automatic_cstate_conversion_probe(unsigned int family, unsigned int model) |
| 4053 | { |
| 4054 | if (is_skx(family, model) || is_bdx(family, model)) |
| 4055 | has_automatic_cstate_conversion = 1; |
| 4056 | } |
| 4057 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4058 | int print_thermal(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 4059 | { |
| 4060 | unsigned long long msr; |
Len Brown | f4896fa5 | 2017-03-04 18:10:45 -0500 | [diff] [blame] | 4061 | unsigned int dts, dts2; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4062 | int cpu; |
| 4063 | |
| 4064 | if (!(do_dts || do_ptm)) |
| 4065 | return 0; |
| 4066 | |
| 4067 | cpu = t->cpu_id; |
| 4068 | |
| 4069 | /* DTS is per-core, no need to print for each thread */ |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 4070 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4071 | return 0; |
| 4072 | |
| 4073 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4074 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4075 | return -1; |
| 4076 | } |
| 4077 | |
| 4078 | if (do_ptm && (t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) { |
| 4079 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_STATUS, &msr)) |
| 4080 | return 0; |
| 4081 | |
| 4082 | dts = (msr >> 16) & 0x7F; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4083 | fprintf(outf, "cpu%d: MSR_IA32_PACKAGE_THERM_STATUS: 0x%08llx (%d C)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4084 | cpu, msr, tcc_activation_temp - dts); |
| 4085 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4086 | if (get_msr(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, &msr)) |
| 4087 | return 0; |
| 4088 | |
| 4089 | dts = (msr >> 16) & 0x7F; |
| 4090 | dts2 = (msr >> 8) & 0x7F; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4091 | fprintf(outf, "cpu%d: MSR_IA32_PACKAGE_THERM_INTERRUPT: 0x%08llx (%d C, %d C)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4092 | cpu, msr, tcc_activation_temp - dts, tcc_activation_temp - dts2); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4093 | } |
| 4094 | |
| 4095 | |
Len Brown | f4896fa5 | 2017-03-04 18:10:45 -0500 | [diff] [blame] | 4096 | if (do_dts && debug) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4097 | unsigned int resolution; |
| 4098 | |
| 4099 | if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr)) |
| 4100 | return 0; |
| 4101 | |
| 4102 | dts = (msr >> 16) & 0x7F; |
| 4103 | resolution = (msr >> 27) & 0xF; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4104 | fprintf(outf, "cpu%d: MSR_IA32_THERM_STATUS: 0x%08llx (%d C +/- %d)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4105 | cpu, msr, tcc_activation_temp - dts, resolution); |
| 4106 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4107 | if (get_msr(cpu, MSR_IA32_THERM_INTERRUPT, &msr)) |
| 4108 | return 0; |
| 4109 | |
| 4110 | dts = (msr >> 16) & 0x7F; |
| 4111 | dts2 = (msr >> 8) & 0x7F; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4112 | fprintf(outf, "cpu%d: MSR_IA32_THERM_INTERRUPT: 0x%08llx (%d C, %d C)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4113 | cpu, msr, tcc_activation_temp - dts, tcc_activation_temp - dts2); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4114 | } |
| 4115 | |
| 4116 | return 0; |
| 4117 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 4118 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4119 | void print_power_limit_msr(int cpu, unsigned long long msr, char *label) |
| 4120 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4121 | fprintf(outf, "cpu%d: %s: %sabled (%f Watts, %f sec, clamp %sabled)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4122 | cpu, label, |
| 4123 | ((msr >> 15) & 1) ? "EN" : "DIS", |
| 4124 | ((msr >> 0) & 0x7FFF) * rapl_power_units, |
| 4125 | (1.0 + (((msr >> 22) & 0x3)/4.0)) * (1 << ((msr >> 17) & 0x1F)) * rapl_time_units, |
| 4126 | (((msr >> 16) & 1) ? "EN" : "DIS")); |
| 4127 | |
| 4128 | return; |
| 4129 | } |
| 4130 | |
| 4131 | int print_rapl(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 4132 | { |
| 4133 | unsigned long long msr; |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 4134 | const char *msr_name; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4135 | int cpu; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4136 | |
| 4137 | if (!do_rapl) |
| 4138 | return 0; |
| 4139 | |
| 4140 | /* RAPL counters are per package, so print only for 1st thread/package */ |
| 4141 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 4142 | return 0; |
| 4143 | |
| 4144 | cpu = t->cpu_id; |
| 4145 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4146 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4147 | return -1; |
| 4148 | } |
| 4149 | |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 4150 | if (do_rapl & RAPL_AMD_F17H) { |
| 4151 | msr_name = "MSR_RAPL_PWR_UNIT"; |
| 4152 | if (get_msr(cpu, MSR_RAPL_PWR_UNIT, &msr)) |
| 4153 | return -1; |
| 4154 | } else { |
| 4155 | msr_name = "MSR_RAPL_POWER_UNIT"; |
| 4156 | if (get_msr(cpu, MSR_RAPL_POWER_UNIT, &msr)) |
| 4157 | return -1; |
| 4158 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4159 | |
Calvin Walton | 9392bd9 | 2018-08-17 12:34:41 -0400 | [diff] [blame] | 4160 | fprintf(outf, "cpu%d: %s: 0x%08llx (%f Watts, %f Joules, %f sec.)\n", cpu, msr_name, msr, |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4161 | rapl_power_units, rapl_energy_units, rapl_time_units); |
| 4162 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4163 | if (do_rapl & RAPL_PKG_POWER_INFO) { |
| 4164 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4165 | if (get_msr(cpu, MSR_PKG_POWER_INFO, &msr)) |
| 4166 | return -5; |
| 4167 | |
| 4168 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4169 | fprintf(outf, "cpu%d: MSR_PKG_POWER_INFO: 0x%08llx (%.0f W TDP, RAPL %.0f - %.0f W, %f sec.)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4170 | cpu, msr, |
| 4171 | ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 4172 | ((msr >> 16) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 4173 | ((msr >> 32) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 4174 | ((msr >> 48) & RAPL_TIME_GRANULARITY) * rapl_time_units); |
| 4175 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4176 | } |
| 4177 | if (do_rapl & RAPL_PKG) { |
| 4178 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4179 | if (get_msr(cpu, MSR_PKG_POWER_LIMIT, &msr)) |
| 4180 | return -9; |
| 4181 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4182 | fprintf(outf, "cpu%d: MSR_PKG_POWER_LIMIT: 0x%08llx (%slocked)\n", |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4183 | cpu, msr, (msr >> 63) & 1 ? "" : "UN"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4184 | |
| 4185 | print_power_limit_msr(cpu, msr, "PKG Limit #1"); |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4186 | fprintf(outf, "cpu%d: PKG Limit #2: %sabled (%f Watts, %f* sec, clamp %sabled)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4187 | cpu, |
| 4188 | ((msr >> 47) & 1) ? "EN" : "DIS", |
| 4189 | ((msr >> 32) & 0x7FFF) * rapl_power_units, |
| 4190 | (1.0 + (((msr >> 54) & 0x3)/4.0)) * (1 << ((msr >> 49) & 0x1F)) * rapl_time_units, |
| 4191 | ((msr >> 48) & 1) ? "EN" : "DIS"); |
| 4192 | } |
| 4193 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 4194 | if (do_rapl & RAPL_DRAM_POWER_INFO) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4195 | if (get_msr(cpu, MSR_DRAM_POWER_INFO, &msr)) |
| 4196 | return -6; |
| 4197 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4198 | fprintf(outf, "cpu%d: MSR_DRAM_POWER_INFO,: 0x%08llx (%.0f W TDP, RAPL %.0f - %.0f W, %f sec.)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4199 | cpu, msr, |
| 4200 | ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 4201 | ((msr >> 16) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 4202 | ((msr >> 32) & RAPL_POWER_GRANULARITY) * rapl_power_units, |
| 4203 | ((msr >> 48) & RAPL_TIME_GRANULARITY) * rapl_time_units); |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 4204 | } |
| 4205 | if (do_rapl & RAPL_DRAM) { |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4206 | if (get_msr(cpu, MSR_DRAM_POWER_LIMIT, &msr)) |
| 4207 | return -9; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4208 | fprintf(outf, "cpu%d: MSR_DRAM_POWER_LIMIT: 0x%08llx (%slocked)\n", |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4209 | cpu, msr, (msr >> 31) & 1 ? "" : "UN"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4210 | |
| 4211 | print_power_limit_msr(cpu, msr, "DRAM Limit"); |
| 4212 | } |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4213 | if (do_rapl & RAPL_CORE_POLICY) { |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4214 | if (get_msr(cpu, MSR_PP0_POLICY, &msr)) |
| 4215 | return -7; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4216 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4217 | fprintf(outf, "cpu%d: MSR_PP0_POLICY: %lld\n", cpu, msr & 0xF); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4218 | } |
Jacob Pan | 9148494 | 2016-06-16 09:48:20 -0700 | [diff] [blame] | 4219 | if (do_rapl & RAPL_CORES_POWER_LIMIT) { |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4220 | if (get_msr(cpu, MSR_PP0_POWER_LIMIT, &msr)) |
| 4221 | return -9; |
| 4222 | fprintf(outf, "cpu%d: MSR_PP0_POWER_LIMIT: 0x%08llx (%slocked)\n", |
| 4223 | cpu, msr, (msr >> 31) & 1 ? "" : "UN"); |
| 4224 | print_power_limit_msr(cpu, msr, "Cores Limit"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4225 | } |
| 4226 | if (do_rapl & RAPL_GFX) { |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4227 | if (get_msr(cpu, MSR_PP1_POLICY, &msr)) |
| 4228 | return -8; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4229 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4230 | fprintf(outf, "cpu%d: MSR_PP1_POLICY: %lld\n", cpu, msr & 0xF); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4231 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4232 | if (get_msr(cpu, MSR_PP1_POWER_LIMIT, &msr)) |
| 4233 | return -9; |
| 4234 | fprintf(outf, "cpu%d: MSR_PP1_POWER_LIMIT: 0x%08llx (%slocked)\n", |
| 4235 | cpu, msr, (msr >> 31) & 1 ? "" : "UN"); |
| 4236 | print_power_limit_msr(cpu, msr, "GFX Limit"); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4237 | } |
| 4238 | return 0; |
| 4239 | } |
| 4240 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4241 | /* |
| 4242 | * SNB adds support for additional MSRs: |
| 4243 | * |
| 4244 | * MSR_PKG_C7_RESIDENCY 0x000003fa |
| 4245 | * MSR_CORE_C7_RESIDENCY 0x000003fe |
| 4246 | * MSR_PKG_C2_RESIDENCY 0x0000060d |
| 4247 | */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4248 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4249 | int has_snb_msrs(unsigned int family, unsigned int model) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4250 | { |
| 4251 | if (!genuine_intel) |
| 4252 | return 0; |
| 4253 | |
| 4254 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4255 | case INTEL_FAM6_SANDYBRIDGE: |
| 4256 | case INTEL_FAM6_SANDYBRIDGE_X: |
| 4257 | case INTEL_FAM6_IVYBRIDGE: /* IVB */ |
| 4258 | case INTEL_FAM6_IVYBRIDGE_X: /* IVB Xeon */ |
| 4259 | case INTEL_FAM6_HASWELL_CORE: /* HSW */ |
| 4260 | case INTEL_FAM6_HASWELL_X: /* HSW */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4261 | case INTEL_FAM6_HASWELL_GT3E: /* HSW */ |
| 4262 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 4263 | case INTEL_FAM6_BROADWELL_GT3E: /* BDW */ |
| 4264 | case INTEL_FAM6_BROADWELL_X: /* BDX */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4265 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame] | 4266 | case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4267 | case INTEL_FAM6_SKYLAKE_X: /* SKX */ |
| 4268 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Peter Zijlstra | f2c4db1 | 2018-08-07 10:17:27 -0700 | [diff] [blame] | 4269 | case INTEL_FAM6_ATOM_GOLDMONT_PLUS: |
| 4270 | case INTEL_FAM6_ATOM_GOLDMONT_X: /* DNV */ |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4271 | return 1; |
| 4272 | } |
| 4273 | return 0; |
| 4274 | } |
| 4275 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4276 | /* |
| 4277 | * HSW adds support for additional MSRs: |
| 4278 | * |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 4279 | * MSR_PKG_C8_RESIDENCY 0x00000630 |
| 4280 | * MSR_PKG_C9_RESIDENCY 0x00000631 |
| 4281 | * MSR_PKG_C10_RESIDENCY 0x00000632 |
| 4282 | * |
| 4283 | * MSR_PKGC8_IRTL 0x00000633 |
| 4284 | * MSR_PKGC9_IRTL 0x00000634 |
| 4285 | * MSR_PKGC10_IRTL 0x00000635 |
| 4286 | * |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4287 | */ |
| 4288 | int has_hsw_msrs(unsigned int family, unsigned int model) |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 4289 | { |
| 4290 | if (!genuine_intel) |
| 4291 | return 0; |
| 4292 | |
| 4293 | switch (model) { |
Len Brown | f5a4c76 | 2018-12-14 16:26:37 -0500 | [diff] [blame] | 4294 | case INTEL_FAM6_HASWELL_CORE: |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4295 | case INTEL_FAM6_BROADWELL_CORE: /* BDW */ |
| 4296 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame] | 4297 | case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4298 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Peter Zijlstra | f2c4db1 | 2018-08-07 10:17:27 -0700 | [diff] [blame] | 4299 | case INTEL_FAM6_ATOM_GOLDMONT_PLUS: |
Kristen Carlson Accardi | ca58710 | 2012-11-21 05:22:43 -0800 | [diff] [blame] | 4300 | return 1; |
| 4301 | } |
| 4302 | return 0; |
| 4303 | } |
| 4304 | |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 4305 | /* |
| 4306 | * SKL adds support for additional MSRS: |
| 4307 | * |
| 4308 | * MSR_PKG_WEIGHTED_CORE_C0_RES 0x00000658 |
| 4309 | * MSR_PKG_ANY_CORE_C0_RES 0x00000659 |
| 4310 | * MSR_PKG_ANY_GFXE_C0_RES 0x0000065A |
| 4311 | * MSR_PKG_BOTH_CORE_GFXE_C0_RES 0x0000065B |
| 4312 | */ |
| 4313 | int has_skl_msrs(unsigned int family, unsigned int model) |
| 4314 | { |
| 4315 | if (!genuine_intel) |
| 4316 | return 0; |
| 4317 | |
| 4318 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4319 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame] | 4320 | case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ |
Len Brown | 0b2bb69 | 2015-03-26 00:50:30 -0400 | [diff] [blame] | 4321 | return 1; |
| 4322 | } |
| 4323 | return 0; |
| 4324 | } |
| 4325 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4326 | int is_slm(unsigned int family, unsigned int model) |
| 4327 | { |
| 4328 | if (!genuine_intel) |
| 4329 | return 0; |
| 4330 | switch (model) { |
Peter Zijlstra | f2c4db1 | 2018-08-07 10:17:27 -0700 | [diff] [blame] | 4331 | case INTEL_FAM6_ATOM_SILVERMONT: /* BYT */ |
| 4332 | case INTEL_FAM6_ATOM_SILVERMONT_X: /* AVN */ |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4333 | return 1; |
| 4334 | } |
| 4335 | return 0; |
| 4336 | } |
| 4337 | |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 4338 | int is_knl(unsigned int family, unsigned int model) |
| 4339 | { |
| 4340 | if (!genuine_intel) |
| 4341 | return 0; |
| 4342 | switch (model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4343 | case INTEL_FAM6_XEON_PHI_KNL: /* KNL */ |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 4344 | return 1; |
| 4345 | } |
| 4346 | return 0; |
| 4347 | } |
| 4348 | |
Srinivas Pandruvada | 997e539 | 2018-05-31 10:39:07 -0700 | [diff] [blame] | 4349 | int is_cnl(unsigned int family, unsigned int model) |
| 4350 | { |
| 4351 | if (!genuine_intel) |
| 4352 | return 0; |
| 4353 | |
| 4354 | switch (model) { |
| 4355 | case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ |
| 4356 | return 1; |
| 4357 | } |
| 4358 | |
| 4359 | return 0; |
| 4360 | } |
| 4361 | |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 4362 | unsigned int get_aperf_mperf_multiplier(unsigned int family, unsigned int model) |
| 4363 | { |
| 4364 | if (is_knl(family, model)) |
| 4365 | return 1024; |
| 4366 | return 1; |
| 4367 | } |
| 4368 | |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4369 | #define SLM_BCLK_FREQS 5 |
| 4370 | double slm_freq_table[SLM_BCLK_FREQS] = { 83.3, 100.0, 133.3, 116.7, 80.0}; |
| 4371 | |
| 4372 | double slm_bclk(void) |
| 4373 | { |
| 4374 | unsigned long long msr = 3; |
| 4375 | unsigned int i; |
| 4376 | double freq; |
| 4377 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 4378 | if (get_msr(base_cpu, MSR_FSB_FREQ, &msr)) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4379 | fprintf(outf, "SLM BCLK: unknown\n"); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4380 | |
| 4381 | i = msr & 0xf; |
| 4382 | if (i >= SLM_BCLK_FREQS) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4383 | fprintf(outf, "SLM BCLK[%d] invalid\n", i); |
Colin Ian King | 0a91e55 | 2016-04-25 13:03:15 +0100 | [diff] [blame] | 4384 | i = 3; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4385 | } |
| 4386 | freq = slm_freq_table[i]; |
| 4387 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4388 | if (!quiet) |
Len Brown | 8f6196c | 2017-01-07 22:40:23 -0500 | [diff] [blame] | 4389 | fprintf(outf, "SLM BCLK: %.1f Mhz\n", freq); |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4390 | |
| 4391 | return freq; |
| 4392 | } |
| 4393 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4394 | double discover_bclk(unsigned int family, unsigned int model) |
| 4395 | { |
Chrzaniuk, Hubert | 121b48b | 2016-02-10 16:35:17 +0100 | [diff] [blame] | 4396 | if (has_snb_msrs(family, model) || is_knl(family, model)) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4397 | return 100.00; |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4398 | else if (is_slm(family, model)) |
| 4399 | return slm_bclk(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4400 | else |
| 4401 | return 133.33; |
| 4402 | } |
| 4403 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4404 | /* |
| 4405 | * MSR_IA32_TEMPERATURE_TARGET indicates the temperature where |
| 4406 | * the Thermal Control Circuit (TCC) activates. |
| 4407 | * This is usually equal to tjMax. |
| 4408 | * |
| 4409 | * Older processors do not have this MSR, so there we guess, |
| 4410 | * but also allow cmdline over-ride with -T. |
| 4411 | * |
| 4412 | * Several MSR temperature values are in units of degrees-C |
| 4413 | * below this value, including the Digital Thermal Sensor (DTS), |
| 4414 | * Package Thermal Management Sensor (PTM), and thermal event thresholds. |
| 4415 | */ |
| 4416 | int set_temperature_target(struct thread_data *t, struct core_data *c, struct pkg_data *p) |
| 4417 | { |
| 4418 | unsigned long long msr; |
| 4419 | unsigned int target_c_local; |
| 4420 | int cpu; |
| 4421 | |
| 4422 | /* tcc_activation_temp is used only for dts or ptm */ |
| 4423 | if (!(do_dts || do_ptm)) |
| 4424 | return 0; |
| 4425 | |
| 4426 | /* this is a per-package concept */ |
| 4427 | if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE) || !(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE)) |
| 4428 | return 0; |
| 4429 | |
| 4430 | cpu = t->cpu_id; |
| 4431 | if (cpu_migrate(cpu)) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4432 | fprintf(outf, "Could not migrate to CPU %d\n", cpu); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4433 | return -1; |
| 4434 | } |
| 4435 | |
| 4436 | if (tcc_activation_temp_override != 0) { |
| 4437 | tcc_activation_temp = tcc_activation_temp_override; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4438 | fprintf(outf, "cpu%d: Using cmdline TCC Target (%d C)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4439 | cpu, tcc_activation_temp); |
| 4440 | return 0; |
| 4441 | } |
| 4442 | |
| 4443 | /* Temperature Target MSR is Nehalem and newer only */ |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4444 | if (!do_nhm_platform_info) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4445 | goto guess; |
| 4446 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 4447 | if (get_msr(base_cpu, MSR_IA32_TEMPERATURE_TARGET, &msr)) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4448 | goto guess; |
| 4449 | |
Jean Delvare | 3482124 | 2014-05-01 11:40:19 +0200 | [diff] [blame] | 4450 | target_c_local = (msr >> 16) & 0xFF; |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4451 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4452 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4453 | fprintf(outf, "cpu%d: MSR_IA32_TEMPERATURE_TARGET: 0x%08llx (%d C)\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4454 | cpu, msr, target_c_local); |
| 4455 | |
Jean Delvare | 3482124 | 2014-05-01 11:40:19 +0200 | [diff] [blame] | 4456 | if (!target_c_local) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4457 | goto guess; |
| 4458 | |
| 4459 | tcc_activation_temp = target_c_local; |
| 4460 | |
| 4461 | return 0; |
| 4462 | |
| 4463 | guess: |
| 4464 | tcc_activation_temp = TJMAX_DEFAULT; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4465 | fprintf(outf, "cpu%d: Guessing tjMax %d C, Please use -T to specify\n", |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4466 | cpu, tcc_activation_temp); |
| 4467 | |
| 4468 | return 0; |
| 4469 | } |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4470 | |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 4471 | void decode_feature_control_msr(void) |
| 4472 | { |
| 4473 | unsigned long long msr; |
| 4474 | |
| 4475 | if (!get_msr(base_cpu, MSR_IA32_FEATURE_CONTROL, &msr)) |
| 4476 | fprintf(outf, "cpu%d: MSR_IA32_FEATURE_CONTROL: 0x%08llx (%sLocked %s)\n", |
| 4477 | base_cpu, msr, |
| 4478 | msr & FEATURE_CONTROL_LOCKED ? "" : "UN-", |
| 4479 | msr & (1 << 18) ? "SGX" : ""); |
| 4480 | } |
| 4481 | |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4482 | void decode_misc_enable_msr(void) |
| 4483 | { |
| 4484 | unsigned long long msr; |
| 4485 | |
Len Brown | f26b151 | 2017-06-23 20:45:54 -0700 | [diff] [blame] | 4486 | if (!genuine_intel) |
| 4487 | return; |
| 4488 | |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4489 | if (!get_msr(base_cpu, MSR_IA32_MISC_ENABLE, &msr)) |
Len Brown | e651262 | 2017-01-11 23:17:24 -0500 | [diff] [blame] | 4490 | fprintf(outf, "cpu%d: MSR_IA32_MISC_ENABLE: 0x%08llx (%sTCC %sEIST %sMWAIT %sPREFETCH %sTURBO)\n", |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4491 | base_cpu, msr, |
Len Brown | e651262 | 2017-01-11 23:17:24 -0500 | [diff] [blame] | 4492 | msr & MSR_IA32_MISC_ENABLE_TM1 ? "" : "No-", |
| 4493 | msr & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP ? "" : "No-", |
Len Brown | fd3933c | 2017-11-08 23:15:42 -0500 | [diff] [blame] | 4494 | msr & MSR_IA32_MISC_ENABLE_MWAIT ? "" : "No-", |
Len Brown | e651262 | 2017-01-11 23:17:24 -0500 | [diff] [blame] | 4495 | msr & MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE ? "No-" : "", |
| 4496 | msr & MSR_IA32_MISC_ENABLE_TURBO_DISABLE ? "No-" : ""); |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4497 | } |
| 4498 | |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 4499 | void decode_misc_feature_control(void) |
| 4500 | { |
| 4501 | unsigned long long msr; |
| 4502 | |
| 4503 | if (!has_misc_feature_control) |
| 4504 | return; |
| 4505 | |
| 4506 | if (!get_msr(base_cpu, MSR_MISC_FEATURE_CONTROL, &msr)) |
| 4507 | fprintf(outf, "cpu%d: MSR_MISC_FEATURE_CONTROL: 0x%08llx (%sL2-Prefetch %sL2-Prefetch-pair %sL1-Prefetch %sL1-IP-Prefetch)\n", |
| 4508 | base_cpu, msr, |
| 4509 | msr & (0 << 0) ? "No-" : "", |
| 4510 | msr & (1 << 0) ? "No-" : "", |
| 4511 | msr & (2 << 0) ? "No-" : "", |
| 4512 | msr & (3 << 0) ? "No-" : ""); |
| 4513 | } |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 4514 | /* |
| 4515 | * Decode MSR_MISC_PWR_MGMT |
| 4516 | * |
| 4517 | * Decode the bits according to the Nehalem documentation |
| 4518 | * bit[0] seems to continue to have same meaning going forward |
| 4519 | * bit[1] less so... |
| 4520 | */ |
| 4521 | void decode_misc_pwr_mgmt_msr(void) |
| 4522 | { |
| 4523 | unsigned long long msr; |
| 4524 | |
| 4525 | if (!do_nhm_platform_info) |
| 4526 | return; |
| 4527 | |
Len Brown | cf4cbe5 | 2017-01-01 13:08:33 -0500 | [diff] [blame] | 4528 | if (no_MSR_MISC_PWR_MGMT) |
| 4529 | return; |
| 4530 | |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 4531 | if (!get_msr(base_cpu, MSR_MISC_PWR_MGMT, &msr)) |
Srinivas Pandruvada | ddadb8a | 2016-11-11 14:29:48 -0800 | [diff] [blame] | 4532 | fprintf(outf, "cpu%d: MSR_MISC_PWR_MGMT: 0x%08llx (%sable-EIST_Coordination %sable-EPB %sable-OOB)\n", |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 4533 | base_cpu, msr, |
| 4534 | msr & (1 << 0) ? "DIS" : "EN", |
Srinivas Pandruvada | ddadb8a | 2016-11-11 14:29:48 -0800 | [diff] [blame] | 4535 | msr & (1 << 1) ? "EN" : "DIS", |
| 4536 | msr & (1 << 8) ? "EN" : "DIS"); |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 4537 | } |
Len Brown | 71616c8 | 2017-01-07 22:37:48 -0500 | [diff] [blame] | 4538 | /* |
| 4539 | * Decode MSR_CC6_DEMOTION_POLICY_CONFIG, MSR_MC6_DEMOTION_POLICY_CONFIG |
| 4540 | * |
| 4541 | * This MSRs are present on Silvermont processors, |
| 4542 | * Intel Atom processor E3000 series (Baytrail), and friends. |
| 4543 | */ |
| 4544 | void decode_c6_demotion_policy_msr(void) |
| 4545 | { |
| 4546 | unsigned long long msr; |
| 4547 | |
| 4548 | if (!get_msr(base_cpu, MSR_CC6_DEMOTION_POLICY_CONFIG, &msr)) |
| 4549 | fprintf(outf, "cpu%d: MSR_CC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-CC6-Demotion)\n", |
| 4550 | base_cpu, msr, msr & (1 << 0) ? "EN" : "DIS"); |
| 4551 | |
| 4552 | if (!get_msr(base_cpu, MSR_MC6_DEMOTION_POLICY_CONFIG, &msr)) |
| 4553 | fprintf(outf, "cpu%d: MSR_MC6_DEMOTION_POLICY_CONFIG: 0x%08llx (%sable-MC6-Demotion)\n", |
| 4554 | base_cpu, msr, msr & (1 << 0) ? "EN" : "DIS"); |
| 4555 | } |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4556 | |
Len Brown | f5a4c76 | 2018-12-14 16:26:37 -0500 | [diff] [blame] | 4557 | /* |
| 4558 | * When models are the same, for the purpose of turbostat, reuse |
| 4559 | */ |
| 4560 | unsigned int intel_model_duplicates(unsigned int model) |
| 4561 | { |
| 4562 | |
| 4563 | switch(model) { |
| 4564 | case INTEL_FAM6_NEHALEM_EP: /* Core i7, Xeon 5500 series - Bloomfield, Gainstown NHM-EP */ |
| 4565 | case INTEL_FAM6_NEHALEM: /* Core i7 and i5 Processor - Clarksfield, Lynnfield, Jasper Forest */ |
| 4566 | case 0x1F: /* Core i7 and i5 Processor - Nehalem */ |
| 4567 | case INTEL_FAM6_WESTMERE: /* Westmere Client - Clarkdale, Arrandale */ |
| 4568 | case INTEL_FAM6_WESTMERE_EP: /* Westmere EP - Gulftown */ |
| 4569 | return INTEL_FAM6_NEHALEM; |
| 4570 | |
| 4571 | case INTEL_FAM6_NEHALEM_EX: /* Nehalem-EX Xeon - Beckton */ |
| 4572 | case INTEL_FAM6_WESTMERE_EX: /* Westmere-EX Xeon - Eagleton */ |
| 4573 | return INTEL_FAM6_NEHALEM_EX; |
| 4574 | |
| 4575 | case INTEL_FAM6_XEON_PHI_KNM: |
| 4576 | return INTEL_FAM6_XEON_PHI_KNL; |
| 4577 | |
| 4578 | case INTEL_FAM6_HASWELL_ULT: |
| 4579 | return INTEL_FAM6_HASWELL_CORE; |
| 4580 | |
| 4581 | case INTEL_FAM6_BROADWELL_X: |
| 4582 | case INTEL_FAM6_BROADWELL_XEON_D: /* BDX-DE */ |
| 4583 | return INTEL_FAM6_BROADWELL_X; |
| 4584 | |
| 4585 | case INTEL_FAM6_SKYLAKE_MOBILE: |
| 4586 | case INTEL_FAM6_SKYLAKE_DESKTOP: |
| 4587 | case INTEL_FAM6_KABYLAKE_MOBILE: |
| 4588 | case INTEL_FAM6_KABYLAKE_DESKTOP: |
| 4589 | return INTEL_FAM6_SKYLAKE_MOBILE; |
Len Brown | 937807d | 2019-03-19 19:09:07 -0400 | [diff] [blame] | 4590 | |
| 4591 | case INTEL_FAM6_ICELAKE_MOBILE: |
| 4592 | return INTEL_FAM6_CANNONLAKE_MOBILE; |
Len Brown | f5a4c76 | 2018-12-14 16:26:37 -0500 | [diff] [blame] | 4593 | } |
| 4594 | return model; |
| 4595 | } |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 4596 | void process_cpuid() |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4597 | { |
Len Brown | 3404155 | 2018-08-07 20:22:28 -0400 | [diff] [blame] | 4598 | unsigned int eax, ebx, ecx, edx; |
| 4599 | unsigned int fms, family, model, stepping, ecx_flags, edx_flags; |
Len Brown | b3a34e9 | 2017-01-21 00:50:08 -0500 | [diff] [blame] | 4600 | unsigned int has_turbo; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4601 | |
| 4602 | eax = ebx = ecx = edx = 0; |
| 4603 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4604 | __cpuid(0, max_level, ebx, ecx, edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4605 | |
Len Brown | 3404155 | 2018-08-07 20:22:28 -0400 | [diff] [blame] | 4606 | if (ebx == 0x756e6547 && ecx == 0x6c65746e && edx == 0x49656e69) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4607 | genuine_intel = 1; |
Len Brown | 3404155 | 2018-08-07 20:22:28 -0400 | [diff] [blame] | 4608 | else if (ebx == 0x68747541 && ecx == 0x444d4163 && edx == 0x69746e65) |
| 4609 | authentic_amd = 1; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4610 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4611 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4612 | fprintf(outf, "CPUID(0): %.4s%.4s%.4s ", |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4613 | (char *)&ebx, (char *)&edx, (char *)&ecx); |
| 4614 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4615 | __cpuid(1, fms, ebx, ecx, edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4616 | family = (fms >> 8) & 0xf; |
| 4617 | model = (fms >> 4) & 0xf; |
| 4618 | stepping = fms & 0xf; |
Calvin Walton | 5aa3d1a | 2018-07-27 07:50:53 -0400 | [diff] [blame] | 4619 | if (family == 0xf) |
| 4620 | family += (fms >> 20) & 0xff; |
| 4621 | if (family >= 6) |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4622 | model += ((fms >> 16) & 0xf) << 4; |
Len Brown | 3404155 | 2018-08-07 20:22:28 -0400 | [diff] [blame] | 4623 | ecx_flags = ecx; |
| 4624 | edx_flags = edx; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4625 | |
| 4626 | /* |
| 4627 | * check max extended function levels of CPUID. |
| 4628 | * This is needed to check for invariant TSC. |
| 4629 | * This check is valid for both Intel and AMD. |
| 4630 | */ |
| 4631 | ebx = ecx = edx = 0; |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4632 | __cpuid(0x80000000, max_extended_level, ebx, ecx, edx); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4633 | |
Len Brown | 3404155 | 2018-08-07 20:22:28 -0400 | [diff] [blame] | 4634 | if (!quiet) { |
| 4635 | fprintf(outf, "0x%x CPUID levels; 0x%x xlevels; family:model:stepping 0x%x:%x:%x (%d:%d:%d)\n", |
| 4636 | max_level, max_extended_level, family, model, stepping, family, model, stepping); |
| 4637 | fprintf(outf, "CPUID(1): %s %s %s %s %s %s %s %s %s %s\n", |
| 4638 | ecx_flags & (1 << 0) ? "SSE3" : "-", |
| 4639 | ecx_flags & (1 << 3) ? "MONITOR" : "-", |
| 4640 | ecx_flags & (1 << 6) ? "SMX" : "-", |
| 4641 | ecx_flags & (1 << 7) ? "EIST" : "-", |
| 4642 | ecx_flags & (1 << 8) ? "TM2" : "-", |
| 4643 | edx_flags & (1 << 4) ? "TSC" : "-", |
| 4644 | edx_flags & (1 << 5) ? "MSR" : "-", |
| 4645 | edx_flags & (1 << 22) ? "ACPI-TM" : "-", |
| 4646 | edx_flags & (1 << 28) ? "HT" : "-", |
| 4647 | edx_flags & (1 << 29) ? "TM" : "-"); |
| 4648 | } |
Len Brown | f5a4c76 | 2018-12-14 16:26:37 -0500 | [diff] [blame] | 4649 | if (genuine_intel) |
| 4650 | model = intel_model_duplicates(model); |
Len Brown | 3404155 | 2018-08-07 20:22:28 -0400 | [diff] [blame] | 4651 | |
| 4652 | if (!(edx_flags & (1 << 5))) |
| 4653 | errx(1, "CPUID: no MSR"); |
| 4654 | |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 4655 | if (max_extended_level >= 0x80000007) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4656 | |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4657 | /* |
| 4658 | * Non-Stop TSC is advertised by CPUID.EAX=0x80000007: EDX.bit8 |
| 4659 | * this check is valid for both Intel and AMD |
| 4660 | */ |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4661 | __cpuid(0x80000007, eax, ebx, ecx, edx); |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4662 | has_invariant_tsc = edx & (1 << 8); |
| 4663 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4664 | |
| 4665 | /* |
| 4666 | * APERF/MPERF is advertised by CPUID.EAX=0x6: ECX.bit0 |
| 4667 | * this check is valid for both Intel and AMD |
| 4668 | */ |
| 4669 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4670 | __cpuid(0x6, eax, ebx, ecx, edx); |
Thomas Renninger | 8209e05 | 2011-01-21 15:11:19 +0100 | [diff] [blame] | 4671 | has_aperf = ecx & (1 << 0); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4672 | if (has_aperf) { |
| 4673 | BIC_PRESENT(BIC_Avg_MHz); |
| 4674 | BIC_PRESENT(BIC_Busy); |
| 4675 | BIC_PRESENT(BIC_Bzy_MHz); |
| 4676 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4677 | do_dts = eax & (1 << 0); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4678 | if (do_dts) |
| 4679 | BIC_PRESENT(BIC_CoreTmp); |
Len Brown | b3a34e9 | 2017-01-21 00:50:08 -0500 | [diff] [blame] | 4680 | has_turbo = eax & (1 << 1); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4681 | do_ptm = eax & (1 << 6); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4682 | if (do_ptm) |
| 4683 | BIC_PRESENT(BIC_PkgTmp); |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4684 | has_hwp = eax & (1 << 7); |
| 4685 | has_hwp_notify = eax & (1 << 8); |
| 4686 | has_hwp_activity_window = eax & (1 << 9); |
| 4687 | has_hwp_epp = eax & (1 << 10); |
| 4688 | has_hwp_pkg = eax & (1 << 11); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4689 | has_epb = ecx & (1 << 3); |
| 4690 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4691 | if (!quiet) |
Len Brown | b3a34e9 | 2017-01-21 00:50:08 -0500 | [diff] [blame] | 4692 | fprintf(outf, "CPUID(6): %sAPERF, %sTURBO, %sDTS, %sPTM, %sHWP, " |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4693 | "%sHWPnotify, %sHWPwindow, %sHWPepp, %sHWPpkg, %sEPB\n", |
| 4694 | has_aperf ? "" : "No-", |
Len Brown | b3a34e9 | 2017-01-21 00:50:08 -0500 | [diff] [blame] | 4695 | has_turbo ? "" : "No-", |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 4696 | do_dts ? "" : "No-", |
| 4697 | do_ptm ? "" : "No-", |
| 4698 | has_hwp ? "" : "No-", |
| 4699 | has_hwp_notify ? "" : "No-", |
| 4700 | has_hwp_activity_window ? "" : "No-", |
| 4701 | has_hwp_epp ? "" : "No-", |
| 4702 | has_hwp_pkg ? "" : "No-", |
| 4703 | has_epb ? "" : "No-"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4704 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4705 | if (!quiet) |
Len Brown | 69807a6 | 2015-11-21 12:22:47 -0500 | [diff] [blame] | 4706 | decode_misc_enable_msr(); |
| 4707 | |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 4708 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4709 | if (max_level >= 0x7 && !quiet) { |
Len Brown | aa8d8cc | 2016-03-11 13:26:03 -0500 | [diff] [blame] | 4710 | int has_sgx; |
| 4711 | |
| 4712 | ecx = 0; |
| 4713 | |
| 4714 | __cpuid_count(0x7, 0, eax, ebx, ecx, edx); |
| 4715 | |
| 4716 | has_sgx = ebx & (1 << 2); |
| 4717 | fprintf(outf, "CPUID(7): %sSGX\n", has_sgx ? "" : "No-"); |
| 4718 | |
| 4719 | if (has_sgx) |
| 4720 | decode_feature_control_msr(); |
| 4721 | } |
| 4722 | |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 4723 | if (max_level >= 0x15) { |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4724 | unsigned int eax_crystal; |
| 4725 | unsigned int ebx_tsc; |
| 4726 | |
| 4727 | /* |
| 4728 | * CPUID 15H TSC/Crystal ratio, possibly Crystal Hz |
| 4729 | */ |
| 4730 | eax_crystal = ebx_tsc = crystal_hz = edx = 0; |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4731 | __cpuid(0x15, eax_crystal, ebx_tsc, crystal_hz, edx); |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4732 | |
| 4733 | if (ebx_tsc != 0) { |
| 4734 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4735 | if (!quiet && (ebx != 0)) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4736 | fprintf(outf, "CPUID(0x15): eax_crystal: %d ebx_tsc: %d ecx_crystal_hz: %d\n", |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4737 | eax_crystal, ebx_tsc, crystal_hz); |
| 4738 | |
| 4739 | if (crystal_hz == 0) |
| 4740 | switch(model) { |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4741 | case INTEL_FAM6_SKYLAKE_MOBILE: /* SKL */ |
Len Brown | e8efbc8 | 2016-04-06 17:15:57 -0400 | [diff] [blame] | 4742 | crystal_hz = 24000000; /* 24.0 MHz */ |
| 4743 | break; |
Peter Zijlstra | f2c4db1 | 2018-08-07 10:17:27 -0700 | [diff] [blame] | 4744 | case INTEL_FAM6_ATOM_GOLDMONT_X: /* DNV */ |
Len Brown | ec53e59 | 2016-04-06 17:15:58 -0400 | [diff] [blame] | 4745 | crystal_hz = 25000000; /* 25.0 MHz */ |
| 4746 | break; |
Len Brown | 869ce69e | 2016-06-16 23:22:37 -0400 | [diff] [blame] | 4747 | case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ |
Peter Zijlstra | f2c4db1 | 2018-08-07 10:17:27 -0700 | [diff] [blame] | 4748 | case INTEL_FAM6_ATOM_GOLDMONT_PLUS: |
Len Brown | e8efbc8 | 2016-04-06 17:15:57 -0400 | [diff] [blame] | 4749 | crystal_hz = 19200000; /* 19.2 MHz */ |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4750 | break; |
| 4751 | default: |
| 4752 | crystal_hz = 0; |
| 4753 | } |
| 4754 | |
| 4755 | if (crystal_hz) { |
| 4756 | tsc_hz = (unsigned long long) crystal_hz * ebx_tsc / eax_crystal; |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4757 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4758 | fprintf(outf, "TSC: %lld MHz (%d Hz * %d / %d / 1000000)\n", |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4759 | tsc_hz / 1000000, crystal_hz, ebx_tsc, eax_crystal); |
| 4760 | } |
| 4761 | } |
| 4762 | } |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 4763 | if (max_level >= 0x16) { |
| 4764 | unsigned int base_mhz, max_mhz, bus_mhz, edx; |
| 4765 | |
| 4766 | /* |
| 4767 | * CPUID 16H Base MHz, Max MHz, Bus MHz |
| 4768 | */ |
| 4769 | base_mhz = max_mhz = bus_mhz = edx = 0; |
| 4770 | |
Len Brown | 5aea2f7 | 2016-03-13 03:14:35 -0400 | [diff] [blame] | 4771 | __cpuid(0x16, base_mhz, max_mhz, bus_mhz, edx); |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4772 | if (!quiet) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4773 | fprintf(outf, "CPUID(0x16): base_mhz: %d max_mhz: %d bus_mhz: %d\n", |
Len Brown | 61a87ba | 2015-11-23 02:30:51 -0500 | [diff] [blame] | 4774 | base_mhz, max_mhz, bus_mhz); |
| 4775 | } |
Len Brown | 8a5bdf4 | 2015-04-01 21:02:57 -0400 | [diff] [blame] | 4776 | |
Hubert Chrzaniuk | b2b34df | 2015-09-14 13:31:00 +0200 | [diff] [blame] | 4777 | if (has_aperf) |
| 4778 | aperf_mperf_multiplier = get_aperf_mperf_multiplier(family, model); |
| 4779 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4780 | BIC_PRESENT(BIC_IRQ); |
| 4781 | BIC_PRESENT(BIC_TSC_MHz); |
| 4782 | |
| 4783 | if (probe_nhm_msrs(family, model)) { |
| 4784 | do_nhm_platform_info = 1; |
| 4785 | BIC_PRESENT(BIC_CPU_c1); |
| 4786 | BIC_PRESENT(BIC_CPU_c3); |
| 4787 | BIC_PRESENT(BIC_CPU_c6); |
| 4788 | BIC_PRESENT(BIC_SMI); |
| 4789 | } |
Len Brown | d789944 | 2015-01-23 00:12:33 -0500 | [diff] [blame] | 4790 | do_snb_cstates = has_snb_msrs(family, model); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4791 | |
| 4792 | if (do_snb_cstates) |
| 4793 | BIC_PRESENT(BIC_CPU_c7); |
| 4794 | |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 4795 | do_irtl_snb = has_snb_msrs(family, model); |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4796 | if (do_snb_cstates && (pkg_cstate_limit >= PCL__2)) |
| 4797 | BIC_PRESENT(BIC_Pkgpc2); |
| 4798 | if (pkg_cstate_limit >= PCL__3) |
| 4799 | BIC_PRESENT(BIC_Pkgpc3); |
| 4800 | if (pkg_cstate_limit >= PCL__6) |
| 4801 | BIC_PRESENT(BIC_Pkgpc6); |
| 4802 | if (do_snb_cstates && (pkg_cstate_limit >= PCL__7)) |
| 4803 | BIC_PRESENT(BIC_Pkgpc7); |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 4804 | if (has_slv_msrs(family, model)) { |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4805 | BIC_NOT_PRESENT(BIC_Pkgpc2); |
| 4806 | BIC_NOT_PRESENT(BIC_Pkgpc3); |
| 4807 | BIC_PRESENT(BIC_Pkgpc6); |
| 4808 | BIC_NOT_PRESENT(BIC_Pkgpc7); |
Len Brown | 0539ba11 | 2017-02-10 00:27:20 -0500 | [diff] [blame] | 4809 | BIC_PRESENT(BIC_Mod_c6); |
| 4810 | use_c1_residency_msr = 1; |
| 4811 | } |
Len Brown | 7170a37 | 2017-01-27 02:13:27 -0500 | [diff] [blame] | 4812 | if (is_dnv(family, model)) { |
| 4813 | BIC_PRESENT(BIC_CPU_c1); |
| 4814 | BIC_NOT_PRESENT(BIC_CPU_c3); |
| 4815 | BIC_NOT_PRESENT(BIC_Pkgpc3); |
| 4816 | BIC_NOT_PRESENT(BIC_CPU_c7); |
| 4817 | BIC_NOT_PRESENT(BIC_Pkgpc7); |
| 4818 | use_c1_residency_msr = 1; |
| 4819 | } |
Len Brown | 34c76197 | 2017-01-27 02:36:41 -0500 | [diff] [blame] | 4820 | if (is_skx(family, model)) { |
| 4821 | BIC_NOT_PRESENT(BIC_CPU_c3); |
| 4822 | BIC_NOT_PRESENT(BIC_Pkgpc3); |
| 4823 | BIC_NOT_PRESENT(BIC_CPU_c7); |
| 4824 | BIC_NOT_PRESENT(BIC_Pkgpc7); |
| 4825 | } |
Len Brown | ade0eba | 2017-02-10 01:56:47 -0500 | [diff] [blame] | 4826 | if (is_bdx(family, model)) { |
| 4827 | BIC_NOT_PRESENT(BIC_CPU_c7); |
| 4828 | BIC_NOT_PRESENT(BIC_Pkgpc7); |
| 4829 | } |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 4830 | if (has_hsw_msrs(family, model)) { |
| 4831 | BIC_PRESENT(BIC_Pkgpc8); |
| 4832 | BIC_PRESENT(BIC_Pkgpc9); |
| 4833 | BIC_PRESENT(BIC_Pkgpc10); |
| 4834 | } |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 4835 | do_irtl_hsw = has_hsw_msrs(family, model); |
Len Brown | a99d873 | 2017-05-20 20:11:55 -0400 | [diff] [blame] | 4836 | if (has_skl_msrs(family, model)) { |
| 4837 | BIC_PRESENT(BIC_Totl_c0); |
| 4838 | BIC_PRESENT(BIC_Any_c0); |
| 4839 | BIC_PRESENT(BIC_GFX_c0); |
| 4840 | BIC_PRESENT(BIC_CPUGFX); |
| 4841 | } |
Len Brown | 144b44b | 2013-11-09 00:30:16 -0500 | [diff] [blame] | 4842 | do_slm_cstates = is_slm(family, model); |
Dasaratharaman Chandramouli | fb5d432 | 2015-05-20 09:49:34 -0700 | [diff] [blame] | 4843 | do_knl_cstates = is_knl(family, model); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4844 | |
Len Brown | 31a1f15 | 2019-03-19 17:55:06 -0400 | [diff] [blame] | 4845 | if (do_slm_cstates || do_knl_cstates || is_cnl(family, model)) |
Len Brown | 562855e | 2019-03-19 17:52:32 -0400 | [diff] [blame] | 4846 | BIC_NOT_PRESENT(BIC_CPU_c3); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4847 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4848 | if (!quiet) |
Len Brown | f005731 | 2015-12-03 01:35:36 -0500 | [diff] [blame] | 4849 | decode_misc_pwr_mgmt_msr(); |
| 4850 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4851 | if (!quiet && has_slv_msrs(family, model)) |
Len Brown | 71616c8 | 2017-01-07 22:37:48 -0500 | [diff] [blame] | 4852 | decode_c6_demotion_policy_msr(); |
| 4853 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4854 | rapl_probe(family, model); |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 4855 | perf_limit_reasons_probe(family, model); |
Artem Bityutskiy | ac980e1 | 2017-09-05 15:14:08 +0300 | [diff] [blame] | 4856 | automatic_cstate_conversion_probe(family, model); |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4857 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4858 | if (!quiet) |
Colin Ian King | 1b69317 | 2016-03-02 13:50:25 +0000 | [diff] [blame] | 4859 | dump_cstate_pstate_config_info(family, model); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 4860 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4861 | if (!quiet) |
| 4862 | dump_sysfs_cstate_config(); |
Len Brown | 7293fcc | 2017-02-22 00:11:12 -0500 | [diff] [blame] | 4863 | if (!quiet) |
| 4864 | dump_sysfs_pstate_config(); |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 4865 | |
Len Brown | a2b7b74 | 2015-09-26 00:12:38 -0400 | [diff] [blame] | 4866 | if (has_skl_msrs(family, model)) |
| 4867 | calculate_tsc_tweak(); |
| 4868 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4869 | if (!access("/sys/class/drm/card0/power/rc6_residency_ms", R_OK)) |
| 4870 | BIC_PRESENT(BIC_GFX_rc6); |
Len Brown | fdf676e | 2016-02-27 01:28:12 -0500 | [diff] [blame] | 4871 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4872 | if (!access("/sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz", R_OK)) |
| 4873 | BIC_PRESENT(BIC_GFXMHz); |
Len Brown | 27d4735 | 2016-02-27 00:37:54 -0500 | [diff] [blame] | 4874 | |
Len Brown | be0e54c | 2018-06-01 12:35:53 -0400 | [diff] [blame] | 4875 | if (!access("/sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us", R_OK)) |
| 4876 | BIC_PRESENT(BIC_CPU_LPI); |
| 4877 | else |
| 4878 | BIC_NOT_PRESENT(BIC_CPU_LPI); |
| 4879 | |
| 4880 | if (!access("/sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us", R_OK)) |
| 4881 | BIC_PRESENT(BIC_SYS_LPI); |
| 4882 | else |
| 4883 | BIC_NOT_PRESENT(BIC_SYS_LPI); |
| 4884 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 4885 | if (!quiet) |
Len Brown | 33148d6 | 2017-01-21 01:26:16 -0500 | [diff] [blame] | 4886 | decode_misc_feature_control(); |
| 4887 | |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 4888 | return; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4889 | } |
| 4890 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 4891 | /* |
| 4892 | * in /dev/cpu/ return success for names that are numbers |
| 4893 | * ie. filter out ".", "..", "microcode". |
| 4894 | */ |
| 4895 | int dir_filter(const struct dirent *dirp) |
| 4896 | { |
| 4897 | if (isdigit(dirp->d_name[0])) |
| 4898 | return 1; |
| 4899 | else |
| 4900 | return 0; |
| 4901 | } |
| 4902 | |
| 4903 | int open_dev_cpu_msr(int dummy1) |
| 4904 | { |
| 4905 | return 0; |
| 4906 | } |
| 4907 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4908 | void topology_probe() |
| 4909 | { |
| 4910 | int i; |
| 4911 | int max_core_id = 0; |
| 4912 | int max_package_id = 0; |
Len Brown | 6de68fe | 2019-02-14 19:17:40 -0800 | [diff] [blame] | 4913 | int max_die_id = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4914 | int max_siblings = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4915 | |
| 4916 | /* Initialize num_cpus, max_cpu_num */ |
Prarit Bhargava | 843c579 | 2018-06-01 10:04:28 -0400 | [diff] [blame] | 4917 | set_max_cpu_num(); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4918 | topo.num_cpus = 0; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4919 | for_all_proc_cpus(count_cpus); |
| 4920 | if (!summary_only && topo.num_cpus > 1) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 4921 | BIC_PRESENT(BIC_CPU); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4922 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4923 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4924 | fprintf(outf, "num_cpus %d max_cpu_num %d\n", topo.num_cpus, topo.max_cpu_num); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4925 | |
| 4926 | cpus = calloc(1, (topo.max_cpu_num + 1) * sizeof(struct cpu_topology)); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4927 | if (cpus == NULL) |
| 4928 | err(1, "calloc cpus"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4929 | |
| 4930 | /* |
| 4931 | * Allocate and initialize cpu_present_set |
| 4932 | */ |
| 4933 | cpu_present_set = CPU_ALLOC((topo.max_cpu_num + 1)); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4934 | if (cpu_present_set == NULL) |
| 4935 | err(3, "CPU_ALLOC"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4936 | cpu_present_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); |
| 4937 | CPU_ZERO_S(cpu_present_setsize, cpu_present_set); |
| 4938 | for_all_proc_cpus(mark_cpu_present); |
| 4939 | |
| 4940 | /* |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 4941 | * Validate that all cpus in cpu_subset are also in cpu_present_set |
| 4942 | */ |
| 4943 | for (i = 0; i < CPU_SUBSET_MAXCPUS; ++i) { |
| 4944 | if (CPU_ISSET_S(i, cpu_subset_size, cpu_subset)) |
| 4945 | if (!CPU_ISSET_S(i, cpu_present_setsize, cpu_present_set)) |
| 4946 | err(1, "cpu%d not present", i); |
| 4947 | } |
| 4948 | |
| 4949 | /* |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4950 | * Allocate and initialize cpu_affinity_set |
| 4951 | */ |
| 4952 | cpu_affinity_set = CPU_ALLOC((topo.max_cpu_num + 1)); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 4953 | if (cpu_affinity_set == NULL) |
| 4954 | err(3, "CPU_ALLOC"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4955 | cpu_affinity_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); |
| 4956 | CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); |
| 4957 | |
Prarit Bhargava | 8cb48b3 | 2018-06-01 10:04:31 -0400 | [diff] [blame] | 4958 | for_all_proc_cpus(init_thread_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4959 | |
| 4960 | /* |
| 4961 | * For online cpus |
| 4962 | * find max_core_id, max_package_id |
| 4963 | */ |
| 4964 | for (i = 0; i <= topo.max_cpu_num; ++i) { |
| 4965 | int siblings; |
| 4966 | |
| 4967 | if (cpu_is_not_present(i)) { |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 4968 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 4969 | fprintf(outf, "cpu%d NOT PRESENT\n", i); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4970 | continue; |
| 4971 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4972 | |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 4973 | cpus[i].logical_cpu_id = i; |
| 4974 | |
| 4975 | /* get package information */ |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4976 | cpus[i].physical_package_id = get_physical_package_id(i); |
| 4977 | if (cpus[i].physical_package_id > max_package_id) |
| 4978 | max_package_id = cpus[i].physical_package_id; |
| 4979 | |
Len Brown | 6de68fe | 2019-02-14 19:17:40 -0800 | [diff] [blame] | 4980 | /* get die information */ |
| 4981 | cpus[i].die_id = get_die_id(i); |
| 4982 | if (cpus[i].die_id > max_die_id) |
| 4983 | max_die_id = cpus[i].die_id; |
| 4984 | |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 4985 | /* get numa node information */ |
Prarit Bhargava | ef60574 | 2018-06-01 10:04:30 -0400 | [diff] [blame] | 4986 | cpus[i].physical_node_id = get_physical_node_id(&cpus[i]); |
| 4987 | if (cpus[i].physical_node_id > topo.max_node_num) |
| 4988 | topo.max_node_num = cpus[i].physical_node_id; |
Len Brown | 0e2d8f0 | 2018-06-01 22:08:58 -0400 | [diff] [blame] | 4989 | |
| 4990 | /* get core information */ |
| 4991 | cpus[i].physical_core_id = get_core_id(i); |
| 4992 | if (cpus[i].physical_core_id > max_core_id) |
| 4993 | max_core_id = cpus[i].physical_core_id; |
| 4994 | |
| 4995 | /* get thread information */ |
| 4996 | siblings = get_thread_siblings(&cpus[i]); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 4997 | if (siblings > max_siblings) |
| 4998 | max_siblings = siblings; |
Artem Bityutskiy | 4f206a0 | 2018-07-25 11:52:06 +0300 | [diff] [blame] | 4999 | if (cpus[i].thread_id == 0) |
Prarit Bhargava | 8cb48b3 | 2018-06-01 10:04:31 -0400 | [diff] [blame] | 5000 | topo.num_cores++; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5001 | } |
Prarit Bhargava | ef60574 | 2018-06-01 10:04:30 -0400 | [diff] [blame] | 5002 | |
Prarit Bhargava | 70a9c6e | 2018-06-01 10:04:33 -0400 | [diff] [blame] | 5003 | topo.cores_per_node = max_core_id + 1; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5004 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5005 | fprintf(outf, "max_core_id %d, sizing for %d cores per package\n", |
Prarit Bhargava | 70a9c6e | 2018-06-01 10:04:33 -0400 | [diff] [blame] | 5006 | max_core_id, topo.cores_per_node); |
| 5007 | if (!summary_only && topo.cores_per_node > 1) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5008 | BIC_PRESENT(BIC_Core); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5009 | |
Len Brown | 6de68fe | 2019-02-14 19:17:40 -0800 | [diff] [blame] | 5010 | topo.num_die = max_die_id + 1; |
| 5011 | if (debug > 1) |
| 5012 | fprintf(outf, "max_die_id %d, sizing for %d die\n", |
| 5013 | max_die_id, topo.num_die); |
| 5014 | if (!summary_only && topo.num_die > 1) |
| 5015 | BIC_PRESENT(BIC_Die); |
| 5016 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5017 | topo.num_packages = max_package_id + 1; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5018 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5019 | fprintf(outf, "max_package_id %d, sizing for %d packages\n", |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5020 | max_package_id, topo.num_packages); |
Len Brown | 7da6e3e | 2017-02-21 23:43:41 -0500 | [diff] [blame] | 5021 | if (!summary_only && topo.num_packages > 1) |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5022 | BIC_PRESENT(BIC_Package); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5023 | |
Prarit Bhargava | ef60574 | 2018-06-01 10:04:30 -0400 | [diff] [blame] | 5024 | set_node_data(); |
| 5025 | if (debug > 1) |
Prarit Bhargava | 70a9c6e | 2018-06-01 10:04:33 -0400 | [diff] [blame] | 5026 | fprintf(outf, "nodes_per_pkg %d\n", topo.nodes_per_pkg); |
Prarit Bhargava | 0123504 | 2018-06-01 10:04:35 -0400 | [diff] [blame] | 5027 | if (!summary_only && topo.nodes_per_pkg > 1) |
| 5028 | BIC_PRESENT(BIC_Node); |
Prarit Bhargava | ef60574 | 2018-06-01 10:04:30 -0400 | [diff] [blame] | 5029 | |
Prarit Bhargava | 70a9c6e | 2018-06-01 10:04:33 -0400 | [diff] [blame] | 5030 | topo.threads_per_core = max_siblings; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5031 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5032 | fprintf(outf, "max_siblings %d\n", max_siblings); |
Prarit Bhargava | 2ffbb22 | 2018-07-26 09:08:54 -0400 | [diff] [blame] | 5033 | |
| 5034 | if (debug < 1) |
| 5035 | return; |
| 5036 | |
| 5037 | for (i = 0; i <= topo.max_cpu_num; ++i) { |
Len Brown | 0ec712e | 2018-09-21 22:26:57 -0400 | [diff] [blame] | 5038 | if (cpu_is_not_present(i)) |
| 5039 | continue; |
Prarit Bhargava | 2ffbb22 | 2018-07-26 09:08:54 -0400 | [diff] [blame] | 5040 | fprintf(outf, |
Len Brown | 6de68fe | 2019-02-14 19:17:40 -0800 | [diff] [blame] | 5041 | "cpu %d pkg %d die %d node %d lnode %d core %d thread %d\n", |
| 5042 | i, cpus[i].physical_package_id, cpus[i].die_id, |
Prarit Bhargava | 2ffbb22 | 2018-07-26 09:08:54 -0400 | [diff] [blame] | 5043 | cpus[i].physical_node_id, |
| 5044 | cpus[i].logical_node_id, |
| 5045 | cpus[i].physical_core_id, |
| 5046 | cpus[i].thread_id); |
| 5047 | } |
| 5048 | |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5049 | } |
| 5050 | |
| 5051 | void |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 5052 | allocate_counters(struct thread_data **t, struct core_data **c, |
| 5053 | struct pkg_data **p) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5054 | { |
| 5055 | int i; |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 5056 | int num_cores = topo.cores_per_node * topo.nodes_per_pkg * |
| 5057 | topo.num_packages; |
| 5058 | int num_threads = topo.threads_per_core * num_cores; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5059 | |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 5060 | *t = calloc(num_threads, sizeof(struct thread_data)); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5061 | if (*t == NULL) |
| 5062 | goto error; |
| 5063 | |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 5064 | for (i = 0; i < num_threads; i++) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5065 | (*t)[i].cpu_id = -1; |
| 5066 | |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 5067 | *c = calloc(num_cores, sizeof(struct core_data)); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5068 | if (*c == NULL) |
| 5069 | goto error; |
| 5070 | |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 5071 | for (i = 0; i < num_cores; i++) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5072 | (*c)[i].core_id = -1; |
| 5073 | |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 5074 | *p = calloc(topo.num_packages, sizeof(struct pkg_data)); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5075 | if (*p == NULL) |
| 5076 | goto error; |
| 5077 | |
| 5078 | for (i = 0; i < topo.num_packages; i++) |
| 5079 | (*p)[i].package_id = i; |
| 5080 | |
| 5081 | return; |
| 5082 | error: |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 5083 | err(1, "calloc counters"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5084 | } |
| 5085 | /* |
| 5086 | * init_counter() |
| 5087 | * |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5088 | * set FIRST_THREAD_IN_CORE and FIRST_CORE_IN_PACKAGE |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5089 | */ |
| 5090 | void init_counter(struct thread_data *thread_base, struct core_data *core_base, |
Prarit Bhargava | 8cb48b3 | 2018-06-01 10:04:31 -0400 | [diff] [blame] | 5091 | struct pkg_data *pkg_base, int cpu_id) |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5092 | { |
Prarit Bhargava | 8cb48b3 | 2018-06-01 10:04:31 -0400 | [diff] [blame] | 5093 | int pkg_id = cpus[cpu_id].physical_package_id; |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 5094 | int node_id = cpus[cpu_id].logical_node_id; |
Prarit Bhargava | 8cb48b3 | 2018-06-01 10:04:31 -0400 | [diff] [blame] | 5095 | int core_id = cpus[cpu_id].physical_core_id; |
| 5096 | int thread_id = cpus[cpu_id].thread_id; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5097 | struct thread_data *t; |
| 5098 | struct core_data *c; |
| 5099 | struct pkg_data *p; |
| 5100 | |
Nathan Ciobanu | 42dd452 | 2018-06-08 15:15:12 -0700 | [diff] [blame] | 5101 | |
| 5102 | /* Workaround for systems where physical_node_id==-1 |
| 5103 | * and logical_node_id==(-1 - topo.num_cpus) |
| 5104 | */ |
| 5105 | if (node_id < 0) |
| 5106 | node_id = 0; |
| 5107 | |
Prarit Bhargava | 40f5cfe | 2018-06-01 10:04:34 -0400 | [diff] [blame] | 5108 | t = GET_THREAD(thread_base, thread_id, core_id, node_id, pkg_id); |
| 5109 | c = GET_CORE(core_base, core_id, node_id, pkg_id); |
Prarit Bhargava | 8cb48b3 | 2018-06-01 10:04:31 -0400 | [diff] [blame] | 5110 | p = GET_PKG(pkg_base, pkg_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5111 | |
| 5112 | t->cpu_id = cpu_id; |
Prarit Bhargava | 8cb48b3 | 2018-06-01 10:04:31 -0400 | [diff] [blame] | 5113 | if (thread_id == 0) { |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5114 | t->flags |= CPU_IS_FIRST_THREAD_IN_CORE; |
| 5115 | if (cpu_is_first_core_in_package(cpu_id)) |
| 5116 | t->flags |= CPU_IS_FIRST_CORE_IN_PACKAGE; |
| 5117 | } |
| 5118 | |
Prarit Bhargava | 8cb48b3 | 2018-06-01 10:04:31 -0400 | [diff] [blame] | 5119 | c->core_id = core_id; |
| 5120 | p->package_id = pkg_id; |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5121 | } |
| 5122 | |
| 5123 | |
| 5124 | int initialize_counters(int cpu_id) |
| 5125 | { |
Prarit Bhargava | 8cb48b3 | 2018-06-01 10:04:31 -0400 | [diff] [blame] | 5126 | init_counter(EVEN_COUNTERS, cpu_id); |
| 5127 | init_counter(ODD_COUNTERS, cpu_id); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5128 | return 0; |
| 5129 | } |
| 5130 | |
| 5131 | void allocate_output_buffer() |
| 5132 | { |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 5133 | output_buffer = calloc(1, (1 + topo.num_cpus) * 1024); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5134 | outp = output_buffer; |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 5135 | if (outp == NULL) |
| 5136 | err(-1, "calloc output buffer"); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5137 | } |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 5138 | void allocate_fd_percpu(void) |
| 5139 | { |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 5140 | fd_percpu = calloc(topo.max_cpu_num + 1, sizeof(int)); |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 5141 | if (fd_percpu == NULL) |
| 5142 | err(-1, "calloc fd_percpu"); |
| 5143 | } |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 5144 | void allocate_irq_buffers(void) |
| 5145 | { |
| 5146 | irq_column_2_cpu = calloc(topo.num_cpus, sizeof(int)); |
| 5147 | if (irq_column_2_cpu == NULL) |
| 5148 | err(-1, "calloc %d", topo.num_cpus); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5149 | |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 5150 | irqs_per_cpu = calloc(topo.max_cpu_num + 1, sizeof(int)); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 5151 | if (irqs_per_cpu == NULL) |
Mika Westerberg | 01a67ad | 2016-04-22 11:13:23 +0300 | [diff] [blame] | 5152 | err(-1, "calloc %d", topo.max_cpu_num + 1); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 5153 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5154 | void setup_all_buffers(void) |
| 5155 | { |
| 5156 | topology_probe(); |
Len Brown | 562a2d3 | 2016-02-26 23:48:05 -0500 | [diff] [blame] | 5157 | allocate_irq_buffers(); |
Len Brown | 3622989 | 2016-02-26 20:51:02 -0500 | [diff] [blame] | 5158 | allocate_fd_percpu(); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5159 | allocate_counters(&thread_even, &core_even, &package_even); |
| 5160 | allocate_counters(&thread_odd, &core_odd, &package_odd); |
| 5161 | allocate_output_buffer(); |
| 5162 | for_all_proc_cpus(initialize_counters); |
| 5163 | } |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 5164 | |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 5165 | void set_base_cpu(void) |
| 5166 | { |
| 5167 | base_cpu = sched_getcpu(); |
| 5168 | if (base_cpu < 0) |
| 5169 | err(-ENODEV, "No valid cpus found"); |
| 5170 | |
| 5171 | if (debug > 1) |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5172 | fprintf(outf, "base_cpu = %d\n", base_cpu); |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 5173 | } |
| 5174 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5175 | void turbostat_init() |
| 5176 | { |
Prarit Bhargava | 7ce7d5d | 2015-05-25 08:34:28 -0400 | [diff] [blame] | 5177 | setup_all_buffers(); |
| 5178 | set_base_cpu(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5179 | check_dev_msr(); |
Len Brown | 98481e7 | 2014-08-15 00:36:50 -0400 | [diff] [blame] | 5180 | check_permissions(); |
Len Brown | fcd1721 | 2015-03-23 20:29:09 -0400 | [diff] [blame] | 5181 | process_cpuid(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5182 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5183 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5184 | if (!quiet) |
Len Brown | 7f5c258 | 2015-12-01 01:36:39 -0500 | [diff] [blame] | 5185 | for_all_cpus(print_hwp, ODD_COUNTERS); |
| 5186 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5187 | if (!quiet) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 5188 | for_all_cpus(print_epb, ODD_COUNTERS); |
| 5189 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5190 | if (!quiet) |
Len Brown | 3a9a941 | 2014-08-15 02:39:52 -0400 | [diff] [blame] | 5191 | for_all_cpus(print_perf_limit, ODD_COUNTERS); |
| 5192 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5193 | if (!quiet) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 5194 | for_all_cpus(print_rapl, ODD_COUNTERS); |
| 5195 | |
| 5196 | for_all_cpus(set_temperature_target, ODD_COUNTERS); |
| 5197 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5198 | if (!quiet) |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 5199 | for_all_cpus(print_thermal, ODD_COUNTERS); |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 5200 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5201 | if (!quiet && do_irtl_snb) |
Len Brown | 5a63426 | 2016-04-06 17:15:55 -0400 | [diff] [blame] | 5202 | print_irtl(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5203 | } |
| 5204 | |
| 5205 | int fork_it(char **argv) |
| 5206 | { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5207 | pid_t child_pid; |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 5208 | int status; |
Len Brown | d15cf7c | 2012-06-03 23:24:00 -0400 | [diff] [blame] | 5209 | |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 5210 | snapshot_proc_sysfs_files(); |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 5211 | status = for_all_cpus(get_counters, EVEN_COUNTERS); |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 5212 | first_counter_read = 0; |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 5213 | if (status) |
| 5214 | exit(status); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5215 | /* clear affinity side-effect of get_counters() */ |
| 5216 | sched_setaffinity(0, cpu_present_setsize, cpu_present_set); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5217 | gettimeofday(&tv_even, (struct timezone *)NULL); |
| 5218 | |
| 5219 | child_pid = fork(); |
| 5220 | if (!child_pid) { |
| 5221 | /* child */ |
| 5222 | execvp(argv[0], argv); |
Len Brown | 0815a3d | 2017-02-23 17:00:51 -0500 | [diff] [blame] | 5223 | err(errno, "exec %s", argv[0]); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5224 | } else { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5225 | |
| 5226 | /* parent */ |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 5227 | if (child_pid == -1) |
| 5228 | err(1, "fork"); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5229 | |
| 5230 | signal(SIGINT, SIG_IGN); |
| 5231 | signal(SIGQUIT, SIG_IGN); |
Josh Triplett | b2c95d9 | 2013-08-20 17:20:18 -0700 | [diff] [blame] | 5232 | if (waitpid(child_pid, &status, 0) == -1) |
| 5233 | err(status, "waitpid"); |
David Arcari | 2a95496 | 2019-02-12 09:34:39 -0500 | [diff] [blame] | 5234 | |
| 5235 | if (WIFEXITED(status)) |
| 5236 | status = WEXITSTATUS(status); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5237 | } |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5238 | /* |
| 5239 | * n.b. fork_it() does not check for errors from for_all_cpus() |
| 5240 | * because re-starting is problematic when forking |
| 5241 | */ |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 5242 | snapshot_proc_sysfs_files(); |
Len Brown | c98d5d9 | 2012-06-04 00:56:40 -0400 | [diff] [blame] | 5243 | for_all_cpus(get_counters, ODD_COUNTERS); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5244 | gettimeofday(&tv_odd, (struct timezone *)NULL); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5245 | timersub(&tv_odd, &tv_even, &tv_delta); |
Len Brown | ba3dec9 | 2016-04-22 20:31:46 -0400 | [diff] [blame] | 5246 | if (for_all_cpus_2(delta_cpu, ODD_COUNTERS, EVEN_COUNTERS)) |
| 5247 | fprintf(outf, "%s: Counter reset detected\n", progname); |
| 5248 | else { |
| 5249 | compute_average(EVEN_COUNTERS); |
| 5250 | format_all_counters(EVEN_COUNTERS); |
| 5251 | } |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5252 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5253 | fprintf(outf, "%.6f sec\n", tv_delta.tv_sec + tv_delta.tv_usec/1000000.0); |
| 5254 | |
| 5255 | flush_output_stderr(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5256 | |
Len Brown | d91bb17 | 2012-11-01 00:08:19 -0400 | [diff] [blame] | 5257 | return status; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5258 | } |
| 5259 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 5260 | int get_and_dump_counters(void) |
| 5261 | { |
| 5262 | int status; |
| 5263 | |
Len Brown | 218f0e8 | 2017-02-14 22:07:52 -0500 | [diff] [blame] | 5264 | snapshot_proc_sysfs_files(); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 5265 | status = for_all_cpus(get_counters, ODD_COUNTERS); |
| 5266 | if (status) |
| 5267 | return status; |
| 5268 | |
| 5269 | status = for_all_cpus(dump_counters, ODD_COUNTERS); |
| 5270 | if (status) |
| 5271 | return status; |
| 5272 | |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5273 | flush_output_stdout(); |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 5274 | |
| 5275 | return status; |
| 5276 | } |
| 5277 | |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5278 | void print_version() { |
Len Brown | 0f71d08 | 2019-03-20 23:23:25 -0400 | [diff] [blame] | 5279 | fprintf(outf, "turbostat version 19.03.20" |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5280 | " - Len Brown <lenb@kernel.org>\n"); |
| 5281 | } |
| 5282 | |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 5283 | int add_counter(unsigned int msr_num, char *path, char *name, |
| 5284 | unsigned int width, enum counter_scope scope, |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5285 | enum counter_type type, enum counter_format format, int flags) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5286 | { |
| 5287 | struct msr_counter *msrp; |
| 5288 | |
| 5289 | msrp = calloc(1, sizeof(struct msr_counter)); |
| 5290 | if (msrp == NULL) { |
| 5291 | perror("calloc"); |
| 5292 | exit(1); |
| 5293 | } |
| 5294 | |
| 5295 | msrp->msr_num = msr_num; |
| 5296 | strncpy(msrp->name, name, NAME_BYTES); |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 5297 | if (path) |
| 5298 | strncpy(msrp->path, path, PATH_BYTES); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5299 | msrp->width = width; |
| 5300 | msrp->type = type; |
| 5301 | msrp->format = format; |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5302 | msrp->flags = flags; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5303 | |
| 5304 | switch (scope) { |
| 5305 | |
| 5306 | case SCOPE_CPU: |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5307 | msrp->next = sys.tp; |
| 5308 | sys.tp = msrp; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 5309 | sys.added_thread_counters++; |
Len Brown | 0748eaf | 2018-06-01 12:38:29 -0400 | [diff] [blame] | 5310 | if (sys.added_thread_counters > MAX_ADDED_THREAD_COUNTERS) { |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 5311 | fprintf(stderr, "exceeded max %d added thread counters\n", |
| 5312 | MAX_ADDED_COUNTERS); |
| 5313 | exit(-1); |
| 5314 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5315 | break; |
| 5316 | |
| 5317 | case SCOPE_CORE: |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5318 | msrp->next = sys.cp; |
| 5319 | sys.cp = msrp; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 5320 | sys.added_core_counters++; |
| 5321 | if (sys.added_core_counters > MAX_ADDED_COUNTERS) { |
| 5322 | fprintf(stderr, "exceeded max %d added core counters\n", |
| 5323 | MAX_ADDED_COUNTERS); |
| 5324 | exit(-1); |
| 5325 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5326 | break; |
| 5327 | |
| 5328 | case SCOPE_PACKAGE: |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5329 | msrp->next = sys.pp; |
| 5330 | sys.pp = msrp; |
Len Brown | 678a3bd | 2017-02-09 22:22:13 -0500 | [diff] [blame] | 5331 | sys.added_package_counters++; |
| 5332 | if (sys.added_package_counters > MAX_ADDED_COUNTERS) { |
| 5333 | fprintf(stderr, "exceeded max %d added package counters\n", |
| 5334 | MAX_ADDED_COUNTERS); |
| 5335 | exit(-1); |
| 5336 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5337 | break; |
| 5338 | } |
| 5339 | |
| 5340 | return 0; |
| 5341 | } |
| 5342 | |
| 5343 | void parse_add_command(char *add_command) |
| 5344 | { |
| 5345 | int msr_num = 0; |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 5346 | char *path = NULL; |
Len Brown | 0f47c08 | 2017-01-27 00:50:45 -0500 | [diff] [blame] | 5347 | char name_buffer[NAME_BYTES] = ""; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5348 | int width = 64; |
| 5349 | int fail = 0; |
| 5350 | enum counter_scope scope = SCOPE_CPU; |
| 5351 | enum counter_type type = COUNTER_CYCLES; |
| 5352 | enum counter_format format = FORMAT_DELTA; |
| 5353 | |
| 5354 | while (add_command) { |
| 5355 | |
| 5356 | if (sscanf(add_command, "msr0x%x", &msr_num) == 1) |
| 5357 | goto next; |
| 5358 | |
| 5359 | if (sscanf(add_command, "msr%d", &msr_num) == 1) |
| 5360 | goto next; |
| 5361 | |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 5362 | if (*add_command == '/') { |
| 5363 | path = add_command; |
| 5364 | goto next; |
| 5365 | } |
| 5366 | |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5367 | if (sscanf(add_command, "u%d", &width) == 1) { |
| 5368 | if ((width == 32) || (width == 64)) |
| 5369 | goto next; |
| 5370 | width = 64; |
| 5371 | } |
| 5372 | if (!strncmp(add_command, "cpu", strlen("cpu"))) { |
| 5373 | scope = SCOPE_CPU; |
| 5374 | goto next; |
| 5375 | } |
| 5376 | if (!strncmp(add_command, "core", strlen("core"))) { |
| 5377 | scope = SCOPE_CORE; |
| 5378 | goto next; |
| 5379 | } |
| 5380 | if (!strncmp(add_command, "package", strlen("package"))) { |
| 5381 | scope = SCOPE_PACKAGE; |
| 5382 | goto next; |
| 5383 | } |
| 5384 | if (!strncmp(add_command, "cycles", strlen("cycles"))) { |
| 5385 | type = COUNTER_CYCLES; |
| 5386 | goto next; |
| 5387 | } |
| 5388 | if (!strncmp(add_command, "seconds", strlen("seconds"))) { |
| 5389 | type = COUNTER_SECONDS; |
| 5390 | goto next; |
| 5391 | } |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5392 | if (!strncmp(add_command, "usec", strlen("usec"))) { |
| 5393 | type = COUNTER_USEC; |
| 5394 | goto next; |
| 5395 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5396 | if (!strncmp(add_command, "raw", strlen("raw"))) { |
| 5397 | format = FORMAT_RAW; |
| 5398 | goto next; |
| 5399 | } |
| 5400 | if (!strncmp(add_command, "delta", strlen("delta"))) { |
| 5401 | format = FORMAT_DELTA; |
| 5402 | goto next; |
| 5403 | } |
| 5404 | if (!strncmp(add_command, "percent", strlen("percent"))) { |
| 5405 | format = FORMAT_PERCENT; |
| 5406 | goto next; |
| 5407 | } |
| 5408 | |
| 5409 | if (sscanf(add_command, "%18s,%*s", name_buffer) == 1) { /* 18 < NAME_BYTES */ |
| 5410 | char *eos; |
| 5411 | |
| 5412 | eos = strchr(name_buffer, ','); |
| 5413 | if (eos) |
| 5414 | *eos = '\0'; |
| 5415 | goto next; |
| 5416 | } |
| 5417 | |
| 5418 | next: |
| 5419 | add_command = strchr(add_command, ','); |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 5420 | if (add_command) { |
| 5421 | *add_command = '\0'; |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5422 | add_command++; |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 5423 | } |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5424 | |
| 5425 | } |
Len Brown | 495c7654 | 2017-02-08 02:41:51 -0500 | [diff] [blame] | 5426 | if ((msr_num == 0) && (path == NULL)) { |
| 5427 | fprintf(stderr, "--add: (msrDDD | msr0xXXX | /path_to_counter ) required\n"); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5428 | fail++; |
| 5429 | } |
| 5430 | |
| 5431 | /* generate default column header */ |
| 5432 | if (*name_buffer == '\0') { |
Len Brown | 5f3aea5 | 2017-02-23 18:10:27 -0500 | [diff] [blame] | 5433 | if (width == 32) |
| 5434 | sprintf(name_buffer, "M0x%x%s", msr_num, format == FORMAT_PERCENT ? "%" : ""); |
| 5435 | else |
| 5436 | sprintf(name_buffer, "M0X%x%s", msr_num, format == FORMAT_PERCENT ? "%" : ""); |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5437 | } |
| 5438 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5439 | if (add_counter(msr_num, path, name_buffer, width, scope, type, format, 0)) |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5440 | fail++; |
| 5441 | |
| 5442 | if (fail) { |
| 5443 | help(); |
| 5444 | exit(1); |
| 5445 | } |
| 5446 | } |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5447 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 5448 | int is_deferred_skip(char *name) |
| 5449 | { |
| 5450 | int i; |
| 5451 | |
| 5452 | for (i = 0; i < deferred_skip_index; ++i) |
| 5453 | if (!strcmp(name, deferred_skip_names[i])) |
| 5454 | return 1; |
| 5455 | return 0; |
| 5456 | } |
| 5457 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5458 | void probe_sysfs(void) |
| 5459 | { |
| 5460 | char path[64]; |
| 5461 | char name_buf[16]; |
| 5462 | FILE *input; |
| 5463 | int state; |
| 5464 | char *sp; |
| 5465 | |
| 5466 | if (!DO_BIC(BIC_sysfs)) |
| 5467 | return; |
| 5468 | |
Len Brown | 0748eaf | 2018-06-01 12:38:29 -0400 | [diff] [blame] | 5469 | for (state = 10; state >= 0; --state) { |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5470 | |
| 5471 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", |
| 5472 | base_cpu, state); |
| 5473 | input = fopen(path, "r"); |
| 5474 | if (input == NULL) |
| 5475 | continue; |
Ben Hutchings | 8173c33 | 2019-03-20 23:01:03 -0400 | [diff] [blame] | 5476 | if (!fgets(name_buf, sizeof(name_buf), input)) |
| 5477 | err(1, "%s: failed to read file", path); |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5478 | |
| 5479 | /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ |
| 5480 | sp = strchr(name_buf, '-'); |
| 5481 | if (!sp) |
| 5482 | sp = strchrnul(name_buf, '\n'); |
| 5483 | *sp = '%'; |
| 5484 | *(sp + 1) = '\0'; |
| 5485 | |
| 5486 | fclose(input); |
| 5487 | |
| 5488 | sprintf(path, "cpuidle/state%d/time", state); |
| 5489 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 5490 | if (is_deferred_skip(name_buf)) |
| 5491 | continue; |
| 5492 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5493 | add_counter(0, path, name_buf, 64, SCOPE_CPU, COUNTER_USEC, |
| 5494 | FORMAT_PERCENT, SYSFS_PERCPU); |
| 5495 | } |
| 5496 | |
Len Brown | 0748eaf | 2018-06-01 12:38:29 -0400 | [diff] [blame] | 5497 | for (state = 10; state >= 0; --state) { |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5498 | |
| 5499 | sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", |
| 5500 | base_cpu, state); |
| 5501 | input = fopen(path, "r"); |
| 5502 | if (input == NULL) |
| 5503 | continue; |
Ben Hutchings | 8173c33 | 2019-03-20 23:01:03 -0400 | [diff] [blame] | 5504 | if (!fgets(name_buf, sizeof(name_buf), input)) |
| 5505 | err(1, "%s: failed to read file", path); |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5506 | /* truncate "C1-HSW\n" to "C1", or truncate "C1\n" to "C1" */ |
| 5507 | sp = strchr(name_buf, '-'); |
| 5508 | if (!sp) |
| 5509 | sp = strchrnul(name_buf, '\n'); |
| 5510 | *sp = '\0'; |
| 5511 | fclose(input); |
| 5512 | |
| 5513 | sprintf(path, "cpuidle/state%d/usage", state); |
| 5514 | |
Len Brown | dd778a5 | 2017-02-21 23:21:13 -0500 | [diff] [blame] | 5515 | if (is_deferred_skip(name_buf)) |
| 5516 | continue; |
| 5517 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5518 | add_counter(0, path, name_buf, 64, SCOPE_CPU, COUNTER_ITEMS, |
| 5519 | FORMAT_DELTA, SYSFS_PERCPU); |
| 5520 | } |
| 5521 | |
| 5522 | } |
| 5523 | |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 5524 | |
| 5525 | /* |
| 5526 | * parse cpuset with following syntax |
| 5527 | * 1,2,4..6,8-10 and set bits in cpu_subset |
| 5528 | */ |
| 5529 | void parse_cpu_command(char *optarg) |
| 5530 | { |
| 5531 | unsigned int start, end; |
| 5532 | char *next; |
| 5533 | |
Len Brown | 4e4e1e7 | 2017-02-21 22:33:42 -0500 | [diff] [blame] | 5534 | if (!strcmp(optarg, "core")) { |
| 5535 | if (cpu_subset) |
| 5536 | goto error; |
| 5537 | show_core_only++; |
| 5538 | return; |
| 5539 | } |
| 5540 | if (!strcmp(optarg, "package")) { |
| 5541 | if (cpu_subset) |
| 5542 | goto error; |
| 5543 | show_pkg_only++; |
| 5544 | return; |
| 5545 | } |
| 5546 | if (show_core_only || show_pkg_only) |
| 5547 | goto error; |
| 5548 | |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 5549 | cpu_subset = CPU_ALLOC(CPU_SUBSET_MAXCPUS); |
| 5550 | if (cpu_subset == NULL) |
| 5551 | err(3, "CPU_ALLOC"); |
| 5552 | cpu_subset_size = CPU_ALLOC_SIZE(CPU_SUBSET_MAXCPUS); |
| 5553 | |
| 5554 | CPU_ZERO_S(cpu_subset_size, cpu_subset); |
| 5555 | |
| 5556 | next = optarg; |
| 5557 | |
| 5558 | while (next && *next) { |
| 5559 | |
| 5560 | if (*next == '-') /* no negative cpu numbers */ |
| 5561 | goto error; |
| 5562 | |
| 5563 | start = strtoul(next, &next, 10); |
| 5564 | |
| 5565 | if (start >= CPU_SUBSET_MAXCPUS) |
| 5566 | goto error; |
| 5567 | CPU_SET_S(start, cpu_subset_size, cpu_subset); |
| 5568 | |
| 5569 | if (*next == '\0') |
| 5570 | break; |
| 5571 | |
| 5572 | if (*next == ',') { |
| 5573 | next += 1; |
| 5574 | continue; |
| 5575 | } |
| 5576 | |
| 5577 | if (*next == '-') { |
| 5578 | next += 1; /* start range */ |
| 5579 | } else if (*next == '.') { |
| 5580 | next += 1; |
| 5581 | if (*next == '.') |
| 5582 | next += 1; /* start range */ |
| 5583 | else |
| 5584 | goto error; |
| 5585 | } |
| 5586 | |
| 5587 | end = strtoul(next, &next, 10); |
| 5588 | if (end <= start) |
| 5589 | goto error; |
| 5590 | |
| 5591 | while (++start <= end) { |
| 5592 | if (start >= CPU_SUBSET_MAXCPUS) |
| 5593 | goto error; |
| 5594 | CPU_SET_S(start, cpu_subset_size, cpu_subset); |
| 5595 | } |
| 5596 | |
| 5597 | if (*next == ',') |
| 5598 | next += 1; |
| 5599 | else if (*next != '\0') |
| 5600 | goto error; |
| 5601 | } |
| 5602 | |
| 5603 | return; |
| 5604 | |
| 5605 | error: |
Len Brown | 4e4e1e7 | 2017-02-21 22:33:42 -0500 | [diff] [blame] | 5606 | fprintf(stderr, "\"--cpu %s\" malformed\n", optarg); |
| 5607 | help(); |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 5608 | exit(-1); |
| 5609 | } |
| 5610 | |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5611 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5612 | void cmdline(int argc, char **argv) |
| 5613 | { |
| 5614 | int opt; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5615 | int option_index = 0; |
| 5616 | static struct option long_options[] = { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5617 | {"add", required_argument, 0, 'a'}, |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 5618 | {"cpu", required_argument, 0, 'c'}, |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5619 | {"Dump", no_argument, 0, 'D'}, |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5620 | {"debug", no_argument, 0, 'd'}, /* internal, not documented */ |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5621 | {"enable", required_argument, 0, 'e'}, |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5622 | {"interval", required_argument, 0, 'i'}, |
Chen Yu | 023fe0a | 2018-04-26 08:41:03 +0800 | [diff] [blame] | 5623 | {"num_iterations", required_argument, 0, 'n'}, |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5624 | {"help", no_argument, 0, 'h'}, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5625 | {"hide", required_argument, 0, 'H'}, // meh, -h taken by --help |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5626 | {"Joules", no_argument, 0, 'J'}, |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 5627 | {"list", no_argument, 0, 'l'}, |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5628 | {"out", required_argument, 0, 'o'}, |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5629 | {"quiet", no_argument, 0, 'q'}, |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5630 | {"show", required_argument, 0, 's'}, |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5631 | {"Summary", no_argument, 0, 'S'}, |
| 5632 | {"TCC", required_argument, 0, 'T'}, |
| 5633 | {"version", no_argument, 0, 'v' }, |
| 5634 | {0, 0, 0, 0 } |
| 5635 | }; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5636 | |
| 5637 | progname = argv[0]; |
| 5638 | |
Chen Yu | 023fe0a | 2018-04-26 08:41:03 +0800 | [diff] [blame] | 5639 | while ((opt = getopt_long_only(argc, argv, "+C:c:Dde:hi:Jn:o:qST:v", |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5640 | long_options, &option_index)) != -1) { |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5641 | switch (opt) { |
Len Brown | 388e9c8 | 2016-12-22 23:57:55 -0500 | [diff] [blame] | 5642 | case 'a': |
| 5643 | parse_add_command(optarg); |
| 5644 | break; |
Len Brown | 1ef7d21 | 2017-02-10 23:54:15 -0500 | [diff] [blame] | 5645 | case 'c': |
| 5646 | parse_cpu_command(optarg); |
| 5647 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5648 | case 'D': |
| 5649 | dump_only++; |
Len Brown | 8e180f3 | 2012-09-22 01:25:08 -0400 | [diff] [blame] | 5650 | break; |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5651 | case 'e': |
| 5652 | /* --enable specified counter */ |
Len Brown | 4c2122d | 2018-06-06 17:44:48 -0400 | [diff] [blame] | 5653 | bic_enabled = bic_enabled | bic_lookup(optarg, SHOW_LIST); |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5654 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5655 | case 'd': |
| 5656 | debug++; |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5657 | ENABLE_BIC(BIC_DISABLED_BY_DEFAULT); |
Len Brown | 2f32edf | 2012-09-21 23:45:46 -0400 | [diff] [blame] | 5658 | break; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5659 | case 'H': |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5660 | /* |
| 5661 | * --hide: do not show those specified |
| 5662 | * multiple invocations simply clear more bits in enabled mask |
| 5663 | */ |
| 5664 | bic_enabled &= ~bic_lookup(optarg, HIDE_LIST); |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5665 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5666 | case 'h': |
| 5667 | default: |
| 5668 | help(); |
| 5669 | exit(1); |
| 5670 | case 'i': |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 5671 | { |
| 5672 | double interval = strtod(optarg, NULL); |
| 5673 | |
| 5674 | if (interval < 0.001) { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5675 | fprintf(outf, "interval %f seconds is too small\n", |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 5676 | interval); |
| 5677 | exit(2); |
| 5678 | } |
| 5679 | |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 5680 | interval_tv.tv_sec = interval_ts.tv_sec = interval; |
Len Brown | b9ad8ee | 2017-07-19 19:28:37 -0400 | [diff] [blame] | 5681 | interval_tv.tv_usec = (interval - interval_tv.tv_sec) * 1000000; |
Artem Bityutskiy | 47936f9 | 2017-10-04 15:01:47 +0300 | [diff] [blame] | 5682 | interval_ts.tv_nsec = (interval - interval_ts.tv_sec) * 1000000000; |
Len Brown | 2a0609c | 2016-02-12 22:44:48 -0500 | [diff] [blame] | 5683 | } |
Len Brown | 889facb | 2012-11-08 00:48:57 -0500 | [diff] [blame] | 5684 | break; |
Dirk Brandewie | 5c56be9 | 2013-12-16 10:23:41 -0800 | [diff] [blame] | 5685 | case 'J': |
| 5686 | rapl_joules++; |
| 5687 | break; |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 5688 | case 'l': |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5689 | ENABLE_BIC(BIC_DISABLED_BY_DEFAULT); |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 5690 | list_header_only++; |
| 5691 | quiet++; |
| 5692 | break; |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5693 | case 'o': |
| 5694 | outf = fopen_or_die(optarg, "w"); |
| 5695 | break; |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5696 | case 'q': |
| 5697 | quiet = 1; |
| 5698 | break; |
Chen Yu | 023fe0a | 2018-04-26 08:41:03 +0800 | [diff] [blame] | 5699 | case 'n': |
| 5700 | num_iterations = strtod(optarg, NULL); |
| 5701 | |
| 5702 | if (num_iterations <= 0) { |
| 5703 | fprintf(outf, "iterations %d should be positive number\n", |
| 5704 | num_iterations); |
| 5705 | exit(2); |
| 5706 | } |
| 5707 | break; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5708 | case 's': |
Len Brown | 3f44a5c | 2017-10-17 15:42:56 -0400 | [diff] [blame] | 5709 | /* |
| 5710 | * --show: show only those specified |
| 5711 | * The 1st invocation will clear and replace the enabled mask |
| 5712 | * subsequent invocations can add to it. |
| 5713 | */ |
| 5714 | if (shown == 0) |
| 5715 | bic_enabled = bic_lookup(optarg, SHOW_LIST); |
| 5716 | else |
| 5717 | bic_enabled |= bic_lookup(optarg, SHOW_LIST); |
| 5718 | shown = 1; |
Len Brown | 812db3f | 2017-02-10 00:25:41 -0500 | [diff] [blame] | 5719 | break; |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5720 | case 'S': |
| 5721 | summary_only++; |
| 5722 | break; |
| 5723 | case 'T': |
| 5724 | tcc_activation_temp_override = atoi(optarg); |
| 5725 | break; |
| 5726 | case 'v': |
| 5727 | print_version(); |
| 5728 | exit(0); |
| 5729 | break; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5730 | } |
| 5731 | } |
| 5732 | } |
| 5733 | |
| 5734 | int main(int argc, char **argv) |
| 5735 | { |
Len Brown | b7d8c14 | 2016-02-13 23:36:17 -0500 | [diff] [blame] | 5736 | outf = stderr; |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5737 | cmdline(argc, argv); |
| 5738 | |
Len Brown | 96e4715 | 2017-01-21 02:26:00 -0500 | [diff] [blame] | 5739 | if (!quiet) |
Len Brown | d8af6f5 | 2015-02-10 01:56:38 -0500 | [diff] [blame] | 5740 | print_version(); |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5741 | |
Len Brown | 41618e6 | 2017-02-09 18:25:22 -0500 | [diff] [blame] | 5742 | probe_sysfs(); |
| 5743 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5744 | turbostat_init(); |
| 5745 | |
Andy Shevchenko | 3b4d5c7 | 2014-01-23 17:13:15 +0200 | [diff] [blame] | 5746 | /* dump counters and exit */ |
| 5747 | if (dump_only) |
| 5748 | return get_and_dump_counters(); |
| 5749 | |
Len Brown | c8ade36 | 2017-02-15 17:15:11 -0500 | [diff] [blame] | 5750 | /* list header and exit */ |
| 5751 | if (list_header_only) { |
| 5752 | print_header(","); |
| 5753 | flush_output_stdout(); |
| 5754 | return 0; |
| 5755 | } |
| 5756 | |
Len Brown | 103a8fe | 2010-10-22 23:53:03 -0400 | [diff] [blame] | 5757 | /* |
| 5758 | * if any params left, it must be a command to fork |
| 5759 | */ |
| 5760 | if (argc - optind) |
| 5761 | return fork_it(argv + optind); |
| 5762 | else |
| 5763 | turbostat_loop(); |
| 5764 | |
| 5765 | return 0; |
| 5766 | } |