Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename the fields of 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 <xbt/base.h>
8
9 #include "src/surf/cpu_interface.hpp"
10 #include "src/surf/trace_mgr.hpp"
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 *timePoints_;
43   double *integral_;
44   int nbPoints_;
45   int binarySearch(double *array, double a, int low, int high);
46 };
47
48 enum trace_type {
49
50   TRACE_FIXED,                /*< Trace fixed, no availability file */
51   TRACE_DYNAMIC               /*< Dynamic, have an availability file */
52 };
53
54 class CpuTiTgmr {
55 public:
56   CpuTiTgmr(trace_type type, double value)
57     : type_(type), value_(value)
58   {};
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 type_;
68   double value_;                 /*< Percentage of cpu speed available. Value fixed between 0 and 1 */
69
70   /* Dynamic */
71   double lastTime_ = 0.0;             /*< Integral interval last point (discrete time) */
72   double total_    = 0.0;             /*< Integral total between 0 and last_pointn */
73
74   CpuTiTrace *trace_ = nullptr;
75   tmgr_trace_t speedTrace_ = nullptr;
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, CpuTi *cpu);
86
87   void setState(e_surf_action_state_t state) override;
88   int unref() override;
89   void cancel() override;
90   void updateIndexHeap(int i);
91   void suspend() override;
92   void resume() override;
93   void setMaxDuration(double duration) override;
94   void setPriority(double priority) override;
95   double getRemains() override;
96   void setAffinity(Cpu * /*cpu*/, unsigned long /*mask*/) override {};
97
98   CpuTi *cpu_;
99   int indexHeap_;
100   int suspended_ = 0;
101 public:
102   boost::intrusive::list_member_hook<> action_ti_hook;
103 };
104
105 typedef boost::intrusive::member_hook<CpuTiAction, boost::intrusive::list_member_hook<>, &CpuTiAction::action_ti_hook> ActionTiListOptions;
106 typedef boost::intrusive::list<CpuTiAction, ActionTiListOptions > ActionTiList;
107
108 /************
109  * Resource *
110  ************/
111 class CpuTi : public Cpu {
112 public:
113   CpuTi(CpuTiModel *model, simgrid::s4u::Host *host, xbt_dynar_t speedPeak,
114         int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
115         int initiallyOn, tmgr_trace_t stateTrace) ;
116   ~CpuTi();
117
118   void set_speed_trace(tmgr_trace_t trace) override;
119
120   void apply_event(tmgr_trace_iterator_t event, double value) override;
121   void updateActionsFinishTime(double now);
122   void updateRemainingAmount(double now);
123
124   bool isUsed() override;
125   CpuAction *execution_start(double size) override;
126   CpuAction *sleep(double duration) override;
127   double getAvailableSpeed() override;
128
129   void modified(bool modified);
130
131   CpuTiTgmr *availTrace_;       /*< Structure with data needed to integrate trace file */
132   ActionTiList *actionSet_;        /*< set with all actions running on cpu */
133   double sumPriority_;          /*< the sum of actions' priority that are running on cpu */
134   double lastUpdate_ = 0;       /*< last update of actions' remaining amount done */
135
136   double currentFrequency_;
137
138 public:
139   boost::intrusive::list_member_hook<> cpu_ti_hook;
140 };
141
142 typedef boost::intrusive::member_hook<CpuTi, boost::intrusive::list_member_hook<>, &CpuTi::cpu_ti_hook> CpuTiListOptions;
143 typedef boost::intrusive::list<CpuTi, CpuTiListOptions> CpuTiList;
144
145 /*********
146  * Model *
147  *********/
148 class CpuTiModel : public CpuModel {
149 public:
150   CpuTiModel();
151   ~CpuTiModel();
152   Cpu *createCpu(simgrid::s4u::Host *host,  xbt_dynar_t speedPeak,
153                           int pstate, double speedScale,
154                           tmgr_trace_t speedTrace, int core,
155                           int initiallyOn, tmgr_trace_t state_trace) override;
156   double next_occuring_event(double now) override;
157   void updateActionsState(double now, double delta) override;
158
159   ActionList *runningActionSetThatDoesNotNeedBeingChecked_;
160   CpuTiList *modifiedCpu_;
161   xbt_heap_t tiActionHeap_;
162
163 protected:
164   void NotifyResourceTurnedOn(simgrid::surf::Resource*){};
165   void NotifyResourceTurnedOff(simgrid::surf::Resource*){};
166
167   void NotifyActionCancel(Action*){};
168   void NotifyActionResume(Action*){};
169   void NotifyActionSuspend(Action*){};
170 };
171
172 }
173 }