Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
turbostat.c File Reference
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/resource.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/time.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>
#include <ctype.h>
#include <sched.h>

Go to the source code of this file.

Data Structures

struct  thread_data
 
struct  core_data
 
struct  pkg_data
 
struct  system_summary
 
struct  topo_params
 

Macros

#define _GNU_SOURCE
 
#define MSR_NEHALEM_PLATFORM_INFO   0xCE
 
#define MSR_NEHALEM_TURBO_RATIO_LIMIT   0x1AD
 
#define MSR_IVT_TURBO_RATIO_LIMIT   0x1AE
 
#define MSR_APERF   0xE8
 
#define MSR_MPERF   0xE7
 
#define MSR_PKG_C2_RESIDENCY   0x60D /* SNB only */
 
#define MSR_PKG_C3_RESIDENCY   0x3F8
 
#define MSR_PKG_C6_RESIDENCY   0x3F9
 
#define MSR_PKG_C7_RESIDENCY   0x3FA /* SNB only */
 
#define MSR_CORE_C3_RESIDENCY   0x3FC
 
#define MSR_CORE_C6_RESIDENCY   0x3FD
 
#define MSR_CORE_C7_RESIDENCY   0x3FE /* SNB only */
 
#define CPU_IS_FIRST_THREAD_IN_CORE   0x2
 
#define CPU_IS_FIRST_CORE_IN_PACKAGE   0x4
 
#define ODD_COUNTERS   thread_odd, core_odd, package_odd
 
#define EVEN_COUNTERS   thread_even, core_even, package_even
 
#define GET_THREAD(thread_base, thread_no, core_no, pkg_no)
 
#define GET_CORE(core_base, core_no, pkg_no)   (core_base + (pkg_no) * topo.num_cores_per_pkg + (core_no))
 
#define GET_PKG(pkg_base, pkg_no)   (pkg_base + pkg_no)
 

Functions

void setup_all_buffers (void)
 
int cpu_is_not_present (int cpu)
 
int for_all_cpus (int(func)(struct thread_data *, struct core_data *, struct pkg_data *), struct thread_data *thread_base, struct core_data *core_base, struct pkg_data *pkg_base)
 
int cpu_migrate (int cpu)
 
int get_msr (int cpu, off_t offset, unsigned long long *msr)
 
void print_header (void)
 
int dump_counters (struct thread_data *t, struct core_data *c, struct pkg_data *p)
 
int format_counters (struct thread_data *t, struct core_data *c, struct pkg_data *p)
 
void flush_stdout ()
 
void flush_stderr ()
 
void format_all_counters (struct thread_data *t, struct core_data *c, struct pkg_data *p)
 
void delta_package (struct pkg_data *new, struct pkg_data *old)
 
void delta_core (struct core_data *new, struct core_data *old)
 
void delta_thread (struct thread_data *new, struct thread_data *old, struct core_data *core_delta)
 
int delta_cpu (struct thread_data *t, struct core_data *c, struct pkg_data *p, struct thread_data *t2, struct core_data *c2, struct pkg_data *p2)
 
void clear_counters (struct thread_data *t, struct core_data *c, struct pkg_data *p)
 
int sum_counters (struct thread_data *t, struct core_data *c, struct pkg_data *p)
 
void compute_average (struct thread_data *t, struct core_data *c, struct pkg_data *p)
 
int get_counters (struct thread_data *t, struct core_data *c, struct pkg_data *p)
 
void print_verbose_header (void)
 
void free_all_buffers (void)
 
int cpu_is_first_sibling_in_core (int cpu)
 
int cpu_is_first_core_in_package (int cpu)
 
int get_physical_package_id (int cpu)
 
int get_core_id (int cpu)
 
int get_num_ht_siblings (int cpu)
 
int for_all_cpus_2 (int(func)(struct thread_data *, struct core_data *, struct pkg_data *, struct thread_data *, struct core_data *, struct pkg_data *), struct thread_data *thread_base, struct core_data *core_base, struct pkg_data *pkg_base, struct thread_data *thread_base2, struct core_data *core_base2, struct pkg_data *pkg_base2)
 
int for_all_proc_cpus (int(func)(int))
 
void re_initialize (void)
 
int count_cpus (int cpu)
 
int mark_cpu_present (int cpu)
 
void turbostat_loop ()
 
void check_dev_msr ()
 
void check_super_user ()
 
int has_nehalem_turbo_ratio_limit (unsigned int family, unsigned int model)
 
int has_ivt_turbo_ratio_limit (unsigned int family, unsigned int model)
 
int is_snb (unsigned int family, unsigned int model)
 
