Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Give ctor/dtor for s_dw_type
[simgrid.git] / src / mc / RegionSnapshot.cpp
1 /* Copyright (c) 2007-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "mc/mc.h"
8 #include "mc_snapshot.h"
9 #include "RegionSnapshot.hpp"
10
11 extern "C" {
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_RegionSnaphot, mc,
14                                 "Logging specific to region snapshots");
15
16 }
17
18 namespace simgrid {
19 namespace mc {
20
21 RegionSnapshot dense_region(
22   RegionType region_type,
23   void *start_addr, void* permanent_addr, size_t size)
24 {
25   std::vector<char> data(size);
26   mc_model_checker->process().read_bytes(data.data(), size,
27     remote(permanent_addr),
28     simgrid::mc::ProcessIndexDisabled);
29
30   simgrid::mc::RegionSnapshot region(
31     region_type, start_addr, permanent_addr, size);
32   region.flat_data(std::move(data));
33
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);
37 }
38
39 /** @brief Take a snapshot of a given region
40  *
41  * @param type
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*
45  */
46 RegionSnapshot region(
47   RegionType type, void *start_addr, void* permanent_addr, size_t size)
48 {
49   if (_sg_mc_sparse_checkpoint) {
50     return sparse_region(type, start_addr, permanent_addr, size);
51   } else  {
52     return dense_region(type, start_addr, permanent_addr, size);
53   }
54 }
55
56 RegionSnapshot sparse_region(RegionType region_type,
57   void *start_addr, void* permanent_addr, size_t size)
58 {
59   mc_process_t process = &mc_model_checker->process();
60
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);
66
67   simgrid::mc::PerPageCopy page_data(mc_model_checker->page_store(), *process,
68       permanent_addr, page_count);
69
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);
74 }
75   
76 }
77 }