Logo AND Algorithmique Numérique Distribuée

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