1 /* Copyright (c) 2007-2017. 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"
8 #include "src/kernel/activity/ExecImpl.hpp"
9 #include "src/simix/smx_host_private.hpp"
10 #include "src/surf/surf_interface.hpp"
12 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_process);
14 simgrid::kernel::activity::ExecImpl::ExecImpl(const char* name, sg_host_t host) : host_(host)
18 this->state = SIMIX_RUNNING;
19 XBT_DEBUG("Create exec %p", this);
22 simgrid::kernel::activity::ExecImpl::~ExecImpl()
27 timeoutDetector->unref();
28 XBT_DEBUG("Destroy exec %p", this);
30 void simgrid::kernel::activity::ExecImpl::suspend()
32 XBT_VERB("This exec is suspended (remain: %f)", surfAction_->getRemains());
34 surfAction_->suspend();
37 void simgrid::kernel::activity::ExecImpl::resume()
39 XBT_VERB("This exec is resumed (remain: %f)", surfAction_->getRemains());
41 surfAction_->resume();
44 double simgrid::kernel::activity::ExecImpl::remains()
46 xbt_assert(host_ != nullptr, "Calling remains() on a parallel execution is not allowed. "
47 "We would need to return a vector instead of a scalar. "
48 "Did you meant remainingRatio() instead?");
50 return surfAction_ ? surfAction_->getRemains() : 0;
52 double simgrid::kernel::activity::ExecImpl::remainingRatio()
54 if (host_ == nullptr) // parallel task: their remain is already between 0 and 1 (see comment in ExecImpl::remains())
55 return surfAction_->getRemains();
56 else // Actually compute the ratio for sequential tasks
57 return surfAction_->getRemains() / surfAction_->getCost();
60 void simgrid::kernel::activity::ExecImpl::post()
62 if (host_ && host_->isOff()) { /* FIXME: handle resource failure for parallel tasks too */
63 /* If the host running the synchro failed, notice it. This way, the asking
64 * process can be killed if it runs on that host itself */
66 } else if (surfAction_->getState() == simgrid::surf::Action::State::failed) {
67 /* If the host running the synchro didn't fail, then the synchro was canceled */
68 state = SIMIX_CANCELED;
69 } else if (timeoutDetector && timeoutDetector->getState() == simgrid::surf::Action::State::done) {
70 state = SIMIX_TIMEOUT;
77 surfAction_ = nullptr;
79 if (timeoutDetector) {
80 timeoutDetector->unref();
81 timeoutDetector = nullptr;
84 /* If there are simcalls associated with the synchro, then answer them */
85 if (not simcalls.empty())
86 SIMIX_execution_finish(this);
92 simgrid::xbt::signal<void(simgrid::kernel::activity::ExecImplPtr)> simgrid::kernel::activity::ExecImpl::onCreation;
93 simgrid::xbt::signal<void(simgrid::kernel::activity::ExecImplPtr)> simgrid::kernel::activity::ExecImpl::onDestruction;