libmsr  0.3.0
A friendlier interface to accessing MSRs on Intel platforms
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
Functions
msr_counters.c File Reference
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/time.h>
#include "msr_core.h"
#include "memhdlr.h"
#include "msr_counters.h"
#include "cpuid.h"
#include "libmsr_debug.h"
Include dependency graph for msr_counters.c:

Functions

void print_available_counters (void)
 Print available general-purpose performance counters.
 
void perfevtsel_storage (struct perfevtsel **e)
 Store the performance event select counter data on the heap.
 
void pmc_storage (struct pmc **p)
 Store the general-purpose performance counter data on the heap.
 
void set_pmc_ctrl_flags (uint64_t cmask, uint64_t flags, uint64_t umask, uint64_t eventsel, int pmcnum, unsigned thread)
 Set a performance event select counter on a single logical processor.
 
void set_all_pmc_ctrl (uint64_t cmask, uint64_t flags, uint64_t umask, uint64_t eventsel, int pmcnum)
 Set a performance event select counter to the same event on all logical processors.
 
int enable_pmc (void)
 Allocate storage for performance counters and reset values.
 
void clear_all_pmc (void)
 Reset all performance counters for each logical processor.
 
int clear_pmc (int idx)
 Reset performance counter on a specific logical processor.
 
void dump_pmc_data_readable (FILE *writedest)
 Print out detailed performance counter data.
 
void unc_perfevtsel_storage (struct unc_perfevtsel **uevt)
 Store the uncore performance event select counter data on the heap.
 
void unc_counters_storage (struct unc_counters **uc)
 Store the uncore general-purpose performance counter data on the heap.
 
void set_pcu_ctrl_flags (uint64_t flags, uint64_t reset, uint64_t occ, uint64_t eventsel, int pcunum, unsigned socket)
 Set an uncore performance event select counter to the same event on a single socket.
 
void set_all_pcu_ctrl (uint64_t flags, uint64_t reset, uint64_t occ, uint64_t eventsel, int pcunum)
 Set an uncore performance event select counter to the same event on all sockets.
 
void enable_pcu (void)
 Allocate storage for uncore performance counters and reset values.
 
void clear_all_pcu (void)
 Reset all uncore performance counters for each socket.
 
int clear_pcu (int idx)
 Reset uncore performance counter on a specific socket.
 
void dump_unc_counter_data_label (FILE *writedest)
 Print the label for the uncore performance counter data print out.
 
void dump_unc_counter_data (FILE *writedest)
 Print out uncore performance counter data.
 
void fixed_counter_storage (struct fixed_counter **ctr0, struct fixed_counter **ctr1, struct fixed_counter **ctr2)
 Initialize storage for fixed-function performance counter data, and store it on the heap.
 
void fixed_counter_ctrl_storage (uint64_t ***perf_ctrl, uint64_t ***fixed_ctrl)
 Initialize storage for performance global control and fixed-function performance control data, and store it on the heap.
 
void init_fixed_counter (struct fixed_counter *ctr)
 Initialize storage for fixed-function performance counter data.
 
void get_fixed_ctr_ctrl (struct fixed_counter *ctr0, struct fixed_counter *ctr1, struct fixed_counter *ctr2)
 
void set_fixed_counter_ctrl (struct fixed_counter *ctr0, struct fixed_counter *ctr1, struct fixed_counter *ctr2)
 Set value of IA32_FIXED_CTR_CTL and IA32_PERF_GLOBAL_CTL and reset all fixed-function performance counters on all logical processors.
 
void get_fixed_counter_config (struct fixed_counter_config *data)
 Retrieve number of fixed-function performance counters on the platform and the bit width of these counters.
 
void enable_fixed_counters (void)
 Enable fixed-function counters by setting enable bit in IA32_FIXED_CTR_CTL.
 
void disable_fixed_counters (void)
 Disable fixed-function counters by clearing enable bit in IA32_FIXED_CTR_CTL.
 
