Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move libsosp into its own directory
[simgrid.git] / src / mc / sosp / ChunkedData.cpp
1 /* Copyright (c) 2007-2018. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include <cstddef>
7 #include <cstdint>
8
9 #include <vector>
10
11 #include "xbt/asserts.h"
12 #include "xbt/misc.h"
13
14 #include "src/mc/AddressSpace.hpp"
15 #include "src/mc/sosp/ChunkedData.hpp"
16 #include "src/mc/sosp/PageStore.hpp"
17
18 namespace simgrid {
19 namespace mc {
20
21 /** Take a per-page snapshot of a region
22  *
23  *  @param addr            The start of the region (must be at the beginning of a page)
24  *  @param page_count      Number of pages of the region
25  *  @return                Snapshot page numbers of this new snapshot
26  */
27 ChunkedData::ChunkedData(PageStore& store, AddressSpace& as, RemotePtr<void> addr, std::size_t page_count)
28 {
29   store_ = &store;
30   this->pagenos_.resize(page_count);
31   std::vector<char> buffer(xbt_pagesize);
32
33   for (size_t i = 0; i != page_count; ++i) {
34
35     RemotePtr<void> page = remote((void*)simgrid::mc::mmu::join(i, addr.address()));
36     xbt_assert(simgrid::mc::mmu::split(page.address()).second == 0, "Not at the beginning of a page");
37
38     /* Adding another copy (and a syscall) will probably slow things a lot.
39        TODO, optimize this somehow (at least by grouping the syscalls)
40        if needed. Either:
41        - reduce the number of syscalls
42        - let the application snapshot itself
43        - move the segments in shared memory (this will break `fork` however)
44     */
45
46     as.read_bytes(buffer.data(), xbt_pagesize, page, simgrid::mc::ProcessIndexDisabled);
47
48     pagenos_[i] = store_->store_page(buffer.data());
49   }
50 }
51
52 } // namespace mc
53 } // namespace simgrid