double discover_bclk (unsigned int family, unsigned int model)
 
void check_cpuid ()
 
void usage ()
 
int dir_filter (const struct dirent *dirp)
 
int open_dev_cpu_msr (int dummy1)
 
void topology_probe ()
 
void allocate_counters (struct thread_data **t, struct core_data **c, struct pkg_data **p)
 
void init_counter (struct thread_data *thread_base, struct core_data *core_base, struct pkg_data *pkg_base, int thread_num, int core_num, int pkg_num, int cpu_id)
 
int initialize_counters (int cpu_id)
 
void allocate_output_buffer ()
 
void turbostat_init ()
 
int fork_it (char **argv)
 
void cmdline (int argc, char **argv)
 
int main (int argc, char **argv)
 

Variables

charproc_stat = "/proc/stat"
 
unsigned int interval_sec = 5
 
unsigned int verbose
 
unsigned int summary_only
 
unsigned int skip_c0
 
unsigned int skip_c1
 
unsigned int do_nhm_cstates
 
unsigned int do_snb_cstates
 
unsigned int has_aperf
 
unsigned int units = 1000000000
 
unsigned int genuine_intel
 
unsigned int has_invariant_tsc
 
unsigned int do_nehalem_platform_info
 
unsigned int do_nehalem_turbo_ratio_limit
 
unsigned int do_ivt_turbo_ratio_limit
 
unsigned int extra_msr_offset32
 
unsigned int extra_msr_offset64
 
unsigned int extra_delta_offset32
 
unsigned int extra_delta_offset64
 
double bclk
 
unsigned int show_pkg
 
unsigned int show_core
 
unsigned int show_cpu
 
unsigned int show_pkg_only
 
unsigned int show_core_only
 
charoutput_buffer
 
charoutp
 
int aperf_mperf_unstable
 
int backwards_count
 
charprogname
 
cpu_set_t * cpu_present_set
 
cpu_set_t * cpu_affinity_set
 
size_t cpu_present_setsize
 
size_t cpu_affinity_setsize
 
struct thread_datathread_even
 
struct thread_datathread_odd
 
struct core_datacore_even
 
struct core_datacore_odd
 
struct pkg_datapackage_even
 
struct pkg_datapackage_odd
 
struct system_summary sum
 
struct system_summary average
 
struct topo_params topo
 
struct timeval tv_even tv_odd tv_delta
 

Macro Definition Documentation

#define _GNU_SOURCE

Definition at line 22 of file turbostat.c.

#define CPU_IS_FIRST_CORE_IN_PACKAGE   0x4

Definition at line 97 of file turbostat.c.

#define CPU_IS_FIRST_THREAD_IN_CORE   0x2

Definition at line 96 of file turbostat.c.

#define EVEN_COUNTERS   thread_even, core_even, package_even

Definition at line 116 of file turbostat.c.

#define GET_CORE (   core_base,
  core_no,
  pkg_no 
)    (core_base + (pkg_no) * topo.num_cores_per_pkg + (core_no))

Definition at line 122 of file turbostat.c.

#define GET_PKG (   pkg_base,
  pkg_no 
)    (pkg_base + pkg_no)

Definition at line 124 of file turbostat.c.

#define GET_THREAD (   thread_base,
  thread_no,
  core_no,
  pkg_no 
)
Value:
(thread_base + (pkg_no) * topo.num_cores_per_pkg * \
topo.num_threads_per_core + \
(core_no) * topo.num_threads_per_core + (thread_no))

Definition at line 118 of file turbostat.c.

#define MSR_APERF   0xE8

Definition at line 41 of file turbostat.c.

#define MSR_CORE_C3_RESIDENCY   0x3FC

Definition at line 47 of file turbostat.c.

#define MSR_CORE_C6_RESIDENCY   0x3FD

Definition at line 48 of file turbostat.c.

#define MSR_CORE_C7_RESIDENCY   0x3FE /* SNB only */

Definition at line 49 of file turbostat.c.

#define MSR_IVT_TURBO_RATIO_LIMIT   0x1AE

Definition at line 40 of file turbostat.c.

#define MSR_MPERF   0xE7

Definition at line 42 of file turbostat.c.

#define MSR_NEHALEM_PLATFORM_INFO   0xCE

Definition at line 38 of file turbostat.c.

#define MSR_NEHALEM_TURBO_RATIO_LIMIT   0x1AD

Definition at line 39 of file turbostat.c.

#define MSR_PKG_C2_RESIDENCY   0x60D /* SNB only */

Definition at line 43 of file turbostat.c.

#define MSR_PKG_C3_RESIDENCY   0x3F8

Definition at line 44 of file turbostat.c.

