Logo AND Algorithmique Numérique Distribuée

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