Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
include cleanups (mostly surf/surf.hpp)
[simgrid.git] / src / plugins / vm / VirtualMachineImpl.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 #include "simgrid/s4u/VirtualMachine.hpp"
7 #include "src/kernel/actor/ActorImpl.hpp"
8 #include "src/surf/HostImpl.hpp"
9 #include <algorithm>
10 #include <deque>
11 #include <unordered_map>
12
13 #ifndef VM_INTERFACE_HPP_
14 #define VM_INTERFACE_HPP_
15
16 namespace simgrid {
17
18 extern template class XBT_PUBLIC xbt::Extendable<vm::VirtualMachineImpl>;
19
20 namespace vm {
21
22 /************
23  * Resource *
24  ************/
25
26 /** @ingroup SURF_vm_interface
27  * @brief SURF VM interface class
28  * @details A VM represent a virtual machine
29  */
30 class XBT_PUBLIC VirtualMachineImpl : public surf::HostImpl, public simgrid::xbt::Extendable<VirtualMachineImpl> {
31 #ifndef DOXYGEN
32   friend simgrid::s4u::VirtualMachine;
33 #endif
34
35 public:
36   static std::deque<s4u::VirtualMachine*> allVms_;
37
38   explicit VirtualMachineImpl(const std::string& name, s4u::VirtualMachine* piface, s4u::Host* host, int core_amount,
39                               size_t ramsize);
40
41   void suspend(kernel::actor::ActorImpl* issuer);
42   void resume();
43   void shutdown(kernel::actor::ActorImpl* issuer);
44   void vm_destroy();
45
46   /** @brief Change the physical host on which the given VM is running */
47   void set_physical_host(s4u::Host* dest);
48   /** @brief Get the physical host on which the given VM is running */
49   s4u::Host* get_physical_host() const { return physical_host_; }
50
51   sg_size_t get_ramsize() const { return ramsize_; }
52   void set_ramsize(sg_size_t ramsize) { ramsize_ = ramsize; }
53
54   s4u::VirtualMachine::State get_state() const { return vm_state_; }
55   void set_state(s4u::VirtualMachine::State state) { vm_state_ = state; }
56
57   unsigned int get_core_amount() const { return core_amount_; }
58   kernel::resource::Action* get_action() const { return action_; }
59
60   const s4u::VirtualMachine* get_iface() const override { return piface_; }
61   s4u::VirtualMachine* get_iface() override { return piface_; }
62
63   void set_bound(double bound);
64
65   void update_action_weight();
66
67   void add_active_exec() { active_execs_++; }
68   void remove_active_exec() { active_execs_--; }
69
70   void start_migration() { is_migrating_ = true; }
71   void end_migration() { is_migrating_ = false; }
72   bool is_migrating() const { return is_migrating_; }
73
74 private:
75   s4u::VirtualMachine* piface_;
76   kernel::resource::Action* action_ = nullptr;
77   unsigned int active_execs_        = 0;
78   s4u::Host* physical_host_;
79   unsigned int core_amount_;
80   double user_bound_                   = std::numeric_limits<double>::max();
81   size_t ramsize_                      = 0;
82   s4u::VirtualMachine::State vm_state_ = s4u::VirtualMachine::State::CREATED;
83   bool is_migrating_                   = false;
84 };
85
86 /*********
87  * Model *
88  *********/
89 /** @ingroup SURF_vm_interface
90  * @brief SURF VM model interface class
91  * @details A model is an object which handle the interactions between its Resources and its Actions
92  */
93 class XBT_PRIVATE VMModel : public surf::HostModel {
94 public:
95   explicit VMModel(const std::string& name);
96
97   double next_occurring_event(double now) override;
98   void update_actions_state(double /*now*/, double /*delta*/) override{};
99   kernel::resource::Action* execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
100                                              const double* bytes_amount, double rate) override
101   {
102     return nullptr;
103   };
104 };
105 } // namespace vm
106 } // namespace simgrid
107
108 #endif /* VM_INTERFACE_HPP_ */