Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
mc: inline two functions
[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 "mc/mc.h"
14 #include "src/mc/mc_config.hpp"
15 #include "src/mc/sosp/mc_snapshot.hpp"
16
17 #include "src/mc/sosp/ChunkedData.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 RegionSnapshot dense_region(RegionType region_type, void* start_addr, void* permanent_addr, size_t size)
26 {
27   simgrid::mc::Buffer data = Buffer::malloc(size);
28
29   mc_model_checker->process().read_bytes(data.get(), size, remote(permanent_addr), simgrid::mc::ProcessIndexDisabled);
30
31   simgrid::mc::RegionSnapshot region(region_type, start_addr, permanent_addr, size);
32   region.flat_data(std::move(data));
33
34   XBT_DEBUG("New region : type : %s, data : %p (real addr %p), size : %zu",
35             (region_type == RegionType::Heap ? "Heap" : (region_type == RegionType::Data ? "Data" : "?")),
36             region.flat_data().get(), permanent_addr, size);
37   return region;
38 }
39
40 /** @brief Take a snapshot of a given region
41  *
42  * @param type
43  * @param start_addr   Address of the region in the simulated process
44  * @param permanent_addr Permanent address of this data (for privatized variables, this is the virtual address of the
45  * privatized mapping)
46  * @param size         Size of the data*
47  */
48 RegionSnapshot region(RegionType type, void* start_addr, void* permanent_addr, size_t size)
49 {
50   if (_sg_mc_sparse_checkpoint)
51     return sparse_region(type, start_addr, permanent_addr, size);
52   else
53     return dense_region(type, start_addr, permanent_addr, size);
54 }
55
56 RegionSnapshot sparse_region(RegionType region_type, void* start_addr, void* permanent_addr, size_t size)
57 {
58   simgrid::mc::RemoteClient* process = &mc_model_checker->process();
59   assert(process != nullptr);
60
61   xbt_assert((((uintptr_t)start_addr) & (xbt_pagesize - 1)) == 0, "Start address not at the beginning of a page");
62   xbt_assert((((uintptr_t)permanent_addr) & (xbt_pagesize - 1)) == 0,
63              "Permanent address not at the beginning of a page");
64   size_t page_count = simgrid::mc::mmu::chunkCount(size);
65
66   simgrid::mc::ChunkedData page_data(mc_model_checker->page_store(), *process, RemotePtr<void>(permanent_addr),
67                                      page_count);
68
69   simgrid::mc::RegionSnapshot region(region_type, start_addr, permanent_addr, size);
70   region.page_data(std::move(page_data));
71   return region;
72 }
73
74 } // namespace mc
75 } // namespace simgrid