1 /* Copyright (c) 2019-2021. 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. */
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"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_observer, mc, "Logging specific to MC simcall observation");
17 std::string SimcallObserver::to_string(int /*times_considered*/) const
19 return simgrid::xbt::string_printf("[(%ld)%s (%s)] ", issuer_->get_pid(), issuer_->get_host()->get_cname(),
20 issuer_->get_cname());
23 std::string SimcallObserver::dot_label() const
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());
30 std::string RandomSimcall::to_string(int times_considered) const
32 return SimcallObserver::to_string(times_considered) + "MC_RANDOM(" + std::to_string(times_considered) + ")";
35 std::string RandomSimcall::dot_label() const
37 return SimcallObserver::dot_label() + "MC_RANDOM(" + std::to_string(next_value_) + ")";
40 void RandomSimcall::prepare(int times_considered)
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);
46 int RandomSimcall::get_max_consider() const
48 return max_ - min_ + 1;
51 std::string MutexUnlockSimcall::to_string(int times_considered) const
53 return SimcallObserver::to_string(times_considered) + "Mutex UNLOCK";
56 std::string MutexUnlockSimcall::dot_label() const
58 return SimcallObserver::dot_label() + "Mutex UNLOCK";
61 std::string MutexLockSimcall::to_string(int times_considered) const
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)";
70 std::string MutexLockSimcall::dot_label() const
72 return SimcallObserver::dot_label() + (blocking_ ? "Mutex LOCK" : "Mutex TRYLOCK");
75 bool MutexLockSimcall::is_enabled() const
77 return not blocking_ || mutex_->get_owner() == nullptr || mutex_->get_owner() == get_issuer();
80 std::string ConditionWaitSimcall::to_string(int times_considered) const
82 std::string res = SimcallObserver::to_string(times_considered) + "Condition WAIT";
83 res += "(" + (timeout_ == -1.0 ? "" : std::to_string(timeout_)) + ")";
87 std::string ConditionWaitSimcall::dot_label() const
89 return SimcallObserver::dot_label() + "Condition WAIT";
92 bool ConditionWaitSimcall::is_enabled() const
94 static bool warned = false;
96 XBT_INFO("Using condition variables in model-checked code is still experimental. Use at your own risk");
102 std::string SemAcquireSimcall::to_string(int times_considered) const
104 std::string res = SimcallObserver::to_string(times_considered) + "Sem ACQUIRE";
105 res += "(" + (timeout_ == -1.0 ? "" : std::to_string(timeout_)) + ")";
109 std::string SemAcquireSimcall::dot_label() const
111 return SimcallObserver::dot_label() + "Sem ACQUIRE";
114 bool SemAcquireSimcall::is_enabled() const
116 static bool warned = false;
118 XBT_INFO("Using semaphore in model-checked code is still experimental. Use at your own risk");
124 std::string ExecutionWaitanySimcall::to_string(int times_considered) const
126 std::string res = SimcallObserver::to_string(times_considered) + "Execution WAITANY";
127 res += "(" + (timeout_ == -1.0 ? "" : std::to_string(timeout_)) + ")";
131 std::string ExecutionWaitanySimcall::dot_label() const
133 return SimcallObserver::dot_label() + "Execution WAITANY";
136 } // namespace kernel
137 } // namespace simgrid