Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ns3: kill dead prototypes
[simgrid.git] / src / surf / cpu_interface.hpp
1 /* Copyright (c) 2004-2017. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SURF_CPU_INTERFACE_HPP_
7 #define SURF_CPU_INTERFACE_HPP_
8
9 #include "simgrid/s4u/Host.hpp"
10 #include "src/kernel/lmm/maxmin.hpp"
11
12 #include <list>
13
14 /***********
15  * Classes *
16  ***********/
17
18 namespace simgrid {
19 namespace surf {
20
21  /** @ingroup SURF_cpu_interface
22  * @brief SURF cpu model interface class
23  * @details A model is an object which handle the interactions between its Resources and its Actions
24  */
25 XBT_PUBLIC_CLASS CpuModel : public Model {
26 public:
27   /**
28    * @brief Create a Cpu
29    *
30    * @param host The host that will have this CPU
31    * @param speedPerPstate Processor speed (in Flops) of each pstate. This ignores any potential external load coming from a trace.
32    * @param core The number of core of this Cpu
33    */
34   virtual Cpu *createCpu(simgrid::s4u::Host *host, std::vector<double> *speedPerPstate, int core)=0;
35
36   void updateActionsStateLazy(double now, double delta) override;
37   void updateActionsStateFull(double now, double delta) override;
38 };
39
40 /************
41  * Resource *
42  ************/
43
44 /** @ingroup SURF_cpu_interface
45 * @brief SURF cpu resource interface class
46 * @details A Cpu represent a cpu associated to a host
47 */
48 XBT_PUBLIC_CLASS Cpu : public simgrid::surf::Resource {
49 public:
50   /**
51    * @brief Cpu constructor
52    *
53    * @param model The CpuModel associated to this Cpu
54    * @param host The host in which this Cpu should be plugged
55    * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
56    * @param speedPerPstate Processor speed (in flop per second) for each pstate
57    * @param core The number of core of this Cpu
58    */
59   Cpu(simgrid::surf::Model* model, simgrid::s4u::Host* host, lmm_constraint_t constraint,
60       std::vector<double>* speedPerPstate, int core);
61
62   /**
63    * @brief Cpu constructor
64    *
65    * @param model The CpuModel associated to this Cpu
66    * @param host The host in which this Cpu should be plugged
67    * @param speedPerPstate Processor speed (in flop per second) for each pstate
68    * @param core The number of core of this Cpu
69    */
70   Cpu(simgrid::surf::Model* model, simgrid::s4u::Host* host, std::vector<double>* speedPerPstate, int core);
71
72   ~Cpu();
73
74   /**
75    * @brief Execute some quantity of computation
76    *
77    * @param size The value of the processing amount (in flop) needed to process
78    * @return The CpuAction corresponding to the processing
79    */
80   virtual simgrid::surf::Action *execution_start(double size)=0;
81
82   /**
83    * @brief Execute some quantity of computation on more than one core
84    *
85    * @param size The value of the processing amount (in flop) needed to process
86    * @param requestedCores The desired amount of cores. Must be >= 1
87    * @return The CpuAction corresponding to the processing
88    */
89   virtual simgrid::surf::Action* execution_start(double size, int requestedCores)
90   {
91     THROW_UNIMPLEMENTED;
92     return nullptr;
93   }
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 getPstateSpeed(int pstate_index);
119
120   virtual int getNbPStates();
121   virtual void setPState(int pstate_index);
122   virtual int  getPState();
123
124   simgrid::s4u::Host* getHost() { return host_; }
125
126   int coresAmount_ = 1;
127   simgrid::s4u::Host* host_;
128
129   std::vector<double> speedPerPstate_; /*< List of supported CPU capacities (pstate related) */
130   int pstate_ = 0;                     /*< Current pstate (index in the speedPeakList)*/
131
132   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). */
133   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) */
134
135   tmgr_trace_event_t stateEvent_ = nullptr;
136   s_surf_metric_t speed_ = {1.0, 0, nullptr};
137 };
138
139 /**********
140  * Action *
141  **********/
142
143  /** @ingroup SURF_cpu_interface
144  * @brief A CpuAction represents the execution of code on one or several Cpus
145  */
146 XBT_PUBLIC_CLASS CpuAction : public simgrid::surf::Action {
147   friend XBT_PUBLIC(Cpu*) getActionCpu(CpuAction* action);
148
149 public:
150   /** @brief Signal emitted when the action state changes (ready/running/done, etc)
151    *  Signature: `void(CpuAction *action, simgrid::surf::Action::State previous)`
152    */
153   static simgrid::xbt::signal<void(simgrid::surf::CpuAction*, simgrid::surf::Action::State)> onStateChange;
154   /** @brief Signal emitted when the action share changes (amount of flops it gets)
155    *  Signature: `void(CpuAction *action)`
156    */
157   static simgrid::xbt::signal<void(simgrid::surf::CpuAction*)> onShareChange;
158
159   CpuAction(simgrid::surf::Model* model, double cost, bool failed) : Action(model, cost, failed) {}
160   CpuAction(simgrid::surf::Model* model, double cost, bool failed, lmm_variable_t var)
161       : Action(model, cost, failed, var)
162   {
163   }
164
165   void setState(simgrid::surf::Action::State state) override;
166
167   void updateRemainingLazy(double now) override;
168   std::list<Cpu*> cpus();
169   
170   void suspend() override;
171   void resume() override;
172 };
173
174 }
175 }
176
177 #endif /* SURF_CPU_INTERFACE_HPP_ */