diff options
author | Prarit Bhargava <prarit@redhat.com> | 2015-05-25 08:34:28 -0400 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2015-05-27 18:04:01 -0400 |
commit | 7ce7d5de6dd08ee2a713ef13f4499073b4a72b7f (patch) | |
tree | d3e3e6dac67aed79f05a334e012ae6213b29ec42 /tools/power/x86 | |
parent | e9be7dd62899194ebdd90d417fc6c07d5d157912 (diff) |
tools/power turbostat: allow running without cpu0
Linux-3.7 added CONFIG_BOOTPARAM_HOTPLUG_CPU0,
allowing systems to offline cpu0.
But when cpu0 is offline, turbostat will not run:
# turbostat ls
turbostat: no /dev/cpu/0/msr
This patch replaces the hard-coded use of cpu0 in turbostat
with the current cpu, allowing it to run without a cpu0.
Fewer cross-calls may also be needed due to use of current cpu,
though this hard-coding was used only for the --debug preamble.
Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'tools/power/x86')
-rw-r--r-- | tools/power/x86/turbostat/turbostat.c | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index f92211e9e70c..68e77fdd4c04 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c | |||
@@ -92,6 +92,7 @@ unsigned int do_gfx_perf_limit_reasons; | |||
92 | unsigned int do_ring_perf_limit_reasons; | 92 | unsigned int do_ring_perf_limit_reasons; |
93 | unsigned int crystal_hz; | 93 | unsigned int crystal_hz; |
94 | unsigned long long tsc_hz; | 94 | unsigned long long tsc_hz; |
95 | int base_cpu; | ||
95 | 96 | ||
96 | #define RAPL_PKG (1 << 0) | 97 | #define RAPL_PKG (1 << 0) |
97 | /* 0x610 MSR_PKG_POWER_LIMIT */ | 98 | /* 0x610 MSR_PKG_POWER_LIMIT */ |
@@ -1154,7 +1155,7 @@ dump_nhm_platform_info(void) | |||
1154 | unsigned long long msr; | 1155 | unsigned long long msr; |
1155 | unsigned int ratio; | 1156 | unsigned int ratio; |
1156 | 1157 | ||
1157 | get_msr(0, MSR_NHM_PLATFORM_INFO, &msr); | 1158 | get_msr(base_cpu, MSR_NHM_PLATFORM_INFO, &msr); |
1158 | 1159 | ||
1159 | fprintf(stderr, "cpu0: MSR_NHM_PLATFORM_INFO: 0x%08llx\n", msr); | 1160 | fprintf(stderr, "cpu0: MSR_NHM_PLATFORM_INFO: 0x%08llx\n", msr); |
1160 | 1161 | ||
@@ -1166,7 +1167,7 @@ dump_nhm_platform_info(void) | |||
1166 | fprintf(stderr, "%d * %.0f = %.0f MHz base frequency\n", | 1167 | fprintf(stderr, "%d * %.0f = %.0f MHz base frequency\n", |
1167 | ratio, bclk, ratio * bclk); | 1168 | ratio, bclk, ratio * bclk); |
1168 | 1169 | ||
1169 | get_msr(0, MSR_IA32_POWER_CTL, &msr); | 1170 | get_msr(base_cpu, MSR_IA32_POWER_CTL, &msr); |
1170 | fprintf(stderr, "cpu0: MSR_IA32_POWER_CTL: 0x%08llx (C1E auto-promotion: %sabled)\n", | 1171 | fprintf(stderr, "cpu0: MSR_IA32_POWER_CTL: 0x%08llx (C1E auto-promotion: %sabled)\n", |
1171 | msr, msr & 0x2 ? "EN" : "DIS"); | 1172 | msr, msr & 0x2 ? "EN" : "DIS"); |
1172 | 1173 | ||
@@ -1179,7 +1180,7 @@ dump_hsw_turbo_ratio_limits(void) | |||
1179 | unsigned long long msr; | 1180 | unsigned long long msr; |
1180 | unsigned int ratio; | 1181 | unsigned int ratio; |
1181 | 1182 | ||
1182 | get_msr(0, MSR_TURBO_RATIO_LIMIT2, &msr); | 1183 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT2, &msr); |
1183 | 1184 | ||
1184 | fprintf(stderr, "cpu0: MSR_TURBO_RATIO_LIMIT2: 0x%08llx\n", msr); | 1185 | fprintf(stderr, "cpu0: MSR_TURBO_RATIO_LIMIT2: 0x%08llx\n", msr); |
1185 | 1186 | ||
@@ -1201,7 +1202,7 @@ dump_ivt_turbo_ratio_limits(void) | |||
1201 | unsigned long long msr; | 1202 | unsigned long long msr; |
1202 | unsigned int ratio; | 1203 | unsigned int ratio; |
1203 | 1204 | ||
1204 | get_msr(0, MSR_TURBO_RATIO_LIMIT1, &msr); | 1205 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT1, &msr); |
1205 | 1206 | ||
1206 | fprintf(stderr, "cpu0: MSR_TURBO_RATIO_LIMIT1: 0x%08llx\n", msr); | 1207 | fprintf(stderr, "cpu0: MSR_TURBO_RATIO_LIMIT1: 0x%08llx\n", msr); |
1207 | 1208 | ||
@@ -1253,7 +1254,7 @@ dump_nhm_turbo_ratio_limits(void) | |||
1253 | unsigned long long msr; | 1254 | unsigned long long msr; |
1254 | unsigned int ratio; | 1255 | unsigned int ratio; |
1255 | 1256 | ||
1256 | get_msr(0, MSR_TURBO_RATIO_LIMIT, &msr); | 1257 | get_msr(base_cpu, MSR_TURBO_RATIO_LIMIT, &msr); |
1257 | 1258 | ||
1258 | fprintf(stderr, "cpu0: MSR_TURBO_RATIO_LIMIT: 0x%08llx\n", msr); | 1259 | fprintf(stderr, "cpu0: MSR_TURBO_RATIO_LIMIT: 0x%08llx\n", msr); |
1259 | 1260 | ||
@@ -1309,7 +1310,7 @@ dump_knl_turbo_ratio_limits(void) | |||
1309 | int delta_ratio; | 1310 | int delta_ratio; |
1310 | int i; | 1311 | int i; |
1311 | 1312 | ||
1312 | get_msr(0, MSR_NHM_TURBO_RATIO_LIMIT, &msr); | 1313 | get_msr(base_cpu, MSR_NHM_TURBO_RATIO_LIMIT, &msr); |
1313 | 1314 | ||
1314 | fprintf(stderr, "cpu0: MSR_NHM_TURBO_RATIO_LIMIT: 0x%08llx\n", | 1315 | fprintf(stderr, "cpu0: MSR_NHM_TURBO_RATIO_LIMIT: 0x%08llx\n", |
1315 | msr); | 1316 | msr); |
@@ -1365,7 +1366,7 @@ dump_nhm_cst_cfg(void) | |||
1365 | { | 1366 | { |
1366 | unsigned long long msr; | 1367 | unsigned long long msr; |
1367 | 1368 | ||
1368 | get_msr(0, MSR_NHM_SNB_PKG_CST_CFG_CTL, &msr); | 1369 | get_msr(base_cpu, MSR_NHM_SNB_PKG_CST_CFG_CTL, &msr); |
1369 | 1370 | ||
1370 | #define SNB_C1_AUTO_UNDEMOTE (1UL << 27) | 1371 | #define SNB_C1_AUTO_UNDEMOTE (1UL << 27) |
1371 | #define SNB_C3_AUTO_UNDEMOTE (1UL << 28) | 1372 | #define SNB_C3_AUTO_UNDEMOTE (1UL << 28) |
@@ -1694,8 +1695,10 @@ restart: | |||
1694 | void check_dev_msr() | 1695 | void check_dev_msr() |
1695 | { | 1696 | { |
1696 | struct stat sb; | 1697 | struct stat sb; |
1698 | char pathname[32]; | ||
1697 | 1699 | ||
1698 | if (stat("/dev/cpu/0/msr", &sb)) | 1700 | sprintf(pathname, "/dev/cpu/%d/msr", base_cpu); |
1701 | if (stat(pathname, &sb)) | ||
1699 | if (system("/sbin/modprobe msr > /dev/null 2>&1")) | 1702 | if (system("/sbin/modprobe msr > /dev/null 2>&1")) |
1700 | err(-5, "no /dev/cpu/0/msr, Try \"# modprobe msr\" "); | 1703 | err(-5, "no /dev/cpu/0/msr, Try \"# modprobe msr\" "); |
1701 | } | 1704 | } |
@@ -1708,6 +1711,7 @@ void check_permissions() | |||
1708 | cap_user_data_t cap_data = &cap_data_data; | 1711 | cap_user_data_t cap_data = &cap_data_data; |
1709 | extern int capget(cap_user_header_t hdrp, cap_user_data_t datap); | 1712 | extern int capget(cap_user_header_t hdrp, cap_user_data_t datap); |
1710 | int do_exit = 0; | 1713 | int do_exit = 0; |
1714 | char pathname[32]; | ||
1711 | 1715 | ||
1712 | /* check for CAP_SYS_RAWIO */ | 1716 | /* check for CAP_SYS_RAWIO */ |
1713 | cap_header->pid = getpid(); | 1717 | cap_header->pid = getpid(); |
@@ -1722,7 +1726,8 @@ void check_permissions() | |||
1722 | } | 1726 | } |
1723 | 1727 | ||
1724 | /* test file permissions */ | 1728 | /* test file permissions */ |
1725 | if (euidaccess("/dev/cpu/0/msr", R_OK)) { | 1729 | sprintf(pathname, "/dev/cpu/%d/msr", base_cpu); |
1730 | if (euidaccess(pathname, R_OK)) { | ||
1726 | do_exit++; | 1731 | do_exit++; |
1727 | warn("/dev/cpu/0/msr open failed, try chown or chmod +r /dev/cpu/*/msr"); | 1732 | warn("/dev/cpu/0/msr open failed, try chown or chmod +r /dev/cpu/*/msr"); |
1728 | } | 1733 | } |
@@ -1804,7 +1809,7 @@ int probe_nhm_msrs(unsigned int family, unsigned int model) | |||
1804 | default: | 1809 | default: |
1805 | return 0; | 1810 | return 0; |
1806 | } | 1811 | } |
1807 | get_msr(0, MSR_NHM_SNB_PKG_CST_CFG_CTL, &msr); | 1812 | get_msr(base_cpu, MSR_NHM_SNB_PKG_CST_CFG_CTL, &msr); |
1808 | 1813 | ||
1809 | pkg_cstate_limit = pkg_cstate_limits[msr & 0xF]; | 1814 | pkg_cstate_limit = pkg_cstate_limits[msr & 0xF]; |
1810 | 1815 | ||
@@ -2043,7 +2048,7 @@ double get_tdp(model) | |||
2043 | unsigned long long msr; | 2048 | unsigned long long msr; |
2044 | 2049 | ||
2045 | if (do_rapl & RAPL_PKG_POWER_INFO) | 2050 | if (do_rapl & RAPL_PKG_POWER_INFO) |
2046 | if (!get_msr(0, MSR_PKG_POWER_INFO, &msr)) | 2051 | if (!get_msr(base_cpu, MSR_PKG_POWER_INFO, &msr)) |
2047 | return ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units; | 2052 | return ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units; |
2048 | 2053 | ||
2049 | switch (model) { | 2054 | switch (model) { |
@@ -2126,7 +2131,7 @@ void rapl_probe(unsigned int family, unsigned int model) | |||
2126 | } | 2131 | } |
2127 | 2132 | ||
2128 | /* units on package 0, verify later other packages match */ | 2133 | /* units on package 0, verify later other packages match */ |
2129 | if (get_msr(0, MSR_RAPL_POWER_UNIT, &msr)) | 2134 | if (get_msr(base_cpu, MSR_RAPL_POWER_UNIT, &msr)) |
2130 | return; | 2135 | return; |
2131 | 2136 | ||
2132 | rapl_power_units = 1.0 / (1 << (msr & 0xF)); | 2137 | rapl_power_units = 1.0 / (1 << (msr & 0xF)); |
@@ -2471,7 +2476,7 @@ double slm_bclk(void) | |||
2471 | unsigned int i; | 2476 | unsigned int i; |
2472 | double freq; | 2477 | double freq; |
2473 | 2478 | ||
2474 | if (get_msr(0, MSR_FSB_FREQ, &msr)) | 2479 | if (get_msr(base_cpu, MSR_FSB_FREQ, &msr)) |
2475 | fprintf(stderr, "SLM BCLK: unknown\n"); | 2480 | fprintf(stderr, "SLM BCLK: unknown\n"); |
2476 | 2481 | ||
2477 | i = msr & 0xf; | 2482 | i = msr & 0xf; |
@@ -2539,7 +2544,7 @@ int set_temperature_target(struct thread_data *t, struct core_data *c, struct pk | |||
2539 | if (!do_nhm_platform_info) | 2544 | if (!do_nhm_platform_info) |
2540 | goto guess; | 2545 | goto guess; |
2541 | 2546 | ||
2542 | if (get_msr(0, MSR_IA32_TEMPERATURE_TARGET, &msr)) | 2547 | if (get_msr(base_cpu, MSR_IA32_TEMPERATURE_TARGET, &msr)) |
2543 | goto guess; | 2548 | goto guess; |
2544 | 2549 | ||
2545 | target_c_local = (msr >> 16) & 0xFF; | 2550 | target_c_local = (msr >> 16) & 0xFF; |
@@ -2913,13 +2918,24 @@ void setup_all_buffers(void) | |||
2913 | for_all_proc_cpus(initialize_counters); | 2918 | for_all_proc_cpus(initialize_counters); |
2914 | } | 2919 | } |
2915 | 2920 | ||
2921 | void set_base_cpu(void) | ||
2922 | { | ||
2923 | base_cpu = sched_getcpu(); | ||
2924 | if (base_cpu < 0) | ||
2925 | err(-ENODEV, "No valid cpus found"); | ||
2926 | |||
2927 | if (debug > 1) | ||
2928 | fprintf(stderr, "base_cpu = %d\n", base_cpu); | ||
2929 | } | ||
2930 | |||
2916 | void turbostat_init() | 2931 | void turbostat_init() |
2917 | { | 2932 | { |
2933 | setup_all_buffers(); | ||
2934 | set_base_cpu(); | ||
2918 | check_dev_msr(); | 2935 | check_dev_msr(); |
2919 | check_permissions(); | 2936 | check_permissions(); |
2920 | process_cpuid(); | 2937 | process_cpuid(); |
2921 | 2938 | ||
2922 | setup_all_buffers(); | ||
2923 | 2939 | ||
2924 | if (debug) | 2940 | if (debug) |
2925 | for_all_cpus(print_epb, ODD_COUNTERS); | 2941 | for_all_cpus(print_epb, ODD_COUNTERS); |