1 /* Copyright (c) 2008-2020. 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. */
7 #include "src/kernel/actor/ActorImpl.hpp"
10 #include "src/mc/Session.hpp"
11 #include "src/mc/checker/Checker.hpp"
12 #include "src/mc/inspect/mc_unw.hpp"
13 #include "src/mc/mc_comm_pattern.hpp"
14 #include "src/mc/mc_config.hpp"
15 #include "src/mc/mc_private.hpp"
16 #include "src/mc/mc_request.hpp"
17 #include "src/mc/mc_safety.hpp"
18 #include "src/mc/mc_smx.hpp"
19 #include "src/mc/remote/AppSide.hpp"
20 #include "src/mc/sosp/Snapshot.hpp"
21 #include "xbt/backtrace.hpp"
23 #include <libunwind.h>
32 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_global, mc, "Logging specific to MC (global)");
37 std::vector<double> processes_time;
49 xbt_automaton_t property_automaton = nullptr;
55 FILE *dot_output = nullptr;
58 /******************************* Initialization of MC *******************************/
59 /*********************************************************************************/
61 void MC_init_dot_output()
63 dot_output = fopen(_sg_mc_dot_output_file.get().c_str(), "w");
65 if (dot_output == nullptr) {
66 perror("Error open dot output file");
71 "digraph graphname{\n fixedsize=true; rankdir=TB; ranksep=.25; edge [fontsize=12]; node [fontsize=10, shape=circle,width=.5 ]; graph [resolution=20, fontsize=10];\n");
74 /******************************* Core of MC *******************************/
75 /**************************************************************************/
79 simgrid::mc::processes_time.resize(simgrid::kernel::actor::get_maxpid());
80 MC_ignore_heap(simgrid::mc::processes_time.data(),
81 simgrid::mc::processes_time.size() * sizeof(simgrid::mc::processes_time[0]));
82 simgrid::mc::AppSide::get()->main_loop();
85 void MC_show_deadlock()
87 XBT_INFO("**************************");
88 XBT_INFO("*** DEADLOCK DETECTED ***");
89 XBT_INFO("**************************");
90 XBT_INFO("Counter-example execution trace:");
91 for (auto const& s : mc_model_checker->getChecker()->get_textual_trace())
92 XBT_INFO(" %s", s.c_str());
93 simgrid::mc::dumpRecordPath();
94 simgrid::mc::session->log_state();
97 void MC_automaton_load(const char *file)
99 if (simgrid::mc::property_automaton == nullptr)
100 simgrid::mc::property_automaton = xbt_automaton_new();
102 xbt_automaton_load(simgrid::mc::property_automaton, file);
108 void dumpStack(FILE* file, unw_cursor_t* cursor)
115 const char* name = not unw_get_proc_name(cursor, buffer, 100, &off) ? buffer : "?";
116 // Unmangle C++ names:
117 auto realname = simgrid::xbt::demangle(name);
119 #if defined(__x86_64__)
122 unw_get_reg(cursor, UNW_X86_64_RIP, &rip);
123 unw_get_reg(cursor, UNW_X86_64_RSP, &rsp);
124 fprintf(file, " %i: %s (RIP=0x%" PRIx64 " RSP=0x%" PRIx64 ")\n", nframe, realname.get(), (std::uint64_t)rip,
127 fprintf(file, " %i: %s\n", nframe, realname.get());
131 } while (unw_step(cursor));
138 double MC_process_clock_get(const simgrid::kernel::actor::ActorImpl* process)
140 if (simgrid::mc::processes_time.empty())
142 if (process != nullptr)
143 return simgrid::mc::processes_time[process->get_pid()];
147 void MC_process_clock_add(const simgrid::kernel::actor::ActorImpl* process, double amount)
149 simgrid::mc::processes_time[process->get_pid()] += amount;