Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix doxygen comments.
[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 /*********
33  * Trace *
34  *********/
35 class CpuTiTrace {
36 public:
37   CpuTiTrace(tmgr_trace_t powerTrace);
38   ~CpuTiTrace();
39
40   double integrateSimple(double a, double b);
41   double integrateSimplePoint(double a);
42   double solveSimple(double a, double amount);
43
44   double *p_timePoints;
45   double *p_integral;
46   int m_nbPoints;
47   int binarySearch(double *array, double a, int low, int high);
48
49 private:
50 };
51
52 enum trace_type {
53   
54   TRACE_FIXED,                /*< Trace fixed, no availability file */
55   TRACE_DYNAMIC               /*< Dynamic, availability file disponible */
56 };
57
58 class CpuTiTgmr {
59 public:
60   CpuTiTgmr(trace_type type, double value): m_type(type), m_value(value){};
61   CpuTiTgmr(tmgr_trace_t power_trace, double value);
62   ~CpuTiTgmr();
63
64   double integrate(double a, double b);
65   double solve(double a, double amount);
66   double solveSomewhatSimple(double a, double amount);
67   double getPowerScale(double a);
68
69   trace_type m_type;
70   double m_value;                 /*< Percentage of cpu power disponible. Value fixed between 0 and 1 */
71
72   /* Dynamic */
73   double m_lastTime;             /*< Integral interval last point (discret time) */
74   double m_total;                 /*< Integral total between 0 and last_pointn */
75
76   CpuTiTracePtr p_trace;
77   tmgr_trace_t p_powerTrace;
78 };
79
80 /*********
81  * Model *
82  *********/
83 class CpuTiModel : public CpuModel {
84 public:
85   CpuTiModel();
86   ~CpuTiModel();
87
88   void parseInit(sg_platf_host_cbarg_t host);
89   CpuTiPtr createResource(const char *name,  xbt_dynar_t powerPeak,
90                           int pstate, double power_scale,
91                           tmgr_trace_t power_trace, int core,
92                           e_surf_resource_state_t state_initial,
93                           tmgr_trace_t state_trace,
94                           xbt_dict_t cpu_properties);
95   double shareResources(double now);
96   void updateActionsState(double now, double delta);
97   void addTraces();
98
99   ActionListPtr p_runningActionSetThatDoesNotNeedBeingChecked;
100   xbt_swag_t p_modifiedCpu;
101   xbt_heap_t p_tiActionHeap;
102
103 protected:
104   void NotifyResourceTurnedOn(ResourcePtr){};
105   void NotifyResourceTurnedOff(ResourcePtr){};
106
107   void NotifyActionCancel(ActionPtr){};
108   void NotifyActionResume(ActionPtr){};
109   void NotifyActionSuspend(ActionPtr){};
110 };
111
112 /************
113  * Resource *
114  ************/
115 class CpuTi : public Cpu {
116 public:
117   CpuTi() {};
118   CpuTi(CpuTiModelPtr model, const char *name, xbt_dynar_t powerPeak,
119         int pstate, double powerScale, tmgr_trace_t powerTrace, int core,
120         e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
121         xbt_dict_t properties) ;
122   ~CpuTi();
123
124   void updateState(tmgr_trace_event_t event_type, double value, double date);  
125   void updateActionsFinishTime(double now);
126   bool isUsed();
127   void printCpuTiModel();
128   CpuActionPtr execute(double size);
129   CpuActionPtr sleep(double duration);
130   double getAvailableSpeed();
131
132   double getCurrentPowerPeak() {THROW_UNIMPLEMENTED;};
133   double getPowerPeakAt(int /*pstate_index*/) {THROW_UNIMPLEMENTED;};
134   int getNbPstates() {THROW_UNIMPLEMENTED;};
135   void setPowerPeakAt(int /*pstate_index*/) {THROW_UNIMPLEMENTED;};
136
137   CpuTiTgmrPtr p_availTrace;       /*< Structure with data needed to integrate trace file */
138   tmgr_trace_event_t p_stateEvent;       /*< trace file with states events (ON or OFF) */
139   tmgr_trace_event_t p_powerEvent;       /*< trace file with availability events */
140   xbt_swag_t p_actionSet;        /*< set with all actions running on cpu */
141   s_xbt_swag_hookup_t p_modifiedCpuHookup;      /*< hookup to swag that indicates whether share resources must be recalculated or not */
142   double m_sumPriority;          /*< the sum of actions' priority that are running on cpu */
143   double m_lastUpdate;           /*< last update of actions' remaining amount done */
144
145   int m_pstate;                                                         /*< Current pstate (index in the power_peak_list)*/
146   double current_frequency;
147
148   void updateRemainingAmount(double now);
149 };
150
151 /**********
152  * Action *
153  **********/
154
155 class CpuTiAction: public CpuAction {
156   friend CpuActionPtr CpuTi::execute(double size);
157   friend CpuActionPtr CpuTi::sleep(double duration);
158   friend void CpuTi::updateActionsFinishTime(double now);//FIXME
159   friend void CpuTi::updateRemainingAmount(double now);//FIXME
160
161 public:
162   CpuTiAction() {};
163   CpuTiAction(CpuTiModelPtr model, double cost, bool failed,
164                                  CpuTiPtr cpu);
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
179   CpuTiPtr p_cpu;
180   int m_indexHeap;
181   s_xbt_swag_hookup_t p_cpuListHookup;
182   int m_suspended;
183 private:
184 };