Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
french comment --
[simgrid.git] / src / surf / cpu_ti.hpp
1 /* Copyright (c) 2013-2019. 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 #ifndef SURF_MODEL_CPUTI_H_
7 #define SURF_MODEL_CPUTI_H_
8
9 #include "src/kernel/resource/profile/trace_mgr.hpp"
10 #include "src/surf/cpu_interface.hpp"
11
12 #include <boost/intrusive/list.hpp>
13
14 namespace simgrid {
15 namespace kernel {
16 namespace resource {
17
18 /***********
19  * Classes *
20  ***********/
21 class XBT_PRIVATE CpuTiModel;
22 class XBT_PRIVATE CpuTi;
23
24 /*********
25  * Trace *
26  *********/
27 class CpuTiProfile {
28 public:
29   explicit CpuTiProfile(profile::Profile* profile);
30   CpuTiProfile(const CpuTiProfile&) = delete;
31   CpuTiProfile& operator=(const CpuTiProfile&) = delete;
32   ~CpuTiProfile();
33
34   double integrate_simple(double a, double b);
35   double integrate_simple_point(double a);
36   double solve_simple(double a, double amount);
37
38   double* time_points_;
39   double *integral_;
40   int nb_points_;
41   int binary_search(double* array, double a, int low, int high);
42 };
43
44 class CpuTiTmgr {
45   enum class Type {
46     FIXED,  /*< Trace fixed, no availability file */
47     DYNAMIC /*< Dynamic, have an availability file */
48   };
49
50 public:
51   explicit CpuTiTmgr(double value) : type_(Type::FIXED), value_(value){};
52   CpuTiTmgr(profile::Profile* speed_profile, double value);
53   CpuTiTmgr(const CpuTiTmgr&) = delete;
54   CpuTiTmgr& operator=(const CpuTiTmgr&) = delete;
55   ~CpuTiTmgr();
56
57   double integrate(double a, double b);
58   double solve(double a, double amount);
59   double get_power_scale(double a);
60
61 private:
62   Type type_;
63   double value_;                 /*< Percentage of cpu speed available. Value fixed between 0 and 1 */
64
65   /* Dynamic */
66   double last_time_ = 0.0;             /*< Integral interval last point (discrete time) */
67   double total_    = 0.0;             /*< Integral total between 0 and last_pointn */
68
69   CpuTiProfile* profile_                   = nullptr;
70   profile::Profile* speed_profile_         = nullptr;
71 };
72
73 /**********
74  * Action *
75  **********/
76
77 class XBT_PRIVATE CpuTiAction : public CpuAction {
78   friend class CpuTi;
79 public:
80   CpuTiAction(CpuTi* cpu, double cost);
81   CpuTiAction(const CpuTiAction&) = delete;
82   CpuTiAction& operator=(const CpuTiAction&) = delete;
83   ~CpuTiAction();
84
85   void set_state(Action::State state) override;
86   void cancel() override;
87   void suspend() override;
88   void resume() override;
89   void set_max_duration(double duration) override;
90   void set_priority(double priority) override;
91   double get_remains() override;
92
93   CpuTi *cpu_;
94
95   boost::intrusive::list_member_hook<> action_ti_hook;
96 };
97
98 typedef boost::intrusive::member_hook<CpuTiAction, boost::intrusive::list_member_hook<>, &CpuTiAction::action_ti_hook> ActionTiListOptions;
99 typedef boost::intrusive::list<CpuTiAction, ActionTiListOptions > ActionTiList;
100
101 /************
102  * Resource *
103  ************/
104 class CpuTi : public Cpu {
105 public:
106   CpuTi(CpuTiModel* model, s4u::Host* host, const std::vector<double>& speed_per_pstate, int core);
107   CpuTi(const CpuTi&)            = delete;
108   CpuTi& operator&(const CpuTi&) = delete;
109   ~CpuTi() override;
110
111   void set_speed_profile(profile::Profile* profile) override;
112
113   void apply_event(profile::Event* event, double value) override;
114   void update_actions_finish_time(double now);
115   void update_remaining_amount(double now);
116
117   bool is_used() override;
118   CpuAction* execution_start(double size) override;
119   Action* execution_start(double, int) override
120   {
121     THROW_UNIMPLEMENTED;
122     return nullptr;
123   }
124   CpuAction* sleep(double duration) override;
125   double get_speed_ratio() override;
126
127   void set_modified(bool modified);
128
129   CpuTiTmgr* speed_integrated_trace_ = nullptr; /*< Structure with data needed to integrate trace file */
130   ActionTiList action_set_;                     /*< set with all actions running on cpu */
131   double sum_priority_ = 0;                  /*< the sum of actions' priority that are running on cpu */
132   double last_update_  = 0;                  /*< last update of actions' remaining amount done */
133
134   boost::intrusive::list_member_hook<> cpu_ti_hook;
135 };
136
137 typedef boost::intrusive::member_hook<CpuTi, boost::intrusive::list_member_hook<>, &CpuTi::cpu_ti_hook> CpuTiListOptions;
138 typedef boost::intrusive::list<CpuTi, CpuTiListOptions> CpuTiList;
139
140 /*********
141  * Model *
142  *********/
143 class CpuTiModel : public CpuModel {
144 public:
145   static void create_pm_vm_models(); // Make both models be TI models
146
147   CpuTiModel();
148   CpuTiModel(const CpuTiModel&) = delete;
149   CpuTiModel& operator=(const CpuTiModel&) = delete;
150   ~CpuTiModel() override;
151   Cpu* create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate, int core) override;
152   double next_occuring_event(double now) override;
153   void update_actions_state(double now, double delta) override;
154
155   CpuTiList modified_cpus_;
156 };
157
158 } // namespace resource
159 } // namespace kernel
160 } // namespace simgrid
161
162 #endif /* SURF_MODEL_CPUTI_H_ */