power info file to json

This commit is contained in:
scorrea
2020-05-19 00:22:46 +02:00
parent e96347b41f
commit 05edd5274f
3 changed files with 60 additions and 40 deletions

View File

@@ -4,7 +4,7 @@
"StaticTemperatureDefaultValue": "89",
"ThermalSimPeriod":"100",
"ThermalSimUnit":"us",
"PowerInfoFile": "powerInfo.xml",
"PowerInfoFile": "powerInfo.json",
"IceServerIp": "127.0.0.1",
"IceServerPort": "11880",
"SimPeriodAdjustFactor" : "10",

View File

@@ -0,0 +1,20 @@
{
"powerInfo": {
"dram_die_channel0": {
"init_pow": "0",
"threshold": "1.0"
},
"dram_die_channel1": {
"init_pow": "0",
"threshold": "1.0"
},
"dram_die_channel2": {
"init_pow": "0",
"threshold": "1.0"
},
"dram_die_channel3": {
"init_pow": "0",
"threshold": "1.0"
}
}
}

View File

@@ -82,49 +82,49 @@ struct TemperatureSimConfig
+ "/configs/thermalsim/"
+ powerInfoFile;
// Load the XML file into memory and parse it
tinyxml2::XMLDocument xml;
loadXML(powerInfoFile, xml);
tinyxml2::XMLElement *powInfoElem = xml.FirstChildElement("powerInfo");
// Load the JSON file into memory and parse it
nlohmann::json powInfoElem = nlohmann::json::parse(std::ifstream(powerInfoFile));
if (powInfoElem == NULL) {
// Invalid file
std::string errormsg = "Invalid Power Info File " + powerInfoFile;
PRINTDEBUGMESSAGE("TemperatureSimConfig", errormsg);
SC_REPORT_FATAL("Temperature Sim Config", errormsg.c_str());
if (powInfoElem["powerInfo"].empty()){
// Invalid file
std::string errormsg = "Invalid Power Info File " + powerInfoFile;
PRINTDEBUGMESSAGE("TemperatureSimConfig", errormsg);
SC_REPORT_FATAL("Temperature Sim Config", errormsg.c_str());
}
else {
for ( auto it: powInfoElem["powerInfo"].items() ){
// Load initial power values for all devices
auto value= it.value();
std::string init_pow_str = value["init_pow"];
float pow = std::stof(init_pow_str);
powerInitialValues.push_back(pow);
// Load power thresholds for all devices
//Changes in power dissipation that exceed the threshods
//will make the thermal simulation to be executed more often)
std::string thr_str = value["threshold"];
float thr = std::stof(thr_str);
powerThresholds.push_back(thr);
}
}
showTemperatureSimConfig();
}
for (tinyxml2::XMLElement *e = powInfoElem->FirstChildElement(); e != NULL;
e = e->NextSiblingElement()) {
// Load initial power values for all devices
std::string init_pow_str = e->Attribute("init_pow");
float pow = std::stof(init_pow_str);
powerInitialValues.push_back(pow);
// Load power thresholds for all devices (changes in power dissipation that exceed the threshods will make the thermal simulation to be executed more often)
std::string thr_str = e->Attribute("threshold");
float thr = std::stof(thr_str);
powerThresholds.push_back(thr);
void showTemperatureSimConfig()
{
int i __attribute__((unused)) = 0;
for (auto e __attribute__((unused)) : powerInitialValues) {
PRINTDEBUGMESSAGE("TemperatureSimConfig", "powerInitialValues["
+ std::to_string(i++) + "]: " + std::to_string(e));
}
i = 0;
for (auto e __attribute__((unused)) : powerThresholds) {
PRINTDEBUGMESSAGE("TemperatureSimConfig", "powerThreshold["
+ std::to_string(i++) + "]: " + std::to_string(e));
}
}
showTemperatureSimConfig();
}
void showTemperatureSimConfig()
{
int i __attribute__((unused)) = 0;
for (auto e __attribute__((unused)) : powerInitialValues) {
PRINTDEBUGMESSAGE("TemperatureSimConfig", "powerInitialValues["
+ std::to_string(i++) + "]: " + std::to_string(e));
}
i = 0;
for (auto e __attribute__((unused)) : powerThresholds) {
PRINTDEBUGMESSAGE("TemperatureSimConfig", "powerThreshold["
+ std::to_string(i++) + "]: " + std::to_string(e));
}
}
};
};
#endif // TEMPERATURESIMCONFIG_H