Logo AND Algorithmique Numérique Distribuée

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