1 /* Copyright (c) 2004-2016. The SimGrid Team. All rights reserved. */
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. */
6 #include "simgrid/s4u/VirtualMachine.hpp"
7 #include "src/simix/ActorImpl.hpp"
8 #include "src/surf/HostImpl.hpp"
10 #ifndef VM_INTERFACE_HPP_
11 #define VM_INTERFACE_HPP_
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.
23 class XBT_PRIVATE VMModel;
24 XBT_PUBLIC_CLASS VirtualMachineImpl; // Made visible to the Java plugin
30 /** @ingroup SURF_callbacks
31 * @brief Callbacks fired after VM creation. Signature: `void(VirtualMachine*)`
33 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::vm::VirtualMachineImpl*)> onVmCreation;
35 /** @ingroup SURF_callbacks
36 * @brief Callbacks fired after VM destruction. Signature: `void(VirtualMachine*)`
38 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::vm::VirtualMachineImpl*)> onVmDestruction;
40 /** @ingroup SURF_callbacks
41 * @brief Callbacks after VM State changes. Signature: `void(VirtualMachine*)`
43 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::vm::VirtualMachineImpl*)> onVmStateChange;
49 /** @ingroup SURF_vm_interface
50 * @brief SURF VM interface class
51 * @details A VM represent a virtual machine
53 XBT_PUBLIC_CLASS VirtualMachineImpl : public surf::HostImpl
55 friend simgrid::s4u::VirtualMachine;
58 explicit VirtualMachineImpl(s4u::VirtualMachine* piface, s4u::Host* host);
59 ~VirtualMachineImpl();
61 /** @brief Suspend the VM */
62 virtual void suspend(simgrid::simix::ActorImpl* issuer);
64 /** @brief Resume the VM */
65 virtual void resume();
67 /** @brief Shutdown the VM */
68 virtual void shutdown(simgrid::simix::ActorImpl* issuer);
70 /** @brief Change the physical host on which the given VM is running */
71 virtual void setPm(s4u::Host* dest);
73 /** @brief Get the physical machine hosting the VM */
76 sg_size_t getRamsize();
78 virtual void setBound(double bound);
80 void getParams(vm_params_t params);
81 void setParams(vm_params_t params);
83 /* The vm object of the lower layer */
84 surf::Action* action_ = nullptr;
86 /* Dirty pages stuff */
88 xbt_dict_t dp_objs = nullptr;
89 double dp_updated_by_deleted_tasks = 0;
92 simgrid::s4u::Host* hostPM_;
95 e_surf_vm_state_t getState();
96 void setState(e_surf_vm_state_t state);
97 static std::deque<s4u::VirtualMachine*> allVms_;
99 bool isMigrating = false;
102 s_vm_params_t params_;
105 e_surf_vm_state_t vmState_ = SURF_VM_STATE_CREATED;
111 /** @ingroup SURF_vm_interface
112 * @brief SURF VM model interface class
113 * @details A model is an object which handle the interactions between its Resources and its Actions
115 class VMModel : public surf::HostModel {
117 void adjustWeightOfDummyCpuActions() override{};
119 double nextOccuringEvent(double now) override;
120 void updateActionsState(double /*now*/, double /*delta*/) override{};
125 XBT_PUBLIC_DATA(simgrid::vm::VMModel*) surf_vm_model;
127 #endif /* VM_INTERFACE_HPP_ */