Processor Counter Monitor
Classes | Macros | Functions | Variables
cpucounters.cpp File Reference

The bulk of PCM implementation. More...

#include <stdio.h>
#include <assert.h>
#include "cpucounters.h"
#include "msr.h"
#include "pci.h"
#include "types.h"
#include "utils.h"
#include "topology.h"
#include <pthread.h>
#include <errno.h>
#include <sys/time.h>
#include <string.h>
#include <limits>
#include <map>
#include <algorithm>
#include <thread>
#include <future>
#include <functional>
#include <queue>
#include <condition_variable>
#include <mutex>
#include <atomic>
Include dependency graph for cpucounters.cpp:

Classes

class  pcm::TemporalThreadAffinity
 
class  pcm::CoreTaskQueue
 

Macros

#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_QPI_INIT(port, arch)
 
#define PCM_PCICFG_M3UPI_INIT(port, arch)
 
#define PCM_PCICFG_EDC_INIT(controller, clock, arch)
 
#define PCM_PCICFG_M2M_INIT(x, arch)
 
#define PCM_PCICFG_HA_INIT(x, arch)
 
#define PCM_MEM_CAPACITY   (1024ULL*1024ULL*64ULL)
 

Functions

int32 pcm::extractThermalHeadroom (uint64 val)
 
uint64 pcm::get_frequency_from_cpuid ()
 
void pcm::pcm_cpuid (const unsigned leaf, const unsigned subleaf, PCM_CPUID_INFO &info)
 
void pcm::initSocket2Bus (std::vector< std::pair< uint32, uint32 > > &socket2bus, uint32 device, uint32 function, const uint32 DEV_IDS[], uint32 devIdsSize)
 
void pcm::initSocket2Ubox0Bus ()
 
uint64 pcm::RDTSC ()
 
SystemCounterState pcm::getSystemCounterState ()
 Reads the counter state of the system. More...
 
SocketCounterState pcm::getSocketCounterState (uint32 socket)
 Reads the counter state of a socket. More...
 
CoreCounterState pcm::getCoreCounterState (uint32 core)
 Reads the counter state of a (logical) core. More...
 
void pcm::print_mcfg (const char *path)
 
int pcm::getBusFromSocket (const uint32 socket)
 

Variables

std::mutex pcm::instanceCreationMutex
 
std::vector< std::pair< uint32, uint32 > > pcm::socket2UBOX0bus
 
std::mutex pcm::printErrorMutex
 
Mutex pcm::socket2busMutex
 

Detailed Description

The bulk of PCM implementation.

Macro Definition Documentation

◆ CPUCNT_INIT_THE_REST_OF_EVTCNT

#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;

◆ PCM_CSTATE_ARRAY

#define PCM_CSTATE_ARRAY (   array_,
  val 
)
Value:
{ \
static uint64 tmp[] = val; \
PCM_COMPILE_ASSERT(sizeof(tmp) / sizeof(uint64) == (static_cast<int>(MAX_C_STATE)+1)); \
array_ = tmp; \
break; \
}

◆ PCM_PCICFG_EDC_INIT

#define PCM_PCICFG_EDC_INIT (   controller,
  clock,
  arch 
)
Value:
EDCRegisterLocation.resize(controller + 1); \
EDCRegisterLocation[controller] = std::make_pair(arch##_EDC##controller##_##clock##_REGISTER_DEV_ADDR, arch##_EDC##controller##_##clock##_REGISTER_FUNC_ADDR);

◆ PCM_PCICFG_HA_INIT

#define PCM_PCICFG_HA_INIT (   x,
  arch 
)
Value:
HARegisterLocation.resize(x + 1); \
HARegisterLocation[x] = std::make_pair(arch##_HA##x##_REGISTER_DEV_ADDR, arch##_HA##x##_REGISTER_FUNC_ADDR);

◆ PCM_PCICFG_M2M_INIT

#define PCM_PCICFG_M2M_INIT (   x,
  arch 
)
Value:
M2MRegisterLocation.resize(x + 1); \
M2MRegisterLocation[x] = std::make_pair(arch##_M2M_##x##_REGISTER_DEV_ADDR, arch##_M2M_##x##_REGISTER_FUNC_ADDR);

◆ PCM_PCICFG_M3UPI_INIT

#define PCM_PCICFG_M3UPI_INIT (   port,
  arch 
)
Value:
M3UPIRegisterLocation.resize(port + 1); \
M3UPIRegisterLocation[port] = std::make_pair(arch##_M3UPI_PORT##port##_REGISTER_DEV_ADDR, arch##_M3UPI_PORT##port##_REGISTER_FUNC_ADDR);

◆ PCM_PCICFG_MC_INIT

#define PCM_PCICFG_MC_INIT (   controller,
  channel,
  arch 
)
Value:
MCRegisterLocation.resize(controller + 1); \
MCRegisterLocation[controller].resize(channel + 1); \
MCRegisterLocation[controller][channel] = \
std::make_pair(arch##_MC##controller##_CH##channel##_REGISTER_DEV_ADDR, arch##_MC##controller##_CH##channel##_REGISTER_FUNC_ADDR);

◆ PCM_PCICFG_QPI_INIT

#define PCM_PCICFG_QPI_INIT (   port,
  arch 
)
Value:
XPIRegisterLocation.resize(port + 1); \
XPIRegisterLocation[port] = std::make_pair(arch##_QPI_PORT##port##_REGISTER_DEV_ADDR, arch##_QPI_PORT##port##_REGISTER_FUNC_ADDR);

◆ SAFE_SYSCTLBYNAME

#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.\n"; \
return false; \
} \
if(NULL == (pParam = (char *)malloc(size))) \
{ \
std::cerr << "Unable to allocate memory for " << message << "\n"; \
return false; \
} \
if(0 != sysctlbyname(message, (void*)pParam, &size, NULL, 0)) \
{ \
std::cerr << "Unable to get " << message << " from sysctl.\n"; \
return false; \
} \
ret_value = convertUnknownToInt(size, pParam); \
free(pParam); \
}

Function Documentation

◆ getCoreCounterState()

PCM_API CoreCounterState pcm::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::PCM::getCoreCounterState(), and pcm::PCM::getInstance().

◆ getSocketCounterState()

PCM_API SocketCounterState pcm::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::PCM::getInstance(), and pcm::PCM::getSocketCounterState().

◆ getSystemCounterState()

PCM_API SystemCounterState pcm::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::PCM::getInstance(), and pcm::PCM::getSystemCounterState().