3 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
12 #include "xbt/dynar.h"
15 /* Actions and resources are higly connected structures... */
17 /** \brief Action datatype
18 * \ingroup SURF_actions
20 * An action is some working amount on a resource.
21 * It is represented as a cost, a priority, a duration and a state.
23 * \see e_surf_action_state_t
25 typedef struct surf_action *surf_action_t;
27 /** \brief Resource datatype
28 * \ingroup SURF_resources
30 * Generic data structure for a resource. The workstations,
31 * the CPUs and the network links are examples of resources.
33 typedef struct surf_resource *surf_resource_t;
35 /** \brief Action structure
36 * \ingroup SURF_actions
38 * Never create s_surf_action_t by yourself ! The actions are created
39 * on the fly when you call execute or communicate on a resource.
41 * \see e_surf_action_state_t
43 typedef struct surf_action {
44 s_xbt_swag_hookup_t state_hookup;
46 double cost; /**< cost */
47 double priority; /**< priority (1.0 by default) */
48 double max_duration; /**< max_duration (may fluctuate until
49 the task is completed) */
50 double remains; /**< How much of that cost remains to
51 * be done in the currently running task */
52 double start; /**< start time */
53 double finish; /**< finish time : this is modified during the run
54 * and fluctuates until the task is completed */
55 void *data; /**< for your convenience */
57 surf_resource_t resource_type;
60 /** \brief Action states
61 * \ingroup SURF_actions
65 * \see surf_action_t, surf_action_state_t
68 SURF_ACTION_READY = 0, /**< Ready */
69 SURF_ACTION_RUNNING, /**< Running */
70 SURF_ACTION_FAILED, /**< Task Failure */
71 SURF_ACTION_DONE, /**< Completed */
72 SURF_ACTION_TO_FREE, /**< Action to free in next cleanup */
73 SURF_ACTION_NOT_IN_THE_SYSTEM /**< Not in the system anymore. Why did you ask ? */
74 } e_surf_action_state_t;
76 /** \brief Action state sets
77 * \ingroup SURF_actions
79 * This structure contains some sets of actions.
80 * It provides a fast access to the actions in each state.
82 * \see surf_action_t, e_surf_action_state_t
84 typedef struct surf_action_state {
85 xbt_swag_t ready_action_set; /**< Actions in state SURF_ACTION_READY */
86 xbt_swag_t running_action_set; /**< Actions in state SURF_ACTION_RUNNING */
87 xbt_swag_t failed_action_set; /**< Actions in state SURF_ACTION_FAILED */
88 xbt_swag_t done_action_set; /**< Actions in state SURF_ACTION_DONE */
89 } s_surf_action_state_t, *surf_action_state_t;
91 /***************************/
92 /* Generic resource object */
93 /***************************/
95 /** \brief Public data available on all resources
96 * \ingroup SURF_resources
98 * These functions are implemented by all resources.
100 typedef struct surf_resource_public {
101 s_surf_action_state_t states; /**< Any living action on this resource */
102 void *(*name_service) (const char *name); /**< Return a resource given its name */
103 const char *(*get_resource_name) (void *resource_id); /**< Return the name of a resource */
105 e_surf_action_state_t(*action_get_state) (surf_action_t action); /**< Return the state of an action */
106 double (*action_get_start_time) (surf_action_t action); /**< Return the start time of an action */
107 double (*action_get_finish_time) (surf_action_t action); /**< Return the finish time of an action */
108 void (*action_use) (surf_action_t action); /**< Set an action used */
109 int (*action_free) (surf_action_t action); /**< Free an action */
110 void (*action_cancel) (surf_action_t action); /**< Cancel a running action */
111 void (*action_recycle) (surf_action_t action); /**< Recycle an action */
112 void (*action_change_state) (surf_action_t action, /**< Change an action state*/
113 e_surf_action_state_t state);
114 void (*action_set_data) (surf_action_t action, void *data); /**< Set the user data of an action */
115 void (*suspend) (surf_action_t action); /**< Suspend an action */
116 void (*resume) (surf_action_t action); /**< Resume a suspended action */
117 int (*is_suspended) (surf_action_t action); /**< Return whether an action is suspended */
118 void (*set_max_duration) (surf_action_t action, double duration); /**< Set the max duration of an action*/
119 void (*set_priority) (surf_action_t action, double priority); /**< Set the priority of an action */
120 const char *name; /**< Name of this resource */
121 } s_surf_resource_public_t, *surf_resource_public_t;
123 /** \brief Private data available on all resources
124 * \ingroup SURF_resources
126 typedef struct surf_resource_private *surf_resource_private_t;
128 /** \brief Resource datatype
129 * \ingroup SURF_resources
131 * Generic data structure for a resource. The workstations,
132 * the CPUs and the network links are examples of resources.
134 typedef struct surf_resource {
135 surf_resource_private_t common_private;
136 surf_resource_public_t common_public;
139 /**************************************/
140 /* Implementations of resource object */
141 /**************************************/
143 /** \brief Timer resource extension public
144 * \ingroup SURF_resource
146 * Additionnal functions specific to the timer resource
148 typedef struct surf_timer_resource_extension_public {
149 void (*set) (double date, void *function, void *arg);
150 int (*get) (void **function, void **arg);
151 } s_surf_timer_resource_extension_public_t,
152 *surf_timer_resource_extension_public_t;
154 /** \brief Timer resource
155 * \ingroup SURF_resources
157 typedef struct surf_timer_resource {
158 surf_resource_private_t common_private;
159 surf_resource_public_t common_public;
160 surf_timer_resource_extension_public_t extension_public;
161 } s_surf_timer_resource_t, *surf_timer_resource_t;
163 /** \brief The timer resource
164 * \ingroup SURF_resources
166 extern surf_timer_resource_t surf_timer_resource;
168 /** \brief Initializes the timer resource
169 * \ingroup SURF_resources
171 XBT_PUBLIC void surf_timer_resource_init(const char *filename);
176 * \ingroup SURF_resources
179 SURF_CPU_ON = 1, /**< Ready */
180 SURF_CPU_OFF = 0 /**< Running */
181 } e_surf_cpu_state_t;
183 /** \brief CPU resource extension public
184 * \ingroup SURF_resources
186 * Public functions specific to the CPU resource.
188 typedef struct surf_cpu_resource_extension_public {
189 surf_action_t(*execute) (void *cpu, double size);
190 surf_action_t(*sleep) (void *cpu, double duration);
191 e_surf_cpu_state_t(*get_state) (void *cpu);
192 double (*get_speed) (void *cpu, double load);
193 double (*get_available_speed) (void *cpu);
194 } s_surf_cpu_resource_extension_public_t,
195 *surf_cpu_resource_extension_public_t;
197 /** \brief CPU resource datatype
198 * \ingroup SURF_resources
200 typedef struct surf_cpu_resource {
201 surf_resource_private_t common_private;
202 surf_resource_public_t common_public;
203 surf_cpu_resource_extension_public_t extension_public;
204 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
206 /** \brief The CPU resource
207 * \ingroup SURF_resources
209 extern surf_cpu_resource_t surf_cpu_resource;
211 /** \brief Initializes the CPU resource with the model Cas01
212 * \ingroup SURF_resources
214 * This function is called by surf_workstation_resource_init_CLM03
215 * so you shouldn't have to call it by yourself.
217 * \see surf_workstation_resource_init_CLM03()
219 XBT_PUBLIC void surf_cpu_resource_init_Cas01(const char *filename);
221 /* Network resource */
223 /** \brief Network resource extension public
224 * \ingroup SURF_resources
226 * Public functions specific to the network resource
228 typedef struct surf_network_resource_extension_public {
229 surf_action_t(*communicate) (void *src, void *dst, double size,
231 const void** (*get_route) (void *src, void *dst);
232 int (*get_route_size) (void *src, void *dst);
233 const char* (*get_link_name) (const void *link);
234 double (*get_link_bandwidth) (const void *link);
235 double (*get_link_latency) (const void *link);
236 } s_surf_network_resource_extension_public_t,
237 *surf_network_resource_extension_public_t;
239 /** \brief Network resource datatype
240 * \ingroup SURF_resources
242 typedef struct surf_network_resource {
243 surf_resource_private_t common_private;
244 surf_resource_public_t common_public;
245 surf_network_resource_extension_public_t extension_public;
246 } s_surf_network_resource_t, *surf_network_resource_t;
248 /** \brief The network resource
249 * \ingroup SURF_resources
251 * When creating a new API on top on SURF, you shouldn't use the
252 * network resource unless you know what you are doing. Only the workstation
253 * resource should be accessed because depending on the platform model,
254 * the network resource can be NULL.
256 extern surf_network_resource_t surf_network_resource;
258 /** \brief Initializes the platform with the network model CM02
259 * \ingroup SURF_resources
260 * \param filename XML platform file name
262 * This function is called by surf_workstation_resource_init_CLM03
263 * so you shouldn't call it by yourself.
265 * \see surf_workstation_resource_init_CLM03()
267 XBT_PUBLIC void surf_network_resource_init_CM02(const char *filename);
269 /** \brief Workstation resource extension public
270 * \ingroup SURF_resources
272 * Public functions specific to the workstation resource.
274 typedef struct surf_workstation_resource_extension_public {
275 surf_action_t(*execute) (void *workstation, double size); /**< Execute a computation amount on a workstation
276 and create the corresponding action */
277 surf_action_t(*sleep) (void *workstation, double duration); /**< Make a workstation sleep during a given duration */
278 e_surf_cpu_state_t(*get_state) (void *workstation); /**< Return the CPU state of a workstation */
279 double (*get_speed) (void *workstation, double load); /**< Return the speed of a workstation */
280 double (*get_available_speed) (void *workstation); /**< Return tha available speed of a workstation */
281 surf_action_t(*communicate) (void *workstation_src, /**< Execute a communication amount between two workstations */
282 void *workstation_dst, double size,
284 surf_action_t(*execute_parallel_task) (int workstation_nb, /**< Execute a parallel task on several workstations */
285 void **workstation_list,
286 double *computation_amount,
287 double *communication_amount,
290 const void** (*get_route) (void *src, void *dst); /**< Return the network link list between two workstations */
291 int (*get_route_size) (void *src, void *dst); /**< Return the route size between two workstations */
292 const char* (*get_link_name) (const void *link); /**< Return the name of a network link */
293 double (*get_link_bandwidth) (const void *link); /**< Return the current bandwidth of a network link */
294 double (*get_link_latency) (const void *link); /**< Return the current latency of a network link */
295 } s_surf_workstation_resource_extension_public_t,
296 *surf_workstation_resource_extension_public_t;
298 /** \brief Workstation resource datatype.
299 * \ingroup SURF_resources
302 typedef struct surf_workstation_resource {
303 surf_resource_private_t common_private;
304 surf_resource_public_t common_public;
305 surf_workstation_resource_extension_public_t extension_public;
306 } s_surf_workstation_resource_t, *surf_workstation_resource_t;
308 /** \brief The workstation resource
309 * \ingroup SURF_resources
311 * Note that when you create an API on top of SURF,
312 * the workstation resource should be the only one you use
313 * because depending on the platform model, the network resource and the CPU resource
316 extern surf_workstation_resource_t surf_workstation_resource;
318 /** \brief Initializes the platform with the workstation model CLM03
319 * \ingroup SURF_resources
320 * \param filename XML platform file name
322 * This platform model seperates the workstation resource and the network resource.
323 * The workstation resource will be initialized with the model CLM03, the network
324 * resource with the model CM02 and the CPU resource with the model Cas01.
325 * In future releases, some other network models will be implemented and will be
326 * combined with the workstation model CLM03.
328 * \see surf_workstation_resource_init_KCCFLN05()
330 XBT_PUBLIC void surf_workstation_resource_init_CLM03(const char *filename);
332 /** \brief Initializes the platform with the model KCCFLN05
333 * \ingroup SURF_resources
334 * \param filename XML platform file name
336 * With this model, the workstations and the network are handled together.
337 * There is no network resource. This platform model is the default one for
340 * \see surf_workstation_resource_init_CLM03()
342 void surf_workstation_resource_init_KCCFLN05(const char *filename);
344 /** \brief The network links
345 * \ingroup SURF_resources
347 * This dict contains all network links.
349 * \see workstation_set
351 extern xbt_dict_t network_link_set;
353 /** \brief The workstations
354 * \ingroup SURF_resources
356 * This dict contains all workstations.
358 * \see network_link_set
360 extern xbt_dict_t workstation_set;
362 /** \brief List of initialized resources
363 * \ingroup SURF_resources
365 extern xbt_dynar_t resource_list;
367 /*******************************************/
368 /*** SURF Globals **************************/
369 /*******************************************/
371 /** \brief Initialize SURF
372 * \ingroup SURF_simulation
373 * \param argc argument number
374 * \param argv arguments
376 * This function has to be called to initialize the common structures.
377 * Then you will have to create the environment by calling surf_timer_resource_init()
378 * and surf_workstation_resource_init_CLM03() or surf_workstation_resource_init_KCCFLN05().
380 * \see surf_timer_resource_init(), surf_workstation_resource_init_CLM03(),
381 * surf_workstation_resource_init_KCCFLN05(), surf_exit()
383 void surf_init(int *argc, char **argv); /* initialize common structures */
385 /** \brief Performs a part of the simulation
386 * \ingroup SURF_simulation
387 * \return the elapsed time, or -1.0 if no event could be executed
389 * This function execute all possible events, update the action states
390 * and returns the time elapsed.
391 * When you call execute or communicate on a resource, the corresponding actions
392 * are not executed immediately but only when you call surf_solve.
393 * Note that the returned elapsed time can be zero.
395 double surf_solve(void);
397 /** \brief Return the current time
398 * \ingroup SURF_simulation
400 * Return the current time in millisecond.
402 double surf_get_clock(void);
405 * \ingroup SURF_simulation
411 void surf_exit(void);
413 #endif /* _SURF_SURF_H */