Intel(r) Performance Counter Monitor
Classes | Macros | Functions | Variables
cpucounters.cpp File Reference

The bulk of Intel PCM implementation. More...

#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include "cpucounters.h"
#include "msr.h"
#include "pci.h"
#include "types.h"
#include "utils.h"
#include <pthread.h>
#include <errno.h>
#include <sys/time.h>
#include <string.h>
#include <limits>
#include <map>
#include <fstream>
#include <algorithm>

Classes

class  InstanceLock
 
union  PCM_CPUID_INFO
 
class  TemporalThreadAffinity
 

Macros

#define PCM_INSTANCE_LOCK_SEMAPHORE_NAME   "Intel(r) PCM inst lock"
 
#define PCM_NUM_INSTANCES_SEMAPHORE_NAME   "Num Intel(r) PCM insts"
 
#define PCM_PARAM_PROTECT(...)   __VA_ARGS__
 
#define PCM_CSTATE_ARRAY(array_, val)
 
#define SAFE_SYSCTLBYNAME(message, ret_value)
 
#define CPUCNT_INIT_THE_REST_OF_EVTCNT
 
#define PCM_PCICFG_MC_INIT(controller, channel, arch)
 
#define PCM_PCICFG_SETUP_MC_HANDLE(controller, channel)
 
#define PCM_PCICFG_QPI_INIT(port, arch)
 

Functions

int bitCount (uint64 n)
 
uint32 build_bit_ui (int beg, int end)
 
uint32 extract_bits_ui (uint32 myin, uint32 beg, uint32 end)
 
uint64 build_bit (uint32 beg, uint32 end)
 
uint64 extract_bits (uint64 myin, uint32 beg, uint32 end)
 
int32 extractThermalHeadroom (uint64 val)
 
uint64 get_frequency_from_cpuid ()
 
void pcm_cpuid (int leaf, PCM_CPUID_INFO &info)
 
void pcm_cpuid (const unsigned leaf, const unsigned subleaf, PCM_CPUID_INFO &info)
 
uint64 RDTSC ()
 
uint64 RDTSCP ()
 
SystemCounterState getSystemCounterState ()
 Reads the counter state of the system. More...
 
SocketCounterState getSocketCounterState (uint32 socket)
 Reads the counter state of a socket. More...
 
CoreCounterState getCoreCounterState (uint32 core)
 Reads the counter state of a (logical) core. More...
 
void print_mcfg (const char *path)
 
int getBusFromSocket (const uint32 socket)
 
void * WatchDogProc (void *state)
 

Variables

pthread_mutex_t processIntanceMutex = PTHREAD_MUTEX_INITIALIZER
 

Detailed Description

The bulk of Intel PCM implementation.

Macro Definition Documentation

#define CPUCNT_INIT_THE_REST_OF_EVTCNT
Value:
unc_event_select_reg.fields.occ_ctr_rst = 1; \
unc_event_select_reg.fields.edge = 0; \
unc_event_select_reg.fields.enable_pmi = 0; \
unc_event_select_reg.fields.enable = 1; \
unc_event_select_reg.fields.invert = 0; \
unc_event_select_reg.fields.cmask = 0;
#define PCM_CSTATE_ARRAY (   array_,
  val 
)
Value:
{ \
static uint64 tmp[] = val; \
PCM_COMPILE_ASSERT( sizeof(tmp)/sizeof(uint64) == MAX_C_STATE + 1); \
array_ = tmp; \
break; \
}
#define PCM_PCICFG_MC_INIT (   controller,
  channel,
  arch 
)
Value:
MCX_CHY_REGISTER_DEV_ADDR[controller][channel] = arch##_MC##controller##_CH##channel##_REGISTER_DEV_ADDR; \
MCX_CHY_REGISTER_FUNC_ADDR[controller][channel] = arch##_MC##controller##_CH##channel##_REGISTER_FUNC_ADDR;
#define PCM_PCICFG_QPI_INIT (   port,
  arch 
)
Value:
QPI_PORTX_REGISTER_DEV_ADDR[port] = arch##_QPI_PORT##port##_REGISTER_DEV_ADDR; \
QPI_PORTX_REGISTER_FUNC_ADDR[port] = arch##_QPI_PORT##port##_REGISTER_FUNC_ADDR;
#define PCM_PCICFG_SETUP_MC_HANDLE (   controller,
  channel 
)
Value:
{ \
PciHandleM * handle = createIntelPerfMonDevice(groupnr, bus, \
MCX_CHY_REGISTER_DEV_ADDR[controller][channel], MCX_CHY_REGISTER_FUNC_ADDR[controller][channel], true); \
if(handle) imcHandles[num_imc_channels++] = handle; \
}
#define SAFE_SYSCTLBYNAME (   message,
  ret_value 
)
Value:
{ \
size_t size; \
char *pParam; \
if(0 != sysctlbyname(message, NULL, &size, NULL, 0)) \
{ \
std::cerr << "Unable to determine size of " << message << " sysctl return type." << std::endl; \
return false; \
} \
if(NULL == (pParam = (char *)malloc(size))) \
{ \
std::cerr << "Unable to allocate memory for " << message << std::endl; \
return false; \
} \
if(0 != sysctlbyname(message, (void*)pParam, &size, NULL, 0)) \
{ \
std::cerr << "Unable to get " << message << " from sysctl." << std::endl; \
return false; \
} \
ret_value = convertUnknownToInt(size, pParam); \
free(pParam); \
}

Function Documentation

CoreCounterState getCoreCounterState ( uint32  core)

Reads the counter state of a (logical) core.

Helper function. Uses PCM object to access counters.

Parameters
corecore id
Returns
State of counters in the core

References PCM::getCoreCounterState(), and PCM::getInstance().

SocketCounterState getSocketCounterState ( uint32  socket)

Reads the counter state of a socket.

Helper function. Uses PCM object to access counters.

Parameters
socketsocket id
Returns
State of counters in the socket

References PCM::getInstance(), and PCM::getSocketCounterState().

SystemCounterState getSystemCounterState ( )

Reads the counter state of the system.

Helper function. Uses PCM object to access counters.

System consists of several sockets (CPUs). Socket has a CPU in it. Socket (CPU) consists of several (logical) cores.

Returns
State of counters in the entire system

References PCM::getInstance(), and PCM::getSystemCounterState().