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"
21 /* Actions and models are higly connected structures... */
23 /** \brief Action datatype
24 * \ingroup SURF_actions
26 * An action is some working amount on a model.
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_models
36 * Generic data structure for a model. The workstations,
37 * the CPUs and the network links are examples of models.
39 typedef struct surf_model *surf_model_t;
41 /** \brief Resource model description
43 typedef struct surf_model_description {
46 void (* model_init) (const char *filename);
47 void (* create_ws) (void);
48 } s_surf_model_description_t, *surf_model_description_t;
50 XBT_PUBLIC(void) update_model_description(s_surf_model_description_t *table,
55 XBT_PUBLIC(int) find_model_description(s_surf_model_description_t *table,
59 /** \brief Action structure
60 * \ingroup SURF_actions
62 * Never create s_surf_action_t by yourself ! The actions are created
63 * on the fly when you call execute or communicate on a model.
65 * \see e_surf_action_state_t
67 typedef struct surf_action {
68 s_xbt_swag_hookup_t state_hookup;
70 double cost; /**< cost */
71 double priority; /**< priority (1.0 by default) */
72 double max_duration; /**< max_duration (may fluctuate until
73 the task is completed) */
74 double remains; /**< How much of that cost remains to
75 * be done in the currently running task */
76 double start; /**< start time */
77 double finish; /**< finish time : this is modified during the run
78 * and fluctuates until the task is completed */
79 void *data; /**< for your convenience */
81 surf_model_t model_type;
84 /** \brief Action states
85 * \ingroup SURF_actions
89 * \see surf_action_t, surf_action_state_t
92 SURF_ACTION_READY = 0, /**< Ready */
93 SURF_ACTION_RUNNING, /**< Running */
94 SURF_ACTION_FAILED, /**< Task Failure */
95 SURF_ACTION_DONE, /**< Completed */
96 SURF_ACTION_TO_FREE, /**< Action to free in next cleanup */
97 SURF_ACTION_NOT_IN_THE_SYSTEM /**< Not in the system anymore. Why did you ask ? */
98 } e_surf_action_state_t;
100 /** \brief Action state sets
101 * \ingroup SURF_actions
103 * This structure contains some sets of actions.
104 * It provides a fast access to the actions in each state.
106 * \see surf_action_t, e_surf_action_state_t
108 typedef struct surf_action_state {
109 xbt_swag_t ready_action_set; /**< Actions in state SURF_ACTION_READY */
110 xbt_swag_t running_action_set; /**< Actions in state SURF_ACTION_RUNNING */
111 xbt_swag_t failed_action_set; /**< Actions in state SURF_ACTION_FAILED */
112 xbt_swag_t done_action_set; /**< Actions in state SURF_ACTION_DONE */
113 } s_surf_action_state_t, *surf_action_state_t;
115 /***************************/
116 /* Generic model object */
117 /***************************/
119 /** \brief Public data available on all models
120 * \ingroup SURF_models
122 * These functions are implemented by all models.
124 typedef struct surf_model_public {
125 s_surf_action_state_t states; /**< Any living action on this model */
126 void *(*name_service) (const char *name); /**< Return a model given its name */
127 const char *(*get_resource_name) (void *resource_id); /**< Return the name of a resource */
129 e_surf_action_state_t(*action_get_state) (surf_action_t action); /**< Return the state of an action */
130 double (*action_get_start_time) (surf_action_t action); /**< Return the start time of an action */
131 double (*action_get_finish_time) (surf_action_t action); /**< Return the finish time of an action */
132 void (*action_use) (surf_action_t action); /**< Set an action used */
133 int (*action_free) (surf_action_t action); /**< Free an action */
134 void (*action_cancel) (surf_action_t action); /**< Cancel a running action */
135 void (*action_recycle) (surf_action_t action); /**< Recycle an action */
136 void (*action_change_state) (surf_action_t action, /**< Change an action state*/
137 e_surf_action_state_t state);
138 void (*action_set_data) (surf_action_t action, void *data); /**< Set the user data of an action */
139 void (*suspend) (surf_action_t action); /**< Suspend an action */
140 void (*resume) (surf_action_t action); /**< Resume a suspended action */
141 int (*is_suspended) (surf_action_t action); /**< Return whether an action is suspended */
142 void (*set_max_duration) (surf_action_t action, double duration); /**< Set the max duration of an action*/
143 void (*set_priority) (surf_action_t action, double priority); /**< Set the priority of an action */
144 const char *name; /**< Name of this model */
146 xbt_dict_t (*get_properties) (void* link); /**< Return the properties dictionary */
148 } s_surf_model_public_t, *surf_model_public_t;
150 /** \brief Private data available on all models
151 * \ingroup SURF_models
153 typedef struct surf_model_private *surf_model_private_t;
155 /** \brief Resource datatype
156 * \ingroup SURF_models
158 * Generic data structure for a model. The workstations,
159 * the CPUs and the network links are examples of models.
161 typedef struct surf_model {
162 surf_model_private_t common_private;
163 surf_model_public_t common_public;
166 /**************************************/
167 /* Implementations of model object */
168 /**************************************/
170 /** \brief Timer model extension public
171 * \ingroup SURF_model
173 * Additionnal functions specific to the timer model
175 typedef struct surf_timer_model_extension_public {
176 void (*set) (double date, void *function, void *arg);
177 int (*get) (void **function, void **arg);
178 } s_surf_timer_model_extension_public_t,
179 *surf_timer_model_extension_public_t;
181 /** \brief Timer model
182 * \ingroup SURF_models
184 typedef struct surf_timer_model {
185 surf_model_private_t common_private;
186 surf_model_public_t common_public;
187 surf_timer_model_extension_public_t extension_public;
188 } s_surf_timer_model_t, *surf_timer_model_t;
190 /** \brief The timer model
191 * \ingroup SURF_models
193 XBT_PUBLIC_DATA(surf_timer_model_t) surf_timer_model;
195 /** \brief Initializes the timer model
196 * \ingroup SURF_models
198 XBT_PUBLIC(void) surf_timer_model_init(const char *filename);
203 * \ingroup SURF_models
206 SURF_CPU_ON = 1, /**< Up & ready */
207 SURF_CPU_OFF = 0 /**< Down & broken */
208 } e_surf_cpu_state_t;
210 /** \brief CPU model extension public
211 * \ingroup SURF_models
213 * Public functions specific to the CPU model.
215 typedef struct surf_cpu_model_extension_public {
216 surf_action_t(*execute) (void *cpu, double size);
217 surf_action_t(*sleep) (void *cpu, double duration);
218 e_surf_cpu_state_t(*get_state) (void *cpu);
219 double (*get_speed) (void *cpu, double load);
220 double (*get_available_speed) (void *cpu);
221 } s_surf_cpu_model_extension_public_t,
222 *surf_cpu_model_extension_public_t;
224 /** \brief CPU model datatype
225 * \ingroup SURF_models
227 typedef struct surf_cpu_model {
228 surf_model_private_t common_private;
229 surf_model_public_t common_public;
230 surf_cpu_model_extension_public_t extension_public;
231 } s_surf_cpu_model_t, *surf_cpu_model_t;
233 /** \brief The CPU model
234 * \ingroup SURF_models
236 XBT_PUBLIC_DATA(surf_cpu_model_t) surf_cpu_model;
238 /** \brief Initializes the CPU model with the model Cas01
239 * \ingroup SURF_models
241 * This function is called by surf_workstation_model_init_CLM03
242 * so you shouldn't have to call it by yourself.
244 * \see surf_workstation_model_init_CLM03()
246 XBT_PUBLIC(void) surf_cpu_model_init_Cas01(const char *filename);
248 XBT_PUBLIC_DATA(int) surf_cpu_model_description_size;
249 /** \brief The list of all available cpu model models
250 * \ingroup SURF_models
252 XBT_PUBLIC_DATA(s_surf_model_description_t) surf_cpu_model_description[];
256 /** \brief Network model extension public
257 * \ingroup SURF_models
259 * Public functions specific to the network model
261 typedef struct surf_network_model_extension_public {
262 surf_action_t(*communicate) (void *src, void *dst, double size,
264 const void** (*get_route) (void *src, void *dst);
265 int (*get_route_size) (void *src, void *dst);
266 const char* (*get_link_name) (const void *link);
267 double (*get_link_bandwidth) (const void *link);
268 double (*get_link_latency) (const void *link);
269 } s_surf_network_model_extension_public_t,
270 *surf_network_model_extension_public_t;
272 /** \brief Network model datatype
273 * \ingroup SURF_models
275 typedef struct surf_network_model {
276 surf_model_private_t common_private;
277 surf_model_public_t common_public;
278 surf_network_model_extension_public_t extension_public;
279 } s_surf_network_model_t, *surf_network_model_t;
281 XBT_PUBLIC(void) create_workstations(void);
283 /** \brief The network model
284 * \ingroup SURF_models
286 * When creating a new API on top on SURF, you shouldn't use the
287 * network model unless you know what you are doing. Only the workstation
288 * model should be accessed because depending on the platform model,
289 * the network model can be NULL.
291 XBT_PUBLIC_DATA(surf_network_model_t) surf_network_model;
293 /** \brief Initializes the platform with the network model CM02
294 * \ingroup SURF_models
295 * \param filename XML platform file name
297 * This function is called by surf_workstation_model_init_CLM03
298 * or by yourself only if you plan using surf_workstation_model_init_compound
300 * \see surf_workstation_model_init_CLM03()
302 XBT_PUBLIC(void) surf_network_model_init_CM02(const char *filename);
305 /** \brief Initializes the platform with the network model GTNETS
306 * \ingroup SURF_models
307 * \param filename XML platform file name
309 * This function is called by surf_workstation_model_init_GTNETS
310 * or by yourself only if you plan using surf_workstation_model_init_compound
312 * \see surf_workstation_model_init_GTNETS()
314 XBT_PUBLIC(void) surf_network_model_init_GTNETS(const char *filename);
317 /** \brief Initializes the platform with the network model Reno
318 * \ingroup SURF_models
319 * \param filename XML platform file name
321 * The problem is related to max( sum( arctan(C * Df * xi) ) ).
324 * [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
325 * IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
327 * Call this function only if you plan using surf_workstation_model_init_compound.
330 XBT_PUBLIC(void) surf_network_model_init_Reno(const char *filename);
332 /** \brief Initializes the platform with the network model Vegas
333 * \ingroup SURF_models
334 * \param filename XML platform file name
336 * This problem is related to max( sum( a * Df * ln(xi) ) ) which is equivalent
337 * to the proportional fairness.
340 * [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
341 * IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
343 * Call this function only if you plan using surf_workstation_model_init_compound.
346 XBT_PUBLIC(void) surf_network_model_init_Vegas(const char *filename);
349 /** \brief Initializes the platform with the network model based on SDP
350 * \ingroup SURF_models
351 * \param filename XML platform file name
353 * This function implements the proportional fairness known as the maximization
358 * [TAG03]. Corinne Touati, Eitan Altman, and Jérôme Galtier.
359 * Semi-definite programming approach for bandwidth allocation and routing in networks.
360 * Game Theory and Applications, 9:169-179, December 2003. Nova publisher.
362 * Call this function only if you plan using surf_workstation_model_init_compound.
364 XBT_PUBLIC(void) surf_network_model_init_SDP(const char *filename);
369 XBT_PUBLIC_DATA(int) surf_network_model_description_size;
370 /** \brief The list of all available network model models
371 * \ingroup SURF_models
373 XBT_PUBLIC_DATA(s_surf_model_description_t) surf_network_model_description[];
375 /** \brief Workstation model extension public
376 * \ingroup SURF_models
378 * Public functions specific to the workstation model.
380 typedef struct surf_workstation_model_extension_public {
381 surf_action_t(*execute) (void *workstation, double size); /**< Execute a computation amount on a workstation
382 and create the corresponding action */
383 surf_action_t(*sleep) (void *workstation, double duration); /**< Make a workstation sleep during a given duration */
384 e_surf_cpu_state_t(*get_state) (void *workstation); /**< Return the CPU state of a workstation */
385 double (*get_speed) (void *workstation, double load); /**< Return the speed of a workstation */
386 double (*get_available_speed) (void *workstation); /**< Return tha available speed of a workstation */
387 surf_action_t(*communicate) (void *workstation_src, /**< Execute a communication amount between two workstations */
388 void *workstation_dst, double size,
391 surf_action_t(*execute_parallel_task) (int workstation_nb, /**< Execute a parallel task on several workstations */
392 void **workstation_list,
393 double *computation_amount,
394 double *communication_amount,
397 const void** (*get_route) (void *src, void *dst); /**< Return the network link list between two workstations */
398 int (*get_route_size) (void *src, void *dst); /**< Return the route size between two workstations */
399 const char* (*get_link_name) (const void *link); /**< Return the name of a network link */
400 double (*get_link_bandwidth) (const void *link); /**< Return the current bandwidth of a network link */
401 double (*get_link_latency) (const void *link); /**< Return the current latency of a network link */
402 } s_surf_workstation_model_extension_public_t,
403 *surf_workstation_model_extension_public_t;
405 /** \brief Workstation model datatype.
406 * \ingroup SURF_models
409 typedef struct surf_workstation_model {
410 surf_model_private_t common_private;
411 surf_model_public_t common_public;
412 surf_workstation_model_extension_public_t extension_public;
413 } s_surf_workstation_model_t, *surf_workstation_model_t;
415 /** \brief The workstation model
416 * \ingroup SURF_models
418 * Note that when you create an API on top of SURF,
419 * the workstation model should be the only one you use
420 * because depending on the platform model, the network model and the CPU model
423 XBT_PUBLIC_DATA(surf_workstation_model_t) surf_workstation_model;
425 /** \brief Initializes the platform with a compound workstation model
426 * \ingroup SURF_models
427 * \param filename XML platform file name
429 * This function should be called after a cpu_model and a
430 * network_model have been set up.
433 XBT_PUBLIC(void) surf_workstation_model_init_compound(const char *filename);
435 /** \brief Initializes the platform with the workstation model CLM03
436 * \ingroup SURF_models
437 * \param filename XML platform file name
439 * This platform model seperates the workstation model and the network model.
440 * The workstation model will be initialized with the model CLM03, the network
441 * model with the model CM02 and the CPU model with the model Cas01.
442 * In future releases, some other network models will be implemented and will be
443 * combined with the workstation model CLM03.
445 * \see surf_workstation_model_init_KCCFLN05()
447 XBT_PUBLIC(void) surf_workstation_model_init_CLM03(const char *filename);
449 /** \brief Initializes the platform with the model KCCFLN05
450 * \ingroup SURF_models
451 * \param filename XML platform file name
453 * With this model, the workstations and the network are handled
454 * together. The network model is roughly the same as in CM02 but
455 * interference between computations and communications can be taken
456 * into account. This platform model is the default one for MSG and
460 XBT_PUBLIC(void) surf_workstation_model_init_KCCFLN05(const char *filename);
462 /** \brief Initializes the platform with the model KCCFLN05
463 * \ingroup SURF_models
464 * \param filename XML platform file name
466 * With this model, only parallel tasks can be used. Resource sharing
467 * is done by identifying bottlenecks and giving an equal share of
468 * the model to each action.
471 XBT_PUBLIC(void) surf_workstation_model_init_ptask_L07(const char *filename);
473 XBT_PUBLIC_DATA(int) surf_workstation_model_description_size;
474 /** \brief The list of all available workstation model models
475 * \ingroup SURF_models
477 XBT_PUBLIC_DATA(s_surf_model_description_t) surf_workstation_model_description[];
479 /** \brief The network links
480 * \ingroup SURF_models
482 * This dict contains all network links.
484 * \see workstation_set
486 XBT_PUBLIC_DATA(xbt_dict_t) link_set;
488 /** \brief The workstations
489 * \ingroup SURF_models
491 * This dict contains all workstations.
495 XBT_PUBLIC_DATA(xbt_dict_t) workstation_set;
496 XBT_PUBLIC_DATA(xbt_dict_t) cpu_set;
497 /** \brief List of initialized models
498 * \ingroup SURF_models
500 XBT_PUBLIC_DATA(xbt_dynar_t) model_list;
502 /*******************************************/
503 /*** SURF Globals **************************/
504 /*******************************************/
506 /** \brief Initialize SURF
507 * \ingroup SURF_simulation
508 * \param argc argument number
509 * \param argv arguments
511 * This function has to be called to initialize the common
512 * structures. Then you will have to create the environment by
513 * calling surf_timer_model_init() and
514 * e.g. surf_workstation_model_init_CLM03() or
515 * surf_workstation_model_init_KCCFLN05().
517 * \see surf_timer_model_init(), surf_workstation_model_init_CLM03(),
518 * surf_workstation_model_init_KCCFLN05(), surf_workstation_model_init_compound(), surf_exit()
520 XBT_PUBLIC(void) surf_init(int *argc, char **argv); /* initialize common structures */
522 /** \brief Performs a part of the simulation
523 * \ingroup SURF_simulation
524 * \return the elapsed time, or -1.0 if no event could be executed
526 * This function execute all possible events, update the action states
527 * and returns the time elapsed.
528 * When you call execute or communicate on a model, the corresponding actions
529 * are not executed immediately but only when you call surf_solve.
530 * Note that the returned elapsed time can be zero.
532 XBT_PUBLIC(double) surf_solve(void);
534 /** \brief Return the current time
535 * \ingroup SURF_simulation
537 * Return the current time in millisecond.
539 XBT_PUBLIC(double)surf_get_clock(void);
542 * \ingroup SURF_simulation
548 XBT_PUBLIC(void) surf_exit(void);
550 /* Prototypes of the functions that handle the properties */
551 XBT_PUBLIC_DATA(xbt_dict_t) current_property_set; /* the prop set for the currently parsed element (also used in SIMIX) */
552 void parse_properties(void);
553 void free_string(void*);
555 /* Prototypes for functions handling routing and were factorized succesfully from the models */
556 void init_data(void);
557 void parse_route_elem(void);
559 /* surf parse file related */
560 void parse_platform_file(const char* file);
562 /* Stores the sets */
563 XBT_PUBLIC_DATA(xbt_dict_t) set_list;
565 void parse_foreach(void);
566 void parse_sets(void);
567 void parse_route_multi_set_endpoints(void);
568 void parse_route_multi_set_route(void);
569 void parse_cluster(void);
570 void parse_trace_init(void);
571 void parse_trace_finalize(void);
572 void parse_trace_c_connect(void);
574 void manage_route(xbt_dict_t route_table, const char* route_name, int action, int isMultiRoute);
575 XBT_PUBLIC_DATA(int) route_action;
577 /* This is used by all models when creating the routing table while parsing */
578 XBT_PUBLIC_DATA(xbt_dict_t) route_table;
579 XBT_PUBLIC_DATA(xbt_dict_t) route_multi_table;
580 XBT_PUBLIC_DATA(xbt_dict_t) route_table;
581 XBT_PUBLIC_DATA(xbt_dict_t) route_multi_table;
582 XBT_PUBLIC_DATA(xbt_dynar_t) route_link_list;
584 /* For the trace and trace:connect tag */
585 XBT_PUBLIC_DATA(xbt_dict_t) traces_set_list;
586 XBT_PUBLIC_DATA(xbt_dynar_t) traces_connect_list;
588 double get_cpu_power(const char* power);
589 void init_randomness(void);
590 void add_randomness(void);
594 #endif /* _SURF_SURF_H */