X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ea74f5d95928a521a588737e81f1de94eef25d19..HEAD:/src/kernel/resource/Resource.hpp diff --git a/src/kernel/resource/Resource.hpp b/src/kernel/resource/Resource.hpp index 48f5a76691..1ed1e3541c 100644 --- a/src/kernel/resource/Resource.hpp +++ b/src/kernel/resource/Resource.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2004-2022. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2004-2023. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -7,6 +7,8 @@ #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" #include "src/kernel/resource/profile/FutureEvtSet.hpp" @@ -17,15 +19,13 @@ #include -namespace simgrid { -namespace kernel { -namespace resource { +namespace simgrid::kernel::resource { -/** @ingroup SURF_interface - * @brief SURF resource interface class +/** @ingroup Model_interface + * @brief Resource interface class * @details This is the ancestor class of every resources in SimGrid, such as links, CPU or disk */ -class XBT_PUBLIC Resource { +class XBT_PUBLIC Resource : public actor::ObjectAccessSimcallItem { std::string name_ = "unnamed"; bool is_on_ = true; bool sealed_ = false; @@ -73,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. */ @@ -102,17 +117,26 @@ public: lmm::Constraint* get_constraint() const { return constraint_; } + /** @brief Set the concurrency limit for this resource */ + virtual void set_concurrency_limit(int limit) const + { + if (limit != -1) + get_constraint()->reset_concurrency_maximum(); + get_constraint()->set_concurrency_limit(limit); + } + + /** @brief Get the concurrency limit of this resource */ + virtual int get_concurrency_limit() const { return get_constraint()->get_concurrency_limit(); } + /** @brief returns the current load due to activities (in flops per second, byte per second or similar) * * The load due to external usages modeled by profile files is ignored.*/ - virtual double get_load() const { return constraint_->get_usage(); } + virtual double get_load() const { return constraint_->get_load(); } bool is_used() const override { return model_->get_maxmin_system()->constraint_used(constraint_); } }; -} // namespace resource -} // namespace kernel -} // namespace simgrid +} // namespace simgrid::kernel::resource namespace std { template <> class hash {