1 /* Copyright (c) 2013-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include <boost/intrusive/list.hpp>
11 #include "src/surf/cpu_interface.hpp"
12 #include "src/surf/trace_mgr.hpp"
15 #define EPSILON 0.000000001
23 class XBT_PRIVATE CpuTiTrace;
24 class XBT_PRIVATE CpuTiTgmr;
25 class XBT_PRIVATE CpuTiModel;
26 class XBT_PRIVATE CpuTi;
27 class XBT_PRIVATE CpuTiAction;
36 explicit CpuTiTrace(tmgr_trace_t speedTrace);
39 double integrateSimple(double a, double b);
40 double integrateSimplePoint(double a);
41 double solveSimple(double a, double amount);
46 int binarySearch(double *array, double a, int low, int high);
51 TRACE_FIXED, /*< Trace fixed, no availability file */
52 TRACE_DYNAMIC /*< Dynamic, have an availability file */
57 CpuTiTgmr(trace_type type, double value)
58 : type_(type), value_(value)
60 CpuTiTgmr(tmgr_trace_t speedTrace, double value);
63 double integrate(double a, double b);
64 double solve(double a, double amount);
65 double solveSomewhatSimple(double a, double amount);
66 double getPowerScale(double a);
69 double value_; /*< Percentage of cpu speed available. Value fixed between 0 and 1 */
72 double lastTime_ = 0.0; /*< Integral interval last point (discrete time) */
73 double total_ = 0.0; /*< Integral total between 0 and last_pointn */
75 CpuTiTrace *trace_ = nullptr;
76 tmgr_trace_t speedTrace_ = nullptr;
83 class CpuTiAction: public CpuAction {
86 CpuTiAction(CpuTiModel *model, double cost, bool failed, CpuTi *cpu);
88 void setState(simgrid::surf::Action::State state) override;
90 void cancel() override;
91 void updateIndexHeap(int i) override;
92 void suspend() override;
93 void resume() override;
94 void setMaxDuration(double duration) override;
95 void setSharingWeight(double priority) override;
96 double getRemains() override;
100 boost::intrusive::list_member_hook<> action_ti_hook;
103 typedef boost::intrusive::member_hook<CpuTiAction, boost::intrusive::list_member_hook<>, &CpuTiAction::action_ti_hook> ActionTiListOptions;
104 typedef boost::intrusive::list<CpuTiAction, ActionTiListOptions > ActionTiList;
109 class CpuTi : public Cpu {
111 CpuTi(CpuTiModel *model, simgrid::s4u::Host *host, std::vector<double> *speedPerPstate, int core);
114 void setSpeedTrace(tmgr_trace_t trace) override;
116 void apply_event(tmgr_trace_event_t event, double value) override;
117 void updateActionsFinishTime(double now);
118 void updateRemainingAmount(double now);
120 bool isUsed() override;
121 CpuAction *execution_start(double size) override;
122 CpuAction *sleep(double duration) override;
123 double getAvailableSpeed() override;
125 void modified(bool modified);
127 CpuTiTgmr *speedIntegratedTrace_ = nullptr;/*< Structure with data needed to integrate trace file */
128 ActionTiList *actionSet_ = nullptr; /*< set with all actions running on cpu */
129 double sumPriority_ = 0; /*< the sum of actions' priority that are running on cpu */
130 double lastUpdate_ = 0; /*< last update of actions' remaining amount done */
132 double currentFrequency_;
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 {
146 ~CpuTiModel() override;
147 Cpu *createCpu(simgrid::s4u::Host *host, std::vector<double>* speedPerPstate, int core) override;
148 double nextOccuringEvent(double now) override;
149 void updateActionsState(double now, double delta) override;
151 ActionList *runningActionSetThatDoesNotNeedBeingChecked_;
152 CpuTiList *modifiedCpu_;
153 xbt_heap_t tiActionHeap_;