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
23 typedef boost::intrusive::list<CpuTi> CpuTiList;
24 typedef boost::intrusive::list_base_hook<> cpuTiHook;
27 typedef boost::intrusive::list<CpuTiAction, boost::intrusive::base_hook<boost::intrusive::list_base_hook<boost::intrusive::tag<tiTag> > > > ActionTiList;
28 typedef boost::intrusive::list_base_hook<boost::intrusive::tag<tiTag> > actionTiHook;
35 CpuTiTrace(tmgr_trace_t powerTrace);
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, availability file disponible */
58 CpuTiTgmr(trace_type type, double value): m_type(type), m_value(value){};
59 CpuTiTgmr(tmgr_trace_t power_trace, 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 power disponible. Value fixed between 0 and 1 */
71 double m_lastTime; /*< Integral interval last point (discret time) */
72 double m_total; /*< Integral total between 0 and last_pointn */
75 tmgr_trace_t p_powerTrace;
81 class CpuTiModel : public CpuModel {
85 Cpu *createCpu(const char *name, xbt_dynar_t powerPeak,
86 int pstate, double power_scale,
87 tmgr_trace_t power_trace, int core,
88 e_surf_resource_state_t state_initial,
89 tmgr_trace_t state_trace,
90 xbt_dict_t cpu_properties);
91 double shareResources(double now);
92 void updateActionsState(double now, double delta);
95 ActionList *p_runningActionSetThatDoesNotNeedBeingChecked;
96 CpuTiList *p_modifiedCpu;
97 xbt_heap_t p_tiActionHeap;
100 void NotifyResourceTurnedOn(Resource*){};
101 void NotifyResourceTurnedOff(Resource*){};
103 void NotifyActionCancel(Action*){};
104 void NotifyActionResume(Action*){};
105 void NotifyActionSuspend(Action*){};
111 class CpuTi : public cpuTiHook, public Cpu {
114 CpuTi(CpuTiModel *model, const char *name, xbt_dynar_t powerPeak,
115 int pstate, double powerScale, tmgr_trace_t powerTrace, int core,
116 e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
117 xbt_dict_t properties) ;
120 void updateState(tmgr_trace_event_t event_type, double value, double date);
121 void updateActionsFinishTime(double now);
123 void printCpuTiModel();
124 CpuAction *execute(double size);
125 CpuAction *sleep(double duration);
126 double getAvailableSpeed();
128 double getCurrentPowerPeak() {THROW_UNIMPLEMENTED;};
129 double getPowerPeakAt(int /*pstate_index*/) {THROW_UNIMPLEMENTED;};
130 int getNbPstates() {THROW_UNIMPLEMENTED;};
131 void setPstate(int /*pstate_index*/) {THROW_UNIMPLEMENTED;};
132 int getPstate() { THROW_UNIMPLEMENTED;}
133 void modified(bool modified);
135 CpuTiTgmr *p_availTrace; /*< Structure with data needed to integrate trace file */
136 tmgr_trace_event_t p_stateEvent; /*< trace file with states events (ON or OFF) */
137 tmgr_trace_event_t p_powerEvent; /*< trace file with availability events */
138 ActionTiList *p_actionSet; /*< set with all actions running on cpu */
139 double m_sumPriority; /*< the sum of actions' priority that are running on cpu */
140 double m_lastUpdate; /*< last update of actions' remaining amount done */
142 double current_frequency;
144 void updateRemainingAmount(double now);
151 class CpuTiAction: public actionTiHook, public CpuAction {
152 friend CpuAction *CpuTi::execute(double size);
153 friend CpuAction *CpuTi::sleep(double duration);
154 friend void CpuTi::updateActionsFinishTime(double now);//FIXME
155 friend void CpuTi::updateRemainingAmount(double now);//FIXME
158 CpuTiAction(CpuTiModel *model, double cost, bool failed,
161 void setState(e_surf_action_state_t state);
164 void updateIndexHeap(int i);
168 void setMaxDuration(double duration);
169 void setPriority(double priority);
171 void setAffinity(Cpu */*cpu*/, unsigned long /*mask*/) {};