Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
mc: move some files related to ELF, DWARF or unwind reading into their own directory
[simgrid.git] / src / mc / mc_comm_pattern.cpp
1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include <cstring>
7
8 #include "xbt/dynar.h"
9 #include "xbt/sysdep.h"
10
11 #include "src/mc/checker/CommunicationDeterminismChecker.hpp"
12 #include "src/mc/mc_comm_pattern.hpp"
13 #include "src/mc/mc_smx.hpp"
14
15 using simgrid::mc::remote;
16
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_comm_pattern, mc,
18                                 "Logging specific to MC communication patterns");
19
20 static void MC_patterns_copy(std::vector<simgrid::mc::PatternCommunication*>& dest,
21                              std::vector<simgrid::mc::PatternCommunication> const& source)
22 {
23   dest.clear();
24   for (simgrid::mc::PatternCommunication const& comm : source) {
25     simgrid::mc::PatternCommunication* copy_comm = new simgrid::mc::PatternCommunication(comm.dup());
26     dest.push_back(copy_comm);
27   }
28 }
29
30 void MC_restore_communications_pattern(simgrid::mc::State* state)
31 {
32   for (unsigned i = 0; i < initial_communications_pattern.size(); i++)
33     initial_communications_pattern[i].index_comm = state->communicationIndices[i];
34
35   for (unsigned i = 0; i < MC_smx_get_maxpid(); i++)
36     MC_patterns_copy(incomplete_communications_pattern[i], state->incomplete_comm_pattern[i]);
37 }
38
39 void MC_state_copy_incomplete_communications_pattern(simgrid::mc::State* state)
40 {
41   state->incomplete_comm_pattern.clear();
42   for (unsigned i=0; i < MC_smx_get_maxpid(); i++) {
43     std::vector<simgrid::mc::PatternCommunication> res;
44     for (auto const& comm : incomplete_communications_pattern[i])
45       res.push_back(comm->dup());
46     state->incomplete_comm_pattern.push_back(std::move(res));
47   }
48 }
49
50 void MC_state_copy_index_communications_pattern(simgrid::mc::State* state)
51 {
52   state->communicationIndices.clear();
53   for (auto const& list_process_comm : initial_communications_pattern)
54     state->communicationIndices.push_back(list_process_comm.index_comm);
55 }
56
57 void MC_handle_comm_pattern(e_mc_call_type_t call_type, smx_simcall_t req, int value, int backtracking)
58 {
59   // HACK, do not rely on the Checker implementation outside of it
60   simgrid::mc::CommunicationDeterminismChecker* checker =
61     (simgrid::mc::CommunicationDeterminismChecker*) mc_model_checker->getChecker();
62
63   switch(call_type) {
64   case MC_CALL_TYPE_NONE:
65     break;
66   case MC_CALL_TYPE_SEND:
67   case MC_CALL_TYPE_RECV:
68     checker->get_comm_pattern(req, call_type, backtracking);
69     break;
70   case MC_CALL_TYPE_WAIT:
71   case MC_CALL_TYPE_WAITANY:
72     {
73     simgrid::mc::RemotePtr<simgrid::kernel::activity::CommImpl> comm_addr{nullptr};
74     if (call_type == MC_CALL_TYPE_WAIT)
75       comm_addr = remote(static_cast<simgrid::kernel::activity::CommImpl*>(simcall_comm_wait__getraw__comm(req)));
76
77     else {
78       simgrid::kernel::activity::ActivityImpl* addr;
79       addr      = mc_model_checker->process().read(remote(simcall_comm_waitany__getraw__comms(req) + value));
80       comm_addr = remote(static_cast<simgrid::kernel::activity::CommImpl*>(addr));
81       }
82       checker->complete_comm_pattern(comm_addr, MC_smx_simcall_get_issuer(req)->get_pid(), backtracking);
83     }
84     break;
85   default:
86     xbt_die("Unexpected call type %i", (int)call_type);
87   }
88
89 }