1 /* Copyright (c) 2004-2021. 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 disk
24 class XBT_PUBLIC Resource {
25 std::string name_ = "unnamed";
26 Model* model_ = nullptr;
29 lmm::Constraint* constraint_ = nullptr;
33 double peak; /**< The peak of the metric, ie its max value */
34 double scale; /**< Current availability of the metric according to the profiles, in [0,1] */
35 profile::Event* event; /**< The associated profile event associated to the metric */
37 profile::Event* state_event_ = nullptr;
41 virtual ~Resource() = default;
43 /** @brief Get the Model of the current Resource */
44 Model* get_model() const { return model_; }
45 Resource* set_model(Model* model);
47 /** @brief Get the name of the current Resource */
48 const std::string& get_name() const { return name_; }
49 /** @brief Get the name of the current Resource */
50 const char* get_cname() const { return name_.c_str(); }
51 Resource* set_name(const std::string& name);
53 /** @brief Get the lmm constraint associated to this Resource if it is part of a LMM component (or null if none) */
54 lmm::Constraint* get_constraint() const { return constraint_; }
55 Resource* set_constraint(lmm::Constraint* constraint);
57 bool operator==(const Resource& other) const { return name_ == other.name_; }
59 /** @brief Apply an event of external load event to that resource */
60 virtual void apply_event(profile::Event* event, double value) = 0;
62 /** @brief Check if the current Resource is used (if it currently serves an action) */
63 virtual bool is_used() const = 0;
65 /** @brief returns the current load due to activities (in flops per second, byte per second or similar)
67 * The load due to external usages modeled by profile files is ignored.*/
68 virtual double get_load() const;
70 /** @brief Check if the current Resource is active */
71 virtual bool is_on() const { return is_on_; }
72 /** @brief Turn on the current Resource */
73 virtual void turn_on() { is_on_ = true; }
74 /** @brief Turn off the current Resource */
75 virtual void turn_off() { is_on_ = false; }
76 /** @brief setup the profile file with states events (ON or OFF). The profile must contain boolean values. */
77 virtual void set_state_profile(profile::Profile* profile);
80 } // namespace resource
82 } // namespace simgrid
85 template <> class hash<simgrid::kernel::resource::Resource> {
87 std::size_t operator()(const simgrid::kernel::resource::Resource& r) const
89 return (std::size_t)xbt_str_hash(r.get_cname());