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"
16 #include "xbt/config.h"
22 /* 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 Model 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,
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
95 /**< Not in the system anymore. Why did you ask ? */
96 } e_surf_action_state_t;
98 /** \brief Action state sets
99 * \ingroup SURF_actions
101 * This structure contains some sets of actions.
102 * It provides a fast access to the actions in each state.
104 * \see surf_action_t, e_surf_action_state_t
106 typedef struct surf_action_state {
107 xbt_swag_t ready_action_set;
108 /**< Actions in state SURF_ACTION_READY */
109 xbt_swag_t running_action_set;
110 /**< Actions in state SURF_ACTION_RUNNING */
111 xbt_swag_t failed_action_set;
112 /**< Actions in state SURF_ACTION_FAILED */
113 xbt_swag_t done_action_set;
114 /**< Actions in state SURF_ACTION_DONE */
115 } s_surf_action_state_t, *surf_action_state_t;
117 /***************************/
118 /* Generic model object */
119 /***************************/
121 /** \brief Public data available on all models
122 * \ingroup SURF_models
124 * These functions are implemented by all models.
126 typedef struct surf_model_public {
127 s_surf_action_state_t states;
128 /**< Any living action on this model */
129 void *(*name_service) (const char *name);
130 /**< Return a model given its name */
131 const char *(*get_resource_name) (void *resource_id);
132 /**< Return the name of a resource */
134 e_surf_action_state_t(*action_get_state) (surf_action_t action);
135 /**< Return the state of an action */
136 double (*action_get_start_time) (surf_action_t action);
137 /**< Return the start time of an action */
138 double (*action_get_finish_time) (surf_action_t action);
139 /**< Return the finish time of an action */
140 void (*action_use) (surf_action_t action);
141 /**< Set an action used */
142 int (*action_free) (surf_action_t action);
143 /**< Free an action */
144 void (*action_cancel) (surf_action_t action);
145 /**< Cancel a running action */
146 void (*action_recycle) (surf_action_t action);
147 /**< Recycle an action */
148 void (*action_change_state) (surf_action_t action,
149 /**< Change an action state*/
150 e_surf_action_state_t state);
151 void (*action_set_data) (surf_action_t action, void *data);
152 /**< Set the user data of an action */
153 void (*suspend) (surf_action_t action);
154 /**< Suspend an action */
155 void (*resume) (surf_action_t action);
156 /**< Resume a suspended action */
157 int (*is_suspended) (surf_action_t action);
158 /**< Return whether an action is suspended */
159 void (*set_max_duration) (surf_action_t action, double duration);
160 /**< Set the max duration of an action*/
161 void (*set_priority) (surf_action_t action, double priority);
162 /**< Set the priority of an action */
163 xbt_dict_t(*get_properties) (void *resource_id);
164 /**< Return the properties dictionary */
166 /**< Name of this model */
167 } s_surf_model_public_t, *surf_model_public_t;
169 /** \brief Private data available on all models
170 * \ingroup SURF_models
172 typedef struct surf_model_private *surf_model_private_t;
174 /** \brief Model datatype
175 * \ingroup SURF_models
177 * Generic data structure for a model. The workstations,
178 * the CPUs and the network links are examples of models.
180 typedef struct surf_model {
181 surf_model_private_t common_private;
182 surf_model_public_t common_public;
185 /**************************************/
186 /* Implementations of model object */
187 /**************************************/
189 /** \brief Timer model extension public
190 * \ingroup SURF_model
192 * Additionnal functions specific to the timer model
194 typedef struct surf_timer_model_extension_public {
195 void (*set) (double date, void *function, void *arg);
196 int (*get) (void **function, void **arg);
197 } s_surf_timer_model_extension_public_t,
198 *surf_timer_model_extension_public_t;
200 /** \brief Timer model
201 * \ingroup SURF_models
203 typedef struct surf_timer_model {
204 surf_model_private_t common_private;
205 surf_model_public_t common_public;
206 surf_timer_model_extension_public_t extension_public;
207 } s_surf_timer_model_t, *surf_timer_model_t;
209 /** \brief The timer model
210 * \ingroup SURF_models
212 XBT_PUBLIC_DATA(surf_timer_model_t) surf_timer_model;
214 /** \brief Initializes the timer model
215 * \ingroup SURF_models
217 XBT_PUBLIC(void) surf_timer_model_init(const char *filename);
222 * \ingroup SURF_models
225 SURF_CPU_ON = 1, /**< Up & ready */
226 SURF_CPU_OFF = 0 /**< Down & broken */
227 } e_surf_cpu_state_t;
229 /** \brief CPU model extension public
230 * \ingroup SURF_models
232 * Public functions specific to the CPU model.
234 typedef struct surf_cpu_model_extension_public {
235 surf_action_t(*execute) (void *cpu, double size);
236 surf_action_t(*sleep) (void *cpu, double duration);
237 e_surf_cpu_state_t(*get_state) (void *cpu);
238 double (*get_speed) (void *cpu, double load);
239 double (*get_available_speed) (void *cpu);
240 } s_surf_cpu_model_extension_public_t,
241 *surf_cpu_model_extension_public_t;
243 /** \brief CPU model datatype
244 * \ingroup SURF_models
246 typedef struct surf_cpu_model {
247 surf_model_private_t common_private;
248 surf_model_public_t common_public;
249 surf_cpu_model_extension_public_t extension_public;
250 } s_surf_cpu_model_t, *surf_cpu_model_t;
252 /** \brief The CPU model
253 * \ingroup SURF_models
255 XBT_PUBLIC_DATA(surf_cpu_model_t) surf_cpu_model;
257 /** \brief Initializes the CPU model with the model Cas01
258 * \ingroup SURF_models
260 * This function is called by surf_workstation_model_init_CLM03
261 * so you shouldn't have to call it by yourself.
263 * \see surf_workstation_model_init_CLM03()
265 XBT_PUBLIC(void) surf_cpu_model_init_Cas01(const char *filename);
267 /** \brief The list of all available cpu model models
268 * \ingroup SURF_models
270 XBT_PUBLIC_DATA(s_surf_model_description_t) surf_cpu_model_description[];
274 /** \brief Network model extension public
275 * \ingroup SURF_models
277 * Public functions specific to the network model
279 typedef struct surf_network_model_extension_public {
280 surf_action_t(*communicate) (void *src, void *dst, double size,
282 const void **(*get_route) (void *src, void *dst);
283 int (*get_route_size) (void *src, void *dst);
284 const char *(*get_link_name) (const void *link);
285 double (*get_link_bandwidth) (const void *link);
286 double (*get_link_latency) (const void *link);
287 int (*link_shared) (const void *link);
288 } s_surf_network_model_extension_public_t,
289 *surf_network_model_extension_public_t;
291 /** \brief Network model datatype
292 * \ingroup SURF_models
294 typedef struct surf_network_model {
295 surf_model_private_t common_private;
296 surf_model_public_t common_public;
297 surf_network_model_extension_public_t extension_public;
298 } s_surf_network_model_t, *surf_network_model_t;
300 XBT_PUBLIC(void) create_workstations(void);
302 /** \brief The network model
303 * \ingroup SURF_models
305 * When creating a new API on top on SURF, you shouldn't use the
306 * network model unless you know what you are doing. Only the workstation
307 * model should be accessed because depending on the platform model,
308 * the network model can be NULL.
310 XBT_PUBLIC_DATA(surf_network_model_t) surf_network_model;
312 /** \brief Initializes the platform with the network model 'LagrangeVelho'
313 * \ingroup SURF_models
314 * \param filename XML platform file name
316 * This model is proposed by Arnaud Legrand and Pedro Velho based on
317 * the results obtained with the GTNets simulator for onelink and
318 * dogbone sharing scenarios.
320 * \see surf_workstation_model_init_LegrandVelho()
322 XBT_PUBLIC(void) surf_network_model_init_LegrandVelho(const char *filename);
324 /** \brief Initializes the platform with the network model 'Constant'
325 * \ingroup SURF_models
326 * \param filename XML platform file name
328 * In this model, the communication time between two network cards is
329 * constant, hence no need for a routing table. This is particularly
330 * usefull when simulating huge distributed algorithms where
331 * scalability is really an issue. This function is called in
332 * conjunction with surf_workstation_model_init_compound.
334 * \see surf_workstation_model_init_compound()
336 XBT_PUBLIC(void) surf_network_model_init_Constant(const char *filename);
338 /** \brief Initializes the platform with the network model CM02
339 * \ingroup SURF_models
340 * \param filename XML platform file name
342 * This function is called by surf_workstation_model_init_CLM03
343 * or by yourself only if you plan using surf_workstation_model_init_compound
345 * \see surf_workstation_model_init_CLM03()
347 XBT_PUBLIC(void) surf_network_model_init_CM02(const char *filename);
350 /** \brief Initializes the platform with the network model GTNETS
351 * \ingroup SURF_models
352 * \param filename XML platform file name
354 * This function is called by surf_workstation_model_init_GTNETS
355 * or by yourself only if you plan using surf_workstation_model_init_compound
357 * \see surf_workstation_model_init_GTNETS()
359 XBT_PUBLIC(void) surf_network_model_init_GTNETS(const char *filename);
362 /** \brief Initializes the platform with the network model Reno
363 * \ingroup SURF_models
364 * \param filename XML platform file name
366 * The problem is related to max( sum( arctan(C * Df * xi) ) ).
369 * [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
370 * IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
372 * Call this function only if you plan using surf_workstation_model_init_compound.
375 XBT_PUBLIC(void) surf_network_model_init_Reno(const char *filename);
377 /** \brief Initializes the platform with the network model Reno2
378 * \ingroup SURF_models
379 * \param filename XML platform file name
381 * The problem is related to max( sum( arctan(C * Df * xi) ) ).
384 * [LOW01] S. H. Low. A duality model of TCP and queue management algorithms.
385 * IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
387 * Call this function only if you plan using surf_workstation_model_init_compound.
390 XBT_PUBLIC(void) surf_network_model_init_Reno2(const char *filename);
392 /** \brief Initializes the platform with the network model Vegas
393 * \ingroup SURF_models
394 * \param filename XML platform file name
396 * This problem is related to max( sum( a * Df * ln(xi) ) ) which is equivalent
397 * to the proportional fairness.
400 * [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
401 * IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
403 * Call this function only if you plan using surf_workstation_model_init_compound.
406 XBT_PUBLIC(void) surf_network_model_init_Vegas(const char *filename);
409 /** \brief Initializes the platform with the network model based on SDP
410 * \ingroup SURF_models
411 * \param filename XML platform file name
413 * This function implements the proportional fairness known as the maximization
418 * [TAG03]. Corinne Touati, Eitan Altman, and Jerome Galtier.
419 * Semi-definite programming approach for bandwidth allocation and routing in networks.
420 * Game Theory and Applications, 9:169-179, December 2003. Nova publisher.
422 * Call this function only if you plan using surf_workstation_model_init_compound.
424 XBT_PUBLIC(void) surf_network_model_init_SDP(const char *filename);
427 /** \brief The list of all available network model models
428 * \ingroup SURF_models
430 XBT_PUBLIC_DATA(s_surf_model_description_t) surf_network_model_description[];
432 /** \brief Workstation model extension public
433 * \ingroup SURF_models
435 * Public functions specific to the workstation model.
437 typedef struct surf_workstation_model_extension_public {
438 surf_action_t(*execute) (void *workstation, double size); /**< Execute a computation amount on a workstation
439 and create the corresponding action */
440 surf_action_t(*sleep) (void *workstation, double duration); /**< Make a workstation sleep during a given duration */
441 e_surf_cpu_state_t(*get_state) (void *workstation); /**< Return the CPU state of a workstation */
442 double (*get_speed) (void *workstation, double load); /**< Return the speed of a workstation */
443 double (*get_available_speed) (void *workstation); /**< Return tha available speed of a workstation */
444 surf_action_t(*communicate) (void *workstation_src, /**< Execute a communication amount between two workstations */
445 void *workstation_dst, double size,
448 surf_action_t(*execute_parallel_task) (int workstation_nb, /**< Execute a parallel task on several workstations */
449 void **workstation_list,
450 double *computation_amount,
451 double *communication_amount,
452 double amount, double rate);
453 const void **(*get_route) (void *src, void *dst); /**< Return the network link list between two workstations */
454 int (*get_route_size) (void *src, void *dst); /**< Return the route size between two workstations */
455 const char *(*get_link_name) (const void *link); /**< Return the name of a network link */
456 double (*get_link_bandwidth) (const void *link); /**< Return the current bandwidth of a network link */
457 double (*get_link_latency) (const void *link); /**< Return the current latency of a network link */
458 int (*link_shared) (const void *link);
459 } s_surf_workstation_model_extension_public_t,
460 *surf_workstation_model_extension_public_t;
462 /** \brief Workstation model datatype.
463 * \ingroup SURF_models
466 typedef struct surf_workstation_model {
467 surf_model_private_t common_private;
468 surf_model_public_t common_public;
469 surf_workstation_model_extension_public_t extension_public;
470 } s_surf_workstation_model_t, *surf_workstation_model_t;
472 /** \brief The workstation model
473 * \ingroup SURF_models
475 * Note that when you create an API on top of SURF,
476 * the workstation model should be the only one you use
477 * because depending on the platform model, the network model and the CPU model
480 XBT_PUBLIC_DATA(surf_workstation_model_t) surf_workstation_model;
482 /** \brief Initializes the platform with a compound workstation model
483 * \ingroup SURF_models
484 * \param filename XML platform file name
486 * This function should be called after a cpu_model and a
487 * network_model have been set up.
490 XBT_PUBLIC(void) surf_workstation_model_init_compound(const char *filename);
492 /** \brief Initializes the platform with the workstation model CLM03
493 * \ingroup SURF_models
494 * \param filename XML platform file name
496 * This platform model seperates the workstation model and the network model.
497 * The workstation model will be initialized with the model CLM03, the network
498 * model with the model CM02 and the CPU model with the model Cas01.
499 * In future releases, some other network models will be implemented and will be
500 * combined with the workstation model CLM03.
502 * \see surf_workstation_model_init_KCCFLN05()
504 XBT_PUBLIC(void) surf_workstation_model_init_CLM03(const char *filename);
506 /** \brief Initializes the platform with the model KCCFLN05
507 * \ingroup SURF_models
508 * \param filename XML platform file name
510 * With this model, the workstations and the network are handled
511 * together. The network model is roughly the same as in CM02 but
512 * interference between computations and communications can be taken
513 * into account. This platform model is the default one for MSG and
517 XBT_PUBLIC(void) surf_workstation_model_init_KCCFLN05(const char *filename);
519 /** \brief Initializes the platform with the model KCCFLN05
520 * \ingroup SURF_models
521 * \param filename XML platform file name
523 * With this model, only parallel tasks can be used. Resource sharing
524 * is done by identifying bottlenecks and giving an equal share of
525 * the model to each action.
528 XBT_PUBLIC(void) surf_workstation_model_init_ptask_L07(const char *filename);
530 /** \brief The list of all available workstation model models
531 * \ingroup SURF_models
533 XBT_PUBLIC_DATA(s_surf_model_description_t)
534 surf_workstation_model_description[];
536 /** \brief The network links
537 * \ingroup SURF_models
539 * This dict contains all network links.
541 * \see workstation_set
543 XBT_PUBLIC_DATA(xbt_dict_t) link_set;
545 /** \brief The workstations
546 * \ingroup SURF_models
548 * This dict contains all workstations.
552 XBT_PUBLIC_DATA(xbt_dict_t) workstation_set;
553 XBT_PUBLIC_DATA(xbt_dict_t) cpu_set;
554 /** \brief List of initialized models
555 * \ingroup SURF_models
557 XBT_PUBLIC_DATA(xbt_dynar_t) model_list;
559 /*******************************************/
560 /*** SURF Globals **************************/
561 /*******************************************/
562 XBT_PUBLIC_DATA(xbt_cfg_t) _surf_cfg_set;
564 /** \brief Initialize SURF
565 * \ingroup SURF_simulation
566 * \param argc argument number
567 * \param argv arguments
569 * This function has to be called to initialize the common
570 * structures. Then you will have to create the environment by
571 * calling surf_timer_model_init() and
572 * e.g. surf_workstation_model_init_CLM03() or
573 * surf_workstation_model_init_KCCFLN05().
575 * \see surf_timer_model_init(), surf_workstation_model_init_CLM03(),
576 * surf_workstation_model_init_KCCFLN05(), surf_workstation_model_init_compound(), surf_exit()
578 XBT_PUBLIC(void) surf_init(int *argc, char **argv); /* initialize common structures */
580 /** \brief Initialize the used models.
582 * Must be called after the surf_init so that configuration infrastructure is created
583 * Must be called before parsing/creating the environment
584 * Must not be called within the initialization process so that the use get a chance to change the settings from
585 * its code between, say, MSG_init and MSG_create_environment using MSG_config
587 XBT_PUBLIC(void) surf_config_models_setup(const char *platform_file);
589 /** \brief create the elements of the models
591 * Must be called after parsing the platform file and before using any elements
593 XBT_PUBLIC(void) surf_config_models_create_elms(void);
595 /** \brief Finish simulation initialization
596 * \ingroup SURF_simulation
598 * This function must be called before the first call to surf_solve()
600 XBT_PUBLIC(void) surf_presolve(void);
602 /** \brief Performs a part of the simulation
603 * \ingroup SURF_simulation
604 * \return the elapsed time, or -1.0 if no event could be executed
606 * This function execute all possible events, update the action states
607 * and returns the time elapsed.
608 * When you call execute or communicate on a model, the corresponding actions
609 * are not executed immediately but only when you call surf_solve.
610 * Note that the returned elapsed time can be zero.
612 XBT_PUBLIC(double) surf_solve(void);
614 /** \brief Return the current time
615 * \ingroup SURF_simulation
617 * Return the current time in millisecond.
619 XBT_PUBLIC(double) surf_get_clock(void);
622 * \ingroup SURF_simulation
628 XBT_PUBLIC(void) surf_exit(void);
630 /* Prototypes of the functions that handle the properties */
631 XBT_PUBLIC_DATA(xbt_dict_t) current_property_set; /* the prop set for the currently parsed element (also used in SIMIX) */
632 XBT_PUBLIC_DATA(void) parse_properties(void);
634 /* surf parse file related (public because called from a test suite) */
635 XBT_PUBLIC(void) parse_platform_file(const char *file);
637 /* Stores the sets */
638 XBT_PUBLIC_DATA(xbt_dict_t) set_list;
640 XBT_PUBLIC_DATA(void) manage_route(xbt_dict_t route_table,
641 const char *route_name, int action,
643 XBT_PUBLIC_DATA(int) route_action;
645 /* This is used by all models when creating the routing table while parsing */
646 XBT_PUBLIC_DATA(xbt_dict_t) route_table;
647 XBT_PUBLIC_DATA(xbt_dict_t) route_multi_table;
650 /* For the trace and trace:connect tag (store their content till the end of the parsing) */
651 XBT_PUBLIC_DATA(xbt_dict_t) traces_set_list;
652 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_host_avail;
653 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_power;
654 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_link_avail;
655 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_bandwidth;
656 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_latency;
659 XBT_PUBLIC_DATA(double) get_cpu_power(const char *power);
663 #endif /* _SURF_SURF_H */