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 "cpu_interface.hpp"
10 #include "trace_mgr_private.h"
11 #include "surf/surf_routing.h"
14 #define EPSILON 0.000000001
19 class XBT_PRIVATE CpuTiTrace;
20 class XBT_PRIVATE CpuTiTgmr;
21 class XBT_PRIVATE CpuTiModel;
22 class XBT_PRIVATE CpuTi;
23 class XBT_PRIVATE CpuTiAction;
32 CpuTiTrace(tmgr_trace_t speedTrace);
35 double integrateSimple(double a, double b);
36 double integrateSimplePoint(double a);
37 double solveSimple(double a, double amount);
42 int binarySearch(double *array, double a, int low, int high);
49 TRACE_FIXED, /*< Trace fixed, no availability file */
50 TRACE_DYNAMIC /*< Dynamic, have an availability file */
55 CpuTiTgmr(trace_type type, double value): m_type(type), m_value(value){};
56 CpuTiTgmr(tmgr_trace_t speedTrace, double value);
59 double integrate(double a, double b);
60 double solve(double a, double amount);
61 double solveSomewhatSimple(double a, double amount);
62 double getPowerScale(double a);
65 double m_value; /*< Percentage of cpu speed available. Value fixed between 0 and 1 */
68 double m_lastTime; /*< Integral interval last point (discrete time) */
69 double m_total; /*< Integral total between 0 and last_pointn */
72 tmgr_trace_t p_speedTrace;
79 class CpuTiAction: public CpuAction {
82 CpuTiAction(CpuTiModel *model, double cost, bool failed,
85 void setState(e_surf_action_state_t state);
88 void updateIndexHeap(int i);
92 void setMaxDuration(double duration);
93 void setPriority(double priority);
95 void setAffinity(Cpu * /*cpu*/, unsigned long /*mask*/) {};
101 boost::intrusive::list_member_hook<> action_ti_hook;
104 typedef boost::intrusive::member_hook<
105 CpuTiAction, boost::intrusive::list_member_hook<>, &CpuTiAction::action_ti_hook> ActionTiListOptions;
106 typedef boost::intrusive::list<
107 CpuTiAction, ActionTiListOptions > ActionTiList;
112 class CpuTi : public Cpu {
115 CpuTi(CpuTiModel *model, const char *name, xbt_dynar_t speedPeak,
116 int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
117 e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
118 xbt_dict_t properties) ;
121 void updateState(tmgr_trace_event_t event_type, double value, double date);
122 void updateActionsFinishTime(double now);
124 void printCpuTiModel();
125 CpuAction *execute(double size);
126 CpuAction *sleep(double duration);
127 double getAvailableSpeed();
129 double getCurrentPowerPeak() {THROW_UNIMPLEMENTED;};
130 double getPowerPeakAt(int /*pstate_index*/) {THROW_UNIMPLEMENTED;};
131 int getNbPstates() {THROW_UNIMPLEMENTED;};
132 void setPstate(int /*pstate_index*/) {THROW_UNIMPLEMENTED;};
133 int getPstate() { THROW_UNIMPLEMENTED;}
134 void modified(bool modified);
136 CpuTiTgmr *p_availTrace; /*< Structure with data needed to integrate trace file */
137 tmgr_trace_event_t p_stateEvent; /*< trace file with states events (ON or OFF) */
138 tmgr_trace_event_t p_speedEvent; /*< trace file with availability events */
139 ActionTiList *p_actionSet; /*< set with all actions running on cpu */
140 double m_sumPriority; /*< the sum of actions' priority that are running on cpu */
141 double m_lastUpdate; /*< last update of actions' remaining amount done */
143 double current_frequency;
145 void updateRemainingAmount(double now);
147 boost::intrusive::list_member_hook<> cpu_ti_hook;
150 typedef boost::intrusive::member_hook<
151 CpuTi, boost::intrusive::list_member_hook<>, &CpuTi::cpu_ti_hook> CpuTiListOptions;
152 typedef boost::intrusive::list<CpuTi, CpuTiListOptions> CpuTiList;
157 class CpuTiModel : public CpuModel {
161 Cpu *createCpu(const char *name, xbt_dynar_t speedPeak,
162 int pstate, double speedScale,
163 tmgr_trace_t speedTrace, int core,
164 e_surf_resource_state_t state_initial,
165 tmgr_trace_t state_trace,
166 xbt_dict_t cpu_properties);
167 double shareResources(double now);
168 void updateActionsState(double now, double delta);
171 ActionList *p_runningActionSetThatDoesNotNeedBeingChecked;
172 CpuTiList *p_modifiedCpu;
173 xbt_heap_t p_tiActionHeap;
176 void NotifyResourceTurnedOn(Resource*){};
177 void NotifyResourceTurnedOff(Resource*){};
179 void NotifyActionCancel(Action*){};
180 void NotifyActionResume(Action*){};
181 void NotifyActionSuspend(Action*){};