Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
79a8045fcedc9bacbc2a876c518843f074bdae1b
[simgrid.git] / src / surf / cpu_ti.hpp
1 #include "cpu.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, double power_peak, 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
93 protected:
94   void NotifyResourceTurnedOn(ResourcePtr r){};
95   void NotifyResourceTurnedOff(ResourcePtr r){};
96
97   void NotifyActionCancel(ActionPtr a){};
98   void NotifyActionResume(ActionPtr a){};
99   void NotifyActionSuspend(ActionPtr a){};
100 };
101
102 /************
103  * Resource *
104  ************/
105 class CpuTi : public Cpu {
106 public:
107   CpuTi(CpuTiModelPtr model, const char *name, double powerPeak,
108         double powerScale, tmgr_trace_t powerTrace, int core,
109         e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
110         xbt_dict_t properties) ;
111   ~CpuTi() {};
112
113   void updateState(tmgr_trace_event_t event_type, double value, double date);  
114   void updateActionFinishDate(double now);
115   bool isUsed();  
116   double getSpeed (double load);
117   double getAvailableSpeed ();
118   void addTraces();
119   void printCpuTiModel();
120   CpuTiModelPtr getModel();
121   CpuActionPtr execute(double size);
122   CpuActionPtr sleep(double duration);
123   e_surf_resource_state_t getState();
124   
125   double m_powerPeak;            /*< CPU power peak */
126   double m_powerScale;           /*< Percentage of CPU disponible */
127   CpuTiTgmrPtr p_availTrace;       /*< Structure with data needed to integrate trace file */
128   e_surf_resource_state_t p_stateCurrent;        /*< CPU current state (ON or OFF) */
129   tmgr_trace_event_t p_stateEvent;       /*< trace file with states events (ON or OFF) */
130   tmgr_trace_event_t p_powerEvent;       /*< trace file with availabitly events */
131   xbt_swag_t p_actionSet;        /*< set with all actions running on cpu */
132   s_xbt_swag_hookup_t p_modifiedCpuHookup;      /*< hookup to swag that indicacates whether share resources must be recalculated or not */
133   double m_sumPriority;          /*< the sum of actions' priority that are running on cpu */
134   double m_lastUpdate;           /*< last update of actions' remaining amount done */
135   void updateRemainingAmount(double now);
136 };
137
138 /**********
139  * Action *
140  **********/
141 class CpuTiAction: public CpuAction {
142 public:
143   CpuTiAction(CpuTiModelPtr model, double cost, bool failed): CpuAction(model, cost, failed) {};
144
145   void setState(e_surf_action_state_t state);
146   int unref();
147   void cancel();
148   void recycle();
149   void updateIndexHeap(int i);
150   void suspend();
151   void resume();
152   bool isSuspended();
153   void setMaxDuration(double duration);
154   void setPriority(double priority);
155   double getRemains();
156   CpuTiPtr p_cpu;
157   int m_indexHeap;
158
159 private:
160 };