Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
routing cleanup: symbol renaming
[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 *p_timePoints;
43   double *p_integral;
44   int m_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     : m_type(type), m_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 m_type;
68   double m_value;                 /*< Percentage of cpu speed available. Value fixed between 0 and 1 */
69
70   /* Dynamic */
71   double m_lastTime = 0.0;             /*< Integral interval last point (discrete time) */
72   double m_total = 0.0;                 /*< Integral total between 0 and last_pointn */
73
74   CpuTiTrace *p_trace = nullptr;
75   tmgr_trace_t p_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,
86                    CpuTi *cpu);
87
88   void setState(e_surf_action_state_t state) override;
89   int unref() override;
90   void cancel() override;
91   void updateIndexHeap(int i);
92   void suspend() override;
93   void resume() override;
94   void setMaxDuration(double duration) override;
95   void setPriority(double priority) override;
96   double getRemains() override;
97   void setAffinity(Cpu * /*cpu*/, unsigned long /*mask*/) override {};
98
99   CpuTi *p_cpu;
100   int m_indexHeap;
101   int m_suspended = 0;
102 public:
103   boost::intrusive::list_member_hook<> action_ti_hook;
104 };
105
106 typedef boost::intrusive::member_hook<
107   CpuTiAction, boost::intrusive::list_member_hook<>, &CpuTiAction::action_ti_hook> ActionTiListOptions;
108 typedef boost::intrusive::list<
109   CpuTiAction, ActionTiListOptions > ActionTiList;
110
111 /************
112  * Resource *
113  ************/
114 class CpuTi : public Cpu {
115 public:
116   CpuTi(CpuTiModel *model, simgrid::s4u::Host *host, xbt_dynar_t speedPeak,
117         int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
118         int initiallyOn, tmgr_trace_t stateTrace) ;
119   ~CpuTi();
120
121   void set_speed_trace(tmgr_trace_t trace) override;
122
123   void apply_event(tmgr_trace_iterator_t event, double value) override;
124   void updateActionsFinishTime(double now);
125   void updateRemainingAmount(double now);
126
127   bool isUsed() override;
128   CpuAction *execution_start(double size) override;
129   CpuAction *sleep(double duration) override;
130   double getAvailableSpeed() override;
131
132   void modified(bool modified);
133
134   CpuTiTgmr *p_availTrace;       /*< Structure with data needed to integrate trace file */
135   ActionTiList *p_actionSet;        /*< set with all actions running on cpu */
136   double m_sumPriority;          /*< the sum of actions' priority that are running on cpu */
137   double m_lastUpdate = 0;       /*< last update of actions' remaining amount done */
138
139   double current_frequency;
140
141 public:
142   boost::intrusive::list_member_hook<> cpu_ti_hook;
143 };
144
145 typedef boost::intrusive::member_hook<
146   CpuTi, boost::intrusive::list_member_hook<>, &CpuTi::cpu_ti_hook> CpuTiListOptions;
147 typedef boost::intrusive::list<CpuTi, CpuTiListOptions> CpuTiList;
148
149 /*********
150  * Model *
151  *********/
152 class CpuTiModel : public CpuModel {
153 public:
154   CpuTiModel();
155   ~CpuTiModel();
156   Cpu *createCpu(simgrid::s4u::Host *host,  xbt_dynar_t speedPeak,
157                           int pstate, double speedScale,
158                           tmgr_trace_t speedTrace, int core,
159                           int initiallyOn, tmgr_trace_t state_trace) override;
160   double next_occuring_event(double now) override;
161   void updateActionsState(double now, double delta) override;
162
163   ActionList *p_runningActionSetThatDoesNotNeedBeingChecked;
164   CpuTiList *p_modifiedCpu;
165   xbt_heap_t p_tiActionHeap;
166
167 protected:
168   void NotifyResourceTurnedOn(simgrid::surf::Resource*){};
169   void NotifyResourceTurnedOff(simgrid::surf::Resource*){};
170
171   void NotifyActionCancel(Action*){};
172   void NotifyActionResume(Action*){};
173   void NotifyActionSuspend(Action*){};
174 };
175
176 }
177 }