Logo AND Algorithmique Numérique Distribuée

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