Logo AND Algorithmique Numérique Distribuée

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