Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Get rid of surf_cpu_model_vm.
[simgrid.git] / include / simgrid / kernel / resource / Model.hpp
1 /* Copyright (c) 2004-2021. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef SIMGRID_KERNEL_RESOURCE_MODEL_HPP
7 #define SIMGRID_KERNEL_RESOURCE_MODEL_HPP
8
9 #include <memory>
10 #include <simgrid/kernel/resource/Action.hpp>
11 #include <unordered_map>
12
13 namespace simgrid {
14 namespace kernel {
15 namespace resource {
16
17 /** @ingroup SURF_interface
18  * @brief SURF model interface class
19  * @details A model is an object which handle the interactions between its Resources and its Actions
20  */
21 class XBT_PUBLIC Model {
22 public:
23   /** @brief Possible model types */
24   enum class Type {
25     HOST,    /**< Host models: see surf_host_model_description for more details */
26     NETWORK, /**< Network models: see surf_network_model_description for more details */
27     CPU_PM,  /**< CPU model for physical machines: see surf_cpu_model_description for more details */
28     CPU_VM,  /**< CPU model for virtual machines: see surf_cpu_model_description for more details */
29     DISK,    /**< Disk models: see surf_disk_model_description for more details */
30     VM       /**< VM model */
31   };
32
33   /** @brief Possible update mechanisms */
34   enum class UpdateAlgo {
35     FULL, /**< Full update mechanism: the remaining time of every action is recomputed at each step */
36     LAZY  /**< Lazy update mechanism: only the modified actions get recomputed.
37                    It may be slower than full if your system is tightly coupled to the point where every action
38                    gets recomputed anyway. In that case, you'd better not try to be cleaver with lazy and go for
39                    a simple full update.  */
40   };
41
42   explicit Model(Model::UpdateAlgo algo);
43   Model(const Model&) = delete;
44   Model& operator=(const Model&) = delete;
45
46   virtual ~Model();
47
48   bool is_update_lazy() const { return update_algorithm_ == UpdateAlgo::LAZY; }
49
50   /** @brief Get the set of [actions](@ref Action) in *inited* state */
51   Action::StateSet* get_inited_action_set() { return &inited_action_set_; }
52
53   /** @brief Get the set of [actions](@ref Action) in *started* state */
54   Action::StateSet* get_started_action_set() { return &started_action_set_; }
55
56   /** @brief Get the set of [actions](@ref Action) in *failed* state */
57   Action::StateSet* get_failed_action_set() { return &failed_action_set_; }
58
59   /** @brief Get the set of [actions](@ref Action) in *finished* state */
60   Action::StateSet* get_finished_action_set() { return &finished_action_set_; }
61
62   /** @brief Get the set of [actions](@ref Action) in *ignored* state */
63   Action::StateSet* get_ignored_action_set() { return &ignored_action_set_; }
64
65   /** @brief Get the set of modified [actions](@ref Action) */
66   Action::ModifiedSet* get_modified_set() const;
67
68   /** @brief Get the maxmin system of the current Model */
69   lmm::System* get_maxmin_system() const { return maxmin_system_.get(); }
70
71   /** @brief Set the maxmin system of the current Model */
72   void set_maxmin_system(lmm::System* system);
73
74   /** @brief Get the update algorithm of the current Model */
75   XBT_ATTRIB_DEPRECATED_v329("Please use is_update_lazy()") UpdateAlgo get_update_algorithm() const
76   {
77     return update_algorithm_;
78   }
79
80   /** @brief Get Action heap */
81   ActionHeap& get_action_heap() { return action_heap_; }
82
83   /**
84    * @brief Share the resources between the actions
85    *
86    * @param now The current time of the simulation
87    * @return The delta of time till the next action will finish
88    */
89   virtual double next_occurring_event(double now);
90   virtual double next_occurring_event_lazy(double now);
91   virtual double next_occurring_event_full(double now);
92
93   XBT_ATTRIB_DEPRECATED_v329("Please use next_occurring_event()") virtual double next_occuring_event(double now) final
94   {
95     return next_occurring_event(now);
96   }
97   XBT_ATTRIB_DEPRECATED_v329("Please use next_occurring_event_lazy()") virtual double next_occuring_event_lazy(
98       double now) final
99   {
100     return next_occurring_event_lazy(now);
101   }
102   XBT_ATTRIB_DEPRECATED_v329("Please use next_occurring_event_full()") virtual double next_occuring_event_full(
103       double now) final
104   {
105     return next_occurring_event_full(now);
106   }
107
108 private:
109   Action* extract_action(Action::StateSet* list);
110
111 public:
112   Action* extract_done_action();
113   Action* extract_failed_action();
114
115   /**
116    * @brief Update action to the current time
117    *
118    * @param now The current time of the simulation
119    * @param delta The delta of time since the last update
120    */
121   virtual void update_actions_state(double now, double delta);
122   virtual void update_actions_state_lazy(double now, double delta);
123   virtual void update_actions_state_full(double now, double delta);
124
125   /** @brief Returns whether this model have an idempotent share_resource()
126    *
127    * The only model that is not is ns-3: computing the next timestamp moves the model up to that point,
128    * so we need to call it only when the next timestamp of other sources is computed.
129    */
130   virtual bool next_occurring_event_is_idempotent() { return true; }
131
132   XBT_ATTRIB_DEPRECATED_v329(
133       "Please use next_occurring_event_is_idempotent()") virtual bool next_occuring_event_is_idempotent() final
134   {
135     return next_occurring_event_is_idempotent();
136   }
137
138 private:
139   std::unique_ptr<lmm::System> maxmin_system_;
140   const UpdateAlgo update_algorithm_;
141   Action::StateSet inited_action_set_;   /**< Created not started */
142   Action::StateSet started_action_set_;  /**< Started not done */
143   Action::StateSet failed_action_set_;   /**< Done with failure */
144   Action::StateSet finished_action_set_; /**< Done successful */
145   Action::StateSet ignored_action_set_;  /**< not considered (failure detectors?) */
146
147   ActionHeap action_heap_;
148 };
149
150 } // namespace resource
151 } // namespace kernel
152 } // namespace simgrid
153
154 /** @ingroup SURF_models
155  *  @brief List of initialized models
156  */
157 XBT_PUBLIC_DATA std::vector<simgrid::kernel::resource::Model*> all_existing_models;
158 /** @ingroup SURF_models
159  *  @brief Map of initialized models by category
160  */
161 XBT_PUBLIC_DATA
162 std::unordered_map<simgrid::kernel::resource::Model::Type, std::vector<simgrid::kernel::resource::Model*>>
163     models_by_type;
164
165 #endif