Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[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 ActorJoinSimcall::ActorJoinSimcall(ActorImpl* actor, ActorImpl* other, double timeout)
42     : SimcallObserver(actor), other_(s4u::ActorPtr(other->get_iface())), timeout_(timeout)
43 {
44 }
45 bool ActorJoinSimcall::is_enabled()
46 {
47   return other_->get_impl()->wannadie();
48 }
49 void ActorJoinSimcall::serialize(std::stringstream& stream) const
50 {
51   stream << (short)mc::Transition::Type::ACTOR_JOIN << ' ';
52   stream << other_->get_pid() << ' ' << (timeout_ > 0);
53 }
54 std::string ActorJoinSimcall::to_string() const
55 {
56   return "ActorJoin(pid:" + std::to_string(other_->get_pid()) + ")";
57 }
58 void ActorSleepSimcall::serialize(std::stringstream& stream) const
59 {
60   stream << (short)mc::Transition::Type::ACTOR_SLEEP;
61 }
62
63 std::string ActorSleepSimcall::to_string() const
64 {
65   return "ActorSleep()";
66 }
67
68 void ObjectAccessSimcallObserver::serialize(std::stringstream& stream) const
69 {
70   stream << (short)mc::Transition::Type::OBJECT_ACCESS << ' ';
71   stream << object_ << ' ' << get_owner()->get_pid();
72 }
73 std::string ObjectAccessSimcallObserver::to_string() const
74 {
75   return "ObjectAccess(obj:" + ptr_to_id<ObjectAccessSimcallItem const>(object_) +
76          " owner:" + std::to_string(get_owner()->get_pid()) + ")";
77 }
78 bool ObjectAccessSimcallObserver::is_visible() const
79 {
80   return get_owner() != get_issuer();
81 }
82 ActorImpl* ObjectAccessSimcallObserver::get_owner() const
83 {
84   return object_->simcall_owner_;
85 }
86
87 } // namespace simgrid::kernel::actor