1 /* Copyright (c) 2004-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include <boost/intrusive/list.hpp>
11 #include "src/surf/HostImpl.hpp"
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 class XBT_PRIVATE VMModel;
27 class XBT_PRIVATE VirtualMachine;
33 /** @ingroup SURF_callbacks
34 * @brief Callbacks fired after VM creation. Signature: `void(VirtualMachine*)`
36 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> VMCreatedCallbacks;
38 /** @ingroup SURF_callbacks
39 * @brief Callbacks fired after VM destruction. Signature: `void(VirtualMachine*)`
41 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> VMDestructedCallbacks;
43 /** @ingroup SURF_callbacks
44 * @brief Callbacks after VM State changes. Signature: `void(VirtualMachine*)`
46 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> VMStateChangedCallbacks;
52 /** @ingroup SURF_vm_interface
53 * @brief SURF VM interface class
54 * @details A VM represent a virtual machine
56 class VirtualMachine : public HostImpl {
58 VirtualMachine(simgrid::surf::HostModel *model, const char *name, simgrid::s4u::Host *host);
61 /** @brief Suspend the VM */
62 virtual void suspend()=0;
64 /** @brief Resume the VM */
65 virtual void resume()=0;
67 /** @brief Save the VM (Not yet implemented) */
68 virtual void save()=0;
70 /** @brief Restore the VM (Not yet implemented) */
71 virtual void restore()=0;
73 /** @brief Migrate the VM to the destination host */
74 virtual void migrate(sg_host_t dest_PM)=0;
76 /** @brief Get the physical machine hosting the VM */
79 virtual void setBound(double bound)=0;
80 virtual void setAffinity(Cpu *cpu, unsigned long mask)=0;
82 /* The vm object of the lower layer */
85 simgrid::s4u::Host *hostPM_;
88 void turnOn() override;
89 void turnOff() override;
91 e_surf_vm_state_t getState();
92 void setState(e_surf_vm_state_t state);
94 e_surf_vm_state_t p_vm_state = SURF_VM_STATE_CREATED;
97 boost::intrusive::list_member_hook<> vm_hook;
103 /** @ingroup SURF_vm_interface
104 * @brief SURF VM model interface class
105 * @details A model is an object which handle the interactions between its Resources and its Actions
107 class VMModel : public HostModel {
109 VMModel() :HostModel(){}
113 * @brief Create a new VM
115 * @param name The name of the new VM
116 * @param host_PM The real machine hosting the VM
118 virtual VirtualMachine *createVM(const char *name, sg_host_t host_PM)=0;
119 void adjustWeightOfDummyCpuActions() {};
121 typedef boost::intrusive::member_hook<
122 VirtualMachine, boost::intrusive::list_member_hook<>, &VirtualMachine::vm_hook> VmOptions;
123 typedef boost::intrusive::list<VirtualMachine, VmOptions, boost::intrusive::constant_time_size<false> > vm_list_t;
124 static vm_list_t ws_vms;
130 #endif /* VM_INTERFACE_HPP_ */