1 //using namespace generic;
11 #include <boost/function.hpp>
12 #include "surf/trace_mgr.h"
14 #include "surf/surf_routing.h"
15 #include "simgrid/platf_interface.h"
16 #include "surf/surf.h"
17 #include "surf/surf_private.h"
19 extern tmgr_history_t history;
20 #define NO_MAX_DURATION -1.0
24 /** \ingroup SURF_simulation
25 * \brief Return the current time
27 * Return the current time in millisecond.
34 /* user-visible parameters */
35 extern double sg_tcp_gamma;
36 extern double sg_sender_gap;
37 extern double sg_latency_factor;
38 extern double sg_bandwidth_factor;
39 extern double sg_weight_S_parameter;
40 extern int sg_network_crosstraffic;
42 extern double sg_gtnets_jitter;
43 extern int sg_gtnets_jitter_seed;
45 extern xbt_dynar_t surf_path;
48 XBT_PUBLIC(double) surf_get_clock(void);
51 extern double sg_sender_gap;
52 XBT_PUBLIC(int) SURF_CPU_LEVEL; //Surf cpu level
54 int __surf_is_absolute_file_path(const char *file_path);
60 typedef Model* ModelPtr;
63 typedef Resource* ResourcePtr;
64 typedef boost::function<void (ResourcePtr r)> ResourceCallback;
67 typedef Action* ActionPtr;
68 typedef boost::function<void (ActionPtr a)> ActionCallback;
71 typedef ActionLmm* ActionLmmPtr;
73 enum heap_action_type{
83 /* For the trace and trace:connect tag (store their content till the end of the parsing) */
84 XBT_PUBLIC_DATA(xbt_dict_t) traces_set_list;
85 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_host_avail;
86 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_power;
87 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_link_avail;
88 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_bandwidth;
89 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_latency;
95 XBT_PUBLIC_DATA(xbt_dynar_t) model_list;
100 xbt_swag_t p_readyActionSet; /**< Actions in state SURF_ACTION_READY */
101 xbt_swag_t p_runningActionSet; /**< Actions in state SURF_ACTION_RUNNING */
102 xbt_swag_t p_failedActionSet; /**< Actions in state SURF_ACTION_FAILED */
103 xbt_swag_t p_doneActionSet; /**< Actions in state SURF_ACTION_DONE */
105 ResourceCallback m_resOnCB, m_resOffCB;
106 ActionCallback m_actCancelCB, m_actSuspendCB, m_actResumeCB;
109 xbt_swag_t p_modifiedSet;
111 lmm_system_t p_maxminSystem;
112 e_UM_t p_updateMechanism;
113 int m_selectiveUpdate;
114 xbt_heap_t p_actionHeap;
117 Model(const char *name);
120 const char *getName() {return p_name;}
121 xbt_swag_t getReadyActionSet() {return p_readyActionSet;}
122 xbt_swag_t getRunningActionSet() {return p_runningActionSet;}
123 xbt_swag_t getFailedActionSet() {return p_failedActionSet;}
124 xbt_swag_t getDoneActionSet() {return p_doneActionSet;}
125 xbt_swag_t getModifiedSet() {return p_modifiedSet;}
126 lmm_system_t getMaxminSystem() {return p_maxminSystem;}
127 e_UM_t getUpdateMechanism() {return p_updateMechanism;}
128 xbt_heap_t getActionHeap() {return p_actionHeap;}
130 ActionPtr createAction(double _cost, bool _failed);
131 virtual double shareResources(double now);
132 virtual double shareResourcesLazy(double now);
133 virtual double shareResourcesFull(double now);
134 double shareResourcesMaxMin(xbt_swag_t running_actions,
136 void (*solve) (lmm_system_t));
137 virtual void updateActionsState(double now, double delta);
138 virtual void updateActionsStateLazy(double now, double delta);
139 virtual void updateActionsStateFull(double now, double delta);
141 void addTurnedOnCallback(ResourceCallback rc);
142 void notifyResourceTurnedOn(ResourcePtr r);
144 void addTurnedOffCallback(ResourceCallback rc);
145 void notifyResourceTurnedOff(ResourcePtr r);
147 void addActionCancelCallback(ActionCallback ac);
148 void notifyActionCancel(ActionPtr a);
149 void addActionResumeCallback(ActionCallback ac);
150 void notifyActionResume(ActionPtr a);
151 void addActionSuspendCallback(ActionCallback ac);
152 void notifyActionSuspend(ActionPtr a);
160 * Resource which have a metric handled by a maxmin system
165 tmgr_trace_event_t event;
172 xbt_dict_t p_properties;
176 e_surf_resource_state_t m_stateCurrent;
180 Resource(ModelPtr model, const char *name, xbt_dict_t properties);
181 Resource(surf_model_t model, const char *name, xbt_dict_t props, e_surf_resource_state_t stateInit);
182 virtual ~Resource() {
183 xbt_free((void*)p_name);
184 xbt_dict_free(&p_properties);
187 ModelPtr getModel() {return p_model;};
188 const char *getName() {return p_name;};
189 virtual xbt_dict_t getProperties() {return p_properties;};
191 virtual void updateState(tmgr_trace_event_t event_type, double value, double date)=0;
192 virtual bool isUsed()=0;
196 void setName(string name);
198 virtual e_surf_resource_state_t getState();
199 virtual void setState(e_surf_resource_state_t state);
202 class ResourceLmm: virtual public Resource {
203 lmm_constraint_t p_constraint;
207 ResourceLmm(lmm_constraint_t constraint);
211 lmm_constraint_t constraint() {return p_constraint;};
219 xbt_swag_t p_modifiedSet;
220 xbt_heap_t p_actionHeap;
221 int m_selectiveUpdate;
223 double m_bound; /**< the capping of the CPU use */
225 double m_start; /**< start time */
226 char *p_category; /**< tracing category for categorized resource utilization monitoring */
228 #ifdef HAVE_LATENCY_BOUND_TRACKING
229 int m_latencyLimited; /**< Set to 1 if is limited by latency, 0 otherwise */
232 void *p_data; /**< for your convenience */
235 xbt_swag_t p_stateSet;
236 double m_priority; /**< priority (1.0 by default) */
238 double m_remains; /**< How much of that cost remains to be done in the currently running task */
239 double m_maxDuration; /*< max_duration (may fluctuate until the task is completed) */
240 double m_finish; /**< finish time : this is modified during the run and fluctuates until the task is completed */
242 ModelPtr getModel() {return p_model;}
247 Action(ModelPtr model, double cost, bool failed);
251 s_xbt_swag_hookup_t p_stateHookup;
253 e_surf_action_state_t getState(); /**< get the state*/
254 virtual void setState(e_surf_action_state_t state); /**< Change state*/
255 double getBound() {return m_bound;}
256 double getStartTime(); /**< Return the start time of an action */
257 double getFinishTime(); /**< Return the finish time of an action */
258 void *getData() {return p_data;}
259 void setData(void* data);
260 double getMaxDuration() {return m_maxDuration;}
261 char *getCategory() {return p_category;}
262 double getCost() {return m_cost;}
263 void setCost(double cost) {m_cost = cost;}
265 void updateMaxDuration(double delta) {double_update(&m_maxDuration, delta);}
266 void updateRemains(double delta) {double_update(&m_remains, delta);}
267 void setRemains(double value) {m_remains = value;}
268 void setFinishTime(double value) {m_finish = value;}
272 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. */
273 virtual void cancel(); /**< Cancel a running action */
274 virtual void recycle(); /**< Recycle an action */
276 virtual void suspend()=0; /**< Suspend an action */
277 virtual void resume()=0; /**< Resume a suspended action */
278 virtual bool isSuspended()=0; /**< Return whether an action is suspended */
279 virtual void setMaxDuration(double duration)=0; /**< Set the max duration of an action*/
280 virtual void setPriority(double priority)=0; /**< Set the priority of an action */
282 void setCategory(const char *category); /**< Set the category of an action */
284 virtual double getRemains(); /**< Get the remains of an action */
285 #ifdef HAVE_LATENCY_BOUND_TRACKING
286 int getLatencyLimited(); /**< Return 1 if action is limited by latency, 0 otherwise */
290 double getPriority() {return m_priority;};
291 xbt_swag_t getStateSet() {return p_stateSet;};
294 int resourceUsed(void *resource_id);
295 /* Share the resources to the actions and return in how much time
296 the next action may terminate */
297 double shareResources(double now);
298 /* Update the actions' state */
299 void updateActionsState(double now, double delta);
300 void updateResourceState(void *id, tmgr_trace_event_t event_type,
301 double value, double time);
307 void surf_action_lmm_update_index_heap(void *action, int i);
309 class ActionLmm: virtual public Action {
312 lmm_variable_t p_variable;
317 enum heap_action_type m_hat;
320 ActionLmm() : m_suspended(false) {
321 p_actionListHookup.prev = 0;
322 p_actionListHookup.next = 0;
326 ActionLmm(lmm_variable_t var) : m_suspended(false) {
327 p_actionListHookup.prev = 0;
328 p_actionListHookup.next = 0;
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 double getRemains(); /**< Get the remains of an action */
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;}
349 void setMaxDuration(double duration);
350 void setPriority(double priority);
352 s_xbt_swag_hookup_t p_actionListHookup;
356 #endif /* SURF_MODEL_H_ */