Logo AND Algorithmique Numérique Distribuée

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