1 //using namespace generic;
10 #include <boost/function.hpp>
11 #include "surf/trace_mgr.h"
13 #include "surf/surf_routing.h"
14 #include "simgrid/platf_interface.h"
15 #include "surf/surf.h"
16 #include "surf/surf_private.h"
18 extern tmgr_history_t history;
19 #define NO_MAX_DURATION -1.0
23 /** \ingroup SURF_simulation
24 * \brief Return the current time
26 * Return the current time in millisecond.
33 /* user-visible parameters */
34 extern double sg_tcp_gamma;
35 extern double sg_sender_gap;
36 extern double sg_latency_factor;
37 extern double sg_bandwidth_factor;
38 extern double sg_weight_S_parameter;
39 extern int sg_network_crosstraffic;
41 extern double sg_gtnets_jitter;
42 extern int sg_gtnets_jitter_seed;
44 extern xbt_dynar_t surf_path;
49 XBT_PUBLIC(double) surf_get_clock(void);
54 extern double sg_sender_gap;
55 XBT_PUBLIC(int) SURF_CPU_LEVEL; //Surf cpu level
57 int __surf_is_absolute_file_path(const char *file_path);
63 typedef Model* ModelPtr;
66 typedef Resource* ResourcePtr;
67 typedef boost::function<void (ResourcePtr r)> ResourceCallback;
70 typedef Action* ActionPtr;
71 typedef boost::function<void (ActionPtr a)> ActionCallback;
74 typedef ActionLmm* ActionLmmPtr;
76 enum heap_action_type{
86 /* For the trace and trace:connect tag (store their content till the end of the parsing) */
87 XBT_PUBLIC_DATA(xbt_dict_t) traces_set_list;
88 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_host_avail;
89 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_power;
90 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_link_avail;
91 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_bandwidth;
92 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_latency;
98 XBT_PUBLIC_DATA(xbt_dynar_t) model_list;
105 ResourcePtr createResource(string name);
106 ActionPtr createAction(double _cost, bool _failed);
107 virtual double shareResources(double now);
108 virtual double shareResourcesLazy(double now);
109 virtual double shareResourcesFull(double now);
110 double shareResourcesMaxMin(xbt_swag_t running_actions,
112 void (*solve) (lmm_system_t));
113 virtual void updateActionsState(double now, double delta);
114 virtual void updateActionsStateLazy(double now, double delta);
115 virtual void updateActionsStateFull(double now, double delta);
117 string getName() {return m_name;};
119 void addTurnedOnCallback(ResourceCallback rc);
120 void notifyResourceTurnedOn(ResourcePtr r);
122 void addTurnedOffCallback(ResourceCallback rc);
123 void notifyResourceTurnedOff(ResourcePtr r);
125 void addActionCancelCallback(ActionCallback ac);
126 void notifyActionCancel(ActionPtr a);
127 void addActionResumeCallback(ActionCallback ac);
128 void notifyActionResume(ActionPtr a);
129 void addActionSuspendCallback(ActionCallback ac);
130 void notifyActionSuspend(ActionPtr a);
132 lmm_system_t p_maxminSystem;
133 e_UM_t p_updateMechanism;
134 xbt_swag_t p_modifiedSet;
135 xbt_heap_t p_actionHeap;
136 int m_selectiveUpdate;
138 xbt_swag_t p_readyActionSet; /**< Actions in state SURF_ACTION_READY */
139 xbt_swag_t p_runningActionSet; /**< Actions in state SURF_ACTION_RUNNING */
140 xbt_swag_t p_failedActionSet; /**< Actions in state SURF_ACTION_FAILED */
141 xbt_swag_t p_doneActionSet; /**< Actions in state SURF_ACTION_DONE */
145 std::vector<ActionPtr> m_failedActions, m_runningActions;
148 ResourceCallback m_resOnCB, m_resOffCB;
149 ActionCallback m_actCancelCB, m_actSuspendCB, m_actResumeCB;
157 * Resource which have a metric handled by a maxmin system
162 tmgr_trace_event_t event;
168 Resource(ModelPtr model, const char *name, xbt_dict_t properties);
169 virtual ~Resource() {};
171 virtual void updateState(tmgr_trace_event_t event_type, double value, double date)=0;
174 virtual bool isUsed()=0;
175 //FIXME:updateActionState();
176 //FIXME:updateResourceState();
182 void setName(string name);
183 const char *getName();
184 virtual xbt_dict_t getProperties();
186 ModelPtr getModel() {return p_model;};
187 virtual e_surf_resource_state_t getState();
188 virtual void setState(e_surf_resource_state_t state);
189 void printModel() { std::cout << p_model->getName() << "<<plop"<<std::endl;};
192 xbt_dict_t m_properties;
194 e_surf_resource_state_t p_stateCurrent;
202 class ResourceLmm: virtual public Resource {
205 ResourceLmm(surf_model_t model, const char *name, xbt_dict_t props,
207 double constraint_value,
208 tmgr_history_t history,
209 e_surf_resource_state_t state_init,
210 tmgr_trace_t state_trace,
212 tmgr_trace_t metric_trace);
213 lmm_constraint_t p_constraint;
214 tmgr_trace_event_t p_stateEvent;
215 s_surf_metric_t p_power;
225 Action(ModelPtr model, double cost, bool failed);
228 s_xbt_swag_hookup_t p_stateHookup;
230 e_surf_action_state_t getState(); /**< get the state*/
231 virtual void setState(e_surf_action_state_t state); /**< Change state*/
232 double getStartTime(); /**< Return the start time of an action */
233 double getFinishTime(); /**< Return the finish time of an action */
234 void setData(void* data);
237 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. */
238 virtual void cancel(); /**< Cancel a running action */
239 virtual void recycle(); /**< Recycle an action */
241 virtual void suspend()=0; /**< Suspend an action */
242 virtual void resume()=0; /**< Resume a suspended action */
243 virtual bool isSuspended()=0; /**< Return whether an action is suspended */
244 virtual void setMaxDuration(double duration)=0; /**< Set the max duration of an action*/
245 virtual void setPriority(double priority)=0; /**< Set the priority of an action */
247 void setCategory(const char *category); /**< Set the category of an action */
249 virtual double getRemains(); /**< Get the remains of an action */
250 #ifdef HAVE_LATENCY_BOUND_TRACKING
251 int getLatencyLimited(); /**< Return 1 if action is limited by latency, 0 otherwise */
254 xbt_swag_t p_stateSet;
256 double m_priority; /**< priority (1.0 by default) */
257 double m_bound; /**< the capping of the CPU use */
259 double m_start; /**< start time */
260 double m_finish; /**< finish time : this is modified during the run and fluctuates until the task is completed */
261 double m_remains; /**< How much of that cost remains to be done in the currently running task */
262 #ifdef HAVE_LATENCY_BOUND_TRACKING
263 int m_latencyLimited; /**< Set to 1 if is limited by latency, 0 otherwise */
265 double m_maxDuration; /*< max_duration (may fluctuate until the task is completed) */
266 char *p_category; /**< tracing category for categorized resource utilization monitoring */
268 void *p_data; /**< for your convenience */
274 e_UM_t p_updateMechanism;
277 int resourceUsed(void *resource_id);
278 /* Share the resources to the actions and return in how much time
279 the next action may terminate */
280 double shareResources(double now);
281 /* Update the actions' state */
282 void updateActionsState(double now, double delta);
283 void updateResourceState(void *id, tmgr_trace_event_t event_type,
284 double value, double time);
286 xbt_swag_t p_modifiedSet;
287 xbt_heap_t p_actionHeap;
288 int m_selectiveUpdate;
292 void surf_action_lmm_update_index_heap(void *action, int i);
294 class ActionLmm: virtual public Action {
296 ActionLmm() : m_suspended(false) {
297 p_actionListHookup.prev = 0;
298 p_actionListHookup.next = 0;
300 ActionLmm(ModelPtr model, double cost, bool failed) : m_suspended(false) {
301 p_actionListHookup.prev = 0;
302 p_actionListHookup.next = 0;
305 virtual void updateRemainingLazy(double now);
306 void heapInsert(xbt_heap_t heap, double key, enum heap_action_type hat);
307 void heapRemove(xbt_heap_t heap);
308 double getRemains(); /**< Get the remains of an action */
309 void updateIndexHeap(int i);
316 void setMaxDuration(double duration);
317 void setPriority(double priority);
320 lmm_variable_t p_variable;
321 s_xbt_swag_hookup_t p_actionListHookup;
325 enum heap_action_type m_hat;
329 #endif /* SURF_MODEL_H_ */