1 /* Copyright (c) 2010-2022. 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 "simgrid/s4u/Host.hpp"
7 #include "src/kernel/actor/ActorImpl.hpp"
8 #include "src/kernel/actor/SimcallObserver.hpp"
9 #include "src/kernel/context/Context.hpp"
10 #include "src/simix/popping_private.hpp"
13 XBT_LOG_NEW_DEFAULT_CATEGORY(simix, "transmuting from user request into kernel handlers");
15 constexpr std::array<const char*, simgrid::simix::NUM_SIMCALLS> simcall_names{{
17 "Simcall::RUN_KERNEL",
18 "Simcall::RUN_BLOCKING",
22 * @brief (in kernel mode) unpack the simcall and activate the handler
24 * This function is generated from src/simix/simcalls.in
26 void simgrid::kernel::actor::ActorImpl::simcall_handle(int times_considered)
28 XBT_DEBUG("Handling simcall %p: %s", &simcall_, SIMIX_simcall_name(simcall_));
29 if (simcall_.observer_ != nullptr)
30 simcall_.observer_->prepare(times_considered);
31 if (context_->wannadie())
33 switch (simcall_.call_) {
34 case simgrid::simix::Simcall::RUN_KERNEL:
35 SIMIX_run_kernel(simcall_.code_);
39 case simgrid::simix::Simcall::RUN_BLOCKING:
40 SIMIX_run_blocking(simcall_.code_);
43 case simgrid::simix::Simcall::NONE:
44 throw std::invalid_argument(
45 simgrid::xbt::string_printf("Asked to do the noop syscall on %s@%s", get_cname(), get_host()->get_cname()));
51 void SIMIX_run_kernel(std::function<void()> const* code)
56 /** Kernel code for run_blocking
58 * The implementation looks a lot like SIMIX_run_kernel ^^
60 * However, this `run_blocking` is blocking so the process will not be woken
61 * up until `ActorImpl::simcall_answer()`` is called by the kernel.
62 * This means that `code` is responsible for doing this.
64 void SIMIX_run_blocking(std::function<void()> const* code)