Logo AND Algorithmique Numérique Distribuée

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