X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/54b039b2cb830d851ebe173aaad0a2bbf3129174..75e190d86217c3892c9d2a9bbe880fc327fef874:/src/mc/RegionSnapshot.hpp diff --git a/src/mc/RegionSnapshot.hpp b/src/mc/RegionSnapshot.hpp index 0c85f22eb3..52deff2007 100644 --- a/src/mc/RegionSnapshot.hpp +++ b/src/mc/RegionSnapshot.hpp @@ -1,129 +1,129 @@ -/* Copyright (c) 2007-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#ifndef SIMGRID_MC_REGION_SNAPSHOT_HPP +#define SIMGRID_MC_REGION_SNAPSHOT_HPP + #include #include -#include "PageStore.hpp" -#include "AddressSpace.hpp" - -#ifndef SIMGRID_MC_REGION_SNAPSHOT_HPP -#define SIMGRID_MC_REGION_SNAPSHOT_HPP +#include +#include -typedef enum e_mc_region_type_t { - MC_REGION_TYPE_UNKNOWN = 0, - MC_REGION_TYPE_HEAP = 1, - MC_REGION_TYPE_DATA = 2 -} mc_region_type_t; +#include "xbt/base.h" -// TODO, use OO instead of this -typedef enum e_mc_region_storage_type_t { - MC_REGION_STORAGE_TYPE_NONE = 0, - MC_REGION_STORAGE_TYPE_FLAT = 1, - MC_REGION_STORAGE_TYPE_CHUNKED = 2, - MC_REGION_STORAGE_TYPE_PRIVATIZED = 3 -} mc_region_storage_type_t; +#include "src/mc/AddressSpace.hpp" +#include "src/mc/ChunkedData.hpp" +#include "src/mc/PageStore.hpp" +#include "src/mc/remote/RemotePtr.hpp" namespace simgrid { namespace mc { -class PerPageCopy { - PageStore* store_; - std::vector pagenos_; +enum class RegionType { + Unknown = 0, + Heap = 1, + Data = 2 +}; + +enum class StorageType { + NoData = 0, + Flat = 1, + Chunked = 2, + Privatized = 3 +}; + +class Buffer { +private: + enum class Type { + Malloc, + Mmap + }; + void* data_ = nullptr; + std::size_t size_; + Type type_ = Type::Malloc; +private: + Buffer(std::size_t size, Type type = Type::Malloc); + Buffer(void* data, std::size_t size, Type type = Type::Malloc) : + data_(data), size_(size), type_(type) {} 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(); - } + Buffer() = default; + void clear() noexcept; + ~Buffer() noexcept { clear(); } - PerPageCopy(PerPageCopy&& that) - { - store_ = that.store_; - that.store_ = nullptr; - pagenos_ = std::move(that.pagenos_); - that.pagenos_.clear(); - } - PerPageCopy& operator=(PerPageCopy const& that) + static Buffer malloc(std::size_t size) { - this->clear(); - store_ = that.store_; - pagenos_ = that.pagenos_; - for (std::size_t pageno : pagenos_) - store_->ref_page(pageno); - return *this; + return Buffer(size, Type::Malloc); } - PerPageCopy& operator=(PerPageCopy && that) + static Buffer mmap(std::size_t size) { - this->clear(); - store_ = that.store_; - that.store_ = nullptr; - pagenos_ = std::move(that.pagenos_); - that.pagenos_.clear(); - return *this; + return Buffer(size, Type::Mmap); } - std::size_t page_count() const - { - return pagenos_.size(); - } + // No copy + Buffer(Buffer const& buffer) = delete; + Buffer& operator=(Buffer const& buffer) = delete; - std::size_t pageno(std::size_t i) const + // Move + Buffer(Buffer&& that) noexcept + : data_(that.data_), size_(that.size_), type_(that.type_) { - return pagenos_[i]; + that.data_ = nullptr; + that.size_ = 0; + that.type_ = Type::Malloc; } - - const void* page(std::size_t i) const + Buffer& operator=(Buffer&& that) noexcept { - return store_->get_page(pagenos_[i]); + clear(); + data_ = that.data_; + size_ = that.size_; + type_ = that.type_; + that.data_ = nullptr; + that.size_ = 0; + that.type_ = Type::Malloc; + return *this; } - PerPageCopy(PageStore& store, AddressSpace& as, - remote_ptr addr, std::size_t page_count); + void* get() { return data_; } + const void* get() const { return data_; } + std::size_t size() const { return size_; } }; -/** @brief Copy/snapshot of a given memory region +/** A copy/snapshot of a given memory region * * Different types of region snapshot storage types exist: - *
    - *
  • flat/dense snapshots are a simple copy of the region;
  • - *
  • sparse/per-page snapshots are snaapshots which shared - * identical pages.
  • - *
  • privatized (SMPI global variable privatisation). - *
* - * This is handled with a variant based approch: + * * flat/dense snapshots are a simple copy of the region; * - * * `storage_type` identified the type of storage; - * * an anonymous enum is used to distinguish the relevant types for - * each type. + * * sparse/per-page snapshots are snaapshots which shared + * identical pages. + * + * * privatized (SMPI global variable privatization). + * + * This is handled with a variant based approach: + * + * * `storage_type` identified the type of storage; + * + * * an anonymous enum is used to distinguish the relevant types for + * each type. */ class RegionSnapshot { +public: + static const RegionType UnknownRegion = RegionType::Unknown; + static const RegionType HeapRegion = RegionType::Heap; + static const RegionType DataRegion = RegionType::Data; private: - mc_region_type_t region_type_; - mc_region_storage_type_t storage_type_; - mc_object_info_t object_info_; + RegionType region_type_; + StorageType storage_type_; + simgrid::mc::ObjectInformation* object_info_; /** @brief Virtual address of the region in the simulated process */ void *start_addr_; /** @brief Size of the data region in bytes */ - size_t size_; + std::size_t size_; /** @brief Permanent virtual address of the region * @@ -136,40 +136,40 @@ private: * */ void *permanent_addr_; - std::vector flat_data_; - PerPageCopy page_numbers_; + Buffer flat_data_; + ChunkedData page_numbers_; std::vector privatized_regions_; public: RegionSnapshot() : - region_type_(MC_REGION_TYPE_UNKNOWN), - storage_type_(MC_REGION_STORAGE_TYPE_NONE), + region_type_(UnknownRegion), + storage_type_(StorageType::NoData), object_info_(nullptr), start_addr_(nullptr), size_(0), permanent_addr_(nullptr) {} - RegionSnapshot(mc_region_type_t type, void *start_addr, void* permanent_addr, size_t size) : + RegionSnapshot(RegionType type, void *start_addr, void* permanent_addr, size_t size) : region_type_(type), - storage_type_(MC_REGION_STORAGE_TYPE_NONE), + storage_type_(StorageType::NoData), object_info_(nullptr), start_addr_(start_addr), size_(size), permanent_addr_(permanent_addr) {} - ~RegionSnapshot() {} + ~RegionSnapshot() = default; RegionSnapshot(RegionSnapshot const&) = default; RegionSnapshot& operator=(RegionSnapshot const&) = default; RegionSnapshot(RegionSnapshot&& that) + : region_type_(that.region_type_) + , storage_type_(that.storage_type_) + , object_info_(that.object_info_) + , start_addr_(that.start_addr_) + , size_(that.size_) + , permanent_addr_(that.permanent_addr_) + , flat_data_(std::move(that.flat_data_)) + , page_numbers_(std::move(that.page_numbers_)) + , privatized_regions_(std::move(that.privatized_regions_)) { - region_type_ = that.region_type_; - storage_type_ = that.storage_type_; - object_info_ = that.object_info_; - start_addr_ = that.start_addr_; - size_ = that.size_; - permanent_addr_ = that.permanent_addr_; - flat_data_ = std::move(that.flat_data_); - page_numbers_ = std::move(that.page_numbers_); - privatized_regions_ = std::move(that.privatized_regions_); that.clear(); } RegionSnapshot& operator=(RegionSnapshot&& that) @@ -191,8 +191,8 @@ public: void clear() { - region_type_ = MC_REGION_TYPE_UNKNOWN; - storage_type_ = MC_REGION_STORAGE_TYPE_NONE; + region_type_ = UnknownRegion; + storage_type_ = StorageType::NoData; privatized_regions_.clear(); page_numbers_.clear(); flat_data_.clear(); @@ -204,33 +204,34 @@ public: void clear_data() { - storage_type_ = MC_REGION_STORAGE_TYPE_NONE; + storage_type_ = StorageType::NoData; flat_data_.clear(); page_numbers_.clear(); privatized_regions_.clear(); } - - void flat_data(std::vector data) + + void flat_data(Buffer data) { - storage_type_ = MC_REGION_STORAGE_TYPE_FLAT; + storage_type_ = StorageType::Flat; flat_data_ = std::move(data); page_numbers_.clear(); privatized_regions_.clear(); } - std::vector const& flat_data() const { return flat_data_; } + const Buffer& flat_data() const { return flat_data_; } + Buffer& flat_data() { return flat_data_; } - void page_data(PerPageCopy page_data) + void page_data(ChunkedData page_data) { - storage_type_ = MC_REGION_STORAGE_TYPE_CHUNKED; + storage_type_ = StorageType::Chunked; flat_data_.clear(); 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 data) { - storage_type_ = MC_REGION_STORAGE_TYPE_PRIVATIZED; + storage_type_ = StorageType::Privatized; flat_data_.clear(); page_numbers_.clear(); privatized_regions_ = std::move(data); @@ -244,36 +245,37 @@ public: return privatized_regions_; } - mc_object_info_t object_info() const { return object_info_; } - void object_info(mc_object_info_t info) { object_info_ = info; } + simgrid::mc::ObjectInformation* object_info() const { return object_info_; } + void object_info(simgrid::mc::ObjectInformation* info) { object_info_ = info; } // Other getters - remote_ptr start() const { return remote(start_addr_); } - remote_ptr end() const { return remote((char*)start_addr_ + size_); } - remote_ptr permanent_address() const { return remote(permanent_addr_); } + RemotePtr start() const { return remote(start_addr_); } + RemotePtr end() const { return remote((char*)start_addr_ + size_); } + RemotePtr permanent_address() const { return remote(permanent_addr_); } std::size_t size() const { return size_; } - mc_region_storage_type_t storage_type() const { return storage_type_; } - mc_region_type_t region_type() const { return region_type_; } + StorageType storage_type() const { return storage_type_; } + RegionType region_type() const { return region_type_; } - bool contain(remote_ptr p) const + bool contain(RemotePtr p) const { return p >= start() && p < end(); } }; -simgrid::mc::RegionSnapshot privatized_region( - mc_region_type_t type, void *start_addr, void* data_addr, size_t size); -simgrid::mc::RegionSnapshot dense_region( - mc_region_type_t type, void *start_addr, void* data_addr, size_t size); +RegionSnapshot privatized_region( + RegionType region_type, void *start_addr, void* permanent_addr, + std::size_t size); +RegionSnapshot dense_region( + RegionType type, void *start_addr, void* data_addr, std::size_t size); simgrid::mc::RegionSnapshot sparse_region( - mc_region_type_t type, void *start_addr, void* data_addr, size_t size); + RegionType type, void *start_addr, void* data_addr, std::size_t size); simgrid::mc::RegionSnapshot region( - mc_region_type_t type, void *start_addr, void* data_addr, size_t size); - + RegionType type, void *start_addr, void* data_addr, std::size_t size); + } } -typedef class simgrid::mc::RegionSnapshot s_mc_mem_region_t, *mc_mem_region_t; - +typedef class simgrid::mc::RegionSnapshot s_mc_mem_region_t; +typedef s_mc_mem_region_t* mc_mem_region_t; #endif