Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
mc: Also remove the process_index
[simgrid.git] / src / mc / sosp / RegionSnapshot.hpp
index 4e051c4..a6735e7 100644 (file)
@@ -6,64 +6,58 @@
 #ifndef SIMGRID_MC_REGION_SNAPSHOT_HPP
 #define SIMGRID_MC_REGION_SNAPSHOT_HPP
 
-#include <cstddef>
-#include <utility>
+#include "src/mc/remote/RemotePtr.hpp"
+#include "src/mc/sosp/ChunkedData.hpp"
 
 #include <memory>
 #include <vector>
 
-#include "xbt/base.h"
-
-#include "src/mc/AddressSpace.hpp"
-#include "src/mc/remote/RemotePtr.hpp"
-#include "src/mc/sosp/ChunkedData.hpp"
-#include "src/mc/sosp/PageStore.hpp"
-
 namespace simgrid {
 namespace mc {
 
 enum class RegionType { Unknown = 0, Heap = 1, Data = 2 };
 
-enum class StorageType { NoData = 0, Flat = 1, Chunked = 2, Privatized = 3 };
+enum class StorageType { NoData = 0, Flat = 1, Chunked = 2 };
 
 class Buffer {
 private:
-  enum class Type { Malloc, Mmap };
   void* data_ = nullptr;
   std::size_t size_;
-  Type type_ = Type::Malloc;
 
-  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) {}
+  explicit Buffer(std::size_t size) : size_(size) { data_ = ::operator new(size_); }
+
+  Buffer(void* data, std::size_t size) : data_(data), size_(size) {}
 
 public:
   Buffer() = default;
-  void clear() noexcept;
+  void clear() noexcept
+  {
+    ::operator delete(data_);
+    data_ = nullptr;
+    size_ = 0;
+  }
+
   ~Buffer() noexcept { clear(); }
 
-  static Buffer malloc(std::size_t size) { return Buffer(size, Type::Malloc); }
-  static Buffer mmap(std::size_t size) { return Buffer(size, Type::Mmap); }
+  static Buffer malloc(std::size_t size) { return Buffer(size); }
 
   // No copy
   Buffer(Buffer const& buffer) = delete;
   Buffer& operator=(Buffer const& buffer) = delete;
 
   // Move
-  Buffer(Buffer&& that) noexcept : data_(that.data_), size_(that.size_), type_(that.type_)
+  Buffer(Buffer&& that) noexcept : data_(that.data_), size_(that.size_)
   {
     that.data_ = nullptr;
     that.size_ = 0;
-    that.type_ = Type::Malloc;
   }
   Buffer& operator=(Buffer&& that) noexcept
   {
     clear();
     data_      = that.data_;
     size_      = that.size_;
-    type_      = that.type_;
     that.data_ = nullptr;
     that.size_ = 0;
-    that.type_ = Type::Malloc;
     return *this;
   }
 
@@ -96,16 +90,16 @@ public:
   static const RegionType HeapRegion    = RegionType::Heap;
   static const RegionType DataRegion    = RegionType::Data;
 
-private:
-  RegionType region_type_;
-  StorageType storage_type_;
-  simgrid::mc::ObjectInformation* object_info_;
+protected:
+  RegionType region_type_                      = UnknownRegion;
+  StorageType storage_type_                    = StorageType::NoData;
+  simgrid::mc::ObjectInformation* object_info_ = nullptr;
 
   /** @brief  Virtual address of the region in the simulated process */
-  void* start_addr_;
+  void* start_addr_ = nullptr;
 
   /** @brief Size of the data region in bytes */
-  std::size_t size_;
+  std::size_t size_ = 0;
 
   /** @brief Permanent virtual address of the region
    *
@@ -116,26 +110,15 @@ private:
    * on the region of the global variables.
    *
    * */
-  void* permanent_addr_;
+  void* permanent_addr_ = nullptr;
 
   Buffer flat_data_;
   ChunkedData page_numbers_;
-  std::vector<RegionSnapshot> privatized_regions_;
 
 public:
-  RegionSnapshot()
-      : region_type_(UnknownRegion)
-      , storage_type_(StorageType::NoData)
-      , object_info_(nullptr)
-      , start_addr_(nullptr)
-      , size_(0)
-      , permanent_addr_(nullptr)
-  {
-  }
+  RegionSnapshot() {}
   RegionSnapshot(RegionType type, void* start_addr, void* permanent_addr, size_t size)
       : region_type_(type)
-      , storage_type_(StorageType::NoData)
-      , object_info_(nullptr)
       , start_addr_(start_addr)
       , size_(size)
       , permanent_addr_(permanent_addr)
@@ -153,7 +136,6 @@ public:
       , 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();
   }
@@ -167,7 +149,6 @@ public:
     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();
     return *this;
   }
@@ -178,7 +159,6 @@ public:
   {
     region_type_  = UnknownRegion;
     storage_type_ = StorageType::NoData;
-    privatized_regions_.clear();
     page_numbers_.clear();
     flat_data_.clear();
     object_info_    = nullptr;
@@ -192,38 +172,13 @@ public:
     storage_type_ = StorageType::NoData;
     flat_data_.clear();
     page_numbers_.clear();
-    privatized_regions_.clear();
   }
 
-  void flat_data(Buffer data)
-  {
-    storage_type_ = StorageType::Flat;
-    flat_data_    = std::move(data);
-    page_numbers_.clear();
-    privatized_regions_.clear();
-  }
   const Buffer& flat_data() const { return flat_data_; }
   Buffer& flat_data() { return flat_data_; }
 
-  void page_data(ChunkedData page_data)
-  {
-    storage_type_ = StorageType::Chunked;
-    flat_data_.clear();
-    page_numbers_ = std::move(page_data);
-    privatized_regions_.clear();
-  }
   ChunkedData const& page_data() const { return page_numbers_; }
 
-  void privatized_data(std::vector<RegionSnapshot> data)
-  {
-    storage_type_ = StorageType::Privatized;
-    flat_data_.clear();
-    page_numbers_.clear();
-    privatized_regions_ = std::move(data);
-  }
-  std::vector<RegionSnapshot> const& privatized_data() const { return privatized_regions_; }
-  std::vector<RegionSnapshot>& privatized_data() { return privatized_regions_; }
-
   simgrid::mc::ObjectInformation* object_info() const { return object_info_; }
   void object_info(simgrid::mc::ObjectInformation* info) { object_info_ = info; }
 
@@ -237,16 +192,23 @@ public:
   RegionType region_type() const { return region_type_; }
 
   bool contain(RemotePtr<void> p) const { return p >= start() && p < end(); }
+
+  /** @brief Restore a region from a snapshot */
+  void restore();
+};
+
+class RegionDense : public RegionSnapshot {
+public:
+  RegionDense(RegionType type, void* start_addr, void* data_addr, std::size_t size);
+};
+class RegionSparse : public RegionSnapshot {
+public:
+  RegionSparse(RegionType type, void* start_addr, void* data_addr, std::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(RegionType type, void* start_addr, void* data_addr, std::size_t size);
-simgrid::mc::RegionSnapshot region(RegionType type, void* start_addr, void* data_addr, std::size_t size);
+RegionSnapshot* region(RegionType type, void* start_addr, void* data_addr, std::size_t size);
 
 } // namespace mc
 } // namespace simgrid
 
-typedef simgrid::mc::RegionSnapshot s_mc_mem_region_t;
-typedef s_mc_mem_region_t* mc_mem_region_t;
 #endif