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);
33 double integrate_simple(double a, double b);
34 double integrate_simple_point(double a);
35 double solve_simple(double a, double amount);
40 int binary_search(double* array, double a, int low, int high);
45 TRACE_FIXED, /*< Trace fixed, no availability file */
46 TRACE_DYNAMIC /*< Dynamic, have an availability file */
51 CpuTiTgmr(trace_type type, double value)
52 : type_(type), value_(value)
54 CpuTiTgmr(tmgr_trace_t speedTrace, double value);
57 double integrate(double a, double b);
58 double solve(double a, double amount);
59 double get_power_scale(double a);
62 double value_; /*< Percentage of cpu speed available. Value fixed between 0 and 1 */
65 double last_time_ = 0.0; /*< Integral interval last point (discrete time) */
66 double total_ = 0.0; /*< Integral total between 0 and last_pointn */
68 CpuTiTrace *trace_ = nullptr;
69 tmgr_trace_t speed_trace_ = nullptr;
76 class CpuTiAction: public CpuAction {
79 CpuTiAction(CpuTiModel *model, double cost, bool failed, CpuTi *cpu);
82 void set_state(simgrid::kernel::resource::Action::State state) override;
83 void cancel() override;
84 void suspend() override;
85 void resume() override;
86 void set_max_duration(double duration) override;
87 void set_priority(double priority) override;
88 double get_remains() override;
92 boost::intrusive::list_member_hook<> action_ti_hook;
95 typedef boost::intrusive::member_hook<CpuTiAction, boost::intrusive::list_member_hook<>, &CpuTiAction::action_ti_hook> ActionTiListOptions;
96 typedef boost::intrusive::list<CpuTiAction, ActionTiListOptions > ActionTiList;
101 class CpuTi : public Cpu {
103 CpuTi(CpuTiModel* model, simgrid::s4u::Host* host, std::vector<double>* speed_per_pstate, int core);
106 void set_speed_trace(tmgr_trace_t trace) override;
108 void apply_event(tmgr_trace_event_t event, double value) override;
109 void update_actions_finish_time(double now);
110 void update_remaining_amount(double now);
112 bool is_used() override;
113 CpuAction *execution_start(double size) override;
114 simgrid::kernel::resource::Action* execution_start(double size, int requestedCores) override
119 CpuAction *sleep(double duration) override;
120 double get_available_speed() override;
122 void set_modified(bool modified);
124 CpuTiTgmr* speed_integrated_trace_ = nullptr; /*< Structure with data needed to integrate trace file */
125 ActionTiList action_set_; /*< set with all actions running on cpu */
126 double sum_priority_ = 0; /*< the sum of actions' priority that are running on cpu */
127 double last_update_ = 0; /*< last update of actions' remaining amount done */
129 double current_frequency_;
131 boost::intrusive::list_member_hook<> cpu_ti_hook;
134 typedef boost::intrusive::member_hook<CpuTi, boost::intrusive::list_member_hook<>, &CpuTi::cpu_ti_hook> CpuTiListOptions;
135 typedef boost::intrusive::list<CpuTi, CpuTiListOptions> CpuTiList;
140 class CpuTiModel : public CpuModel {
142 CpuTiModel() = default;
143 ~CpuTiModel() override;
144 Cpu* createCpu(simgrid::s4u::Host* host, std::vector<double>* speed_per_pstate, int core) override;
145 double next_occuring_event(double now) override;
146 void update_actions_state(double now, double delta) override;
148 kernel::resource::Action::StateSet runningActionSetThatDoesNotNeedBeingChecked_;
149 CpuTiList modified_cpus_;