From 9abea5188b7bc67c822270a2cb300c777d3b2727 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Thu, 8 Jun 2023 22:35:40 +0200 Subject: [PATCH] Factorize common code to cancel actions when a resource is turned off. --- src/deprecated.cpp | 2 ++ src/kernel/EngineImpl.hpp | 1 - src/kernel/resource/CpuImpl.cpp | 12 +----------- src/kernel/resource/DiskImpl.cpp | 11 +---------- src/kernel/resource/Resource.hpp | 16 ++++++++++++++++ src/kernel/resource/StandardLinkImpl.cpp | 12 +----------- src/kernel/resource/models/cpu_cas01.cpp | 14 +------------- src/kernel/resource/models/cpu_ti.cpp | 4 ++-- src/kernel/xml/sg_platf.cpp | 1 + 9 files changed, 25 insertions(+), 48 deletions(-) diff --git a/src/deprecated.cpp b/src/deprecated.cpp index 79b6a897b0..0881f549b8 100644 --- a/src/deprecated.cpp +++ b/src/deprecated.cpp @@ -16,6 +16,8 @@ #define SIMIX_H_NO_DEPRECATED_WARNING // avoid deprecation warning on include (remove with XBT_ATTRIB_DEPRECATED_v335) #include +#include + void simcall_comm_send(simgrid::kernel::actor::ActorImpl* sender, simgrid::kernel::activity::MailboxImpl* mbox, double task_size, double rate, void* src_buff, size_t src_buff_size, bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*), diff --git a/src/kernel/EngineImpl.hpp b/src/kernel/EngineImpl.hpp index 33a12ddcda..4c25e54720 100644 --- a/src/kernel/EngineImpl.hpp +++ b/src/kernel/EngineImpl.hpp @@ -19,7 +19,6 @@ #include "src/kernel/activity/SleepImpl.hpp" #include "src/kernel/activity/Synchro.hpp" #include "src/kernel/actor/ActorImpl.hpp" -#include "src/kernel/resource/SplitDuplexLinkImpl.hpp" #include #include diff --git a/src/kernel/resource/CpuImpl.cpp b/src/kernel/resource/CpuImpl.cpp index 313b3fcb11..acd7aa4a89 100644 --- a/src/kernel/resource/CpuImpl.cpp +++ b/src/kernel/resource/CpuImpl.cpp @@ -4,7 +4,6 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "src/kernel/resource/CpuImpl.hpp" -#include "src/kernel/EngineImpl.hpp" #include "src/kernel/resource/models/cpu_ti.hpp" #include "src/kernel/resource/profile/Profile.hpp" #include "src/simgrid/math_utils.h" @@ -157,16 +156,7 @@ void CpuImpl::turn_off() { if (is_on()) { Resource::turn_off(); - - const kernel::lmm::Element* elem = nullptr; - double now = EngineImpl::get_clock(); - while (const auto* var = get_constraint()->get_variable(&elem)) { - Action* action = var->get_id(); - if (action->get_state() == Action::State::INITED || action->get_state() == Action::State::STARTED) { - action->set_finish_time(now); - action->set_state(Action::State::FAILED); - } - } + cancel_actions(); } } diff --git a/src/kernel/resource/DiskImpl.cpp b/src/kernel/resource/DiskImpl.cpp index a231432488..20c23ac077 100644 --- a/src/kernel/resource/DiskImpl.cpp +++ b/src/kernel/resource/DiskImpl.cpp @@ -71,16 +71,7 @@ void DiskImpl::turn_off() Resource::turn_off(); s4u::Disk::on_onoff(piface_); piface_.on_this_onoff(piface_); - - const kernel::lmm::Element* elem = nullptr; - double now = EngineImpl::get_clock(); - while (const auto* var = get_constraint()->get_variable(&elem)) { - Action* action = var->get_id(); - if (action->get_state() == Action::State::INITED || action->get_state() == Action::State::STARTED) { - action->set_finish_time(now); - action->set_state(Action::State::FAILED); - } - } + cancel_actions(); } } diff --git a/src/kernel/resource/Resource.hpp b/src/kernel/resource/Resource.hpp index 9e2f2842fc..1ed1e3541c 100644 --- a/src/kernel/resource/Resource.hpp +++ b/src/kernel/resource/Resource.hpp @@ -7,6 +7,7 @@ #define SIMGRID_KERNEL_RESOURCE_RESOURCE_HPP #include "simgrid/forward.h" +#include "src/kernel/EngineImpl.hpp" #include "src/kernel/actor/Simcall.hpp" #include "src/kernel/lmm/maxmin.hpp" // Constraint #include "src/kernel/resource/profile/Event.hpp" @@ -72,6 +73,21 @@ template class Resource_T : public Resource { Model* model_ = nullptr; lmm::Constraint* constraint_ = nullptr; +protected: + void cancel_actions() + { + const kernel::lmm::Element* elem = nullptr; + double now = EngineImpl::get_clock(); + while (const auto* var = get_constraint()->get_variable(&elem)) { + Action* action = var->get_id(); + if (action->get_state() == Action::State::INITED || action->get_state() == Action::State::STARTED || + action->get_state() == Action::State::IGNORED) { + action->set_finish_time(now); + action->set_state(Action::State::FAILED); + } + } + } + public: using Resource::Resource; /** @brief setup the profile file with states events (ON or OFF). The profile must contain boolean values. */ diff --git a/src/kernel/resource/StandardLinkImpl.cpp b/src/kernel/resource/StandardLinkImpl.cpp index a7661a1ab7..9df40d0924 100644 --- a/src/kernel/resource/StandardLinkImpl.cpp +++ b/src/kernel/resource/StandardLinkImpl.cpp @@ -5,7 +5,6 @@ #include -#include "src/kernel/EngineImpl.hpp" #include "src/kernel/resource/StandardLinkImpl.hpp" #include @@ -93,16 +92,7 @@ void StandardLinkImpl::turn_off() Resource::turn_off(); s4u::Link::on_onoff(piface_); piface_.on_this_onoff(piface_); - - const kernel::lmm::Element* elem = nullptr; - double now = EngineImpl::get_clock(); - while (const auto* var = get_constraint()->get_variable(&elem)) { - Action* action = var->get_id(); - if (action->get_state() == Action::State::INITED || action->get_state() == Action::State::STARTED) { - action->set_finish_time(now); - action->set_state(Action::State::FAILED); - } - } + cancel_actions(); } } diff --git a/src/kernel/resource/models/cpu_cas01.cpp b/src/kernel/resource/models/cpu_cas01.cpp index c9386243f9..35af6fa8f1 100644 --- a/src/kernel/resource/models/cpu_cas01.cpp +++ b/src/kernel/resource/models/cpu_cas01.cpp @@ -113,20 +113,8 @@ void CpuCas01::apply_event(profile::Event* event, double value) get_iface()->turn_on(); } } else { - const lmm::Element* elem = nullptr; - double date = EngineImpl::get_clock(); - get_iface()->turn_off(); - - while (const auto* var = get_constraint()->get_variable(&elem)) { - Action* action = var->get_id(); - - if (action->get_state() == Action::State::INITED || action->get_state() == Action::State::STARTED || - action->get_state() == Action::State::IGNORED) { - action->set_finish_time(date); - action->set_state(Action::State::FAILED); - } - } + cancel_actions(); } unref_state_event(); diff --git a/src/kernel/resource/models/cpu_ti.cpp b/src/kernel/resource/models/cpu_ti.cpp index c927bece8c..6b522bb296 100644 --- a/src/kernel/resource/models/cpu_ti.cpp +++ b/src/kernel/resource/models/cpu_ti.cpp @@ -387,13 +387,13 @@ void CpuTi::apply_event(kernel::profile::Event* event, double value) } } else { get_iface()->turn_off(); - double date = EngineImpl::get_clock(); /* put all action running on cpu to failed */ + double now = EngineImpl::get_clock(); for (CpuTiAction& action : action_set_) { if (action.get_state() == Action::State::INITED || action.get_state() == Action::State::STARTED || action.get_state() == Action::State::IGNORED) { - action.set_finish_time(date); + action.set_finish_time(now); action.set_state(Action::State::FAILED); get_model()->get_action_heap().remove(&action); } diff --git a/src/kernel/xml/sg_platf.cpp b/src/kernel/xml/sg_platf.cpp index 0d64feb5ab..b4b4a3294b 100644 --- a/src/kernel/xml/sg_platf.cpp +++ b/src/kernel/xml/sg_platf.cpp @@ -23,6 +23,7 @@ #include "src/kernel/EngineImpl.hpp" #include "src/kernel/resource/DiskImpl.hpp" #include "src/kernel/resource/HostImpl.hpp" +#include "src/kernel/resource/StandardLinkImpl.hpp" #include "src/kernel/resource/profile/Profile.hpp" #include "src/kernel/xml/platf.hpp" #include "src/kernel/xml/platf_private.hpp" -- 2.20.1