Commit 93668e42 authored by Ondrej Vysocky's avatar Ondrej Vysocky
Browse files

ENH uncore frequency tuning using libmsr #59

parent 6a88b468
...@@ -216,7 +216,15 @@ void Environment::getFrequenciesLimits() ...@@ -216,7 +216,15 @@ void Environment::getFrequenciesLimits()
FreqLimits[SYS_OTHER].minCoreFreq = std::stol(freqBound) * 1000; FreqLimits[SYS_OTHER].minCoreFreq = std::stol(freqBound) * 1000;
//UnCORE freq //UnCORE freq
#ifdef HAVE_X86_ADAPT_H #ifdef HAVE_MSR_CORE_H
uint64_t MSR_UNCORE_RATIO_LIMIT_bits;
read_msr_by_idx(0, MSR_UNCORE_RATIO_LIMIT, &MSR_UNCORE_RATIO_LIMIT_bits);
FreqLimits[SYS_OTHER].maxUncoreFreq = (MSR_UNCORE_RATIO_LIMIT_bits & MSR_UNCORE_RATIO_LIMIT_max_mask) * 100000000;
FreqLimits[SYS_OTHER].defaultUncoreFreq = FreqLimits[SYS_OTHER].maxUncoreFreq;
FreqLimits[SYS_OTHER].minUncoreFreq = ((MSR_UNCORE_RATIO_LIMIT_bits & MSR_UNCORE_RATIO_LIMIT_min_mask) >> MSR_UNCORE_RATIO_LIMIT_min_shift) * 100000000;
#elif defined HAVE_X86_ADAPT_H
int fd = x86_adapt_get_device_ro(X86_ADAPT_DIE, 0); int fd = x86_adapt_get_device_ro(X86_ADAPT_DIE, 0);
int adaptHandlerUncore = x86_adapt_lookup_ci_name(X86_ADAPT_DIE, "Intel_UNCORE_MAX_RATIO"); int adaptHandlerUncore = x86_adapt_lookup_ci_name(X86_ADAPT_DIE, "Intel_UNCORE_MAX_RATIO");
uint64_t setting; uint64_t setting;
...@@ -226,7 +234,9 @@ void Environment::getFrequenciesLimits() ...@@ -226,7 +234,9 @@ void Environment::getFrequenciesLimits()
adaptHandlerUncore = x86_adapt_lookup_ci_name(X86_ADAPT_DIE, "Intel_UNCORE_MIN_RATIO"); adaptHandlerUncore = x86_adapt_lookup_ci_name(X86_ADAPT_DIE, "Intel_UNCORE_MIN_RATIO");
x86_adapt_get_setting(fd, adaptHandlerUncore, &setting); x86_adapt_get_setting(fd, adaptHandlerUncore, &setting);
FreqLimits[SYS_OTHER].minUncoreFreq = setting * 100000000; FreqLimits[SYS_OTHER].minUncoreFreq = setting * 100000000;
#endif
#if defined HAVE_MSR_CORE_H || defined HAVE_X86_ADAPT_H
struct stat info; struct stat info;
std::string uncoreFrequencyDefaultFile = std::string(MERIC_PATH)+"/build/ucfRestore.csv"; std::string uncoreFrequencyDefaultFile = std::string(MERIC_PATH)+"/build/ucfRestore.csv";
if(stat(uncoreFrequencyDefaultFile.c_str(), &info ) != 0) if(stat(uncoreFrequencyDefaultFile.c_str(), &info ) != 0)
...@@ -425,7 +435,7 @@ void Environment::frequency(uint64_t freq, int socket) ...@@ -425,7 +435,7 @@ void Environment::frequency(uint64_t freq, int socket)
cpu = SOCKET_SIZE_CPU*socket; cpu = SOCKET_SIZE_CPU*socket;
} }
#ifdef HAVE_MSR_CORE_H #ifdef HAVE_MSR_CORE_H
MERIC_INFO << "MSR set frequency to: " << freq; MERIC_INFO << "LIBMSR set frequency to: " << freq;
if (socket != -1) if (socket != -1)
MERIC_INFO << "; socket: " << socket; MERIC_INFO << "; socket: " << socket;
MERIC_INFO << "; cpu " << cpu << " - " << nodeSize-1<< std::endl; MERIC_INFO << "; cpu " << cpu << " - " << nodeSize-1<< std::endl;
...@@ -527,7 +537,26 @@ void Environment::uncoreFrequency(uint64_t maxFreq, uint64_t minFreq, int socket ...@@ -527,7 +537,26 @@ void Environment::uncoreFrequency(uint64_t maxFreq, uint64_t minFreq, int socket
} }
else else
{ {
#ifdef HAVE_X86_ADAPT_H #ifdef HAVE_MSR_CORE_H
MERIC_INFO << "LIBMSR set uncore frequency to: "<< maxFreq;
if (maxFreq != minFreq)
MERIC_INFO << " - " << minFreq;
int max = NODE_SIZE_SOCKET;
int die=0;
if (socket != -1 && socket < max)
{
die = socket;
max = socket+1;
}
MERIC_INFO << "; soc " << die << " - " << max-1<< std::endl;
uint64_t MSR_UNCORE_RATIO_LIMIT_bits = ((minFreq/100000000) << MSR_UNCORE_RATIO_LIMIT_min_shift) + maxFreq/100000000;
for (; die<max; die++)
{
write_msr_by_idx(die * SOCKET_SIZE_CPU, MSR_UNCORE_RATIO_LIMIT, MSR_UNCORE_RATIO_LIMIT_bits);
}
#elif defined HAVE_X86_ADAPT_H
if (x86_adapt_lookup_ci_name(X86_ADAPT_DIE, "Intel_UNCORE_MAX_RATIO") < 0) if (x86_adapt_lookup_ci_name(X86_ADAPT_DIE, "Intel_UNCORE_MAX_RATIO") < 0)
{ {
std::cerr << "X86ADAPT ERROR: uncore frequency settings not allowed\n"; std::cerr << "X86ADAPT ERROR: uncore frequency settings not allowed\n";
...@@ -572,7 +601,6 @@ void Environment::uncoreFrequency(uint64_t maxFreq, uint64_t minFreq, int socket ...@@ -572,7 +601,6 @@ void Environment::uncoreFrequency(uint64_t maxFreq, uint64_t minFreq, int socket
if (x86_adapt_put_device(X86_ADAPT_DIE, die)) if (x86_adapt_put_device(X86_ADAPT_DIE, die))
std::cerr << "X86ADAPT ERROR: error while closing file descriptor\n"; std::cerr << "X86ADAPT ERROR: error while closing file descriptor\n";
} }
#else
#endif #endif
} }
clock_gettime(CLOCK_REALTIME, &stop_time); clock_gettime(CLOCK_REALTIME, &stop_time);
......
...@@ -20,8 +20,13 @@ ...@@ -20,8 +20,13 @@
#include <msr_rapl.h> #include <msr_rapl.h>
#include <msr_clocks.h> #include <msr_clocks.h>
#include <libmsr_error.h> #include <libmsr_error.h>
//TODO where does this register addres come from?
#define IA32_ENERGY_PERF_BIAS 0x1B0 #ifndef IA32_ENERGY_PERF_BIAS
#define IA32_ENERGY_PERF_BIAS 0x1B0
#endif
#ifndef MSR_UNCORE_RATIO_LIMIT
#define MSR_UNCORE_RATIO_LIMIT 0x620
#endif
#endif #endif
#ifdef HAVE_CILK_CILK_API_H #ifdef HAVE_CILK_CILK_API_H
...@@ -36,6 +41,10 @@ ...@@ -36,6 +41,10 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
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;
namespace meric { 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 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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment