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
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);
52 TRACE_FIXED, /*< Trace fixed, no availability file */
53 TRACE_DYNAMIC /*< Dynamic, have an availability file */
58 CpuTiTgmr(trace_type type, double value): m_type(type), m_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 m_value; /*< Percentage of cpu speed available. Value fixed between 0 and 1 */
71 double m_lastTime; /*< Integral interval last point (discrete time) */
72 double m_total; /*< Integral total between 0 and last_pointn */
75 tmgr_trace_t p_speedTrace;
82 class CpuTiAction: public CpuAction {
85 CpuTiAction(CpuTiModel *model, double cost, bool failed,
88 void setState(e_surf_action_state_t state);
91 void updateIndexHeap(int i);
95 void setMaxDuration(double duration);
96 void setPriority(double priority);
98 void setAffinity(Cpu * /*cpu*/, unsigned long /*mask*/) {};
104 boost::intrusive::list_member_hook<> action_ti_hook;
107 typedef boost::intrusive::member_hook<
108 CpuTiAction, boost::intrusive::list_member_hook<>, &CpuTiAction::action_ti_hook> ActionTiListOptions;
109 typedef boost::intrusive::list<
110 CpuTiAction, ActionTiListOptions > ActionTiList;
115 class CpuTi : public Cpu {
117 CpuTi(CpuTiModel *model, simgrid::Host *host, xbt_dynar_t speedPeak,
118 int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
119 e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace) ;
122 void updateState(tmgr_trace_event_t event_type, double value, double date);
123 void updateActionsFinishTime(double now);
125 void printCpuTiModel();
126 CpuAction *execute(double size);
127 CpuAction *sleep(double duration);
128 double getAvailableSpeed();
130 void modified(bool modified);
132 CpuTiTgmr *p_availTrace; /*< Structure with data needed to integrate trace file */
133 tmgr_trace_event_t p_stateEvent; /*< trace file with states events (ON or OFF) */
134 tmgr_trace_event_t p_speedEvent; /*< trace file with availability events */
135 ActionTiList *p_actionSet; /*< set with all actions running on cpu */
136 double m_sumPriority; /*< the sum of actions' priority that are running on cpu */
137 double m_lastUpdate; /*< last update of actions' remaining amount done */
139 double current_frequency;
141 void updateRemainingAmount(double now);
143 boost::intrusive::list_member_hook<> cpu_ti_hook;
146 typedef boost::intrusive::member_hook<
147 CpuTi, boost::intrusive::list_member_hook<>, &CpuTi::cpu_ti_hook> CpuTiListOptions;
148 typedef boost::intrusive::list<CpuTi, CpuTiListOptions> CpuTiList;
153 class CpuTiModel : public CpuModel {
157 Cpu *createCpu(simgrid::Host *host, xbt_dynar_t speedPeak,
158 int pstate, double speedScale,
159 tmgr_trace_t speedTrace, int core,
160 e_surf_resource_state_t state_initial,
161 tmgr_trace_t state_trace);
162 double shareResources(double now);
163 void updateActionsState(double now, double delta);
166 ActionList *p_runningActionSetThatDoesNotNeedBeingChecked;
167 CpuTiList *p_modifiedCpu;
168 xbt_heap_t p_tiActionHeap;
171 void NotifyResourceTurnedOn(simgrid::surf::Resource*){};
172 void NotifyResourceTurnedOff(simgrid::surf::Resource*){};
174 void NotifyActionCancel(Action*){};
175 void NotifyActionResume(Action*){};
176 void NotifyActionSuspend(Action*){};