Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill the RegionSparse subclass now that there is no alternative
[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 /** @brief Take a snapshot of a given region
26  *
27  * @param type
28  * @param start_addr   Address of the region in the simulated process
29  * @param permanent_addr Permanent address of this data (for privatized variables, this is the virtual address of the
30  * privatized mapping)
31  * @param size         Size of the data*
32  */
33 RegionSnapshot* region(RegionType type, void* start_addr, void* permanent_addr, size_t size)
34 {
35   return new RegionSnapshot(type, start_addr, permanent_addr, size);
36 }
37
38 RegionSnapshot::RegionSnapshot(RegionType region_type, void* start_addr, void* permanent_addr, size_t size)
39     : region_type_(region_type), start_addr_(start_addr), size_(size), permanent_addr_(permanent_addr)
40 {
41   simgrid::mc::RemoteClient* process = &mc_model_checker->process();
42
43   xbt_assert((((uintptr_t)start_addr) & (xbt_pagesize - 1)) == 0, "Start address not at the beginning of a page");
44   xbt_assert((((uintptr_t)permanent_addr) & (xbt_pagesize - 1)) == 0,
45              "Permanent address not at the beginning of a page");
46
47   page_numbers_ =
48       ChunkedData(mc_model_checker->page_store(), *process, RemotePtr<void>(permanent_addr), mmu::chunk_count(size));
49 }
50
51 /** @brief Restore a region from a snapshot
52  *
53  *  @param region     Target region
54  */
55 void RegionSnapshot::restore()
56 {
57       xbt_assert(((permanent_address().address()) & (xbt_pagesize - 1)) == 0, "Not at the beginning of a page");
58       xbt_assert(simgrid::mc::mmu::chunk_count(size()) == page_data().page_count());
59
60       for (size_t i = 0; i != page_data().page_count(); ++i) {
61         void* target_page = (void*)simgrid::mc::mmu::join(i, (std::uintptr_t)(void*)permanent_address().address());
62         const void* source_page = page_data().page(i);
63         mc_model_checker->process().write_bytes(source_page, xbt_pagesize, remote(target_page));
64       }
65 }
66
67 } // namespace mc
68 } // namespace simgrid