X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ab0bf820128e74dc5e7d9e6413b88bca2621a34e..873fe7743b2a9f2eddc53ed3383bdd74bb3fe226:/src/mc/mc_comm_determinism.cpp diff --git a/src/mc/mc_comm_determinism.cpp b/src/mc/mc_comm_determinism.cpp index 1be100a433..7e7d2b1814 100644 --- a/src/mc/mc_comm_determinism.cpp +++ b/src/mc/mc_comm_determinism.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -18,16 +19,16 @@ #include "src/mc/mc_private.h" #include "src/mc/mc_record.h" #include "src/mc/mc_smx.h" -#include "src/mc/mc_client.h" +#include "src/mc/Client.hpp" #include "src/mc/mc_exit.h" using simgrid::mc::remote; -extern "C" { - XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_comm_determinism, mc, "Logging specific to MC communication determinism detection"); +extern "C" { + /********** Global variables **********/ xbt_dynar_t initial_communications_pattern; @@ -54,9 +55,8 @@ static e_mc_comm_pattern_difference_t compare_comm_pattern(mc_comm_pattern_t com if (!memcmp(comm1->data, comm2->data, comm1->data_size)) return NONE_DIFF; return DATA_DIFF; - }else{ + } else return DATA_DIFF; - } return NONE_DIFF; } @@ -249,9 +249,8 @@ void MC_get_comm_pattern(xbt_dynar_t list, smx_simcall_t request, e_mc_call_type pattern->rdv = mc_model_checker->process().read_string(remote_name); pattern->dst_proc = MC_smx_resolve_process(synchro.comm.dst_proc)->pid; pattern->dst_host = MC_smx_process_get_host_name(issuer); - } else { + } else xbt_die("Unexpected call_type %i", (int) call_type); - } xbt_dynar_push( xbt_dynar_get_as(incomplete_communications_pattern, issuer->pid, xbt_dynar_t), @@ -267,7 +266,7 @@ void MC_complete_comm_pattern(xbt_dynar_t list, smx_synchro_t comm_addr, unsigne int completed = 0; /* Complete comm pattern */ - xbt_dynar_foreach(xbt_dynar_get_as(incomplete_communications_pattern, issuer, xbt_dynar_t), cursor, current_comm_pattern) { + xbt_dynar_foreach(xbt_dynar_get_as(incomplete_communications_pattern, issuer, xbt_dynar_t), cursor, current_comm_pattern) if (current_comm_pattern->comm_addr == comm_addr) { update_comm_pattern(current_comm_pattern, comm_addr); completed = 1; @@ -277,17 +276,17 @@ void MC_complete_comm_pattern(xbt_dynar_t list, smx_synchro_t comm_addr, unsigne XBT_DEBUG("Remove incomplete comm pattern for process %u at cursor %u", issuer, cursor); break; } - } + if(!completed) xbt_die("Corresponding communication not found!"); mc_list_comm_pattern_t pattern = xbt_dynar_get_as( initial_communications_pattern, issuer, mc_list_comm_pattern_t); - if (!initial_global_state->initial_communications_pattern_done) { + if (!initial_global_state->initial_communications_pattern_done) /* Store comm pattern */ xbt_dynar_push(pattern->list, &comm_pattern); - } else { + else { /* Evaluate comm determinism */ deterministic_comm_pattern(issuer, comm_pattern, backtracking); pattern->index_comm++; @@ -302,12 +301,10 @@ static int MC_modelcheck_comm_determinism_main(void); static void MC_pre_modelcheck_comm_determinism(void) { mc_state_t initial_state = nullptr; - smx_process_t process; int i; const int maxpid = MC_smx_get_maxpid(); - if (_sg_mc_visited > 0) - visited_states = xbt_dynar_new(sizeof(mc_visited_state_t), visited_state_free_voidp); + simgrid::mc::visited_states.clear(); // Create initial_communications_pattern elements: initial_communications_pattern = xbt_dynar_new(sizeof(mc_list_comm_pattern_t), MC_list_comm_pattern_free_voidp); @@ -333,11 +330,9 @@ static void MC_pre_modelcheck_comm_determinism(void) mc_model_checker->wait_for_requests(); /* Get an enabled process and insert it in the interleave set of the initial state */ - MC_EACH_SIMIX_PROCESS(process, - if (MC_process_is_enabled(process)) { - MC_state_interleave_process(initial_state, process); - } - ); + for (auto& p : mc_model_checker->process().simix_processes()) + if (simgrid::mc::process_is_enabled(&p.copy)) + MC_state_interleave_process(initial_state, &p.copy); xbt_fifo_unshift(mc_stack, initial_state); } @@ -347,9 +342,8 @@ static int MC_modelcheck_comm_determinism_main(void) char *req_str = nullptr; int value; - mc_visited_state_t visited_state = nullptr; + std::unique_ptr visited_state = nullptr; smx_simcall_t req = nullptr; - smx_process_t process = nullptr; mc_state_t state = nullptr, next_state = NULL; while (xbt_fifo_size(mc_stack) > 0) { @@ -369,25 +363,23 @@ static int MC_modelcheck_comm_determinism_main(void) && (req = MC_state_get_request(state, &value)) && (visited_state == nullptr)) { - req_str = MC_request_to_string(req, value, MC_REQUEST_SIMIX); + req_str = simgrid::mc::request_to_string(req, value, simgrid::mc::RequestType::simix); XBT_DEBUG("Execute: %s", req_str); xbt_free(req_str); - if (dot_output != nullptr) { - req_str = MC_request_get_dot_output(req, value); - } + if (dot_output != nullptr) + req_str = simgrid::mc::request_get_dot_output(req, value); MC_state_set_executed_request(state, req, value); mc_stats->executed_transitions++; /* TODO : handle test and testany simcalls */ e_mc_call_type_t call = MC_CALL_TYPE_NONE; - if (_sg_mc_comms_determinism || _sg_mc_send_determinism) { + if (_sg_mc_comms_determinism || _sg_mc_send_determinism) call = MC_get_call_type(req); - } /* Answer the request */ - MC_simcall_handle(req, value); /* After this call req is no longer useful */ + simgrid::mc::handle_simcall(req, value); /* After this call req is no longer useful */ if(!initial_global_state->initial_communications_pattern_done) MC_handle_comm_pattern(call, req, value, initial_communications_pattern, 0); @@ -400,24 +392,19 @@ static int MC_modelcheck_comm_determinism_main(void) /* Create the new expanded state */ next_state = MC_state_new(); - if ((visited_state = is_visited_state(next_state)) == nullptr) { + if ((visited_state = simgrid::mc::is_visited_state(next_state)) == nullptr) { /* Get enabled processes and insert them in the interleave set of the next state */ - MC_EACH_SIMIX_PROCESS(process, - if (MC_process_is_enabled(process)) { - MC_state_interleave_process(next_state, process); - } - ); + for (auto& p : mc_model_checker->process().simix_processes()) + if (simgrid::mc::process_is_enabled(&p.copy)) + MC_state_interleave_process(next_state, &p.copy); if (dot_output != nullptr) fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", state->num, next_state->num, req_str); - } else { - - if (dot_output != nullptr) - fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", state->num, visited_state->other_num == -1 ? visited_state->num : visited_state->other_num, req_str); - - } + } else if (dot_output != nullptr) + fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", + state->num, visited_state->other_num == -1 ? visited_state->num : visited_state->other_num, req_str); xbt_fifo_unshift(mc_stack, next_state); @@ -426,13 +413,12 @@ static int MC_modelcheck_comm_determinism_main(void) } else { - if (xbt_fifo_size(mc_stack) > _sg_mc_max_depth) { + if (xbt_fifo_size(mc_stack) > _sg_mc_max_depth) XBT_WARN("/!\\ Max depth reached ! /!\\ "); - } else if (visited_state != nullptr) { + 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 { + else XBT_DEBUG("There are no more processes to interleave. (depth %d)", xbt_fifo_size(mc_stack)); - } if (!initial_global_state->initial_communications_pattern_done) initial_global_state->initial_communications_pattern_done = 1; @@ -445,12 +431,12 @@ static int MC_modelcheck_comm_determinism_main(void) visited_state = nullptr; /* Check for deadlocks */ - if (MC_deadlock_check()) { + if (mc_model_checker->checkDeadlock()) { MC_show_deadlock(nullptr); return SIMGRID_MC_EXIT_DEADLOCK; } - while ((state = (mc_state_t) xbt_fifo_shift(mc_stack)) != nullptr) { + while ((state = (mc_state_t) xbt_fifo_shift(mc_stack)) != nullptr) if (MC_state_interleave_size(state) && xbt_fifo_size(mc_stack) < _sg_mc_max_depth) { /* We found a back-tracking point, let's loop */ XBT_DEBUG("Back-tracking to state %d at depth %d", state->num, xbt_fifo_size(mc_stack) + 1); @@ -465,7 +451,7 @@ static int MC_modelcheck_comm_determinism_main(void) XBT_DEBUG("Delete state %d at depth %d", state->num, xbt_fifo_size(mc_stack) + 1); MC_state_delete(state, !state->in_visited_states ? 1 : 0); } - } + } } @@ -476,13 +462,11 @@ static int MC_modelcheck_comm_determinism_main(void) int MC_modelcheck_comm_determinism(void) { XBT_INFO("Check communication determinism"); - mc_reduce_kind = e_mc_reduce_none; mc_model_checker->wait_for_requests(); - if (mc_mode == MC_MODE_CLIENT) { + if (mc_mode == MC_MODE_CLIENT) // This will move somehwere else: - MC_client_handle_messages(); - } + simgrid::mc::Client::get()->handleMessages(); /* Create exploration stack */ mc_stack = xbt_fifo_new();