Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
f42b6ea0e01d6a4dbd93a341e53cba9b19044bff
[simgrid.git] / src / surf / cpu_ti.hpp
1 /* Copyright (c) 2013-2018. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include <boost/intrusive/list.hpp>
7
8 #include <xbt/base.h>
9
10 #include "src/surf/cpu_interface.hpp"
11 #include "src/surf/trace_mgr.hpp"
12
13 /* Epsilon */
14 #define EPSILON 0.000000001
15
16 namespace simgrid {
17 namespace surf {
18
19 /***********
20  * Classes *
21  ***********/
22 class XBT_PRIVATE CpuTiModel;
23 class XBT_PRIVATE CpuTi;
24
25 /*********
26  * Trace *
27  *********/
28 class CpuTiTrace {
29 public:
30   explicit CpuTiTrace(tmgr_trace_t speedTrace);
31   CpuTiTrace(const CpuTiTrace&) = delete;
32   CpuTiTrace& operator=(const CpuTiTrace&) = delete;
33   ~CpuTiTrace();
34
35   double integrate_simple(double a, double b);
36   double integrate_simple_point(double a);
37   double solve_simple(double a, double amount);
38
39   double* time_points_;
40   double *integral_;
41   int nb_points_;
42   int binary_search(double* array, double a, int low, int high);
43 };
44
45 enum trace_type {
46
47   TRACE_FIXED,                /*< Trace fixed, no availability file */
48   TRACE_DYNAMIC               /*< Dynamic, have an availability file */
49 };
50
51 class CpuTiTgmr {
52 public:
53   CpuTiTgmr(trace_type type, double value)
54     : type_(type), value_(value)
55   {};
56   CpuTiTgmr(tmgr_trace_t speedTrace, double value);
57   CpuTiTgmr(const CpuTiTgmr&) = delete;
58   CpuTiTgmr& operator=(const CpuTiTgmr&) = delete;
59   ~CpuTiTgmr();
60
61   double integrate(double a, double b);
62   double solve(double a, double amount);
63   double get_power_scale(double a);
64
65   trace_type type_;
66   double value_;                 /*< Percentage of cpu speed available. Value fixed between 0 and 1 */
67
68   /* Dynamic */
69   double last_time_ = 0.0;             /*< Integral interval last point (discrete time) */
70   double total_    = 0.0;             /*< Integral total between 0 and last_pointn */
71
72   CpuTiTrace *trace_ = nullptr;
73   tmgr_trace_t speed_trace_ = nullptr;
74 };
75
76 /**********
77  * Action *
78  **********/
79
80 class XBT_PRIVATE CpuTiAction : public CpuAction {
81   friend class CpuTi;
82 public:
83   CpuTiAction(CpuTiModel *model, double cost, bool failed, CpuTi *cpu);
84   ~CpuTiAction();
85
86   void set_state(simgrid::kernel::resource::Action::State state) override;
87   void cancel() override;
88   void suspend() override;
89   void resume() override;
90   void set_max_duration(double duration) override;
91   void set_priority(double priority) override;
92   double get_remains() override;
93
94   CpuTi *cpu_;
95
96   boost::intrusive::list_member_hook<> action_ti_hook;
97 };
98
99 typedef boost::intrusive::member_hook<CpuTiAction, boost::intrusive::list_member_hook<>, &CpuTiAction::action_ti_hook> ActionTiListOptions;
100 typedef boost::intrusive::list<CpuTiAction, ActionTiListOptions > ActionTiList;
101
102 /************
103  * Resource *
104  ************/
105 class CpuTi : public Cpu {
106 public:
107   CpuTi(CpuTiModel* model, simgrid::s4u::Host* host, std::vector<double>* speed_per_pstate, int core);
108   ~CpuTi() override;
109
110   void set_speed_trace(tmgr_trace_t trace) override;
111
112   void apply_event(tmgr_trace_event_t event, double value) override;
113   void update_actions_finish_time(double now);
114   void update_remaining_amount(double now);
115
116   bool is_used() override;
117   CpuAction *execution_start(double size) override;
118   simgrid::kernel::resource::Action* execution_start(double size, int requestedCores) override
119   {
120     THROW_UNIMPLEMENTED;
121     return nullptr;
122   }
123   CpuAction *sleep(double duration) override;
124   double get_available_speed() override;
125
126   void set_modified(bool modified);
127
128   CpuTiTgmr* speed_integrated_trace_ = nullptr; /*< Structure with data needed to integrate trace file */
129   ActionTiList action_set_;                     /*< set with all actions running on cpu */
130   double sum_priority_ = 0;                  /*< the sum of actions' priority that are running on cpu */
131   double last_update_  = 0;                  /*< last update of actions' remaining amount done */
132
133   double current_frequency_;
134
135   boost::intrusive::list_member_hook<> cpu_ti_hook;
136 };
137
138 typedef boost::intrusive::member_hook<CpuTi, boost::intrusive::list_member_hook<>, &CpuTi::cpu_ti_hook> CpuTiListOptions;
139 typedef boost::intrusive::list<CpuTi, CpuTiListOptions> CpuTiList;
140
141 /*********
142  * Model *
143  *********/
144 class CpuTiModel : public CpuModel {
145 public:
146   CpuTiModel() : CpuModel(Model::UpdateAlgo::Full){};
147   ~CpuTiModel() override;
148   Cpu* createCpu(simgrid::s4u::Host* host, std::vector<double>* speed_per_pstate, int core) override;
149   double next_occuring_event(double now) override;
150   void update_actions_state(double now, double delta) override;
151
152   kernel::resource::Action::StateSet runningActionSetThatDoesNotNeedBeingChecked_;
153   CpuTiList modified_cpus_;
154 };
155
156 }
157 }