Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0a25e54fed2ad6f3a906417e198cb1667f015f4a
[simgrid.git] / src / plugins / vm / VirtualMachineImpl.hpp
1 /* Copyright (c) 2004-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <boost/intrusive/list.hpp>
8 #include <deque>
9
10 #include <xbt/base.h>
11
12 #include "simgrid/s4u/VirtualMachine.hpp"
13 #include "src/surf/HostImpl.hpp"
14
15 #ifndef VM_INTERFACE_HPP_
16 #define VM_INTERFACE_HPP_
17
18 #define GUESTOS_NOISE 100 // This value corresponds to the cost of the global action associated to the VM
19                           // It corresponds to the cost of a VM running no tasks.
20
21 namespace simgrid {
22 namespace surf {
23
24 /***********
25  * Classes *
26  ***********/
27
28 class XBT_PRIVATE VMModel;
29 class XBT_PRIVATE VirtualMachineImpl;
30
31 /*************
32  * Callbacks *
33  *************/
34
35 /** @ingroup SURF_callbacks
36  * @brief Callbacks fired after VM creation. Signature: `void(VirtualMachine*)`
37  */
38 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachineImpl*)> onVmCreation;
39
40 /** @ingroup SURF_callbacks
41  * @brief Callbacks fired after VM destruction. Signature: `void(VirtualMachine*)`
42  */
43 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachineImpl*)> onVmDestruction;
44
45 /** @ingroup SURF_callbacks
46  * @brief Callbacks after VM State changes. Signature: `void(VirtualMachine*)`
47  */
48 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachineImpl*)> onVmStateChange;
49
50 /************
51  * Resource *
52  ************/
53
54 /** @ingroup SURF_vm_interface
55  * @brief SURF VM interface class
56  * @details A VM represent a virtual machine
57  */
58 class VirtualMachineImpl : public HostImpl {
59 public:
60   explicit VirtualMachineImpl(s4u::Host* piface, s4u::Host* host);
61   ~VirtualMachineImpl();
62
63   /** @brief Suspend the VM */
64   virtual void suspend();
65
66   /** @brief Resume the VM */
67   virtual void resume();
68
69   /** @brief Save the VM (Not yet implemented) */
70   virtual void save();
71
72   /** @brief Restore the VM (Not yet implemented) */
73   virtual void restore();
74
75   /** @brief Migrate the VM to the destination host */
76   virtual void migrate(s4u::Host* dest);
77
78   /** @brief Get the physical machine hosting the VM */
79   s4u::Host* getPm();
80
81   virtual void setBound(double bound);
82
83   void getParams(vm_params_t params);
84   void setParams(vm_params_t params);
85
86   /* The vm object of the lower layer */
87   CpuAction* action_ = nullptr;
88
89   /* Dirty pages stuff */
90   int dp_enabled                     = 0;
91   xbt_dict_t dp_objs                 = nullptr;
92   double dp_updated_by_deleted_tasks = 0;
93
94 protected:
95   simgrid::s4u::Host* hostPM_;
96
97 public:
98   e_surf_vm_state_t getState();
99   void setState(e_surf_vm_state_t state);
100   static std::deque<VirtualMachineImpl*> allVms_;
101
102   bool isMigrating = false;
103
104 private:
105   s_vm_params_t params_;
106
107 protected:
108   e_surf_vm_state_t vmState_ = SURF_VM_STATE_CREATED;
109 };
110
111 /*********
112  * Model *
113  *********/
114 /** @ingroup SURF_vm_interface
115  * @brief SURF VM model interface class
116  * @details A model is an object which handle the interactions between its Resources and its Actions
117  */
118 class VMModel : public HostModel {
119 public:
120   void adjustWeightOfDummyCpuActions() override{};
121
122   double nextOccuringEvent(double now) override;
123   void updateActionsState(double /*now*/, double /*delta*/) override{};
124 };
125 }
126 }
127
128 #endif /* VM_INTERFACE_HPP_ */