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. */
9 #include "src/surf/HostImpl.hpp"
11 #ifndef VM_INTERFACE_HPP_
12 #define VM_INTERFACE_HPP_
14 #define GUESTOS_NOISE 100 // This value corresponds to the cost of the global action associated to the VM
15 // It corresponds to the cost of a VM running no tasks.
24 class XBT_PRIVATE VMModel;
25 class XBT_PRIVATE VirtualMachine;
31 /** @ingroup SURF_callbacks
32 * @brief Callbacks fired after VM creation. Signature: `void(VirtualMachine*)`
34 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> VMCreatedCallbacks;
36 /** @ingroup SURF_callbacks
37 * @brief Callbacks fired after VM destruction. Signature: `void(VirtualMachine*)`
39 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> VMDestructedCallbacks;
41 /** @ingroup SURF_callbacks
42 * @brief Callbacks after VM State changes. Signature: `void(VirtualMachine*)`
44 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> VMStateChangedCallbacks;
50 /** @ingroup SURF_vm_interface
51 * @brief SURF VM interface class
52 * @details A VM represent a virtual machine
54 class VirtualMachine : public HostImpl {
56 VirtualMachine(simgrid::surf::HostModel *model, const char *name, simgrid::s4u::Host *host);
59 /** @brief Suspend the VM */
60 virtual void suspend()=0;
62 /** @brief Resume the VM */
63 virtual void resume()=0;
65 /** @brief Save the VM (Not yet implemented) */
66 virtual void save()=0;
68 /** @brief Restore the VM (Not yet implemented) */
69 virtual void restore()=0;
71 /** @brief Migrate the VM to the destination host */
72 virtual void migrate(sg_host_t dest_PM)=0;
74 /** @brief Get the physical machine hosting the VM */
77 virtual void setBound(double bound)=0;
78 virtual void setAffinity(Cpu *cpu, unsigned long mask)=0;
80 /* The vm object of the lower layer */
83 simgrid::s4u::Host *hostPM_;
86 void turnOn() override;
87 void turnOff() override;
89 e_surf_vm_state_t getState();
90 void setState(e_surf_vm_state_t state);
92 e_surf_vm_state_t p_vm_state = SURF_VM_STATE_CREATED;
95 boost::intrusive::list_member_hook<> vm_hook;
101 /** @ingroup SURF_vm_interface
102 * @brief SURF VM model interface class
103 * @details A model is an object which handle the interactions between its Resources and its Actions
105 class VMModel : public HostModel {
107 VMModel() :HostModel(){}
111 * @brief Create a new VM
113 * @param name The name of the new VM
114 * @param host_PM The real machine hosting the VM
116 virtual VirtualMachine *createVM(const char *name, sg_host_t host_PM)=0;
117 void adjustWeightOfDummyCpuActions() {};
119 typedef boost::intrusive::member_hook<
120 VirtualMachine, boost::intrusive::list_member_hook<>, &VirtualMachine::vm_hook> VmOptions;
121 typedef boost::intrusive::list<VirtualMachine, VmOptions, boost::intrusive::constant_time_size<false> > vm_list_t;
122 static vm_list_t ws_vms;
128 #endif /* VM_INTERFACE_HPP_ */