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 powerTrace);
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, availability file disponible */
55 CpuTiTgmr(trace_type type, double value): m_type(type), m_value(value){};
56 CpuTiTgmr(tmgr_trace_t power_trace, 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 power disponible. Value fixed between 0 and 1 */
68 double m_lastTime; /*< Integral interval last point (discret time) */
69 double m_total; /*< Integral total between 0 and last_pointn */
72 tmgr_trace_t p_speedTrace;
79 class CpuTiAction: public CpuAction {
81 // friend CpuAction *CpuTi::execute(double size);
82 // friend CpuAction *CpuTi::sleep(double duration);
83 // friend void CpuTi::updateActionsFinishTime(double now);//FIXME
84 // friend void CpuTi::updateRemainingAmount(double now);//FIXME
86 CpuTiAction(CpuTiModel *model, double cost, bool failed,
89 void setState(e_surf_action_state_t state);
92 void updateIndexHeap(int i);
96 void setMaxDuration(double duration);
97 void setPriority(double priority);
99 void setAffinity(Cpu * /*cpu*/, unsigned long /*mask*/) {};
105 boost::intrusive::list_member_hook<> action_ti_hook;
108 typedef boost::intrusive::member_hook<
109 CpuTiAction, boost::intrusive::list_member_hook<>, &CpuTiAction::action_ti_hook> ActionTiListOptions;
110 typedef boost::intrusive::list<
111 CpuTiAction, ActionTiListOptions > ActionTiList;
116 class CpuTi : public Cpu {
119 CpuTi(CpuTiModel *model, const char *name, xbt_dynar_t speedPeak,
120 int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
121 e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
122 xbt_dict_t properties) ;
125 void updateState(tmgr_trace_event_t event_type, double value, double date);
126 void updateActionsFinishTime(double now);
128 void printCpuTiModel();
129 CpuAction *execute(double size);
130 CpuAction *sleep(double duration);
131 double getAvailableSpeed();
133 double getCurrentPowerPeak() {THROW_UNIMPLEMENTED;};
134 double getPowerPeakAt(int /*pstate_index*/) {THROW_UNIMPLEMENTED;};
135 int getNbPstates() {THROW_UNIMPLEMENTED;};
136 void setPstate(int /*pstate_index*/) {THROW_UNIMPLEMENTED;};
137 int getPstate() { THROW_UNIMPLEMENTED;}
138 void modified(bool modified);
140 CpuTiTgmr *p_availTrace; /*< Structure with data needed to integrate trace file */
141 tmgr_trace_event_t p_stateEvent; /*< trace file with states events (ON or OFF) */
142 tmgr_trace_event_t p_speedEvent; /*< trace file with availability events */
143 ActionTiList *p_actionSet; /*< set with all actions running on cpu */
144 double m_sumPriority; /*< the sum of actions' priority that are running on cpu */
145 double m_lastUpdate; /*< last update of actions' remaining amount done */
147 double current_frequency;
149 void updateRemainingAmount(double now);
151 boost::intrusive::list_member_hook<> cpu_ti_hook;
154 typedef boost::intrusive::member_hook<
155 CpuTi, boost::intrusive::list_member_hook<>, &CpuTi::cpu_ti_hook> CpuTiListOptions;
156 typedef boost::intrusive::list<CpuTi, CpuTiListOptions> CpuTiList;
161 class CpuTiModel : public CpuModel {
165 Cpu *createCpu(const char *name, xbt_dynar_t speedPeak,
166 int pstate, double speedScale,
167 tmgr_trace_t speedTrace, int core,
168 e_surf_resource_state_t state_initial,
169 tmgr_trace_t state_trace,
170 xbt_dict_t cpu_properties);
171 double shareResources(double now);
172 void updateActionsState(double now, double delta);
175 ActionList *p_runningActionSetThatDoesNotNeedBeingChecked;
176 CpuTiList *p_modifiedCpu;
177 xbt_heap_t p_tiActionHeap;
180 void NotifyResourceTurnedOn(Resource*){};
181 void NotifyResourceTurnedOff(Resource*){};
183 void NotifyActionCancel(Action*){};
184 void NotifyActionResume(Action*){};
185 void NotifyActionSuspend(Action*){};