1 //using namespace generic;
10 #include <boost/smart_ptr.hpp>
11 #include <boost/function.hpp>
12 #include <boost/functional/factory.hpp>
13 #include <boost/bind.hpp>
14 #include "surf/trace_mgr.h"
16 #include "surf/surf_routing.h"
17 #include "simgrid/platf_interface.h"
19 extern tmgr_history_t history;
20 #define NO_MAX_DURATION -1.0
24 // TODO: put in surf_private.hpp
25 extern xbt_dict_t watched_hosts_lib;
27 /** \ingroup SURF_simulation
28 * \brief Return the current time
30 * Return the current time in millisecond.
40 XBT_PUBLIC(double) surf_get_clock(void);
41 XBT_PUBLIC(void) surf_watched_hosts(void);
46 extern double sg_sender_gap;
47 XBT_PUBLIC(int) SURF_CPU_LEVEL; //Surf cpu level
53 typedef Model* ModelPtr;
56 typedef Resource* ResourcePtr;
57 typedef boost::function<void (ResourcePtr r)> ResourceCallback;
60 typedef Action* ActionPtr;
61 typedef boost::function<void (ActionPtr a)> ActionCallback;
64 typedef ActionLmm* ActionLmmPtr;
66 enum heap_action_type{
82 /* For the trace and trace:connect tag (store their content till the end of the parsing) */
83 XBT_PUBLIC_DATA(xbt_dict_t) traces_set_list;
84 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_host_avail;
85 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_power;
86 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_link_avail;
87 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_bandwidth;
88 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_latency;
94 XBT_PUBLIC_DATA(xbt_dynar_t) model_list;
100 m_resOnCB = m_resOffCB= 0;
101 m_actSuspendCB = m_actCancelCB = m_actResumeCB = 0;
104 xbt_swag_free(p_readyActionSet);
105 xbt_swag_free(p_runningActionSet);
106 xbt_swag_free(p_failedActionSet);
107 xbt_swag_free(p_doneActionSet);
109 ResourcePtr createResource(string name);
110 ActionPtr createAction(double _cost, bool _failed);
111 double (Model::*shareResources)(double now);
112 double shareResourcesLazy(double now);
113 double shareResourcesFull(xbt_swag_t running_actions,
116 void (*solve) (lmm_system_t));
117 void (Model::*updateActionsState)(double now, double delta);
118 void updateActionsStateLazy(double now, double delta);
119 void updateActionsStateFull(double now, double delta);
121 string getName() {return m_name;};
122 void gapRemove(ActionLmmPtr action);
124 void addTurnedOnCallback(ResourceCallback rc);
125 void notifyResourceTurnedOn(ResourcePtr r);
127 void addTurnedOffCallback(ResourceCallback rc);
128 void notifyResourceTurnedOff(ResourcePtr r);
130 void addActionCancelCallback(ActionCallback ac);
131 void notifyActionCancel(ActionPtr a);
132 void addActionResumeCallback(ActionCallback ac);
133 void notifyActionResume(ActionPtr a);
134 void addActionSuspendCallback(ActionCallback ac);
135 void notifyActionSuspend(ActionPtr a);
137 lmm_system_t p_maxminSystem;
138 e_UM_t p_updateMechanism;
139 xbt_swag_t p_modifiedSet;
140 xbt_heap_t p_actionHeap;
141 int m_selectiveUpdate;
143 xbt_swag_t p_readyActionSet; /**< Actions in state SURF_ACTION_READY */
144 xbt_swag_t p_runningActionSet; /**< Actions in state SURF_ACTION_RUNNING */
145 xbt_swag_t p_failedActionSet; /**< Actions in state SURF_ACTION_FAILED */
146 xbt_swag_t p_doneActionSet; /**< Actions in state SURF_ACTION_DONE */
149 std::vector<ActionPtr> m_failedActions, m_runningActions;
153 ResourceCallback m_resOnCB, m_resOffCB;
154 ActionCallback m_actCancelCB, m_actSuspendCB, m_actResumeCB;
162 * Resource which have a metric handled by a maxmin system
167 tmgr_trace_event_t event;
173 Resource(ModelPtr model, const char *name, xbt_dict_t properties):
174 m_name(name),m_running(true),p_model(model),m_properties(properties) {};
175 virtual ~Resource() {};
177 void updateState(tmgr_trace_event_t event_type, double value, double date);
181 //TODOupdateActionState();
182 //TODOupdateResourceState();
188 void setName(string name);
190 ModelPtr getModel() {return p_model;};
191 e_surf_resource_state_t getState();
192 void printModel() { std::cout << p_model->getName() << "<<plop"<<std::endl;};
194 e_surf_resource_state_t m_stateCurrent;
199 xbt_dict_t m_properties;
205 class ResourceLmm: virtual public Resource {
208 lmm_constraint_t p_constraint;
209 e_surf_resource_state_t p_stateCurrent;
210 tmgr_trace_event_t p_stateEvent;
211 s_surf_metric_t p_power;
214 static inline void *surf_cpu_resource_priv(const void *host) {
215 return xbt_lib_get_level((xbt_dictelm_t)host, SURF_CPU_LEVEL);
217 /*static inline void *surf_workstation_resource_priv(const void *host){
218 return xbt_lib_get_level((xbt_dictelm_t)host, SURF_WKS_LEVEL);
220 static inline void *surf_storage_resource_priv(const void *host){
221 return xbt_lib_get_level((xbt_dictelm_t)host, SURF_STORAGE_LEVEL);
224 static inline void *surf_cpu_resource_by_name(const char *name) {
225 return xbt_lib_get_elm_or_null(host_lib, name);
227 /*static inline void *surf_workstation_resource_by_name(const char *name){
228 return xbt_lib_get_elm_or_null(host_lib, name);
230 static inline void *surf_storage_resource_by_name(const char *name){
231 return xbt_lib_get_elm_or_null(storage_lib, name);*/
237 /** \ingroup SURF_actions
238 * \brief Action states
242 * \see surf_action_t, surf_action_state_t
244 extern const char *surf_action_state_names[6];
247 SURF_ACTION_READY = 0, /**< Ready */
248 SURF_ACTION_RUNNING, /**< Running */
249 SURF_ACTION_FAILED, /**< Task Failure */
250 SURF_ACTION_DONE, /**< Completed */
251 SURF_ACTION_TO_FREE, /**< Action to free in next cleanup */
252 SURF_ACTION_NOT_IN_THE_SYSTEM
253 /**< Not in the system anymore. Why did you ask ? */
254 } e_surf_action_state_t;
259 Action(ModelPtr model, double cost, bool failed):
260 m_cost(cost), p_model(model), m_failed(failed),
261 m_refcount(1), m_priority(1.0), m_maxDuration(NO_MAX_DURATION),
262 m_start(surf_get_clock()), m_finish(-1.0)
264 m_priority = m_start = m_finish = m_maxDuration = -1.0;
265 m_start = 10;//surf_get_clock();
268 virtual ~Action() {};
270 s_xbt_swag_hookup_t p_stateHookup;
271 e_surf_action_state_t getState(); /**< get the state*/
272 void setState(e_surf_action_state_t state); /**< Change state*/
273 double getStartTime(); /**< Return the start time of an action */
274 double getFinishTime(); /**< Return the finish time of an action */
275 void setData(void* data);
277 virtual int unref()=0; /**< 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. */
278 virtual void cancel()=0; /**< Cancel a running action */
279 virtual void recycle()=0; /**< Recycle an action */
281 void suspend(); /**< Suspend an action */
282 void resume(); /**< Resume a suspended action */
283 bool isSuspended(); /**< Return whether an action is suspended */
284 void setMaxDuration(double duration); /**< Set the max duration of an action*/
285 void setPriority(double priority); /**< Set the priority of an action */
287 void setCategory(const char *category); /**< Set the category of an action */
289 double getRemains(); /**< Get the remains of an action */
290 #ifdef HAVE_LATENCY_BOUND_TRACKING
291 int getLatencyLimited(); /**< Return 1 if action is limited by latency, 0 otherwise */
294 xbt_swag_t p_stateSet;
296 double m_priority; /**< priority (1.0 by default) */
299 double m_start; /**< start time */
300 double m_finish; /**< finish time : this is modified during the run and fluctuates until the task is completed */
301 double m_remains; /**< How much of that cost remains to be done in the currently running task */
302 #ifdef HAVE_LATENCY_BOUND_TRACKING
303 int m_latencyLimited; /**< Set to 1 if is limited by latency, 0 otherwise */
305 double m_maxDuration; /*< max_duration (may fluctuate until the task is completed) */
306 char *p_category; /**< tracing category for categorized resource utilization monitoring */
311 void *p_data; /**< for your convenience */
314 e_UM_t p_updateMechanism;
317 int resourceUsed(void *resource_id);
318 /* Share the resources to the actions and return in how much time
319 the next action may terminate */
320 double shareResources(double now);
321 /* Update the actions' state */
322 void updateActionsState(double now, double delta);
323 void updateResourceState(void *id, tmgr_trace_event_t event_type,
324 double value, double time);
327 lmm_system_t p_maxminSystem;
328 xbt_swag_t p_modifiedSet;
329 xbt_heap_t p_actionHeap;
330 int m_selectiveUpdate;
333 void surf_action_lmm_update_index_heap(void *action, int i);
335 class ActionLmm: virtual public Action {
338 ActionLmm(ModelPtr model, double cost, bool failed) {};
340 virtual void updateRemainingLazy(double now)=0;
341 void heapInsert(xbt_heap_t heap, double key, enum heap_action_type hat);
342 void heapRemove(xbt_heap_t heap);
343 double getRemains(); /**< Get the remains of an action */
344 void updateIndexHeap(int i);
347 lmm_variable_t p_variable;
349 s_xbt_swag_hookup_t p_actionListHookup;
353 enum heap_action_type m_hat;
356 #endif /* SURF_MODEL_H_ */