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. */
10 #define MAP_POPULATE MAP_PREFAULT_READ
14 #include "src/mc/mc_config.hpp"
15 #include "src/mc/sosp/mc_snapshot.hpp"
17 #include "src/mc/mc_smx.hpp"
18 #include "src/mc/sosp/ChunkedData.hpp"
19 #include "src/mc/sosp/RegionSnapshot.hpp"
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_RegionSnaphot, mc, "Logging specific to region snapshots");
26 RegionDense::RegionDense(RegionType region_type, void* start_addr, void* permanent_addr, size_t size)
27 : RegionSnapshot(region_type, start_addr, permanent_addr, size)
29 flat_data_ = Buffer::malloc(size);
31 mc_model_checker->process().read_bytes(flat_data_.get(), size, remote(permanent_addr),
32 simgrid::mc::ProcessIndexDisabled);
34 storage_type_ = StorageType::Flat;
35 page_numbers_.clear();
36 privatized_regions_.clear();
38 XBT_DEBUG("New region : type : %s, data : %p (real addr %p), size : %zu",
39 (region_type == RegionType::Heap ? "Heap" : (region_type == RegionType::Data ? "Data" : "?")),
40 flat_data().get(), permanent_addr, size);
43 /** @brief Take a snapshot of a given region
46 * @param start_addr Address of the region in the simulated process
47 * @param permanent_addr Permanent address of this data (for privatized variables, this is the virtual address of the
49 * @param size Size of the data*
51 RegionSnapshot* region(RegionType type, void* start_addr, void* permanent_addr, size_t size)
53 if (_sg_mc_sparse_checkpoint)
54 return new RegionSparse(type, start_addr, permanent_addr, size);
56 return new RegionDense(type, start_addr, permanent_addr, size);
59 RegionSparse::RegionSparse(RegionType region_type, void* start_addr, void* permanent_addr, size_t size)
60 : RegionSnapshot(region_type, start_addr, permanent_addr, size)
62 simgrid::mc::RemoteClient* process = &mc_model_checker->process();
63 assert(process != nullptr);
65 xbt_assert((((uintptr_t)start_addr) & (xbt_pagesize - 1)) == 0, "Start address not at the beginning of a page");
66 xbt_assert((((uintptr_t)permanent_addr) & (xbt_pagesize - 1)) == 0,
67 "Permanent address not at the beginning of a page");
69 storage_type_ = StorageType::Chunked;
71 privatized_regions_.clear();
74 ChunkedData(mc_model_checker->page_store(), *process, RemotePtr<void>(permanent_addr), mmu::chunk_count(size));
78 RegionPrivatized::RegionPrivatized(RegionType region_type, void* start_addr, void* permanent_addr, std::size_t size)
79 : RegionSnapshot(region_type, start_addr, permanent_addr, size)
81 storage_type_ = StorageType::Privatized;
83 size_t process_count = MC_smpi_process_count();
85 // Read smpi_privatization_regions from MCed:
86 smpi_privatization_region_t remote_smpi_privatization_regions;
87 mc_model_checker->process().read_variable("smpi_privatization_regions", &remote_smpi_privatization_regions,
88 sizeof(remote_smpi_privatization_regions));
89 s_smpi_privatization_region_t privatization_regions[process_count];
90 mc_model_checker->process().read_bytes(&privatization_regions, sizeof(privatization_regions),
91 remote(remote_smpi_privatization_regions));
93 privatized_regions_.reserve(process_count);
94 for (size_t i = 0; i < process_count; i++)
95 privatized_regions_.push_back(std::unique_ptr<simgrid::mc::RegionSnapshot>(
96 region(region_type, start_addr, privatization_regions[i].address, size)));
99 page_numbers_.clear();
104 } // namespace simgrid