Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
mc: create RegionSparse, RegionDense and RegionPrivatized (WIP)
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Mon, 20 May 2019 22:58:19 +0000 (00:58 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Wed, 22 May 2019 08:19:54 +0000 (10:19 +0200)
The content is still in the ancestor class, with a switch on the type_
field. This will soon change.

src/mc/sosp/RegionSnapshot.cpp
src/mc/sosp/RegionSnapshot.hpp
src/mc/sosp/mc_checkpoint.cpp
src/mc/sosp/mc_snapshot.cpp
src/mc/sosp/mc_snapshot_test.cpp

index a657ea0..13d6c5b 100644 (file)
@@ -14,6 +14,7 @@
 #include "src/mc/mc_config.hpp"
 #include "src/mc/sosp/mc_snapshot.hpp"
 
+#include "src/mc/mc_smx.hpp"
 #include "src/mc/sosp/ChunkedData.hpp"
 #include "src/mc/sosp/RegionSnapshot.hpp"
 
@@ -22,19 +23,21 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_RegionSnaphot, mc, "Logging specific to regio
 namespace simgrid {
 namespace mc {
 
-RegionSnapshot* dense_region(RegionType region_type, void* start_addr, void* permanent_addr, size_t size)
+RegionDense::RegionDense(RegionType region_type, void* start_addr, void* permanent_addr, size_t size)
+    : RegionSnapshot(region_type, start_addr, permanent_addr, size)
 {
-  simgrid::mc::Buffer data = Buffer::malloc(size);
+  flat_data_ = Buffer::malloc(size);
 
-  mc_model_checker->process().read_bytes(data.get(), size, remote(permanent_addr), simgrid::mc::ProcessIndexDisabled);
+  mc_model_checker->process().read_bytes(flat_data_.get(), size, remote(permanent_addr),
+                                         simgrid::mc::ProcessIndexDisabled);
 
-  simgrid::mc::RegionSnapshot* region = new RegionSnapshot(region_type, start_addr, permanent_addr, size);
-  region->flat_data(std::move(data));
+  storage_type_ = StorageType::Flat;
+  page_numbers_.clear();
+  privatized_regions_.clear();
 
   XBT_DEBUG("New region : type : %s, data : %p (real addr %p), size : %zu",
             (region_type == RegionType::Heap ? "Heap" : (region_type == RegionType::Data ? "Data" : "?")),
-            region->flat_data().get(), permanent_addr, size);
-  return region;
+            flat_data().get(), permanent_addr, size);
 }
 
 /** @brief Take a snapshot of a given region
@@ -48,12 +51,13 @@ RegionSnapshot* dense_region(RegionType region_type, void* start_addr, void* per
 RegionSnapshot* region(RegionType type, void* start_addr, void* permanent_addr, size_t size)
 {
   if (_sg_mc_sparse_checkpoint)
-    return sparse_region(type, start_addr, permanent_addr, size);
+    return new RegionSparse(type, start_addr, permanent_addr, size);
   else
-    return dense_region(type, start_addr, permanent_addr, size);
+    return new RegionDense(type, start_addr, permanent_addr, size);
 }
 
-RegionSnapshot* sparse_region(RegionType region_type, void* start_addr, void* permanent_addr, size_t size)
+RegionSparse::RegionSparse(RegionType region_type, void* start_addr, void* permanent_addr, size_t size)
+    : RegionSnapshot(region_type, start_addr, permanent_addr, size)
 {
   simgrid::mc::RemoteClient* process = &mc_model_checker->process();
   assert(process != nullptr);
@@ -61,15 +65,40 @@ RegionSnapshot* sparse_region(RegionType region_type, void* start_addr, void* pe
   xbt_assert((((uintptr_t)start_addr) & (xbt_pagesize - 1)) == 0, "Start address not at the beginning of a page");
   xbt_assert((((uintptr_t)permanent_addr) & (xbt_pagesize - 1)) == 0,
              "Permanent address not at the beginning of a page");
-  size_t page_count = simgrid::mc::mmu::chunk_count(size);
 
-  simgrid::mc::ChunkedData page_data(mc_model_checker->page_store(), *process, RemotePtr<void>(permanent_addr),
-                                     page_count);
+  storage_type_ = StorageType::Chunked;
+  flat_data_.clear();
+  privatized_regions_.clear();
 
-  simgrid::mc::RegionSnapshot* region = new RegionSnapshot(region_type, start_addr, permanent_addr, size);
-  region->page_data(std::move(page_data));
-  return region;
+  page_numbers_ =
+      ChunkedData(mc_model_checker->page_store(), *process, RemotePtr<void>(permanent_addr), mmu::chunk_count(size));
 }
 
+#if HAVE_SMPI
+RegionPrivatized::RegionPrivatized(RegionType region_type, void* start_addr, void* permanent_addr, std::size_t size)
+    : RegionSnapshot(region_type, start_addr, permanent_addr, size)
+{
+  storage_type_ = StorageType::Privatized;
+
+  size_t process_count = MC_smpi_process_count();
+
+  // Read smpi_privatization_regions from MCed:
+  smpi_privatization_region_t remote_smpi_privatization_regions;
+  mc_model_checker->process().read_variable("smpi_privatization_regions", &remote_smpi_privatization_regions,
+                                            sizeof(remote_smpi_privatization_regions));
+  s_smpi_privatization_region_t privatization_regions[process_count];
+  mc_model_checker->process().read_bytes(&privatization_regions, sizeof(privatization_regions),
+                                         remote(remote_smpi_privatization_regions));
+
+  privatized_regions_.reserve(process_count);
+  for (size_t i = 0; i < process_count; i++)
+    privatized_regions_.push_back(std::unique_ptr<simgrid::mc::RegionSnapshot>(
+        region(region_type, start_addr, privatization_regions[i].address, size)));
+
+  flat_data_.clear();
+  page_numbers_.clear();
+}
+#endif
+
 } // namespace mc
 } // namespace simgrid
index 5869ba6..2284ffa 100644 (file)
@@ -97,7 +97,7 @@ public:
   static const RegionType HeapRegion    = RegionType::Heap;
   static const RegionType DataRegion    = RegionType::Data;
 
-private:
+protected:
   RegionType region_type_                      = UnknownRegion;
   StorageType storage_type_                    = StorageType::NoData;
   simgrid::mc::ObjectInformation* object_info_ = nullptr;
@@ -186,32 +186,11 @@ public:
     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<std::unique_ptr<RegionSnapshot>> data)
-  {
-    storage_type_ = StorageType::Privatized;
-    flat_data_.clear();
-    page_numbers_.clear();
-    privatized_regions_ = std::move(data);
-  }
   std::vector<std::unique_ptr<RegionSnapshot>> const& privatized_data() const { return privatized_regions_; }
   std::vector<std::unique_ptr<RegionSnapshot>>& privatized_data() { return privatized_regions_; }
 
@@ -230,9 +209,19 @@ public:
   bool contain(RemotePtr<void> p) const { return p >= start() && p < end(); }
 };
 
-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);
-RegionSnapshot* sparse_region(RegionType type, void* start_addr, void* data_addr, std::size_t size);
+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);
+};
+class RegionPrivatized : public RegionSnapshot {
+public:
+  RegionPrivatized(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
index 760a0c2..1b1ff78 100644 (file)
@@ -84,31 +84,6 @@ static void restore(RegionSnapshot* region)
   }
 }
 
-#if HAVE_SMPI
-RegionSnapshot* privatized_region(RegionType region_type, void* start_addr, void* permanent_addr, std::size_t size)
-{
-  size_t process_count = MC_smpi_process_count();
-
-  // Read smpi_privatization_regions from MCed:
-  smpi_privatization_region_t remote_smpi_privatization_regions;
-  mc_model_checker->process().read_variable("smpi_privatization_regions", &remote_smpi_privatization_regions,
-                                            sizeof(remote_smpi_privatization_regions));
-  s_smpi_privatization_region_t privatization_regions[process_count];
-  mc_model_checker->process().read_bytes(&privatization_regions, sizeof(privatization_regions),
-                                         remote(remote_smpi_privatization_regions));
-
-  std::vector<std::unique_ptr<RegionSnapshot>> data;
-  data.reserve(process_count);
-  for (size_t i = 0; i < process_count; i++)
-    data.push_back(std::unique_ptr<simgrid::mc::RegionSnapshot>(
-        region(region_type, start_addr, privatization_regions[i].address, size)));
-
-  RegionSnapshot* reg = new RegionSnapshot(region_type, start_addr, permanent_addr, size);
-  reg->privatized_data(std::move(data));
-  return reg;
-}
-#endif
-
 static void get_memory_regions(simgrid::mc::RemoteClient* process, simgrid::mc::Snapshot* snapshot)
 {
   snapshot->snapshot_regions_.clear();
index da489b9..e8d20cf 100644 (file)
@@ -122,7 +122,7 @@ void Snapshot::add_region(RegionType type, ObjectInformation* object_info, void*
 #if HAVE_SMPI
   const bool privatization_aware = object_info && mc_model_checker->process().privatized(*object_info);
   if (privatization_aware && MC_smpi_process_count())
-    region = simgrid::mc::privatized_region(type, start_addr, permanent_addr, size);
+    region = new RegionPrivatized(type, start_addr, permanent_addr, size);
   else
 #endif
     region = simgrid::mc::region(type, start_addr, permanent_addr, size);
index 80a7357..64fb6ed 100644 (file)
@@ -82,12 +82,12 @@ snap_test_helper::prologue_return snap_test_helper::prologue(int n)
   // Init memory and take snapshots:
   init_memory(source, byte_size);
   simgrid::mc::RegionSnapshot* region0 =
-      simgrid::mc::sparse_region(simgrid::mc::RegionType::Unknown, source, source, byte_size);
+      new simgrid::mc::RegionSparse(simgrid::mc::RegionType::Unknown, source, source, byte_size);
   for (int i = 0; i < n; i += 2) {
     init_memory((char*)source + i * xbt_pagesize, xbt_pagesize);
   }
   simgrid::mc::RegionSnapshot* region =
-      simgrid::mc::sparse_region(simgrid::mc::RegionType::Unknown, source, source, byte_size);
+      new simgrid::mc::RegionSparse(simgrid::mc::RegionType::Unknown, source, source, byte_size);
 
   void* destination = mmap(nullptr, byte_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   INFO("Could not allocate destination memory");
@@ -179,7 +179,7 @@ void snap_test_helper::read_pointer()
   prologue_return ret = prologue(1);
   memcpy(ret.src, &mc_model_checker, sizeof(void*));
   simgrid::mc::RegionSnapshot* region2 =
-      simgrid::mc::sparse_region(simgrid::mc::RegionType::Unknown, ret.src, ret.src, ret.size);
+      new simgrid::mc::RegionSparse(simgrid::mc::RegionType::Unknown, ret.src, ret.src, ret.size);
   INFO("Mismtach in MC_region_read_pointer()");
   REQUIRE(MC_region_read_pointer(region2, ret.src) == mc_model_checker);