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/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"
15 #include "simgrid/s4u/Host.hpp"
17 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_process);
19 simgrid::kernel::activity::ExecImpl::ExecImpl(const char* name, sg_host_t host) : host_(host)
23 this->state = SIMIX_RUNNING;
24 XBT_DEBUG("Create exec %p", this);
27 simgrid::kernel::activity::ExecImpl::~ExecImpl()
32 timeoutDetector->unref();
33 XBT_DEBUG("Destroy exec %p", this);
35 void simgrid::kernel::activity::ExecImpl::suspend()
37 XBT_VERB("This exec is suspended (remain: %f)", surfAction_->getRemains());
39 surfAction_->suspend();
42 void simgrid::kernel::activity::ExecImpl::resume()
44 XBT_VERB("This exec is resumed (remain: %f)", surfAction_->getRemains());
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 meant remainingRatio() instead?");
55 return surfAction_ ? surfAction_->getRemains() : 0;
57 double simgrid::kernel::activity::ExecImpl::remainingRatio()
59 if (host_ == nullptr) // parallel task: their remain is already between 0 and 1 (see comment in ExecImpl::remains())
60 return surfAction_->getRemains();
61 else // Actually compute the ratio for sequential tasks
62 return surfAction_->getRemains() / surfAction_->getCost();
65 void simgrid::kernel::activity::ExecImpl::post()
67 if (host_ && host_->isOff()) { /* FIXME: handle resource failure for parallel tasks too */
68 /* If the host running the synchro failed, notice it. This way, the asking
69 * process can be killed if it runs on that host itself */
71 } else if (surfAction_->getState() == simgrid::surf::Action::State::failed) {
72 /* If the host running the synchro didn't fail, then the synchro was canceled */
73 state = SIMIX_CANCELED;
74 } else if (timeoutDetector && timeoutDetector->getState() == simgrid::surf::Action::State::done) {
75 state = SIMIX_TIMEOUT;
82 surfAction_ = nullptr;
84 if (timeoutDetector) {
85 timeoutDetector->unref();
86 timeoutDetector = nullptr;
90 /* If there are simcalls associated with the synchro, then answer them */
91 if (not simcalls.empty())
92 SIMIX_execution_finish(this);
95 simgrid::kernel::activity::ActivityImpl*
96 simgrid::kernel::activity::ExecImpl::migrate(simgrid::s4u::Host* to)
99 if (not MC_is_active() && not MC_record_replay_is_active()) {
100 surf_action_t oldAction = this->surfAction_;
101 surf_action_t newAction = to->pimpl_cpu->execution_start(oldAction->getCost());
102 newAction->setRemains(oldAction->getRemains());
103 newAction->setData(this);
104 newAction->setSharingWeight(oldAction->getPriority());
106 // FIXME: the user-defined bound seem to not be kept by LMM, that seem to overwrite it for the multi-core modeling.
107 // I hope that the user did not provide any.
109 oldAction->setData(nullptr);
112 this->surfAction_ = newAction;
115 onMigration(this, to);
123 simgrid::xbt::signal<void(simgrid::kernel::activity::ExecImplPtr)> simgrid::kernel::activity::ExecImpl::onCreation;
124 simgrid::xbt::signal<void(simgrid::kernel::activity::ExecImplPtr)> simgrid::kernel::activity::ExecImpl::onCompletion;
125 simgrid::xbt::signal<void(simgrid::kernel::activity::ExecImplPtr, simgrid::s4u::Host*)> simgrid::kernel::activity::ExecImpl::onMigration;