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. */
13 #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 #define surf_cpu_model_description_size 1
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[surf_cpu_model_description_size];
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;
294 /** \brief Initializes the platform with the network model 'Constant'
295 * \ingroup SURF_models
296 * \param filename XML platform file name
298 * In this model, the communication time between two network cards is
299 * constant, hence no need for a routing table. This is particularly
300 * usefull when simulating huge distributed algorithms where
301 * scalability is really an issue. This function is called in
302 * conjunction with surf_workstation_model_init_compound.
304 * \see surf_workstation_model_init_compound()
306 XBT_PUBLIC(void) surf_network_model_init_Constant(const char *filename);
308 /** \brief Initializes the platform with the network model CM02
309 * \ingroup SURF_models
310 * \param filename XML platform file name
312 * This function is called by surf_workstation_model_init_CLM03
313 * or by yourself only if you plan using surf_workstation_model_init_compound
315 * \see surf_workstation_model_init_CLM03()
317 XBT_PUBLIC(void) surf_network_model_init_CM02(const char *filename);
320 /** \brief Initializes the platform with the network model GTNETS
321 * \ingroup SURF_models
322 * \param filename XML platform file name
324 * This function is called by surf_workstation_model_init_GTNETS
325 * or by yourself only if you plan using surf_workstation_model_init_compound
327 * \see surf_workstation_model_init_GTNETS()
329 XBT_PUBLIC(void) surf_network_model_init_GTNETS(const char *filename);
332 /** \brief Initializes the platform with the network model Reno
333 * \ingroup SURF_models
334 * \param filename XML platform file name
336 * The problem is related to max( sum( arctan(C * Df * xi) ) ).
339 * [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
340 * IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
342 * Call this function only if you plan using surf_workstation_model_init_compound.
345 XBT_PUBLIC(void) surf_network_model_init_Reno(const char *filename);
347 /** \brief Initializes the platform with the network model Reno2
348 * \ingroup SURF_models
349 * \param filename XML platform file name
351 * The problem is related to max( sum( arctan(C * Df * xi) ) ).
354 * [LOW01] S. H. Low. A duality model of TCP and queue management algorithms.
355 * IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
357 * Call this function only if you plan using surf_workstation_model_init_compound.
360 XBT_PUBLIC(void) surf_network_model_init_Reno2(const char *filename);
362 /** \brief Initializes the platform with the network model Vegas
363 * \ingroup SURF_models
364 * \param filename XML platform file name
366 * This problem is related to max( sum( a * Df * ln(xi) ) ) which is equivalent
367 * to the proportional fairness.
370 * [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
371 * IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
373 * Call this function only if you plan using surf_workstation_model_init_compound.
376 XBT_PUBLIC(void) surf_network_model_init_Vegas(const char *filename);
379 /** \brief Initializes the platform with the network model based on SDP
380 * \ingroup SURF_models
381 * \param filename XML platform file name
383 * This function implements the proportional fairness known as the maximization
388 * [TAG03]. Corinne Touati, Eitan Altman, and Jerome Galtier.
389 * Semi-definite programming approach for bandwidth allocation and routing in networks.
390 * Game Theory and Applications, 9:169-179, December 2003. Nova publisher.
392 * Call this function only if you plan using surf_workstation_model_init_compound.
394 XBT_PUBLIC(void) surf_network_model_init_SDP(const char *filename);
408 #define surf_network_model_description_size 5+inc_SDP+inc_GT
410 /** \brief The list of all available network model models
411 * \ingroup SURF_models
413 XBT_PUBLIC_DATA(s_surf_model_description_t) surf_network_model_description[surf_network_model_description_size];
415 /** \brief Workstation model extension public
416 * \ingroup SURF_models
418 * Public functions specific to the workstation model.
420 typedef struct surf_workstation_model_extension_public {
421 surf_action_t(*execute) (void *workstation, double size); /**< Execute a computation amount on a workstation
422 and create the corresponding action */
423 surf_action_t(*sleep) (void *workstation, double duration); /**< Make a workstation sleep during a given duration */
424 e_surf_cpu_state_t(*get_state) (void *workstation); /**< Return the CPU state of a workstation */
425 double (*get_speed) (void *workstation, double load); /**< Return the speed of a workstation */
426 double (*get_available_speed) (void *workstation); /**< Return tha available speed of a workstation */
427 surf_action_t(*communicate) (void *workstation_src, /**< Execute a communication amount between two workstations */
428 void *workstation_dst, double size,
431 surf_action_t(*execute_parallel_task) (int workstation_nb, /**< Execute a parallel task on several workstations */
432 void **workstation_list,
433 double *computation_amount,
434 double *communication_amount,
437 const void** (*get_route) (void *src, void *dst); /**< Return the network link list between two workstations */
438 int (*get_route_size) (void *src, void *dst); /**< Return the route size between two workstations */
439 const char* (*get_link_name) (const void *link); /**< Return the name of a network link */
440 double (*get_link_bandwidth) (const void *link); /**< Return the current bandwidth of a network link */
441 double (*get_link_latency) (const void *link); /**< Return the current latency of a network link */
442 } s_surf_workstation_model_extension_public_t,
443 *surf_workstation_model_extension_public_t;
445 /** \brief Workstation model datatype.
446 * \ingroup SURF_models
449 typedef struct surf_workstation_model {
450 surf_model_private_t common_private;
451 surf_model_public_t common_public;
452 surf_workstation_model_extension_public_t extension_public;
453 } s_surf_workstation_model_t, *surf_workstation_model_t;
455 /** \brief The workstation model
456 * \ingroup SURF_models
458 * Note that when you create an API on top of SURF,
459 * the workstation model should be the only one you use
460 * because depending on the platform model, the network model and the CPU model
463 XBT_PUBLIC_DATA(surf_workstation_model_t) surf_workstation_model;
465 /** \brief Initializes the platform with a compound workstation model
466 * \ingroup SURF_models
467 * \param filename XML platform file name
469 * This function should be called after a cpu_model and a
470 * network_model have been set up.
473 XBT_PUBLIC(void) surf_workstation_model_init_compound(const char *filename);
475 /** \brief Initializes the platform with the workstation model CLM03
476 * \ingroup SURF_models
477 * \param filename XML platform file name
479 * This platform model seperates the workstation model and the network model.
480 * The workstation model will be initialized with the model CLM03, the network
481 * model with the model CM02 and the CPU model with the model Cas01.
482 * In future releases, some other network models will be implemented and will be
483 * combined with the workstation model CLM03.
485 * \see surf_workstation_model_init_KCCFLN05()
487 XBT_PUBLIC(void) surf_workstation_model_init_CLM03(const char *filename);
489 /** \brief Initializes the platform with the model KCCFLN05
490 * \ingroup SURF_models
491 * \param filename XML platform file name
493 * With this model, the workstations and the network are handled
494 * together. The network model is roughly the same as in CM02 but
495 * interference between computations and communications can be taken
496 * into account. This platform model is the default one for MSG and
500 XBT_PUBLIC(void) surf_workstation_model_init_KCCFLN05(const char *filename);
502 /** \brief Initializes the platform with the model KCCFLN05
503 * \ingroup SURF_models
504 * \param filename XML platform file name
506 * With this model, only parallel tasks can be used. Resource sharing
507 * is done by identifying bottlenecks and giving an equal share of
508 * the model to each action.
511 XBT_PUBLIC(void) surf_workstation_model_init_ptask_L07(const char *filename);
513 #define surf_workstation_model_description_size 4
514 /** \brief The list of all available workstation model models
515 * \ingroup SURF_models
517 XBT_PUBLIC_DATA(s_surf_model_description_t) surf_workstation_model_description[surf_workstation_model_description_size];
519 /** \brief The network links
520 * \ingroup SURF_models
522 * This dict contains all network links.
524 * \see workstation_set
526 XBT_PUBLIC_DATA(xbt_dict_t) link_set;
528 /** \brief The workstations
529 * \ingroup SURF_models
531 * This dict contains all workstations.
535 XBT_PUBLIC_DATA(xbt_dict_t) workstation_set;
536 XBT_PUBLIC_DATA(xbt_dict_t) cpu_set;
537 /** \brief List of initialized models
538 * \ingroup SURF_models
540 XBT_PUBLIC_DATA(xbt_dynar_t) model_list;
542 /*******************************************/
543 /*** SURF Globals **************************/
544 /*******************************************/
546 /** \brief Initialize SURF
547 * \ingroup SURF_simulation
548 * \param argc argument number
549 * \param argv arguments
551 * This function has to be called to initialize the common
552 * structures. Then you will have to create the environment by
553 * calling surf_timer_model_init() and
554 * e.g. surf_workstation_model_init_CLM03() or
555 * surf_workstation_model_init_KCCFLN05().
557 * \see surf_timer_model_init(), surf_workstation_model_init_CLM03(),
558 * surf_workstation_model_init_KCCFLN05(), surf_workstation_model_init_compound(), surf_exit()
560 XBT_PUBLIC(void) surf_init(int *argc, char **argv); /* initialize common structures */
562 /** \brief Finish simulation initialization
563 * \ingroup SURF_simulation
565 * This function must be called before the first call to surf_solve()
567 XBT_PUBLIC(void) surf_presolve(void);
569 /** \brief Performs a part of the simulation
570 * \ingroup SURF_simulation
571 * \return the elapsed time, or -1.0 if no event could be executed
573 * This function execute all possible events, update the action states
574 * and returns the time elapsed.
575 * When you call execute or communicate on a model, the corresponding actions
576 * are not executed immediately but only when you call surf_solve.
577 * Note that the returned elapsed time can be zero.
579 XBT_PUBLIC(double) surf_solve(void);
581 /** \brief Return the current time
582 * \ingroup SURF_simulation
584 * Return the current time in millisecond.
586 XBT_PUBLIC(double)surf_get_clock(void);
589 * \ingroup SURF_simulation
595 XBT_PUBLIC(void) surf_exit(void);
597 /* Prototypes of the functions that handle the properties */
598 XBT_PUBLIC_DATA(xbt_dict_t) current_property_set; /* the prop set for the currently parsed element (also used in SIMIX) */
599 void parse_properties(void);
601 /* Prototypes for functions handling routing and were factorized succesfully from the models */
602 void init_data(void);
603 void parse_route_elem(void);
605 /* surf parse file related (public because called from a test suite) */
606 XBT_PUBLIC(void) parse_platform_file(const char* file);
608 /* Stores the sets */
609 XBT_PUBLIC_DATA(xbt_dict_t) set_list;
611 void parse_foreach(void);
612 void parse_sets(void);
613 void parse_route_multi_set_endpoints(void);
614 void parse_route_multi_set_route(void);
615 void parse_cluster(void);
616 void parse_trace_init(void);
617 void parse_trace_finalize(void);
618 void parse_trace_c_connect(void);
620 void manage_route(xbt_dict_t route_table, const char* route_name, int action, int isMultiRoute);
621 XBT_PUBLIC_DATA(int) route_action;
623 /* This is used by all models when creating the routing table while parsing */
624 XBT_PUBLIC_DATA(xbt_dict_t) route_table;
625 XBT_PUBLIC_DATA(xbt_dict_t) route_multi_table;
626 XBT_PUBLIC_DATA(xbt_dict_t) route_table;
627 XBT_PUBLIC_DATA(xbt_dict_t) route_multi_table;
628 XBT_PUBLIC_DATA(xbt_dynar_t) route_link_list;
630 /* For the trace and trace:connect tag (store their content till the end of the parsing) */
631 XBT_PUBLIC_DATA(xbt_dict_t) traces_set_list;
632 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_host_avail;
633 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_power;
634 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_link_avail;
635 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_bandwidth;
636 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_latency;
639 double get_cpu_power(const char* power);
640 void init_randomness(void);
641 void add_randomness(void);
645 #endif /* _SURF_SURF_H */