Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4059783161497f09c986e96e7087c231d3d38a91
[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 <boost/intrusive/list.hpp>
8
9 #include <xbt/base.h>
10
11 #include "src/surf/cpu_interface.hpp"
12 #include "src/surf/trace_mgr.hpp"
13 #include "surf/surf_routing.h"
14
15 /* Epsilon */
16 #define EPSILON 0.000000001
17
18 namespace simgrid {
19 namespace surf {
20
21 /***********
22  * Classes *
23  ***********/
24 class XBT_PRIVATE CpuTiTrace;
25 class XBT_PRIVATE CpuTiTgmr;
26 class XBT_PRIVATE CpuTiModel;
27 class XBT_PRIVATE CpuTi;
28 class XBT_PRIVATE CpuTiAction;
29
30 struct tiTag;
31
32 /*********
33  * Trace *
34  *********/
35 class CpuTiTrace {
36 public:
37   explicit CpuTiTrace(tmgr_trace_t speedTrace);
38   ~CpuTiTrace();
39
40   double integrateSimple(double a, double b);
41   double integrateSimplePoint(double a);
42   double solveSimple(double a, double amount);
43
44   double *timePoints_;
45   double *integral_;
46   int nbPoints_;
47   int binarySearch(double *array, double a, int low, int high);
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)
59     : type_(type), value_(value)
60   {};
61   CpuTiTgmr(tmgr_trace_t speedTrace, double value);
62   ~CpuTiTgmr();
63
64   double integrate(double a, double b);
65   double solve(double a, double amount);
66   double solveSomewhatSimple(double a, double amount);
67   double getPowerScale(double a);
68
69   trace_type type_;
70   double value_;                 /*< Percentage of cpu speed available. Value fixed between 0 and 1 */
71
72   /* Dynamic */
73   double lastTime_ = 0.0;             /*< Integral interval last point (discrete time) */
74   double total_    = 0.0;             /*< Integral total between 0 and last_pointn */
75
76   CpuTiTrace *trace_ = nullptr;
77   tmgr_trace_t speedTrace_ = nullptr;
78 };
79
80 /**********
81  * Action *
82  **********/
83
84 class CpuTiAction: public CpuAction {
85   friend class CpuTi;
86 public:
87   CpuTiAction(CpuTiModel *model, double cost, bool failed, CpuTi *cpu);
88
89   void setState(simgrid::surf::Action::State state) override;
90   int unref() override;
91   void cancel() override;
92   void updateIndexHeap(int i);
93   void suspend() override;
94   void resume() override;
95   void setMaxDuration(double duration) override;
96   void setPriority(double priority) override;
97   double getRemains() override;
98
99   CpuTi *cpu_;
100   int indexHeap_ = -1;
101   int suspended_ = 0;
102
103   boost::intrusive::list_member_hook<> action_ti_hook;
104 };
105
106 typedef boost::intrusive::member_hook<CpuTiAction, boost::intrusive::list_member_hook<>, &CpuTiAction::action_ti_hook> ActionTiListOptions;
107 typedef boost::intrusive::list<CpuTiAction, ActionTiListOptions > ActionTiList;
108
109 /************
110  * Resource *
111  ************/
112 class CpuTi : public Cpu {
113 public:
114   CpuTi(CpuTiModel *model, simgrid::s4u::Host *host, std::vector<double> *speedPerPstate, int core);
115   ~CpuTi() override;
116
117   void setSpeedTrace(tmgr_trace_t trace) override;
118
119   void apply_event(tmgr_trace_event_t event, double value) override;
120   void updateActionsFinishTime(double now);
121   void updateRemainingAmount(double now);
122
123   bool isUsed() override;
124   CpuAction *execution_start(double size) override;
125   CpuAction *sleep(double duration) override;
126   double getAvailableSpeed() override;
127
128   void modified(bool modified);
129
130   CpuTiTgmr *speedIntegratedTrace_ = nullptr;/*< Structure with data needed to integrate trace file */
131   ActionTiList *actionSet_ = nullptr;        /*< set with all actions running on cpu */
132   double sumPriority_ = 0; /*< the sum of actions' priority that are running on cpu */
133   double lastUpdate_ = 0;  /*< last update of actions' remaining amount done */
134
135   double currentFrequency_;
136
137   boost::intrusive::list_member_hook<> cpu_ti_hook;
138 };
139
140 typedef boost::intrusive::member_hook<CpuTi, boost::intrusive::list_member_hook<>, &CpuTi::cpu_ti_hook> CpuTiListOptions;
141 typedef boost::intrusive::list<CpuTi, CpuTiListOptions> CpuTiList;
142
143 /*********
144  * Model *
145  *********/
146 class CpuTiModel : public CpuModel {
147 public:
148   CpuTiModel();
149   ~CpuTiModel() override;
150   Cpu *createCpu(simgrid::s4u::Host *host,  std::vector<double>* speedPerPstate, int core) override;
151   double nextOccuringEvent(double now) override;
152   void updateActionsState(double now, double delta) override;
153
154   ActionList *runningActionSetThatDoesNotNeedBeingChecked_;
155   CpuTiList *modifiedCpu_;
156   xbt_heap_t tiActionHeap_;
157
158 protected:
159   void NotifyResourceTurnedOn(simgrid::surf::Resource*){};
160   void NotifyResourceTurnedOff(simgrid::surf::Resource*){};
161
162   void NotifyActionCancel(Action*){};
163   void NotifyActionResume(Action*){};
164   void NotifyActionSuspend(Action*){};
165 };
166
167 }
168 }