10#include "sparta/functional/ArchData.hpp"
15#include "sparta/serialization/checkpoint/Checkpointer.hpp"
17#include "sparta/serialization/checkpoint/VectorStorage.hpp"
18#include "sparta/serialization/checkpoint/StringStreamStorage.hpp"
20namespace sparta::serialization::checkpoint
22 class FastCheckpointer;
42 template<
typename StorageT=storage::StringStreamStorage>
98 is_snapshot_(is_snapshot)
100 if(
nullptr == prev_delta){
101 if(is_snapshot ==
false){
103 <<
id <<
" at tick=" << tick <<
" which has no prev_delta and is not a snapshot";
111 storeSnapshot_(dats);
131 std::cerr <<
"WARNING: DeltaCheckpoint " <<
getID()
132 <<
" being destructed without being allowed to delete" << std::endl;
143 std::stringstream ss;
144 ss <<
"<DeltaCheckpoint id=";
164 virtual void dumpData(std::ostream& o)
const override {
202 +
sizeof(
decltype(*this)) \
203 + (
getNexts().size() *
sizeof(
typename std::remove_reference<
decltype(*
this)>::type*));
210 return data_.getSize();
220 void traceValue(std::ostream& o,
const std::vector<ArchData*>& dats,
221 const ArchData* container, uint32_t offset, uint32_t size)
225 std::vector<std::pair<uint8_t,bool>> bytes;
226 bytes.resize(size,
decltype(bytes)::value_type(0,
false));
228 constexpr uint32_t BUF_SIZE = 8192*2;
229 std::unique_ptr<char[]> buf(
new char[BUF_SIZE]);
231 while(!dcps.empty()){
235 d->data_.prepareForLoad();
236 bool found_ad =
false;
237 bool changed =
false;
242 for(
auto &x : bytes){
248 auto ln_idx = d->data_.getNextRestoreLine();
257 auto ln_off = ln_idx * ad->getLineSize();
259 "Cannot trace value on ArchDatas with line sizes > " << BUF_SIZE <<
" (" << ad->getLineSize() <<
")");
260 d->data_.copyLineBytes((
char*)buf.get(), ad->getLineSize());
264 if(offset >= ln_off && offset < ln_off + ad->getLineSize()){
266 "Cannot trace value which spans multiple lines!");
268 "Value being traced changed twice in the same checkpoint");
270 auto off_in_line = offset - ln_off;
271 o <<
"trace: Value changed (line " << std::dec << ln_idx <<
")" << std::endl;
272 for(uint32_t i=0; i<bytes.size(); i++){
273 bytes[i].first = buf.get()[i+off_in_line];
274 bytes[i].second =
true;
281 o <<
"trace: Could not find selected ArchData " << (
const void*)container <<
" in this checkpoint!" << std::endl;
283 o <<
"trace: Value:";
284 for(uint32_t i=0; i<bytes.size(); i++){
286 o <<
' ' << std::setfill(
'0') << std::setw(2) << std::hex << (uint16_t)bytes[i].first;
306 std::stack<DeltaCheckpoint*> dcps;
322 std::stack<DeltaCheckpoint*> dcps;
339 std::stack<const DeltaCheckpoint*> dcps;
357 if (!prev->isFlaggedDeleted()) {
358 return prev->getID();
369 std::vector<chkpt_id_t> next_ids;
370 for (
const auto chkpt :
getNexts()) {
372 if (!dcp->isFlaggedDeleted()) {
373 next_ids.push_back(chkpt->getID());
386 virtual void load(
const std::vector<ArchData*>& dats)
override {
391 while(!dcps.empty()){
432 "Cannot delete a checkpoint when it is already deleted: " <<
this);
433 deleted_id_ =
getID();
464 std::stringstream ss;
502#pragma clang diagnostic push
503#pragma clang diagnostic ignored "-Wexceptions"
504#elif defined __GNUC__
505#pragma GCC diagnostic push
508#pragma GCC diagnostic ignored "-Wterminate"
513 throw CheckpointError() <<
"In getDistanceToPrevious, somehow reached null "
514 <<
"previous-checkpoint without encountering a snapshot. This should "
515 <<
"never occur and is a critical error";
517#pragma clang diagnostic pop
518#elif defined __GNUC__
519#pragma GCC diagnostic pop
544 template <
typename Archive>
545 void serialize(Archive& ar,
const unsigned int version) {
563 data_.prepareForLoad();
565 "Attempted to loadState from a DeltaCheckpoint with a bad data buffer");
569 ad->restoreAll(data_);
591 void storeSnapshot_(
const std::vector<ArchData*>& dats) {
593 "Attempted to storeSnapshot_ from a DeltaCheckpoint with a bad data buffer");
607 void storeDelta_(
const std::vector<ArchData*>& dats) {
609 "Attempted to storeDelta_ from a DeltaCheckpoint with a bad data buffer");
629 bool is_snapshot_ =
false;
File that contains checkpoint exception types.
A simple time-based, event precedence based scheduler.
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...
static const line_idx_type INVALID_LINE_IDX
Invalid line index.
uint64_t chkpt_id_t
tick_t Checkpoint ID type to which checkpoints will refer
void serialize(Archive &ar, const unsigned int)
boost::serialization support
void setID_(chkpt_id_t id)
Sets the checkpoint ID.
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.
sparta::Scheduler::Tick tick_t
tick_t Tick type to which checkpoints will refer
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.
const std::vector< Checkpoint * > & getNexts() const noexcept
Returns next checkpoint following *this. May be an empty vector if there are no later checkpoints fol...
void makeHeadCheckpoint() override
Make this the head checkpoint by detaching from previous checkpoint.
void addNext(Checkpoint *next)
Adds another next checkpoint following *this.
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...
void makeHeadCheckpoint() override
Make this the head checkpoint by detaching from previous checkpoint.
std::vector< chkpt_id_t > getNextIDs() const override
Returns next checkpoint following *this. May be an empty vector if there are no later checkpoints.
virtual void dumpData(std::ostream &o) const override
Writes all checkpoint raw data to an ostream.
chkpt_id_t getPrevID() const override
Get the ID of our previous checkpoint. Returns UNIDENTIFIED_CHECKPOINT if we have no previous checkpo...
std::stack< DeltaCheckpoint * > getHistoryChain()
Returns a stack of checkpoints from this checkpoint as far back as possible until no previous link is...
bool isSnapshot() const noexcept
Is this checkpoint a snapshot (contains ALL simulator state)
std::stack< const DeltaCheckpoint * > getRestoreChain() const
Const-qualified version of getRestoreChain.
bool isFlaggedDeleted() const noexcept
Indicates whether this checkpoint has been flagged deleted.
virtual std::string getDeletedRepr() const override
Gets the representation of this deleted checkpoint as part of a checkpoint chain (if that checkpointe...
virtual ~DeltaCheckpoint()
Destructor.
std::stack< DeltaCheckpoint * > getRestoreChain()
Returns a stack of checkpoints that must be restored from top-to-bottom to fully restore the state as...
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....
const DeltaCheckpoint & operator=(const DeltaCheckpoint &)=delete
Non-assignable.
void loadState(const std::vector< ArchData * > &dats)
Loads delta state of this checkpoint to root. Does not look at any other checkpoints checkpoints.
DeltaCheckpoint(const DeltaCheckpoint &)=delete
Not copy constructable.
virtual uint64_t getContentMemoryUse() const noexcept override
Returns memory usage by the content of this checkpoint.
DeltaCheckpoint()=default
Default constructor to support boost::serialization.
virtual uint64_t getTotalMemoryUse() const noexcept override
Returns memory usage by this checkpoint.
void serialize(Archive &ar, const unsigned int version)
boost::serialization support
virtual std::string stringize() const override
Returns a string describing this object.
uint32_t getDistanceToPrevSnapshot() const noexcept
Determines how many checkpoints away the closest, earlier snapshot is.
void dumpRestoreChain(std::ostream &o) const
Dumps the restore chain for this checkpoint.
Implements quick checkpointing through delta-checkpoint trees which store state-deltas in a compact f...