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 #include "gras_config.h"
21 /* Actions and resources are higly connected structures... */
23 /** \brief Action datatype
24 * \ingroup SURF_actions
26 * An action is some working amount on a resource.
27 * It is represented as a cost, a priority, a duration and a state.
29 * \see e_surf_action_state_t
31 typedef struct surf_action *surf_action_t;
33 /** \brief Resource datatype
34 * \ingroup SURF_resources
36 * Generic data structure for a resource. The workstations,
37 * the CPUs and the network links are examples of resources.
39 typedef struct surf_resource *surf_resource_t;
41 /** \brief Resource model description
43 typedef struct surf_resource_description {
45 surf_resource_t resource;
46 void (* resource_init) (const char *filename);
47 } s_surf_resource_description_t, *surf_resource_description_t;
49 XBT_PUBLIC(void) update_resource_description(s_surf_resource_description_t *table,
52 surf_resource_t resource
54 XBT_PUBLIC(int) find_resource_description(s_surf_resource_description_t *table,
58 /** \brief Action structure
59 * \ingroup SURF_actions
61 * Never create s_surf_action_t by yourself ! The actions are created
62 * on the fly when you call execute or communicate on a resource.
64 * \see e_surf_action_state_t
66 typedef struct surf_action {
67 s_xbt_swag_hookup_t state_hookup;
69 double cost; /**< cost */
70 double priority; /**< priority (1.0 by default) */
71 double max_duration; /**< max_duration (may fluctuate until
72 the task is completed) */
73 double remains; /**< How much of that cost remains to
74 * be done in the currently running task */
75 double start; /**< start time */
76 double finish; /**< finish time : this is modified during the run
77 * and fluctuates until the task is completed */
78 void *data; /**< for your convenience */
80 surf_resource_t resource_type;
83 /** \brief Action states
84 * \ingroup SURF_actions
88 * \see surf_action_t, surf_action_state_t
91 SURF_ACTION_READY = 0, /**< Ready */
92 SURF_ACTION_RUNNING, /**< Running */
93 SURF_ACTION_FAILED, /**< Task Failure */
94 SURF_ACTION_DONE, /**< Completed */
95 SURF_ACTION_TO_FREE, /**< Action to free in next cleanup */
96 SURF_ACTION_NOT_IN_THE_SYSTEM /**< Not in the system anymore. Why did you ask ? */
97 } e_surf_action_state_t;
99 /** \brief Action state sets
100 * \ingroup SURF_actions
102 * This structure contains some sets of actions.
103 * It provides a fast access to the actions in each state.
105 * \see surf_action_t, e_surf_action_state_t
107 typedef struct surf_action_state {
108 xbt_swag_t ready_action_set; /**< Actions in state SURF_ACTION_READY */
109 xbt_swag_t running_action_set; /**< Actions in state SURF_ACTION_RUNNING */
110 xbt_swag_t failed_action_set; /**< Actions in state SURF_ACTION_FAILED */
111 xbt_swag_t done_action_set; /**< Actions in state SURF_ACTION_DONE */
112 } s_surf_action_state_t, *surf_action_state_t;
114 /***************************/
115 /* Generic resource object */
116 /***************************/
118 /** \brief Public data available on all resources
119 * \ingroup SURF_resources
121 * These functions are implemented by all resources.
123 typedef struct surf_resource_public {
124 s_surf_action_state_t states; /**< Any living action on this resource */
125 void *(*name_service) (const char *name); /**< Return a resource given its name */
126 const char *(*get_resource_name) (void *resource_id); /**< Return the name of a resource */
128 e_surf_action_state_t(*action_get_state) (surf_action_t action); /**< Return the state of an action */
129 double (*action_get_start_time) (surf_action_t action); /**< Return the start time of an action */
130 double (*action_get_finish_time) (surf_action_t action); /**< Return the finish time of an action */
131 void (*action_use) (surf_action_t action); /**< Set an action used */
132 int (*action_free) (surf_action_t action); /**< Free an action */
133 void (*action_cancel) (surf_action_t action); /**< Cancel a running action */
134 void (*action_recycle) (surf_action_t action); /**< Recycle an action */
135 void (*action_change_state) (surf_action_t action, /**< Change an action state*/
136 e_surf_action_state_t state);
137 void (*action_set_data) (surf_action_t action, void *data); /**< Set the user data of an action */
138 void (*suspend) (surf_action_t action); /**< Suspend an action */
139 void (*resume) (surf_action_t action); /**< Resume a suspended action */
140 int (*is_suspended) (surf_action_t action); /**< Return whether an action is suspended */
141 void (*set_max_duration) (surf_action_t action, double duration); /**< Set the max duration of an action*/
142 void (*set_priority) (surf_action_t action, double priority); /**< Set the priority of an action */
143 const char *name; /**< Name of this resource */
144 } s_surf_resource_public_t, *surf_resource_public_t;
146 /** \brief Private data available on all resources
147 * \ingroup SURF_resources
149 typedef struct surf_resource_private *surf_resource_private_t;
151 /** \brief Resource datatype
152 * \ingroup SURF_resources
154 * Generic data structure for a resource. The workstations,
155 * the CPUs and the network links are examples of resources.
157 typedef struct surf_resource {
158 surf_resource_private_t common_private;
159 surf_resource_public_t common_public;
162 /**************************************/
163 /* Implementations of resource object */
164 /**************************************/
166 /** \brief Timer resource extension public
167 * \ingroup SURF_resource
169 * Additionnal functions specific to the timer resource
171 typedef struct surf_timer_resource_extension_public {
172 void (*set) (double date, void *function, void *arg);
173 int (*get) (void **function, void **arg);
174 } s_surf_timer_resource_extension_public_t,
175 *surf_timer_resource_extension_public_t;
177 /** \brief Timer resource
178 * \ingroup SURF_resources
180 typedef struct surf_timer_resource {
181 surf_resource_private_t common_private;
182 surf_resource_public_t common_public;
183 surf_timer_resource_extension_public_t extension_public;
184 } s_surf_timer_resource_t, *surf_timer_resource_t;
186 /** \brief The timer resource
187 * \ingroup SURF_resources
189 XBT_PUBLIC_DATA(surf_timer_resource_t) surf_timer_resource;
191 /** \brief Initializes the timer resource
192 * \ingroup SURF_resources
194 XBT_PUBLIC(void) surf_timer_resource_init(const char *filename);
199 * \ingroup SURF_resources
202 SURF_CPU_ON = 1, /**< Ready */
203 SURF_CPU_OFF = 0 /**< Running */
204 } e_surf_cpu_state_t;
206 /** \brief CPU resource extension public
207 * \ingroup SURF_resources
209 * Public functions specific to the CPU resource.
211 typedef struct surf_cpu_resource_extension_public {
212 surf_action_t(*execute) (void *cpu, double size);
213 surf_action_t(*sleep) (void *cpu, double duration);
214 e_surf_cpu_state_t(*get_state) (void *cpu);
215 double (*get_speed) (void *cpu, double load);
216 double (*get_available_speed) (void *cpu);
217 } s_surf_cpu_resource_extension_public_t,
218 *surf_cpu_resource_extension_public_t;
220 /** \brief CPU resource datatype
221 * \ingroup SURF_resources
223 typedef struct surf_cpu_resource {
224 surf_resource_private_t common_private;
225 surf_resource_public_t common_public;
226 surf_cpu_resource_extension_public_t extension_public;
227 } s_surf_cpu_resource_t, *surf_cpu_resource_t;
229 /** \brief The CPU resource
230 * \ingroup SURF_resources
232 XBT_PUBLIC_DATA(surf_cpu_resource_t) surf_cpu_resource;
234 /** \brief Initializes the CPU resource with the model Cas01
235 * \ingroup SURF_resources
237 * This function is called by surf_workstation_resource_init_CLM03
238 * so you shouldn't have to call it by yourself.
240 * \see surf_workstation_resource_init_CLM03()
242 XBT_PUBLIC(void) surf_cpu_resource_init_Cas01(const char *filename);
244 extern XBT_PUBLIC_DATA(int) surf_cpu_resource_description_size;
245 /** \brief The list of all available cpu resource models
246 * \ingroup SURF_resources
248 extern XBT_PUBLIC_DATA(s_surf_resource_description_t) surf_cpu_resource_description[];
250 /* Network resource */
252 /** \brief Network resource extension public
253 * \ingroup SURF_resources
255 * Public functions specific to the network resource
257 typedef struct surf_network_resource_extension_public {
258 surf_action_t(*communicate) (void *src, void *dst, double size,
260 const void** (*get_route) (void *src, void *dst);
261 int (*get_route_size) (void *src, void *dst);
262 const char* (*get_link_name) (const void *link);
263 double (*get_link_bandwidth) (const void *link);
264 double (*get_link_latency) (const void *link);
265 } s_surf_network_resource_extension_public_t,
266 *surf_network_resource_extension_public_t;
268 /** \brief Network resource datatype
269 * \ingroup SURF_resources
271 typedef struct surf_network_resource {
272 surf_resource_private_t common_private;
273 surf_resource_public_t common_public;
274 surf_network_resource_extension_public_t extension_public;
275 } s_surf_network_resource_t, *surf_network_resource_t;
277 /** \brief The network resource
278 * \ingroup SURF_resources
280 * When creating a new API on top on SURF, you shouldn't use the
281 * network resource unless you know what you are doing. Only the workstation
282 * resource should be accessed because depending on the platform model,
283 * the network resource can be NULL.
285 XBT_PUBLIC_DATA(surf_network_resource_t) surf_network_resource;
287 /** \brief Initializes the platform with the network model CM02
288 * \ingroup SURF_resources
289 * \param filename XML platform file name
291 * This function is called by surf_workstation_resource_init_CLM03
292 * or by yourself only if you plan using surf_workstation_resource_init_compound
294 * \see surf_workstation_resource_init_CLM03()
296 XBT_PUBLIC(void) surf_network_resource_init_CM02(const char *filename);
299 /** \brief Initializes the platform with the network model GTNETS
300 * \ingroup SURF_resources
301 * \param filename XML platform file name
303 * This function is called by surf_workstation_resource_init_GTNETS
304 * or by yourself only if you plan using surf_workstation_resource_init_compound
306 * \see surf_workstation_resource_init_GTNETS()
308 XBT_PUBLIC(void) surf_network_resource_init_GTNETS(const char *filename);
311 /** \brief Initializes the platform with the network model Reno
312 * \ingroup SURF_resources
313 * \param filename XML platform file name
315 * The problem is related to max( sum( arctan(C * Df * xi) ) ).
318 * [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
319 * IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
321 * Call this function only if you plan using surf_workstation_resource_init_compound.
324 XBT_PUBLIC(void) surf_network_resource_init_Reno(const char *filename);
326 /** \brief Initializes the platform with the network model Vegas
327 * \ingroup SURF_resources
328 * \param filename XML platform file name
330 * This problem is related to max( sum( a * Df * ln(xi) ) ) which is equivalent
331 * to the proportional fairness.
334 * [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
335 * IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
337 * Call this function only if you plan using surf_workstation_resource_init_compound.
340 XBT_PUBLIC(void) surf_network_resource_init_Vegas(const char *filename);
343 /** \brief Initializes the platform with the network model based on SDP
344 * \ingroup SURF_resources
345 * \param filename XML platform file name
347 * This function implements the proportional fairness known as the maximization
352 * [TAG03]. Corinne Touati, Eitan Altman, and Jérôme Galtier.
353 * Semi-definite programming approach for bandwidth allocation and routing in networks.
354 * Game Theory and Applications, 9:169-179, December 2003. Nova publisher.
356 * Call this function only if you plan using surf_workstation_resource_init_compound.
358 XBT_PUBLIC(void) surf_network_resource_init_SDP(const char *filename);
363 extern XBT_PUBLIC_DATA(int) surf_network_resource_description_size;
364 /** \brief The list of all available network resource models
365 * \ingroup SURF_resources
367 extern XBT_PUBLIC_DATA(s_surf_resource_description_t) surf_network_resource_description[];
369 /** \brief Workstation resource extension public
370 * \ingroup SURF_resources
372 * Public functions specific to the workstation resource.
374 typedef struct surf_workstation_resource_extension_public {
375 surf_action_t(*execute) (void *workstation, double size); /**< Execute a computation amount on a workstation
376 and create the corresponding action */
377 surf_action_t(*sleep) (void *workstation, double duration); /**< Make a workstation sleep during a given duration */
378 e_surf_cpu_state_t(*get_state) (void *workstation); /**< Return the CPU state of a workstation */
379 double (*get_speed) (void *workstation, double load); /**< Return the speed of a workstation */
380 double (*get_available_speed) (void *workstation); /**< Return tha available speed of a workstation */
381 surf_action_t(*communicate) (void *workstation_src, /**< Execute a communication amount between two workstations */
382 void *workstation_dst, double size,
384 surf_action_t(*execute_parallel_task) (int workstation_nb, /**< Execute a parallel task on several workstations */
385 void **workstation_list,
386 double *computation_amount,
387 double *communication_amount,
390 const void** (*get_route) (void *src, void *dst); /**< Return the network link list between two workstations */
391 int (*get_route_size) (void *src, void *dst); /**< Return the route size between two workstations */
392 const char* (*get_link_name) (const void *link); /**< Return the name of a network link */
393 double (*get_link_bandwidth) (const void *link); /**< Return the current bandwidth of a network link */
394 double (*get_link_latency) (const void *link); /**< Return the current latency of a network link */
395 } s_surf_workstation_resource_extension_public_t,
396 *surf_workstation_resource_extension_public_t;
398 /** \brief Workstation resource datatype.
399 * \ingroup SURF_resources
402 typedef struct surf_workstation_resource {
403 surf_resource_private_t common_private;
404 surf_resource_public_t common_public;
405 surf_workstation_resource_extension_public_t extension_public;
406 } s_surf_workstation_resource_t, *surf_workstation_resource_t;
408 /** \brief The workstation resource
409 * \ingroup SURF_resources
411 * Note that when you create an API on top of SURF,
412 * the workstation resource should be the only one you use
413 * because depending on the platform model, the network resource and the CPU resource
416 XBT_PUBLIC_DATA(surf_workstation_resource_t) surf_workstation_resource;
418 /** \brief Initializes the platform with a compound workstation model
419 * \ingroup SURF_resources
420 * \param filename XML platform file name
422 * This function should be called after a cpu_resource and a
423 * network_resource have been set up.
426 XBT_PUBLIC(void) surf_workstation_resource_init_compound(const char *filename);
428 /** \brief Initializes the platform with the workstation model CLM03
429 * \ingroup SURF_resources
430 * \param filename XML platform file name
432 * This platform model seperates the workstation resource and the network resource.
433 * The workstation resource will be initialized with the model CLM03, the network
434 * resource with the model CM02 and the CPU resource with the model Cas01.
435 * In future releases, some other network models will be implemented and will be
436 * combined with the workstation model CLM03.
438 * \see surf_workstation_resource_init_KCCFLN05()
440 XBT_PUBLIC(void) surf_workstation_resource_init_CLM03(const char *filename);
442 /** \brief Initializes the platform with the model KCCFLN05
443 * \ingroup SURF_resources
444 * \param filename XML platform file name
446 * With this model, the workstations and the network are handled
447 * together. The network model is roughly the same as in CM02 but
448 * interference between computations and communications can be taken
449 * into account. This platform model is the default one for MSG and
453 XBT_PUBLIC(void) surf_workstation_resource_init_KCCFLN05(const char *filename);
455 /** \brief Initializes the platform with the model KCCFLN05
456 * \ingroup SURF_resources
457 * \param filename XML platform file name
459 * With this model, only parallel tasks can be used. Resource sharing
460 * is done by identifying bottlenecks and giving an equal share of
461 * the resource to each action.
464 XBT_PUBLIC(void) surf_workstation_resource_init_ptask_L07(const char *filename);
466 extern XBT_PUBLIC_DATA(int) surf_workstation_resource_description_size;
467 /** \brief The list of all available workstation resource models
468 * \ingroup SURF_resources
470 extern XBT_PUBLIC_DATA(s_surf_resource_description_t) surf_workstation_resource_description[];
472 /** \brief The network links
473 * \ingroup SURF_resources
475 * This dict contains all network links.
477 * \see workstation_set
479 XBT_PUBLIC_DATA(xbt_dict_t) network_link_set;
481 /** \brief The workstations
482 * \ingroup SURF_resources
484 * This dict contains all workstations.
486 * \see network_link_set
488 XBT_PUBLIC_DATA(xbt_dict_t) workstation_set;
490 /** \brief List of initialized resources
491 * \ingroup SURF_resources
493 XBT_PUBLIC_DATA(xbt_dynar_t) resource_list;
495 /*******************************************/
496 /*** SURF Globals **************************/
497 /*******************************************/
499 /** \brief Initialize SURF
500 * \ingroup SURF_simulation
501 * \param argc argument number
502 * \param argv arguments
504 * This function has to be called to initialize the common
505 * structures. Then you will have to create the environment by
506 * calling surf_timer_resource_init() and
507 * e.g. surf_workstation_resource_init_CLM03() or
508 * surf_workstation_resource_init_KCCFLN05().
510 * \see surf_timer_resource_init(), surf_workstation_resource_init_CLM03(),
511 * surf_workstation_resource_init_KCCFLN05(), surf_workstation_resource_init_compound(), surf_exit()
513 XBT_PUBLIC(void) surf_init(int *argc, char **argv); /* initialize common structures */
515 /** \brief Performs a part of the simulation
516 * \ingroup SURF_simulation
517 * \return the elapsed time, or -1.0 if no event could be executed
519 * This function execute all possible events, update the action states
520 * and returns the time elapsed.
521 * When you call execute or communicate on a resource, the corresponding actions
522 * are not executed immediately but only when you call surf_solve.
523 * Note that the returned elapsed time can be zero.
525 XBT_PUBLIC(double) surf_solve(void);
527 /** \brief Return the current time
528 * \ingroup SURF_simulation
530 * Return the current time in millisecond.
532 XBT_PUBLIC(double)surf_get_clock(void);
535 * \ingroup SURF_simulation
541 XBT_PUBLIC(void) surf_exit(void);
546 #endif /* _SURF_SURF_H */