Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ns3: no need for 2 postparse callbacks
[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;// FIXME:DEADCODE
24
25  /** @ingroup SURF_cpu_interface
26  * @brief SURF cpu model interface class
27  * @details A model is an object which handle the interactions between its Resources and its Actions
28  */
29 XBT_PUBLIC_CLASS CpuModel : public Model {
30 public:
31   CpuModel() : Model() {};
32
33   /**
34    * @brief Create a Cpu
35    *
36    * @param host The host that will have this CPU
37    * @param speedPerPstate Processor speed (in Flops) of each pstate. This ignores any potential external load coming from a trace.
38    * @param core The number of core of this Cpu
39    */
40   virtual Cpu *createCpu(simgrid::s4u::Host *host, xbt_dynar_t speedPerPstate, int core)=0;
41
42   void updateActionsStateLazy(double now, double delta);
43   void updateActionsStateFull(double now, double delta);
44   bool next_occuring_event_isIdempotent() {return true;}
45 };
46
47 /************
48  * Resource *
49  ************/
50
51 /** @ingroup SURF_cpu_interface
52 * @brief SURF cpu resource interface class
53 * @details A Cpu represent a cpu associated to a host
54 */
55 XBT_PUBLIC_CLASS Cpu : public simgrid::surf::Resource {
56 public:
57   /**
58    * @brief Cpu constructor
59    *
60    * @param model The CpuModel associated to this Cpu
61    * @param host The host in which this Cpu should be plugged
62    * @param constraint The lmm constraint associated to this Cpu if it is part of a LMM component
63    * @param speedPerPstate Processor speed (in flop per second) for each pstate
64    * @param core The number of core of this Cpu
65    */
66   Cpu(simgrid::surf::Model *model, simgrid::s4u::Host *host, lmm_constraint_t constraint, xbt_dynar_t speedPerPstate, int core);
67
68   /**
69    * @brief Cpu constructor
70    *
71    * @param model The CpuModel associated to this Cpu
72    * @param host The host in which this Cpu should be plugged
73    * @param speedPerPstate Processor speed (in flop per second) for each pstate
74    * @param core The number of core of this Cpu
75    */
76   Cpu(simgrid::surf::Model *model, simgrid::s4u::Host *host, xbt_dynar_t speedPerPstate, int core);
77
78   ~Cpu();
79
80   /**
81    * @brief Execute some quantity of computation
82    *
83    * @param size The value of the processing amount (in flop) needed to process
84    * @return The CpuAction corresponding to the processing
85    */
86   virtual simgrid::surf::Action *execution_start(double size)=0;
87
88   /**
89    * @brief Make a process sleep for duration (in seconds)
90    *
91    * @param duration The number of seconds to sleep
92    * @return The CpuAction corresponding to the sleeping
93    */
94   virtual simgrid::surf::Action *sleep(double duration)=0;
95
96   /** @brief Get the amount of cores */
97   virtual int getCore();
98
99   /** @brief Get the speed, accounting for the trace load and provided process load instead of the real current one */
100   virtual double getSpeed(double load);
101
102 protected:
103   /** @brief Take speed changes (either load or max) into account */
104   virtual void onSpeedChange();
105
106 public:
107   /** @brief Get the available speed of the current Cpu */
108   virtual double getAvailableSpeed();
109
110   /** @brief Get the current Cpu power peak */
111   virtual double getCurrentPowerPeak();
112
113   virtual double getPowerPeakAt(int pstate_index);
114
115   virtual int getNbPStates();
116   virtual void setPState(int pstate_index);
117   virtual int  getPState();
118
119   simgrid::s4u::Host* getHost() { return host_; }
120
121 public:
122   int coresAmount_ = 1;
123   simgrid::s4u::Host* host_;
124
125   xbt_dynar_t speedPerPstate_ = NULL; /*< List of supported CPU capacities (pstate related) */
126   int pstate_ = 0;                   /*< Current pstate (index in the speedPeakList)*/
127
128   /* Note (hypervisor): */
129   lmm_constraint_t *p_constraintCore=NULL;
130   void **p_constraintCoreId=NULL;
131
132 public:
133   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). */
134   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) */
135
136   tmgr_trace_iterator_t stateEvent_ = nullptr;
137   s_surf_metric_t speed_ = {1.0, 0, nullptr};
138 };
139
140 /**********
141  * Action *
142  **********/
143
144  /** @ingroup SURF_cpu_interface
145  * @brief A CpuAction represents the execution of code on one or several Cpus
146  */
147 XBT_PUBLIC_CLASS CpuAction : public simgrid::surf::Action {
148 friend XBT_PUBLIC(Cpu*) getActionCpu(CpuAction *action);
149 public:
150   /** @brief Callbacks handler which emit the callbacks after CpuAction State changed *
151    * @details Callback functions have the following 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
155   CpuAction(simgrid::surf::Model *model, double cost, bool failed)
156   : Action(model, cost, failed) {} //FIXME:DEADCODE?
157   CpuAction(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
158   : Action(model, cost, failed, var) {}
159
160   /** @brief Set the affinity of the current CpuAction */
161   virtual void setAffinity(Cpu *cpu, unsigned long mask);
162
163   void setState(simgrid::surf::Action::State state) override;
164
165   void updateRemainingLazy(double now) override;
166   std::list<Cpu*> cpus();
167 };
168
169 }
170 }
171
172 #endif /* SURF_CPU_INTERFACE_HPP_ */