Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge remote-tracking branch 'origin2/master'
[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 static inline
22 const char* to_cstr(RegionType region)
23 {
24   switch (region) {
25   case RegionType::Unknown:
26     return "unknown";
27   case RegionType::Heap:
28     return "Heap";
29   case RegionType::Data:
30     return "Data";
31   default:
32     return "?";
33   }
34 }
35
36 RegionSnapshot dense_region(
37   RegionType region_type,
38   void *start_addr, void* permanent_addr, size_t size)
39 {
40   std::vector<char> data(size);
41   mc_model_checker->process().read_bytes(data.data(), size,
42     remote(permanent_addr),
43     simgrid::mc::ProcessIndexDisabled);
44
45   simgrid::mc::RegionSnapshot region(
46     region_type, start_addr, permanent_addr, size);
47   region.flat_data(std::move(data));
48
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);
52 }
53
54 /** @brief Take a snapshot of a given region
55  *
56  * @param type
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*
60  */
61 RegionSnapshot region(
62   RegionType type, void *start_addr, void* permanent_addr, size_t size)
63 {
64   if (_sg_mc_sparse_checkpoint) {
65     return sparse_region(type, start_addr, permanent_addr, size);
66   } else  {
67     return dense_region(type, start_addr, permanent_addr, size);
68   }
69 }
70
71 RegionSnapshot sparse_region(RegionType region_type,
72   void *start_addr, void* permanent_addr, size_t size)
73 {
74   simgrid::mc::Process* process = &mc_model_checker->process();
75
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);
81
82   simgrid::mc::PerPageCopy page_data(mc_model_checker->page_store(), *process,
83       permanent_addr, page_count);
84
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);
89 }
90   
91 }
92 }