Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
please sonar by removing useless asignments and return statements
[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> 
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 namespace simgrid {
20 namespace mc {
21
22 /** Take a per-page snapshot of a region
23  *
24  *  @param data            The start of the region (must be at the beginning of a page)
25  *  @param page_count      Number of pages of the region
26  *  @return                Snapshot page numbers of this new snapshot
27  */
28 ChunkedData::ChunkedData(PageStore& store, AddressSpace& as,
29     RemotePtr<void> addr, std::size_t page_count)
30 {
31   store_ = &store;
32   this->pagenos_.resize(page_count);
33   std::vector<char> buffer(xbt_pagesize);
34
35   for (size_t i = 0; i != page_count; ++i) {
36
37       RemotePtr<void> page = remote((void*)
38         simgrid::mc::mmu::join(i, addr.address()));
39       xbt_assert(simgrid::mc::mmu::split(page.address()).second == 0,
40         "Not at the beginning of a page");
41
42         /* Adding another copy (and a syscall) will probably slow things a lot.
43            TODO, optimize this somehow (at least by grouping the syscalls)
44            if needed. Either:
45             - reduce the number of syscalls;
46             - let the application snapshot itself;
47             - move the segments in shared memory (this will break `fork` however).
48         */
49
50         as.read_bytes(
51           buffer.data(), xbt_pagesize, page,
52           simgrid::mc::ProcessIndexDisabled);
53
54       pagenos_[i] = store_->store_page(buffer.data());
55
56   }
57 }
58
59 }
60 }