From d5c5c81b80995b117219aa475399de9aaeef5763 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Thu, 17 May 2018 21:30:15 +0200 Subject: [PATCH 1/1] cleanups in Action::State - Rename "ready" to "inited", for symmetry to s4u::Activity - Remove the unused state "to_free" - Rename the funky state "not_in_the_system" into "ignored", and improve its documentation. Further cleanups could include not having any action set beyond the ones existing in kernel::resource::Model, so that kernel::resource::Action::get_state() see them all. CpuCas01 is the one heavily using ignored actions, as failure detectors. --- include/simgrid/kernel/resource/Action.hpp | 11 +++++------ include/simgrid/kernel/resource/Model.hpp | 12 ++++++------ src/kernel/resource/Action.cpp | 10 +++++----- src/kernel/resource/Model.cpp | 2 +- src/surf/cpu_cas01.cpp | 6 +++--- src/surf/cpu_ti.cpp | 6 +++--- src/surf/network_cm02.cpp | 2 +- teshsuite/surf/surf_usage/surf_usage.cpp | 8 ++++---- 8 files changed, 28 insertions(+), 29 deletions(-) diff --git a/include/simgrid/kernel/resource/Action.hpp b/include/simgrid/kernel/resource/Action.hpp index d482732388..95a5947f53 100644 --- a/include/simgrid/kernel/resource/Action.hpp +++ b/include/simgrid/kernel/resource/Action.hpp @@ -62,12 +62,11 @@ public: StateSet; enum class State { - ready = 0, /**< Ready */ - running, /**< Running */ - failed, /**< Task Failure */ - done, /**< Completed */ - to_free, /**< Action to free in next cleanup */ - not_in_the_system /**< Not in the system anymore. Why did you ask ? */ + inited, /**< Created, but not started yet */ + running, /**< Started, currently running */ + failed, /**< Completed (unsuccessfully: either the resource failed, or the action was canceled) */ + done, /**< Completed (successfully) */ + ignored /**< e.g. failure detectors, these infinite sleep actions that are put on resources which failure should be notified */ }; enum class SuspendStates { diff --git a/include/simgrid/kernel/resource/Model.hpp b/include/simgrid/kernel/resource/Model.hpp index 045d201d60..399a5073d7 100644 --- a/include/simgrid/kernel/resource/Model.hpp +++ b/include/simgrid/kernel/resource/Model.hpp @@ -31,8 +31,8 @@ public: virtual ~Model(); - /** @brief Get the set of [actions](@ref Action) in *ready* state */ - Action::StateSet* get_ready_action_set() const { return ready_action_set_; } + /** @brief Get the set of [actions](@ref Action) in *inited* state */ + Action::StateSet* get_inited_action_set() const { return inited_action_set_; } /** @brief Get the set of [actions](@ref Action) in *running* state */ Action::StateSet* get_running_action_set() const { return running_action_set_; } @@ -88,10 +88,10 @@ public: private: lmm::System* maxmin_system_ = nullptr; const UpdateAlgo update_algorithm_; - Action::StateSet* ready_action_set_ = new Action::StateSet(); /**< Actions in state SURF_ACTION_READY */ - Action::StateSet* running_action_set_ = new Action::StateSet(); /**< Actions in state SURF_ACTION_RUNNING */ - Action::StateSet* failed_action_set_ = new Action::StateSet(); /**< Actions in state SURF_ACTION_FAILED */ - Action::StateSet* done_action_set_ = new Action::StateSet(); /**< Actions in state SURF_ACTION_DONE */ + Action::StateSet* inited_action_set_ = new Action::StateSet(); /**< Created not started */ + Action::StateSet* running_action_set_ = new Action::StateSet(); /**< Started not done */ + Action::StateSet* failed_action_set_ = new Action::StateSet(); /**< Done with failure */ + Action::StateSet* done_action_set_ = new Action::StateSet(); /**< Done successful */ ActionHeap action_heap_; }; diff --git a/src/kernel/resource/Action.cpp b/src/kernel/resource/Action.cpp index 430c897e31..02505ea100 100644 --- a/src/kernel/resource/Action.cpp +++ b/src/kernel/resource/Action.cpp @@ -55,23 +55,23 @@ void Action::finish(Action::State state) Action::State Action::get_state() const { - if (state_set_ == model_->get_ready_action_set()) - return Action::State::ready; + if (state_set_ == model_->get_inited_action_set()) + return Action::State::inited; if (state_set_ == model_->get_running_action_set()) return Action::State::running; if (state_set_ == model_->get_failed_action_set()) return Action::State::failed; if (state_set_ == model_->get_done_action_set()) return Action::State::done; - return Action::State::not_in_the_system; + return Action::State::ignored; } void Action::set_state(Action::State state) { simgrid::xbt::intrusive_erase(*state_set_, *this); switch (state) { - case Action::State::ready: - state_set_ = model_->get_ready_action_set(); + case Action::State::inited: + state_set_ = model_->get_inited_action_set(); break; case Action::State::running: state_set_ = model_->get_running_action_set(); diff --git a/src/kernel/resource/Model.cpp b/src/kernel/resource/Model.cpp index 7f8fff9fcf..f73ee9865e 100644 --- a/src/kernel/resource/Model.cpp +++ b/src/kernel/resource/Model.cpp @@ -16,7 +16,7 @@ Model::Model(Model::UpdateAlgo algo) : update_algorithm_(algo) {} Model::~Model() { - delete ready_action_set_; + delete inited_action_set_; delete running_action_set_; delete failed_action_set_; delete done_action_set_; diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index 57eb37e1bd..e01b903371 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -151,9 +151,9 @@ void CpuCas01::apply_event(tmgr_trace_event_t event, double value) while ((var = cnst->get_variable(&elem))) { kernel::resource::Action* action = static_cast(var->get_id()); - if (action->get_state() == kernel::resource::Action::State::running || - action->get_state() == kernel::resource::Action::State::ready || - action->get_state() == kernel::resource::Action::State::not_in_the_system) { + if (action->get_state() == kernel::resource::Action::State::inited || + action->get_state() == kernel::resource::Action::State::running || + action->get_state() == kernel::resource::Action::State::ignored) { action->set_finish_time(date); action->set_state(kernel::resource::Action::State::failed); } diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index 53e49ebb82..b1928e4684 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -413,9 +413,9 @@ void CpuTi::apply_event(tmgr_trace_event_t event, double value) /* put all action running on cpu to failed */ for (CpuTiAction& action : action_set_) { - if (action.get_state() == kernel::resource::Action::State::running || - action.get_state() == kernel::resource::Action::State::ready || - action.get_state() == kernel::resource::Action::State::not_in_the_system) { + if (action.get_state() == kernel::resource::Action::State::inited || + action.get_state() == kernel::resource::Action::State::running || + action.get_state() == kernel::resource::Action::State::ignored) { action.set_finish_time(date); action.set_state(kernel::resource::Action::State::failed); get_model()->get_action_heap().remove(&action); diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index 4fde97afa7..761f90d0bf 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -349,7 +349,7 @@ void NetworkCm02Link::apply_event(tmgr_trace_event_t triggered, double value) while ((var = get_constraint()->get_variable(&elem))) { Action* action = static_cast(var->get_id()); - if (action->get_state() == Action::State::running || action->get_state() == Action::State::ready) { + if (action->get_state() == Action::State::inited || action->get_state() == Action::State::running) { action->set_finish_time(now); action->set_state(Action::State::failed); } diff --git a/teshsuite/surf/surf_usage/surf_usage.cpp b/teshsuite/surf/surf_usage/surf_usage.cpp index 153da3f99d..6299c7cf99 100644 --- a/teshsuite/surf/surf_usage/surf_usage.cpp +++ b/teshsuite/surf/surf_usage/surf_usage.cpp @@ -16,16 +16,16 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example"); static const char* string_action(simgrid::kernel::resource::Action::State state) { switch (state) { - case simgrid::kernel::resource::Action::State::ready: - return "SURF_ACTION_READY"; + case simgrid::kernel::resource::Action::State::inited: + return "SURF_ACTION_INITED"; case simgrid::kernel::resource::Action::State::running: return "SURF_ACTION_RUNNING"; case simgrid::kernel::resource::Action::State::failed: return "SURF_ACTION_FAILED"; case simgrid::kernel::resource::Action::State::done: return "SURF_ACTION_DONE"; - case simgrid::kernel::resource::Action::State::not_in_the_system: - return "SURF_ACTION_NOT_IN_THE_SYSTEM"; + case simgrid::kernel::resource::Action::State::ignored: + return "SURF_ACTION_IGNORED"; default: return "INVALID STATE"; } -- 2.20.1