Logo AND Algorithmique Numérique Distribuée

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