1 /* Copyright (c) 2004-2023. 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>
8 #include "src/kernel/resource/HostImpl.hpp"
10 #ifndef VM_INTERFACE_HPP_
11 #define VM_INTERFACE_HPP_
15 extern template class XBT_PUBLIC xbt::Extendable<kernel::resource::VirtualMachineImpl>;
17 namespace kernel::resource {
23 class XBT_PUBLIC VirtualMachineImpl : public HostImpl, public xbt::Extendable<VirtualMachineImpl> {
25 friend s4u::VirtualMachine;
29 static std::deque<s4u::VirtualMachine*> allVms_;
31 explicit VirtualMachineImpl(const std::string& name, s4u::VirtualMachine* piface, s4u::Host* host, int core_amount,
33 explicit VirtualMachineImpl(const std::string& name, simgrid::s4u::Host* host_PM, int core_amount, size_t ramsize);
34 void set_piface(s4u::VirtualMachine* piface);
37 void suspend(const actor::ActorImpl* issuer);
39 void shutdown(kernel::actor::ActorImpl* issuer);
42 /** @brief Change the physical host on which the given VM is running */
43 void set_physical_host(s4u::Host* dest);
44 /** @brief Get the physical host on which the given VM is running */
45 s4u::Host* get_physical_host() const { return physical_host_; }
47 size_t get_ramsize() const { return ramsize_; }
48 void set_ramsize(size_t ramsize) { ramsize_ = ramsize; }
50 s4u::VirtualMachine::State get_state() const { return vm_state_; }
51 void set_state(s4u::VirtualMachine::State state) { vm_state_ = state; }
53 unsigned int get_core_amount() const { return core_amount_; }
54 Action* get_action() const { return action_; }
56 const s4u::VirtualMachine* get_iface() const override { return piface_; }
57 s4u::VirtualMachine* get_iface() override { return piface_; }
59 void set_bound(double bound);
61 void update_action_weight();
63 void add_active_exec() { active_execs_++; }
64 void remove_active_exec() { active_execs_--; }
66 void start_migration();
68 bool is_migrating() const { return is_migrating_; }
72 s4u::VirtualMachine* piface_ = nullptr;
73 Action* action_ = nullptr;
74 unsigned int active_execs_ = 0;
75 s4u::Host* physical_host_;
76 unsigned int core_amount_;
77 double user_bound_ = std::numeric_limits<double>::max();
79 s4u::VirtualMachine::State vm_state_ = s4u::VirtualMachine::State::CREATED;
80 bool is_migrating_ = false;
86 /** @ingroup Model_vm_interface
87 * @brief VM model interface class
88 * @details A model is an object which handle the interactions between its Resources and its Actions
90 class XBT_PRIVATE VMModel : public HostModel {
92 explicit VMModel(const std::string& name);
94 double next_occurring_event(double now) override;
95 void update_actions_state(double /*now*/, double /*delta*/) override{};
96 Action* execute_thread(const s4u::Host* host, double flops_amount, int thread_count) override;
97 Action* execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
98 const double* bytes_amount, double rate) override
102 Action* io_stream(s4u::Host* src_host, DiskImpl* src_disk, s4u::Host* dst_host, DiskImpl* dst_disk, double size) override { return nullptr; }
104 } // namespace kernel::resource
105 } // namespace simgrid
107 #endif /* VM_INTERFACE_HPP_ */