Introduce SimulationTime config

Use SimulationTime to forcefully stop simulation at a specified point in
time.
This commit is contained in:
2024-12-10 10:03:07 +01:00
parent be1807e9b0
commit 703ee81d7e
7 changed files with 24 additions and 8 deletions

View File

@@ -157,6 +157,7 @@ The content of [ddr3.json](simconfig/example.json) is presented below as an exam
{ {
"simconfig": { "simconfig": {
"SimulationName": "example", "SimulationName": "example",
"SimulationTime": 1e-3,
"Debug": false, "Debug": false,
"DatabaseRecording": true, "DatabaseRecording": true,
"PowerAnalysis": false, "PowerAnalysis": false,
@@ -173,6 +174,9 @@ The content of [ddr3.json](simconfig/example.json) is presented below as an exam
- *SimulationName* (string) - *SimulationName* (string)
- Give the name of the simulation for distinguishing from other simulations. - Give the name of the simulation for distinguishing from other simulations.
- *SimulationTime* (double)
- Time at which the simulation is forcefully stopped. Useful for generating multiple simulations over the exact same timeframe.
- Default: unlimited
- *Debug* (boolean) - *Debug* (boolean)
- true: enables debug output on console (only supported by a debug build) - true: enables debug output on console (only supported by a debug build)
- false: disables debug output - false: disables debug output

View File

@@ -72,6 +72,7 @@ struct SimConfig
std::optional<bool> ThermalSimulation; std::optional<bool> ThermalSimulation;
std::optional<bool> UseMalloc; std::optional<bool> UseMalloc;
std::optional<unsigned int> WindowSize; std::optional<unsigned int> WindowSize;
std::optional<double> SimulationTime;
}; };
NLOHMANN_JSONIFY_ALL_THINGS(SimConfig, NLOHMANN_JSONIFY_ALL_THINGS(SimConfig,
@@ -86,7 +87,8 @@ NLOHMANN_JSONIFY_ALL_THINGS(SimConfig,
StoreMode, StoreMode,
ThermalSimulation, ThermalSimulation,
UseMalloc, UseMalloc,
WindowSize) WindowSize,
SimulationTime)
} // namespace DRAMSys::Config } // namespace DRAMSys::Config

View File

@@ -57,7 +57,7 @@ int sc_main(int argc, char** argv)
DRAMSys::Config::from_path(baseConfig.c_str(), resourceDirectory.c_str()); DRAMSys::Config::from_path(baseConfig.c_str(), resourceDirectory.c_str());
Simulator simulator(std::move(configuration), std::move(resourceDirectory)); Simulator simulator(std::move(configuration), std::move(resourceDirectory));
Simulator::run(); simulator.run();
return 0; return 0;
} }

View File

@@ -156,7 +156,15 @@ void Simulator::run()
auto start = std::chrono::high_resolution_clock::now(); auto start = std::chrono::high_resolution_clock::now();
// Start the SystemC simulation // Start the SystemC simulation
sc_core::sc_start(); if (configuration.simconfig.SimulationTime.has_value())
{
sc_core::sc_start(
sc_core::sc_time(configuration.simconfig.SimulationTime.value(), sc_core::SC_SEC));
}
else
{
sc_core::sc_start();
}
if (!sc_core::sc_end_of_simulation_invoked()) if (!sc_core::sc_end_of_simulation_invoked())
{ {

View File

@@ -49,7 +49,7 @@ public:
Simulator(DRAMSys::Config::Configuration configuration, Simulator(DRAMSys::Config::Configuration configuration,
std::filesystem::path resourceDirectory); std::filesystem::path resourceDirectory);
static void run(); void run();
private: private:
std::unique_ptr<Initiator> instantiateInitiator(const DRAMSys::Config::Initiator& initiator); std::unique_ptr<Initiator> instantiateInitiator(const DRAMSys::Config::Initiator& initiator);

View File

@@ -151,7 +151,8 @@
"StoreMode": "NoStorage", "StoreMode": "NoStorage",
"ThermalSimulation": false, "ThermalSimulation": false,
"UseMalloc": false, "UseMalloc": false,
"WindowSize": 1000 "WindowSize": 1000,
"SimulationTime": 1e-3
}, },
"simulationid": "std::string_simulationId", "simulationid": "std::string_simulationId",
"tracesetup": [ "tracesetup": [

View File

@@ -39,7 +39,6 @@
#include <fstream> #include <fstream>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <iostream> #include <iostream>
#include <unordered_map>
using namespace DRAMSys::Config; using namespace DRAMSys::Config;
@@ -115,7 +114,8 @@ protected:
DRAMSys::Config::StoreModeType::NoStorage, DRAMSys::Config::StoreModeType::NoStorage,
false, false,
false, false,
1000}; 1000,
1e-3};
DRAMSys::Config::MemSpec memSpec; DRAMSys::Config::MemSpec memSpec;
@@ -328,7 +328,8 @@ TEST_F(ConfigurationTest, SimConfig)
"StoreMode": "NoStorage", "StoreMode": "NoStorage",
"ThermalSimulation": false, "ThermalSimulation": false,
"UseMalloc": false, "UseMalloc": false,
"WindowSize": 1000 "WindowSize": 1000,
"SimulationTime": 1e-3
} }
} }
)"; )";