Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Some #include fixes
[simgrid.git] / src / surf / virtual_machine.hpp
1 /* Copyright (c) 2004-2015. 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 <boost/intrusive/list.hpp>
8
9 #include <xbt/base.h>
10
11 #include "src/surf/HostImpl.hpp"
12
13 #ifndef VM_INTERFACE_HPP_
14 #define VM_INTERFACE_HPP_
15
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.
18
19 namespace simgrid {
20 namespace surf {
21
22 /***********
23  * Classes *
24  ***********/
25
26 class XBT_PRIVATE VMModel;
27 class XBT_PRIVATE VirtualMachine;
28
29 /*************
30  * Callbacks *
31  *************/
32
33 /** @ingroup SURF_callbacks
34  * @brief Callbacks fired after VM creation. Signature: `void(VirtualMachine*)`
35  */
36 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> VMCreatedCallbacks;
37
38 /** @ingroup SURF_callbacks
39  * @brief Callbacks fired after VM destruction. Signature: `void(VirtualMachine*)`
40  */
41 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> VMDestructedCallbacks;
42
43 /** @ingroup SURF_callbacks
44  * @brief Callbacks after VM State changes. Signature: `void(VirtualMachine*)`
45  */
46 extern XBT_PRIVATE simgrid::xbt::signal<void(simgrid::surf::VirtualMachine*)> VMStateChangedCallbacks;
47
48 /************
49  * Resource *
50  ************/
51
52 /** @ingroup SURF_vm_interface
53  * @brief SURF VM interface class
54  * @details A VM represent a virtual machine
55  */
56 class VirtualMachine : public HostImpl {
57 public:
58   VirtualMachine(simgrid::surf::HostModel *model, const char *name, simgrid::s4u::Host *host);
59   ~VirtualMachine();
60
61   /** @brief Suspend the VM */
62   virtual void suspend()=0;
63
64   /** @brief Resume the VM */
65   virtual void resume()=0;
66
67   /** @brief Save the VM (Not yet implemented) */
68   virtual void save()=0;
69
70   /** @brief Restore the VM (Not yet implemented) */
71   virtual void restore()=0;
72
73   /** @brief Migrate the VM to the destination host */
74   virtual void migrate(sg_host_t dest_PM)=0;
75
76   /** @brief Get the physical machine hosting the VM */
77   sg_host_t getPm();
78
79   virtual void setBound(double bound)=0;
80   virtual void setAffinity(Cpu *cpu, unsigned long mask)=0;
81
82   /* The vm object of the lower layer */
83   CpuAction *action_;
84 protected:
85   simgrid::s4u::Host *hostPM_;
86
87 public:
88   void turnOn() override;
89   void turnOff() override;
90
91   e_surf_vm_state_t getState();
92   void setState(e_surf_vm_state_t state);
93 protected:
94   e_surf_vm_state_t p_vm_state = SURF_VM_STATE_CREATED;
95
96 public:
97   boost::intrusive::list_member_hook<> vm_hook;
98 };
99
100 /*********
101  * Model *
102  *********/
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
106  */
107 class VMModel : public HostModel {
108 public:
109   VMModel() :HostModel(){}
110   ~VMModel(){};
111
112   /**
113    * @brief Create a new VM
114    *
115    * @param name The name of the new VM
116    * @param host_PM The real machine hosting the VM
117    */
118   virtual VirtualMachine *createVM(const char *name, sg_host_t host_PM)=0;
119   void adjustWeightOfDummyCpuActions() {};
120
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;
125 };
126
127 }
128 }
129
130 #endif /* VM_INTERFACE_HPP_ */