Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
dict to map in vms
[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 #include <algorithm>
10 #include <deque>
11 #include <unordered_map>
12
13 #ifndef VM_INTERFACE_HPP_
14 #define VM_INTERFACE_HPP_
15
16 #define GUESTOS_NOISE 100 // This value corresponds to the cost of the global action associated to the VM
17                           // It corresponds to the cost of a VM running no tasks.
18
19 typedef struct dirty_page* dirty_page_t;
20
21 namespace simgrid {
22 namespace vm {
23
24 /***********
25  * Classes *
26  ***********/
27
28 class XBT_PRIVATE VMModel;
29 XBT_PUBLIC_CLASS VirtualMachineImpl; // Made visible to the Java plugin
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 XBT_PUBLIC_CLASS VirtualMachineImpl : public surf::HostImpl
59 {
60   friend simgrid::s4u::VirtualMachine;
61
62 public:
63   explicit VirtualMachineImpl(s4u::VirtualMachine * piface, s4u::Host * host, int coreAmount);
64   ~VirtualMachineImpl();
65
66   /** @brief Suspend the VM */
67   virtual void suspend(simgrid::simix::ActorImpl* issuer);
68
69   /** @brief Resume the VM */
70   virtual void resume();
71
72   /** @brief Shutdown the VM */
73   virtual void shutdown(simgrid::simix::ActorImpl* issuer);
74
75   /** @brief Change the physical host on which the given VM is running */
76   virtual void setPm(s4u::Host* dest);
77
78   /** @brief Get the physical machine hosting the VM */
79   s4u::Host* getPm();
80
81   sg_size_t getRamsize();
82
83   virtual void setBound(double bound);
84
85   void getParams(vm_params_t params);
86   void setParams(vm_params_t params);
87
88   /* The vm object of the lower layer */
89   surf::Action* action_ = nullptr;
90
91   /* Dirty pages stuff */
92   std::unordered_map<std::string, dirty_page_t> dp_objs;
93   int dp_enabled                     = 0;
94   double dp_updated_by_deleted_tasks = 0;
95
96 protected:
97   simgrid::s4u::Host* hostPM_;
98
99 public:
100   e_surf_vm_state_t getState();
101   void setState(e_surf_vm_state_t state);
102   static std::deque<s4u::VirtualMachine*> allVms_;
103   int coreAmount() { return coreAmount_; }
104
105   bool isMigrating = false;
106
107 private:
108   s_vm_params_t params_;
109   int coreAmount_;
110
111 protected:
112   e_surf_vm_state_t vmState_ = SURF_VM_STATE_CREATED;
113 };
114
115 /*********
116  * Model *
117  *********/
118 /** @ingroup SURF_vm_interface
119  * @brief SURF VM model interface class
120  * @details A model is an object which handle the interactions between its Resources and its Actions
121  */
122 class VMModel : public surf::HostModel {
123 public:
124   void ignoreEmptyVmInPmLMM() override{};
125
126   double nextOccuringEvent(double now) override;
127   void updateActionsState(double /*now*/, double /*delta*/) override{};
128 };
129 }
130 }
131
132 XBT_PUBLIC_DATA(simgrid::vm::VMModel*) surf_vm_model;
133
134 #endif /* VM_INTERFACE_HPP_ */