From: Gabriel Corona Date: Mon, 4 Apr 2016 13:32:20 +0000 (+0200) Subject: [mc] Move the stack as field of SafetyChecker and CommDetChecker X-Git-Tag: v3_13~187^2~8 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/2376a01092173679830310f4d57b267445959f97 [mc] Move the stack as field of SafetyChecker and CommDetChecker --- diff --git a/src/mc/CommunicationDeterminismChecker.cpp b/src/mc/CommunicationDeterminismChecker.cpp index fc90234a01..ae4e36c11e 100644 --- a/src/mc/CommunicationDeterminismChecker.cpp +++ b/src/mc/CommunicationDeterminismChecker.cpp @@ -28,8 +28,6 @@ using simgrid::mc::remote; XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_comm_determinism, mc, "Logging specific to MC communication determinism detection"); -XBT_PRIVATE static std::list mc_stack; - /********** Global variables **********/ xbt_dynar_t initial_communications_pattern; @@ -317,7 +315,7 @@ CommunicationDeterminismChecker::~CommunicationDeterminismChecker() RecordTrace CommunicationDeterminismChecker::getRecordTrace() // override { RecordTrace res; - for (simgrid::mc::State* state : mc_stack) { + for (simgrid::mc::State* state : stack_) { int value = 0; smx_simcall_t saved_req = MC_state_get_executed_request(state, &value); const smx_process_t issuer = MC_smx_simcall_get_issuer(saved_req); @@ -331,7 +329,7 @@ RecordTrace CommunicationDeterminismChecker::getRecordTrace() // override std::vector CommunicationDeterminismChecker::getTextualTrace() // override { std::vector trace; - for (simgrid::mc::State* state : mc_stack) { + for (simgrid::mc::State* state : stack_) { int value; smx_simcall_t req = MC_state_get_executed_request(state, &value); if (req) { @@ -380,7 +378,7 @@ void CommunicationDeterminismChecker::prepare() if (simgrid::mc::process_is_enabled(&p.copy)) MC_state_interleave_process(initial_state, &p.copy); - mc_stack.push_back(initial_state); + stack_.push_back(initial_state); } static inline @@ -406,20 +404,20 @@ int CommunicationDeterminismChecker::main(void) smx_simcall_t req = nullptr; simgrid::mc::State* next_state = nullptr; - while (!mc_stack.empty()) { + while (!stack_.empty()) { /* Get current state */ - simgrid::mc::State* state = mc_stack.back(); + simgrid::mc::State* state = stack_.back(); XBT_DEBUG("**************************************************"); XBT_DEBUG("Exploration depth = %zi (state = %d, interleaved processes = %d)", - mc_stack.size(), state->num, + stack_.size(), state->num, MC_state_interleave_size(state)); /* Update statistics */ mc_stats->visited_states++; - if (mc_stack.size() <= _sg_mc_max_depth + if (stack_.size() <= _sg_mc_max_depth && (req = MC_state_get_request(state, &value)) && (visited_state == nullptr)) { @@ -473,29 +471,29 @@ int CommunicationDeterminismChecker::main(void) fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", state->num, visited_state->other_num == -1 ? visited_state->num : visited_state->other_num, req_str); - mc_stack.push_back(next_state); + stack_.push_back(next_state); if (dot_output != nullptr) xbt_free(req_str); } else { - if (mc_stack.size() > _sg_mc_max_depth) + if (stack_.size() > _sg_mc_max_depth) XBT_WARN("/!\\ Max depth reached ! /!\\ "); else if (visited_state != nullptr) XBT_DEBUG("State already visited (equal to state %d), exploration stopped on this path.", visited_state->other_num == -1 ? visited_state->num : visited_state->other_num); else XBT_DEBUG("There are no more processes to interleave. (depth %zi)", - mc_stack.size()); + stack_.size()); if (!initial_global_state->initial_communications_pattern_done) initial_global_state->initial_communications_pattern_done = 1; /* Trash the current state, no longer needed */ - mc_stack.pop_back(); + stack_.pop_back(); MC_state_delete(state, !state->in_visited_states ? 1 : 0); XBT_DEBUG("Delete state %d at depth %zi", - state->num, mc_stack.size() + 1); + state->num, stack_.size() + 1); visited_state = nullptr; @@ -505,25 +503,25 @@ int CommunicationDeterminismChecker::main(void) return SIMGRID_MC_EXIT_DEADLOCK; } - while (!mc_stack.empty()) { - simgrid::mc::State* state = mc_stack.back(); - mc_stack.pop_back(); + while (!stack_.empty()) { + simgrid::mc::State* state = stack_.back(); + stack_.pop_back(); if (MC_state_interleave_size(state) - && mc_stack.size() < _sg_mc_max_depth) { + && stack_.size() < _sg_mc_max_depth) { /* We found a back-tracking point, let's loop */ XBT_DEBUG("Back-tracking to state %d at depth %zi", - state->num, mc_stack.size() + 1); - mc_stack.push_back(state); + state->num, stack_.size() + 1); + stack_.push_back(state); - simgrid::mc::replay(mc_stack); + simgrid::mc::replay(stack_); XBT_DEBUG("Back-tracking to state %d at depth %zi done", - state->num, mc_stack.size()); + state->num, stack_.size()); break; } else { XBT_DEBUG("Delete state %d at depth %zi", - state->num, mc_stack.size() + 1); + state->num, stack_.size() + 1); MC_state_delete(state, !state->in_visited_states ? 1 : 0); } } @@ -543,9 +541,6 @@ int CommunicationDeterminismChecker::run() // This will move somehwere else: simgrid::mc::Client::get()->handleMessages(); - /* Create exploration stack */ - mc_stack.clear(); - this->prepare(); initial_global_state = std::unique_ptr(new s_mc_global_t()); diff --git a/src/mc/CommunicationDeterminismChecker.hpp b/src/mc/CommunicationDeterminismChecker.hpp index e04657c56e..5fe0011d5e 100644 --- a/src/mc/CommunicationDeterminismChecker.hpp +++ b/src/mc/CommunicationDeterminismChecker.hpp @@ -4,6 +4,8 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include + #include "src/mc/mc_forward.hpp" #include "src/mc/Checker.hpp" @@ -23,6 +25,9 @@ public: private: void prepare(); int main(); +private: + /** Stack representing the position in the exploration graph */ + std::list stack_; }; #endif diff --git a/src/mc/SafetyChecker.cpp b/src/mc/SafetyChecker.cpp index 182ff28964..98596c26fc 100644 --- a/src/mc/SafetyChecker.cpp +++ b/src/mc/SafetyChecker.cpp @@ -30,14 +30,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_safety, mc, "Logging specific to MC safety verification "); - -/** Stack (of `simgrid::mc::State*`) representing the current position of the - * the MC in the exploration graph - * - * It is managed by its head (`xbt_fifo_shift` and `xbt_fifo_unshift`). - */ -XBT_PRIVATE static std::list mc_stack; - namespace simgrid { namespace mc { @@ -61,20 +53,21 @@ static int snapshot_compare(simgrid::mc::State* state1, simgrid::mc::State* stat return snapshot_compare(num1, s1, num2, s2); } -static int is_exploration_stack_state(simgrid::mc::State* current_state) +bool SafetyChecker::is_exploration_stack_state(simgrid::mc::State* current_state) { - for (auto i = mc_stack.rbegin(); i != mc_stack.rend(); ++i) + for (auto i = stack_.rbegin(); i != stack_.rend(); ++i) if(snapshot_compare(*i, current_state) == 0){ - XBT_INFO("Non-progressive cycle : state %d -> state %d", (*i)->num, current_state->num); - return 1; + XBT_INFO("Non-progressive cycle : state %d -> state %d", + (*i)->num, current_state->num); + return true; } - return 0; + return false; } RecordTrace SafetyChecker::getRecordTrace() // override { RecordTrace res; - for (simgrid::mc::State* state : mc_stack) { + for (simgrid::mc::State* state : stack_) { int value = 0; smx_simcall_t saved_req = MC_state_get_executed_request(state, &value); const smx_process_t issuer = MC_smx_simcall_get_issuer(saved_req); @@ -87,7 +80,7 @@ RecordTrace SafetyChecker::getRecordTrace() // override std::vector SafetyChecker::getTextualTrace() // override { std::vector trace; - for (simgrid::mc::State* state : mc_stack) { + for (simgrid::mc::State* state : stack_) { int value; smx_simcall_t req = MC_state_get_executed_request(state, &value); if (req) { @@ -112,23 +105,23 @@ int SafetyChecker::run() xbt_fifo_item_t item = nullptr; std::unique_ptr visited_state = nullptr; - while (!mc_stack.empty()) { + while (!stack_.empty()) { /* Get current state */ - simgrid::mc::State* state = mc_stack.back(); + simgrid::mc::State* state = stack_.back(); XBT_DEBUG("**************************************************"); - XBT_DEBUG - ("Exploration depth=%zi (state=%p, num %d)(%u interleave, user_max_depth %d)", - mc_stack.size(), state, state->num, - MC_state_interleave_size(state), user_max_depth_reached); + XBT_DEBUG( + "Exploration depth=%zi (state=%p, num %d)(%u interleave, user_max_depth %d)", + stack_.size(), state, state->num, + MC_state_interleave_size(state), user_max_depth_reached); /* Update statistics */ mc_stats->visited_states++; /* If there are processes to interleave and the maximum depth has not been reached then perform one step of the exploration algorithm */ - if (mc_stack.size() <= _sg_mc_max_depth && !user_max_depth_reached + if (stack_.size() <= _sg_mc_max_depth && !user_max_depth_reached && (req = MC_state_get_request(state, &value)) && visited_state == nullptr) { req_str = simgrid::mc::request_to_string(req, value, simgrid::mc::RequestType::simix); @@ -151,7 +144,7 @@ int SafetyChecker::run() /* Create the new expanded state */ next_state = MC_state_new(); - if(_sg_mc_termination && is_exploration_stack_state(next_state)){ + if(_sg_mc_termination && this->is_exploration_stack_state(next_state)){ MC_show_non_termination(); return SIMGRID_MC_EXIT_NON_TERMINATION; } @@ -172,7 +165,7 @@ int SafetyChecker::run() } else if (dot_output != nullptr) std::fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", state->num, visited_state->other_num == -1 ? visited_state->num : visited_state->other_num, req_str); - mc_stack.push_back(next_state); + stack_.push_back(next_state); if (dot_output != nullptr) xbt_free(req_str); @@ -182,8 +175,7 @@ int SafetyChecker::run() /* The interleave set is empty or the maximum depth is reached, let's back-track */ } else { - if (mc_stack.size() > _sg_mc_max_depth - || user_max_depth_reached + if (stack_.size() > _sg_mc_max_depth || user_max_depth_reached || visited_state != nullptr) { if (user_max_depth_reached && visited_state == nullptr) @@ -195,12 +187,11 @@ int SafetyChecker::run() } else XBT_DEBUG("There are no more processes to interleave. (depth %zi)", - mc_stack.size() + 1); + stack_.size() + 1); /* Trash the current state, no longer needed */ - mc_stack.pop_back(); - XBT_DEBUG("Delete state %d at depth %zi", - state->num, mc_stack.size() + 1); + stack_.pop_back(); + XBT_DEBUG("Delete state %d at depth %zi", state->num, stack_.size() + 1); MC_state_delete(state, !state->in_visited_states ? 1 : 0); visited_state = nullptr; @@ -218,16 +209,16 @@ int SafetyChecker::run() executed before it. If it does then add it to the interleave set of the state that executed that previous request. */ - while (!mc_stack.empty()) { - state = mc_stack.back(); - mc_stack.pop_back(); + while (!stack_.empty()) { + state = stack_.back(); + stack_.pop_back(); if (reductionMode_ == simgrid::mc::ReductionMode::dpor) { req = MC_state_get_internal_request(state); if (req->call == SIMCALL_MUTEX_LOCK || req->call == SIMCALL_MUTEX_TRYLOCK) xbt_die("Mutex is currently not supported with DPOR, " "use --cfg=model-check/reduction:none"); const smx_process_t issuer = MC_smx_simcall_get_issuer(req); - for (auto i = mc_stack.rbegin(); i != mc_stack.rend(); ++i) { + for (auto i = stack_.rbegin(); i != stack_.rend(); ++i) { simgrid::mc::State* prev_state = *i; if (reductionMode_ != simgrid::mc::ReductionMode::none && simgrid::mc::request_depend(req, MC_state_get_internal_request(prev_state))) { @@ -269,18 +260,18 @@ int SafetyChecker::run() } if (MC_state_interleave_size(state) - && mc_stack.size() < _sg_mc_max_depth) { + && stack_.size() < _sg_mc_max_depth) { /* We found a back-tracking point, let's loop */ XBT_DEBUG("Back-tracking to state %d at depth %zi", - state->num, mc_stack.size() + 1); - mc_stack.push_back(state); - simgrid::mc::replay(mc_stack); + state->num, stack_.size() + 1); + stack_.push_back(state); + simgrid::mc::replay(stack_); XBT_DEBUG("Back-tracking to state %d at depth %zi done", - state->num, mc_stack.size()); + state->num, stack_.size()); break; } else { XBT_DEBUG("Delete state %d at depth %zi", - state->num, mc_stack.size() + 1); + state->num, stack_.size() + 1); MC_state_delete(state, !state->in_visited_states ? 1 : 0); } } @@ -309,9 +300,6 @@ void SafetyChecker::init() XBT_DEBUG("Starting the safety algorithm"); - /* Create exploration stack */ - mc_stack.clear(); - simgrid::mc::visited_states.clear(); simgrid::mc::State* initial_state = MC_state_new(); @@ -330,7 +318,7 @@ void SafetyChecker::init() break; } - mc_stack.push_back(initial_state); + stack_.push_back(initial_state); /* Save the initial state */ initial_global_state = std::unique_ptr(new s_mc_global_t()); diff --git a/src/mc/SafetyChecker.hpp b/src/mc/SafetyChecker.hpp index 48edb7b23e..b2aa1387cc 100644 --- a/src/mc/SafetyChecker.hpp +++ b/src/mc/SafetyChecker.hpp @@ -7,6 +7,8 @@ #ifndef SIMGRID_MC_SAFETY_CHECKER_HPP #define SIMGRID_MC_SAFETY_CHECKER_HPP +#include + #include "src/mc/mc_forward.hpp" #include "src/mc/Checker.hpp" @@ -24,6 +26,10 @@ public: private: // Temp void init(); + bool is_exploration_stack_state(simgrid::mc::State* current_state); +private: + /** Stack representing the position in the exploration graph */ + std::list stack_; }; }