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"
19 #include "internal_config.h"
23 #include <sigc++/sigc++.h>
24 #define surf_callback(arg1, ...) sigc::signal<arg1,__VA_ARGS__>
25 #define surf_callback_connect(callback, fun_ptr) callback.connect(sigc::ptr_fun(fun_ptr))
26 #define surf_callback_emit(callback, ...) callback.emit(__VA_ARGS__)
28 #include <boost/signals2.hpp>
29 #define surf_callback(arg1, ...) boost::signals2::signal<arg1(__VA_ARGS__)>
30 #define surf_callback_connect(callback, fun_ptr) callback.connect(fun_ptr)
31 #define surf_callback_emit(callback, ...) callback(__VA_ARGS__)
34 extern tmgr_history_t history;
35 #define NO_MAX_DURATION -1.0
39 /** \ingroup SURF_simulation
40 * \brief Return the current time
42 * Return the current time in millisecond.
49 /* user-visible parameters */
50 extern double sg_tcp_gamma;
51 extern double sg_sender_gap;
52 extern double sg_latency_factor;
53 extern double sg_bandwidth_factor;
54 extern double sg_weight_S_parameter;
55 extern int sg_network_crosstraffic;
57 extern double sg_gtnets_jitter;
58 extern int sg_gtnets_jitter_seed;
60 extern xbt_dynar_t surf_path;
63 XBT_PUBLIC(double) surf_get_clock(void);
66 extern double sg_sender_gap;
67 XBT_PUBLIC(int) SURF_CPU_LEVEL; //Surf cpu level
69 int __surf_is_absolute_file_path(const char *file_path);
75 typedef Model* ModelPtr;
78 typedef Resource* ResourcePtr;
79 typedef boost::function<void (ResourcePtr r)> ResourceCallback;
82 typedef Action* ActionPtr;
83 typedef boost::function<void (ActionPtr a)> ActionCallback;
85 typedef boost::intrusive::list<Action> ActionList;
86 typedef ActionList* ActionListPtr;
87 typedef boost::intrusive::list_base_hook<> actionHook;
90 typedef boost::intrusive::list<Action, boost::intrusive::base_hook<boost::intrusive::list_base_hook<boost::intrusive::tag<lmmTag> > > > ActionLmmList;
91 typedef ActionLmmList* ActionLmmListPtr;
92 typedef boost::intrusive::list_base_hook<boost::intrusive::tag<lmmTag> > actionLmmHook;
95 enum heap_action_type{
105 /* For the trace and trace:connect tag (store their content till the end of the parsing) */
106 XBT_PUBLIC_DATA(xbt_dict_t) traces_set_list;
107 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_host_avail;
108 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_power;
109 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_link_avail;
110 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_bandwidth;
111 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_latency;
116 XBT_PUBLIC_DATA(xbt_dynar_t) model_list;
121 ActionListPtr p_readyActionSet; /**< Actions in state SURF_ACTION_READY */
122 ActionListPtr p_runningActionSet; /**< Actions in state SURF_ACTION_RUNNING */
123 ActionListPtr p_failedActionSet; /**< Actions in state SURF_ACTION_FAILED */
124 ActionListPtr p_doneActionSet; /**< Actions in state SURF_ACTION_DONE */
126 ResourceCallback m_resOnCB, m_resOffCB;
127 ActionCallback m_actCancelCB, m_actSuspendCB, m_actResumeCB;
130 ActionLmmListPtr p_modifiedSet;
132 lmm_system_t p_maxminSystem;
133 e_UM_t p_updateMechanism;
134 int m_selectiveUpdate;
135 xbt_heap_t p_actionHeap;
138 Model(const char *name);
141 const char *getName() {return p_name;}
142 virtual ActionListPtr getReadyActionSet() {return p_readyActionSet;}
143 virtual ActionListPtr getRunningActionSet() {return p_runningActionSet;}
144 virtual ActionListPtr getFailedActionSet() {return p_failedActionSet;}
145 virtual ActionListPtr getDoneActionSet() {return p_doneActionSet;}
146 virtual ActionLmmListPtr getModifiedSet() {return p_modifiedSet;}
147 lmm_system_t getMaxminSystem() {return p_maxminSystem;}
148 e_UM_t getUpdateMechanism() {return p_updateMechanism;}
149 xbt_heap_t getActionHeap() {return p_actionHeap;}
151 ActionPtr createAction(double _cost, bool _failed);
152 virtual double shareResources(double now);
153 virtual double shareResourcesLazy(double now);
154 virtual double shareResourcesFull(double now);
155 double shareResourcesMaxMin(ActionListPtr running_actions,
157 void (*solve) (lmm_system_t));
158 virtual void updateActionsState(double now, double delta);
159 virtual void updateActionsStateLazy(double now, double delta);
160 virtual void updateActionsStateFull(double now, double delta);
162 void addTurnedOnCallback(ResourceCallback rc);
163 void notifyResourceTurnedOn(ResourcePtr r);
165 void addTurnedOffCallback(ResourceCallback rc);
166 void notifyResourceTurnedOff(ResourcePtr r);
168 void addActionCancelCallback(ActionCallback ac);
169 void notifyActionCancel(ActionPtr a);
170 void addActionResumeCallback(ActionCallback ac);
171 void notifyActionResume(ActionPtr a);
172 void addActionSuspendCallback(ActionCallback ac);
173 void notifyActionSuspend(ActionPtr a);
181 * Resource which have a metric handled by a maxmin system
186 tmgr_trace_event_t event;
193 xbt_dict_t p_properties;
197 e_surf_resource_state_t m_stateCurrent;
201 Resource(ModelPtr model, const char *name, xbt_dict_t props);
202 Resource(ModelPtr model, const char *name, xbt_dict_t props, lmm_constraint_t constraint);
203 Resource(ModelPtr model, const char *name, xbt_dict_t props, e_surf_resource_state_t stateInit);
204 Resource(ModelPtr model, const char *name, xbt_dict_t props, e_surf_resource_state_t stateInit, lmm_constraint_t constraint);
206 virtual ~Resource() {
207 xbt_free((void*)p_name);
208 xbt_dict_free(&p_properties);
211 ModelPtr getModel() {return p_model;};
212 const char *getName() {return p_name;};
213 virtual xbt_dict_t getProperties() {return p_properties;};
215 virtual void updateState(tmgr_trace_event_t event_type, double value, double date)=0;
216 virtual bool isUsed()=0;
220 void setName(string name);
222 virtual e_surf_resource_state_t getState();
223 virtual void setState(e_surf_resource_state_t state);
227 lmm_constraint_t p_constraint;
229 lmm_constraint_t getConstraint() {return p_constraint;};
236 void surf_action_lmm_update_index_heap(void *action, int i);
238 class Action : public actionHook, public actionLmmHook {
239 ActionLmmListPtr p_modifiedSet;
240 xbt_heap_t p_actionHeap;
241 int m_selectiveUpdate;
243 double m_bound; /**< the capping of the CPU use */
245 double m_start; /**< start time */
246 char *p_category; /**< tracing category for categorized resource utilization monitoring */
248 #ifdef HAVE_LATENCY_BOUND_TRACKING
249 int m_latencyLimited; /**< Set to 1 if is limited by latency, 0 otherwise */
252 void *p_data; /**< for your convenience */
255 ActionListPtr p_stateSet;
256 double m_priority; /**< priority (1.0 by default) */
258 double m_remains; /**< How much of that cost remains to be done in the currently running task */
259 double m_maxDuration; /*< max_duration (may fluctuate until the task is completed) */
260 double m_finish; /**< finish time : this is modified during the run and fluctuates until the task is completed */
262 ModelPtr getModel() {return p_model;}
267 Action(ModelPtr model, double cost, bool failed);
268 Action(ModelPtr model, double cost, bool failed, lmm_variable_t var);
272 s_xbt_swag_hookup_t p_stateHookup;
274 e_surf_action_state_t getState(); /**< get the state*/
275 virtual void setState(e_surf_action_state_t state); /**< Change state*/
276 double getBound() {return m_bound;}
277 double getStartTime(); /**< Return the start time of an action */
278 double getFinishTime(); /**< Return the finish time of an action */
279 void *getData() {return p_data;}
280 void setData(void* data);
281 double getMaxDuration() {return m_maxDuration;}
282 char *getCategory() {return p_category;}
283 double getCost() {return m_cost;}
284 void setCost(double cost) {m_cost = cost;}
286 void updateMaxDuration(double delta) {double_update(&m_maxDuration, delta);}
287 void updateRemains(double delta) {double_update(&m_remains, delta);}
288 void setRemains(double value) {m_remains = value;}
289 void setFinishTime(double value) {m_finish = value;}
293 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. */
294 virtual void cancel(); /**< Cancel a running action */
295 virtual void recycle(){}; /**< Recycle an action */
297 virtual void suspend(); /**< Suspend an action */
298 virtual void resume(); /**< Resume a suspended action */
299 virtual bool isSuspended(); /**< Return whether an action is suspended */
300 virtual void setMaxDuration(double duration); /**< Set the max duration of an action*/
301 virtual void setPriority(double priority); /**< Set the priority of an action */
303 void setCategory(const char *category); /**< Set the category of an action */
305 virtual double getRemains(); /**< Get the remains of an action */
306 double getRemainsNoUpdate();
308 #ifdef HAVE_LATENCY_BOUND_TRACKING
309 int getLatencyLimited(); /**< Return 1 if action is limited by latency, 0 otherwise */
312 double getPriority() {return m_priority;};
313 ActionListPtr getStateSet() {return p_stateSet;};
316 int resourceUsed(void *resource_id);
317 /* Share the resources to the actions and return in how much time
318 the next action may terminate */
319 double shareResources(double now);
320 /* Update the actions' state */
321 void updateActionsState(double now, double delta);
322 void updateResourceState(void *id, tmgr_trace_event_t event_type,
323 double value, double time);
327 lmm_variable_t p_variable;
332 enum heap_action_type m_hat;
335 virtual void updateRemainingLazy(double now);
336 void heapInsert(xbt_heap_t heap, double key, enum heap_action_type hat);
337 void heapRemove(xbt_heap_t heap);
338 void updateIndexHeap(int i);
339 lmm_variable_t getVariable() {return p_variable;}
340 double getLastUpdate() {return m_lastUpdate;}
341 void refreshLastUpdate() {m_lastUpdate = surf_get_clock();}
342 enum heap_action_type getHat() {return m_hat;}
343 bool is_linked() {return actionLmmHook::is_linked();}
347 #endif /* SURF_MODEL_H_ */