Logo AND Algorithmique Numérique Distribuée

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