1 /* Copyright (c) 2004-2017. 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"
11 #include <unordered_map>
13 #ifndef VM_INTERFACE_HPP_
14 #define VM_INTERFACE_HPP_
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.
26 /** @ingroup SURF_vm_interface
27 * @brief SURF VM interface class
28 * @details A VM represent a virtual machine
30 XBT_PUBLIC_CLASS VirtualMachineImpl : public surf::HostImpl, public simgrid::xbt::Extendable<VirtualMachineImpl>
32 friend simgrid::s4u::VirtualMachine;
35 explicit VirtualMachineImpl(s4u::VirtualMachine * piface, s4u::Host * host, int coreAmount, size_t ramsize);
36 ~VirtualMachineImpl();
38 /** @brief Suspend the VM */
39 virtual void suspend(simgrid::simix::ActorImpl* issuer);
41 /** @brief Resume the VM */
42 virtual void resume();
44 /** @brief Shutdown the VM */
45 virtual void shutdown(simgrid::simix::ActorImpl* issuer);
47 /** @brief Change the physical host on which the given VM is running */
48 virtual void setPm(s4u::Host* dest);
50 /** @brief Get the physical machine hosting the VM */
53 sg_size_t getRamsize() { return ramsize_; }
54 void setRamsize(sg_size_t ramsize) { ramsize_ = ramsize; }
56 virtual void setBound(double bound);
58 /* The vm object of the lower layer */
59 surf::Action* action_ = nullptr;
61 e_surf_vm_state_t getState();
62 void setState(e_surf_vm_state_t state);
63 static std::deque<s4u::VirtualMachine*> allVms_;
64 int coreAmount() { return coreAmount_; }
66 bool isMigrating = false;
70 /** @ingroup SURF_callbacks
71 * @brief Callbacks fired after VM creation. Signature: `void(VirtualMachine*)`
73 static simgrid::xbt::signal<void(simgrid::vm::VirtualMachineImpl*)> onVmCreation;
75 /** @ingroup SURF_callbacks
76 * @brief Callbacks fired after VM destruction. Signature: `void(VirtualMachine*)`
78 static simgrid::xbt::signal<void(simgrid::vm::VirtualMachineImpl*)> onVmDestruction;
80 /** @ingroup SURF_callbacks
81 * @brief Callbacks after VM State changes. Signature: `void(VirtualMachine*)`
83 static simgrid::xbt::signal<void(simgrid::vm::VirtualMachineImpl*)> onVmStateChange;
86 simgrid::s4u::Host* hostPM_;
89 e_surf_vm_state_t vmState_ = SURF_VM_STATE_CREATED;
95 /** @ingroup SURF_vm_interface
96 * @brief SURF VM model interface class
97 * @details A model is an object which handle the interactions between its Resources and its Actions
99 class XBT_PRIVATE VMModel : public surf::HostModel {
102 void ignoreEmptyVmInPmLMM() override{};
104 double nextOccuringEvent(double now) override;
105 void updateActionsState(double /*now*/, double /*delta*/) override{};
110 XBT_PUBLIC_DATA(simgrid::vm::VMModel*) surf_vm_model;
112 #endif /* VM_INTERFACE_HPP_ */