1 //using namespace generic;
11 #include <boost/function.hpp>
12 #include <boost/intrusive/list.hpp>
13 #include "surf/trace_mgr.h"
15 #include "surf/surf_routing.h"
16 #include "simgrid/platf_interface.h"
17 #include "surf/surf.h"
18 #include "surf/surf_private.h"
20 extern tmgr_history_t history;
21 #define NO_MAX_DURATION -1.0
25 /** \ingroup SURF_simulation
26 * \brief Return the current time
28 * Return the current time in millisecond.
35 /* user-visible parameters */
36 extern double sg_tcp_gamma;
37 extern double sg_sender_gap;
38 extern double sg_latency_factor;
39 extern double sg_bandwidth_factor;
40 extern double sg_weight_S_parameter;
41 extern int sg_network_crosstraffic;
43 extern double sg_gtnets_jitter;
44 extern int sg_gtnets_jitter_seed;
46 extern xbt_dynar_t surf_path;
49 XBT_PUBLIC(double) surf_get_clock(void);
52 extern double sg_sender_gap;
53 XBT_PUBLIC(int) SURF_CPU_LEVEL; //Surf cpu level
55 int __surf_is_absolute_file_path(const char *file_path);
61 typedef Model* ModelPtr;
64 typedef Resource* ResourcePtr;
65 typedef boost::function<void (ResourcePtr r)> ResourceCallback;
68 typedef Action* ActionPtr;
69 typedef boost::function<void (ActionPtr a)> ActionCallback;
71 typedef boost::intrusive::list<Action> ActionList;
72 typedef ActionList* ActionListPtr;
73 typedef boost::intrusive::list_base_hook<> actionHook;
76 typedef boost::intrusive::list<Action, boost::intrusive::base_hook<boost::intrusive::list_base_hook<boost::intrusive::tag<lmmTag> > > > ActionLmmList;
77 typedef ActionLmmList* ActionLmmListPtr;
78 typedef boost::intrusive::list_base_hook<boost::intrusive::tag<lmmTag> > actionLmmHook;
80 enum heap_action_type{
90 /* For the trace and trace:connect tag (store their content till the end of the parsing) */
91 XBT_PUBLIC_DATA(xbt_dict_t) traces_set_list;
92 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_host_avail;
93 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_power;
94 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_link_avail;
95 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_bandwidth;
96 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_latency;
102 XBT_PUBLIC_DATA(xbt_dynar_t) model_list;
107 ActionListPtr p_readyActionSet; /**< Actions in state SURF_ACTION_READY */
108 ActionListPtr p_runningActionSet; /**< Actions in state SURF_ACTION_RUNNING */
109 ActionListPtr p_failedActionSet; /**< Actions in state SURF_ACTION_FAILED */
110 ActionListPtr p_doneActionSet; /**< Actions in state SURF_ACTION_DONE */
112 ResourceCallback m_resOnCB, m_resOffCB;
113 ActionCallback m_actCancelCB, m_actSuspendCB, m_actResumeCB;
116 ActionLmmListPtr p_modifiedSet;
118 lmm_system_t p_maxminSystem;
119 e_UM_t p_updateMechanism;
120 int m_selectiveUpdate;
121 xbt_heap_t p_actionHeap;
124 Model(const char *name);
127 const char *getName() {return p_name;}
128 virtual ActionListPtr getReadyActionSet() {return p_readyActionSet;}
129 virtual ActionListPtr getRunningActionSet() {return p_runningActionSet;}
130 virtual ActionListPtr getFailedActionSet() {return p_failedActionSet;}
131 virtual ActionListPtr getDoneActionSet() {return p_doneActionSet;}
132 virtual ActionLmmListPtr getModifiedSet() {return p_modifiedSet;}
133 lmm_system_t getMaxminSystem() {return p_maxminSystem;}
134 e_UM_t getUpdateMechanism() {return p_updateMechanism;}
135 xbt_heap_t getActionHeap() {return p_actionHeap;}
137 ActionPtr createAction(double _cost, bool _failed);
138 virtual double shareResources(double now);
139 virtual double shareResourcesLazy(double now);
140 virtual double shareResourcesFull(double now);
141 double shareResourcesMaxMin(ActionListPtr running_actions,
143 void (*solve) (lmm_system_t));
144 virtual void updateActionsState(double now, double delta);
145 virtual void updateActionsStateLazy(double now, double delta);
146 virtual void updateActionsStateFull(double now, double delta);
148 void addTurnedOnCallback(ResourceCallback rc);
149 void notifyResourceTurnedOn(ResourcePtr r);
151 void addTurnedOffCallback(ResourceCallback rc);
152 void notifyResourceTurnedOff(ResourcePtr r);
154 void addActionCancelCallback(ActionCallback ac);
155 void notifyActionCancel(ActionPtr a);
156 void addActionResumeCallback(ActionCallback ac);
157 void notifyActionResume(ActionPtr a);
158 void addActionSuspendCallback(ActionCallback ac);
159 void notifyActionSuspend(ActionPtr a);
167 * Resource which have a metric handled by a maxmin system
172 tmgr_trace_event_t event;
179 xbt_dict_t p_properties;
183 e_surf_resource_state_t m_stateCurrent;
187 Resource(ModelPtr model, const char *name, xbt_dict_t props);
188 Resource(ModelPtr model, const char *name, xbt_dict_t props, lmm_constraint_t constraint);
189 Resource(ModelPtr model, const char *name, xbt_dict_t props, e_surf_resource_state_t stateInit);
190 Resource(ModelPtr model, const char *name, xbt_dict_t props, e_surf_resource_state_t stateInit, lmm_constraint_t constraint);
192 virtual ~Resource() {
193 xbt_free((void*)p_name);
194 xbt_dict_free(&p_properties);
197 ModelPtr getModel() {return p_model;};
198 const char *getName() {return p_name;};
199 virtual xbt_dict_t getProperties() {return p_properties;};
201 virtual void updateState(tmgr_trace_event_t event_type, double value, double date)=0;
202 virtual bool isUsed()=0;
206 void setName(string name);
208 virtual e_surf_resource_state_t getState();
209 virtual void setState(e_surf_resource_state_t state);
213 lmm_constraint_t p_constraint;
215 lmm_constraint_t getConstraint() {return p_constraint;};
222 void surf_action_lmm_update_index_heap(void *action, int i);
224 class Action : public actionHook, public actionLmmHook {
225 ActionLmmListPtr p_modifiedSet;
226 xbt_heap_t p_actionHeap;
227 int m_selectiveUpdate;
229 double m_bound; /**< the capping of the CPU use */
231 double m_start; /**< start time */
232 char *p_category; /**< tracing category for categorized resource utilization monitoring */
234 #ifdef HAVE_LATENCY_BOUND_TRACKING
235 int m_latencyLimited; /**< Set to 1 if is limited by latency, 0 otherwise */
238 void *p_data; /**< for your convenience */
241 ActionListPtr p_stateSet;
242 double m_priority; /**< priority (1.0 by default) */
244 double m_remains; /**< How much of that cost remains to be done in the currently running task */
245 double m_maxDuration; /*< max_duration (may fluctuate until the task is completed) */
246 double m_finish; /**< finish time : this is modified during the run and fluctuates until the task is completed */
248 ModelPtr getModel() {return p_model;}
253 Action(ModelPtr model, double cost, bool failed);
254 Action(ModelPtr model, double cost, bool failed, lmm_variable_t var);
258 s_xbt_swag_hookup_t p_stateHookup;
260 e_surf_action_state_t getState(); /**< get the state*/
261 virtual void setState(e_surf_action_state_t state); /**< Change state*/
262 double getBound() {return m_bound;}
263 double getStartTime(); /**< Return the start time of an action */
264 double getFinishTime(); /**< Return the finish time of an action */
265 void *getData() {return p_data;}
266 void setData(void* data);
267 double getMaxDuration() {return m_maxDuration;}
268 char *getCategory() {return p_category;}
269 double getCost() {return m_cost;}
270 void setCost(double cost) {m_cost = cost;}
272 void updateMaxDuration(double delta) {double_update(&m_maxDuration, delta);}
273 void updateRemains(double delta) {double_update(&m_remains, delta);}
274 void setRemains(double value) {m_remains = value;}
275 void setFinishTime(double value) {m_finish = value;}
279 virtual int unref(); /**< Specify that we don't use that action anymore. Returns true if the action was destroyed and false if someone still has references on it. */
280 virtual void cancel(); /**< Cancel a running action */
281 virtual void recycle(){}; /**< Recycle an action */
283 virtual void suspend(); /**< Suspend an action */
284 virtual void resume(); /**< Resume a suspended action */
285 virtual bool isSuspended(); /**< Return whether an action is suspended */
286 virtual void setMaxDuration(double duration); /**< Set the max duration of an action*/
287 virtual void setPriority(double priority); /**< Set the priority of an action */
289 void setCategory(const char *category); /**< Set the category of an action */
291 virtual double getRemains(); /**< Get the remains of an action */
292 #ifdef HAVE_LATENCY_BOUND_TRACKING
293 int getLatencyLimited(); /**< Return 1 if action is limited by latency, 0 otherwise */
297 double getPriority() {return m_priority;};
298 ActionListPtr getStateSet() {return p_stateSet;};
301 int resourceUsed(void *resource_id);
302 /* Share the resources to the actions and return in how much time
303 the next action may terminate */
304 double shareResources(double now);
305 /* Update the actions' state */
306 void updateActionsState(double now, double delta);
307 void updateResourceState(void *id, tmgr_trace_event_t event_type,
308 double value, double time);
312 lmm_variable_t p_variable;
317 enum heap_action_type m_hat;
320 virtual void updateRemainingLazy(double now);
321 void heapInsert(xbt_heap_t heap, double key, enum heap_action_type hat);
322 void heapRemove(xbt_heap_t heap);
323 void updateIndexHeap(int i);
324 lmm_variable_t getVariable() {return p_variable;}
325 double getLastUpdate() {return m_lastUpdate;}
326 void refreshLastUpdate() {m_lastUpdate = surf_get_clock();}
327 enum heap_action_type getHat() {return m_hat;}
328 bool is_linked() {return actionLmmHook::is_linked();}
332 #endif /* SURF_MODEL_H_ */