1 /* Copyright (c) 2019-2023. 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/CommImpl.hpp"
9 #include "src/kernel/activity/MailboxImpl.hpp"
10 #include "src/kernel/activity/MutexImpl.hpp"
11 #include "src/kernel/actor/ActorImpl.hpp"
12 #include "src/mc/mc_config.hpp"
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_observer, mc, "Logging specific to MC simcall observation");
18 namespace simgrid::kernel::actor {
20 void RandomSimcall::serialize(std::stringstream& stream) const
22 stream << (short)mc::Transition::Type::RANDOM << ' ';
23 stream << min_ << ' ' << max_;
25 std::string RandomSimcall::to_string() const
27 return "Random(min:" + std::to_string(min_) + " max:" + std::to_string(max_) + ")";
30 void RandomSimcall::prepare(int times_considered)
32 next_value_ = min_ + times_considered;
33 XBT_DEBUG("MC_RANDOM(%d, %d) will return %d after %d times", min_, max_, next_value_, times_considered);
36 int RandomSimcall::get_max_consider() const
38 return max_ - min_ + 1;
41 bool ConditionWaitSimcall::is_enabled()
43 if (static bool warned = false; not warned) {
44 XBT_INFO("Using condition variables in model-checked code is still experimental. Use at your own risk");
49 void ConditionWaitSimcall::serialize(std::stringstream& stream) const
53 std::string ConditionWaitSimcall::to_string() const
55 return "ConditionWait(cond_id:" + ptr_to_id<activity::ConditionVariableImpl const>(get_cond()) +
56 " mutex_id:" + std::to_string(get_mutex()->get_id()) + ")";
59 ActorJoinSimcall::ActorJoinSimcall(ActorImpl* actor, ActorImpl* other, double timeout)
60 : SimcallObserver(actor), other_(s4u::ActorPtr(other->get_iface())), timeout_(timeout)
63 bool ActorJoinSimcall::is_enabled()
65 return other_->get_impl()->wannadie();
67 void ActorJoinSimcall::serialize(std::stringstream& stream) const
69 stream << (short)mc::Transition::Type::ACTOR_JOIN << ' ';
70 stream << other_->get_pid() << ' ' << (timeout_ > 0);
72 std::string ActorJoinSimcall::to_string() const
74 return "ActorJoin(pid:" + std::to_string(other_->get_pid()) + ")";
77 void ObjectAccessSimcallObserver::serialize(std::stringstream& stream) const
79 stream << (short)mc::Transition::Type::OBJECT_ACCESS << ' ';
80 stream << object_ << ' ' << get_owner()->get_pid();
82 std::string ObjectAccessSimcallObserver::to_string() const
84 return "ObjectAccess(obj:" + ptr_to_id<ObjectAccessSimcallItem const>(object_) +
85 " owner:" + std::to_string(get_owner()->get_pid()) + ")";
87 bool ObjectAccessSimcallObserver::is_visible() const
89 return get_owner() != get_issuer();
91 ActorImpl* ObjectAccessSimcallObserver::get_owner() const
93 return object_->simcall_owner_;
96 } // namespace simgrid::kernel::actor