1 /* Copyright (c) 2007-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "mc_snapshot.h"
9 #include "RegionSnapshot.hpp"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_RegionSnaphot, mc,
14 "Logging specific to region snapshots");
22 const char* to_cstr(RegionType region)
25 case RegionType::Unknown:
27 case RegionType::Heap:
29 case RegionType::Data:
36 RegionSnapshot dense_region(
37 RegionType region_type,
38 void *start_addr, void* permanent_addr, size_t size)
40 std::vector<char> data(size);
41 mc_model_checker->process().read_bytes(data.data(), size,
42 remote(permanent_addr),
43 simgrid::mc::ProcessIndexDisabled);
45 simgrid::mc::RegionSnapshot region(
46 region_type, start_addr, permanent_addr, size);
47 region.flat_data(std::move(data));
49 XBT_DEBUG("New region : type : %s, data : %p (real addr %p), size : %zu",
50 to_cstr(region_type), region.flat_data().data(), permanent_addr, size);
51 return std::move(region);
54 /** @brief Take a snapshot of a given region
57 * @param start_addr Address of the region in the simulated process
58 * @param permanent_addr Permanent address of this data (for privatized variables, this is the virtual address of the privatized mapping)
59 * @param size Size of the data*
61 RegionSnapshot region(
62 RegionType type, void *start_addr, void* permanent_addr, size_t size)
64 if (_sg_mc_sparse_checkpoint) {
65 return sparse_region(type, start_addr, permanent_addr, size);
67 return dense_region(type, start_addr, permanent_addr, size);
71 RegionSnapshot sparse_region(RegionType region_type,
72 void *start_addr, void* permanent_addr, size_t size)
74 simgrid::mc::Process* process = &mc_model_checker->process();
76 xbt_assert((((uintptr_t)start_addr) & (xbt_pagesize-1)) == 0,
77 "Not at the beginning of a page");
78 xbt_assert((((uintptr_t)permanent_addr) & (xbt_pagesize-1)) == 0,
79 "Not at the beginning of a page");
80 size_t page_count = mc_page_count(size);
82 simgrid::mc::PerPageCopy page_data(mc_model_checker->page_store(), *process,
83 permanent_addr, page_count);
85 simgrid::mc::RegionSnapshot region(
86 region_type, start_addr, permanent_addr, size);
87 region.page_data(std::move(page_data));
88 return std::move(region);