Logo AND Algorithmique Numérique Distribuée

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