Logo AND Algorithmique Numérique Distribuée

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