#define MSR_PKG_C6_RESIDENCY   0x3F9

Definition at line 45 of file turbostat.c.

#define MSR_PKG_C7_RESIDENCY   0x3FA /* SNB only */

Definition at line 46 of file turbostat.c.

#define ODD_COUNTERS   thread_odd, core_odd, package_odd

Definition at line 115 of file turbostat.c.

Function Documentation

void allocate_counters ( struct thread_data **  t,
struct core_data **  c,
struct pkg_data **  p 
)

Definition at line 1438 of file turbostat.c.

void allocate_output_buffer ( )

Definition at line 1522 of file turbostat.c.

void check_cpuid ( )

Definition at line 1234 of file turbostat.c.

void check_dev_msr ( )

Definition at line 1150 of file turbostat.c.

void check_super_user ( )

Definition at line 1161 of file turbostat.c.

void clear_counters ( struct thread_data t,
struct core_data c,
struct pkg_data p 
)

Definition at line 569 of file turbostat.c.

void cmdline ( int  argc,
char **  argv 
)

Definition at line 1601 of file turbostat.c.

void compute_average ( struct thread_data t,
struct core_data c,
struct pkg_data p 
)

Definition at line 625 of file turbostat.c.

int count_cpus ( int  cpu)

Definition at line 1086 of file turbostat.c.

int cpu_is_first_core_in_package ( int  cpu)

Definition at line 913 of file turbostat.c.

int cpu_is_first_sibling_in_core ( int  cpu)

Definition at line 892 of file turbostat.c.

int cpu_is_not_present ( int  cpu)

Definition at line 146 of file turbostat.c.

int cpu_migrate ( int  cpu)

Definition at line 185 of file turbostat.c.

void delta_core ( struct core_data new,
struct core_data old 
)

Definition at line 474 of file turbostat.c.

int delta_cpu ( struct thread_data t,
struct core_data c,
struct pkg_data p,
struct thread_data t2,
struct core_data c2,
struct pkg_data p2 
)

Definition at line 551 of file turbostat.c.

void delta_package ( struct pkg_data new,
struct pkg_data old 
)

Definition at line 465 of file turbostat.c.

void delta_thread ( struct thread_data new,
struct thread_data old,
struct core_data core_delta 
)

Definition at line 485 of file turbostat.c.

int dir_filter ( const struct dirent dirp)

Definition at line 1325 of file turbostat.c.

double discover_bclk ( unsigned int  family,
unsigned int  model 
)

Definition at line 1226 of file turbostat.c.

int dump_counters ( struct thread_data t,
struct core_data c,
struct pkg_data p 
)

Definition at line 262 of file turbostat.c.

void flush_stderr ( )

Definition at line 440 of file turbostat.c.

void flush_stdout ( )

Definition at line 435 of file turbostat.c.

int for_all_cpus ( int(func)(struct thread_data *, struct core_data *, struct pkg_data *)  ,
struct thread_data thread_base,
struct core_data core_base,
struct pkg_data pkg_base 
)

Definition at line 155 of file turbostat.c.

int for_all_cpus_2 ( int(func)(struct thread_data *, struct core_data *, struct pkg_data *, struct thread_data *, struct core_data *, struct pkg_data *)  ,
struct thread_data thread_base,
struct core_data core_base,
struct pkg_data pkg_base,
struct thread_data thread_base2,
struct core_data core_base2,
struct pkg_data pkg_base2 
)

Definition at line 998 of file turbostat.c.