void dump_fixed_counter_data_terse (FILE *writedest)
 Print abbreviated fixed-function performance counter data.
 
void dump_fixed_counter_data_terse_label (FILE *writedest)
 Print the label for the abbreviated fixed-function performance counter data print out.
 
void dump_fixed_counter_data_readable (FILE *writedest)
 Print detailed fixed-function performance counter data.
 

Function Documentation

void clear_all_pcu ( void  )

Reset all uncore performance counters for each socket.

void clear_all_pmc ( void  )

Reset all performance counters for each logical processor.

int clear_pcu ( int  idx)

Reset uncore performance counter on a specific socket.

Parameters
[in]idxUnique socket/package identifier.
Returns
0 if successful, else -1 if socket is invalid.
int clear_pmc ( int  idx)

Reset performance counter on a specific logical processor.

Parameters
[in]idxUnique logical processor identifier.
Returns
0 if successful, else -1 if logical processor is invalid.
void disable_fixed_counters ( void  )

Disable fixed-function counters by clearing enable bit in IA32_FIXED_CTR_CTL.

void dump_fixed_counter_data_readable ( FILE *  writedest)

Print detailed fixed-function performance counter data.

Parameters
[in]writedestFile stream where output will be written to.
void dump_fixed_counter_data_terse ( FILE *  writedest)

Print abbreviated fixed-function performance counter data.

Parameters
[in]writedestFile stream where output will be written to.
void dump_fixed_counter_data_terse_label ( FILE *  writedest)

Print the label for the abbreviated fixed-function performance counter data print out.

Parameters
[in]writedestFile stream where output will be written to.
void dump_pmc_data_readable ( FILE *  writedest)

Print out detailed performance counter data.

Parameters
[in]writedestFile stream where output will be written to.
void dump_unc_counter_data ( FILE *  writedest)

Print out uncore performance counter data.

Parameters
[in]writedestFile stream where output will be written to.
void dump_unc_counter_data_label ( FILE *  writedest)

Print the label for the uncore performance counter data print out.

Parameters
[in]writedestFile stream where output will be written to.
void enable_fixed_counters ( void  )

Enable fixed-function counters by setting enable bit in IA32_FIXED_CTR_CTL.

void enable_pcu ( void  )

Allocate storage for uncore performance counters and reset values.

int enable_pmc ( void  )

Allocate storage for performance counters and reset values.

Returns
0 if successful, else -1 if no general-purpose performance counters are available.
void fixed_counter_ctrl_storage ( uint64_t ***  perf_ctrl,
uint64_t ***  fixed_ctrl 
)

Initialize storage for performance global control and fixed-function performance control data, and store it on the heap.

There are plans to use a struct to make the indirection less crazy.

Parameters
[out]perf_ctrlData for controlling counting of each performance counter.
[out]fixed_ctrlPointer to data for controlling the operations of a fixed-function performance counter.
void fixed_counter_storage ( struct fixed_counter **  ctr0,
struct fixed_counter **  ctr1,
struct fixed_counter **  ctr2 
)

Initialize storage for fixed-function performance counter data, and store it on the heap.

Parameters
[out]ctr0Data for fixed-function performance counter for any instructions retired.
[out]ctr1Data for fixed-function performance counter for core unhalted clock cycles.
[out]ctr2Data for fixed-function performance counter for unhalted reference clock cycles.
void get_fixed_counter_config ( struct fixed_counter_config data)

Retrieve number of fixed-function performance counters on the platform and the bit width of these counters.

Parameters
[out]dataData for general information about fixed-function performance counters.
void get_fixed_ctr_ctrl ( struct fixed_counter ctr0,
struct fixed_counter ctr1,
struct fixed_counter ctr2 
)
void init_fixed_counter ( struct fixed_counter ctr)

Initialize storage for fixed-function performance counter data.

