Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0196d9178886d7d85f8a2c69e7cc37c65551452e
[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 (discrete 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 public:
82   CpuTiAction(CpuTiModel *model, double cost, bool failed,
83                    CpuTi *cpu);
84
85   void setState(e_surf_action_state_t state);
86   int unref();
87   void cancel();
88   void updateIndexHeap(int i);
89   void suspend();
90   void resume();
91   bool isSuspended();
92   void setMaxDuration(double duration);
93   void setPriority(double priority);
94   double getRemains();
95   void setAffinity(Cpu * /*cpu*/, unsigned long /*mask*/) {};
96
97   CpuTi *p_cpu;
98   int m_indexHeap;
99   int m_suspended;
100 public:
101   boost::intrusive::list_member_hook<> action_ti_hook;
102 };
103
104 typedef boost::intrusive::member_hook<
105   CpuTiAction, boost::intrusive::list_member_hook<>, &CpuTiAction::action_ti_hook> ActionTiListOptions;
106 typedef boost::intrusive::list<
107   CpuTiAction, ActionTiListOptions > ActionTiList;
108
109 /************
110  * Resource *
111  ************/
112 class CpuTi : public Cpu {
113 public:
114   CpuTi() {};
115   CpuTi(CpuTiModel *model, const char *name, xbt_dynar_t speedPeak,
116         int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
117         e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
118         xbt_dict_t properties) ;
119   ~CpuTi();
120
121   void updateState(tmgr_trace_event_t event_type, double value, double date);
122   void updateActionsFinishTime(double now);
123   bool isUsed();
124   void printCpuTiModel();
125   CpuAction *execute(double size);
126   CpuAction *sleep(double duration);
127   double getAvailableSpeed();
128
129   double getCurrentPowerPeak() {THROW_UNIMPLEMENTED;};
130   double getPowerPeakAt(int /*pstate_index*/) {THROW_UNIMPLEMENTED;};
131   int getNbPstates() {THROW_UNIMPLEMENTED;};
132   void setPstate(int /*pstate_index*/) {THROW_UNIMPLEMENTED;};
133   int  getPstate() { THROW_UNIMPLEMENTED;}
134   void modified(bool modified);
135
136   CpuTiTgmr *p_availTrace;       /*< Structure with data needed to integrate trace file */
137   tmgr_trace_event_t p_stateEvent;       /*< trace file with states events (ON or OFF) */
138   tmgr_trace_event_t p_speedEvent;       /*< trace file with availability events */
139   ActionTiList *p_actionSet;        /*< set with all actions running on cpu */
140   double m_sumPriority;          /*< the sum of actions' priority that are running on cpu */
141   double m_lastUpdate;           /*< last update of actions' remaining amount done */
142
143   double current_frequency;
144
145   void updateRemainingAmount(double now);
146 public:
147   boost::intrusive::list_member_hook<> cpu_ti_hook;
148 };
149
150 typedef boost::intrusive::member_hook<
151   CpuTi, boost::intrusive::list_member_hook<>, &CpuTi::cpu_ti_hook> CpuTiListOptions;
152 typedef boost::intrusive::list<CpuTi, CpuTiListOptions> CpuTiList;
153
154 /*********
155  * Model *
156  *********/
157 class CpuTiModel : public CpuModel {
158 public:
159   CpuTiModel();
160   ~CpuTiModel();
161   Cpu *createCpu(const char *name,  xbt_dynar_t speedPeak,
162                           int pstate, double speedScale,
163                           tmgr_trace_t speedTrace, int core,
164                           e_surf_resource_state_t state_initial,
165                           tmgr_trace_t state_trace,
166                           xbt_dict_t cpu_properties);
167   double shareResources(double now);
168   void updateActionsState(double now, double delta);
169   void addTraces();
170
171   ActionList *p_runningActionSetThatDoesNotNeedBeingChecked;
172   CpuTiList *p_modifiedCpu;
173   xbt_heap_t p_tiActionHeap;
174
175 protected:
176   void NotifyResourceTurnedOn(Resource*){};
177   void NotifyResourceTurnedOff(Resource*){};
178
179   void NotifyActionCancel(Action*){};
180   void NotifyActionResume(Action*){};
181   void NotifyActionSuspend(Action*){};
182 };