Logo AND Algorithmique Numérique Distribuée

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