1 /* Copyright (c) 2013-2018. 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 #include <boost/intrusive/list.hpp>
10 #include "src/surf/cpu_interface.hpp"
11 #include "src/surf/trace_mgr.hpp"
14 #define EPSILON 0.000000001
22 class XBT_PRIVATE CpuTiModel;
23 class XBT_PRIVATE CpuTi;
30 explicit CpuTiTrace(tmgr_trace_t speedTrace);
31 CpuTiTrace(const CpuTiTrace&) = delete;
32 CpuTiTrace& operator=(const CpuTiTrace&) = delete;
35 double integrate_simple(double a, double b);
36 double integrate_simple_point(double a);
37 double solve_simple(double a, double amount);
42 int binary_search(double* array, double a, int low, int high);
47 TRACE_FIXED, /*< Trace fixed, no availability file */
48 TRACE_DYNAMIC /*< Dynamic, have an availability file */
53 CpuTiTgmr(trace_type type, double value)
54 : type_(type), value_(value)
56 CpuTiTgmr(tmgr_trace_t speedTrace, double value);
57 CpuTiTgmr(const CpuTiTgmr&) = delete;
58 CpuTiTgmr& operator=(const CpuTiTgmr&) = delete;
61 double integrate(double a, double b);
62 double solve(double a, double amount);
63 double get_power_scale(double a);
66 double value_; /*< Percentage of cpu speed available. Value fixed between 0 and 1 */
69 double last_time_ = 0.0; /*< Integral interval last point (discrete time) */
70 double total_ = 0.0; /*< Integral total between 0 and last_pointn */
72 CpuTiTrace *trace_ = nullptr;
73 tmgr_trace_t speed_trace_ = nullptr;
80 class XBT_PRIVATE CpuTiAction : public CpuAction {
83 CpuTiAction(CpuTiModel *model, double cost, bool failed, CpuTi *cpu);
86 void set_state(simgrid::kernel::resource::Action::State state) override;
87 void cancel() override;
88 void suspend() override;
89 void resume() override;
90 void set_max_duration(double duration) override;
91 void set_priority(double priority) override;
92 double get_remains() override;
96 boost::intrusive::list_member_hook<> action_ti_hook;
99 typedef boost::intrusive::member_hook<CpuTiAction, boost::intrusive::list_member_hook<>, &CpuTiAction::action_ti_hook> ActionTiListOptions;
100 typedef boost::intrusive::list<CpuTiAction, ActionTiListOptions > ActionTiList;
105 class CpuTi : public Cpu {
107 CpuTi(CpuTiModel* model, simgrid::s4u::Host* host, std::vector<double>* speed_per_pstate, int core);
110 void set_speed_trace(tmgr_trace_t trace) override;
112 void apply_event(tmgr_trace_event_t event, double value) override;
113 void update_actions_finish_time(double now);
114 void update_remaining_amount(double now);
116 bool is_used() override;
117 CpuAction *execution_start(double size) override;
118 simgrid::kernel::resource::Action* execution_start(double size, int requestedCores) override
123 CpuAction *sleep(double duration) override;
124 double get_available_speed() override;
126 void set_modified(bool modified);
128 CpuTiTgmr* 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 */
133 double current_frequency_;
135 boost::intrusive::list_member_hook<> cpu_ti_hook;
138 typedef boost::intrusive::member_hook<CpuTi, boost::intrusive::list_member_hook<>, &CpuTi::cpu_ti_hook> CpuTiListOptions;
139 typedef boost::intrusive::list<CpuTi, CpuTiListOptions> CpuTiList;
144 class CpuTiModel : public CpuModel {
146 CpuTiModel() : CpuModel(Model::UpdateAlgo::Full){};
147 ~CpuTiModel() override;
148 Cpu* createCpu(simgrid::s4u::Host* host, std::vector<double>* speed_per_pstate, int core) override;
149 double next_occuring_event(double now) override;
150 void update_actions_state(double now, double delta) override;
152 kernel::resource::Action::StateSet runningActionSetThatDoesNotNeedBeingChecked_;
153 CpuTiList modified_cpus_;