Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
3bd6ab97f1e083c30e06a8c2cb13ef18faa3d174
[simgrid.git] / src / kernel / actor / SimcallObserver.cpp
1 /* Copyright (c) 2019-2023. 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/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"
13
14 #include <sstream>
15
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_observer, mc, "Logging specific to MC simcall observation");
17
18 namespace simgrid::kernel::actor {
19
20 void RandomSimcall::serialize(std::stringstream& stream) const
21 {
22   stream << (short)mc::Transition::Type::RANDOM << ' ';
23   stream << min_ << ' ' << max_;
24 }
25 std::string RandomSimcall::to_string() const
26 {
27   return "Random(min:" + std::to_string(min_) + " max:" + std::to_string(max_) + ")";
28 }
29
30 void RandomSimcall::prepare(int times_considered)
31 {
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);
34 }
35
36 int RandomSimcall::get_max_consider() const
37 {
38   return max_ - min_ + 1;
39 }
40
41 bool ConditionWaitSimcall::is_enabled()
42 {
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");
45     warned = true;
46   }
47   return true;
48 }
49 void ConditionWaitSimcall::serialize(std::stringstream& stream) const
50 {
51   THROW_UNIMPLEMENTED;
52 }
53 std::string ConditionWaitSimcall::to_string() const
54 {
55   return "ConditionWait(cond_id:" + ptr_to_id<activity::ConditionVariableImpl const>(get_cond()) +
56          " mutex_id:" + std::to_string(get_mutex()->get_id()) + ")";
57 }
58
59 ActorJoinSimcall::ActorJoinSimcall(ActorImpl* actor, ActorImpl* other, double timeout)
60     : SimcallObserver(actor), other_(s4u::ActorPtr(other->get_iface())), timeout_(timeout)
61 {
62 }
63 bool ActorJoinSimcall::is_enabled()
64 {
65   return other_->get_impl()->wannadie();
66 }
67 void ActorJoinSimcall::serialize(std::stringstream& stream) const
68 {
69   stream << (short)mc::Transition::Type::ACTOR_JOIN << ' ';
70   stream << other_->get_pid() << ' ' << (timeout_ > 0);
71 }
72 std::string ActorJoinSimcall::to_string() const
73 {
74   return "ActorJoin(pid:" + std::to_string(other_->get_pid()) + ")";
75 }
76 void ActorSleepSimcall::serialize(std::stringstream& stream) const
77 {
78   stream << (short)mc::Transition::Type::ACTOR_SLEEP;
79 }
80
81 std::string ActorSleepSimcall::to_string() const
82 {
83   return "ActorSleep()";
84 }
85
86 void ObjectAccessSimcallObserver::serialize(std::stringstream& stream) const
87 {
88   stream << (short)mc::Transition::Type::OBJECT_ACCESS << ' ';
89   stream << object_ << ' ' << get_owner()->get_pid();
90 }
91 std::string ObjectAccessSimcallObserver::to_string() const
92 {
93   return "ObjectAccess(obj:" + ptr_to_id<ObjectAccessSimcallItem const>(object_) +
94          " owner:" + std::to_string(get_owner()->get_pid()) + ")";
95 }
96 bool ObjectAccessSimcallObserver::is_visible() const
97 {
98   return get_owner() != get_issuer();
99 }
100 ActorImpl* ObjectAccessSimcallObserver::get_owner() const
101 {
102   return object_->simcall_owner_;
103 }
104
105 } // namespace simgrid::kernel::actor