Logo AND Algorithmique Numérique Distribuée

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