Logo AND Algorithmique Numérique Distribuée

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