int for_all_proc_cpus ( int(func)(int )

Definition at line 1041 of file turbostat.c.

int fork_it ( char **  argv)

Definition at line 1553 of file turbostat.c.

void format_all_counters ( struct thread_data t,
struct core_data c,
struct pkg_data p 
)

Definition at line 445 of file turbostat.c.

int format_counters ( struct thread_data t,
struct core_data c,
struct pkg_data p 
)

Definition at line 309 of file turbostat.c.

void free_all_buffers ( void  )

Definition at line 857 of file turbostat.c.

int get_core_id ( int  cpu)

Definition at line 947 of file turbostat.c.

int get_counters ( struct thread_data t,
struct core_data c,
struct pkg_data p 
)

Definition at line 667 of file turbostat.c.

int get_msr ( int  cpu,
off_t  offset,
unsigned long long msr 
)

Definition at line 195 of file turbostat.c.

int get_num_ht_siblings ( int  cpu)

Definition at line 964 of file turbostat.c.

int get_physical_package_id ( int  cpu)

Definition at line 930 of file turbostat.c.

int has_ivt_turbo_ratio_limit ( unsigned int  family,
unsigned int  model 
)

Definition at line 1194 of file turbostat.c.

int has_nehalem_turbo_ratio_limit ( unsigned int  family,
unsigned int  model 
)

Definition at line 1169 of file turbostat.c.

void init_counter ( struct thread_data thread_base,
struct core_data core_base,
struct pkg_data pkg_base,
int  thread_num,
int  core_num,
int  pkg_num,
int  cpu_id 
)

Definition at line 1479 of file turbostat.c.

int initialize_counters ( int  cpu_id)

Definition at line 1503 of file turbostat.c.

int is_snb ( unsigned int  family,
unsigned int  model 
)

Definition at line 1211 of file turbostat.c.

int main ( int  argc,
char **  argv 
)

Definition at line 1645 of file turbostat.c.

int mark_cpu_present ( int  cpu)

Definition at line 1094 of file turbostat.c.

int open_dev_cpu_msr ( int  dummy1)

Definition at line 1333 of file turbostat.c.

void print_header ( void  )

Definition at line 217 of file turbostat.c.

void print_verbose_header ( void  )

Definition at line 737 of file turbostat.c.

void re_initialize ( void  )

Definition at line 1074 of file turbostat.c.

void setup_all_buffers ( void  )

Definition at line 1532 of file turbostat.c.

int sum_counters ( struct thread_data t,
struct core_data c,
struct pkg_data p 
)

Definition at line 591 of file turbostat.c.

void topology_probe ( )

Definition at line 1338 of file turbostat.c.

void turbostat_init ( )

Definition at line 1540 of file turbostat.c.

void turbostat_loop ( )

Definition at line 1100 of file turbostat.c.

void usage ( void  )

Definition at line 1313 of file turbostat.c.

Variable Documentation

int aperf_mperf_unstable

Definition at line 78 of file turbostat.c.

int backwards_count

Definition at line 79 of file turbostat.c.

double bclk

Definition at line 70 of file turbostat.c.

struct core_data * core_even
struct core_data * core_odd
cpu_set_t * cpu_affinity_set

Definition at line 82 of file turbostat.c.

size_t cpu_affinity_setsize

Definition at line 83 of file turbostat.c.

cpu_set_t* cpu_present_set

Definition at line 82 of file turbostat.c.

size_t cpu_present_setsize

Definition at line 83 of file turbostat.c.

unsigned int do_ivt_turbo_ratio_limit

Definition at line 65 of file turbostat.c.

unsigned int do_nehalem_platform_info

Definition at line 63 of file turbostat.c.

unsigned int do_nehalem_turbo_ratio_limit

Definition at line 64 of file turbostat.c.

unsigned int do_nhm_cstates

Definition at line 57 of file turbostat.c.

unsigned int do_snb_cstates

Definition at line 58 of file turbostat.c.

unsigned int extra_delta_offset32

Definition at line 68 of file turbostat.c.

unsigned int extra_delta_offset64

Definition at line 69 of file turbostat.c.

unsigned int extra_msr_offset32

Definition at line 66 of file turbostat.c.

unsigned int extra_msr_offset64

Definition at line 67 of file turbostat.c.

unsigned int genuine_intel

Definition at line 61 of file turbostat.c.

unsigned int has_aperf

Definition at line 59 of file turbostat.c.

unsigned int has_invariant_tsc

Definition at line 62 of file turbostat.c.

unsigned int interval_sec = 5

Definition at line 52 of file turbostat.c.

char * outp

Definition at line 76 of file turbostat.c.

char* output_buffer

Definition at line 76 of file turbostat.c.

struct pkg_data * package_even
struct pkg_data * package_odd
char* proc_stat = "/proc/stat"

Definition at line 51 of file turbostat.c.

char* progname

Definition at line 80 of file turbostat.c.

unsigned int show_core

Definition at line 72 of file turbostat.c.

unsigned int show_core_only

Definition at line 75 of file turbostat.c.

unsigned int show_cpu

Definition at line 73 of file turbostat.c.

unsigned int show_pkg

Definition at line 71 of file turbostat.c.

unsigned int show_pkg_only

Definition at line 74 of file turbostat.c.

unsigned int skip_c0

Definition at line 55 of file turbostat.c.

unsigned int skip_c1

Definition at line 56 of file turbostat.c.

unsigned int summary_only

Definition at line 54 of file turbostat.c.

struct thread_data * thread_even
struct thread_data * thread_odd
struct timeval tv_even tv_odd tv_delta

Definition at line 142 of file turbostat.c.

unsigned int units = 1000000000

Definition at line 60 of file turbostat.c.

unsigned int verbose

Definition at line 53 of file turbostat.c.