Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'torus'
[simgrid.git] / src / surf / cpu_interface.hpp
1 /* Copyright (c) 2004-2013. 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 "surf_interface.hpp"
8 #include "maxmin_private.hpp"
9
10 #ifndef SURF_CPU_INTERFACE_HPP_
11 #define SURF_CPU_INTERFACE_HPP_
12
13 /***********
14  * Classes *
15  ***********/
16 class CpuModel;
17 typedef CpuModel *CpuModelPtr;
18
19 class Cpu;
20 typedef Cpu *CpuPtr;
21
22 class CpuAction;
23 typedef CpuAction *CpuActionPtr;
24
25 class CpuPlugin;
26 typedef CpuPlugin *CpuPluginPtr;
27
28 /*************
29  * Callbacks *
30  *************/
31 CpuPtr getActionCpu(CpuActionPtr action);
32
33 /** @ingroup SURF_callbacks
34  * @brief Callbacks handler which emit the callbacks after Cpu creation * 
35  * @detail Callback functions have the following signature: `void(CpuPtr)`
36  */
37 extern surf_callback(void, CpuPtr) createCpuCallbacks;
38
39 /** @ingroup SURF_callbacks
40  * @brief Callbacks handler which emit the callbacks after Cpu destruction * 
41  * @detail Callback functions have the following signature: `void(CpuPtr)`
42  */
43 extern surf_callback(void, CpuPtr) deleteCpuCallbacks;
44
45 /** @ingroup SURF_callbacks
46  * @brief Callbacks handler which emit the callbacks after CpuAction update * 
47  * @detail Callback functions have the following signature: `void(CpuActionPtr)`
48  */
49 extern surf_callback(void, CpuActionPtr) updateCpuActionCallbacks;
50
51 /*********
52  * Model *
53  *********/
54
55  /** @ingroup SURF_cpu_interface
56  * @brief SURF cpu model interface class
57  * @details A model is an object which handle the interactions between its Resources and its Actions
58  */
59 class CpuModel : public Model {
60 public:
61   /**
62    * @brief CpuModel constructor
63    * 
64    * @param name The name of the model
65    */
66   CpuModel(const char *name) : Model(name) {};
67
68   /**
69    * @brief Create a Cpu
70    * 
71    * @param name The name of the Cpu
72    * 
73    * @return The created Cpu
74    */
75   CpuPtr createResource(string name);
76
77
78   void updateActionsStateLazy(double now, double delta);
79   void updateActionsStateFull(double now, double delta);
80
81   virtual void addTraces() =0;
82 };
83
84 /************
85  * Resource *
86  ************/
87
88 /** @ingroup SURF_cpu_interface
89 * @brief SURF cpu resource interface class
90 * @details A Cpu represent a cpu associated to a workstation
91 */
92 class Cpu : public Resource {
93 public:
94   /**
95    * @brief Cpu constructor
96    */
97   Cpu();
98
99   /**
100    * @brief Cpu constructor
101    * 
102    * @param model The CpuModel associated to this Cpu
103    * @param name The name of the Cpu
104    * @param props Dictionary of properties associated to this Cpu
105    * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
106    * @param core The number of core of this Cpu
107    * @param powerPeak The power peak of this Cpu
108    * @param powerScale The power scale of this Cpu
109    */
110   Cpu(ModelPtr model, const char *name, xbt_dict_t props,
111           lmm_constraint_t constraint, int core, double powerPeak, double powerScale);
112
113   /**
114    * @brief Cpu constructor
115    * 
116    * @param model The CpuModel associated to this Cpu
117    * @param name The name of the Cpu
118    * @param props Dictionary of properties associated to this Cpu
119    * @param core The number of core of this Cpu
120    * @param powerPeak The power peak of this Cpu in [TODO]
121    * @param powerScale The power scale of this Cpu in [TODO]
122    */
123   Cpu(ModelPtr model, const char *name, xbt_dict_t props,
124           int core, double powerPeak, double powerScale);
125
126   /**
127    * @brieaf Cpu destructor
128    */
129   ~Cpu();
130
131   /**
132    * @brief Execute some quantity of computation
133    * 
134    * @param size The value of the processing amount (in flop) needed to process
135    * @return The CpuAction corresponding to the processing
136    */
137   virtual CpuActionPtr execute(double size)=0;
138
139   /**
140    * @brief Make a process sleep for duration (in seconds)
141    * 
142    * @param duration The number of seconds to sleep
143    * @return The CpuAction corresponding to the sleeping
144    */
145   virtual CpuActionPtr sleep(double duration)=0;
146
147   /**
148    * @brief Get the number of cores of the current Cpu
149    * 
150    * @return The number of cores of the current Cpu
151    */
152   virtual int getCore();
153
154   /**
155    * @brief Get the speed of the current Cpu
156    * @details [TODO] load * m_powerPeak
157    * 
158    * @param load [TODO]
159    * 
160    * @return The speed of the current Cpu
161    */
162   virtual double getSpeed(double load);
163
164   /**
165    * @brief Get the available speed of the current Cpu
166    * @details [TODO]
167    * 
168    * @return The available speed of the current Cpu
169    */
170   virtual double getAvailableSpeed();
171
172   /**
173    * @brief Get the current Cpu power peak
174    * 
175    * @return The current Cpu power peak
176    */
177   virtual double getCurrentPowerPeak()=0;
178
179
180   virtual double getPowerPeakAt(int pstate_index)=0;
181   
182   virtual int getNbPstates()=0;
183   
184   virtual void setPowerPeakAt(int pstate_index)=0;
185
186   void addTraces(void);
187   int m_core;
188   double m_powerPeak;            /*< CPU power peak */
189   double m_powerScale;           /*< Percentage of CPU disponible */
190
191   /* Note (hypervisor): */
192   lmm_constraint_t *p_constraintCore;
193   void **p_constraintCoreId;
194 };
195
196 /**********
197  * Action *
198  **********/
199
200  /** @ingroup SURF_cpu_interface
201  * @brief SURF Cpu action interface class
202  * @details A CpuAction represent the execution of code on a Cpu
203  */
204 class CpuAction : public Action {
205 friend CpuPtr getActionCpu(CpuActionPtr action);
206 public:
207   /**
208    * @brief CpuAction constructor
209    */
210   CpuAction(){};
211
212   /**
213    * @brief CpuAction constructor
214    * 
215    * @param model The CpuModel associated to this CpuAction
216    * @param cost [TODO]
217    * @param failed [TODO]
218    */
219   CpuAction(ModelPtr model, double cost, bool failed)
220   : Action(model, cost, failed) {} //FIXME:REMOVE
221
222   /**
223    * @brief CpuAction constructor
224    * 
225    * @param model The CpuModel associated to this CpuAction
226    * @param cost [TODO]
227    * @param failed [TODO]
228    * @param var The lmm variable associated to this CpuAction if it is part of a LMM component
229    */
230   CpuAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
231   : Action(model, cost, failed, var) {}
232
233   /**
234    * @brief Set the affinity of the current CpuAction
235    * @details [TODO]
236    * 
237    * @param cpu [TODO]
238    * @param long [TODO]
239    */
240   virtual void setAffinity(CpuPtr cpu, unsigned long mask);
241
242   /**
243    * @brief Set the bound of current CpuAction
244    * @details [TODO]
245    * 
246    * @param bound [TODO]
247    */
248   virtual void setBound(double bound);
249
250   void updateRemainingLazy(double now);
251   double m_bound;
252 };
253
254 #endif /* SURF_CPU_INTERFACE_HPP_ */