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;
37 CpuTiTrace(tmgr_trace_t powerTrace);
40 double integrateSimple(double a, double b);
41 double integrateSimplePoint(double a);
42 double solveSimple(double a, double amount);
47 int binarySearch(double *array, double a, int low, int high);
54 TRACE_FIXED, /*< Trace fixed, no availability file */
55 TRACE_DYNAMIC /*< Dynamic, availability file disponible */
60 CpuTiTgmr(trace_type type, double value): m_type(type), m_value(value){};
61 CpuTiTgmr(tmgr_trace_t power_trace, double value);
64 double integrate(double a, double b);
65 double solve(double a, double amount);
66 double solveSomewhatSimple(double a, double amount);
67 double getPowerScale(double a);
70 double m_value; /*< Percentage of cpu power disponible. Value fixed between 0 and 1 */
73 double m_lastTime; /*< Integral interval last point (discret time) */
74 double m_total; /*< Integral total between 0 and last_pointn */
76 CpuTiTracePtr p_trace;
77 tmgr_trace_t p_powerTrace;
83 class CpuTiModel : public CpuModel {
88 void parseInit(sg_platf_host_cbarg_t host);
89 CpuTiPtr createResource(const char *name, xbt_dynar_t powerPeak,
90 int pstate, double power_scale,
91 tmgr_trace_t power_trace, int core,
92 e_surf_resource_state_t state_initial,
93 tmgr_trace_t state_trace,
94 xbt_dict_t cpu_properties);
95 CpuTiActionPtr createAction(double cost, bool failed);
96 double shareResources(double now);
97 void updateActionsState(double now, double delta);
100 ActionListPtr p_runningActionSetThatDoesNotNeedBeingChecked;
101 xbt_swag_t p_modifiedCpu;
102 xbt_heap_t p_tiActionHeap;
105 void NotifyResourceTurnedOn(ResourcePtr){};
106 void NotifyResourceTurnedOff(ResourcePtr){};
108 void NotifyActionCancel(ActionPtr){};
109 void NotifyActionResume(ActionPtr){};
110 void NotifyActionSuspend(ActionPtr){};
116 class CpuTi : public Cpu {
119 CpuTi(CpuTiModelPtr model, const char *name, xbt_dynar_t powerPeak,
120 int pstate, double powerScale, tmgr_trace_t powerTrace, 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 CpuActionPtr execute(double size);
130 CpuActionPtr 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 setPowerPeakAt(int /*pstate_index*/) {THROW_UNIMPLEMENTED;};
138 CpuTiTgmrPtr p_availTrace; /*< Structure with data needed to integrate trace file */
139 tmgr_trace_event_t p_stateEvent; /*< trace file with states events (ON or OFF) */
140 tmgr_trace_event_t p_powerEvent; /*< trace file with availability events */
141 xbt_swag_t p_actionSet; /*< set with all actions running on cpu */
142 s_xbt_swag_hookup_t p_modifiedCpuHookup; /*< hookup to swag that indicates whether share resources must be recalculated or not */
143 double m_sumPriority; /*< the sum of actions' priority that are running on cpu */
144 double m_lastUpdate; /*< last update of actions' remaining amount done */
146 int m_pstate; /*< Current pstate (index in the power_peak_list)*/
147 double current_frequency;
149 void updateRemainingAmount(double now);
156 class CpuTiAction: public CpuAction {
157 friend CpuActionPtr CpuTi::execute(double size);
158 friend CpuActionPtr CpuTi::sleep(double duration);
159 friend void CpuTi::updateActionsFinishTime(double now);//FIXME
160 friend void CpuTi::updateRemainingAmount(double now);//FIXME
164 CpuTiAction(CpuTiModelPtr model, double cost, bool failed,
167 void setState(e_surf_action_state_t state);
171 void updateIndexHeap(int i);
175 void setMaxDuration(double duration);
176 void setPriority(double priority);
178 void setAffinity(CpuPtr /*cpu*/, unsigned long /*mask*/) {};
179 void setBound(double /*bound*/) {};
183 s_xbt_swag_hookup_t p_cpuListHookup;