Logo AND Algorithmique Numérique Distribuée

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