Logo AND Algorithmique Numérique Distribuée

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