Logo AND Algorithmique Numérique Distribuée

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