Logo AND Algorithmique Numérique Distribuée

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