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, where identical pages are stored only once */
21 class RegionSnapshot {
23 static const RegionType UnknownRegion = RegionType::Unknown;
24 static const RegionType HeapRegion = RegionType::Heap;
25 static const RegionType DataRegion = RegionType::Data;
28 RegionType region_type_ = UnknownRegion;
29 simgrid::mc::ObjectInformation* object_info_ = nullptr;
31 /** @brief Virtual address of the region in the simulated process */
32 void* start_addr_ = nullptr;
34 /** @brief Size of the data region in bytes */
35 std::size_t size_ = 0;
37 /** @brief Permanent virtual address of the region
39 * This is usually the same address as the simuilated process address.
40 * However, when using SMPI privatization of global variables,
41 * each SMPI process has its own set of global variables stored
42 * at a different virtual address. The scheduler maps those region
43 * on the region of the global variables.
46 void* permanent_addr_ = nullptr;
48 ChunkedData page_numbers_;
51 RegionSnapshot(RegionType type, void* start_addr, void* permanent_addr, size_t size);
52 ~RegionSnapshot() = default;
53 RegionSnapshot(RegionSnapshot const&) = delete;
54 RegionSnapshot& operator=(RegionSnapshot const&) = delete;
55 RegionSnapshot(RegionSnapshot&& that)
56 : region_type_(that.region_type_)
57 , object_info_(that.object_info_)
58 , start_addr_(that.start_addr_)
60 , permanent_addr_(that.permanent_addr_)
61 , page_numbers_(std::move(that.page_numbers_))
65 RegionSnapshot& operator=(RegionSnapshot&& that)
67 region_type_ = that.region_type_;
68 object_info_ = that.object_info_;
69 start_addr_ = that.start_addr_;
71 permanent_addr_ = that.permanent_addr_;
72 page_numbers_ = std::move(that.page_numbers_);
81 region_type_ = UnknownRegion;
82 page_numbers_.clear();
83 object_info_ = nullptr;
84 start_addr_ = nullptr;
86 permanent_addr_ = nullptr;
91 page_numbers_.clear();
94 ChunkedData const& page_data() const { return page_numbers_; }
96 simgrid::mc::ObjectInformation* object_info() const { return object_info_; }
97 void object_info(simgrid::mc::ObjectInformation* info) { object_info_ = info; }
101 RemotePtr<void> start() const { return remote(start_addr_); }
102 RemotePtr<void> end() const { return remote((char*)start_addr_ + size_); }
103 RemotePtr<void> permanent_address() const { return remote(permanent_addr_); }
104 std::size_t size() const { return size_; }
105 RegionType region_type() const { return region_type_; }
107 bool contain(RemotePtr<void> p) const { return p >= start() && p < end(); }
109 /** @brief Restore a region from a snapshot */
114 } // namespace simgrid