Logo AND Algorithmique Numérique Distribuée

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