Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MC: remove support for flat storage of regions
[simgrid.git] / src / mc / sosp / RegionSnapshot.hpp
1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_MC_REGION_SNAPSHOT_HPP
7 #define SIMGRID_MC_REGION_SNAPSHOT_HPP
8
9 #include "src/mc/remote/RemotePtr.hpp"
10 #include "src/mc/sosp/ChunkedData.hpp"
11
12 #include <memory>
13 #include <vector>
14
15 namespace simgrid {
16 namespace mc {
17
18 enum class RegionType { Unknown = 0, Heap = 1, Data = 2 };
19
20 /** A copy/snapshot of a given memory region
21  *
22  *  Different types of region snapshot storage types exist:
23  *
24  *  * flat/dense snapshots are a simple copy of the region;
25  *
26  *  * sparse/per-page snapshots are snaapshots which shared
27  *    identical pages.
28  *
29  *  * privatized (SMPI global variable privatization).
30  *
31  *  This is handled with a variant based approach:
32  *
33  *  * `storage_type` identified the type of storage;
34  *
35  *  * an anonymous enum is used to distinguish the relevant types for
36  *    each type.
37  */
38 class RegionSnapshot {
39 public:
40   static const RegionType UnknownRegion = RegionType::Unknown;
41   static const RegionType HeapRegion    = RegionType::Heap;
42   static const RegionType DataRegion    = RegionType::Data;
43
44 protected:
45   RegionType region_type_                      = UnknownRegion;
46   simgrid::mc::ObjectInformation* object_info_ = nullptr;
47
48   /** @brief  Virtual address of the region in the simulated process */
49   void* start_addr_ = nullptr;
50
51   /** @brief Size of the data region in bytes */
52   std::size_t size_ = 0;
53
54   /** @brief Permanent virtual address of the region
55    *
56    * This is usually the same address as the simuilated process address.
57    * However, when using SMPI privatization of global variables,
58    * each SMPI process has its own set of global variables stored
59    * at a different virtual address. The scheduler maps those region
60    * on the region of the global variables.
61    *
62    * */
63   void* permanent_addr_ = nullptr;
64
65   ChunkedData page_numbers_;
66
67 public:
68   RegionSnapshot() {}
69   RegionSnapshot(RegionType type, void* start_addr, void* permanent_addr, size_t size)
70       : region_type_(type)
71       , start_addr_(start_addr)
72       , size_(size)
73       , permanent_addr_(permanent_addr)
74   {
75   }
76   ~RegionSnapshot()                     = default;
77   RegionSnapshot(RegionSnapshot const&) = delete;
78   RegionSnapshot& operator=(RegionSnapshot const&) = delete;
79   RegionSnapshot(RegionSnapshot&& that)
80       : region_type_(that.region_type_)
81       , object_info_(that.object_info_)
82       , start_addr_(that.start_addr_)
83       , size_(that.size_)
84       , permanent_addr_(that.permanent_addr_)
85       , page_numbers_(std::move(that.page_numbers_))
86   {
87     that.clear();
88   }
89   RegionSnapshot& operator=(RegionSnapshot&& that)
90   {
91     region_type_        = that.region_type_;
92     object_info_        = that.object_info_;
93     start_addr_         = that.start_addr_;
94     size_               = that.size_;
95     permanent_addr_     = that.permanent_addr_;
96     page_numbers_       = std::move(that.page_numbers_);
97     that.clear();
98     return *this;
99   }
100
101   // Data
102
103   void clear()
104   {
105     region_type_  = UnknownRegion;
106     page_numbers_.clear();
107     object_info_    = nullptr;
108     start_addr_     = nullptr;
109     size_           = 0;
110     permanent_addr_ = nullptr;
111   }
112
113   void clear_data()
114   {
115     page_numbers_.clear();
116   }
117
118   ChunkedData const& page_data() const { return page_numbers_; }
119
120   simgrid::mc::ObjectInformation* object_info() const { return object_info_; }
121   void object_info(simgrid::mc::ObjectInformation* info) { object_info_ = info; }
122
123   // Other getters
124
125   RemotePtr<void> start() const { return remote(start_addr_); }
126   RemotePtr<void> end() const { return remote((char*)start_addr_ + size_); }
127   RemotePtr<void> permanent_address() const { return remote(permanent_addr_); }
128   std::size_t size() const { return size_; }
129   RegionType region_type() const { return region_type_; }
130
131   bool contain(RemotePtr<void> p) const { return p >= start() && p < end(); }
132
133   /** @brief Restore a region from a snapshot */
134   void restore();
135 };
136
137 class RegionSparse : public RegionSnapshot {
138 public:
139   RegionSparse(RegionType type, void* start_addr, void* data_addr, std::size_t size);
140 };
141
142 RegionSnapshot* region(RegionType type, void* start_addr, void* data_addr, std::size_t size);
143
144 } // namespace mc
145 } // namespace simgrid
146
147 #endif