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;
50 XBT_PUBLIC(double) surf_get_clock(void);
55 extern double sg_sender_gap;
56 XBT_PUBLIC(int) SURF_CPU_LEVEL; //Surf cpu level
58 int __surf_is_absolute_file_path(const char *file_path);
64 typedef Model* ModelPtr;
67 typedef Resource* ResourcePtr;
68 typedef boost::function<void (ResourcePtr r)> ResourceCallback;
71 typedef Action* ActionPtr;
72 typedef boost::function<void (ActionPtr a)> ActionCallback;
75 typedef ActionLmm* ActionLmmPtr;
77 enum heap_action_type{
87 /* For the trace and trace:connect tag (store their content till the end of the parsing) */
88 XBT_PUBLIC_DATA(xbt_dict_t) traces_set_list;
89 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_host_avail;
90 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_power;
91 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_link_avail;
92 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_bandwidth;
93 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_latency;
99 XBT_PUBLIC_DATA(xbt_dynar_t) model_list;
106 ResourcePtr createResource(string name);
107 ActionPtr createAction(double _cost, bool _failed);
108 virtual double shareResources(double now);
109 virtual double shareResourcesLazy(double now);
110 virtual double shareResourcesFull(double now);
111 double shareResourcesMaxMin(xbt_swag_t running_actions,
113 void (*solve) (lmm_system_t));
114 virtual void updateActionsState(double now, double delta);
115 virtual void updateActionsStateLazy(double now, double delta);
116 virtual void updateActionsStateFull(double now, double delta);
118 string getName() {return m_name;};
120 void addTurnedOnCallback(ResourceCallback rc);
121 void notifyResourceTurnedOn(ResourcePtr r);
123 void addTurnedOffCallback(ResourceCallback rc);
124 void notifyResourceTurnedOff(ResourcePtr r);
126 void addActionCancelCallback(ActionCallback ac);
127 void notifyActionCancel(ActionPtr a);
128 void addActionResumeCallback(ActionCallback ac);
129 void notifyActionResume(ActionPtr a);
130 void addActionSuspendCallback(ActionCallback ac);
131 void notifyActionSuspend(ActionPtr a);
133 lmm_system_t p_maxminSystem;
134 e_UM_t p_updateMechanism;
135 xbt_swag_t p_modifiedSet;
136 xbt_heap_t p_actionHeap;
137 int m_selectiveUpdate;
139 xbt_swag_t p_readyActionSet; /**< Actions in state SURF_ACTION_READY */
140 xbt_swag_t p_runningActionSet; /**< Actions in state SURF_ACTION_RUNNING */
141 xbt_swag_t p_failedActionSet; /**< Actions in state SURF_ACTION_FAILED */
142 xbt_swag_t p_doneActionSet; /**< Actions in state SURF_ACTION_DONE */
146 std::vector<ActionPtr> m_failedActions, m_runningActions;
149 ResourceCallback m_resOnCB, m_resOffCB;
150 ActionCallback m_actCancelCB, m_actSuspendCB, m_actResumeCB;
158 * Resource which have a metric handled by a maxmin system
163 tmgr_trace_event_t event;
169 Resource(ModelPtr model, const char *name, xbt_dict_t properties);
170 virtual ~Resource() {
171 xbt_free((void*)m_name);
172 xbt_dict_free(&m_properties);
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 virtual void setState(e_surf_resource_state_t state);
193 void printModel() { std::cout << p_model->getName() << "<<plop"<<std::endl;};
196 xbt_dict_t m_properties;
198 e_surf_resource_state_t p_stateCurrent;
206 class ResourceLmm: virtual public Resource {
208 ResourceLmm() : p_constraint(NULL) {
209 p_power.event = NULL;
211 ResourceLmm(lmm_system_t system,
212 double constraint_value,
213 tmgr_history_t history,
214 e_surf_resource_state_t state_init,
215 tmgr_trace_t state_trace,
217 tmgr_trace_t metric_trace);
220 lmm_constraint_t p_constraint;
221 tmgr_trace_event_t p_stateEvent;
222 s_surf_metric_t p_power;
232 Action(ModelPtr model, double cost, bool failed);
235 s_xbt_swag_hookup_t p_stateHookup;
237 e_surf_action_state_t getState(); /**< get the state*/
238 virtual void setState(e_surf_action_state_t state); /**< Change state*/
239 double getStartTime(); /**< Return the start time of an action */
240 double getFinishTime(); /**< Return the finish time of an action */
241 void setData(void* data);
244 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. */
245 virtual void cancel(); /**< Cancel a running action */
246 virtual void recycle(); /**< Recycle an action */
248 virtual void suspend()=0; /**< Suspend an action */
249 virtual void resume()=0; /**< Resume a suspended action */
250 virtual bool isSuspended()=0; /**< Return whether an action is suspended */
251 virtual void setMaxDuration(double duration)=0; /**< Set the max duration of an action*/
252 virtual void setPriority(double priority)=0; /**< Set the priority of an action */
254 void setCategory(const char *category); /**< Set the category of an action */
256 virtual double getRemains(); /**< Get the remains of an action */
257 #ifdef HAVE_LATENCY_BOUND_TRACKING
258 int getLatencyLimited(); /**< Return 1 if action is limited by latency, 0 otherwise */
261 xbt_swag_t p_stateSet;
263 double m_priority; /**< priority (1.0 by default) */
264 double m_bound; /**< the capping of the CPU use */
266 double m_start; /**< start time */
267 double m_finish; /**< finish time : this is modified during the run and fluctuates until the task is completed */
268 double m_remains; /**< How much of that cost remains to be done in the currently running task */
269 #ifdef HAVE_LATENCY_BOUND_TRACKING
270 int m_latencyLimited; /**< Set to 1 if is limited by latency, 0 otherwise */
272 double m_maxDuration; /*< max_duration (may fluctuate until the task is completed) */
273 char *p_category; /**< tracing category for categorized resource utilization monitoring */
275 void *p_data; /**< for your convenience */
283 int resourceUsed(void *resource_id);
284 /* Share the resources to the actions and return in how much time
285 the next action may terminate */
286 double shareResources(double now);
287 /* Update the actions' state */
288 void updateActionsState(double now, double delta);
289 void updateResourceState(void *id, tmgr_trace_event_t event_type,
290 double value, double time);
292 xbt_swag_t p_modifiedSet;
293 xbt_heap_t p_actionHeap;
294 int m_selectiveUpdate;
298 void surf_action_lmm_update_index_heap(void *action, int i);
300 class ActionLmm: virtual public Action {
302 ActionLmm() : m_suspended(false) {
303 p_actionListHookup.prev = 0;
304 p_actionListHookup.next = 0;
308 ActionLmm(ModelPtr /*model*/, double /*cost*/, bool /*failed*/) : m_suspended(false) {
309 p_actionListHookup.prev = 0;
310 p_actionListHookup.next = 0;
315 virtual void updateRemainingLazy(double now);
316 void heapInsert(xbt_heap_t heap, double key, enum heap_action_type hat);
317 void heapRemove(xbt_heap_t heap);
318 double getRemains(); /**< Get the remains of an action */
319 void updateIndexHeap(int i);
326 void setMaxDuration(double duration);
327 void setPriority(double priority);
330 lmm_variable_t p_variable;
331 s_xbt_swag_hookup_t p_actionListHookup;
335 enum heap_action_type m_hat;
339 #endif /* SURF_MODEL_H_ */