Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[surf] Remove sg_cabinet_cb
[simgrid.git] / src / mc / ChunkedData.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
8 #include "src/mc/ChunkedData.hpp"
9
10 #define SOFT_DIRTY_BIT_NUMBER 55
11 #define SOFT_DIRTY (((uint64_t)1) << SOFT_DIRTY_BIT_NUMBER)
12
13 namespace simgrid {
14 namespace mc {
15
16 /** Take a per-page snapshot of a region
17  *
18  *  @param data            The start of the region (must be at the beginning of a page)
19  *  @param pag_count       Number of pages of the region
20  *  @return                Snapshot page numbers of this new snapshot
21  */
22 ChunkedData::ChunkedData(PageStore& store, AddressSpace& as,
23     remote_ptr<void> addr, std::size_t page_count,
24     const std::size_t* ref_page_numbers, const std::uint64_t* pagemap)
25 {
26   store_ = &store;
27   this->pagenos_.resize(page_count);
28   std::vector<char> buffer(xbt_pagesize);
29
30   for (size_t i = 0; i != page_count; ++i) {
31
32     // We don't have to compare soft-clean pages:
33     if (ref_page_numbers && pagemap && !(pagemap[i] & SOFT_DIRTY)) {
34       pagenos_[i] = ref_page_numbers[i];
35       store_->ref_page(ref_page_numbers[i]);
36       continue;
37     }
38
39       remote_ptr<void> page = remote(addr.address() + (i << xbt_pagebits));
40       xbt_assert(mc_page_offset((void*)page.address())==0,
41         "Not at the beginning of a page");
42
43         /* Adding another copy (and a syscall) will probably slow things a lot.
44            TODO, optimize this somehow (at least by grouping the syscalls)
45            if needed. Either:
46             - reduce the number of syscalls;
47             - let the application snapshot itself;
48             - move the segments in shared memory (this will break `fork` however).
49         */
50
51         as.read_bytes(
52           buffer.data(), xbt_pagesize, page,
53           simgrid::mc::ProcessIndexDisabled);
54
55       pagenos_[i] = store_->store_page(buffer.data());
56
57   }
58 }
59
60 }
61 }