Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
2c6e95e9b55d1e2c43472b87992228976a6b7afc
[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 vm {
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::vm::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::vm::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::vm::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 surf::HostImpl {
59   friend simgrid::s4u::VirtualMachine;
60
61 public:
62   explicit VirtualMachineImpl(s4u::VirtualMachine* piface, s4u::Host* host);
63   ~VirtualMachineImpl();
64
65   /** @brief Suspend the VM */
66   virtual void suspend(smx_actor_t issuer);
67
68   /** @brief Resume the VM */
69   virtual void resume();
70
71   /** @brief Save (suspend+store on disk) the VM */
72   virtual void save(smx_actor_t issuer);
73
74   /** @brief Restore (read from disk+resume) the VM */
75   virtual void restore();
76
77   /** @brief Shutdown the VM */
78   virtual void shutdown(smx_actor_t issuer);
79
80   /** @brief Change the physical host on which the given VM is running */
81   virtual void setPm(s4u::Host* dest);
82
83   /** @brief Get the physical machine hosting the VM */
84   s4u::Host* getPm();
85
86   sg_size_t getRamsize();
87
88   virtual void setBound(double bound);
89
90   void getParams(vm_params_t params);
91   void setParams(vm_params_t params);
92
93   /* The vm object of the lower layer */
94   surf::Action* action_ = nullptr;
95
96   /* Dirty pages stuff */
97   int dp_enabled                     = 0;
98   xbt_dict_t dp_objs                 = nullptr;
99   double dp_updated_by_deleted_tasks = 0;
100
101 protected:
102   simgrid::s4u::Host* hostPM_;
103
104 public:
105   e_surf_vm_state_t getState();
106   void setState(e_surf_vm_state_t state);
107   static std::deque<s4u::VirtualMachine*> allVms_;
108
109   bool isMigrating = false;
110
111 private:
112   s_vm_params_t params_;
113
114 protected:
115   e_surf_vm_state_t vmState_ = SURF_VM_STATE_CREATED;
116 };
117
118 /*********
119  * Model *
120  *********/
121 /** @ingroup SURF_vm_interface
122  * @brief SURF VM model interface class
123  * @details A model is an object which handle the interactions between its Resources and its Actions
124  */
125 class VMModel : public surf::HostModel {
126 public:
127   void adjustWeightOfDummyCpuActions() override{};
128
129   double nextOccuringEvent(double now) override;
130   void updateActionsState(double /*now*/, double /*delta*/) override{};
131 };
132 }
133 }
134
135 XBT_PUBLIC_DATA(simgrid::vm::VMModel*) surf_vm_model;
136
137 #endif /* VM_INTERFACE_HPP_ */