Skip to content

Commit

Permalink
feat: add options to delay logging
Browse files Browse the repository at this point in the history
Also delete unused methods from flexus.cpp
  • Loading branch information
branylagaffe committed Oct 29, 2024
1 parent ba20bd6 commit 5887b4c
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 57 deletions.
5 changes: 3 additions & 2 deletions core/debug/aux_/process.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <boost/preprocessor/seq/elem.hpp>
#include <boost/preprocessor/tuple/elem.hpp>
#include <core/boost_extensions/va.h>
#include <core/flexus.hpp>

#define DBG__internal_FIRST(x, y) x

Expand Down Expand Up @@ -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)), \
Expand Down
6 changes: 6 additions & 0 deletions core/debug/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ Debugger::reset()
theTargets.clear();
}

bool
Debugger::is_logging_enabled(void)
{
return (cycleCount()) ? (static_cast<uint64_t>(cycleCount()) >= *cycle_delay_log) : true;
}

Debugger* Debugger::theDebugger((Debugger*)0);

void
Expand Down
10 changes: 8 additions & 2 deletions core/debug/debugger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Debugger

int64_t theCount;
uint64_t* theCycleCount;
uint64_t* cycle_delay_log;

std::priority_queue<At> theAts; // Owns all targets

Expand All @@ -47,7 +48,8 @@ class Debugger

Debugger()
: theCount(0)
, theCycleCount(0)
, theCycleCount(nullptr)
, cycle_delay_log(nullptr)
, theMinimumSeverity(SevDev)
{
}
Expand All @@ -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);
Expand All @@ -84,6 +89,7 @@ class Debugger
void checkAt();
void doNextAt();
void reset();
bool is_logging_enabled(void);

void setMinSev(Severity aSeverity) { theMinimumSeverity = aSeverity; }
};
Expand Down
50 changes: 23 additions & 27 deletions core/flexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::function<void()>> 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
Expand All @@ -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);
Expand All @@ -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() {}
};
Expand All @@ -120,16 +110,14 @@ FlexusImpl::setCycle(uint64_t cycle)
{
theCycleCount = cycle;
theStopCycle += cycle;
cycle_delay_log += cycle;
}

void
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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<uint64_t>(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<uint64_t>(aValue);
DBG_(Dev, Set((Source) << "flexus")(<< "Set stat interval to : " << theStatInterval));
theStatInterval = aValue;
DBG_(Dev, Set((Source) << "flexus")(<< "Set STAT interval to : " << theStatInterval));
}

void
Expand Down Expand Up @@ -252,7 +249,6 @@ FlexusImpl::saveState(std::string const& aDirName)
}
}


void
FlexusImpl::loadState(std::string const& aDirName)
{
Expand Down
12 changes: 6 additions & 6 deletions core/flexus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <string>

namespace Flexus::Core {

class FlexusInterface
{
public:
Expand All @@ -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

Expand All @@ -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;
Expand Down
28 changes: 12 additions & 16 deletions core/qemu/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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----------------------------
*---------------------------------------------------------------*/
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions core/qemu/startup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion target/keenkraken/wiring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion target/knottykraken/wiring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 5887b4c

Please sign in to comment.