Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Restructure surf++ cpu and network
[simgrid.git] / src / surf / cpu_ti.hpp
1 #include "cpu_interface.hpp"
2 #include "trace_mgr_private.h"
3 #include "surf/surf_routing.h"
4
5 /* Epsilon */
6 #define EPSILON 0.000000001
7
8 /***********
9  * Classes *
10  ***********/
11 class CpuTiTrace;
12 typedef CpuTiTrace *CpuTiTracePtr;
13
14 class CpuTiTgmr;
15 typedef CpuTiTgmr *CpuTiTgmrPtr;
16
17 class CpuTiModel;
18 typedef CpuTiModel *CpuTiModelPtr;
19
20 class CpuTi;
21 typedef CpuTi *CpuTiPtr;
22
23 class CpuTiAction;
24 typedef CpuTiAction *CpuTiActionPtr;
25
26 /*********
27  * Trace *
28  *********/
29 class CpuTiTrace {
30 public:
31   CpuTiTrace(tmgr_trace_t powerTrace);
32   ~CpuTiTrace();
33
34   double integrateSimple(double a, double b);
35   double integrateSimplePoint(double a);
36   double solveSimple(double a, double amount);
37
38   double *p_timePoints;
39   double *p_integral;
40   int m_nbPoints;
41   int binarySearch(double *array, double a, int low, int high);
42
43 private:
44 };
45
46 enum trace_type {
47   
48   TRACE_FIXED,                /*< Trace fixed, no availability file */
49   TRACE_DYNAMIC               /*< Dynamic, availability file disponible */
50 };
51
52 class CpuTiTgmr {
53 public:
54   CpuTiTgmr(trace_type type, double value): m_type(type), m_value(value){};
55   CpuTiTgmr(tmgr_trace_t power_trace, double value);
56   ~CpuTiTgmr();
57
58   double integrate(double a, double b);
59   double solve(double a, double amount);
60   double solveSomewhatSimple(double a, double amount);
61   double getPowerScale(double a);
62
63   trace_type m_type;
64   double m_value;                 /*< Percentage of cpu power disponible. Value fixed between 0 and 1 */
65
66   /* Dynamic */
67   double m_lastTime;             /*< Integral interval last point (discret time) */
68   double m_total;                 /*< Integral total between 0 and last_pointn */
69
70   CpuTiTracePtr p_trace;
71   tmgr_trace_t p_powerTrace;
72 };
73
74
75 /*********
76  * Model *
77  *********/
78 class CpuTiModel : public CpuModel {
79 public:
80   CpuTiModel();
81   ~CpuTiModel();
82
83   void parseInit(sg_platf_host_cbarg_t host);
84   CpuTiPtr createResource(const char *name,  xbt_dynar_t powerPeak,
85                           int pstate, double power_scale,
86                           tmgr_trace_t power_trace, int core,
87                           e_surf_resource_state_t state_initial,
88                           tmgr_trace_t state_trace,
89                           xbt_dict_t cpu_properties);
90   CpuTiActionPtr createAction(double cost, bool failed);
91   double shareResources(double now);
92   void updateActionsState(double now, double delta);
93   void addTraces();
94
95   xbt_swag_t p_runningActionSetThatDoesNotNeedBeingChecked;
96   xbt_swag_t p_modifiedCpu;
97   xbt_heap_t p_tiActionHeap;
98
99 protected:
100   void NotifyResourceTurnedOn(ResourcePtr){};
101   void NotifyResourceTurnedOff(ResourcePtr){};
102
103   void NotifyActionCancel(ActionPtr){};
104   void NotifyActionResume(ActionPtr){};
105   void NotifyActionSuspend(ActionPtr){};
106 };
107
108 /************
109  * Resource *
110  ************/
111 class CpuTi : public Cpu {
112 public:
113   CpuTi() {};
114   CpuTi(CpuTiModelPtr model, const char *name, xbt_dynar_t powerPeak,
115         int pstate, double powerScale, tmgr_trace_t powerTrace, int core,
116         e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
117         xbt_dict_t properties) ;
118   ~CpuTi();
119
120   void updateState(tmgr_trace_event_t event_type, double value, double date);  
121   void updateActionFinishDate(double now);
122   bool isUsed();
123   void printCpuTiModel();
124   CpuActionPtr execute(double size);
125   CpuTiActionPtr _execute(double size);
126   CpuActionPtr sleep(double duration);
127   double getAvailableSpeed();
128
129   xbt_dynar_t getWattsRangeList() {THROW_UNIMPLEMENTED;};
130   double getCurrentWattsValue(double /*cpu_load*/) {THROW_UNIMPLEMENTED;};
131   void updateEnergy(double /*cpu_load*/) {THROW_UNIMPLEMENTED;};
132
133   double getCurrentPowerPeak() {THROW_UNIMPLEMENTED;};
134   double getPowerPeakAt(int /*pstate_index*/) {THROW_UNIMPLEMENTED;};
135   int getNbPstates() {THROW_UNIMPLEMENTED;};
136   void setPowerPeakAt(int /*pstate_index*/) {THROW_UNIMPLEMENTED;};
137   double getConsumedEnergy() {THROW_UNIMPLEMENTED;};
138
139   CpuTiTgmrPtr p_availTrace;       /*< Structure with data needed to integrate trace file */
140   tmgr_trace_event_t p_stateEvent;       /*< trace file with states events (ON or OFF) */
141   tmgr_trace_event_t p_powerEvent;       /*< trace file with availability events */
142   xbt_swag_t p_actionSet;        /*< set with all actions running on cpu */
143   s_xbt_swag_hookup_t p_modifiedCpuHookup;      /*< hookup to swag that indicates whether share resources must be recalculated or not */
144   double m_sumPriority;          /*< the sum of actions' priority that are running on cpu */
145   double m_lastUpdate;           /*< last update of actions' remaining amount done */
146
147   int m_pstate;                                                         /*< Current pstate (index in the power_peak_list)*/
148   double current_frequency;
149
150   void updateRemainingAmount(double now);
151 };
152
153 /**********
154  * Action *
155  **********/
156
157 class CpuTiAction: public CpuAction {
158 public:
159   CpuTiAction() {};
160   CpuTiAction(CpuTiModelPtr model, double cost, bool failed)
161   : Action(model, cost, failed), CpuAction(model, cost, failed) {
162         p_cpuListHookup.next = 0;
163         p_cpuListHookup.prev = 0;
164   };
165
166   void setState(e_surf_action_state_t state);
167   int unref();
168   void cancel();
169   void recycle();
170   void updateIndexHeap(int i);
171   void suspend();
172   void resume();
173   bool isSuspended();
174   void setMaxDuration(double duration);
175   void setPriority(double priority);
176   double getRemains();
177   void setAffinity(CpuPtr /*cpu*/, unsigned long /*mask*/) {};
178   void setBound(double /*bound*/) {};
179
180   CpuTiPtr p_cpu;
181   int m_indexHeap;
182   s_xbt_swag_hookup_t p_cpuListHookup;
183   int m_suspended;
184 private:
185 };