1 /* Copyright (c) 2004-2018. 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 class XBT_PUBLIC VirtualMachineImpl : public surf::HostImpl, public simgrid::xbt::Extendable<VirtualMachineImpl> {
31 friend simgrid::s4u::VirtualMachine;
34 explicit VirtualMachineImpl(s4u::VirtualMachine* piface, s4u::Host* host, int core_amount, size_t ramsize);
35 ~VirtualMachineImpl();
37 /** @brief Callbacks fired after VM creation. Signature: `void(VirtualMachineImpl*)` */
38 static xbt::signal<void(simgrid::vm::VirtualMachineImpl*)> on_creation;
39 /** @brief Callbacks fired after VM destruction. Signature: `void(VirtualMachineImpl*)` */
40 static xbt::signal<void(simgrid::vm::VirtualMachineImpl*)> on_destruction;
41 /** @brief Callbacks after VM State changes. Signature: `void(VirtualMachineImpl*)` */
42 static xbt::signal<void(simgrid::vm::VirtualMachineImpl*)> on_state_change;
44 virtual void suspend(kernel::actor::ActorImpl* issuer);
45 virtual void resume();
46 virtual void shutdown(kernel::actor::ActorImpl* issuer);
48 /** @brief Change the physical host on which the given VM is running */
49 virtual void set_physical_host(s4u::Host* dest);
50 /** @brief Get the physical host on which the given VM is running */
51 s4u::Host* get_physical_host() { return physical_host_; }
53 sg_size_t get_ramsize() { return ramsize_; }
54 void set_ramsize(sg_size_t ramsize) { ramsize_ = ramsize; }
56 s4u::VirtualMachine::state get_state() { return vm_state_; }
57 void set_state(s4u::VirtualMachine::state state) { vm_state_ = state; }
59 int get_core_amount() { return core_amount_; }
61 virtual void set_bound(double bound);
63 /* The vm object of the lower layer */
64 kernel::resource::Action* action_ = nullptr;
65 static std::deque<s4u::VirtualMachine*> allVms_;
66 bool is_migrating_ = false;
69 s4u::Host* physical_host_;
72 s4u::VirtualMachine::state vm_state_ = s4u::VirtualMachine::state::CREATED;
78 /** @ingroup SURF_vm_interface
79 * @brief SURF VM model interface class
80 * @details A model is an object which handle the interactions between its Resources and its Actions
82 class XBT_PRIVATE VMModel : public surf::HostModel {
85 void ignore_empty_vm_in_pm_LMM() override{};
87 double next_occuring_event(double now) override;
88 void update_actions_state(double /*now*/, double /*delta*/) override{};
93 XBT_PUBLIC_DATA simgrid::vm::VMModel* surf_vm_model;
95 #endif /* VM_INTERFACE_HPP_ */