Logo AND Algorithmique Numérique Distribuée

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