Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Align the behavior of MC and MC_replay in SMPI, so that replay actually works
[simgrid.git] / src / kernel / actor / Simcall.cpp
1 /* Copyright (c) 2010-2022. 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 "Simcall.hpp"
7 #include "simgrid/s4u/Host.hpp"
8 #include "src/kernel/actor/ActorImpl.hpp"
9 #include "src/kernel/actor/SimcallObserver.hpp"
10 #include "src/kernel/context/Context.hpp"
11 #include "xbt/log.h"
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_simcall, kernel, "transmuting from user request into kernel handlers");
14
15 namespace simgrid::kernel::actor {
16
17 /** @private
18  * @brief (in kernel mode) unpack the simcall and activate the handler
19  *
20  */
21 void ActorImpl::simcall_handle(int times_considered)
22 {
23   XBT_DEBUG("Handling simcall %p: %s(%ld) %s", &simcall_, simcall_.issuer_->get_cname(), simcall_.issuer_->get_pid(),
24             (simcall_.observer_ != nullptr ? simcall_.observer_->to_string().c_str() : simcall_.get_cname()));
25   if (simcall_.observer_ != nullptr)
26     simcall_.observer_->prepare(times_considered);
27   if (wannadie())
28     return;
29
30   xbt_assert(simcall_.call_ != Simcall::Type::NONE, "Asked to do the noop syscall on %s@%s", get_cname(),
31              get_host()->get_cname());
32
33   (*simcall_.code_)();
34   if (simcall_.call_ == Simcall::Type::RUN_ANSWERED)
35     simcall_answer();
36 }
37
38 /** @brief returns a printable string representing a simcall */
39 const char* Simcall::get_cname() const
40 {
41   if (observer_ != nullptr) {
42     static std::string name;
43     name              = boost::core::demangle(typeid(*observer_).name());
44     const char* cname = name.c_str();
45     if (name.rfind("simgrid::kernel::", 0) == 0)
46       cname += 17; // strip prefix "simgrid::kernel::"
47     return cname;
48   } else {
49     return to_c_str(call_);
50   }
51 }
52
53 } // namespace simgrid::kernel::actor