Logo AND Algorithmique Numérique Distribuée

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