1 /* Copyright (c) 2004-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include <boost/intrusive/list.hpp>
12 #include "simgrid/s4u/VirtualMachine.hpp"
13 #include "src/surf/HostImpl.hpp"
15 #ifndef VM_INTERFACE_HPP_
16 #define VM_INTERFACE_HPP_
18 #define GUESTOS_NOISE 100 // This value corresponds to the cost of the global action associated to the VM
19 // It corresponds to the cost of a VM running no tasks.
28 class XBT_PRIVATE VMModel;
29 class XBT_PRIVATE VirtualMachineImpl;
35 /** @ingroup SURF_callbacks
36 * @brief Callbacks fired after VM creation. Signature: `void(VirtualMachine*)`
38 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::vm::VirtualMachineImpl*)> onVmCreation;
40 /** @ingroup SURF_callbacks
41 * @brief Callbacks fired after VM destruction. Signature: `void(VirtualMachine*)`
43 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::vm::VirtualMachineImpl*)> onVmDestruction;
45 /** @ingroup SURF_callbacks
46 * @brief Callbacks after VM State changes. Signature: `void(VirtualMachine*)`
48 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::vm::VirtualMachineImpl*)> onVmStateChange;
54 /** @ingroup SURF_vm_interface
55 * @brief SURF VM interface class
56 * @details A VM represent a virtual machine
58 class VirtualMachineImpl : public surf::HostImpl {
59 friend simgrid::s4u::VirtualMachine;
62 explicit VirtualMachineImpl(s4u::VirtualMachine* piface, s4u::Host* host);
63 ~VirtualMachineImpl();
65 /** @brief Suspend the VM */
66 virtual void suspend();
68 /** @brief Resume the VM */
69 virtual void resume();
71 /** @brief Save the VM (Not yet implemented) */
74 /** @brief Restore the VM (Not yet implemented) */
75 virtual void restore();
77 /** @brief Migrate the VM to the destination host */
78 virtual void migrate(s4u::Host* dest);
80 /** @brief Get the physical machine hosting the VM */
83 sg_size_t getRamsize();
85 virtual void setBound(double bound);
87 void getParams(vm_params_t params);
88 void setParams(vm_params_t params);
90 /* The vm object of the lower layer */
91 surf::Action* action_ = nullptr;
93 /* Dirty pages stuff */
95 xbt_dict_t dp_objs = nullptr;
96 double dp_updated_by_deleted_tasks = 0;
99 simgrid::s4u::Host* hostPM_;
102 e_surf_vm_state_t getState();
103 void setState(e_surf_vm_state_t state);
104 static std::deque<s4u::VirtualMachine*> allVms_;
106 bool isMigrating = false;
109 s_vm_params_t params_;
112 e_surf_vm_state_t vmState_ = SURF_VM_STATE_CREATED;
118 /** @ingroup SURF_vm_interface
119 * @brief SURF VM model interface class
120 * @details A model is an object which handle the interactions between its Resources and its Actions
122 class VMModel : public surf::HostModel {
124 void adjustWeightOfDummyCpuActions() override{};
126 double nextOccuringEvent(double now) override;
127 void updateActionsState(double /*now*/, double /*delta*/) override{};
132 #endif /* VM_INTERFACE_HPP_ */