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");
21 RegionSnapshot dense_region(
22 RegionType region_type,
23 void *start_addr, void* permanent_addr, size_t size)
25 std::vector<char> data(size);
26 mc_model_checker->process().read_bytes(data.data(), size,
27 remote(permanent_addr),
28 simgrid::mc::ProcessIndexDisabled);
30 simgrid::mc::RegionSnapshot region(
31 region_type, start_addr, permanent_addr, size);
32 region.flat_data(std::move(data));
34 XBT_DEBUG("New region : type : %d, data : %p (real addr %p), size : %zu",
35 region_type, region.flat_data().data(), permanent_addr, size);
36 return std::move(region);
39 /** @brief Take a snapshot of a given region
42 * @param start_addr Address of the region in the simulated process
43 * @param permanent_addr Permanent address of this data (for privatized variables, this is the virtual address of the privatized mapping)
44 * @param size Size of the data*
46 RegionSnapshot region(
47 RegionType type, void *start_addr, void* permanent_addr, size_t size)
49 if (_sg_mc_sparse_checkpoint) {
50 return sparse_region(type, start_addr, permanent_addr, size);
52 return dense_region(type, start_addr, permanent_addr, size);
56 RegionSnapshot sparse_region(RegionType region_type,
57 void *start_addr, void* permanent_addr, size_t size)
59 simgrid::mc::Process* process = &mc_model_checker->process();
61 xbt_assert((((uintptr_t)start_addr) & (xbt_pagesize-1)) == 0,
62 "Not at the beginning of a page");
63 xbt_assert((((uintptr_t)permanent_addr) & (xbt_pagesize-1)) == 0,
64 "Not at the beginning of a page");
65 size_t page_count = mc_page_count(size);
67 simgrid::mc::PerPageCopy page_data(mc_model_checker->page_store(), *process,
68 permanent_addr, page_count);
70 simgrid::mc::RegionSnapshot region(
71 region_type, start_addr, permanent_addr, size);
72 region.page_data(std::move(page_data));
73 return std::move(region);