Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[surf] Move storageCreatedCallbacks outside of constructor
[simgrid.git] / src / surf / cpu_interface.hpp
1 /* Copyright (c) 2004-2015. 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 class Cpu;
18 class CpuAction;
19 class CpuPlugin;
20
21 /*************
22  * Callbacks *
23  *************/
24 XBT_PUBLIC(Cpu*) getActionCpu(CpuAction *action);
25
26 /** @ingroup SURF_callbacks
27  * @brief Callbacks handler which emit the callbacks after Cpu creation *
28  * @details Callback functions have the following signature: `void(CpuPtr)`
29  */
30 XBT_PUBLIC_DATA( surf_callback(void, Cpu*)) cpuCreatedCallbacks;
31
32 /** @ingroup SURF_callbacks
33  * @brief Callbacks handler which emit the callbacks after Cpu destruction *
34  * @details Callback functions have the following signature: `void(CpuPtr)`
35  */
36 XBT_PUBLIC_DATA( surf_callback(void, Cpu*)) cpuDestructedCallbacks;
37
38 /** @ingroup SURF_callbacks
39  * @brief Callbacks handler which emit the callbacks after Cpu State changed *
40  * @details Callback functions have the following signature: `void(CpuAction *action, e_surf_resource_state_t old, e_surf_resource_state_t current)`
41  */
42 XBT_PUBLIC_DATA( surf_callback(void, Cpu*, e_surf_resource_state_t, e_surf_resource_state_t)) cpuStateChangedCallbacks;
43
44 /** @ingroup SURF_callbacks
45  * @brief Callbacks handler which emit the callbacks after CpuAction State changed *
46  * @details Callback functions have the following signature: `void(CpuAction *action, e_surf_action_state_t old, e_surf_action_state_t current)`
47  */
48 XBT_PUBLIC_DATA( surf_callback(void, CpuAction*, e_surf_action_state_t, e_surf_action_state_t)) cpuActionStateChangedCallbacks;
49
50 XBT_PUBLIC(void) cpu_parse_init(sg_platf_host_cbarg_t host);
51
52 XBT_PUBLIC(void) cpu_add_traces();
53
54 /*********
55  * Model *
56  *********/
57
58  /** @ingroup SURF_cpu_interface
59  * @brief SURF cpu model interface class
60  * @details A model is an object which handle the interactions between its Resources and its Actions
61  */
62 XBT_PUBLIC_CLASS CpuModel : public Model {
63 public:
64   CpuModel() : Model() {};
65
66   /**
67    * @brief Create a Cpu
68    *
69    * @param name The name of the Cpu
70    * @param power_peak The power peak of this Cpu
71    * @param pstate [TODO]
72    * @param power_scale The power scale of this Cpu
73    * @param power_trace [TODO]
74    * @param core The number of core of this Cpu
75    * @param state_initial [TODO]
76    * @param state_trace [TODO]
77    * @param cpu_properties Dictionary of properties associated to this Cpu
78    */
79   virtual Cpu *createCpu(const char *name, xbt_dynar_t power_peak,
80                       int pstate, double power_scale,
81                           tmgr_trace_t power_trace, int core,
82                           e_surf_resource_state_t state_initial,
83                           tmgr_trace_t state_trace,
84                           xbt_dict_t cpu_properties)=0;
85
86   void updateActionsStateLazy(double now, double delta);
87   void updateActionsStateFull(double now, double delta);
88   bool shareResourcesIsIdempotent() {return true;}
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 host
98 */
99 XBT_PUBLIC_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(Model *model, const char *name, xbt_dict_t props,
118           lmm_constraint_t constraint, int core, double powerPeak, double powerScale,
119     e_surf_resource_state_t stateInitial);
120
121   /**
122    * @brief Cpu constructor
123    *
124    * @param model The CpuModel associated to this Cpu
125    * @param name The name of the Cpu
126    * @param props Dictionary of properties associated to this Cpu
127    * @param core The number of core of this Cpu
128    * @param powerPeak The power peak of this Cpu in [TODO]
129    * @param powerScale The power scale of this Cpu in [TODO]
130    */
131   Cpu(Model *model, const char *name, xbt_dict_t props,
132           int core, double powerPeak, double powerScale,
133     e_surf_resource_state_t stateInitial);
134
135   Cpu(Model *model, const char *name, xbt_dict_t props,
136           lmm_constraint_t constraint, int core, double powerPeak, double powerScale);
137   Cpu(Model *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 CpuAction *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 CpuAction *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 setPstate(int pstate_index)=0;
199   virtual int  getPstate()=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 available */
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 XBT_PUBLIC_CLASS CpuAction : public Action {
222 friend XBT_PUBLIC(Cpu*) getActionCpu(CpuAction *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(Model *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(Model *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(Cpu *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_ */