The Sparta Modeling Framework
Loading...
Searching...
No Matches
DatabaseCheckpoint.hpp
1// <DatabaseCheckpoint> -*- C++ -*-
2
3#pragma once
4
5#include "sparta/serialization/checkpoint/CheckpointBase.hpp"
7#include "sparta/serialization/checkpoint/VectorStorage.hpp"
8
9namespace sparta::serialization::checkpoint
10{
11 class DatabaseCheckpointer;
12 class DatabaseCheckpoint;
13
21 struct ChkptWindow {
22 using chkpt_id_t = CheckpointBase::chkpt_id_t;
23 std::vector<std::shared_ptr<DatabaseCheckpoint>> chkpts;
24 chkpt_id_t start_chkpt_id = CheckpointBase::UNIDENTIFIED_CHECKPOINT;
25 chkpt_id_t end_chkpt_id = CheckpointBase::UNIDENTIFIED_CHECKPOINT;
26 uint64_t start_tick = 0;
27 uint64_t end_tick = 0;
28 bool ignore = false;
29
31 template <typename Archive>
32 void serialize(Archive& ar, const unsigned int /*version*/);
33 };
34
39 using chkpt_id_t = CheckpointBase::chkpt_id_t;
40 std::vector<char> chkpt_bytes;
41 chkpt_id_t start_chkpt_id = CheckpointBase::UNIDENTIFIED_CHECKPOINT;
42 chkpt_id_t end_chkpt_id = CheckpointBase::UNIDENTIFIED_CHECKPOINT;
43 uint64_t start_tick = 0;
44 uint64_t end_tick = 0;
45 bool ignore = false;
46 };
47
53 {
54 public:
55
59
62
65
68
71
72 private:
73
75 DatabaseCheckpoint(const std::vector<ArchData*>& dats,
76 chkpt_id_t id,
77 tick_t tick,
79 bool is_snapshot,
80 DatabaseCheckpointer* checkpointer);
81
83 DatabaseCheckpoint() = default;
84
87
88 friend struct ChkptWindow;
89 friend class DatabaseCheckpointer;
90
91 public:
92
93 /*
94 * \brief Support boost::serialization
95 */
96 template <typename Archive>
97 void serialize(Archive& ar, const unsigned int version) {
98 CheckpointBase::serialize(ar, version);
99 ar & prev_id_;
100 ar & next_ids_;
101 ar & is_snapshot_;
102 ar & data_;
103 }
104
108 std::string stringize() const override;
109
115 void dumpData(std::ostream& o) const override;
116
120 uint64_t getTotalMemoryUse() const noexcept override;
121
125 uint64_t getContentMemoryUse() const noexcept override;
126
134 std::stack<chkpt_id_t> getHistoryChain() const;
135
141 std::stack<chkpt_id_t> getRestoreChain() const;
142
147 chkpt_id_t getPrevID() const override;
148
156 std::vector<chkpt_id_t> getNextIDs() const override;
157
165 void load(const std::vector<ArchData*>& dats) override;
166
171 bool isSnapshot() const noexcept;
172
181 uint32_t getDistanceToPrevSnapshot() const noexcept;
182
188 void loadState(const std::vector<ArchData*>& dats);
189
190 private:
191
200 void storeSnapshot_(const std::vector<ArchData*>& dats);
201
210 void storeDelta_(const std::vector<ArchData*>& dats);
211
213 chkpt_id_t prev_id_;
214
220 std::vector<chkpt_id_t> next_ids_;
221
223 bool is_snapshot_;
224
226 storage::VectorStorage data_;
227
229 DatabaseCheckpointer* checkpointer_ = nullptr;
230 };
231
236 template <typename Archive>
237 inline void ChkptWindow::serialize(Archive& ar, const unsigned int /*version*/) {
238 ar & start_chkpt_id;
239 ar & end_chkpt_id;
240 ar & start_tick;
241 ar & end_tick;
242
243 if (chkpts.empty()) {
244 // We are loading a checkpoint window from disk
245 const auto num_chkpts = end_chkpt_id - start_chkpt_id + 1;
246 for (size_t i = 0; i < num_chkpts; ++i) {
247 chkpts.emplace_back(new DatabaseCheckpoint);
248 ar & *chkpts.back();
249 }
250 } else {
251 // We are saving a checkpoint window to disk
252 for (auto& chkpt : chkpts) {
253 ar & *chkpt;
254 }
255 }
256 }
257
258} // namespace sparta::serialization::checkpoint
File that contains checkpoint exception types.
Contains a set of contiguous line of architectural data which can be referred to by any architected o...
Definition ArchData.hpp:39
Single checkpoint object interface with a tick number and an ID unique to the owning Checkpointer ins...
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
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
Checkpoint class optimized for use with database-backed checkpointers.
bool isSnapshot() const noexcept
Is this checkpoint a snapshot? If true, this checkpoint has no dependencies and contains all simulato...
std::stack< chkpt_id_t > getRestoreChain() const
Returns a stack of checkpoints that must be restored from top-to-bottom to fully restore the state as...
void loadState(const std::vector< ArchData * > &dats)
Loads delta state of this checkpoint to root.
std::string stringize() const override
Returns a string describing this object.
std::stack< chkpt_id_t > getHistoryChain() const
Returns a stack of checkpoints from this checkpoint as far back as possible until no previous link is...
uint32_t getDistanceToPrevSnapshot() const noexcept
Determines how many checkpoints away the closest, earlier snapshot is.
uint64_t getTotalMemoryUse() const noexcept override
Returns memory usage by this checkpoint.
uint64_t getContentMemoryUse() const noexcept override
Returns memory usage by the content of this checkpoint.
void dumpData(std::ostream &o) const override
Writes all checkpoint raw data to an ostream.
DatabaseCheckpoint(const DatabaseCheckpoint &)=delete
Not copy constructable.
chkpt_id_t getPrevID() const override
Get the ID of our previous checkpoint. Returns UNIDENTIFIED_CHECKPOINT only for the head checkpoint.
DatabaseCheckpoint & operator=(DatabaseCheckpoint &&)=delete
Not move assignable.
DatabaseCheckpoint & operator=(const DatabaseCheckpoint &)=delete
Non-assignable.
std::vector< chkpt_id_t > getNextIDs() const override
Returns next checkpoints following this one. May be an empty vector if there are no later checkpoints...
DatabaseCheckpoint(DatabaseCheckpoint &&)=delete
Not move constructable.
void load(const std::vector< ArchData * > &dats) override
Attempts to restore this checkpoint including any previous deltas (dependencies).
Implementation of the FastCheckpointer which only holds a subset of checkpoints in memory at any give...
Compressed version of ChkptWindow to be stored in the database.
A window of checkpoints to be sent to/from the database as a unit.
void serialize(Archive &ar, const unsigned int)
Support boost::serialization.