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 XBT_PUBLIC(int) SURF_CPU_LEVEL; //Surf cpu level
52 typedef Model* ModelPtr;
55 typedef Resource* ResourcePtr;
56 typedef boost::function<void (ResourcePtr r)> ResourceCallback;
59 typedef Action* ActionPtr;
60 typedef boost::function<void (ActionPtr a)> ActionCallback;
65 /* For the trace and trace:connect tag (store their content till the end of the parsing) */
66 XBT_PUBLIC_DATA(xbt_dict_t) traces_set_list;
67 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_host_avail;
68 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_power;
69 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_link_avail;
70 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_bandwidth;
71 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_latency;
77 XBT_PUBLIC_DATA(xbt_dynar_t) model_list;
83 m_resOnCB = m_resOffCB= 0;
84 m_actSuspendCB = m_actCancelCB = m_actResumeCB = 0;
87 xbt_swag_free(p_readyActionSet);
88 xbt_swag_free(p_runningActionSet);
89 xbt_swag_free(p_failedActionSet);
90 xbt_swag_free(p_doneActionSet);
92 ResourcePtr createResource(string name);
93 ActionPtr createAction(double _cost, bool _failed);
94 double shareResources(double now);
95 void updateActionsState(double now, double delta);
97 string getName() {return m_name;};
99 void addTurnedOnCallback(ResourceCallback rc);
100 void notifyResourceTurnedOn(ResourcePtr r);
102 void addTurnedOffCallback(ResourceCallback rc);
103 void notifyResourceTurnedOff(ResourcePtr r);
105 void addActionCancelCallback(ActionCallback ac);
106 void notifyActionCancel(ActionPtr a);
107 void addActionResumeCallback(ActionCallback ac);
108 void notifyActionResume(ActionPtr a);
109 void addActionSuspendCallback(ActionCallback ac);
110 void notifyActionSuspend(ActionPtr a);
112 xbt_swag_t p_readyActionSet; /**< Actions in state SURF_ACTION_READY */
113 xbt_swag_t p_runningActionSet; /**< Actions in state SURF_ACTION_RUNNING */
114 xbt_swag_t p_failedActionSet; /**< Actions in state SURF_ACTION_FAILED */
115 xbt_swag_t p_doneActionSet; /**< Actions in state SURF_ACTION_DONE */
118 std::vector<ActionPtr> m_failedActions, m_runningActions;
122 ResourceCallback m_resOnCB, m_resOffCB;
123 ActionCallback m_actCancelCB, m_actSuspendCB, m_actResumeCB;
131 Resource(ModelPtr model, const char *name, xbt_dict_t properties):
132 m_name(name),m_running(true),p_model(model),m_properties(properties) {};
133 virtual ~Resource() {};
135 void updateState(tmgr_trace_event_t event_type, double value, double date);
139 //TODOupdateActionState();
140 //TODOupdateResourceState();
146 void setName(string name);
148 ModelPtr getModel() {return p_model;};
149 void printModel() { std::cout << p_model->getName() << "<<plop"<<std::endl;};
151 e_surf_resource_state_t m_stateCurrent;
156 xbt_dict_t m_properties;
162 static inline void *surf_cpu_resource_priv(const void *host) {
163 return xbt_lib_get_level((xbt_dictelm_t)host, SURF_CPU_LEVEL);
165 /*static inline void *surf_workstation_resource_priv(const void *host){
166 return xbt_lib_get_level((xbt_dictelm_t)host, SURF_WKS_LEVEL);
168 static inline void *surf_storage_resource_priv(const void *host){
169 return xbt_lib_get_level((xbt_dictelm_t)host, SURF_STORAGE_LEVEL);
172 static inline void *surf_cpu_resource_by_name(const char *name) {
173 return xbt_lib_get_elm_or_null(host_lib, name);
175 /*static inline void *surf_workstation_resource_by_name(const char *name){
176 return xbt_lib_get_elm_or_null(host_lib, name);
178 static inline void *surf_storage_resource_by_name(const char *name){
179 return xbt_lib_get_elm_or_null(storage_lib, name);*/
185 /** \ingroup SURF_actions
186 * \brief Action states
190 * \see surf_action_t, surf_action_state_t
192 extern const char *surf_action_state_names[6];
195 SURF_ACTION_READY = 0, /**< Ready */
196 SURF_ACTION_RUNNING, /**< Running */
197 SURF_ACTION_FAILED, /**< Task Failure */
198 SURF_ACTION_DONE, /**< Completed */
199 SURF_ACTION_TO_FREE, /**< Action to free in next cleanup */
200 SURF_ACTION_NOT_IN_THE_SYSTEM
201 /**< Not in the system anymore. Why did you ask ? */
202 } e_surf_action_state_t;
212 Action(ModelPtr model, double cost, bool failed):
213 m_cost(cost), p_model(model), m_failed(failed),
214 m_refcount(1), m_priority(1.0), m_maxDuration(NO_MAX_DURATION),
215 m_start(surf_get_clock()), m_finish(-1.0)
217 m_priority = m_start = m_finish = m_maxDuration = -1.0;
218 m_start = 10;//surf_get_clock();
221 virtual ~Action() {};
223 e_surf_action_state_t getState(); /**< get the state*/
224 void setState(e_surf_action_state_t state); /**< Change state*/
225 double getStartTime(); /**< Return the start time of an action */
226 double getFinishTime(); /**< Return the finish time of an action */
227 void setData(void* data);
229 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. */
230 virtual void cancel()=0; /**< Cancel a running action */
231 virtual void recycle()=0; /**< Recycle an action */
233 void suspend(); /**< Suspend an action */
234 void resume(); /**< Resume a suspended action */
235 bool isSuspended(); /**< Return whether an action is suspended */
236 void setMaxDuration(double duration); /**< Set the max duration of an action*/
237 void setPriority(double priority); /**< Set the priority of an action */
239 void setCategory(const char *category); /**< Set the category of an action */
241 double getRemains(); /**< Get the remains of an action */
242 #ifdef HAVE_LATENCY_BOUND_TRACKING
243 int getLatencyLimited(); /**< Return 1 if action is limited by latency, 0 otherwise */
245 xbt_swag_t p_stateSet;
247 double m_priority; /**< priority (1.0 by default) */
250 double m_start; /**< start time */
251 double m_finish; /**< finish time : this is modified during the run and fluctuates until the task is completed */
252 double m_remains; /**< How much of that cost remains to be done in the currently running task */
253 #ifdef HAVE_LATENCY_BOUND_TRACKING
254 int m_latencyLimited; /**< Set to 1 if is limited by latency, 0 otherwise */
256 double m_maxDuration; /*< max_duration (may fluctuate until the task is completed) */
261 void *p_data; /**< for your convenience */
263 char *p_category; /**< tracing category for categorized resource utilization monitoring */
267 int resourceUsed(void *resource_id);
268 /* Share the resources to the actions and return in how much time
269 the next action may terminate */
270 double shareResources(double now);
271 /* Update the actions' state */
272 void updateActionsState(double now, double delta);
273 void updateResourceState(void *id, tmgr_trace_event_t event_type,
274 double value, double time);
277 lmm_system_t p_maxminSystem;
278 e_UM_t p_updateMechanism;
279 xbt_swag_t p_modifiedSet;
280 xbt_heap_t p_actionHeap;
281 int m_selectiveUpdate;
284 #endif /* SURF_MODEL_H_ */