1 /* Copyright (c) 2013-2019. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SURF_MODEL_CPUTI_H_
7 #define SURF_MODEL_CPUTI_H_
9 #include "src/kernel/resource/profile/trace_mgr.hpp"
10 #include "src/surf/cpu_interface.hpp"
12 #include <boost/intrusive/list.hpp>
21 class XBT_PRIVATE CpuTiModel;
22 class XBT_PRIVATE CpuTi;
29 explicit CpuTiProfile(profile::Profile* profile);
30 CpuTiProfile(const CpuTiProfile&) = delete;
31 CpuTiProfile& operator=(const CpuTiProfile&) = delete;
34 double integrate_simple(double a, double b);
35 double integrate_simple_point(double a);
36 double solve_simple(double a, double amount);
41 int binary_search(double* array, double a, int low, int high);
46 FIXED, /*< Trace fixed, no availability file */
47 DYNAMIC /*< Dynamic, have an availability file */
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;
57 double integrate(double a, double b);
58 double solve(double a, double amount);
59 double get_power_scale(double a);
63 double value_; /*< Percentage of cpu speed available. Value fixed between 0 and 1 */
66 double last_time_ = 0.0; /*< Integral interval last point (discrete time) */
67 double total_ = 0.0; /*< Integral total between 0 and last_pointn */
69 CpuTiProfile* profile_ = nullptr;
70 profile::Profile* speed_profile_ = nullptr;
77 class XBT_PRIVATE CpuTiAction : public CpuAction {
80 CpuTiAction(CpuTi* cpu, double cost);
81 CpuTiAction(const CpuTiAction&) = delete;
82 CpuTiAction& operator=(const CpuTiAction&) = delete;
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;
95 boost::intrusive::list_member_hook<> action_ti_hook;
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;
104 class CpuTi : public Cpu {
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;
111 void set_speed_profile(profile::Profile* profile) override;
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);
117 bool is_used() override;
118 CpuAction* execution_start(double size) override;
119 Action* execution_start(double, int) override
124 CpuAction* sleep(double duration) override;
125 double get_speed_ratio() override;
127 void set_modified(bool modified);
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 */
134 boost::intrusive::list_member_hook<> cpu_ti_hook;
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;
143 class CpuTiModel : public CpuModel {
145 static void create_pm_vm_models(); // Make both models be TI models
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;
155 CpuTiList modified_cpus_;
158 } // namespace resource
159 } // namespace kernel
160 } // namespace simgrid
162 #endif /* SURF_MODEL_CPUTI_H_ */