Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
75ffbf40e8b1e4f60916b014f88353f1ae11e3d7
[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 namespace simgrid {
17 namespace surf {
18
19 /***********
20  * Classes *
21  ***********/
22 class XBT_PRIVATE CpuTiTrace;
23 class XBT_PRIVATE CpuTiTgmr;
24 class XBT_PRIVATE CpuTiModel;
25 class XBT_PRIVATE CpuTi;
26 class XBT_PRIVATE CpuTiAction;
27
28 struct tiTag;
29
30 /*********
31  * Trace *
32  *********/
33 class CpuTiTrace {
34 public:
35   CpuTiTrace(tmgr_trace_t speedTrace);
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, have an availability file */
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 speedTrace, 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 speed available. Value fixed between 0 and 1 */
69
70   /* Dynamic */
71   double m_lastTime;             /*< Integral interval last point (discrete time) */
72   double m_total;                 /*< Integral total between 0 and last_pointn */
73
74   CpuTiTrace *p_trace;
75   tmgr_trace_t p_speedTrace;
76 };
77
78 /**********
79  * Action *
80  **********/
81
82 class CpuTiAction: public CpuAction {
83   friend class CpuTi;
84 public:
85   CpuTiAction(CpuTiModel *model, double cost, bool failed,
86                    CpuTi *cpu);
87
88   void setState(e_surf_action_state_t state);
89   int unref();
90   void cancel();
91   void updateIndexHeap(int i);
92   void suspend();
93   void resume();
94   bool isSuspended();
95   void setMaxDuration(double duration);
96   void setPriority(double priority);
97   double getRemains();
98   void setAffinity(Cpu * /*cpu*/, unsigned long /*mask*/) {};
99
100   CpuTi *p_cpu;
101   int m_indexHeap;
102   int m_suspended;
103 public:
104   boost::intrusive::list_member_hook<> action_ti_hook;
105 };
106
107 typedef boost::intrusive::member_hook<
108   CpuTiAction, boost::intrusive::list_member_hook<>, &CpuTiAction::action_ti_hook> ActionTiListOptions;
109 typedef boost::intrusive::list<
110   CpuTiAction, ActionTiListOptions > ActionTiList;
111
112 /************
113  * Resource *
114  ************/
115 class CpuTi : public Cpu {
116 public:
117   CpuTi() {};
118   CpuTi(CpuTiModel *model, const char *name, xbt_dynar_t speedPeak,
119         int pstate, double speedScale, tmgr_trace_t speedTrace, 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   CpuAction *execute(double size);
129   CpuAction *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 setPstate(int /*pstate_index*/) {THROW_UNIMPLEMENTED;};
136   int  getPstate() { THROW_UNIMPLEMENTED;}
137   void modified(bool modified);
138
139   CpuTiTgmr *p_availTrace;       /*< Structure with data needed to integrate trace file */
140   tmgr_trace_event_t p_stateEvent;       /*< trace file with states events (ON or OFF) */
141   tmgr_trace_event_t p_speedEvent;       /*< trace file with availability events */
142   ActionTiList *p_actionSet;        /*< set with all actions running on cpu */
143   double m_sumPriority;          /*< the sum of actions' priority that are running on cpu */
144   double m_lastUpdate;           /*< last update of actions' remaining amount done */
145
146   double current_frequency;
147
148   void updateRemainingAmount(double now);
149 public:
150   boost::intrusive::list_member_hook<> cpu_ti_hook;
151 };
152
153 typedef boost::intrusive::member_hook<
154   CpuTi, boost::intrusive::list_member_hook<>, &CpuTi::cpu_ti_hook> CpuTiListOptions;
155 typedef boost::intrusive::list<CpuTi, CpuTiListOptions> CpuTiList;
156
157 /*********
158  * Model *
159  *********/
160 class CpuTiModel : public CpuModel {
161 public:
162   CpuTiModel();
163   ~CpuTiModel();
164   Cpu *createCpu(const char *name,  xbt_dynar_t speedPeak,
165                           int pstate, double speedScale,
166                           tmgr_trace_t speedTrace, int core,
167                           e_surf_resource_state_t state_initial,
168                           tmgr_trace_t state_trace,
169                           xbt_dict_t cpu_properties);
170   double shareResources(double now);
171   void updateActionsState(double now, double delta);
172   void addTraces();
173
174   ActionList *p_runningActionSetThatDoesNotNeedBeingChecked;
175   CpuTiList *p_modifiedCpu;
176   xbt_heap_t p_tiActionHeap;
177
178 protected:
179   void NotifyResourceTurnedOn(simgrid::surf::Resource*){};
180   void NotifyResourceTurnedOff(simgrid::surf::Resource*){};
181
182   void NotifyActionCancel(Action*){};
183   void NotifyActionResume(Action*){};
184   void NotifyActionSuspend(Action*){};
185 };
186
187 }
188 }