Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
this is a bool
[simgrid.git] / src / plugins / vm / VirtualMachineImpl.hpp
1 /* Copyright (c) 2004-2017. 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 s_dirty_page* dirty_page_t;
20
21 namespace simgrid {
22 namespace vm {
23
24 /*************
25  * Callbacks *
26  *************/
27
28 /** @ingroup SURF_callbacks
29  * @brief Callbacks fired after VM creation. Signature: `void(VirtualMachine*)`
30  */
31 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::vm::VirtualMachineImpl*)> onVmCreation;
32
33 /** @ingroup SURF_callbacks
34  * @brief Callbacks fired after VM destruction. Signature: `void(VirtualMachine*)`
35  */
36 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::vm::VirtualMachineImpl*)> onVmDestruction;
37
38 /** @ingroup SURF_callbacks
39  * @brief Callbacks after VM State changes. Signature: `void(VirtualMachine*)`
40  */
41 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::vm::VirtualMachineImpl*)> onVmStateChange;
42
43 /************
44  * Resource *
45  ************/
46
47 /** @ingroup SURF_vm_interface
48  * @brief SURF VM interface class
49  * @details A VM represent a virtual machine
50  */
51 XBT_PUBLIC_CLASS VirtualMachineImpl : public surf::HostImpl
52 {
53   friend simgrid::s4u::VirtualMachine;
54
55 public:
56   explicit VirtualMachineImpl(s4u::VirtualMachine * piface, s4u::Host * host, int coreAmount, size_t ramsize);
57   ~VirtualMachineImpl();
58
59   /** @brief Suspend the VM */
60   virtual void suspend(simgrid::simix::ActorImpl* issuer);
61
62   /** @brief Resume the VM */
63   virtual void resume();
64
65   /** @brief Shutdown the VM */
66   virtual void shutdown(simgrid::simix::ActorImpl* issuer);
67
68   /** @brief Change the physical host on which the given VM is running */
69   virtual void setPm(s4u::Host* dest);
70
71   /** @brief Get the physical machine hosting the VM */
72   s4u::Host* getPm();
73
74   sg_size_t getRamsize() { return ramsize_; }
75   void setRamsize(sg_size_t ramsize) { ramsize_ = ramsize; }
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   std::unordered_map<std::string, dirty_page_t> dp_objs;
87   bool dp_enabled                    = false;
88   double dp_updated_by_deleted_tasks = 0;
89
90   e_surf_vm_state_t getState();
91   void setState(e_surf_vm_state_t state);
92   static std::deque<s4u::VirtualMachine*> allVms_;
93   int coreAmount() { return coreAmount_; }
94
95   bool isMigrating = false;
96
97 private:
98   simgrid::s4u::Host* hostPM_;
99   s_vm_params_t params_;
100   int coreAmount_;
101   size_t ramsize_            = 0;
102   e_surf_vm_state_t vmState_ = SURF_VM_STATE_CREATED;
103 };
104
105 /*********
106  * Model *
107  *********/
108 /** @ingroup SURF_vm_interface
109  * @brief SURF VM model interface class
110  * @details A model is an object which handle the interactions between its Resources and its Actions
111  */
112 class XBT_PRIVATE VMModel : public surf::HostModel {
113 public:
114   VMModel();
115   void ignoreEmptyVmInPmLMM() override{};
116
117   double nextOccuringEvent(double now) override;
118   void updateActionsState(double /*now*/, double /*delta*/) override{};
119 };
120 }
121 }
122
123 XBT_PUBLIC_DATA(simgrid::vm::VMModel*) surf_vm_model;
124
125 #endif /* VM_INTERFACE_HPP_ */