Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
423dd14d490d7582afe9ac5357dad808fbebf7df
[simgrid.git] / src / mc / mc_global.cpp
1 /* Copyright (c) 2008-2022. 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 "mc/mc.h"
7 #include "src/kernel/actor/ActorImpl.hpp"
8
9 #if SIMGRID_HAVE_MC
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_safety.hpp"
17 #include "src/mc/remote/AppSide.hpp"
18 #include "src/mc/sosp/Snapshot.hpp"
19
20 #include <array>
21 #include <boost/core/demangle.hpp>
22 #include <cerrno>
23 #include <cstring>
24 #include <libunwind.h>
25 #endif
26
27 #ifndef _WIN32
28 #include <sys/time.h>
29 #include <sys/wait.h>
30 #include <unistd.h>
31 #endif
32
33 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_global, mc, "Logging specific to MC (global)");
34
35 namespace simgrid {
36 namespace mc {
37
38 std::vector<double> processes_time;
39
40 }
41 }
42
43 #if SIMGRID_HAVE_MC
44
45 /* Liveness */
46
47 namespace simgrid {
48 namespace mc {
49
50 xbt_automaton_t property_automaton = nullptr;
51
52 }
53 }
54
55 /* Dot output */
56 FILE *dot_output = nullptr;
57
58
59 /*******************************  Initialization of MC *******************************/
60 /*********************************************************************************/
61
62 void MC_init_dot_output()
63 {
64   dot_output = fopen(_sg_mc_dot_output_file.get().c_str(), "w");
65   xbt_assert(dot_output != nullptr, "Error open dot output file: %s", strerror(errno));
66
67   fprintf(dot_output,
68           "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");
69 }
70
71 /*******************************  Core of MC *******************************/
72 /**************************************************************************/
73
74 void MC_run()
75 {
76   simgrid::mc::processes_time.resize(simgrid::kernel::actor::get_maxpid());
77   MC_ignore_heap(simgrid::mc::processes_time.data(),
78     simgrid::mc::processes_time.size() * sizeof(simgrid::mc::processes_time[0]));
79   simgrid::mc::AppSide::get()->main_loop();
80 }
81
82 namespace simgrid {
83 namespace mc {
84
85 void dumpStack(FILE* file, unw_cursor_t* cursor)
86 {
87   int nframe = 0;
88   std::array<char, 100> buffer;
89
90   unw_word_t off;
91   do {
92     const char* name = not unw_get_proc_name(cursor, buffer.data(), buffer.size(), &off) ? buffer.data() : "?";
93     // Unmangle C++ names:
94     std::string realname = boost::core::demangle(name);
95
96 #if defined(__x86_64__)
97     unw_word_t rip = 0;
98     unw_word_t rsp = 0;
99     unw_get_reg(cursor, UNW_X86_64_RIP, &rip);
100     unw_get_reg(cursor, UNW_X86_64_RSP, &rsp);
101     fprintf(file, "  %i: %s (RIP=0x%" PRIx64 " RSP=0x%" PRIx64 ")\n", nframe, realname.c_str(), (std::uint64_t)rip,
102             (std::uint64_t)rsp);
103 #else
104     fprintf(file, "  %i: %s\n", nframe, realname.c_str());
105 #endif
106
107     ++nframe;
108   } while (unw_step(cursor));
109 }
110
111 }
112 }
113 #endif
114
115 double MC_process_clock_get(const simgrid::kernel::actor::ActorImpl* process)
116 {
117   if (simgrid::mc::processes_time.empty())
118     return 0;
119   if (process != nullptr)
120     return simgrid::mc::processes_time[process->get_pid()];
121   return -1;
122 }
123
124 void MC_process_clock_add(const simgrid::kernel::actor::ActorImpl* process, double amount)
125 {
126   simgrid::mc::processes_time[process->get_pid()] += amount;
127 }