X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/12a5e400dc33bddd5a5799d5481f51cfa3c58b01..d2b42c9c0b31834a48bc489d05e4f9499b81bb72:/src/mc/sosp/mc_snapshot.cpp diff --git a/src/mc/sosp/mc_snapshot.cpp b/src/mc/sosp/mc_snapshot.cpp index 6ba9b6af24..757c46a3b5 100644 --- a/src/mc/sosp/mc_snapshot.cpp +++ b/src/mc/sosp/mc_snapshot.cpp @@ -38,7 +38,7 @@ const void* MC_region_read_fragmented(simgrid::mc::RegionSnapshot* region, void* // Read each page: while (simgrid::mc::mmu::split((std::uintptr_t)addr).first != page_end) { - void* snapshot_addr = mc_translate_address_region_chunked((uintptr_t)addr, region); + void* snapshot_addr = mc_translate_address_region((uintptr_t)addr, region); void* next_page = (void*)simgrid::mc::mmu::join(simgrid::mc::mmu::split((std::uintptr_t)addr).first + 1, 0); size_t readable = (char*)next_page - (char*)addr; memcpy(dest, snapshot_addr, readable); @@ -48,7 +48,7 @@ const void* MC_region_read_fragmented(simgrid::mc::RegionSnapshot* region, void* } // Read the end: - void* snapshot_addr = mc_translate_address_region_chunked((uintptr_t)addr, region); + void* snapshot_addr = mc_translate_address_region((uintptr_t)addr, region); memcpy(dest, snapshot_addr, size); return target; @@ -68,12 +68,8 @@ int MC_snapshot_region_memcmp(const void* addr1, simgrid::mc::RegionSnapshot* re // Using alloca() for large allocations may trigger stack overflow: // use malloc if the buffer is too big. bool stack_alloc = size < 64; - void* buffer1a = nullptr; - void* buffer2a = nullptr; - if (region1 != nullptr && region1->storage_type() != simgrid::mc::StorageType::Flat) - buffer1a = stack_alloc ? alloca(size) : ::operator new(size); - if (region2 != nullptr && region2->storage_type() != simgrid::mc::StorageType::Flat) - buffer2a = stack_alloc ? alloca(size) : ::operator new(size); + void* buffer1a = stack_alloc ? alloca(size) : ::operator new(size); + void* buffer2a = stack_alloc ? alloca(size) : ::operator new(size); const void* buffer1 = MC_region_read(region1, buffer1a, addr1, size); const void* buffer2 = MC_region_read(region2, buffer2a, addr2, size); int res; @@ -93,30 +89,22 @@ namespace mc { /************************************* Take Snapshot ************************************/ /****************************************************************************************/ -static void get_memory_regions(simgrid::mc::RemoteClient* process, simgrid::mc::Snapshot* snapshot) +void simgrid::mc::Snapshot::snapshot_regions(simgrid::mc::RemoteClient* process) { - snapshot->snapshot_regions_.clear(); + snapshot_regions_.clear(); for (auto const& object_info : process->object_infos) - snapshot->add_region(simgrid::mc::RegionType::Data, object_info.get(), object_info->start_rw, object_info->start_rw, - object_info->end_rw - object_info->start_rw); + add_region(simgrid::mc::RegionType::Data, object_info.get(), object_info->start_rw, object_info->start_rw, + object_info->end_rw - object_info->start_rw); xbt_mheap_t heap = process->get_heap(); void* start_heap = heap->base; void* end_heap = heap->breakval; - snapshot->add_region(simgrid::mc::RegionType::Heap, nullptr, start_heap, start_heap, - (char*)end_heap - (char*)start_heap); - snapshot->heap_bytes_used_ = mmalloc_get_bytes_used_remote(heap->heaplimit, process->get_malloc_info()); - snapshot->privatization_index_ = simgrid::mc::ProcessIndexMissing; - -#if HAVE_SMPI - if (mc_model_checker->process().privatized() && MC_smpi_process_count()) - // snapshot->privatization_index = smpi_loaded_page - mc_model_checker->process().read_variable("smpi_loaded_page", &snapshot->privatization_index_, - sizeof(snapshot->privatization_index_)); -#endif + add_region(simgrid::mc::RegionType::Heap, nullptr, start_heap, start_heap, (char*)end_heap - (char*)start_heap); + heap_bytes_used_ = mmalloc_get_bytes_used_remote(heap->heaplimit, process->get_malloc_info()); } + /** @brief Checks whether the variable is in scope for a given IP. * * A variable may be defined only from a given value of IP. @@ -135,7 +123,7 @@ static bool valid_variable(simgrid::mc::Variable* var, simgrid::mc::Frame* scope return true; } -static void fill_local_variables_values(mc_stack_frame_t stack_frame, simgrid::mc::Frame* scope, int process_index, +static void fill_local_variables_values(mc_stack_frame_t stack_frame, simgrid::mc::Frame* scope, std::vector& result) { if (not scope || not scope->range.contain(stack_frame->ip)) @@ -158,7 +146,7 @@ static void fill_local_variables_values(mc_stack_frame_t stack_frame, simgrid::m else if (not current_variable.location_list.empty()) { simgrid::dwarf::Location location = simgrid::dwarf::resolve( current_variable.location_list, current_variable.object_info, &(stack_frame->unw_cursor), - (void*)stack_frame->frame_base, &mc_model_checker->process(), process_index); + (void*)stack_frame->frame_base, &mc_model_checker->process()); if (not location.in_memory()) xbt_die("Cannot handle non-address variable"); @@ -172,15 +160,14 @@ static void fill_local_variables_values(mc_stack_frame_t stack_frame, simgrid::m // Recursive processing of nested scopes: for (simgrid::mc::Frame& nested_scope : scope->scopes) - fill_local_variables_values(stack_frame, &nested_scope, process_index, result); + fill_local_variables_values(stack_frame, &nested_scope, result); } -static std::vector get_local_variables_values(std::vector& stack_frames, - int process_index) +static std::vector get_local_variables_values(std::vector& stack_frames) { std::vector variables; for (s_mc_stack_frame_t& stack_frame : stack_frames) - fill_local_variables_values(&stack_frame, stack_frame.frame, process_index, variables); + fill_local_variables_values(&stack_frame, stack_frame.frame, variables); return variables; } @@ -239,9 +226,9 @@ static std::vector unwind_stack_frames(simgrid::mc::UnwindCo return result; } -static void take_snapshot_stacks(simgrid::mc::Snapshot* snapshot) +void simgrid::mc::Snapshot::snapshot_stacks(simgrid::mc::RemoteClient* process) { - for (auto const& stack : mc_model_checker->process().stack_areas()) { + for (auto const& stack : process->stack_areas()) { s_mc_snapshot_stack_t st; // Read the context from remote process: @@ -251,15 +238,14 @@ static void take_snapshot_stacks(simgrid::mc::Snapshot* snapshot) st.context.initialize(&mc_model_checker->process(), &context); st.stack_frames = unwind_stack_frames(&st.context); - st.local_variables = get_local_variables_values(st.stack_frames, stack.process_index); - st.process_index = stack.process_index; + st.local_variables = get_local_variables_values(st.stack_frames); unw_word_t sp = st.stack_frames[0].sp; - snapshot->stacks_.push_back(std::move(st)); + stacks_.push_back(std::move(st)); size_t stack_size = (char*)stack.address + stack.size - (char*)sp; - snapshot->stack_sizes_.push_back(stack_size); + stack_sizes_.push_back(stack_size); } } @@ -273,8 +259,7 @@ static void snapshot_handle_ignore(simgrid::mc::Snapshot* snapshot) ignored_data.start = (void*)region.addr; ignored_data.data.resize(region.size); // TODO, we should do this once per privatization segment: - snapshot->process()->read_bytes(ignored_data.data.data(), region.size, remote(region.addr), - simgrid::mc::ProcessIndexDisabled); + snapshot->process()->read_bytes(ignored_data.data.data(), region.size, remote(region.addr)); snapshot->ignored_data_.push_back(std::move(ignored_data)); } @@ -293,21 +278,20 @@ Snapshot::Snapshot(int _num_state, RemoteClient* process) , num_state_(_num_state) , heap_bytes_used_(0) , enabled_processes_() - , privatization_index_(0) , hash_(0) { - for (auto const& p : mc_model_checker->process().actors()) - enabled_processes_.insert(p.copy.getBuffer()->get_pid()); + for (auto const& p : process->actors()) + enabled_processes_.insert(p.copy.get_buffer()->get_pid()); snapshot_handle_ignore(this); /* Save the std heap and the writable mapped pages of libsimgrid and binary */ - get_memory_regions(process, this); + snapshot_regions(process); - to_ignore_ = mc_model_checker->process().ignored_heap(); + to_ignore_ = process->ignored_heap(); if (_sg_mc_max_visited_states > 0 || not _sg_mc_property_file.get().empty()) { - take_snapshot_stacks(this); + snapshot_stacks(process); if (_sg_mc_hash) hash_ = simgrid::mc::hash(*this); } @@ -323,23 +307,14 @@ void Snapshot::add_region(RegionType type, ObjectInformation* object_info, void* else if (type == simgrid::mc::RegionType::Heap) xbt_assert(not object_info, "Unexpected object info for heap region."); - simgrid::mc::RegionSnapshot* region; -#if HAVE_SMPI - const bool privatization_aware = object_info && mc_model_checker->process().privatized(*object_info); - if (privatization_aware && MC_smpi_process_count()) - region = new RegionPrivatized(type, start_addr, permanent_addr, size); - else -#endif - region = simgrid::mc::region(type, start_addr, permanent_addr, size); - + simgrid::mc::RegionSnapshot* region = simgrid::mc::region(type, start_addr, permanent_addr, size); region->object_info(object_info); snapshot_regions_.push_back(std::unique_ptr(std::move(region))); } -const void* Snapshot::read_bytes(void* buffer, std::size_t size, RemotePtr address, int process_index, - ReadOptions options) const +const void* Snapshot::read_bytes(void* buffer, std::size_t size, RemotePtr address, ReadOptions options) const { - RegionSnapshot* region = this->get_region((void*)address.address(), process_index); + RegionSnapshot* region = this->get_region((void*)address.address()); if (region) { const void* res = MC_region_read(region, buffer, (void*)address.address(), size); if (buffer == res || options & ReadOptions::lazy()) @@ -349,14 +324,13 @@ const void* Snapshot::read_bytes(void* buffer, std::size_t size, RemotePtr return buffer; } } else - return this->process()->read_bytes(buffer, size, address, process_index, options); + return this->process()->read_bytes(buffer, size, address, options); } /** @brief Find the snapshoted region from a pointer * * @param addr Pointer - * @param process_index rank requesting the region * */ -RegionSnapshot* Snapshot::get_region(const void* addr, int process_index) const +RegionSnapshot* Snapshot::get_region(const void* addr) const { size_t n = snapshot_regions_.size(); for (size_t i = 0; i != n; ++i) { @@ -364,22 +338,6 @@ RegionSnapshot* Snapshot::get_region(const void* addr, int process_index) const if (not(region && region->contain(simgrid::mc::remote(addr)))) continue; - if (region->storage_type() == simgrid::mc::StorageType::Privatized) { -#if HAVE_SMPI - // Use the current process index of the snapshot: - if (process_index == simgrid::mc::ProcessIndexDisabled) - process_index = privatization_index_; - xbt_assert(process_index >= 0, "Missing process index"); - xbt_assert(process_index < (int)region->privatized_data().size(), "Invalid process index"); - - RegionSnapshot* priv_region = region->privatized_data()[process_index].get(); - xbt_assert(priv_region->contain(simgrid::mc::remote(addr))); - return priv_region; -#else - xbt_die("Privatized region in a non SMPI build (this should not happen)"); -#endif - } - return region; } @@ -387,37 +345,26 @@ RegionSnapshot* Snapshot::get_region(const void* addr, int process_index) const } /** @brief Find the snapshoted region from a pointer, with a hinted_region */ -RegionSnapshot* Snapshot::get_region(const void* addr, int process_index, RegionSnapshot* hinted_region) const +RegionSnapshot* Snapshot::get_region(const void* addr, RegionSnapshot* hinted_region) const { if (hinted_region->contain(simgrid::mc::remote(addr))) return hinted_region; else - return get_region(addr, process_index); + return get_region(addr); } -static inline void restore_snapshot_regions(simgrid::mc::Snapshot* snapshot) +void Snapshot::restore(RemoteClient* process) { - for (std::unique_ptr const& region : snapshot->snapshot_regions_) { - // For privatized, variables we decided it was not necessary to take the snapshot: - if (region) - region.get()->restore(); - } + XBT_DEBUG("Restore snapshot %i", num_state_); -#if HAVE_SMPI - if (snapshot->privatization_index_ >= 0) { - // Fix the privatization mmap: - s_mc_message_restore_t message{MC_MESSAGE_RESTORE, snapshot->privatization_index_}; - mc_model_checker->process().getChannel().send(message); + // Restore regions + for (std::unique_ptr const& region : snapshot_regions_) { + if (region) // privatized variables are not snapshoted + region.get()->restore(); } -#endif -} -void restore_snapshot(std::shared_ptr snapshot) -{ - XBT_DEBUG("Restore snapshot %i", snapshot->num_state_); - restore_snapshot_regions(snapshot.get()); - snapshot_ignore_restore(snapshot.get()); - mc_model_checker->process().clear_cache(); + snapshot_ignore_restore(this); + process->clear_cache(); } } // namespace mc