X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/8bcc1dbe28f658ea786ba234a679601edd30758a..3549ebd27861c2514a3f697a128fa05b5ca685e2:/src/mc/RegionSnapshot.hpp diff --git a/src/mc/RegionSnapshot.hpp b/src/mc/RegionSnapshot.hpp index e427a299f6..52deff2007 100644 --- a/src/mc/RegionSnapshot.hpp +++ b/src/mc/RegionSnapshot.hpp @@ -1,5 +1,4 @@ -/* 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. */ @@ -10,119 +9,111 @@ #include #include -#include +#include +#include -#include "PageStore.hpp" -#include "AddressSpace.hpp" +#include "xbt/base.h" + +#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); -}; - -enum class RegionType { - Unknown = 0, - Heap = 1, - Data = 2 -}; - -// TODO, use Boost.Variant instead of this -enum class StorageType { - NoData = 0, - Flat = 1, - Chunked = 2, - Privatized = 3 + 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; + * + * * sparse/per-page snapshots are snaapshots which shared + * identical pages. * - * * `storage_type` identified the type of storage; - * * an anonymous enum is used to distinguish the relevant types for - * each type. + * * 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; - static const StorageType NoData = StorageType::NoData; - static const StorageType FlatData = StorageType::Flat; - static const StorageType ChunkedData = StorageType::Chunked; - static const StorageType PrivatizedData = StorageType::Privatized; private: RegionType region_type_; StorageType storage_type_; @@ -132,7 +123,7 @@ private: 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 * @@ -145,13 +136,13 @@ 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_(UnknownRegion), - storage_type_(NoData), + storage_type_(StorageType::NoData), object_info_(nullptr), start_addr_(nullptr), size_(0), @@ -159,26 +150,26 @@ public: {} 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), 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) @@ -201,7 +192,7 @@ public: void clear() { region_type_ = UnknownRegion; - storage_type_ = NoData; + storage_type_ = StorageType::NoData; privatized_regions_.clear(); page_numbers_.clear(); flat_data_.clear(); @@ -213,33 +204,34 @@ public: void clear_data() { - storage_type_ = NoData; + 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_ = FlatData; + 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_ = ChunkedData; + 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_ = PrivatizedData; + storage_type_ = StorageType::Privatized; flat_data_.clear(); page_numbers_.clear(); privatized_regions_ = std::move(data); @@ -258,31 +250,32 @@ public: // 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_; } 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(); } }; RegionSnapshot privatized_region( - RegionType type, void *start_addr, void* data_addr, size_t size); + RegionType region_type, void *start_addr, void* permanent_addr, + std::size_t size); RegionSnapshot dense_region( - RegionType 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 sparse_region( - RegionType 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( - RegionType 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