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"
20 /* Actions and models are higly connected structures... */
22 /** \brief Action datatype
23 * \ingroup SURF_actions
25 * An action is some working amount on a model.
26 * It is represented as a cost, a priority, a duration and a state.
28 * \see e_surf_action_state_t
30 typedef struct surf_action *surf_action_t;
32 /** \brief Resource datatype
33 * \ingroup SURF_models
35 * Generic data structure for a model. The workstations,
36 * the CPUs and the network links are examples of models.
38 typedef struct surf_model *surf_model_t;
40 /** \brief Resource model description
42 typedef struct surf_model_description {
45 void (* model_init) (const char *filename);
46 void (* create_ws) (void);
47 } s_surf_model_description_t, *surf_model_description_t;
49 XBT_PUBLIC(void) update_model_description(s_surf_model_description_t *table,
53 XBT_PUBLIC(int) find_model_description(s_surf_model_description_t *table,
56 /** \brief Action structure
57 * \ingroup SURF_actions
59 * Never create s_surf_action_t by yourself ! The actions are created
60 * on the fly when you call execute or communicate on a model.
62 * \see e_surf_action_state_t
64 typedef struct surf_action {
65 s_xbt_swag_hookup_t state_hookup;
67 double cost; /**< cost */
68 double priority; /**< priority (1.0 by default) */
69 double max_duration; /**< max_duration (may fluctuate until
70 the task is completed) */
71 double remains; /**< How much of that cost remains to
72 * be done in the currently running task */
73 double start; /**< start time */
74 double finish; /**< finish time : this is modified during the run
75 * and fluctuates until the task is completed */
76 void *data; /**< for your convenience */
78 surf_model_t model_type;
81 /** \brief Action states
82 * \ingroup SURF_actions
86 * \see surf_action_t, surf_action_state_t
89 SURF_ACTION_READY = 0, /**< Ready */
90 SURF_ACTION_RUNNING, /**< Running */
91 SURF_ACTION_FAILED, /**< Task Failure */
92 SURF_ACTION_DONE, /**< Completed */
93 SURF_ACTION_TO_FREE, /**< Action to free in next cleanup */
94 SURF_ACTION_NOT_IN_THE_SYSTEM /**< Not in the system anymore. Why did you ask ? */
95 } e_surf_action_state_t;
97 /** \brief Action state sets
98 * \ingroup SURF_actions
100 * This structure contains some sets of actions.
101 * It provides a fast access to the actions in each state.
103 * \see surf_action_t, e_surf_action_state_t
105 typedef struct surf_action_state {
106 xbt_swag_t ready_action_set; /**< Actions in state SURF_ACTION_READY */
107 xbt_swag_t running_action_set; /**< Actions in state SURF_ACTION_RUNNING */
108 xbt_swag_t failed_action_set; /**< Actions in state SURF_ACTION_FAILED */
109 xbt_swag_t done_action_set; /**< Actions in state SURF_ACTION_DONE */
110 } s_surf_action_state_t, *surf_action_state_t;
112 /***************************/
113 /* Generic model object */
114 /***************************/
116 /** \brief Public data available on all models
117 * \ingroup SURF_models
119 * These functions are implemented by all models.
121 typedef struct surf_model_public {
122 s_surf_action_state_t states; /**< Any living action on this model */
123 void *(*name_service) (const char *name); /**< Return a model given its name */
124 const char *(*get_resource_name) (void *resource_id); /**< Return the name of a resource */
126 e_surf_action_state_t(*action_get_state) (surf_action_t action); /**< Return the state of an action */
127 double (*action_get_start_time) (surf_action_t action); /**< Return the start time of an action */
128 double (*action_get_finish_time) (surf_action_t action); /**< Return the finish time of an action */
129 void (*action_use) (surf_action_t action); /**< Set an action used */
130 int (*action_free) (surf_action_t action); /**< Free an action */
131 void (*action_cancel) (surf_action_t action); /**< Cancel a running action */
132 void (*action_recycle) (surf_action_t action); /**< Recycle an action */
133 void (*action_change_state) (surf_action_t action, /**< Change an action state*/
134 e_surf_action_state_t state);
135 void (*action_set_data) (surf_action_t action, void *data); /**< Set the user data of an action */
136 void (*suspend) (surf_action_t action); /**< Suspend an action */
137 void (*resume) (surf_action_t action); /**< Resume a suspended action */
138 int (*is_suspended) (surf_action_t action); /**< Return whether an action is suspended */
139 void (*set_max_duration) (surf_action_t action, double duration); /**< Set the max duration of an action*/
140 void (*set_priority) (surf_action_t action, double priority); /**< Set the priority of an action */
141 xbt_dict_t (*get_properties) (void* resource_id); /**< Return the properties dictionary */
142 const char *name; /**< Name of this model */
143 } s_surf_model_public_t, *surf_model_public_t;
145 /** \brief Private data available on all models
146 * \ingroup SURF_models
148 typedef struct surf_model_private *surf_model_private_t;
150 /** \brief Resource datatype
151 * \ingroup SURF_models
153 * Generic data structure for a model. The workstations,
154 * the CPUs and the network links are examples of models.
156 typedef struct surf_model {
157 surf_model_private_t common_private;
158 surf_model_public_t common_public;
161 /**************************************/
162 /* Implementations of model object */
163 /**************************************/
165 /** \brief Timer model extension public
166 * \ingroup SURF_model
168 * Additionnal functions specific to the timer model
170 typedef struct surf_timer_model_extension_public {
171 void (*set) (double date, void *function, void *arg);
172 int (*get) (void **function, void **arg);
173 } s_surf_timer_model_extension_public_t,
174 *surf_timer_model_extension_public_t;
176 /** \brief Timer model
177 * \ingroup SURF_models
179 typedef struct surf_timer_model {
180 surf_model_private_t common_private;
181 surf_model_public_t common_public;
182 surf_timer_model_extension_public_t extension_public;
183 } s_surf_timer_model_t, *surf_timer_model_t;
185 /** \brief The timer model
186 * \ingroup SURF_models
188 XBT_PUBLIC_DATA(surf_timer_model_t) surf_timer_model;
190 /** \brief Initializes the timer model
191 * \ingroup SURF_models
193 XBT_PUBLIC(void) surf_timer_model_init(const char *filename);
198 * \ingroup SURF_models
201 SURF_CPU_ON = 1, /**< Up & ready */
202 SURF_CPU_OFF = 0 /**< Down & broken */
203 } e_surf_cpu_state_t;
205 /** \brief CPU model extension public
206 * \ingroup SURF_models
208 * Public functions specific to the CPU model.
210 typedef struct surf_cpu_model_extension_public {
211 surf_action_t(*execute) (void *cpu, double size);
212 surf_action_t(*sleep) (void *cpu, double duration);
213 e_surf_cpu_state_t(*get_state) (void *cpu);
214 double (*get_speed) (void *cpu, double load);
215 double (*get_available_speed) (void *cpu);
216 } s_surf_cpu_model_extension_public_t,
217 *surf_cpu_model_extension_public_t;
219 /** \brief CPU model datatype
220 * \ingroup SURF_models
222 typedef struct surf_cpu_model {
223 surf_model_private_t common_private;
224 surf_model_public_t common_public;
225 surf_cpu_model_extension_public_t extension_public;
226 } s_surf_cpu_model_t, *surf_cpu_model_t;
228 /** \brief The CPU model
229 * \ingroup SURF_models
231 XBT_PUBLIC_DATA(surf_cpu_model_t) surf_cpu_model;
233 /** \brief Initializes the CPU model with the model Cas01
234 * \ingroup SURF_models
236 * This function is called by surf_workstation_model_init_CLM03
237 * so you shouldn't have to call it by yourself.
239 * \see surf_workstation_model_init_CLM03()
241 XBT_PUBLIC(void) surf_cpu_model_init_Cas01(const char *filename);
243 /** \brief The list of all available cpu model models
244 * \ingroup SURF_models
246 XBT_PUBLIC_DATA(s_surf_model_description_t) surf_cpu_model_description[];
250 /** \brief Network model extension public
251 * \ingroup SURF_models
253 * Public functions specific to the network model
255 typedef struct surf_network_model_extension_public {
256 surf_action_t(*communicate) (void *src, void *dst, double size,
258 const void** (*get_route) (void *src, void *dst);
259 int (*get_route_size) (void *src, void *dst);
260 const char* (*get_link_name) (const void *link);
261 double (*get_link_bandwidth) (const void *link);
262 double (*get_link_latency) (const void *link);
263 } s_surf_network_model_extension_public_t,
264 *surf_network_model_extension_public_t;
266 /** \brief Network model datatype
267 * \ingroup SURF_models
269 typedef struct surf_network_model {
270 surf_model_private_t common_private;
271 surf_model_public_t common_public;
272 surf_network_model_extension_public_t extension_public;
273 } s_surf_network_model_t, *surf_network_model_t;
275 XBT_PUBLIC(void) create_workstations(void);
277 /** \brief The network model
278 * \ingroup SURF_models
280 * When creating a new API on top on SURF, you shouldn't use the
281 * network model unless you know what you are doing. Only the workstation
282 * model should be accessed because depending on the platform model,
283 * the network model can be NULL.
285 XBT_PUBLIC_DATA(surf_network_model_t) surf_network_model;
288 /** \brief Initializes the platform with the network model 'Constant'
289 * \ingroup SURF_models
290 * \param filename XML platform file name
292 * In this model, the communication time between two network cards is
293 * constant, hence no need for a routing table. This is particularly
294 * usefull when simulating huge distributed algorithms where
295 * scalability is really an issue. This function is called in
296 * conjunction with surf_workstation_model_init_compound.
298 * \see surf_workstation_model_init_compound()
300 XBT_PUBLIC(void) surf_network_model_init_Constant(const char *filename);
302 /** \brief Initializes the platform with the network model CM02
303 * \ingroup SURF_models
304 * \param filename XML platform file name
306 * This function is called by surf_workstation_model_init_CLM03
307 * or by yourself only if you plan using surf_workstation_model_init_compound
309 * \see surf_workstation_model_init_CLM03()
311 XBT_PUBLIC(void) surf_network_model_init_CM02(const char *filename);
314 /** \brief Initializes the platform with the network model GTNETS
315 * \ingroup SURF_models
316 * \param filename XML platform file name
318 * This function is called by surf_workstation_model_init_GTNETS
319 * or by yourself only if you plan using surf_workstation_model_init_compound
321 * \see surf_workstation_model_init_GTNETS()
323 XBT_PUBLIC(void) surf_network_model_init_GTNETS(const char *filename);
326 /** \brief Initializes the platform with the network model Reno
327 * \ingroup SURF_models
328 * \param filename XML platform file name
330 * The problem is related to max( sum( arctan(C * Df * xi) ) ).
333 * [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
334 * IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
336 * Call this function only if you plan using surf_workstation_model_init_compound.
339 XBT_PUBLIC(void) surf_network_model_init_Reno(const char *filename);
341 /** \brief Initializes the platform with the network model Reno2
342 * \ingroup SURF_models
343 * \param filename XML platform file name
345 * The problem is related to max( sum( arctan(C * Df * xi) ) ).
348 * [LOW01] S. H. Low. A duality model of TCP and queue management algorithms.
349 * IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
351 * Call this function only if you plan using surf_workstation_model_init_compound.
354 XBT_PUBLIC(void) surf_network_model_init_Reno2(const char *filename);
356 /** \brief Initializes the platform with the network model Vegas
357 * \ingroup SURF_models
358 * \param filename XML platform file name
360 * This problem is related to max( sum( a * Df * ln(xi) ) ) which is equivalent
361 * to the proportional fairness.
364 * [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
365 * IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
367 * Call this function only if you plan using surf_workstation_model_init_compound.
370 XBT_PUBLIC(void) surf_network_model_init_Vegas(const char *filename);
373 /** \brief Initializes the platform with the network model based on SDP
374 * \ingroup SURF_models
375 * \param filename XML platform file name
377 * This function implements the proportional fairness known as the maximization
382 * [TAG03]. Corinne Touati, Eitan Altman, and Jerome Galtier.
383 * Semi-definite programming approach for bandwidth allocation and routing in networks.
384 * Game Theory and Applications, 9:169-179, December 2003. Nova publisher.
386 * Call this function only if you plan using surf_workstation_model_init_compound.
388 XBT_PUBLIC(void) surf_network_model_init_SDP(const char *filename);
391 /** \brief The list of all available network model models
392 * \ingroup SURF_models
394 XBT_PUBLIC_DATA(s_surf_model_description_t) surf_network_model_description[];
396 /** \brief Workstation model extension public
397 * \ingroup SURF_models
399 * Public functions specific to the workstation model.
401 typedef struct surf_workstation_model_extension_public {
402 surf_action_t(*execute) (void *workstation, double size); /**< Execute a computation amount on a workstation
403 and create the corresponding action */
404 surf_action_t(*sleep) (void *workstation, double duration); /**< Make a workstation sleep during a given duration */
405 e_surf_cpu_state_t(*get_state) (void *workstation); /**< Return the CPU state of a workstation */
406 double (*get_speed) (void *workstation, double load); /**< Return the speed of a workstation */
407 double (*get_available_speed) (void *workstation); /**< Return tha available speed of a workstation */
408 surf_action_t(*communicate) (void *workstation_src, /**< Execute a communication amount between two workstations */
409 void *workstation_dst, double size,
412 surf_action_t(*execute_parallel_task) (int workstation_nb, /**< Execute a parallel task on several workstations */
413 void **workstation_list,
414 double *computation_amount,
415 double *communication_amount,
418 const void** (*get_route) (void *src, void *dst); /**< Return the network link list between two workstations */
419 int (*get_route_size) (void *src, void *dst); /**< Return the route size between two workstations */
420 const char* (*get_link_name) (const void *link); /**< Return the name of a network link */
421 double (*get_link_bandwidth) (const void *link); /**< Return the current bandwidth of a network link */
422 double (*get_link_latency) (const void *link); /**< Return the current latency of a network link */
423 } s_surf_workstation_model_extension_public_t,
424 *surf_workstation_model_extension_public_t;
426 /** \brief Workstation model datatype.
427 * \ingroup SURF_models
430 typedef struct surf_workstation_model {
431 surf_model_private_t common_private;
432 surf_model_public_t common_public;
433 surf_workstation_model_extension_public_t extension_public;
434 } s_surf_workstation_model_t, *surf_workstation_model_t;
436 /** \brief The workstation model
437 * \ingroup SURF_models
439 * Note that when you create an API on top of SURF,
440 * the workstation model should be the only one you use
441 * because depending on the platform model, the network model and the CPU model
444 XBT_PUBLIC_DATA(surf_workstation_model_t) surf_workstation_model;
446 /** \brief Initializes the platform with a compound workstation model
447 * \ingroup SURF_models
448 * \param filename XML platform file name
450 * This function should be called after a cpu_model and a
451 * network_model have been set up.
454 XBT_PUBLIC(void) surf_workstation_model_init_compound(const char *filename);
456 /** \brief Initializes the platform with the workstation model CLM03
457 * \ingroup SURF_models
458 * \param filename XML platform file name
460 * This platform model seperates the workstation model and the network model.
461 * The workstation model will be initialized with the model CLM03, the network
462 * model with the model CM02 and the CPU model with the model Cas01.
463 * In future releases, some other network models will be implemented and will be
464 * combined with the workstation model CLM03.
466 * \see surf_workstation_model_init_KCCFLN05()
468 XBT_PUBLIC(void) surf_workstation_model_init_CLM03(const char *filename);
470 /** \brief Initializes the platform with the model KCCFLN05
471 * \ingroup SURF_models
472 * \param filename XML platform file name
474 * With this model, the workstations and the network are handled
475 * together. The network model is roughly the same as in CM02 but
476 * interference between computations and communications can be taken
477 * into account. This platform model is the default one for MSG and
481 XBT_PUBLIC(void) surf_workstation_model_init_KCCFLN05(const char *filename);
483 /** \brief Initializes the platform with the model KCCFLN05
484 * \ingroup SURF_models
485 * \param filename XML platform file name
487 * With this model, only parallel tasks can be used. Resource sharing
488 * is done by identifying bottlenecks and giving an equal share of
489 * the model to each action.
492 XBT_PUBLIC(void) surf_workstation_model_init_ptask_L07(const char *filename);
494 /** \brief The list of all available workstation model models
495 * \ingroup SURF_models
497 XBT_PUBLIC_DATA(s_surf_model_description_t) surf_workstation_model_description[];
499 /** \brief The network links
500 * \ingroup SURF_models
502 * This dict contains all network links.
504 * \see workstation_set
506 XBT_PUBLIC_DATA(xbt_dict_t) link_set;
508 /** \brief The workstations
509 * \ingroup SURF_models
511 * This dict contains all workstations.
515 XBT_PUBLIC_DATA(xbt_dict_t) workstation_set;
516 XBT_PUBLIC_DATA(xbt_dict_t) cpu_set;
517 /** \brief List of initialized models
518 * \ingroup SURF_models
520 XBT_PUBLIC_DATA(xbt_dynar_t) model_list;
522 /*******************************************/
523 /*** SURF Globals **************************/
524 /*******************************************/
526 /** \brief Initialize SURF
527 * \ingroup SURF_simulation
528 * \param argc argument number
529 * \param argv arguments
531 * This function has to be called to initialize the common
532 * structures. Then you will have to create the environment by
533 * calling surf_timer_model_init() and
534 * e.g. surf_workstation_model_init_CLM03() or
535 * surf_workstation_model_init_KCCFLN05().
537 * \see surf_timer_model_init(), surf_workstation_model_init_CLM03(),
538 * surf_workstation_model_init_KCCFLN05(), surf_workstation_model_init_compound(), surf_exit()
540 XBT_PUBLIC(void) surf_init(int *argc, char **argv); /* initialize common structures */
542 /** \brief Finish simulation initialization
543 * \ingroup SURF_simulation
545 * This function must be called before the first call to surf_solve()
547 XBT_PUBLIC(void) surf_presolve(void);
549 /** \brief Performs a part of the simulation
550 * \ingroup SURF_simulation
551 * \return the elapsed time, or -1.0 if no event could be executed
553 * This function execute all possible events, update the action states
554 * and returns the time elapsed.
555 * When you call execute or communicate on a model, the corresponding actions
556 * are not executed immediately but only when you call surf_solve.
557 * Note that the returned elapsed time can be zero.
559 XBT_PUBLIC(double) surf_solve(void);
561 /** \brief Return the current time
562 * \ingroup SURF_simulation
564 * Return the current time in millisecond.
566 XBT_PUBLIC(double)surf_get_clock(void);
569 * \ingroup SURF_simulation
575 XBT_PUBLIC(void) surf_exit(void);
577 /* Prototypes of the functions that handle the properties */
578 XBT_PUBLIC_DATA(xbt_dict_t) current_property_set; /* the prop set for the currently parsed element (also used in SIMIX) */
579 XBT_PUBLIC_DATA(void) parse_properties(void);
581 /* surf parse file related (public because called from a test suite) */
582 XBT_PUBLIC(void) parse_platform_file(const char* file);
584 /* Stores the sets */
585 XBT_PUBLIC_DATA(xbt_dict_t) set_list;
587 XBT_PUBLIC_DATA(void) manage_route(xbt_dict_t route_table, const char* route_name, int action, int isMultiRoute);
588 XBT_PUBLIC_DATA(int) route_action;
590 /* This is used by all models when creating the routing table while parsing */
591 XBT_PUBLIC_DATA(xbt_dict_t) route_table;
592 XBT_PUBLIC_DATA(xbt_dict_t) route_multi_table;
593 XBT_PUBLIC_DATA(xbt_dict_t) route_multi_table;
595 /* For the trace and trace:connect tag (store their content till the end of the parsing) */
596 XBT_PUBLIC_DATA(xbt_dict_t) traces_set_list;
597 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_host_avail;
598 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_power;
599 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_link_avail;
600 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_bandwidth;
601 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_latency;
604 XBT_PUBLIC_DATA(double) get_cpu_power(const char* power);
609 #endif /* _SURF_SURF_H */