1 /* Copyright (c) 2004-2018. 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 #ifndef SIMGRID_KERNEL_RESOURCE_RESOURCE_HPP
7 #define SIMGRID_KERNEL_RESOURCE_RESOURCE_HPP
9 #include <simgrid/forward.h>
10 #include <xbt/signal.hpp>
12 #include <xbt/utility.hpp>
20 /** @ingroup SURF_interface
21 * @brief SURF resource interface class
22 * @details This is the ancestor class of every resources in SimGrid, such as links, CPU or storage
24 class XBT_PUBLIC Resource {
27 * @brief Constructor of LMM Resources
29 * @param model Model associated to this Resource
30 * @param name The name of the Resource
31 * @param constraint The lmm constraint associated to this Resource if it is part of a LMM component
33 Resource(Model* model, const std::string& name, lmm::Constraint* constraint);
37 /** @brief Get the Model of the current Resource */
38 Model* get_model() const;
40 /** @brief Get the name of the current Resource */
41 const std::string& get_name() const;
42 /** @brief Get the name of the current Resource */
43 const char* get_cname() const;
45 bool operator==(const Resource& other) const;
47 /** @brief Apply an event of external load event to that resource */
48 virtual void apply_event(TraceEvent* event, double value) = 0;
50 /** @brief Check if the current Resource is used (if it currently serves an action) */
51 virtual bool is_used() = 0;
53 /** @brief returns the current load (in flops per second, byte per second or similar) */
54 virtual double get_load();
56 /** @brief Check if the current Resource is active */
57 virtual bool is_on() const;
58 /** @brief Check if the current Resource is shut down */
59 virtual bool is_off() const;
60 /** @brief Turn on the current Resource */
61 virtual void turn_on();
62 /** @brief Turn off the current Resource */
63 virtual void turn_off();
71 /** @brief Get the lmm constraint associated to this Resource if it is part of a LMM component (or null if none) */
72 lmm::Constraint* get_constraint() const;
75 kernel::lmm::Constraint* const constraint_ = nullptr;
79 double peak; /**< The peak of the metric, ie its max value */
80 double scale; /**< Current availability of the metric according to the traces, in [0,1] */
81 TraceEvent* event; /**< The associated trace event associated to the metric */
84 } // namespace resource
86 } // namespace simgrid
89 template <> class hash<simgrid::kernel::resource::Resource> {
91 std::size_t operator()(const simgrid::kernel::resource::Resource& r) const
93 return (std::size_t)xbt_str_hash(r.get_cname());