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"
18 #include "surf/surf.h"
19 #include "surf/surf_private.h"
21 extern tmgr_history_t history;
22 #define NO_MAX_DURATION -1.0
26 /** \ingroup SURF_simulation
27 * \brief Return the current time
29 * Return the current time in millisecond.
36 /* user-visible parameters */
37 extern double sg_tcp_gamma;
38 extern double sg_sender_gap;
39 extern double sg_latency_factor;
40 extern double sg_bandwidth_factor;
41 extern double sg_weight_S_parameter;
42 extern int sg_network_crosstraffic;
44 extern double sg_gtnets_jitter;
45 extern int sg_gtnets_jitter_seed;
47 extern xbt_dynar_t surf_path;
52 XBT_PUBLIC(double) surf_get_clock(void);
53 XBT_PUBLIC(void) surf_watched_hosts(void);
58 extern double sg_sender_gap;
59 XBT_PUBLIC(int) SURF_CPU_LEVEL; //Surf cpu level
61 int __surf_is_absolute_file_path(const char *file_path);
67 typedef Model* ModelPtr;
70 typedef Resource* ResourcePtr;
71 typedef boost::function<void (ResourcePtr r)> ResourceCallback;
74 typedef Action* ActionPtr;
75 typedef boost::function<void (ActionPtr a)> ActionCallback;
78 typedef ActionLmm* ActionLmmPtr;
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;
109 ResourcePtr createResource(string name);
110 ActionPtr createAction(double _cost, bool _failed);
111 virtual double shareResources(double now);
112 virtual double shareResourcesLazy(double now);
113 virtual double shareResourcesFull(double now);
114 double shareResourcesMaxMin(xbt_swag_t running_actions,
116 void (*solve) (lmm_system_t));
117 virtual void updateActionsState(double now, double delta);
118 virtual void updateActionsStateLazy(double now, double delta);
119 virtual void updateActionsStateFull(double now, double delta);
121 string getName() {return m_name;};
123 void addTurnedOnCallback(ResourceCallback rc);
124 void notifyResourceTurnedOn(ResourcePtr r);
126 void addTurnedOffCallback(ResourceCallback rc);
127 void notifyResourceTurnedOff(ResourcePtr r);
129 void addActionCancelCallback(ActionCallback ac);
130 void notifyActionCancel(ActionPtr a);
131 void addActionResumeCallback(ActionCallback ac);
132 void notifyActionResume(ActionPtr a);
133 void addActionSuspendCallback(ActionCallback ac);
134 void notifyActionSuspend(ActionPtr a);
136 lmm_system_t p_maxminSystem;
137 e_UM_t p_updateMechanism;
138 xbt_swag_t p_modifiedSet;
139 xbt_heap_t p_actionHeap;
140 int m_selectiveUpdate;
142 xbt_swag_t p_readyActionSet; /**< Actions in state SURF_ACTION_READY */
143 xbt_swag_t p_runningActionSet; /**< Actions in state SURF_ACTION_RUNNING */
144 xbt_swag_t p_failedActionSet; /**< Actions in state SURF_ACTION_FAILED */
145 xbt_swag_t p_doneActionSet; /**< Actions in state SURF_ACTION_DONE */
149 std::vector<ActionPtr> m_failedActions, m_runningActions;
152 ResourceCallback m_resOnCB, m_resOffCB;
153 ActionCallback m_actCancelCB, m_actSuspendCB, m_actResumeCB;
161 * Resource which have a metric handled by a maxmin system
166 tmgr_trace_event_t event;
172 Resource(ModelPtr model, const char *name, xbt_dict_t properties);
173 virtual ~Resource() {};
175 virtual void updateState(tmgr_trace_event_t event_type, double value, double date)=0;
178 virtual bool isUsed()=0;
179 //FIXME:updateActionState();
180 //FIXME:updateResourceState();
186 void setName(string name);
187 const char *getName();
188 virtual xbt_dict_t getProperties();
190 ModelPtr getModel() {return p_model;};
191 virtual e_surf_resource_state_t getState();
192 void printModel() { std::cout << p_model->getName() << "<<plop"<<std::endl;};
195 xbt_dict_t m_properties;
197 e_surf_resource_state_t p_stateCurrent;
205 class ResourceLmm: virtual public Resource {
208 ResourceLmm(surf_model_t model, const char *name, xbt_dict_t props,
210 double constraint_value,
211 tmgr_history_t history,
212 e_surf_resource_state_t state_init,
213 tmgr_trace_t state_trace,
215 tmgr_trace_t metric_trace);
216 lmm_constraint_t p_constraint;
217 tmgr_trace_event_t p_stateEvent;
218 s_surf_metric_t p_power;
228 Action(ModelPtr model, double cost, bool failed);
231 s_xbt_swag_hookup_t p_stateHookup;
233 e_surf_action_state_t getState(); /**< get the state*/
234 virtual void setState(e_surf_action_state_t state); /**< Change state*/
235 double getStartTime(); /**< Return the start time of an action */
236 double getFinishTime(); /**< Return the finish time of an action */
237 void setData(void* data);
240 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. */
241 virtual void cancel(); /**< Cancel a running action */
242 virtual void recycle(); /**< Recycle an action */
244 virtual void suspend()=0; /**< Suspend an action */
245 virtual void resume()=0; /**< Resume a suspended action */
246 virtual bool isSuspended()=0; /**< Return whether an action is suspended */
247 virtual void setMaxDuration(double duration)=0; /**< Set the max duration of an action*/
248 virtual void setPriority(double priority)=0; /**< Set the priority of an action */
250 void setCategory(const char *category); /**< Set the category of an action */
252 virtual double getRemains(); /**< Get the remains of an action */
253 #ifdef HAVE_LATENCY_BOUND_TRACKING
254 int getLatencyLimited(); /**< Return 1 if action is limited by latency, 0 otherwise */
257 xbt_swag_t p_stateSet;
259 double m_priority; /**< priority (1.0 by default) */
261 double m_start; /**< start time */
262 double m_finish; /**< finish time : this is modified during the run and fluctuates until the task is completed */
263 double m_remains; /**< How much of that cost remains to be done in the currently running task */
264 #ifdef HAVE_LATENCY_BOUND_TRACKING
265 int m_latencyLimited; /**< Set to 1 if is limited by latency, 0 otherwise */
267 double m_maxDuration; /*< max_duration (may fluctuate until the task is completed) */
268 char *p_category; /**< tracing category for categorized resource utilization monitoring */
270 void *p_data; /**< for your convenience */
276 e_UM_t p_updateMechanism;
279 int resourceUsed(void *resource_id);
280 /* Share the resources to the actions and return in how much time
281 the next action may terminate */
282 double shareResources(double now);
283 /* Update the actions' state */
284 void updateActionsState(double now, double delta);
285 void updateResourceState(void *id, tmgr_trace_event_t event_type,
286 double value, double time);
288 xbt_swag_t p_modifiedSet;
289 xbt_heap_t p_actionHeap;
290 int m_selectiveUpdate;
294 void surf_action_lmm_update_index_heap(void *action, int i);
296 class ActionLmm: virtual public Action {
298 ActionLmm() : m_suspended(false) {
299 p_actionListHookup.prev = 0;
300 p_actionListHookup.next = 0;
302 ActionLmm(ModelPtr model, double cost, bool failed) : m_suspended(false) {
303 p_actionListHookup.prev = 0;
304 p_actionListHookup.next = 0;
307 virtual void updateRemainingLazy(double now);
308 void heapInsert(xbt_heap_t heap, double key, enum heap_action_type hat);
309 void heapRemove(xbt_heap_t heap);
310 double getRemains(); /**< Get the remains of an action */
311 void updateIndexHeap(int i);
318 void setMaxDuration(double duration);
319 void setPriority(double priority);
322 lmm_variable_t p_variable;
323 s_xbt_swag_hookup_t p_actionListHookup;
327 enum heap_action_type m_hat;
331 #endif /* SURF_MODEL_H_ */