From: Martin Quinson Date: Sat, 10 Mar 2018 16:36:49 +0000 (+0100) Subject: Cut k/m/Resource.[ch] to its own files X-Git-Tag: v3.19~99 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/7981fe568ccfcc3c517bd73ac146d2b59fa85ea2 Cut k/m/Resource.[ch] to its own files --- diff --git a/src/kernel/model/Resource.cpp b/src/kernel/model/Resource.cpp new file mode 100644 index 0000000000..f7b290c48c --- /dev/null +++ b/src/kernel/model/Resource.cpp @@ -0,0 +1,72 @@ +/* Copyright (c) 2004-2018. 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. */ + +#include "src/kernel/model/Resource.hpp" +#include "src/kernel/lmm/maxmin.hpp" // Constraint +#include "src/surf/surf_interface.hpp" + +namespace simgrid { +namespace kernel { +namespace model { + +Resource::Resource(surf::Model* model, const std::string& name, lmm::Constraint* constraint) + : name_(name), model_(model), constraint_(constraint) +{ +} + +Resource::~Resource() = default; + +bool Resource::isOn() const +{ + return isOn_; +} +bool Resource::isOff() const +{ + return not isOn_; +} + +void Resource::turnOn() +{ + isOn_ = true; +} + +void Resource::turnOff() +{ + isOn_ = false; +} + +double Resource::getLoad() +{ + return constraint_->get_usage(); +} + +surf::Model* Resource::model() const +{ + return model_; +} + +const std::string& Resource::getName() const +{ + return name_; +} + +const char* Resource::getCname() const +{ + return name_.c_str(); +} + +bool Resource::operator==(const Resource& other) const +{ + return name_ == other.name_; +} + +kernel::lmm::Constraint* Resource::constraint() const +{ + return const_cast(constraint_); +} + +} // namespace model +} // namespace kernel +} // namespace simgrid diff --git a/src/kernel/model/Resource.hpp b/src/kernel/model/Resource.hpp new file mode 100644 index 0000000000..153325e405 --- /dev/null +++ b/src/kernel/model/Resource.hpp @@ -0,0 +1,92 @@ +/* Copyright (c) 2004-2018. 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. */ + +#ifndef SIMGRID_KERNEL_MODEL_RESOURCE_HPP +#define SIMGRID_KERNEL_MODEL_RESOURCE_HPP + +#include "src/surf/surf_interface.hpp" + +namespace simgrid { +namespace kernel { +namespace model { + +/** @ingroup SURF_interface + * @brief SURF resource interface class + * @details This is the ancestor class of every resources in SimGrid, such as links, CPU or storage + */ +XBT_PUBLIC_CLASS Resource +{ +public: + /** + * @brief Constructor of LMM Resources + * + * @param model Model associated to this Resource + * @param name The name of the Resource + * @param constraint The lmm constraint associated to this Resource if it is part of a LMM component + */ + Resource(surf::Model * model, const std::string& name, lmm::Constraint* constraint); + + virtual ~Resource(); + + /** @brief Get the Model of the current Resource */ + surf::Model* model() const; + + /** @brief Get the name of the current Resource */ + const std::string& getName() const; + /** @brief Get the name of the current Resource */ + const char* getCname() const; + + bool operator==(const Resource& other) const; + + /** + * @brief Apply an event of external load event to that resource + * + * @param event What happened + * @param value [TODO] + */ + virtual void apply_event(tmgr_trace_event_t event, double value) = 0; + + /** @brief Check if the current Resource is used (if it currently serves an action) */ + virtual bool isUsed() = 0; + + /** @brief returns the current load (in flops per second, byte per second or similar) */ + virtual double getLoad(); + + /** @brief Check if the current Resource is active */ + virtual bool isOn() const; + /** @brief Check if the current Resource is shut down */ + virtual bool isOff() const; + /** @brief Turn on the current Resource */ + virtual void turnOn(); + /** @brief Turn off the current Resource */ + virtual void turnOff(); + +private: + std::string name_; + surf::Model* model_; + bool isOn_ = true; + +public: /* LMM */ + /** @brief Get the lmm constraint associated to this Resource if it is part of a LMM component (or null if none) */ + kernel::lmm::Constraint* constraint() const; + +protected: + const kernel::lmm::Constraint* constraint_ = nullptr; +}; +} // namespace model +} // namespace kernel +} // namespace simgrid + +namespace std { +template <> class hash { +public: + std::size_t operator()(const simgrid::kernel::model::Resource& r) const + { + return (std::size_t)xbt_str_hash(r.getCname()); + } +}; +} // namespace std + +#endif diff --git a/src/s4u/s4u_storage.cpp b/src/s4u/s4u_storage.cpp index e1aabf1839..983b597ddc 100644 --- a/src/s4u/s4u_storage.cpp +++ b/src/s4u/s4u_storage.cpp @@ -7,6 +7,7 @@ #include "simgrid/s4u/Host.hpp" #include "simgrid/s4u/Storage.hpp" #include "simgrid/simix.hpp" +#include "src/kernel/model/Resource.hpp" #include "src/plugins/file_system/FileSystem.hpp" #include "src/surf/StorageImpl.hpp" #include diff --git a/src/surf/StorageImpl.hpp b/src/surf/StorageImpl.hpp index 20ccd5571f..e290906d60 100644 --- a/src/surf/StorageImpl.hpp +++ b/src/surf/StorageImpl.hpp @@ -8,6 +8,7 @@ #include #include "simgrid/s4u/Storage.hpp" +#include "src/kernel/model/Resource.hpp" #include "src/surf/PropertyHolder.hpp" #include "surf_interface.hpp" #include diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index 9a8bdde71b..1eb54c3f22 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -8,6 +8,7 @@ #include "simgrid/s4u/Host.hpp" #include "src/kernel/lmm/maxmin.hpp" +#include "src/kernel/model/Resource.hpp" #include diff --git a/src/surf/network_interface.hpp b/src/surf/network_interface.hpp index 082dc35f07..aedbde82f0 100644 --- a/src/surf/network_interface.hpp +++ b/src/surf/network_interface.hpp @@ -8,6 +8,7 @@ #include "simgrid/s4u/Link.hpp" #include "src/kernel/lmm/maxmin.hpp" +#include "src/kernel/model/Resource.hpp" #include "src/surf/PropertyHolder.hpp" #include "src/surf/surf_interface.hpp" #include "xbt/base.h" diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index d887e1f4ae..78638e2edc 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -515,66 +515,6 @@ void Model::updateActionsStateFull(double /*now*/, double /*delta*/) * Resource * ************/ -namespace simgrid { -namespace kernel { -namespace model { - -Resource::Resource(surf::Model* model, const std::string& name, lmm::Constraint* constraint) - : name_(name), model_(model), constraint_(constraint) -{} - -Resource::~Resource() = default; - -bool Resource::isOn() const { - return isOn_; -} -bool Resource::isOff() const { - return not isOn_; -} - -void Resource::turnOn() -{ - isOn_ = true; -} - -void Resource::turnOff() -{ - isOn_ = false; -} - -double Resource::getLoad() -{ - return constraint_->get_usage(); -} - -surf::Model* Resource::model() const -{ - return model_; -} - -const std::string& Resource::getName() const -{ - return name_; -} - -const char* Resource::getCname() const -{ - return name_.c_str(); -} - -bool Resource::operator==(const Resource &other) const { - return name_ == other.name_; -} - -kernel::lmm::Constraint* Resource::constraint() const -{ - return const_cast(constraint_); -} - -} -} // namespace kernel -} - /********** * Action * **********/ diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index 9c0859b2e0..adfddab53d 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -382,84 +382,5 @@ struct s_surf_metric_t { tmgr_trace_event_t event; /**< The associated trace event associated to the metric */ }; -namespace simgrid { -namespace kernel { -namespace model { - -/** @ingroup SURF_interface - * @brief SURF resource interface class - * @details This is the ancestor class of every resources in SimGrid, such as links, CPU or storage - */ -XBT_PUBLIC_CLASS Resource { -public: - /** - * @brief Constructor of LMM Resources - * - * @param model Model associated to this Resource - * @param name The name of the Resource - * @param constraint The lmm constraint associated to this Resource if it is part of a LMM component - */ - Resource(surf::Model * model, const std::string& name, lmm::Constraint* constraint); - - virtual ~Resource(); - - /** @brief Get the Model of the current Resource */ - surf::Model* model() const; - - /** @brief Get the name of the current Resource */ - const std::string& getName() const; - /** @brief Get the name of the current Resource */ - const char* getCname() const; - - bool operator==(const Resource &other) const; - - /** - * @brief Apply an event of external load event to that resource - * - * @param event What happened - * @param value [TODO] - */ - virtual void apply_event(tmgr_trace_event_t event, double value) = 0; - - /** @brief Check if the current Resource is used (if it currently serves an action) */ - virtual bool isUsed()=0; - - /** @brief returns the current load (in flops per second, byte per second or similar) */ - virtual double getLoad(); - - /** @brief Check if the current Resource is active */ - virtual bool isOn() const; - /** @brief Check if the current Resource is shut down */ - virtual bool isOff() const; - /** @brief Turn on the current Resource */ - virtual void turnOn(); - /** @brief Turn off the current Resource */ - virtual void turnOff(); - -private: - std::string name_; - surf::Model* model_; - bool isOn_ = true; - -public: /* LMM */ - /** @brief Get the lmm constraint associated to this Resource if it is part of a LMM component (or null if none) */ - kernel::lmm::Constraint* constraint() const; - -protected: - const kernel::lmm::Constraint* constraint_ = nullptr; -}; -} // namespace model -} -} - -namespace std { -template <> class hash { -public: - std::size_t operator()(const simgrid::kernel::model::Resource& r) const - { - return (std::size_t)xbt_str_hash(r.getCname()); - } -}; -} #endif /* SURF_MODEL_H_ */ diff --git a/src/surf/trace_mgr_test.cpp b/src/surf/trace_mgr_test.cpp index a63420b93e..d8bc1c94c0 100644 --- a/src/surf/trace_mgr_test.cpp +++ b/src/surf/trace_mgr_test.cpp @@ -9,6 +9,7 @@ bool init_unit_test(); // boost forget to give this prototype on NetBSD, which d #define BOOST_TEST_NO_MAIN #include +#include "src/kernel/model/Resource.hpp" #include "src/surf/surf_interface.hpp" #include "src/surf/trace_mgr.hpp" diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index ba15c8c017..b77c0a11fa 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -303,6 +303,9 @@ set(SURF_SRC src/kernel/lmm/maxmin.hpp src/kernel/lmm/maxmin.cpp + src/kernel/model/Resource.hpp + src/kernel/model/Resource.cpp + src/kernel/routing/ClusterZone.cpp src/kernel/routing/ClusterZone.hpp src/kernel/routing/DijkstraZone.cpp