Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Mark another execution path for deletion
[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
17 namespace simgrid {
18 namespace surf {
19
20 class CpuModel;
21 class Cpu;
22 class CpuAction;
23 class CpuPlugin;
24
25 /*************
26  * Callbacks *
27  *************/
28 XBT_PUBLIC(Cpu*) getActionCpu(CpuAction *action);
29
30 XBT_PUBLIC(void) cpu_add_traces();
31
32 /*********
33  * Model *
34  *********/
35
36  /** @ingroup SURF_cpu_interface
37  * @brief SURF cpu model interface class
38  * @details A model is an object which handle the interactions between its Resources and its Actions
39  */
40 XBT_PUBLIC_CLASS CpuModel : public Model {
41 public:
42   CpuModel() : Model() {};
43
44   /**
45    * @brief Create a Cpu
46    *
47    * @param name The name of the Cpu
48    * @param speedPeak The peak spead (max speed in Flops)
49    * @param pstate [TODO]
50    * @param speedScale The speed scale (in [O;1] available speed from peak)
51    * @param speedTrace Trace variations
52    * @param core The number of core of this Cpu
53    * @param state_initial [TODO]
54    * @param state_trace [TODO]
55    */
56   virtual Cpu *createCpu(simgrid::Host *host, xbt_dynar_t speedPeak,
57                       int pstate, double speedScale,
58                           tmgr_trace_t speedTrace, int core,
59                           e_surf_resource_state_t state_initial,
60                           tmgr_trace_t state_trace)=0;
61
62   void updateActionsStateLazy(double now, double delta);
63   void updateActionsStateFull(double now, double delta);
64   bool shareResourcesIsIdempotent() {return true;}
65 };
66
67 /************
68  * Resource *
69  ************/
70
71 /** @ingroup SURF_cpu_interface
72 * @brief SURF cpu resource interface class
73 * @details A Cpu represent a cpu associated to a host
74 */
75 XBT_PUBLIC_CLASS Cpu : public simgrid::surf::Resource {
76 public:
77   Cpu();
78
79   /**
80    * @brief Cpu constructor
81    *
82    * @param model The CpuModel associated to this Cpu
83    * @param host The host in which this Cpu should be plugged
84    * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
85    * @param core The number of core of this Cpu
86    * @param speedPeak The speed peak of this Cpu in flops (max speed)
87    * @param speedScale The speed scale of this Cpu in [0;1] (available amount)
88    * @param stateInitial whether it is created running or crashed
89    */
90   Cpu(simgrid::surf::Model *model, simgrid::Host *host, lmm_constraint_t constraint,
91           xbt_dynar_t speedPeakList, int pstate,
92           int core, double speedPeak, double speedScale,
93           e_surf_resource_state_t stateInitial);
94
95   /**
96    * @brief Cpu constructor
97    *
98    * @param model The CpuModel associated to this Cpu
99    * @param host The host in which this Cpu should be plugged
100    * @param core The number of core of this Cpu
101    * @param speedPeak The speed peak of this Cpu in flops (max speed)
102    * @param speedScale The speed scale of this Cpu in [0;1] (available amount)
103    * @param stateInitial whether it is created running or crashed
104    */
105   Cpu(simgrid::surf::Model *model, simgrid::Host *host,
106       xbt_dynar_t speedPeakList, int pstate,
107           int core, double speedPeak, double speedScale,
108           e_surf_resource_state_t stateInitial);
109
110   Cpu(simgrid::surf::Model *model, simgrid::Host *host, lmm_constraint_t constraint,
111           xbt_dynar_t speedPeakList, int pstate,
112           int core, double speedPeak, double speedScale);
113   Cpu(simgrid::surf::Model *model, simgrid::Host *host,
114           xbt_dynar_t speedPeakList, int pstate,
115           int core, double speedPeak, double speedScale);
116
117   ~Cpu();
118
119   /**
120    * @brief Execute some quantity of computation
121    *
122    * @param size The value of the processing amount (in flop) needed to process
123    * @return The CpuAction corresponding to the processing
124    */
125   virtual simgrid::surf::Action *execute(double size)=0;
126
127   /**
128    * @brief Make a process sleep for duration (in seconds)
129    *
130    * @param duration The number of seconds to sleep
131    * @return The CpuAction corresponding to the sleeping
132    */
133   virtual simgrid::surf::Action *sleep(double duration)=0;
134
135   /** @brief Get the amount of cores */
136   virtual int getCore();
137
138   /** @brief Get the speed, accounting for the trace load and provided process load instead of the real current one */
139   virtual double getSpeed(double load);
140
141   /** @brief Get the available speed of the current Cpu */
142   virtual double getAvailableSpeed();
143
144   /** @brief Get the current Cpu power peak */
145   virtual double getCurrentPowerPeak();
146
147   virtual double getPowerPeakAt(int pstate_index);
148
149   virtual int getNbPStates();
150   virtual void setPState(int pstate_index);
151   virtual int  getPState();
152
153   void addTraces(void);
154   simgrid::Host* getHost() { return m_host; }
155
156 public:
157   int m_core = 1;                /* Amount of cores */
158   double m_speedPeak;            /*< CPU speed peak, ie max value */
159   double m_speedScale;           /*< Percentage of CPU available according to the trace, in [O,1] */
160   simgrid::Host* m_host;
161
162   xbt_dynar_t p_speedPeakList = NULL; /*< List of supported CPU capacities (pstate related) */
163   int m_pstate = 0;                   /*< Current pstate (index in the speedPeakList)*/
164
165   /* Note (hypervisor): */
166   lmm_constraint_t *p_constraintCore=NULL;
167   void **p_constraintCoreId=NULL;
168
169 };
170
171 /**********
172  * Action *
173  **********/
174
175  /** @ingroup SURF_cpu_interface
176  * @brief SURF Cpu action interface class
177  * @details A CpuAction represent the execution of code on a Cpu
178  */
179 XBT_PUBLIC_CLASS CpuAction : public simgrid::surf::Action {
180 friend XBT_PUBLIC(Cpu*) getActionCpu(CpuAction *action);
181 public:
182 /** @brief Callbacks handler which emit the callbacks after CpuAction State changed *
183  * @details Callback functions have the following signature: `void(CpuAction *action, e_surf_action_state_t old, e_surf_action_state_t current)`
184  */
185   static simgrid::surf::signal<void(simgrid::surf::CpuAction*, e_surf_action_state_t, e_surf_action_state_t)> onStateChange;
186
187   /** @brief CpuAction constructor */
188   CpuAction(simgrid::surf::Model *model, double cost, bool failed)
189     : Action(model, cost, failed) {} //FIXME:REMOVE
190
191   /** @brief CpuAction constructor */
192   CpuAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
193     : Action(model, cost, failed, var) {}
194
195   /**
196    * @brief Set the affinity of the current CpuAction
197    * @details [TODO]
198    */
199   virtual void setAffinity(Cpu *cpu, unsigned long mask);
200
201   void setState(e_surf_action_state_t state);
202
203   void updateRemainingLazy(double now);
204
205 };
206
207 }
208 }
209
210 #endif /* SURF_CPU_INTERFACE_HPP_ */