--- /dev/null
+#include <mc/ChunkedData.hpp>
+
+#define SOFT_DIRTY_BIT_NUMBER 55
+#define SOFT_DIRTY (((uint64_t)1) << SOFT_DIRTY_BIT_NUMBER)
+
+namespace simgrid {
+namespace mc {
+
+/** Take a per-page snapshot of a region
+ *
+ * @param data The start of the region (must be at the beginning of a page)
+ * @param pag_count Number of pages of the region
+ * @return Snapshot page numbers of this new snapshot
+ */
+ChunkedData::ChunkedData(PageStore& store, AddressSpace& as,
+ remote_ptr<void> addr, std::size_t page_count,
+ const std::size_t* ref_page_numbers, const std::uint64_t* pagemap)
+{
+ store_ = &store;
+ this->pagenos_.resize(page_count);
+ std::vector<char> buffer(xbt_pagesize);
+
+ for (size_t i = 0; i != page_count; ++i) {
+
+ // We don't have to compare soft-clean pages:
+ if (ref_page_numbers && pagemap && !(pagemap[i] & SOFT_DIRTY)) {
+ pagenos_[i] = ref_page_numbers[i];
+ store_->ref_page(ref_page_numbers[i]);
+ continue;
+ }
+
+ remote_ptr<void> page = remote(addr.address() + (i << xbt_pagebits));
+ xbt_assert(mc_page_offset((void*)page.address())==0,
+ "Not at the beginning of a page");
+
+ /* Adding another copy (and a syscall) will probably slow things a lot.
+ TODO, optimize this somehow (at least by grouping the syscalls)
+ if needed. Either:
+ - reduce the number of syscalls;
+ - let the application snapshot itself;
+ - move the segments in shared memory (this will break `fork` however).
+ */
+
+ as.read_bytes(
+ buffer.data(), xbt_pagesize, page,
+ simgrid::mc::ProcessIndexDisabled);
+
+ pagenos_[i] = store_->store_page(buffer.data());
+
+ }
+}
+
+}
+}
--- /dev/null
+#ifndef SIMGRID_MC_CHUNKED_DATA_HPP
+#define SIMGRID_MC_CHUNKED_DATA_HPP
+
+#include <cstddef>
+#include <cstdint>
+
+#include <vector>
+
+#include <mc/mc_forward.hpp>
+#include <mc/AddressSpace.hpp>
+#include <mc/PageStore.hpp>
+
+namespace simgrid {
+namespace mc {
+
+class ChunkedData {
+ PageStore* store_;
+ std::vector<std::size_t> pagenos_;
+public:
+ ChunkedData() : store_(nullptr) {}
+ ChunkedData(ChunkedData const& that)
+ {
+ store_ = that.store_;
+ pagenos_ = that.pagenos_;
+ for (std::size_t pageno : pagenos_)
+ store_->ref_page(pageno);
+ }
+ void clear()
+ {
+ for (std::size_t pageno : pagenos_)
+ store_->unref_page(pageno);
+ pagenos_.clear();
+ }
+ ~ChunkedData()
+ {
+ clear();
+ }
+
+ ChunkedData(ChunkedData&& that)
+ {
+ store_ = that.store_;
+ that.store_ = nullptr;
+ pagenos_ = std::move(that.pagenos_);
+ that.pagenos_.clear();
+ }
+ ChunkedData& operator=(ChunkedData const& that)
+ {
+ this->clear();
+ store_ = that.store_;
+ pagenos_ = that.pagenos_;
+ for (std::size_t pageno : pagenos_)
+ store_->ref_page(pageno);
+ return *this;
+ }
+ ChunkedData& operator=(ChunkedData && that)
+ {
+ this->clear();
+ store_ = that.store_;
+ that.store_ = nullptr;
+ pagenos_ = std::move(that.pagenos_);
+ that.pagenos_.clear();
+ return *this;
+ }
+
+ std::size_t page_count() const { return pagenos_.size(); }
+ std::size_t pageno(std::size_t i) const { return pagenos_[i]; }
+ const std::size_t* pagenos() const { return pagenos_.data(); }
+ std::size_t* pagenos() { return pagenos_.data(); }
+
+ const void* page(std::size_t i) const
+ {
+ return store_->get_page(pagenos_[i]);
+ }
+
+ ChunkedData(PageStore& store, AddressSpace& as,
+ remote_ptr<void> addr, std::size_t page_count,
+ const std::size_t* ref_page_numbers, const std::uint64_t* pagemap);
+};
+
+}
+}
+
+#endif
#include "mc/mc.h"
#include "mc_snapshot.h"
-#include "RegionSnapshot.hpp"
+
+#include <mc/ChunkedData.hpp>
+#include <mc/RegionSnapshot.hpp>
extern "C" {
ref_page_numbers = ref_region->page_data().pagenos();
}
- simgrid::mc::PerPageCopy page_data(
+ simgrid::mc::ChunkedData page_data(
mc_model_checker->page_store(), *process, permanent_addr, page_count,
ref_page_numbers,
use_soft_dirty ? pagemap.data() : nullptr);
#include <mc/PageStore.hpp>
#include <mc/AddressSpace.hpp>
+#include <mc/ChunkedData.hpp>
namespace simgrid {
namespace mc {
-class PerPageCopy {
- PageStore* store_;
- std::vector<std::size_t> pagenos_;
-public:
- PerPageCopy() : store_(nullptr) {}
- PerPageCopy(PerPageCopy const& that)
- {
- store_ = that.store_;
- pagenos_ = that.pagenos_;
- for (std::size_t pageno : pagenos_)
- store_->ref_page(pageno);
- }
- void clear()
- {
- for (std::size_t pageno : pagenos_)
- store_->unref_page(pageno);
- pagenos_.clear();
- }
- ~PerPageCopy() {
- clear();
- }
-
- PerPageCopy(PerPageCopy&& that)
- {
- store_ = that.store_;
- that.store_ = nullptr;
- pagenos_ = std::move(that.pagenos_);
- that.pagenos_.clear();
- }
- PerPageCopy& operator=(PerPageCopy const& that)
- {
- this->clear();
- store_ = that.store_;
- pagenos_ = that.pagenos_;
- for (std::size_t pageno : pagenos_)
- store_->ref_page(pageno);
- return *this;
- }
- PerPageCopy& operator=(PerPageCopy && that)
- {
- this->clear();
- store_ = that.store_;
- that.store_ = nullptr;
- pagenos_ = std::move(that.pagenos_);
- that.pagenos_.clear();
- return *this;
- }
-
- std::size_t page_count() const
- {
- return pagenos_.size();
- }
-
- std::size_t pageno(std::size_t i) const
- {
- return pagenos_[i];
- }
-
- const std::size_t* pagenos() const { return pagenos_.data(); }
- std::size_t* pagenos() { return pagenos_.data(); }
-
- const void* page(std::size_t i) const
- {
- return store_->get_page(pagenos_[i]);
- }
-
- PerPageCopy(PageStore& store, AddressSpace& as,
- remote_ptr<void> addr, std::size_t page_count,
- const size_t* ref_page_numbers, const std::uint64_t* pagemap);
-};
-
enum class RegionType {
Unknown = 0,
Heap = 1,
static const RegionType UnknownRegion = RegionType::Unknown;
static const RegionType HeapRegion = RegionType::Heap;
static const RegionType DataRegion = RegionType::Data;
- static const StorageType NoData = StorageType::NoData;
- static const StorageType FlatData = StorageType::Flat;
- static const StorageType ChunkedData = StorageType::Chunked;
- static const StorageType PrivatizedData = StorageType::Privatized;
public:
typedef unique_data_ptr flat_data_ptr;
private:
void *permanent_addr_;
flat_data_ptr flat_data_;
- PerPageCopy page_numbers_;
+ ChunkedData page_numbers_;
std::vector<RegionSnapshot> privatized_regions_;
public:
RegionSnapshot() :
region_type_(UnknownRegion),
- storage_type_(NoData),
+ storage_type_(StorageType::NoData),
object_info_(nullptr),
start_addr_(nullptr),
size_(0),
{}
RegionSnapshot(RegionType type, void *start_addr, void* permanent_addr, size_t size) :
region_type_(type),
- storage_type_(NoData),
+ storage_type_(StorageType::NoData),
object_info_(nullptr),
start_addr_(start_addr),
size_(size),
void clear()
{
region_type_ = UnknownRegion;
- storage_type_ = NoData;
+ storage_type_ = StorageType::NoData;
privatized_regions_.clear();
page_numbers_.clear();
flat_data_.reset();
void clear_data()
{
- storage_type_ = NoData;
+ storage_type_ = StorageType::NoData;
flat_data_.reset();
page_numbers_.clear();
privatized_regions_.clear();
void flat_data(flat_data_ptr data)
{
- storage_type_ = FlatData;
+ storage_type_ = StorageType::Flat;
flat_data_ = std::move(data);
page_numbers_.clear();
privatized_regions_.clear();
}
const char* flat_data() const { return flat_data_.get(); }
- void page_data(PerPageCopy page_data)
+ void page_data(ChunkedData page_data)
{
- storage_type_ = ChunkedData;
+ storage_type_ = StorageType::Chunked;
flat_data_.reset();
page_numbers_ = std::move(page_data);
privatized_regions_.clear();
}
- PerPageCopy const& page_data() const { return page_numbers_; }
+ ChunkedData const& page_data() const { return page_numbers_; }
void privatized_data(std::vector<RegionSnapshot> data)
{
- storage_type_ = PrivatizedData;
+ storage_type_ = StorageType::Privatized;
flat_data_.reset();
page_numbers_.clear();
privatized_regions_ = std::move(data);
namespace mc {
class PageStore;
+class ChunkedData;
class ModelChecker;
class AddressSpace;
class Process;
#include "mc_snapshot.h"
#include <xbt/mmalloc.h>
-
-#define SOFT_DIRTY_BIT_NUMBER 55
-#define SOFT_DIRTY (((uint64_t)1) << SOFT_DIRTY_BIT_NUMBER)
+#include <mc/ChunkedData.hpp>
using simgrid::mc::remote;
-namespace simgrid {
-namespace mc {
-
-/** @brief Take a per-page snapshot of a region
- *
- * @param data The start of the region (must be at the beginning of a page)
- * @param pag_count Number of pages of the region
- * @return Snapshot page numbers of this new snapshot
- */
-PerPageCopy::PerPageCopy(PageStore& store, AddressSpace& as,
- remote_ptr<void> addr, std::size_t page_count,
- const size_t* ref_page_numbers, const std::uint64_t* pagemap)
-{
- store_ = &store;
- this->pagenos_.resize(page_count);
- std::vector<char> buffer(xbt_pagesize);
-
- for (size_t i = 0; i != page_count; ++i) {
-
- // We don't have to compare soft-clean pages:
- if (ref_page_numbers && pagemap && !(pagemap[i] & SOFT_DIRTY)) {
- pagenos_[i] = ref_page_numbers[i];
- store_->ref_page(ref_page_numbers[i]);
- continue;
- }
-
- remote_ptr<void> page = remote(addr.address() + (i << xbt_pagebits));
- xbt_assert(mc_page_offset((void*)page.address())==0,
- "Not at the beginning of a page");
-
- /* Adding another copy (and a syscall) will probably slow things a lot.
- TODO, optimize this somehow (at least by grouping the syscalls)
- if needed. Either:
- - reduce the number of syscalls;
- - let the application snapshot itself;
- - move the segments in shared memory (this will break `fork` however).
- */
-
- as.read_bytes(
- buffer.data(), xbt_pagesize, page,
- simgrid::mc::ProcessIndexDisabled);
-
- pagenos_[i] = store_->store_page(buffer.data());
-
- }
-}
-
-}
-}
-
extern "C" {
/** @brief Restore a snapshot of a region
* @param pagenos
*/
void mc_restore_page_snapshot_region(simgrid::mc::Process* process,
- void* start_addr, simgrid::mc::PerPageCopy const& pages_copy)
+ void* start_addr, simgrid::mc::ChunkedData const& pages_copy)
{
for (size_t i = 0; i != pages_copy.page_count(); ++i) {
// Otherwise, copy the page:
XBT_PRIVATE void mc_restore_page_snapshot_region(
simgrid::mc::Process* process,
- void* start_addr, simgrid::mc::PerPageCopy const& pagenos);
+ void* start_addr, simgrid::mc::ChunkedData const& pagenos);
const void* MC_region_read_fragmented(
mc_mem_region_t region, void* target, const void* addr, size_t size);
src/mc/ObjectInformation.cpp
src/mc/PageStore.hpp
src/mc/PageStore.cpp
+ src/mc/ChunkedData.hpp
+ src/mc/ChunkedData.cpp
src/mc/RegionSnapshot.cpp
src/mc/RegionSnapshot.hpp
src/mc/Type.hpp