1 /* Copyright (c) 2015-2021. 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 #ifndef SIMGRID_S4U_VM_HPP
7 #define SIMGRID_S4U_VM_HPP
9 #include <simgrid/forward.h>
10 #include <simgrid/s4u/Host.hpp>
11 #include <xbt/utility.hpp>
16 /** @brief Host extension for the VMs */
19 static xbt::Extension<s4u::Host, VmHostExt> EXTENSION_ID;
21 sg_size_t ramsize = 0; /* available ramsize (0= not taken into account) */
22 bool overcommit = true; /* Whether the host allows overcommiting more VM than the avail ramsize allows */
23 static void ensureVmExtInstalled();
30 * A VM represents a virtual machine (or a container) that hosts actors.
31 * The total computing power that the contained actors can get is constrained to the virtual machine size.
34 class XBT_PUBLIC VirtualMachine : public s4u::Host {
35 kernel::resource::VirtualMachineImpl* const pimpl_vm_;
38 explicit VirtualMachine(const std::string& name, Host* physical_host, int core_amount);
39 explicit VirtualMachine(const std::string& name, Host* physical_host, int core_amount, size_t ramsize);
43 VirtualMachine(VirtualMachine const&) = delete;
44 VirtualMachine& operator=(VirtualMachine const&) = delete;
47 // enum class State { ... }
48 XBT_DECLARE_ENUM_CLASS(State,
49 CREATED, /**< created, but not yet started */
51 SUSPENDED, /**< Suspend/resume does not involve disk I/O, so we assume there is no transition states. */
55 using state XBT_ATTRIB_DEPRECATED_v332("Please use VirtualMachine::State") = State;
58 kernel::resource::VirtualMachineImpl* get_vm_impl() const { return pimpl_vm_; }
63 void destroy() override;
66 VirtualMachine* set_pm(Host* pm);
67 size_t get_ramsize() const;
68 VirtualMachine* set_ramsize(size_t ramsize);
69 VirtualMachine* set_bound(double bound);
71 State get_state() const;
72 static xbt::signal<void(VirtualMachine&)> on_creation;
73 static xbt::signal<void(VirtualMachine const&)> on_start;
74 static xbt::signal<void(VirtualMachine const&)> on_started;
75 static xbt::signal<void(VirtualMachine const&)> on_shutdown;
76 static xbt::signal<void(VirtualMachine const&)> on_suspend;
77 static xbt::signal<void(VirtualMachine const&)> on_resume;
78 static xbt::signal<void(VirtualMachine const&)> on_migration_start;
79 static xbt::signal<void(VirtualMachine const&)> on_migration_end;
80 static xbt::signal<void(VirtualMachine const&)> on_destruction;
83 } // namespace simgrid