Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Initial support MC record/replay
[simgrid.git] / src / surf / vm_workstation_interface.hpp
1 /* Copyright (c) 2004-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "workstation_interface.hpp"
8
9 #ifndef VM_WORKSTATION_INTERFACE_HPP_
10 #define VM_WORKSTATION_INTERFACE_HPP_
11
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.
14
15 /***********
16  * Classes *
17  ***********/
18
19 class WorkstationVMModel;
20 typedef WorkstationVMModel *WorkstationVMModelPtr;
21
22 class WorkstationVM;
23 typedef WorkstationVM *WorkstationVMPtr;
24
25 class WorkstationVMLmm;
26 typedef WorkstationVMLmm *WorkstationVMLmmPtr;
27
28 /*************
29  * Callbacks *
30  *************/
31
32 /** @ingroup SURF_callbacks
33  * @brief Callbacks handler which emit the callbacks after WorkstationVM creation *
34  * @details Callback functions have the following signature: `void(WorkstationVMPtr)`
35  */
36 extern surf_callback(void, WorkstationVMPtr) workstationVMCreatedCallbacks;
37
38 /** @ingroup SURF_callbacks
39  * @brief Callbacks handler which emit the callbacks after WorkstationVM destruction *
40  * @details Callback functions have the following signature: `void(WorkstationVMPtr)`
41  */
42 extern surf_callback(void, WorkstationVMPtr) workstationVMDestructedCallbacks;
43
44 /** @ingroup SURF_callbacks
45  * @brief Callbacks handler which emit the callbacks after WorkstationVM State changed *
46  * @details Callback functions have the following signature: `void(WorkstationVMActionPtr)`
47  */
48 extern surf_callback(void, WorkstationVMPtr) workstationVMStateChangedCallbacks;
49
50 /*********
51  * Model *
52  *********/
53 /** @ingroup SURF_vm_workstation_interface
54  * @brief SURF workstation VM model interface class
55  * @details A model is an object which handle the interactions between its Resources and its Actions
56  */
57 class WorkstationVMModel : public WorkstationModel {
58 public:
59   /**
60    * @brief WorkstationVMModel consrtuctor
61    */
62   WorkstationVMModel();
63
64     /**
65    * @brief WorkstationVMModel consrtuctor
66    */
67   ~WorkstationVMModel(){};
68
69   WorkstationPtr createWorkstation(const char *name){DIE_IMPOSSIBLE;}
70
71   /**
72    * @brief Create a new WorkstationVM
73    *
74    * @param name The name of the new WorkstationVM
75    * @param ind_phys_workstation The workstation hosting the VM
76    *
77    */
78   virtual WorkstationVMPtr createWorkstationVM(const char *name, surf_resource_t ind_phys_workstation)=0;
79   void adjustWeightOfDummyCpuActions() {};
80
81   typedef boost::intrusive::list<WorkstationVM,
82                                  boost::intrusive::constant_time_size<false> >
83           vm_list_t;
84   static vm_list_t ws_vms;
85 };
86
87 /************
88  * Resource *
89  ************/
90
91 /** @ingroup SURF_vm_workstation_interface
92  * @brief SURF workstation VM interface class
93  * @details A workstation VM represent an virtual machine
94  */
95 class WorkstationVM : public Workstation,
96                       public boost::intrusive::list_base_hook<> {
97 public:
98   /**
99    * @brief WorkstationVM consrtructor
100    *
101    * @param model WorkstationModel associated to this Workstation
102    * @param name The name of the Workstation
103    * @param props Dictionary of properties associated to this Workstation
104    * @param netElm The RoutingEdge associated to this Workstation
105    * @param cpu The Cpu associated to this Workstation
106    */
107   WorkstationVM(ModelPtr model, const char *name, xbt_dict_t props,
108                         RoutingEdgePtr netElm, CpuPtr cpu);
109
110   /**
111    * @brief WdorkstationVM destructor
112    */
113   ~WorkstationVM();
114
115   void setState(e_surf_resource_state_t state);
116
117   /**
118    * @brief Suspend the VM
119    */
120   virtual void suspend()=0;
121
122   /**
123    * @brief Resume the VM
124    */
125   virtual void resume()=0;
126
127   /**
128    * @brief Save the VM (Not yet implemented)
129    */
130   virtual void save()=0;
131
132   /**
133    * @brief Restore the VM (Not yet implemented)
134    */
135   virtual void restore()=0;
136
137   /**
138    * @brief Migrate the VM to the destination host
139    *
140    * @param ind_vm_ws_dest The destination host
141    */
142   virtual void migrate(surf_resource_t ind_vm_ws_dest)=0;
143
144   /**
145    * @brief Get the physical machine hosting the VM
146    * @return The physical machine hosting the VM
147    */
148   virtual surf_resource_t getPm()=0;
149
150   virtual void setBound(double bound)=0;
151   virtual void setAffinity(CpuPtr cpu, unsigned long mask)=0;
152
153   /* The workstation object of the lower layer */
154   CpuActionPtr p_action;
155   WorkstationPtr p_subWs;  // Pointer to the ''host'' OS
156   e_surf_vm_state_t p_currentState;
157 };
158
159 /**********
160  * Action *
161  **********/
162
163 #endif /* VM_WORKSTATION_INTERFACE_HPP_ */