1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved. */
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. */
9 #include "xbt/sysdep.h"
11 #include "src/mc/checker/CommunicationDeterminismChecker.hpp"
12 #include "src/mc/mc_comm_pattern.hpp"
13 #include "src/mc/mc_smx.hpp"
15 using simgrid::mc::remote;
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_comm_pattern, mc,
18 "Logging specific to MC communication patterns");
20 static void MC_patterns_copy(xbt_dynar_t dest,
21 std::vector<simgrid::mc::PatternCommunication> const& source)
23 xbt_dynar_reset(dest);
24 for (simgrid::mc::PatternCommunication const& comm : source) {
25 simgrid::mc::PatternCommunication* copy_comm = new simgrid::mc::PatternCommunication(comm.dup());
26 xbt_dynar_push(dest, ©_comm);
30 void MC_restore_communications_pattern(simgrid::mc::State* state)
32 simgrid::mc::PatternCommunicationList* list_process_comm;
35 xbt_dynar_foreach(initial_communications_pattern, cursor, list_process_comm)
36 list_process_comm->index_comm = state->communicationIndices[cursor];
38 for (unsigned i = 0; i < MC_smx_get_maxpid(); i++)
40 xbt_dynar_get_as(incomplete_communications_pattern, i, xbt_dynar_t),
41 state->incomplete_comm_pattern[i]
45 void MC_state_copy_incomplete_communications_pattern(simgrid::mc::State* state)
47 state->incomplete_comm_pattern.clear();
48 for (unsigned i=0; i < MC_smx_get_maxpid(); i++) {
49 xbt_dynar_t patterns = xbt_dynar_get_as(incomplete_communications_pattern, i, xbt_dynar_t);
50 std::vector<simgrid::mc::PatternCommunication> res;
51 simgrid::mc::PatternCommunication* comm;
53 xbt_dynar_foreach(patterns, cursor, comm)
54 res.push_back(comm->dup());
55 state->incomplete_comm_pattern.push_back(std::move(res));
59 void MC_state_copy_index_communications_pattern(simgrid::mc::State* state)
61 state->communicationIndices.clear();
62 simgrid::mc::PatternCommunicationList* list_process_comm;
64 xbt_dynar_foreach(initial_communications_pattern, cursor, list_process_comm)
65 state->communicationIndices.push_back(list_process_comm->index_comm);
68 void MC_handle_comm_pattern(e_mc_call_type_t call_type, smx_simcall_t req, int value, int backtracking)
70 // HACK, do not rely on the Checker implementation outside of it
71 simgrid::mc::CommunicationDeterminismChecker* checker =
72 (simgrid::mc::CommunicationDeterminismChecker*) mc_model_checker->getChecker();
75 case MC_CALL_TYPE_NONE:
77 case MC_CALL_TYPE_SEND:
78 case MC_CALL_TYPE_RECV:
79 checker->get_comm_pattern(req, call_type, backtracking);
81 case MC_CALL_TYPE_WAIT:
82 case MC_CALL_TYPE_WAITANY:
84 simgrid::mc::RemotePtr<simgrid::kernel::activity::CommImpl> comm_addr{nullptr};
85 if (call_type == MC_CALL_TYPE_WAIT)
86 comm_addr = remote(static_cast<simgrid::kernel::activity::CommImpl*>(simcall_comm_wait__getraw__comm(req)));
89 simgrid::kernel::activity::ActivityImpl* addr;
90 addr = mc_model_checker->process().read(remote(simcall_comm_waitany__getraw__comms(req) + value));
91 comm_addr = remote(static_cast<simgrid::kernel::activity::CommImpl*>(addr));
93 checker->complete_comm_pattern(comm_addr, MC_smx_simcall_get_issuer(req)->get_pid(), backtracking);
97 xbt_die("Unexpected call type %i", (int)call_type);