Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill the support for privatized SMPI in MC mode
[simgrid.git] / src / mc / sosp / RegionSnapshot.cpp
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 #include <cstdlib>
7
8 #include <sys/mman.h>
9 #ifdef __FreeBSD__
10 #define MAP_POPULATE MAP_PREFAULT_READ
11 #endif
12
13 #include "src/mc/ModelChecker.hpp"
14 #include "src/mc/mc_config.hpp"
15 #include "src/mc/mc_forward.hpp"
16
17 #include "src/mc/mc_smx.hpp"
18 #include "src/mc/sosp/RegionSnapshot.hpp"
19
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_RegionSnaphot, mc, "Logging specific to region snapshots");
21
22 namespace simgrid {
23 namespace mc {
24
25 RegionDense::RegionDense(RegionType region_type, void* start_addr, void* permanent_addr, size_t size)
26     : RegionSnapshot(region_type, start_addr, permanent_addr, size)
27 {
28   flat_data_ = Buffer::malloc(size);
29
30   mc_model_checker->process().read_bytes(flat_data_.get(), size, remote(permanent_addr),
31                                          simgrid::mc::ProcessIndexDisabled);
32
33   storage_type_ = StorageType::Flat;
34   page_numbers_.clear();
35
36   XBT_DEBUG("New region : type : %s, data : %p (real addr %p), size : %zu",
37             (region_type == RegionType::Heap ? "Heap" : (region_type == RegionType::Data ? "Data" : "?")),
38             flat_data().get(), permanent_addr, size);
39 }
40
41 /** @brief Take a snapshot of a given region
42  *
43  * @param type
44  * @param start_addr   Address of the region in the simulated process
45  * @param permanent_addr Permanent address of this data (for privatized variables, this is the virtual address of the
46  * privatized mapping)
47  * @param size         Size of the data*
48  */
49 RegionSnapshot* region(RegionType type, void* start_addr, void* permanent_addr, size_t size)
50 {
51   if (_sg_mc_sparse_checkpoint)
52     return new RegionSparse(type, start_addr, permanent_addr, size);
53   else
54     return new RegionDense(type, start_addr, permanent_addr, size);
55 }
56
57 RegionSparse::RegionSparse(RegionType region_type, void* start_addr, void* permanent_addr, size_t size)
58     : RegionSnapshot(region_type, start_addr, permanent_addr, size)
59 {
60   simgrid::mc::RemoteClient* process = &mc_model_checker->process();
61   assert(process != nullptr);
62
63   xbt_assert((((uintptr_t)start_addr) & (xbt_pagesize - 1)) == 0, "Start address not at the beginning of a page");
64   xbt_assert((((uintptr_t)permanent_addr) & (xbt_pagesize - 1)) == 0,
65              "Permanent address not at the beginning of a page");
66
67   storage_type_ = StorageType::Chunked;
68   flat_data_.clear();
69
70   page_numbers_ =
71       ChunkedData(mc_model_checker->page_store(), *process, RemotePtr<void>(permanent_addr), mmu::chunk_count(size));
72 }
73
74 /** @brief Restore a region from a snapshot
75  *
76  *  @param region     Target region
77  */
78 void RegionSnapshot::restore()
79 {
80   switch (storage_type()) {
81     case simgrid::mc::StorageType::Flat:
82       mc_model_checker->process().write_bytes(flat_data().get(), size(), permanent_address());
83       break;
84
85     case simgrid::mc::StorageType::Chunked:
86       xbt_assert(((permanent_address().address()) & (xbt_pagesize - 1)) == 0, "Not at the beginning of a page");
87       xbt_assert(simgrid::mc::mmu::chunk_count(size()) == page_data().page_count());
88
89       for (size_t i = 0; i != page_data().page_count(); ++i) {
90         void* target_page = (void*)simgrid::mc::mmu::join(i, (std::uintptr_t)(void*)permanent_address().address());
91         const void* source_page = page_data().page(i);
92         mc_model_checker->process().write_bytes(source_page, xbt_pagesize, remote(target_page));
93       }
94
95       break;
96
97     default: // includes StorageType::NoData
98       xbt_die("Storage type not supported");
99       break;
100   }
101 }
102
103 } // namespace mc
104 } // namespace simgrid