Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill a bunch of empty ctor/dtor
[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 <list>
8
9 #include <xbt/base.h>
10 #include <xbt/signal.hpp>
11
12 #include <simgrid/forward.h>
13 #include <simgrid/s4u/host.hpp>
14
15 #include "surf/datatypes.h"
16 #include "surf_interface.hpp"
17 #include "maxmin_private.hpp"
18 #include "trace_mgr.hpp"
19
20 #ifndef SURF_CPU_INTERFACE_HPP_
21 #define SURF_CPU_INTERFACE_HPP_
22
23 /***********
24  * Classes *
25  ***********/
26
27 namespace simgrid {
28 namespace surf {
29
30 class CpuModel;
31 class Cpu;
32 class CpuAction;
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   /**
41    * @brief Create a Cpu
42    *
43    * @param host The host that will have this CPU
44    * @param speedPerPstate Processor speed (in Flops) of each pstate. This ignores any potential external load coming from a trace.
45    * @param core The number of core of this Cpu
46    */
47   virtual Cpu *createCpu(simgrid::s4u::Host *host, std::vector<double> *speedPerPstate, int core)=0;
48
49   void updateActionsStateLazy(double now, double delta) override;
50   void updateActionsStateFull(double now, double delta) override;
51 };
52
53 /************
54  * Resource *
55  ************/
56
57 /** @ingroup SURF_cpu_interface
58 * @brief SURF cpu resource interface class
59 * @details A Cpu represent a cpu associated to a host
60 */
61 XBT_PUBLIC_CLASS Cpu : public simgrid::surf::Resource {
62 public:
63   /**
64    * @brief Cpu constructor
65    *
66    * @param model The CpuModel associated to this Cpu
67    * @param host The host in which this Cpu should be plugged
68    * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
69    * @param speedPerPstate Processor speed (in flop per second) for each pstate
70    * @param core The number of core of this Cpu
71    */
72   Cpu(simgrid::surf::Model *model, simgrid::s4u::Host *host, lmm_constraint_t constraint,
73       std::vector<double> *speedPerPstate, int core);
74
75   /**
76    * @brief Cpu constructor
77    *
78    * @param model The CpuModel associated to this Cpu
79    * @param host The host in which this Cpu should be plugged
80    * @param speedPerPstate Processor speed (in flop per second) for each pstate
81    * @param core The number of core of this Cpu
82    */
83   Cpu(simgrid::surf::Model *model, simgrid::s4u::Host *host, std::vector<double> *speedPerPstate, int core);
84
85   ~Cpu();
86
87   /**
88    * @brief Execute some quantity of computation
89    *
90    * @param size The value of the processing amount (in flop) needed to process
91    * @return The CpuAction corresponding to the processing
92    */
93   virtual simgrid::surf::Action *execution_start(double size)=0;
94
95   /**
96    * @brief Make a process sleep for duration (in seconds)
97    *
98    * @param duration The number of seconds to sleep
99    * @return The CpuAction corresponding to the sleeping
100    */
101   virtual simgrid::surf::Action *sleep(double duration)=0;
102
103   /** @brief Get the amount of cores */
104   virtual int coreCount();
105
106   /** @brief Get the speed, accounting for the trace load and provided process load instead of the real current one */
107   virtual double getSpeed(double load);
108
109 protected:
110   /** @brief Take speed changes (either load or max) into account */
111   virtual void onSpeedChange();
112
113 public:
114   /** @brief Get the available speed of the current Cpu */
115   virtual double getAvailableSpeed();
116
117   /** @brief Get the current Cpu computational speed */
118   virtual double getPstateSpeedCurrent();
119   virtual double getPstateSpeed(int pstate_index);
120
121   virtual int getNbPStates();
122   virtual void setPState(int pstate_index);
123   virtual int  getPState();
124
125   simgrid::s4u::Host* getHost() { return host_; }
126
127 public:
128   int coresAmount_ = 1;
129   simgrid::s4u::Host* host_;
130
131   std::vector<double> speedPerPstate_; /*< List of supported CPU capacities (pstate related) */
132   int pstate_ = 0;                     /*< Current pstate (index in the speedPeakList)*/
133
134 public:
135   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). */
136   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) */
137
138   tmgr_trace_iterator_t stateEvent_ = nullptr;
139   s_surf_metric_t speed_ = {1.0, 0, nullptr};
140 };
141
142 /**********
143  * Action *
144  **********/
145
146  /** @ingroup SURF_cpu_interface
147  * @brief A CpuAction represents the execution of code on one or several Cpus
148  */
149 XBT_PUBLIC_CLASS CpuAction : public simgrid::surf::Action {
150 friend XBT_PUBLIC(Cpu*) getActionCpu(CpuAction *action);
151 public:
152 /** @brief Signal emitted when the action state changes (ready/running/done, etc)
153  *  Signature: `void(CpuAction *action, simgrid::surf::Action::State previous)`
154  */
155 static simgrid::xbt::signal<void(simgrid::surf::CpuAction*, simgrid::surf::Action::State)> onStateChange;
156 /** @brief Signal emitted when the action share changes (amount of flops it gets)
157  *  Signature: `void(CpuAction *action)`
158  */
159 static simgrid::xbt::signal<void(simgrid::surf::CpuAction*)> onShareChange;
160
161   CpuAction(simgrid::surf::Model *model, double cost, bool failed)
162   : Action(model, cost, failed) {}
163   CpuAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
164   : Action(model, cost, failed, var) {}
165
166   void setState(simgrid::surf::Action::State state) override;
167
168   void updateRemainingLazy(double now) override;
169   std::list<Cpu*> cpus();
170 };
171
172 }
173 }
174
175 #endif /* SURF_CPU_INTERFACE_HPP_ */