1 /* Copyright (c) 2004-2014. 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 "host_interface.hpp"
9 #ifndef VM_INTERFACE_HPP_
10 #define VM_INTERFACE_HPP_
12 #define GUESTOS_NOISE 100 // This value corresponds to the cost of the global action associated to the VM
13 // It corresponds to the cost of a VM running no tasks.
20 typedef VMModel *VMModelPtr;
26 typedef VMLmm *VMLmmPtr;
32 /** @ingroup SURF_callbacks
33 * @brief Callbacks handler which emit the callbacks after VM creation *
34 * @details Callback functions have the following signature: `void(VMPtr)`
36 extern surf_callback(void, VMPtr) VMCreatedCallbacks;
38 /** @ingroup SURF_callbacks
39 * @brief Callbacks handler which emit the callbacks after VM destruction *
40 * @details Callback functions have the following signature: `void(VMPtr)`
42 extern surf_callback(void, VMPtr) VMDestructedCallbacks;
44 /** @ingroup SURF_callbacks
45 * @brief Callbacks handler which emit the callbacks after VM State changed *
46 * @details Callback functions have the following signature: `void(VMActionPtr)`
48 extern surf_callback(void, VMPtr) VMStateChangedCallbacks;
53 /** @ingroup SURF_vm_interface
54 * @brief SURF VM model interface class
55 * @details A model is an object which handle the interactions between its Resources and its Actions
57 class VMModel : public HostModel {
62 HostPtr createHost(const char *name){DIE_IMPOSSIBLE;}
65 * @brief Create a new VM
67 * @param name The name of the new VM
68 * @param host_PM The real machine hosting the VM
71 virtual VMPtr createVM(const char *name, surf_resource_t host_PM)=0;
72 void adjustWeightOfDummyCpuActions() {};
74 typedef boost::intrusive::list<VM,
75 boost::intrusive::constant_time_size<false> >
77 static vm_list_t ws_vms;
84 /** @ingroup SURF_vm_interface
85 * @brief SURF VM interface class
86 * @details A VM represent a virtual machine
88 class VM : public Host,
89 public boost::intrusive::list_base_hook<> {
92 * @brief VM constructor
94 * @param model VMModel associated to this VM
95 * @param name The name of the VM
96 * @param props Dictionary of properties associated to this VM
97 * @param netElm The RoutingEdge associated to this VM
98 * @param cpu The Cpu associated to this VM
100 VM(ModelPtr model, const char *name, xbt_dict_t props,
101 RoutingEdgePtr netElm, CpuPtr cpu);
104 * @brief WdorkstationVM destructor
108 void setState(e_surf_resource_state_t state);
111 * @brief Suspend the VM
113 virtual void suspend()=0;
116 * @brief Resume the VM
118 virtual void resume()=0;
121 * @brief Save the VM (Not yet implemented)
123 virtual void save()=0;
126 * @brief Restore the VM (Not yet implemented)
128 virtual void restore()=0;
131 * @brief Migrate the VM to the destination host
133 * @param ind_vm_ws_dest The destination host
135 virtual void migrate(surf_resource_t ind_vm_ws_dest)=0;
138 * @brief Get the physical machine hosting the VM
139 * @return The physical machine hosting the VM
141 virtual surf_resource_t getPm()=0;
143 virtual void setBound(double bound)=0;
144 virtual void setAffinity(CpuPtr cpu, unsigned long mask)=0;
146 /* The vm object of the lower layer */
147 CpuActionPtr p_action;
148 HostPtr p_subWs; // Pointer to the ''host'' OS
149 e_surf_vm_state_t p_currentState;
156 #endif /* VM_INTERFACE_HPP_ */