1 /* Copyright (c) 2007-2018. 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/modelchecker.h"
7 #include "src/mc/mc_replay.hpp"
9 #include "src/kernel/activity/ExecImpl.hpp"
10 #include "src/simix/smx_host_private.hpp"
11 #include "src/surf/surf_interface.hpp"
12 #include "src/surf/cpu_interface.hpp"
14 #include "simgrid/s4u/Host.hpp"
16 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_process);
18 simgrid::kernel::activity::ExecImpl::ExecImpl(const char* name, sg_host_t host) : host_(host)
22 this->state = SIMIX_RUNNING;
23 XBT_DEBUG("Create exec %p", this);
26 simgrid::kernel::activity::ExecImpl::~ExecImpl()
31 timeoutDetector->unref();
32 XBT_DEBUG("Destroy exec %p", this);
35 void simgrid::kernel::activity::ExecImpl::suspend()
37 XBT_VERB("This exec is suspended (remain: %f)", surfAction_->get_remains());
39 surfAction_->suspend();
42 void simgrid::kernel::activity::ExecImpl::resume()
44 XBT_VERB("This exec is resumed (remain: %f)", surfAction_->get_remains());
46 surfAction_->resume();
49 double simgrid::kernel::activity::ExecImpl::remains()
51 xbt_assert(host_ != nullptr, "Calling remains() on a parallel execution is not allowed. "
52 "We would need to return a vector instead of a scalar. "
53 "Did you mean remainingRatio() instead?");
55 return surfAction_ ? surfAction_->get_remains() : 0;
58 double simgrid::kernel::activity::ExecImpl::remainingRatio()
60 if (host_ == nullptr) // parallel task: their remain is already between 0 and 1 (see comment in ExecImpl::remains())
61 return surfAction_->get_remains();
62 else // Actually compute the ratio for sequential tasks
63 return surfAction_->get_remains() / surfAction_->get_cost();
66 void simgrid::kernel::activity::ExecImpl::setBound(double bound)
69 surfAction_->set_bound(bound);
72 void simgrid::kernel::activity::ExecImpl::post()
74 if (host_ && host_->isOff()) { /* FIXME: handle resource failure for parallel tasks too */
75 /* If the host running the synchro failed, notice it. This way, the asking
76 * process can be killed if it runs on that host itself */
78 } else if (surfAction_ && surfAction_->get_state() == simgrid::kernel::resource::Action::State::failed) {
79 /* If the host running the synchro didn't fail, then the synchro was canceled */
80 state = SIMIX_CANCELED;
81 } else if (timeoutDetector && timeoutDetector->get_state() == simgrid::kernel::resource::Action::State::done) {
82 state = SIMIX_TIMEOUT;
89 surfAction_ = nullptr;
91 if (timeoutDetector) {
92 timeoutDetector->unref();
93 timeoutDetector = nullptr;
97 /* If there are simcalls associated with the synchro, then answer them */
98 if (not simcalls.empty())
99 SIMIX_execution_finish(this);
102 simgrid::kernel::activity::ActivityImpl*
103 simgrid::kernel::activity::ExecImpl::migrate(simgrid::s4u::Host* to)
106 if (not MC_is_active() && not MC_record_replay_is_active()) {
107 simgrid::kernel::resource::Action* oldAction = this->surfAction_;
108 simgrid::kernel::resource::Action* newAction = to->pimpl_cpu->execution_start(oldAction->get_cost());
109 newAction->set_remains(oldAction->get_remains());
110 newAction->set_data(this);
111 newAction->set_priority(oldAction->get_priority());
113 // FIXME: the user-defined bound seem to not be kept by LMM, that seem to overwrite it for the multi-core modeling.
114 // I hope that the user did not provide any.
116 oldAction->set_data(nullptr);
119 this->surfAction_ = newAction;
122 onMigration(this, to);
129 simgrid::xbt::signal<void(simgrid::kernel::activity::ExecImplPtr)> simgrid::kernel::activity::ExecImpl::onCreation;
130 simgrid::xbt::signal<void(simgrid::kernel::activity::ExecImplPtr)> simgrid::kernel::activity::ExecImpl::onCompletion;
131 simgrid::xbt::signal<void(simgrid::kernel::activity::ExecImplPtr, simgrid::s4u::Host*)> simgrid::kernel::activity::ExecImpl::onMigration;