Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Cosmetics: make parameter name match with .hpp.
[simgrid.git] / src / kernel / actor / SimcallObserver.cpp
1 /* Copyright (c) 2019-2021. 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 "src/kernel/actor/SimcallObserver.hpp"
7 #include "simgrid/s4u/Host.hpp"
8 #include "src/kernel/activity/MutexImpl.hpp"
9 #include "src/kernel/actor/ActorImpl.hpp"
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_observer, mc, "Logging specific to MC simcall observation");
12
13 namespace simgrid {
14 namespace kernel {
15 namespace actor {
16
17 std::string SimcallObserver::to_string(int /*times_considered*/) const
18 {
19   return simgrid::xbt::string_printf("[(%ld)%s (%s)] ", issuer_->get_pid(), issuer_->get_host()->get_cname(),
20                                      issuer_->get_cname());
21 }
22
23 std::string SimcallObserver::dot_label() const
24 {
25   if (issuer_->get_host())
26     return xbt::string_printf("[(%ld)%s] ", issuer_->get_pid(), issuer_->get_cname());
27   return xbt::string_printf("[(%ld)] ", issuer_->get_pid());
28 }
29
30 std::string RandomSimcall::to_string(int times_considered) const
31 {
32   return SimcallObserver::to_string(times_considered) + "MC_RANDOM(" + std::to_string(times_considered) + ")";
33 }
34
35 std::string RandomSimcall::dot_label() const
36 {
37   return SimcallObserver::dot_label() + "MC_RANDOM(" + std::to_string(next_value_) + ")";
38 }
39
40 void RandomSimcall::prepare(int times_considered)
41 {
42   next_value_ = min_ + times_considered;
43   XBT_DEBUG("MC_RANDOM(%d, %d) will return %d after %d times", min_, max_, next_value_, times_considered);
44 }
45
46 int RandomSimcall::get_max_consider() const
47 {
48   return max_ - min_ + 1;
49 }
50
51 std::string MutexUnlockSimcall::to_string(int times_considered) const
52 {
53   return SimcallObserver::to_string(times_considered) + "Mutex UNLOCK";
54 }
55
56 std::string MutexUnlockSimcall::dot_label() const
57 {
58   return SimcallObserver::dot_label() + "Mutex UNLOCK";
59 }
60
61 std::string MutexLockSimcall::to_string(int times_considered) const
62 {
63   std::string res = SimcallObserver::to_string(times_considered) + (blocking_ ? "Mutex LOCK" : "Mutex TRYLOCK");
64   res += "(locked = " + std::to_string(mutex_->is_locked());
65   res += ", owner = " + std::to_string(mutex_->get_owner() ? mutex_->get_owner()->get_pid() : -1);
66   res += ", sleeping = n/a)";
67   return res;
68 }
69
70 std::string MutexLockSimcall::dot_label() const
71 {
72   return SimcallObserver::dot_label() + (blocking_ ? "Mutex LOCK" : "Mutex TRYLOCK");
73 }
74
75 bool MutexLockSimcall::is_enabled() const
76 {
77   return not blocking_ || mutex_->get_owner() == nullptr || mutex_->get_owner() == get_issuer();
78 }
79
80 std::string ConditionWaitSimcall::to_string(int times_considered) const
81 {
82   std::string res = SimcallObserver::to_string(times_considered) + "Condition WAIT";
83   res += "(" + (timeout_ == -1.0 ? "" : std::to_string(timeout_)) + ")";
84   return res;
85 }
86
87 std::string ConditionWaitSimcall::dot_label() const
88 {
89   return SimcallObserver::dot_label() + "Condition WAIT";
90 }
91
92 bool ConditionWaitSimcall::is_enabled() const
93 {
94   static bool warned = false;
95   if (not warned) {
96     XBT_INFO("Using condition variables in model-checked code is still experimental. Use at your own risk");
97     warned = true;
98   }
99   return true;
100 }
101
102 std::string SemAcquireSimcall::to_string(int times_considered) const
103 {
104   std::string res = SimcallObserver::to_string(times_considered) + "Sem ACQUIRE";
105   res += "(" + (timeout_ == -1.0 ? "" : std::to_string(timeout_)) + ")";
106   return res;
107 }
108
109 std::string SemAcquireSimcall::dot_label() const
110 {
111   return SimcallObserver::dot_label() + "Sem ACQUIRE";
112 }
113
114 bool SemAcquireSimcall::is_enabled() const
115 {
116   static bool warned = false;
117   if (not warned) {
118     XBT_INFO("Using semaphore in model-checked code is still experimental. Use at your own risk");
119     warned = true;
120   }
121   return true;
122 }
123
124 std::string ExecutionWaitanySimcall::to_string(int times_considered) const
125 {
126   std::string res = SimcallObserver::to_string(times_considered) + "Execution WAITANY";
127   res += "(" + (timeout_ == -1.0 ? "" : std::to_string(timeout_)) + ")";
128   return res;
129 }
130
131 std::string ExecutionWaitanySimcall::dot_label() const
132 {
133   return SimcallObserver::dot_label() + "Execution WAITANY";
134 }
135 } // namespace actor
136 } // namespace kernel
137 } // namespace simgrid