1 /* Copyright (c) 2013-2014. 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 "cpu_interface.hpp"
8 #include "trace_mgr_private.h"
9 #include "surf/surf_routing.h"
12 #define EPSILON 0.000000001
18 typedef CpuTiTrace *CpuTiTracePtr;
21 typedef CpuTiTgmr *CpuTiTgmrPtr;
24 typedef CpuTiModel *CpuTiModelPtr;
27 typedef CpuTi *CpuTiPtr;
30 typedef CpuTiAction *CpuTiActionPtr;
32 typedef boost::intrusive::list<CpuTi> CpuTiList;
33 typedef CpuTiList* CpuTiListPtr;
34 typedef boost::intrusive::list_base_hook<> cpuTiHook;
37 typedef boost::intrusive::list<CpuTiAction, boost::intrusive::base_hook<boost::intrusive::list_base_hook<boost::intrusive::tag<tiTag> > > > ActionTiList;
38 typedef ActionTiList* ActionTiListPtr;
39 typedef boost::intrusive::list_base_hook<boost::intrusive::tag<tiTag> > actionTiHook;
46 CpuTiTrace(tmgr_trace_t powerTrace);
49 double integrateSimple(double a, double b);
50 double integrateSimplePoint(double a);
51 double solveSimple(double a, double amount);
56 int binarySearch(double *array, double a, int low, int high);
63 TRACE_FIXED, /*< Trace fixed, no availability file */
64 TRACE_DYNAMIC /*< Dynamic, availability file disponible */
69 CpuTiTgmr(trace_type type, double value): m_type(type), m_value(value){};
70 CpuTiTgmr(tmgr_trace_t power_trace, double value);
73 double integrate(double a, double b);
74 double solve(double a, double amount);
75 double solveSomewhatSimple(double a, double amount);
76 double getPowerScale(double a);
79 double m_value; /*< Percentage of cpu power disponible. Value fixed between 0 and 1 */
82 double m_lastTime; /*< Integral interval last point (discret time) */
83 double m_total; /*< Integral total between 0 and last_pointn */
85 CpuTiTracePtr p_trace;
86 tmgr_trace_t p_powerTrace;
92 class CpuTiModel : public CpuModel {
96 CpuPtr createCpu(const char *name, xbt_dynar_t powerPeak,
97 int pstate, double power_scale,
98 tmgr_trace_t power_trace, int core,
99 e_surf_resource_state_t state_initial,
100 tmgr_trace_t state_trace,
101 xbt_dict_t cpu_properties);
102 double shareResources(double now);
103 void updateActionsState(double now, double delta);
106 ActionListPtr p_runningActionSetThatDoesNotNeedBeingChecked;
107 CpuTiListPtr p_modifiedCpu;
108 xbt_heap_t p_tiActionHeap;
111 void NotifyResourceTurnedOn(ResourcePtr){};
112 void NotifyResourceTurnedOff(ResourcePtr){};
114 void NotifyActionCancel(ActionPtr){};
115 void NotifyActionResume(ActionPtr){};
116 void NotifyActionSuspend(ActionPtr){};
122 class CpuTi : public cpuTiHook, public Cpu {
125 CpuTi(CpuTiModelPtr model, const char *name, xbt_dynar_t powerPeak,
126 int pstate, double powerScale, tmgr_trace_t powerTrace, int core,
127 e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
128 xbt_dict_t properties) ;
131 void updateState(tmgr_trace_event_t event_type, double value, double date);
132 void updateActionsFinishTime(double now);
134 void printCpuTiModel();
135 CpuActionPtr execute(double size);
136 CpuActionPtr sleep(double duration);
137 double getAvailableSpeed();
139 double getCurrentPowerPeak() {THROW_UNIMPLEMENTED;};
140 double getPowerPeakAt(int /*pstate_index*/) {THROW_UNIMPLEMENTED;};
141 int getNbPstates() {THROW_UNIMPLEMENTED;};
142 void setPowerPeakAt(int /*pstate_index*/) {THROW_UNIMPLEMENTED;};
143 void modified(bool modified);
145 CpuTiTgmrPtr p_availTrace; /*< Structure with data needed to integrate trace file */
146 tmgr_trace_event_t p_stateEvent; /*< trace file with states events (ON or OFF) */
147 tmgr_trace_event_t p_powerEvent; /*< trace file with availability events */
148 ActionTiListPtr p_actionSet; /*< set with all actions running on cpu */
149 double m_sumPriority; /*< the sum of actions' priority that are running on cpu */
150 double m_lastUpdate; /*< last update of actions' remaining amount done */
152 double current_frequency;
154 void updateRemainingAmount(double now);
161 class CpuTiAction: public actionTiHook, public CpuAction {
162 friend CpuActionPtr CpuTi::execute(double size);
163 friend CpuActionPtr CpuTi::sleep(double duration);
164 friend void CpuTi::updateActionsFinishTime(double now);//FIXME
165 friend void CpuTi::updateRemainingAmount(double now);//FIXME
168 CpuTiAction(CpuTiModelPtr model, double cost, bool failed,
171 void setState(e_surf_action_state_t state);
175 void updateIndexHeap(int i);
179 void setMaxDuration(double duration);
180 void setPriority(double priority);
182 void setAffinity(CpuPtr /*cpu*/, unsigned long /*mask*/) {};