1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SIMGRID_MC_REGION_SNAPSHOT_HPP
7 #define SIMGRID_MC_REGION_SNAPSHOT_HPP
9 #include "src/mc/remote/RemotePtr.hpp"
10 #include "src/mc/sosp/ChunkedData.hpp"
18 enum class RegionType { Unknown = 0, Heap = 1, Data = 2 };
20 /** A copy/snapshot of a given memory region
22 * Different types of region snapshot storage types exist:
24 * * flat/dense snapshots are a simple copy of the region;
26 * * sparse/per-page snapshots are snaapshots which shared
29 * * privatized (SMPI global variable privatization).
31 * This is handled with a variant based approach:
33 * * `storage_type` identified the type of storage;
35 * * an anonymous enum is used to distinguish the relevant types for
38 class RegionSnapshot {
40 static const RegionType UnknownRegion = RegionType::Unknown;
41 static const RegionType HeapRegion = RegionType::Heap;
42 static const RegionType DataRegion = RegionType::Data;
45 RegionType region_type_ = UnknownRegion;
46 simgrid::mc::ObjectInformation* object_info_ = nullptr;
48 /** @brief Virtual address of the region in the simulated process */
49 void* start_addr_ = nullptr;
51 /** @brief Size of the data region in bytes */
52 std::size_t size_ = 0;
54 /** @brief Permanent virtual address of the region
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.
63 void* permanent_addr_ = nullptr;
65 ChunkedData page_numbers_;
69 RegionSnapshot(RegionType type, void* start_addr, void* permanent_addr, size_t size)
71 , start_addr_(start_addr)
73 , permanent_addr_(permanent_addr)
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_)
84 , permanent_addr_(that.permanent_addr_)
85 , page_numbers_(std::move(that.page_numbers_))
89 RegionSnapshot& operator=(RegionSnapshot&& that)
91 region_type_ = that.region_type_;
92 object_info_ = that.object_info_;
93 start_addr_ = that.start_addr_;
95 permanent_addr_ = that.permanent_addr_;
96 page_numbers_ = std::move(that.page_numbers_);
105 region_type_ = UnknownRegion;
106 page_numbers_.clear();
107 object_info_ = nullptr;
108 start_addr_ = nullptr;
110 permanent_addr_ = nullptr;
115 page_numbers_.clear();
118 ChunkedData const& page_data() const { return page_numbers_; }
120 simgrid::mc::ObjectInformation* object_info() const { return object_info_; }
121 void object_info(simgrid::mc::ObjectInformation* info) { object_info_ = info; }
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_; }
131 bool contain(RemotePtr<void> p) const { return p >= start() && p < end(); }
133 /** @brief Restore a region from a snapshot */
137 class RegionSparse : public RegionSnapshot {
139 RegionSparse(RegionType type, void* start_addr, void* data_addr, std::size_t size);
142 RegionSnapshot* region(RegionType type, void* start_addr, void* data_addr, std::size_t size);
145 } // namespace simgrid