11#include "sparta/functional/ArchData.hpp"
15#include "sparta/serialization/checkpoint/DeltaCheckpoint.hpp"
18#ifndef DEFAULT_SNAPSHOT_THRESH
19#define DEFAULT_SNAPSHOT_THRESH 20
22namespace sparta::serialization::checkpoint
92 snap_thresh_(DEFAULT_SNAPSHOT_THRESH),
94 num_alive_checkpoints_(0),
95 num_alive_snapshots_(0),
96 num_dead_checkpoints_(0)
140 snap_thresh_ = thresh;
175 <<
id <<
" because no checkpoint by this ID was found";
182 num_dead_checkpoints_++;
184 num_alive_snapshots_--;
186 num_alive_checkpoints_--;
212 <<
id <<
" because no checkpoint by this ID was found";
256 std::vector<chkpt_id_t> results;
261 results.push_back(cp->
getID());
276 std::vector<chkpt_id_t> results;
281 results.push_back(cp->
getID());
291 return num_alive_checkpoints_;
298 return num_alive_snapshots_;
313 return num_dead_checkpoints_;
332 std::deque<chkpt_id_t> results;
341 results.push_back(d->
getID());
402 std::stringstream ss;
412 o <<
"trace: Searching for 0x" << std::hex << offset <<
" (" << std::dec << size
413 <<
" bytes) in ArchData " << (
const void*)container <<
" when loading checkpoint "
414 << std::dec <<
id << std::endl;
416 o <<
"trace: Checkpoint " <<
id <<
" not found" << std::endl;
496 num_dead_checkpoints_--;
519 const std::vector<Checkpoint*> & nexts = d->
getNexts();
520 for(
const auto & chkpt : nexts)
579 static std::string SNAPSHOT_NOTICE =
"(s)";
592 o <<
' ' << SNAPSHOT_NOTICE;
601 void createHead_()
override {
608 throw CheckpointError(
"Cannot create head at ")
609 << tick <<
" because a head already exists in this checkpointer";
611 if(
getRoot().isFinalized() ==
false){
612 CheckpointError exc(
"Cannot create a checkpoint until the tree is finalized. Attempting to checkpoint from node ");
617 exc <<
"<no scheduler>";
622 checkpoint_type* dcp =
new checkpoint_type(
getRoot(),
getArchDatas(), next_chkpt_id_++, tick,
nullptr,
true);
623 chkpts_[dcp->getID()].reset(dcp);
625 num_alive_checkpoints_++;
626 num_alive_snapshots_++;
630 chkpt_id_t createCheckpoint_(
bool force_snapshot=
false)
override {
632 checkpoint_type* prev;
635 throw CheckpointError(
"Exhausted all ")
637 <<
"This is likely a gross misuse of checkpointing";
651 throw CheckpointError(
"Cannot create a new checkpoint at tick ")
652 << tick <<
" because this tick number is smaller than the tick number of the head checkpoint at: "
653 <<
getHead()->
getTick() <<
". The head checkpoint cannot be reset once created, so it should be done "
654 <<
"at the start of simulation before running. The simulator front-end should do this so this must "
655 <<
"likely be fixed in the simulator.";
660 prev =
static_cast<checkpoint_type*
>(
getHead_());
664 throw CheckpointError(
"Current tick number from sparta scheduler (")
665 << tick <<
" ) is less than the current checkpoint's tick number ("
666 <<
getCurrent_()->
getTick() <<
" To create a checkpoint with an earlier tick number, an "
667 <<
"older checkpoint having a tick number <= the tick number specified here must first be "
673 prev =
static_cast<checkpoint_type*
>(
getCurrent_());
677 checkpoint_type* dcp =
new checkpoint_type(
getRoot(),
682 force_snapshot || is_snapshot);
683 chkpts_[dcp->getID()].reset(dcp);
684 num_alive_checkpoints_++;
685 num_alive_snapshots_ += (dcp->isSnapshot() ==
true);
688 if (dcp->isSnapshot()){
703 uint32_t snap_thresh_;
714 uint32_t num_alive_checkpoints_;
722 uint32_t num_alive_snapshots_;
728 uint32_t num_dead_checkpoints_;
Set of macros for Sparta assertions. Caught by the framework.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
Exception class for all of Sparta.
Basic Node framework in sparta device tree composite pattern.
Contains a set of contiguous line of architectural data which can be referred to by any architected o...
A class that lets you schedule events now and in the future.
Tick getCurrentTick() const noexcept
The current tick the Scheduler is working on or just finished.
void restartAt(Tick t)
Clears the events in the scheduler, sets the current tick to tick and the elapsed ticks to either tic...
Node in a composite tree representing a sparta Tree item.
std::string getLocation() const override final
Indicates that there was an issue operating on checkpoints within the SPARTA framework.
Single checkpoint object interface with a tick number and an ID unique to the owning Checkpointer ins...
Checkpoint * getPrev() const noexcept
Returns the previous checkpoint. If this checkpoint is a snapshot, it has no previous checkpoint.
virtual std::string getDeletedRepr() const
Gets the representation of this deleted checkpoint as part of a checkpoint chain (if that checkpointe...
const std::vector< Checkpoint * > & getNexts() const noexcept
Returns next checkpoint following *this. May be an empty vector if there are no later checkpoints fol...
chkpt_id_t getID() const noexcept
Returns the ID of this checkpoint.
tick_t getTick() const noexcept
Returns the tick number at which this checkpoint was taken.
static const chkpt_id_t UNIDENTIFIED_CHECKPOINT
Indicates unidentified checkpoint (could mean 'invalid' or 'any') depending on context.
Checkpointer interface. Defines an ID-based checkpointing API for tree of related checkpoints which c...
const std::vector< ArchData * > & getArchDatas() const
Returns ArchDatas enumerated by this Checkpointer for iteration when saving or loading checkpoint dat...
Scheduler *const sched_
Scheduler whose tick count will be set and read. Cannnot be updated after first checkpoint without ba...
const TreeNode & getRoot() const noexcept
Returns the root associated with this checkpointer.
Checkpoint * getCurrent_() const noexcept
Gets the current checkpointer pointer. Returns nullptr if there is no current checkpoint object.
Checkpoint * getHead_() noexcept
Non-const variant of getHead_.
tick_t getCurrentTick() const
Gets the tick number of the current checkpoint (see getCurrentID). This is the tick number of the lat...
Checkpoint::tick_t tick_t
tick_t Tick type to which checkpoints will refer
std::map< chkpt_id_t, std::unique_ptr< Checkpoint > > chkpts_
All checkpoints sorted by ascending tick number (or equivalently ascending checkpoint ID since both a...
const Checkpoint * getHead() const noexcept
Returns the head checkpoint which is equivalent to the earliest checkpoint taken.
Checkpoint::chkpt_id_t chkpt_id_t
tick_t Tick type to which checkpoints will refer
void setCurrent_(Checkpoint *current)
Sets the current checkpoint pointer.
void setHead_(Checkpoint *head)
Sets the head checkpointer pointer to head for the first time.
Single delta checkpoint object containing all simulator state which changed since some previous Delta...
chkpt_id_t getDeletedID() const noexcept
Return the ID had by this checkpoint before it was deleted If this checkpoint has not been flagged fo...
bool isSnapshot() const noexcept
Is this checkpoint a snapshot (contains ALL simulator state)
bool isFlaggedDeleted() const noexcept
Indicates whether this checkpoint has been flagged deleted.
virtual void load(const std::vector< ArchData * > &dats) override
Attempts to restore this checkpoint including any previous deltas (dependencies).
bool canDelete() const noexcept
Can this checkpoint be deleted Cannot be deleted if:
void traceValue(std::ostream &o, const std::vector< ArchData * > &dats, const ArchData *container, uint32_t offset, uint32_t size)
Implement trace of a value across the restore chain as described in Checkpointer::traceValue.
void flagDeleted()
Allows this checkpoint to be deleted if it is no longer a previous delta of some other delta (i....
Implements quick checkpointing through delta-checkpoint trees which store state-deltas in a compact f...
FastCheckpointer(TreeNode &root, Scheduler *sched=nullptr)
FastCheckpointer Constructor.
void deleteCheckpoint(chkpt_id_t id) override
Deletes a checkpoint by ID.
void setSnapshotThreshold(uint32_t thresh) noexcept
Sets the snapshot threshold.
uint32_t getNumCheckpoints() const noexcept override
Gets the current number of checkpoints having valid IDs.
std::string stringize() const override
Returns a string describing this object.
void cleanupChain_(checkpoint_type *d)
Delete given checkpoint and all contiguous previous checkpoints which can be deleted (See checkpoint_...
checkpoint_type * findLatestCheckpointAtOrBefore(tick_t tick, chkpt_id_t from) override
Finds the latest checkpoint at or before the given tick starting at the from checkpoint and working b...
uint32_t getSnapshotThreshold() const noexcept
Returns the next-shapshot threshold.
void dumpCheckpointNode_(const Checkpoint *chkpt, std::ostream &o) const override
Implements Checkpointer::dumpCheckpointNode_.
std::vector< chkpt_id_t > getCheckpointsAt(tick_t t) const override
Gets all checkpoints taken at tick t on any timeline.
std::deque< chkpt_id_t > getCheckpointChain(chkpt_id_t id) const override
Debugging utility which gets a deque of checkpoints representing a chain starting at the checkpoint h...
const checkpoint_type * findCheckpoint_(chkpt_id_t id) const noexcept override
const variant of findCheckpoint_
uint32_t getNumDeltas() const noexcept
Gets the current number of delta checkpoints with valid IDs.
void loadCheckpoint(chkpt_id_t id) override
Loads state from a specific checkpoint by ID.
checkpoint_type * findCheckpoint_(chkpt_id_t id) noexcept override
Attempts to find a checkpoint within this checkpointer by ID.
uint32_t getNumSnapshots() const noexcept
Gets the current number of snapshots with valid IDs.
uint32_t getNumDeadCheckpoints() const noexcept
Gets the curent number of checkpoints (delta or snapshot) withOUT valid IDs.
bool recursForwardFindAlive_(checkpoint_type *d) const
Look forward to see if any future checkpoints depend on d.
std::vector< chkpt_id_t > getCheckpoints() const override
Gets all checkpoint IDs available on any timeline sorted by tick (or equivalently checkpoint ID).
~FastCheckpointer()
Destructor.
checkpoint_type * findInternalCheckpoint(chkpt_id_t id)
Gets a checkpoint through findCheckpoint interface casted to the type of Checkpoint subclass used by ...
bool checkpointExists(chkpt_id_t id)
Queries a specific checkpoint by ID.
void traceValue(std::ostream &o, chkpt_id_t id, const ArchData *container, uint32_t offset, uint32_t size) override
Forwards debug/trace info onto checkpoint by ID.