Logo AND Algorithmique Numérique Distribuée

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