Commit c697f4f1 authored by Ondrej Vysocky's avatar Ondrej Vysocky
Browse files

NEW RAPL power capping for package #53

parent b3f8fa93
......@@ -251,9 +251,9 @@ DistributedMeric::DistributedMeric()
if (Meric::MODE == MODE_RAPL || Meric::MODE == MODE_BOTH)
{
if (Meric::DETAILED)
RAPL::detailed();
RAPL::init();
// if (Meric::DETAILED)
// RAPL::detailed();
RAPL::init(Meric::DETAILED);
}
std::string applicationMainRegion = std::string(program_invocation_name);
......
......@@ -166,7 +166,7 @@ public:
if (!_MPInodeRank)
{
Environment::setDefaultFrequencies();
Environment::restoreSystemSettings();
}
if (_stack.size() != 0)
......
......@@ -49,6 +49,8 @@ int Meric::getDefaultParameters()
defaultParameter.nthreads = mutils::getenv("MERIC_NUM_THREADS", -1);
defaultParameter.frequency = mutils::frequencyToHz(mutils::getenv("MERIC_FREQUENCY", std::string("")));
defaultParameter.uncoreFrequency = mutils::frequencyToHz(mutils::getenv("MERIC_UNCORE_FREQUENCY", std::string("")));
defaultParameter.powerCapPKG = mutils::getenv("MERIC_PWRCAP_POWER", -1);
defaultParameter.powerCapPKGtime = mutils::getenv("MERIC_PWRCAP_TIME", -1);
#if defined (HAVE_CPUFREQ_H) || defined (HAVE_X86_ADAPT_H) || defined (HAVE_MSR_CORE_H)
if (defaultParameter.frequency < 0)
......@@ -88,6 +90,25 @@ int Meric::getDefaultParameters()
}
#endif
#if defined (HAVE_X86_ADAPT_H) || defined (HAVE_MSR_CORE_H)
if (defaultParameter.powerCapPKG < 0 || defaultParameter.powerCapPKGtime < 0)
{
std::cerr << "MERIC ERROR: set MERIC_PWRCAP_POWER [W] and MERIC_PWRCAP_TIME [us]\n";
ret = 1;
}
else if (defaultParameter.powerCapPKG != 0)
{
Meric::outputFilenameInfo +="PWR_";
if (defaultParameter.powerCapPKGtime != 0)
Meric::outputFilenameInfo +="Twindow_";
}
else if (defaultParameter.powerCapPKGtime != 0)
{
std::cerr << "MERIC ERROR: MERIC_PWRCAP_POWER [W] must be set to change MERIC_PWRCAP_TIME [us]\n";
ret = 1;
}
#endif
#ifndef HAVE_HDF5_H
Meric::HDF5 = false;
#endif
......@@ -96,9 +117,10 @@ int Meric::getDefaultParameters()
return ret;
//OPTIONAL SECTION
MERIC_INFO << "Default number of threads: " << defaultParameter.nthreads << "\n";
MERIC_INFO << "Default frequency: " << defaultParameter.frequency << "\n";
MERIC_INFO << "Default number of threads: " << defaultParameter.nthreads << " Hz\n";
MERIC_INFO << "Default frequency: " << defaultParameter.frequency << " Hz\n";
MERIC_INFO << "Default uncore frequency: " << defaultParameter.uncoreFrequency << "\n";
MERIC_INFO << "Default powercap: " << defaultParameter.powerCapPKG << " W\t" << defaultParameter.powerCapPKGtime << " us\n";
std::string outputFilenameSuffix = mutils::getenv("MERIC_OUTPUT_FILENAME", std::string(""));
if (outputFilenameSuffix.size() == 0)
......@@ -318,6 +340,16 @@ RegionParameters Meric::getRegionSettings(json_object_element_s * data)
if (defaultParameter.nthreads != 0)
param.nthreads = std::stoi(std::string(((struct json_string_s*)set->value->payload)->string));
}
else if ("PWRCAP_POWER" == std::string(set->name->string))
{
if (defaultParameter.powerCapPKG != 0)
param.powerCapPKG = std::stol(std::string(((struct json_string_s*)set->value->payload)->string));
}
else if ("PWRCAP_TIME" == std::string(set->name->string))
{
if (defaultParameter.powerCapPKGtime != 0)
param.powerCapPKGtime = std::stol(std::string(((struct json_string_s*)set->value->payload)->string));
}
else
std::cerr << "MERIC ERROR: invalid region options key - " << set->name->string << std::endl;
set = set->next;
......
......@@ -162,7 +162,7 @@ protected:
auto cmpSettings = [&] (SocketsRegionParameters & prev, RegionParameters & next, int socket)
{
uint64_t paramChange;
long paramChange;
//core frequency
if (next.frequency)
{
......@@ -222,6 +222,46 @@ protected:
prev.socket[socket].nthreads = defaultParameter.nthreads;
}
}
//power cap
if (next.powerCapPKG)
{
paramChange = prev.socket[socket].powerCapPKG > next.powerCapPKG ? prev.socket[socket].powerCapPKG-next.powerCapPKG : next.powerCapPKG-prev.socket[socket].powerCapPKG;
if (paramChange > ignoreSettings.powerCapPKG)
{
change.socket[socket].powerCapPKG = paramChange;
prev.socket[socket].powerCapPKG = next.powerCapPKG;
}
}
else
{
paramChange = prev.socket[socket].powerCapPKG > defaultParameter.powerCapPKG ? prev.socket[socket].powerCapPKG-defaultParameter.powerCapPKG : defaultParameter.powerCapPKG-prev.socket[socket].powerCapPKG;
if (paramChange > ignoreSettings.powerCapPKG)
{
change.socket[socket].powerCapPKG = paramChange;
prev.socket[socket].powerCapPKG = defaultParameter.powerCapPKG;
}
}
if (next.powerCapPKGtime)
{
paramChange = prev.socket[socket].powerCapPKGtime > next.powerCapPKGtime ? prev.socket[socket].powerCapPKGtime-next.powerCapPKGtime : next.powerCapPKGtime-prev.socket[socket].powerCapPKGtime;
if (paramChange > ignoreSettings.powerCapPKGtime)
{
change.socket[socket].powerCapPKGtime = paramChange;
prev.socket[socket].powerCapPKGtime = next.powerCapPKGtime;
}
}
else
{
paramChange = prev.socket[socket].powerCapPKGtime > defaultParameter.powerCapPKGtime ? prev.socket[socket].powerCapPKGtime-defaultParameter.powerCapPKGtime : defaultParameter.powerCapPKGtime-prev.socket[socket].powerCapPKGtime;
if (paramChange > ignoreSettings.powerCapPKGtime)
{
change.socket[socket].powerCapPKGtime = paramChange;
prev.socket[socket].powerCapPKGtime = defaultParameter.powerCapPKGtime;
}
}
};
if (parameter.find(region) == parameter.end()) //region name not in list
......@@ -246,9 +286,12 @@ protected:
}
/*
MERIC_INFO << region << " CHANGE\n"
<< "\tFRQ "<< change.socket[0].frequency << std::endl
<< "\tunF "<< change.socket[0].uncoreFrequency << std::endl
<< "\tTHR "<< change.socket[0].nthreads << std::endl;
<< "\tFRQ "<< change.socket[0].frequency << std::endl
<< "\tunF "<< change.socket[0].uncoreFrequency << std::endl
<< "\tTHR "<< change.socket[0].nthreads << std::endl
<< "\tPWR "<< change.socket[0].powerCapPKG << std::endl
<< "\tTWD "<< change.socket[0].powerCapPKGtime << std::endl
;
*/
return change;
}
......@@ -264,7 +307,7 @@ protected:
{
//set core frequency
bool differentSettingsForSockets = false;
double diffCore = change.socket[0].frequency;
long diffCore = change.socket[0].frequency;
for (int socket=1; socket < Environment::NODE_SIZE_SOCKET; socket++)
{
if (diffCore != change.socket[socket].frequency)
......@@ -284,7 +327,7 @@ protected:
//set uncore frequncy
differentSettingsForSockets = false;
uint64_t diffUncore = change.socket[0].uncoreFrequency;
long diffUncore = change.socket[0].uncoreFrequency;
for (int socket=1; socket < Environment::NODE_SIZE_SOCKET; socket++)
{
if (diffUncore != change.socket[socket].uncoreFrequency)
......@@ -301,6 +344,30 @@ protected:
}
else if (diffUncore)
Environment::uncoreFrequency(currentState.socket[0].uncoreFrequency, currentState.socket[0].uncoreFrequency);
//set powercap - to change timeWindow also power must be different
differentSettingsForSockets = false;
long diffCapPower = change.socket[0].powerCapPKG;
long diffCapTime = change.socket[0].powerCapPKGtime;
for (int socket=1; socket < Environment::NODE_SIZE_SOCKET; socket++)
{
if (diffCapPower != change.socket[socket].powerCapPKG || diffCapTime != change.socket[0].powerCapPKGtime)
{
differentSettingsForSockets = true;
break;
}
}
if (differentSettingsForSockets)
{
for (int socket=0; socket < Environment::NODE_SIZE_SOCKET; socket++)
{
if(change.socket[socket].powerCapPKG)
Environment::powercap(currentState.socket[socket].powerCapPKG, currentState.socket[socket].powerCapPKGtime, socket);
}
}
else if (diffCapPower)
Environment::powercap(currentState.socket[0].powerCapPKG, currentState.socket[0].powerCapPKGtime);
}
if(change.socket[0].nthreads)
Environment::threadNumber(currentState.socket[0].nthreads);
......
......@@ -89,9 +89,9 @@ SharedMeric::SharedMeric()
PAPI::init();
if (Meric::MODE == MODE_RAPL || Meric::MODE == MODE_BOTH)
{
if (Meric::DETAILED)
RAPL::detailed();
RAPL::init();
// if (Meric::DETAILED)
// RAPL::detailed();
RAPL::init(Meric::DETAILED);
}
if (Meric::MODE == MODE_JETSON && Meric::CONTINUAL)
JETSON::init();
......
......@@ -149,7 +149,7 @@ public:
}
Meric::close();
Environment::setDefaultFrequencies();
Environment::restoreSystemSettings();
if (_stack.size() != 0)
{
......
......@@ -126,6 +126,8 @@ protected:
+ (records[starts.back()].configuration.frequency == 0 ? "" : std::to_string(records[starts.back()].configuration.frequency) +"_" )
+ (records[starts.back()].configuration.uncoreFrequency == 0 ? "" : std::to_string(records[starts.back()].configuration.uncoreFrequency) +"_" )
+ (records[starts.back()].configuration.nthreads == 0 ? "" : std::to_string(records[starts.back()].configuration.nthreads) +"_" )
+ (records[starts.back()].configuration.powerCapPKG == 0 ? "" : std::to_string(records[starts.back()].configuration.powerCapPKG) +"_" )
+ (records[starts.back()].configuration.powerCapPKGtime == 0 ? "" : std::to_string(records[starts.back()].configuration.powerCapPKGtime) +"_" )
+ outputFilename;
if (filenamePrefix.back() == '_')
filenamePrefix.pop_back();
......
......@@ -72,6 +72,10 @@ const std::string RAPL_DRAM_CH2 = "Intel_DRAM_ENERGY_STATUS_CH2";
const std::string RAPL_DRAM_CH3 = "Intel_DRAM_ENERGY_STATUS_CH3";
*/
const std::string RAPL_PCKG_POWER_LIMIT = "Intel_RAPL_PKG_POWER_LIMIT_1";
const std::string RAPL_RAM_POWER_LIMIT = "Intel_RAPL_RAM_POWER_LIMIT";
const std::string RAPL_POWER_LIMIT_TIMEWINDOW = "Intel_RAPL_POWER_UNIT_TIMEWINDOW";
static std::map<std::string, std::string> counterLabel = {
{ "Intel_RAPL_Pckg_Energy", "RAPL_PCKG [J]" },
{ "Intel_RAPL_RAM_Energy", "RAPL_RAM [J]" },
......@@ -93,6 +97,10 @@ const std::string RAPL_PP0_ENERGY = "MSR_PP0_ENERGY_STATUS"; //not available
const std::string RAPL_PP1_ENERGY = "MSR_PP1_ENERGY_STATUS";
*/
const std::string RAPL_PCKG_POWER_LIMIT = "MSR_PKG_POWER_LIMIT";
const std::string RAPL_RAM_POWER_LIMIT = "MSR_DRAM_POWER_LIMIT";
const std::string RAPL_POWER_LIMIT_TIMEWINDOW = "MSR_RAPL_POWER_UNIT_TIMEWINDOW";
static std::map<std::string, std::string> counterLabel = {
{ "MSR_PKG_ENERGY_STATUS", "RAPL_PCKG [J]" },
{ "MSR_DRAM_ENERGY_STATUS", "RAPL_RAM [J]" },
......
This diff is collapsed.
......@@ -4,22 +4,15 @@
#include "../basis/utils.h"
#ifdef HAVE_CPUFREQ_H
#include "cpufreq.h"
#include <cpufreq.h>
#endif
#ifdef HAVE_X86_ADAPT_H
#include <stdint.h>
#include <memory>
#include "x86_adapt.h"
#endif
#ifdef HAVE_NUMA_H
#include <numa.h>
#endif
#ifdef HAVE_MSR_CORE_H
#include <msr_core.h>
#include <msr_rapl.h>
#include <msr_clocks.h>
#include <libmsr_error.h>
......@@ -29,6 +22,13 @@
#ifndef MSR_UNCORE_RATIO_LIMIT
#define MSR_UNCORE_RATIO_LIMIT 0x620
#endif
#ifndef MSR_UNCORE_CURRENT_RATIO
#define MSR_UNCORE_CURRENT_RATIO 0x621
#endif
#endif
#ifdef HAVE_NUMA_H
#include <numa.h>
#endif
#ifdef HAVE_CILK_CILK_API_H
......@@ -43,6 +43,43 @@
#include <iostream>
#include <fstream>
//POWER-CAP
const uint64_t MSR_DRAM_POWER_LIMIT_mask = 0x7FFF;
const uint64_t MSR_DRAM_POWER_LIMIT_enable_mask = 0x8000;
const uint64_t MSR_DRAM_POWER_LIMIT_enable_shift = 15;
const uint64_t MSR_DRAM_POWER_LIMIT_clamping_mask = 0x10000;
const uint64_t MSR_DRAM_POWER_LIMIT_clamping_shift = 16;
const uint64_t MSR_DRAM_POWER_LIMIT_time_f_mask = 0xC00000;
const uint64_t MSR_DRAM_POWER_LIMIT_time_y_mask = 0x3E0000;
const uint64_t MSR_DRAM_POWER_LIMIT_time_f_shift = 22;
const uint64_t MSR_DRAM_POWER_LIMIT_time_y_shift = 17;
const uint64_t MSR_PKG_POWER_LIMIT_mask = 0x7FFF;
const uint64_t MSR_PKG_POWER_LIMIT_shift = 0;
const uint64_t MSR_PKG_POWER_LIMIT_enable_mask = 0x8000;
const uint64_t MSR_PKG_POWER_LIMIT_enable_shift = 15;
const uint64_t MSR_PKG_POWER_LIMIT_clamping_mask = 0x10000;
const uint64_t MSR_PKG_POWER_LIMIT_clamping_shift = 16;
const uint64_t MSR_PKG_POWER_LIMIT_time_y_mask = 0x3E0000;
const uint64_t MSR_PKG_POWER_LIMIT_time_y_shift = 17;
const uint64_t MSR_PKG_POWER_LIMIT_time_z_mask = 0xC00000;
const uint64_t MSR_PKG_POWER_LIMIT_time_z_shift = 22;
const uint64_t MSR_PKG_POWER_LIMIT_power1_shift = 0;
const uint64_t MSR_PKG_POWER_LIMIT_power2_shift = 32; //use "half register-length" shift instead of specifying all the mask and shifts for the second half of the register
const uint64_t MSR_PKG_POWER_LIMIT_lock_mask = 0x8000000000000000;
const uint64_t MSR_DRAM_POWER_LIMIT_lock_mask = 0x80000000;
const uint64_t MSR_PKG_DRAM_POWER_INFO_min_power_mask = 0x7FFF0000;
const uint64_t MSR_PKG_DRAM_POWER_INFO_min_power_shift = 16;
const uint64_t MSR_PKG_DRAM_POWER_INFO_max_power_mask = 0x7FF700000000;
const uint64_t MSR_PKG_DRAM_POWER_INFO_max_power_shift = 32;
const uint64_t MSR_PKG_DRAM_POWER_INFO_max_time_mask = 0x3F000000000000;
const uint64_t MSR_PKG_DRAM_POWER_INFO_max_time_shift = 48;
//CORE
const uint64_t IA32_PERF_CTL_shift = 8;
//UNCORE
const uint64_t MSR_UNCORE_RATIO_LIMIT_max_mask = 0x7F;
const uint64_t MSR_UNCORE_RATIO_LIMIT_min_mask = 0x7F00;
const uint64_t MSR_UNCORE_RATIO_LIMIT_min_shift = 8;
......@@ -52,24 +89,40 @@ namespace meric {
enum mode {MODE_HDEEM, MODE_RAPL, MODE_BOTH, MODE_RUN, MODE_JETSON, MODE_THUNDER, MODE_DAVIDE, MODE_TIME, MODE_LIMIT}; //keep MODE_LIMIT always as the last MODE in the list
enum system {SYS_HASWELL, SYS_JETSON, SYS_THUNDER, SYS_DAVIDE, SYS_OTHER};
struct RegionParameters {
long frequency; //must be able to carry -1
long uncoreFrequency; //must be able to carry -1
int nthreads;
struct RegionParameters { //must be able to carry -1
long frequency; //Hz
long uncoreFrequency; //Hz
int nthreads; //#omp threads
long powerCapPKG; //W
long powerCapPKGtime; //us
// long powerCapRAM; //W
// long powerCapRAMtime; //us
};
struct systemLimits{ //Hz
long maxCoreFreq;
long defaultCoreFreq;
long minCoreFreq;
long maxUncoreFreq;
long defaultUncoreFreq;
long minUncoreFreq;
struct systemLimits{
long maxCoreFreq; //Hz
long defaultCoreFreq; //Hz
long minCoreFreq; //Hz
long maxUncoreFreq; //Hz
long defaultUncoreFreq; //Hz
long minUncoreFreq; //Hz
long maxPowerCapPKG; //W
long minPowerCapPKG; //W
long maxPowerCapPKGtime; //us
uint64_t defaultPowerCapPKG; //raw register value
long maxPowerCapRAM; //W
long minPowerCapRAM; //W
long maxPowerCapRAMtime; //us
uint64_t defaultPowerCapRAM; //raw register value
// std::string defaultGovernor;
// uint64_t default_IA32_ENERGY_PERF_BIAS; //TODO
};
const int MSR_FREQ_MULT = 256;
class Environment {
......@@ -79,25 +132,27 @@ public:
static int NODE_SIZE_SOCKET;
static int SOCKET_SIZE_CPU;
static systemLimits FreqLimits [5];
static int systemType;
static void frequency(uint64_t freq, int socket = -1);
static void uncoreFrequency(uint64_t maxFreq, uint64_t minFreq, int socket = -1);
static void threadNumber(int nthreads);
static void powercap(uint64_t power, uint64_t timeWindow = 0, int socket = -1);
static void init(int system, RegionParameters defaultParameter, int rank);
static void initHWSizes();
static void setDefaultFrequencies();
static void restoreSystemSettings();
static void close();
private:
static uint64_t IA32_ENERGY_PERF_BIAS_default;
static void getFrequenciesLimits();
static void initHWSizes();
static void getSystemDefaultSettings();
static systemLimits defaultSettings [5];
static bool usedDVFS;
static bool usedUFS;
static std::string originalGovernor;
static bool usedPWRCAP;
static bool CPUFREQ_GOVERNOR;
static std::string originalGovernor;
static uint64_t IA32_ENERGY_PERF_BIAS_default;
};
......
#include "raplwrapper.h"
#include "../basis/utils.h"
/**
* Intel RAPL energy consumption mearurement registers description
......@@ -71,29 +71,19 @@ const uint64_t MSR_PKG_ENERGY_STATUS_mask = 0xFFFFFFFF;
//const uint64_t MSR_PP0_ENERGY_STATUS_mask = 0xFFFFFFFF;
//const uint64_t MSR_PP1_ENERGY_STATUS_mask = 0xFFFFFFFF;
#ifdef HAVE_X86_ADAPT_H
#include "x86_adapt.h"
using namespace X86ADAPT_RAPL_COUNTERS;
#elif defined (HAVE_MSR_CORE_H)
#include <msr_core.h>
#include <msr_rapl.h>
using namespace MSR_RAPL_COUNTERS;
#else
using namespace X86ADAPT_RAPL_COUNTERS;
#endif
using namespace meric;
std::string RAPL::suffix = "_";
bool RAPL::detailedMode = false;
unsigned long long int RAPL::COUNTERMAX = pow(2,32);
int RAPL::NODE_SIZE_SOCKET = 1;
uint64_t RAPL::NODE_SIZE_SOCKET = 1;
#if defined (HAVE_X86_ADAPT_H) || defined (HAVE_MSR_CORE_H)
std::map<std::string, unsigned long long int> RAPL::counters;
std::map<std::string, double> RAPL::energyUnit;
int RAPL::NODE_SIZE_CPU = 1;
int RAPL::SOCKET_SIZE_CPU = 1;
std::map<std::string, double> RAPL::units;
uint64_t RAPL::SOCKET_SIZE_CPU = 1;
// solve counter overflow and add baseline energy consumption
unsigned long long RAPL::getResultValue(unsigned long long int startValue, unsigned long long int stopValue, double runtime, std::string counter)
......@@ -109,57 +99,66 @@ unsigned long long RAPL::getResultValue(unsigned long long int startValue, unsig
if (stopValue < startValue)
{
if (energyUnit.count(counterName))
if (units.count(counterName))
{
MERIC_INFO << "RAPL OVERFLOW, MAX VALUE: " <<COUNTERMAX << "*"<< energyUnit[counterName] <<" " <<counterName << std::endl;
MERIC_INFO << "RAPL REPAIR " << startValue << " .. " << stopValue << " = " << ((COUNTERMAX - startValue) + stopValue) * energyUnit[counterName] << std::endl;
return ((COUNTERMAX - startValue) + stopValue) * energyUnit[counterName];
MERIC_INFO << "RAPL OVERFLOW, MAX VALUE: " <<COUNTERMAX << "*"<< units[counterName] <<" " <<counterName << std::endl;
MERIC_INFO << "RAPL REPAIR " << startValue << " .. " << stopValue << " = " << ((COUNTERMAX - startValue) + stopValue) * units[counterName] << std::endl;
return ((COUNTERMAX - startValue) + stopValue) * units[counterName];
} //else: unit modifier is missing
return 0;
}
else
return (stopValue - startValue) * energyUnit[counterName];
return (stopValue - startValue) * units[counterName];
}
#endif
#ifdef HAVE_X86_ADAPT_H
// set counters units
void RAPL::init()
void RAPL::init(bool detailed)
{
detailedMode = detailed;
#ifdef HAVE_MSR_CORE_H
core_config(&SOCKET_SIZE_CPU, NULL, &NODE_SIZE_SOCKET, NULL);
#elif defined HAVE_X86_ADAPT_H
NODE_SIZE_SOCKET = x86_adapt_get_nr_avaible_devices(X86_ADAPT_DIE);
//SOCKET_SIZE_CPU is not used when using adapt
#endif
initMap(counters);
//initCountersUnits() is already called from environmentwrapper
}
//set unit modifier for Intel_RAPL_Pckg_Energy
uint64_t unit;
//ignoring the fact that different sockets may have different units
void RAPL::initCountersUnits()
{
uint64_t MSR_RAPL_POWER_UNIT_bits = 0x0;
#ifdef HAVE_MSR_CORE_H
read_msr_by_idx(0, MSR_RAPL_POWER_UNIT, &MSR_RAPL_POWER_UNIT_bits);
#elif defined HAVE_X86_ADAPT_H
const int fd = x86_adapt_get_device_ro(X86_ADAPT_DIE, 0);
if (fd < 0)
{
std::cerr << "X86ADAPT RAPL INIT error while accessing file descriptor\n";
std::cerr << "WARNING: RAPL values will be without any unit\n";
return;
}
const int itemId = x86_adapt_lookup_ci_name(X86_ADAPT_DIE, "Intel_RAPL_Power_Unit");
x86_adapt_get_setting(fd, itemId, &unit);
unit &= MSR_RAPL_POWER_UNIT_energy_mask;
unit >>= MSR_RAPL_POWER_UNIT_energy_shift;
x86_adapt_get_setting(fd, itemId, &MSR_RAPL_POWER_UNIT_bits);
if (x86_adapt_put_device(X86_ADAPT_DIE, 0))
std::cerr << "X86ADAPT RAPL INIT error while closing file descriptor\n";
energyUnit[RAPL_PCKG_ENERGY] = 1.0/pow(2,unit);
//the rest unit modifiers are set according to x86_adapt "documentation"
//https://github.com/tud-zih-energy/x86_energy/blob/eac130973b2fbfa0b5a3e72ef9912af617584d97/rapl.c#L763
//DRAM ENERGY unit is fixed to 15.3uJ
//https://www.intel.com/content/dam/www/public/us/en/documents/datasheets/xeon-e5-v3-datasheet-vol-2.pdf
energyUnit[RAPL_RAM_ENERGY] = 1.0/pow(2,16);
/*
energyUnit[RAPL_DRAM_CH0] = 1.0/pow(2,16); //1.0/pow(2,18)
energyUnit[RAPL_DRAM_CH1] = energyUnit[RAPL_DRAM_CH0];
energyUnit[RAPL_DRAM_CH2] = energyUnit[RAPL_DRAM_CH0];
energyUnit[RAPL_DRAM_CH3] = energyUnit[RAPL_DRAM_CH0];
*/
#endif
if (MSR_RAPL_POWER_UNIT_bits != 0)
{
units[RAPL_PCKG_POWER_LIMIT] = 1.0/pow(2,(MSR_RAPL_POWER_UNIT_bits & MSR_RAPL_POWER_UNIT_power_mask));
units[RAPL_RAM_POWER_LIMIT] = units[RAPL_PCKG_POWER_LIMIT];
units[RAPL_PCKG_ENERGY] = 1.0/pow(2,((MSR_RAPL_POWER_UNIT_bits & MSR_RAPL_POWER_UNIT_energy_mask) >> MSR_RAPL_POWER_UNIT_energy_shift));
//DRAM ENERGY unit is fixed to 15.3uJ
//https://www.intel.com/content/dam/www/public/us/en/documents/datasheets/xeon-e5-v3-datasheet-vol-2.pdf
units[RAPL_RAM_ENERGY] = 1.0/pow(2,16);
units[RAPL_POWER_LIMIT_TIMEWINDOW] = 1.0/pow(2,((MSR_RAPL_POWER_UNIT_bits & MSR_RAPL_POWER_UNIT_time_mask) >> MSR_RAPL_POWER_UNIT_time_shift));
}
}
#endif
#ifdef HAVE_X86_ADAPT_H
// read counters values
void RAPL::getCounterValues(std::map<std::string, unsigned long long int> & record)
{
......@@ -192,7 +191,7 @@ void RAPL::getCounterValues(std::map<std::string, unsigned long long int> & reco
std::cerr << "X86ADAPT RAPL wrong counter name - " << itemName <<std::endl;
continue;
}
if (!energyUnit.count(itemName))
if (!units.count(itemName))
{
std::cerr << "X86ADAPT RAPL missing unit modifier for counter - " << itemName <<" Add modifier in RAPL::init()"<<std::endl;
continue;
......@@ -228,25 +227,6 @@ void RAPL::getCounterValues(std::map<std::string, unsigned long long int> & reco
////////////////////////////////////////////////////////////////////////////////
#elif defined HAVE_MSR_CORE_H
// set counters units
void RAPL::init()
{
uint64_t cs = 0;
uint64_t ss = 0;
core_config(&cs, NULL, &ss, NULL);
NODE_SIZE_SOCKET = ss;
SOCKET_SIZE_CPU = cs;
NODE_SIZE_CPU = SOCKET_SIZE_CPU * NODE_SIZE_SOCKET;
initMap(counters);
uint64_t unit;
read_msr_by_idx(0, MSR_RAPL_POWER_UNIT, &unit);
energyUnit[RAPL_PCKG_ENERGY] = 1.0/pow(2,((unit & MSR_RAPL_POWER_UNIT_energy_mask) >> MSR_RAPL_POWER_UNIT_energy_shift));
//DRAM ENERGY unit is fixed to 15.3uJ
//https://www.intel.com/content/dam/www/public/us/en/documents/datasheets/xeon-e5-v3-datasheet-vol-2.pdf
energyUnit[RAPL_RAM_ENERGY] = 1.0/pow(2,16);
}
void RAPL::getCounterValues(std::map<std::string, unsigned long long int> & record)
{
for(std::map<std::string, unsigned long long int>::iterator iterator = counters.begin(); iterator != counters.end(); iterator++)
......@@ -306,6 +286,14 @@ void RAPL::getSummaryValue(double time, unsigned long long int * counterSummary)
*counterSummary += time * RAPL_BASELINE;