diff --git a/core/debug/aux_/process.hpp b/core/debug/aux_/process.hpp index 6296e990..607e21bc 100644 --- a/core/debug/aux_/process.hpp +++ b/core/debug/aux_/process.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #define DBG__internal_FIRST(x, y) x @@ -146,9 +147,9 @@ #define DBG__internal_PROCESS_DEFAULT_OPS_1(output, State, empty) (output, State, empty) /**/ #define DBG__internal_FINALIZE(output, state, empty) \ - if (Flexus::Dbg::Debugger::theDebugger->theMinimumSeverity <= DBG__internal_State_GetSev(state) && \ + if (Flexus::Dbg::Debugger::theDebugger->is_logging_enabled() && Flexus::Dbg::Debugger::theDebugger->theMinimumSeverity <= DBG__internal_State_GetSev(state) && \ (DBG__internal_ASSERTIONS_ENABLED || !DBG__internal_State_GetAssert(state))) { \ - if (DBG__internal_BUILTIN_CONDITIONS(state) && DBG__internal_State_GetCondition(state)) { \ + if (DBG__internal_BUILTIN_CONDITIONS(state) && DBG__internal_State_GetCondition(state)) { \ using namespace DBG_Cats; \ using DBG_Cats::Core; \ Flexus::Dbg::Entry entry__(/*Severity*/ Flexus::Dbg::Severity(DBG__internal_State_GetSev(state)), \ diff --git a/core/debug/debugger.cpp b/core/debug/debugger.cpp index 3aaa9f8d..5274b4cf 100644 --- a/core/debug/debugger.cpp +++ b/core/debug/debugger.cpp @@ -212,6 +212,12 @@ Debugger::reset() theTargets.clear(); } +bool +Debugger::is_logging_enabled(void) +{ + return (cycleCount()) ? (static_cast(cycleCount()) >= *cycle_delay_log) : true; +} + Debugger* Debugger::theDebugger((Debugger*)0); void diff --git a/core/debug/debugger.hpp b/core/debug/debugger.hpp index 4bc41f17..5056f563 100644 --- a/core/debug/debugger.hpp +++ b/core/debug/debugger.hpp @@ -38,6 +38,7 @@ class Debugger int64_t theCount; uint64_t* theCycleCount; + uint64_t* cycle_delay_log; std::priority_queue theAts; // Owns all targets @@ -47,7 +48,8 @@ class Debugger Debugger() : theCount(0) - , theCycleCount(0) + , theCycleCount(nullptr) + , cycle_delay_log(nullptr) , theMinimumSeverity(SevDev) { } @@ -67,7 +69,10 @@ class Debugger return 0; } - void connectCycleCount(uint64_t* aCount) { theCycleCount = aCount; } + void connectCycleCount(uint64_t* aCount, uint64_t* log_delay) { + theCycleCount = aCount; + cycle_delay_log = log_delay; + } void process(Entry const& anEntry); void printConfiguration(std::ostream& anOstream); @@ -84,6 +89,7 @@ class Debugger void checkAt(); void doNextAt(); void reset(); + bool is_logging_enabled(void); void setMinSev(Severity aSeverity) { theMinimumSeverity = aSeverity; } }; diff --git a/core/flexus.cpp b/core/flexus.cpp index 66395762..b714de73 100644 --- a/core/flexus.cpp +++ b/core/flexus.cpp @@ -42,23 +42,14 @@ class FlexusImpl : public FlexusInterface uint64_t theCycleCount; uint64_t theStatInterval; uint64_t theStopCycle; + uint64_t cycle_delay_log; Stat::StatCounter theCycleCountStat; - std::string theCurrentStatRegionName; - uint32_t theCurrentStatRegion; - typedef std::vector> void_fn_vector; void_fn_vector theTerminateFunctions; bool theQuiesceRequested; bool theSaveRequested; - std::string theSaveName; - - bool theFastMode; - - int32_t theBreakCPU; - uint64_t theBreakInsn; - int32_t theSaveCtr; public: // Initialization functions @@ -85,8 +76,9 @@ class FlexusImpl : public FlexusInterface void reset_core_watchdog(uint32_t); // Flexus command line interface - void setStopCycle(std::string const& aValue); - void setStatInterval(std::string const& aValue); + void setStopCycle(uint64_t aValue); + void setStatInterval(uint64_t aValue); + void set_log_delay(uint64_t aValue); void parseConfiguration(std::string const& aFilename); void writeMeasurement(std::string const& aMeasurement, std::string const& aFilename); void saveState(std::string const& aDirName); @@ -101,16 +93,14 @@ class FlexusImpl : public FlexusInterface : cpu_watchdog_timeout(2000) , theInitialized(false) , theCycleCount(0) - , theStatInterval(50000) + , theStatInterval(10000) , theStopCycle(2000000000) + , cycle_delay_log(0) , theCycleCountStat("sys-cycles") , theQuiesceRequested(false) , theSaveRequested(false) - , theBreakCPU(-1) - , theBreakInsn(0) - , theSaveCtr(1) { - Flexus::Dbg::Debugger::theDebugger->connectCycleCount(&theCycleCount); + Flexus::Dbg::Debugger::theDebugger->connectCycleCount(&theCycleCount, &cycle_delay_log); } virtual ~FlexusImpl() {} }; @@ -120,6 +110,7 @@ FlexusImpl::setCycle(uint64_t cycle) { theCycleCount = cycle; theStopCycle += cycle; + cycle_delay_log += cycle; } void @@ -127,9 +118,6 @@ FlexusImpl::initializeComponents() { DBG_(VVerb, (<< "Inititializing Flexus components...")); Stat::getStatManager()->initialize(); - theCurrentStatRegion = 0; - theCurrentStatRegionName = std::string("Region ") + boost::padded_string_cast<3, '0'>(theCurrentStatRegion++); - Stat::getStatManager()->openMeasurement(theCurrentStatRegionName); parseConfiguration(config_file); ConfigurationManager::getConfigurationManager().checkAllOverrides(); ComponentManager::getComponentManager().initComponents(); @@ -161,7 +149,8 @@ FlexusImpl::advanceCycles(int64_t aCycleCount) static uint64_t last_stats = 0; if (theStatInterval && (advanced_cycle_count - last_stats >= theStatInterval)) { DBG_(Dev, Core()(<< "Saving stats at: " << theCycleCount)); - std::string report_name = "all.measurement." + boost::padded_string_cast<10, '0'>(advanced_cycle_count) + ".log"; + std::string report_name = + "all.measurement." + boost::padded_string_cast<10, '0'>(advanced_cycle_count) + ".log"; writeMeasurement("all", report_name); last_stats = advanced_cycle_count; } @@ -213,16 +202,24 @@ FlexusImpl::reset_core_watchdog(uint32_t core_idx) } void -FlexusImpl::setStopCycle(std::string const& aValue) +FlexusImpl::set_log_delay(uint64_t aValue) +{ + cycle_delay_log = aValue; + DBG_(Dev, Set((Source) << "flexus")(<< "Set LOG delay to : " << cycle_delay_log)); +} + +void +FlexusImpl::setStopCycle(uint64_t aValue) { - theStopCycle = boost::lexical_cast(aValue); + theStopCycle = aValue; + DBG_(Dev, Set((Source) << "flexus")(<< "Set STOP to : " << theStopCycle)); } void -FlexusImpl::setStatInterval(std::string const& aValue) +FlexusImpl::setStatInterval(uint64_t aValue) { - theStatInterval = boost::lexical_cast(aValue); - DBG_(Dev, Set((Source) << "flexus")(<< "Set stat interval to : " << theStatInterval)); + theStatInterval = aValue; + DBG_(Dev, Set((Source) << "flexus")(<< "Set STAT interval to : " << theStatInterval)); } void @@ -252,7 +249,6 @@ FlexusImpl::saveState(std::string const& aDirName) } } - void FlexusImpl::loadState(std::string const& aDirName) { diff --git a/core/flexus.hpp b/core/flexus.hpp index 797cf23c..0d345e37 100644 --- a/core/flexus.hpp +++ b/core/flexus.hpp @@ -6,7 +6,6 @@ #include namespace Flexus::Core { - class FlexusInterface { public: @@ -16,7 +15,7 @@ class FlexusInterface // The main cycle function virtual void doCycle() = 0; virtual void setCycle(uint64_t cycle) = 0; - virtual bool quiescing() const = 0; + virtual bool quiescing() const = 0; // fast-forward through cycles // Note: does not tick stats, check watchdogs, or call drives @@ -26,13 +25,14 @@ class FlexusInterface // Watchdog Functions virtual void reset_core_watchdog(uint32_t) = 0; - virtual void terminateSimulation() = 0; + virtual void terminateSimulation() = 0; virtual void setDebug(std::string const& aDebugSeverity) = 0; - virtual void setStatInterval(std::string const& aValue) = 0; - virtual void setStopCycle(std::string const& aValue) = 0; + virtual void setStatInterval(uint64_t aValue) = 0; + virtual void setStopCycle(uint64_t aValue) = 0; + virtual void set_log_delay(uint64_t aValue) = 0; - virtual void writeMeasurement(std::string const& aMeasurement, std::string const& aFilename) = 0; + virtual void writeMeasurement(std::string const& aMeasurement, std::string const& aFilename) = 0; }; extern FlexusInterface* theFlexus; diff --git a/core/qemu/api.h b/core/qemu/api.h index 0bd22d69..c99df687 100644 --- a/core/qemu/api.h +++ b/core/qemu/api.h @@ -49,7 +49,11 @@ typedef uint64_t logical_address_t; typedef enum { + QMP_FLEXUS_SETSTATINTERVAL, QMP_FLEXUS_WRITEMEASUREMENT, + QMP_FLEXUS_DOLOAD, + QMP_FLEXUS_DOSAVE, + QMP_FLEXUS_SAVESTATS, QMP_FLEXUS_TERMINATESIMULATION, } qmp_flexus_cmd_t; @@ -195,6 +199,13 @@ typedef struct } memory_transaction_t; +struct cycles_opts +{ + uint64_t until_stop; + uint64_t stats_interval; + uint64_t log_delay; +}; + /*--------------------------------------------------------------- *-------------------------TYPEDEFS---------------------------- *---------------------------------------------------------------*/ @@ -220,7 +231,7 @@ typedef uint64_t (*QEMU_READ_SYSREG_t)(size_t core_index, uint8_t op2, uint8_t crn, uint8_t crm, - uint8_t ignore_permission_check); + bool ignore_permission_check); typedef size_t (*QEMU_GET_NUM_CORES_t)(void); typedef logical_address_t (*QEMU_GET_PC_t)(size_t core_index); typedef bool (*QEMU_GET_IRQ_t)(size_t core_index); @@ -247,19 +258,6 @@ typedef struct FLEXUS_API_t typedef struct QEMU_API_t { - // QEMU_GET_ALL_CPUS_t get_all_cpus; - // QEMU_GET_CPU_BY_IDX_t get_cpu_by_idx; - // QEMU_GET_CPU_IDX_t get_cpu_idx; - // QEMU_GET_CSR_t get_csr; - // QEMU_GET_CYCLES_LEFT_t get_cycles_left; - // QEMU_GET_FPR_t get_fpr; - // QEMU_GET_GPR_t get_gpr; - // QEMU_GET_OBJ_BY_NAME_t get_obj_by_name; - // QEMU_GET_PL_t get_pl; - // QEMU_GET_SNAP_t get_snap; - // QEMU_MEM_OP_IS_DATA_t mem_op_is_data; - // QEMU_MEM_OP_IS_WRITE_t mem_op_is_write; - // ─── Bryan ─────────────────────────────────────────────────────────── QEMU_GET_NUM_CORES_t get_num_cores; QEMU_READ_REG_t read_register; QEMU_READ_SYSREG_t read_sys_register; @@ -272,8 +270,6 @@ typedef struct QEMU_API_t QEMU_TICK_t tick; QEMU_DISASS_t disassembly; QEMU_CPU_BUSY_t is_busy; - // ───────────────────────────────────────────────────────────────────── - } QEMU_API_t; extern QEMU_API_t qemu_api; diff --git a/core/qemu/startup.cpp b/core/qemu/startup.cpp index cdc768d9..c1228087 100644 --- a/core/qemu/startup.cpp +++ b/core/qemu/startup.cpp @@ -114,7 +114,7 @@ extern "C" uint32_t ncores, const char* cfg, const char* dbg, - const char* max, + Flexus::Qemu::API::cycles_opts cycles, const char* cwd) { auto oldcwd = get_current_dir_name(); @@ -151,8 +151,12 @@ extern "C" Flexus::Dbg::Debugger::theDebugger->initialize(); + Flexus::Core::theFlexus->setStopCycle(cycles.until_stop); + Flexus::Core::theFlexus->setStatInterval(cycles.stats_interval); + Flexus::Core::theFlexus->set_log_delay(cycles.log_delay); + if (dbg) Flexus::Core::theFlexus->setDebug(dbg); - if (max) Flexus::Core::theFlexus->setStopCycle(max); + Flexus::Core::ComponentManager::getComponentManager().instantiateComponents(ncores); diff --git a/target/keenkraken/wiring.cpp b/target/keenkraken/wiring.cpp index 30efff89..ae82ac37 100644 --- a/target/keenkraken/wiring.cpp +++ b/target/keenkraken/wiring.cpp @@ -82,7 +82,7 @@ bool initializeParameters() { theMMUCfg.iTLBSize.initialize(64); theMMUCfg.dTLBSize.initialize(64); - theFlexus->setStatInterval("10000000"); // 10M + theFlexus->setStatInterval(10000000); // 10M return false; // Abort simulation if parameters are not initialized } diff --git a/target/knottykraken/wiring.cpp b/target/knottykraken/wiring.cpp index 5cd379da..b8bee266 100644 --- a/target/knottykraken/wiring.cpp +++ b/target/knottykraken/wiring.cpp @@ -230,7 +230,7 @@ bool initializeParameters() { theMMUCfg.PerfectTLB.initialize(true); - theFlexus->setStatInterval("100000"); + theFlexus->setStatInterval(100000); return true; // true = Abort simulation if parameters are not initialized }