Logo AND Algorithmique Numérique Distribuée

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