Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 19 additions & 100 deletions src/include/simeng/config/SimInfo.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,155 +25,74 @@ class SimInfo {
public:
/** A getter function to retrieve the ryml::Tree representing the underlying
* model config file. */
static ryml::ConstNodeRef getConfig() {
return getInstance()->validatedConfig_.crootref();
}
static ryml::ConstNodeRef getConfig();

/** A setter function to set the model config file from a path to a YAML file.
*/
static void setConfig(std::string path) { getInstance()->makeConfig(path); }
static void setConfig(std::string path);

/** A function to add additional config values to the model config file. */
static void addToConfig(std::string configAdditions) {
getInstance()->modelConfig_.addConfigOptions(configAdditions);
// Replace the validated config with new instance with the supplied
// additional values
getInstance()->validatedConfig_ = getInstance()->modelConfig_.getConfig();
// Update previously extracted values from the config file
getInstance()->extractValues();
}
static void addToConfig(std::string configAdditions);

/** A function to generate a default config file based on a passed ISA. */
static void generateDefault(ISA isa, bool force = false) {
if (isa == ISA::AArch64)
getInstance()->modelConfig_.reGenerateDefault(ISA::AArch64, force);
else if (isa == ISA::RV64)
getInstance()->modelConfig_.reGenerateDefault(ISA::RV64, force);

// Update config path to be the default string
getInstance()->configFilePath_ = DEFAULT_STR;

// Replace the validated config with the new default config
getInstance()->validatedConfig_ = getInstance()->modelConfig_.getConfig();
// Update previously extracted values from the config file
getInstance()->extractValues();
}
static void generateDefault(ISA isa, bool force = false);

/** A getter function to retrieve the config file path. */
static std::string getConfigPath() { return getInstance()->configFilePath_; }
static std::string getConfigPath();

/** A getter function to retrieve the simulation mode of the current SimEng
* instance. */
static SimulationMode getSimMode() { return getInstance()->mode_; }
static SimulationMode getSimMode();

/** A getter function to retrieve the simulation mode of the current SimEng
* instance as a string. */
static std::string getSimModeStr() { return getInstance()->modeStr_; }
static std::string getSimModeStr();

/** A getter function to retrieve which ISA the current simulation is using.
*/
static ISA getISA() { return getInstance()->isa_; }
static ISA getISA();

/** A getter function to retrieve which ISA the current simulation is using in
* a string format. */
static std::string getISAString() { return getInstance()->isaString_; }
static std::string getISAString();

/** A getter function to retrieve a vector of {size, number} pairs describing
* the available architectural registers. */
static const std::vector<simeng::RegisterFileStructure>& getArchRegStruct() {
return getInstance()->archInfo_->getArchRegStruct();
}
static const std::vector<simeng::RegisterFileStructure>& getArchRegStruct();

/** A getter function to retrieve a vector of {size, number} pairs describing
* the available physical registers. */
static const std::vector<simeng::RegisterFileStructure>& getPhysRegStruct() {
return getInstance()->archInfo_->getPhysRegStruct();
}
static const std::vector<simeng::RegisterFileStructure>& getPhysRegStruct();

/** A getter function to retrieve a vector of uint16_t values describing
* the quantities of physical registers available. */
static const std::vector<uint16_t>& getPhysRegQuantities() {
return getInstance()->archInfo_->getPhysRegQuantities();
}
static const std::vector<uint16_t>& getPhysRegQuantities();

/** A getter function to retrieve a vector of Capstone sysreg enums for
* all the system registers that should be utilised in simulation. */
static const std::vector<uint64_t>& getSysRegVec() {
return getInstance()->archInfo_->getSysRegEnums();
}
static const std::vector<uint64_t>& getSysRegVec();

/** A getter function to retrieve whether or not the special files
* directories should be generated. */
static bool getGenSpecFiles() { return getInstance()->genSpecialFiles_; }
static bool getGenSpecFiles();

/** A utility function to rebuild/construct member variables/classes. For use
* if the configuration used changes during simulation (e.g. during the
* execution of a test suite). */
static void reBuild() { getInstance()->extractValues(); }
static void reBuild();

private:
SimInfo() {
// Set the validated config file to be the current default config
// generated by the default constructor of ModelConfig
validatedConfig_ = modelConfig_.getConfig();
extractValues();
}
SimInfo();

/** Gets the static instance of the SimInfo class. */
static std::unique_ptr<SimInfo>& getInstance() {
static std::unique_ptr<SimInfo> SimInfoClass = nullptr;
if (SimInfoClass == nullptr) {
SimInfoClass = std::unique_ptr<SimInfo>(new SimInfo());
}
return SimInfoClass;
}
static std::unique_ptr<SimInfo>& getInstance();

/** Create a model config from a passed YAML file path. */
void makeConfig(std::string path) {
// Recreate the model config instance from the YAML file path
modelConfig_ = ModelConfig(path);

// Update config path to be the passed path
configFilePath_ = path;

// Update the validated config file
validatedConfig_ = modelConfig_.getConfig();
extractValues();
}
void makeConfig(std::string path);

/** A function to extract various values from the generated config file to
* populate frequently queried model config values. */
void extractValues() {
// Get ISA type and set the corresponding ArchInfo class
isaString_ = validatedConfig_["Core"]["ISA"].as<std::string>();
if (isaString_ == "AArch64") {
isa_ = ISA::AArch64;
archInfo_ = std::make_unique<arch::aarch64::ArchInfo>(
arch::aarch64::ArchInfo(validatedConfig_));
} else if (isaString_ == "rv64") {
isa_ = ISA::RV64;
archInfo_ = std::make_unique<arch::riscv::ArchInfo>(
arch::riscv::ArchInfo(validatedConfig_));
}

// Get Simulation mode
std::string mode =
validatedConfig_["Core"]["Simulation-Mode"].as<std::string>();
if (mode == "emulation") {
mode_ = SimulationMode::Emulation;
modeStr_ = "Emulation";
} else if (mode == "inorderpipelined") {
mode_ = SimulationMode::InOrderPipelined;
modeStr_ = "In-Order Pipelined";
} else if (mode == "outoforder") {
mode_ = SimulationMode::Outoforder;
modeStr_ = "Out-of-Order";
}

// Get if the special files directory should be created
genSpecialFiles_ =
validatedConfig_["CPU-Info"]["Generate-Special-Dir"].as<bool>();
}
void extractValues();

/** The validated model config file represented as a ryml:Tree. */
ryml::Tree validatedConfig_;
Expand Down
1 change: 1 addition & 0 deletions src/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set(SIMENG_SOURCES
branchpredictors/GenericPredictor.cc
branchpredictors/PerceptronPredictor.cc
config/ModelConfig.cc
config/SimInfo.cc
kernel/Linux.cc
kernel/LinuxProcess.cc
memory/FixedLatencyMemoryInterface.cc
Expand Down
126 changes: 126 additions & 0 deletions src/lib/config/SimInfo.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#include "simeng/config/SimInfo.hh"

namespace simeng {
namespace config {

ryml::ConstNodeRef SimInfo::getConfig() {
return getInstance()->validatedConfig_.crootref();
}

void SimInfo::setConfig(std::string path) { getInstance()->makeConfig(path); }

void SimInfo::addToConfig(std::string configAdditions) {
getInstance()->modelConfig_.addConfigOptions(configAdditions);
// Replace the validated config with new instance with the supplied
// additional values
getInstance()->validatedConfig_ = getInstance()->modelConfig_.getConfig();
// Update previously extracted values from the config file
getInstance()->extractValues();
}

void SimInfo::generateDefault(ISA isa, bool force) {
if (isa == ISA::AArch64)
getInstance()->modelConfig_.reGenerateDefault(ISA::AArch64, force);
else if (isa == ISA::RV64)
getInstance()->modelConfig_.reGenerateDefault(ISA::RV64, force);

// Update config path to be the default string
getInstance()->configFilePath_ = DEFAULT_STR;

// Replace the validated config with the new default config
getInstance()->validatedConfig_ = getInstance()->modelConfig_.getConfig();
// Update previously extracted values from the config file
getInstance()->extractValues();
}

std::string SimInfo::getConfigPath() { return getInstance()->configFilePath_; }

SimulationMode SimInfo::getSimMode() { return getInstance()->mode_; }

std::string SimInfo::getSimModeStr() { return getInstance()->modeStr_; }

ISA SimInfo::getISA() { return getInstance()->isa_; }

std::string SimInfo::getISAString() { return getInstance()->isaString_; }

const std::vector<simeng::RegisterFileStructure>& SimInfo::getArchRegStruct() {
return getInstance()->archInfo_->getArchRegStruct();
}

const std::vector<simeng::RegisterFileStructure>& SimInfo::getPhysRegStruct() {
return getInstance()->archInfo_->getPhysRegStruct();
}

const std::vector<uint16_t>& SimInfo::getPhysRegQuantities() {
return getInstance()->archInfo_->getPhysRegQuantities();
}

const std::vector<uint64_t>& SimInfo::getSysRegVec() {
return getInstance()->archInfo_->getSysRegEnums();
}

bool SimInfo::getGenSpecFiles() { return getInstance()->genSpecialFiles_; }

void SimInfo::reBuild() { getInstance()->extractValues(); }

SimInfo::SimInfo() {
// Set the validated config file to be the current default config
// generated by the default constructor of ModelConfig
validatedConfig_ = modelConfig_.getConfig();
extractValues();
}

std::unique_ptr<SimInfo>& SimInfo::getInstance() {
static std::unique_ptr<SimInfo> SimInfoClass = nullptr;
if (SimInfoClass == nullptr) {
SimInfoClass = std::unique_ptr<SimInfo>(new SimInfo());
}
return SimInfoClass;
}

void SimInfo::makeConfig(std::string path) {
// Recreate the model config instance from the YAML file path
modelConfig_ = ModelConfig(path);

// Update config path to be the passed path
configFilePath_ = path;

// Update the validated config file
validatedConfig_ = modelConfig_.getConfig();
extractValues();
}

void SimInfo::extractValues() {
// Get ISA type and set the corresponding ArchInfo class
isaString_ = validatedConfig_["Core"]["ISA"].as<std::string>();
if (isaString_ == "AArch64") {
isa_ = ISA::AArch64;
archInfo_ = std::make_unique<arch::aarch64::ArchInfo>(
arch::aarch64::ArchInfo(validatedConfig_));
} else if (isaString_ == "rv64") {
isa_ = ISA::RV64;
archInfo_ = std::make_unique<arch::riscv::ArchInfo>(
arch::riscv::ArchInfo(validatedConfig_));
}

// Get Simulation mode
std::string mode =
validatedConfig_["Core"]["Simulation-Mode"].as<std::string>();
if (mode == "emulation") {
mode_ = SimulationMode::Emulation;
modeStr_ = "Emulation";
} else if (mode == "inorderpipelined") {
mode_ = SimulationMode::InOrderPipelined;
modeStr_ = "In-Order Pipelined";
} else if (mode == "outoforder") {
mode_ = SimulationMode::Outoforder;
modeStr_ = "Out-of-Order";
}

// Get if the special files directory should be created
genSpecialFiles_ =
validatedConfig_["CPU-Info"]["Generate-Special-Dir"].as<bool>();
}

} // namespace config
} // namespace simeng