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. */
9 #include "src/surf/cpu_interface.hpp"
10 #include "src/surf/trace_mgr.hpp"
11 #include "surf/surf_routing.h"
14 #define EPSILON 0.000000001
22 class XBT_PRIVATE CpuTiTrace;
23 class XBT_PRIVATE CpuTiTgmr;
24 class XBT_PRIVATE CpuTiModel;
25 class XBT_PRIVATE CpuTi;
26 class XBT_PRIVATE CpuTiAction;
35 CpuTiTrace(tmgr_trace_t speedTrace);
38 double integrateSimple(double a, double b);
39 double integrateSimplePoint(double a);
40 double solveSimple(double a, double amount);
45 int binarySearch(double *array, double a, int low, int high);
50 TRACE_FIXED, /*< Trace fixed, no availability file */
51 TRACE_DYNAMIC /*< Dynamic, have an availability file */
56 CpuTiTgmr(trace_type type, double value)
57 : type_(type), value_(value)
59 CpuTiTgmr(tmgr_trace_t speedTrace, double value);
62 double integrate(double a, double b);
63 double solve(double a, double amount);
64 double solveSomewhatSimple(double a, double amount);
65 double getPowerScale(double a);
68 double value_; /*< Percentage of cpu speed available. Value fixed between 0 and 1 */
71 double lastTime_ = 0.0; /*< Integral interval last point (discrete time) */
72 double total_ = 0.0; /*< Integral total between 0 and last_pointn */
74 CpuTiTrace *trace_ = nullptr;
75 tmgr_trace_t speedTrace_ = nullptr;
82 class CpuTiAction: public CpuAction {
85 CpuTiAction(CpuTiModel *model, double cost, bool failed, CpuTi *cpu);
87 void setState(simgrid::surf::Action::State state) override;
89 void cancel() override;
90 void updateIndexHeap(int i);
91 void suspend() override;
92 void resume() override;
93 void setMaxDuration(double duration) override;
94 void setPriority(double priority) override;
95 double getRemains() override;
96 void setAffinity(Cpu * /*cpu*/, unsigned long /*mask*/) override {};
102 boost::intrusive::list_member_hook<> action_ti_hook;
105 typedef boost::intrusive::member_hook<CpuTiAction, boost::intrusive::list_member_hook<>, &CpuTiAction::action_ti_hook> ActionTiListOptions;
106 typedef boost::intrusive::list<CpuTiAction, ActionTiListOptions > ActionTiList;
111 class CpuTi : public Cpu {
113 CpuTi(CpuTiModel *model, simgrid::s4u::Host *host, xbt_dynar_t speedPerPstate, int core);
116 void setSpeedTrace(tmgr_trace_t trace) override;
118 void apply_event(tmgr_trace_iterator_t event, double value) override;
119 void updateActionsFinishTime(double now);
120 void updateRemainingAmount(double now);
122 bool isUsed() override;
123 CpuAction *execution_start(double size) override;
124 CpuAction *sleep(double duration) override;
125 double getAvailableSpeed() override;
127 void modified(bool modified);
129 CpuTiTgmr *speedIntegratedTrace_ = NULL;/*< Structure with data needed to integrate trace file */
130 ActionTiList *actionSet_ = NULL; /*< set with all actions running on cpu */
131 double sumPriority_ = 0; /*< the sum of actions' priority that are running on cpu */
132 double lastUpdate_ = 0; /*< last update of actions' remaining amount done */
134 double currentFrequency_;
137 boost::intrusive::list_member_hook<> cpu_ti_hook;
140 typedef boost::intrusive::member_hook<CpuTi, boost::intrusive::list_member_hook<>, &CpuTi::cpu_ti_hook> CpuTiListOptions;
141 typedef boost::intrusive::list<CpuTi, CpuTiListOptions> CpuTiList;
146 class CpuTiModel : public CpuModel {
150 Cpu *createCpu(simgrid::s4u::Host *host, xbt_dynar_t speedPerPstate, int core) override;
151 double next_occuring_event(double now) override;
152 void updateActionsState(double now, double delta) override;
154 ActionList *runningActionSetThatDoesNotNeedBeingChecked_;
155 CpuTiList *modifiedCpu_;
156 xbt_heap_t tiActionHeap_;
159 void NotifyResourceTurnedOn(simgrid::surf::Resource*){};
160 void NotifyResourceTurnedOff(simgrid::surf::Resource*){};
162 void NotifyActionCancel(Action*){};
163 void NotifyActionResume(Action*){};
164 void NotifyActionSuspend(Action*){};