Logo AND Algorithmique Numérique Distribuée

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