Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / plugins / vm / VirtualMachineImpl.hpp
1 /* Copyright (c) 2004-2016. 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/simix/ActorImpl.hpp"
8 #include "src/surf/HostImpl.hpp"
9
10 #ifndef VM_INTERFACE_HPP_
11 #define VM_INTERFACE_HPP_
12
13 #define GUESTOS_NOISE 100 // This value corresponds to the cost of the global action associated to the VM
14                           // It corresponds to the cost of a VM running no tasks.
15
16 namespace simgrid {
17 namespace vm {
18
19 /***********
20  * Classes *
21  ***********/
22
23 class XBT_PRIVATE VMModel;
24 class XBT_PRIVATE VirtualMachineImpl;
25
26 /*************
27  * Callbacks *
28  *************/
29
30 /** @ingroup SURF_callbacks
31  * @brief Callbacks fired after VM creation. Signature: `void(VirtualMachine*)`
32  */
33 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::vm::VirtualMachineImpl*)> onVmCreation;
34
35 /** @ingroup SURF_callbacks
36  * @brief Callbacks fired after VM destruction. Signature: `void(VirtualMachine*)`
37  */
38 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::vm::VirtualMachineImpl*)> onVmDestruction;
39
40 /** @ingroup SURF_callbacks
41  * @brief Callbacks after VM State changes. Signature: `void(VirtualMachine*)`
42  */
43 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::vm::VirtualMachineImpl*)> onVmStateChange;
44
45 /************
46  * Resource *
47  ************/
48
49 /** @ingroup SURF_vm_interface
50  * @brief SURF VM interface class
51  * @details A VM represent a virtual machine
52  */
53 class VirtualMachineImpl : public surf::HostImpl {
54   friend simgrid::s4u::VirtualMachine;
55
56 public:
57   explicit VirtualMachineImpl(s4u::VirtualMachine* piface, s4u::Host* host);
58   ~VirtualMachineImpl();
59
60   /** @brief Suspend the VM */
61   virtual void suspend(simgrid::simix::ActorImpl* issuer);
62
63   /** @brief Resume the VM */
64   virtual void resume();
65
66   /** @brief Shutdown the VM */
67   virtual void shutdown(simgrid::simix::ActorImpl* issuer);
68
69   /** @brief Change the physical host on which the given VM is running */
70   virtual void setPm(s4u::Host* dest);
71
72   /** @brief Get the physical machine hosting the VM */
73   s4u::Host* getPm();
74
75   sg_size_t getRamsize();
76
77   virtual void setBound(double bound);
78
79   void getParams(vm_params_t params);
80   void setParams(vm_params_t params);
81
82   /* The vm object of the lower layer */
83   surf::Action* action_ = nullptr;
84
85   /* Dirty pages stuff */
86   int dp_enabled                     = 0;
87   xbt_dict_t dp_objs                 = nullptr;
88   double dp_updated_by_deleted_tasks = 0;
89
90 protected:
91   simgrid::s4u::Host* hostPM_;
92
93 public:
94   e_surf_vm_state_t getState();
95   void setState(e_surf_vm_state_t state);
96   static std::deque<s4u::VirtualMachine*> allVms_;
97
98   bool isMigrating = false;
99
100 private:
101   s_vm_params_t params_;
102
103 protected:
104   e_surf_vm_state_t vmState_ = SURF_VM_STATE_CREATED;
105 };
106
107 /*********
108  * Model *
109  *********/
110 /** @ingroup SURF_vm_interface
111  * @brief SURF VM model interface class
112  * @details A model is an object which handle the interactions between its Resources and its Actions
113  */
114 class VMModel : public surf::HostModel {
115 public:
116   void adjustWeightOfDummyCpuActions() override{};
117
118   double nextOccuringEvent(double now) override;
119   void updateActionsState(double /*now*/, double /*delta*/) override{};
120 };
121 }
122 }
123
124 XBT_PUBLIC_DATA(simgrid::vm::VMModel*) surf_vm_model;
125
126 #endif /* VM_INTERFACE_HPP_ */