Logo AND Algorithmique Numérique Distribuée

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