Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines with new year.
[simgrid.git] / src / plugins / vm / VirtualMachineImpl.hpp
1 /* Copyright (c) 2004-2020. 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 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   friend simgrid::s4u::VirtualMachine;
29
30 public:
31   explicit VirtualMachineImpl(s4u::VirtualMachine* piface, s4u::Host* host, int core_amount, size_t ramsize);
32   ~VirtualMachineImpl();
33
34   /** @brief Callbacks fired after VM creation. Signature: `void(VirtualMachineImpl&)` */
35   static xbt::signal<void(simgrid::vm::VirtualMachineImpl&)> on_creation;
36   /** @brief Callbacks fired after VM destruction. Signature: `void(VirtualMachineImpl const&)` */
37   static xbt::signal<void(simgrid::vm::VirtualMachineImpl const&)> on_destruction;
38
39   virtual void suspend(kernel::actor::ActorImpl* issuer);
40   virtual void resume();
41   virtual void shutdown(kernel::actor::ActorImpl* issuer);
42
43   /** @brief Change the physical host on which the given VM is running */
44   virtual 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() { 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   int get_core_amount() { return core_amount_; }
55
56   virtual void set_bound(double bound);
57
58   /* The vm object of the lower layer */
59   kernel::resource::Action* action_ = nullptr;
60   static std::deque<s4u::VirtualMachine*> allVms_;
61   bool is_migrating_ = false;
62   int active_tasks_ = 0;
63
64   void update_action_weight();
65
66 private:
67   s4u::Host* physical_host_;
68   int core_amount_;
69   double user_bound_                   = std::numeric_limits<double>::max();
70   size_t ramsize_            = 0;
71   s4u::VirtualMachine::state vm_state_ = s4u::VirtualMachine::state::CREATED;
72 };
73
74 /*********
75  * Model *
76  *********/
77 /** @ingroup SURF_vm_interface
78  * @brief SURF VM model interface class
79  * @details A model is an object which handle the interactions between its Resources and its Actions
80  */
81 class XBT_PRIVATE VMModel : public surf::HostModel {
82 public:
83   VMModel();
84
85   double next_occurring_event(double now) override;
86   void update_actions_state(double /*now*/, double /*delta*/) override{};
87   kernel::resource::Action* execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
88                                              const double* bytes_amount, double rate) override
89   {
90     return nullptr;
91   };
92 };
93 }
94 }
95
96 XBT_PUBLIC_DATA simgrid::vm::VMModel* surf_vm_model;
97
98 #endif /* VM_INTERFACE_HPP_ */