Logo AND Algorithmique Numérique Distribuée

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