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"
22 #include <sigc++/sigc++.h>
23 #define surf_callback(arg1, ...) sigc::signal<arg1,__VA_ARGS__>
24 #define surf_callback_connect(callback, fun_ptr) callback.connect(sigc::ptr_fun(fun_ptr))
25 #define surf_callback_emit(callback, ...) callback.emit(__VA_ARGS__)
27 #include <boost/signals2.hpp>
28 #define surf_callback(arg1, ...) boost::signals2::signal<arg1(__VA_ARGS__)>
29 #define surf_callback_connect(callback, fun_ptr) callback.connect(fun_ptr)
30 #define surf_callback_emit(callback, ...) callback(__VA_ARGS__)
33 extern tmgr_history_t history;
34 #define NO_MAX_DURATION -1.0
38 /** \ingroup SURF_simulation
39 * \brief Return the current time
41 * Return the current time in millisecond.
48 /* user-visible parameters */
49 extern double sg_tcp_gamma;
50 extern double sg_sender_gap;
51 extern double sg_latency_factor;
52 extern double sg_bandwidth_factor;
53 extern double sg_weight_S_parameter;
54 extern int sg_network_crosstraffic;
56 extern double sg_gtnets_jitter;
57 extern int sg_gtnets_jitter_seed;
59 extern xbt_dynar_t surf_path;
62 XBT_PUBLIC(double) surf_get_clock(void);
65 extern double sg_sender_gap;
66 XBT_PUBLIC(int) SURF_CPU_LEVEL; //Surf cpu level
68 int __surf_is_absolute_file_path(const char *file_path);
74 typedef Model* ModelPtr;
77 typedef Resource* ResourcePtr;
78 typedef boost::function<void (ResourcePtr r)> ResourceCallback;
81 typedef Action* ActionPtr;
82 typedef boost::function<void (ActionPtr a)> ActionCallback;
84 typedef boost::intrusive::list<Action> ActionList;
85 typedef ActionList* ActionListPtr;
86 typedef boost::intrusive::list_base_hook<> actionHook;
89 typedef boost::intrusive::list<Action, boost::intrusive::base_hook<boost::intrusive::list_base_hook<boost::intrusive::tag<lmmTag> > > > ActionLmmList;
90 typedef ActionLmmList* ActionLmmListPtr;
91 typedef boost::intrusive::list_base_hook<boost::intrusive::tag<lmmTag> > actionLmmHook;
94 enum heap_action_type{
104 /* For the trace and trace:connect tag (store their content till the end of the parsing) */
105 XBT_PUBLIC_DATA(xbt_dict_t) traces_set_list;
106 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_host_avail;
107 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_power;
108 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_link_avail;
109 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_bandwidth;
110 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_latency;
115 XBT_PUBLIC_DATA(xbt_dynar_t) model_list;
120 ActionListPtr p_readyActionSet; /**< Actions in state SURF_ACTION_READY */
121 ActionListPtr p_runningActionSet; /**< Actions in state SURF_ACTION_RUNNING */
122 ActionListPtr p_failedActionSet; /**< Actions in state SURF_ACTION_FAILED */
123 ActionListPtr p_doneActionSet; /**< Actions in state SURF_ACTION_DONE */
125 ResourceCallback m_resOnCB, m_resOffCB;
126 ActionCallback m_actCancelCB, m_actSuspendCB, m_actResumeCB;
129 ActionLmmListPtr p_modifiedSet;
131 lmm_system_t p_maxminSystem;
132 e_UM_t p_updateMechanism;
133 int m_selectiveUpdate;
134 xbt_heap_t p_actionHeap;
137 Model(const char *name);
140 const char *getName() {return p_name;}
141 virtual ActionListPtr getReadyActionSet() {return p_readyActionSet;}
142 virtual ActionListPtr getRunningActionSet() {return p_runningActionSet;}
143 virtual ActionListPtr getFailedActionSet() {return p_failedActionSet;}
144 virtual ActionListPtr getDoneActionSet() {return p_doneActionSet;}
145 virtual ActionLmmListPtr getModifiedSet() {return p_modifiedSet;}
146 lmm_system_t getMaxminSystem() {return p_maxminSystem;}
147 e_UM_t getUpdateMechanism() {return p_updateMechanism;}
148 xbt_heap_t getActionHeap() {return p_actionHeap;}
150 ActionPtr createAction(double _cost, bool _failed);
151 virtual double shareResources(double now);
152 virtual double shareResourcesLazy(double now);
153 virtual double shareResourcesFull(double now);
154 double shareResourcesMaxMin(ActionListPtr running_actions,
156 void (*solve) (lmm_system_t));
157 virtual void updateActionsState(double now, double delta);
158 virtual void updateActionsStateLazy(double now, double delta);
159 virtual void updateActionsStateFull(double now, double delta);
161 void addTurnedOnCallback(ResourceCallback rc);
162 void notifyResourceTurnedOn(ResourcePtr r);
164 void addTurnedOffCallback(ResourceCallback rc);
165 void notifyResourceTurnedOff(ResourcePtr r);
167 void addActionCancelCallback(ActionCallback ac);
168 void notifyActionCancel(ActionPtr a);
169 void addActionResumeCallback(ActionCallback ac);
170 void notifyActionResume(ActionPtr a);
171 void addActionSuspendCallback(ActionCallback ac);
172 void notifyActionSuspend(ActionPtr a);
180 * Resource which have a metric handled by a maxmin system
185 tmgr_trace_event_t event;
192 xbt_dict_t p_properties;
196 e_surf_resource_state_t m_stateCurrent;
200 Resource(ModelPtr model, const char *name, xbt_dict_t props);
201 Resource(ModelPtr model, const char *name, xbt_dict_t props, lmm_constraint_t constraint);
202 Resource(ModelPtr model, const char *name, xbt_dict_t props, e_surf_resource_state_t stateInit);
203 Resource(ModelPtr model, const char *name, xbt_dict_t props, e_surf_resource_state_t stateInit, lmm_constraint_t constraint);
205 virtual ~Resource() {
206 xbt_free((void*)p_name);
207 xbt_dict_free(&p_properties);
210 ModelPtr getModel() {return p_model;};
211 const char *getName() {return p_name;};
212 virtual xbt_dict_t getProperties() {return p_properties;};
214 virtual void updateState(tmgr_trace_event_t event_type, double value, double date)=0;
215 virtual bool isUsed()=0;
219 void setName(string name);
221 virtual e_surf_resource_state_t getState();
222 virtual void setState(e_surf_resource_state_t state);
226 lmm_constraint_t p_constraint;
228 lmm_constraint_t getConstraint() {return p_constraint;};
235 void surf_action_lmm_update_index_heap(void *action, int i);
237 class Action : public actionHook, public actionLmmHook {
238 ActionLmmListPtr p_modifiedSet;
239 xbt_heap_t p_actionHeap;
240 int m_selectiveUpdate;
242 double m_bound; /**< the capping of the CPU use */
244 double m_start; /**< start time */
245 char *p_category; /**< tracing category for categorized resource utilization monitoring */
247 #ifdef HAVE_LATENCY_BOUND_TRACKING
248 int m_latencyLimited; /**< Set to 1 if is limited by latency, 0 otherwise */
251 void *p_data; /**< for your convenience */
254 ActionListPtr p_stateSet;
255 double m_priority; /**< priority (1.0 by default) */
257 double m_remains; /**< How much of that cost remains to be done in the currently running task */
258 double m_maxDuration; /*< max_duration (may fluctuate until the task is completed) */
259 double m_finish; /**< finish time : this is modified during the run and fluctuates until the task is completed */
261 ModelPtr getModel() {return p_model;}
266 Action(ModelPtr model, double cost, bool failed);
267 Action(ModelPtr model, double cost, bool failed, lmm_variable_t var);
271 s_xbt_swag_hookup_t p_stateHookup;
273 e_surf_action_state_t getState(); /**< get the state*/
274 virtual void setState(e_surf_action_state_t state); /**< Change state*/
275 double getBound() {return m_bound;}
276 double getStartTime(); /**< Return the start time of an action */
277 double getFinishTime(); /**< Return the finish time of an action */
278 void *getData() {return p_data;}
279 void setData(void* data);
280 double getMaxDuration() {return m_maxDuration;}
281 char *getCategory() {return p_category;}
282 double getCost() {return m_cost;}
283 void setCost(double cost) {m_cost = cost;}
285 void updateMaxDuration(double delta) {double_update(&m_maxDuration, delta);}
286 void updateRemains(double delta) {double_update(&m_remains, delta);}
287 void setRemains(double value) {m_remains = value;}
288 void setFinishTime(double value) {m_finish = value;}
292 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. */
293 virtual void cancel(); /**< Cancel a running action */
294 virtual void recycle(){}; /**< Recycle an action */
296 virtual void suspend(); /**< Suspend an action */
297 virtual void resume(); /**< Resume a suspended action */
298 virtual bool isSuspended(); /**< Return whether an action is suspended */
299 virtual void setMaxDuration(double duration); /**< Set the max duration of an action*/
300 virtual void setPriority(double priority); /**< Set the priority of an action */
302 void setCategory(const char *category); /**< Set the category of an action */
304 virtual double getRemains(); /**< Get the remains of an action */
305 double getRemainsNoUpdate();
307 #ifdef HAVE_LATENCY_BOUND_TRACKING
308 int getLatencyLimited(); /**< Return 1 if action is limited by latency, 0 otherwise */
311 double getPriority() {return m_priority;};
312 ActionListPtr getStateSet() {return p_stateSet;};
315 int resourceUsed(void *resource_id);
316 /* Share the resources to the actions and return in how much time
317 the next action may terminate */
318 double shareResources(double now);
319 /* Update the actions' state */
320 void updateActionsState(double now, double delta);
321 void updateResourceState(void *id, tmgr_trace_event_t event_type,
322 double value, double time);
326 lmm_variable_t p_variable;
331 enum heap_action_type m_hat;
334 virtual void updateRemainingLazy(double now);
335 void heapInsert(xbt_heap_t heap, double key, enum heap_action_type hat);
336 void heapRemove(xbt_heap_t heap);
337 void updateIndexHeap(int i);
338 lmm_variable_t getVariable() {return p_variable;}
339 double getLastUpdate() {return m_lastUpdate;}
340 void refreshLastUpdate() {m_lastUpdate = surf_get_clock();}
341 enum heap_action_type getHat() {return m_hat;}
342 bool is_linked() {return actionLmmHook::is_linked();}
346 #endif /* SURF_MODEL_H_ */