Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
changing namespace for cpu_interface
[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 surf {
16
17 /***********
18  * Classes *
19  ***********/
20 class XBT_PRIVATE CpuTiModel;
21 class XBT_PRIVATE CpuTi;
22
23 /*********
24  * Trace *
25  *********/
26 class CpuTiProfile {
27 public:
28   explicit CpuTiProfile(kernel::profile::Profile* profile);
29   CpuTiProfile(const CpuTiProfile&) = delete;
30   CpuTiProfile& operator=(const CpuTiProfile&) = delete;
31   ~CpuTiProfile();
32
33   double integrate_simple(double a, double b);
34   double integrate_simple_point(double a);
35   double solve_simple(double a, double amount);
36
37   double* time_points_;
38   double *integral_;
39   int nb_points_;
40   int binary_search(double* array, double a, int low, int high);
41 };
42
43 class CpuTiTmgr {
44   enum class Type {
45     FIXED,  /*< Trace fixed, no availability file */
46     DYNAMIC /*< Dynamic, have an availability file */
47   };
48
49 public:
50   explicit CpuTiTmgr(double value) : type_(Type::FIXED), value_(value){};
51   CpuTiTmgr(kernel::profile::Profile* speed_profile, double value);
52   CpuTiTmgr(const CpuTiTmgr&) = delete;
53   CpuTiTmgr& operator=(const CpuTiTmgr&) = delete;
54   ~CpuTiTmgr();
55
56   double integrate(double a, double b);
57   double solve(double a, double amount);
58   double get_power_scale(double a);
59
60 private:
61   Type type_;
62   double value_;                 /*< Percentage of cpu speed available. Value fixed between 0 and 1 */
63
64   /* Dynamic */
65   double last_time_ = 0.0;             /*< Integral interval last point (discrete time) */
66   double total_    = 0.0;             /*< Integral total between 0 and last_pointn */
67
68   CpuTiProfile* profile_                   = nullptr;
69   kernel::profile::Profile* speed_profile_ = nullptr;
70 };
71
72 /**********
73  * Action *
74  **********/
75
76 class XBT_PRIVATE CpuTiAction : public kernel::resource::CpuAction {
77   friend class CpuTi;
78 public:
79   CpuTiAction(CpuTi* cpu, double cost);
80   CpuTiAction(const CpuTiAction&) = delete;
81   CpuTiAction& operator=(const CpuTiAction&) = delete;
82   ~CpuTiAction();
83
84   void set_state(kernel::resource::Action::State state) override;
85   void cancel() override;
86   void suspend() override;
87   void resume() override;
88   void set_max_duration(double duration) override;
89   void set_priority(double priority) override;
90   double get_remains() override;
91
92   CpuTi *cpu_;
93
94   boost::intrusive::list_member_hook<> action_ti_hook;
95 };
96
97 typedef boost::intrusive::member_hook<CpuTiAction, boost::intrusive::list_member_hook<>, &CpuTiAction::action_ti_hook> ActionTiListOptions;
98 typedef boost::intrusive::list<CpuTiAction, ActionTiListOptions > ActionTiList;
99
100 /************
101  * Resource *
102  ************/
103 class CpuTi : public kernel::resource::Cpu {
104 public:
105   CpuTi(CpuTiModel* model, s4u::Host* host, const std::vector<double>& speed_per_pstate, int core);
106   CpuTi(const CpuTi&)            = delete;
107   CpuTi& operator&(const CpuTi&) = delete;
108   ~CpuTi() override;
109
110   void set_speed_profile(kernel::profile::Profile* profile) override;
111
112   void apply_event(kernel::profile::Event* 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   kernel::resource::CpuAction* execution_start(double size) override;
118   kernel::resource::Action* execution_start(double, int) override
119   {
120     THROW_UNIMPLEMENTED;
121     return nullptr;
122   }
123   kernel::resource::CpuAction* sleep(double duration) override;
124   double get_speed_ratio() override;
125
126   void set_modified(bool modified);
127
128   CpuTiTmgr* 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   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 kernel::resource::CpuModel {
143 public:
144   static void create_pm_vm_models(); // Make both models be TI models
145
146   CpuTiModel();
147   CpuTiModel(const CpuTiModel&) = delete;
148   CpuTiModel& operator=(const CpuTiModel&) = delete;
149   ~CpuTiModel() override;
150   kernel::resource::Cpu* create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate, int core) override;
151   double next_occuring_event(double now) override;
152   void update_actions_state(double now, double delta) override;
153
154   CpuTiList modified_cpus_;
155 };
156
157 } // namespace surf
158 } // namespace simgrid
159
160 #endif /* SURF_MODEL_CPUTI_H_ */