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
13 #include "src/mc/ModelChecker.hpp"
14 #include "src/mc/mc_config.hpp"
15 #include "src/mc/mc_forward.hpp"
17 #include "src/mc/mc_smx.hpp"
18 #include "src/mc/sosp/RegionSnapshot.hpp"
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_RegionSnaphot, mc, "Logging specific to region snapshots");
25 RegionDense::RegionDense(RegionType region_type, void* start_addr, void* permanent_addr, size_t size)
26 : RegionSnapshot(region_type, start_addr, permanent_addr, size)
28 flat_data_ = Buffer::malloc(size);
30 mc_model_checker->process().read_bytes(flat_data_.get(), size, remote(permanent_addr),
31 simgrid::mc::ProcessIndexDisabled);
33 storage_type_ = StorageType::Flat;
34 page_numbers_.clear();
35 privatized_regions_.clear();
37 XBT_DEBUG("New region : type : %s, data : %p (real addr %p), size : %zu",
38 (region_type == RegionType::Heap ? "Heap" : (region_type == RegionType::Data ? "Data" : "?")),
39 flat_data().get(), permanent_addr, size);
42 /** @brief Take a snapshot of a given region
45 * @param start_addr Address of the region in the simulated process
46 * @param permanent_addr Permanent address of this data (for privatized variables, this is the virtual address of the
48 * @param size Size of the data*
50 RegionSnapshot* region(RegionType type, void* start_addr, void* permanent_addr, size_t size)
52 if (_sg_mc_sparse_checkpoint)
53 return new RegionSparse(type, start_addr, permanent_addr, size);
55 return new RegionDense(type, start_addr, permanent_addr, size);
58 RegionSparse::RegionSparse(RegionType region_type, void* start_addr, void* permanent_addr, size_t size)
59 : RegionSnapshot(region_type, start_addr, permanent_addr, size)
61 simgrid::mc::RemoteClient* process = &mc_model_checker->process();
62 assert(process != nullptr);
64 xbt_assert((((uintptr_t)start_addr) & (xbt_pagesize - 1)) == 0, "Start address not at the beginning of a page");
65 xbt_assert((((uintptr_t)permanent_addr) & (xbt_pagesize - 1)) == 0,
66 "Permanent address not at the beginning of a page");
68 storage_type_ = StorageType::Chunked;
70 privatized_regions_.clear();
73 ChunkedData(mc_model_checker->page_store(), *process, RemotePtr<void>(permanent_addr), mmu::chunk_count(size));
77 RegionPrivatized::RegionPrivatized(RegionType region_type, void* start_addr, void* permanent_addr, std::size_t size)
78 : RegionSnapshot(region_type, start_addr, permanent_addr, size)
80 storage_type_ = StorageType::Privatized;
82 size_t process_count = MC_smpi_process_count();
84 // Read smpi_privatization_regions from MCed:
85 smpi_privatization_region_t remote_smpi_privatization_regions;
86 mc_model_checker->process().read_variable("smpi_privatization_regions", &remote_smpi_privatization_regions,
87 sizeof(remote_smpi_privatization_regions));
88 s_smpi_privatization_region_t privatization_regions[process_count];
89 mc_model_checker->process().read_bytes(&privatization_regions, sizeof(privatization_regions),
90 remote(remote_smpi_privatization_regions));
92 privatized_regions_.reserve(process_count);
93 for (size_t i = 0; i < process_count; i++)
94 privatized_regions_.push_back(std::unique_ptr<simgrid::mc::RegionSnapshot>(
95 region(region_type, start_addr, privatization_regions[i].address, size)));
98 page_numbers_.clear();
103 } // namespace simgrid