turbostat.c (aeb01e6d71ffaf3011ac755c3083cc200ed57cb4) | turbostat.c (7ab5ff4937a338783d147ec2d8c8714f48a5de79) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * turbostat -- show CPU frequency and C-state residency 4 * on modern Intel and AMD processors. 5 * 6 * Copyright (c) 2013 Intel Corporation. 7 * Len Brown <len.brown@intel.com> 8 */ --- 21 unchanged lines hidden (view full) --- 30#include <sched.h> 31#include <time.h> 32#include <cpuid.h> 33#include <sys/capability.h> 34#include <errno.h> 35#include <math.h> 36#include <linux/perf_event.h> 37#include <asm/unistd.h> | 1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * turbostat -- show CPU frequency and C-state residency 4 * on modern Intel and AMD processors. 5 * 6 * Copyright (c) 2013 Intel Corporation. 7 * Len Brown <len.brown@intel.com> 8 */ --- 21 unchanged lines hidden (view full) --- 30#include <sched.h> 31#include <time.h> 32#include <cpuid.h> 33#include <sys/capability.h> 34#include <errno.h> 35#include <math.h> 36#include <linux/perf_event.h> 37#include <asm/unistd.h> |
38#include <stdbool.h> |
|
38 39char *proc_stat = "/proc/stat"; 40FILE *outf; 41int *fd_percpu; 42int *fd_instr_count_percpu; 43struct timeval interval_tv = {5, 0}; 44struct timespec interval_ts = {5, 0}; 45unsigned int num_iterations; --- 134 unchanged lines hidden (view full) --- 180 unsigned long long c1; 181 unsigned long long instr_count; 182 unsigned long long irq_count; 183 unsigned int smi_count; 184 unsigned int cpu_id; 185 unsigned int apic_id; 186 unsigned int x2apic_id; 187 unsigned int flags; | 39 40char *proc_stat = "/proc/stat"; 41FILE *outf; 42int *fd_percpu; 43int *fd_instr_count_percpu; 44struct timeval interval_tv = {5, 0}; 45struct timespec interval_ts = {5, 0}; 46unsigned int num_iterations; --- 134 unchanged lines hidden (view full) --- 181 unsigned long long c1; 182 unsigned long long instr_count; 183 unsigned long long irq_count; 184 unsigned int smi_count; 185 unsigned int cpu_id; 186 unsigned int apic_id; 187 unsigned int x2apic_id; 188 unsigned int flags; |
189 bool is_atom; |
|
188#define CPU_IS_FIRST_THREAD_IN_CORE 0x2 189#define CPU_IS_FIRST_CORE_IN_PACKAGE 0x4 190 unsigned long long counter[MAX_ADDED_THREAD_COUNTERS]; 191} *thread_even, *thread_odd; 192 193struct core_data { 194 unsigned long long c3; 195 unsigned long long c6; --- 1889 unchanged lines hidden (view full) --- 2085 if ((DO_BIC(BIC_CPU_c6) || soft_c1_residency_display(BIC_CPU_c6)) && !do_knl_cstates) { 2086 if (get_msr(cpu, MSR_CORE_C6_RESIDENCY, &c->c6)) 2087 return -7; 2088 } else if (do_knl_cstates || soft_c1_residency_display(BIC_CPU_c6)) { 2089 if (get_msr(cpu, MSR_KNL_CORE_C6_RESIDENCY, &c->c6)) 2090 return -7; 2091 } 2092 | 190#define CPU_IS_FIRST_THREAD_IN_CORE 0x2 191#define CPU_IS_FIRST_CORE_IN_PACKAGE 0x4 192 unsigned long long counter[MAX_ADDED_THREAD_COUNTERS]; 193} *thread_even, *thread_odd; 194 195struct core_data { 196 unsigned long long c3; 197 unsigned long long c6; --- 1889 unchanged lines hidden (view full) --- 2087 if ((DO_BIC(BIC_CPU_c6) || soft_c1_residency_display(BIC_CPU_c6)) && !do_knl_cstates) { 2088 if (get_msr(cpu, MSR_CORE_C6_RESIDENCY, &c->c6)) 2089 return -7; 2090 } else if (do_knl_cstates || soft_c1_residency_display(BIC_CPU_c6)) { 2091 if (get_msr(cpu, MSR_KNL_CORE_C6_RESIDENCY, &c->c6)) 2092 return -7; 2093 } 2094 |
2093 if (DO_BIC(BIC_CPU_c7) || soft_c1_residency_display(BIC_CPU_c7)) | 2095 if (DO_BIC(BIC_CPU_c7) || soft_c1_residency_display(BIC_CPU_c7)) { |
2094 if (get_msr(cpu, MSR_CORE_C7_RESIDENCY, &c->c7)) 2095 return -8; | 2096 if (get_msr(cpu, MSR_CORE_C7_RESIDENCY, &c->c7)) 2097 return -8; |
2098 else if (t->is_atom) { 2099 /* 2100 * For Atom CPUs that has core cstate deeper than c6, 2101 * MSR_CORE_C6_RESIDENCY returns residency of cc6 and deeper. 2102 * Minus CC7 (and deeper cstates) residency to get 2103 * accturate cc6 residency. 2104 */ 2105 c->c6 -= c->c7; 2106 } 2107 } |
|
2096 2097 if (DO_BIC(BIC_Mod_c6)) 2098 if (get_msr(cpu, MSR_MODULE_C6_RES_MS, &c->mc6_us)) 2099 return -8; 2100 2101 if (DO_BIC(BIC_CoreTmp)) { 2102 if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr)) 2103 return -9; --- 2802 unchanged lines hidden (view full) --- 4906 if (has_snb_msrs(family, model) || is_knl(family, model)) 4907 return 100.00; 4908 else if (is_slm(family, model)) 4909 return slm_bclk(); 4910 else 4911 return 133.33; 4912} 4913 | 2108 2109 if (DO_BIC(BIC_Mod_c6)) 2110 if (get_msr(cpu, MSR_MODULE_C6_RES_MS, &c->mc6_us)) 2111 return -8; 2112 2113 if (DO_BIC(BIC_CoreTmp)) { 2114 if (get_msr(cpu, MSR_IA32_THERM_STATUS, &msr)) 2115 return -9; --- 2802 unchanged lines hidden (view full) --- 4918 if (has_snb_msrs(family, model) || is_knl(family, model)) 4919 return 100.00; 4920 else if (is_slm(family, model)) 4921 return slm_bclk(); 4922 else 4923 return 133.33; 4924} 4925 |
4926int get_cpu_type(struct thread_data *t, struct core_data *c, struct pkg_data *p) 4927{ 4928 unsigned int eax, ebx, ecx, edx; 4929 4930 if (!genuine_intel) 4931 return 0; 4932 4933 if (cpu_migrate(t->cpu_id)) { 4934 fprintf(outf, "Could not migrate to CPU %d\n", t->cpu_id); 4935 return -1; 4936 } 4937 4938 if (max_level < 0x1a) 4939 return 0; 4940 4941 __cpuid(0x1a, eax, ebx, ecx, edx); 4942 eax = (eax >> 24) & 0xFF; 4943 if (eax == 0x20 ) 4944 t->is_atom = true; 4945 return 0; 4946} 4947 |
|
4914/* 4915 * MSR_IA32_TEMPERATURE_TARGET indicates the temperature where 4916 * the Thermal Control Circuit (TCC) activates. 4917 * This is usually equal to tjMax. 4918 * 4919 * Older processors do not have this MSR, so there we guess, 4920 * but also allow cmdline over-ride with -T. 4921 * --- 869 unchanged lines hidden (view full) --- 5791 if (!quiet) 5792 for_all_cpus(print_perf_limit, ODD_COUNTERS); 5793 5794 if (!quiet) 5795 for_all_cpus(print_rapl, ODD_COUNTERS); 5796 5797 for_all_cpus(set_temperature_target, ODD_COUNTERS); 5798 | 4948/* 4949 * MSR_IA32_TEMPERATURE_TARGET indicates the temperature where 4950 * the Thermal Control Circuit (TCC) activates. 4951 * This is usually equal to tjMax. 4952 * 4953 * Older processors do not have this MSR, so there we guess, 4954 * but also allow cmdline over-ride with -T. 4955 * --- 869 unchanged lines hidden (view full) --- 5825 if (!quiet) 5826 for_all_cpus(print_perf_limit, ODD_COUNTERS); 5827 5828 if (!quiet) 5829 for_all_cpus(print_rapl, ODD_COUNTERS); 5830 5831 for_all_cpus(set_temperature_target, ODD_COUNTERS); 5832 |
5833 for_all_cpus(get_cpu_type, ODD_COUNTERS); 5834 for_all_cpus(get_cpu_type, EVEN_COUNTERS); 5835 |
|
5799 if (!quiet) 5800 for_all_cpus(print_thermal, ODD_COUNTERS); 5801 5802 if (!quiet && do_irtl_snb) 5803 print_irtl(); 5804} 5805 5806int fork_it(char **argv) --- 567 unchanged lines hidden --- | 5836 if (!quiet) 5837 for_all_cpus(print_thermal, ODD_COUNTERS); 5838 5839 if (!quiet && do_irtl_snb) 5840 print_irtl(); 5841} 5842 5843int fork_it(char **argv) --- 567 unchanged lines hidden --- |