Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Energy is now a plugin
[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  * Model *
76  *********/
77 class CpuTiModel : public CpuModel {
78 public:
79   CpuTiModel();
80   ~CpuTiModel();
81
82   void parseInit(sg_platf_host_cbarg_t host);
83   CpuTiPtr createResource(const char *name,  xbt_dynar_t powerPeak,
84                           int pstate, double power_scale,
85                           tmgr_trace_t power_trace, int core,
86                           e_surf_resource_state_t state_initial,
87                           tmgr_trace_t state_trace,
88                           xbt_dict_t cpu_properties);
89   CpuTiActionPtr createAction(double cost, bool failed);
90   double shareResources(double now);
91   void updateActionsState(double now, double delta);
92   void addTraces();
93
94   ActionListPtr p_runningActionSetThatDoesNotNeedBeingChecked;
95   xbt_swag_t p_modifiedCpu;
96   xbt_heap_t p_tiActionHeap;
97
98 protected:
99   void NotifyResourceTurnedOn(ResourcePtr){};
100   void NotifyResourceTurnedOff(ResourcePtr){};
101
102   void NotifyActionCancel(ActionPtr){};
103   void NotifyActionResume(ActionPtr){};
104   void NotifyActionSuspend(ActionPtr){};
105 };
106
107 /************
108  * Resource *
109  ************/
110 class CpuTi : public Cpu {
111 public:
112   CpuTi() {};
113   CpuTi(CpuTiModelPtr model, const char *name, xbt_dynar_t powerPeak,
114         int pstate, double powerScale, tmgr_trace_t powerTrace, int core,
115         e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
116         xbt_dict_t properties) ;
117   ~CpuTi();
118
119   void updateState(tmgr_trace_event_t event_type, double value, double date);  
120   void updateActionsFinishTime(double now);
121   bool isUsed();
122   void printCpuTiModel();
123   CpuActionPtr execute(double size);
124   CpuActionPtr sleep(double duration);
125   double getAvailableSpeed();
126
127   double getCurrentPowerPeak() {THROW_UNIMPLEMENTED;};
128   double getPowerPeakAt(int /*pstate_index*/) {THROW_UNIMPLEMENTED;};
129   int getNbPstates() {THROW_UNIMPLEMENTED;};
130   void setPowerPeakAt(int /*pstate_index*/) {THROW_UNIMPLEMENTED;};
131
132   CpuTiTgmrPtr p_availTrace;       /*< Structure with data needed to integrate trace file */
133   tmgr_trace_event_t p_stateEvent;       /*< trace file with states events (ON or OFF) */
134   tmgr_trace_event_t p_powerEvent;       /*< trace file with availability events */
135   xbt_swag_t p_actionSet;        /*< set with all actions running on cpu */
136   s_xbt_swag_hookup_t p_modifiedCpuHookup;      /*< hookup to swag that indicates whether share resources must be recalculated or not */
137   double m_sumPriority;          /*< the sum of actions' priority that are running on cpu */
138   double m_lastUpdate;           /*< last update of actions' remaining amount done */
139
140   int m_pstate;                                                         /*< Current pstate (index in the power_peak_list)*/
141   double current_frequency;
142
143   void updateRemainingAmount(double now);
144 };
145
146 /**********
147  * Action *
148  **********/
149
150 class CpuTiAction: public CpuAction {
151   friend CpuActionPtr CpuTi::execute(double size);
152   friend CpuActionPtr CpuTi::sleep(double duration);
153   friend void CpuTi::updateActionsFinishTime(double now);//FIXME
154   friend void CpuTi::updateRemainingAmount(double now);//FIXME
155
156 public:
157   CpuTiAction() {};
158   CpuTiAction(CpuTiModelPtr model, double cost, bool failed,
159                                  CpuTiPtr cpu);
160
161   void setState(e_surf_action_state_t state);
162   int unref();
163   void cancel();
164   void recycle();
165   void updateIndexHeap(int i);
166   void suspend();
167   void resume();
168   bool isSuspended();
169   void setMaxDuration(double duration);
170   void setPriority(double priority);
171   double getRemains();
172   void setAffinity(CpuPtr /*cpu*/, unsigned long /*mask*/) {};
173   void setBound(double /*bound*/) {};
174
175   CpuTiPtr p_cpu;
176   int m_indexHeap;
177   s_xbt_swag_hookup_t p_cpuListHookup;
178   int m_suspended;
179 private:
180 };