Parameters
[out]ctrData for fixed-function performance counters.
void perfevtsel_storage ( struct perfevtsel **  e)

Store the performance event select counter data on the heap.

Parameters
[out]eData for performance event select counters.
void pmc_storage ( struct pmc **  p)

Store the general-purpose performance counter data on the heap.

Parameters
[out]pData for general-purpose performance counters.
void print_available_counters ( void  )

Print available general-purpose performance counters.

void set_all_pcu_ctrl ( uint64_t  flags,
uint64_t  reset,
uint64_t  occ,
uint64_t  eventsel,
int  pcunum 
)

Set an uncore performance event select counter to the same event on all sockets.

Can probably consolidate event select into a single function.

Parameters
[in]flagsToggle additional options, such as user mode vs. OS mode, enable PMI upon counter overflow, invert cmask, edge detection of event occurrence, etc.
[in]reset
[in]occReset queue occupancy counter
[in]eventselUnique event logic unit identifier.
[in]pcunumUnique performance event select counter identifier.
void set_all_pmc_ctrl ( uint64_t  cmask,
uint64_t  flags,
uint64_t  umask,
uint64_t  eventsel,
int  pmcnum 
)

Set a performance event select counter to the same event on all logical processors.

Parameters
[in]cmaskCount multiple event occurrences per cycle.
[in]flagsToggle additional options, such as user mode vs. OS mode, enable PMI upon counter overflow, invert cmask, edge detection of event occurrence, etc.
[in]umaskCondition to be detected by the event logic unit.
[in]eventselUnique event logic unit identifier.
[in]pmcnumUnique performance event select counter identifier.
void set_fixed_counter_ctrl ( struct fixed_counter ctr0,
struct fixed_counter ctr1,
struct fixed_counter ctr2 
)

Set value of IA32_FIXED_CTR_CTL and IA32_PERF_GLOBAL_CTL and reset all fixed-function performance counters on all logical processors.

Parameters
[in]ctr0Data for fixed-function performance counter for any instructions retired.
[in]ctr1Data for fixed-function performance counter for core unhalted clock cycles.
[in]ctr2Data for fixed-function performance counter for unhalted reference clock cycles.
void set_pcu_ctrl_flags ( uint64_t  flags,
uint64_t  reset,
uint64_t  occ,
uint64_t  eventsel,
int  pcunum,
unsigned  socket 
)

Set an uncore performance event select counter to the same event on a single socket.

Parameters
[in]flagsToggle additional options, such as user mode vs. OS mode, enable PMI upon counter overflow, invert cmask, edge detection of event occurrence, etc.
[in]resetEnable reset of queue occupancy counter.
[in]occCounter for queue occupancy.
[in]eventselUnique event logic unit identifier.
[in]pcunumUnique performance event select counter identifier.
[in]socketUnique socket/package identifier.
void set_pmc_ctrl_flags ( uint64_t  cmask,
uint64_t  flags,
uint64_t  umask,
uint64_t  eventsel,
int  pmcnum,
unsigned  thread 
)

Set a performance event select counter on a single logical processor.

Parameters
[in]cmaskCount multiple event occurrences per cycle.
[in]flagsToggle additional options, such as user mode vs. OS mode, enable PMI upon counter overflow, invert cmask, edge detection of event occurrence, etc.
[in]umaskCondition to be detected by the event logic unit.
[in]eventselUnique event logic unit identifier.
[in]pmcnumUnique performance event select counter identifier.
[in]threadUnique logical processor identifier.
void unc_counters_storage ( struct unc_counters **  uc)

Store the uncore general-purpose performance counter data on the heap.

Parameters
[out]ucPointer to data for uncore general-purpose performance counters.
void unc_perfevtsel_storage ( struct unc_perfevtsel **  uevt)

Store the uncore performance event select counter data on the heap.

Parameters
[out]uevtPointer to data for uncore performance event select counters.